blob: 2cd342cb7c9fc78e114099249aa3f51078cefbf8 [file] [log] [blame]
Ed Heyl9e7b9b92014-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 Wangf05c4f72013-01-31 11:16:57 -08006- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [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.
15- jgrep: Greps on all local Java files.
16- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080017- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070018
19Look at the source to view more functions. The complete list is:
20EOF
21 T=$(gettop)
22 local A
23 A=""
24 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
25 A="$A $i"
26 done
27 echo $A
28}
29
30# Get the value of a build variable as an absolute path.
31function get_abs_build_var()
32{
33 T=$(gettop)
34 if [ ! "$T" ]; then
35 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
36 return
37 fi
Ying Wang9cd17642012-12-13 10:52:07 -080038 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heyl9e7b9b92014-06-18 14:55:58 -070039 $MAKE_UTIL --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070040}
41
42# Get the exact value of a build variable.
43function get_build_var()
44{
45 T=$(gettop)
46 if [ ! "$T" ]; then
47 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
48 return
49 fi
Andrew Boie6905e212013-12-19 13:21:46 -080050 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heyl9e7b9b92014-06-18 14:55:58 -070051 $MAKE_UTIL --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080052}
53
54# check to see if the supplied product is one we can build
55function check_product()
56{
57 T=$(gettop)
58 if [ ! "$T" ]; then
59 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
60 return
61 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -070062 TARGET_PRODUCT=$1 \
63 TARGET_BUILD_VARIANT= \
64 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070065 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080066 get_build_var TARGET_DEVICE > /dev/null
67 # hide successful answers, but allow the errors to show
68}
69
70VARIANT_CHOICES=(user userdebug eng)
71
72# check to see if the supplied variant is valid
73function check_variant()
74{
75 for v in ${VARIANT_CHOICES[@]}
76 do
77 if [ "$v" = "$1" ]
78 then
79 return 0
80 fi
81 done
82 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070083}
84
85function setpaths()
86{
87 T=$(gettop)
88 if [ ! "$T" ]; then
89 echo "Couldn't locate the top of the tree. Try setting TOP."
90 return
91 fi
92
93 ##################################################################
94 # #
95 # Read me before you modify this code #
96 # #
97 # This function sets ANDROID_BUILD_PATHS to what it is adding #
98 # to PATH, and the next time it is run, it removes that from #
99 # PATH. This is required so lunch can be run more than once #
100 # and still have working paths. #
101 # #
102 ##################################################################
103
Raphael Mollc639c782011-06-20 17:25:01 -0700104 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
105 # due to "C:\Program Files" being in the path.
106
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700107 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700108 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700109 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
110 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700111 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700112 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800113 # strip leading ':', if any
114 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500115 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700116
117 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700118 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700119 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700120
Ben Cheng8bc4c432012-11-16 13:29:13 -0800121 # defined in core/config.mk
122 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700123 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800124 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800125
Raphael Mollc639c782011-06-20 17:25:01 -0700126 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800127 export ANDROID_TOOLCHAIN=
128 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200129 local ARCH=$(get_build_var TARGET_ARCH)
130 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400131 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700132 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400133 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
134 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800135 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200136 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800137 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700138 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700139 ;;
Duane Sand6670e242014-07-22 14:34:00 -0700140 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000141 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200142 *)
143 echo "Can't find toolchain for unknown architecture: $ARCH"
144 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700145 ;;
146 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700147 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800148 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700149 fi
Raphael732936d2011-06-22 14:35:32 -0700150
Ben Chengfba67bf2014-02-25 10:27:07 -0800151 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
152 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
153 fi
154
155 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700156 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700157 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800158 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800159 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700160 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100161 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
162 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700163 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700164 ;;
165 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700166 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700167 ;;
168 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700169
Ying Wang564f9122013-03-29 17:40:14 -0700170 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wang2a859d52014-06-30 10:25:33 -0700171 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 +0200172
173 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
174 # to ensure that the corresponding 'emulator' binaries are used.
175 case $(uname -s) in
176 Darwin)
177 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
178 ;;
179 Linux)
180 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
181 ;;
182 *)
183 ANDROID_EMULATOR_PREBUILTS=
184 ;;
185 esac
186 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700187 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200188 export ANDROID_EMULATOR_PREBUILTS
189 fi
190
Ying Wangaa1c9b52012-11-26 20:51:59 -0800191 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800192
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500193 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900194 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500195 if [ -n "$JAVA_HOME" ]; then
196 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900197 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
198 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500199 fi
200
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800201 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700202 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
203 export OUT=$ANDROID_PRODUCT_OUT
204
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700205 unset ANDROID_HOST_OUT
206 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
207
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800208 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700209 # TODO: fix the path
210 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
211}
212
213function printconfig()
214{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800215 T=$(gettop)
216 if [ ! "$T" ]; then
217 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
218 return
219 fi
220 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700221}
222
223function set_stuff_for_environment()
224{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800225 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500226 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800227 setpaths
228 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700229
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800230 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700231 # With this environment variable new GCC can apply colors to warnings/errors
232 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 -0700233}
234
235function set_sequence_number()
236{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700237 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700238}
239
240function settitle()
241{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800242 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700243 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700244 local product=$TARGET_PRODUCT
245 local variant=$TARGET_BUILD_VARIANT
246 local apps=$TARGET_BUILD_APPS
247 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700248 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700249 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700250 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700251 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800252 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700253}
254
Kenny Root52aa81c2011-07-15 11:07:06 -0700255function addcompletions()
256{
257 local T dir f
258
259 # Keep us from trying to run in something that isn't bash.
260 if [ -z "${BASH_VERSION}" ]; then
261 return
262 fi
263
264 # Keep us from trying to run in bash that's too old.
265 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
266 return
267 fi
268
269 dir="sdk/bash_completion"
270 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700271 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700272 echo "including $f"
273 . $f
274 done
275 fi
276}
277
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700278function choosetype()
279{
280 echo "Build type choices are:"
281 echo " 1. release"
282 echo " 2. debug"
283 echo
284
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800285 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700286 DEFAULT_NUM=1
287 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700288
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800289 export TARGET_BUILD_TYPE=
290 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700291 while [ -z $TARGET_BUILD_TYPE ]
292 do
293 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800294 if [ -z "$1" ] ; then
295 read ANSWER
296 else
297 echo $1
298 ANSWER=$1
299 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300 case $ANSWER in
301 "")
302 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
303 ;;
304 1)
305 export TARGET_BUILD_TYPE=release
306 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800307 release)
308 export TARGET_BUILD_TYPE=release
309 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700310 2)
311 export TARGET_BUILD_TYPE=debug
312 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800313 debug)
314 export TARGET_BUILD_TYPE=debug
315 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700316 *)
317 echo
318 echo "I didn't understand your response. Please try again."
319 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700320 ;;
321 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800322 if [ -n "$1" ] ; then
323 break
324 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325 done
326
327 set_stuff_for_environment
328}
329
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800330#
331# This function isn't really right: It chooses a TARGET_PRODUCT
332# based on the list of boards. Usually, that gets you something
333# that kinda works with a generic product, but really, you should
334# pick a product by name.
335#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700336function chooseproduct()
337{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338 if [ "x$TARGET_PRODUCT" != x ] ; then
339 default_value=$TARGET_PRODUCT
340 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700341 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700342 fi
343
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800344 export TARGET_PRODUCT=
345 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346 while [ -z "$TARGET_PRODUCT" ]
347 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700348 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800349 if [ -z "$1" ] ; then
350 read ANSWER
351 else
352 echo $1
353 ANSWER=$1
354 fi
355
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700356 if [ -z "$ANSWER" ] ; then
357 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800358 else
359 if check_product $ANSWER
360 then
361 export TARGET_PRODUCT=$ANSWER
362 else
363 echo "** Not a valid product: $ANSWER"
364 fi
365 fi
366 if [ -n "$1" ] ; then
367 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700368 fi
369 done
370
371 set_stuff_for_environment
372}
373
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800374function choosevariant()
375{
376 echo "Variant choices are:"
377 local index=1
378 local v
379 for v in ${VARIANT_CHOICES[@]}
380 do
381 # The product name is the name of the directory containing
382 # the makefile we found, above.
383 echo " $index. $v"
384 index=$(($index+1))
385 done
386
387 local default_value=eng
388 local ANSWER
389
390 export TARGET_BUILD_VARIANT=
391 while [ -z "$TARGET_BUILD_VARIANT" ]
392 do
393 echo -n "Which would you like? [$default_value] "
394 if [ -z "$1" ] ; then
395 read ANSWER
396 else
397 echo $1
398 ANSWER=$1
399 fi
400
401 if [ -z "$ANSWER" ] ; then
402 export TARGET_BUILD_VARIANT=$default_value
403 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
404 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800405 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800406 fi
407 else
408 if check_variant $ANSWER
409 then
410 export TARGET_BUILD_VARIANT=$ANSWER
411 else
412 echo "** Not a valid variant: $ANSWER"
413 fi
414 fi
415 if [ -n "$1" ] ; then
416 break
417 fi
418 done
419}
420
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700421function choosecombo()
422{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700423 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700424
425 echo
426 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700427 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700428
429 echo
430 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700431 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800432
433 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700434 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800435 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700436}
437
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800438# Clear this variable. It will be built up again when the vendorsetup.sh
439# files are included at the end of this file.
440unset LUNCH_MENU_CHOICES
441function add_lunch_combo()
442{
443 local new_combo=$1
444 local c
445 for c in ${LUNCH_MENU_CHOICES[@]} ; do
446 if [ "$new_combo" = "$c" ] ; then
447 return
448 fi
449 done
450 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
451}
452
453# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700454add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800455add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000456add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800457add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000458add_lunch_combo aosp_x86-eng
459add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800460add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800461
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700462function print_lunch_menu()
463{
464 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465 echo
466 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700467 echo
468 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469
470 local i=1
471 local choice
472 for choice in ${LUNCH_MENU_CHOICES[@]}
473 do
474 echo " $i. $choice"
475 i=$(($i+1))
476 done
477
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478 echo
479}
480
481function lunch()
482{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800483 local answer
484
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700485 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700487 else
488 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700489 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700491 fi
492
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800493 local selection=
494
495 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700496 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700497 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800498 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
499 then
500 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
501 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800502 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800503 fi
504 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
505 then
506 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700507 fi
508
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800509 if [ -z "$selection" ]
510 then
511 echo
512 echo "Invalid lunch combo: $answer"
513 return 1
514 fi
515
Joe Onoratoda12daf2010-06-09 18:18:31 -0700516 export TARGET_BUILD_APPS=
517
Jeff Browne33ba4c2011-07-11 22:11:46 -0700518 local product=$(echo -n $selection | sed -e "s/-.*$//")
519 check_product $product
520 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700522 echo
523 echo "** Don't have a product spec for: '$product'"
524 echo "** Do you have the right repo manifest?"
525 product=
526 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800527
Jeff Browne33ba4c2011-07-11 22:11:46 -0700528 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
529 check_variant $variant
530 if [ $? -ne 0 ]
531 then
532 echo
533 echo "** Invalid variant: '$variant'"
534 echo "** Must be one of ${VARIANT_CHOICES[@]}"
535 variant=
536 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800537
Jeff Browne33ba4c2011-07-11 22:11:46 -0700538 if [ -z "$product" -o -z "$variant" ]
539 then
540 echo
541 return 1
542 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800543
Jeff Browne33ba4c2011-07-11 22:11:46 -0700544 export TARGET_PRODUCT=$product
545 export TARGET_BUILD_VARIANT=$variant
546 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700547
548 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800549
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700550 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800551 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700552}
553
Jeff Davidson513d7a42010-08-02 10:00:44 -0700554# Tab completion for lunch.
555function _lunch()
556{
557 local cur prev opts
558 COMPREPLY=()
559 cur="${COMP_WORDS[COMP_CWORD]}"
560 prev="${COMP_WORDS[COMP_CWORD-1]}"
561
562 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
563 return 0
564}
565complete -F _lunch lunch
566
Joe Onoratoda12daf2010-06-09 18:18:31 -0700567# Configures the build to build unbundled apps.
568# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
569function tapas()
570{
Ying Wangf05c4f72013-01-31 11:16:57 -0800571 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600572 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800573 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5)$'))
Joe Onoratoda12daf2010-06-09 18:18:31 -0700574
Ying Wang67f02922012-08-22 10:25:20 -0700575 if [ $(echo $arch | wc -w) -gt 1 ]; then
576 echo "tapas: Error: Multiple build archs supplied: $arch"
577 return
578 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700579 if [ $(echo $variant | wc -w) -gt 1 ]; then
580 echo "tapas: Error: Multiple build variants supplied: $variant"
581 return
582 fi
Ying Wang67f02922012-08-22 10:25:20 -0700583
584 local product=full
585 case $arch in
586 x86) product=full_x86;;
587 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800588 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700589 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700590 if [ -z "$variant" ]; then
591 variant=eng
592 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700593 if [ -z "$apps" ]; then
594 apps=all
595 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700596
Ying Wang67f02922012-08-22 10:25:20 -0700597 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700598 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700599 export TARGET_BUILD_TYPE=release
600 export TARGET_BUILD_APPS=$apps
601
602 set_stuff_for_environment
603 printconfig
604}
605
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700606function gettop
607{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800608 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700609 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
610 echo $TOP
611 else
612 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800613 # The following circumlocution (repeated below as well) ensures
614 # that we record the true directory name and not one that is
615 # faked up with symlink names.
616 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700617 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800618 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700619 T=
620 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800621 \cd ..
synergyb112a402013-07-05 19:47:47 -0700622 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700623 done
Ying Wang9cd17642012-12-13 10:52:07 -0800624 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700625 if [ -f "$T/$TOPFILE" ]; then
626 echo $T
627 fi
628 fi
629 fi
630}
631
Andrew Hsieh906cb782013-09-10 17:37:14 +0800632# Return driver for "make", if any (eg. static analyzer)
633function getdriver()
634{
635 local T="$1"
636 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
637 if [ -n "$WITH_STATIC_ANALYZER" ]; then
638 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800639$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
640--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800641--status-bugs \
642--top=$T"
643 fi
644}
645
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700646function m()
647{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800648 local T=$(gettop)
649 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700650 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800651 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700652 else
653 echo "Couldn't locate the top of the tree. Try setting TOP."
654 fi
655}
656
657function findmakefile()
658{
659 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800660 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661 T=
662 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700663 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700664 if [ -f "$T/Android.mk" ]; then
665 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800666 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700667 return
668 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800669 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700670 done
Ying Wang9cd17642012-12-13 10:52:07 -0800671 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672}
673
674function mm()
675{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800676 local T=$(gettop)
677 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700678 # If we're sitting in the root of the build tree, just do a
679 # normal make.
680 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800681 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700682 else
683 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800684 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700685 local MODULES=
686 local GET_INSTALL_PATH=
687 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700688 # Remove the path to top as the makefilepath needs to be relative
689 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700690 if [ ! "$T" ]; then
691 echo "Couldn't locate the top of the tree. Try setting TOP."
692 elif [ ! "$M" ]; then
693 echo "Couldn't locate a makefile from the current directory."
694 else
Ying Wanga7deb082013-08-16 13:24:47 -0700695 for ARG in $@; do
696 case $ARG in
697 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
698 esac
699 done
700 if [ -n "$GET_INSTALL_PATH" ]; then
701 MODULES=
702 ARGS=GET-INSTALL-PATH
703 else
704 MODULES=all_modules
705 ARGS=$@
706 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700707 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 -0700708 fi
709 fi
710}
711
712function mmm()
713{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800714 local T=$(gettop)
715 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700716 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800717 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800718 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800719 local ARGS=
720 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700721 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800722 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
723 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
724 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800725 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
726 if [ "$MODULES" = "" ]; then
727 MODULES=all_modules
728 fi
729 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700730 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700731 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
732 local TO_CHOP=`expr $TO_CHOP + 1`
733 local START=`PWD= /bin/pwd`
734 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700735 if [ "$MFILE" = "" ] ; then
736 MFILE=$DIR/Android.mk
737 else
738 MFILE=$MFILE/$DIR/Android.mk
739 fi
740 MAKEFILE="$MAKEFILE $MFILE"
741 else
Ying Wanga7deb082013-08-16 13:24:47 -0700742 case $DIR in
743 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
744 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
745 *) echo "No Android.mk in $DIR."; return 1;;
746 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700747 fi
748 done
Ying Wanga7deb082013-08-16 13:24:47 -0700749 if [ -n "$GET_INSTALL_PATH" ]; then
750 ARGS=$GET_INSTALL_PATH
751 MODULES=
752 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800753 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 -0700754 else
755 echo "Couldn't locate the top of the tree. Try setting TOP."
756 fi
757}
758
Ying Wangb607f7b2013-02-08 18:01:04 -0800759function mma()
760{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800761 local T=$(gettop)
762 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800763 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800764 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800765 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800766 if [ ! "$T" ]; then
767 echo "Couldn't locate the top of the tree. Try setting TOP."
768 fi
769 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800770 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800771 fi
772}
773
774function mmma()
775{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800776 local T=$(gettop)
777 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800778 if [ "$T" ]; then
779 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
780 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
781 local MY_PWD=`PWD= /bin/pwd`
782 if [ "$MY_PWD" = "$T" ]; then
783 MY_PWD=
784 else
785 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
786 fi
787 local DIR=
788 local MODULE_PATHS=
789 local ARGS=
790 for DIR in $DIRS ; do
791 if [ -d $DIR ]; then
792 if [ "$MY_PWD" = "" ]; then
793 MODULE_PATHS="$MODULE_PATHS $DIR"
794 else
795 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
796 fi
797 else
798 case $DIR in
799 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
800 *) echo "Couldn't find directory $DIR"; return 1;;
801 esac
802 fi
803 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800804 $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 -0800805 else
806 echo "Couldn't locate the top of the tree. Try setting TOP."
807 fi
808}
809
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700810function croot()
811{
812 T=$(gettop)
813 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800814 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700815 else
816 echo "Couldn't locate the top of the tree. Try setting TOP."
817 fi
818}
819
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700820function cproj()
821{
822 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700823 local HERE=$PWD
824 T=
825 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
826 T=$PWD
827 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800828 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700829 return
830 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800831 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700832 done
Ying Wang9cd17642012-12-13 10:52:07 -0800833 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700834 echo "can't find Android.mk"
835}
836
Daniel Sandler47e0a882013-07-30 13:23:52 -0400837# simplified version of ps; output in the form
838# <pid> <procname>
839function qpid() {
840 local prepend=''
841 local append=''
842 if [ "$1" = "--exact" ]; then
843 prepend=' '
844 append='$'
845 shift
846 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
847 echo "usage: qpid [[--exact] <process name|pid>"
848 return 255
849 fi
850
851 local EXE="$1"
852 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700853 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400854 else
855 adb shell ps \
856 | tr -d '\r' \
857 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
858 fi
859}
860
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700861function pid()
862{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400863 local prepend=''
864 local append=''
865 if [ "$1" = "--exact" ]; then
866 prepend=' '
867 append='$'
868 shift
869 fi
870 local EXE="$1"
871 if [ "$EXE" ] ; then
872 local PID=`adb shell ps \
873 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700874 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400875 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
876 echo "$PID"
877 else
878 echo "usage: pid [--exact] <process name>"
879 return 255
880 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700881}
882
Christopher Tate744ee802009-11-12 15:33:08 -0800883# systemstack - dump the current stack trace of all threads in the system process
884# to the usual ANR traces file
885function systemstack()
886{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800887 stacks system_server
888}
889
890function stacks()
891{
892 if [[ $1 =~ ^[0-9]+$ ]] ; then
893 local PID="$1"
894 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700895 local PIDLIST="$(pid $1)"
896 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
897 local PID="$PIDLIST"
898 elif [ "$PIDLIST" ] ; then
899 echo "more than one process: $1"
900 else
901 echo "no such process: $1"
902 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800903 else
904 echo "usage: stacks [pid|process name]"
905 fi
906
907 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700908 # Determine whether the process is native
909 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
910 # Dump stacks of Dalvik process
911 local TRACES=/data/anr/traces.txt
912 local ORIG=/data/anr/traces.orig
913 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800914
Jeff Brownb12c2e52013-08-19 15:14:16 -0700915 # Keep original traces to avoid clobbering
916 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800917
Jeff Brownb12c2e52013-08-19 15:14:16 -0700918 # Make sure we have a usable file
919 adb shell touch $TRACES
920 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800921
Jeff Brownb12c2e52013-08-19 15:14:16 -0700922 # Dump stacks and wait for dump to finish
923 adb shell kill -3 $PID
924 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800925
Jeff Brownb12c2e52013-08-19 15:14:16 -0700926 # Restore original stacks, and show current output
927 adb shell mv $TRACES $TMP
928 adb shell mv $ORIG $TRACES
929 adb shell cat $TMP
930 else
931 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -0700932 local USE64BIT="$(is64bit $PID)"
933 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -0700934 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800935 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800936}
937
John Michelau50200252012-11-09 11:48:04 -0600938function gdbwrapper()
939{
Ben Chengfba67bf2014-02-25 10:27:07 -0800940 local GDB_CMD="$1"
941 shift 1
942 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -0600943}
944
Brigid Smith0a2712d2014-05-28 14:36:43 -0700945function get_symbols_directory()
946{
947 echo $(get_abs_build_var TARGET_OUT_UNSTRIPPED)
948}
949
Michael Wrightaeed7212014-06-19 19:58:12 -0700950# Read the ELF header from /proc/$PID/exe to determine if the process is
951# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -0800952function is64bit()
953{
954 local PID="$1"
955 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -0700956 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800957 echo "64"
958 else
959 echo ""
960 fi
961 else
962 echo ""
963 fi
964}
965
966# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
967# executable, set up the approriate gdbserver, then invokes the proper host
968# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700969function gdbclient()
970{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800971 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
972 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
973 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
Colin Cross3655a682014-05-22 11:59:10 -0700974 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
Brigid Smith0a2712d2014-05-28 14:36:43 -0700975 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800976 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800977 local ARCH=$(get_build_var TARGET_ARCH)
978 local GDB
979 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800980 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800981 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Duane Sand6670e242014-07-22 14:34:00 -0700982 mips|mips64) GDB=mips64el-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000983 x86) GDB=x86_64-linux-android-gdb;;
984 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800985 *) echo "Unknown arch $ARCH"; return 1;;
986 esac
987
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700988 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
989 local EXE="$1"
990 if [ "$EXE" ] ; then
991 EXE=$1
Brigid Smith7a569a62014-06-20 14:12:12 -0700992 if [[ $EXE =~ ^[^/].* ]] ; then
993 EXE="system/bin/"$EXE
994 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700995 else
996 EXE="app_process"
997 fi
998
999 local PORT="$2"
1000 if [ "$PORT" ] ; then
1001 PORT=$2
1002 else
1003 PORT=":5039"
1004 fi
1005
Chris Craik20c136a2012-11-09 18:02:19 -08001006 local PID="$3"
1007 if [ "$PID" ] ; then
1008 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -07001009 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -08001010 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1011 # that likely didn't work because of returning multiple processes
1012 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001013 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001014 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1015 then
1016 echo "Couldn't resolve '$3' to single PID"
1017 return 1
1018 else
1019 echo ""
1020 echo "WARNING: multiple processes matching '$3' observed, using root process"
1021 echo ""
1022 fi
1023 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001024 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001025 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001026 local USE64BIT="$(is64bit $PID)"
1027 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001028 sleep 2
1029 else
1030 echo ""
1031 echo "If you haven't done so already, do this first on the device:"
1032 echo " gdbserver $PORT /system/bin/$EXE"
1033 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001034 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001035 echo ""
1036 fi
1037
Colin Cross84480ad2014-04-10 12:51:39 -07001038 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1039
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001040 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Colin Cross3655a682014-05-22 11:59:10 -07001041 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 -07001042 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001043 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1044 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1045
Ben Chengfba67bf2014-02-25 10:27:07 -08001046 local WHICH_GDB=
1047 # 64-bit exe found
1048 if [ "$USE64BIT" != "" ] ; then
1049 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1050 # 32-bit exe / 32-bit platform
1051 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1052 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1053 # 32-bit exe / 64-bit platform
1054 else
1055 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1056 fi
Brigid Smith0a2712d2014-05-28 14:36:43 -07001057
Ben Chengfba67bf2014-02-25 10:27:07 -08001058 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001059 else
1060 echo "Unable to determine build system output dir."
1061 fi
1062
1063}
1064
1065case `uname -s` in
1066 Darwin)
1067 function sgrep()
1068 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001069 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 -07001070 }
1071
1072 ;;
1073 *)
1074 function sgrep()
1075 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001076 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 -07001077 }
1078 ;;
1079esac
1080
Raghu Gandham8da43102012-07-25 19:57:22 -07001081function gettargetarch
1082{
1083 get_build_var TARGET_ARCH
1084}
1085
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001086function jgrep()
1087{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001088 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 -07001089}
1090
1091function cgrep()
1092{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001093 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 -07001094}
1095
1096function resgrep()
1097{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001098 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 -07001099}
1100
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001101function mangrep()
1102{
1103 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1104}
1105
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001106function sepgrep()
1107{
1108 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 "$@"
1109}
1110
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001111case `uname -s` in
1112 Darwin)
1113 function mgrep()
1114 {
Ying Wang324c2b22012-08-17 15:03:20 -07001115 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 -07001116 }
1117
1118 function treegrep()
1119 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001120 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 -07001121 }
1122
1123 ;;
1124 *)
1125 function mgrep()
1126 {
Ying Wang324c2b22012-08-17 15:03:20 -07001127 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 -07001128 }
1129
1130 function treegrep()
1131 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001132 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 -07001133 }
1134
1135 ;;
1136esac
1137
1138function getprebuilt
1139{
1140 get_abs_build_var ANDROID_PREBUILTS
1141}
1142
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001143function tracedmdump()
1144{
1145 T=$(gettop)
1146 if [ ! "$T" ]; then
1147 echo "Couldn't locate the top of the tree. Try setting TOP."
1148 return
1149 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001150 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001151 local arch=$(gettargetarch)
1152 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001153
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001154 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001155 if [ ! "$TRACE" ] ; then
1156 echo "usage: tracedmdump tracename"
1157 return
1158 fi
1159
Jack Veenstra60116fc2009-04-09 18:12:34 -07001160 if [ ! -r "$KERNEL" ] ; then
1161 echo "Error: cannot find kernel: '$KERNEL'"
1162 return
1163 fi
1164
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001165 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001166 if [ "$BASETRACE" = "$TRACE" ] ; then
1167 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1168 fi
1169
1170 echo "post-processing traces..."
1171 rm -f $TRACE/qtrace.dexlist
1172 post_trace $TRACE
1173 if [ $? -ne 0 ]; then
1174 echo "***"
1175 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1176 echo "***"
1177 return
1178 fi
1179 echo "generating dexlist output..."
1180 /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
1181 echo "generating dmtrace data..."
1182 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1183 echo "generating html file..."
1184 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1185 echo "done, see $TRACE/dmtrace.html for details"
1186 echo "or run:"
1187 echo " traceview $TRACE/dmtrace"
1188}
1189
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001190# communicate with a running device or emulator, set up necessary state,
1191# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001192function runhat()
1193{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001194 # process standard adb options
1195 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001196 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001197 adbTarget=$1
1198 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001199 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001200 adbTarget="$1 $2"
1201 shift 2
1202 fi
1203 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001204 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001205
1206 # runhat options
1207 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001208
1209 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001210 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001211 return
1212 fi
1213
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001214 # confirm hat is available
1215 if [ -z $(which hat) ]; then
1216 echo "hat is not available in this configuration."
1217 return
1218 fi
1219
Andy McFaddenb6289852010-07-12 08:00:19 -07001220 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001221 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001222 local devFile=$sdcard/hprof-$targetPid
1223 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001224 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001225 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001226 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001227 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001228 echo -n "> "
1229 read
1230
The Android Open Source Project88b60792009-03-03 19:28:42 -08001231 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001232
The Android Open Source Project88b60792009-03-03 19:28:42 -08001233 echo "Retrieving file $devFile..."
1234 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001235
The Android Open Source Project88b60792009-03-03 19:28:42 -08001236 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001237
The Android Open Source Project88b60792009-03-03 19:28:42 -08001238 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001239 echo "View the output by pointing your browser at http://localhost:7000/"
1240 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001241 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001242}
1243
1244function getbugreports()
1245{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001246 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001247
1248 if [ ! "$reports" ]; then
1249 echo "Could not locate any bugreports."
1250 return
1251 fi
1252
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001253 local report
1254 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001255 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001256 echo "/sdcard/bugreports/${report}"
1257 adb pull /sdcard/bugreports/${report} ${report}
1258 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001259 done
1260}
1261
Victoria Lease1b296b42012-08-21 15:44:06 -07001262function getsdcardpath()
1263{
1264 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1265}
1266
1267function getscreenshotpath()
1268{
1269 echo "$(getsdcardpath)/Pictures/Screenshots"
1270}
1271
1272function getlastscreenshot()
1273{
1274 local screenshot_path=$(getscreenshotpath)
1275 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1276 if [ "$screenshot" = "" ]; then
1277 echo "No screenshots found."
1278 return
1279 fi
1280 echo "${screenshot}"
1281 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1282}
1283
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001284function startviewserver()
1285{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001286 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001287 if [ $# -gt 0 ]; then
1288 port=$1
1289 fi
1290 adb shell service call window 1 i32 $port
1291}
1292
1293function stopviewserver()
1294{
1295 adb shell service call window 2
1296}
1297
1298function isviewserverstarted()
1299{
1300 adb shell service call window 3
1301}
1302
Romain Guyb84049a2010-10-04 16:56:11 -07001303function key_home()
1304{
1305 adb shell input keyevent 3
1306}
1307
1308function key_back()
1309{
1310 adb shell input keyevent 4
1311}
1312
1313function key_menu()
1314{
1315 adb shell input keyevent 82
1316}
1317
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001318function smoketest()
1319{
1320 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1321 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1322 return
1323 fi
1324 T=$(gettop)
1325 if [ ! "$T" ]; then
1326 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1327 return
1328 fi
1329
Ying Wang9cd17642012-12-13 10:52:07 -08001330 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001331 adb uninstall com.android.smoketest > /dev/null &&
1332 adb uninstall com.android.smoketest.tests > /dev/null &&
1333 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1334 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1335 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1336}
1337
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001338# simple shortcut to the runtest command
1339function runtest()
1340{
1341 T=$(gettop)
1342 if [ ! "$T" ]; then
1343 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1344 return
1345 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001346 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001347}
1348
The Android Open Source Project88b60792009-03-03 19:28:42 -08001349function godir () {
1350 if [[ -z "$1" ]]; then
1351 echo "Usage: godir <regex>"
1352 return
1353 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001354 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001355 if [[ ! -f $T/filelist ]]; then
1356 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001357 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001358 echo " Done"
1359 echo ""
1360 fi
1361 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001362 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001363 if [[ ${#lines[@]} = 0 ]]; then
1364 echo "Not found"
1365 return
1366 fi
1367 local pathname
1368 local choice
1369 if [[ ${#lines[@]} > 1 ]]; then
1370 while [[ -z "$pathname" ]]; do
1371 local index=1
1372 local line
1373 for line in ${lines[@]}; do
1374 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001375 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001376 done
1377 echo
1378 echo -n "Select one: "
1379 unset choice
1380 read choice
1381 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1382 echo "Invalid choice"
1383 continue
1384 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001385 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001386 done
1387 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001388 pathname=${lines[0]}
1389 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001390 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001391}
1392
Narayan Kamath9260bba2014-01-17 10:05:25 +00001393# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1394#
1395# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1396# For some reason, installing the JDK doesn't make it show up in the
1397# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001398function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001399 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001400 # we can reset it later, depending on the version of java the build
1401 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001402 #
1403 # If we don't do this, the JAVA_HOME value set by the first call to
1404 # build/envsetup.sh will persist forever.
1405 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1406 export JAVA_HOME=""
1407 fi
1408
Andy McFaddenbd960942010-06-24 12:52:51 -07001409 if [ ! "$JAVA_HOME" ]; then
Narayan Kamathc84889b2014-04-01 14:16:26 +01001410 if [ -n "$LEGACY_USE_JAVA6" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001411 case `uname -s` in
1412 Darwin)
1413 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1414 ;;
1415 *)
1416 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1417 ;;
1418 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001419 else
1420 case `uname -s` in
1421 Darwin)
Jason Parks30cfbd72014-04-28 13:32:10 -05001422 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
Narayan Kamath9260bba2014-01-17 10:05:25 +00001423 ;;
1424 *)
1425 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1426 ;;
1427 esac
1428 fi
1429
1430 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1431 # we can change it on the next envsetup.sh, if required.
1432 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001433 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001434}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001435
Alex Rayf0d08eb2013-03-08 15:15:06 -08001436# Print colored exit condition
1437function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001438 "$@"
1439 local retval=$?
1440 if [ $retval -ne 0 ]
1441 then
1442 echo -e "\e[0;31mFAILURE\e[00m"
1443 else
1444 echo -e "\e[0;32mSUCCESS\e[00m"
1445 fi
1446 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001447}
1448
Ed Heyl9e7b9b92014-06-18 14:55:58 -07001449function make()
1450{
1451 local start_time=$(date +"%s")
1452 $MAKE_UTIL $@
1453 local ret=$?
1454 local end_time=$(date +"%s")
1455 local tdiff=$(($end_time-$start_time))
1456 local hours=$(($tdiff / 3600 ))
1457 local mins=$((($tdiff % 3600) / 60))
1458 local secs=$(($tdiff % 60))
1459 echo
1460 if [ $ret -eq 0 ] ; then
1461 echo -n -e "\e[0;32m#### make completed successfully "
1462 else
1463 echo -n -e "\e[0;31m#### make failed to build some targets "
1464 fi
1465 if [ $hours -gt 0 ] ; then
1466 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1467 elif [ $mins -gt 0 ] ; then
1468 printf "(%02g:%02g (mm:ss))" $mins $secs
1469 elif [ $secs -gt 0 ] ; then
1470 printf "(%s seconds)" $secs
1471 fi
1472 echo -e " ####\e[00m"
1473 echo
1474 return $ret
1475}
1476
1477
1478
Raphael Moll70a86b02011-06-20 16:03:14 -07001479if [ "x$SHELL" != "x/bin/bash" ]; then
1480 case `ps -o command -p $$` in
1481 *bash*)
1482 ;;
1483 *)
1484 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1485 ;;
1486 esac
1487fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001488
1489# Execute the contents of any vendorsetup.sh files we can find.
Ying Wang506410a2014-07-09 15:37:34 -07001490for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1491 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001492do
1493 echo "including $f"
1494 . $f
1495done
1496unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001497
1498addcompletions