blob: 9689cce7c817fc0e52ece348e07d27bca59f33ce [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 Wangf05c4f72013-01-31 11:16:57 -08005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [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.
14- jgrep: Greps on all local Java files.
15- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080016- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070017
18Look at the source to view more functions. The complete list is:
19EOF
20 T=$(gettop)
21 local A
22 A=""
23 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
24 A="$A $i"
25 done
26 echo $A
27}
28
29# Get the value of a build variable as an absolute path.
30function get_abs_build_var()
31{
32 T=$(gettop)
33 if [ ! "$T" ]; then
34 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
35 return
36 fi
Ying Wang9cd17642012-12-13 10:52:07 -080037 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Andrew Boie6905e212013-12-19 13:21:46 -080038 make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070039}
40
41# Get the exact value of a build variable.
42function get_build_var()
43{
44 T=$(gettop)
45 if [ ! "$T" ]; then
46 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
47 return
48 fi
Andrew Boie6905e212013-12-19 13:21:46 -080049 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
50 make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080051}
52
53# check to see if the supplied product is one we can build
54function check_product()
55{
56 T=$(gettop)
57 if [ ! "$T" ]; then
58 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
59 return
60 fi
61 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Jeff Browne33ba4c2011-07-11 22:11:46 -070062 TARGET_PRODUCT=$1 \
63 TARGET_BUILD_VARIANT= \
64 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070065 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080066 get_build_var TARGET_DEVICE > /dev/null
67 # hide successful answers, but allow the errors to show
68}
69
70VARIANT_CHOICES=(user userdebug eng)
71
72# check to see if the supplied variant is valid
73function check_variant()
74{
75 for v in ${VARIANT_CHOICES[@]}
76 do
77 if [ "$v" = "$1" ]
78 then
79 return 0
80 fi
81 done
82 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070083}
84
85function setpaths()
86{
87 T=$(gettop)
88 if [ ! "$T" ]; then
89 echo "Couldn't locate the top of the tree. Try setting TOP."
90 return
91 fi
92
93 ##################################################################
94 # #
95 # Read me before you modify this code #
96 # #
97 # This function sets ANDROID_BUILD_PATHS to what it is adding #
98 # to PATH, and the next time it is run, it removes that from #
99 # PATH. This is required so lunch can be run more than once #
100 # and still have working paths. #
101 # #
102 ##################################################################
103
Raphael Mollc639c782011-06-20 17:25:01 -0700104 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
105 # due to "C:\Program Files" being in the path.
106
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700107 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700108 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700109 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
110 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700111 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700112 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800113 # strip leading ':', if any
114 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500115 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700116
117 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700118 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700119 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700120
Ben Cheng8bc4c432012-11-16 13:29:13 -0800121 # defined in core/config.mk
122 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700123 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800124 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800125
Raphael Mollc639c782011-06-20 17:25:01 -0700126 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800127 export ANDROID_TOOLCHAIN=
128 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200129 local ARCH=$(get_build_var TARGET_ARCH)
130 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400131 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700132 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400133 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
134 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800135 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200136 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800137 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700138 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700139 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800140 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700141 ;;
Chris Dearman1efd9e42014-02-03 15:01:24 -0800142 mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000143 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200144 *)
145 echo "Can't find toolchain for unknown architecture: $ARCH"
146 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700147 ;;
148 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700149 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800150 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700151 fi
Raphael732936d2011-06-22 14:35:32 -0700152
Ben Chengfba67bf2014-02-25 10:27:07 -0800153 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
154 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
155 fi
156
157 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700158 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700159 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800160 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800161 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700162 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100163 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
164 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700165 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700166 ;;
167 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700168 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700169 ;;
170 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700171
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700172 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700173 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Colin Cross6a5fa062014-05-22 11:58:40 -0700174 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200175
176 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
177 # to ensure that the corresponding 'emulator' binaries are used.
178 case $(uname -s) in
179 Darwin)
180 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
181 ;;
182 Linux)
183 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
184 ;;
185 *)
186 ANDROID_EMULATOR_PREBUILTS=
187 ;;
188 esac
189 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700190 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200191 export ANDROID_EMULATOR_PREBUILTS
192 fi
193
Ying Wangaa1c9b52012-11-26 20:51:59 -0800194 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800195
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500196 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900197 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500198 if [ -n "$JAVA_HOME" ]; then
199 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900200 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
201 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500202 fi
203
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800204 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700205 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
206 export OUT=$ANDROID_PRODUCT_OUT
207
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700208 unset ANDROID_HOST_OUT
209 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
210
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800211 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700212 # TODO: fix the path
213 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
214}
215
216function printconfig()
217{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800218 T=$(gettop)
219 if [ ! "$T" ]; then
220 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
221 return
222 fi
223 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700224}
225
226function set_stuff_for_environment()
227{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800228 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500229 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800230 setpaths
231 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700232
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800233 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700234 # With this environment variable new GCC can apply colors to warnings/errors
235 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700236}
237
238function set_sequence_number()
239{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700240 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700241}
242
243function settitle()
244{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800245 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700246 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700247 local product=$TARGET_PRODUCT
248 local variant=$TARGET_BUILD_VARIANT
249 local apps=$TARGET_BUILD_APPS
250 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700251 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700252 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700253 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700254 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800255 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700256}
257
Kenny Root52aa81c2011-07-15 11:07:06 -0700258function addcompletions()
259{
260 local T dir f
261
262 # Keep us from trying to run in something that isn't bash.
263 if [ -z "${BASH_VERSION}" ]; then
264 return
265 fi
266
267 # Keep us from trying to run in bash that's too old.
268 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
269 return
270 fi
271
272 dir="sdk/bash_completion"
273 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700274 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700275 echo "including $f"
276 . $f
277 done
278 fi
279}
280
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700281function choosetype()
282{
283 echo "Build type choices are:"
284 echo " 1. release"
285 echo " 2. debug"
286 echo
287
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800288 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700289 DEFAULT_NUM=1
290 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700291
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800292 export TARGET_BUILD_TYPE=
293 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700294 while [ -z $TARGET_BUILD_TYPE ]
295 do
296 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800297 if [ -z "$1" ] ; then
298 read ANSWER
299 else
300 echo $1
301 ANSWER=$1
302 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700303 case $ANSWER in
304 "")
305 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
306 ;;
307 1)
308 export TARGET_BUILD_TYPE=release
309 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800310 release)
311 export TARGET_BUILD_TYPE=release
312 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700313 2)
314 export TARGET_BUILD_TYPE=debug
315 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 debug)
317 export TARGET_BUILD_TYPE=debug
318 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319 *)
320 echo
321 echo "I didn't understand your response. Please try again."
322 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700323 ;;
324 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800325 if [ -n "$1" ] ; then
326 break
327 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700328 done
329
330 set_stuff_for_environment
331}
332
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800333#
334# This function isn't really right: It chooses a TARGET_PRODUCT
335# based on the list of boards. Usually, that gets you something
336# that kinda works with a generic product, but really, you should
337# pick a product by name.
338#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339function chooseproduct()
340{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700341 if [ "x$TARGET_PRODUCT" != x ] ; then
342 default_value=$TARGET_PRODUCT
343 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700344 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700345 fi
346
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800347 export TARGET_PRODUCT=
348 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700349 while [ -z "$TARGET_PRODUCT" ]
350 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700351 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800352 if [ -z "$1" ] ; then
353 read ANSWER
354 else
355 echo $1
356 ANSWER=$1
357 fi
358
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700359 if [ -z "$ANSWER" ] ; then
360 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800361 else
362 if check_product $ANSWER
363 then
364 export TARGET_PRODUCT=$ANSWER
365 else
366 echo "** Not a valid product: $ANSWER"
367 fi
368 fi
369 if [ -n "$1" ] ; then
370 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700371 fi
372 done
373
374 set_stuff_for_environment
375}
376
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800377function choosevariant()
378{
379 echo "Variant choices are:"
380 local index=1
381 local v
382 for v in ${VARIANT_CHOICES[@]}
383 do
384 # The product name is the name of the directory containing
385 # the makefile we found, above.
386 echo " $index. $v"
387 index=$(($index+1))
388 done
389
390 local default_value=eng
391 local ANSWER
392
393 export TARGET_BUILD_VARIANT=
394 while [ -z "$TARGET_BUILD_VARIANT" ]
395 do
396 echo -n "Which would you like? [$default_value] "
397 if [ -z "$1" ] ; then
398 read ANSWER
399 else
400 echo $1
401 ANSWER=$1
402 fi
403
404 if [ -z "$ANSWER" ] ; then
405 export TARGET_BUILD_VARIANT=$default_value
406 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
407 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800408 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800409 fi
410 else
411 if check_variant $ANSWER
412 then
413 export TARGET_BUILD_VARIANT=$ANSWER
414 else
415 echo "** Not a valid variant: $ANSWER"
416 fi
417 fi
418 if [ -n "$1" ] ; then
419 break
420 fi
421 done
422}
423
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700424function choosecombo()
425{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700426 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700427
428 echo
429 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700430 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700431
432 echo
433 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700434 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800435
436 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700437 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800438 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700439}
440
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800441# Clear this variable. It will be built up again when the vendorsetup.sh
442# files are included at the end of this file.
443unset LUNCH_MENU_CHOICES
444function add_lunch_combo()
445{
446 local new_combo=$1
447 local c
448 for c in ${LUNCH_MENU_CHOICES[@]} ; do
449 if [ "$new_combo" = "$c" ] ; then
450 return
451 fi
452 done
453 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
454}
455
456# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700457add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800458add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000459add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800460add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000461add_lunch_combo aosp_x86-eng
462add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800463add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800464
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465function print_lunch_menu()
466{
467 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468 echo
469 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470 echo
471 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472
473 local i=1
474 local choice
475 for choice in ${LUNCH_MENU_CHOICES[@]}
476 do
477 echo " $i. $choice"
478 i=$(($i+1))
479 done
480
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700481 echo
482}
483
484function lunch()
485{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486 local answer
487
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700488 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800489 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700490 else
491 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700492 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800493 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700494 fi
495
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800496 local selection=
497
498 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700499 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700500 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800501 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
502 then
503 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
504 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800505 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506 fi
507 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
508 then
509 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700510 fi
511
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512 if [ -z "$selection" ]
513 then
514 echo
515 echo "Invalid lunch combo: $answer"
516 return 1
517 fi
518
Joe Onoratoda12daf2010-06-09 18:18:31 -0700519 export TARGET_BUILD_APPS=
520
Jeff Browne33ba4c2011-07-11 22:11:46 -0700521 local product=$(echo -n $selection | sed -e "s/-.*$//")
522 check_product $product
523 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800524 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700525 echo
526 echo "** Don't have a product spec for: '$product'"
527 echo "** Do you have the right repo manifest?"
528 product=
529 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530
Jeff Browne33ba4c2011-07-11 22:11:46 -0700531 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
532 check_variant $variant
533 if [ $? -ne 0 ]
534 then
535 echo
536 echo "** Invalid variant: '$variant'"
537 echo "** Must be one of ${VARIANT_CHOICES[@]}"
538 variant=
539 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800540
Jeff Browne33ba4c2011-07-11 22:11:46 -0700541 if [ -z "$product" -o -z "$variant" ]
542 then
543 echo
544 return 1
545 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800546
Jeff Browne33ba4c2011-07-11 22:11:46 -0700547 export TARGET_PRODUCT=$product
548 export TARGET_BUILD_VARIANT=$variant
549 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700550
551 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800552
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700553 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800554 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700555}
556
Jeff Davidson513d7a42010-08-02 10:00:44 -0700557# Tab completion for lunch.
558function _lunch()
559{
560 local cur prev opts
561 COMPREPLY=()
562 cur="${COMP_WORDS[COMP_CWORD]}"
563 prev="${COMP_WORDS[COMP_CWORD-1]}"
564
565 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
566 return 0
567}
568complete -F _lunch lunch
569
Joe Onoratoda12daf2010-06-09 18:18:31 -0700570# Configures the build to build unbundled apps.
571# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
572function tapas()
573{
Ying Wangf05c4f72013-01-31 11:16:57 -0800574 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600575 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800576 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5)$'))
Joe Onoratoda12daf2010-06-09 18:18:31 -0700577
Ying Wang67f02922012-08-22 10:25:20 -0700578 if [ $(echo $arch | wc -w) -gt 1 ]; then
579 echo "tapas: Error: Multiple build archs supplied: $arch"
580 return
581 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700582 if [ $(echo $variant | wc -w) -gt 1 ]; then
583 echo "tapas: Error: Multiple build variants supplied: $variant"
584 return
585 fi
Ying Wang67f02922012-08-22 10:25:20 -0700586
587 local product=full
588 case $arch in
589 x86) product=full_x86;;
590 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800591 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700592 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700593 if [ -z "$variant" ]; then
594 variant=eng
595 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700596 if [ -z "$apps" ]; then
597 apps=all
598 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700599
Ying Wang67f02922012-08-22 10:25:20 -0700600 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700601 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700602 export TARGET_BUILD_TYPE=release
603 export TARGET_BUILD_APPS=$apps
604
605 set_stuff_for_environment
606 printconfig
607}
608
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700609function gettop
610{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800611 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700612 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
613 echo $TOP
614 else
615 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800616 # The following circumlocution (repeated below as well) ensures
617 # that we record the true directory name and not one that is
618 # faked up with symlink names.
619 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700620 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800621 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700622 T=
623 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800624 \cd ..
synergyb112a402013-07-05 19:47:47 -0700625 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700626 done
Ying Wang9cd17642012-12-13 10:52:07 -0800627 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700628 if [ -f "$T/$TOPFILE" ]; then
629 echo $T
630 fi
631 fi
632 fi
633}
634
Andrew Hsieh906cb782013-09-10 17:37:14 +0800635# Return driver for "make", if any (eg. static analyzer)
636function getdriver()
637{
638 local T="$1"
639 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
640 if [ -n "$WITH_STATIC_ANALYZER" ]; then
641 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800642$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
643--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800644--status-bugs \
645--top=$T"
646 fi
647}
648
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649function m()
650{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800651 local T=$(gettop)
652 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800654 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700655 else
656 echo "Couldn't locate the top of the tree. Try setting TOP."
657 fi
658}
659
660function findmakefile()
661{
662 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800663 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700664 T=
665 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700666 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700667 if [ -f "$T/Android.mk" ]; then
668 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800669 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700670 return
671 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800672 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700673 done
Ying Wang9cd17642012-12-13 10:52:07 -0800674 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700675}
676
677function mm()
678{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800679 local T=$(gettop)
680 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700681 # If we're sitting in the root of the build tree, just do a
682 # normal make.
683 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800684 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700685 else
686 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800687 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700688 local MODULES=
689 local GET_INSTALL_PATH=
690 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700691 # Remove the path to top as the makefilepath needs to be relative
692 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700693 if [ ! "$T" ]; then
694 echo "Couldn't locate the top of the tree. Try setting TOP."
695 elif [ ! "$M" ]; then
696 echo "Couldn't locate a makefile from the current directory."
697 else
Ying Wanga7deb082013-08-16 13:24:47 -0700698 for ARG in $@; do
699 case $ARG in
700 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
701 esac
702 done
703 if [ -n "$GET_INSTALL_PATH" ]; then
704 MODULES=
705 ARGS=GET-INSTALL-PATH
706 else
707 MODULES=all_modules
708 ARGS=$@
709 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700710 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 -0700711 fi
712 fi
713}
714
715function mmm()
716{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800717 local T=$(gettop)
718 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700719 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800720 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800721 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800722 local ARGS=
723 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700724 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800725 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
726 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
727 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800728 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
729 if [ "$MODULES" = "" ]; then
730 MODULES=all_modules
731 fi
732 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700733 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700734 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
735 local TO_CHOP=`expr $TO_CHOP + 1`
736 local START=`PWD= /bin/pwd`
737 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700738 if [ "$MFILE" = "" ] ; then
739 MFILE=$DIR/Android.mk
740 else
741 MFILE=$MFILE/$DIR/Android.mk
742 fi
743 MAKEFILE="$MAKEFILE $MFILE"
744 else
Ying Wanga7deb082013-08-16 13:24:47 -0700745 case $DIR in
746 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
747 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
748 *) echo "No Android.mk in $DIR."; return 1;;
749 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700750 fi
751 done
Ying Wanga7deb082013-08-16 13:24:47 -0700752 if [ -n "$GET_INSTALL_PATH" ]; then
753 ARGS=$GET_INSTALL_PATH
754 MODULES=
755 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800756 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 -0700757 else
758 echo "Couldn't locate the top of the tree. Try setting TOP."
759 fi
760}
761
Ying Wangb607f7b2013-02-08 18:01:04 -0800762function mma()
763{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800764 local T=$(gettop)
765 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800766 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800767 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800768 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800769 if [ ! "$T" ]; then
770 echo "Couldn't locate the top of the tree. Try setting TOP."
771 fi
772 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800773 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800774 fi
775}
776
777function mmma()
778{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800779 local T=$(gettop)
780 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800781 if [ "$T" ]; then
782 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
783 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
784 local MY_PWD=`PWD= /bin/pwd`
785 if [ "$MY_PWD" = "$T" ]; then
786 MY_PWD=
787 else
788 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
789 fi
790 local DIR=
791 local MODULE_PATHS=
792 local ARGS=
793 for DIR in $DIRS ; do
794 if [ -d $DIR ]; then
795 if [ "$MY_PWD" = "" ]; then
796 MODULE_PATHS="$MODULE_PATHS $DIR"
797 else
798 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
799 fi
800 else
801 case $DIR in
802 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
803 *) echo "Couldn't find directory $DIR"; return 1;;
804 esac
805 fi
806 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800807 $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 -0800808 else
809 echo "Couldn't locate the top of the tree. Try setting TOP."
810 fi
811}
812
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700813function croot()
814{
815 T=$(gettop)
816 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800817 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700818 else
819 echo "Couldn't locate the top of the tree. Try setting TOP."
820 fi
821}
822
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700823function cproj()
824{
825 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700826 local HERE=$PWD
827 T=
828 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
829 T=$PWD
830 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800831 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700832 return
833 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800834 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700835 done
Ying Wang9cd17642012-12-13 10:52:07 -0800836 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700837 echo "can't find Android.mk"
838}
839
Daniel Sandler47e0a882013-07-30 13:23:52 -0400840# simplified version of ps; output in the form
841# <pid> <procname>
842function qpid() {
843 local prepend=''
844 local append=''
845 if [ "$1" = "--exact" ]; then
846 prepend=' '
847 append='$'
848 shift
849 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
850 echo "usage: qpid [[--exact] <process name|pid>"
851 return 255
852 fi
853
854 local EXE="$1"
855 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700856 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400857 else
858 adb shell ps \
859 | tr -d '\r' \
860 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
861 fi
862}
863
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700864function pid()
865{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400866 local prepend=''
867 local append=''
868 if [ "$1" = "--exact" ]; then
869 prepend=' '
870 append='$'
871 shift
872 fi
873 local EXE="$1"
874 if [ "$EXE" ] ; then
875 local PID=`adb shell ps \
876 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700877 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400878 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
879 echo "$PID"
880 else
881 echo "usage: pid [--exact] <process name>"
882 return 255
883 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700884}
885
Christopher Tate744ee802009-11-12 15:33:08 -0800886# systemstack - dump the current stack trace of all threads in the system process
887# to the usual ANR traces file
888function systemstack()
889{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800890 stacks system_server
891}
892
893function stacks()
894{
895 if [[ $1 =~ ^[0-9]+$ ]] ; then
896 local PID="$1"
897 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700898 local PIDLIST="$(pid $1)"
899 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
900 local PID="$PIDLIST"
901 elif [ "$PIDLIST" ] ; then
902 echo "more than one process: $1"
903 else
904 echo "no such process: $1"
905 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800906 else
907 echo "usage: stacks [pid|process name]"
908 fi
909
910 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700911 # Determine whether the process is native
912 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
913 # Dump stacks of Dalvik process
914 local TRACES=/data/anr/traces.txt
915 local ORIG=/data/anr/traces.orig
916 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800917
Jeff Brownb12c2e52013-08-19 15:14:16 -0700918 # Keep original traces to avoid clobbering
919 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800920
Jeff Brownb12c2e52013-08-19 15:14:16 -0700921 # Make sure we have a usable file
922 adb shell touch $TRACES
923 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800924
Jeff Brownb12c2e52013-08-19 15:14:16 -0700925 # Dump stacks and wait for dump to finish
926 adb shell kill -3 $PID
927 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800928
Jeff Brownb12c2e52013-08-19 15:14:16 -0700929 # Restore original stacks, and show current output
930 adb shell mv $TRACES $TMP
931 adb shell mv $ORIG $TRACES
932 adb shell cat $TMP
933 else
934 # Dump stacks of native process
935 adb shell debuggerd -b $PID
936 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800937 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800938}
939
John Michelau50200252012-11-09 11:48:04 -0600940function gdbwrapper()
941{
Ben Chengfba67bf2014-02-25 10:27:07 -0800942 local GDB_CMD="$1"
943 shift 1
944 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -0600945}
946
Brigid Smith0a2712d2014-05-28 14:36:43 -0700947function get_symbols_directory()
948{
949 echo $(get_abs_build_var TARGET_OUT_UNSTRIPPED)
950}
951
Ben Chengfba67bf2014-02-25 10:27:07 -0800952# process the symbolic link of /proc/$PID/exe and use the host file tool to
953# determine whether it is a 32-bit or 64-bit executable. It returns "" or "64"
954# which can be conveniently used as suffix.
955function is64bit()
956{
957 local PID="$1"
958 if [ "$PID" ] ; then
Brigid Smith0a2712d2014-05-28 14:36:43 -0700959 local EXE=`adb shell readlink /proc/$PID/exe`
960 local EXE_DIR=`get_abs_build_var PRODUCT_OUT`
961 local IS64BIT=`file "$EXE_DIR$EXE" | grep "64-bit"`
Ben Chengfba67bf2014-02-25 10:27:07 -0800962 if [ "$IS64BIT" != "" ]; then
963 echo "64"
964 else
965 echo ""
966 fi
967 else
968 echo ""
969 fi
970}
971
972# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
973# executable, set up the approriate gdbserver, then invokes the proper host
974# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700975function gdbclient()
976{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800977 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
978 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
979 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
Colin Cross3655a682014-05-22 11:59:10 -0700980 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
Brigid Smith0a2712d2014-05-28 14:36:43 -0700981 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800982 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800983 local ARCH=$(get_build_var TARGET_ARCH)
984 local GDB
985 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800986 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800987 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700988 mips) GDB=mipsel-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000989 mips64) GDB=mipsel-linux-android-gdb;;
990 x86) GDB=x86_64-linux-android-gdb;;
991 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800992 *) echo "Unknown arch $ARCH"; return 1;;
993 esac
994
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700995 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
996 local EXE="$1"
997 if [ "$EXE" ] ; then
998 EXE=$1
999 else
1000 EXE="app_process"
1001 fi
1002
1003 local PORT="$2"
1004 if [ "$PORT" ] ; then
1005 PORT=$2
1006 else
1007 PORT=":5039"
1008 fi
1009
Chris Craik20c136a2012-11-09 18:02:19 -08001010 local PID="$3"
1011 if [ "$PID" ] ; then
1012 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -07001013 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -08001014 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1015 # that likely didn't work because of returning multiple processes
1016 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001017 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001018 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1019 then
1020 echo "Couldn't resolve '$3' to single PID"
1021 return 1
1022 else
1023 echo ""
1024 echo "WARNING: multiple processes matching '$3' observed, using root process"
1025 echo ""
1026 fi
1027 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001028 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001029 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001030 local USE64BIT="$(is64bit $PID)"
1031 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001032 sleep 2
1033 else
1034 echo ""
1035 echo "If you haven't done so already, do this first on the device:"
1036 echo " gdbserver $PORT /system/bin/$EXE"
1037 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001038 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001039 echo ""
1040 fi
1041
Colin Cross84480ad2014-04-10 12:51:39 -07001042 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1043
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001044 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Colin Cross3655a682014-05-22 11:59:10 -07001045 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl"
Ben Cheng72398162013-06-24 14:36:21 -07001046 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001047 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1048 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1049
Ben Chengfba67bf2014-02-25 10:27:07 -08001050 local WHICH_GDB=
1051 # 64-bit exe found
1052 if [ "$USE64BIT" != "" ] ; then
1053 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1054 # 32-bit exe / 32-bit platform
1055 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1056 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1057 # 32-bit exe / 64-bit platform
1058 else
1059 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1060 fi
Brigid Smith0a2712d2014-05-28 14:36:43 -07001061
Ben Chengfba67bf2014-02-25 10:27:07 -08001062 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001063 else
1064 echo "Unable to determine build system output dir."
1065 fi
1066
1067}
1068
1069case `uname -s` in
1070 Darwin)
1071 function sgrep()
1072 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001073 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml|sh|mk)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001074 }
1075
1076 ;;
1077 *)
1078 function sgrep()
1079 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001080 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cpp\|S\|java\|xml\|sh\|mk\)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001081 }
1082 ;;
1083esac
1084
Raghu Gandham8da43102012-07-25 19:57:22 -07001085function gettargetarch
1086{
1087 get_build_var TARGET_ARCH
1088}
1089
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001090function jgrep()
1091{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001092 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 -07001093}
1094
1095function cgrep()
1096{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001097 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' \) -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001098}
1099
1100function resgrep()
1101{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001102 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 -07001103}
1104
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001105function mangrep()
1106{
1107 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1108}
1109
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001110function sepgrep()
1111{
1112 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 "$@"
1113}
1114
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001115case `uname -s` in
1116 Darwin)
1117 function mgrep()
1118 {
Ying Wang324c2b22012-08-17 15:03:20 -07001119 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 -07001120 }
1121
1122 function treegrep()
1123 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001124 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 -07001125 }
1126
1127 ;;
1128 *)
1129 function mgrep()
1130 {
Ying Wang324c2b22012-08-17 15:03:20 -07001131 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 -07001132 }
1133
1134 function treegrep()
1135 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001136 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 -07001137 }
1138
1139 ;;
1140esac
1141
1142function getprebuilt
1143{
1144 get_abs_build_var ANDROID_PREBUILTS
1145}
1146
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001147function tracedmdump()
1148{
1149 T=$(gettop)
1150 if [ ! "$T" ]; then
1151 echo "Couldn't locate the top of the tree. Try setting TOP."
1152 return
1153 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001154 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001155 local arch=$(gettargetarch)
1156 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001157
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001158 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001159 if [ ! "$TRACE" ] ; then
1160 echo "usage: tracedmdump tracename"
1161 return
1162 fi
1163
Jack Veenstra60116fc2009-04-09 18:12:34 -07001164 if [ ! -r "$KERNEL" ] ; then
1165 echo "Error: cannot find kernel: '$KERNEL'"
1166 return
1167 fi
1168
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001169 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001170 if [ "$BASETRACE" = "$TRACE" ] ; then
1171 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1172 fi
1173
1174 echo "post-processing traces..."
1175 rm -f $TRACE/qtrace.dexlist
1176 post_trace $TRACE
1177 if [ $? -ne 0 ]; then
1178 echo "***"
1179 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1180 echo "***"
1181 return
1182 fi
1183 echo "generating dexlist output..."
1184 /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
1185 echo "generating dmtrace data..."
1186 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1187 echo "generating html file..."
1188 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1189 echo "done, see $TRACE/dmtrace.html for details"
1190 echo "or run:"
1191 echo " traceview $TRACE/dmtrace"
1192}
1193
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001194# communicate with a running device or emulator, set up necessary state,
1195# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001196function runhat()
1197{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001198 # process standard adb options
1199 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001200 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001201 adbTarget=$1
1202 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001203 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001204 adbTarget="$1 $2"
1205 shift 2
1206 fi
1207 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001208 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001209
1210 # runhat options
1211 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001212
1213 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001214 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001215 return
1216 fi
1217
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001218 # confirm hat is available
1219 if [ -z $(which hat) ]; then
1220 echo "hat is not available in this configuration."
1221 return
1222 fi
1223
Andy McFaddenb6289852010-07-12 08:00:19 -07001224 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001225 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001226 local devFile=$sdcard/hprof-$targetPid
1227 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001228 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001229 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001230 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001231 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001232 echo -n "> "
1233 read
1234
The Android Open Source Project88b60792009-03-03 19:28:42 -08001235 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236
The Android Open Source Project88b60792009-03-03 19:28:42 -08001237 echo "Retrieving file $devFile..."
1238 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001239
The Android Open Source Project88b60792009-03-03 19:28:42 -08001240 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001241
The Android Open Source Project88b60792009-03-03 19:28:42 -08001242 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001243 echo "View the output by pointing your browser at http://localhost:7000/"
1244 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001245 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001246}
1247
1248function getbugreports()
1249{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001250 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001251
1252 if [ ! "$reports" ]; then
1253 echo "Could not locate any bugreports."
1254 return
1255 fi
1256
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001257 local report
1258 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001259 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001260 echo "/sdcard/bugreports/${report}"
1261 adb pull /sdcard/bugreports/${report} ${report}
1262 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001263 done
1264}
1265
Victoria Lease1b296b42012-08-21 15:44:06 -07001266function getsdcardpath()
1267{
1268 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1269}
1270
1271function getscreenshotpath()
1272{
1273 echo "$(getsdcardpath)/Pictures/Screenshots"
1274}
1275
1276function getlastscreenshot()
1277{
1278 local screenshot_path=$(getscreenshotpath)
1279 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1280 if [ "$screenshot" = "" ]; then
1281 echo "No screenshots found."
1282 return
1283 fi
1284 echo "${screenshot}"
1285 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1286}
1287
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001288function startviewserver()
1289{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001290 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001291 if [ $# -gt 0 ]; then
1292 port=$1
1293 fi
1294 adb shell service call window 1 i32 $port
1295}
1296
1297function stopviewserver()
1298{
1299 adb shell service call window 2
1300}
1301
1302function isviewserverstarted()
1303{
1304 adb shell service call window 3
1305}
1306
Romain Guyb84049a2010-10-04 16:56:11 -07001307function key_home()
1308{
1309 adb shell input keyevent 3
1310}
1311
1312function key_back()
1313{
1314 adb shell input keyevent 4
1315}
1316
1317function key_menu()
1318{
1319 adb shell input keyevent 82
1320}
1321
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001322function smoketest()
1323{
1324 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1325 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1326 return
1327 fi
1328 T=$(gettop)
1329 if [ ! "$T" ]; then
1330 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1331 return
1332 fi
1333
Ying Wang9cd17642012-12-13 10:52:07 -08001334 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001335 adb uninstall com.android.smoketest > /dev/null &&
1336 adb uninstall com.android.smoketest.tests > /dev/null &&
1337 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1338 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1339 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1340}
1341
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001342# simple shortcut to the runtest command
1343function runtest()
1344{
1345 T=$(gettop)
1346 if [ ! "$T" ]; then
1347 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1348 return
1349 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001350 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001351}
1352
The Android Open Source Project88b60792009-03-03 19:28:42 -08001353function godir () {
1354 if [[ -z "$1" ]]; then
1355 echo "Usage: godir <regex>"
1356 return
1357 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001358 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001359 if [[ ! -f $T/filelist ]]; then
1360 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001361 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001362 echo " Done"
1363 echo ""
1364 fi
1365 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001366 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001367 if [[ ${#lines[@]} = 0 ]]; then
1368 echo "Not found"
1369 return
1370 fi
1371 local pathname
1372 local choice
1373 if [[ ${#lines[@]} > 1 ]]; then
1374 while [[ -z "$pathname" ]]; do
1375 local index=1
1376 local line
1377 for line in ${lines[@]}; do
1378 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001379 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001380 done
1381 echo
1382 echo -n "Select one: "
1383 unset choice
1384 read choice
1385 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1386 echo "Invalid choice"
1387 continue
1388 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001389 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001390 done
1391 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001392 pathname=${lines[0]}
1393 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001394 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001395}
1396
Narayan Kamath9260bba2014-01-17 10:05:25 +00001397# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1398#
1399# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1400# For some reason, installing the JDK doesn't make it show up in the
1401# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001402function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001403 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001404 # we can reset it later, depending on the version of java the build
1405 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001406 #
1407 # If we don't do this, the JAVA_HOME value set by the first call to
1408 # build/envsetup.sh will persist forever.
1409 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1410 export JAVA_HOME=""
1411 fi
1412
Andy McFaddenbd960942010-06-24 12:52:51 -07001413 if [ ! "$JAVA_HOME" ]; then
Narayan Kamathc84889b2014-04-01 14:16:26 +01001414 if [ -n "$LEGACY_USE_JAVA6" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001415 case `uname -s` in
1416 Darwin)
1417 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1418 ;;
1419 *)
1420 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1421 ;;
1422 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001423 else
1424 case `uname -s` in
1425 Darwin)
Jason Parks30cfbd72014-04-28 13:32:10 -05001426 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
Narayan Kamath9260bba2014-01-17 10:05:25 +00001427 ;;
1428 *)
1429 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1430 ;;
1431 esac
1432 fi
1433
1434 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1435 # we can change it on the next envsetup.sh, if required.
1436 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001437 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001438}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001439
Alex Rayf0d08eb2013-03-08 15:15:06 -08001440# Print colored exit condition
1441function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001442 "$@"
1443 local retval=$?
1444 if [ $retval -ne 0 ]
1445 then
1446 echo -e "\e[0;31mFAILURE\e[00m"
1447 else
1448 echo -e "\e[0;32mSUCCESS\e[00m"
1449 fi
1450 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001451}
1452
Raphael Moll70a86b02011-06-20 16:03:14 -07001453if [ "x$SHELL" != "x/bin/bash" ]; then
1454 case `ps -o command -p $$` in
1455 *bash*)
1456 ;;
1457 *)
1458 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1459 ;;
1460 esac
1461fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001462
1463# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001464for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1465 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001466do
1467 echo "including $f"
1468 . $f
1469done
1470unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001471
1472addcompletions