blob: 81f8b748c90e1a46d27b4bf54118f0d5728adf6d [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Ying Wang67f02922012-08-22 10:25:20 -07004- lunch: lunch <product_name>-<build_variant>
Ying Wangb541ab62014-05-29 17:57:40 -07005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07006- croot: Changes directory to the top of the tree.
7- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08008- mm: Builds all of the modules in the current directory, but not their dependencies.
9- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000010 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080011- mma: Builds all of the modules in the current directory, and their dependencies.
Daniel Bateman22185ba2012-08-04 03:48:09 -050012- mmp: Builds all of the modules in the current directory and pushes them to the device.
13- mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
Ying Wangb607f7b2013-02-08 18:01:04 -080014- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070015- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070016- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070017- jgrep: Greps on all local Java files.
18- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000019- mangrep: Greps on all local AndroidManifest.xml files.
20- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070021- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080022- godir: Go to the directory containing a file.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060023- cmremote: Add git remote for CM Gerrit Review
24- cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
25- cmrebase: Rebase a Gerrit change and push it again
Steve Kondik873fa562012-09-17 11:33:18 -070026- aospremote: Add git remote for matching AOSP repository
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060027- mka: Builds using SCHED_BATCH on all processors
28- reposync: Parallel repo sync using ionice and SCHED_BATCH
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070029
Dan Albert4ae5d4b2014-10-31 16:23:08 -070030Environemnt options:
31- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
32 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
33 build is leak-check clean.
34
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070035Look at the source to view more functions. The complete list is:
36EOF
37 T=$(gettop)
38 local A
39 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070040 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070041 A="$A $i"
42 done
43 echo $A
44}
45
46# Get the value of a build variable as an absolute path.
47function get_abs_build_var()
48{
49 T=$(gettop)
50 if [ ! "$T" ]; then
51 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
52 return
53 fi
Ying Wang9cd17642012-12-13 10:52:07 -080054 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070055 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070056}
57
58# Get the exact value of a build variable.
59function get_build_var()
60{
61 T=$(gettop)
62 if [ ! "$T" ]; then
63 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
64 return
65 fi
Andrew Boie6905e212013-12-19 13:21:46 -080066 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070067 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080068}
69
70# check to see if the supplied product is one we can build
71function check_product()
72{
73 T=$(gettop)
74 if [ ! "$T" ]; then
75 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
76 return
77 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000078
79 if (echo -n $1 | grep -q -e "^cm_") ; then
80 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
81 else
82 CM_BUILD=
83 fi
84 export CM_BUILD
85
Jeff Browne33ba4c2011-07-11 22:11:46 -070086 TARGET_PRODUCT=$1 \
87 TARGET_BUILD_VARIANT= \
88 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070089 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080090 get_build_var TARGET_DEVICE > /dev/null
91 # hide successful answers, but allow the errors to show
92}
93
94VARIANT_CHOICES=(user userdebug eng)
95
96# check to see if the supplied variant is valid
97function check_variant()
98{
99 for v in ${VARIANT_CHOICES[@]}
100 do
101 if [ "$v" = "$1" ]
102 then
103 return 0
104 fi
105 done
106 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700107}
108
109function setpaths()
110{
111 T=$(gettop)
112 if [ ! "$T" ]; then
113 echo "Couldn't locate the top of the tree. Try setting TOP."
114 return
115 fi
116
117 ##################################################################
118 # #
119 # Read me before you modify this code #
120 # #
121 # This function sets ANDROID_BUILD_PATHS to what it is adding #
122 # to PATH, and the next time it is run, it removes that from #
123 # PATH. This is required so lunch can be run more than once #
124 # and still have working paths. #
125 # #
126 ##################################################################
127
Raphael Mollc639c782011-06-20 17:25:01 -0700128 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
129 # due to "C:\Program Files" being in the path.
130
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700131 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700132 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700133 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
134 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700135 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700136 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800137 # strip leading ':', if any
138 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500139 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700140
141 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700142 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700143 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700144
Ben Cheng8bc4c432012-11-16 13:29:13 -0800145 # defined in core/config.mk
146 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700147 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800148 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800149
Raphael Mollc639c782011-06-20 17:25:01 -0700150 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800151 export ANDROID_TOOLCHAIN=
152 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200153 local ARCH=$(get_build_var TARGET_ARCH)
154 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400155 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700156 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400157 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
158 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800159 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200160 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800161 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700162 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700163 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700164 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000165 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200166 *)
167 echo "Can't find toolchain for unknown architecture: $ARCH"
168 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700169 ;;
170 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700171 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800172 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700173 fi
Raphael732936d2011-06-22 14:35:32 -0700174
Ben Chengfba67bf2014-02-25 10:27:07 -0800175 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
176 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
177 fi
178
179 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700180 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700181 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800182 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800183 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700184 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100185 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
186 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700187 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700188 ;;
189 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700190 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700191 ;;
192 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700193
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700194 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700195 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200196
197 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
198 # to ensure that the corresponding 'emulator' binaries are used.
199 case $(uname -s) in
200 Darwin)
201 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
202 ;;
203 Linux)
204 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
205 ;;
206 *)
207 ANDROID_EMULATOR_PREBUILTS=
208 ;;
209 esac
210 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700211 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200212 export ANDROID_EMULATOR_PREBUILTS
213 fi
214
Ying Wangaa1c9b52012-11-26 20:51:59 -0800215 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800216
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500217 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900218 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500219 if [ -n "$JAVA_HOME" ]; then
220 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900221 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
222 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500223 fi
224
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800225 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700226 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
227 export OUT=$ANDROID_PRODUCT_OUT
228
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700229 unset ANDROID_HOST_OUT
230 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
231
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800232 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700233 # TODO: fix the path
234 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
235}
236
237function printconfig()
238{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800239 T=$(gettop)
240 if [ ! "$T" ]; then
241 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
242 return
243 fi
244 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700245}
246
247function set_stuff_for_environment()
248{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800249 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500250 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 setpaths
252 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700253
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800254 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700255 # With this environment variable new GCC can apply colors to warnings/errors
256 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
Dan Albert4ae5d4b2014-10-31 16:23:08 -0700257 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700258}
259
260function set_sequence_number()
261{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700262 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263}
264
265function settitle()
266{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800267 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700268 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700269 local product=$TARGET_PRODUCT
270 local variant=$TARGET_BUILD_VARIANT
271 local apps=$TARGET_BUILD_APPS
272 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700273 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700274 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700275 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700276 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800277 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700278}
279
Kenny Root52aa81c2011-07-15 11:07:06 -0700280function addcompletions()
281{
282 local T dir f
283
284 # Keep us from trying to run in something that isn't bash.
285 if [ -z "${BASH_VERSION}" ]; then
286 return
287 fi
288
289 # Keep us from trying to run in bash that's too old.
290 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
291 return
292 fi
293
294 dir="sdk/bash_completion"
295 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700296 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700297 echo "including $f"
298 . $f
299 done
300 fi
301}
302
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700303function choosetype()
304{
305 echo "Build type choices are:"
306 echo " 1. release"
307 echo " 2. debug"
308 echo
309
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800310 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700311 DEFAULT_NUM=1
312 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700313
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800314 export TARGET_BUILD_TYPE=
315 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700316 while [ -z $TARGET_BUILD_TYPE ]
317 do
318 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800319 if [ -z "$1" ] ; then
320 read ANSWER
321 else
322 echo $1
323 ANSWER=$1
324 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325 case $ANSWER in
326 "")
327 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
328 ;;
329 1)
330 export TARGET_BUILD_TYPE=release
331 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332 release)
333 export TARGET_BUILD_TYPE=release
334 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335 2)
336 export TARGET_BUILD_TYPE=debug
337 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800338 debug)
339 export TARGET_BUILD_TYPE=debug
340 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700341 *)
342 echo
343 echo "I didn't understand your response. Please try again."
344 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700345 ;;
346 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800347 if [ -n "$1" ] ; then
348 break
349 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700350 done
351
352 set_stuff_for_environment
353}
354
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800355#
356# This function isn't really right: It chooses a TARGET_PRODUCT
357# based on the list of boards. Usually, that gets you something
358# that kinda works with a generic product, but really, you should
359# pick a product by name.
360#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700361function chooseproduct()
362{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700363 if [ "x$TARGET_PRODUCT" != x ] ; then
364 default_value=$TARGET_PRODUCT
365 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700366 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700367 fi
368
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800369 export TARGET_PRODUCT=
370 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700371 while [ -z "$TARGET_PRODUCT" ]
372 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700373 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800374 if [ -z "$1" ] ; then
375 read ANSWER
376 else
377 echo $1
378 ANSWER=$1
379 fi
380
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700381 if [ -z "$ANSWER" ] ; then
382 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800383 else
384 if check_product $ANSWER
385 then
386 export TARGET_PRODUCT=$ANSWER
387 else
388 echo "** Not a valid product: $ANSWER"
389 fi
390 fi
391 if [ -n "$1" ] ; then
392 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700393 fi
394 done
395
396 set_stuff_for_environment
397}
398
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800399function choosevariant()
400{
401 echo "Variant choices are:"
402 local index=1
403 local v
404 for v in ${VARIANT_CHOICES[@]}
405 do
406 # The product name is the name of the directory containing
407 # the makefile we found, above.
408 echo " $index. $v"
409 index=$(($index+1))
410 done
411
412 local default_value=eng
413 local ANSWER
414
415 export TARGET_BUILD_VARIANT=
416 while [ -z "$TARGET_BUILD_VARIANT" ]
417 do
418 echo -n "Which would you like? [$default_value] "
419 if [ -z "$1" ] ; then
420 read ANSWER
421 else
422 echo $1
423 ANSWER=$1
424 fi
425
426 if [ -z "$ANSWER" ] ; then
427 export TARGET_BUILD_VARIANT=$default_value
428 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
429 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800430 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800431 fi
432 else
433 if check_variant $ANSWER
434 then
435 export TARGET_BUILD_VARIANT=$ANSWER
436 else
437 echo "** Not a valid variant: $ANSWER"
438 fi
439 fi
440 if [ -n "$1" ] ; then
441 break
442 fi
443 done
444}
445
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446function choosecombo()
447{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700448 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449
450 echo
451 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700452 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700453
454 echo
455 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700456 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800457
458 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700459 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800460 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461}
462
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800463# Clear this variable. It will be built up again when the vendorsetup.sh
464# files are included at the end of this file.
465unset LUNCH_MENU_CHOICES
466function add_lunch_combo()
467{
468 local new_combo=$1
469 local c
470 for c in ${LUNCH_MENU_CHOICES[@]} ; do
471 if [ "$new_combo" = "$c" ] ; then
472 return
473 fi
474 done
475 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
476}
477
478# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700479add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800480add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000481add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800482add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000483add_lunch_combo aosp_x86-eng
484add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800485
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486function print_lunch_menu()
487{
488 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700489 echo
490 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000491 if [ "$(uname)" = "Darwin" ] ; then
492 echo " (ohai, koush!)"
493 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700494 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000495 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
496 echo "Breakfast menu... pick a combo:"
497 else
498 echo "Lunch menu... pick a combo:"
499 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800500
501 local i=1
502 local choice
503 for choice in ${LUNCH_MENU_CHOICES[@]}
504 do
505 echo " $i. $choice"
506 i=$(($i+1))
507 done
508
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000509 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
510 echo "... and don't forget the bacon!"
511 fi
512
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700513 echo
514}
515
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000516function brunch()
517{
518 breakfast $*
519 if [ $? -eq 0 ]; then
520 mka bacon
521 else
522 echo "No such item in brunch menu. Try 'breakfast'"
523 return 1
524 fi
525 return $?
526}
527
528function breakfast()
529{
530 target=$1
531 CM_DEVICES_ONLY="true"
532 unset LUNCH_MENU_CHOICES
533 add_lunch_combo full-eng
534 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
535 do
536 echo "including $f"
537 . $f
538 done
539 unset f
540
541 if [ $# -eq 0 ]; then
542 # No arguments, so let's have the full menu
543 lunch
544 else
545 echo "z$target" | grep -q "-"
546 if [ $? -eq 0 ]; then
547 # A buildtype was specified, assume a full device name
548 lunch $target
549 else
550 # This is probably just the CM model name
551 lunch cm_$target-userdebug
552 fi
553 fi
554 return $?
555}
556
557alias bib=breakfast
558
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700559function lunch()
560{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800561 local answer
562
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700563 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800564 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700565 else
566 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700567 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800568 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700569 fi
570
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800571 local selection=
572
573 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700574 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700575 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800576 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
577 then
578 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
579 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800580 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800581 fi
582 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
583 then
584 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585 fi
586
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587 if [ -z "$selection" ]
588 then
589 echo
590 echo "Invalid lunch combo: $answer"
591 return 1
592 fi
593
Joe Onoratoda12daf2010-06-09 18:18:31 -0700594 export TARGET_BUILD_APPS=
595
Jeff Browne33ba4c2011-07-11 22:11:46 -0700596 local product=$(echo -n $selection | sed -e "s/-.*$//")
597 check_product $product
598 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800599 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800600 # if we can't find a product, try to grab it off the CM github
601 T=$(gettop)
602 pushd $T > /dev/null
603 build/tools/roomservice.py $product
604 popd > /dev/null
605 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000606 else
607 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800608 fi
609 if [ $? -ne 0 ]
610 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700611 echo
612 echo "** Don't have a product spec for: '$product'"
613 echo "** Do you have the right repo manifest?"
614 product=
615 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800616
Jeff Browne33ba4c2011-07-11 22:11:46 -0700617 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
618 check_variant $variant
619 if [ $? -ne 0 ]
620 then
621 echo
622 echo "** Invalid variant: '$variant'"
623 echo "** Must be one of ${VARIANT_CHOICES[@]}"
624 variant=
625 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800626
Jeff Browne33ba4c2011-07-11 22:11:46 -0700627 if [ -z "$product" -o -z "$variant" ]
628 then
629 echo
630 return 1
631 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800632
Jeff Browne33ba4c2011-07-11 22:11:46 -0700633 export TARGET_PRODUCT=$product
634 export TARGET_BUILD_VARIANT=$variant
635 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700636
637 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800638
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700639 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800640 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700641}
642
Jeff Davidson513d7a42010-08-02 10:00:44 -0700643# Tab completion for lunch.
644function _lunch()
645{
646 local cur prev opts
647 COMPREPLY=()
648 cur="${COMP_WORDS[COMP_CWORD]}"
649 prev="${COMP_WORDS[COMP_CWORD-1]}"
650
651 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
652 return 0
653}
654complete -F _lunch lunch
655
Joe Onoratoda12daf2010-06-09 18:18:31 -0700656# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700657# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700658function tapas()
659{
Ying Wangb541ab62014-05-29 17:57:40 -0700660 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700661 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700662 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
663 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700664
Ying Wang67f02922012-08-22 10:25:20 -0700665 if [ $(echo $arch | wc -w) -gt 1 ]; then
666 echo "tapas: Error: Multiple build archs supplied: $arch"
667 return
668 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700669 if [ $(echo $variant | wc -w) -gt 1 ]; then
670 echo "tapas: Error: Multiple build variants supplied: $variant"
671 return
672 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700673 if [ $(echo $density | wc -w) -gt 1 ]; then
674 echo "tapas: Error: Multiple densities supplied: $density"
675 return
676 fi
Ying Wang67f02922012-08-22 10:25:20 -0700677
678 local product=full
679 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700680 x86) product=full_x86;;
681 mips) product=full_mips;;
682 armv5) product=generic_armv5;;
683 arm64) product=aosp_arm64;;
684 x86_64) product=aosp_x86_64;;
685 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700686 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700687 if [ -z "$variant" ]; then
688 variant=eng
689 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700690 if [ -z "$apps" ]; then
691 apps=all
692 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600693 if [ -z "$density" ]; then
694 density=alldpi
695 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700696
Ying Wang67f02922012-08-22 10:25:20 -0700697 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700698 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700699 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700700 export TARGET_BUILD_TYPE=release
701 export TARGET_BUILD_APPS=$apps
702
703 set_stuff_for_environment
704 printconfig
705}
706
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100707function eat()
708{
709 if [ "$OUT" ] ; then
710 MODVERSION=`sed -n -e'/ro\.cm\.version/s/.*=//p' $OUT/system/build.prop`
711 ZIPFILE=cm-$MODVERSION.zip
712 ZIPPATH=$OUT/$ZIPFILE
713 if [ ! -f $ZIPPATH ] ; then
714 echo "Nothing to eat"
715 return 1
716 fi
717 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
718 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
719 echo "No device is online. Waiting for one..."
720 echo "Please connect USB and/or enable USB debugging"
721 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
722 sleep 1
723 done
724 echo "Device Found.."
725 fi
726 # if adbd isn't root we can't write to /cache/recovery/
727 adb root
728 sleep 1
729 adb wait-for-device
730 SZ=`stat -c %s $ZIPPATH`
731 CACHESIZE=`adb shell busybox df -PB1 /cache | grep /cache | tr -s ' ' | cut -d ' ' -f 4`
732 if [ $CACHESIZE -gt $SZ ];
733 then
734 PUSHDIR=/cache/
735 DIR=cache
736 else
737 PUSHDIR=/storage/sdcard0/
738 # Optional path for sdcard0 in recovery
739 [ -z "$1" ] && DIR=sdcard/0 || DIR=$1
740 fi
741 echo "Pushing $ZIPFILE to $PUSHDIR"
742 if adb push $ZIPPATH $PUSHDIR ; then
743 cat << EOF > /tmp/command
744--update_package=/$DIR/$ZIPFILE
745EOF
746 if adb push /tmp/command /cache/recovery/ ; then
747 echo "Rebooting into recovery for installation"
748 adb reboot recovery
749 fi
750 rm /tmp/command
751 fi
752 else
753 echo "Nothing to eat"
754 return 1
755 fi
756 return $?
757}
758
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700759function gettop
760{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800761 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700762 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700763 # The following circumlocution ensures we remove symlinks from TOP.
764 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700765 else
766 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800767 # The following circumlocution (repeated below as well) ensures
768 # that we record the true directory name and not one that is
769 # faked up with symlink names.
770 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700771 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800772 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700773 T=
774 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800775 \cd ..
synergyb112a402013-07-05 19:47:47 -0700776 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700777 done
Ying Wang9cd17642012-12-13 10:52:07 -0800778 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779 if [ -f "$T/$TOPFILE" ]; then
780 echo $T
781 fi
782 fi
783 fi
784}
785
Andrew Hsieh906cb782013-09-10 17:37:14 +0800786# Return driver for "make", if any (eg. static analyzer)
787function getdriver()
788{
789 local T="$1"
790 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
791 if [ -n "$WITH_STATIC_ANALYZER" ]; then
792 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800793$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
794--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800795--status-bugs \
796--top=$T"
797 fi
798}
799
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700800function m()
801{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800802 local T=$(gettop)
803 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700804 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800805 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700806 else
807 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700808 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700809 fi
810}
811
812function findmakefile()
813{
814 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800815 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700816 T=
817 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700818 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700819 if [ -f "$T/Android.mk" ]; then
820 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800821 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700822 return
823 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800824 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700825 done
Ying Wang9cd17642012-12-13 10:52:07 -0800826 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700827}
828
829function mm()
830{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800831 local T=$(gettop)
832 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700833 # If we're sitting in the root of the build tree, just do a
834 # normal make.
835 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800836 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700837 else
838 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800839 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700840 local MODULES=
841 local GET_INSTALL_PATH=
842 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700843 # Remove the path to top as the makefilepath needs to be relative
844 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845 if [ ! "$T" ]; then
846 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700847 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700848 elif [ ! "$M" ]; then
849 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700850 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700851 else
Ying Wanga7deb082013-08-16 13:24:47 -0700852 for ARG in $@; do
853 case $ARG in
854 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
855 esac
856 done
857 if [ -n "$GET_INSTALL_PATH" ]; then
858 MODULES=
859 ARGS=GET-INSTALL-PATH
860 else
861 MODULES=all_modules
862 ARGS=$@
863 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700864 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700865 fi
866 fi
867}
868
869function mmm()
870{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800871 local T=$(gettop)
872 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700873 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800874 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800875 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800876 local ARGS=
877 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700878 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800879 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
880 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
881 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800882 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
883 if [ "$MODULES" = "" ]; then
884 MODULES=all_modules
885 fi
886 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700887 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700888 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
889 local TO_CHOP=`expr $TO_CHOP + 1`
890 local START=`PWD= /bin/pwd`
891 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700892 if [ "$MFILE" = "" ] ; then
893 MFILE=$DIR/Android.mk
894 else
895 MFILE=$MFILE/$DIR/Android.mk
896 fi
897 MAKEFILE="$MAKEFILE $MFILE"
898 else
Ying Wanga7deb082013-08-16 13:24:47 -0700899 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100900 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700901 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
902 *) echo "No Android.mk in $DIR."; return 1;;
903 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700904 fi
905 done
Ying Wanga7deb082013-08-16 13:24:47 -0700906 if [ -n "$GET_INSTALL_PATH" ]; then
907 ARGS=$GET_INSTALL_PATH
908 MODULES=
909 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800910 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700911 else
912 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700913 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700914 fi
915}
916
Ying Wangb607f7b2013-02-08 18:01:04 -0800917function mma()
918{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800919 local T=$(gettop)
920 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800921 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800922 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800923 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800924 if [ ! "$T" ]; then
925 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700926 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800927 fi
928 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800929 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800930 fi
931}
932
933function mmma()
934{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800935 local T=$(gettop)
936 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800937 if [ "$T" ]; then
938 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
939 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
940 local MY_PWD=`PWD= /bin/pwd`
941 if [ "$MY_PWD" = "$T" ]; then
942 MY_PWD=
943 else
944 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
945 fi
946 local DIR=
947 local MODULE_PATHS=
948 local ARGS=
949 for DIR in $DIRS ; do
950 if [ -d $DIR ]; then
951 if [ "$MY_PWD" = "" ]; then
952 MODULE_PATHS="$MODULE_PATHS $DIR"
953 else
954 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
955 fi
956 else
957 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100958 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800959 *) echo "Couldn't find directory $DIR"; return 1;;
960 esac
961 fi
962 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800963 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
Ying Wangb607f7b2013-02-08 18:01:04 -0800964 else
965 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700966 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800967 fi
968}
969
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700970function croot()
971{
972 T=$(gettop)
973 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800974 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700975 else
976 echo "Couldn't locate the top of the tree. Try setting TOP."
977 fi
978}
979
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700980function cproj()
981{
982 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700983 local HERE=$PWD
984 T=
985 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
986 T=$PWD
987 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800988 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700989 return
990 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800991 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700992 done
Ying Wang9cd17642012-12-13 10:52:07 -0800993 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700994 echo "can't find Android.mk"
995}
996
Daniel Sandler47e0a882013-07-30 13:23:52 -0400997# simplified version of ps; output in the form
998# <pid> <procname>
999function qpid() {
1000 local prepend=''
1001 local append=''
1002 if [ "$1" = "--exact" ]; then
1003 prepend=' '
1004 append='$'
1005 shift
1006 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1007 echo "usage: qpid [[--exact] <process name|pid>"
1008 return 255
1009 fi
1010
1011 local EXE="$1"
1012 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001013 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001014 else
1015 adb shell ps \
1016 | tr -d '\r' \
1017 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1018 fi
1019}
1020
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001021function pid()
1022{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001023 local prepend=''
1024 local append=''
1025 if [ "$1" = "--exact" ]; then
1026 prepend=' '
1027 append='$'
1028 shift
1029 fi
1030 local EXE="$1"
1031 if [ "$EXE" ] ; then
1032 local PID=`adb shell ps \
1033 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001034 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001035 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1036 echo "$PID"
1037 else
1038 echo "usage: pid [--exact] <process name>"
1039 return 255
1040 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001041}
1042
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001043# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001044# that has the core-file-size limit set correctly
1045#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001046# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001047# if its core-file-size limit is not set already.
1048# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1049
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001050function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001051{
1052 echo "Getting root...";
1053 adb root;
1054 adb wait-for-device;
1055
1056 echo "Remounting root parition read-write...";
1057 adb shell mount -w -o remount -t rootfs rootfs;
1058 sleep 1;
1059 adb wait-for-device;
1060 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001061 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001062 adb shell chmod 0777 /cores;
1063
1064 echo "Granting SELinux permission to dump in /cores...";
1065 adb shell restorecon -R /cores;
1066
1067 echo "Set core pattern.";
1068 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1069
1070 echo "Done."
1071}
1072
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001073# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001074# $1 = PID of process (e.g., $(pid mediaserver))
1075#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001076# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001077# dump to actually be generated.
1078
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001079function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001080{
1081 local PID=$1;
1082 if [ -z "$PID" ]; then
1083 printf "Expecting a PID!\n";
1084 return;
1085 fi;
1086 echo "Setting core limit for $PID to infinite...";
1087 adb shell prlimit $PID 4 -1 -1
1088}
1089
1090# core - send SIGV and pull the core for process
1091# $1 = PID of process (e.g., $(pid mediaserver))
1092#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001093# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001094# enabled globally.
1095
1096function core()
1097{
1098 local PID=$1;
1099
1100 if [ -z "$PID" ]; then
1101 printf "Expecting a PID!\n";
1102 return;
1103 fi;
1104
1105 local CORENAME=core.$PID;
1106 local COREPATH=/cores/$CORENAME;
1107 local SIG=SEGV;
1108
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001109 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001110
1111 local done=0;
1112 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1113 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1114 adb shell kill -$SIG $PID;
1115 sleep 1;
1116 done;
1117
1118 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1119 echo "Done: core is under $COREPATH on device.";
1120}
1121
Christopher Tate744ee802009-11-12 15:33:08 -08001122# systemstack - dump the current stack trace of all threads in the system process
1123# to the usual ANR traces file
1124function systemstack()
1125{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001126 stacks system_server
1127}
1128
1129function stacks()
1130{
1131 if [[ $1 =~ ^[0-9]+$ ]] ; then
1132 local PID="$1"
1133 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001134 local PIDLIST="$(pid $1)"
1135 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1136 local PID="$PIDLIST"
1137 elif [ "$PIDLIST" ] ; then
1138 echo "more than one process: $1"
1139 else
1140 echo "no such process: $1"
1141 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001142 else
1143 echo "usage: stacks [pid|process name]"
1144 fi
1145
1146 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001147 # Determine whether the process is native
1148 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1149 # Dump stacks of Dalvik process
1150 local TRACES=/data/anr/traces.txt
1151 local ORIG=/data/anr/traces.orig
1152 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001153
Jeff Brownb12c2e52013-08-19 15:14:16 -07001154 # Keep original traces to avoid clobbering
1155 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001156
Jeff Brownb12c2e52013-08-19 15:14:16 -07001157 # Make sure we have a usable file
1158 adb shell touch $TRACES
1159 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001160
Jeff Brownb12c2e52013-08-19 15:14:16 -07001161 # Dump stacks and wait for dump to finish
1162 adb shell kill -3 $PID
1163 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001164
Jeff Brownb12c2e52013-08-19 15:14:16 -07001165 # Restore original stacks, and show current output
1166 adb shell mv $TRACES $TMP
1167 adb shell mv $ORIG $TRACES
1168 adb shell cat $TMP
1169 else
1170 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001171 local USE64BIT="$(is64bit $PID)"
1172 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001173 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001174 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001175}
1176
Michael Wrightaeed7212014-06-19 19:58:12 -07001177# Read the ELF header from /proc/$PID/exe to determine if the process is
1178# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001179function is64bit()
1180{
1181 local PID="$1"
1182 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001183 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001184 echo "64"
1185 else
1186 echo ""
1187 fi
1188 else
1189 echo ""
1190 fi
1191}
1192
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001193case `uname -s` in
1194 Darwin)
1195 function sgrep()
1196 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001197 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001198 }
1199
1200 ;;
1201 *)
1202 function sgrep()
1203 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001204 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001205 }
1206 ;;
1207esac
1208
Raghu Gandham8da43102012-07-25 19:57:22 -07001209function gettargetarch
1210{
1211 get_build_var TARGET_ARCH
1212}
1213
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001214function ggrep()
1215{
1216 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1217}
1218
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001219function jgrep()
1220{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001221 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001222}
1223
1224function cgrep()
1225{
Dan Albert01961192014-11-22 10:16:01 -08001226 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001227}
1228
1229function resgrep()
1230{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001231 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001232}
1233
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001234function mangrep()
1235{
1236 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1237}
1238
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001239function sepgrep()
1240{
1241 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d -print0 | xargs -0 grep --color -n -r --exclude-dir=\.git "$@"
1242}
1243
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001244function rcgrep()
1245{
1246 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1247}
1248
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001249case `uname -s` in
1250 Darwin)
1251 function mgrep()
1252 {
Ying Wang324c2b22012-08-17 15:03:20 -07001253 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001254 }
1255
1256 function treegrep()
1257 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001258 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001259 }
1260
1261 ;;
1262 *)
1263 function mgrep()
1264 {
Ying Wang324c2b22012-08-17 15:03:20 -07001265 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001266 }
1267
1268 function treegrep()
1269 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001270 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001271 }
1272
1273 ;;
1274esac
1275
1276function getprebuilt
1277{
1278 get_abs_build_var ANDROID_PREBUILTS
1279}
1280
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001281function tracedmdump()
1282{
1283 T=$(gettop)
1284 if [ ! "$T" ]; then
1285 echo "Couldn't locate the top of the tree. Try setting TOP."
1286 return
1287 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001288 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001289 local arch=$(gettargetarch)
1290 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001291
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001292 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001293 if [ ! "$TRACE" ] ; then
1294 echo "usage: tracedmdump tracename"
1295 return
1296 fi
1297
Jack Veenstra60116fc2009-04-09 18:12:34 -07001298 if [ ! -r "$KERNEL" ] ; then
1299 echo "Error: cannot find kernel: '$KERNEL'"
1300 return
1301 fi
1302
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001303 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001304 if [ "$BASETRACE" = "$TRACE" ] ; then
1305 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1306 fi
1307
1308 echo "post-processing traces..."
1309 rm -f $TRACE/qtrace.dexlist
1310 post_trace $TRACE
1311 if [ $? -ne 0 ]; then
1312 echo "***"
1313 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1314 echo "***"
1315 return
1316 fi
1317 echo "generating dexlist output..."
1318 /bin/ls $ANDROID_PRODUCT_OUT/system/framework/*.jar $ANDROID_PRODUCT_OUT/system/app/*.apk $ANDROID_PRODUCT_OUT/data/app/*.apk 2>/dev/null | xargs dexlist > $TRACE/qtrace.dexlist
1319 echo "generating dmtrace data..."
1320 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1321 echo "generating html file..."
1322 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1323 echo "done, see $TRACE/dmtrace.html for details"
1324 echo "or run:"
1325 echo " traceview $TRACE/dmtrace"
1326}
1327
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001328# communicate with a running device or emulator, set up necessary state,
1329# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001330function runhat()
1331{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001332 # process standard adb options
1333 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001334 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001335 adbTarget=$1
1336 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001337 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001338 adbTarget="$1 $2"
1339 shift 2
1340 fi
1341 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001342 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001343
1344 # runhat options
1345 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001346
1347 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001348 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001349 return
1350 fi
1351
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001352 # confirm hat is available
1353 if [ -z $(which hat) ]; then
1354 echo "hat is not available in this configuration."
1355 return
1356 fi
1357
Andy McFaddenb6289852010-07-12 08:00:19 -07001358 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001359 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001360 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001361 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001362 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001363 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001364 echo -n "> "
1365 read
1366
The Android Open Source Project88b60792009-03-03 19:28:42 -08001367 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001368
The Android Open Source Project88b60792009-03-03 19:28:42 -08001369 echo "Retrieving file $devFile..."
1370 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001371
The Android Open Source Project88b60792009-03-03 19:28:42 -08001372 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001373
The Android Open Source Project88b60792009-03-03 19:28:42 -08001374 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001375 echo "View the output by pointing your browser at http://localhost:7000/"
1376 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001377 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001378}
1379
1380function getbugreports()
1381{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001382 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001383
1384 if [ ! "$reports" ]; then
1385 echo "Could not locate any bugreports."
1386 return
1387 fi
1388
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001389 local report
1390 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001391 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001392 echo "/sdcard/bugreports/${report}"
1393 adb pull /sdcard/bugreports/${report} ${report}
1394 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001395 done
1396}
1397
Victoria Lease1b296b42012-08-21 15:44:06 -07001398function getsdcardpath()
1399{
1400 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1401}
1402
1403function getscreenshotpath()
1404{
1405 echo "$(getsdcardpath)/Pictures/Screenshots"
1406}
1407
1408function getlastscreenshot()
1409{
1410 local screenshot_path=$(getscreenshotpath)
1411 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1412 if [ "$screenshot" = "" ]; then
1413 echo "No screenshots found."
1414 return
1415 fi
1416 echo "${screenshot}"
1417 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1418}
1419
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001420function startviewserver()
1421{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001422 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001423 if [ $# -gt 0 ]; then
1424 port=$1
1425 fi
1426 adb shell service call window 1 i32 $port
1427}
1428
1429function stopviewserver()
1430{
1431 adb shell service call window 2
1432}
1433
1434function isviewserverstarted()
1435{
1436 adb shell service call window 3
1437}
1438
Romain Guyb84049a2010-10-04 16:56:11 -07001439function key_home()
1440{
1441 adb shell input keyevent 3
1442}
1443
1444function key_back()
1445{
1446 adb shell input keyevent 4
1447}
1448
1449function key_menu()
1450{
1451 adb shell input keyevent 82
1452}
1453
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001454function smoketest()
1455{
1456 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1457 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1458 return
1459 fi
1460 T=$(gettop)
1461 if [ ! "$T" ]; then
1462 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1463 return
1464 fi
1465
Ying Wang9cd17642012-12-13 10:52:07 -08001466 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001467 adb uninstall com.android.smoketest > /dev/null &&
1468 adb uninstall com.android.smoketest.tests > /dev/null &&
1469 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1470 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1471 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1472}
1473
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001474# simple shortcut to the runtest command
1475function runtest()
1476{
1477 T=$(gettop)
1478 if [ ! "$T" ]; then
1479 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1480 return
1481 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001482 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001483}
1484
The Android Open Source Project88b60792009-03-03 19:28:42 -08001485function godir () {
1486 if [[ -z "$1" ]]; then
1487 echo "Usage: godir <regex>"
1488 return
1489 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001490 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001491 if [[ ! -f $T/filelist ]]; then
1492 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001493 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001494 echo " Done"
1495 echo ""
1496 fi
1497 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001498 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001499 if [[ ${#lines[@]} = 0 ]]; then
1500 echo "Not found"
1501 return
1502 fi
1503 local pathname
1504 local choice
1505 if [[ ${#lines[@]} > 1 ]]; then
1506 while [[ -z "$pathname" ]]; do
1507 local index=1
1508 local line
1509 for line in ${lines[@]}; do
1510 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001511 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001512 done
1513 echo
1514 echo -n "Select one: "
1515 unset choice
1516 read choice
1517 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1518 echo "Invalid choice"
1519 continue
1520 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001521 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001522 done
1523 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001524 pathname=${lines[0]}
1525 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001526 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001527}
1528
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001529function cmremote()
1530{
1531 git remote rm cmremote 2> /dev/null
1532 if [ ! -d .git ]
1533 then
1534 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1535 fi
1536 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1537 if [ -z "$GERRIT_REMOTE" ]
1538 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001539 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1540 if [ -z "$GERRIT_REMOTE" ]
1541 then
1542 echo Unable to set up the git remote, are you in the root of the repo?
1543 return 0
1544 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001545 fi
1546 CMUSER=`git config --get review.review.cyanogenmod.com.username`
1547 if [ -z "$CMUSER" ]
1548 then
1549 git remote add cmremote ssh://review.cyanogenmod.com:29418/$GERRIT_REMOTE
1550 else
1551 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.com:29418/$GERRIT_REMOTE
1552 fi
1553 echo You can now push to "cmremote".
1554}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001555export -f cmremote
1556
Steve Kondik873fa562012-09-17 11:33:18 -07001557function aospremote()
1558{
1559 git remote rm aosp 2> /dev/null
1560 if [ ! -d .git ]
1561 then
1562 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1563 fi
1564 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1565 if (echo $PROJECT | grep -qv "^device")
1566 then
1567 PFX="platform/"
1568 fi
1569 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1570 echo "Remote 'aosp' created"
1571}
1572export -f aospremote
1573
Steve Kondikf00e7d92012-09-23 23:46:55 -07001574function installboot()
1575{
1576 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1577 then
1578 echo "No recovery.fstab found. Build recovery first."
1579 return 1
1580 fi
1581 if [ ! -e "$OUT/boot.img" ];
1582 then
1583 echo "No boot.img found. Run make bootimage first."
1584 return 1
1585 fi
1586 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1587 if [ -z "$PARTITION" ];
1588 then
1589 echo "Unable to determine boot partition."
1590 return 1
1591 fi
1592 adb start-server
1593 adb root
1594 sleep 1
1595 adb wait-for-device
1596 adb remount
1597 adb wait-for-device
1598 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1599 then
1600 adb push $OUT/boot.img /cache/
1601 for i in $OUT/system/lib/modules/*;
1602 do
1603 adb push $i /system/lib/modules/
1604 done
1605 adb shell dd if=/cache/boot.img of=$PARTITION
1606 adb shell chmod 644 /system/lib/modules/*
1607 echo "Installation complete."
1608 else
1609 echo "The connected device does not appear to be $CM_BUILD, run away!"
1610 fi
1611}
1612
1613
Koushik Duttab55f13a2012-05-14 16:14:36 -07001614function makerecipe() {
1615 if [ -z "$1" ]
1616 then
1617 echo "No branch name provided."
1618 return 1
1619 fi
1620 cd android
1621 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1622 git commit -a -m "$1"
1623 cd ..
1624
1625 repo forall -c '
1626
1627 if [ "$REPO_REMOTE" == "github" ]
1628 then
1629 pwd
1630 cmremote
1631 git push cmremote HEAD:refs/heads/'$1'
1632 fi
1633 '
1634}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001635
1636function cmgerrit() {
1637 if [ $# -eq 0 ]; then
1638 $FUNCNAME help
1639 return 1
1640 fi
1641 local user=`git config --get review.review.cyanogenmod.com.username`
1642 local review=`git config --get remote.github.review`
1643 local project=`git config --get remote.github.projectname`
1644 local command=$1
1645 shift
1646 case $command in
1647 help)
1648 if [ $# -eq 0 ]; then
1649 cat <<EOF
1650Usage:
1651 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1652
1653Commands:
1654 fetch Just fetch the change as FETCH_HEAD
1655 help Show this help, or for a specific command
1656 pull Pull a change into current branch
1657 push Push HEAD or a local branch to Gerrit for a specific branch
1658
1659Any other Git commands that support refname would work as:
1660 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1661
1662See '$FUNCNAME help COMMAND' for more information on a specific command.
1663
1664Example:
1665 $FUNCNAME checkout -b topic 1234/5
1666works as:
1667 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1668 && git checkout -b topic FETCH_HEAD
1669will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1670Patch-set 1 will be fetched if omitted.
1671EOF
1672 return
1673 fi
1674 case $1 in
1675 __cmg_*) echo "For internal use only." ;;
1676 changes|for)
1677 if [ "$FUNCNAME" = "cmgerrit" ]; then
1678 echo "'$FUNCNAME $1' is deprecated."
1679 fi
1680 ;;
1681 help) $FUNCNAME help ;;
1682 fetch|pull) cat <<EOF
1683usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1684
1685works as:
1686 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1687 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1688
1689Example:
1690 $FUNCNAME $1 1234
1691will $1 patch-set 1 of change 1234
1692EOF
1693 ;;
1694 push) cat <<EOF
1695usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1696
1697works as:
1698 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1699 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1700
1701Example:
1702 $FUNCNAME push fix6789:gingerbread
1703will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1704HEAD will be pushed from local if omitted.
1705EOF
1706 ;;
1707 *)
1708 $FUNCNAME __cmg_err_not_supported $1 && return
1709 cat <<EOF
1710usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1711
1712works as:
1713 git fetch http://DOMAIN/p/PROJECT \\
1714 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1715 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1716EOF
1717 ;;
1718 esac
1719 ;;
1720 __cmg_get_ref)
1721 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1722 local change_id patchset_id hash
1723 case $1 in
1724 */*)
1725 change_id=${1%%/*}
1726 patchset_id=${1#*/}
1727 ;;
1728 *)
1729 change_id=$1
1730 patchset_id=1
1731 ;;
1732 esac
1733 hash=$(($change_id % 100))
1734 case $hash in
1735 [0-9]) hash="0$hash" ;;
1736 esac
1737 echo "refs/changes/$hash/$change_id/$patchset_id"
1738 ;;
1739 fetch|pull)
1740 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1741 $FUNCNAME __cmg_err_not_repo && return 1
1742 local change=$1
1743 shift
1744 git $command $@ http://$review/p/$project \
1745 $($FUNCNAME __cmg_get_ref $change) || return 1
1746 ;;
1747 push)
1748 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1749 $FUNCNAME __cmg_err_not_repo && return 1
1750 if [ -z "$user" ]; then
1751 echo >&2 "Gerrit username not found."
1752 return 1
1753 fi
1754 local local_branch remote_branch
1755 case $1 in
1756 *:*)
1757 local_branch=${1%:*}
1758 remote_branch=${1##*:}
1759 ;;
1760 *)
1761 local_branch=HEAD
1762 remote_branch=$1
1763 ;;
1764 esac
1765 shift
1766 git push $@ ssh://$user@$review:29418/$project \
1767 $local_branch:refs/for/$remote_branch || return 1
1768 ;;
1769 changes|for)
1770 if [ "$FUNCNAME" = "cmgerrit" ]; then
1771 echo >&2 "'$FUNCNAME $command' is deprecated."
1772 fi
1773 ;;
1774 __cmg_err_no_arg)
1775 if [ $# -lt 2 ]; then
1776 echo >&2 "'$FUNCNAME $command' missing argument."
1777 elif [ $2 -eq 0 ]; then
1778 if [ -n "$3" ]; then
1779 $FUNCNAME help $1
1780 else
1781 echo >&2 "'$FUNCNAME $1' missing argument."
1782 fi
1783 else
1784 return 1
1785 fi
1786 ;;
1787 __cmg_err_not_repo)
1788 if [ -z "$review" -o -z "$project" ]; then
1789 echo >&2 "Not currently in any reviewable repository."
1790 else
1791 return 1
1792 fi
1793 ;;
1794 __cmg_err_not_supported)
1795 $FUNCNAME __cmg_err_no_arg $command $# && return
1796 case $1 in
1797 #TODO: filter more git commands that don't use refname
1798 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1799 echo >&2 "'$FUNCNAME $1' is not supported."
1800 ;;
1801 *) return 1 ;;
1802 esac
1803 ;;
1804 #TODO: other special cases?
1805 *)
1806 $FUNCNAME __cmg_err_not_supported $command && return 1
1807 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1808 $FUNCNAME __cmg_err_not_repo && return 1
1809 local args="$@"
1810 local change pre_args refs_arg post_args
1811 case "$args" in
1812 *--\ *)
1813 pre_args=${args%%-- *}
1814 post_args="-- ${args#*-- }"
1815 ;;
1816 *) pre_args="$args" ;;
1817 esac
1818 args=($pre_args)
1819 pre_args=
1820 if [ ${#args[@]} -gt 0 ]; then
1821 change=${args[${#args[@]}-1]}
1822 fi
1823 if [ ${#args[@]} -gt 1 ]; then
1824 pre_args=${args[0]}
1825 for ((i=1; i<${#args[@]}-1; i++)); do
1826 pre_args="$pre_args ${args[$i]}"
1827 done
1828 fi
1829 while ((1)); do
1830 case $change in
1831 ""|--)
1832 $FUNCNAME help $command
1833 return 1
1834 ;;
1835 *@*)
1836 if [ -z "$refs_arg" ]; then
1837 refs_arg="@${change#*@}"
1838 change=${change%%@*}
1839 fi
1840 ;;
1841 *~*)
1842 if [ -z "$refs_arg" ]; then
1843 refs_arg="~${change#*~}"
1844 change=${change%%~*}
1845 fi
1846 ;;
1847 *^*)
1848 if [ -z "$refs_arg" ]; then
1849 refs_arg="^${change#*^}"
1850 change=${change%%^*}
1851 fi
1852 ;;
1853 *:*)
1854 if [ -z "$refs_arg" ]; then
1855 refs_arg=":${change#*:}"
1856 change=${change%%:*}
1857 fi
1858 ;;
1859 *) break ;;
1860 esac
1861 done
1862 $FUNCNAME fetch $change \
1863 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1864 || return 1
1865 ;;
1866 esac
1867}
1868
1869function cmrebase() {
1870 local repo=$1
1871 local refs=$2
1872 local pwd="$(pwd)"
1873 local dir="$(gettop)/$repo"
1874
1875 if [ -z $repo ] || [ -z $refs ]; then
1876 echo "CyanogenMod Gerrit Rebase Usage: "
1877 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1878 echo " The patch IDs appear on the Gerrit commands that are offered."
1879 echo " They consist on a series of numbers and slashes, after the text"
1880 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1881 echo ""
1882 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1883 echo ""
1884 return
1885 fi
1886
1887 if [ ! -d $dir ]; then
1888 echo "Directory $dir doesn't exist in tree."
1889 return
1890 fi
1891 cd $dir
1892 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1893 echo "Starting branch..."
1894 repo start tmprebase .
1895 echo "Bringing it up to date..."
1896 repo sync .
1897 echo "Fetching change..."
1898 git fetch "http://review.cyanogenmod.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
1899 if [ "$?" != "0" ]; then
1900 echo "Error cherry-picking. Not uploading!"
1901 return
1902 fi
1903 echo "Uploading..."
1904 repo upload .
1905 echo "Cleaning up..."
1906 repo abandon tmprebase .
1907 cd $pwd
1908}
1909
1910function mka() {
1911 case `uname -s` in
1912 Darwin)
1913 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1914 ;;
1915 *)
1916 schedtool -B -n 1 -e ionice -n 1 make -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@"
1917 ;;
1918 esac
1919}
1920
1921function reposync() {
1922 case `uname -s` in
1923 Darwin)
1924 repo sync -j 4 "$@"
1925 ;;
1926 *)
Alan Orthef363cd2012-09-07 11:44:27 +03001927 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001928 ;;
1929 esac
1930}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02001931
1932function repodiff() {
1933 if [ -z "$*" ]; then
1934 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1935 return
1936 fi
1937 diffopts=$* repo forall -c \
1938 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
1939}
1940
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301941# Credit for color strip sed: http://goo.gl/BoIcm
1942function dopush()
1943{
1944 local func=$1
1945 shift
1946
1947 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
1948 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
1949 echo "No device is online. Waiting for one..."
1950 echo "Please connect USB and/or enable USB debugging"
1951 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
1952 sleep 1
1953 done
1954 echo "Device Found."
1955 fi
1956
1957 adb root &> /dev/null
1958 sleep 0.3
1959 adb wait-for-device &> /dev/null
1960 sleep 0.3
1961 adb remount &> /dev/null
1962
1963 $func $* | tee $OUT/.log
1964
1965 # Install: <file>
1966 LOC=$(cat $OUT/.log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep 'Install' | cut -d ':' -f 2)
1967
1968 # Copy: <file>
1969 LOC=$LOC $(cat $OUT/.log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep 'Copy' | cut -d ':' -f 2)
1970
1971 for FILE in $LOC; do
1972 # Get target file name (i.e. system/bin/adb)
1973 TARGET=$(echo $FILE | sed "s#$OUT/##")
1974
1975 # Don't send files that are not in /system.
1976 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
1977 continue
1978 else
1979 case $TARGET in
1980 system/app/SystemUI.apk|system/framework/*)
1981 stop_n_start=true
1982 ;;
1983 *)
1984 stop_n_start=false
1985 ;;
1986 esac
1987 if $stop_n_start ; then adb shell stop ; fi
1988 echo "Pushing: $TARGET"
1989 adb push $FILE $TARGET
1990 if $stop_n_start ; then adb shell start ; fi
1991 fi
1992 done
1993 rm -f $OUT/.log
1994 return 0
1995}
1996
1997alias mmp='dopush mm'
1998alias mmmp='dopush mmm'
1999alias mkap='dopush mka'
2000alias cmkap='dopush cmka'
2001
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002002# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002003#
2004# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2005# For some reason, installing the JDK doesn't make it show up in the
2006# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002007function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002008 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002009 # we can reset it later, depending on the version of java the build
2010 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002011 #
2012 # If we don't do this, the JAVA_HOME value set by the first call to
2013 # build/envsetup.sh will persist forever.
2014 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2015 export JAVA_HOME=""
2016 fi
2017
Andy McFaddenbd960942010-06-24 12:52:51 -07002018 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002019 case `uname -s` in
2020 Darwin)
2021 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2022 ;;
2023 *)
2024 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2025 ;;
2026 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002027
2028 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2029 # we can change it on the next envsetup.sh, if required.
2030 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002031 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002032}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002033
Alex Rayf0d08eb2013-03-08 15:15:06 -08002034# Print colored exit condition
2035function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002036 "$@"
2037 local retval=$?
2038 if [ $retval -ne 0 ]
2039 then
2040 echo -e "\e[0;31mFAILURE\e[00m"
2041 else
2042 echo -e "\e[0;32mSUCCESS\e[00m"
2043 fi
2044 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002045}
2046
Ying Wanged21d4c2014-08-24 22:14:19 -07002047function get_make_command()
2048{
2049 echo command make
2050}
2051
Ed Heylcc6be0a2014-06-18 14:55:58 -07002052function make()
2053{
2054 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002055 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002056 local ret=$?
2057 local end_time=$(date +"%s")
2058 local tdiff=$(($end_time-$start_time))
2059 local hours=$(($tdiff / 3600 ))
2060 local mins=$((($tdiff % 3600) / 60))
2061 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002062 local ncolors=$(tput colors 2>/dev/null)
2063 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2064 color_failed="\e[0;31m"
2065 color_success="\e[0;32m"
2066 color_reset="\e[00m"
2067 else
2068 color_failed=""
2069 color_success=""
2070 color_reset=""
2071 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002072 echo
2073 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002074 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002075 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002076 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002077 fi
2078 if [ $hours -gt 0 ] ; then
2079 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2080 elif [ $mins -gt 0 ] ; then
2081 printf "(%02g:%02g (mm:ss))" $mins $secs
2082 elif [ $secs -gt 0 ] ; then
2083 printf "(%s seconds)" $secs
2084 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002085 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002086 echo
2087 return $ret
2088}
2089
Raphael Moll70a86b02011-06-20 16:03:14 -07002090if [ "x$SHELL" != "x/bin/bash" ]; then
2091 case `ps -o command -p $$` in
2092 *bash*)
2093 ;;
2094 *)
2095 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2096 ;;
2097 esac
2098fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002099
2100# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002101for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2102 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002103do
2104 echo "including $f"
2105 . $f
2106done
2107unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002108
2109addcompletions