blob: da7b6b3299aba6d9a41c5b6e6c6043825ae34eac [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 Wangb541ab62014-05-29 17:57:40 -07005- 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 -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.
Jeff Brown46cbd202014-07-26 15:15:41 -070017- sgrep: Greps on all local source 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=""
Jeff Brown46cbd202014-07-26 15:15:41 -070025 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070026 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 Heylc6d11f82014-06-27 13:32:39 -070040 command make --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 Heylc6d11f82014-06-27 13:32:39 -070052 command make --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
Jeff Browne33ba4c2011-07-11 22:11:46 -070063 TARGET_PRODUCT=$1 \
64 TARGET_BUILD_VARIANT= \
65 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070066 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080067 get_build_var TARGET_DEVICE > /dev/null
68 # hide successful answers, but allow the errors to show
69}
70
71VARIANT_CHOICES=(user userdebug eng)
72
73# check to see if the supplied variant is valid
74function check_variant()
75{
76 for v in ${VARIANT_CHOICES[@]}
77 do
78 if [ "$v" = "$1" ]
79 then
80 return 0
81 fi
82 done
83 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070084}
85
86function setpaths()
87{
88 T=$(gettop)
89 if [ ! "$T" ]; then
90 echo "Couldn't locate the top of the tree. Try setting TOP."
91 return
92 fi
93
94 ##################################################################
95 # #
96 # Read me before you modify this code #
97 # #
98 # This function sets ANDROID_BUILD_PATHS to what it is adding #
99 # to PATH, and the next time it is run, it removes that from #
100 # PATH. This is required so lunch can be run more than once #
101 # and still have working paths. #
102 # #
103 ##################################################################
104
Raphael Mollc639c782011-06-20 17:25:01 -0700105 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
106 # due to "C:\Program Files" being in the path.
107
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700108 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700109 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700110 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
111 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700112 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700113 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800114 # strip leading ':', if any
115 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500116 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700117
118 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700119 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700120 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700121
Ben Cheng8bc4c432012-11-16 13:29:13 -0800122 # defined in core/config.mk
123 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700124 targetgccversion2=$(get_build_var 2ND_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;
Colin Cross03b424a2014-05-22 11:57:43 -0700139 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/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
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100164 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
165 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700166 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700167 ;;
168 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700169 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700170 ;;
171 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700172
Ying Wang564f9122013-03-29 17:40:14 -0700173 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wang2a859d52014-06-30 10:25:33 -0700174 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200175
176 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
177 # to ensure that the corresponding 'emulator' binaries are used.
178 case $(uname -s) in
179 Darwin)
180 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
181 ;;
182 Linux)
183 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
184 ;;
185 *)
186 ANDROID_EMULATOR_PREBUILTS=
187 ;;
188 esac
189 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700190 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200191 export ANDROID_EMULATOR_PREBUILTS
192 fi
193
Ying Wangaa1c9b52012-11-26 20:51:59 -0800194 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800195
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500196 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900197 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500198 if [ -n "$JAVA_HOME" ]; then
199 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900200 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
201 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500202 fi
203
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800204 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700205 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
206 export OUT=$ANDROID_PRODUCT_OUT
207
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700208 unset ANDROID_HOST_OUT
209 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
210
David 'Digit' Turner7cde0302014-05-05 16:13:50 +0200211 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
212 # to ensure that the corresponding 'emulator' binaries are used.
213 case $(uname -s) in
214 Darwin)
215 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
216 ;;
217 Linux)
218 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
219 ;;
220 *)
221 ANDROID_EMULATOR_PREBUILTS=
222 ;;
223 esac
224 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
225 PATH=$ANDROID_EMULATOR_PREBUILTS:$PATH
226 export ANDROID_EMULATOR_PREBUILTS
227 fi
228
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800229 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700230 # TODO: fix the path
231 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
232}
233
234function printconfig()
235{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800236 T=$(gettop)
237 if [ ! "$T" ]; then
238 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
239 return
240 fi
241 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700242}
243
244function set_stuff_for_environment()
245{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800246 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500247 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800248 setpaths
249 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700250
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700252 # With this environment variable new GCC can apply colors to warnings/errors
253 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700254}
255
256function set_sequence_number()
257{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700258 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700259}
260
261function settitle()
262{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800263 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700264 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700265 local product=$TARGET_PRODUCT
266 local variant=$TARGET_BUILD_VARIANT
267 local apps=$TARGET_BUILD_APPS
268 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700269 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700270 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700271 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700272 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800273 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700274}
275
Kenny Root52aa81c2011-07-15 11:07:06 -0700276function addcompletions()
277{
278 local T dir f
279
280 # Keep us from trying to run in something that isn't bash.
281 if [ -z "${BASH_VERSION}" ]; then
282 return
283 fi
284
285 # Keep us from trying to run in bash that's too old.
286 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
287 return
288 fi
289
290 dir="sdk/bash_completion"
291 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700292 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700293 echo "including $f"
294 . $f
295 done
296 fi
297}
298
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700299function choosetype()
300{
301 echo "Build type choices are:"
302 echo " 1. release"
303 echo " 2. debug"
304 echo
305
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800306 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700307 DEFAULT_NUM=1
308 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800310 export TARGET_BUILD_TYPE=
311 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700312 while [ -z $TARGET_BUILD_TYPE ]
313 do
314 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800315 if [ -z "$1" ] ; then
316 read ANSWER
317 else
318 echo $1
319 ANSWER=$1
320 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321 case $ANSWER in
322 "")
323 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
324 ;;
325 1)
326 export TARGET_BUILD_TYPE=release
327 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800328 release)
329 export TARGET_BUILD_TYPE=release
330 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700331 2)
332 export TARGET_BUILD_TYPE=debug
333 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800334 debug)
335 export TARGET_BUILD_TYPE=debug
336 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700337 *)
338 echo
339 echo "I didn't understand your response. Please try again."
340 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700341 ;;
342 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800343 if [ -n "$1" ] ; then
344 break
345 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346 done
347
348 set_stuff_for_environment
349}
350
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800351#
352# This function isn't really right: It chooses a TARGET_PRODUCT
353# based on the list of boards. Usually, that gets you something
354# that kinda works with a generic product, but really, you should
355# pick a product by name.
356#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700357function chooseproduct()
358{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700359 if [ "x$TARGET_PRODUCT" != x ] ; then
360 default_value=$TARGET_PRODUCT
361 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700362 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700363 fi
364
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800365 export TARGET_PRODUCT=
366 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700367 while [ -z "$TARGET_PRODUCT" ]
368 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700369 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800370 if [ -z "$1" ] ; then
371 read ANSWER
372 else
373 echo $1
374 ANSWER=$1
375 fi
376
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700377 if [ -z "$ANSWER" ] ; then
378 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800379 else
380 if check_product $ANSWER
381 then
382 export TARGET_PRODUCT=$ANSWER
383 else
384 echo "** Not a valid product: $ANSWER"
385 fi
386 fi
387 if [ -n "$1" ] ; then
388 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700389 fi
390 done
391
392 set_stuff_for_environment
393}
394
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800395function choosevariant()
396{
397 echo "Variant choices are:"
398 local index=1
399 local v
400 for v in ${VARIANT_CHOICES[@]}
401 do
402 # The product name is the name of the directory containing
403 # the makefile we found, above.
404 echo " $index. $v"
405 index=$(($index+1))
406 done
407
408 local default_value=eng
409 local ANSWER
410
411 export TARGET_BUILD_VARIANT=
412 while [ -z "$TARGET_BUILD_VARIANT" ]
413 do
414 echo -n "Which would you like? [$default_value] "
415 if [ -z "$1" ] ; then
416 read ANSWER
417 else
418 echo $1
419 ANSWER=$1
420 fi
421
422 if [ -z "$ANSWER" ] ; then
423 export TARGET_BUILD_VARIANT=$default_value
424 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
425 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800426 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800427 fi
428 else
429 if check_variant $ANSWER
430 then
431 export TARGET_BUILD_VARIANT=$ANSWER
432 else
433 echo "** Not a valid variant: $ANSWER"
434 fi
435 fi
436 if [ -n "$1" ] ; then
437 break
438 fi
439 done
440}
441
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700442function choosecombo()
443{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700444 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700445
446 echo
447 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700448 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449
450 echo
451 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700452 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800453
454 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700455 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800456 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700457}
458
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800459# Clear this variable. It will be built up again when the vendorsetup.sh
460# files are included at the end of this file.
461unset LUNCH_MENU_CHOICES
462function add_lunch_combo()
463{
464 local new_combo=$1
465 local c
466 for c in ${LUNCH_MENU_CHOICES[@]} ; do
467 if [ "$new_combo" = "$c" ] ; then
468 return
469 fi
470 done
471 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
472}
473
474# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700475add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800476add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000477add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800478add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000479add_lunch_combo aosp_x86-eng
480add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800481add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483function print_lunch_menu()
484{
485 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486 echo
487 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700488 echo
489 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490
491 local i=1
492 local choice
493 for choice in ${LUNCH_MENU_CHOICES[@]}
494 do
495 echo " $i. $choice"
496 i=$(($i+1))
497 done
498
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700499 echo
500}
501
502function lunch()
503{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 local answer
505
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 else
509 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700510 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700512 fi
513
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800514 local selection=
515
516 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700517 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700518 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800519 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
520 then
521 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
522 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800523 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800524 fi
525 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
526 then
527 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700528 fi
529
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530 if [ -z "$selection" ]
531 then
532 echo
533 echo "Invalid lunch combo: $answer"
534 return 1
535 fi
536
Joe Onoratoda12daf2010-06-09 18:18:31 -0700537 export TARGET_BUILD_APPS=
538
Jeff Browne33ba4c2011-07-11 22:11:46 -0700539 local product=$(echo -n $selection | sed -e "s/-.*$//")
540 check_product $product
541 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800542 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700543 echo
544 echo "** Don't have a product spec for: '$product'"
545 echo "** Do you have the right repo manifest?"
546 product=
547 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800548
Jeff Browne33ba4c2011-07-11 22:11:46 -0700549 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
550 check_variant $variant
551 if [ $? -ne 0 ]
552 then
553 echo
554 echo "** Invalid variant: '$variant'"
555 echo "** Must be one of ${VARIANT_CHOICES[@]}"
556 variant=
557 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800558
Jeff Browne33ba4c2011-07-11 22:11:46 -0700559 if [ -z "$product" -o -z "$variant" ]
560 then
561 echo
562 return 1
563 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800564
Jeff Browne33ba4c2011-07-11 22:11:46 -0700565 export TARGET_PRODUCT=$product
566 export TARGET_BUILD_VARIANT=$variant
567 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700568
569 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800570
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700571 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800572 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700573}
574
Jeff Davidson513d7a42010-08-02 10:00:44 -0700575# Tab completion for lunch.
576function _lunch()
577{
578 local cur prev opts
579 COMPREPLY=()
580 cur="${COMP_WORDS[COMP_CWORD]}"
581 prev="${COMP_WORDS[COMP_CWORD-1]}"
582
583 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
584 return 0
585}
586complete -F _lunch lunch
587
Joe Onoratoda12daf2010-06-09 18:18:31 -0700588# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700589# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700590function tapas()
591{
Ying Wangb541ab62014-05-29 17:57:40 -0700592 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 -0700593 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Ying Wangb541ab62014-05-29 17:57:40 -0700594 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 -0700595
Ying Wang67f02922012-08-22 10:25:20 -0700596 if [ $(echo $arch | wc -w) -gt 1 ]; then
597 echo "tapas: Error: Multiple build archs supplied: $arch"
598 return
599 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700600 if [ $(echo $variant | wc -w) -gt 1 ]; then
601 echo "tapas: Error: Multiple build variants supplied: $variant"
602 return
603 fi
Ying Wang67f02922012-08-22 10:25:20 -0700604
605 local product=full
606 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700607 x86) product=full_x86;;
608 mips) product=full_mips;;
609 armv5) product=generic_armv5;;
610 arm64) product=aosp_arm64;;
611 x86_64) product=aosp_x86_64;;
612 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700613 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700614 if [ -z "$variant" ]; then
615 variant=eng
616 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700617 if [ -z "$apps" ]; then
618 apps=all
619 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700620
Ying Wang67f02922012-08-22 10:25:20 -0700621 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700622 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700623 export TARGET_BUILD_TYPE=release
624 export TARGET_BUILD_APPS=$apps
625
626 set_stuff_for_environment
627 printconfig
628}
629
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700630function gettop
631{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800632 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700633 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
634 echo $TOP
635 else
636 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800637 # The following circumlocution (repeated below as well) ensures
638 # that we record the true directory name and not one that is
639 # faked up with symlink names.
640 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700641 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800642 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700643 T=
644 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800645 \cd ..
synergyb112a402013-07-05 19:47:47 -0700646 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700647 done
Ying Wang9cd17642012-12-13 10:52:07 -0800648 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649 if [ -f "$T/$TOPFILE" ]; then
650 echo $T
651 fi
652 fi
653 fi
654}
655
Andrew Hsieh906cb782013-09-10 17:37:14 +0800656# Return driver for "make", if any (eg. static analyzer)
657function getdriver()
658{
659 local T="$1"
660 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
661 if [ -n "$WITH_STATIC_ANALYZER" ]; then
662 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800663$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
664--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800665--status-bugs \
666--top=$T"
667 fi
668}
669
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700670function m()
671{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800672 local T=$(gettop)
673 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700674 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800675 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700676 else
677 echo "Couldn't locate the top of the tree. Try setting TOP."
678 fi
679}
680
681function findmakefile()
682{
683 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800684 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700685 T=
686 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700687 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700688 if [ -f "$T/Android.mk" ]; then
689 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800690 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700691 return
692 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800693 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700694 done
Ying Wang9cd17642012-12-13 10:52:07 -0800695 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700696}
697
698function mm()
699{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800700 local T=$(gettop)
701 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700702 # If we're sitting in the root of the build tree, just do a
703 # normal make.
704 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800705 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700706 else
707 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800708 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700709 local MODULES=
710 local GET_INSTALL_PATH=
711 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700712 # Remove the path to top as the makefilepath needs to be relative
713 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700714 if [ ! "$T" ]; then
715 echo "Couldn't locate the top of the tree. Try setting TOP."
716 elif [ ! "$M" ]; then
717 echo "Couldn't locate a makefile from the current directory."
718 else
Ying Wanga7deb082013-08-16 13:24:47 -0700719 for ARG in $@; do
720 case $ARG in
721 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
722 esac
723 done
724 if [ -n "$GET_INSTALL_PATH" ]; then
725 MODULES=
726 ARGS=GET-INSTALL-PATH
727 else
728 MODULES=all_modules
729 ARGS=$@
730 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700731 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 -0700732 fi
733 fi
734}
735
736function mmm()
737{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800738 local T=$(gettop)
739 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700740 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800741 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800742 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800743 local ARGS=
744 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700745 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800746 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
747 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
748 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800749 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
750 if [ "$MODULES" = "" ]; then
751 MODULES=all_modules
752 fi
753 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700754 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700755 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
756 local TO_CHOP=`expr $TO_CHOP + 1`
757 local START=`PWD= /bin/pwd`
758 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700759 if [ "$MFILE" = "" ] ; then
760 MFILE=$DIR/Android.mk
761 else
762 MFILE=$MFILE/$DIR/Android.mk
763 fi
764 MAKEFILE="$MAKEFILE $MFILE"
765 else
Ying Wanga7deb082013-08-16 13:24:47 -0700766 case $DIR in
767 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
768 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
769 *) echo "No Android.mk in $DIR."; return 1;;
770 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700771 fi
772 done
Ying Wanga7deb082013-08-16 13:24:47 -0700773 if [ -n "$GET_INSTALL_PATH" ]; then
774 ARGS=$GET_INSTALL_PATH
775 MODULES=
776 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800777 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 -0700778 else
779 echo "Couldn't locate the top of the tree. Try setting TOP."
780 fi
781}
782
Ying Wangb607f7b2013-02-08 18:01:04 -0800783function mma()
784{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800785 local T=$(gettop)
786 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800787 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800788 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800789 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800790 if [ ! "$T" ]; then
791 echo "Couldn't locate the top of the tree. Try setting TOP."
792 fi
793 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800794 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800795 fi
796}
797
798function mmma()
799{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800800 local T=$(gettop)
801 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800802 if [ "$T" ]; then
803 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
804 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
805 local MY_PWD=`PWD= /bin/pwd`
806 if [ "$MY_PWD" = "$T" ]; then
807 MY_PWD=
808 else
809 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
810 fi
811 local DIR=
812 local MODULE_PATHS=
813 local ARGS=
814 for DIR in $DIRS ; do
815 if [ -d $DIR ]; then
816 if [ "$MY_PWD" = "" ]; then
817 MODULE_PATHS="$MODULE_PATHS $DIR"
818 else
819 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
820 fi
821 else
822 case $DIR in
823 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
824 *) echo "Couldn't find directory $DIR"; return 1;;
825 esac
826 fi
827 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800828 $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 -0800829 else
830 echo "Couldn't locate the top of the tree. Try setting TOP."
831 fi
832}
833
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700834function croot()
835{
836 T=$(gettop)
837 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800838 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839 else
840 echo "Couldn't locate the top of the tree. Try setting TOP."
841 fi
842}
843
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700844function cproj()
845{
846 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700847 local HERE=$PWD
848 T=
849 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
850 T=$PWD
851 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800852 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700853 return
854 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800855 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700856 done
Ying Wang9cd17642012-12-13 10:52:07 -0800857 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700858 echo "can't find Android.mk"
859}
860
Daniel Sandler47e0a882013-07-30 13:23:52 -0400861# simplified version of ps; output in the form
862# <pid> <procname>
863function qpid() {
864 local prepend=''
865 local append=''
866 if [ "$1" = "--exact" ]; then
867 prepend=' '
868 append='$'
869 shift
870 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
871 echo "usage: qpid [[--exact] <process name|pid>"
872 return 255
873 fi
874
875 local EXE="$1"
876 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700877 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400878 else
879 adb shell ps \
880 | tr -d '\r' \
881 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
882 fi
883}
884
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700885function pid()
886{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400887 local prepend=''
888 local append=''
889 if [ "$1" = "--exact" ]; then
890 prepend=' '
891 append='$'
892 shift
893 fi
894 local EXE="$1"
895 if [ "$EXE" ] ; then
896 local PID=`adb shell ps \
897 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700898 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400899 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
900 echo "$PID"
901 else
902 echo "usage: pid [--exact] <process name>"
903 return 255
904 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700905}
906
Christopher Tate744ee802009-11-12 15:33:08 -0800907# systemstack - dump the current stack trace of all threads in the system process
908# to the usual ANR traces file
909function systemstack()
910{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800911 stacks system_server
912}
913
914function stacks()
915{
916 if [[ $1 =~ ^[0-9]+$ ]] ; then
917 local PID="$1"
918 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700919 local PIDLIST="$(pid $1)"
920 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
921 local PID="$PIDLIST"
922 elif [ "$PIDLIST" ] ; then
923 echo "more than one process: $1"
924 else
925 echo "no such process: $1"
926 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800927 else
928 echo "usage: stacks [pid|process name]"
929 fi
930
931 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700932 # Determine whether the process is native
933 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
934 # Dump stacks of Dalvik process
935 local TRACES=/data/anr/traces.txt
936 local ORIG=/data/anr/traces.orig
937 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800938
Jeff Brownb12c2e52013-08-19 15:14:16 -0700939 # Keep original traces to avoid clobbering
940 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800941
Jeff Brownb12c2e52013-08-19 15:14:16 -0700942 # Make sure we have a usable file
943 adb shell touch $TRACES
944 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800945
Jeff Brownb12c2e52013-08-19 15:14:16 -0700946 # Dump stacks and wait for dump to finish
947 adb shell kill -3 $PID
948 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800949
Jeff Brownb12c2e52013-08-19 15:14:16 -0700950 # Restore original stacks, and show current output
951 adb shell mv $TRACES $TMP
952 adb shell mv $ORIG $TRACES
953 adb shell cat $TMP
954 else
955 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -0700956 local USE64BIT="$(is64bit $PID)"
957 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -0700958 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800959 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800960}
961
John Michelau50200252012-11-09 11:48:04 -0600962function gdbwrapper()
963{
Ben Chengfba67bf2014-02-25 10:27:07 -0800964 local GDB_CMD="$1"
965 shift 1
966 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -0600967}
968
Brigid Smith0a2712d2014-05-28 14:36:43 -0700969function get_symbols_directory()
970{
971 echo $(get_abs_build_var TARGET_OUT_UNSTRIPPED)
972}
973
Michael Wrightaeed7212014-06-19 19:58:12 -0700974# Read the ELF header from /proc/$PID/exe to determine if the process is
975# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -0800976function is64bit()
977{
978 local PID="$1"
979 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -0700980 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800981 echo "64"
982 else
983 echo ""
984 fi
985 else
986 echo ""
987 fi
988}
989
990# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
991# executable, set up the approriate gdbserver, then invokes the proper host
992# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700993function gdbclient()
994{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800995 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
996 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
997 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
Colin Cross3655a682014-05-22 11:59:10 -0700998 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
Brigid Smith0a2712d2014-05-28 14:36:43 -0700999 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001000 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001001 local ARCH=$(get_build_var TARGET_ARCH)
1002 local GDB
1003 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001004 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -08001005 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -07001006 mips) GDB=mipsel-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +00001007 mips64) GDB=mipsel-linux-android-gdb;;
1008 x86) GDB=x86_64-linux-android-gdb;;
1009 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001010 *) echo "Unknown arch $ARCH"; return 1;;
1011 esac
1012
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001013 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1014 local EXE="$1"
1015 if [ "$EXE" ] ; then
1016 EXE=$1
Brigid Smith7a569a62014-06-20 14:12:12 -07001017 if [[ $EXE =~ ^[^/].* ]] ; then
1018 EXE="system/bin/"$EXE
1019 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001020 else
1021 EXE="app_process"
1022 fi
1023
1024 local PORT="$2"
1025 if [ "$PORT" ] ; then
1026 PORT=$2
1027 else
1028 PORT=":5039"
1029 fi
1030
Chris Craik20c136a2012-11-09 18:02:19 -08001031 local PID="$3"
1032 if [ "$PID" ] ; then
1033 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -07001034 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -08001035 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1036 # that likely didn't work because of returning multiple processes
1037 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001038 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001039 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1040 then
1041 echo "Couldn't resolve '$3' to single PID"
1042 return 1
1043 else
1044 echo ""
1045 echo "WARNING: multiple processes matching '$3' observed, using root process"
1046 echo ""
1047 fi
1048 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001049 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001050 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001051 local USE64BIT="$(is64bit $PID)"
1052 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001053 sleep 2
1054 else
1055 echo ""
1056 echo "If you haven't done so already, do this first on the device:"
1057 echo " gdbserver $PORT /system/bin/$EXE"
1058 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001059 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001060 echo ""
1061 fi
1062
Colin Cross84480ad2014-04-10 12:51:39 -07001063 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
Colin Crossa58f8e02014-06-20 13:33:36 -07001064 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
Colin Cross84480ad2014-04-10 12:51:39 -07001065
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001066 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Colin Cross3655a682014-05-22 11:59:10 -07001067 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 -07001068 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001069 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1070 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1071
Ben Chengfba67bf2014-02-25 10:27:07 -08001072 local WHICH_GDB=
1073 # 64-bit exe found
1074 if [ "$USE64BIT" != "" ] ; then
1075 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1076 # 32-bit exe / 32-bit platform
1077 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1078 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1079 # 32-bit exe / 64-bit platform
1080 else
1081 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1082 fi
Brigid Smith0a2712d2014-05-28 14:36:43 -07001083
Ben Chengfba67bf2014-02-25 10:27:07 -08001084 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001085 else
1086 echo "Unable to determine build system output dir."
1087 fi
1088
1089}
1090
1091case `uname -s` in
1092 Darwin)
1093 function sgrep()
1094 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001095 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001096 }
1097
1098 ;;
1099 *)
1100 function sgrep()
1101 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001102 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001103 }
1104 ;;
1105esac
1106
Raghu Gandham8da43102012-07-25 19:57:22 -07001107function gettargetarch
1108{
1109 get_build_var TARGET_ARCH
1110}
1111
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001112function ggrep()
1113{
1114 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1115}
1116
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001117function jgrep()
1118{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001119 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 -07001120}
1121
1122function cgrep()
1123{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001124 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 -07001125}
1126
1127function resgrep()
1128{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001129 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 -07001130}
1131
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001132function mangrep()
1133{
1134 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1135}
1136
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001137function sepgrep()
1138{
1139 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 "$@"
1140}
1141
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001142case `uname -s` in
1143 Darwin)
1144 function mgrep()
1145 {
Ying Wang324c2b22012-08-17 15:03:20 -07001146 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 -07001147 }
1148
1149 function treegrep()
1150 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001151 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 -07001152 }
1153
1154 ;;
1155 *)
1156 function mgrep()
1157 {
Ying Wang324c2b22012-08-17 15:03:20 -07001158 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 -07001159 }
1160
1161 function treegrep()
1162 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001163 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 -07001164 }
1165
1166 ;;
1167esac
1168
1169function getprebuilt
1170{
1171 get_abs_build_var ANDROID_PREBUILTS
1172}
1173
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001174function tracedmdump()
1175{
1176 T=$(gettop)
1177 if [ ! "$T" ]; then
1178 echo "Couldn't locate the top of the tree. Try setting TOP."
1179 return
1180 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001181 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001182 local arch=$(gettargetarch)
1183 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001184
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001185 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001186 if [ ! "$TRACE" ] ; then
1187 echo "usage: tracedmdump tracename"
1188 return
1189 fi
1190
Jack Veenstra60116fc2009-04-09 18:12:34 -07001191 if [ ! -r "$KERNEL" ] ; then
1192 echo "Error: cannot find kernel: '$KERNEL'"
1193 return
1194 fi
1195
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001196 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001197 if [ "$BASETRACE" = "$TRACE" ] ; then
1198 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1199 fi
1200
1201 echo "post-processing traces..."
1202 rm -f $TRACE/qtrace.dexlist
1203 post_trace $TRACE
1204 if [ $? -ne 0 ]; then
1205 echo "***"
1206 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1207 echo "***"
1208 return
1209 fi
1210 echo "generating dexlist output..."
1211 /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
1212 echo "generating dmtrace data..."
1213 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1214 echo "generating html file..."
1215 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1216 echo "done, see $TRACE/dmtrace.html for details"
1217 echo "or run:"
1218 echo " traceview $TRACE/dmtrace"
1219}
1220
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001221# communicate with a running device or emulator, set up necessary state,
1222# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001223function runhat()
1224{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001225 # process standard adb options
1226 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001227 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001228 adbTarget=$1
1229 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001230 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001231 adbTarget="$1 $2"
1232 shift 2
1233 fi
1234 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001235 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001236
1237 # runhat options
1238 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001239
1240 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001241 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001242 return
1243 fi
1244
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001245 # confirm hat is available
1246 if [ -z $(which hat) ]; then
1247 echo "hat is not available in this configuration."
1248 return
1249 fi
1250
Andy McFaddenb6289852010-07-12 08:00:19 -07001251 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001252 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001253 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001254 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001255 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001256 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001257 echo -n "> "
1258 read
1259
The Android Open Source Project88b60792009-03-03 19:28:42 -08001260 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001261
The Android Open Source Project88b60792009-03-03 19:28:42 -08001262 echo "Retrieving file $devFile..."
1263 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001264
The Android Open Source Project88b60792009-03-03 19:28:42 -08001265 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001266
The Android Open Source Project88b60792009-03-03 19:28:42 -08001267 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001268 echo "View the output by pointing your browser at http://localhost:7000/"
1269 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001270 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001271}
1272
1273function getbugreports()
1274{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001275 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001276
1277 if [ ! "$reports" ]; then
1278 echo "Could not locate any bugreports."
1279 return
1280 fi
1281
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001282 local report
1283 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001284 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001285 echo "/sdcard/bugreports/${report}"
1286 adb pull /sdcard/bugreports/${report} ${report}
1287 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001288 done
1289}
1290
Victoria Lease1b296b42012-08-21 15:44:06 -07001291function getsdcardpath()
1292{
1293 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1294}
1295
1296function getscreenshotpath()
1297{
1298 echo "$(getsdcardpath)/Pictures/Screenshots"
1299}
1300
1301function getlastscreenshot()
1302{
1303 local screenshot_path=$(getscreenshotpath)
1304 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1305 if [ "$screenshot" = "" ]; then
1306 echo "No screenshots found."
1307 return
1308 fi
1309 echo "${screenshot}"
1310 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1311}
1312
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001313function startviewserver()
1314{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001315 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001316 if [ $# -gt 0 ]; then
1317 port=$1
1318 fi
1319 adb shell service call window 1 i32 $port
1320}
1321
1322function stopviewserver()
1323{
1324 adb shell service call window 2
1325}
1326
1327function isviewserverstarted()
1328{
1329 adb shell service call window 3
1330}
1331
Romain Guyb84049a2010-10-04 16:56:11 -07001332function key_home()
1333{
1334 adb shell input keyevent 3
1335}
1336
1337function key_back()
1338{
1339 adb shell input keyevent 4
1340}
1341
1342function key_menu()
1343{
1344 adb shell input keyevent 82
1345}
1346
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001347function smoketest()
1348{
1349 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1350 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1351 return
1352 fi
1353 T=$(gettop)
1354 if [ ! "$T" ]; then
1355 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1356 return
1357 fi
1358
Ying Wang9cd17642012-12-13 10:52:07 -08001359 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001360 adb uninstall com.android.smoketest > /dev/null &&
1361 adb uninstall com.android.smoketest.tests > /dev/null &&
1362 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1363 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1364 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1365}
1366
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001367# simple shortcut to the runtest command
1368function runtest()
1369{
1370 T=$(gettop)
1371 if [ ! "$T" ]; then
1372 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1373 return
1374 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001375 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001376}
1377
The Android Open Source Project88b60792009-03-03 19:28:42 -08001378function godir () {
1379 if [[ -z "$1" ]]; then
1380 echo "Usage: godir <regex>"
1381 return
1382 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001383 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001384 if [[ ! -f $T/filelist ]]; then
1385 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001386 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001387 echo " Done"
1388 echo ""
1389 fi
1390 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001391 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001392 if [[ ${#lines[@]} = 0 ]]; then
1393 echo "Not found"
1394 return
1395 fi
1396 local pathname
1397 local choice
1398 if [[ ${#lines[@]} > 1 ]]; then
1399 while [[ -z "$pathname" ]]; do
1400 local index=1
1401 local line
1402 for line in ${lines[@]}; do
1403 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001404 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001405 done
1406 echo
1407 echo -n "Select one: "
1408 unset choice
1409 read choice
1410 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1411 echo "Invalid choice"
1412 continue
1413 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001414 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001415 done
1416 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001417 pathname=${lines[0]}
1418 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001419 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001420}
1421
Narayan Kamath9260bba2014-01-17 10:05:25 +00001422# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1423#
1424# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1425# For some reason, installing the JDK doesn't make it show up in the
1426# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001427function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001428 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001429 # we can reset it later, depending on the version of java the build
1430 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001431 #
1432 # If we don't do this, the JAVA_HOME value set by the first call to
1433 # build/envsetup.sh will persist forever.
1434 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1435 export JAVA_HOME=""
1436 fi
1437
Andy McFaddenbd960942010-06-24 12:52:51 -07001438 if [ ! "$JAVA_HOME" ]; then
Narayan Kamathc84889b2014-04-01 14:16:26 +01001439 if [ -n "$LEGACY_USE_JAVA6" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001440 case `uname -s` in
1441 Darwin)
1442 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1443 ;;
1444 *)
1445 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1446 ;;
1447 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001448 else
1449 case `uname -s` in
1450 Darwin)
Jason Parks13b2e192014-04-28 13:32:10 -05001451 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
Narayan Kamath9260bba2014-01-17 10:05:25 +00001452 ;;
1453 *)
1454 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1455 ;;
1456 esac
1457 fi
1458
1459 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1460 # we can change it on the next envsetup.sh, if required.
1461 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001462 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001463}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001464
Alex Rayf0d08eb2013-03-08 15:15:06 -08001465# Print colored exit condition
1466function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001467 "$@"
1468 local retval=$?
1469 if [ $retval -ne 0 ]
1470 then
1471 echo -e "\e[0;31mFAILURE\e[00m"
1472 else
1473 echo -e "\e[0;32mSUCCESS\e[00m"
1474 fi
1475 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001476}
1477
Ed Heylcc6be0a2014-06-18 14:55:58 -07001478function make()
1479{
1480 local start_time=$(date +"%s")
Ying Wangdcc8b372014-07-01 10:58:10 -07001481 command make "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001482 local ret=$?
1483 local end_time=$(date +"%s")
1484 local tdiff=$(($end_time-$start_time))
1485 local hours=$(($tdiff / 3600 ))
1486 local mins=$((($tdiff % 3600) / 60))
1487 local secs=$(($tdiff % 60))
1488 echo
1489 if [ $ret -eq 0 ] ; then
Ed Heylc6d11f82014-06-27 13:32:39 -07001490 echo -n -e "#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001491 else
Ed Heylc6d11f82014-06-27 13:32:39 -07001492 echo -n -e "#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001493 fi
1494 if [ $hours -gt 0 ] ; then
1495 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1496 elif [ $mins -gt 0 ] ; then
1497 printf "(%02g:%02g (mm:ss))" $mins $secs
1498 elif [ $secs -gt 0 ] ; then
1499 printf "(%s seconds)" $secs
1500 fi
Ed Heylc6d11f82014-06-27 13:32:39 -07001501 echo -e " ####"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001502 echo
1503 return $ret
1504}
1505
1506
1507
Raphael Moll70a86b02011-06-20 16:03:14 -07001508if [ "x$SHELL" != "x/bin/bash" ]; then
1509 case `ps -o command -p $$` in
1510 *bash*)
1511 ;;
1512 *)
1513 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1514 ;;
1515 esac
1516fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001517
1518# Execute the contents of any vendorsetup.sh files we can find.
Ying Wang506410a2014-07-09 15:37:34 -07001519for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1520 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001521do
1522 echo "including $f"
1523 . $f
1524done
1525unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001526
1527addcompletions