blob: 8c96e004a0fb2ca138fe57fd5823b63001eb8114 [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
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
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700173 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700174 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Colin Cross6a5fa062014-05-22 11:58:40 -0700175 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 +0200176
177 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
178 # to ensure that the corresponding 'emulator' binaries are used.
179 case $(uname -s) in
180 Darwin)
181 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
182 ;;
183 Linux)
184 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
185 ;;
186 *)
187 ANDROID_EMULATOR_PREBUILTS=
188 ;;
189 esac
190 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700191 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200192 export ANDROID_EMULATOR_PREBUILTS
193 fi
194
Ying Wangaa1c9b52012-11-26 20:51:59 -0800195 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800196
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500197 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900198 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500199 if [ -n "$JAVA_HOME" ]; then
200 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900201 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
202 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500203 fi
204
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800205 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700206 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
207 export OUT=$ANDROID_PRODUCT_OUT
208
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700209 unset ANDROID_HOST_OUT
210 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
211
David 'Digit' Turner7cde0302014-05-05 16:13:50 +0200212 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
213 # to ensure that the corresponding 'emulator' binaries are used.
214 case $(uname -s) in
215 Darwin)
216 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
217 ;;
218 Linux)
219 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
220 ;;
221 *)
222 ANDROID_EMULATOR_PREBUILTS=
223 ;;
224 esac
225 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
226 PATH=$ANDROID_EMULATOR_PREBUILTS:$PATH
227 export ANDROID_EMULATOR_PREBUILTS
228 fi
229
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800230 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700231 # TODO: fix the path
232 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
233}
234
235function printconfig()
236{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800237 T=$(gettop)
238 if [ ! "$T" ]; then
239 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
240 return
241 fi
242 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700243}
244
245function set_stuff_for_environment()
246{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800247 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500248 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800249 setpaths
250 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700251
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800252 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700253 # With this environment variable new GCC can apply colors to warnings/errors
254 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 -0700255}
256
257function set_sequence_number()
258{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700259 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700260}
261
262function settitle()
263{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800264 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700265 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700266 local product=$TARGET_PRODUCT
267 local variant=$TARGET_BUILD_VARIANT
268 local apps=$TARGET_BUILD_APPS
269 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700270 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700271 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700272 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700273 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800274 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700275}
276
Kenny Root52aa81c2011-07-15 11:07:06 -0700277function addcompletions()
278{
279 local T dir f
280
281 # Keep us from trying to run in something that isn't bash.
282 if [ -z "${BASH_VERSION}" ]; then
283 return
284 fi
285
286 # Keep us from trying to run in bash that's too old.
287 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
288 return
289 fi
290
291 dir="sdk/bash_completion"
292 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700293 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700294 echo "including $f"
295 . $f
296 done
297 fi
298}
299
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300function choosetype()
301{
302 echo "Build type choices are:"
303 echo " 1. release"
304 echo " 2. debug"
305 echo
306
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800307 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700308 DEFAULT_NUM=1
309 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700310
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800311 export TARGET_BUILD_TYPE=
312 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700313 while [ -z $TARGET_BUILD_TYPE ]
314 do
315 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 if [ -z "$1" ] ; then
317 read ANSWER
318 else
319 echo $1
320 ANSWER=$1
321 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700322 case $ANSWER in
323 "")
324 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
325 ;;
326 1)
327 export TARGET_BUILD_TYPE=release
328 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800329 release)
330 export TARGET_BUILD_TYPE=release
331 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332 2)
333 export TARGET_BUILD_TYPE=debug
334 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335 debug)
336 export TARGET_BUILD_TYPE=debug
337 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338 *)
339 echo
340 echo "I didn't understand your response. Please try again."
341 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700342 ;;
343 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800344 if [ -n "$1" ] ; then
345 break
346 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 done
348
349 set_stuff_for_environment
350}
351
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800352#
353# This function isn't really right: It chooses a TARGET_PRODUCT
354# based on the list of boards. Usually, that gets you something
355# that kinda works with a generic product, but really, you should
356# pick a product by name.
357#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700358function chooseproduct()
359{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700360 if [ "x$TARGET_PRODUCT" != x ] ; then
361 default_value=$TARGET_PRODUCT
362 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700363 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700364 fi
365
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800366 export TARGET_PRODUCT=
367 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700368 while [ -z "$TARGET_PRODUCT" ]
369 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700370 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800371 if [ -z "$1" ] ; then
372 read ANSWER
373 else
374 echo $1
375 ANSWER=$1
376 fi
377
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700378 if [ -z "$ANSWER" ] ; then
379 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800380 else
381 if check_product $ANSWER
382 then
383 export TARGET_PRODUCT=$ANSWER
384 else
385 echo "** Not a valid product: $ANSWER"
386 fi
387 fi
388 if [ -n "$1" ] ; then
389 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700390 fi
391 done
392
393 set_stuff_for_environment
394}
395
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800396function choosevariant()
397{
398 echo "Variant choices are:"
399 local index=1
400 local v
401 for v in ${VARIANT_CHOICES[@]}
402 do
403 # The product name is the name of the directory containing
404 # the makefile we found, above.
405 echo " $index. $v"
406 index=$(($index+1))
407 done
408
409 local default_value=eng
410 local ANSWER
411
412 export TARGET_BUILD_VARIANT=
413 while [ -z "$TARGET_BUILD_VARIANT" ]
414 do
415 echo -n "Which would you like? [$default_value] "
416 if [ -z "$1" ] ; then
417 read ANSWER
418 else
419 echo $1
420 ANSWER=$1
421 fi
422
423 if [ -z "$ANSWER" ] ; then
424 export TARGET_BUILD_VARIANT=$default_value
425 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
426 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800427 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800428 fi
429 else
430 if check_variant $ANSWER
431 then
432 export TARGET_BUILD_VARIANT=$ANSWER
433 else
434 echo "** Not a valid variant: $ANSWER"
435 fi
436 fi
437 if [ -n "$1" ] ; then
438 break
439 fi
440 done
441}
442
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700443function choosecombo()
444{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700445 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446
447 echo
448 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700449 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700450
451 echo
452 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700453 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800454
455 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700456 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800457 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458}
459
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800460# Clear this variable. It will be built up again when the vendorsetup.sh
461# files are included at the end of this file.
462unset LUNCH_MENU_CHOICES
463function add_lunch_combo()
464{
465 local new_combo=$1
466 local c
467 for c in ${LUNCH_MENU_CHOICES[@]} ; do
468 if [ "$new_combo" = "$c" ] ; then
469 return
470 fi
471 done
472 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
473}
474
475# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700476add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800477add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000478add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800479add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000480add_lunch_combo aosp_x86-eng
481add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800482add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800483
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700484function print_lunch_menu()
485{
486 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700487 echo
488 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700489 echo
490 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800491
492 local i=1
493 local choice
494 for choice in ${LUNCH_MENU_CHOICES[@]}
495 do
496 echo " $i. $choice"
497 i=$(($i+1))
498 done
499
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700500 echo
501}
502
503function lunch()
504{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800505 local answer
506
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700507 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800508 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700509 else
510 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700511 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700513 fi
514
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800515 local selection=
516
517 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700518 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700519 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
521 then
522 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
523 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800524 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800525 fi
526 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
527 then
528 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700529 fi
530
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800531 if [ -z "$selection" ]
532 then
533 echo
534 echo "Invalid lunch combo: $answer"
535 return 1
536 fi
537
Joe Onoratoda12daf2010-06-09 18:18:31 -0700538 export TARGET_BUILD_APPS=
539
Jeff Browne33ba4c2011-07-11 22:11:46 -0700540 local product=$(echo -n $selection | sed -e "s/-.*$//")
541 check_product $product
542 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800543 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700544 echo
545 echo "** Don't have a product spec for: '$product'"
546 echo "** Do you have the right repo manifest?"
547 product=
548 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800549
Jeff Browne33ba4c2011-07-11 22:11:46 -0700550 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
551 check_variant $variant
552 if [ $? -ne 0 ]
553 then
554 echo
555 echo "** Invalid variant: '$variant'"
556 echo "** Must be one of ${VARIANT_CHOICES[@]}"
557 variant=
558 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800559
Jeff Browne33ba4c2011-07-11 22:11:46 -0700560 if [ -z "$product" -o -z "$variant" ]
561 then
562 echo
563 return 1
564 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800565
Jeff Browne33ba4c2011-07-11 22:11:46 -0700566 export TARGET_PRODUCT=$product
567 export TARGET_BUILD_VARIANT=$variant
568 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700569
570 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800571
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700572 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800573 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700574}
575
Jeff Davidson513d7a42010-08-02 10:00:44 -0700576# Tab completion for lunch.
577function _lunch()
578{
579 local cur prev opts
580 COMPREPLY=()
581 cur="${COMP_WORDS[COMP_CWORD]}"
582 prev="${COMP_WORDS[COMP_CWORD-1]}"
583
584 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
585 return 0
586}
587complete -F _lunch lunch
588
Joe Onoratoda12daf2010-06-09 18:18:31 -0700589# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700590# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700591function tapas()
592{
Ying Wangb541ab62014-05-29 17:57:40 -0700593 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 -0700594 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Ying Wangb541ab62014-05-29 17:57:40 -0700595 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 -0700596
Ying Wang67f02922012-08-22 10:25:20 -0700597 if [ $(echo $arch | wc -w) -gt 1 ]; then
598 echo "tapas: Error: Multiple build archs supplied: $arch"
599 return
600 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700601 if [ $(echo $variant | wc -w) -gt 1 ]; then
602 echo "tapas: Error: Multiple build variants supplied: $variant"
603 return
604 fi
Ying Wang67f02922012-08-22 10:25:20 -0700605
606 local product=full
607 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700608 x86) product=full_x86;;
609 mips) product=full_mips;;
610 armv5) product=generic_armv5;;
611 arm64) product=aosp_arm64;;
612 x86_64) product=aosp_x86_64;;
613 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700614 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700615 if [ -z "$variant" ]; then
616 variant=eng
617 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700618 if [ -z "$apps" ]; then
619 apps=all
620 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700621
Ying Wang67f02922012-08-22 10:25:20 -0700622 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700623 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700624 export TARGET_BUILD_TYPE=release
625 export TARGET_BUILD_APPS=$apps
626
627 set_stuff_for_environment
628 printconfig
629}
630
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700631function gettop
632{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800633 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700634 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
635 echo $TOP
636 else
637 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800638 # The following circumlocution (repeated below as well) ensures
639 # that we record the true directory name and not one that is
640 # faked up with symlink names.
641 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700642 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800643 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700644 T=
645 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800646 \cd ..
synergyb112a402013-07-05 19:47:47 -0700647 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700648 done
Ying Wang9cd17642012-12-13 10:52:07 -0800649 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700650 if [ -f "$T/$TOPFILE" ]; then
651 echo $T
652 fi
653 fi
654 fi
655}
656
Andrew Hsieh906cb782013-09-10 17:37:14 +0800657# Return driver for "make", if any (eg. static analyzer)
658function getdriver()
659{
660 local T="$1"
661 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
662 if [ -n "$WITH_STATIC_ANALYZER" ]; then
663 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800664$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
665--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800666--status-bugs \
667--top=$T"
668 fi
669}
670
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700671function m()
672{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800673 local T=$(gettop)
674 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700675 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800676 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700677 else
678 echo "Couldn't locate the top of the tree. Try setting TOP."
679 fi
680}
681
682function findmakefile()
683{
684 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800685 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700686 T=
687 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700688 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700689 if [ -f "$T/Android.mk" ]; then
690 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800691 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700692 return
693 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800694 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700695 done
Ying Wang9cd17642012-12-13 10:52:07 -0800696 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700697}
698
699function mm()
700{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800701 local T=$(gettop)
702 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700703 # If we're sitting in the root of the build tree, just do a
704 # normal make.
705 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800706 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700707 else
708 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800709 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700710 local MODULES=
711 local GET_INSTALL_PATH=
712 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700713 # Remove the path to top as the makefilepath needs to be relative
714 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700715 if [ ! "$T" ]; then
716 echo "Couldn't locate the top of the tree. Try setting TOP."
717 elif [ ! "$M" ]; then
718 echo "Couldn't locate a makefile from the current directory."
719 else
Ying Wanga7deb082013-08-16 13:24:47 -0700720 for ARG in $@; do
721 case $ARG in
722 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
723 esac
724 done
725 if [ -n "$GET_INSTALL_PATH" ]; then
726 MODULES=
727 ARGS=GET-INSTALL-PATH
728 else
729 MODULES=all_modules
730 ARGS=$@
731 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700732 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 -0700733 fi
734 fi
735}
736
737function mmm()
738{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800739 local T=$(gettop)
740 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700741 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800742 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800743 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800744 local ARGS=
745 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700746 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800747 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
748 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
749 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800750 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
751 if [ "$MODULES" = "" ]; then
752 MODULES=all_modules
753 fi
754 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700755 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700756 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
757 local TO_CHOP=`expr $TO_CHOP + 1`
758 local START=`PWD= /bin/pwd`
759 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700760 if [ "$MFILE" = "" ] ; then
761 MFILE=$DIR/Android.mk
762 else
763 MFILE=$MFILE/$DIR/Android.mk
764 fi
765 MAKEFILE="$MAKEFILE $MFILE"
766 else
Ying Wanga7deb082013-08-16 13:24:47 -0700767 case $DIR in
768 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
769 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
770 *) echo "No Android.mk in $DIR."; return 1;;
771 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700772 fi
773 done
Ying Wanga7deb082013-08-16 13:24:47 -0700774 if [ -n "$GET_INSTALL_PATH" ]; then
775 ARGS=$GET_INSTALL_PATH
776 MODULES=
777 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800778 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 -0700779 else
780 echo "Couldn't locate the top of the tree. Try setting TOP."
781 fi
782}
783
Ying Wangb607f7b2013-02-08 18:01:04 -0800784function mma()
785{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800786 local T=$(gettop)
787 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800788 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800789 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800790 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800791 if [ ! "$T" ]; then
792 echo "Couldn't locate the top of the tree. Try setting TOP."
793 fi
794 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800795 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800796 fi
797}
798
799function mmma()
800{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800801 local T=$(gettop)
802 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800803 if [ "$T" ]; then
804 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
805 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
806 local MY_PWD=`PWD= /bin/pwd`
807 if [ "$MY_PWD" = "$T" ]; then
808 MY_PWD=
809 else
810 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
811 fi
812 local DIR=
813 local MODULE_PATHS=
814 local ARGS=
815 for DIR in $DIRS ; do
816 if [ -d $DIR ]; then
817 if [ "$MY_PWD" = "" ]; then
818 MODULE_PATHS="$MODULE_PATHS $DIR"
819 else
820 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
821 fi
822 else
823 case $DIR in
824 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
825 *) echo "Couldn't find directory $DIR"; return 1;;
826 esac
827 fi
828 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800829 $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 -0800830 else
831 echo "Couldn't locate the top of the tree. Try setting TOP."
832 fi
833}
834
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700835function croot()
836{
837 T=$(gettop)
838 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800839 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700840 else
841 echo "Couldn't locate the top of the tree. Try setting TOP."
842 fi
843}
844
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700845function cproj()
846{
847 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700848 local HERE=$PWD
849 T=
850 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
851 T=$PWD
852 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800853 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700854 return
855 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800856 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700857 done
Ying Wang9cd17642012-12-13 10:52:07 -0800858 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700859 echo "can't find Android.mk"
860}
861
Daniel Sandler47e0a882013-07-30 13:23:52 -0400862# simplified version of ps; output in the form
863# <pid> <procname>
864function qpid() {
865 local prepend=''
866 local append=''
867 if [ "$1" = "--exact" ]; then
868 prepend=' '
869 append='$'
870 shift
871 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
872 echo "usage: qpid [[--exact] <process name|pid>"
873 return 255
874 fi
875
876 local EXE="$1"
877 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700878 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400879 else
880 adb shell ps \
881 | tr -d '\r' \
882 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
883 fi
884}
885
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700886function pid()
887{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400888 local prepend=''
889 local append=''
890 if [ "$1" = "--exact" ]; then
891 prepend=' '
892 append='$'
893 shift
894 fi
895 local EXE="$1"
896 if [ "$EXE" ] ; then
897 local PID=`adb shell ps \
898 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700899 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400900 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
901 echo "$PID"
902 else
903 echo "usage: pid [--exact] <process name>"
904 return 255
905 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700906}
907
Christopher Tate744ee802009-11-12 15:33:08 -0800908# systemstack - dump the current stack trace of all threads in the system process
909# to the usual ANR traces file
910function systemstack()
911{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800912 stacks system_server
913}
914
915function stacks()
916{
917 if [[ $1 =~ ^[0-9]+$ ]] ; then
918 local PID="$1"
919 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700920 local PIDLIST="$(pid $1)"
921 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
922 local PID="$PIDLIST"
923 elif [ "$PIDLIST" ] ; then
924 echo "more than one process: $1"
925 else
926 echo "no such process: $1"
927 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800928 else
929 echo "usage: stacks [pid|process name]"
930 fi
931
932 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700933 # Determine whether the process is native
934 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
935 # Dump stacks of Dalvik process
936 local TRACES=/data/anr/traces.txt
937 local ORIG=/data/anr/traces.orig
938 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800939
Jeff Brownb12c2e52013-08-19 15:14:16 -0700940 # Keep original traces to avoid clobbering
941 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800942
Jeff Brownb12c2e52013-08-19 15:14:16 -0700943 # Make sure we have a usable file
944 adb shell touch $TRACES
945 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800946
Jeff Brownb12c2e52013-08-19 15:14:16 -0700947 # Dump stacks and wait for dump to finish
948 adb shell kill -3 $PID
949 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800950
Jeff Brownb12c2e52013-08-19 15:14:16 -0700951 # Restore original stacks, and show current output
952 adb shell mv $TRACES $TMP
953 adb shell mv $ORIG $TRACES
954 adb shell cat $TMP
955 else
956 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -0700957 local USE64BIT="$(is64bit $PID)"
958 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -0700959 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
Michael Wrightaeed7212014-06-19 19:58:12 -0700975# Read the ELF header from /proc/$PID/exe to determine if the process is
976# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -0800977function is64bit()
978{
979 local PID="$1"
980 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -0700981 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800982 echo "64"
983 else
984 echo ""
985 fi
986 else
987 echo ""
988 fi
989}
990
991# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
992# executable, set up the approriate gdbserver, then invokes the proper host
993# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700994function gdbclient()
995{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800996 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
997 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
998 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
Colin Cross3655a682014-05-22 11:59:10 -0700999 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
Brigid Smith0a2712d2014-05-28 14:36:43 -07001000 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001001 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001002 local ARCH=$(get_build_var TARGET_ARCH)
1003 local GDB
1004 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001005 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -08001006 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -07001007 mips) GDB=mipsel-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +00001008 mips64) GDB=mipsel-linux-android-gdb;;
1009 x86) GDB=x86_64-linux-android-gdb;;
1010 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001011 *) echo "Unknown arch $ARCH"; return 1;;
1012 esac
1013
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001014 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1015 local EXE="$1"
1016 if [ "$EXE" ] ; then
1017 EXE=$1
Brigid Smith7a569a62014-06-20 14:12:12 -07001018 if [[ $EXE =~ ^[^/].* ]] ; then
1019 EXE="system/bin/"$EXE
1020 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001021 else
1022 EXE="app_process"
1023 fi
1024
1025 local PORT="$2"
1026 if [ "$PORT" ] ; then
1027 PORT=$2
1028 else
1029 PORT=":5039"
1030 fi
1031
Chris Craik20c136a2012-11-09 18:02:19 -08001032 local PID="$3"
1033 if [ "$PID" ] ; then
1034 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -07001035 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -08001036 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1037 # that likely didn't work because of returning multiple processes
1038 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001039 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001040 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1041 then
1042 echo "Couldn't resolve '$3' to single PID"
1043 return 1
1044 else
1045 echo ""
1046 echo "WARNING: multiple processes matching '$3' observed, using root process"
1047 echo ""
1048 fi
1049 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001050 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001051 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001052 local USE64BIT="$(is64bit $PID)"
1053 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001054 sleep 2
1055 else
1056 echo ""
1057 echo "If you haven't done so already, do this first on the device:"
1058 echo " gdbserver $PORT /system/bin/$EXE"
1059 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001060 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001061 echo ""
1062 fi
1063
Colin Cross84480ad2014-04-10 12:51:39 -07001064 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
Colin Crossa58f8e02014-06-20 13:33:36 -07001065 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
Colin Cross84480ad2014-04-10 12:51:39 -07001066
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