blob: ba4f68357fe0afee95383e5afc8e48132d68c6c1 [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
118 CODE_REVIEWS=
119 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700120 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700121
Ben Cheng8bc4c432012-11-16 13:29:13 -0800122 # defined in core/config.mk
123 targetgccversion=$(get_build_var 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;
138 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion/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
Ben Chengfba67bf2014-02-25 10:27:07 -0800163 ANDROID_KERNEL_TOOLCHAIN_PATH="$gccprebuiltdir/$toolchaindir"
164 export ARM_EABI_TOOLCHAIN=$ANDROID_KERNEL_TOOLCHAIN_PATH
Bruce Beare42ced6d2012-07-17 21:40:01 -0700165 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700166 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700167 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
168 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700169 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700170 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700171 ;;
172 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700173
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700174 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700175 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ben Chengfba67bf2014-02-25 10:27:07 -0800176 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_KERNEL_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
Ying Wangaa1c9b52012-11-26 20:51:59 -0800177 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800178
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500179 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900180 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500181 if [ -n "$JAVA_HOME" ]; then
182 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900183 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
184 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500185 fi
186
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800187 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700188 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
189 export OUT=$ANDROID_PRODUCT_OUT
190
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700191 unset ANDROID_HOST_OUT
192 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
193
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800194 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700195 # TODO: fix the path
196 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
197}
198
199function printconfig()
200{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800201 T=$(gettop)
202 if [ ! "$T" ]; then
203 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
204 return
205 fi
206 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700207}
208
209function set_stuff_for_environment()
210{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800211 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500212 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800213 setpaths
214 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700215
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800216 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700217 # With this environment variable new GCC can apply colors to warnings/errors
218 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 -0700219}
220
221function set_sequence_number()
222{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700223 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700224}
225
226function settitle()
227{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800228 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700229 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700230 local product=$TARGET_PRODUCT
231 local variant=$TARGET_BUILD_VARIANT
232 local apps=$TARGET_BUILD_APPS
233 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700234 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700235 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700236 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700237 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800238 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700239}
240
Kenny Root52aa81c2011-07-15 11:07:06 -0700241function addcompletions()
242{
243 local T dir f
244
245 # Keep us from trying to run in something that isn't bash.
246 if [ -z "${BASH_VERSION}" ]; then
247 return
248 fi
249
250 # Keep us from trying to run in bash that's too old.
251 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
252 return
253 fi
254
255 dir="sdk/bash_completion"
256 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700257 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700258 echo "including $f"
259 . $f
260 done
261 fi
262}
263
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700264function choosetype()
265{
266 echo "Build type choices are:"
267 echo " 1. release"
268 echo " 2. debug"
269 echo
270
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800271 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700272 DEFAULT_NUM=1
273 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700274
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800275 export TARGET_BUILD_TYPE=
276 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700277 while [ -z $TARGET_BUILD_TYPE ]
278 do
279 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800280 if [ -z "$1" ] ; then
281 read ANSWER
282 else
283 echo $1
284 ANSWER=$1
285 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700286 case $ANSWER in
287 "")
288 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
289 ;;
290 1)
291 export TARGET_BUILD_TYPE=release
292 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800293 release)
294 export TARGET_BUILD_TYPE=release
295 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700296 2)
297 export TARGET_BUILD_TYPE=debug
298 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800299 debug)
300 export TARGET_BUILD_TYPE=debug
301 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700302 *)
303 echo
304 echo "I didn't understand your response. Please try again."
305 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700306 ;;
307 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800308 if [ -n "$1" ] ; then
309 break
310 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700311 done
312
313 set_stuff_for_environment
314}
315
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316#
317# This function isn't really right: It chooses a TARGET_PRODUCT
318# based on the list of boards. Usually, that gets you something
319# that kinda works with a generic product, but really, you should
320# pick a product by name.
321#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700322function chooseproduct()
323{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700324 if [ "x$TARGET_PRODUCT" != x ] ; then
325 default_value=$TARGET_PRODUCT
326 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700327 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700328 fi
329
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800330 export TARGET_PRODUCT=
331 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332 while [ -z "$TARGET_PRODUCT" ]
333 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700334 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335 if [ -z "$1" ] ; then
336 read ANSWER
337 else
338 echo $1
339 ANSWER=$1
340 fi
341
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700342 if [ -z "$ANSWER" ] ; then
343 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800344 else
345 if check_product $ANSWER
346 then
347 export TARGET_PRODUCT=$ANSWER
348 else
349 echo "** Not a valid product: $ANSWER"
350 fi
351 fi
352 if [ -n "$1" ] ; then
353 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700354 fi
355 done
356
357 set_stuff_for_environment
358}
359
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800360function choosevariant()
361{
362 echo "Variant choices are:"
363 local index=1
364 local v
365 for v in ${VARIANT_CHOICES[@]}
366 do
367 # The product name is the name of the directory containing
368 # the makefile we found, above.
369 echo " $index. $v"
370 index=$(($index+1))
371 done
372
373 local default_value=eng
374 local ANSWER
375
376 export TARGET_BUILD_VARIANT=
377 while [ -z "$TARGET_BUILD_VARIANT" ]
378 do
379 echo -n "Which would you like? [$default_value] "
380 if [ -z "$1" ] ; then
381 read ANSWER
382 else
383 echo $1
384 ANSWER=$1
385 fi
386
387 if [ -z "$ANSWER" ] ; then
388 export TARGET_BUILD_VARIANT=$default_value
389 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
390 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800391 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800392 fi
393 else
394 if check_variant $ANSWER
395 then
396 export TARGET_BUILD_VARIANT=$ANSWER
397 else
398 echo "** Not a valid variant: $ANSWER"
399 fi
400 fi
401 if [ -n "$1" ] ; then
402 break
403 fi
404 done
405}
406
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700407function choosecombo()
408{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700409 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700410
411 echo
412 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700413 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700414
415 echo
416 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700417 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800418
419 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700420 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800421 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700422}
423
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800424# Clear this variable. It will be built up again when the vendorsetup.sh
425# files are included at the end of this file.
426unset LUNCH_MENU_CHOICES
427function add_lunch_combo()
428{
429 local new_combo=$1
430 local c
431 for c in ${LUNCH_MENU_CHOICES[@]} ; do
432 if [ "$new_combo" = "$c" ] ; then
433 return
434 fi
435 done
436 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
437}
438
439# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700440add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800441add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000442add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800443add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000444add_lunch_combo aosp_x86-eng
445add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800446add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800447
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700448function print_lunch_menu()
449{
450 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700451 echo
452 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700453 echo
454 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800455
456 local i=1
457 local choice
458 for choice in ${LUNCH_MENU_CHOICES[@]}
459 do
460 echo " $i. $choice"
461 i=$(($i+1))
462 done
463
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700464 echo
465}
466
467function lunch()
468{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469 local answer
470
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 else
474 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700475 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700477 fi
478
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479 local selection=
480
481 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700482 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700483 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800484 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
485 then
486 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
487 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800488 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800489 fi
490 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
491 then
492 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700493 fi
494
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800495 if [ -z "$selection" ]
496 then
497 echo
498 echo "Invalid lunch combo: $answer"
499 return 1
500 fi
501
Joe Onoratoda12daf2010-06-09 18:18:31 -0700502 export TARGET_BUILD_APPS=
503
Jeff Browne33ba4c2011-07-11 22:11:46 -0700504 local product=$(echo -n $selection | sed -e "s/-.*$//")
505 check_product $product
506 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700508 echo
509 echo "** Don't have a product spec for: '$product'"
510 echo "** Do you have the right repo manifest?"
511 product=
512 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800513
Jeff Browne33ba4c2011-07-11 22:11:46 -0700514 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
515 check_variant $variant
516 if [ $? -ne 0 ]
517 then
518 echo
519 echo "** Invalid variant: '$variant'"
520 echo "** Must be one of ${VARIANT_CHOICES[@]}"
521 variant=
522 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800523
Jeff Browne33ba4c2011-07-11 22:11:46 -0700524 if [ -z "$product" -o -z "$variant" ]
525 then
526 echo
527 return 1
528 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800529
Jeff Browne33ba4c2011-07-11 22:11:46 -0700530 export TARGET_PRODUCT=$product
531 export TARGET_BUILD_VARIANT=$variant
532 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700533
534 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800535
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700536 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800537 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700538}
539
Jeff Davidson513d7a42010-08-02 10:00:44 -0700540# Tab completion for lunch.
541function _lunch()
542{
543 local cur prev opts
544 COMPREPLY=()
545 cur="${COMP_WORDS[COMP_CWORD]}"
546 prev="${COMP_WORDS[COMP_CWORD-1]}"
547
548 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
549 return 0
550}
551complete -F _lunch lunch
552
Joe Onoratoda12daf2010-06-09 18:18:31 -0700553# Configures the build to build unbundled apps.
554# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
555function tapas()
556{
Ying Wangf05c4f72013-01-31 11:16:57 -0800557 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600558 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800559 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 -0700560
Ying Wang67f02922012-08-22 10:25:20 -0700561 if [ $(echo $arch | wc -w) -gt 1 ]; then
562 echo "tapas: Error: Multiple build archs supplied: $arch"
563 return
564 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700565 if [ $(echo $variant | wc -w) -gt 1 ]; then
566 echo "tapas: Error: Multiple build variants supplied: $variant"
567 return
568 fi
Ying Wang67f02922012-08-22 10:25:20 -0700569
570 local product=full
571 case $arch in
572 x86) product=full_x86;;
573 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800574 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700575 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700576 if [ -z "$variant" ]; then
577 variant=eng
578 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700579 if [ -z "$apps" ]; then
580 apps=all
581 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700582
Ying Wang67f02922012-08-22 10:25:20 -0700583 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700584 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700585 export TARGET_BUILD_TYPE=release
586 export TARGET_BUILD_APPS=$apps
587
588 set_stuff_for_environment
589 printconfig
590}
591
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592function gettop
593{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800594 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700595 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
596 echo $TOP
597 else
598 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800599 # The following circumlocution (repeated below as well) ensures
600 # that we record the true directory name and not one that is
601 # faked up with symlink names.
602 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700603 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800604 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700605 T=
606 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800607 \cd ..
synergyb112a402013-07-05 19:47:47 -0700608 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700609 done
Ying Wang9cd17642012-12-13 10:52:07 -0800610 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700611 if [ -f "$T/$TOPFILE" ]; then
612 echo $T
613 fi
614 fi
615 fi
616}
617
Andrew Hsieh906cb782013-09-10 17:37:14 +0800618# Return driver for "make", if any (eg. static analyzer)
619function getdriver()
620{
621 local T="$1"
622 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
623 if [ -n "$WITH_STATIC_ANALYZER" ]; then
624 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800625$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
626--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800627--status-bugs \
628--top=$T"
629 fi
630}
631
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700632function m()
633{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800634 local T=$(gettop)
635 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700636 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800637 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700638 else
639 echo "Couldn't locate the top of the tree. Try setting TOP."
640 fi
641}
642
643function findmakefile()
644{
645 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800646 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700647 T=
648 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700649 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700650 if [ -f "$T/Android.mk" ]; then
651 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800652 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653 return
654 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800655 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700656 done
Ying Wang9cd17642012-12-13 10:52:07 -0800657 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658}
659
660function mm()
661{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800662 local T=$(gettop)
663 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700664 # If we're sitting in the root of the build tree, just do a
665 # normal make.
666 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800667 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700668 else
669 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800670 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700671 local MODULES=
672 local GET_INSTALL_PATH=
673 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700674 # Remove the path to top as the makefilepath needs to be relative
675 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700676 if [ ! "$T" ]; then
677 echo "Couldn't locate the top of the tree. Try setting TOP."
678 elif [ ! "$M" ]; then
679 echo "Couldn't locate a makefile from the current directory."
680 else
Ying Wanga7deb082013-08-16 13:24:47 -0700681 for ARG in $@; do
682 case $ARG in
683 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
684 esac
685 done
686 if [ -n "$GET_INSTALL_PATH" ]; then
687 MODULES=
688 ARGS=GET-INSTALL-PATH
689 else
690 MODULES=all_modules
691 ARGS=$@
692 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700693 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 -0700694 fi
695 fi
696}
697
698function mmm()
699{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800700 local T=$(gettop)
701 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700702 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800703 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800704 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800705 local ARGS=
706 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700707 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800708 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
709 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
710 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800711 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
712 if [ "$MODULES" = "" ]; then
713 MODULES=all_modules
714 fi
715 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700716 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700717 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
718 local TO_CHOP=`expr $TO_CHOP + 1`
719 local START=`PWD= /bin/pwd`
720 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700721 if [ "$MFILE" = "" ] ; then
722 MFILE=$DIR/Android.mk
723 else
724 MFILE=$MFILE/$DIR/Android.mk
725 fi
726 MAKEFILE="$MAKEFILE $MFILE"
727 else
Ying Wanga7deb082013-08-16 13:24:47 -0700728 case $DIR in
729 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
730 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
731 *) echo "No Android.mk in $DIR."; return 1;;
732 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700733 fi
734 done
Ying Wanga7deb082013-08-16 13:24:47 -0700735 if [ -n "$GET_INSTALL_PATH" ]; then
736 ARGS=$GET_INSTALL_PATH
737 MODULES=
738 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800739 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 -0700740 else
741 echo "Couldn't locate the top of the tree. Try setting TOP."
742 fi
743}
744
Ying Wangb607f7b2013-02-08 18:01:04 -0800745function mma()
746{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800747 local T=$(gettop)
748 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800749 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800750 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800751 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800752 if [ ! "$T" ]; then
753 echo "Couldn't locate the top of the tree. Try setting TOP."
754 fi
755 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800756 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800757 fi
758}
759
760function mmma()
761{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800762 local T=$(gettop)
763 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800764 if [ "$T" ]; then
765 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
766 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
767 local MY_PWD=`PWD= /bin/pwd`
768 if [ "$MY_PWD" = "$T" ]; then
769 MY_PWD=
770 else
771 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
772 fi
773 local DIR=
774 local MODULE_PATHS=
775 local ARGS=
776 for DIR in $DIRS ; do
777 if [ -d $DIR ]; then
778 if [ "$MY_PWD" = "" ]; then
779 MODULE_PATHS="$MODULE_PATHS $DIR"
780 else
781 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
782 fi
783 else
784 case $DIR in
785 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
786 *) echo "Couldn't find directory $DIR"; return 1;;
787 esac
788 fi
789 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800790 $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 -0800791 else
792 echo "Couldn't locate the top of the tree. Try setting TOP."
793 fi
794}
795
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700796function croot()
797{
798 T=$(gettop)
799 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800800 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 else
802 echo "Couldn't locate the top of the tree. Try setting TOP."
803 fi
804}
805
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700806function cproj()
807{
808 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700809 local HERE=$PWD
810 T=
811 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
812 T=$PWD
813 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800814 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700815 return
816 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800817 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700818 done
Ying Wang9cd17642012-12-13 10:52:07 -0800819 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700820 echo "can't find Android.mk"
821}
822
Daniel Sandler47e0a882013-07-30 13:23:52 -0400823# simplified version of ps; output in the form
824# <pid> <procname>
825function qpid() {
826 local prepend=''
827 local append=''
828 if [ "$1" = "--exact" ]; then
829 prepend=' '
830 append='$'
831 shift
832 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
833 echo "usage: qpid [[--exact] <process name|pid>"
834 return 255
835 fi
836
837 local EXE="$1"
838 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700839 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400840 else
841 adb shell ps \
842 | tr -d '\r' \
843 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
844 fi
845}
846
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700847function pid()
848{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400849 local prepend=''
850 local append=''
851 if [ "$1" = "--exact" ]; then
852 prepend=' '
853 append='$'
854 shift
855 fi
856 local EXE="$1"
857 if [ "$EXE" ] ; then
858 local PID=`adb shell ps \
859 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700860 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400861 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
862 echo "$PID"
863 else
864 echo "usage: pid [--exact] <process name>"
865 return 255
866 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700867}
868
Christopher Tate744ee802009-11-12 15:33:08 -0800869# systemstack - dump the current stack trace of all threads in the system process
870# to the usual ANR traces file
871function systemstack()
872{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800873 stacks system_server
874}
875
876function stacks()
877{
878 if [[ $1 =~ ^[0-9]+$ ]] ; then
879 local PID="$1"
880 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700881 local PIDLIST="$(pid $1)"
882 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
883 local PID="$PIDLIST"
884 elif [ "$PIDLIST" ] ; then
885 echo "more than one process: $1"
886 else
887 echo "no such process: $1"
888 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800889 else
890 echo "usage: stacks [pid|process name]"
891 fi
892
893 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700894 # Determine whether the process is native
895 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
896 # Dump stacks of Dalvik process
897 local TRACES=/data/anr/traces.txt
898 local ORIG=/data/anr/traces.orig
899 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800900
Jeff Brownb12c2e52013-08-19 15:14:16 -0700901 # Keep original traces to avoid clobbering
902 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800903
Jeff Brownb12c2e52013-08-19 15:14:16 -0700904 # Make sure we have a usable file
905 adb shell touch $TRACES
906 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800907
Jeff Brownb12c2e52013-08-19 15:14:16 -0700908 # Dump stacks and wait for dump to finish
909 adb shell kill -3 $PID
910 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800911
Jeff Brownb12c2e52013-08-19 15:14:16 -0700912 # Restore original stacks, and show current output
913 adb shell mv $TRACES $TMP
914 adb shell mv $ORIG $TRACES
915 adb shell cat $TMP
916 else
917 # Dump stacks of native process
918 adb shell debuggerd -b $PID
919 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800920 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800921}
922
John Michelau50200252012-11-09 11:48:04 -0600923function gdbwrapper()
924{
Ben Chengfba67bf2014-02-25 10:27:07 -0800925 local GDB_CMD="$1"
926 shift 1
927 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -0600928}
929
Ben Chengfba67bf2014-02-25 10:27:07 -0800930# process the symbolic link of /proc/$PID/exe and use the host file tool to
931# determine whether it is a 32-bit or 64-bit executable. It returns "" or "64"
932# which can be conveniently used as suffix.
933function is64bit()
934{
935 local PID="$1"
936 if [ "$PID" ] ; then
937 local EXE=`adb shell ls -l /proc/$PID/exe \
938 | tr -d '\r' \
939 | cut -d'>' -f2 \
940 | tr -d ' ' \
941 | cut -d'/' -f4`
942
943 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
944 local IS64BIT=`file $OUT_EXE_SYMBOLS/$EXE | grep "64-bit"`
945 if [ "$IS64BIT" != "" ]; then
946 echo "64"
947 else
948 echo ""
949 fi
950 else
951 echo ""
952 fi
953}
954
955# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
956# executable, set up the approriate gdbserver, then invokes the proper host
957# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700958function gdbclient()
959{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800960 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
961 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
962 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
963 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
964 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800965 local ARCH=$(get_build_var TARGET_ARCH)
966 local GDB
967 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800968 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800969 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700970 mips) GDB=mipsel-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000971 mips64) GDB=mipsel-linux-android-gdb;;
972 x86) GDB=x86_64-linux-android-gdb;;
973 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800974 *) echo "Unknown arch $ARCH"; return 1;;
975 esac
976
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700977 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
978 local EXE="$1"
979 if [ "$EXE" ] ; then
980 EXE=$1
981 else
982 EXE="app_process"
983 fi
984
985 local PORT="$2"
986 if [ "$PORT" ] ; then
987 PORT=$2
988 else
989 PORT=":5039"
990 fi
991
Chris Craik20c136a2012-11-09 18:02:19 -0800992 local PID="$3"
993 if [ "$PID" ] ; then
994 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700995 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800996 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
997 # that likely didn't work because of returning multiple processes
998 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -0700999 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001000 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1001 then
1002 echo "Couldn't resolve '$3' to single PID"
1003 return 1
1004 else
1005 echo ""
1006 echo "WARNING: multiple processes matching '$3' observed, using root process"
1007 echo ""
1008 fi
1009 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001010 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001011 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001012 local USE64BIT="$(is64bit $PID)"
1013 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001014 sleep 2
1015 else
1016 echo ""
1017 echo "If you haven't done so already, do this first on the device:"
1018 echo " gdbserver $PORT /system/bin/$EXE"
1019 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001020 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001021 echo ""
1022 fi
1023
1024 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Ben Chengfba67bf2014-02-25 10:27:07 -08001025 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS$USE64BIT:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx"
Ben Cheng72398162013-06-24 14:36:21 -07001026 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001027 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1028 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1029
Ben Chengfba67bf2014-02-25 10:27:07 -08001030 local WHICH_GDB=
1031 # 64-bit exe found
1032 if [ "$USE64BIT" != "" ] ; then
1033 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1034 # 32-bit exe / 32-bit platform
1035 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1036 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1037 # 32-bit exe / 64-bit platform
1038 else
1039 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1040 fi
1041 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001042 else
1043 echo "Unable to determine build system output dir."
1044 fi
1045
1046}
1047
1048case `uname -s` in
1049 Darwin)
1050 function sgrep()
1051 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001052 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 -07001053 }
1054
1055 ;;
1056 *)
1057 function sgrep()
1058 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001059 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 -07001060 }
1061 ;;
1062esac
1063
Raghu Gandham8da43102012-07-25 19:57:22 -07001064function gettargetarch
1065{
1066 get_build_var TARGET_ARCH
1067}
1068
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001069function jgrep()
1070{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001071 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 -07001072}
1073
1074function cgrep()
1075{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001076 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 -07001077}
1078
1079function resgrep()
1080{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001081 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 -07001082}
1083
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001084function mangrep()
1085{
1086 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1087}
1088
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001089function sepgrep()
1090{
1091 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 "$@"
1092}
1093
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001094case `uname -s` in
1095 Darwin)
1096 function mgrep()
1097 {
Ying Wang324c2b22012-08-17 15:03:20 -07001098 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 -07001099 }
1100
1101 function treegrep()
1102 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001103 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 -07001104 }
1105
1106 ;;
1107 *)
1108 function mgrep()
1109 {
Ying Wang324c2b22012-08-17 15:03:20 -07001110 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 -07001111 }
1112
1113 function treegrep()
1114 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001115 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 -07001116 }
1117
1118 ;;
1119esac
1120
1121function getprebuilt
1122{
1123 get_abs_build_var ANDROID_PREBUILTS
1124}
1125
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001126function tracedmdump()
1127{
1128 T=$(gettop)
1129 if [ ! "$T" ]; then
1130 echo "Couldn't locate the top of the tree. Try setting TOP."
1131 return
1132 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001133 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001134 local arch=$(gettargetarch)
1135 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001136
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001137 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001138 if [ ! "$TRACE" ] ; then
1139 echo "usage: tracedmdump tracename"
1140 return
1141 fi
1142
Jack Veenstra60116fc2009-04-09 18:12:34 -07001143 if [ ! -r "$KERNEL" ] ; then
1144 echo "Error: cannot find kernel: '$KERNEL'"
1145 return
1146 fi
1147
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001148 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001149 if [ "$BASETRACE" = "$TRACE" ] ; then
1150 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1151 fi
1152
1153 echo "post-processing traces..."
1154 rm -f $TRACE/qtrace.dexlist
1155 post_trace $TRACE
1156 if [ $? -ne 0 ]; then
1157 echo "***"
1158 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1159 echo "***"
1160 return
1161 fi
1162 echo "generating dexlist output..."
1163 /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
1164 echo "generating dmtrace data..."
1165 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1166 echo "generating html file..."
1167 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1168 echo "done, see $TRACE/dmtrace.html for details"
1169 echo "or run:"
1170 echo " traceview $TRACE/dmtrace"
1171}
1172
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001173# communicate with a running device or emulator, set up necessary state,
1174# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001175function runhat()
1176{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001177 # process standard adb options
1178 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001179 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001180 adbTarget=$1
1181 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001182 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001183 adbTarget="$1 $2"
1184 shift 2
1185 fi
1186 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001187 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001188
1189 # runhat options
1190 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001191
1192 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001193 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001194 return
1195 fi
1196
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001197 # confirm hat is available
1198 if [ -z $(which hat) ]; then
1199 echo "hat is not available in this configuration."
1200 return
1201 fi
1202
Andy McFaddenb6289852010-07-12 08:00:19 -07001203 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001204 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001205 local devFile=$sdcard/hprof-$targetPid
1206 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001207 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001208 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001209 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001210 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001211 echo -n "> "
1212 read
1213
The Android Open Source Project88b60792009-03-03 19:28:42 -08001214 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001215
The Android Open Source Project88b60792009-03-03 19:28:42 -08001216 echo "Retrieving file $devFile..."
1217 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001218
The Android Open Source Project88b60792009-03-03 19:28:42 -08001219 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001220
The Android Open Source Project88b60792009-03-03 19:28:42 -08001221 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001222 echo "View the output by pointing your browser at http://localhost:7000/"
1223 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001224 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001225}
1226
1227function getbugreports()
1228{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001229 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001230
1231 if [ ! "$reports" ]; then
1232 echo "Could not locate any bugreports."
1233 return
1234 fi
1235
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001236 local report
1237 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001238 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001239 echo "/sdcard/bugreports/${report}"
1240 adb pull /sdcard/bugreports/${report} ${report}
1241 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001242 done
1243}
1244
Victoria Lease1b296b42012-08-21 15:44:06 -07001245function getsdcardpath()
1246{
1247 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1248}
1249
1250function getscreenshotpath()
1251{
1252 echo "$(getsdcardpath)/Pictures/Screenshots"
1253}
1254
1255function getlastscreenshot()
1256{
1257 local screenshot_path=$(getscreenshotpath)
1258 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1259 if [ "$screenshot" = "" ]; then
1260 echo "No screenshots found."
1261 return
1262 fi
1263 echo "${screenshot}"
1264 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1265}
1266
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001267function startviewserver()
1268{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001269 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001270 if [ $# -gt 0 ]; then
1271 port=$1
1272 fi
1273 adb shell service call window 1 i32 $port
1274}
1275
1276function stopviewserver()
1277{
1278 adb shell service call window 2
1279}
1280
1281function isviewserverstarted()
1282{
1283 adb shell service call window 3
1284}
1285
Romain Guyb84049a2010-10-04 16:56:11 -07001286function key_home()
1287{
1288 adb shell input keyevent 3
1289}
1290
1291function key_back()
1292{
1293 adb shell input keyevent 4
1294}
1295
1296function key_menu()
1297{
1298 adb shell input keyevent 82
1299}
1300
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001301function smoketest()
1302{
1303 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1304 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1305 return
1306 fi
1307 T=$(gettop)
1308 if [ ! "$T" ]; then
1309 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1310 return
1311 fi
1312
Ying Wang9cd17642012-12-13 10:52:07 -08001313 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001314 adb uninstall com.android.smoketest > /dev/null &&
1315 adb uninstall com.android.smoketest.tests > /dev/null &&
1316 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1317 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1318 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1319}
1320
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001321# simple shortcut to the runtest command
1322function runtest()
1323{
1324 T=$(gettop)
1325 if [ ! "$T" ]; then
1326 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1327 return
1328 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001329 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001330}
1331
The Android Open Source Project88b60792009-03-03 19:28:42 -08001332function godir () {
1333 if [[ -z "$1" ]]; then
1334 echo "Usage: godir <regex>"
1335 return
1336 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001337 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001338 if [[ ! -f $T/filelist ]]; then
1339 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001340 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001341 echo " Done"
1342 echo ""
1343 fi
1344 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001345 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001346 if [[ ${#lines[@]} = 0 ]]; then
1347 echo "Not found"
1348 return
1349 fi
1350 local pathname
1351 local choice
1352 if [[ ${#lines[@]} > 1 ]]; then
1353 while [[ -z "$pathname" ]]; do
1354 local index=1
1355 local line
1356 for line in ${lines[@]}; do
1357 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001358 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001359 done
1360 echo
1361 echo -n "Select one: "
1362 unset choice
1363 read choice
1364 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1365 echo "Invalid choice"
1366 continue
1367 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001368 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001369 done
1370 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001371 pathname=${lines[0]}
1372 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001373 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001374}
1375
Narayan Kamath9260bba2014-01-17 10:05:25 +00001376# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1377#
1378# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1379# For some reason, installing the JDK doesn't make it show up in the
1380# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001381function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001382 # Clear the existing JAVA_HOME value if we set it ourselves, so that
1383 # we can reset it later, depending on the value of EXPERIMENTAL_USE_JAVA7.
1384 #
1385 # If we don't do this, the JAVA_HOME value set by the first call to
1386 # build/envsetup.sh will persist forever.
1387 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1388 export JAVA_HOME=""
1389 fi
1390
Andy McFaddenbd960942010-06-24 12:52:51 -07001391 if [ ! "$JAVA_HOME" ]; then
Narayan Kamath9260bba2014-01-17 10:05:25 +00001392 if [ ! "$EXPERIMENTAL_USE_JAVA7" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001393 case `uname -s` in
1394 Darwin)
1395 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1396 ;;
1397 *)
1398 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1399 ;;
1400 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001401 else
1402 case `uname -s` in
1403 Darwin)
1404 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
1405 ;;
1406 *)
1407 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1408 ;;
1409 esac
1410 fi
1411
1412 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1413 # we can change it on the next envsetup.sh, if required.
1414 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001415 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001416}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001417
Alex Rayf0d08eb2013-03-08 15:15:06 -08001418# Print colored exit condition
1419function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001420 "$@"
1421 local retval=$?
1422 if [ $retval -ne 0 ]
1423 then
1424 echo -e "\e[0;31mFAILURE\e[00m"
1425 else
1426 echo -e "\e[0;32mSUCCESS\e[00m"
1427 fi
1428 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001429}
1430
Raphael Moll70a86b02011-06-20 16:03:14 -07001431if [ "x$SHELL" != "x/bin/bash" ]; then
1432 case `ps -o command -p $$` in
1433 *bash*)
1434 ;;
1435 *)
1436 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1437 ;;
1438 esac
1439fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001440
1441# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001442for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1443 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001444do
1445 echo "including $f"
1446 . $f
1447done
1448unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001449
1450addcompletions