blob: b039bbc534c32c458ee54e874337b125414565a5 [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 \
Brian Carlstrom177285a2010-04-06 13:22:02 -070037 make --no-print-directory -C "$T" -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
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080048 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
49 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1
50}
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
Ben Cheng054ffd22012-12-11 14:01:10 -0800129 x86) toolchaindir=x86/i686-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700130 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800131 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200132 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800133 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700134 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200135 *)
136 echo "Can't find toolchain for unknown architecture: $ARCH"
137 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700138 ;;
139 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700140 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
141 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700142 fi
Raphael732936d2011-06-22 14:35:32 -0700143
Bruce Beare42ced6d2012-07-17 21:40:01 -0700144 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700145 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700146 arm)
Ben Cheng8bc4c432012-11-16 13:29:13 -0800147 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700148 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
149 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
150 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
151 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700152 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700153 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
154 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700155 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700156 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700157 ;;
158 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700159
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700160 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
161 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700162 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wangaa1c9b52012-11-26 20:51:59 -0800163 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
164 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800165
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500166 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900167 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500168 if [ -n "$JAVA_HOME" ]; then
169 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900170 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
171 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500172 fi
173
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800174 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700175 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
176 export OUT=$ANDROID_PRODUCT_OUT
177
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700178 unset ANDROID_HOST_OUT
179 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
180
Ben Cheng057fde12011-11-28 13:55:14 -0800181 # needed for processing samples collected by perf counters
182 unset OPROFILE_EVENTS_DIR
183 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
184
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800185 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700186 # TODO: fix the path
187 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
188}
189
190function printconfig()
191{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800192 T=$(gettop)
193 if [ ! "$T" ]; then
194 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
195 return
196 fi
197 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700198}
199
200function set_stuff_for_environment()
201{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800202 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500203 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800204 setpaths
205 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700206
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800207 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700208 # With this environment variable new GCC can apply colors to warnings/errors
209 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 -0700210}
211
212function set_sequence_number()
213{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700214 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700215}
216
217function settitle()
218{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800219 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700220 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700221 local product=$TARGET_PRODUCT
222 local variant=$TARGET_BUILD_VARIANT
223 local apps=$TARGET_BUILD_APPS
224 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700225 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700226 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700227 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700228 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800229 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700230}
231
Kenny Root52aa81c2011-07-15 11:07:06 -0700232function addcompletions()
233{
234 local T dir f
235
236 # Keep us from trying to run in something that isn't bash.
237 if [ -z "${BASH_VERSION}" ]; then
238 return
239 fi
240
241 # Keep us from trying to run in bash that's too old.
242 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
243 return
244 fi
245
246 dir="sdk/bash_completion"
247 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700248 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700249 echo "including $f"
250 . $f
251 done
252 fi
253}
254
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255function choosetype()
256{
257 echo "Build type choices are:"
258 echo " 1. release"
259 echo " 2. debug"
260 echo
261
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800262 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700263 DEFAULT_NUM=1
264 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700265
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800266 export TARGET_BUILD_TYPE=
267 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700268 while [ -z $TARGET_BUILD_TYPE ]
269 do
270 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800271 if [ -z "$1" ] ; then
272 read ANSWER
273 else
274 echo $1
275 ANSWER=$1
276 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700277 case $ANSWER in
278 "")
279 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
280 ;;
281 1)
282 export TARGET_BUILD_TYPE=release
283 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800284 release)
285 export TARGET_BUILD_TYPE=release
286 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700287 2)
288 export TARGET_BUILD_TYPE=debug
289 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800290 debug)
291 export TARGET_BUILD_TYPE=debug
292 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700293 *)
294 echo
295 echo "I didn't understand your response. Please try again."
296 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297 ;;
298 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800299 if [ -n "$1" ] ; then
300 break
301 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700302 done
303
304 set_stuff_for_environment
305}
306
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800307#
308# This function isn't really right: It chooses a TARGET_PRODUCT
309# based on the list of boards. Usually, that gets you something
310# that kinda works with a generic product, but really, you should
311# pick a product by name.
312#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700313function chooseproduct()
314{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315 if [ "x$TARGET_PRODUCT" != x ] ; then
316 default_value=$TARGET_PRODUCT
317 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700318 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319 fi
320
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800321 export TARGET_PRODUCT=
322 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700323 while [ -z "$TARGET_PRODUCT" ]
324 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700325 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800326 if [ -z "$1" ] ; then
327 read ANSWER
328 else
329 echo $1
330 ANSWER=$1
331 fi
332
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700333 if [ -z "$ANSWER" ] ; then
334 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335 else
336 if check_product $ANSWER
337 then
338 export TARGET_PRODUCT=$ANSWER
339 else
340 echo "** Not a valid product: $ANSWER"
341 fi
342 fi
343 if [ -n "$1" ] ; then
344 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700345 fi
346 done
347
348 set_stuff_for_environment
349}
350
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800351function choosevariant()
352{
353 echo "Variant choices are:"
354 local index=1
355 local v
356 for v in ${VARIANT_CHOICES[@]}
357 do
358 # The product name is the name of the directory containing
359 # the makefile we found, above.
360 echo " $index. $v"
361 index=$(($index+1))
362 done
363
364 local default_value=eng
365 local ANSWER
366
367 export TARGET_BUILD_VARIANT=
368 while [ -z "$TARGET_BUILD_VARIANT" ]
369 do
370 echo -n "Which would you like? [$default_value] "
371 if [ -z "$1" ] ; then
372 read ANSWER
373 else
374 echo $1
375 ANSWER=$1
376 fi
377
378 if [ -z "$ANSWER" ] ; then
379 export TARGET_BUILD_VARIANT=$default_value
380 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
381 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800382 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800383 fi
384 else
385 if check_variant $ANSWER
386 then
387 export TARGET_BUILD_VARIANT=$ANSWER
388 else
389 echo "** Not a valid variant: $ANSWER"
390 fi
391 fi
392 if [ -n "$1" ] ; then
393 break
394 fi
395 done
396}
397
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700398function choosecombo()
399{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700400 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700401
402 echo
403 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700404 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700405
406 echo
407 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700408 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800409
410 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700411 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800412 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700413}
414
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800415# Clear this variable. It will be built up again when the vendorsetup.sh
416# files are included at the end of this file.
417unset LUNCH_MENU_CHOICES
418function add_lunch_combo()
419{
420 local new_combo=$1
421 local c
422 for c in ${LUNCH_MENU_CHOICES[@]} ; do
423 if [ "$new_combo" = "$c" ] ; then
424 return
425 fi
426 done
427 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
428}
429
430# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700431add_lunch_combo aosp_arm-eng
432add_lunch_combo aosp_x86-eng
433add_lunch_combo aosp_mips-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800434add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800435
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700436function print_lunch_menu()
437{
438 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700439 echo
440 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700441 echo
442 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800443
444 local i=1
445 local choice
446 for choice in ${LUNCH_MENU_CHOICES[@]}
447 do
448 echo " $i. $choice"
449 i=$(($i+1))
450 done
451
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700452 echo
453}
454
455function lunch()
456{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800457 local answer
458
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700459 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800460 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461 else
462 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700463 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800464 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465 fi
466
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800467 local selection=
468
469 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700471 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
473 then
474 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
475 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800476 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477 fi
478 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
479 then
480 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700481 fi
482
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800483 if [ -z "$selection" ]
484 then
485 echo
486 echo "Invalid lunch combo: $answer"
487 return 1
488 fi
489
Joe Onoratoda12daf2010-06-09 18:18:31 -0700490 export TARGET_BUILD_APPS=
491
Jeff Browne33ba4c2011-07-11 22:11:46 -0700492 local product=$(echo -n $selection | sed -e "s/-.*$//")
493 check_product $product
494 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800495 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700496 echo
497 echo "** Don't have a product spec for: '$product'"
498 echo "** Do you have the right repo manifest?"
499 product=
500 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800501
Jeff Browne33ba4c2011-07-11 22:11:46 -0700502 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
503 check_variant $variant
504 if [ $? -ne 0 ]
505 then
506 echo
507 echo "** Invalid variant: '$variant'"
508 echo "** Must be one of ${VARIANT_CHOICES[@]}"
509 variant=
510 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511
Jeff Browne33ba4c2011-07-11 22:11:46 -0700512 if [ -z "$product" -o -z "$variant" ]
513 then
514 echo
515 return 1
516 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800517
Jeff Browne33ba4c2011-07-11 22:11:46 -0700518 export TARGET_PRODUCT=$product
519 export TARGET_BUILD_VARIANT=$variant
520 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700521
522 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800523
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700524 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800525 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700526}
527
Jeff Davidson513d7a42010-08-02 10:00:44 -0700528# Tab completion for lunch.
529function _lunch()
530{
531 local cur prev opts
532 COMPREPLY=()
533 cur="${COMP_WORDS[COMP_CWORD]}"
534 prev="${COMP_WORDS[COMP_CWORD-1]}"
535
536 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
537 return 0
538}
539complete -F _lunch lunch
540
Joe Onoratoda12daf2010-06-09 18:18:31 -0700541# Configures the build to build unbundled apps.
542# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
543function tapas()
544{
Ying Wangf05c4f72013-01-31 11:16:57 -0800545 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600546 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800547 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 -0700548
Ying Wang67f02922012-08-22 10:25:20 -0700549 if [ $(echo $arch | wc -w) -gt 1 ]; then
550 echo "tapas: Error: Multiple build archs supplied: $arch"
551 return
552 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700553 if [ $(echo $variant | wc -w) -gt 1 ]; then
554 echo "tapas: Error: Multiple build variants supplied: $variant"
555 return
556 fi
Ying Wang67f02922012-08-22 10:25:20 -0700557
558 local product=full
559 case $arch in
560 x86) product=full_x86;;
561 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800562 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700563 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700564 if [ -z "$variant" ]; then
565 variant=eng
566 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700567 if [ -z "$apps" ]; then
568 apps=all
569 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700570
Ying Wang67f02922012-08-22 10:25:20 -0700571 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700572 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700573 export TARGET_BUILD_TYPE=release
574 export TARGET_BUILD_APPS=$apps
575
576 set_stuff_for_environment
577 printconfig
578}
579
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700580function gettop
581{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800582 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700583 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
584 echo $TOP
585 else
586 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800587 # The following circumlocution (repeated below as well) ensures
588 # that we record the true directory name and not one that is
589 # faked up with symlink names.
590 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800592 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700593 T=
594 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800595 \cd ..
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800596 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700597 done
Ying Wang9cd17642012-12-13 10:52:07 -0800598 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700599 if [ -f "$T/$TOPFILE" ]; then
600 echo $T
601 fi
602 fi
603 fi
604}
605
Andrew Hsieh906cb782013-09-10 17:37:14 +0800606# Return driver for "make", if any (eg. static analyzer)
607function getdriver()
608{
609 local T="$1"
610 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
611 if [ -n "$WITH_STATIC_ANALYZER" ]; then
612 echo "\
613$T/prebuilts/clang/linux-x86/host/3.3/tools/scan-build/scan-build \
614--use-analyzer $T/prebuilts/clang/linux-x86/host/3.3/bin/clang \
615--status-bugs \
616--top=$T"
617 fi
618}
619
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700620function m()
621{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800622 local T=$(gettop)
623 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700624 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800625 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700626 else
627 echo "Couldn't locate the top of the tree. Try setting TOP."
628 fi
629}
630
631function findmakefile()
632{
633 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800634 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700635 T=
636 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700637 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700638 if [ -f "$T/Android.mk" ]; then
639 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800640 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700641 return
642 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800643 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700644 done
Ying Wang9cd17642012-12-13 10:52:07 -0800645 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700646}
647
648function mm()
649{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800650 local T=$(gettop)
651 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700652 # If we're sitting in the root of the build tree, just do a
653 # normal make.
654 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800655 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700656 else
657 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800658 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700659 local MODULES=
660 local GET_INSTALL_PATH=
661 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700662 # Remove the path to top as the makefilepath needs to be relative
663 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700664 if [ ! "$T" ]; then
665 echo "Couldn't locate the top of the tree. Try setting TOP."
666 elif [ ! "$M" ]; then
667 echo "Couldn't locate a makefile from the current directory."
668 else
Ying Wanga7deb082013-08-16 13:24:47 -0700669 for ARG in $@; do
670 case $ARG in
671 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
672 esac
673 done
674 if [ -n "$GET_INSTALL_PATH" ]; then
675 MODULES=
676 ARGS=GET-INSTALL-PATH
677 else
678 MODULES=all_modules
679 ARGS=$@
680 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700681 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 -0700682 fi
683 fi
684}
685
686function mmm()
687{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800688 local T=$(gettop)
689 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700690 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800691 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800692 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800693 local ARGS=
694 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700695 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800696 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
697 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
698 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800699 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
700 if [ "$MODULES" = "" ]; then
701 MODULES=all_modules
702 fi
703 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700704 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700705 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
706 local TO_CHOP=`expr $TO_CHOP + 1`
707 local START=`PWD= /bin/pwd`
708 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700709 if [ "$MFILE" = "" ] ; then
710 MFILE=$DIR/Android.mk
711 else
712 MFILE=$MFILE/$DIR/Android.mk
713 fi
714 MAKEFILE="$MAKEFILE $MFILE"
715 else
Ying Wanga7deb082013-08-16 13:24:47 -0700716 case $DIR in
717 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
718 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
719 *) echo "No Android.mk in $DIR."; return 1;;
720 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700721 fi
722 done
Ying Wanga7deb082013-08-16 13:24:47 -0700723 if [ -n "$GET_INSTALL_PATH" ]; then
724 ARGS=$GET_INSTALL_PATH
725 MODULES=
726 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800727 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 -0700728 else
729 echo "Couldn't locate the top of the tree. Try setting TOP."
730 fi
731}
732
Ying Wangb607f7b2013-02-08 18:01:04 -0800733function mma()
734{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800735 local T=$(gettop)
736 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800737 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800738 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800739 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800740 if [ ! "$T" ]; then
741 echo "Couldn't locate the top of the tree. Try setting TOP."
742 fi
743 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800744 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800745 fi
746}
747
748function mmma()
749{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800750 local T=$(gettop)
751 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800752 if [ "$T" ]; then
753 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
754 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
755 local MY_PWD=`PWD= /bin/pwd`
756 if [ "$MY_PWD" = "$T" ]; then
757 MY_PWD=
758 else
759 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
760 fi
761 local DIR=
762 local MODULE_PATHS=
763 local ARGS=
764 for DIR in $DIRS ; do
765 if [ -d $DIR ]; then
766 if [ "$MY_PWD" = "" ]; then
767 MODULE_PATHS="$MODULE_PATHS $DIR"
768 else
769 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
770 fi
771 else
772 case $DIR in
773 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
774 *) echo "Couldn't find directory $DIR"; return 1;;
775 esac
776 fi
777 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800778 $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 -0800779 else
780 echo "Couldn't locate the top of the tree. Try setting TOP."
781 fi
782}
783
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784function croot()
785{
786 T=$(gettop)
787 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800788 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700789 else
790 echo "Couldn't locate the top of the tree. Try setting TOP."
791 fi
792}
793
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700794function cproj()
795{
796 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700797 local HERE=$PWD
798 T=
799 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
800 T=$PWD
801 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800802 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700803 return
804 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800805 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700806 done
Ying Wang9cd17642012-12-13 10:52:07 -0800807 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700808 echo "can't find Android.mk"
809}
810
Daniel Sandler47e0a882013-07-30 13:23:52 -0400811# simplified version of ps; output in the form
812# <pid> <procname>
813function qpid() {
814 local prepend=''
815 local append=''
816 if [ "$1" = "--exact" ]; then
817 prepend=' '
818 append='$'
819 shift
820 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
821 echo "usage: qpid [[--exact] <process name|pid>"
822 return 255
823 fi
824
825 local EXE="$1"
826 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700827 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400828 else
829 adb shell ps \
830 | tr -d '\r' \
831 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
832 fi
833}
834
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700835function pid()
836{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400837 local prepend=''
838 local append=''
839 if [ "$1" = "--exact" ]; then
840 prepend=' '
841 append='$'
842 shift
843 fi
844 local EXE="$1"
845 if [ "$EXE" ] ; then
846 local PID=`adb shell ps \
847 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700848 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400849 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
850 echo "$PID"
851 else
852 echo "usage: pid [--exact] <process name>"
853 return 255
854 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855}
856
Christopher Tate744ee802009-11-12 15:33:08 -0800857# systemstack - dump the current stack trace of all threads in the system process
858# to the usual ANR traces file
859function systemstack()
860{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800861 stacks system_server
862}
863
864function stacks()
865{
866 if [[ $1 =~ ^[0-9]+$ ]] ; then
867 local PID="$1"
868 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700869 local PIDLIST="$(pid $1)"
870 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
871 local PID="$PIDLIST"
872 elif [ "$PIDLIST" ] ; then
873 echo "more than one process: $1"
874 else
875 echo "no such process: $1"
876 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800877 else
878 echo "usage: stacks [pid|process name]"
879 fi
880
881 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700882 # Determine whether the process is native
883 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
884 # Dump stacks of Dalvik process
885 local TRACES=/data/anr/traces.txt
886 local ORIG=/data/anr/traces.orig
887 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800888
Jeff Brownb12c2e52013-08-19 15:14:16 -0700889 # Keep original traces to avoid clobbering
890 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800891
Jeff Brownb12c2e52013-08-19 15:14:16 -0700892 # Make sure we have a usable file
893 adb shell touch $TRACES
894 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800895
Jeff Brownb12c2e52013-08-19 15:14:16 -0700896 # Dump stacks and wait for dump to finish
897 adb shell kill -3 $PID
898 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800899
Jeff Brownb12c2e52013-08-19 15:14:16 -0700900 # Restore original stacks, and show current output
901 adb shell mv $TRACES $TMP
902 adb shell mv $ORIG $TRACES
903 adb shell cat $TMP
904 else
905 # Dump stacks of native process
906 adb shell debuggerd -b $PID
907 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800908 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800909}
910
John Michelau50200252012-11-09 11:48:04 -0600911function gdbwrapper()
912{
913 $ANDROID_TOOLCHAIN/$GDB -x "$@"
914}
915
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700916function gdbclient()
917{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800918 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
919 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
920 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
921 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
922 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800923 local ARCH=$(get_build_var TARGET_ARCH)
924 local GDB
925 case "$ARCH" in
Jean-Baptiste Querufeec98b2012-05-16 13:18:39 -0700926 x86) GDB=i686-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800927 arm) GDB=arm-linux-androideabi-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700928 mips) GDB=mipsel-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800929 *) echo "Unknown arch $ARCH"; return 1;;
930 esac
931
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700932 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
933 local EXE="$1"
934 if [ "$EXE" ] ; then
935 EXE=$1
936 else
937 EXE="app_process"
938 fi
939
940 local PORT="$2"
941 if [ "$PORT" ] ; then
942 PORT=$2
943 else
944 PORT=":5039"
945 fi
946
Chris Craik20c136a2012-11-09 18:02:19 -0800947 local PID="$3"
948 if [ "$PID" ] ; then
949 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700950 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800951 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
952 # that likely didn't work because of returning multiple processes
953 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -0700954 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -0800955 if [[ ! "$PID" =~ ^[0-9]+$ ]]
956 then
957 echo "Couldn't resolve '$3' to single PID"
958 return 1
959 else
960 echo ""
961 echo "WARNING: multiple processes matching '$3' observed, using root process"
962 echo ""
963 fi
964 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -0700965 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966 adb forward "tcp$PORT" "tcp$PORT"
967 adb shell gdbserver $PORT --attach $PID &
968 sleep 2
969 else
970 echo ""
971 echo "If you haven't done so already, do this first on the device:"
972 echo " gdbserver $PORT /system/bin/$EXE"
973 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -0800974 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700975 echo ""
976 fi
977
978 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Chris Dearman6858d512012-02-02 14:16:52 -0800979 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 -0700980 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700981 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
982 echo >>"$OUT_ROOT/gdbclient.cmds" ""
983
John Michelau50200252012-11-09 11:48:04 -0600984 gdbwrapper "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700985 else
986 echo "Unable to determine build system output dir."
987 fi
988
989}
990
991case `uname -s` in
992 Darwin)
993 function sgrep()
994 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700995 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 -0700996 }
997
998 ;;
999 *)
1000 function sgrep()
1001 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001002 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 -07001003 }
1004 ;;
1005esac
1006
Raghu Gandham8da43102012-07-25 19:57:22 -07001007function gettargetarch
1008{
1009 get_build_var TARGET_ARCH
1010}
1011
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001012function jgrep()
1013{
Joe Onoratof50e84b2011-03-15 14:15:46 -07001014 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 -07001015}
1016
1017function cgrep()
1018{
Mike Dodd0c26d342011-04-07 13:29:06 -07001019 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 -07001020}
1021
1022function resgrep()
1023{
Joe Onoratof50e84b2011-03-15 14:15:46 -07001024 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 -07001025}
1026
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001027function mangrep()
1028{
1029 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1030}
1031
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001032function sepgrep()
1033{
1034 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 "$@"
1035}
1036
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001037case `uname -s` in
1038 Darwin)
1039 function mgrep()
1040 {
Ying Wang324c2b22012-08-17 15:03:20 -07001041 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 -07001042 }
1043
1044 function treegrep()
1045 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001046 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 -07001047 }
1048
1049 ;;
1050 *)
1051 function mgrep()
1052 {
Ying Wang324c2b22012-08-17 15:03:20 -07001053 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 -07001054 }
1055
1056 function treegrep()
1057 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001058 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 -07001059 }
1060
1061 ;;
1062esac
1063
1064function getprebuilt
1065{
1066 get_abs_build_var ANDROID_PREBUILTS
1067}
1068
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001069function tracedmdump()
1070{
1071 T=$(gettop)
1072 if [ ! "$T" ]; then
1073 echo "Couldn't locate the top of the tree. Try setting TOP."
1074 return
1075 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001076 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001077 local arch=$(gettargetarch)
1078 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001079
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001080 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001081 if [ ! "$TRACE" ] ; then
1082 echo "usage: tracedmdump tracename"
1083 return
1084 fi
1085
Jack Veenstra60116fc2009-04-09 18:12:34 -07001086 if [ ! -r "$KERNEL" ] ; then
1087 echo "Error: cannot find kernel: '$KERNEL'"
1088 return
1089 fi
1090
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001091 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001092 if [ "$BASETRACE" = "$TRACE" ] ; then
1093 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1094 fi
1095
1096 echo "post-processing traces..."
1097 rm -f $TRACE/qtrace.dexlist
1098 post_trace $TRACE
1099 if [ $? -ne 0 ]; then
1100 echo "***"
1101 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1102 echo "***"
1103 return
1104 fi
1105 echo "generating dexlist output..."
1106 /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
1107 echo "generating dmtrace data..."
1108 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1109 echo "generating html file..."
1110 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1111 echo "done, see $TRACE/dmtrace.html for details"
1112 echo "or run:"
1113 echo " traceview $TRACE/dmtrace"
1114}
1115
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001116# communicate with a running device or emulator, set up necessary state,
1117# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001118function runhat()
1119{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001120 # process standard adb options
1121 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001122 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001123 adbTarget=$1
1124 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001125 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001126 adbTarget="$1 $2"
1127 shift 2
1128 fi
1129 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001130 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001131
1132 # runhat options
1133 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001134
1135 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001136 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001137 return
1138 fi
1139
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001140 # confirm hat is available
1141 if [ -z $(which hat) ]; then
1142 echo "hat is not available in this configuration."
1143 return
1144 fi
1145
Andy McFaddenb6289852010-07-12 08:00:19 -07001146 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001147 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001148 local devFile=$sdcard/hprof-$targetPid
1149 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001150 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001151 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001152 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001153 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001154 echo -n "> "
1155 read
1156
The Android Open Source Project88b60792009-03-03 19:28:42 -08001157 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001158
The Android Open Source Project88b60792009-03-03 19:28:42 -08001159 echo "Retrieving file $devFile..."
1160 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001161
The Android Open Source Project88b60792009-03-03 19:28:42 -08001162 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001163
The Android Open Source Project88b60792009-03-03 19:28:42 -08001164 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001165 echo "View the output by pointing your browser at http://localhost:7000/"
1166 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001167 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001168}
1169
1170function getbugreports()
1171{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001172 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001173
1174 if [ ! "$reports" ]; then
1175 echo "Could not locate any bugreports."
1176 return
1177 fi
1178
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001179 local report
1180 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001181 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001182 echo "/sdcard/bugreports/${report}"
1183 adb pull /sdcard/bugreports/${report} ${report}
1184 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001185 done
1186}
1187
Victoria Lease1b296b42012-08-21 15:44:06 -07001188function getsdcardpath()
1189{
1190 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1191}
1192
1193function getscreenshotpath()
1194{
1195 echo "$(getsdcardpath)/Pictures/Screenshots"
1196}
1197
1198function getlastscreenshot()
1199{
1200 local screenshot_path=$(getscreenshotpath)
1201 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1202 if [ "$screenshot" = "" ]; then
1203 echo "No screenshots found."
1204 return
1205 fi
1206 echo "${screenshot}"
1207 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1208}
1209
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001210function startviewserver()
1211{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001212 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001213 if [ $# -gt 0 ]; then
1214 port=$1
1215 fi
1216 adb shell service call window 1 i32 $port
1217}
1218
1219function stopviewserver()
1220{
1221 adb shell service call window 2
1222}
1223
1224function isviewserverstarted()
1225{
1226 adb shell service call window 3
1227}
1228
Romain Guyb84049a2010-10-04 16:56:11 -07001229function key_home()
1230{
1231 adb shell input keyevent 3
1232}
1233
1234function key_back()
1235{
1236 adb shell input keyevent 4
1237}
1238
1239function key_menu()
1240{
1241 adb shell input keyevent 82
1242}
1243
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001244function smoketest()
1245{
1246 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1247 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1248 return
1249 fi
1250 T=$(gettop)
1251 if [ ! "$T" ]; then
1252 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1253 return
1254 fi
1255
Ying Wang9cd17642012-12-13 10:52:07 -08001256 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001257 adb uninstall com.android.smoketest > /dev/null &&
1258 adb uninstall com.android.smoketest.tests > /dev/null &&
1259 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1260 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1261 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1262}
1263
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001264# simple shortcut to the runtest command
1265function runtest()
1266{
1267 T=$(gettop)
1268 if [ ! "$T" ]; then
1269 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1270 return
1271 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001272 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001273}
1274
The Android Open Source Project88b60792009-03-03 19:28:42 -08001275function godir () {
1276 if [[ -z "$1" ]]; then
1277 echo "Usage: godir <regex>"
1278 return
1279 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001280 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001281 if [[ ! -f $T/filelist ]]; then
1282 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001283 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001284 echo " Done"
1285 echo ""
1286 fi
1287 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001288 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001289 if [[ ${#lines[@]} = 0 ]]; then
1290 echo "Not found"
1291 return
1292 fi
1293 local pathname
1294 local choice
1295 if [[ ${#lines[@]} > 1 ]]; then
1296 while [[ -z "$pathname" ]]; do
1297 local index=1
1298 local line
1299 for line in ${lines[@]}; do
1300 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001301 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001302 done
1303 echo
1304 echo -n "Select one: "
1305 unset choice
1306 read choice
1307 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1308 echo "Invalid choice"
1309 continue
1310 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001311 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001312 done
1313 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001314 pathname=${lines[0]}
1315 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001316 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001317}
1318
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001319# Force JAVA_HOME to point to java 1.6 if it isn't already set
1320function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001321 if [ ! "$JAVA_HOME" ]; then
1322 case `uname -s` in
1323 Darwin)
1324 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1325 ;;
1326 *)
1327 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1328 ;;
1329 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001330 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001331}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001332
Alex Rayf0d08eb2013-03-08 15:15:06 -08001333# Print colored exit condition
1334function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001335 "$@"
1336 local retval=$?
1337 if [ $retval -ne 0 ]
1338 then
1339 echo -e "\e[0;31mFAILURE\e[00m"
1340 else
1341 echo -e "\e[0;32mSUCCESS\e[00m"
1342 fi
1343 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001344}
1345
Raphael Moll70a86b02011-06-20 16:03:14 -07001346if [ "x$SHELL" != "x/bin/bash" ]; then
1347 case `ps -o command -p $$` in
1348 *bash*)
1349 ;;
1350 *)
1351 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1352 ;;
1353 esac
1354fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001355
1356# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001357for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1358 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001359do
1360 echo "including $f"
1361 . $f
1362done
1363unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001364
1365addcompletions