blob: d126ebca0911727ecf1986c89b0e5317d0dfb98c [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.
12- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070013- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070014- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070015- jgrep: Greps on all local Java files.
16- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000017- mangrep: Greps on all local AndroidManifest.xml files.
18- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070019- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080020- godir: Go to the directory containing a file.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060021- cmremote: Add git remote for CM Gerrit Review
22- cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
23- cmrebase: Rebase a Gerrit change and push it again
24- mka: Builds using SCHED_BATCH on all processors
25- reposync: Parallel repo sync using ionice and SCHED_BATCH
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070026
Dan Albert4ae5d4b2014-10-31 16:23:08 -070027Environemnt options:
28- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
29 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
30 build is leak-check clean.
31
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070032Look at the source to view more functions. The complete list is:
33EOF
34 T=$(gettop)
35 local A
36 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070037 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 -070038 A="$A $i"
39 done
40 echo $A
41}
42
43# Get the value of a build variable as an absolute path.
44function get_abs_build_var()
45{
46 T=$(gettop)
47 if [ ! "$T" ]; then
48 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
49 return
50 fi
Ying Wang9cd17642012-12-13 10:52:07 -080051 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070052 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070053}
54
55# Get the exact value of a build variable.
56function get_build_var()
57{
58 T=$(gettop)
59 if [ ! "$T" ]; then
60 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
61 return
62 fi
Andrew Boie6905e212013-12-19 13:21:46 -080063 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070064 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080065}
66
67# check to see if the supplied product is one we can build
68function check_product()
69{
70 T=$(gettop)
71 if [ ! "$T" ]; then
72 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
73 return
74 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -070075 TARGET_PRODUCT=$1 \
76 TARGET_BUILD_VARIANT= \
77 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070078 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080079 get_build_var TARGET_DEVICE > /dev/null
80 # hide successful answers, but allow the errors to show
81}
82
83VARIANT_CHOICES=(user userdebug eng)
84
85# check to see if the supplied variant is valid
86function check_variant()
87{
88 for v in ${VARIANT_CHOICES[@]}
89 do
90 if [ "$v" = "$1" ]
91 then
92 return 0
93 fi
94 done
95 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070096}
97
98function setpaths()
99{
100 T=$(gettop)
101 if [ ! "$T" ]; then
102 echo "Couldn't locate the top of the tree. Try setting TOP."
103 return
104 fi
105
106 ##################################################################
107 # #
108 # Read me before you modify this code #
109 # #
110 # This function sets ANDROID_BUILD_PATHS to what it is adding #
111 # to PATH, and the next time it is run, it removes that from #
112 # PATH. This is required so lunch can be run more than once #
113 # and still have working paths. #
114 # #
115 ##################################################################
116
Raphael Mollc639c782011-06-20 17:25:01 -0700117 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
118 # due to "C:\Program Files" being in the path.
119
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700120 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700121 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700122 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
123 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700124 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700125 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800126 # strip leading ':', if any
127 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500128 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700129
130 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700131 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700132 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700133
Ben Cheng8bc4c432012-11-16 13:29:13 -0800134 # defined in core/config.mk
135 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700136 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800137 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800138
Raphael Mollc639c782011-06-20 17:25:01 -0700139 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800140 export ANDROID_TOOLCHAIN=
141 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200142 local ARCH=$(get_build_var TARGET_ARCH)
143 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400144 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700145 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400146 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
147 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800148 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200149 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800150 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700151 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700152 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700153 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000154 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200155 *)
156 echo "Can't find toolchain for unknown architecture: $ARCH"
157 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700158 ;;
159 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700160 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800161 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700162 fi
Raphael732936d2011-06-22 14:35:32 -0700163
Ben Chengfba67bf2014-02-25 10:27:07 -0800164 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
165 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
166 fi
167
168 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700169 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700170 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800171 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800172 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700173 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100174 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
175 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700176 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700177 ;;
178 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700179 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700180 ;;
181 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700182
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700183 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700184 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 +0200185
186 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
187 # to ensure that the corresponding 'emulator' binaries are used.
188 case $(uname -s) in
189 Darwin)
190 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
191 ;;
192 Linux)
193 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
194 ;;
195 *)
196 ANDROID_EMULATOR_PREBUILTS=
197 ;;
198 esac
199 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700200 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200201 export ANDROID_EMULATOR_PREBUILTS
202 fi
203
Ying Wangaa1c9b52012-11-26 20:51:59 -0800204 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800205
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500206 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900207 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500208 if [ -n "$JAVA_HOME" ]; then
209 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900210 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
211 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500212 fi
213
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800214 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700215 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
216 export OUT=$ANDROID_PRODUCT_OUT
217
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700218 unset ANDROID_HOST_OUT
219 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
220
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800221 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700222 # TODO: fix the path
223 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
224}
225
226function printconfig()
227{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800228 T=$(gettop)
229 if [ ! "$T" ]; then
230 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
231 return
232 fi
233 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700234}
235
236function set_stuff_for_environment()
237{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800238 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500239 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800240 setpaths
241 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700242
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800243 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700244 # With this environment variable new GCC can apply colors to warnings/errors
245 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 -0700246 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700247}
248
249function set_sequence_number()
250{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700251 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700252}
253
254function settitle()
255{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800256 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700257 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700258 local product=$TARGET_PRODUCT
259 local variant=$TARGET_BUILD_VARIANT
260 local apps=$TARGET_BUILD_APPS
261 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700262 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700263 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700264 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700265 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800266 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700267}
268
Kenny Root52aa81c2011-07-15 11:07:06 -0700269function addcompletions()
270{
271 local T dir f
272
273 # Keep us from trying to run in something that isn't bash.
274 if [ -z "${BASH_VERSION}" ]; then
275 return
276 fi
277
278 # Keep us from trying to run in bash that's too old.
279 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
280 return
281 fi
282
283 dir="sdk/bash_completion"
284 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700285 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700286 echo "including $f"
287 . $f
288 done
289 fi
290}
291
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700292function choosetype()
293{
294 echo "Build type choices are:"
295 echo " 1. release"
296 echo " 2. debug"
297 echo
298
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800299 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700300 DEFAULT_NUM=1
301 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700302
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303 export TARGET_BUILD_TYPE=
304 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700305 while [ -z $TARGET_BUILD_TYPE ]
306 do
307 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800308 if [ -z "$1" ] ; then
309 read ANSWER
310 else
311 echo $1
312 ANSWER=$1
313 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700314 case $ANSWER in
315 "")
316 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
317 ;;
318 1)
319 export TARGET_BUILD_TYPE=release
320 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800321 release)
322 export TARGET_BUILD_TYPE=release
323 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700324 2)
325 export TARGET_BUILD_TYPE=debug
326 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800327 debug)
328 export TARGET_BUILD_TYPE=debug
329 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700330 *)
331 echo
332 echo "I didn't understand your response. Please try again."
333 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700334 ;;
335 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336 if [ -n "$1" ] ; then
337 break
338 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339 done
340
341 set_stuff_for_environment
342}
343
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800344#
345# This function isn't really right: It chooses a TARGET_PRODUCT
346# based on the list of boards. Usually, that gets you something
347# that kinda works with a generic product, but really, you should
348# pick a product by name.
349#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700350function chooseproduct()
351{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700352 if [ "x$TARGET_PRODUCT" != x ] ; then
353 default_value=$TARGET_PRODUCT
354 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700355 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700356 fi
357
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800358 export TARGET_PRODUCT=
359 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700360 while [ -z "$TARGET_PRODUCT" ]
361 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700362 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800363 if [ -z "$1" ] ; then
364 read ANSWER
365 else
366 echo $1
367 ANSWER=$1
368 fi
369
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700370 if [ -z "$ANSWER" ] ; then
371 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800372 else
373 if check_product $ANSWER
374 then
375 export TARGET_PRODUCT=$ANSWER
376 else
377 echo "** Not a valid product: $ANSWER"
378 fi
379 fi
380 if [ -n "$1" ] ; then
381 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700382 fi
383 done
384
385 set_stuff_for_environment
386}
387
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800388function choosevariant()
389{
390 echo "Variant choices are:"
391 local index=1
392 local v
393 for v in ${VARIANT_CHOICES[@]}
394 do
395 # The product name is the name of the directory containing
396 # the makefile we found, above.
397 echo " $index. $v"
398 index=$(($index+1))
399 done
400
401 local default_value=eng
402 local ANSWER
403
404 export TARGET_BUILD_VARIANT=
405 while [ -z "$TARGET_BUILD_VARIANT" ]
406 do
407 echo -n "Which would you like? [$default_value] "
408 if [ -z "$1" ] ; then
409 read ANSWER
410 else
411 echo $1
412 ANSWER=$1
413 fi
414
415 if [ -z "$ANSWER" ] ; then
416 export TARGET_BUILD_VARIANT=$default_value
417 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
418 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800419 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800420 fi
421 else
422 if check_variant $ANSWER
423 then
424 export TARGET_BUILD_VARIANT=$ANSWER
425 else
426 echo "** Not a valid variant: $ANSWER"
427 fi
428 fi
429 if [ -n "$1" ] ; then
430 break
431 fi
432 done
433}
434
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700435function choosecombo()
436{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700437 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700438
439 echo
440 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700441 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700442
443 echo
444 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700445 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800446
447 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700448 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800449 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700450}
451
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800452# Clear this variable. It will be built up again when the vendorsetup.sh
453# files are included at the end of this file.
454unset LUNCH_MENU_CHOICES
455function add_lunch_combo()
456{
457 local new_combo=$1
458 local c
459 for c in ${LUNCH_MENU_CHOICES[@]} ; do
460 if [ "$new_combo" = "$c" ] ; then
461 return
462 fi
463 done
464 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
465}
466
467# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700468add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800469add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000470add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800471add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000472add_lunch_combo aosp_x86-eng
473add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800474
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475function print_lunch_menu()
476{
477 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478 echo
479 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700480 echo
481 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482
483 local i=1
484 local choice
485 for choice in ${LUNCH_MENU_CHOICES[@]}
486 do
487 echo " $i. $choice"
488 i=$(($i+1))
489 done
490
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700491 echo
492}
493
494function lunch()
495{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800496 local answer
497
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700498 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700500 else
501 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700502 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800503 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700504 fi
505
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506 local selection=
507
508 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700509 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700510 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
512 then
513 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
514 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800515 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800516 fi
517 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
518 then
519 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700520 fi
521
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522 if [ -z "$selection" ]
523 then
524 echo
525 echo "Invalid lunch combo: $answer"
526 return 1
527 fi
528
Joe Onoratoda12daf2010-06-09 18:18:31 -0700529 export TARGET_BUILD_APPS=
530
Jeff Browne33ba4c2011-07-11 22:11:46 -0700531 local product=$(echo -n $selection | sed -e "s/-.*$//")
532 check_product $product
533 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800534 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700535 echo
536 echo "** Don't have a product spec for: '$product'"
537 echo "** Do you have the right repo manifest?"
538 product=
539 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800540
Jeff Browne33ba4c2011-07-11 22:11:46 -0700541 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
542 check_variant $variant
543 if [ $? -ne 0 ]
544 then
545 echo
546 echo "** Invalid variant: '$variant'"
547 echo "** Must be one of ${VARIANT_CHOICES[@]}"
548 variant=
549 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800550
Jeff Browne33ba4c2011-07-11 22:11:46 -0700551 if [ -z "$product" -o -z "$variant" ]
552 then
553 echo
554 return 1
555 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800556
Jeff Browne33ba4c2011-07-11 22:11:46 -0700557 export TARGET_PRODUCT=$product
558 export TARGET_BUILD_VARIANT=$variant
559 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700560
561 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800562
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700563 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800564 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700565}
566
Jeff Davidson513d7a42010-08-02 10:00:44 -0700567# Tab completion for lunch.
568function _lunch()
569{
570 local cur prev opts
571 COMPREPLY=()
572 cur="${COMP_WORDS[COMP_CWORD]}"
573 prev="${COMP_WORDS[COMP_CWORD-1]}"
574
575 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
576 return 0
577}
578complete -F _lunch lunch
579
Joe Onoratoda12daf2010-06-09 18:18:31 -0700580# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700581# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700582function tapas()
583{
Ying Wangb541ab62014-05-29 17:57:40 -0700584 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 -0700585 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700586 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
587 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 -0700588
Ying Wang67f02922012-08-22 10:25:20 -0700589 if [ $(echo $arch | wc -w) -gt 1 ]; then
590 echo "tapas: Error: Multiple build archs supplied: $arch"
591 return
592 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700593 if [ $(echo $variant | wc -w) -gt 1 ]; then
594 echo "tapas: Error: Multiple build variants supplied: $variant"
595 return
596 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700597 if [ $(echo $density | wc -w) -gt 1 ]; then
598 echo "tapas: Error: Multiple densities supplied: $density"
599 return
600 fi
Ying Wang67f02922012-08-22 10:25:20 -0700601
602 local product=full
603 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700604 x86) product=full_x86;;
605 mips) product=full_mips;;
606 armv5) product=generic_armv5;;
607 arm64) product=aosp_arm64;;
608 x86_64) product=aosp_x86_64;;
609 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700610 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700611 if [ -z "$variant" ]; then
612 variant=eng
613 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700614 if [ -z "$apps" ]; then
615 apps=all
616 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600617 if [ -z "$density" ]; then
618 density=alldpi
619 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700620
Ying Wang67f02922012-08-22 10:25:20 -0700621 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700622 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700623 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700624 export TARGET_BUILD_TYPE=release
625 export TARGET_BUILD_APPS=$apps
626
627 set_stuff_for_environment
628 printconfig
629}
630
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700631function gettop
632{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800633 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700634 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700635 # The following circumlocution ensures we remove symlinks from TOP.
636 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700637 else
638 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800639 # The following circumlocution (repeated below as well) ensures
640 # that we record the true directory name and not one that is
641 # faked up with symlink names.
642 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700643 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800644 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700645 T=
646 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800647 \cd ..
synergyb112a402013-07-05 19:47:47 -0700648 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649 done
Ying Wang9cd17642012-12-13 10:52:07 -0800650 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651 if [ -f "$T/$TOPFILE" ]; then
652 echo $T
653 fi
654 fi
655 fi
656}
657
Andrew Hsieh906cb782013-09-10 17:37:14 +0800658# Return driver for "make", if any (eg. static analyzer)
659function getdriver()
660{
661 local T="$1"
662 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
663 if [ -n "$WITH_STATIC_ANALYZER" ]; then
664 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800665$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
666--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800667--status-bugs \
668--top=$T"
669 fi
670}
671
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672function m()
673{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800674 local T=$(gettop)
675 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700676 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800677 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700678 else
679 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700680 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700681 fi
682}
683
684function findmakefile()
685{
686 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800687 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700688 T=
689 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700690 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700691 if [ -f "$T/Android.mk" ]; then
692 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800693 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700694 return
695 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800696 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700697 done
Ying Wang9cd17642012-12-13 10:52:07 -0800698 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700699}
700
701function mm()
702{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800703 local T=$(gettop)
704 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700705 # If we're sitting in the root of the build tree, just do a
706 # normal make.
707 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800708 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700709 else
710 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800711 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700712 local MODULES=
713 local GET_INSTALL_PATH=
714 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700715 # Remove the path to top as the makefilepath needs to be relative
716 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700717 if [ ! "$T" ]; then
718 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700719 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700720 elif [ ! "$M" ]; then
721 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700722 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700723 else
Ying Wanga7deb082013-08-16 13:24:47 -0700724 for ARG in $@; do
725 case $ARG in
726 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
727 esac
728 done
729 if [ -n "$GET_INSTALL_PATH" ]; then
730 MODULES=
731 ARGS=GET-INSTALL-PATH
732 else
733 MODULES=all_modules
734 ARGS=$@
735 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700736 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 -0700737 fi
738 fi
739}
740
741function mmm()
742{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800743 local T=$(gettop)
744 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700745 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800746 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800747 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800748 local ARGS=
749 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700750 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800751 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
752 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
753 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800754 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
755 if [ "$MODULES" = "" ]; then
756 MODULES=all_modules
757 fi
758 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700759 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700760 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
761 local TO_CHOP=`expr $TO_CHOP + 1`
762 local START=`PWD= /bin/pwd`
763 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700764 if [ "$MFILE" = "" ] ; then
765 MFILE=$DIR/Android.mk
766 else
767 MFILE=$MFILE/$DIR/Android.mk
768 fi
769 MAKEFILE="$MAKEFILE $MFILE"
770 else
Ying Wanga7deb082013-08-16 13:24:47 -0700771 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100772 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700773 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
774 *) echo "No Android.mk in $DIR."; return 1;;
775 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700776 fi
777 done
Ying Wanga7deb082013-08-16 13:24:47 -0700778 if [ -n "$GET_INSTALL_PATH" ]; then
779 ARGS=$GET_INSTALL_PATH
780 MODULES=
781 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800782 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 -0700783 else
784 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700785 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700786 fi
787}
788
Ying Wangb607f7b2013-02-08 18:01:04 -0800789function mma()
790{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800791 local T=$(gettop)
792 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800793 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800794 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800795 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800796 if [ ! "$T" ]; then
797 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700798 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800799 fi
800 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800801 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800802 fi
803}
804
805function mmma()
806{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800807 local T=$(gettop)
808 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800809 if [ "$T" ]; then
810 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
811 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
812 local MY_PWD=`PWD= /bin/pwd`
813 if [ "$MY_PWD" = "$T" ]; then
814 MY_PWD=
815 else
816 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
817 fi
818 local DIR=
819 local MODULE_PATHS=
820 local ARGS=
821 for DIR in $DIRS ; do
822 if [ -d $DIR ]; then
823 if [ "$MY_PWD" = "" ]; then
824 MODULE_PATHS="$MODULE_PATHS $DIR"
825 else
826 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
827 fi
828 else
829 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100830 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800831 *) echo "Couldn't find directory $DIR"; return 1;;
832 esac
833 fi
834 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800835 $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 -0800836 else
837 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700838 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800839 fi
840}
841
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700842function croot()
843{
844 T=$(gettop)
845 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800846 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700847 else
848 echo "Couldn't locate the top of the tree. Try setting TOP."
849 fi
850}
851
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700852function cproj()
853{
854 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700855 local HERE=$PWD
856 T=
857 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
858 T=$PWD
859 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800860 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700861 return
862 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800863 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700864 done
Ying Wang9cd17642012-12-13 10:52:07 -0800865 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700866 echo "can't find Android.mk"
867}
868
Daniel Sandler47e0a882013-07-30 13:23:52 -0400869# simplified version of ps; output in the form
870# <pid> <procname>
871function qpid() {
872 local prepend=''
873 local append=''
874 if [ "$1" = "--exact" ]; then
875 prepend=' '
876 append='$'
877 shift
878 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
879 echo "usage: qpid [[--exact] <process name|pid>"
880 return 255
881 fi
882
883 local EXE="$1"
884 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700885 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400886 else
887 adb shell ps \
888 | tr -d '\r' \
889 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
890 fi
891}
892
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700893function pid()
894{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400895 local prepend=''
896 local append=''
897 if [ "$1" = "--exact" ]; then
898 prepend=' '
899 append='$'
900 shift
901 fi
902 local EXE="$1"
903 if [ "$EXE" ] ; then
904 local PID=`adb shell ps \
905 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700906 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400907 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
908 echo "$PID"
909 else
910 echo "usage: pid [--exact] <process name>"
911 return 255
912 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700913}
914
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800915# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700916# that has the core-file-size limit set correctly
917#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800918# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700919# if its core-file-size limit is not set already.
920# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
921
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800922function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700923{
924 echo "Getting root...";
925 adb root;
926 adb wait-for-device;
927
928 echo "Remounting root parition read-write...";
929 adb shell mount -w -o remount -t rootfs rootfs;
930 sleep 1;
931 adb wait-for-device;
932 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -0800933 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700934 adb shell chmod 0777 /cores;
935
936 echo "Granting SELinux permission to dump in /cores...";
937 adb shell restorecon -R /cores;
938
939 echo "Set core pattern.";
940 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
941
942 echo "Done."
943}
944
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800945# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700946# $1 = PID of process (e.g., $(pid mediaserver))
947#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800948# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700949# dump to actually be generated.
950
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800951function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700952{
953 local PID=$1;
954 if [ -z "$PID" ]; then
955 printf "Expecting a PID!\n";
956 return;
957 fi;
958 echo "Setting core limit for $PID to infinite...";
959 adb shell prlimit $PID 4 -1 -1
960}
961
962# core - send SIGV and pull the core for process
963# $1 = PID of process (e.g., $(pid mediaserver))
964#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800965# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700966# enabled globally.
967
968function core()
969{
970 local PID=$1;
971
972 if [ -z "$PID" ]; then
973 printf "Expecting a PID!\n";
974 return;
975 fi;
976
977 local CORENAME=core.$PID;
978 local COREPATH=/cores/$CORENAME;
979 local SIG=SEGV;
980
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800981 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700982
983 local done=0;
984 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
985 printf "\tSending SIG%s to %d...\n" $SIG $PID;
986 adb shell kill -$SIG $PID;
987 sleep 1;
988 done;
989
990 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
991 echo "Done: core is under $COREPATH on device.";
992}
993
Christopher Tate744ee802009-11-12 15:33:08 -0800994# systemstack - dump the current stack trace of all threads in the system process
995# to the usual ANR traces file
996function systemstack()
997{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800998 stacks system_server
999}
1000
1001function stacks()
1002{
1003 if [[ $1 =~ ^[0-9]+$ ]] ; then
1004 local PID="$1"
1005 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001006 local PIDLIST="$(pid $1)"
1007 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1008 local PID="$PIDLIST"
1009 elif [ "$PIDLIST" ] ; then
1010 echo "more than one process: $1"
1011 else
1012 echo "no such process: $1"
1013 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001014 else
1015 echo "usage: stacks [pid|process name]"
1016 fi
1017
1018 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001019 # Determine whether the process is native
1020 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1021 # Dump stacks of Dalvik process
1022 local TRACES=/data/anr/traces.txt
1023 local ORIG=/data/anr/traces.orig
1024 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001025
Jeff Brownb12c2e52013-08-19 15:14:16 -07001026 # Keep original traces to avoid clobbering
1027 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001028
Jeff Brownb12c2e52013-08-19 15:14:16 -07001029 # Make sure we have a usable file
1030 adb shell touch $TRACES
1031 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001032
Jeff Brownb12c2e52013-08-19 15:14:16 -07001033 # Dump stacks and wait for dump to finish
1034 adb shell kill -3 $PID
1035 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001036
Jeff Brownb12c2e52013-08-19 15:14:16 -07001037 # Restore original stacks, and show current output
1038 adb shell mv $TRACES $TMP
1039 adb shell mv $ORIG $TRACES
1040 adb shell cat $TMP
1041 else
1042 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001043 local USE64BIT="$(is64bit $PID)"
1044 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001045 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001046 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001047}
1048
Michael Wrightaeed7212014-06-19 19:58:12 -07001049# Read the ELF header from /proc/$PID/exe to determine if the process is
1050# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001051function is64bit()
1052{
1053 local PID="$1"
1054 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001055 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001056 echo "64"
1057 else
1058 echo ""
1059 fi
1060 else
1061 echo ""
1062 fi
1063}
1064
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001065case `uname -s` in
1066 Darwin)
1067 function sgrep()
1068 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001069 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 -07001070 }
1071
1072 ;;
1073 *)
1074 function sgrep()
1075 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001076 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 -07001077 }
1078 ;;
1079esac
1080
Raghu Gandham8da43102012-07-25 19:57:22 -07001081function gettargetarch
1082{
1083 get_build_var TARGET_ARCH
1084}
1085
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001086function ggrep()
1087{
1088 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1089}
1090
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001091function jgrep()
1092{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001093 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 -07001094}
1095
1096function cgrep()
1097{
Dan Albert01961192014-11-22 10:16:01 -08001098 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 -07001099}
1100
1101function resgrep()
1102{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001103 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 -07001104}
1105
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001106function mangrep()
1107{
1108 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1109}
1110
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001111function sepgrep()
1112{
1113 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 "$@"
1114}
1115
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001116function rcgrep()
1117{
1118 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1119}
1120
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001121case `uname -s` in
1122 Darwin)
1123 function mgrep()
1124 {
Ying Wang324c2b22012-08-17 15:03:20 -07001125 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 -07001126 }
1127
1128 function treegrep()
1129 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001130 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 -07001131 }
1132
1133 ;;
1134 *)
1135 function mgrep()
1136 {
Ying Wang324c2b22012-08-17 15:03:20 -07001137 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 -07001138 }
1139
1140 function treegrep()
1141 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001142 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 -07001143 }
1144
1145 ;;
1146esac
1147
1148function getprebuilt
1149{
1150 get_abs_build_var ANDROID_PREBUILTS
1151}
1152
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001153function tracedmdump()
1154{
1155 T=$(gettop)
1156 if [ ! "$T" ]; then
1157 echo "Couldn't locate the top of the tree. Try setting TOP."
1158 return
1159 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001160 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001161 local arch=$(gettargetarch)
1162 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001163
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001164 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001165 if [ ! "$TRACE" ] ; then
1166 echo "usage: tracedmdump tracename"
1167 return
1168 fi
1169
Jack Veenstra60116fc2009-04-09 18:12:34 -07001170 if [ ! -r "$KERNEL" ] ; then
1171 echo "Error: cannot find kernel: '$KERNEL'"
1172 return
1173 fi
1174
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001175 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001176 if [ "$BASETRACE" = "$TRACE" ] ; then
1177 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1178 fi
1179
1180 echo "post-processing traces..."
1181 rm -f $TRACE/qtrace.dexlist
1182 post_trace $TRACE
1183 if [ $? -ne 0 ]; then
1184 echo "***"
1185 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1186 echo "***"
1187 return
1188 fi
1189 echo "generating dexlist output..."
1190 /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
1191 echo "generating dmtrace data..."
1192 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1193 echo "generating html file..."
1194 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1195 echo "done, see $TRACE/dmtrace.html for details"
1196 echo "or run:"
1197 echo " traceview $TRACE/dmtrace"
1198}
1199
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001200# communicate with a running device or emulator, set up necessary state,
1201# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001202function runhat()
1203{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001204 # process standard adb options
1205 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001206 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001207 adbTarget=$1
1208 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001209 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001210 adbTarget="$1 $2"
1211 shift 2
1212 fi
1213 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001214 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001215
1216 # runhat options
1217 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001218
1219 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001220 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001221 return
1222 fi
1223
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001224 # confirm hat is available
1225 if [ -z $(which hat) ]; then
1226 echo "hat is not available in this configuration."
1227 return
1228 fi
1229
Andy McFaddenb6289852010-07-12 08:00:19 -07001230 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001231 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001232 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001233 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001234 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001235 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236 echo -n "> "
1237 read
1238
The Android Open Source Project88b60792009-03-03 19:28:42 -08001239 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001240
The Android Open Source Project88b60792009-03-03 19:28:42 -08001241 echo "Retrieving file $devFile..."
1242 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001243
The Android Open Source Project88b60792009-03-03 19:28:42 -08001244 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001245
The Android Open Source Project88b60792009-03-03 19:28:42 -08001246 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001247 echo "View the output by pointing your browser at http://localhost:7000/"
1248 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001249 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001250}
1251
1252function getbugreports()
1253{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001254 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001255
1256 if [ ! "$reports" ]; then
1257 echo "Could not locate any bugreports."
1258 return
1259 fi
1260
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001261 local report
1262 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001263 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001264 echo "/sdcard/bugreports/${report}"
1265 adb pull /sdcard/bugreports/${report} ${report}
1266 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001267 done
1268}
1269
Victoria Lease1b296b42012-08-21 15:44:06 -07001270function getsdcardpath()
1271{
1272 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1273}
1274
1275function getscreenshotpath()
1276{
1277 echo "$(getsdcardpath)/Pictures/Screenshots"
1278}
1279
1280function getlastscreenshot()
1281{
1282 local screenshot_path=$(getscreenshotpath)
1283 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1284 if [ "$screenshot" = "" ]; then
1285 echo "No screenshots found."
1286 return
1287 fi
1288 echo "${screenshot}"
1289 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1290}
1291
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001292function startviewserver()
1293{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001294 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001295 if [ $# -gt 0 ]; then
1296 port=$1
1297 fi
1298 adb shell service call window 1 i32 $port
1299}
1300
1301function stopviewserver()
1302{
1303 adb shell service call window 2
1304}
1305
1306function isviewserverstarted()
1307{
1308 adb shell service call window 3
1309}
1310
Romain Guyb84049a2010-10-04 16:56:11 -07001311function key_home()
1312{
1313 adb shell input keyevent 3
1314}
1315
1316function key_back()
1317{
1318 adb shell input keyevent 4
1319}
1320
1321function key_menu()
1322{
1323 adb shell input keyevent 82
1324}
1325
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001326function smoketest()
1327{
1328 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1329 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1330 return
1331 fi
1332 T=$(gettop)
1333 if [ ! "$T" ]; then
1334 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1335 return
1336 fi
1337
Ying Wang9cd17642012-12-13 10:52:07 -08001338 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001339 adb uninstall com.android.smoketest > /dev/null &&
1340 adb uninstall com.android.smoketest.tests > /dev/null &&
1341 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1342 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1343 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1344}
1345
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001346# simple shortcut to the runtest command
1347function runtest()
1348{
1349 T=$(gettop)
1350 if [ ! "$T" ]; then
1351 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1352 return
1353 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001354 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001355}
1356
The Android Open Source Project88b60792009-03-03 19:28:42 -08001357function godir () {
1358 if [[ -z "$1" ]]; then
1359 echo "Usage: godir <regex>"
1360 return
1361 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001362 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001363 if [[ ! -f $T/filelist ]]; then
1364 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001365 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001366 echo " Done"
1367 echo ""
1368 fi
1369 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001370 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001371 if [[ ${#lines[@]} = 0 ]]; then
1372 echo "Not found"
1373 return
1374 fi
1375 local pathname
1376 local choice
1377 if [[ ${#lines[@]} > 1 ]]; then
1378 while [[ -z "$pathname" ]]; do
1379 local index=1
1380 local line
1381 for line in ${lines[@]}; do
1382 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001383 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001384 done
1385 echo
1386 echo -n "Select one: "
1387 unset choice
1388 read choice
1389 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1390 echo "Invalid choice"
1391 continue
1392 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001393 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001394 done
1395 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001396 pathname=${lines[0]}
1397 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001398 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001399}
1400
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001401function cmremote()
1402{
1403 git remote rm cmremote 2> /dev/null
1404 if [ ! -d .git ]
1405 then
1406 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1407 fi
1408 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1409 if [ -z "$GERRIT_REMOTE" ]
1410 then
1411 echo Unable to set up the git remote, are you in the root of the repo?
1412 return 0
1413 fi
1414 CMUSER=`git config --get review.review.cyanogenmod.com.username`
1415 if [ -z "$CMUSER" ]
1416 then
1417 git remote add cmremote ssh://review.cyanogenmod.com:29418/$GERRIT_REMOTE
1418 else
1419 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.com:29418/$GERRIT_REMOTE
1420 fi
1421 echo You can now push to "cmremote".
1422}
1423
1424function cmgerrit() {
1425 if [ $# -eq 0 ]; then
1426 $FUNCNAME help
1427 return 1
1428 fi
1429 local user=`git config --get review.review.cyanogenmod.com.username`
1430 local review=`git config --get remote.github.review`
1431 local project=`git config --get remote.github.projectname`
1432 local command=$1
1433 shift
1434 case $command in
1435 help)
1436 if [ $# -eq 0 ]; then
1437 cat <<EOF
1438Usage:
1439 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1440
1441Commands:
1442 fetch Just fetch the change as FETCH_HEAD
1443 help Show this help, or for a specific command
1444 pull Pull a change into current branch
1445 push Push HEAD or a local branch to Gerrit for a specific branch
1446
1447Any other Git commands that support refname would work as:
1448 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1449
1450See '$FUNCNAME help COMMAND' for more information on a specific command.
1451
1452Example:
1453 $FUNCNAME checkout -b topic 1234/5
1454works as:
1455 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1456 && git checkout -b topic FETCH_HEAD
1457will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1458Patch-set 1 will be fetched if omitted.
1459EOF
1460 return
1461 fi
1462 case $1 in
1463 __cmg_*) echo "For internal use only." ;;
1464 changes|for)
1465 if [ "$FUNCNAME" = "cmgerrit" ]; then
1466 echo "'$FUNCNAME $1' is deprecated."
1467 fi
1468 ;;
1469 help) $FUNCNAME help ;;
1470 fetch|pull) cat <<EOF
1471usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1472
1473works as:
1474 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1475 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1476
1477Example:
1478 $FUNCNAME $1 1234
1479will $1 patch-set 1 of change 1234
1480EOF
1481 ;;
1482 push) cat <<EOF
1483usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1484
1485works as:
1486 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1487 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1488
1489Example:
1490 $FUNCNAME push fix6789:gingerbread
1491will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1492HEAD will be pushed from local if omitted.
1493EOF
1494 ;;
1495 *)
1496 $FUNCNAME __cmg_err_not_supported $1 && return
1497 cat <<EOF
1498usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1499
1500works as:
1501 git fetch http://DOMAIN/p/PROJECT \\
1502 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1503 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1504EOF
1505 ;;
1506 esac
1507 ;;
1508 __cmg_get_ref)
1509 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1510 local change_id patchset_id hash
1511 case $1 in
1512 */*)
1513 change_id=${1%%/*}
1514 patchset_id=${1#*/}
1515 ;;
1516 *)
1517 change_id=$1
1518 patchset_id=1
1519 ;;
1520 esac
1521 hash=$(($change_id % 100))
1522 case $hash in
1523 [0-9]) hash="0$hash" ;;
1524 esac
1525 echo "refs/changes/$hash/$change_id/$patchset_id"
1526 ;;
1527 fetch|pull)
1528 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1529 $FUNCNAME __cmg_err_not_repo && return 1
1530 local change=$1
1531 shift
1532 git $command $@ http://$review/p/$project \
1533 $($FUNCNAME __cmg_get_ref $change) || return 1
1534 ;;
1535 push)
1536 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1537 $FUNCNAME __cmg_err_not_repo && return 1
1538 if [ -z "$user" ]; then
1539 echo >&2 "Gerrit username not found."
1540 return 1
1541 fi
1542 local local_branch remote_branch
1543 case $1 in
1544 *:*)
1545 local_branch=${1%:*}
1546 remote_branch=${1##*:}
1547 ;;
1548 *)
1549 local_branch=HEAD
1550 remote_branch=$1
1551 ;;
1552 esac
1553 shift
1554 git push $@ ssh://$user@$review:29418/$project \
1555 $local_branch:refs/for/$remote_branch || return 1
1556 ;;
1557 changes|for)
1558 if [ "$FUNCNAME" = "cmgerrit" ]; then
1559 echo >&2 "'$FUNCNAME $command' is deprecated."
1560 fi
1561 ;;
1562 __cmg_err_no_arg)
1563 if [ $# -lt 2 ]; then
1564 echo >&2 "'$FUNCNAME $command' missing argument."
1565 elif [ $2 -eq 0 ]; then
1566 if [ -n "$3" ]; then
1567 $FUNCNAME help $1
1568 else
1569 echo >&2 "'$FUNCNAME $1' missing argument."
1570 fi
1571 else
1572 return 1
1573 fi
1574 ;;
1575 __cmg_err_not_repo)
1576 if [ -z "$review" -o -z "$project" ]; then
1577 echo >&2 "Not currently in any reviewable repository."
1578 else
1579 return 1
1580 fi
1581 ;;
1582 __cmg_err_not_supported)
1583 $FUNCNAME __cmg_err_no_arg $command $# && return
1584 case $1 in
1585 #TODO: filter more git commands that don't use refname
1586 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1587 echo >&2 "'$FUNCNAME $1' is not supported."
1588 ;;
1589 *) return 1 ;;
1590 esac
1591 ;;
1592 #TODO: other special cases?
1593 *)
1594 $FUNCNAME __cmg_err_not_supported $command && return 1
1595 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1596 $FUNCNAME __cmg_err_not_repo && return 1
1597 local args="$@"
1598 local change pre_args refs_arg post_args
1599 case "$args" in
1600 *--\ *)
1601 pre_args=${args%%-- *}
1602 post_args="-- ${args#*-- }"
1603 ;;
1604 *) pre_args="$args" ;;
1605 esac
1606 args=($pre_args)
1607 pre_args=
1608 if [ ${#args[@]} -gt 0 ]; then
1609 change=${args[${#args[@]}-1]}
1610 fi
1611 if [ ${#args[@]} -gt 1 ]; then
1612 pre_args=${args[0]}
1613 for ((i=1; i<${#args[@]}-1; i++)); do
1614 pre_args="$pre_args ${args[$i]}"
1615 done
1616 fi
1617 while ((1)); do
1618 case $change in
1619 ""|--)
1620 $FUNCNAME help $command
1621 return 1
1622 ;;
1623 *@*)
1624 if [ -z "$refs_arg" ]; then
1625 refs_arg="@${change#*@}"
1626 change=${change%%@*}
1627 fi
1628 ;;
1629 *~*)
1630 if [ -z "$refs_arg" ]; then
1631 refs_arg="~${change#*~}"
1632 change=${change%%~*}
1633 fi
1634 ;;
1635 *^*)
1636 if [ -z "$refs_arg" ]; then
1637 refs_arg="^${change#*^}"
1638 change=${change%%^*}
1639 fi
1640 ;;
1641 *:*)
1642 if [ -z "$refs_arg" ]; then
1643 refs_arg=":${change#*:}"
1644 change=${change%%:*}
1645 fi
1646 ;;
1647 *) break ;;
1648 esac
1649 done
1650 $FUNCNAME fetch $change \
1651 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1652 || return 1
1653 ;;
1654 esac
1655}
1656
1657function cmrebase() {
1658 local repo=$1
1659 local refs=$2
1660 local pwd="$(pwd)"
1661 local dir="$(gettop)/$repo"
1662
1663 if [ -z $repo ] || [ -z $refs ]; then
1664 echo "CyanogenMod Gerrit Rebase Usage: "
1665 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1666 echo " The patch IDs appear on the Gerrit commands that are offered."
1667 echo " They consist on a series of numbers and slashes, after the text"
1668 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1669 echo ""
1670 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1671 echo ""
1672 return
1673 fi
1674
1675 if [ ! -d $dir ]; then
1676 echo "Directory $dir doesn't exist in tree."
1677 return
1678 fi
1679 cd $dir
1680 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1681 echo "Starting branch..."
1682 repo start tmprebase .
1683 echo "Bringing it up to date..."
1684 repo sync .
1685 echo "Fetching change..."
1686 git fetch "http://review.cyanogenmod.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
1687 if [ "$?" != "0" ]; then
1688 echo "Error cherry-picking. Not uploading!"
1689 return
1690 fi
1691 echo "Uploading..."
1692 repo upload .
1693 echo "Cleaning up..."
1694 repo abandon tmprebase .
1695 cd $pwd
1696}
1697
1698function mka() {
1699 case `uname -s` in
1700 Darwin)
1701 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1702 ;;
1703 *)
1704 schedtool -B -n 1 -e ionice -n 1 make -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@"
1705 ;;
1706 esac
1707}
1708
1709function reposync() {
1710 case `uname -s` in
1711 Darwin)
1712 repo sync -j 4 "$@"
1713 ;;
1714 *)
1715 schedtool -B -n 1 -e ionice -n 1 repo sync -j 4 "$@"
1716 ;;
1717 esac
1718}
1719# 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 +00001720#
1721# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1722# For some reason, installing the JDK doesn't make it show up in the
1723# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001724function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001725 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001726 # we can reset it later, depending on the version of java the build
1727 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001728 #
1729 # If we don't do this, the JAVA_HOME value set by the first call to
1730 # build/envsetup.sh will persist forever.
1731 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1732 export JAVA_HOME=""
1733 fi
1734
Andy McFaddenbd960942010-06-24 12:52:51 -07001735 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01001736 case `uname -s` in
1737 Darwin)
1738 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1739 ;;
1740 *)
1741 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1742 ;;
1743 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001744
1745 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1746 # we can change it on the next envsetup.sh, if required.
1747 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001748 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001749}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001750
Alex Rayf0d08eb2013-03-08 15:15:06 -08001751# Print colored exit condition
1752function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001753 "$@"
1754 local retval=$?
1755 if [ $retval -ne 0 ]
1756 then
1757 echo -e "\e[0;31mFAILURE\e[00m"
1758 else
1759 echo -e "\e[0;32mSUCCESS\e[00m"
1760 fi
1761 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001762}
1763
Ying Wanged21d4c2014-08-24 22:14:19 -07001764function get_make_command()
1765{
1766 echo command make
1767}
1768
Ed Heylcc6be0a2014-06-18 14:55:58 -07001769function make()
1770{
1771 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001772 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001773 local ret=$?
1774 local end_time=$(date +"%s")
1775 local tdiff=$(($end_time-$start_time))
1776 local hours=$(($tdiff / 3600 ))
1777 local mins=$((($tdiff % 3600) / 60))
1778 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001779 local ncolors=$(tput colors 2>/dev/null)
1780 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
1781 color_failed="\e[0;31m"
1782 color_success="\e[0;32m"
1783 color_reset="\e[00m"
1784 else
1785 color_failed=""
1786 color_success=""
1787 color_reset=""
1788 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001789 echo
1790 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001791 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001792 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001793 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001794 fi
1795 if [ $hours -gt 0 ] ; then
1796 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1797 elif [ $mins -gt 0 ] ; then
1798 printf "(%02g:%02g (mm:ss))" $mins $secs
1799 elif [ $secs -gt 0 ] ; then
1800 printf "(%s seconds)" $secs
1801 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001802 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001803 echo
1804 return $ret
1805}
1806
Raphael Moll70a86b02011-06-20 16:03:14 -07001807if [ "x$SHELL" != "x/bin/bash" ]; then
1808 case `ps -o command -p $$` in
1809 *bash*)
1810 ;;
1811 *)
1812 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1813 ;;
1814 esac
1815fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001816
1817# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02001818for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
1819 `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 -08001820do
1821 echo "including $f"
1822 . $f
1823done
1824unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001825
1826addcompletions