blob: 8fad5fb65dc19fbf10dd33b0ddfa43e05d06f5d8 [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Ying Wang67f02922012-08-22 10:25:20 -07004- lunch: lunch <product_name>-<build_variant>
Ying Wangf05c4f72013-01-31 11:16:57 -08005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [eng|userdebug|user]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07006- croot: Changes directory to the top of the tree.
7- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08008- mm: Builds all of the modules in the current directory, but not their dependencies.
9- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000010 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080011- mma: Builds all of the modules in the current directory, and their dependencies.
12- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070013- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070014- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070015- jgrep: Greps on all local Java files.
16- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080017- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070018
19Look at the source to view more functions. The complete list is:
20EOF
21 T=$(gettop)
22 local A
23 A=""
24 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
25 A="$A $i"
26 done
27 echo $A
28}
29
30# Get the value of a build variable as an absolute path.
31function get_abs_build_var()
32{
33 T=$(gettop)
34 if [ ! "$T" ]; then
35 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
36 return
37 fi
Ying Wang9cd17642012-12-13 10:52:07 -080038 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Andrew Boie6905e212013-12-19 13:21:46 -080039 make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070040}
41
42# Get the exact value of a build variable.
43function get_build_var()
44{
45 T=$(gettop)
46 if [ ! "$T" ]; then
47 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
48 return
49 fi
Andrew Boie6905e212013-12-19 13:21:46 -080050 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
51 make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080052}
53
54# check to see if the supplied product is one we can build
55function check_product()
56{
57 T=$(gettop)
58 if [ ! "$T" ]; then
59 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
60 return
61 fi
62 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Jeff Browne33ba4c2011-07-11 22:11:46 -070063 TARGET_PRODUCT=$1 \
64 TARGET_BUILD_VARIANT= \
65 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070066 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080067 get_build_var TARGET_DEVICE > /dev/null
68 # hide successful answers, but allow the errors to show
69}
70
71VARIANT_CHOICES=(user userdebug eng)
72
73# check to see if the supplied variant is valid
74function check_variant()
75{
76 for v in ${VARIANT_CHOICES[@]}
77 do
78 if [ "$v" = "$1" ]
79 then
80 return 0
81 fi
82 done
83 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070084}
85
86function setpaths()
87{
88 T=$(gettop)
89 if [ ! "$T" ]; then
90 echo "Couldn't locate the top of the tree. Try setting TOP."
91 return
92 fi
93
94 ##################################################################
95 # #
96 # Read me before you modify this code #
97 # #
98 # This function sets ANDROID_BUILD_PATHS to what it is adding #
99 # to PATH, and the next time it is run, it removes that from #
100 # PATH. This is required so lunch can be run more than once #
101 # and still have working paths. #
102 # #
103 ##################################################################
104
Raphael Mollc639c782011-06-20 17:25:01 -0700105 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
106 # due to "C:\Program Files" being in the path.
107
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700108 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700109 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700110 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
111 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700112 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700113 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800114 # strip leading ':', if any
115 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500116 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700117
118 # and in with the new
119 CODE_REVIEWS=
120 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700121 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700122
Ben Cheng8bc4c432012-11-16 13:29:13 -0800123 # defined in core/config.mk
124 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800125 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800126
Raphael Mollc639c782011-06-20 17:25:01 -0700127 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800128 export ANDROID_TOOLCHAIN=
129 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200130 local ARCH=$(get_build_var TARGET_ARCH)
131 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400132 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700133 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400134 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
135 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800136 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200137 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800138 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
139 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700140 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800141 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700142 ;;
Chris Dearman1efd9e42014-02-03 15:01:24 -0800143 mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000144 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200145 *)
146 echo "Can't find toolchain for unknown architecture: $ARCH"
147 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700148 ;;
149 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700150 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800151 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700152 fi
Raphael732936d2011-06-22 14:35:32 -0700153
Ben Chengfba67bf2014-02-25 10:27:07 -0800154 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
155 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
156 fi
157
158 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700159 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700160 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800161 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800162 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700163 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800164 ANDROID_KERNEL_TOOLCHAIN_PATH="$gccprebuiltdir/$toolchaindir"
165 export ARM_EABI_TOOLCHAIN=$ANDROID_KERNEL_TOOLCHAIN_PATH
Bruce Beare42ced6d2012-07-17 21:40:01 -0700166 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700167 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700168 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
169 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700170 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700171 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700172 ;;
173 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700174
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700175 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700176 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ben Chengfba67bf2014-02-25 10:27:07 -0800177 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 -0800178 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800179
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500180 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900181 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500182 if [ -n "$JAVA_HOME" ]; then
183 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900184 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
185 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500186 fi
187
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800188 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700189 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
190 export OUT=$ANDROID_PRODUCT_OUT
191
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700192 unset ANDROID_HOST_OUT
193 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
194
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800195 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700196 # TODO: fix the path
197 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
198}
199
200function printconfig()
201{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800202 T=$(gettop)
203 if [ ! "$T" ]; then
204 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
205 return
206 fi
207 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700208}
209
210function set_stuff_for_environment()
211{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800212 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500213 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800214 setpaths
215 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700216
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800217 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700218 # With this environment variable new GCC can apply colors to warnings/errors
219 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 -0700220}
221
222function set_sequence_number()
223{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700224 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700225}
226
227function settitle()
228{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800229 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700230 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700231 local product=$TARGET_PRODUCT
232 local variant=$TARGET_BUILD_VARIANT
233 local apps=$TARGET_BUILD_APPS
234 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700235 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700236 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700237 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700238 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800239 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700240}
241
Kenny Root52aa81c2011-07-15 11:07:06 -0700242function addcompletions()
243{
244 local T dir f
245
246 # Keep us from trying to run in something that isn't bash.
247 if [ -z "${BASH_VERSION}" ]; then
248 return
249 fi
250
251 # Keep us from trying to run in bash that's too old.
252 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
253 return
254 fi
255
256 dir="sdk/bash_completion"
257 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700258 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700259 echo "including $f"
260 . $f
261 done
262 fi
263}
264
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700265function choosetype()
266{
267 echo "Build type choices are:"
268 echo " 1. release"
269 echo " 2. debug"
270 echo
271
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800272 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700273 DEFAULT_NUM=1
274 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700275
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800276 export TARGET_BUILD_TYPE=
277 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700278 while [ -z $TARGET_BUILD_TYPE ]
279 do
280 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800281 if [ -z "$1" ] ; then
282 read ANSWER
283 else
284 echo $1
285 ANSWER=$1
286 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700287 case $ANSWER in
288 "")
289 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
290 ;;
291 1)
292 export TARGET_BUILD_TYPE=release
293 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800294 release)
295 export TARGET_BUILD_TYPE=release
296 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297 2)
298 export TARGET_BUILD_TYPE=debug
299 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800300 debug)
301 export TARGET_BUILD_TYPE=debug
302 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700303 *)
304 echo
305 echo "I didn't understand your response. Please try again."
306 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700307 ;;
308 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800309 if [ -n "$1" ] ; then
310 break
311 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700312 done
313
314 set_stuff_for_environment
315}
316
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800317#
318# This function isn't really right: It chooses a TARGET_PRODUCT
319# based on the list of boards. Usually, that gets you something
320# that kinda works with a generic product, but really, you should
321# pick a product by name.
322#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700323function chooseproduct()
324{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325 if [ "x$TARGET_PRODUCT" != x ] ; then
326 default_value=$TARGET_PRODUCT
327 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700328 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700329 fi
330
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 export TARGET_PRODUCT=
332 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700333 while [ -z "$TARGET_PRODUCT" ]
334 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700335 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336 if [ -z "$1" ] ; then
337 read ANSWER
338 else
339 echo $1
340 ANSWER=$1
341 fi
342
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700343 if [ -z "$ANSWER" ] ; then
344 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800345 else
346 if check_product $ANSWER
347 then
348 export TARGET_PRODUCT=$ANSWER
349 else
350 echo "** Not a valid product: $ANSWER"
351 fi
352 fi
353 if [ -n "$1" ] ; then
354 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700355 fi
356 done
357
358 set_stuff_for_environment
359}
360
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800361function choosevariant()
362{
363 echo "Variant choices are:"
364 local index=1
365 local v
366 for v in ${VARIANT_CHOICES[@]}
367 do
368 # The product name is the name of the directory containing
369 # the makefile we found, above.
370 echo " $index. $v"
371 index=$(($index+1))
372 done
373
374 local default_value=eng
375 local ANSWER
376
377 export TARGET_BUILD_VARIANT=
378 while [ -z "$TARGET_BUILD_VARIANT" ]
379 do
380 echo -n "Which would you like? [$default_value] "
381 if [ -z "$1" ] ; then
382 read ANSWER
383 else
384 echo $1
385 ANSWER=$1
386 fi
387
388 if [ -z "$ANSWER" ] ; then
389 export TARGET_BUILD_VARIANT=$default_value
390 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
391 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800392 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800393 fi
394 else
395 if check_variant $ANSWER
396 then
397 export TARGET_BUILD_VARIANT=$ANSWER
398 else
399 echo "** Not a valid variant: $ANSWER"
400 fi
401 fi
402 if [ -n "$1" ] ; then
403 break
404 fi
405 done
406}
407
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700408function choosecombo()
409{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700410 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700411
412 echo
413 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700414 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700415
416 echo
417 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700418 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800419
420 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700421 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800422 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700423}
424
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800425# Clear this variable. It will be built up again when the vendorsetup.sh
426# files are included at the end of this file.
427unset LUNCH_MENU_CHOICES
428function add_lunch_combo()
429{
430 local new_combo=$1
431 local c
432 for c in ${LUNCH_MENU_CHOICES[@]} ; do
433 if [ "$new_combo" = "$c" ] ; then
434 return
435 fi
436 done
437 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
438}
439
440# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700441add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800442add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000443add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800444add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000445add_lunch_combo aosp_x86-eng
446add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800447add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800448
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449function print_lunch_menu()
450{
451 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700452 echo
453 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700454 echo
455 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800456
457 local i=1
458 local choice
459 for choice in ${LUNCH_MENU_CHOICES[@]}
460 do
461 echo " $i. $choice"
462 i=$(($i+1))
463 done
464
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465 echo
466}
467
468function lunch()
469{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800470 local answer
471
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700472 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800473 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474 else
475 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700476 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478 fi
479
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480 local selection=
481
482 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700484 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800485 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
486 then
487 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
488 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800489 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490 fi
491 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
492 then
493 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700494 fi
495
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800496 if [ -z "$selection" ]
497 then
498 echo
499 echo "Invalid lunch combo: $answer"
500 return 1
501 fi
502
Joe Onoratoda12daf2010-06-09 18:18:31 -0700503 export TARGET_BUILD_APPS=
504
Jeff Browne33ba4c2011-07-11 22:11:46 -0700505 local product=$(echo -n $selection | sed -e "s/-.*$//")
506 check_product $product
507 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800508 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700509 echo
510 echo "** Don't have a product spec for: '$product'"
511 echo "** Do you have the right repo manifest?"
512 product=
513 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800514
Jeff Browne33ba4c2011-07-11 22:11:46 -0700515 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
516 check_variant $variant
517 if [ $? -ne 0 ]
518 then
519 echo
520 echo "** Invalid variant: '$variant'"
521 echo "** Must be one of ${VARIANT_CHOICES[@]}"
522 variant=
523 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800524
Jeff Browne33ba4c2011-07-11 22:11:46 -0700525 if [ -z "$product" -o -z "$variant" ]
526 then
527 echo
528 return 1
529 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530
Jeff Browne33ba4c2011-07-11 22:11:46 -0700531 export TARGET_PRODUCT=$product
532 export TARGET_BUILD_VARIANT=$variant
533 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700534
535 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800536
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700537 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800538 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700539}
540
Jeff Davidson513d7a42010-08-02 10:00:44 -0700541# Tab completion for lunch.
542function _lunch()
543{
544 local cur prev opts
545 COMPREPLY=()
546 cur="${COMP_WORDS[COMP_CWORD]}"
547 prev="${COMP_WORDS[COMP_CWORD-1]}"
548
549 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
550 return 0
551}
552complete -F _lunch lunch
553
Joe Onoratoda12daf2010-06-09 18:18:31 -0700554# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700555# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700556function tapas()
557{
Doug Zongker0d8179e2014-04-16 11:34:34 -0700558 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$' | xargs)"
559 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
560 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700561
Ying Wang67f02922012-08-22 10:25:20 -0700562 if [ $(echo $arch | wc -w) -gt 1 ]; then
563 echo "tapas: Error: Multiple build archs supplied: $arch"
564 return
565 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700566 if [ $(echo $variant | wc -w) -gt 1 ]; then
567 echo "tapas: Error: Multiple build variants supplied: $variant"
568 return
569 fi
Ying Wang67f02922012-08-22 10:25:20 -0700570
571 local product=full
572 case $arch in
573 x86) product=full_x86;;
574 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800575 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700576 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700577 if [ -z "$variant" ]; then
578 variant=eng
579 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700580 if [ -z "$apps" ]; then
581 apps=all
582 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700583
Ying Wang67f02922012-08-22 10:25:20 -0700584 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700585 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700586 export TARGET_BUILD_TYPE=release
587 export TARGET_BUILD_APPS=$apps
588
589 set_stuff_for_environment
590 printconfig
591}
592
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700593function gettop
594{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800595 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
597 echo $TOP
598 else
599 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800600 # The following circumlocution (repeated below as well) ensures
601 # that we record the true directory name and not one that is
602 # faked up with symlink names.
603 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800605 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700606 T=
607 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800608 \cd ..
synergyb112a402013-07-05 19:47:47 -0700609 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700610 done
Ying Wang9cd17642012-12-13 10:52:07 -0800611 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700612 if [ -f "$T/$TOPFILE" ]; then
613 echo $T
614 fi
615 fi
616 fi
617}
618
Andrew Hsieh906cb782013-09-10 17:37:14 +0800619# Return driver for "make", if any (eg. static analyzer)
620function getdriver()
621{
622 local T="$1"
623 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
624 if [ -n "$WITH_STATIC_ANALYZER" ]; then
625 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800626$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
627--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800628--status-bugs \
629--top=$T"
630 fi
631}
632
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700633function m()
634{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800635 local T=$(gettop)
636 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700637 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800638 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700639 else
640 echo "Couldn't locate the top of the tree. Try setting TOP."
641 fi
642}
643
644function findmakefile()
645{
646 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800647 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700648 T=
649 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700650 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651 if [ -f "$T/Android.mk" ]; then
652 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800653 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700654 return
655 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800656 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657 done
Ying Wang9cd17642012-12-13 10:52:07 -0800658 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659}
660
661function mm()
662{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800663 local T=$(gettop)
664 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700665 # If we're sitting in the root of the build tree, just do a
666 # normal make.
667 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800668 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700669 else
670 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800671 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700672 local MODULES=
673 local GET_INSTALL_PATH=
674 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700675 # Remove the path to top as the makefilepath needs to be relative
676 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700677 if [ ! "$T" ]; then
678 echo "Couldn't locate the top of the tree. Try setting TOP."
679 elif [ ! "$M" ]; then
680 echo "Couldn't locate a makefile from the current directory."
681 else
Ying Wanga7deb082013-08-16 13:24:47 -0700682 for ARG in $@; do
683 case $ARG in
684 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
685 esac
686 done
687 if [ -n "$GET_INSTALL_PATH" ]; then
688 MODULES=
689 ARGS=GET-INSTALL-PATH
690 else
691 MODULES=all_modules
692 ARGS=$@
693 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700694 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 -0700695 fi
696 fi
697}
698
699function mmm()
700{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800701 local T=$(gettop)
702 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700703 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800704 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800705 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800706 local ARGS=
707 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700708 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800709 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
710 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
711 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800712 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
713 if [ "$MODULES" = "" ]; then
714 MODULES=all_modules
715 fi
716 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700717 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700718 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
719 local TO_CHOP=`expr $TO_CHOP + 1`
720 local START=`PWD= /bin/pwd`
721 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700722 if [ "$MFILE" = "" ] ; then
723 MFILE=$DIR/Android.mk
724 else
725 MFILE=$MFILE/$DIR/Android.mk
726 fi
727 MAKEFILE="$MAKEFILE $MFILE"
728 else
Ying Wanga7deb082013-08-16 13:24:47 -0700729 case $DIR in
730 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
731 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
732 *) echo "No Android.mk in $DIR."; return 1;;
733 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700734 fi
735 done
Ying Wanga7deb082013-08-16 13:24:47 -0700736 if [ -n "$GET_INSTALL_PATH" ]; then
737 ARGS=$GET_INSTALL_PATH
738 MODULES=
739 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800740 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 -0700741 else
742 echo "Couldn't locate the top of the tree. Try setting TOP."
743 fi
744}
745
Ying Wangb607f7b2013-02-08 18:01:04 -0800746function mma()
747{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800748 local T=$(gettop)
749 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800750 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800751 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800752 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800753 if [ ! "$T" ]; then
754 echo "Couldn't locate the top of the tree. Try setting TOP."
755 fi
756 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800757 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800758 fi
759}
760
761function mmma()
762{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800763 local T=$(gettop)
764 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800765 if [ "$T" ]; then
766 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
767 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
768 local MY_PWD=`PWD= /bin/pwd`
769 if [ "$MY_PWD" = "$T" ]; then
770 MY_PWD=
771 else
772 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
773 fi
774 local DIR=
775 local MODULE_PATHS=
776 local ARGS=
777 for DIR in $DIRS ; do
778 if [ -d $DIR ]; then
779 if [ "$MY_PWD" = "" ]; then
780 MODULE_PATHS="$MODULE_PATHS $DIR"
781 else
782 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
783 fi
784 else
785 case $DIR in
786 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
787 *) echo "Couldn't find directory $DIR"; return 1;;
788 esac
789 fi
790 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800791 $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 -0800792 else
793 echo "Couldn't locate the top of the tree. Try setting TOP."
794 fi
795}
796
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797function croot()
798{
799 T=$(gettop)
800 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800801 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700802 else
803 echo "Couldn't locate the top of the tree. Try setting TOP."
804 fi
805}
806
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700807function cproj()
808{
809 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700810 local HERE=$PWD
811 T=
812 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
813 T=$PWD
814 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800815 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700816 return
817 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800818 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700819 done
Ying Wang9cd17642012-12-13 10:52:07 -0800820 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700821 echo "can't find Android.mk"
822}
823
Daniel Sandler47e0a882013-07-30 13:23:52 -0400824# simplified version of ps; output in the form
825# <pid> <procname>
826function qpid() {
827 local prepend=''
828 local append=''
829 if [ "$1" = "--exact" ]; then
830 prepend=' '
831 append='$'
832 shift
833 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
834 echo "usage: qpid [[--exact] <process name|pid>"
835 return 255
836 fi
837
838 local EXE="$1"
839 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700840 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400841 else
842 adb shell ps \
843 | tr -d '\r' \
844 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
845 fi
846}
847
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700848function pid()
849{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400850 local prepend=''
851 local append=''
852 if [ "$1" = "--exact" ]; then
853 prepend=' '
854 append='$'
855 shift
856 fi
857 local EXE="$1"
858 if [ "$EXE" ] ; then
859 local PID=`adb shell ps \
860 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700861 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400862 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
863 echo "$PID"
864 else
865 echo "usage: pid [--exact] <process name>"
866 return 255
867 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700868}
869
Christopher Tate744ee802009-11-12 15:33:08 -0800870# systemstack - dump the current stack trace of all threads in the system process
871# to the usual ANR traces file
872function systemstack()
873{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800874 stacks system_server
875}
876
877function stacks()
878{
879 if [[ $1 =~ ^[0-9]+$ ]] ; then
880 local PID="$1"
881 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700882 local PIDLIST="$(pid $1)"
883 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
884 local PID="$PIDLIST"
885 elif [ "$PIDLIST" ] ; then
886 echo "more than one process: $1"
887 else
888 echo "no such process: $1"
889 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800890 else
891 echo "usage: stacks [pid|process name]"
892 fi
893
894 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700895 # Determine whether the process is native
896 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
897 # Dump stacks of Dalvik process
898 local TRACES=/data/anr/traces.txt
899 local ORIG=/data/anr/traces.orig
900 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800901
Jeff Brownb12c2e52013-08-19 15:14:16 -0700902 # Keep original traces to avoid clobbering
903 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800904
Jeff Brownb12c2e52013-08-19 15:14:16 -0700905 # Make sure we have a usable file
906 adb shell touch $TRACES
907 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800908
Jeff Brownb12c2e52013-08-19 15:14:16 -0700909 # Dump stacks and wait for dump to finish
910 adb shell kill -3 $PID
911 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800912
Jeff Brownb12c2e52013-08-19 15:14:16 -0700913 # Restore original stacks, and show current output
914 adb shell mv $TRACES $TMP
915 adb shell mv $ORIG $TRACES
916 adb shell cat $TMP
917 else
918 # Dump stacks of native process
919 adb shell debuggerd -b $PID
920 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800921 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800922}
923
John Michelau50200252012-11-09 11:48:04 -0600924function gdbwrapper()
925{
Ben Chengfba67bf2014-02-25 10:27:07 -0800926 local GDB_CMD="$1"
927 shift 1
928 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -0600929}
930
Ben Chengfba67bf2014-02-25 10:27:07 -0800931# process the symbolic link of /proc/$PID/exe and use the host file tool to
932# determine whether it is a 32-bit or 64-bit executable. It returns "" or "64"
933# which can be conveniently used as suffix.
934function is64bit()
935{
936 local PID="$1"
937 if [ "$PID" ] ; then
938 local EXE=`adb shell ls -l /proc/$PID/exe \
939 | tr -d '\r' \
940 | cut -d'>' -f2 \
941 | tr -d ' ' \
942 | cut -d'/' -f4`
943
944 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
945 local IS64BIT=`file $OUT_EXE_SYMBOLS/$EXE | grep "64-bit"`
946 if [ "$IS64BIT" != "" ]; then
947 echo "64"
948 else
949 echo ""
950 fi
951 else
952 echo ""
953 fi
954}
955
956# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
957# executable, set up the approriate gdbserver, then invokes the proper host
958# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700959function gdbclient()
960{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800961 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
962 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
963 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
964 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
965 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800966 local ARCH=$(get_build_var TARGET_ARCH)
967 local GDB
968 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800969 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800970 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700971 mips) GDB=mipsel-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000972 mips64) GDB=mipsel-linux-android-gdb;;
973 x86) GDB=x86_64-linux-android-gdb;;
974 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800975 *) echo "Unknown arch $ARCH"; return 1;;
976 esac
977
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700978 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
979 local EXE="$1"
980 if [ "$EXE" ] ; then
981 EXE=$1
982 else
983 EXE="app_process"
984 fi
985
986 local PORT="$2"
987 if [ "$PORT" ] ; then
988 PORT=$2
989 else
990 PORT=":5039"
991 fi
992
Chris Craik20c136a2012-11-09 18:02:19 -0800993 local PID="$3"
994 if [ "$PID" ] ; then
995 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700996 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800997 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
998 # that likely didn't work because of returning multiple processes
999 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001000 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001001 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1002 then
1003 echo "Couldn't resolve '$3' to single PID"
1004 return 1
1005 else
1006 echo ""
1007 echo "WARNING: multiple processes matching '$3' observed, using root process"
1008 echo ""
1009 fi
1010 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001011 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001012 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001013 local USE64BIT="$(is64bit $PID)"
1014 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001015 sleep 2
1016 else
1017 echo ""
1018 echo "If you haven't done so already, do this first on the device:"
1019 echo " gdbserver $PORT /system/bin/$EXE"
1020 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001021 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001022 echo ""
1023 fi
1024
Colin Cross84480ad2014-04-10 12:51:39 -07001025 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1026
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001027 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Colin Cross84480ad2014-04-10 12:51:39 -07001028 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 -07001029 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001030 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1031 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1032
Ben Chengfba67bf2014-02-25 10:27:07 -08001033 local WHICH_GDB=
1034 # 64-bit exe found
1035 if [ "$USE64BIT" != "" ] ; then
1036 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1037 # 32-bit exe / 32-bit platform
1038 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1039 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1040 # 32-bit exe / 64-bit platform
1041 else
1042 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1043 fi
1044 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001045 else
1046 echo "Unable to determine build system output dir."
1047 fi
1048
1049}
1050
1051case `uname -s` in
1052 Darwin)
1053 function sgrep()
1054 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001055 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 -07001056 }
1057
1058 ;;
1059 *)
1060 function sgrep()
1061 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001062 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 -07001063 }
1064 ;;
1065esac
1066
Raghu Gandham8da43102012-07-25 19:57:22 -07001067function gettargetarch
1068{
1069 get_build_var TARGET_ARCH
1070}
1071
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001072function ggrep()
1073{
1074 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1075}
1076
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001077function jgrep()
1078{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001079 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 -07001080}
1081
1082function cgrep()
1083{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001084 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 -07001085}
1086
1087function resgrep()
1088{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001089 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 -07001090}
1091
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001092function mangrep()
1093{
1094 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1095}
1096
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001097function sepgrep()
1098{
1099 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 "$@"
1100}
1101
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001102case `uname -s` in
1103 Darwin)
1104 function mgrep()
1105 {
Ying Wang324c2b22012-08-17 15:03:20 -07001106 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 -07001107 }
1108
1109 function treegrep()
1110 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001111 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 -07001112 }
1113
1114 ;;
1115 *)
1116 function mgrep()
1117 {
Ying Wang324c2b22012-08-17 15:03:20 -07001118 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 -07001119 }
1120
1121 function treegrep()
1122 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001123 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 -07001124 }
1125
1126 ;;
1127esac
1128
1129function getprebuilt
1130{
1131 get_abs_build_var ANDROID_PREBUILTS
1132}
1133
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001134function tracedmdump()
1135{
1136 T=$(gettop)
1137 if [ ! "$T" ]; then
1138 echo "Couldn't locate the top of the tree. Try setting TOP."
1139 return
1140 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001141 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001142 local arch=$(gettargetarch)
1143 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001144
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001145 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001146 if [ ! "$TRACE" ] ; then
1147 echo "usage: tracedmdump tracename"
1148 return
1149 fi
1150
Jack Veenstra60116fc2009-04-09 18:12:34 -07001151 if [ ! -r "$KERNEL" ] ; then
1152 echo "Error: cannot find kernel: '$KERNEL'"
1153 return
1154 fi
1155
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001156 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001157 if [ "$BASETRACE" = "$TRACE" ] ; then
1158 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1159 fi
1160
1161 echo "post-processing traces..."
1162 rm -f $TRACE/qtrace.dexlist
1163 post_trace $TRACE
1164 if [ $? -ne 0 ]; then
1165 echo "***"
1166 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1167 echo "***"
1168 return
1169 fi
1170 echo "generating dexlist output..."
1171 /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
1172 echo "generating dmtrace data..."
1173 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1174 echo "generating html file..."
1175 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1176 echo "done, see $TRACE/dmtrace.html for details"
1177 echo "or run:"
1178 echo " traceview $TRACE/dmtrace"
1179}
1180
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001181# communicate with a running device or emulator, set up necessary state,
1182# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001183function runhat()
1184{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001185 # process standard adb options
1186 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001187 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001188 adbTarget=$1
1189 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001190 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001191 adbTarget="$1 $2"
1192 shift 2
1193 fi
1194 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001195 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001196
1197 # runhat options
1198 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001199
1200 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001201 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001202 return
1203 fi
1204
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001205 # confirm hat is available
1206 if [ -z $(which hat) ]; then
1207 echo "hat is not available in this configuration."
1208 return
1209 fi
1210
Andy McFaddenb6289852010-07-12 08:00:19 -07001211 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001212 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001213 local devFile=$sdcard/hprof-$targetPid
1214 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001215 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001216 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001217 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001218 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001219 echo -n "> "
1220 read
1221
The Android Open Source Project88b60792009-03-03 19:28:42 -08001222 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001223
The Android Open Source Project88b60792009-03-03 19:28:42 -08001224 echo "Retrieving file $devFile..."
1225 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001226
The Android Open Source Project88b60792009-03-03 19:28:42 -08001227 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001228
The Android Open Source Project88b60792009-03-03 19:28:42 -08001229 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001230 echo "View the output by pointing your browser at http://localhost:7000/"
1231 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001232 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001233}
1234
1235function getbugreports()
1236{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001237 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001238
1239 if [ ! "$reports" ]; then
1240 echo "Could not locate any bugreports."
1241 return
1242 fi
1243
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001244 local report
1245 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001246 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001247 echo "/sdcard/bugreports/${report}"
1248 adb pull /sdcard/bugreports/${report} ${report}
1249 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001250 done
1251}
1252
Victoria Lease1b296b42012-08-21 15:44:06 -07001253function getsdcardpath()
1254{
1255 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1256}
1257
1258function getscreenshotpath()
1259{
1260 echo "$(getsdcardpath)/Pictures/Screenshots"
1261}
1262
1263function getlastscreenshot()
1264{
1265 local screenshot_path=$(getscreenshotpath)
1266 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1267 if [ "$screenshot" = "" ]; then
1268 echo "No screenshots found."
1269 return
1270 fi
1271 echo "${screenshot}"
1272 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1273}
1274
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001275function startviewserver()
1276{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001277 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001278 if [ $# -gt 0 ]; then
1279 port=$1
1280 fi
1281 adb shell service call window 1 i32 $port
1282}
1283
1284function stopviewserver()
1285{
1286 adb shell service call window 2
1287}
1288
1289function isviewserverstarted()
1290{
1291 adb shell service call window 3
1292}
1293
Romain Guyb84049a2010-10-04 16:56:11 -07001294function key_home()
1295{
1296 adb shell input keyevent 3
1297}
1298
1299function key_back()
1300{
1301 adb shell input keyevent 4
1302}
1303
1304function key_menu()
1305{
1306 adb shell input keyevent 82
1307}
1308
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001309function smoketest()
1310{
1311 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1312 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1313 return
1314 fi
1315 T=$(gettop)
1316 if [ ! "$T" ]; then
1317 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1318 return
1319 fi
1320
Ying Wang9cd17642012-12-13 10:52:07 -08001321 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001322 adb uninstall com.android.smoketest > /dev/null &&
1323 adb uninstall com.android.smoketest.tests > /dev/null &&
1324 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1325 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1326 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1327}
1328
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001329# simple shortcut to the runtest command
1330function runtest()
1331{
1332 T=$(gettop)
1333 if [ ! "$T" ]; then
1334 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1335 return
1336 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001337 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001338}
1339
The Android Open Source Project88b60792009-03-03 19:28:42 -08001340function godir () {
1341 if [[ -z "$1" ]]; then
1342 echo "Usage: godir <regex>"
1343 return
1344 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001345 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001346 if [[ ! -f $T/filelist ]]; then
1347 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001348 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001349 echo " Done"
1350 echo ""
1351 fi
1352 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001353 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001354 if [[ ${#lines[@]} = 0 ]]; then
1355 echo "Not found"
1356 return
1357 fi
1358 local pathname
1359 local choice
1360 if [[ ${#lines[@]} > 1 ]]; then
1361 while [[ -z "$pathname" ]]; do
1362 local index=1
1363 local line
1364 for line in ${lines[@]}; do
1365 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001366 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001367 done
1368 echo
1369 echo -n "Select one: "
1370 unset choice
1371 read choice
1372 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1373 echo "Invalid choice"
1374 continue
1375 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001376 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001377 done
1378 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001379 pathname=${lines[0]}
1380 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001381 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001382}
1383
Narayan Kamath9260bba2014-01-17 10:05:25 +00001384# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1385#
1386# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1387# For some reason, installing the JDK doesn't make it show up in the
1388# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001389function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001390 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001391 # we can reset it later, depending on the version of java the build
1392 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001393 #
1394 # If we don't do this, the JAVA_HOME value set by the first call to
1395 # build/envsetup.sh will persist forever.
1396 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1397 export JAVA_HOME=""
1398 fi
1399
Andy McFaddenbd960942010-06-24 12:52:51 -07001400 if [ ! "$JAVA_HOME" ]; then
Narayan Kamathc84889b2014-04-01 14:16:26 +01001401 if [ -n "$LEGACY_USE_JAVA6" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001402 case `uname -s` in
1403 Darwin)
1404 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1405 ;;
1406 *)
1407 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1408 ;;
1409 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001410 else
1411 case `uname -s` in
1412 Darwin)
1413 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
1414 ;;
1415 *)
1416 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1417 ;;
1418 esac
1419 fi
1420
1421 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1422 # we can change it on the next envsetup.sh, if required.
1423 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001424 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001425}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001426
Alex Rayf0d08eb2013-03-08 15:15:06 -08001427# Print colored exit condition
1428function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001429 "$@"
1430 local retval=$?
1431 if [ $retval -ne 0 ]
1432 then
1433 echo -e "\e[0;31mFAILURE\e[00m"
1434 else
1435 echo -e "\e[0;32mSUCCESS\e[00m"
1436 fi
1437 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001438}
1439
Raphael Moll70a86b02011-06-20 16:03:14 -07001440if [ "x$SHELL" != "x/bin/bash" ]; then
1441 case `ps -o command -p $$` in
1442 *bash*)
1443 ;;
1444 *)
1445 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1446 ;;
1447 esac
1448fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001449
1450# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001451for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1452 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001453do
1454 echo "including $f"
1455 . $f
1456done
1457unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001458
1459addcompletions