blob: 4fa74e67c2bfbefc26551e8abad47e55f0d1ab6c [file] [log] [blame]
Dan Albertf9631fd2015-02-12 11:14:39 -08001# These unsets should stay to clear the old functions from any long running
2# shells.
3# TODO(danalbert): Remove this in a day or so.
4unset -f gdbwrapper
5unset -f get_symbols_directory
6unset -f adb_get_product_device
7unset -f adb_get_traced_by
8unset -f gdbclient
9unset -f gdbclient_old
10
Scott Anderson1a5fc952012-03-07 17:15:06 -080011function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070012cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080013Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Ying Wang67f02922012-08-22 10:25:20 -070014- lunch: lunch <product_name>-<build_variant>
Ying Wangb541ab62014-05-29 17:57:40 -070015- 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 -070016- croot: Changes directory to the top of the tree.
17- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -080018- mm: Builds all of the modules in the current directory, but not their dependencies.
19- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000020 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080021- mma: Builds all of the modules in the current directory, and their dependencies.
22- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070023- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070024- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070025- jgrep: Greps on all local Java files.
26- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000027- mangrep: Greps on all local AndroidManifest.xml files.
28- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070029- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080030- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070031
Dan Albert4ae5d4b2014-10-31 16:23:08 -070032Environemnt options:
33- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
34 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
35 build is leak-check clean.
36
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070037Look at the source to view more functions. The complete list is:
38EOF
39 T=$(gettop)
40 local A
41 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070042 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070043 A="$A $i"
44 done
45 echo $A
46}
47
48# Get the value of a build variable as an absolute path.
49function get_abs_build_var()
50{
51 T=$(gettop)
52 if [ ! "$T" ]; then
53 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
54 return
55 fi
Ying Wang9cd17642012-12-13 10:52:07 -080056 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070057 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070058}
59
60# Get the exact value of a build variable.
61function get_build_var()
62{
63 T=$(gettop)
64 if [ ! "$T" ]; then
65 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
66 return
67 fi
Andrew Boie6905e212013-12-19 13:21:46 -080068 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070069 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080070}
71
72# check to see if the supplied product is one we can build
73function check_product()
74{
75 T=$(gettop)
76 if [ ! "$T" ]; then
77 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
78 return
79 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -070080 TARGET_PRODUCT=$1 \
81 TARGET_BUILD_VARIANT= \
82 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070083 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080084 get_build_var TARGET_DEVICE > /dev/null
85 # hide successful answers, but allow the errors to show
86}
87
88VARIANT_CHOICES=(user userdebug eng)
89
90# check to see if the supplied variant is valid
91function check_variant()
92{
93 for v in ${VARIANT_CHOICES[@]}
94 do
95 if [ "$v" = "$1" ]
96 then
97 return 0
98 fi
99 done
100 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700101}
102
103function setpaths()
104{
105 T=$(gettop)
106 if [ ! "$T" ]; then
107 echo "Couldn't locate the top of the tree. Try setting TOP."
108 return
109 fi
110
111 ##################################################################
112 # #
113 # Read me before you modify this code #
114 # #
115 # This function sets ANDROID_BUILD_PATHS to what it is adding #
116 # to PATH, and the next time it is run, it removes that from #
117 # PATH. This is required so lunch can be run more than once #
118 # and still have working paths. #
119 # #
120 ##################################################################
121
Raphael Mollc639c782011-06-20 17:25:01 -0700122 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
123 # due to "C:\Program Files" being in the path.
124
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700125 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700126 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700127 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
128 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700129 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700130 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800131 # strip leading ':', if any
132 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500133 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700134
135 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700136 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700137 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700138
Ben Cheng8bc4c432012-11-16 13:29:13 -0800139 # defined in core/config.mk
140 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700141 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800142 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800143
Raphael Mollc639c782011-06-20 17:25:01 -0700144 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800145 export ANDROID_TOOLCHAIN=
146 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200147 local ARCH=$(get_build_var TARGET_ARCH)
148 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400149 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700150 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400151 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
152 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800153 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200154 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800155 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700156 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700157 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700158 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000159 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200160 *)
161 echo "Can't find toolchain for unknown architecture: $ARCH"
162 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700163 ;;
164 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700165 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800166 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700167 fi
Raphael732936d2011-06-22 14:35:32 -0700168
Ben Chengfba67bf2014-02-25 10:27:07 -0800169 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
170 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
171 fi
172
173 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700174 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700175 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800176 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800177 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700178 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100179 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
180 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700181 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700182 ;;
183 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700184 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700185 ;;
186 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700187
Ying Wang564f9122013-03-29 17:40:14 -0700188 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wang2a859d52014-06-30 10:25:33 -0700189 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 +0200190
191 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
192 # to ensure that the corresponding 'emulator' binaries are used.
193 case $(uname -s) in
194 Darwin)
195 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
196 ;;
197 Linux)
198 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
199 ;;
200 *)
201 ANDROID_EMULATOR_PREBUILTS=
202 ;;
203 esac
204 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700205 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200206 export ANDROID_EMULATOR_PREBUILTS
207 fi
208
Ying Wangaa1c9b52012-11-26 20:51:59 -0800209 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800210
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500211 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900212 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500213 if [ -n "$JAVA_HOME" ]; then
214 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900215 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
216 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500217 fi
218
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800219 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700220 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
221 export OUT=$ANDROID_PRODUCT_OUT
222
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700223 unset ANDROID_HOST_OUT
224 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
225
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800226 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700227 # TODO: fix the path
228 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
229}
230
231function printconfig()
232{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800233 T=$(gettop)
234 if [ ! "$T" ]; then
235 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
236 return
237 fi
238 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700239}
240
241function set_stuff_for_environment()
242{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800243 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500244 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800245 setpaths
246 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700247
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800248 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700249 # With this environment variable new GCC can apply colors to warnings/errors
250 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
Dan Albert4ae5d4b2014-10-31 16:23:08 -0700251 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700252}
253
254function set_sequence_number()
255{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700256 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700257}
258
259function settitle()
260{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800261 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700262 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700263 local product=$TARGET_PRODUCT
264 local variant=$TARGET_BUILD_VARIANT
265 local apps=$TARGET_BUILD_APPS
266 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700267 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700268 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700269 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700270 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800271 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700272}
273
Kenny Root52aa81c2011-07-15 11:07:06 -0700274function addcompletions()
275{
276 local T dir f
277
278 # Keep us from trying to run in something that isn't bash.
279 if [ -z "${BASH_VERSION}" ]; then
280 return
281 fi
282
283 # Keep us from trying to run in bash that's too old.
284 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
285 return
286 fi
287
288 dir="sdk/bash_completion"
289 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700290 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700291 echo "including $f"
292 . $f
293 done
294 fi
295}
296
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297function choosetype()
298{
299 echo "Build type choices are:"
300 echo " 1. release"
301 echo " 2. debug"
302 echo
303
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800304 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700305 DEFAULT_NUM=1
306 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700307
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800308 export TARGET_BUILD_TYPE=
309 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700310 while [ -z $TARGET_BUILD_TYPE ]
311 do
312 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800313 if [ -z "$1" ] ; then
314 read ANSWER
315 else
316 echo $1
317 ANSWER=$1
318 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319 case $ANSWER in
320 "")
321 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
322 ;;
323 1)
324 export TARGET_BUILD_TYPE=release
325 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800326 release)
327 export TARGET_BUILD_TYPE=release
328 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700329 2)
330 export TARGET_BUILD_TYPE=debug
331 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332 debug)
333 export TARGET_BUILD_TYPE=debug
334 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335 *)
336 echo
337 echo "I didn't understand your response. Please try again."
338 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339 ;;
340 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800341 if [ -n "$1" ] ; then
342 break
343 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700344 done
345
346 set_stuff_for_environment
347}
348
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800349#
350# This function isn't really right: It chooses a TARGET_PRODUCT
351# based on the list of boards. Usually, that gets you something
352# that kinda works with a generic product, but really, you should
353# pick a product by name.
354#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700355function chooseproduct()
356{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700357 if [ "x$TARGET_PRODUCT" != x ] ; then
358 default_value=$TARGET_PRODUCT
359 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700360 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700361 fi
362
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800363 export TARGET_PRODUCT=
364 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700365 while [ -z "$TARGET_PRODUCT" ]
366 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700367 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800368 if [ -z "$1" ] ; then
369 read ANSWER
370 else
371 echo $1
372 ANSWER=$1
373 fi
374
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700375 if [ -z "$ANSWER" ] ; then
376 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800377 else
378 if check_product $ANSWER
379 then
380 export TARGET_PRODUCT=$ANSWER
381 else
382 echo "** Not a valid product: $ANSWER"
383 fi
384 fi
385 if [ -n "$1" ] ; then
386 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700387 fi
388 done
389
390 set_stuff_for_environment
391}
392
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800393function choosevariant()
394{
395 echo "Variant choices are:"
396 local index=1
397 local v
398 for v in ${VARIANT_CHOICES[@]}
399 do
400 # The product name is the name of the directory containing
401 # the makefile we found, above.
402 echo " $index. $v"
403 index=$(($index+1))
404 done
405
406 local default_value=eng
407 local ANSWER
408
409 export TARGET_BUILD_VARIANT=
410 while [ -z "$TARGET_BUILD_VARIANT" ]
411 do
412 echo -n "Which would you like? [$default_value] "
413 if [ -z "$1" ] ; then
414 read ANSWER
415 else
416 echo $1
417 ANSWER=$1
418 fi
419
420 if [ -z "$ANSWER" ] ; then
421 export TARGET_BUILD_VARIANT=$default_value
422 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
423 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800424 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800425 fi
426 else
427 if check_variant $ANSWER
428 then
429 export TARGET_BUILD_VARIANT=$ANSWER
430 else
431 echo "** Not a valid variant: $ANSWER"
432 fi
433 fi
434 if [ -n "$1" ] ; then
435 break
436 fi
437 done
438}
439
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700440function choosecombo()
441{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700442 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700443
444 echo
445 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700446 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700447
448 echo
449 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700450 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800451
452 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700453 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800454 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700455}
456
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800457# Clear this variable. It will be built up again when the vendorsetup.sh
458# files are included at the end of this file.
459unset LUNCH_MENU_CHOICES
460function add_lunch_combo()
461{
462 local new_combo=$1
463 local c
464 for c in ${LUNCH_MENU_CHOICES[@]} ; do
465 if [ "$new_combo" = "$c" ] ; then
466 return
467 fi
468 done
469 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
470}
471
472# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700473add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800474add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000475add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800476add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000477add_lunch_combo aosp_x86-eng
478add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700480function print_lunch_menu()
481{
482 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483 echo
484 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700485 echo
486 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800487
488 local i=1
489 local choice
490 for choice in ${LUNCH_MENU_CHOICES[@]}
491 do
492 echo " $i. $choice"
493 i=$(($i+1))
494 done
495
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700496 echo
497}
498
499function lunch()
500{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800501 local answer
502
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700503 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700505 else
506 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700507 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800508 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700509 fi
510
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 local selection=
512
513 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700514 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700515 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800516 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
517 then
518 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
519 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800520 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521 fi
522 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
523 then
524 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700525 fi
526
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800527 if [ -z "$selection" ]
528 then
529 echo
530 echo "Invalid lunch combo: $answer"
531 return 1
532 fi
533
Joe Onoratoda12daf2010-06-09 18:18:31 -0700534 export TARGET_BUILD_APPS=
535
Jeff Browne33ba4c2011-07-11 22:11:46 -0700536 local product=$(echo -n $selection | sed -e "s/-.*$//")
537 check_product $product
538 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800539 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700540 echo
541 echo "** Don't have a product spec for: '$product'"
542 echo "** Do you have the right repo manifest?"
543 product=
544 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800545
Jeff Browne33ba4c2011-07-11 22:11:46 -0700546 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
547 check_variant $variant
548 if [ $? -ne 0 ]
549 then
550 echo
551 echo "** Invalid variant: '$variant'"
552 echo "** Must be one of ${VARIANT_CHOICES[@]}"
553 variant=
554 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800555
Jeff Browne33ba4c2011-07-11 22:11:46 -0700556 if [ -z "$product" -o -z "$variant" ]
557 then
558 echo
559 return 1
560 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800561
Jeff Browne33ba4c2011-07-11 22:11:46 -0700562 export TARGET_PRODUCT=$product
563 export TARGET_BUILD_VARIANT=$variant
564 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700565
566 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800567
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700568 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800569 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700570}
571
Jeff Davidson513d7a42010-08-02 10:00:44 -0700572# Tab completion for lunch.
573function _lunch()
574{
575 local cur prev opts
576 COMPREPLY=()
577 cur="${COMP_WORDS[COMP_CWORD]}"
578 prev="${COMP_WORDS[COMP_CWORD-1]}"
579
580 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
581 return 0
582}
583complete -F _lunch lunch
584
Joe Onoratoda12daf2010-06-09 18:18:31 -0700585# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700586# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700587function tapas()
588{
Ying Wangb541ab62014-05-29 17:57:40 -0700589 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 -0700590 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700591 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
592 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700593
Ying Wang67f02922012-08-22 10:25:20 -0700594 if [ $(echo $arch | wc -w) -gt 1 ]; then
595 echo "tapas: Error: Multiple build archs supplied: $arch"
596 return
597 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700598 if [ $(echo $variant | wc -w) -gt 1 ]; then
599 echo "tapas: Error: Multiple build variants supplied: $variant"
600 return
601 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700602 if [ $(echo $density | wc -w) -gt 1 ]; then
603 echo "tapas: Error: Multiple densities supplied: $density"
604 return
605 fi
Ying Wang67f02922012-08-22 10:25:20 -0700606
607 local product=full
608 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700609 x86) product=full_x86;;
610 mips) product=full_mips;;
611 armv5) product=generic_armv5;;
612 arm64) product=aosp_arm64;;
613 x86_64) product=aosp_x86_64;;
614 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700615 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700616 if [ -z "$variant" ]; then
617 variant=eng
618 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700619 if [ -z "$apps" ]; then
620 apps=all
621 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600622 if [ -z "$density" ]; then
623 density=alldpi
624 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700625
Ying Wang67f02922012-08-22 10:25:20 -0700626 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700627 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700628 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700629 export TARGET_BUILD_TYPE=release
630 export TARGET_BUILD_APPS=$apps
631
632 set_stuff_for_environment
633 printconfig
634}
635
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700636function gettop
637{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800638 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700639 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700640 # The following circumlocution ensures we remove symlinks from TOP.
641 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700642 else
643 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800644 # The following circumlocution (repeated below as well) ensures
645 # that we record the true directory name and not one that is
646 # faked up with symlink names.
647 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700648 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800649 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700650 T=
651 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800652 \cd ..
synergyb112a402013-07-05 19:47:47 -0700653 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700654 done
Ying Wang9cd17642012-12-13 10:52:07 -0800655 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700656 if [ -f "$T/$TOPFILE" ]; then
657 echo $T
658 fi
659 fi
660 fi
661}
662
Andrew Hsieh906cb782013-09-10 17:37:14 +0800663# Return driver for "make", if any (eg. static analyzer)
664function getdriver()
665{
666 local T="$1"
667 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
668 if [ -n "$WITH_STATIC_ANALYZER" ]; then
669 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800670$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
671--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800672--status-bugs \
673--top=$T"
674 fi
675}
676
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700677function m()
678{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800679 local T=$(gettop)
680 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700681 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800682 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700683 else
684 echo "Couldn't locate the top of the tree. Try setting TOP."
685 fi
686}
687
688function findmakefile()
689{
690 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800691 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700692 T=
693 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700694 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700695 if [ -f "$T/Android.mk" ]; then
696 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800697 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700698 return
699 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800700 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700701 done
Ying Wang9cd17642012-12-13 10:52:07 -0800702 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700703}
704
705function mm()
706{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800707 local T=$(gettop)
708 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700709 # If we're sitting in the root of the build tree, just do a
710 # normal make.
711 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800712 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700713 else
714 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800715 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700716 local MODULES=
717 local GET_INSTALL_PATH=
718 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700719 # Remove the path to top as the makefilepath needs to be relative
720 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700721 if [ ! "$T" ]; then
722 echo "Couldn't locate the top of the tree. Try setting TOP."
723 elif [ ! "$M" ]; then
724 echo "Couldn't locate a makefile from the current directory."
725 else
Ying Wanga7deb082013-08-16 13:24:47 -0700726 for ARG in $@; do
727 case $ARG in
728 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
729 esac
730 done
731 if [ -n "$GET_INSTALL_PATH" ]; then
732 MODULES=
733 ARGS=GET-INSTALL-PATH
734 else
735 MODULES=all_modules
736 ARGS=$@
737 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700738 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 -0700739 fi
740 fi
741}
742
743function mmm()
744{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800745 local T=$(gettop)
746 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700747 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800748 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800749 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800750 local ARGS=
751 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700752 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800753 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
754 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
755 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800756 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
757 if [ "$MODULES" = "" ]; then
758 MODULES=all_modules
759 fi
760 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700761 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700762 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
763 local TO_CHOP=`expr $TO_CHOP + 1`
764 local START=`PWD= /bin/pwd`
765 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700766 if [ "$MFILE" = "" ] ; then
767 MFILE=$DIR/Android.mk
768 else
769 MFILE=$MFILE/$DIR/Android.mk
770 fi
771 MAKEFILE="$MAKEFILE $MFILE"
772 else
Ying Wanga7deb082013-08-16 13:24:47 -0700773 case $DIR in
774 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
775 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
776 *) echo "No Android.mk in $DIR."; return 1;;
777 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700778 fi
779 done
Ying Wanga7deb082013-08-16 13:24:47 -0700780 if [ -n "$GET_INSTALL_PATH" ]; then
781 ARGS=$GET_INSTALL_PATH
782 MODULES=
783 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800784 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 -0700785 else
786 echo "Couldn't locate the top of the tree. Try setting TOP."
787 fi
788}
789
Ying Wangb607f7b2013-02-08 18:01:04 -0800790function mma()
791{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800792 local T=$(gettop)
793 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800794 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800795 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800796 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800797 if [ ! "$T" ]; then
798 echo "Couldn't locate the top of the tree. Try setting TOP."
799 fi
800 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800801 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800802 fi
803}
804
805function mmma()
806{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800807 local T=$(gettop)
808 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800809 if [ "$T" ]; then
810 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
811 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
812 local MY_PWD=`PWD= /bin/pwd`
813 if [ "$MY_PWD" = "$T" ]; then
814 MY_PWD=
815 else
816 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
817 fi
818 local DIR=
819 local MODULE_PATHS=
820 local ARGS=
821 for DIR in $DIRS ; do
822 if [ -d $DIR ]; then
823 if [ "$MY_PWD" = "" ]; then
824 MODULE_PATHS="$MODULE_PATHS $DIR"
825 else
826 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
827 fi
828 else
829 case $DIR in
830 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
831 *) echo "Couldn't find directory $DIR"; return 1;;
832 esac
833 fi
834 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800835 $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 -0800836 else
837 echo "Couldn't locate the top of the tree. Try setting TOP."
838 fi
839}
840
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700841function croot()
842{
843 T=$(gettop)
844 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800845 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700846 else
847 echo "Couldn't locate the top of the tree. Try setting TOP."
848 fi
849}
850
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700851function cproj()
852{
853 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700854 local HERE=$PWD
855 T=
856 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
857 T=$PWD
858 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800859 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700860 return
861 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800862 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700863 done
Ying Wang9cd17642012-12-13 10:52:07 -0800864 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700865 echo "can't find Android.mk"
866}
867
Daniel Sandler47e0a882013-07-30 13:23:52 -0400868# simplified version of ps; output in the form
869# <pid> <procname>
870function qpid() {
871 local prepend=''
872 local append=''
873 if [ "$1" = "--exact" ]; then
874 prepend=' '
875 append='$'
876 shift
877 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
878 echo "usage: qpid [[--exact] <process name|pid>"
879 return 255
880 fi
881
882 local EXE="$1"
883 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700884 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400885 else
886 adb shell ps \
887 | tr -d '\r' \
888 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
889 fi
890}
891
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700892function pid()
893{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400894 local prepend=''
895 local append=''
896 if [ "$1" = "--exact" ]; then
897 prepend=' '
898 append='$'
899 shift
900 fi
901 local EXE="$1"
902 if [ "$EXE" ] ; then
903 local PID=`adb shell ps \
904 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700905 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400906 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
907 echo "$PID"
908 else
909 echo "usage: pid [--exact] <process name>"
910 return 255
911 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700912}
913
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800914# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700915# that has the core-file-size limit set correctly
916#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800917# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700918# if its core-file-size limit is not set already.
919# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
920
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800921function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700922{
923 echo "Getting root...";
924 adb root;
925 adb wait-for-device;
926
927 echo "Remounting root parition read-write...";
928 adb shell mount -w -o remount -t rootfs rootfs;
929 sleep 1;
930 adb wait-for-device;
931 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -0800932 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700933 adb shell chmod 0777 /cores;
934
935 echo "Granting SELinux permission to dump in /cores...";
936 adb shell restorecon -R /cores;
937
938 echo "Set core pattern.";
939 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
940
941 echo "Done."
942}
943
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800944# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700945# $1 = PID of process (e.g., $(pid mediaserver))
946#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800947# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700948# dump to actually be generated.
949
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800950function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700951{
952 local PID=$1;
953 if [ -z "$PID" ]; then
954 printf "Expecting a PID!\n";
955 return;
956 fi;
957 echo "Setting core limit for $PID to infinite...";
958 adb shell prlimit $PID 4 -1 -1
959}
960
961# core - send SIGV and pull the core for process
962# $1 = PID of process (e.g., $(pid mediaserver))
963#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800964# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700965# enabled globally.
966
967function core()
968{
969 local PID=$1;
970
971 if [ -z "$PID" ]; then
972 printf "Expecting a PID!\n";
973 return;
974 fi;
975
976 local CORENAME=core.$PID;
977 local COREPATH=/cores/$CORENAME;
978 local SIG=SEGV;
979
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800980 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700981
982 local done=0;
983 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
984 printf "\tSending SIG%s to %d...\n" $SIG $PID;
985 adb shell kill -$SIG $PID;
986 sleep 1;
987 done;
988
989 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
990 echo "Done: core is under $COREPATH on device.";
991}
992
Christopher Tate744ee802009-11-12 15:33:08 -0800993# systemstack - dump the current stack trace of all threads in the system process
994# to the usual ANR traces file
995function systemstack()
996{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800997 stacks system_server
998}
999
1000function stacks()
1001{
1002 if [[ $1 =~ ^[0-9]+$ ]] ; then
1003 local PID="$1"
1004 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001005 local PIDLIST="$(pid $1)"
1006 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1007 local PID="$PIDLIST"
1008 elif [ "$PIDLIST" ] ; then
1009 echo "more than one process: $1"
1010 else
1011 echo "no such process: $1"
1012 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001013 else
1014 echo "usage: stacks [pid|process name]"
1015 fi
1016
1017 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001018 # Determine whether the process is native
1019 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1020 # Dump stacks of Dalvik process
1021 local TRACES=/data/anr/traces.txt
1022 local ORIG=/data/anr/traces.orig
1023 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001024
Jeff Brownb12c2e52013-08-19 15:14:16 -07001025 # Keep original traces to avoid clobbering
1026 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001027
Jeff Brownb12c2e52013-08-19 15:14:16 -07001028 # Make sure we have a usable file
1029 adb shell touch $TRACES
1030 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001031
Jeff Brownb12c2e52013-08-19 15:14:16 -07001032 # Dump stacks and wait for dump to finish
1033 adb shell kill -3 $PID
1034 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001035
Jeff Brownb12c2e52013-08-19 15:14:16 -07001036 # Restore original stacks, and show current output
1037 adb shell mv $TRACES $TMP
1038 adb shell mv $ORIG $TRACES
1039 adb shell cat $TMP
1040 else
1041 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001042 local USE64BIT="$(is64bit $PID)"
1043 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001044 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001045 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001046}
1047
Michael Wrightaeed7212014-06-19 19:58:12 -07001048# Read the ELF header from /proc/$PID/exe to determine if the process is
1049# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001050function is64bit()
1051{
1052 local PID="$1"
1053 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001054 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001055 echo "64"
1056 else
1057 echo ""
1058 fi
1059 else
1060 echo ""
1061 fi
1062}
1063
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001064case `uname -s` in
1065 Darwin)
1066 function sgrep()
1067 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001068 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001069 }
1070
1071 ;;
1072 *)
1073 function sgrep()
1074 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001075 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001076 }
1077 ;;
1078esac
1079
Raghu Gandham8da43102012-07-25 19:57:22 -07001080function gettargetarch
1081{
1082 get_build_var TARGET_ARCH
1083}
1084
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001085function ggrep()
1086{
1087 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1088}
1089
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001090function jgrep()
1091{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001092 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 -07001093}
1094
1095function cgrep()
1096{
Dan Albert01961192014-11-22 10:16:01 -08001097 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' -o -name '*.hpp' \) -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001098}
1099
1100function resgrep()
1101{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001102 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 -07001103}
1104
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001105function mangrep()
1106{
1107 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1108}
1109
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001110function sepgrep()
1111{
1112 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 "$@"
1113}
1114
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001115case `uname -s` in
1116 Darwin)
1117 function mgrep()
1118 {
Ying Wang324c2b22012-08-17 15:03:20 -07001119 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 -07001120 }
1121
1122 function treegrep()
1123 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001124 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 -07001125 }
1126
1127 ;;
1128 *)
1129 function mgrep()
1130 {
Ying Wang324c2b22012-08-17 15:03:20 -07001131 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 -07001132 }
1133
1134 function treegrep()
1135 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001136 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 -07001137 }
1138
1139 ;;
1140esac
1141
1142function getprebuilt
1143{
1144 get_abs_build_var ANDROID_PREBUILTS
1145}
1146
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001147function tracedmdump()
1148{
1149 T=$(gettop)
1150 if [ ! "$T" ]; then
1151 echo "Couldn't locate the top of the tree. Try setting TOP."
1152 return
1153 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001154 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001155 local arch=$(gettargetarch)
1156 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001157
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001158 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001159 if [ ! "$TRACE" ] ; then
1160 echo "usage: tracedmdump tracename"
1161 return
1162 fi
1163
Jack Veenstra60116fc2009-04-09 18:12:34 -07001164 if [ ! -r "$KERNEL" ] ; then
1165 echo "Error: cannot find kernel: '$KERNEL'"
1166 return
1167 fi
1168
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001169 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001170 if [ "$BASETRACE" = "$TRACE" ] ; then
1171 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1172 fi
1173
1174 echo "post-processing traces..."
1175 rm -f $TRACE/qtrace.dexlist
1176 post_trace $TRACE
1177 if [ $? -ne 0 ]; then
1178 echo "***"
1179 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1180 echo "***"
1181 return
1182 fi
1183 echo "generating dexlist output..."
1184 /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
1185 echo "generating dmtrace data..."
1186 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1187 echo "generating html file..."
1188 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1189 echo "done, see $TRACE/dmtrace.html for details"
1190 echo "or run:"
1191 echo " traceview $TRACE/dmtrace"
1192}
1193
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001194# communicate with a running device or emulator, set up necessary state,
1195# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001196function runhat()
1197{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001198 # process standard adb options
1199 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001200 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001201 adbTarget=$1
1202 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001203 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001204 adbTarget="$1 $2"
1205 shift 2
1206 fi
1207 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001208 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001209
1210 # runhat options
1211 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001212
1213 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001214 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001215 return
1216 fi
1217
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001218 # confirm hat is available
1219 if [ -z $(which hat) ]; then
1220 echo "hat is not available in this configuration."
1221 return
1222 fi
1223
Andy McFaddenb6289852010-07-12 08:00:19 -07001224 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001225 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001226 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001227 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001228 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001229 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001230 echo -n "> "
1231 read
1232
The Android Open Source Project88b60792009-03-03 19:28:42 -08001233 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001234
The Android Open Source Project88b60792009-03-03 19:28:42 -08001235 echo "Retrieving file $devFile..."
1236 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001237
The Android Open Source Project88b60792009-03-03 19:28:42 -08001238 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001239
The Android Open Source Project88b60792009-03-03 19:28:42 -08001240 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001241 echo "View the output by pointing your browser at http://localhost:7000/"
1242 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001243 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001244}
1245
1246function getbugreports()
1247{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001248 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001249
1250 if [ ! "$reports" ]; then
1251 echo "Could not locate any bugreports."
1252 return
1253 fi
1254
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001255 local report
1256 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001257 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001258 echo "/sdcard/bugreports/${report}"
1259 adb pull /sdcard/bugreports/${report} ${report}
1260 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001261 done
1262}
1263
Victoria Lease1b296b42012-08-21 15:44:06 -07001264function getsdcardpath()
1265{
1266 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1267}
1268
1269function getscreenshotpath()
1270{
1271 echo "$(getsdcardpath)/Pictures/Screenshots"
1272}
1273
1274function getlastscreenshot()
1275{
1276 local screenshot_path=$(getscreenshotpath)
1277 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1278 if [ "$screenshot" = "" ]; then
1279 echo "No screenshots found."
1280 return
1281 fi
1282 echo "${screenshot}"
1283 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1284}
1285
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001286function startviewserver()
1287{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001288 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001289 if [ $# -gt 0 ]; then
1290 port=$1
1291 fi
1292 adb shell service call window 1 i32 $port
1293}
1294
1295function stopviewserver()
1296{
1297 adb shell service call window 2
1298}
1299
1300function isviewserverstarted()
1301{
1302 adb shell service call window 3
1303}
1304
Romain Guyb84049a2010-10-04 16:56:11 -07001305function key_home()
1306{
1307 adb shell input keyevent 3
1308}
1309
1310function key_back()
1311{
1312 adb shell input keyevent 4
1313}
1314
1315function key_menu()
1316{
1317 adb shell input keyevent 82
1318}
1319
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001320function smoketest()
1321{
1322 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1323 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1324 return
1325 fi
1326 T=$(gettop)
1327 if [ ! "$T" ]; then
1328 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1329 return
1330 fi
1331
Ying Wang9cd17642012-12-13 10:52:07 -08001332 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001333 adb uninstall com.android.smoketest > /dev/null &&
1334 adb uninstall com.android.smoketest.tests > /dev/null &&
1335 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1336 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1337 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1338}
1339
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001340# simple shortcut to the runtest command
1341function runtest()
1342{
1343 T=$(gettop)
1344 if [ ! "$T" ]; then
1345 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1346 return
1347 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001348 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001349}
1350
The Android Open Source Project88b60792009-03-03 19:28:42 -08001351function godir () {
1352 if [[ -z "$1" ]]; then
1353 echo "Usage: godir <regex>"
1354 return
1355 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001356 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001357 if [[ ! -f $T/filelist ]]; then
1358 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001359 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001360 echo " Done"
1361 echo ""
1362 fi
1363 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001364 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001365 if [[ ${#lines[@]} = 0 ]]; then
1366 echo "Not found"
1367 return
1368 fi
1369 local pathname
1370 local choice
1371 if [[ ${#lines[@]} > 1 ]]; then
1372 while [[ -z "$pathname" ]]; do
1373 local index=1
1374 local line
1375 for line in ${lines[@]}; do
1376 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001377 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001378 done
1379 echo
1380 echo -n "Select one: "
1381 unset choice
1382 read choice
1383 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1384 echo "Invalid choice"
1385 continue
1386 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001387 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001388 done
1389 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001390 pathname=${lines[0]}
1391 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001392 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001393}
1394
Neil Fuller46e00ea2014-10-16 10:23:03 +01001395# Force JAVA_HOME to point to java 1.7 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001396#
1397# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1398# For some reason, installing the JDK doesn't make it show up in the
1399# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001400function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001401 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001402 # we can reset it later, depending on the version of java the build
1403 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001404 #
1405 # If we don't do this, the JAVA_HOME value set by the first call to
1406 # build/envsetup.sh will persist forever.
1407 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1408 export JAVA_HOME=""
1409 fi
1410
Andy McFaddenbd960942010-06-24 12:52:51 -07001411 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01001412 case `uname -s` in
1413 Darwin)
1414 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1415 ;;
1416 *)
1417 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1418 ;;
1419 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001420
1421 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1422 # we can change it on the next envsetup.sh, if required.
1423 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001424 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001425}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001426
Alex Rayf0d08eb2013-03-08 15:15:06 -08001427# Print colored exit condition
1428function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001429 "$@"
1430 local retval=$?
1431 if [ $retval -ne 0 ]
1432 then
1433 echo -e "\e[0;31mFAILURE\e[00m"
1434 else
1435 echo -e "\e[0;32mSUCCESS\e[00m"
1436 fi
1437 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001438}
1439
Ying Wanged21d4c2014-08-24 22:14:19 -07001440function get_make_command()
1441{
1442 echo command make
1443}
1444
Ed Heylcc6be0a2014-06-18 14:55:58 -07001445function make()
1446{
1447 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001448 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001449 local ret=$?
1450 local end_time=$(date +"%s")
1451 local tdiff=$(($end_time-$start_time))
1452 local hours=$(($tdiff / 3600 ))
1453 local mins=$((($tdiff % 3600) / 60))
1454 local secs=$(($tdiff % 60))
1455 echo
1456 if [ $ret -eq 0 ] ; then
Dan Albertb59995d2014-11-08 22:41:52 -08001457 if [ $(uname) != "Darwin" ]; then
1458 echo -n -e "\e[0;32m#### make completed successfully "
1459 else
1460 echo -n -e "#### make completed successfully "
1461 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001462 else
Dan Albertb59995d2014-11-08 22:41:52 -08001463 if [ $(uname) != "Darwin" ]; then
1464 echo -n -e "\e[0;31m#### make failed to build some targets "
1465 else
1466 echo -n -e "#### make failed to build some targets "
1467 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001468 fi
1469 if [ $hours -gt 0 ] ; then
1470 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1471 elif [ $mins -gt 0 ] ; then
1472 printf "(%02g:%02g (mm:ss))" $mins $secs
1473 elif [ $secs -gt 0 ] ; then
1474 printf "(%s seconds)" $secs
1475 fi
Dan Albertb59995d2014-11-08 22:41:52 -08001476 if [ $(uname) != "Darwin" ]; then
1477 echo -e " ####\e[00m"
1478 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001479 echo
1480 return $ret
1481}
1482
Raphael Moll70a86b02011-06-20 16:03:14 -07001483if [ "x$SHELL" != "x/bin/bash" ]; then
1484 case `ps -o command -p $$` in
1485 *bash*)
1486 ;;
1487 *)
1488 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1489 ;;
1490 esac
1491fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001492
1493# Execute the contents of any vendorsetup.sh files we can find.
Ying Wang506410a2014-07-09 15:37:34 -07001494for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1495 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001496do
1497 echo "including $f"
1498 . $f
1499done
1500unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001501
1502addcompletions