blob: 26db504fc5cecd210a6761c346e6a4bb90412f52 [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.
13- jgrep: Greps on all local Java files.
14- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080015- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070016
17Look at the source to view more functions. The complete list is:
18EOF
19 T=$(gettop)
20 local A
21 A=""
22 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
23 A="$A $i"
24 done
25 echo $A
26}
27
28# Get the value of a build variable as an absolute path.
29function get_abs_build_var()
30{
31 T=$(gettop)
32 if [ ! "$T" ]; then
33 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
34 return
35 fi
Ying Wang9cd17642012-12-13 10:52:07 -080036 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Andrew Boie6905e212013-12-19 13:21:46 -080037 make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070038}
39
40# Get the exact value of a build variable.
41function get_build_var()
42{
43 T=$(gettop)
44 if [ ! "$T" ]; then
45 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
46 return
47 fi
Andrew Boie6905e212013-12-19 13:21:46 -080048 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
49 make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080050}
51
52# check to see if the supplied product is one we can build
53function check_product()
54{
55 T=$(gettop)
56 if [ ! "$T" ]; then
57 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
58 return
59 fi
60 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Jeff Browne33ba4c2011-07-11 22:11:46 -070061 TARGET_PRODUCT=$1 \
62 TARGET_BUILD_VARIANT= \
63 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070064 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080065 get_build_var TARGET_DEVICE > /dev/null
66 # hide successful answers, but allow the errors to show
67}
68
69VARIANT_CHOICES=(user userdebug eng)
70
71# check to see if the supplied variant is valid
72function check_variant()
73{
74 for v in ${VARIANT_CHOICES[@]}
75 do
76 if [ "$v" = "$1" ]
77 then
78 return 0
79 fi
80 done
81 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070082}
83
84function setpaths()
85{
86 T=$(gettop)
87 if [ ! "$T" ]; then
88 echo "Couldn't locate the top of the tree. Try setting TOP."
89 return
90 fi
91
92 ##################################################################
93 # #
94 # Read me before you modify this code #
95 # #
96 # This function sets ANDROID_BUILD_PATHS to what it is adding #
97 # to PATH, and the next time it is run, it removes that from #
98 # PATH. This is required so lunch can be run more than once #
99 # and still have working paths. #
100 # #
101 ##################################################################
102
Raphael Mollc639c782011-06-20 17:25:01 -0700103 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
104 # due to "C:\Program Files" being in the path.
105
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700106 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700107 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700108 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
109 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700110 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700111 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800112 # strip leading ':', if any
113 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500114 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700115
116 # and in with the new
117 CODE_REVIEWS=
118 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700119 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700120
Ben Cheng8bc4c432012-11-16 13:29:13 -0800121 # defined in core/config.mk
122 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800123 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800124
Raphael Mollc639c782011-06-20 17:25:01 -0700125 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Raphael732936d2011-06-22 14:35:32 -0700126 export ANDROID_EABI_TOOLCHAIN=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200127 local ARCH=$(get_build_var TARGET_ARCH)
128 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400129 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700130 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400131 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
132 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800133 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200134 ;;
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800135 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700136 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800137 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700138 ;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000139 mips64) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
140 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200141 *)
142 echo "Can't find toolchain for unknown architecture: $ARCH"
143 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700144 ;;
145 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700146 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
147 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700148 fi
Raphael732936d2011-06-22 14:35:32 -0700149
Bruce Beare42ced6d2012-07-17 21:40:01 -0700150 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700151 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700152 arm)
Ben Cheng8bc4c432012-11-16 13:29:13 -0800153 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700154 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
155 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
156 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
157 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700158 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700159 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
160 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700161 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700162 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700163 ;;
164 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700165
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700166 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
167 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700168 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wangaa1c9b52012-11-26 20:51:59 -0800169 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
170 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800171
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500172 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900173 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500174 if [ -n "$JAVA_HOME" ]; then
175 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900176 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
177 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500178 fi
179
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800180 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700181 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
182 export OUT=$ANDROID_PRODUCT_OUT
183
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700184 unset ANDROID_HOST_OUT
185 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
186
Ben Cheng057fde12011-11-28 13:55:14 -0800187 # needed for processing samples collected by perf counters
188 unset OPROFILE_EVENTS_DIR
189 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
190
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800191 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700192 # TODO: fix the path
193 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
194}
195
196function printconfig()
197{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800198 T=$(gettop)
199 if [ ! "$T" ]; then
200 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
201 return
202 fi
203 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700204}
205
206function set_stuff_for_environment()
207{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800208 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500209 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800210 setpaths
211 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700212
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800213 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700214 # With this environment variable new GCC can apply colors to warnings/errors
215 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 -0700216}
217
218function set_sequence_number()
219{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700220 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700221}
222
223function settitle()
224{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800225 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700226 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700227 local product=$TARGET_PRODUCT
228 local variant=$TARGET_BUILD_VARIANT
229 local apps=$TARGET_BUILD_APPS
230 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700231 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700232 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700233 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700234 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800235 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700236}
237
Kenny Root52aa81c2011-07-15 11:07:06 -0700238function addcompletions()
239{
240 local T dir f
241
242 # Keep us from trying to run in something that isn't bash.
243 if [ -z "${BASH_VERSION}" ]; then
244 return
245 fi
246
247 # Keep us from trying to run in bash that's too old.
248 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
249 return
250 fi
251
252 dir="sdk/bash_completion"
253 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700254 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700255 echo "including $f"
256 . $f
257 done
258 fi
259}
260
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700261function choosetype()
262{
263 echo "Build type choices are:"
264 echo " 1. release"
265 echo " 2. debug"
266 echo
267
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800268 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700269 DEFAULT_NUM=1
270 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700271
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800272 export TARGET_BUILD_TYPE=
273 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700274 while [ -z $TARGET_BUILD_TYPE ]
275 do
276 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800277 if [ -z "$1" ] ; then
278 read ANSWER
279 else
280 echo $1
281 ANSWER=$1
282 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700283 case $ANSWER in
284 "")
285 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
286 ;;
287 1)
288 export TARGET_BUILD_TYPE=release
289 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800290 release)
291 export TARGET_BUILD_TYPE=release
292 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700293 2)
294 export TARGET_BUILD_TYPE=debug
295 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800296 debug)
297 export TARGET_BUILD_TYPE=debug
298 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700299 *)
300 echo
301 echo "I didn't understand your response. Please try again."
302 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700303 ;;
304 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800305 if [ -n "$1" ] ; then
306 break
307 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700308 done
309
310 set_stuff_for_environment
311}
312
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800313#
314# This function isn't really right: It chooses a TARGET_PRODUCT
315# based on the list of boards. Usually, that gets you something
316# that kinda works with a generic product, but really, you should
317# pick a product by name.
318#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319function chooseproduct()
320{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321 if [ "x$TARGET_PRODUCT" != x ] ; then
322 default_value=$TARGET_PRODUCT
323 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700324 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325 fi
326
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800327 export TARGET_PRODUCT=
328 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700329 while [ -z "$TARGET_PRODUCT" ]
330 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700331 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332 if [ -z "$1" ] ; then
333 read ANSWER
334 else
335 echo $1
336 ANSWER=$1
337 fi
338
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339 if [ -z "$ANSWER" ] ; then
340 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800341 else
342 if check_product $ANSWER
343 then
344 export TARGET_PRODUCT=$ANSWER
345 else
346 echo "** Not a valid product: $ANSWER"
347 fi
348 fi
349 if [ -n "$1" ] ; then
350 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700351 fi
352 done
353
354 set_stuff_for_environment
355}
356
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800357function choosevariant()
358{
359 echo "Variant choices are:"
360 local index=1
361 local v
362 for v in ${VARIANT_CHOICES[@]}
363 do
364 # The product name is the name of the directory containing
365 # the makefile we found, above.
366 echo " $index. $v"
367 index=$(($index+1))
368 done
369
370 local default_value=eng
371 local ANSWER
372
373 export TARGET_BUILD_VARIANT=
374 while [ -z "$TARGET_BUILD_VARIANT" ]
375 do
376 echo -n "Which would you like? [$default_value] "
377 if [ -z "$1" ] ; then
378 read ANSWER
379 else
380 echo $1
381 ANSWER=$1
382 fi
383
384 if [ -z "$ANSWER" ] ; then
385 export TARGET_BUILD_VARIANT=$default_value
386 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
387 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800388 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800389 fi
390 else
391 if check_variant $ANSWER
392 then
393 export TARGET_BUILD_VARIANT=$ANSWER
394 else
395 echo "** Not a valid variant: $ANSWER"
396 fi
397 fi
398 if [ -n "$1" ] ; then
399 break
400 fi
401 done
402}
403
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700404function choosecombo()
405{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700406 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700407
408 echo
409 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700410 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700411
412 echo
413 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700414 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800415
416 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700417 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800418 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700419}
420
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800421# Clear this variable. It will be built up again when the vendorsetup.sh
422# files are included at the end of this file.
423unset LUNCH_MENU_CHOICES
424function add_lunch_combo()
425{
426 local new_combo=$1
427 local c
428 for c in ${LUNCH_MENU_CHOICES[@]} ; do
429 if [ "$new_combo" = "$c" ] ; then
430 return
431 fi
432 done
433 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
434}
435
436# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700437add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800438add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000439add_lunch_combo aosp_mips-eng
440add_lunch_combo aosp_x86-eng
441add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800442add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800443
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444function print_lunch_menu()
445{
446 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700447 echo
448 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449 echo
450 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800451
452 local i=1
453 local choice
454 for choice in ${LUNCH_MENU_CHOICES[@]}
455 do
456 echo " $i. $choice"
457 i=$(($i+1))
458 done
459
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700460 echo
461}
462
463function lunch()
464{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800465 local answer
466
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700467 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800468 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700469 else
470 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700471 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 fi
474
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800475 local selection=
476
477 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700479 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
481 then
482 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
483 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800484 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800485 fi
486 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
487 then
488 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700489 fi
490
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800491 if [ -z "$selection" ]
492 then
493 echo
494 echo "Invalid lunch combo: $answer"
495 return 1
496 fi
497
Joe Onoratoda12daf2010-06-09 18:18:31 -0700498 export TARGET_BUILD_APPS=
499
Jeff Browne33ba4c2011-07-11 22:11:46 -0700500 local product=$(echo -n $selection | sed -e "s/-.*$//")
501 check_product $product
502 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800503 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700504 echo
505 echo "** Don't have a product spec for: '$product'"
506 echo "** Do you have the right repo manifest?"
507 product=
508 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800509
Jeff Browne33ba4c2011-07-11 22:11:46 -0700510 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
511 check_variant $variant
512 if [ $? -ne 0 ]
513 then
514 echo
515 echo "** Invalid variant: '$variant'"
516 echo "** Must be one of ${VARIANT_CHOICES[@]}"
517 variant=
518 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800519
Jeff Browne33ba4c2011-07-11 22:11:46 -0700520 if [ -z "$product" -o -z "$variant" ]
521 then
522 echo
523 return 1
524 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800525
Jeff Browne33ba4c2011-07-11 22:11:46 -0700526 export TARGET_PRODUCT=$product
527 export TARGET_BUILD_VARIANT=$variant
528 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700529
530 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800531
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700532 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800533 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700534}
535
Jeff Davidson513d7a42010-08-02 10:00:44 -0700536# Tab completion for lunch.
537function _lunch()
538{
539 local cur prev opts
540 COMPREPLY=()
541 cur="${COMP_WORDS[COMP_CWORD]}"
542 prev="${COMP_WORDS[COMP_CWORD-1]}"
543
544 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
545 return 0
546}
547complete -F _lunch lunch
548
Joe Onoratoda12daf2010-06-09 18:18:31 -0700549# Configures the build to build unbundled apps.
550# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
551function tapas()
552{
Ying Wangf05c4f72013-01-31 11:16:57 -0800553 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600554 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800555 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 -0700556
Ying Wang67f02922012-08-22 10:25:20 -0700557 if [ $(echo $arch | wc -w) -gt 1 ]; then
558 echo "tapas: Error: Multiple build archs supplied: $arch"
559 return
560 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700561 if [ $(echo $variant | wc -w) -gt 1 ]; then
562 echo "tapas: Error: Multiple build variants supplied: $variant"
563 return
564 fi
Ying Wang67f02922012-08-22 10:25:20 -0700565
566 local product=full
567 case $arch in
568 x86) product=full_x86;;
569 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800570 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700571 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700572 if [ -z "$variant" ]; then
573 variant=eng
574 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700575 if [ -z "$apps" ]; then
576 apps=all
577 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700578
Ying Wang67f02922012-08-22 10:25:20 -0700579 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700580 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700581 export TARGET_BUILD_TYPE=release
582 export TARGET_BUILD_APPS=$apps
583
584 set_stuff_for_environment
585 printconfig
586}
587
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700588function gettop
589{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
592 echo $TOP
593 else
594 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800595 # The following circumlocution (repeated below as well) ensures
596 # that we record the true directory name and not one that is
597 # faked up with symlink names.
598 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700599 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800600 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700601 T=
602 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800603 \cd ..
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800604 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700605 done
Ying Wang9cd17642012-12-13 10:52:07 -0800606 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700607 if [ -f "$T/$TOPFILE" ]; then
608 echo $T
609 fi
610 fi
611 fi
612}
613
Andrew Hsieh906cb782013-09-10 17:37:14 +0800614# Return driver for "make", if any (eg. static analyzer)
615function getdriver()
616{
617 local T="$1"
618 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
619 if [ -n "$WITH_STATIC_ANALYZER" ]; then
620 echo "\
621$T/prebuilts/clang/linux-x86/host/3.3/tools/scan-build/scan-build \
Andrew Hsiehaf738a42013-09-13 15:49:39 +0800622--use-analyzer $T/prebuilts/clang/linux-x86/host/3.3/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800623--status-bugs \
624--top=$T"
625 fi
626}
627
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700628function m()
629{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800630 local T=$(gettop)
631 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700632 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800633 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700634 else
635 echo "Couldn't locate the top of the tree. Try setting TOP."
636 fi
637}
638
639function findmakefile()
640{
641 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800642 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700643 T=
644 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700645 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700646 if [ -f "$T/Android.mk" ]; then
647 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800648 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649 return
650 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800651 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700652 done
Ying Wang9cd17642012-12-13 10:52:07 -0800653 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700654}
655
656function mm()
657{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800658 local T=$(gettop)
659 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700660 # If we're sitting in the root of the build tree, just do a
661 # normal make.
662 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800663 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700664 else
665 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800666 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700667 local MODULES=
668 local GET_INSTALL_PATH=
669 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700670 # Remove the path to top as the makefilepath needs to be relative
671 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672 if [ ! "$T" ]; then
673 echo "Couldn't locate the top of the tree. Try setting TOP."
674 elif [ ! "$M" ]; then
675 echo "Couldn't locate a makefile from the current directory."
676 else
Ying Wanga7deb082013-08-16 13:24:47 -0700677 for ARG in $@; do
678 case $ARG in
679 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
680 esac
681 done
682 if [ -n "$GET_INSTALL_PATH" ]; then
683 MODULES=
684 ARGS=GET-INSTALL-PATH
685 else
686 MODULES=all_modules
687 ARGS=$@
688 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700689 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 -0700690 fi
691 fi
692}
693
694function mmm()
695{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800696 local T=$(gettop)
697 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700698 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800699 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800700 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800701 local ARGS=
702 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700703 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800704 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
705 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
706 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800707 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
708 if [ "$MODULES" = "" ]; then
709 MODULES=all_modules
710 fi
711 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700712 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700713 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
714 local TO_CHOP=`expr $TO_CHOP + 1`
715 local START=`PWD= /bin/pwd`
716 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700717 if [ "$MFILE" = "" ] ; then
718 MFILE=$DIR/Android.mk
719 else
720 MFILE=$MFILE/$DIR/Android.mk
721 fi
722 MAKEFILE="$MAKEFILE $MFILE"
723 else
Ying Wanga7deb082013-08-16 13:24:47 -0700724 case $DIR in
725 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
726 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
727 *) echo "No Android.mk in $DIR."; return 1;;
728 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700729 fi
730 done
Ying Wanga7deb082013-08-16 13:24:47 -0700731 if [ -n "$GET_INSTALL_PATH" ]; then
732 ARGS=$GET_INSTALL_PATH
733 MODULES=
734 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800735 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 -0700736 else
737 echo "Couldn't locate the top of the tree. Try setting TOP."
738 fi
739}
740
Ying Wangb607f7b2013-02-08 18:01:04 -0800741function mma()
742{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800743 local T=$(gettop)
744 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800745 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800746 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800747 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800748 if [ ! "$T" ]; then
749 echo "Couldn't locate the top of the tree. Try setting TOP."
750 fi
751 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800752 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800753 fi
754}
755
756function mmma()
757{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800758 local T=$(gettop)
759 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800760 if [ "$T" ]; then
761 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
762 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
763 local MY_PWD=`PWD= /bin/pwd`
764 if [ "$MY_PWD" = "$T" ]; then
765 MY_PWD=
766 else
767 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
768 fi
769 local DIR=
770 local MODULE_PATHS=
771 local ARGS=
772 for DIR in $DIRS ; do
773 if [ -d $DIR ]; then
774 if [ "$MY_PWD" = "" ]; then
775 MODULE_PATHS="$MODULE_PATHS $DIR"
776 else
777 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
778 fi
779 else
780 case $DIR in
781 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
782 *) echo "Couldn't find directory $DIR"; return 1;;
783 esac
784 fi
785 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800786 $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 -0800787 else
788 echo "Couldn't locate the top of the tree. Try setting TOP."
789 fi
790}
791
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792function croot()
793{
794 T=$(gettop)
795 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800796 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797 else
798 echo "Couldn't locate the top of the tree. Try setting TOP."
799 fi
800}
801
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700802function cproj()
803{
804 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700805 local HERE=$PWD
806 T=
807 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
808 T=$PWD
809 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800810 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700811 return
812 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800813 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700814 done
Ying Wang9cd17642012-12-13 10:52:07 -0800815 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700816 echo "can't find Android.mk"
817}
818
Daniel Sandler47e0a882013-07-30 13:23:52 -0400819# simplified version of ps; output in the form
820# <pid> <procname>
821function qpid() {
822 local prepend=''
823 local append=''
824 if [ "$1" = "--exact" ]; then
825 prepend=' '
826 append='$'
827 shift
828 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
829 echo "usage: qpid [[--exact] <process name|pid>"
830 return 255
831 fi
832
833 local EXE="$1"
834 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700835 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400836 else
837 adb shell ps \
838 | tr -d '\r' \
839 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
840 fi
841}
842
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700843function pid()
844{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400845 local prepend=''
846 local append=''
847 if [ "$1" = "--exact" ]; then
848 prepend=' '
849 append='$'
850 shift
851 fi
852 local EXE="$1"
853 if [ "$EXE" ] ; then
854 local PID=`adb shell ps \
855 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700856 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400857 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
858 echo "$PID"
859 else
860 echo "usage: pid [--exact] <process name>"
861 return 255
862 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700863}
864
Christopher Tate744ee802009-11-12 15:33:08 -0800865# systemstack - dump the current stack trace of all threads in the system process
866# to the usual ANR traces file
867function systemstack()
868{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800869 stacks system_server
870}
871
872function stacks()
873{
874 if [[ $1 =~ ^[0-9]+$ ]] ; then
875 local PID="$1"
876 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700877 local PIDLIST="$(pid $1)"
878 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
879 local PID="$PIDLIST"
880 elif [ "$PIDLIST" ] ; then
881 echo "more than one process: $1"
882 else
883 echo "no such process: $1"
884 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800885 else
886 echo "usage: stacks [pid|process name]"
887 fi
888
889 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700890 # Determine whether the process is native
891 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
892 # Dump stacks of Dalvik process
893 local TRACES=/data/anr/traces.txt
894 local ORIG=/data/anr/traces.orig
895 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800896
Jeff Brownb12c2e52013-08-19 15:14:16 -0700897 # Keep original traces to avoid clobbering
898 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800899
Jeff Brownb12c2e52013-08-19 15:14:16 -0700900 # Make sure we have a usable file
901 adb shell touch $TRACES
902 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800903
Jeff Brownb12c2e52013-08-19 15:14:16 -0700904 # Dump stacks and wait for dump to finish
905 adb shell kill -3 $PID
906 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800907
Jeff Brownb12c2e52013-08-19 15:14:16 -0700908 # Restore original stacks, and show current output
909 adb shell mv $TRACES $TMP
910 adb shell mv $ORIG $TRACES
911 adb shell cat $TMP
912 else
913 # Dump stacks of native process
914 adb shell debuggerd -b $PID
915 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800916 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800917}
918
John Michelau50200252012-11-09 11:48:04 -0600919function gdbwrapper()
920{
921 $ANDROID_TOOLCHAIN/$GDB -x "$@"
922}
923
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700924function gdbclient()
925{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800926 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
927 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
928 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
929 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
930 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800931 local ARCH=$(get_build_var TARGET_ARCH)
932 local GDB
933 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800934 arm) GDB=arm-linux-androideabi-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000935 arm64) GDB=aarch64-linux-android-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700936 mips) GDB=mipsel-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000937 mips64) GDB=mipsel-linux-android-gdb;;
938 x86) GDB=x86_64-linux-android-gdb;;
939 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800940 *) echo "Unknown arch $ARCH"; return 1;;
941 esac
942
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700943 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
944 local EXE="$1"
945 if [ "$EXE" ] ; then
946 EXE=$1
947 else
948 EXE="app_process"
949 fi
950
951 local PORT="$2"
952 if [ "$PORT" ] ; then
953 PORT=$2
954 else
955 PORT=":5039"
956 fi
957
Chris Craik20c136a2012-11-09 18:02:19 -0800958 local PID="$3"
959 if [ "$PID" ] ; then
960 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700961 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800962 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
963 # that likely didn't work because of returning multiple processes
964 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -0700965 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -0800966 if [[ ! "$PID" =~ ^[0-9]+$ ]]
967 then
968 echo "Couldn't resolve '$3' to single PID"
969 return 1
970 else
971 echo ""
972 echo "WARNING: multiple processes matching '$3' observed, using root process"
973 echo ""
974 fi
975 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -0700976 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700977 adb forward "tcp$PORT" "tcp$PORT"
978 adb shell gdbserver $PORT --attach $PID &
979 sleep 2
980 else
981 echo ""
982 echo "If you haven't done so already, do this first on the device:"
983 echo " gdbserver $PORT /system/bin/$EXE"
984 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -0800985 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700986 echo ""
987 fi
988
989 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Chris Dearman6858d512012-02-02 14:16:52 -0800990 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 -0700991 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700992 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
993 echo >>"$OUT_ROOT/gdbclient.cmds" ""
994
John Michelau50200252012-11-09 11:48:04 -0600995 gdbwrapper "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700996 else
997 echo "Unable to determine build system output dir."
998 fi
999
1000}
1001
1002case `uname -s` in
1003 Darwin)
1004 function sgrep()
1005 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001006 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 -07001007 }
1008
1009 ;;
1010 *)
1011 function sgrep()
1012 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001013 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 -07001014 }
1015 ;;
1016esac
1017
Raghu Gandham8da43102012-07-25 19:57:22 -07001018function gettargetarch
1019{
1020 get_build_var TARGET_ARCH
1021}
1022
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001023function jgrep()
1024{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001025 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 -07001026}
1027
1028function cgrep()
1029{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001030 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 -07001031}
1032
1033function resgrep()
1034{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001035 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 -07001036}
1037
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001038function mangrep()
1039{
1040 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1041}
1042
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001043function sepgrep()
1044{
1045 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 "$@"
1046}
1047
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001048case `uname -s` in
1049 Darwin)
1050 function mgrep()
1051 {
Ying Wang324c2b22012-08-17 15:03:20 -07001052 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 -07001053 }
1054
1055 function treegrep()
1056 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001057 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 -07001058 }
1059
1060 ;;
1061 *)
1062 function mgrep()
1063 {
Ying Wang324c2b22012-08-17 15:03:20 -07001064 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 -07001065 }
1066
1067 function treegrep()
1068 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001069 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 -07001070 }
1071
1072 ;;
1073esac
1074
1075function getprebuilt
1076{
1077 get_abs_build_var ANDROID_PREBUILTS
1078}
1079
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001080function tracedmdump()
1081{
1082 T=$(gettop)
1083 if [ ! "$T" ]; then
1084 echo "Couldn't locate the top of the tree. Try setting TOP."
1085 return
1086 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001087 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001088 local arch=$(gettargetarch)
1089 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001090
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001091 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001092 if [ ! "$TRACE" ] ; then
1093 echo "usage: tracedmdump tracename"
1094 return
1095 fi
1096
Jack Veenstra60116fc2009-04-09 18:12:34 -07001097 if [ ! -r "$KERNEL" ] ; then
1098 echo "Error: cannot find kernel: '$KERNEL'"
1099 return
1100 fi
1101
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001102 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001103 if [ "$BASETRACE" = "$TRACE" ] ; then
1104 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1105 fi
1106
1107 echo "post-processing traces..."
1108 rm -f $TRACE/qtrace.dexlist
1109 post_trace $TRACE
1110 if [ $? -ne 0 ]; then
1111 echo "***"
1112 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1113 echo "***"
1114 return
1115 fi
1116 echo "generating dexlist output..."
1117 /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
1118 echo "generating dmtrace data..."
1119 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1120 echo "generating html file..."
1121 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1122 echo "done, see $TRACE/dmtrace.html for details"
1123 echo "or run:"
1124 echo " traceview $TRACE/dmtrace"
1125}
1126
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001127# communicate with a running device or emulator, set up necessary state,
1128# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001129function runhat()
1130{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001131 # process standard adb options
1132 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001133 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001134 adbTarget=$1
1135 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001136 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001137 adbTarget="$1 $2"
1138 shift 2
1139 fi
1140 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001141 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001142
1143 # runhat options
1144 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001145
1146 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001147 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001148 return
1149 fi
1150
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001151 # confirm hat is available
1152 if [ -z $(which hat) ]; then
1153 echo "hat is not available in this configuration."
1154 return
1155 fi
1156
Andy McFaddenb6289852010-07-12 08:00:19 -07001157 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001158 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001159 local devFile=$sdcard/hprof-$targetPid
1160 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001161 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001162 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001163 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001164 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001165 echo -n "> "
1166 read
1167
The Android Open Source Project88b60792009-03-03 19:28:42 -08001168 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001169
The Android Open Source Project88b60792009-03-03 19:28:42 -08001170 echo "Retrieving file $devFile..."
1171 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001172
The Android Open Source Project88b60792009-03-03 19:28:42 -08001173 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001174
The Android Open Source Project88b60792009-03-03 19:28:42 -08001175 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001176 echo "View the output by pointing your browser at http://localhost:7000/"
1177 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001178 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001179}
1180
1181function getbugreports()
1182{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001183 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001184
1185 if [ ! "$reports" ]; then
1186 echo "Could not locate any bugreports."
1187 return
1188 fi
1189
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001190 local report
1191 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001192 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001193 echo "/sdcard/bugreports/${report}"
1194 adb pull /sdcard/bugreports/${report} ${report}
1195 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001196 done
1197}
1198
Victoria Lease1b296b42012-08-21 15:44:06 -07001199function getsdcardpath()
1200{
1201 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1202}
1203
1204function getscreenshotpath()
1205{
1206 echo "$(getsdcardpath)/Pictures/Screenshots"
1207}
1208
1209function getlastscreenshot()
1210{
1211 local screenshot_path=$(getscreenshotpath)
1212 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1213 if [ "$screenshot" = "" ]; then
1214 echo "No screenshots found."
1215 return
1216 fi
1217 echo "${screenshot}"
1218 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1219}
1220
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001221function startviewserver()
1222{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001223 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001224 if [ $# -gt 0 ]; then
1225 port=$1
1226 fi
1227 adb shell service call window 1 i32 $port
1228}
1229
1230function stopviewserver()
1231{
1232 adb shell service call window 2
1233}
1234
1235function isviewserverstarted()
1236{
1237 adb shell service call window 3
1238}
1239
Romain Guyb84049a2010-10-04 16:56:11 -07001240function key_home()
1241{
1242 adb shell input keyevent 3
1243}
1244
1245function key_back()
1246{
1247 adb shell input keyevent 4
1248}
1249
1250function key_menu()
1251{
1252 adb shell input keyevent 82
1253}
1254
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001255function smoketest()
1256{
1257 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1258 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1259 return
1260 fi
1261 T=$(gettop)
1262 if [ ! "$T" ]; then
1263 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1264 return
1265 fi
1266
Ying Wang9cd17642012-12-13 10:52:07 -08001267 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001268 adb uninstall com.android.smoketest > /dev/null &&
1269 adb uninstall com.android.smoketest.tests > /dev/null &&
1270 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1271 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1272 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1273}
1274
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001275# simple shortcut to the runtest command
1276function runtest()
1277{
1278 T=$(gettop)
1279 if [ ! "$T" ]; then
1280 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1281 return
1282 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001283 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001284}
1285
The Android Open Source Project88b60792009-03-03 19:28:42 -08001286function godir () {
1287 if [[ -z "$1" ]]; then
1288 echo "Usage: godir <regex>"
1289 return
1290 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001291 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001292 if [[ ! -f $T/filelist ]]; then
1293 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001294 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001295 echo " Done"
1296 echo ""
1297 fi
1298 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001299 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001300 if [[ ${#lines[@]} = 0 ]]; then
1301 echo "Not found"
1302 return
1303 fi
1304 local pathname
1305 local choice
1306 if [[ ${#lines[@]} > 1 ]]; then
1307 while [[ -z "$pathname" ]]; do
1308 local index=1
1309 local line
1310 for line in ${lines[@]}; do
1311 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001312 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001313 done
1314 echo
1315 echo -n "Select one: "
1316 unset choice
1317 read choice
1318 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1319 echo "Invalid choice"
1320 continue
1321 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001322 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001323 done
1324 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001325 pathname=${lines[0]}
1326 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001327 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001328}
1329
Narayan Kamath9260bba2014-01-17 10:05:25 +00001330# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1331#
1332# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1333# For some reason, installing the JDK doesn't make it show up in the
1334# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001335function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001336 # Clear the existing JAVA_HOME value if we set it ourselves, so that
1337 # we can reset it later, depending on the value of EXPERIMENTAL_USE_JAVA7.
1338 #
1339 # If we don't do this, the JAVA_HOME value set by the first call to
1340 # build/envsetup.sh will persist forever.
1341 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1342 export JAVA_HOME=""
1343 fi
1344
Andy McFaddenbd960942010-06-24 12:52:51 -07001345 if [ ! "$JAVA_HOME" ]; then
Narayan Kamath9260bba2014-01-17 10:05:25 +00001346 if [ ! "$EXPERIMENTAL_USE_JAVA7" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001347 case `uname -s` in
1348 Darwin)
1349 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1350 ;;
1351 *)
1352 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1353 ;;
1354 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001355 else
1356 case `uname -s` in
1357 Darwin)
1358 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
1359 ;;
1360 *)
1361 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1362 ;;
1363 esac
1364 fi
1365
1366 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1367 # we can change it on the next envsetup.sh, if required.
1368 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001369 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001370}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001371
Alex Rayf0d08eb2013-03-08 15:15:06 -08001372# Print colored exit condition
1373function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001374 "$@"
1375 local retval=$?
1376 if [ $retval -ne 0 ]
1377 then
1378 echo -e "\e[0;31mFAILURE\e[00m"
1379 else
1380 echo -e "\e[0;32mSUCCESS\e[00m"
1381 fi
1382 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001383}
1384
Raphael Moll70a86b02011-06-20 16:03:14 -07001385if [ "x$SHELL" != "x/bin/bash" ]; then
1386 case `ps -o command -p $$` in
1387 *bash*)
1388 ;;
1389 *)
1390 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1391 ;;
1392 esac
1393fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001394
1395# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001396for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1397 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001398do
1399 echo "including $f"
1400 . $f
1401done
1402unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001403
1404addcompletions