blob: 8b8d63b35840f96cebf0a45fb9114eefc7400d1d [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Ying Wang67f02922012-08-22 10:25:20 -07004- lunch: lunch <product_name>-<build_variant>
Ying Wangb541ab62014-05-29 17:57:40 -07005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07006- croot: Changes directory to the top of the tree.
7- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08008- mm: Builds all of the modules in the current directory, but not their dependencies.
9- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000010 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080011- mma: Builds all of the modules in the current directory, and their dependencies.
12- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070013- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070014- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070015- jgrep: Greps on all local Java files.
16- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000017- mangrep: Greps on all local AndroidManifest.xml files.
18- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070019- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080020- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070021
Dan Albert4ae5d4b2014-10-31 16:23:08 -070022Environemnt options:
23- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
24 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
25 build is leak-check clean.
26
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070027Look at the source to view more functions. The complete list is:
28EOF
29 T=$(gettop)
30 local A
31 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070032 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 -070033 A="$A $i"
34 done
35 echo $A
36}
37
38# Get the value of a build variable as an absolute path.
39function get_abs_build_var()
40{
41 T=$(gettop)
42 if [ ! "$T" ]; then
43 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
44 return
45 fi
Ying Wang9cd17642012-12-13 10:52:07 -080046 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070047 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070048}
49
50# Get the exact value of a build variable.
51function get_build_var()
52{
53 T=$(gettop)
54 if [ ! "$T" ]; then
55 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
56 return
57 fi
Andrew Boie6905e212013-12-19 13:21:46 -080058 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070059 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080060}
61
62# check to see if the supplied product is one we can build
63function check_product()
64{
65 T=$(gettop)
66 if [ ! "$T" ]; then
67 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
68 return
69 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -070070 TARGET_PRODUCT=$1 \
71 TARGET_BUILD_VARIANT= \
72 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070073 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080074 get_build_var TARGET_DEVICE > /dev/null
75 # hide successful answers, but allow the errors to show
76}
77
78VARIANT_CHOICES=(user userdebug eng)
79
80# check to see if the supplied variant is valid
81function check_variant()
82{
83 for v in ${VARIANT_CHOICES[@]}
84 do
85 if [ "$v" = "$1" ]
86 then
87 return 0
88 fi
89 done
90 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070091}
92
93function setpaths()
94{
95 T=$(gettop)
96 if [ ! "$T" ]; then
97 echo "Couldn't locate the top of the tree. Try setting TOP."
98 return
99 fi
100
101 ##################################################################
102 # #
103 # Read me before you modify this code #
104 # #
105 # This function sets ANDROID_BUILD_PATHS to what it is adding #
106 # to PATH, and the next time it is run, it removes that from #
107 # PATH. This is required so lunch can be run more than once #
108 # and still have working paths. #
109 # #
110 ##################################################################
111
Raphael Mollc639c782011-06-20 17:25:01 -0700112 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
113 # due to "C:\Program Files" being in the path.
114
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700115 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700116 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700117 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
118 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700119 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700120 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800121 # strip leading ':', if any
122 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500123 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700124
125 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700126 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700127 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700128
Ben Cheng8bc4c432012-11-16 13:29:13 -0800129 # defined in core/config.mk
130 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700131 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800132 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800133
Raphael Mollc639c782011-06-20 17:25:01 -0700134 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800135 export ANDROID_TOOLCHAIN=
136 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200137 local ARCH=$(get_build_var TARGET_ARCH)
138 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400139 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700140 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400141 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
142 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800143 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200144 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800145 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700146 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700147 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700148 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000149 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200150 *)
151 echo "Can't find toolchain for unknown architecture: $ARCH"
152 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700153 ;;
154 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700155 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800156 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700157 fi
Raphael732936d2011-06-22 14:35:32 -0700158
Ben Chengfba67bf2014-02-25 10:27:07 -0800159 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
160 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
161 fi
162
163 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700164 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700165 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800166 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800167 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700168 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100169 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
170 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700171 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700172 ;;
173 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700174 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700175 ;;
176 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700177
Ying Wang564f9122013-03-29 17:40:14 -0700178 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wang2a859d52014-06-30 10:25:33 -0700179 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 +0200180
181 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
182 # to ensure that the corresponding 'emulator' binaries are used.
183 case $(uname -s) in
184 Darwin)
185 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
186 ;;
187 Linux)
188 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
189 ;;
190 *)
191 ANDROID_EMULATOR_PREBUILTS=
192 ;;
193 esac
194 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700195 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200196 export ANDROID_EMULATOR_PREBUILTS
197 fi
198
Ying Wangaa1c9b52012-11-26 20:51:59 -0800199 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800200
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500201 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900202 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500203 if [ -n "$JAVA_HOME" ]; then
204 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900205 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
206 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500207 fi
208
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800209 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700210 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
211 export OUT=$ANDROID_PRODUCT_OUT
212
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700213 unset ANDROID_HOST_OUT
214 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
215
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800216 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700217 # TODO: fix the path
218 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
219}
220
221function printconfig()
222{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800223 T=$(gettop)
224 if [ ! "$T" ]; then
225 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
226 return
227 fi
228 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700229}
230
231function set_stuff_for_environment()
232{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800233 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500234 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800235 setpaths
236 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700237
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800238 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700239 # With this environment variable new GCC can apply colors to warnings/errors
240 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 -0700241 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700242}
243
244function set_sequence_number()
245{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700246 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700247}
248
249function settitle()
250{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700252 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700253 local product=$TARGET_PRODUCT
254 local variant=$TARGET_BUILD_VARIANT
255 local apps=$TARGET_BUILD_APPS
256 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700257 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700258 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700259 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700260 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800261 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700262}
263
Kenny Root52aa81c2011-07-15 11:07:06 -0700264function addcompletions()
265{
266 local T dir f
267
268 # Keep us from trying to run in something that isn't bash.
269 if [ -z "${BASH_VERSION}" ]; then
270 return
271 fi
272
273 # Keep us from trying to run in bash that's too old.
274 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
275 return
276 fi
277
278 dir="sdk/bash_completion"
279 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700280 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700281 echo "including $f"
282 . $f
283 done
284 fi
285}
286
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700287function choosetype()
288{
289 echo "Build type choices are:"
290 echo " 1. release"
291 echo " 2. debug"
292 echo
293
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800294 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700295 DEFAULT_NUM=1
296 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800298 export TARGET_BUILD_TYPE=
299 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300 while [ -z $TARGET_BUILD_TYPE ]
301 do
302 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303 if [ -z "$1" ] ; then
304 read ANSWER
305 else
306 echo $1
307 ANSWER=$1
308 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309 case $ANSWER in
310 "")
311 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
312 ;;
313 1)
314 export TARGET_BUILD_TYPE=release
315 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 release)
317 export TARGET_BUILD_TYPE=release
318 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319 2)
320 export TARGET_BUILD_TYPE=debug
321 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800322 debug)
323 export TARGET_BUILD_TYPE=debug
324 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325 *)
326 echo
327 echo "I didn't understand your response. Please try again."
328 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700329 ;;
330 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 if [ -n "$1" ] ; then
332 break
333 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700334 done
335
336 set_stuff_for_environment
337}
338
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800339#
340# This function isn't really right: It chooses a TARGET_PRODUCT
341# based on the list of boards. Usually, that gets you something
342# that kinda works with a generic product, but really, you should
343# pick a product by name.
344#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700345function chooseproduct()
346{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 if [ "x$TARGET_PRODUCT" != x ] ; then
348 default_value=$TARGET_PRODUCT
349 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700350 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700351 fi
352
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800353 export TARGET_PRODUCT=
354 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700355 while [ -z "$TARGET_PRODUCT" ]
356 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700357 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800358 if [ -z "$1" ] ; then
359 read ANSWER
360 else
361 echo $1
362 ANSWER=$1
363 fi
364
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700365 if [ -z "$ANSWER" ] ; then
366 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800367 else
368 if check_product $ANSWER
369 then
370 export TARGET_PRODUCT=$ANSWER
371 else
372 echo "** Not a valid product: $ANSWER"
373 fi
374 fi
375 if [ -n "$1" ] ; then
376 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700377 fi
378 done
379
380 set_stuff_for_environment
381}
382
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800383function choosevariant()
384{
385 echo "Variant choices are:"
386 local index=1
387 local v
388 for v in ${VARIANT_CHOICES[@]}
389 do
390 # The product name is the name of the directory containing
391 # the makefile we found, above.
392 echo " $index. $v"
393 index=$(($index+1))
394 done
395
396 local default_value=eng
397 local ANSWER
398
399 export TARGET_BUILD_VARIANT=
400 while [ -z "$TARGET_BUILD_VARIANT" ]
401 do
402 echo -n "Which would you like? [$default_value] "
403 if [ -z "$1" ] ; then
404 read ANSWER
405 else
406 echo $1
407 ANSWER=$1
408 fi
409
410 if [ -z "$ANSWER" ] ; then
411 export TARGET_BUILD_VARIANT=$default_value
412 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
413 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800414 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800415 fi
416 else
417 if check_variant $ANSWER
418 then
419 export TARGET_BUILD_VARIANT=$ANSWER
420 else
421 echo "** Not a valid variant: $ANSWER"
422 fi
423 fi
424 if [ -n "$1" ] ; then
425 break
426 fi
427 done
428}
429
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700430function choosecombo()
431{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700432 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700433
434 echo
435 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700436 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700437
438 echo
439 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700440 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800441
442 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700443 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800444 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700445}
446
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800447# Clear this variable. It will be built up again when the vendorsetup.sh
448# files are included at the end of this file.
449unset LUNCH_MENU_CHOICES
450function add_lunch_combo()
451{
452 local new_combo=$1
453 local c
454 for c in ${LUNCH_MENU_CHOICES[@]} ; do
455 if [ "$new_combo" = "$c" ] ; then
456 return
457 fi
458 done
459 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
460}
461
462# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700463add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800464add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000465add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800466add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000467add_lunch_combo aosp_x86-eng
468add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470function print_lunch_menu()
471{
472 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 echo
474 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475 echo
476 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477
478 local i=1
479 local choice
480 for choice in ${LUNCH_MENU_CHOICES[@]}
481 do
482 echo " $i. $choice"
483 i=$(($i+1))
484 done
485
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486 echo
487}
488
489function lunch()
490{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800491 local answer
492
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700493 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800494 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700495 else
496 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700497 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800498 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700499 fi
500
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800501 local selection=
502
503 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700504 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700505 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
507 then
508 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
509 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800510 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 fi
512 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
513 then
514 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700515 fi
516
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800517 if [ -z "$selection" ]
518 then
519 echo
520 echo "Invalid lunch combo: $answer"
521 return 1
522 fi
523
Joe Onoratoda12daf2010-06-09 18:18:31 -0700524 export TARGET_BUILD_APPS=
525
Jeff Browne33ba4c2011-07-11 22:11:46 -0700526 local product=$(echo -n $selection | sed -e "s/-.*$//")
527 check_product $product
528 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800529 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700530 echo
531 echo "** Don't have a product spec for: '$product'"
532 echo "** Do you have the right repo manifest?"
533 product=
534 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800535
Jeff Browne33ba4c2011-07-11 22:11:46 -0700536 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
537 check_variant $variant
538 if [ $? -ne 0 ]
539 then
540 echo
541 echo "** Invalid variant: '$variant'"
542 echo "** Must be one of ${VARIANT_CHOICES[@]}"
543 variant=
544 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800545
Jeff Browne33ba4c2011-07-11 22:11:46 -0700546 if [ -z "$product" -o -z "$variant" ]
547 then
548 echo
549 return 1
550 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800551
Jeff Browne33ba4c2011-07-11 22:11:46 -0700552 export TARGET_PRODUCT=$product
553 export TARGET_BUILD_VARIANT=$variant
554 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700555
556 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800557
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700558 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800559 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700560}
561
Jeff Davidson513d7a42010-08-02 10:00:44 -0700562# Tab completion for lunch.
563function _lunch()
564{
565 local cur prev opts
566 COMPREPLY=()
567 cur="${COMP_WORDS[COMP_CWORD]}"
568 prev="${COMP_WORDS[COMP_CWORD-1]}"
569
570 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
571 return 0
572}
573complete -F _lunch lunch
574
Joe Onoratoda12daf2010-06-09 18:18:31 -0700575# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700576# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700577function tapas()
578{
Ying Wangb541ab62014-05-29 17:57:40 -0700579 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 -0700580 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Ying Wangb541ab62014-05-29 17:57:40 -0700581 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700582
Ying Wang67f02922012-08-22 10:25:20 -0700583 if [ $(echo $arch | wc -w) -gt 1 ]; then
584 echo "tapas: Error: Multiple build archs supplied: $arch"
585 return
586 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700587 if [ $(echo $variant | wc -w) -gt 1 ]; then
588 echo "tapas: Error: Multiple build variants supplied: $variant"
589 return
590 fi
Ying Wang67f02922012-08-22 10:25:20 -0700591
592 local product=full
593 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700594 x86) product=full_x86;;
595 mips) product=full_mips;;
596 armv5) product=generic_armv5;;
597 arm64) product=aosp_arm64;;
598 x86_64) product=aosp_x86_64;;
599 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700600 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700601 if [ -z "$variant" ]; then
602 variant=eng
603 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700604 if [ -z "$apps" ]; then
605 apps=all
606 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700607
Ying Wang67f02922012-08-22 10:25:20 -0700608 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700609 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700610 export TARGET_BUILD_TYPE=release
611 export TARGET_BUILD_APPS=$apps
612
613 set_stuff_for_environment
614 printconfig
615}
616
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700617function gettop
618{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800619 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700620 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700621 # The following circumlocution ensures we remove symlinks from TOP.
622 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700623 else
624 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800625 # The following circumlocution (repeated below as well) ensures
626 # that we record the true directory name and not one that is
627 # faked up with symlink names.
628 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700629 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800630 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700631 T=
632 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800633 \cd ..
synergyb112a402013-07-05 19:47:47 -0700634 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700635 done
Ying Wang9cd17642012-12-13 10:52:07 -0800636 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700637 if [ -f "$T/$TOPFILE" ]; then
638 echo $T
639 fi
640 fi
641 fi
642}
643
Andrew Hsieh906cb782013-09-10 17:37:14 +0800644# Return driver for "make", if any (eg. static analyzer)
645function getdriver()
646{
647 local T="$1"
648 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
649 if [ -n "$WITH_STATIC_ANALYZER" ]; then
650 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800651$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
652--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800653--status-bugs \
654--top=$T"
655 fi
656}
657
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658function m()
659{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800660 local T=$(gettop)
661 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800663 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700664 else
665 echo "Couldn't locate the top of the tree. Try setting TOP."
666 fi
667}
668
669function findmakefile()
670{
671 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800672 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700673 T=
674 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700675 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700676 if [ -f "$T/Android.mk" ]; then
677 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800678 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700679 return
680 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800681 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700682 done
Ying Wang9cd17642012-12-13 10:52:07 -0800683 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700684}
685
686function mm()
687{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800688 local T=$(gettop)
689 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700690 # If we're sitting in the root of the build tree, just do a
691 # normal make.
692 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800693 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700694 else
695 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800696 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700697 local MODULES=
698 local GET_INSTALL_PATH=
699 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700700 # Remove the path to top as the makefilepath needs to be relative
701 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700702 if [ ! "$T" ]; then
703 echo "Couldn't locate the top of the tree. Try setting TOP."
704 elif [ ! "$M" ]; then
705 echo "Couldn't locate a makefile from the current directory."
706 else
Ying Wanga7deb082013-08-16 13:24:47 -0700707 for ARG in $@; do
708 case $ARG in
709 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
710 esac
711 done
712 if [ -n "$GET_INSTALL_PATH" ]; then
713 MODULES=
714 ARGS=GET-INSTALL-PATH
715 else
716 MODULES=all_modules
717 ARGS=$@
718 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700719 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 -0700720 fi
721 fi
722}
723
724function mmm()
725{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800726 local T=$(gettop)
727 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700728 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800729 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800730 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800731 local ARGS=
732 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700733 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800734 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
735 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
736 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800737 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
738 if [ "$MODULES" = "" ]; then
739 MODULES=all_modules
740 fi
741 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700742 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700743 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
744 local TO_CHOP=`expr $TO_CHOP + 1`
745 local START=`PWD= /bin/pwd`
746 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700747 if [ "$MFILE" = "" ] ; then
748 MFILE=$DIR/Android.mk
749 else
750 MFILE=$MFILE/$DIR/Android.mk
751 fi
752 MAKEFILE="$MAKEFILE $MFILE"
753 else
Ying Wanga7deb082013-08-16 13:24:47 -0700754 case $DIR in
755 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
756 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
757 *) echo "No Android.mk in $DIR."; return 1;;
758 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700759 fi
760 done
Ying Wanga7deb082013-08-16 13:24:47 -0700761 if [ -n "$GET_INSTALL_PATH" ]; then
762 ARGS=$GET_INSTALL_PATH
763 MODULES=
764 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800765 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 -0700766 else
767 echo "Couldn't locate the top of the tree. Try setting TOP."
768 fi
769}
770
Ying Wangb607f7b2013-02-08 18:01:04 -0800771function mma()
772{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800773 local T=$(gettop)
774 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800775 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800776 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800777 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800778 if [ ! "$T" ]; then
779 echo "Couldn't locate the top of the tree. Try setting TOP."
780 fi
781 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800782 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800783 fi
784}
785
786function mmma()
787{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800788 local T=$(gettop)
789 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800790 if [ "$T" ]; then
791 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
792 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
793 local MY_PWD=`PWD= /bin/pwd`
794 if [ "$MY_PWD" = "$T" ]; then
795 MY_PWD=
796 else
797 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
798 fi
799 local DIR=
800 local MODULE_PATHS=
801 local ARGS=
802 for DIR in $DIRS ; do
803 if [ -d $DIR ]; then
804 if [ "$MY_PWD" = "" ]; then
805 MODULE_PATHS="$MODULE_PATHS $DIR"
806 else
807 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
808 fi
809 else
810 case $DIR in
811 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
812 *) echo "Couldn't find directory $DIR"; return 1;;
813 esac
814 fi
815 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800816 $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 -0800817 else
818 echo "Couldn't locate the top of the tree. Try setting TOP."
819 fi
820}
821
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700822function croot()
823{
824 T=$(gettop)
825 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800826 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700827 else
828 echo "Couldn't locate the top of the tree. Try setting TOP."
829 fi
830}
831
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700832function cproj()
833{
834 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700835 local HERE=$PWD
836 T=
837 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
838 T=$PWD
839 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800840 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700841 return
842 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800843 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700844 done
Ying Wang9cd17642012-12-13 10:52:07 -0800845 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700846 echo "can't find Android.mk"
847}
848
Daniel Sandler47e0a882013-07-30 13:23:52 -0400849# simplified version of ps; output in the form
850# <pid> <procname>
851function qpid() {
852 local prepend=''
853 local append=''
854 if [ "$1" = "--exact" ]; then
855 prepend=' '
856 append='$'
857 shift
858 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
859 echo "usage: qpid [[--exact] <process name|pid>"
860 return 255
861 fi
862
863 local EXE="$1"
864 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700865 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400866 else
867 adb shell ps \
868 | tr -d '\r' \
869 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
870 fi
871}
872
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700873function pid()
874{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400875 local prepend=''
876 local append=''
877 if [ "$1" = "--exact" ]; then
878 prepend=' '
879 append='$'
880 shift
881 fi
882 local EXE="$1"
883 if [ "$EXE" ] ; then
884 local PID=`adb shell ps \
885 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700886 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400887 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
888 echo "$PID"
889 else
890 echo "usage: pid [--exact] <process name>"
891 return 255
892 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700893}
894
Christopher Tate744ee802009-11-12 15:33:08 -0800895# systemstack - dump the current stack trace of all threads in the system process
896# to the usual ANR traces file
897function systemstack()
898{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800899 stacks system_server
900}
901
902function stacks()
903{
904 if [[ $1 =~ ^[0-9]+$ ]] ; then
905 local PID="$1"
906 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700907 local PIDLIST="$(pid $1)"
908 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
909 local PID="$PIDLIST"
910 elif [ "$PIDLIST" ] ; then
911 echo "more than one process: $1"
912 else
913 echo "no such process: $1"
914 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800915 else
916 echo "usage: stacks [pid|process name]"
917 fi
918
919 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700920 # Determine whether the process is native
921 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
922 # Dump stacks of Dalvik process
923 local TRACES=/data/anr/traces.txt
924 local ORIG=/data/anr/traces.orig
925 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800926
Jeff Brownb12c2e52013-08-19 15:14:16 -0700927 # Keep original traces to avoid clobbering
928 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800929
Jeff Brownb12c2e52013-08-19 15:14:16 -0700930 # Make sure we have a usable file
931 adb shell touch $TRACES
932 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800933
Jeff Brownb12c2e52013-08-19 15:14:16 -0700934 # Dump stacks and wait for dump to finish
935 adb shell kill -3 $PID
936 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800937
Jeff Brownb12c2e52013-08-19 15:14:16 -0700938 # Restore original stacks, and show current output
939 adb shell mv $TRACES $TMP
940 adb shell mv $ORIG $TRACES
941 adb shell cat $TMP
942 else
943 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -0700944 local USE64BIT="$(is64bit $PID)"
945 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -0700946 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800947 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800948}
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
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966case `uname -s` in
967 Darwin)
968 function sgrep()
969 {
Jeff Brown46cbd202014-07-26 15:15:41 -0700970 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 -0700971 }
972
973 ;;
974 *)
975 function sgrep()
976 {
Jeff Brown46cbd202014-07-26 15:15:41 -0700977 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 -0700978 }
979 ;;
980esac
981
Raghu Gandham8da43102012-07-25 19:57:22 -0700982function gettargetarch
983{
984 get_build_var TARGET_ARCH
985}
986
Jon Boekenoogencbca56f2014-04-07 10:57:38 -0700987function ggrep()
988{
989 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
990}
991
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700992function jgrep()
993{
Anatolii Shuba91c72d22013-07-05 16:09:25 +0300994 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 -0700995}
996
997function cgrep()
998{
Dan Albert01961192014-11-22 10:16:01 -0800999 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 -07001000}
1001
1002function resgrep()
1003{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001004 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 -07001005}
1006
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001007function mangrep()
1008{
1009 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1010}
1011
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001012function sepgrep()
1013{
1014 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 "$@"
1015}
1016
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001017case `uname -s` in
1018 Darwin)
1019 function mgrep()
1020 {
Ying Wang324c2b22012-08-17 15:03:20 -07001021 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 -07001022 }
1023
1024 function treegrep()
1025 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001026 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 -07001027 }
1028
1029 ;;
1030 *)
1031 function mgrep()
1032 {
Ying Wang324c2b22012-08-17 15:03:20 -07001033 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 -07001034 }
1035
1036 function treegrep()
1037 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001038 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 -07001039 }
1040
1041 ;;
1042esac
1043
1044function getprebuilt
1045{
1046 get_abs_build_var ANDROID_PREBUILTS
1047}
1048
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001049function tracedmdump()
1050{
1051 T=$(gettop)
1052 if [ ! "$T" ]; then
1053 echo "Couldn't locate the top of the tree. Try setting TOP."
1054 return
1055 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001056 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001057 local arch=$(gettargetarch)
1058 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001059
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001060 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001061 if [ ! "$TRACE" ] ; then
1062 echo "usage: tracedmdump tracename"
1063 return
1064 fi
1065
Jack Veenstra60116fc2009-04-09 18:12:34 -07001066 if [ ! -r "$KERNEL" ] ; then
1067 echo "Error: cannot find kernel: '$KERNEL'"
1068 return
1069 fi
1070
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001071 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001072 if [ "$BASETRACE" = "$TRACE" ] ; then
1073 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1074 fi
1075
1076 echo "post-processing traces..."
1077 rm -f $TRACE/qtrace.dexlist
1078 post_trace $TRACE
1079 if [ $? -ne 0 ]; then
1080 echo "***"
1081 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1082 echo "***"
1083 return
1084 fi
1085 echo "generating dexlist output..."
1086 /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
1087 echo "generating dmtrace data..."
1088 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1089 echo "generating html file..."
1090 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1091 echo "done, see $TRACE/dmtrace.html for details"
1092 echo "or run:"
1093 echo " traceview $TRACE/dmtrace"
1094}
1095
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001096# communicate with a running device or emulator, set up necessary state,
1097# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001098function runhat()
1099{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001100 # process standard adb options
1101 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001102 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001103 adbTarget=$1
1104 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001105 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001106 adbTarget="$1 $2"
1107 shift 2
1108 fi
1109 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001110 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001111
1112 # runhat options
1113 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001114
1115 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001116 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001117 return
1118 fi
1119
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001120 # confirm hat is available
1121 if [ -z $(which hat) ]; then
1122 echo "hat is not available in this configuration."
1123 return
1124 fi
1125
Andy McFaddenb6289852010-07-12 08:00:19 -07001126 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001127 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001128 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001129 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001130 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001131 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001132 echo -n "> "
1133 read
1134
The Android Open Source Project88b60792009-03-03 19:28:42 -08001135 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001136
The Android Open Source Project88b60792009-03-03 19:28:42 -08001137 echo "Retrieving file $devFile..."
1138 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001139
The Android Open Source Project88b60792009-03-03 19:28:42 -08001140 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001141
The Android Open Source Project88b60792009-03-03 19:28:42 -08001142 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001143 echo "View the output by pointing your browser at http://localhost:7000/"
1144 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001145 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001146}
1147
1148function getbugreports()
1149{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001150 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001151
1152 if [ ! "$reports" ]; then
1153 echo "Could not locate any bugreports."
1154 return
1155 fi
1156
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001157 local report
1158 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001159 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001160 echo "/sdcard/bugreports/${report}"
1161 adb pull /sdcard/bugreports/${report} ${report}
1162 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001163 done
1164}
1165
Victoria Lease1b296b42012-08-21 15:44:06 -07001166function getsdcardpath()
1167{
1168 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1169}
1170
1171function getscreenshotpath()
1172{
1173 echo "$(getsdcardpath)/Pictures/Screenshots"
1174}
1175
1176function getlastscreenshot()
1177{
1178 local screenshot_path=$(getscreenshotpath)
1179 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1180 if [ "$screenshot" = "" ]; then
1181 echo "No screenshots found."
1182 return
1183 fi
1184 echo "${screenshot}"
1185 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1186}
1187
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001188function startviewserver()
1189{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001190 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001191 if [ $# -gt 0 ]; then
1192 port=$1
1193 fi
1194 adb shell service call window 1 i32 $port
1195}
1196
1197function stopviewserver()
1198{
1199 adb shell service call window 2
1200}
1201
1202function isviewserverstarted()
1203{
1204 adb shell service call window 3
1205}
1206
Romain Guyb84049a2010-10-04 16:56:11 -07001207function key_home()
1208{
1209 adb shell input keyevent 3
1210}
1211
1212function key_back()
1213{
1214 adb shell input keyevent 4
1215}
1216
1217function key_menu()
1218{
1219 adb shell input keyevent 82
1220}
1221
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001222function smoketest()
1223{
1224 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1225 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1226 return
1227 fi
1228 T=$(gettop)
1229 if [ ! "$T" ]; then
1230 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1231 return
1232 fi
1233
Ying Wang9cd17642012-12-13 10:52:07 -08001234 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001235 adb uninstall com.android.smoketest > /dev/null &&
1236 adb uninstall com.android.smoketest.tests > /dev/null &&
1237 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1238 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1239 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1240}
1241
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001242# simple shortcut to the runtest command
1243function runtest()
1244{
1245 T=$(gettop)
1246 if [ ! "$T" ]; then
1247 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1248 return
1249 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001250 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001251}
1252
The Android Open Source Project88b60792009-03-03 19:28:42 -08001253function godir () {
1254 if [[ -z "$1" ]]; then
1255 echo "Usage: godir <regex>"
1256 return
1257 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001258 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001259 if [[ ! -f $T/filelist ]]; then
1260 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001261 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001262 echo " Done"
1263 echo ""
1264 fi
1265 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001266 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001267 if [[ ${#lines[@]} = 0 ]]; then
1268 echo "Not found"
1269 return
1270 fi
1271 local pathname
1272 local choice
1273 if [[ ${#lines[@]} > 1 ]]; then
1274 while [[ -z "$pathname" ]]; do
1275 local index=1
1276 local line
1277 for line in ${lines[@]}; do
1278 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001279 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001280 done
1281 echo
1282 echo -n "Select one: "
1283 unset choice
1284 read choice
1285 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1286 echo "Invalid choice"
1287 continue
1288 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001289 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001290 done
1291 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001292 pathname=${lines[0]}
1293 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001294 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001295}
1296
Neil Fuller46e00ea2014-10-16 10:23:03 +01001297# Force JAVA_HOME to point to java 1.7 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001298#
1299# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1300# For some reason, installing the JDK doesn't make it show up in the
1301# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001302function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001303 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001304 # we can reset it later, depending on the version of java the build
1305 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001306 #
1307 # If we don't do this, the JAVA_HOME value set by the first call to
1308 # build/envsetup.sh will persist forever.
1309 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1310 export JAVA_HOME=""
1311 fi
1312
Andy McFaddenbd960942010-06-24 12:52:51 -07001313 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01001314 case `uname -s` in
1315 Darwin)
1316 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1317 ;;
1318 *)
1319 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1320 ;;
1321 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001322
1323 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1324 # we can change it on the next envsetup.sh, if required.
1325 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001326 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001327}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001328
Alex Rayf0d08eb2013-03-08 15:15:06 -08001329# Print colored exit condition
1330function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001331 "$@"
1332 local retval=$?
1333 if [ $retval -ne 0 ]
1334 then
1335 echo -e "\e[0;31mFAILURE\e[00m"
1336 else
1337 echo -e "\e[0;32mSUCCESS\e[00m"
1338 fi
1339 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001340}
1341
Ying Wanged21d4c2014-08-24 22:14:19 -07001342function get_make_command()
1343{
1344 echo command make
1345}
1346
Ed Heylcc6be0a2014-06-18 14:55:58 -07001347function make()
1348{
1349 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001350 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001351 local ret=$?
1352 local end_time=$(date +"%s")
1353 local tdiff=$(($end_time-$start_time))
1354 local hours=$(($tdiff / 3600 ))
1355 local mins=$((($tdiff % 3600) / 60))
1356 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001357 local ncolors=$(tput colors 2>/dev/null)
1358 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
1359 color_failed="\e[0;31m"
1360 color_success="\e[0;32m"
1361 color_reset="\e[00m"
1362 else
1363 color_failed=""
1364 color_success=""
1365 color_reset=""
1366 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001367 echo
1368 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001369 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001370 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001371 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001372 fi
1373 if [ $hours -gt 0 ] ; then
1374 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1375 elif [ $mins -gt 0 ] ; then
1376 printf "(%02g:%02g (mm:ss))" $mins $secs
1377 elif [ $secs -gt 0 ] ; then
1378 printf "(%s seconds)" $secs
1379 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001380 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001381 echo
1382 return $ret
1383}
1384
Raphael Moll70a86b02011-06-20 16:03:14 -07001385if [ "x$SHELL" != "x/bin/bash" ]; then
1386 case `ps -o command -p $$` in
1387 *bash*)
1388 ;;
1389 *)
1390 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1391 ;;
1392 esac
1393fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001394
1395# Execute the contents of any vendorsetup.sh files we can find.
Ying Wang506410a2014-07-09 15:37:34 -07001396for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1397 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001398do
1399 echo "including $f"
1400 . $f
1401done
1402unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001403
1404addcompletions