blob: 62802df6d2dff6767061be3450670f68b68ffa05 [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.
William Roberts23a298b2015-07-12 17:06:38 -070018- mgrep: Greps on all local Makefiles files.
Trevor Drake9c889762015-01-30 04:42:21 +000019- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070020- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080021- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070022
Dan Albert4ae5d4b2014-10-31 16:23:08 -070023Environemnt options:
24- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
25 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
26 build is leak-check clean.
27
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070028Look at the source to view more functions. The complete list is:
29EOF
30 T=$(gettop)
31 local A
32 A=""
Jacky Cao89483b82015-05-15 22:12:53 +080033 for i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070034 A="$A $i"
35 done
36 echo $A
37}
38
39# Get the value of a build variable as an absolute path.
40function get_abs_build_var()
41{
42 T=$(gettop)
43 if [ ! "$T" ]; then
44 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
45 return
46 fi
Ying Wang9cd17642012-12-13 10:52:07 -080047 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070048 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070049}
50
51# Get the exact value of a build variable.
52function get_build_var()
53{
54 T=$(gettop)
55 if [ ! "$T" ]; then
56 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
57 return
58 fi
Andrew Boie6905e212013-12-19 13:21:46 -080059 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070060 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080061}
62
63# check to see if the supplied product is one we can build
64function check_product()
65{
66 T=$(gettop)
67 if [ ! "$T" ]; then
68 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
69 return
70 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -070071 TARGET_PRODUCT=$1 \
72 TARGET_BUILD_VARIANT= \
73 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070074 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080075 get_build_var TARGET_DEVICE > /dev/null
76 # hide successful answers, but allow the errors to show
77}
78
79VARIANT_CHOICES=(user userdebug eng)
80
81# check to see if the supplied variant is valid
82function check_variant()
83{
84 for v in ${VARIANT_CHOICES[@]}
85 do
86 if [ "$v" = "$1" ]
87 then
88 return 0
89 fi
90 done
91 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070092}
93
94function setpaths()
95{
96 T=$(gettop)
97 if [ ! "$T" ]; then
98 echo "Couldn't locate the top of the tree. Try setting TOP."
99 return
100 fi
101
102 ##################################################################
103 # #
104 # Read me before you modify this code #
105 # #
106 # This function sets ANDROID_BUILD_PATHS to what it is adding #
107 # to PATH, and the next time it is run, it removes that from #
108 # PATH. This is required so lunch can be run more than once #
109 # and still have working paths. #
110 # #
111 ##################################################################
112
Raphael Mollc639c782011-06-20 17:25:01 -0700113 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
114 # due to "C:\Program Files" being in the path.
115
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700116 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700117 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700118 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
119 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700120 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700121 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800122 # strip leading ':', if any
123 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500124 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700125
126 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700127 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700128 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700129
Ben Cheng8bc4c432012-11-16 13:29:13 -0800130 # defined in core/config.mk
131 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700132 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800133 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800134
Raphael Mollc639c782011-06-20 17:25:01 -0700135 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800136 export ANDROID_TOOLCHAIN=
137 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200138 local ARCH=$(get_build_var TARGET_ARCH)
139 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400140 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700141 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400142 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
143 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800144 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200145 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800146 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700147 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700148 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700149 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000150 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200151 *)
152 echo "Can't find toolchain for unknown architecture: $ARCH"
153 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700154 ;;
155 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700156 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800157 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700158 fi
Raphael732936d2011-06-22 14:35:32 -0700159
Ben Chengfba67bf2014-02-25 10:27:07 -0800160 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
161 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
162 fi
163
164 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700165 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700166 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800167 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800168 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700169 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100170 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
171 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700172 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700173 ;;
174 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700175 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700176 ;;
177 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700178
Jeff Vander Stoep5f50f052015-06-12 09:56:39 -0700179 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700180 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 +0200181
182 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
183 # to ensure that the corresponding 'emulator' binaries are used.
184 case $(uname -s) in
185 Darwin)
186 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
187 ;;
188 Linux)
189 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
190 ;;
191 *)
192 ANDROID_EMULATOR_PREBUILTS=
193 ;;
194 esac
195 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700196 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200197 export ANDROID_EMULATOR_PREBUILTS
198 fi
199
Ying Wangaa1c9b52012-11-26 20:51:59 -0800200 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800201
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500202 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900203 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500204 if [ -n "$JAVA_HOME" ]; then
205 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900206 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
207 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500208 fi
209
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800210 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700211 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
212 export OUT=$ANDROID_PRODUCT_OUT
213
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700214 unset ANDROID_HOST_OUT
215 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
216
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800217 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700218 # TODO: fix the path
219 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
220}
221
222function printconfig()
223{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800224 T=$(gettop)
225 if [ ! "$T" ]; then
226 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
227 return
228 fi
229 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700230}
231
232function set_stuff_for_environment()
233{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800234 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500235 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800236 setpaths
237 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700238
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800239 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700240 # With this environment variable new GCC can apply colors to warnings/errors
241 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 -0700242 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700243}
244
245function set_sequence_number()
246{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700247 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700248}
249
250function settitle()
251{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800252 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700253 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700254 local product=$TARGET_PRODUCT
255 local variant=$TARGET_BUILD_VARIANT
256 local apps=$TARGET_BUILD_APPS
257 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700258 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700259 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700260 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700261 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800262 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263}
264
Kenny Root52aa81c2011-07-15 11:07:06 -0700265function addcompletions()
266{
267 local T dir f
268
269 # Keep us from trying to run in something that isn't bash.
270 if [ -z "${BASH_VERSION}" ]; then
271 return
272 fi
273
274 # Keep us from trying to run in bash that's too old.
275 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
276 return
277 fi
278
279 dir="sdk/bash_completion"
280 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700281 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700282 echo "including $f"
283 . $f
284 done
285 fi
286}
287
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700288function choosetype()
289{
290 echo "Build type choices are:"
291 echo " 1. release"
292 echo " 2. debug"
293 echo
294
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800295 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700296 DEFAULT_NUM=1
297 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700298
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800299 export TARGET_BUILD_TYPE=
300 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700301 while [ -z $TARGET_BUILD_TYPE ]
302 do
303 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800304 if [ -z "$1" ] ; then
305 read ANSWER
306 else
307 echo $1
308 ANSWER=$1
309 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700310 case $ANSWER in
311 "")
312 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
313 ;;
314 1)
315 export TARGET_BUILD_TYPE=release
316 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800317 release)
318 export TARGET_BUILD_TYPE=release
319 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700320 2)
321 export TARGET_BUILD_TYPE=debug
322 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800323 debug)
324 export TARGET_BUILD_TYPE=debug
325 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700326 *)
327 echo
328 echo "I didn't understand your response. Please try again."
329 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700330 ;;
331 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332 if [ -n "$1" ] ; then
333 break
334 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335 done
336
337 set_stuff_for_environment
338}
339
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800340#
341# This function isn't really right: It chooses a TARGET_PRODUCT
342# based on the list of boards. Usually, that gets you something
343# that kinda works with a generic product, but really, you should
344# pick a product by name.
345#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346function chooseproduct()
347{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700348 if [ "x$TARGET_PRODUCT" != x ] ; then
349 default_value=$TARGET_PRODUCT
350 else
Ying Wang0a76df52015-06-08 11:57:26 -0700351 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700352 fi
353
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800354 export TARGET_PRODUCT=
355 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700356 while [ -z "$TARGET_PRODUCT" ]
357 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700358 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800359 if [ -z "$1" ] ; then
360 read ANSWER
361 else
362 echo $1
363 ANSWER=$1
364 fi
365
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700366 if [ -z "$ANSWER" ] ; then
367 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800368 else
369 if check_product $ANSWER
370 then
371 export TARGET_PRODUCT=$ANSWER
372 else
373 echo "** Not a valid product: $ANSWER"
374 fi
375 fi
376 if [ -n "$1" ] ; then
377 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700378 fi
379 done
380
381 set_stuff_for_environment
382}
383
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800384function choosevariant()
385{
386 echo "Variant choices are:"
387 local index=1
388 local v
389 for v in ${VARIANT_CHOICES[@]}
390 do
391 # The product name is the name of the directory containing
392 # the makefile we found, above.
393 echo " $index. $v"
394 index=$(($index+1))
395 done
396
397 local default_value=eng
398 local ANSWER
399
400 export TARGET_BUILD_VARIANT=
401 while [ -z "$TARGET_BUILD_VARIANT" ]
402 do
403 echo -n "Which would you like? [$default_value] "
404 if [ -z "$1" ] ; then
405 read ANSWER
406 else
407 echo $1
408 ANSWER=$1
409 fi
410
411 if [ -z "$ANSWER" ] ; then
412 export TARGET_BUILD_VARIANT=$default_value
413 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
414 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800415 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800416 fi
417 else
418 if check_variant $ANSWER
419 then
420 export TARGET_BUILD_VARIANT=$ANSWER
421 else
422 echo "** Not a valid variant: $ANSWER"
423 fi
424 fi
425 if [ -n "$1" ] ; then
426 break
427 fi
428 done
429}
430
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700431function choosecombo()
432{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700433 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700434
435 echo
436 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700437 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700438
439 echo
440 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700441 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800442
443 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800445 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446}
447
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800448# Clear this variable. It will be built up again when the vendorsetup.sh
449# files are included at the end of this file.
450unset LUNCH_MENU_CHOICES
451function add_lunch_combo()
452{
453 local new_combo=$1
454 local c
455 for c in ${LUNCH_MENU_CHOICES[@]} ; do
456 if [ "$new_combo" = "$c" ] ; then
457 return
458 fi
459 done
460 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
461}
462
463# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700464add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800465add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000466add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800467add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000468add_lunch_combo aosp_x86-eng
469add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800470
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471function print_lunch_menu()
472{
473 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474 echo
475 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700476 echo
477 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800478
479 local i=1
480 local choice
481 for choice in ${LUNCH_MENU_CHOICES[@]}
482 do
483 echo " $i. $choice"
484 i=$(($i+1))
485 done
486
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700487 echo
488}
489
490function lunch()
491{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492 local answer
493
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700494 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800495 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700496 else
497 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700498 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700500 fi
501
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800502 local selection=
503
504 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700505 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700506 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
508 then
509 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
510 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800511 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512 fi
513 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
514 then
515 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700516 fi
517
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800518 if [ -z "$selection" ]
519 then
520 echo
521 echo "Invalid lunch combo: $answer"
522 return 1
523 fi
524
Joe Onoratoda12daf2010-06-09 18:18:31 -0700525 export TARGET_BUILD_APPS=
526
Jeff Browne33ba4c2011-07-11 22:11:46 -0700527 local product=$(echo -n $selection | sed -e "s/-.*$//")
528 check_product $product
529 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700531 echo
532 echo "** Don't have a product spec for: '$product'"
533 echo "** Do you have the right repo manifest?"
534 product=
535 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800536
Jeff Browne33ba4c2011-07-11 22:11:46 -0700537 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
538 check_variant $variant
539 if [ $? -ne 0 ]
540 then
541 echo
542 echo "** Invalid variant: '$variant'"
543 echo "** Must be one of ${VARIANT_CHOICES[@]}"
544 variant=
545 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800546
Jeff Browne33ba4c2011-07-11 22:11:46 -0700547 if [ -z "$product" -o -z "$variant" ]
548 then
549 echo
550 return 1
551 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800552
Jeff Browne33ba4c2011-07-11 22:11:46 -0700553 export TARGET_PRODUCT=$product
554 export TARGET_BUILD_VARIANT=$variant
555 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700556
557 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800558
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700559 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800560 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700561}
562
Jeff Davidson513d7a42010-08-02 10:00:44 -0700563# Tab completion for lunch.
564function _lunch()
565{
566 local cur prev opts
567 COMPREPLY=()
568 cur="${COMP_WORDS[COMP_CWORD]}"
569 prev="${COMP_WORDS[COMP_CWORD-1]}"
570
571 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
572 return 0
573}
574complete -F _lunch lunch
575
Joe Onoratoda12daf2010-06-09 18:18:31 -0700576# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700577# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700578function tapas()
579{
Ying Wangb541ab62014-05-29 17:57:40 -0700580 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 -0700581 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700582 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
583 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 -0700584
Ying Wang67f02922012-08-22 10:25:20 -0700585 if [ $(echo $arch | wc -w) -gt 1 ]; then
586 echo "tapas: Error: Multiple build archs supplied: $arch"
587 return
588 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700589 if [ $(echo $variant | wc -w) -gt 1 ]; then
590 echo "tapas: Error: Multiple build variants supplied: $variant"
591 return
592 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700593 if [ $(echo $density | wc -w) -gt 1 ]; then
594 echo "tapas: Error: Multiple densities supplied: $density"
595 return
596 fi
Ying Wang67f02922012-08-22 10:25:20 -0700597
Ying Wang0a76df52015-06-08 11:57:26 -0700598 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700599 case $arch in
Ying Wang0a76df52015-06-08 11:57:26 -0700600 x86) product=aosp_x86;;
601 mips) product=aosp_mips;;
Ying Wangb541ab62014-05-29 17:57:40 -0700602 armv5) product=generic_armv5;;
603 arm64) product=aosp_arm64;;
604 x86_64) product=aosp_x86_64;;
605 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700606 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700607 if [ -z "$variant" ]; then
608 variant=eng
609 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700610 if [ -z "$apps" ]; then
611 apps=all
612 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600613 if [ -z "$density" ]; then
614 density=alldpi
615 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700616
Ying Wang67f02922012-08-22 10:25:20 -0700617 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700618 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700619 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700620 export TARGET_BUILD_TYPE=release
621 export TARGET_BUILD_APPS=$apps
622
623 set_stuff_for_environment
624 printconfig
625}
626
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700627function gettop
628{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800629 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700630 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700631 # The following circumlocution ensures we remove symlinks from TOP.
632 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700633 else
634 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800635 # The following circumlocution (repeated below as well) ensures
636 # that we record the true directory name and not one that is
637 # faked up with symlink names.
638 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700639 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800640 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700641 T=
642 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800643 \cd ..
synergyb112a402013-07-05 19:47:47 -0700644 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700645 done
Ying Wang9cd17642012-12-13 10:52:07 -0800646 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700647 if [ -f "$T/$TOPFILE" ]; then
648 echo $T
649 fi
650 fi
651 fi
652}
653
Andrew Hsieh906cb782013-09-10 17:37:14 +0800654# Return driver for "make", if any (eg. static analyzer)
655function getdriver()
656{
657 local T="$1"
658 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
659 if [ -n "$WITH_STATIC_ANALYZER" ]; then
660 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800661$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
662--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800663--status-bugs \
664--top=$T"
665 fi
666}
667
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700668function m()
669{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800670 local T=$(gettop)
671 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800673 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700674 else
675 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700676 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700677 fi
678}
679
680function findmakefile()
681{
682 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800683 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700684 T=
685 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700686 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700687 if [ -f "$T/Android.mk" ]; then
688 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800689 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700690 return
691 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800692 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700693 done
Ying Wang9cd17642012-12-13 10:52:07 -0800694 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700695}
696
697function mm()
698{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800699 local T=$(gettop)
700 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700701 # If we're sitting in the root of the build tree, just do a
702 # normal make.
703 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800704 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700705 else
706 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800707 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700708 local MODULES=
709 local GET_INSTALL_PATH=
710 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700711 # Remove the path to top as the makefilepath needs to be relative
712 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700713 if [ ! "$T" ]; then
714 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700715 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700716 elif [ ! "$M" ]; then
717 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700718 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700719 else
Ying Wanga7deb082013-08-16 13:24:47 -0700720 for ARG in $@; do
721 case $ARG in
722 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
723 esac
724 done
725 if [ -n "$GET_INSTALL_PATH" ]; then
726 MODULES=
727 ARGS=GET-INSTALL-PATH
728 else
729 MODULES=all_modules
730 ARGS=$@
731 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700732 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 -0700733 fi
734 fi
735}
736
737function mmm()
738{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800739 local T=$(gettop)
740 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700741 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800742 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800743 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800744 local ARGS=
745 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700746 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800747 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
748 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
749 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800750 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
751 if [ "$MODULES" = "" ]; then
752 MODULES=all_modules
753 fi
754 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700755 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700756 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
757 local TO_CHOP=`expr $TO_CHOP + 1`
758 local START=`PWD= /bin/pwd`
759 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700760 if [ "$MFILE" = "" ] ; then
761 MFILE=$DIR/Android.mk
762 else
763 MFILE=$MFILE/$DIR/Android.mk
764 fi
765 MAKEFILE="$MAKEFILE $MFILE"
766 else
Ying Wanga7deb082013-08-16 13:24:47 -0700767 case $DIR in
768 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
769 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
770 *) echo "No Android.mk in $DIR."; return 1;;
771 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700772 fi
773 done
Ying Wanga7deb082013-08-16 13:24:47 -0700774 if [ -n "$GET_INSTALL_PATH" ]; then
775 ARGS=$GET_INSTALL_PATH
776 MODULES=
777 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800778 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 -0700779 else
780 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700781 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700782 fi
783}
784
Ying Wangb607f7b2013-02-08 18:01:04 -0800785function mma()
786{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800787 local T=$(gettop)
788 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800789 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800790 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800791 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800792 if [ ! "$T" ]; then
793 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700794 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800795 fi
796 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800797 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800798 fi
799}
800
801function mmma()
802{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800803 local T=$(gettop)
804 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800805 if [ "$T" ]; then
806 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
807 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
808 local MY_PWD=`PWD= /bin/pwd`
809 if [ "$MY_PWD" = "$T" ]; then
810 MY_PWD=
811 else
812 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
813 fi
814 local DIR=
815 local MODULE_PATHS=
816 local ARGS=
817 for DIR in $DIRS ; do
818 if [ -d $DIR ]; then
819 if [ "$MY_PWD" = "" ]; then
820 MODULE_PATHS="$MODULE_PATHS $DIR"
821 else
822 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
823 fi
824 else
825 case $DIR in
826 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
827 *) echo "Couldn't find directory $DIR"; return 1;;
828 esac
829 fi
830 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800831 $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 -0800832 else
833 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700834 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800835 fi
836}
837
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700838function croot()
839{
840 T=$(gettop)
841 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800842 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700843 else
844 echo "Couldn't locate the top of the tree. Try setting TOP."
845 fi
846}
847
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700848function cproj()
849{
850 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700851 local HERE=$PWD
852 T=
853 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
854 T=$PWD
855 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800856 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700857 return
858 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800859 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700860 done
Ying Wang9cd17642012-12-13 10:52:07 -0800861 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700862 echo "can't find Android.mk"
863}
864
Daniel Sandler47e0a882013-07-30 13:23:52 -0400865# simplified version of ps; output in the form
866# <pid> <procname>
867function qpid() {
868 local prepend=''
869 local append=''
870 if [ "$1" = "--exact" ]; then
871 prepend=' '
872 append='$'
873 shift
874 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
875 echo "usage: qpid [[--exact] <process name|pid>"
876 return 255
877 fi
878
879 local EXE="$1"
880 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700881 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400882 else
883 adb shell ps \
884 | tr -d '\r' \
885 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
886 fi
887}
888
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700889function pid()
890{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400891 local prepend=''
892 local append=''
893 if [ "$1" = "--exact" ]; then
894 prepend=' '
895 append='$'
896 shift
897 fi
898 local EXE="$1"
899 if [ "$EXE" ] ; then
900 local PID=`adb shell ps \
901 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700902 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400903 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
904 echo "$PID"
905 else
906 echo "usage: pid [--exact] <process name>"
907 return 255
908 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700909}
910
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800911# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700912# that has the core-file-size limit set correctly
913#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800914# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700915# if its core-file-size limit is not set already.
916# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
917
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800918function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700919{
920 echo "Getting root...";
921 adb root;
922 adb wait-for-device;
923
924 echo "Remounting root parition read-write...";
925 adb shell mount -w -o remount -t rootfs rootfs;
926 sleep 1;
927 adb wait-for-device;
928 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -0800929 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700930 adb shell chmod 0777 /cores;
931
932 echo "Granting SELinux permission to dump in /cores...";
933 adb shell restorecon -R /cores;
934
935 echo "Set core pattern.";
936 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
937
938 echo "Done."
939}
940
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800941# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700942# $1 = PID of process (e.g., $(pid mediaserver))
943#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800944# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700945# dump to actually be generated.
946
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800947function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700948{
949 local PID=$1;
950 if [ -z "$PID" ]; then
951 printf "Expecting a PID!\n";
952 return;
953 fi;
954 echo "Setting core limit for $PID to infinite...";
955 adb shell prlimit $PID 4 -1 -1
956}
957
958# core - send SIGV and pull the core for process
959# $1 = PID of process (e.g., $(pid mediaserver))
960#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800961# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700962# enabled globally.
963
964function core()
965{
966 local PID=$1;
967
968 if [ -z "$PID" ]; then
969 printf "Expecting a PID!\n";
970 return;
971 fi;
972
973 local CORENAME=core.$PID;
974 local COREPATH=/cores/$CORENAME;
975 local SIG=SEGV;
976
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800977 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700978
979 local done=0;
980 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
981 printf "\tSending SIG%s to %d...\n" $SIG $PID;
982 adb shell kill -$SIG $PID;
983 sleep 1;
984 done;
985
986 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
987 echo "Done: core is under $COREPATH on device.";
988}
989
Christopher Tate744ee802009-11-12 15:33:08 -0800990# systemstack - dump the current stack trace of all threads in the system process
991# to the usual ANR traces file
992function systemstack()
993{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800994 stacks system_server
995}
996
997function stacks()
998{
999 if [[ $1 =~ ^[0-9]+$ ]] ; then
1000 local PID="$1"
1001 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001002 local PIDLIST="$(pid $1)"
1003 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1004 local PID="$PIDLIST"
1005 elif [ "$PIDLIST" ] ; then
1006 echo "more than one process: $1"
1007 else
1008 echo "no such process: $1"
1009 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001010 else
1011 echo "usage: stacks [pid|process name]"
1012 fi
1013
1014 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001015 # Determine whether the process is native
1016 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1017 # Dump stacks of Dalvik process
1018 local TRACES=/data/anr/traces.txt
1019 local ORIG=/data/anr/traces.orig
1020 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001021
Jeff Brownb12c2e52013-08-19 15:14:16 -07001022 # Keep original traces to avoid clobbering
1023 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001024
Jeff Brownb12c2e52013-08-19 15:14:16 -07001025 # Make sure we have a usable file
1026 adb shell touch $TRACES
1027 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001028
Jeff Brownb12c2e52013-08-19 15:14:16 -07001029 # Dump stacks and wait for dump to finish
1030 adb shell kill -3 $PID
1031 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001032
Jeff Brownb12c2e52013-08-19 15:14:16 -07001033 # Restore original stacks, and show current output
1034 adb shell mv $TRACES $TMP
1035 adb shell mv $ORIG $TRACES
1036 adb shell cat $TMP
1037 else
1038 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001039 local USE64BIT="$(is64bit $PID)"
1040 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001041 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001042 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001043}
1044
Michael Wrightaeed7212014-06-19 19:58:12 -07001045# Read the ELF header from /proc/$PID/exe to determine if the process is
1046# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001047function is64bit()
1048{
1049 local PID="$1"
1050 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001051 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001052 echo "64"
1053 else
1054 echo ""
1055 fi
1056 else
1057 echo ""
1058 fi
1059}
1060
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001061case `uname -s` in
1062 Darwin)
1063 function sgrep()
1064 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001065 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 -07001066 }
1067
1068 ;;
1069 *)
1070 function sgrep()
1071 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001072 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 -07001073 }
1074 ;;
1075esac
1076
Raghu Gandham8da43102012-07-25 19:57:22 -07001077function gettargetarch
1078{
1079 get_build_var TARGET_ARCH
1080}
1081
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001082function ggrep()
1083{
1084 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1085}
1086
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001087function jgrep()
1088{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001089 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 -07001090}
1091
1092function cgrep()
1093{
Dan Albert01961192014-11-22 10:16:01 -08001094 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 -07001095}
1096
1097function resgrep()
1098{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001099 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 -07001100}
1101
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001102function mangrep()
1103{
1104 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1105}
1106
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001107function sepgrep()
1108{
1109 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 "$@"
1110}
1111
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001112case `uname -s` in
1113 Darwin)
1114 function mgrep()
1115 {
Ying Wang324c2b22012-08-17 15:03:20 -07001116 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 -07001117 }
1118
1119 function treegrep()
1120 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001121 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 -07001122 }
1123
1124 ;;
1125 *)
1126 function mgrep()
1127 {
Ying Wang324c2b22012-08-17 15:03:20 -07001128 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 -07001129 }
1130
1131 function treegrep()
1132 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001133 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 -07001134 }
1135
1136 ;;
1137esac
1138
1139function getprebuilt
1140{
1141 get_abs_build_var ANDROID_PREBUILTS
1142}
1143
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001144function tracedmdump()
1145{
1146 T=$(gettop)
1147 if [ ! "$T" ]; then
1148 echo "Couldn't locate the top of the tree. Try setting TOP."
1149 return
1150 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001151 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001152 local arch=$(gettargetarch)
1153 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001154
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001155 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001156 if [ ! "$TRACE" ] ; then
1157 echo "usage: tracedmdump tracename"
1158 return
1159 fi
1160
Jack Veenstra60116fc2009-04-09 18:12:34 -07001161 if [ ! -r "$KERNEL" ] ; then
1162 echo "Error: cannot find kernel: '$KERNEL'"
1163 return
1164 fi
1165
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001166 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001167 if [ "$BASETRACE" = "$TRACE" ] ; then
1168 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1169 fi
1170
1171 echo "post-processing traces..."
1172 rm -f $TRACE/qtrace.dexlist
1173 post_trace $TRACE
1174 if [ $? -ne 0 ]; then
1175 echo "***"
1176 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1177 echo "***"
1178 return
1179 fi
1180 echo "generating dexlist output..."
1181 /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
1182 echo "generating dmtrace data..."
1183 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1184 echo "generating html file..."
1185 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1186 echo "done, see $TRACE/dmtrace.html for details"
1187 echo "or run:"
1188 echo " traceview $TRACE/dmtrace"
1189}
1190
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001191# communicate with a running device or emulator, set up necessary state,
1192# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001193function runhat()
1194{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001195 # process standard adb options
1196 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001197 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001198 adbTarget=$1
1199 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001200 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001201 adbTarget="$1 $2"
1202 shift 2
1203 fi
1204 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001205 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001206
1207 # runhat options
1208 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001209
1210 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001211 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001212 return
1213 fi
1214
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001215 # confirm hat is available
1216 if [ -z $(which hat) ]; then
1217 echo "hat is not available in this configuration."
1218 return
1219 fi
1220
Andy McFaddenb6289852010-07-12 08:00:19 -07001221 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001222 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001223 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001224 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001225 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001226 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001227 echo -n "> "
1228 read
1229
The Android Open Source Project88b60792009-03-03 19:28:42 -08001230 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001231
The Android Open Source Project88b60792009-03-03 19:28:42 -08001232 echo "Retrieving file $devFile..."
1233 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001234
The Android Open Source Project88b60792009-03-03 19:28:42 -08001235 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236
The Android Open Source Project88b60792009-03-03 19:28:42 -08001237 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001238 echo "View the output by pointing your browser at http://localhost:7000/"
1239 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001240 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001241}
1242
1243function getbugreports()
1244{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001245 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001246
1247 if [ ! "$reports" ]; then
1248 echo "Could not locate any bugreports."
1249 return
1250 fi
1251
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001252 local report
1253 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001254 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001255 echo "/sdcard/bugreports/${report}"
1256 adb pull /sdcard/bugreports/${report} ${report}
1257 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001258 done
1259}
1260
Victoria Lease1b296b42012-08-21 15:44:06 -07001261function getsdcardpath()
1262{
1263 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1264}
1265
1266function getscreenshotpath()
1267{
1268 echo "$(getsdcardpath)/Pictures/Screenshots"
1269}
1270
1271function getlastscreenshot()
1272{
1273 local screenshot_path=$(getscreenshotpath)
1274 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1275 if [ "$screenshot" = "" ]; then
1276 echo "No screenshots found."
1277 return
1278 fi
1279 echo "${screenshot}"
1280 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1281}
1282
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001283function startviewserver()
1284{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001285 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001286 if [ $# -gt 0 ]; then
1287 port=$1
1288 fi
1289 adb shell service call window 1 i32 $port
1290}
1291
1292function stopviewserver()
1293{
1294 adb shell service call window 2
1295}
1296
1297function isviewserverstarted()
1298{
1299 adb shell service call window 3
1300}
1301
Romain Guyb84049a2010-10-04 16:56:11 -07001302function key_home()
1303{
1304 adb shell input keyevent 3
1305}
1306
1307function key_back()
1308{
1309 adb shell input keyevent 4
1310}
1311
1312function key_menu()
1313{
1314 adb shell input keyevent 82
1315}
1316
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001317function smoketest()
1318{
1319 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1320 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1321 return
1322 fi
1323 T=$(gettop)
1324 if [ ! "$T" ]; then
1325 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1326 return
1327 fi
1328
Ying Wang9cd17642012-12-13 10:52:07 -08001329 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001330 adb uninstall com.android.smoketest > /dev/null &&
1331 adb uninstall com.android.smoketest.tests > /dev/null &&
1332 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1333 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1334 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1335}
1336
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001337# simple shortcut to the runtest command
1338function runtest()
1339{
1340 T=$(gettop)
1341 if [ ! "$T" ]; then
1342 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1343 return
1344 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001345 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001346}
1347
The Android Open Source Project88b60792009-03-03 19:28:42 -08001348function godir () {
1349 if [[ -z "$1" ]]; then
1350 echo "Usage: godir <regex>"
1351 return
1352 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001353 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001354 if [[ ! -f $T/filelist ]]; then
1355 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001356 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001357 echo " Done"
1358 echo ""
1359 fi
1360 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001361 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001362 if [[ ${#lines[@]} = 0 ]]; then
1363 echo "Not found"
1364 return
1365 fi
1366 local pathname
1367 local choice
1368 if [[ ${#lines[@]} > 1 ]]; then
1369 while [[ -z "$pathname" ]]; do
1370 local index=1
1371 local line
1372 for line in ${lines[@]}; do
1373 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001374 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001375 done
1376 echo
1377 echo -n "Select one: "
1378 unset choice
1379 read choice
1380 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1381 echo "Invalid choice"
1382 continue
1383 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001384 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001385 done
1386 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001387 pathname=${lines[0]}
1388 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001389 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001390}
1391
Neil Fuller46e00ea2014-10-16 10:23:03 +01001392# Force JAVA_HOME to point to java 1.7 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001393#
1394# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1395# For some reason, installing the JDK doesn't make it show up in the
1396# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001397function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001398 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001399 # we can reset it later, depending on the version of java the build
1400 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001401 #
1402 # If we don't do this, the JAVA_HOME value set by the first call to
1403 # build/envsetup.sh will persist forever.
1404 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1405 export JAVA_HOME=""
1406 fi
1407
Andy McFaddenbd960942010-06-24 12:52:51 -07001408 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01001409 case `uname -s` in
1410 Darwin)
1411 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1412 ;;
1413 *)
1414 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1415 ;;
1416 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001417
1418 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1419 # we can change it on the next envsetup.sh, if required.
1420 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001421 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001422}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001423
Alex Rayf0d08eb2013-03-08 15:15:06 -08001424# Print colored exit condition
1425function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001426 "$@"
1427 local retval=$?
1428 if [ $retval -ne 0 ]
1429 then
Jacky Cao89483b82015-05-15 22:12:53 +08001430 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001431 else
Jacky Cao89483b82015-05-15 22:12:53 +08001432 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001433 fi
1434 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001435}
1436
Ying Wanged21d4c2014-08-24 22:14:19 -07001437function get_make_command()
1438{
1439 echo command make
1440}
1441
Ed Heylcc6be0a2014-06-18 14:55:58 -07001442function make()
1443{
1444 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001445 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001446 local ret=$?
1447 local end_time=$(date +"%s")
1448 local tdiff=$(($end_time-$start_time))
1449 local hours=$(($tdiff / 3600 ))
1450 local mins=$((($tdiff % 3600) / 60))
1451 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001452 local ncolors=$(tput colors 2>/dev/null)
1453 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001454 color_failed=$'\E'"[0;31m"
1455 color_success=$'\E'"[0;32m"
1456 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001457 else
1458 color_failed=""
1459 color_success=""
1460 color_reset=""
1461 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001462 echo
1463 if [ $ret -eq 0 ] ; then
Jacky Cao89483b82015-05-15 22:12:53 +08001464 echo -n "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001465 else
Jacky Cao89483b82015-05-15 22:12:53 +08001466 echo -n "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001467 fi
1468 if [ $hours -gt 0 ] ; then
1469 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1470 elif [ $mins -gt 0 ] ; then
1471 printf "(%02g:%02g (mm:ss))" $mins $secs
1472 elif [ $secs -gt 0 ] ; then
1473 printf "(%s seconds)" $secs
1474 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001475 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001476 echo
1477 return $ret
1478}
1479
Raphael Moll70a86b02011-06-20 16:03:14 -07001480if [ "x$SHELL" != "x/bin/bash" ]; then
1481 case `ps -o command -p $$` in
1482 *bash*)
1483 ;;
1484 *)
1485 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1486 ;;
1487 esac
1488fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001489
1490# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02001491for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
1492 `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 -08001493do
1494 echo "including $f"
1495 . $f
1496done
1497unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001498
1499addcompletions