blob: bda1c45e3bc0ddd7a3dc70b3109971cefb37ef7c [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
118 CODE_REVIEWS=
119 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
Ben Chengfba67bf2014-02-25 10:27:07 -0800163 ANDROID_KERNEL_TOOLCHAIN_PATH="$gccprebuiltdir/$toolchaindir"
164 export ARM_EABI_TOOLCHAIN=$ANDROID_KERNEL_TOOLCHAIN_PATH
Bruce Beare42ced6d2012-07-17 21:40:01 -0700165 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700166 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700167 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
168 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700169 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700170 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700171 ;;
172 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700173
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700174 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700175 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ben Chengfba67bf2014-02-25 10:27:07 -0800176 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_KERNEL_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
Ying Wangaa1c9b52012-11-26 20:51:59 -0800177 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800178
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500179 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900180 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500181 if [ -n "$JAVA_HOME" ]; then
182 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900183 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
184 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500185 fi
186
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800187 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700188 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
189 export OUT=$ANDROID_PRODUCT_OUT
190
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700191 unset ANDROID_HOST_OUT
192 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
193
Ben Cheng057fde12011-11-28 13:55:14 -0800194 # needed for processing samples collected by perf counters
195 unset OPROFILE_EVENTS_DIR
196 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
197
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800198 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700199 # TODO: fix the path
200 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
201}
202
203function printconfig()
204{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800205 T=$(gettop)
206 if [ ! "$T" ]; then
207 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
208 return
209 fi
210 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700211}
212
213function set_stuff_for_environment()
214{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800215 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500216 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800217 setpaths
218 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700219
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800220 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700221 # With this environment variable new GCC can apply colors to warnings/errors
222 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 -0700223}
224
225function set_sequence_number()
226{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700227 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700228}
229
230function settitle()
231{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800232 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700233 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700234 local product=$TARGET_PRODUCT
235 local variant=$TARGET_BUILD_VARIANT
236 local apps=$TARGET_BUILD_APPS
237 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700238 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700239 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700240 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700241 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800242 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700243}
244
Kenny Root52aa81c2011-07-15 11:07:06 -0700245function addcompletions()
246{
247 local T dir f
248
249 # Keep us from trying to run in something that isn't bash.
250 if [ -z "${BASH_VERSION}" ]; then
251 return
252 fi
253
254 # Keep us from trying to run in bash that's too old.
255 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
256 return
257 fi
258
259 dir="sdk/bash_completion"
260 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700261 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700262 echo "including $f"
263 . $f
264 done
265 fi
266}
267
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700268function choosetype()
269{
270 echo "Build type choices are:"
271 echo " 1. release"
272 echo " 2. debug"
273 echo
274
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800275 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700276 DEFAULT_NUM=1
277 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700278
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800279 export TARGET_BUILD_TYPE=
280 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700281 while [ -z $TARGET_BUILD_TYPE ]
282 do
283 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800284 if [ -z "$1" ] ; then
285 read ANSWER
286 else
287 echo $1
288 ANSWER=$1
289 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700290 case $ANSWER in
291 "")
292 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
293 ;;
294 1)
295 export TARGET_BUILD_TYPE=release
296 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800297 release)
298 export TARGET_BUILD_TYPE=release
299 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300 2)
301 export TARGET_BUILD_TYPE=debug
302 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303 debug)
304 export TARGET_BUILD_TYPE=debug
305 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700306 *)
307 echo
308 echo "I didn't understand your response. Please try again."
309 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700310 ;;
311 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800312 if [ -n "$1" ] ; then
313 break
314 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315 done
316
317 set_stuff_for_environment
318}
319
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800320#
321# This function isn't really right: It chooses a TARGET_PRODUCT
322# based on the list of boards. Usually, that gets you something
323# that kinda works with a generic product, but really, you should
324# pick a product by name.
325#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700326function chooseproduct()
327{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700328 if [ "x$TARGET_PRODUCT" != x ] ; then
329 default_value=$TARGET_PRODUCT
330 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700331 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332 fi
333
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800334 export TARGET_PRODUCT=
335 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700336 while [ -z "$TARGET_PRODUCT" ]
337 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700338 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800339 if [ -z "$1" ] ; then
340 read ANSWER
341 else
342 echo $1
343 ANSWER=$1
344 fi
345
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346 if [ -z "$ANSWER" ] ; then
347 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800348 else
349 if check_product $ANSWER
350 then
351 export TARGET_PRODUCT=$ANSWER
352 else
353 echo "** Not a valid product: $ANSWER"
354 fi
355 fi
356 if [ -n "$1" ] ; then
357 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700358 fi
359 done
360
361 set_stuff_for_environment
362}
363
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800364function choosevariant()
365{
366 echo "Variant choices are:"
367 local index=1
368 local v
369 for v in ${VARIANT_CHOICES[@]}
370 do
371 # The product name is the name of the directory containing
372 # the makefile we found, above.
373 echo " $index. $v"
374 index=$(($index+1))
375 done
376
377 local default_value=eng
378 local ANSWER
379
380 export TARGET_BUILD_VARIANT=
381 while [ -z "$TARGET_BUILD_VARIANT" ]
382 do
383 echo -n "Which would you like? [$default_value] "
384 if [ -z "$1" ] ; then
385 read ANSWER
386 else
387 echo $1
388 ANSWER=$1
389 fi
390
391 if [ -z "$ANSWER" ] ; then
392 export TARGET_BUILD_VARIANT=$default_value
393 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
394 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800395 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800396 fi
397 else
398 if check_variant $ANSWER
399 then
400 export TARGET_BUILD_VARIANT=$ANSWER
401 else
402 echo "** Not a valid variant: $ANSWER"
403 fi
404 fi
405 if [ -n "$1" ] ; then
406 break
407 fi
408 done
409}
410
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700411function choosecombo()
412{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700413 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700414
415 echo
416 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700417 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700418
419 echo
420 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700421 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800422
423 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700424 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800425 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700426}
427
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800428# Clear this variable. It will be built up again when the vendorsetup.sh
429# files are included at the end of this file.
430unset LUNCH_MENU_CHOICES
431function add_lunch_combo()
432{
433 local new_combo=$1
434 local c
435 for c in ${LUNCH_MENU_CHOICES[@]} ; do
436 if [ "$new_combo" = "$c" ] ; then
437 return
438 fi
439 done
440 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
441}
442
443# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700444add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800445add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000446add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800447add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000448add_lunch_combo aosp_x86-eng
449add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800450add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800451
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700452function print_lunch_menu()
453{
454 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700455 echo
456 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700457 echo
458 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800459
460 local i=1
461 local choice
462 for choice in ${LUNCH_MENU_CHOICES[@]}
463 do
464 echo " $i. $choice"
465 i=$(($i+1))
466 done
467
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468 echo
469}
470
471function lunch()
472{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800473 local answer
474
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700477 else
478 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700479 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700481 fi
482
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800483 local selection=
484
485 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700487 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800488 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
489 then
490 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
491 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800492 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800493 fi
494 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
495 then
496 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700497 fi
498
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499 if [ -z "$selection" ]
500 then
501 echo
502 echo "Invalid lunch combo: $answer"
503 return 1
504 fi
505
Joe Onoratoda12daf2010-06-09 18:18:31 -0700506 export TARGET_BUILD_APPS=
507
Jeff Browne33ba4c2011-07-11 22:11:46 -0700508 local product=$(echo -n $selection | sed -e "s/-.*$//")
509 check_product $product
510 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700512 echo
513 echo "** Don't have a product spec for: '$product'"
514 echo "** Do you have the right repo manifest?"
515 product=
516 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800517
Jeff Browne33ba4c2011-07-11 22:11:46 -0700518 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
519 check_variant $variant
520 if [ $? -ne 0 ]
521 then
522 echo
523 echo "** Invalid variant: '$variant'"
524 echo "** Must be one of ${VARIANT_CHOICES[@]}"
525 variant=
526 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800527
Jeff Browne33ba4c2011-07-11 22:11:46 -0700528 if [ -z "$product" -o -z "$variant" ]
529 then
530 echo
531 return 1
532 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800533
Jeff Browne33ba4c2011-07-11 22:11:46 -0700534 export TARGET_PRODUCT=$product
535 export TARGET_BUILD_VARIANT=$variant
536 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700537
538 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800539
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700540 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800541 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700542}
543
Jeff Davidson513d7a42010-08-02 10:00:44 -0700544# Tab completion for lunch.
545function _lunch()
546{
547 local cur prev opts
548 COMPREPLY=()
549 cur="${COMP_WORDS[COMP_CWORD]}"
550 prev="${COMP_WORDS[COMP_CWORD-1]}"
551
552 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
553 return 0
554}
555complete -F _lunch lunch
556
Joe Onoratoda12daf2010-06-09 18:18:31 -0700557# Configures the build to build unbundled apps.
558# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
559function tapas()
560{
Ying Wangf05c4f72013-01-31 11:16:57 -0800561 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600562 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800563 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 -0700564
Ying Wang67f02922012-08-22 10:25:20 -0700565 if [ $(echo $arch | wc -w) -gt 1 ]; then
566 echo "tapas: Error: Multiple build archs supplied: $arch"
567 return
568 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700569 if [ $(echo $variant | wc -w) -gt 1 ]; then
570 echo "tapas: Error: Multiple build variants supplied: $variant"
571 return
572 fi
Ying Wang67f02922012-08-22 10:25:20 -0700573
574 local product=full
575 case $arch in
576 x86) product=full_x86;;
577 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800578 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700579 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700580 if [ -z "$variant" ]; then
581 variant=eng
582 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700583 if [ -z "$apps" ]; then
584 apps=all
585 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700586
Ying Wang67f02922012-08-22 10:25:20 -0700587 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700588 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700589 export TARGET_BUILD_TYPE=release
590 export TARGET_BUILD_APPS=$apps
591
592 set_stuff_for_environment
593 printconfig
594}
595
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596function gettop
597{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700599 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
600 echo $TOP
601 else
602 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800603 # The following circumlocution (repeated below as well) ensures
604 # that we record the true directory name and not one that is
605 # faked up with symlink names.
606 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700607 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800608 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700609 T=
610 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800611 \cd ..
synergyb112a402013-07-05 19:47:47 -0700612 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700613 done
Ying Wang9cd17642012-12-13 10:52:07 -0800614 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700615 if [ -f "$T/$TOPFILE" ]; then
616 echo $T
617 fi
618 fi
619 fi
620}
621
Andrew Hsieh906cb782013-09-10 17:37:14 +0800622# Return driver for "make", if any (eg. static analyzer)
623function getdriver()
624{
625 local T="$1"
626 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
627 if [ -n "$WITH_STATIC_ANALYZER" ]; then
628 echo "\
629$T/prebuilts/clang/linux-x86/host/3.3/tools/scan-build/scan-build \
Andrew Hsiehaf738a42013-09-13 15:49:39 +0800630--use-analyzer $T/prebuilts/clang/linux-x86/host/3.3/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800631--status-bugs \
632--top=$T"
633 fi
634}
635
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700636function m()
637{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800638 local T=$(gettop)
639 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700640 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800641 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700642 else
643 echo "Couldn't locate the top of the tree. Try setting TOP."
644 fi
645}
646
647function findmakefile()
648{
649 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800650 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651 T=
652 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700653 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700654 if [ -f "$T/Android.mk" ]; then
655 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800656 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657 return
658 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800659 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700660 done
Ying Wang9cd17642012-12-13 10:52:07 -0800661 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662}
663
664function mm()
665{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800666 local T=$(gettop)
667 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700668 # If we're sitting in the root of the build tree, just do a
669 # normal make.
670 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800671 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672 else
673 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800674 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700675 local MODULES=
676 local GET_INSTALL_PATH=
677 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700678 # Remove the path to top as the makefilepath needs to be relative
679 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700680 if [ ! "$T" ]; then
681 echo "Couldn't locate the top of the tree. Try setting TOP."
682 elif [ ! "$M" ]; then
683 echo "Couldn't locate a makefile from the current directory."
684 else
Ying Wanga7deb082013-08-16 13:24:47 -0700685 for ARG in $@; do
686 case $ARG in
687 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
688 esac
689 done
690 if [ -n "$GET_INSTALL_PATH" ]; then
691 MODULES=
692 ARGS=GET-INSTALL-PATH
693 else
694 MODULES=all_modules
695 ARGS=$@
696 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700697 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 -0700698 fi
699 fi
700}
701
702function mmm()
703{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800704 local T=$(gettop)
705 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700706 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800707 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800708 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800709 local ARGS=
710 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700711 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800712 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
713 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
714 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800715 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
716 if [ "$MODULES" = "" ]; then
717 MODULES=all_modules
718 fi
719 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700720 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700721 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
722 local TO_CHOP=`expr $TO_CHOP + 1`
723 local START=`PWD= /bin/pwd`
724 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700725 if [ "$MFILE" = "" ] ; then
726 MFILE=$DIR/Android.mk
727 else
728 MFILE=$MFILE/$DIR/Android.mk
729 fi
730 MAKEFILE="$MAKEFILE $MFILE"
731 else
Ying Wanga7deb082013-08-16 13:24:47 -0700732 case $DIR in
733 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
734 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
735 *) echo "No Android.mk in $DIR."; return 1;;
736 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700737 fi
738 done
Ying Wanga7deb082013-08-16 13:24:47 -0700739 if [ -n "$GET_INSTALL_PATH" ]; then
740 ARGS=$GET_INSTALL_PATH
741 MODULES=
742 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800743 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 -0700744 else
745 echo "Couldn't locate the top of the tree. Try setting TOP."
746 fi
747}
748
Ying Wangb607f7b2013-02-08 18:01:04 -0800749function mma()
750{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800751 local T=$(gettop)
752 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800753 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800754 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800755 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800756 if [ ! "$T" ]; then
757 echo "Couldn't locate the top of the tree. Try setting TOP."
758 fi
759 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800760 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800761 fi
762}
763
764function mmma()
765{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800766 local T=$(gettop)
767 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800768 if [ "$T" ]; then
769 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
770 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
771 local MY_PWD=`PWD= /bin/pwd`
772 if [ "$MY_PWD" = "$T" ]; then
773 MY_PWD=
774 else
775 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
776 fi
777 local DIR=
778 local MODULE_PATHS=
779 local ARGS=
780 for DIR in $DIRS ; do
781 if [ -d $DIR ]; then
782 if [ "$MY_PWD" = "" ]; then
783 MODULE_PATHS="$MODULE_PATHS $DIR"
784 else
785 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
786 fi
787 else
788 case $DIR in
789 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
790 *) echo "Couldn't find directory $DIR"; return 1;;
791 esac
792 fi
793 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800794 $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 -0800795 else
796 echo "Couldn't locate the top of the tree. Try setting TOP."
797 fi
798}
799
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700800function croot()
801{
802 T=$(gettop)
803 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800804 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700805 else
806 echo "Couldn't locate the top of the tree. Try setting TOP."
807 fi
808}
809
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700810function cproj()
811{
812 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700813 local HERE=$PWD
814 T=
815 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
816 T=$PWD
817 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800818 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700819 return
820 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800821 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700822 done
Ying Wang9cd17642012-12-13 10:52:07 -0800823 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700824 echo "can't find Android.mk"
825}
826
Daniel Sandler47e0a882013-07-30 13:23:52 -0400827# simplified version of ps; output in the form
828# <pid> <procname>
829function qpid() {
830 local prepend=''
831 local append=''
832 if [ "$1" = "--exact" ]; then
833 prepend=' '
834 append='$'
835 shift
836 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
837 echo "usage: qpid [[--exact] <process name|pid>"
838 return 255
839 fi
840
841 local EXE="$1"
842 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700843 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400844 else
845 adb shell ps \
846 | tr -d '\r' \
847 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
848 fi
849}
850
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700851function pid()
852{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400853 local prepend=''
854 local append=''
855 if [ "$1" = "--exact" ]; then
856 prepend=' '
857 append='$'
858 shift
859 fi
860 local EXE="$1"
861 if [ "$EXE" ] ; then
862 local PID=`adb shell ps \
863 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700864 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400865 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
866 echo "$PID"
867 else
868 echo "usage: pid [--exact] <process name>"
869 return 255
870 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700871}
872
Christopher Tate744ee802009-11-12 15:33:08 -0800873# systemstack - dump the current stack trace of all threads in the system process
874# to the usual ANR traces file
875function systemstack()
876{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800877 stacks system_server
878}
879
880function stacks()
881{
882 if [[ $1 =~ ^[0-9]+$ ]] ; then
883 local PID="$1"
884 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700885 local PIDLIST="$(pid $1)"
886 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
887 local PID="$PIDLIST"
888 elif [ "$PIDLIST" ] ; then
889 echo "more than one process: $1"
890 else
891 echo "no such process: $1"
892 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800893 else
894 echo "usage: stacks [pid|process name]"
895 fi
896
897 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700898 # Determine whether the process is native
899 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
900 # Dump stacks of Dalvik process
901 local TRACES=/data/anr/traces.txt
902 local ORIG=/data/anr/traces.orig
903 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800904
Jeff Brownb12c2e52013-08-19 15:14:16 -0700905 # Keep original traces to avoid clobbering
906 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800907
Jeff Brownb12c2e52013-08-19 15:14:16 -0700908 # Make sure we have a usable file
909 adb shell touch $TRACES
910 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800911
Jeff Brownb12c2e52013-08-19 15:14:16 -0700912 # Dump stacks and wait for dump to finish
913 adb shell kill -3 $PID
914 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800915
Jeff Brownb12c2e52013-08-19 15:14:16 -0700916 # Restore original stacks, and show current output
917 adb shell mv $TRACES $TMP
918 adb shell mv $ORIG $TRACES
919 adb shell cat $TMP
920 else
921 # Dump stacks of native process
922 adb shell debuggerd -b $PID
923 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800924 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800925}
926
John Michelau50200252012-11-09 11:48:04 -0600927function gdbwrapper()
928{
Ben Chengfba67bf2014-02-25 10:27:07 -0800929 local GDB_CMD="$1"
930 shift 1
931 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -0600932}
933
Ben Chengfba67bf2014-02-25 10:27:07 -0800934# process the symbolic link of /proc/$PID/exe and use the host file tool to
935# determine whether it is a 32-bit or 64-bit executable. It returns "" or "64"
936# which can be conveniently used as suffix.
937function is64bit()
938{
939 local PID="$1"
940 if [ "$PID" ] ; then
941 local EXE=`adb shell ls -l /proc/$PID/exe \
942 | tr -d '\r' \
943 | cut -d'>' -f2 \
944 | tr -d ' ' \
945 | cut -d'/' -f4`
946
947 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
948 local IS64BIT=`file $OUT_EXE_SYMBOLS/$EXE | grep "64-bit"`
949 if [ "$IS64BIT" != "" ]; then
950 echo "64"
951 else
952 echo ""
953 fi
954 else
955 echo ""
956 fi
957}
958
959# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
960# executable, set up the approriate gdbserver, then invokes the proper host
961# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700962function gdbclient()
963{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800964 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
965 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
966 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
967 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
968 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800969 local ARCH=$(get_build_var TARGET_ARCH)
970 local GDB
971 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800972 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800973 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700974 mips) GDB=mipsel-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000975 mips64) GDB=mipsel-linux-android-gdb;;
976 x86) GDB=x86_64-linux-android-gdb;;
977 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800978 *) echo "Unknown arch $ARCH"; return 1;;
979 esac
980
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700981 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
982 local EXE="$1"
983 if [ "$EXE" ] ; then
984 EXE=$1
985 else
986 EXE="app_process"
987 fi
988
989 local PORT="$2"
990 if [ "$PORT" ] ; then
991 PORT=$2
992 else
993 PORT=":5039"
994 fi
995
Chris Craik20c136a2012-11-09 18:02:19 -0800996 local PID="$3"
997 if [ "$PID" ] ; then
998 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700999 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -08001000 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1001 # that likely didn't work because of returning multiple processes
1002 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001003 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001004 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1005 then
1006 echo "Couldn't resolve '$3' to single PID"
1007 return 1
1008 else
1009 echo ""
1010 echo "WARNING: multiple processes matching '$3' observed, using root process"
1011 echo ""
1012 fi
1013 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001014 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001015 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001016 local USE64BIT="$(is64bit $PID)"
1017 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001018 sleep 2
1019 else
1020 echo ""
1021 echo "If you haven't done so already, do this first on the device:"
1022 echo " gdbserver $PORT /system/bin/$EXE"
1023 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001024 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001025 echo ""
1026 fi
1027
1028 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Ben Chengfba67bf2014-02-25 10:27:07 -08001029 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS$USE64BIT:$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 -07001030 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001031 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1032 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1033
Ben Chengfba67bf2014-02-25 10:27:07 -08001034 local WHICH_GDB=
1035 # 64-bit exe found
1036 if [ "$USE64BIT" != "" ] ; then
1037 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1038 # 32-bit exe / 32-bit platform
1039 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1040 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1041 # 32-bit exe / 64-bit platform
1042 else
1043 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1044 fi
1045 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001046 else
1047 echo "Unable to determine build system output dir."
1048 fi
1049
1050}
1051
1052case `uname -s` in
1053 Darwin)
1054 function sgrep()
1055 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001056 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 -07001057 }
1058
1059 ;;
1060 *)
1061 function sgrep()
1062 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001063 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 -07001064 }
1065 ;;
1066esac
1067
Raghu Gandham8da43102012-07-25 19:57:22 -07001068function gettargetarch
1069{
1070 get_build_var TARGET_ARCH
1071}
1072
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001073function jgrep()
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 "*\.java" -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001076}
1077
1078function cgrep()
1079{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001080 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 -07001081}
1082
1083function resgrep()
1084{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001085 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 -07001086}
1087
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001088function mangrep()
1089{
1090 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1091}
1092
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001093function sepgrep()
1094{
1095 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 "$@"
1096}
1097
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001098case `uname -s` in
1099 Darwin)
1100 function mgrep()
1101 {
Ying Wang324c2b22012-08-17 15:03:20 -07001102 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 -07001103 }
1104
1105 function treegrep()
1106 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001107 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 -07001108 }
1109
1110 ;;
1111 *)
1112 function mgrep()
1113 {
Ying Wang324c2b22012-08-17 15:03:20 -07001114 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 -07001115 }
1116
1117 function treegrep()
1118 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001119 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 -07001120 }
1121
1122 ;;
1123esac
1124
1125function getprebuilt
1126{
1127 get_abs_build_var ANDROID_PREBUILTS
1128}
1129
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001130function tracedmdump()
1131{
1132 T=$(gettop)
1133 if [ ! "$T" ]; then
1134 echo "Couldn't locate the top of the tree. Try setting TOP."
1135 return
1136 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001137 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001138 local arch=$(gettargetarch)
1139 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001140
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001141 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001142 if [ ! "$TRACE" ] ; then
1143 echo "usage: tracedmdump tracename"
1144 return
1145 fi
1146
Jack Veenstra60116fc2009-04-09 18:12:34 -07001147 if [ ! -r "$KERNEL" ] ; then
1148 echo "Error: cannot find kernel: '$KERNEL'"
1149 return
1150 fi
1151
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001152 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001153 if [ "$BASETRACE" = "$TRACE" ] ; then
1154 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1155 fi
1156
1157 echo "post-processing traces..."
1158 rm -f $TRACE/qtrace.dexlist
1159 post_trace $TRACE
1160 if [ $? -ne 0 ]; then
1161 echo "***"
1162 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1163 echo "***"
1164 return
1165 fi
1166 echo "generating dexlist output..."
1167 /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
1168 echo "generating dmtrace data..."
1169 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1170 echo "generating html file..."
1171 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1172 echo "done, see $TRACE/dmtrace.html for details"
1173 echo "or run:"
1174 echo " traceview $TRACE/dmtrace"
1175}
1176
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001177# communicate with a running device or emulator, set up necessary state,
1178# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001179function runhat()
1180{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001181 # process standard adb options
1182 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001183 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001184 adbTarget=$1
1185 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001186 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001187 adbTarget="$1 $2"
1188 shift 2
1189 fi
1190 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001191 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001192
1193 # runhat options
1194 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001195
1196 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001197 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001198 return
1199 fi
1200
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001201 # confirm hat is available
1202 if [ -z $(which hat) ]; then
1203 echo "hat is not available in this configuration."
1204 return
1205 fi
1206
Andy McFaddenb6289852010-07-12 08:00:19 -07001207 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001208 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001209 local devFile=$sdcard/hprof-$targetPid
1210 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001211 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001212 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001213 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001214 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001215 echo -n "> "
1216 read
1217
The Android Open Source Project88b60792009-03-03 19:28:42 -08001218 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001219
The Android Open Source Project88b60792009-03-03 19:28:42 -08001220 echo "Retrieving file $devFile..."
1221 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001222
The Android Open Source Project88b60792009-03-03 19:28:42 -08001223 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001224
The Android Open Source Project88b60792009-03-03 19:28:42 -08001225 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001226 echo "View the output by pointing your browser at http://localhost:7000/"
1227 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001228 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001229}
1230
1231function getbugreports()
1232{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001233 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001234
1235 if [ ! "$reports" ]; then
1236 echo "Could not locate any bugreports."
1237 return
1238 fi
1239
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001240 local report
1241 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001242 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001243 echo "/sdcard/bugreports/${report}"
1244 adb pull /sdcard/bugreports/${report} ${report}
1245 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001246 done
1247}
1248
Victoria Lease1b296b42012-08-21 15:44:06 -07001249function getsdcardpath()
1250{
1251 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1252}
1253
1254function getscreenshotpath()
1255{
1256 echo "$(getsdcardpath)/Pictures/Screenshots"
1257}
1258
1259function getlastscreenshot()
1260{
1261 local screenshot_path=$(getscreenshotpath)
1262 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1263 if [ "$screenshot" = "" ]; then
1264 echo "No screenshots found."
1265 return
1266 fi
1267 echo "${screenshot}"
1268 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1269}
1270
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001271function startviewserver()
1272{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001273 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001274 if [ $# -gt 0 ]; then
1275 port=$1
1276 fi
1277 adb shell service call window 1 i32 $port
1278}
1279
1280function stopviewserver()
1281{
1282 adb shell service call window 2
1283}
1284
1285function isviewserverstarted()
1286{
1287 adb shell service call window 3
1288}
1289
Romain Guyb84049a2010-10-04 16:56:11 -07001290function key_home()
1291{
1292 adb shell input keyevent 3
1293}
1294
1295function key_back()
1296{
1297 adb shell input keyevent 4
1298}
1299
1300function key_menu()
1301{
1302 adb shell input keyevent 82
1303}
1304
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001305function smoketest()
1306{
1307 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1308 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1309 return
1310 fi
1311 T=$(gettop)
1312 if [ ! "$T" ]; then
1313 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1314 return
1315 fi
1316
Ying Wang9cd17642012-12-13 10:52:07 -08001317 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001318 adb uninstall com.android.smoketest > /dev/null &&
1319 adb uninstall com.android.smoketest.tests > /dev/null &&
1320 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1321 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1322 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1323}
1324
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001325# simple shortcut to the runtest command
1326function runtest()
1327{
1328 T=$(gettop)
1329 if [ ! "$T" ]; then
1330 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1331 return
1332 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001333 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001334}
1335
The Android Open Source Project88b60792009-03-03 19:28:42 -08001336function godir () {
1337 if [[ -z "$1" ]]; then
1338 echo "Usage: godir <regex>"
1339 return
1340 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001341 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001342 if [[ ! -f $T/filelist ]]; then
1343 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001344 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001345 echo " Done"
1346 echo ""
1347 fi
1348 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001349 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001350 if [[ ${#lines[@]} = 0 ]]; then
1351 echo "Not found"
1352 return
1353 fi
1354 local pathname
1355 local choice
1356 if [[ ${#lines[@]} > 1 ]]; then
1357 while [[ -z "$pathname" ]]; do
1358 local index=1
1359 local line
1360 for line in ${lines[@]}; do
1361 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001362 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001363 done
1364 echo
1365 echo -n "Select one: "
1366 unset choice
1367 read choice
1368 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1369 echo "Invalid choice"
1370 continue
1371 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001372 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001373 done
1374 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001375 pathname=${lines[0]}
1376 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001377 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001378}
1379
Narayan Kamath9260bba2014-01-17 10:05:25 +00001380# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1381#
1382# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1383# For some reason, installing the JDK doesn't make it show up in the
1384# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001385function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001386 # Clear the existing JAVA_HOME value if we set it ourselves, so that
1387 # we can reset it later, depending on the value of EXPERIMENTAL_USE_JAVA7.
1388 #
1389 # If we don't do this, the JAVA_HOME value set by the first call to
1390 # build/envsetup.sh will persist forever.
1391 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1392 export JAVA_HOME=""
1393 fi
1394
Andy McFaddenbd960942010-06-24 12:52:51 -07001395 if [ ! "$JAVA_HOME" ]; then
Narayan Kamath9260bba2014-01-17 10:05:25 +00001396 if [ ! "$EXPERIMENTAL_USE_JAVA7" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001397 case `uname -s` in
1398 Darwin)
1399 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1400 ;;
1401 *)
1402 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1403 ;;
1404 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001405 else
1406 case `uname -s` in
1407 Darwin)
1408 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
1409 ;;
1410 *)
1411 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1412 ;;
1413 esac
1414 fi
1415
1416 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1417 # we can change it on the next envsetup.sh, if required.
1418 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001419 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001420}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001421
Alex Rayf0d08eb2013-03-08 15:15:06 -08001422# Print colored exit condition
1423function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001424 "$@"
1425 local retval=$?
1426 if [ $retval -ne 0 ]
1427 then
1428 echo -e "\e[0;31mFAILURE\e[00m"
1429 else
1430 echo -e "\e[0;32mSUCCESS\e[00m"
1431 fi
1432 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001433}
1434
Raphael Moll70a86b02011-06-20 16:03:14 -07001435if [ "x$SHELL" != "x/bin/bash" ]; then
1436 case `ps -o command -p $$` in
1437 *bash*)
1438 ;;
1439 *)
1440 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1441 ;;
1442 esac
1443fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001444
1445# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001446for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1447 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001448do
1449 echo "including $f"
1450 . $f
1451done
1452unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001453
1454addcompletions