blob: 45768c12678bb8cb333ae9fbd48516949a2576fd [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Ying Wang67f02922012-08-22 10:25:20 -07004- lunch: lunch <product_name>-<build_variant>
Ying Wangf05c4f72013-01-31 11:16:57 -08005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [eng|userdebug|user]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07006- croot: Changes directory to the top of the tree.
7- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08008- mm: Builds all of the modules in the current directory, but not their dependencies.
9- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000010 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080011- mma: Builds all of the modules in the current directory, and their dependencies.
12- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070013- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070014- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070015- jgrep: Greps on all local Java files.
16- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080017- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070018
19Look at the source to view more functions. The complete list is:
20EOF
21 T=$(gettop)
22 local A
23 A=""
24 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
25 A="$A $i"
26 done
27 echo $A
28}
29
30# Get the value of a build variable as an absolute path.
31function get_abs_build_var()
32{
33 T=$(gettop)
34 if [ ! "$T" ]; then
35 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
36 return
37 fi
Ying Wang9cd17642012-12-13 10:52:07 -080038 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Andrew Boie6905e212013-12-19 13:21:46 -080039 make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070040}
41
42# Get the exact value of a build variable.
43function get_build_var()
44{
45 T=$(gettop)
46 if [ ! "$T" ]; then
47 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
48 return
49 fi
Andrew Boie6905e212013-12-19 13:21:46 -080050 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
51 make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080052}
53
54# check to see if the supplied product is one we can build
55function check_product()
56{
57 T=$(gettop)
58 if [ ! "$T" ]; then
59 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
60 return
61 fi
62 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Jeff Browne33ba4c2011-07-11 22:11:46 -070063 TARGET_PRODUCT=$1 \
64 TARGET_BUILD_VARIANT= \
65 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070066 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080067 get_build_var TARGET_DEVICE > /dev/null
68 # hide successful answers, but allow the errors to show
69}
70
71VARIANT_CHOICES=(user userdebug eng)
72
73# check to see if the supplied variant is valid
74function check_variant()
75{
76 for v in ${VARIANT_CHOICES[@]}
77 do
78 if [ "$v" = "$1" ]
79 then
80 return 0
81 fi
82 done
83 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070084}
85
86function setpaths()
87{
88 T=$(gettop)
89 if [ ! "$T" ]; then
90 echo "Couldn't locate the top of the tree. Try setting TOP."
91 return
92 fi
93
94 ##################################################################
95 # #
96 # Read me before you modify this code #
97 # #
98 # This function sets ANDROID_BUILD_PATHS to what it is adding #
99 # to PATH, and the next time it is run, it removes that from #
100 # PATH. This is required so lunch can be run more than once #
101 # and still have working paths. #
102 # #
103 ##################################################################
104
Raphael Mollc639c782011-06-20 17:25:01 -0700105 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
106 # due to "C:\Program Files" being in the path.
107
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700108 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700109 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700110 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
111 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700112 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700113 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800114 # strip leading ':', if any
115 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500116 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700117
118 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700119 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700120 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700121
Ben Cheng8bc4c432012-11-16 13:29:13 -0800122 # defined in core/config.mk
123 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800124 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800125
Raphael Mollc639c782011-06-20 17:25:01 -0700126 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800127 export ANDROID_TOOLCHAIN=
128 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200129 local ARCH=$(get_build_var TARGET_ARCH)
130 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400131 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700132 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400133 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
134 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800135 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200136 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800137 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
138 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700139 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800140 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700141 ;;
Chris Dearman1efd9e42014-02-03 15:01:24 -0800142 mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000143 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200144 *)
145 echo "Can't find toolchain for unknown architecture: $ARCH"
146 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700147 ;;
148 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700149 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800150 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700151 fi
Raphael732936d2011-06-22 14:35:32 -0700152
Ben Chengfba67bf2014-02-25 10:27:07 -0800153 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
154 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
155 fi
156
157 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700158 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700159 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800160 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800161 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700162 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100163 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
164 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700165 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700166 ;;
167 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700168 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700169 ;;
170 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700171
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700172 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700173 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100174 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200175
176 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
177 # to ensure that the corresponding 'emulator' binaries are used.
178 case $(uname -s) in
179 Darwin)
180 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
181 ;;
182 Linux)
183 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
184 ;;
185 *)
186 ANDROID_EMULATOR_PREBUILTS=
187 ;;
188 esac
189 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
190 ANDROID_BUILD_PATHS=$ANDROID_EMULATOR_PREBUILTS:$ANDROID_BUILD_PATHS
191 export ANDROID_EMULATOR_PREBUILTS
192 fi
193
Ying Wangaa1c9b52012-11-26 20:51:59 -0800194 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800195
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500196 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900197 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500198 if [ -n "$JAVA_HOME" ]; then
199 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900200 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
201 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500202 fi
203
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800204 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700205 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
206 export OUT=$ANDROID_PRODUCT_OUT
207
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700208 unset ANDROID_HOST_OUT
209 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
210
David 'Digit' Turner7cde0302014-05-05 16:13:50 +0200211 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
212 # to ensure that the corresponding 'emulator' binaries are used.
213 case $(uname -s) in
214 Darwin)
215 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
216 ;;
217 Linux)
218 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
219 ;;
220 *)
221 ANDROID_EMULATOR_PREBUILTS=
222 ;;
223 esac
224 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
225 PATH=$ANDROID_EMULATOR_PREBUILTS:$PATH
226 export ANDROID_EMULATOR_PREBUILTS
227 fi
228
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800229 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700230 # TODO: fix the path
231 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
232}
233
234function printconfig()
235{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800236 T=$(gettop)
237 if [ ! "$T" ]; then
238 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
239 return
240 fi
241 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700242}
243
244function set_stuff_for_environment()
245{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800246 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500247 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800248 setpaths
249 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700250
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700252 # With this environment variable new GCC can apply colors to warnings/errors
253 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 -0700254}
255
256function set_sequence_number()
257{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700258 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700259}
260
261function settitle()
262{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800263 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700264 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700265 local product=$TARGET_PRODUCT
266 local variant=$TARGET_BUILD_VARIANT
267 local apps=$TARGET_BUILD_APPS
268 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700269 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700270 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700271 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700272 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800273 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700274}
275
Kenny Root52aa81c2011-07-15 11:07:06 -0700276function addcompletions()
277{
278 local T dir f
279
280 # Keep us from trying to run in something that isn't bash.
281 if [ -z "${BASH_VERSION}" ]; then
282 return
283 fi
284
285 # Keep us from trying to run in bash that's too old.
286 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
287 return
288 fi
289
290 dir="sdk/bash_completion"
291 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700292 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700293 echo "including $f"
294 . $f
295 done
296 fi
297}
298
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700299function choosetype()
300{
301 echo "Build type choices are:"
302 echo " 1. release"
303 echo " 2. debug"
304 echo
305
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800306 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700307 DEFAULT_NUM=1
308 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800310 export TARGET_BUILD_TYPE=
311 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700312 while [ -z $TARGET_BUILD_TYPE ]
313 do
314 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800315 if [ -z "$1" ] ; then
316 read ANSWER
317 else
318 echo $1
319 ANSWER=$1
320 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321 case $ANSWER in
322 "")
323 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
324 ;;
325 1)
326 export TARGET_BUILD_TYPE=release
327 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800328 release)
329 export TARGET_BUILD_TYPE=release
330 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700331 2)
332 export TARGET_BUILD_TYPE=debug
333 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800334 debug)
335 export TARGET_BUILD_TYPE=debug
336 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700337 *)
338 echo
339 echo "I didn't understand your response. Please try again."
340 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700341 ;;
342 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800343 if [ -n "$1" ] ; then
344 break
345 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346 done
347
348 set_stuff_for_environment
349}
350
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800351#
352# This function isn't really right: It chooses a TARGET_PRODUCT
353# based on the list of boards. Usually, that gets you something
354# that kinda works with a generic product, but really, you should
355# pick a product by name.
356#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700357function chooseproduct()
358{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700359 if [ "x$TARGET_PRODUCT" != x ] ; then
360 default_value=$TARGET_PRODUCT
361 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700362 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700363 fi
364
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800365 export TARGET_PRODUCT=
366 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700367 while [ -z "$TARGET_PRODUCT" ]
368 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700369 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800370 if [ -z "$1" ] ; then
371 read ANSWER
372 else
373 echo $1
374 ANSWER=$1
375 fi
376
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700377 if [ -z "$ANSWER" ] ; then
378 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800379 else
380 if check_product $ANSWER
381 then
382 export TARGET_PRODUCT=$ANSWER
383 else
384 echo "** Not a valid product: $ANSWER"
385 fi
386 fi
387 if [ -n "$1" ] ; then
388 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700389 fi
390 done
391
392 set_stuff_for_environment
393}
394
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800395function choosevariant()
396{
397 echo "Variant choices are:"
398 local index=1
399 local v
400 for v in ${VARIANT_CHOICES[@]}
401 do
402 # The product name is the name of the directory containing
403 # the makefile we found, above.
404 echo " $index. $v"
405 index=$(($index+1))
406 done
407
408 local default_value=eng
409 local ANSWER
410
411 export TARGET_BUILD_VARIANT=
412 while [ -z "$TARGET_BUILD_VARIANT" ]
413 do
414 echo -n "Which would you like? [$default_value] "
415 if [ -z "$1" ] ; then
416 read ANSWER
417 else
418 echo $1
419 ANSWER=$1
420 fi
421
422 if [ -z "$ANSWER" ] ; then
423 export TARGET_BUILD_VARIANT=$default_value
424 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
425 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800426 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800427 fi
428 else
429 if check_variant $ANSWER
430 then
431 export TARGET_BUILD_VARIANT=$ANSWER
432 else
433 echo "** Not a valid variant: $ANSWER"
434 fi
435 fi
436 if [ -n "$1" ] ; then
437 break
438 fi
439 done
440}
441
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700442function choosecombo()
443{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700444 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700445
446 echo
447 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700448 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449
450 echo
451 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700452 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800453
454 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700455 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800456 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700457}
458
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800459# Clear this variable. It will be built up again when the vendorsetup.sh
460# files are included at the end of this file.
461unset LUNCH_MENU_CHOICES
462function add_lunch_combo()
463{
464 local new_combo=$1
465 local c
466 for c in ${LUNCH_MENU_CHOICES[@]} ; do
467 if [ "$new_combo" = "$c" ] ; then
468 return
469 fi
470 done
471 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
472}
473
474# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700475add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800476add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000477add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800478add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000479add_lunch_combo aosp_x86-eng
480add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800481add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483function print_lunch_menu()
484{
485 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486 echo
487 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700488 echo
489 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490
491 local i=1
492 local choice
493 for choice in ${LUNCH_MENU_CHOICES[@]}
494 do
495 echo " $i. $choice"
496 i=$(($i+1))
497 done
498
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700499 echo
500}
501
502function lunch()
503{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 local answer
505
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 else
509 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700510 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700512 fi
513
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800514 local selection=
515
516 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700517 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700518 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800519 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
520 then
521 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
522 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800523 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800524 fi
525 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
526 then
527 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700528 fi
529
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530 if [ -z "$selection" ]
531 then
532 echo
533 echo "Invalid lunch combo: $answer"
534 return 1
535 fi
536
Joe Onoratoda12daf2010-06-09 18:18:31 -0700537 export TARGET_BUILD_APPS=
538
Jeff Browne33ba4c2011-07-11 22:11:46 -0700539 local product=$(echo -n $selection | sed -e "s/-.*$//")
540 check_product $product
541 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800542 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700543 echo
544 echo "** Don't have a product spec for: '$product'"
545 echo "** Do you have the right repo manifest?"
546 product=
547 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800548
Jeff Browne33ba4c2011-07-11 22:11:46 -0700549 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
550 check_variant $variant
551 if [ $? -ne 0 ]
552 then
553 echo
554 echo "** Invalid variant: '$variant'"
555 echo "** Must be one of ${VARIANT_CHOICES[@]}"
556 variant=
557 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800558
Jeff Browne33ba4c2011-07-11 22:11:46 -0700559 if [ -z "$product" -o -z "$variant" ]
560 then
561 echo
562 return 1
563 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800564
Jeff Browne33ba4c2011-07-11 22:11:46 -0700565 export TARGET_PRODUCT=$product
566 export TARGET_BUILD_VARIANT=$variant
567 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700568
569 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800570
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700571 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800572 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700573}
574
Jeff Davidson513d7a42010-08-02 10:00:44 -0700575# Tab completion for lunch.
576function _lunch()
577{
578 local cur prev opts
579 COMPREPLY=()
580 cur="${COMP_WORDS[COMP_CWORD]}"
581 prev="${COMP_WORDS[COMP_CWORD-1]}"
582
583 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
584 return 0
585}
586complete -F _lunch lunch
587
Joe Onoratoda12daf2010-06-09 18:18:31 -0700588# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700589# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700590function tapas()
591{
Doug Zongker0d8179e2014-04-16 11:34:34 -0700592 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$' | xargs)"
593 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
594 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700595
Ying Wang67f02922012-08-22 10:25:20 -0700596 if [ $(echo $arch | wc -w) -gt 1 ]; then
597 echo "tapas: Error: Multiple build archs supplied: $arch"
598 return
599 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700600 if [ $(echo $variant | wc -w) -gt 1 ]; then
601 echo "tapas: Error: Multiple build variants supplied: $variant"
602 return
603 fi
Ying Wang67f02922012-08-22 10:25:20 -0700604
605 local product=full
606 case $arch in
607 x86) product=full_x86;;
608 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800609 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700610 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700611 if [ -z "$variant" ]; then
612 variant=eng
613 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700614 if [ -z "$apps" ]; then
615 apps=all
616 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700617
Ying Wang67f02922012-08-22 10:25:20 -0700618 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700619 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700620 export TARGET_BUILD_TYPE=release
621 export TARGET_BUILD_APPS=$apps
622
623 set_stuff_for_environment
624 printconfig
625}
626
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700627function gettop
628{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800629 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700630 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
631 echo $TOP
632 else
633 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800634 # The following circumlocution (repeated below as well) ensures
635 # that we record the true directory name and not one that is
636 # faked up with symlink names.
637 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700638 else
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 Wang9cd17642012-12-13 10:52:07 -0800642 \cd ..
synergyb112a402013-07-05 19:47:47 -0700643 T=`PWD= /bin/pwd -P`
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 if [ -f "$T/$TOPFILE" ]; then
647 echo $T
648 fi
649 fi
650 fi
651}
652
Andrew Hsieh906cb782013-09-10 17:37:14 +0800653# Return driver for "make", if any (eg. static analyzer)
654function getdriver()
655{
656 local T="$1"
657 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
658 if [ -n "$WITH_STATIC_ANALYZER" ]; then
659 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800660$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
661--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800662--status-bugs \
663--top=$T"
664 fi
665}
666
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700667function m()
668{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800669 local T=$(gettop)
670 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700671 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800672 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700673 else
674 echo "Couldn't locate the top of the tree. Try setting TOP."
675 fi
676}
677
678function findmakefile()
679{
680 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800681 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700682 T=
683 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700684 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700685 if [ -f "$T/Android.mk" ]; then
686 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800687 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700688 return
689 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800690 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700691 done
Ying Wang9cd17642012-12-13 10:52:07 -0800692 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700693}
694
695function mm()
696{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800697 local T=$(gettop)
698 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700699 # If we're sitting in the root of the build tree, just do a
700 # normal make.
701 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800702 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700703 else
704 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800705 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700706 local MODULES=
707 local GET_INSTALL_PATH=
708 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700709 # Remove the path to top as the makefilepath needs to be relative
710 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700711 if [ ! "$T" ]; then
712 echo "Couldn't locate the top of the tree. Try setting TOP."
713 elif [ ! "$M" ]; then
714 echo "Couldn't locate a makefile from the current directory."
715 else
Ying Wanga7deb082013-08-16 13:24:47 -0700716 for ARG in $@; do
717 case $ARG in
718 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
719 esac
720 done
721 if [ -n "$GET_INSTALL_PATH" ]; then
722 MODULES=
723 ARGS=GET-INSTALL-PATH
724 else
725 MODULES=all_modules
726 ARGS=$@
727 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700728 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 -0700729 fi
730 fi
731}
732
733function mmm()
734{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800735 local T=$(gettop)
736 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700737 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800738 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800739 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800740 local ARGS=
741 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700742 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800743 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
744 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
745 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800746 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
747 if [ "$MODULES" = "" ]; then
748 MODULES=all_modules
749 fi
750 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700751 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700752 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
753 local TO_CHOP=`expr $TO_CHOP + 1`
754 local START=`PWD= /bin/pwd`
755 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700756 if [ "$MFILE" = "" ] ; then
757 MFILE=$DIR/Android.mk
758 else
759 MFILE=$MFILE/$DIR/Android.mk
760 fi
761 MAKEFILE="$MAKEFILE $MFILE"
762 else
Ying Wanga7deb082013-08-16 13:24:47 -0700763 case $DIR in
764 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
765 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
766 *) echo "No Android.mk in $DIR."; return 1;;
767 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700768 fi
769 done
Ying Wanga7deb082013-08-16 13:24:47 -0700770 if [ -n "$GET_INSTALL_PATH" ]; then
771 ARGS=$GET_INSTALL_PATH
772 MODULES=
773 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800774 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 -0700775 else
776 echo "Couldn't locate the top of the tree. Try setting TOP."
777 fi
778}
779
Ying Wangb607f7b2013-02-08 18:01:04 -0800780function mma()
781{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800782 local T=$(gettop)
783 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800784 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800785 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800786 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800787 if [ ! "$T" ]; then
788 echo "Couldn't locate the top of the tree. Try setting TOP."
789 fi
790 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800791 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800792 fi
793}
794
795function mmma()
796{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800797 local T=$(gettop)
798 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800799 if [ "$T" ]; then
800 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
801 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
802 local MY_PWD=`PWD= /bin/pwd`
803 if [ "$MY_PWD" = "$T" ]; then
804 MY_PWD=
805 else
806 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
807 fi
808 local DIR=
809 local MODULE_PATHS=
810 local ARGS=
811 for DIR in $DIRS ; do
812 if [ -d $DIR ]; then
813 if [ "$MY_PWD" = "" ]; then
814 MODULE_PATHS="$MODULE_PATHS $DIR"
815 else
816 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
817 fi
818 else
819 case $DIR in
820 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
821 *) echo "Couldn't find directory $DIR"; return 1;;
822 esac
823 fi
824 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800825 $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 -0800826 else
827 echo "Couldn't locate the top of the tree. Try setting TOP."
828 fi
829}
830
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700831function croot()
832{
833 T=$(gettop)
834 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800835 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700836 else
837 echo "Couldn't locate the top of the tree. Try setting TOP."
838 fi
839}
840
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700841function cproj()
842{
843 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700844 local HERE=$PWD
845 T=
846 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
847 T=$PWD
848 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800849 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700850 return
851 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800852 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700853 done
Ying Wang9cd17642012-12-13 10:52:07 -0800854 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700855 echo "can't find Android.mk"
856}
857
Daniel Sandler47e0a882013-07-30 13:23:52 -0400858# simplified version of ps; output in the form
859# <pid> <procname>
860function qpid() {
861 local prepend=''
862 local append=''
863 if [ "$1" = "--exact" ]; then
864 prepend=' '
865 append='$'
866 shift
867 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
868 echo "usage: qpid [[--exact] <process name|pid>"
869 return 255
870 fi
871
872 local EXE="$1"
873 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700874 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400875 else
876 adb shell ps \
877 | tr -d '\r' \
878 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
879 fi
880}
881
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700882function pid()
883{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400884 local prepend=''
885 local append=''
886 if [ "$1" = "--exact" ]; then
887 prepend=' '
888 append='$'
889 shift
890 fi
891 local EXE="$1"
892 if [ "$EXE" ] ; then
893 local PID=`adb shell ps \
894 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700895 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400896 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
897 echo "$PID"
898 else
899 echo "usage: pid [--exact] <process name>"
900 return 255
901 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700902}
903
Christopher Tate744ee802009-11-12 15:33:08 -0800904# systemstack - dump the current stack trace of all threads in the system process
905# to the usual ANR traces file
906function systemstack()
907{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800908 stacks system_server
909}
910
911function stacks()
912{
913 if [[ $1 =~ ^[0-9]+$ ]] ; then
914 local PID="$1"
915 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700916 local PIDLIST="$(pid $1)"
917 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
918 local PID="$PIDLIST"
919 elif [ "$PIDLIST" ] ; then
920 echo "more than one process: $1"
921 else
922 echo "no such process: $1"
923 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800924 else
925 echo "usage: stacks [pid|process name]"
926 fi
927
928 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700929 # Determine whether the process is native
930 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
931 # Dump stacks of Dalvik process
932 local TRACES=/data/anr/traces.txt
933 local ORIG=/data/anr/traces.orig
934 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800935
Jeff Brownb12c2e52013-08-19 15:14:16 -0700936 # Keep original traces to avoid clobbering
937 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800938
Jeff Brownb12c2e52013-08-19 15:14:16 -0700939 # Make sure we have a usable file
940 adb shell touch $TRACES
941 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800942
Jeff Brownb12c2e52013-08-19 15:14:16 -0700943 # Dump stacks and wait for dump to finish
944 adb shell kill -3 $PID
945 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800946
Jeff Brownb12c2e52013-08-19 15:14:16 -0700947 # Restore original stacks, and show current output
948 adb shell mv $TRACES $TMP
949 adb shell mv $ORIG $TRACES
950 adb shell cat $TMP
951 else
952 # Dump stacks of native process
953 adb shell debuggerd -b $PID
954 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800955 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800956}
957
John Michelau50200252012-11-09 11:48:04 -0600958function gdbwrapper()
959{
Ben Chengfba67bf2014-02-25 10:27:07 -0800960 local GDB_CMD="$1"
961 shift 1
962 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -0600963}
964
Ben Chengfba67bf2014-02-25 10:27:07 -0800965# process the symbolic link of /proc/$PID/exe and use the host file tool to
966# determine whether it is a 32-bit or 64-bit executable. It returns "" or "64"
967# which can be conveniently used as suffix.
968function is64bit()
969{
970 local PID="$1"
971 if [ "$PID" ] ; then
972 local EXE=`adb shell ls -l /proc/$PID/exe \
973 | tr -d '\r' \
974 | cut -d'>' -f2 \
975 | tr -d ' ' \
976 | cut -d'/' -f4`
977
978 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
979 local IS64BIT=`file $OUT_EXE_SYMBOLS/$EXE | grep "64-bit"`
980 if [ "$IS64BIT" != "" ]; then
981 echo "64"
982 else
983 echo ""
984 fi
985 else
986 echo ""
987 fi
988}
989
990# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
991# executable, set up the approriate gdbserver, then invokes the proper host
992# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700993function gdbclient()
994{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800995 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
996 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
997 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
998 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
999 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001000 local ARCH=$(get_build_var TARGET_ARCH)
1001 local GDB
1002 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001003 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -08001004 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -07001005 mips) GDB=mipsel-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +00001006 mips64) GDB=mipsel-linux-android-gdb;;
1007 x86) GDB=x86_64-linux-android-gdb;;
1008 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001009 *) echo "Unknown arch $ARCH"; return 1;;
1010 esac
1011
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001012 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1013 local EXE="$1"
1014 if [ "$EXE" ] ; then
1015 EXE=$1
1016 else
1017 EXE="app_process"
1018 fi
1019
1020 local PORT="$2"
1021 if [ "$PORT" ] ; then
1022 PORT=$2
1023 else
1024 PORT=":5039"
1025 fi
1026
Chris Craik20c136a2012-11-09 18:02:19 -08001027 local PID="$3"
1028 if [ "$PID" ] ; then
1029 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -07001030 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -08001031 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1032 # that likely didn't work because of returning multiple processes
1033 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001034 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001035 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1036 then
1037 echo "Couldn't resolve '$3' to single PID"
1038 return 1
1039 else
1040 echo ""
1041 echo "WARNING: multiple processes matching '$3' observed, using root process"
1042 echo ""
1043 fi
1044 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001045 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001046 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001047 local USE64BIT="$(is64bit $PID)"
1048 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001049 sleep 2
1050 else
1051 echo ""
1052 echo "If you haven't done so already, do this first on the device:"
1053 echo " gdbserver $PORT /system/bin/$EXE"
1054 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001055 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001056 echo ""
1057 fi
1058
Colin Cross84480ad2014-04-10 12:51:39 -07001059 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1060
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001061 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Colin Cross84480ad2014-04-10 12:51:39 -07001062 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 -07001063 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001064 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1065 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1066
Ben Chengfba67bf2014-02-25 10:27:07 -08001067 local WHICH_GDB=
1068 # 64-bit exe found
1069 if [ "$USE64BIT" != "" ] ; then
1070 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1071 # 32-bit exe / 32-bit platform
1072 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1073 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1074 # 32-bit exe / 64-bit platform
1075 else
1076 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1077 fi
1078 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001079 else
1080 echo "Unable to determine build system output dir."
1081 fi
1082
1083}
1084
1085case `uname -s` in
1086 Darwin)
1087 function sgrep()
1088 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001089 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 -07001090 }
1091
1092 ;;
1093 *)
1094 function sgrep()
1095 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001096 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 -07001097 }
1098 ;;
1099esac
1100
Raghu Gandham8da43102012-07-25 19:57:22 -07001101function gettargetarch
1102{
1103 get_build_var TARGET_ARCH
1104}
1105
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001106function ggrep()
1107{
1108 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1109}
1110
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001111function jgrep()
1112{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001113 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001114}
1115
1116function cgrep()
1117{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001118 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001119}
1120
1121function resgrep()
1122{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001123 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001124}
1125
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001126function mangrep()
1127{
1128 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1129}
1130
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001131function sepgrep()
1132{
1133 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 "$@"
1134}
1135
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001136case `uname -s` in
1137 Darwin)
1138 function mgrep()
1139 {
Ying Wang324c2b22012-08-17 15:03:20 -07001140 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 -07001141 }
1142
1143 function treegrep()
1144 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001145 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 -07001146 }
1147
1148 ;;
1149 *)
1150 function mgrep()
1151 {
Ying Wang324c2b22012-08-17 15:03:20 -07001152 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 -07001153 }
1154
1155 function treegrep()
1156 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001157 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 -07001158 }
1159
1160 ;;
1161esac
1162
1163function getprebuilt
1164{
1165 get_abs_build_var ANDROID_PREBUILTS
1166}
1167
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001168function tracedmdump()
1169{
1170 T=$(gettop)
1171 if [ ! "$T" ]; then
1172 echo "Couldn't locate the top of the tree. Try setting TOP."
1173 return
1174 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001175 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001176 local arch=$(gettargetarch)
1177 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001178
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001179 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001180 if [ ! "$TRACE" ] ; then
1181 echo "usage: tracedmdump tracename"
1182 return
1183 fi
1184
Jack Veenstra60116fc2009-04-09 18:12:34 -07001185 if [ ! -r "$KERNEL" ] ; then
1186 echo "Error: cannot find kernel: '$KERNEL'"
1187 return
1188 fi
1189
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001190 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001191 if [ "$BASETRACE" = "$TRACE" ] ; then
1192 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1193 fi
1194
1195 echo "post-processing traces..."
1196 rm -f $TRACE/qtrace.dexlist
1197 post_trace $TRACE
1198 if [ $? -ne 0 ]; then
1199 echo "***"
1200 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1201 echo "***"
1202 return
1203 fi
1204 echo "generating dexlist output..."
1205 /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
1206 echo "generating dmtrace data..."
1207 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1208 echo "generating html file..."
1209 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1210 echo "done, see $TRACE/dmtrace.html for details"
1211 echo "or run:"
1212 echo " traceview $TRACE/dmtrace"
1213}
1214
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001215# communicate with a running device or emulator, set up necessary state,
1216# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001217function runhat()
1218{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001219 # process standard adb options
1220 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001221 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001222 adbTarget=$1
1223 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001224 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001225 adbTarget="$1 $2"
1226 shift 2
1227 fi
1228 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001229 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001230
1231 # runhat options
1232 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001233
1234 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001235 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236 return
1237 fi
1238
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001239 # confirm hat is available
1240 if [ -z $(which hat) ]; then
1241 echo "hat is not available in this configuration."
1242 return
1243 fi
1244
Andy McFaddenb6289852010-07-12 08:00:19 -07001245 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001246 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001247 local devFile=$sdcard/hprof-$targetPid
1248 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001249 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001250 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001251 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001252 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001253 echo -n "> "
1254 read
1255
The Android Open Source Project88b60792009-03-03 19:28:42 -08001256 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001257
The Android Open Source Project88b60792009-03-03 19:28:42 -08001258 echo "Retrieving file $devFile..."
1259 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001260
The Android Open Source Project88b60792009-03-03 19:28:42 -08001261 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001262
The Android Open Source Project88b60792009-03-03 19:28:42 -08001263 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001264 echo "View the output by pointing your browser at http://localhost:7000/"
1265 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001266 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001267}
1268
1269function getbugreports()
1270{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001271 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001272
1273 if [ ! "$reports" ]; then
1274 echo "Could not locate any bugreports."
1275 return
1276 fi
1277
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001278 local report
1279 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001280 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001281 echo "/sdcard/bugreports/${report}"
1282 adb pull /sdcard/bugreports/${report} ${report}
1283 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001284 done
1285}
1286
Victoria Lease1b296b42012-08-21 15:44:06 -07001287function getsdcardpath()
1288{
1289 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1290}
1291
1292function getscreenshotpath()
1293{
1294 echo "$(getsdcardpath)/Pictures/Screenshots"
1295}
1296
1297function getlastscreenshot()
1298{
1299 local screenshot_path=$(getscreenshotpath)
1300 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1301 if [ "$screenshot" = "" ]; then
1302 echo "No screenshots found."
1303 return
1304 fi
1305 echo "${screenshot}"
1306 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1307}
1308
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001309function startviewserver()
1310{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001311 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001312 if [ $# -gt 0 ]; then
1313 port=$1
1314 fi
1315 adb shell service call window 1 i32 $port
1316}
1317
1318function stopviewserver()
1319{
1320 adb shell service call window 2
1321}
1322
1323function isviewserverstarted()
1324{
1325 adb shell service call window 3
1326}
1327
Romain Guyb84049a2010-10-04 16:56:11 -07001328function key_home()
1329{
1330 adb shell input keyevent 3
1331}
1332
1333function key_back()
1334{
1335 adb shell input keyevent 4
1336}
1337
1338function key_menu()
1339{
1340 adb shell input keyevent 82
1341}
1342
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001343function smoketest()
1344{
1345 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1346 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1347 return
1348 fi
1349 T=$(gettop)
1350 if [ ! "$T" ]; then
1351 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1352 return
1353 fi
1354
Ying Wang9cd17642012-12-13 10:52:07 -08001355 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001356 adb uninstall com.android.smoketest > /dev/null &&
1357 adb uninstall com.android.smoketest.tests > /dev/null &&
1358 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1359 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1360 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1361}
1362
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001363# simple shortcut to the runtest command
1364function runtest()
1365{
1366 T=$(gettop)
1367 if [ ! "$T" ]; then
1368 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1369 return
1370 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001371 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001372}
1373
The Android Open Source Project88b60792009-03-03 19:28:42 -08001374function godir () {
1375 if [[ -z "$1" ]]; then
1376 echo "Usage: godir <regex>"
1377 return
1378 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001379 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001380 if [[ ! -f $T/filelist ]]; then
1381 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001382 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001383 echo " Done"
1384 echo ""
1385 fi
1386 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001387 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001388 if [[ ${#lines[@]} = 0 ]]; then
1389 echo "Not found"
1390 return
1391 fi
1392 local pathname
1393 local choice
1394 if [[ ${#lines[@]} > 1 ]]; then
1395 while [[ -z "$pathname" ]]; do
1396 local index=1
1397 local line
1398 for line in ${lines[@]}; do
1399 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001400 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001401 done
1402 echo
1403 echo -n "Select one: "
1404 unset choice
1405 read choice
1406 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1407 echo "Invalid choice"
1408 continue
1409 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001410 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001411 done
1412 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001413 pathname=${lines[0]}
1414 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001415 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001416}
1417
Narayan Kamath9260bba2014-01-17 10:05:25 +00001418# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1419#
1420# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1421# For some reason, installing the JDK doesn't make it show up in the
1422# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001423function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001424 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001425 # we can reset it later, depending on the version of java the build
1426 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001427 #
1428 # If we don't do this, the JAVA_HOME value set by the first call to
1429 # build/envsetup.sh will persist forever.
1430 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1431 export JAVA_HOME=""
1432 fi
1433
Andy McFaddenbd960942010-06-24 12:52:51 -07001434 if [ ! "$JAVA_HOME" ]; then
Narayan Kamathc84889b2014-04-01 14:16:26 +01001435 if [ -n "$LEGACY_USE_JAVA6" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001436 case `uname -s` in
1437 Darwin)
1438 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1439 ;;
1440 *)
1441 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1442 ;;
1443 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001444 else
1445 case `uname -s` in
1446 Darwin)
Jason Parks13b2e192014-04-28 13:32:10 -05001447 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
Narayan Kamath9260bba2014-01-17 10:05:25 +00001448 ;;
1449 *)
1450 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1451 ;;
1452 esac
1453 fi
1454
1455 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1456 # we can change it on the next envsetup.sh, if required.
1457 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001458 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001459}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001460
Alex Rayf0d08eb2013-03-08 15:15:06 -08001461# Print colored exit condition
1462function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001463 "$@"
1464 local retval=$?
1465 if [ $retval -ne 0 ]
1466 then
1467 echo -e "\e[0;31mFAILURE\e[00m"
1468 else
1469 echo -e "\e[0;32mSUCCESS\e[00m"
1470 fi
1471 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001472}
1473
Raphael Moll70a86b02011-06-20 16:03:14 -07001474if [ "x$SHELL" != "x/bin/bash" ]; then
1475 case `ps -o command -p $$` in
1476 *bash*)
1477 ;;
1478 *)
1479 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1480 ;;
1481 esac
1482fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001483
1484# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001485for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1486 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001487do
1488 echo "including $f"
1489 . $f
1490done
1491unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001492
1493addcompletions