blob: f510146d0d5005502ae506d655b0bf637ec1eb02 [file] [log] [blame]
Ed Heylcc6be0a2014-06-18 14:55:58 -07001MAKE_UTIL=(`which make`)
Scott Anderson1a5fc952012-03-07 17:15:06 -08002function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07003cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08004Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Ying Wang67f02922012-08-22 10:25:20 -07005- lunch: lunch <product_name>-<build_variant>
Ying Wangb541ab62014-05-29 17:57:40 -07006- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07007- croot: Changes directory to the top of the tree.
8- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08009- mm: Builds all of the modules in the current directory, but not their dependencies.
10- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000011 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080012- mma: Builds all of the modules in the current directory, and their dependencies.
13- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070014- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070015- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070016- jgrep: Greps on all local Java files.
17- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080018- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070019
20Look at the source to view more functions. The complete list is:
21EOF
22 T=$(gettop)
23 local A
24 A=""
25 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
26 A="$A $i"
27 done
28 echo $A
29}
30
31# Get the value of a build variable as an absolute path.
32function get_abs_build_var()
33{
34 T=$(gettop)
35 if [ ! "$T" ]; then
36 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
37 return
38 fi
Ying Wang9cd17642012-12-13 10:52:07 -080039 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylcc6be0a2014-06-18 14:55:58 -070040 $MAKE_UTIL --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070041}
42
43# Get the exact value of a build variable.
44function get_build_var()
45{
46 T=$(gettop)
47 if [ ! "$T" ]; then
48 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
49 return
50 fi
Andrew Boie6905e212013-12-19 13:21:46 -080051 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylcc6be0a2014-06-18 14:55:58 -070052 $MAKE_UTIL --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080053}
54
55# check to see if the supplied product is one we can build
56function check_product()
57{
58 T=$(gettop)
59 if [ ! "$T" ]; then
60 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
61 return
62 fi
63 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Jeff Browne33ba4c2011-07-11 22:11:46 -070064 TARGET_PRODUCT=$1 \
65 TARGET_BUILD_VARIANT= \
66 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070067 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080068 get_build_var TARGET_DEVICE > /dev/null
69 # hide successful answers, but allow the errors to show
70}
71
72VARIANT_CHOICES=(user userdebug eng)
73
74# check to see if the supplied variant is valid
75function check_variant()
76{
77 for v in ${VARIANT_CHOICES[@]}
78 do
79 if [ "$v" = "$1" ]
80 then
81 return 0
82 fi
83 done
84 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070085}
86
87function setpaths()
88{
89 T=$(gettop)
90 if [ ! "$T" ]; then
91 echo "Couldn't locate the top of the tree. Try setting TOP."
92 return
93 fi
94
95 ##################################################################
96 # #
97 # Read me before you modify this code #
98 # #
99 # This function sets ANDROID_BUILD_PATHS to what it is adding #
100 # to PATH, and the next time it is run, it removes that from #
101 # PATH. This is required so lunch can be run more than once #
102 # and still have working paths. #
103 # #
104 ##################################################################
105
Raphael Mollc639c782011-06-20 17:25:01 -0700106 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
107 # due to "C:\Program Files" being in the path.
108
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700109 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700110 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700111 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
112 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700113 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700114 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800115 # strip leading ':', if any
116 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500117 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700118
119 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700120 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)
Colin Cross03b424a2014-05-22 11:57:43 -0700125 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800126 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800127
Raphael Mollc639c782011-06-20 17:25:01 -0700128 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800129 export ANDROID_TOOLCHAIN=
130 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200131 local ARCH=$(get_build_var TARGET_ARCH)
132 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400133 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700134 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400135 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
136 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800137 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200138 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800139 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700140 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700141 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800142 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700143 ;;
Chris Dearman1efd9e42014-02-03 15:01:24 -0800144 mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000145 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200146 *)
147 echo "Can't find toolchain for unknown architecture: $ARCH"
148 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700149 ;;
150 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700151 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800152 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700153 fi
Raphael732936d2011-06-22 14:35:32 -0700154
Ben Chengfba67bf2014-02-25 10:27:07 -0800155 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
156 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
157 fi
158
159 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700160 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700161 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800162 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800163 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700164 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100165 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
166 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700167 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700168 ;;
169 *)
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
Colin Cross6a5fa062014-05-22 11:58:40 -0700176 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200177
178 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
179 # to ensure that the corresponding 'emulator' binaries are used.
180 case $(uname -s) in
181 Darwin)
182 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
183 ;;
184 Linux)
185 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
186 ;;
187 *)
188 ANDROID_EMULATOR_PREBUILTS=
189 ;;
190 esac
191 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700192 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200193 export ANDROID_EMULATOR_PREBUILTS
194 fi
195
Ying Wangaa1c9b52012-11-26 20:51:59 -0800196 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800197
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500198 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900199 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500200 if [ -n "$JAVA_HOME" ]; then
201 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900202 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
203 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500204 fi
205
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800206 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700207 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
208 export OUT=$ANDROID_PRODUCT_OUT
209
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700210 unset ANDROID_HOST_OUT
211 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
212
David 'Digit' Turner7cde0302014-05-05 16:13:50 +0200213 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
214 # to ensure that the corresponding 'emulator' binaries are used.
215 case $(uname -s) in
216 Darwin)
217 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
218 ;;
219 Linux)
220 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
221 ;;
222 *)
223 ANDROID_EMULATOR_PREBUILTS=
224 ;;
225 esac
226 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
227 PATH=$ANDROID_EMULATOR_PREBUILTS:$PATH
228 export ANDROID_EMULATOR_PREBUILTS
229 fi
230
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800231 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700232 # TODO: fix the path
233 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
234}
235
236function printconfig()
237{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800238 T=$(gettop)
239 if [ ! "$T" ]; then
240 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
241 return
242 fi
243 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700244}
245
246function set_stuff_for_environment()
247{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800248 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500249 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800250 setpaths
251 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700252
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800253 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700254 # With this environment variable new GCC can apply colors to warnings/errors
255 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 -0700256}
257
258function set_sequence_number()
259{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700260 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700261}
262
263function settitle()
264{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800265 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700266 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700267 local product=$TARGET_PRODUCT
268 local variant=$TARGET_BUILD_VARIANT
269 local apps=$TARGET_BUILD_APPS
270 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700271 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700272 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700273 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700274 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800275 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700276}
277
Kenny Root52aa81c2011-07-15 11:07:06 -0700278function addcompletions()
279{
280 local T dir f
281
282 # Keep us from trying to run in something that isn't bash.
283 if [ -z "${BASH_VERSION}" ]; then
284 return
285 fi
286
287 # Keep us from trying to run in bash that's too old.
288 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
289 return
290 fi
291
292 dir="sdk/bash_completion"
293 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700294 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700295 echo "including $f"
296 . $f
297 done
298 fi
299}
300
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700301function choosetype()
302{
303 echo "Build type choices are:"
304 echo " 1. release"
305 echo " 2. debug"
306 echo
307
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800308 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700309 DEFAULT_NUM=1
310 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700311
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800312 export TARGET_BUILD_TYPE=
313 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700314 while [ -z $TARGET_BUILD_TYPE ]
315 do
316 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800317 if [ -z "$1" ] ; then
318 read ANSWER
319 else
320 echo $1
321 ANSWER=$1
322 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700323 case $ANSWER in
324 "")
325 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
326 ;;
327 1)
328 export TARGET_BUILD_TYPE=release
329 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800330 release)
331 export TARGET_BUILD_TYPE=release
332 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700333 2)
334 export TARGET_BUILD_TYPE=debug
335 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336 debug)
337 export TARGET_BUILD_TYPE=debug
338 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339 *)
340 echo
341 echo "I didn't understand your response. Please try again."
342 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700343 ;;
344 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800345 if [ -n "$1" ] ; then
346 break
347 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700348 done
349
350 set_stuff_for_environment
351}
352
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800353#
354# This function isn't really right: It chooses a TARGET_PRODUCT
355# based on the list of boards. Usually, that gets you something
356# that kinda works with a generic product, but really, you should
357# pick a product by name.
358#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700359function chooseproduct()
360{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700361 if [ "x$TARGET_PRODUCT" != x ] ; then
362 default_value=$TARGET_PRODUCT
363 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700364 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700365 fi
366
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800367 export TARGET_PRODUCT=
368 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700369 while [ -z "$TARGET_PRODUCT" ]
370 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700371 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800372 if [ -z "$1" ] ; then
373 read ANSWER
374 else
375 echo $1
376 ANSWER=$1
377 fi
378
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700379 if [ -z "$ANSWER" ] ; then
380 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800381 else
382 if check_product $ANSWER
383 then
384 export TARGET_PRODUCT=$ANSWER
385 else
386 echo "** Not a valid product: $ANSWER"
387 fi
388 fi
389 if [ -n "$1" ] ; then
390 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700391 fi
392 done
393
394 set_stuff_for_environment
395}
396
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800397function choosevariant()
398{
399 echo "Variant choices are:"
400 local index=1
401 local v
402 for v in ${VARIANT_CHOICES[@]}
403 do
404 # The product name is the name of the directory containing
405 # the makefile we found, above.
406 echo " $index. $v"
407 index=$(($index+1))
408 done
409
410 local default_value=eng
411 local ANSWER
412
413 export TARGET_BUILD_VARIANT=
414 while [ -z "$TARGET_BUILD_VARIANT" ]
415 do
416 echo -n "Which would you like? [$default_value] "
417 if [ -z "$1" ] ; then
418 read ANSWER
419 else
420 echo $1
421 ANSWER=$1
422 fi
423
424 if [ -z "$ANSWER" ] ; then
425 export TARGET_BUILD_VARIANT=$default_value
426 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
427 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800428 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800429 fi
430 else
431 if check_variant $ANSWER
432 then
433 export TARGET_BUILD_VARIANT=$ANSWER
434 else
435 echo "** Not a valid variant: $ANSWER"
436 fi
437 fi
438 if [ -n "$1" ] ; then
439 break
440 fi
441 done
442}
443
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444function choosecombo()
445{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700446 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700447
448 echo
449 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700450 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700451
452 echo
453 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700454 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800455
456 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700457 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800458 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700459}
460
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800461# Clear this variable. It will be built up again when the vendorsetup.sh
462# files are included at the end of this file.
463unset LUNCH_MENU_CHOICES
464function add_lunch_combo()
465{
466 local new_combo=$1
467 local c
468 for c in ${LUNCH_MENU_CHOICES[@]} ; do
469 if [ "$new_combo" = "$c" ] ; then
470 return
471 fi
472 done
473 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
474}
475
476# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700477add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800478add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000479add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800480add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000481add_lunch_combo aosp_x86-eng
482add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800483add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800484
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700485function print_lunch_menu()
486{
487 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700488 echo
489 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700490 echo
491 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492
493 local i=1
494 local choice
495 for choice in ${LUNCH_MENU_CHOICES[@]}
496 do
497 echo " $i. $choice"
498 i=$(($i+1))
499 done
500
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700501 echo
502}
503
504function lunch()
505{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506 local answer
507
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800509 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700510 else
511 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700512 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800513 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700514 fi
515
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800516 local selection=
517
518 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700519 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700520 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
522 then
523 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
524 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800525 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800526 fi
527 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
528 then
529 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700530 fi
531
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800532 if [ -z "$selection" ]
533 then
534 echo
535 echo "Invalid lunch combo: $answer"
536 return 1
537 fi
538
Joe Onoratoda12daf2010-06-09 18:18:31 -0700539 export TARGET_BUILD_APPS=
540
Jeff Browne33ba4c2011-07-11 22:11:46 -0700541 local product=$(echo -n $selection | sed -e "s/-.*$//")
542 check_product $product
543 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800544 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700545 echo
546 echo "** Don't have a product spec for: '$product'"
547 echo "** Do you have the right repo manifest?"
548 product=
549 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800550
Jeff Browne33ba4c2011-07-11 22:11:46 -0700551 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
552 check_variant $variant
553 if [ $? -ne 0 ]
554 then
555 echo
556 echo "** Invalid variant: '$variant'"
557 echo "** Must be one of ${VARIANT_CHOICES[@]}"
558 variant=
559 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800560
Jeff Browne33ba4c2011-07-11 22:11:46 -0700561 if [ -z "$product" -o -z "$variant" ]
562 then
563 echo
564 return 1
565 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800566
Jeff Browne33ba4c2011-07-11 22:11:46 -0700567 export TARGET_PRODUCT=$product
568 export TARGET_BUILD_VARIANT=$variant
569 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700570
571 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800572
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700573 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800574 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700575}
576
Jeff Davidson513d7a42010-08-02 10:00:44 -0700577# Tab completion for lunch.
578function _lunch()
579{
580 local cur prev opts
581 COMPREPLY=()
582 cur="${COMP_WORDS[COMP_CWORD]}"
583 prev="${COMP_WORDS[COMP_CWORD-1]}"
584
585 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
586 return 0
587}
588complete -F _lunch lunch
589
Joe Onoratoda12daf2010-06-09 18:18:31 -0700590# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700591# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700592function tapas()
593{
Ying Wangb541ab62014-05-29 17:57:40 -0700594 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700595 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Ying Wangb541ab62014-05-29 17:57:40 -0700596 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700597
Ying Wang67f02922012-08-22 10:25:20 -0700598 if [ $(echo $arch | wc -w) -gt 1 ]; then
599 echo "tapas: Error: Multiple build archs supplied: $arch"
600 return
601 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700602 if [ $(echo $variant | wc -w) -gt 1 ]; then
603 echo "tapas: Error: Multiple build variants supplied: $variant"
604 return
605 fi
Ying Wang67f02922012-08-22 10:25:20 -0700606
607 local product=full
608 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700609 x86) product=full_x86;;
610 mips) product=full_mips;;
611 armv5) product=generic_armv5;;
612 arm64) product=aosp_arm64;;
613 x86_64) product=aosp_x86_64;;
614 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700615 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700616 if [ -z "$variant" ]; then
617 variant=eng
618 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700619 if [ -z "$apps" ]; then
620 apps=all
621 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700622
Ying Wang67f02922012-08-22 10:25:20 -0700623 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700624 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700625 export TARGET_BUILD_TYPE=release
626 export TARGET_BUILD_APPS=$apps
627
628 set_stuff_for_environment
629 printconfig
630}
631
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700632function gettop
633{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800634 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700635 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
636 echo $TOP
637 else
638 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800639 # The following circumlocution (repeated below as well) ensures
640 # that we record the true directory name and not one that is
641 # faked up with symlink names.
642 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700643 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800644 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700645 T=
646 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800647 \cd ..
synergyb112a402013-07-05 19:47:47 -0700648 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649 done
Ying Wang9cd17642012-12-13 10:52:07 -0800650 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651 if [ -f "$T/$TOPFILE" ]; then
652 echo $T
653 fi
654 fi
655 fi
656}
657
Andrew Hsieh906cb782013-09-10 17:37:14 +0800658# Return driver for "make", if any (eg. static analyzer)
659function getdriver()
660{
661 local T="$1"
662 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
663 if [ -n "$WITH_STATIC_ANALYZER" ]; then
664 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800665$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
666--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800667--status-bugs \
668--top=$T"
669 fi
670}
671
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672function m()
673{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800674 local T=$(gettop)
675 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700676 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800677 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700678 else
679 echo "Couldn't locate the top of the tree. Try setting TOP."
680 fi
681}
682
683function findmakefile()
684{
685 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800686 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700687 T=
688 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700689 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700690 if [ -f "$T/Android.mk" ]; then
691 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800692 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700693 return
694 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800695 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700696 done
Ying Wang9cd17642012-12-13 10:52:07 -0800697 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700698}
699
700function mm()
701{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800702 local T=$(gettop)
703 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700704 # If we're sitting in the root of the build tree, just do a
705 # normal make.
706 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800707 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700708 else
709 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800710 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700711 local MODULES=
712 local GET_INSTALL_PATH=
713 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700714 # Remove the path to top as the makefilepath needs to be relative
715 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700716 if [ ! "$T" ]; then
717 echo "Couldn't locate the top of the tree. Try setting TOP."
718 elif [ ! "$M" ]; then
719 echo "Couldn't locate a makefile from the current directory."
720 else
Ying Wanga7deb082013-08-16 13:24:47 -0700721 for ARG in $@; do
722 case $ARG in
723 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
724 esac
725 done
726 if [ -n "$GET_INSTALL_PATH" ]; then
727 MODULES=
728 ARGS=GET-INSTALL-PATH
729 else
730 MODULES=all_modules
731 ARGS=$@
732 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700733 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 -0700734 fi
735 fi
736}
737
738function mmm()
739{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800740 local T=$(gettop)
741 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700742 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800743 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800744 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800745 local ARGS=
746 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700747 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800748 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
749 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
750 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800751 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
752 if [ "$MODULES" = "" ]; then
753 MODULES=all_modules
754 fi
755 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700756 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700757 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
758 local TO_CHOP=`expr $TO_CHOP + 1`
759 local START=`PWD= /bin/pwd`
760 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700761 if [ "$MFILE" = "" ] ; then
762 MFILE=$DIR/Android.mk
763 else
764 MFILE=$MFILE/$DIR/Android.mk
765 fi
766 MAKEFILE="$MAKEFILE $MFILE"
767 else
Ying Wanga7deb082013-08-16 13:24:47 -0700768 case $DIR in
769 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
770 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
771 *) echo "No Android.mk in $DIR."; return 1;;
772 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700773 fi
774 done
Ying Wanga7deb082013-08-16 13:24:47 -0700775 if [ -n "$GET_INSTALL_PATH" ]; then
776 ARGS=$GET_INSTALL_PATH
777 MODULES=
778 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800779 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 -0700780 else
781 echo "Couldn't locate the top of the tree. Try setting TOP."
782 fi
783}
784
Ying Wangb607f7b2013-02-08 18:01:04 -0800785function mma()
786{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800787 local T=$(gettop)
788 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800789 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800790 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800791 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800792 if [ ! "$T" ]; then
793 echo "Couldn't locate the top of the tree. Try setting TOP."
794 fi
795 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800796 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800797 fi
798}
799
800function mmma()
801{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800802 local T=$(gettop)
803 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800804 if [ "$T" ]; then
805 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
806 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
807 local MY_PWD=`PWD= /bin/pwd`
808 if [ "$MY_PWD" = "$T" ]; then
809 MY_PWD=
810 else
811 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
812 fi
813 local DIR=
814 local MODULE_PATHS=
815 local ARGS=
816 for DIR in $DIRS ; do
817 if [ -d $DIR ]; then
818 if [ "$MY_PWD" = "" ]; then
819 MODULE_PATHS="$MODULE_PATHS $DIR"
820 else
821 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
822 fi
823 else
824 case $DIR in
825 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
826 *) echo "Couldn't find directory $DIR"; return 1;;
827 esac
828 fi
829 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800830 $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 -0800831 else
832 echo "Couldn't locate the top of the tree. Try setting TOP."
833 fi
834}
835
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700836function croot()
837{
838 T=$(gettop)
839 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800840 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700841 else
842 echo "Couldn't locate the top of the tree. Try setting TOP."
843 fi
844}
845
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700846function cproj()
847{
848 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700849 local HERE=$PWD
850 T=
851 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
852 T=$PWD
853 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800854 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700855 return
856 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800857 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700858 done
Ying Wang9cd17642012-12-13 10:52:07 -0800859 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700860 echo "can't find Android.mk"
861}
862
Daniel Sandler47e0a882013-07-30 13:23:52 -0400863# simplified version of ps; output in the form
864# <pid> <procname>
865function qpid() {
866 local prepend=''
867 local append=''
868 if [ "$1" = "--exact" ]; then
869 prepend=' '
870 append='$'
871 shift
872 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
873 echo "usage: qpid [[--exact] <process name|pid>"
874 return 255
875 fi
876
877 local EXE="$1"
878 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700879 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400880 else
881 adb shell ps \
882 | tr -d '\r' \
883 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
884 fi
885}
886
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700887function pid()
888{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400889 local prepend=''
890 local append=''
891 if [ "$1" = "--exact" ]; then
892 prepend=' '
893 append='$'
894 shift
895 fi
896 local EXE="$1"
897 if [ "$EXE" ] ; then
898 local PID=`adb shell ps \
899 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700900 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400901 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
902 echo "$PID"
903 else
904 echo "usage: pid [--exact] <process name>"
905 return 255
906 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700907}
908
Christopher Tate744ee802009-11-12 15:33:08 -0800909# systemstack - dump the current stack trace of all threads in the system process
910# to the usual ANR traces file
911function systemstack()
912{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800913 stacks system_server
914}
915
916function stacks()
917{
918 if [[ $1 =~ ^[0-9]+$ ]] ; then
919 local PID="$1"
920 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700921 local PIDLIST="$(pid $1)"
922 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
923 local PID="$PIDLIST"
924 elif [ "$PIDLIST" ] ; then
925 echo "more than one process: $1"
926 else
927 echo "no such process: $1"
928 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800929 else
930 echo "usage: stacks [pid|process name]"
931 fi
932
933 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700934 # Determine whether the process is native
935 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
936 # Dump stacks of Dalvik process
937 local TRACES=/data/anr/traces.txt
938 local ORIG=/data/anr/traces.orig
939 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800940
Jeff Brownb12c2e52013-08-19 15:14:16 -0700941 # Keep original traces to avoid clobbering
942 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800943
Jeff Brownb12c2e52013-08-19 15:14:16 -0700944 # Make sure we have a usable file
945 adb shell touch $TRACES
946 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800947
Jeff Brownb12c2e52013-08-19 15:14:16 -0700948 # Dump stacks and wait for dump to finish
949 adb shell kill -3 $PID
950 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800951
Jeff Brownb12c2e52013-08-19 15:14:16 -0700952 # Restore original stacks, and show current output
953 adb shell mv $TRACES $TMP
954 adb shell mv $ORIG $TRACES
955 adb shell cat $TMP
956 else
957 # Dump stacks of native process
958 adb shell debuggerd -b $PID
959 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800960 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800961}
962
John Michelau50200252012-11-09 11:48:04 -0600963function gdbwrapper()
964{
Ben Chengfba67bf2014-02-25 10:27:07 -0800965 local GDB_CMD="$1"
966 shift 1
967 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -0600968}
969
Brigid Smith0a2712d2014-05-28 14:36:43 -0700970function get_symbols_directory()
971{
972 echo $(get_abs_build_var TARGET_OUT_UNSTRIPPED)
973}
974
Ben Chengfba67bf2014-02-25 10:27:07 -0800975# process the symbolic link of /proc/$PID/exe and use the host file tool to
976# determine whether it is a 32-bit or 64-bit executable. It returns "" or "64"
977# which can be conveniently used as suffix.
978function is64bit()
979{
980 local PID="$1"
981 if [ "$PID" ] ; then
Brigid Smith0a2712d2014-05-28 14:36:43 -0700982 local EXE=`adb shell readlink /proc/$PID/exe`
983 local EXE_DIR=`get_abs_build_var PRODUCT_OUT`
984 local IS64BIT=`file "$EXE_DIR$EXE" | grep "64-bit"`
Ben Chengfba67bf2014-02-25 10:27:07 -0800985 if [ "$IS64BIT" != "" ]; then
986 echo "64"
987 else
988 echo ""
989 fi
990 else
991 echo ""
992 fi
993}
994
995# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
996# executable, set up the approriate gdbserver, then invokes the proper host
997# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700998function gdbclient()
999{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001000 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1001 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1002 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
Colin Cross3655a682014-05-22 11:59:10 -07001003 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
Brigid Smith0a2712d2014-05-28 14:36:43 -07001004 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001005 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001006 local ARCH=$(get_build_var TARGET_ARCH)
1007 local GDB
1008 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001009 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -08001010 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -07001011 mips) GDB=mipsel-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +00001012 mips64) GDB=mipsel-linux-android-gdb;;
1013 x86) GDB=x86_64-linux-android-gdb;;
1014 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001015 *) echo "Unknown arch $ARCH"; return 1;;
1016 esac
1017
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001018 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1019 local EXE="$1"
1020 if [ "$EXE" ] ; then
1021 EXE=$1
1022 else
1023 EXE="app_process"
1024 fi
1025
1026 local PORT="$2"
1027 if [ "$PORT" ] ; then
1028 PORT=$2
1029 else
1030 PORT=":5039"
1031 fi
1032
Chris Craik20c136a2012-11-09 18:02:19 -08001033 local PID="$3"
1034 if [ "$PID" ] ; then
1035 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -07001036 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -08001037 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1038 # that likely didn't work because of returning multiple processes
1039 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001040 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001041 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1042 then
1043 echo "Couldn't resolve '$3' to single PID"
1044 return 1
1045 else
1046 echo ""
1047 echo "WARNING: multiple processes matching '$3' observed, using root process"
1048 echo ""
1049 fi
1050 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001051 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001052 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001053 local USE64BIT="$(is64bit $PID)"
1054 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001055 sleep 2
1056 else
1057 echo ""
1058 echo "If you haven't done so already, do this first on the device:"
1059 echo " gdbserver $PORT /system/bin/$EXE"
1060 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001061 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001062 echo ""
1063 fi
1064
Colin Cross84480ad2014-04-10 12:51:39 -07001065 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1066
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001067 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Colin Cross3655a682014-05-22 11:59:10 -07001068 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:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl"
Ben Cheng72398162013-06-24 14:36:21 -07001069 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001070 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1071 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1072
Ben Chengfba67bf2014-02-25 10:27:07 -08001073 local WHICH_GDB=
1074 # 64-bit exe found
1075 if [ "$USE64BIT" != "" ] ; then
1076 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1077 # 32-bit exe / 32-bit platform
1078 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1079 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1080 # 32-bit exe / 64-bit platform
1081 else
1082 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1083 fi
Brigid Smith0a2712d2014-05-28 14:36:43 -07001084
Ben Chengfba67bf2014-02-25 10:27:07 -08001085 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001086 else
1087 echo "Unable to determine build system output dir."
1088 fi
1089
1090}
1091
1092case `uname -s` in
1093 Darwin)
1094 function sgrep()
1095 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001096 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 -07001097 }
1098
1099 ;;
1100 *)
1101 function sgrep()
1102 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001103 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 -07001104 }
1105 ;;
1106esac
1107
Raghu Gandham8da43102012-07-25 19:57:22 -07001108function gettargetarch
1109{
1110 get_build_var TARGET_ARCH
1111}
1112
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001113function ggrep()
1114{
1115 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1116}
1117
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001118function jgrep()
1119{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001120 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 -07001121}
1122
1123function cgrep()
1124{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001125 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 -07001126}
1127
1128function resgrep()
1129{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001130 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 -07001131}
1132
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001133function mangrep()
1134{
1135 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1136}
1137
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001138function sepgrep()
1139{
1140 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 "$@"
1141}
1142
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001143case `uname -s` in
1144 Darwin)
1145 function mgrep()
1146 {
Ying Wang324c2b22012-08-17 15:03:20 -07001147 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 -07001148 }
1149
1150 function treegrep()
1151 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001152 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 -07001153 }
1154
1155 ;;
1156 *)
1157 function mgrep()
1158 {
Ying Wang324c2b22012-08-17 15:03:20 -07001159 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 -07001160 }
1161
1162 function treegrep()
1163 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001164 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 -07001165 }
1166
1167 ;;
1168esac
1169
1170function getprebuilt
1171{
1172 get_abs_build_var ANDROID_PREBUILTS
1173}
1174
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001175function tracedmdump()
1176{
1177 T=$(gettop)
1178 if [ ! "$T" ]; then
1179 echo "Couldn't locate the top of the tree. Try setting TOP."
1180 return
1181 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001182 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001183 local arch=$(gettargetarch)
1184 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001185
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001186 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001187 if [ ! "$TRACE" ] ; then
1188 echo "usage: tracedmdump tracename"
1189 return
1190 fi
1191
Jack Veenstra60116fc2009-04-09 18:12:34 -07001192 if [ ! -r "$KERNEL" ] ; then
1193 echo "Error: cannot find kernel: '$KERNEL'"
1194 return
1195 fi
1196
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001197 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001198 if [ "$BASETRACE" = "$TRACE" ] ; then
1199 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1200 fi
1201
1202 echo "post-processing traces..."
1203 rm -f $TRACE/qtrace.dexlist
1204 post_trace $TRACE
1205 if [ $? -ne 0 ]; then
1206 echo "***"
1207 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1208 echo "***"
1209 return
1210 fi
1211 echo "generating dexlist output..."
1212 /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
1213 echo "generating dmtrace data..."
1214 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1215 echo "generating html file..."
1216 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1217 echo "done, see $TRACE/dmtrace.html for details"
1218 echo "or run:"
1219 echo " traceview $TRACE/dmtrace"
1220}
1221
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001222# communicate with a running device or emulator, set up necessary state,
1223# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001224function runhat()
1225{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001226 # process standard adb options
1227 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001228 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001229 adbTarget=$1
1230 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001231 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001232 adbTarget="$1 $2"
1233 shift 2
1234 fi
1235 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001236 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001237
1238 # runhat options
1239 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001240
1241 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001242 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001243 return
1244 fi
1245
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001246 # confirm hat is available
1247 if [ -z $(which hat) ]; then
1248 echo "hat is not available in this configuration."
1249 return
1250 fi
1251
Andy McFaddenb6289852010-07-12 08:00:19 -07001252 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001253 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001254 local devFile=$sdcard/hprof-$targetPid
1255 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001256 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001257 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001258 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001259 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001260 echo -n "> "
1261 read
1262
The Android Open Source Project88b60792009-03-03 19:28:42 -08001263 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001264
The Android Open Source Project88b60792009-03-03 19:28:42 -08001265 echo "Retrieving file $devFile..."
1266 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001267
The Android Open Source Project88b60792009-03-03 19:28:42 -08001268 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001269
The Android Open Source Project88b60792009-03-03 19:28:42 -08001270 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001271 echo "View the output by pointing your browser at http://localhost:7000/"
1272 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001273 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001274}
1275
1276function getbugreports()
1277{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001278 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001279
1280 if [ ! "$reports" ]; then
1281 echo "Could not locate any bugreports."
1282 return
1283 fi
1284
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001285 local report
1286 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001287 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001288 echo "/sdcard/bugreports/${report}"
1289 adb pull /sdcard/bugreports/${report} ${report}
1290 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001291 done
1292}
1293
Victoria Lease1b296b42012-08-21 15:44:06 -07001294function getsdcardpath()
1295{
1296 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1297}
1298
1299function getscreenshotpath()
1300{
1301 echo "$(getsdcardpath)/Pictures/Screenshots"
1302}
1303
1304function getlastscreenshot()
1305{
1306 local screenshot_path=$(getscreenshotpath)
1307 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1308 if [ "$screenshot" = "" ]; then
1309 echo "No screenshots found."
1310 return
1311 fi
1312 echo "${screenshot}"
1313 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1314}
1315
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001316function startviewserver()
1317{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001318 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001319 if [ $# -gt 0 ]; then
1320 port=$1
1321 fi
1322 adb shell service call window 1 i32 $port
1323}
1324
1325function stopviewserver()
1326{
1327 adb shell service call window 2
1328}
1329
1330function isviewserverstarted()
1331{
1332 adb shell service call window 3
1333}
1334
Romain Guyb84049a2010-10-04 16:56:11 -07001335function key_home()
1336{
1337 adb shell input keyevent 3
1338}
1339
1340function key_back()
1341{
1342 adb shell input keyevent 4
1343}
1344
1345function key_menu()
1346{
1347 adb shell input keyevent 82
1348}
1349
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001350function smoketest()
1351{
1352 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1353 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1354 return
1355 fi
1356 T=$(gettop)
1357 if [ ! "$T" ]; then
1358 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1359 return
1360 fi
1361
Ying Wang9cd17642012-12-13 10:52:07 -08001362 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001363 adb uninstall com.android.smoketest > /dev/null &&
1364 adb uninstall com.android.smoketest.tests > /dev/null &&
1365 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1366 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1367 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1368}
1369
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001370# simple shortcut to the runtest command
1371function runtest()
1372{
1373 T=$(gettop)
1374 if [ ! "$T" ]; then
1375 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1376 return
1377 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001378 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001379}
1380
The Android Open Source Project88b60792009-03-03 19:28:42 -08001381function godir () {
1382 if [[ -z "$1" ]]; then
1383 echo "Usage: godir <regex>"
1384 return
1385 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001386 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001387 if [[ ! -f $T/filelist ]]; then
1388 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001389 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001390 echo " Done"
1391 echo ""
1392 fi
1393 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001394 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001395 if [[ ${#lines[@]} = 0 ]]; then
1396 echo "Not found"
1397 return
1398 fi
1399 local pathname
1400 local choice
1401 if [[ ${#lines[@]} > 1 ]]; then
1402 while [[ -z "$pathname" ]]; do
1403 local index=1
1404 local line
1405 for line in ${lines[@]}; do
1406 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001407 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001408 done
1409 echo
1410 echo -n "Select one: "
1411 unset choice
1412 read choice
1413 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1414 echo "Invalid choice"
1415 continue
1416 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001417 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001418 done
1419 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001420 pathname=${lines[0]}
1421 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001422 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001423}
1424
Narayan Kamath9260bba2014-01-17 10:05:25 +00001425# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1426#
1427# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1428# For some reason, installing the JDK doesn't make it show up in the
1429# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001430function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001431 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001432 # we can reset it later, depending on the version of java the build
1433 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001434 #
1435 # If we don't do this, the JAVA_HOME value set by the first call to
1436 # build/envsetup.sh will persist forever.
1437 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1438 export JAVA_HOME=""
1439 fi
1440
Andy McFaddenbd960942010-06-24 12:52:51 -07001441 if [ ! "$JAVA_HOME" ]; then
Narayan Kamathc84889b2014-04-01 14:16:26 +01001442 if [ -n "$LEGACY_USE_JAVA6" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001443 case `uname -s` in
1444 Darwin)
1445 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1446 ;;
1447 *)
1448 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1449 ;;
1450 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001451 else
1452 case `uname -s` in
1453 Darwin)
Jason Parks13b2e192014-04-28 13:32:10 -05001454 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
Narayan Kamath9260bba2014-01-17 10:05:25 +00001455 ;;
1456 *)
1457 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1458 ;;
1459 esac
1460 fi
1461
1462 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1463 # we can change it on the next envsetup.sh, if required.
1464 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001465 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001466}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001467
Alex Rayf0d08eb2013-03-08 15:15:06 -08001468# Print colored exit condition
1469function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001470 "$@"
1471 local retval=$?
1472 if [ $retval -ne 0 ]
1473 then
1474 echo -e "\e[0;31mFAILURE\e[00m"
1475 else
1476 echo -e "\e[0;32mSUCCESS\e[00m"
1477 fi
1478 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001479}
1480
Ed Heylcc6be0a2014-06-18 14:55:58 -07001481function make()
1482{
1483 local start_time=$(date +"%s")
1484 $MAKE_UTIL $@
1485 local ret=$?
1486 local end_time=$(date +"%s")
1487 local tdiff=$(($end_time-$start_time))
1488 local hours=$(($tdiff / 3600 ))
1489 local mins=$((($tdiff % 3600) / 60))
1490 local secs=$(($tdiff % 60))
1491 echo
1492 if [ $ret -eq 0 ] ; then
1493 echo -n -e "\e[0;32m#### make completed successfully "
1494 else
1495 echo -n -e "\e[0;31m#### make failed to build some targets "
1496 fi
1497 if [ $hours -gt 0 ] ; then
1498 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1499 elif [ $mins -gt 0 ] ; then
1500 printf "(%02g:%02g (mm:ss))" $mins $secs
1501 elif [ $secs -gt 0 ] ; then
1502 printf "(%s seconds)" $secs
1503 fi
1504 echo -e " ####\e[00m"
1505 echo
1506 return $ret
1507}
1508
1509
1510
Raphael Moll70a86b02011-06-20 16:03:14 -07001511if [ "x$SHELL" != "x/bin/bash" ]; then
1512 case `ps -o command -p $$` in
1513 *bash*)
1514 ;;
1515 *)
1516 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1517 ;;
1518 esac
1519fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001520
1521# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001522for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1523 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001524do
1525 echo "including $f"
1526 . $f
1527done
1528unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001529
1530addcompletions