blob: 0223999b1c65e9a66f00d0635a12ad4c460bb86f [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.
10- mma: Builds all of the modules in the current directory, and their dependencies.
11- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070012- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070013- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070014- 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.
Raphael732936d2011-06-22 14:35:32 -0700127 export ANDROID_EABI_TOOLCHAIN=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200128 local ARCH=$(get_build_var TARGET_ARCH)
129 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400130 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700131 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400132 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
133 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800134 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200135 ;;
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800136 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700137 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800138 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700139 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200140 *)
141 echo "Can't find toolchain for unknown architecture: $ARCH"
142 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700143 ;;
144 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700145 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
146 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700147 fi
Raphael732936d2011-06-22 14:35:32 -0700148
Bruce Beare42ced6d2012-07-17 21:40:01 -0700149 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700150 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700151 arm)
Ben Cheng8bc4c432012-11-16 13:29:13 -0800152 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700153 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
154 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
155 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
156 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700157 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700158 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
159 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700160 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700161 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700162 ;;
163 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700164
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700165 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
166 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700167 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wangaa1c9b52012-11-26 20:51:59 -0800168 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
169 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800170
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500171 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900172 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500173 if [ -n "$JAVA_HOME" ]; then
174 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900175 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
176 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500177 fi
178
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800179 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700180 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
181 export OUT=$ANDROID_PRODUCT_OUT
182
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700183 unset ANDROID_HOST_OUT
184 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
185
Ben Cheng057fde12011-11-28 13:55:14 -0800186 # needed for processing samples collected by perf counters
187 unset OPROFILE_EVENTS_DIR
188 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
189
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800190 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700191 # TODO: fix the path
192 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
193}
194
195function printconfig()
196{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800197 T=$(gettop)
198 if [ ! "$T" ]; then
199 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
200 return
201 fi
202 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700203}
204
205function set_stuff_for_environment()
206{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800207 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500208 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800209 setpaths
210 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700211
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800212 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700213 # With this environment variable new GCC can apply colors to warnings/errors
214 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 -0700215}
216
217function set_sequence_number()
218{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700219 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700220}
221
222function settitle()
223{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800224 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700225 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700226 local product=$TARGET_PRODUCT
227 local variant=$TARGET_BUILD_VARIANT
228 local apps=$TARGET_BUILD_APPS
229 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700230 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700231 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700232 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700233 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800234 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700235}
236
Kenny Root52aa81c2011-07-15 11:07:06 -0700237function addcompletions()
238{
239 local T dir f
240
241 # Keep us from trying to run in something that isn't bash.
242 if [ -z "${BASH_VERSION}" ]; then
243 return
244 fi
245
246 # Keep us from trying to run in bash that's too old.
247 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
248 return
249 fi
250
251 dir="sdk/bash_completion"
252 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700253 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700254 echo "including $f"
255 . $f
256 done
257 fi
258}
259
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700260function choosetype()
261{
262 echo "Build type choices are:"
263 echo " 1. release"
264 echo " 2. debug"
265 echo
266
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800267 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700268 DEFAULT_NUM=1
269 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700270
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800271 export TARGET_BUILD_TYPE=
272 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700273 while [ -z $TARGET_BUILD_TYPE ]
274 do
275 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800276 if [ -z "$1" ] ; then
277 read ANSWER
278 else
279 echo $1
280 ANSWER=$1
281 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700282 case $ANSWER in
283 "")
284 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
285 ;;
286 1)
287 export TARGET_BUILD_TYPE=release
288 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800289 release)
290 export TARGET_BUILD_TYPE=release
291 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700292 2)
293 export TARGET_BUILD_TYPE=debug
294 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800295 debug)
296 export TARGET_BUILD_TYPE=debug
297 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700298 *)
299 echo
300 echo "I didn't understand your response. Please try again."
301 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700302 ;;
303 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800304 if [ -n "$1" ] ; then
305 break
306 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700307 done
308
309 set_stuff_for_environment
310}
311
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800312#
313# This function isn't really right: It chooses a TARGET_PRODUCT
314# based on the list of boards. Usually, that gets you something
315# that kinda works with a generic product, but really, you should
316# pick a product by name.
317#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700318function chooseproduct()
319{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700320 if [ "x$TARGET_PRODUCT" != x ] ; then
321 default_value=$TARGET_PRODUCT
322 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700323 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700324 fi
325
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800326 export TARGET_PRODUCT=
327 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700328 while [ -z "$TARGET_PRODUCT" ]
329 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700330 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 if [ -z "$1" ] ; then
332 read ANSWER
333 else
334 echo $1
335 ANSWER=$1
336 fi
337
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338 if [ -z "$ANSWER" ] ; then
339 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800340 else
341 if check_product $ANSWER
342 then
343 export TARGET_PRODUCT=$ANSWER
344 else
345 echo "** Not a valid product: $ANSWER"
346 fi
347 fi
348 if [ -n "$1" ] ; then
349 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700350 fi
351 done
352
353 set_stuff_for_environment
354}
355
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800356function choosevariant()
357{
358 echo "Variant choices are:"
359 local index=1
360 local v
361 for v in ${VARIANT_CHOICES[@]}
362 do
363 # The product name is the name of the directory containing
364 # the makefile we found, above.
365 echo " $index. $v"
366 index=$(($index+1))
367 done
368
369 local default_value=eng
370 local ANSWER
371
372 export TARGET_BUILD_VARIANT=
373 while [ -z "$TARGET_BUILD_VARIANT" ]
374 do
375 echo -n "Which would you like? [$default_value] "
376 if [ -z "$1" ] ; then
377 read ANSWER
378 else
379 echo $1
380 ANSWER=$1
381 fi
382
383 if [ -z "$ANSWER" ] ; then
384 export TARGET_BUILD_VARIANT=$default_value
385 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
386 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800387 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800388 fi
389 else
390 if check_variant $ANSWER
391 then
392 export TARGET_BUILD_VARIANT=$ANSWER
393 else
394 echo "** Not a valid variant: $ANSWER"
395 fi
396 fi
397 if [ -n "$1" ] ; then
398 break
399 fi
400 done
401}
402
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700403function choosecombo()
404{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700405 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700406
407 echo
408 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700409 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700410
411 echo
412 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700413 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800414
415 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700416 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800417 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700418}
419
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800420# Clear this variable. It will be built up again when the vendorsetup.sh
421# files are included at the end of this file.
422unset LUNCH_MENU_CHOICES
423function add_lunch_combo()
424{
425 local new_combo=$1
426 local c
427 for c in ${LUNCH_MENU_CHOICES[@]} ; do
428 if [ "$new_combo" = "$c" ] ; then
429 return
430 fi
431 done
432 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
433}
434
435# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700436add_lunch_combo aosp_arm-eng
437add_lunch_combo aosp_x86-eng
438add_lunch_combo aosp_mips-eng
Pavel Chupinfd82a492012-11-26 09:50:07 +0400439add_lunch_combo aosp_x86_64-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800440add_lunch_combo aosp_arm64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800441add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800442
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700443function print_lunch_menu()
444{
445 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446 echo
447 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700448 echo
449 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800450
451 local i=1
452 local choice
453 for choice in ${LUNCH_MENU_CHOICES[@]}
454 do
455 echo " $i. $choice"
456 i=$(($i+1))
457 done
458
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700459 echo
460}
461
462function lunch()
463{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800464 local answer
465
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700466 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800467 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468 else
469 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700470 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800471 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700472 fi
473
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800474 local selection=
475
476 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700477 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700478 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
480 then
481 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
482 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800483 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800484 fi
485 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
486 then
487 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700488 fi
489
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490 if [ -z "$selection" ]
491 then
492 echo
493 echo "Invalid lunch combo: $answer"
494 return 1
495 fi
496
Joe Onoratoda12daf2010-06-09 18:18:31 -0700497 export TARGET_BUILD_APPS=
498
Jeff Browne33ba4c2011-07-11 22:11:46 -0700499 local product=$(echo -n $selection | sed -e "s/-.*$//")
500 check_product $product
501 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800502 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700503 echo
504 echo "** Don't have a product spec for: '$product'"
505 echo "** Do you have the right repo manifest?"
506 product=
507 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800508
Jeff Browne33ba4c2011-07-11 22:11:46 -0700509 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
510 check_variant $variant
511 if [ $? -ne 0 ]
512 then
513 echo
514 echo "** Invalid variant: '$variant'"
515 echo "** Must be one of ${VARIANT_CHOICES[@]}"
516 variant=
517 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800518
Jeff Browne33ba4c2011-07-11 22:11:46 -0700519 if [ -z "$product" -o -z "$variant" ]
520 then
521 echo
522 return 1
523 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800524
Jeff Browne33ba4c2011-07-11 22:11:46 -0700525 export TARGET_PRODUCT=$product
526 export TARGET_BUILD_VARIANT=$variant
527 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700528
529 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700531 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800532 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700533}
534
Jeff Davidson513d7a42010-08-02 10:00:44 -0700535# Tab completion for lunch.
536function _lunch()
537{
538 local cur prev opts
539 COMPREPLY=()
540 cur="${COMP_WORDS[COMP_CWORD]}"
541 prev="${COMP_WORDS[COMP_CWORD-1]}"
542
543 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
544 return 0
545}
546complete -F _lunch lunch
547
Joe Onoratoda12daf2010-06-09 18:18:31 -0700548# Configures the build to build unbundled apps.
549# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
550function tapas()
551{
Ying Wangf05c4f72013-01-31 11:16:57 -0800552 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600553 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800554 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 -0700555
Ying Wang67f02922012-08-22 10:25:20 -0700556 if [ $(echo $arch | wc -w) -gt 1 ]; then
557 echo "tapas: Error: Multiple build archs supplied: $arch"
558 return
559 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700560 if [ $(echo $variant | wc -w) -gt 1 ]; then
561 echo "tapas: Error: Multiple build variants supplied: $variant"
562 return
563 fi
Ying Wang67f02922012-08-22 10:25:20 -0700564
565 local product=full
566 case $arch in
567 x86) product=full_x86;;
568 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800569 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700570 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700571 if [ -z "$variant" ]; then
572 variant=eng
573 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700574 if [ -z "$apps" ]; then
575 apps=all
576 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700577
Ying Wang67f02922012-08-22 10:25:20 -0700578 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700579 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700580 export TARGET_BUILD_TYPE=release
581 export TARGET_BUILD_APPS=$apps
582
583 set_stuff_for_environment
584 printconfig
585}
586
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700587function gettop
588{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
591 echo $TOP
592 else
593 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800594 # The following circumlocution (repeated below as well) ensures
595 # that we record the true directory name and not one that is
596 # faked up with symlink names.
597 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700598 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800599 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700600 T=
601 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800602 \cd ..
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800603 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 done
Ying Wang9cd17642012-12-13 10:52:07 -0800605 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700606 if [ -f "$T/$TOPFILE" ]; then
607 echo $T
608 fi
609 fi
610 fi
611}
612
Andrew Hsieh906cb782013-09-10 17:37:14 +0800613# Return driver for "make", if any (eg. static analyzer)
614function getdriver()
615{
616 local T="$1"
617 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
618 if [ -n "$WITH_STATIC_ANALYZER" ]; then
619 echo "\
620$T/prebuilts/clang/linux-x86/host/3.3/tools/scan-build/scan-build \
Andrew Hsiehaf738a42013-09-13 15:49:39 +0800621--use-analyzer $T/prebuilts/clang/linux-x86/host/3.3/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800622--status-bugs \
623--top=$T"
624 fi
625}
626
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700627function m()
628{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800629 local T=$(gettop)
630 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700631 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800632 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700633 else
634 echo "Couldn't locate the top of the tree. Try setting TOP."
635 fi
636}
637
638function findmakefile()
639{
640 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800641 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700642 T=
643 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700644 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700645 if [ -f "$T/Android.mk" ]; then
646 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800647 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700648 return
649 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800650 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651 done
Ying Wang9cd17642012-12-13 10:52:07 -0800652 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653}
654
655function mm()
656{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800657 local T=$(gettop)
658 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659 # If we're sitting in the root of the build tree, just do a
660 # normal make.
661 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800662 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700663 else
664 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800665 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700666 local MODULES=
667 local GET_INSTALL_PATH=
668 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700669 # Remove the path to top as the makefilepath needs to be relative
670 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700671 if [ ! "$T" ]; then
672 echo "Couldn't locate the top of the tree. Try setting TOP."
673 elif [ ! "$M" ]; then
674 echo "Couldn't locate a makefile from the current directory."
675 else
Ying Wanga7deb082013-08-16 13:24:47 -0700676 for ARG in $@; do
677 case $ARG in
678 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
679 esac
680 done
681 if [ -n "$GET_INSTALL_PATH" ]; then
682 MODULES=
683 ARGS=GET-INSTALL-PATH
684 else
685 MODULES=all_modules
686 ARGS=$@
687 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700688 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 -0700689 fi
690 fi
691}
692
693function mmm()
694{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800695 local T=$(gettop)
696 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700697 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800698 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800699 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800700 local ARGS=
701 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700702 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800703 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
704 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
705 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800706 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
707 if [ "$MODULES" = "" ]; then
708 MODULES=all_modules
709 fi
710 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700711 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700712 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
713 local TO_CHOP=`expr $TO_CHOP + 1`
714 local START=`PWD= /bin/pwd`
715 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700716 if [ "$MFILE" = "" ] ; then
717 MFILE=$DIR/Android.mk
718 else
719 MFILE=$MFILE/$DIR/Android.mk
720 fi
721 MAKEFILE="$MAKEFILE $MFILE"
722 else
Ying Wanga7deb082013-08-16 13:24:47 -0700723 case $DIR in
724 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
725 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
726 *) echo "No Android.mk in $DIR."; return 1;;
727 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700728 fi
729 done
Ying Wanga7deb082013-08-16 13:24:47 -0700730 if [ -n "$GET_INSTALL_PATH" ]; then
731 ARGS=$GET_INSTALL_PATH
732 MODULES=
733 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800734 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 -0700735 else
736 echo "Couldn't locate the top of the tree. Try setting TOP."
737 fi
738}
739
Ying Wangb607f7b2013-02-08 18:01:04 -0800740function mma()
741{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800742 local T=$(gettop)
743 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800744 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800745 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800746 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800747 if [ ! "$T" ]; then
748 echo "Couldn't locate the top of the tree. Try setting TOP."
749 fi
750 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800751 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800752 fi
753}
754
755function mmma()
756{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800757 local T=$(gettop)
758 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800759 if [ "$T" ]; then
760 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
761 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
762 local MY_PWD=`PWD= /bin/pwd`
763 if [ "$MY_PWD" = "$T" ]; then
764 MY_PWD=
765 else
766 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
767 fi
768 local DIR=
769 local MODULE_PATHS=
770 local ARGS=
771 for DIR in $DIRS ; do
772 if [ -d $DIR ]; then
773 if [ "$MY_PWD" = "" ]; then
774 MODULE_PATHS="$MODULE_PATHS $DIR"
775 else
776 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
777 fi
778 else
779 case $DIR in
780 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
781 *) echo "Couldn't find directory $DIR"; return 1;;
782 esac
783 fi
784 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800785 $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 -0800786 else
787 echo "Couldn't locate the top of the tree. Try setting TOP."
788 fi
789}
790
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791function croot()
792{
793 T=$(gettop)
794 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800795 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700796 else
797 echo "Couldn't locate the top of the tree. Try setting TOP."
798 fi
799}
800
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700801function cproj()
802{
803 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700804 local HERE=$PWD
805 T=
806 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
807 T=$PWD
808 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800809 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700810 return
811 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800812 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700813 done
Ying Wang9cd17642012-12-13 10:52:07 -0800814 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700815 echo "can't find Android.mk"
816}
817
Daniel Sandler47e0a882013-07-30 13:23:52 -0400818# simplified version of ps; output in the form
819# <pid> <procname>
820function qpid() {
821 local prepend=''
822 local append=''
823 if [ "$1" = "--exact" ]; then
824 prepend=' '
825 append='$'
826 shift
827 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
828 echo "usage: qpid [[--exact] <process name|pid>"
829 return 255
830 fi
831
832 local EXE="$1"
833 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700834 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400835 else
836 adb shell ps \
837 | tr -d '\r' \
838 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
839 fi
840}
841
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700842function pid()
843{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400844 local prepend=''
845 local append=''
846 if [ "$1" = "--exact" ]; then
847 prepend=' '
848 append='$'
849 shift
850 fi
851 local EXE="$1"
852 if [ "$EXE" ] ; then
853 local PID=`adb shell ps \
854 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700855 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400856 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
857 echo "$PID"
858 else
859 echo "usage: pid [--exact] <process name>"
860 return 255
861 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700862}
863
Christopher Tate744ee802009-11-12 15:33:08 -0800864# systemstack - dump the current stack trace of all threads in the system process
865# to the usual ANR traces file
866function systemstack()
867{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800868 stacks system_server
869}
870
871function stacks()
872{
873 if [[ $1 =~ ^[0-9]+$ ]] ; then
874 local PID="$1"
875 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700876 local PIDLIST="$(pid $1)"
877 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
878 local PID="$PIDLIST"
879 elif [ "$PIDLIST" ] ; then
880 echo "more than one process: $1"
881 else
882 echo "no such process: $1"
883 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800884 else
885 echo "usage: stacks [pid|process name]"
886 fi
887
888 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700889 # Determine whether the process is native
890 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
891 # Dump stacks of Dalvik process
892 local TRACES=/data/anr/traces.txt
893 local ORIG=/data/anr/traces.orig
894 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800895
Jeff Brownb12c2e52013-08-19 15:14:16 -0700896 # Keep original traces to avoid clobbering
897 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800898
Jeff Brownb12c2e52013-08-19 15:14:16 -0700899 # Make sure we have a usable file
900 adb shell touch $TRACES
901 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800902
Jeff Brownb12c2e52013-08-19 15:14:16 -0700903 # Dump stacks and wait for dump to finish
904 adb shell kill -3 $PID
905 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800906
Jeff Brownb12c2e52013-08-19 15:14:16 -0700907 # Restore original stacks, and show current output
908 adb shell mv $TRACES $TMP
909 adb shell mv $ORIG $TRACES
910 adb shell cat $TMP
911 else
912 # Dump stacks of native process
913 adb shell debuggerd -b $PID
914 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800915 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800916}
917
John Michelau50200252012-11-09 11:48:04 -0600918function gdbwrapper()
919{
920 $ANDROID_TOOLCHAIN/$GDB -x "$@"
921}
922
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700923function gdbclient()
924{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800925 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
926 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
927 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
928 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
929 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800930 local ARCH=$(get_build_var TARGET_ARCH)
931 local GDB
932 case "$ARCH" in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400933 x86) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800934 arm) GDB=arm-linux-androideabi-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700935 mips) GDB=mipsel-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800936 *) echo "Unknown arch $ARCH"; return 1;;
937 esac
938
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700939 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
940 local EXE="$1"
941 if [ "$EXE" ] ; then
942 EXE=$1
943 else
944 EXE="app_process"
945 fi
946
947 local PORT="$2"
948 if [ "$PORT" ] ; then
949 PORT=$2
950 else
951 PORT=":5039"
952 fi
953
Chris Craik20c136a2012-11-09 18:02:19 -0800954 local PID="$3"
955 if [ "$PID" ] ; then
956 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700957 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800958 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
959 # that likely didn't work because of returning multiple processes
960 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -0700961 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -0800962 if [[ ! "$PID" =~ ^[0-9]+$ ]]
963 then
964 echo "Couldn't resolve '$3' to single PID"
965 return 1
966 else
967 echo ""
968 echo "WARNING: multiple processes matching '$3' observed, using root process"
969 echo ""
970 fi
971 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -0700972 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700973 adb forward "tcp$PORT" "tcp$PORT"
974 adb shell gdbserver $PORT --attach $PID &
975 sleep 2
976 else
977 echo ""
978 echo "If you haven't done so already, do this first on the device:"
979 echo " gdbserver $PORT /system/bin/$EXE"
980 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -0800981 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700982 echo ""
983 fi
984
985 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Chris Dearman6858d512012-02-02 14:16:52 -0800986 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"
Ben Cheng72398162013-06-24 14:36:21 -0700987 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700988 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
989 echo >>"$OUT_ROOT/gdbclient.cmds" ""
990
John Michelau50200252012-11-09 11:48:04 -0600991 gdbwrapper "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700992 else
993 echo "Unable to determine build system output dir."
994 fi
995
996}
997
998case `uname -s` in
999 Darwin)
1000 function sgrep()
1001 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001002 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 -07001003 }
1004
1005 ;;
1006 *)
1007 function sgrep()
1008 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001009 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 -07001010 }
1011 ;;
1012esac
1013
Raghu Gandham8da43102012-07-25 19:57:22 -07001014function gettargetarch
1015{
1016 get_build_var TARGET_ARCH
1017}
1018
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001019function ggrep()
1020{
1021 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1022}
1023
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001024function jgrep()
1025{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001026 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 -07001027}
1028
1029function cgrep()
1030{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001031 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 -07001032}
1033
1034function resgrep()
1035{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001036 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 -07001037}
1038
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001039function mangrep()
1040{
1041 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1042}
1043
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001044function sepgrep()
1045{
1046 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 "$@"
1047}
1048
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001049case `uname -s` in
1050 Darwin)
1051 function mgrep()
1052 {
Ying Wang324c2b22012-08-17 15:03:20 -07001053 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 -07001054 }
1055
1056 function treegrep()
1057 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001058 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 -07001059 }
1060
1061 ;;
1062 *)
1063 function mgrep()
1064 {
Ying Wang324c2b22012-08-17 15:03:20 -07001065 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 -07001066 }
1067
1068 function treegrep()
1069 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001070 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 -07001071 }
1072
1073 ;;
1074esac
1075
1076function getprebuilt
1077{
1078 get_abs_build_var ANDROID_PREBUILTS
1079}
1080
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001081function tracedmdump()
1082{
1083 T=$(gettop)
1084 if [ ! "$T" ]; then
1085 echo "Couldn't locate the top of the tree. Try setting TOP."
1086 return
1087 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001088 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001089 local arch=$(gettargetarch)
1090 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001091
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001092 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001093 if [ ! "$TRACE" ] ; then
1094 echo "usage: tracedmdump tracename"
1095 return
1096 fi
1097
Jack Veenstra60116fc2009-04-09 18:12:34 -07001098 if [ ! -r "$KERNEL" ] ; then
1099 echo "Error: cannot find kernel: '$KERNEL'"
1100 return
1101 fi
1102
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001103 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001104 if [ "$BASETRACE" = "$TRACE" ] ; then
1105 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1106 fi
1107
1108 echo "post-processing traces..."
1109 rm -f $TRACE/qtrace.dexlist
1110 post_trace $TRACE
1111 if [ $? -ne 0 ]; then
1112 echo "***"
1113 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1114 echo "***"
1115 return
1116 fi
1117 echo "generating dexlist output..."
1118 /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
1119 echo "generating dmtrace data..."
1120 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1121 echo "generating html file..."
1122 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1123 echo "done, see $TRACE/dmtrace.html for details"
1124 echo "or run:"
1125 echo " traceview $TRACE/dmtrace"
1126}
1127
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001128# communicate with a running device or emulator, set up necessary state,
1129# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001130function runhat()
1131{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001132 # process standard adb options
1133 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001134 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001135 adbTarget=$1
1136 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001137 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001138 adbTarget="$1 $2"
1139 shift 2
1140 fi
1141 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001142 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001143
1144 # runhat options
1145 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001146
1147 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001148 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001149 return
1150 fi
1151
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001152 # confirm hat is available
1153 if [ -z $(which hat) ]; then
1154 echo "hat is not available in this configuration."
1155 return
1156 fi
1157
Andy McFaddenb6289852010-07-12 08:00:19 -07001158 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001159 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001160 local devFile=$sdcard/hprof-$targetPid
1161 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001162 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001163 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001164 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001165 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001166 echo -n "> "
1167 read
1168
The Android Open Source Project88b60792009-03-03 19:28:42 -08001169 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001170
The Android Open Source Project88b60792009-03-03 19:28:42 -08001171 echo "Retrieving file $devFile..."
1172 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001173
The Android Open Source Project88b60792009-03-03 19:28:42 -08001174 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001175
The Android Open Source Project88b60792009-03-03 19:28:42 -08001176 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001177 echo "View the output by pointing your browser at http://localhost:7000/"
1178 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001179 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001180}
1181
1182function getbugreports()
1183{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001184 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001185
1186 if [ ! "$reports" ]; then
1187 echo "Could not locate any bugreports."
1188 return
1189 fi
1190
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001191 local report
1192 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001193 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001194 echo "/sdcard/bugreports/${report}"
1195 adb pull /sdcard/bugreports/${report} ${report}
1196 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001197 done
1198}
1199
Victoria Lease1b296b42012-08-21 15:44:06 -07001200function getsdcardpath()
1201{
1202 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1203}
1204
1205function getscreenshotpath()
1206{
1207 echo "$(getsdcardpath)/Pictures/Screenshots"
1208}
1209
1210function getlastscreenshot()
1211{
1212 local screenshot_path=$(getscreenshotpath)
1213 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1214 if [ "$screenshot" = "" ]; then
1215 echo "No screenshots found."
1216 return
1217 fi
1218 echo "${screenshot}"
1219 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1220}
1221
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001222function startviewserver()
1223{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001224 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001225 if [ $# -gt 0 ]; then
1226 port=$1
1227 fi
1228 adb shell service call window 1 i32 $port
1229}
1230
1231function stopviewserver()
1232{
1233 adb shell service call window 2
1234}
1235
1236function isviewserverstarted()
1237{
1238 adb shell service call window 3
1239}
1240
Romain Guyb84049a2010-10-04 16:56:11 -07001241function key_home()
1242{
1243 adb shell input keyevent 3
1244}
1245
1246function key_back()
1247{
1248 adb shell input keyevent 4
1249}
1250
1251function key_menu()
1252{
1253 adb shell input keyevent 82
1254}
1255
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001256function smoketest()
1257{
1258 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1259 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1260 return
1261 fi
1262 T=$(gettop)
1263 if [ ! "$T" ]; then
1264 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1265 return
1266 fi
1267
Ying Wang9cd17642012-12-13 10:52:07 -08001268 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001269 adb uninstall com.android.smoketest > /dev/null &&
1270 adb uninstall com.android.smoketest.tests > /dev/null &&
1271 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1272 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1273 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1274}
1275
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001276# simple shortcut to the runtest command
1277function runtest()
1278{
1279 T=$(gettop)
1280 if [ ! "$T" ]; then
1281 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1282 return
1283 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001284 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001285}
1286
The Android Open Source Project88b60792009-03-03 19:28:42 -08001287function godir () {
1288 if [[ -z "$1" ]]; then
1289 echo "Usage: godir <regex>"
1290 return
1291 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001292 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001293 if [[ ! -f $T/filelist ]]; then
1294 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001295 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001296 echo " Done"
1297 echo ""
1298 fi
1299 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001300 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001301 if [[ ${#lines[@]} = 0 ]]; then
1302 echo "Not found"
1303 return
1304 fi
1305 local pathname
1306 local choice
1307 if [[ ${#lines[@]} > 1 ]]; then
1308 while [[ -z "$pathname" ]]; do
1309 local index=1
1310 local line
1311 for line in ${lines[@]}; do
1312 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001313 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001314 done
1315 echo
1316 echo -n "Select one: "
1317 unset choice
1318 read choice
1319 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1320 echo "Invalid choice"
1321 continue
1322 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001323 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001324 done
1325 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001326 pathname=${lines[0]}
1327 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001328 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001329}
1330
Narayan Kamath9260bba2014-01-17 10:05:25 +00001331# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1332#
1333# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1334# For some reason, installing the JDK doesn't make it show up in the
1335# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001336function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001337 # Clear the existing JAVA_HOME value if we set it ourselves, so that
1338 # we can reset it later, depending on the value of EXPERIMENTAL_USE_JAVA7.
1339 #
1340 # If we don't do this, the JAVA_HOME value set by the first call to
1341 # build/envsetup.sh will persist forever.
1342 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1343 export JAVA_HOME=""
1344 fi
1345
Andy McFaddenbd960942010-06-24 12:52:51 -07001346 if [ ! "$JAVA_HOME" ]; then
Narayan Kamath9260bba2014-01-17 10:05:25 +00001347 if [ ! "$EXPERIMENTAL_USE_JAVA7" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001348 case `uname -s` in
1349 Darwin)
1350 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1351 ;;
1352 *)
1353 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1354 ;;
1355 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001356 else
1357 case `uname -s` in
1358 Darwin)
1359 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
1360 ;;
1361 *)
1362 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1363 ;;
1364 esac
1365 fi
1366
1367 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1368 # we can change it on the next envsetup.sh, if required.
1369 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001370 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001371}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001372
Alex Rayf0d08eb2013-03-08 15:15:06 -08001373# Print colored exit condition
1374function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001375 "$@"
1376 local retval=$?
1377 if [ $retval -ne 0 ]
1378 then
1379 echo -e "\e[0;31mFAILURE\e[00m"
1380 else
1381 echo -e "\e[0;32mSUCCESS\e[00m"
1382 fi
1383 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001384}
1385
Raphael Moll70a86b02011-06-20 16:03:14 -07001386if [ "x$SHELL" != "x/bin/bash" ]; then
1387 case `ps -o command -p $$` in
1388 *bash*)
1389 ;;
1390 *)
1391 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1392 ;;
1393 esac
1394fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001395
1396# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001397for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1398 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001399do
1400 echo "including $f"
1401 . $f
1402done
1403unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001404
1405addcompletions