blob: f75bf8859976219c459f36a2f9a8040538585dcb [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.
14- jgrep: Greps on all local Java files.
15- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080016- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070017
18Look at the source to view more functions. The complete list is:
19EOF
20 T=$(gettop)
21 local A
22 A=""
23 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
24 A="$A $i"
25 done
26 echo $A
27}
28
29# Get the value of a build variable as an absolute path.
30function get_abs_build_var()
31{
32 T=$(gettop)
33 if [ ! "$T" ]; then
34 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
35 return
36 fi
Ying Wang9cd17642012-12-13 10:52:07 -080037 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Andrew Boie6905e212013-12-19 13:21:46 -080038 make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070039}
40
41# Get the exact value of a build variable.
42function get_build_var()
43{
44 T=$(gettop)
45 if [ ! "$T" ]; then
46 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
47 return
48 fi
Andrew Boie6905e212013-12-19 13:21:46 -080049 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
50 make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080051}
52
53# check to see if the supplied product is one we can build
54function check_product()
55{
56 T=$(gettop)
57 if [ ! "$T" ]; then
58 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
59 return
60 fi
61 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Jeff Browne33ba4c2011-07-11 22:11:46 -070062 TARGET_PRODUCT=$1 \
63 TARGET_BUILD_VARIANT= \
64 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070065 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080066 get_build_var TARGET_DEVICE > /dev/null
67 # hide successful answers, but allow the errors to show
68}
69
70VARIANT_CHOICES=(user userdebug eng)
71
72# check to see if the supplied variant is valid
73function check_variant()
74{
75 for v in ${VARIANT_CHOICES[@]}
76 do
77 if [ "$v" = "$1" ]
78 then
79 return 0
80 fi
81 done
82 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070083}
84
85function setpaths()
86{
87 T=$(gettop)
88 if [ ! "$T" ]; then
89 echo "Couldn't locate the top of the tree. Try setting TOP."
90 return
91 fi
92
93 ##################################################################
94 # #
95 # Read me before you modify this code #
96 # #
97 # This function sets ANDROID_BUILD_PATHS to what it is adding #
98 # to PATH, and the next time it is run, it removes that from #
99 # PATH. This is required so lunch can be run more than once #
100 # and still have working paths. #
101 # #
102 ##################################################################
103
Raphael Mollc639c782011-06-20 17:25:01 -0700104 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
105 # due to "C:\Program Files" being in the path.
106
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700107 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700108 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700109 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
110 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700111 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700112 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800113 # strip leading ':', if any
114 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500115 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700116
117 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700118 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.
Ben Chengfba67bf2014-02-25 10:27:07 -0800126 export ANDROID_TOOLCHAIN=
127 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200128 local ARCH=$(get_build_var TARGET_ARCH)
129 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400130 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700131 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400132 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
133 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800134 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200135 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800136 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
137 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700138 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800139 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700140 ;;
Chris Dearman1efd9e42014-02-03 15:01:24 -0800141 mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000142 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200143 *)
144 echo "Can't find toolchain for unknown architecture: $ARCH"
145 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700146 ;;
147 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700148 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800149 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700150 fi
Raphael732936d2011-06-22 14:35:32 -0700151
Ben Chengfba67bf2014-02-25 10:27:07 -0800152 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
153 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
154 fi
155
156 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700157 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700158 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800159 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800160 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700161 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100162 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
163 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700164 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700165 ;;
166 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700167 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700168 ;;
169 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700170
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700171 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700172 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100173 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
Ying Wangaa1c9b52012-11-26 20:51:59 -0800174 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800175
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500176 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900177 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500178 if [ -n "$JAVA_HOME" ]; then
179 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900180 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
181 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500182 fi
183
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800184 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700185 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
186 export OUT=$ANDROID_PRODUCT_OUT
187
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700188 unset ANDROID_HOST_OUT
189 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
190
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800191 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700192 # TODO: fix the path
193 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
194}
195
196function printconfig()
197{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800198 T=$(gettop)
199 if [ ! "$T" ]; then
200 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
201 return
202 fi
203 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700204}
205
206function set_stuff_for_environment()
207{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800208 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500209 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800210 setpaths
211 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700212
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800213 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700214 # With this environment variable new GCC can apply colors to warnings/errors
215 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700216}
217
218function set_sequence_number()
219{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700220 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700221}
222
223function settitle()
224{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800225 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700226 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700227 local product=$TARGET_PRODUCT
228 local variant=$TARGET_BUILD_VARIANT
229 local apps=$TARGET_BUILD_APPS
230 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700231 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700232 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700233 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700234 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800235 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700236}
237
Kenny Root52aa81c2011-07-15 11:07:06 -0700238function addcompletions()
239{
240 local T dir f
241
242 # Keep us from trying to run in something that isn't bash.
243 if [ -z "${BASH_VERSION}" ]; then
244 return
245 fi
246
247 # Keep us from trying to run in bash that's too old.
248 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
249 return
250 fi
251
252 dir="sdk/bash_completion"
253 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700254 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700255 echo "including $f"
256 . $f
257 done
258 fi
259}
260
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700261function choosetype()
262{
263 echo "Build type choices are:"
264 echo " 1. release"
265 echo " 2. debug"
266 echo
267
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800268 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700269 DEFAULT_NUM=1
270 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700271
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800272 export TARGET_BUILD_TYPE=
273 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700274 while [ -z $TARGET_BUILD_TYPE ]
275 do
276 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800277 if [ -z "$1" ] ; then
278 read ANSWER
279 else
280 echo $1
281 ANSWER=$1
282 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700283 case $ANSWER in
284 "")
285 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
286 ;;
287 1)
288 export TARGET_BUILD_TYPE=release
289 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800290 release)
291 export TARGET_BUILD_TYPE=release
292 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700293 2)
294 export TARGET_BUILD_TYPE=debug
295 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800296 debug)
297 export TARGET_BUILD_TYPE=debug
298 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700299 *)
300 echo
301 echo "I didn't understand your response. Please try again."
302 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700303 ;;
304 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800305 if [ -n "$1" ] ; then
306 break
307 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700308 done
309
310 set_stuff_for_environment
311}
312
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800313#
314# This function isn't really right: It chooses a TARGET_PRODUCT
315# based on the list of boards. Usually, that gets you something
316# that kinda works with a generic product, but really, you should
317# pick a product by name.
318#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319function chooseproduct()
320{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321 if [ "x$TARGET_PRODUCT" != x ] ; then
322 default_value=$TARGET_PRODUCT
323 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700324 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325 fi
326
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800327 export TARGET_PRODUCT=
328 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700329 while [ -z "$TARGET_PRODUCT" ]
330 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700331 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332 if [ -z "$1" ] ; then
333 read ANSWER
334 else
335 echo $1
336 ANSWER=$1
337 fi
338
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339 if [ -z "$ANSWER" ] ; then
340 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800341 else
342 if check_product $ANSWER
343 then
344 export TARGET_PRODUCT=$ANSWER
345 else
346 echo "** Not a valid product: $ANSWER"
347 fi
348 fi
349 if [ -n "$1" ] ; then
350 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700351 fi
352 done
353
354 set_stuff_for_environment
355}
356
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800357function choosevariant()
358{
359 echo "Variant choices are:"
360 local index=1
361 local v
362 for v in ${VARIANT_CHOICES[@]}
363 do
364 # The product name is the name of the directory containing
365 # the makefile we found, above.
366 echo " $index. $v"
367 index=$(($index+1))
368 done
369
370 local default_value=eng
371 local ANSWER
372
373 export TARGET_BUILD_VARIANT=
374 while [ -z "$TARGET_BUILD_VARIANT" ]
375 do
376 echo -n "Which would you like? [$default_value] "
377 if [ -z "$1" ] ; then
378 read ANSWER
379 else
380 echo $1
381 ANSWER=$1
382 fi
383
384 if [ -z "$ANSWER" ] ; then
385 export TARGET_BUILD_VARIANT=$default_value
386 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
387 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800388 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800389 fi
390 else
391 if check_variant $ANSWER
392 then
393 export TARGET_BUILD_VARIANT=$ANSWER
394 else
395 echo "** Not a valid variant: $ANSWER"
396 fi
397 fi
398 if [ -n "$1" ] ; then
399 break
400 fi
401 done
402}
403
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700404function choosecombo()
405{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700406 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700407
408 echo
409 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700410 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700411
412 echo
413 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700414 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800415
416 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700417 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800418 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700419}
420
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800421# Clear this variable. It will be built up again when the vendorsetup.sh
422# files are included at the end of this file.
423unset LUNCH_MENU_CHOICES
424function add_lunch_combo()
425{
426 local new_combo=$1
427 local c
428 for c in ${LUNCH_MENU_CHOICES[@]} ; do
429 if [ "$new_combo" = "$c" ] ; then
430 return
431 fi
432 done
433 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
434}
435
436# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700437add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800438add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000439add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800440add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000441add_lunch_combo aosp_x86-eng
442add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800443add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800444
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700445function print_lunch_menu()
446{
447 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700448 echo
449 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700450 echo
451 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800452
453 local i=1
454 local choice
455 for choice in ${LUNCH_MENU_CHOICES[@]}
456 do
457 echo " $i. $choice"
458 i=$(($i+1))
459 done
460
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461 echo
462}
463
464function lunch()
465{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800466 local answer
467
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470 else
471 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700472 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800473 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474 fi
475
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476 local selection=
477
478 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700479 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700480 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800481 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
482 then
483 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
484 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800485 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486 fi
487 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
488 then
489 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700490 fi
491
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492 if [ -z "$selection" ]
493 then
494 echo
495 echo "Invalid lunch combo: $answer"
496 return 1
497 fi
498
Joe Onoratoda12daf2010-06-09 18:18:31 -0700499 export TARGET_BUILD_APPS=
500
Jeff Browne33ba4c2011-07-11 22:11:46 -0700501 local product=$(echo -n $selection | sed -e "s/-.*$//")
502 check_product $product
503 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700505 echo
506 echo "** Don't have a product spec for: '$product'"
507 echo "** Do you have the right repo manifest?"
508 product=
509 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800510
Jeff Browne33ba4c2011-07-11 22:11:46 -0700511 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
512 check_variant $variant
513 if [ $? -ne 0 ]
514 then
515 echo
516 echo "** Invalid variant: '$variant'"
517 echo "** Must be one of ${VARIANT_CHOICES[@]}"
518 variant=
519 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520
Jeff Browne33ba4c2011-07-11 22:11:46 -0700521 if [ -z "$product" -o -z "$variant" ]
522 then
523 echo
524 return 1
525 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800526
Jeff Browne33ba4c2011-07-11 22:11:46 -0700527 export TARGET_PRODUCT=$product
528 export TARGET_BUILD_VARIANT=$variant
529 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700530
531 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800532
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700533 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800534 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700535}
536
Jeff Davidson513d7a42010-08-02 10:00:44 -0700537# Tab completion for lunch.
538function _lunch()
539{
540 local cur prev opts
541 COMPREPLY=()
542 cur="${COMP_WORDS[COMP_CWORD]}"
543 prev="${COMP_WORDS[COMP_CWORD-1]}"
544
545 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
546 return 0
547}
548complete -F _lunch lunch
549
Joe Onoratoda12daf2010-06-09 18:18:31 -0700550# Configures the build to build unbundled apps.
551# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
552function tapas()
553{
Ying Wangf05c4f72013-01-31 11:16:57 -0800554 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600555 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800556 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 -0700557
Ying Wang67f02922012-08-22 10:25:20 -0700558 if [ $(echo $arch | wc -w) -gt 1 ]; then
559 echo "tapas: Error: Multiple build archs supplied: $arch"
560 return
561 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700562 if [ $(echo $variant | wc -w) -gt 1 ]; then
563 echo "tapas: Error: Multiple build variants supplied: $variant"
564 return
565 fi
Ying Wang67f02922012-08-22 10:25:20 -0700566
567 local product=full
568 case $arch in
569 x86) product=full_x86;;
570 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800571 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700572 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700573 if [ -z "$variant" ]; then
574 variant=eng
575 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700576 if [ -z "$apps" ]; then
577 apps=all
578 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700579
Ying Wang67f02922012-08-22 10:25:20 -0700580 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700581 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700582 export TARGET_BUILD_TYPE=release
583 export TARGET_BUILD_APPS=$apps
584
585 set_stuff_for_environment
586 printconfig
587}
588
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700589function gettop
590{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800591 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
593 echo $TOP
594 else
595 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800596 # The following circumlocution (repeated below as well) ensures
597 # that we record the true directory name and not one that is
598 # faked up with symlink names.
599 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700600 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800601 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700602 T=
603 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800604 \cd ..
synergyb112a402013-07-05 19:47:47 -0700605 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700606 done
Ying Wang9cd17642012-12-13 10:52:07 -0800607 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700608 if [ -f "$T/$TOPFILE" ]; then
609 echo $T
610 fi
611 fi
612 fi
613}
614
Andrew Hsieh906cb782013-09-10 17:37:14 +0800615# Return driver for "make", if any (eg. static analyzer)
616function getdriver()
617{
618 local T="$1"
619 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
620 if [ -n "$WITH_STATIC_ANALYZER" ]; then
621 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800622$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
623--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800624--status-bugs \
625--top=$T"
626 fi
627}
628
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700629function m()
630{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800631 local T=$(gettop)
632 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700633 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800634 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700635 else
636 echo "Couldn't locate the top of the tree. Try setting TOP."
637 fi
638}
639
640function findmakefile()
641{
642 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800643 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700644 T=
645 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700646 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700647 if [ -f "$T/Android.mk" ]; then
648 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800649 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700650 return
651 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800652 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653 done
Ying Wang9cd17642012-12-13 10:52:07 -0800654 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700655}
656
657function mm()
658{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800659 local T=$(gettop)
660 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661 # If we're sitting in the root of the build tree, just do a
662 # normal make.
663 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800664 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700665 else
666 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800667 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700668 local MODULES=
669 local GET_INSTALL_PATH=
670 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700671 # Remove the path to top as the makefilepath needs to be relative
672 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700673 if [ ! "$T" ]; then
674 echo "Couldn't locate the top of the tree. Try setting TOP."
675 elif [ ! "$M" ]; then
676 echo "Couldn't locate a makefile from the current directory."
677 else
Ying Wanga7deb082013-08-16 13:24:47 -0700678 for ARG in $@; do
679 case $ARG in
680 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
681 esac
682 done
683 if [ -n "$GET_INSTALL_PATH" ]; then
684 MODULES=
685 ARGS=GET-INSTALL-PATH
686 else
687 MODULES=all_modules
688 ARGS=$@
689 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700690 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 -0700691 fi
692 fi
693}
694
695function mmm()
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 [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800700 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800701 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800702 local ARGS=
703 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700704 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800705 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
706 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
707 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800708 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
709 if [ "$MODULES" = "" ]; then
710 MODULES=all_modules
711 fi
712 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700713 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700714 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
715 local TO_CHOP=`expr $TO_CHOP + 1`
716 local START=`PWD= /bin/pwd`
717 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700718 if [ "$MFILE" = "" ] ; then
719 MFILE=$DIR/Android.mk
720 else
721 MFILE=$MFILE/$DIR/Android.mk
722 fi
723 MAKEFILE="$MAKEFILE $MFILE"
724 else
Ying Wanga7deb082013-08-16 13:24:47 -0700725 case $DIR in
726 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
727 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
728 *) echo "No Android.mk in $DIR."; return 1;;
729 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700730 fi
731 done
Ying Wanga7deb082013-08-16 13:24:47 -0700732 if [ -n "$GET_INSTALL_PATH" ]; then
733 ARGS=$GET_INSTALL_PATH
734 MODULES=
735 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800736 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 -0700737 else
738 echo "Couldn't locate the top of the tree. Try setting TOP."
739 fi
740}
741
Ying Wangb607f7b2013-02-08 18:01:04 -0800742function mma()
743{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800744 local T=$(gettop)
745 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800746 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800747 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800748 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800749 if [ ! "$T" ]; then
750 echo "Couldn't locate the top of the tree. Try setting TOP."
751 fi
752 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800753 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800754 fi
755}
756
757function mmma()
758{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800759 local T=$(gettop)
760 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800761 if [ "$T" ]; then
762 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
763 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
764 local MY_PWD=`PWD= /bin/pwd`
765 if [ "$MY_PWD" = "$T" ]; then
766 MY_PWD=
767 else
768 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
769 fi
770 local DIR=
771 local MODULE_PATHS=
772 local ARGS=
773 for DIR in $DIRS ; do
774 if [ -d $DIR ]; then
775 if [ "$MY_PWD" = "" ]; then
776 MODULE_PATHS="$MODULE_PATHS $DIR"
777 else
778 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
779 fi
780 else
781 case $DIR in
782 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
783 *) echo "Couldn't find directory $DIR"; return 1;;
784 esac
785 fi
786 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800787 $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 -0800788 else
789 echo "Couldn't locate the top of the tree. Try setting TOP."
790 fi
791}
792
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793function croot()
794{
795 T=$(gettop)
796 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800797 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700798 else
799 echo "Couldn't locate the top of the tree. Try setting TOP."
800 fi
801}
802
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700803function cproj()
804{
805 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700806 local HERE=$PWD
807 T=
808 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
809 T=$PWD
810 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800811 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700812 return
813 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800814 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700815 done
Ying Wang9cd17642012-12-13 10:52:07 -0800816 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700817 echo "can't find Android.mk"
818}
819
Daniel Sandler47e0a882013-07-30 13:23:52 -0400820# simplified version of ps; output in the form
821# <pid> <procname>
822function qpid() {
823 local prepend=''
824 local append=''
825 if [ "$1" = "--exact" ]; then
826 prepend=' '
827 append='$'
828 shift
829 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
830 echo "usage: qpid [[--exact] <process name|pid>"
831 return 255
832 fi
833
834 local EXE="$1"
835 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700836 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400837 else
838 adb shell ps \
839 | tr -d '\r' \
840 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
841 fi
842}
843
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700844function pid()
845{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400846 local prepend=''
847 local append=''
848 if [ "$1" = "--exact" ]; then
849 prepend=' '
850 append='$'
851 shift
852 fi
853 local EXE="$1"
854 if [ "$EXE" ] ; then
855 local PID=`adb shell ps \
856 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700857 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400858 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
859 echo "$PID"
860 else
861 echo "usage: pid [--exact] <process name>"
862 return 255
863 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700864}
865
Christopher Tate744ee802009-11-12 15:33:08 -0800866# systemstack - dump the current stack trace of all threads in the system process
867# to the usual ANR traces file
868function systemstack()
869{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800870 stacks system_server
871}
872
873function stacks()
874{
875 if [[ $1 =~ ^[0-9]+$ ]] ; then
876 local PID="$1"
877 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700878 local PIDLIST="$(pid $1)"
879 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
880 local PID="$PIDLIST"
881 elif [ "$PIDLIST" ] ; then
882 echo "more than one process: $1"
883 else
884 echo "no such process: $1"
885 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800886 else
887 echo "usage: stacks [pid|process name]"
888 fi
889
890 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700891 # Determine whether the process is native
892 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
893 # Dump stacks of Dalvik process
894 local TRACES=/data/anr/traces.txt
895 local ORIG=/data/anr/traces.orig
896 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800897
Jeff Brownb12c2e52013-08-19 15:14:16 -0700898 # Keep original traces to avoid clobbering
899 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800900
Jeff Brownb12c2e52013-08-19 15:14:16 -0700901 # Make sure we have a usable file
902 adb shell touch $TRACES
903 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800904
Jeff Brownb12c2e52013-08-19 15:14:16 -0700905 # Dump stacks and wait for dump to finish
906 adb shell kill -3 $PID
907 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800908
Jeff Brownb12c2e52013-08-19 15:14:16 -0700909 # Restore original stacks, and show current output
910 adb shell mv $TRACES $TMP
911 adb shell mv $ORIG $TRACES
912 adb shell cat $TMP
913 else
914 # Dump stacks of native process
915 adb shell debuggerd -b $PID
916 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800917 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800918}
919
John Michelau50200252012-11-09 11:48:04 -0600920function gdbwrapper()
921{
Ben Chengfba67bf2014-02-25 10:27:07 -0800922 local GDB_CMD="$1"
923 shift 1
924 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -0600925}
926
Ben Chengfba67bf2014-02-25 10:27:07 -0800927# process the symbolic link of /proc/$PID/exe and use the host file tool to
928# determine whether it is a 32-bit or 64-bit executable. It returns "" or "64"
929# which can be conveniently used as suffix.
930function is64bit()
931{
932 local PID="$1"
933 if [ "$PID" ] ; then
934 local EXE=`adb shell ls -l /proc/$PID/exe \
935 | tr -d '\r' \
936 | cut -d'>' -f2 \
937 | tr -d ' ' \
938 | cut -d'/' -f4`
939
940 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
941 local IS64BIT=`file $OUT_EXE_SYMBOLS/$EXE | grep "64-bit"`
942 if [ "$IS64BIT" != "" ]; then
943 echo "64"
944 else
945 echo ""
946 fi
947 else
948 echo ""
949 fi
950}
951
952# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
953# executable, set up the approriate gdbserver, then invokes the proper host
954# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700955function gdbclient()
956{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800957 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
958 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
959 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
960 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
961 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800962 local ARCH=$(get_build_var TARGET_ARCH)
963 local GDB
964 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800965 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800966 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700967 mips) GDB=mipsel-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000968 mips64) GDB=mipsel-linux-android-gdb;;
969 x86) GDB=x86_64-linux-android-gdb;;
970 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800971 *) echo "Unknown arch $ARCH"; return 1;;
972 esac
973
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700974 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
975 local EXE="$1"
976 if [ "$EXE" ] ; then
977 EXE=$1
978 else
979 EXE="app_process"
980 fi
981
982 local PORT="$2"
983 if [ "$PORT" ] ; then
984 PORT=$2
985 else
986 PORT=":5039"
987 fi
988
Chris Craik20c136a2012-11-09 18:02:19 -0800989 local PID="$3"
990 if [ "$PID" ] ; then
991 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700992 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800993 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
994 # that likely didn't work because of returning multiple processes
995 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -0700996 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -0800997 if [[ ! "$PID" =~ ^[0-9]+$ ]]
998 then
999 echo "Couldn't resolve '$3' to single PID"
1000 return 1
1001 else
1002 echo ""
1003 echo "WARNING: multiple processes matching '$3' observed, using root process"
1004 echo ""
1005 fi
1006 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001007 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001008 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001009 local USE64BIT="$(is64bit $PID)"
1010 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001011 sleep 2
1012 else
1013 echo ""
1014 echo "If you haven't done so already, do this first on the device:"
1015 echo " gdbserver $PORT /system/bin/$EXE"
1016 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001017 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001018 echo ""
1019 fi
1020
Colin Cross84480ad2014-04-10 12:51:39 -07001021 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1022
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001023 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Colin Cross84480ad2014-04-10 12:51:39 -07001024 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 -07001025 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001026 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1027 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1028
Ben Chengfba67bf2014-02-25 10:27:07 -08001029 local WHICH_GDB=
1030 # 64-bit exe found
1031 if [ "$USE64BIT" != "" ] ; then
1032 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1033 # 32-bit exe / 32-bit platform
1034 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1035 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1036 # 32-bit exe / 64-bit platform
1037 else
1038 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1039 fi
1040 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001041 else
1042 echo "Unable to determine build system output dir."
1043 fi
1044
1045}
1046
1047case `uname -s` in
1048 Darwin)
1049 function sgrep()
1050 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001051 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml|sh|mk)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001052 }
1053
1054 ;;
1055 *)
1056 function sgrep()
1057 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001058 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 -07001059 }
1060 ;;
1061esac
1062
Raghu Gandham8da43102012-07-25 19:57:22 -07001063function gettargetarch
1064{
1065 get_build_var TARGET_ARCH
1066}
1067
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001068function jgrep()
1069{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001070 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 -07001071}
1072
1073function cgrep()
1074{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001075 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 -07001076}
1077
1078function resgrep()
1079{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001080 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 -07001081}
1082
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001083function mangrep()
1084{
1085 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1086}
1087
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001088function sepgrep()
1089{
1090 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 "$@"
1091}
1092
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001093case `uname -s` in
1094 Darwin)
1095 function mgrep()
1096 {
Ying Wang324c2b22012-08-17 15:03:20 -07001097 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 -07001098 }
1099
1100 function treegrep()
1101 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001102 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 -07001103 }
1104
1105 ;;
1106 *)
1107 function mgrep()
1108 {
Ying Wang324c2b22012-08-17 15:03:20 -07001109 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 -07001110 }
1111
1112 function treegrep()
1113 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001114 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 -07001115 }
1116
1117 ;;
1118esac
1119
1120function getprebuilt
1121{
1122 get_abs_build_var ANDROID_PREBUILTS
1123}
1124
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001125function tracedmdump()
1126{
1127 T=$(gettop)
1128 if [ ! "$T" ]; then
1129 echo "Couldn't locate the top of the tree. Try setting TOP."
1130 return
1131 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001132 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001133 local arch=$(gettargetarch)
1134 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001135
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001136 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001137 if [ ! "$TRACE" ] ; then
1138 echo "usage: tracedmdump tracename"
1139 return
1140 fi
1141
Jack Veenstra60116fc2009-04-09 18:12:34 -07001142 if [ ! -r "$KERNEL" ] ; then
1143 echo "Error: cannot find kernel: '$KERNEL'"
1144 return
1145 fi
1146
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001147 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001148 if [ "$BASETRACE" = "$TRACE" ] ; then
1149 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1150 fi
1151
1152 echo "post-processing traces..."
1153 rm -f $TRACE/qtrace.dexlist
1154 post_trace $TRACE
1155 if [ $? -ne 0 ]; then
1156 echo "***"
1157 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1158 echo "***"
1159 return
1160 fi
1161 echo "generating dexlist output..."
1162 /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
1163 echo "generating dmtrace data..."
1164 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1165 echo "generating html file..."
1166 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1167 echo "done, see $TRACE/dmtrace.html for details"
1168 echo "or run:"
1169 echo " traceview $TRACE/dmtrace"
1170}
1171
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001172# communicate with a running device or emulator, set up necessary state,
1173# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001174function runhat()
1175{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001176 # process standard adb options
1177 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001178 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001179 adbTarget=$1
1180 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001181 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001182 adbTarget="$1 $2"
1183 shift 2
1184 fi
1185 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001186 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001187
1188 # runhat options
1189 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001190
1191 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001192 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001193 return
1194 fi
1195
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001196 # confirm hat is available
1197 if [ -z $(which hat) ]; then
1198 echo "hat is not available in this configuration."
1199 return
1200 fi
1201
Andy McFaddenb6289852010-07-12 08:00:19 -07001202 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001203 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001204 local devFile=$sdcard/hprof-$targetPid
1205 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001206 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001207 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001208 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001209 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001210 echo -n "> "
1211 read
1212
The Android Open Source Project88b60792009-03-03 19:28:42 -08001213 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001214
The Android Open Source Project88b60792009-03-03 19:28:42 -08001215 echo "Retrieving file $devFile..."
1216 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001217
The Android Open Source Project88b60792009-03-03 19:28:42 -08001218 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001219
The Android Open Source Project88b60792009-03-03 19:28:42 -08001220 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001221 echo "View the output by pointing your browser at http://localhost:7000/"
1222 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001223 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001224}
1225
1226function getbugreports()
1227{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001228 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001229
1230 if [ ! "$reports" ]; then
1231 echo "Could not locate any bugreports."
1232 return
1233 fi
1234
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001235 local report
1236 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001237 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001238 echo "/sdcard/bugreports/${report}"
1239 adb pull /sdcard/bugreports/${report} ${report}
1240 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001241 done
1242}
1243
Victoria Lease1b296b42012-08-21 15:44:06 -07001244function getsdcardpath()
1245{
1246 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1247}
1248
1249function getscreenshotpath()
1250{
1251 echo "$(getsdcardpath)/Pictures/Screenshots"
1252}
1253
1254function getlastscreenshot()
1255{
1256 local screenshot_path=$(getscreenshotpath)
1257 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1258 if [ "$screenshot" = "" ]; then
1259 echo "No screenshots found."
1260 return
1261 fi
1262 echo "${screenshot}"
1263 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1264}
1265
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001266function startviewserver()
1267{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001268 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001269 if [ $# -gt 0 ]; then
1270 port=$1
1271 fi
1272 adb shell service call window 1 i32 $port
1273}
1274
1275function stopviewserver()
1276{
1277 adb shell service call window 2
1278}
1279
1280function isviewserverstarted()
1281{
1282 adb shell service call window 3
1283}
1284
Romain Guyb84049a2010-10-04 16:56:11 -07001285function key_home()
1286{
1287 adb shell input keyevent 3
1288}
1289
1290function key_back()
1291{
1292 adb shell input keyevent 4
1293}
1294
1295function key_menu()
1296{
1297 adb shell input keyevent 82
1298}
1299
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001300function smoketest()
1301{
1302 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1303 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1304 return
1305 fi
1306 T=$(gettop)
1307 if [ ! "$T" ]; then
1308 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1309 return
1310 fi
1311
Ying Wang9cd17642012-12-13 10:52:07 -08001312 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001313 adb uninstall com.android.smoketest > /dev/null &&
1314 adb uninstall com.android.smoketest.tests > /dev/null &&
1315 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1316 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1317 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1318}
1319
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001320# simple shortcut to the runtest command
1321function runtest()
1322{
1323 T=$(gettop)
1324 if [ ! "$T" ]; then
1325 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1326 return
1327 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001328 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001329}
1330
The Android Open Source Project88b60792009-03-03 19:28:42 -08001331function godir () {
1332 if [[ -z "$1" ]]; then
1333 echo "Usage: godir <regex>"
1334 return
1335 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001336 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001337 if [[ ! -f $T/filelist ]]; then
1338 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001339 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001340 echo " Done"
1341 echo ""
1342 fi
1343 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001344 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001345 if [[ ${#lines[@]} = 0 ]]; then
1346 echo "Not found"
1347 return
1348 fi
1349 local pathname
1350 local choice
1351 if [[ ${#lines[@]} > 1 ]]; then
1352 while [[ -z "$pathname" ]]; do
1353 local index=1
1354 local line
1355 for line in ${lines[@]}; do
1356 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001357 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001358 done
1359 echo
1360 echo -n "Select one: "
1361 unset choice
1362 read choice
1363 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1364 echo "Invalid choice"
1365 continue
1366 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001367 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001368 done
1369 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001370 pathname=${lines[0]}
1371 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001372 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001373}
1374
Narayan Kamath9260bba2014-01-17 10:05:25 +00001375# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1376#
1377# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1378# For some reason, installing the JDK doesn't make it show up in the
1379# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001380function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001381 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001382 # we can reset it later, depending on the version of java the build
1383 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001384 #
1385 # If we don't do this, the JAVA_HOME value set by the first call to
1386 # build/envsetup.sh will persist forever.
1387 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1388 export JAVA_HOME=""
1389 fi
1390
Andy McFaddenbd960942010-06-24 12:52:51 -07001391 if [ ! "$JAVA_HOME" ]; then
Narayan Kamathc84889b2014-04-01 14:16:26 +01001392 if [ -n "$LEGACY_USE_JAVA6" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001393 case `uname -s` in
1394 Darwin)
1395 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1396 ;;
1397 *)
1398 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1399 ;;
1400 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001401 else
1402 case `uname -s` in
1403 Darwin)
1404 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
1405 ;;
1406 *)
1407 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1408 ;;
1409 esac
1410 fi
1411
1412 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1413 # we can change it on the next envsetup.sh, if required.
1414 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001415 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001416}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001417
Alex Rayf0d08eb2013-03-08 15:15:06 -08001418# Print colored exit condition
1419function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001420 "$@"
1421 local retval=$?
1422 if [ $retval -ne 0 ]
1423 then
1424 echo -e "\e[0;31mFAILURE\e[00m"
1425 else
1426 echo -e "\e[0;32mSUCCESS\e[00m"
1427 fi
1428 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001429}
1430
Raphael Moll70a86b02011-06-20 16:03:14 -07001431if [ "x$SHELL" != "x/bin/bash" ]; then
1432 case `ps -o command -p $$` in
1433 *bash*)
1434 ;;
1435 *)
1436 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1437 ;;
1438 esac
1439fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001440
1441# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001442for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1443 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001444do
1445 echo "including $f"
1446 . $f
1447done
1448unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001449
1450addcompletions