blob: bc4f6a1200b6da5f97760e0e9edd29f41fa243ea [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 ;;
Ben Chengdb4fc202013-10-04 16:02:59 -0700135 aarch64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin
136 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800137 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700138 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200139 *)
140 echo "Can't find toolchain for unknown architecture: $ARCH"
141 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700142 ;;
143 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700144 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
145 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700146 fi
Raphael732936d2011-06-22 14:35:32 -0700147
Bruce Beare42ced6d2012-07-17 21:40:01 -0700148 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700149 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700150 arm)
Ben Cheng8bc4c432012-11-16 13:29:13 -0800151 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700152 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
153 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
154 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
155 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700156 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700157 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
158 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700159 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700160 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700161 ;;
162 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700163
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700164 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
165 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700166 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wangaa1c9b52012-11-26 20:51:59 -0800167 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
168 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800169
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500170 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900171 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500172 if [ -n "$JAVA_HOME" ]; then
173 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900174 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
175 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500176 fi
177
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800178 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700179 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
180 export OUT=$ANDROID_PRODUCT_OUT
181
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700182 unset ANDROID_HOST_OUT
183 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
184
Ben Cheng057fde12011-11-28 13:55:14 -0800185 # needed for processing samples collected by perf counters
186 unset OPROFILE_EVENTS_DIR
187 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
188
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800189 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700190 # TODO: fix the path
191 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
192}
193
194function printconfig()
195{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800196 T=$(gettop)
197 if [ ! "$T" ]; then
198 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
199 return
200 fi
201 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700202}
203
204function set_stuff_for_environment()
205{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800206 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500207 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800208 setpaths
209 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700210
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800211 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700212 # With this environment variable new GCC can apply colors to warnings/errors
213 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 -0700214}
215
216function set_sequence_number()
217{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700218 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700219}
220
221function settitle()
222{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800223 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700224 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700225 local product=$TARGET_PRODUCT
226 local variant=$TARGET_BUILD_VARIANT
227 local apps=$TARGET_BUILD_APPS
228 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700229 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700230 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700231 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700232 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800233 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700234}
235
Kenny Root52aa81c2011-07-15 11:07:06 -0700236function addcompletions()
237{
238 local T dir f
239
240 # Keep us from trying to run in something that isn't bash.
241 if [ -z "${BASH_VERSION}" ]; then
242 return
243 fi
244
245 # Keep us from trying to run in bash that's too old.
246 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
247 return
248 fi
249
250 dir="sdk/bash_completion"
251 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700252 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700253 echo "including $f"
254 . $f
255 done
256 fi
257}
258
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700259function choosetype()
260{
261 echo "Build type choices are:"
262 echo " 1. release"
263 echo " 2. debug"
264 echo
265
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800266 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700267 DEFAULT_NUM=1
268 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700269
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800270 export TARGET_BUILD_TYPE=
271 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700272 while [ -z $TARGET_BUILD_TYPE ]
273 do
274 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800275 if [ -z "$1" ] ; then
276 read ANSWER
277 else
278 echo $1
279 ANSWER=$1
280 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700281 case $ANSWER in
282 "")
283 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
284 ;;
285 1)
286 export TARGET_BUILD_TYPE=release
287 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800288 release)
289 export TARGET_BUILD_TYPE=release
290 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700291 2)
292 export TARGET_BUILD_TYPE=debug
293 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800294 debug)
295 export TARGET_BUILD_TYPE=debug
296 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297 *)
298 echo
299 echo "I didn't understand your response. Please try again."
300 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700301 ;;
302 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303 if [ -n "$1" ] ; then
304 break
305 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700306 done
307
308 set_stuff_for_environment
309}
310
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800311#
312# This function isn't really right: It chooses a TARGET_PRODUCT
313# based on the list of boards. Usually, that gets you something
314# that kinda works with a generic product, but really, you should
315# pick a product by name.
316#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317function chooseproduct()
318{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319 if [ "x$TARGET_PRODUCT" != x ] ; then
320 default_value=$TARGET_PRODUCT
321 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700322 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700323 fi
324
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800325 export TARGET_PRODUCT=
326 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700327 while [ -z "$TARGET_PRODUCT" ]
328 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700329 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800330 if [ -z "$1" ] ; then
331 read ANSWER
332 else
333 echo $1
334 ANSWER=$1
335 fi
336
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700337 if [ -z "$ANSWER" ] ; then
338 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800339 else
340 if check_product $ANSWER
341 then
342 export TARGET_PRODUCT=$ANSWER
343 else
344 echo "** Not a valid product: $ANSWER"
345 fi
346 fi
347 if [ -n "$1" ] ; then
348 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700349 fi
350 done
351
352 set_stuff_for_environment
353}
354
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800355function choosevariant()
356{
357 echo "Variant choices are:"
358 local index=1
359 local v
360 for v in ${VARIANT_CHOICES[@]}
361 do
362 # The product name is the name of the directory containing
363 # the makefile we found, above.
364 echo " $index. $v"
365 index=$(($index+1))
366 done
367
368 local default_value=eng
369 local ANSWER
370
371 export TARGET_BUILD_VARIANT=
372 while [ -z "$TARGET_BUILD_VARIANT" ]
373 do
374 echo -n "Which would you like? [$default_value] "
375 if [ -z "$1" ] ; then
376 read ANSWER
377 else
378 echo $1
379 ANSWER=$1
380 fi
381
382 if [ -z "$ANSWER" ] ; then
383 export TARGET_BUILD_VARIANT=$default_value
384 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
385 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800386 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800387 fi
388 else
389 if check_variant $ANSWER
390 then
391 export TARGET_BUILD_VARIANT=$ANSWER
392 else
393 echo "** Not a valid variant: $ANSWER"
394 fi
395 fi
396 if [ -n "$1" ] ; then
397 break
398 fi
399 done
400}
401
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700402function choosecombo()
403{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700404 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700405
406 echo
407 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700408 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700409
410 echo
411 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700412 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800413
414 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700415 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800416 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700417}
418
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800419# Clear this variable. It will be built up again when the vendorsetup.sh
420# files are included at the end of this file.
421unset LUNCH_MENU_CHOICES
422function add_lunch_combo()
423{
424 local new_combo=$1
425 local c
426 for c in ${LUNCH_MENU_CHOICES[@]} ; do
427 if [ "$new_combo" = "$c" ] ; then
428 return
429 fi
430 done
431 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
432}
433
434# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700435add_lunch_combo aosp_arm-eng
436add_lunch_combo aosp_x86-eng
437add_lunch_combo aosp_mips-eng
Pavel Chupinfd82a492012-11-26 09:50:07 +0400438add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800439add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800440
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700441function print_lunch_menu()
442{
443 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444 echo
445 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446 echo
447 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800448
449 local i=1
450 local choice
451 for choice in ${LUNCH_MENU_CHOICES[@]}
452 do
453 echo " $i. $choice"
454 i=$(($i+1))
455 done
456
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700457 echo
458}
459
460function lunch()
461{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800462 local answer
463
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700464 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800465 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700466 else
467 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700468 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470 fi
471
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472 local selection=
473
474 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700476 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
478 then
479 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
480 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800481 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482 fi
483 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
484 then
485 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486 fi
487
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800488 if [ -z "$selection" ]
489 then
490 echo
491 echo "Invalid lunch combo: $answer"
492 return 1
493 fi
494
Joe Onoratoda12daf2010-06-09 18:18:31 -0700495 export TARGET_BUILD_APPS=
496
Jeff Browne33ba4c2011-07-11 22:11:46 -0700497 local product=$(echo -n $selection | sed -e "s/-.*$//")
498 check_product $product
499 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800500 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700501 echo
502 echo "** Don't have a product spec for: '$product'"
503 echo "** Do you have the right repo manifest?"
504 product=
505 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506
Jeff Browne33ba4c2011-07-11 22:11:46 -0700507 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
508 check_variant $variant
509 if [ $? -ne 0 ]
510 then
511 echo
512 echo "** Invalid variant: '$variant'"
513 echo "** Must be one of ${VARIANT_CHOICES[@]}"
514 variant=
515 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800516
Jeff Browne33ba4c2011-07-11 22:11:46 -0700517 if [ -z "$product" -o -z "$variant" ]
518 then
519 echo
520 return 1
521 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522
Jeff Browne33ba4c2011-07-11 22:11:46 -0700523 export TARGET_PRODUCT=$product
524 export TARGET_BUILD_VARIANT=$variant
525 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700526
527 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800528
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700529 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700531}
532
Jeff Davidson513d7a42010-08-02 10:00:44 -0700533# Tab completion for lunch.
534function _lunch()
535{
536 local cur prev opts
537 COMPREPLY=()
538 cur="${COMP_WORDS[COMP_CWORD]}"
539 prev="${COMP_WORDS[COMP_CWORD-1]}"
540
541 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
542 return 0
543}
544complete -F _lunch lunch
545
Joe Onoratoda12daf2010-06-09 18:18:31 -0700546# Configures the build to build unbundled apps.
547# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
548function tapas()
549{
Ying Wangf05c4f72013-01-31 11:16:57 -0800550 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600551 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800552 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 -0700553
Ying Wang67f02922012-08-22 10:25:20 -0700554 if [ $(echo $arch | wc -w) -gt 1 ]; then
555 echo "tapas: Error: Multiple build archs supplied: $arch"
556 return
557 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700558 if [ $(echo $variant | wc -w) -gt 1 ]; then
559 echo "tapas: Error: Multiple build variants supplied: $variant"
560 return
561 fi
Ying Wang67f02922012-08-22 10:25:20 -0700562
563 local product=full
564 case $arch in
565 x86) product=full_x86;;
566 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800567 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700568 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700569 if [ -z "$variant" ]; then
570 variant=eng
571 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700572 if [ -z "$apps" ]; then
573 apps=all
574 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700575
Ying Wang67f02922012-08-22 10:25:20 -0700576 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700577 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700578 export TARGET_BUILD_TYPE=release
579 export TARGET_BUILD_APPS=$apps
580
581 set_stuff_for_environment
582 printconfig
583}
584
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585function gettop
586{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700588 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
589 echo $TOP
590 else
591 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800592 # The following circumlocution (repeated below as well) ensures
593 # that we record the true directory name and not one that is
594 # faked up with symlink names.
595 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800597 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700598 T=
599 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800600 \cd ..
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800601 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700602 done
Ying Wang9cd17642012-12-13 10:52:07 -0800603 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 if [ -f "$T/$TOPFILE" ]; then
605 echo $T
606 fi
607 fi
608 fi
609}
610
Andrew Hsieh906cb782013-09-10 17:37:14 +0800611# Return driver for "make", if any (eg. static analyzer)
612function getdriver()
613{
614 local T="$1"
615 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
616 if [ -n "$WITH_STATIC_ANALYZER" ]; then
617 echo "\
618$T/prebuilts/clang/linux-x86/host/3.3/tools/scan-build/scan-build \
Andrew Hsiehaf738a42013-09-13 15:49:39 +0800619--use-analyzer $T/prebuilts/clang/linux-x86/host/3.3/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800620--status-bugs \
621--top=$T"
622 fi
623}
624
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700625function m()
626{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800627 local T=$(gettop)
628 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700629 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800630 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700631 else
632 echo "Couldn't locate the top of the tree. Try setting TOP."
633 fi
634}
635
636function findmakefile()
637{
638 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800639 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700640 T=
641 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700642 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700643 if [ -f "$T/Android.mk" ]; then
644 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800645 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700646 return
647 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800648 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649 done
Ying Wang9cd17642012-12-13 10:52:07 -0800650 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651}
652
653function mm()
654{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800655 local T=$(gettop)
656 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657 # If we're sitting in the root of the build tree, just do a
658 # normal make.
659 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800660 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661 else
662 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800663 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700664 local MODULES=
665 local GET_INSTALL_PATH=
666 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700667 # Remove the path to top as the makefilepath needs to be relative
668 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700669 if [ ! "$T" ]; then
670 echo "Couldn't locate the top of the tree. Try setting TOP."
671 elif [ ! "$M" ]; then
672 echo "Couldn't locate a makefile from the current directory."
673 else
Ying Wanga7deb082013-08-16 13:24:47 -0700674 for ARG in $@; do
675 case $ARG in
676 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
677 esac
678 done
679 if [ -n "$GET_INSTALL_PATH" ]; then
680 MODULES=
681 ARGS=GET-INSTALL-PATH
682 else
683 MODULES=all_modules
684 ARGS=$@
685 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700686 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 -0700687 fi
688 fi
689}
690
691function mmm()
692{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800693 local T=$(gettop)
694 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700695 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800696 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800697 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800698 local ARGS=
699 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700700 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800701 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
702 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
703 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800704 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
705 if [ "$MODULES" = "" ]; then
706 MODULES=all_modules
707 fi
708 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700709 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700710 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
711 local TO_CHOP=`expr $TO_CHOP + 1`
712 local START=`PWD= /bin/pwd`
713 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700714 if [ "$MFILE" = "" ] ; then
715 MFILE=$DIR/Android.mk
716 else
717 MFILE=$MFILE/$DIR/Android.mk
718 fi
719 MAKEFILE="$MAKEFILE $MFILE"
720 else
Ying Wanga7deb082013-08-16 13:24:47 -0700721 case $DIR in
722 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
723 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
724 *) echo "No Android.mk in $DIR."; return 1;;
725 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700726 fi
727 done
Ying Wanga7deb082013-08-16 13:24:47 -0700728 if [ -n "$GET_INSTALL_PATH" ]; then
729 ARGS=$GET_INSTALL_PATH
730 MODULES=
731 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800732 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 -0700733 else
734 echo "Couldn't locate the top of the tree. Try setting TOP."
735 fi
736}
737
Ying Wangb607f7b2013-02-08 18:01:04 -0800738function mma()
739{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800740 local T=$(gettop)
741 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800742 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800743 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800744 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800745 if [ ! "$T" ]; then
746 echo "Couldn't locate the top of the tree. Try setting TOP."
747 fi
748 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800749 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800750 fi
751}
752
753function mmma()
754{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800755 local T=$(gettop)
756 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800757 if [ "$T" ]; then
758 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
759 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
760 local MY_PWD=`PWD= /bin/pwd`
761 if [ "$MY_PWD" = "$T" ]; then
762 MY_PWD=
763 else
764 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
765 fi
766 local DIR=
767 local MODULE_PATHS=
768 local ARGS=
769 for DIR in $DIRS ; do
770 if [ -d $DIR ]; then
771 if [ "$MY_PWD" = "" ]; then
772 MODULE_PATHS="$MODULE_PATHS $DIR"
773 else
774 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
775 fi
776 else
777 case $DIR in
778 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
779 *) echo "Couldn't find directory $DIR"; return 1;;
780 esac
781 fi
782 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800783 $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 -0800784 else
785 echo "Couldn't locate the top of the tree. Try setting TOP."
786 fi
787}
788
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700789function croot()
790{
791 T=$(gettop)
792 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800793 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700794 else
795 echo "Couldn't locate the top of the tree. Try setting TOP."
796 fi
797}
798
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700799function cproj()
800{
801 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700802 local HERE=$PWD
803 T=
804 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
805 T=$PWD
806 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800807 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700808 return
809 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800810 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700811 done
Ying Wang9cd17642012-12-13 10:52:07 -0800812 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700813 echo "can't find Android.mk"
814}
815
Daniel Sandler47e0a882013-07-30 13:23:52 -0400816# simplified version of ps; output in the form
817# <pid> <procname>
818function qpid() {
819 local prepend=''
820 local append=''
821 if [ "$1" = "--exact" ]; then
822 prepend=' '
823 append='$'
824 shift
825 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
826 echo "usage: qpid [[--exact] <process name|pid>"
827 return 255
828 fi
829
830 local EXE="$1"
831 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700832 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400833 else
834 adb shell ps \
835 | tr -d '\r' \
836 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
837 fi
838}
839
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700840function pid()
841{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400842 local prepend=''
843 local append=''
844 if [ "$1" = "--exact" ]; then
845 prepend=' '
846 append='$'
847 shift
848 fi
849 local EXE="$1"
850 if [ "$EXE" ] ; then
851 local PID=`adb shell ps \
852 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700853 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400854 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
855 echo "$PID"
856 else
857 echo "usage: pid [--exact] <process name>"
858 return 255
859 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700860}
861
Christopher Tate744ee802009-11-12 15:33:08 -0800862# systemstack - dump the current stack trace of all threads in the system process
863# to the usual ANR traces file
864function systemstack()
865{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800866 stacks system_server
867}
868
869function stacks()
870{
871 if [[ $1 =~ ^[0-9]+$ ]] ; then
872 local PID="$1"
873 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700874 local PIDLIST="$(pid $1)"
875 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
876 local PID="$PIDLIST"
877 elif [ "$PIDLIST" ] ; then
878 echo "more than one process: $1"
879 else
880 echo "no such process: $1"
881 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800882 else
883 echo "usage: stacks [pid|process name]"
884 fi
885
886 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700887 # Determine whether the process is native
888 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
889 # Dump stacks of Dalvik process
890 local TRACES=/data/anr/traces.txt
891 local ORIG=/data/anr/traces.orig
892 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800893
Jeff Brownb12c2e52013-08-19 15:14:16 -0700894 # Keep original traces to avoid clobbering
895 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800896
Jeff Brownb12c2e52013-08-19 15:14:16 -0700897 # Make sure we have a usable file
898 adb shell touch $TRACES
899 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800900
Jeff Brownb12c2e52013-08-19 15:14:16 -0700901 # Dump stacks and wait for dump to finish
902 adb shell kill -3 $PID
903 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800904
Jeff Brownb12c2e52013-08-19 15:14:16 -0700905 # Restore original stacks, and show current output
906 adb shell mv $TRACES $TMP
907 adb shell mv $ORIG $TRACES
908 adb shell cat $TMP
909 else
910 # Dump stacks of native process
911 adb shell debuggerd -b $PID
912 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800913 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800914}
915
John Michelau50200252012-11-09 11:48:04 -0600916function gdbwrapper()
917{
918 $ANDROID_TOOLCHAIN/$GDB -x "$@"
919}
920
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700921function gdbclient()
922{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800923 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
924 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
925 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
926 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
927 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800928 local ARCH=$(get_build_var TARGET_ARCH)
929 local GDB
930 case "$ARCH" in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400931 x86) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800932 arm) GDB=arm-linux-androideabi-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700933 mips) GDB=mipsel-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800934 *) echo "Unknown arch $ARCH"; return 1;;
935 esac
936
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700937 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
938 local EXE="$1"
939 if [ "$EXE" ] ; then
940 EXE=$1
941 else
942 EXE="app_process"
943 fi
944
945 local PORT="$2"
946 if [ "$PORT" ] ; then
947 PORT=$2
948 else
949 PORT=":5039"
950 fi
951
Chris Craik20c136a2012-11-09 18:02:19 -0800952 local PID="$3"
953 if [ "$PID" ] ; then
954 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700955 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800956 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
957 # that likely didn't work because of returning multiple processes
958 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -0700959 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -0800960 if [[ ! "$PID" =~ ^[0-9]+$ ]]
961 then
962 echo "Couldn't resolve '$3' to single PID"
963 return 1
964 else
965 echo ""
966 echo "WARNING: multiple processes matching '$3' observed, using root process"
967 echo ""
968 fi
969 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -0700970 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700971 adb forward "tcp$PORT" "tcp$PORT"
972 adb shell gdbserver $PORT --attach $PID &
973 sleep 2
974 else
975 echo ""
976 echo "If you haven't done so already, do this first on the device:"
977 echo " gdbserver $PORT /system/bin/$EXE"
978 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -0800979 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700980 echo ""
981 fi
982
983 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Chris Dearman6858d512012-02-02 14:16:52 -0800984 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 -0700985 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700986 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
987 echo >>"$OUT_ROOT/gdbclient.cmds" ""
988
John Michelau50200252012-11-09 11:48:04 -0600989 gdbwrapper "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700990 else
991 echo "Unable to determine build system output dir."
992 fi
993
994}
995
996case `uname -s` in
997 Darwin)
998 function sgrep()
999 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001000 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 -07001001 }
1002
1003 ;;
1004 *)
1005 function sgrep()
1006 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001007 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 -07001008 }
1009 ;;
1010esac
1011
Raghu Gandham8da43102012-07-25 19:57:22 -07001012function gettargetarch
1013{
1014 get_build_var TARGET_ARCH
1015}
1016
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001017function jgrep()
1018{
Joe Onoratof50e84b2011-03-15 14:15:46 -07001019 find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001020}
1021
1022function cgrep()
1023{
Mike Dodd0c26d342011-04-07 13:29:06 -07001024 find . -name .repo -prune -o -name .git -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 -07001025}
1026
1027function resgrep()
1028{
Joe Onoratof50e84b2011-03-15 14:15:46 -07001029 for dir in `find . -name .repo -prune -o -name .git -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 -07001030}
1031
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001032function mangrep()
1033{
1034 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1035}
1036
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001037function sepgrep()
1038{
1039 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 "$@"
1040}
1041
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001042case `uname -s` in
1043 Darwin)
1044 function mgrep()
1045 {
Ying Wang324c2b22012-08-17 15:03:20 -07001046 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 -07001047 }
1048
1049 function treegrep()
1050 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001051 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 -07001052 }
1053
1054 ;;
1055 *)
1056 function mgrep()
1057 {
Ying Wang324c2b22012-08-17 15:03:20 -07001058 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 -07001059 }
1060
1061 function treegrep()
1062 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001063 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 -07001064 }
1065
1066 ;;
1067esac
1068
1069function getprebuilt
1070{
1071 get_abs_build_var ANDROID_PREBUILTS
1072}
1073
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001074function tracedmdump()
1075{
1076 T=$(gettop)
1077 if [ ! "$T" ]; then
1078 echo "Couldn't locate the top of the tree. Try setting TOP."
1079 return
1080 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001081 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001082 local arch=$(gettargetarch)
1083 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001084
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001085 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001086 if [ ! "$TRACE" ] ; then
1087 echo "usage: tracedmdump tracename"
1088 return
1089 fi
1090
Jack Veenstra60116fc2009-04-09 18:12:34 -07001091 if [ ! -r "$KERNEL" ] ; then
1092 echo "Error: cannot find kernel: '$KERNEL'"
1093 return
1094 fi
1095
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001096 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001097 if [ "$BASETRACE" = "$TRACE" ] ; then
1098 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1099 fi
1100
1101 echo "post-processing traces..."
1102 rm -f $TRACE/qtrace.dexlist
1103 post_trace $TRACE
1104 if [ $? -ne 0 ]; then
1105 echo "***"
1106 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1107 echo "***"
1108 return
1109 fi
1110 echo "generating dexlist output..."
1111 /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
1112 echo "generating dmtrace data..."
1113 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1114 echo "generating html file..."
1115 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1116 echo "done, see $TRACE/dmtrace.html for details"
1117 echo "or run:"
1118 echo " traceview $TRACE/dmtrace"
1119}
1120
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001121# communicate with a running device or emulator, set up necessary state,
1122# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001123function runhat()
1124{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001125 # process standard adb options
1126 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001127 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001128 adbTarget=$1
1129 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001130 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001131 adbTarget="$1 $2"
1132 shift 2
1133 fi
1134 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001135 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001136
1137 # runhat options
1138 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001139
1140 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001141 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001142 return
1143 fi
1144
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001145 # confirm hat is available
1146 if [ -z $(which hat) ]; then
1147 echo "hat is not available in this configuration."
1148 return
1149 fi
1150
Andy McFaddenb6289852010-07-12 08:00:19 -07001151 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001152 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001153 local devFile=$sdcard/hprof-$targetPid
1154 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001155 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001156 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001157 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001158 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001159 echo -n "> "
1160 read
1161
The Android Open Source Project88b60792009-03-03 19:28:42 -08001162 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001163
The Android Open Source Project88b60792009-03-03 19:28:42 -08001164 echo "Retrieving file $devFile..."
1165 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001166
The Android Open Source Project88b60792009-03-03 19:28:42 -08001167 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001168
The Android Open Source Project88b60792009-03-03 19:28:42 -08001169 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001170 echo "View the output by pointing your browser at http://localhost:7000/"
1171 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001172 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001173}
1174
1175function getbugreports()
1176{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001177 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001178
1179 if [ ! "$reports" ]; then
1180 echo "Could not locate any bugreports."
1181 return
1182 fi
1183
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001184 local report
1185 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001186 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001187 echo "/sdcard/bugreports/${report}"
1188 adb pull /sdcard/bugreports/${report} ${report}
1189 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001190 done
1191}
1192
Victoria Lease1b296b42012-08-21 15:44:06 -07001193function getsdcardpath()
1194{
1195 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1196}
1197
1198function getscreenshotpath()
1199{
1200 echo "$(getsdcardpath)/Pictures/Screenshots"
1201}
1202
1203function getlastscreenshot()
1204{
1205 local screenshot_path=$(getscreenshotpath)
1206 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1207 if [ "$screenshot" = "" ]; then
1208 echo "No screenshots found."
1209 return
1210 fi
1211 echo "${screenshot}"
1212 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1213}
1214
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001215function startviewserver()
1216{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001217 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001218 if [ $# -gt 0 ]; then
1219 port=$1
1220 fi
1221 adb shell service call window 1 i32 $port
1222}
1223
1224function stopviewserver()
1225{
1226 adb shell service call window 2
1227}
1228
1229function isviewserverstarted()
1230{
1231 adb shell service call window 3
1232}
1233
Romain Guyb84049a2010-10-04 16:56:11 -07001234function key_home()
1235{
1236 adb shell input keyevent 3
1237}
1238
1239function key_back()
1240{
1241 adb shell input keyevent 4
1242}
1243
1244function key_menu()
1245{
1246 adb shell input keyevent 82
1247}
1248
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001249function smoketest()
1250{
1251 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1252 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1253 return
1254 fi
1255 T=$(gettop)
1256 if [ ! "$T" ]; then
1257 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1258 return
1259 fi
1260
Ying Wang9cd17642012-12-13 10:52:07 -08001261 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001262 adb uninstall com.android.smoketest > /dev/null &&
1263 adb uninstall com.android.smoketest.tests > /dev/null &&
1264 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1265 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1266 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1267}
1268
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001269# simple shortcut to the runtest command
1270function runtest()
1271{
1272 T=$(gettop)
1273 if [ ! "$T" ]; then
1274 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1275 return
1276 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001277 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001278}
1279
The Android Open Source Project88b60792009-03-03 19:28:42 -08001280function godir () {
1281 if [[ -z "$1" ]]; then
1282 echo "Usage: godir <regex>"
1283 return
1284 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001285 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001286 if [[ ! -f $T/filelist ]]; then
1287 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001288 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001289 echo " Done"
1290 echo ""
1291 fi
1292 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001293 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001294 if [[ ${#lines[@]} = 0 ]]; then
1295 echo "Not found"
1296 return
1297 fi
1298 local pathname
1299 local choice
1300 if [[ ${#lines[@]} > 1 ]]; then
1301 while [[ -z "$pathname" ]]; do
1302 local index=1
1303 local line
1304 for line in ${lines[@]}; do
1305 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001306 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001307 done
1308 echo
1309 echo -n "Select one: "
1310 unset choice
1311 read choice
1312 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1313 echo "Invalid choice"
1314 continue
1315 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001316 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001317 done
1318 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001319 pathname=${lines[0]}
1320 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001321 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001322}
1323
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001324# Force JAVA_HOME to point to java 1.6 if it isn't already set
1325function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001326 if [ ! "$JAVA_HOME" ]; then
1327 case `uname -s` in
1328 Darwin)
1329 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1330 ;;
1331 *)
1332 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1333 ;;
1334 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001335 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001336}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001337
Alex Rayf0d08eb2013-03-08 15:15:06 -08001338# Print colored exit condition
1339function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001340 "$@"
1341 local retval=$?
1342 if [ $retval -ne 0 ]
1343 then
1344 echo -e "\e[0;31mFAILURE\e[00m"
1345 else
1346 echo -e "\e[0;32mSUCCESS\e[00m"
1347 fi
1348 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001349}
1350
Raphael Moll70a86b02011-06-20 16:03:14 -07001351if [ "x$SHELL" != "x/bin/bash" ]; then
1352 case `ps -o command -p $$` in
1353 *bash*)
1354 ;;
1355 *)
1356 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1357 ;;
1358 esac
1359fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001360
1361# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001362for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1363 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001364do
1365 echo "including $f"
1366 . $f
1367done
1368unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001369
1370addcompletions