blob: cfc02c7fa4e14a80fcf8d8603d816c937f4fe333 [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.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060021- cmremote: Add git remote for CM Gerrit Review
22- cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
23- cmrebase: Rebase a Gerrit change and push it again
24- mka: Builds using SCHED_BATCH on all processors
25- reposync: Parallel repo sync using ionice and SCHED_BATCH
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070026
Dan Albert4ae5d4b2014-10-31 16:23:08 -070027Environemnt options:
28- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
29 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
30 build is leak-check clean.
31
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070032Look at the source to view more functions. The complete list is:
33EOF
34 T=$(gettop)
35 local A
36 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070037 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 -070038 A="$A $i"
39 done
40 echo $A
41}
42
43# Get the value of a build variable as an absolute path.
44function get_abs_build_var()
45{
46 T=$(gettop)
47 if [ ! "$T" ]; then
48 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
49 return
50 fi
Ying Wang9cd17642012-12-13 10:52:07 -080051 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070052 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070053}
54
55# Get the exact value of a build variable.
56function get_build_var()
57{
58 T=$(gettop)
59 if [ ! "$T" ]; then
60 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
61 return
62 fi
Andrew Boie6905e212013-12-19 13:21:46 -080063 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070064 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080065}
66
67# check to see if the supplied product is one we can build
68function check_product()
69{
70 T=$(gettop)
71 if [ ! "$T" ]; then
72 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
73 return
74 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000075
76 if (echo -n $1 | grep -q -e "^cm_") ; then
77 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
78 else
79 CM_BUILD=
80 fi
81 export CM_BUILD
82
Jeff Browne33ba4c2011-07-11 22:11:46 -070083 TARGET_PRODUCT=$1 \
84 TARGET_BUILD_VARIANT= \
85 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070086 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080087 get_build_var TARGET_DEVICE > /dev/null
88 # hide successful answers, but allow the errors to show
89}
90
91VARIANT_CHOICES=(user userdebug eng)
92
93# check to see if the supplied variant is valid
94function check_variant()
95{
96 for v in ${VARIANT_CHOICES[@]}
97 do
98 if [ "$v" = "$1" ]
99 then
100 return 0
101 fi
102 done
103 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700104}
105
106function setpaths()
107{
108 T=$(gettop)
109 if [ ! "$T" ]; then
110 echo "Couldn't locate the top of the tree. Try setting TOP."
111 return
112 fi
113
114 ##################################################################
115 # #
116 # Read me before you modify this code #
117 # #
118 # This function sets ANDROID_BUILD_PATHS to what it is adding #
119 # to PATH, and the next time it is run, it removes that from #
120 # PATH. This is required so lunch can be run more than once #
121 # and still have working paths. #
122 # #
123 ##################################################################
124
Raphael Mollc639c782011-06-20 17:25:01 -0700125 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
126 # due to "C:\Program Files" being in the path.
127
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700128 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700129 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700130 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
131 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700132 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700133 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800134 # strip leading ':', if any
135 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500136 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700137
138 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700139 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700140 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700141
Ben Cheng8bc4c432012-11-16 13:29:13 -0800142 # defined in core/config.mk
143 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700144 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800145 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800146
Raphael Mollc639c782011-06-20 17:25:01 -0700147 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800148 export ANDROID_TOOLCHAIN=
149 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200150 local ARCH=$(get_build_var TARGET_ARCH)
151 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400152 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700153 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400154 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
155 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800156 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200157 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800158 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700159 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700160 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700161 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000162 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200163 *)
164 echo "Can't find toolchain for unknown architecture: $ARCH"
165 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700166 ;;
167 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700168 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800169 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700170 fi
Raphael732936d2011-06-22 14:35:32 -0700171
Ben Chengfba67bf2014-02-25 10:27:07 -0800172 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
173 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
174 fi
175
176 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700177 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700178 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800179 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800180 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700181 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100182 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
183 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700184 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700185 ;;
186 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700187 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700188 ;;
189 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700190
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700191 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700192 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 +0200193
194 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
195 # to ensure that the corresponding 'emulator' binaries are used.
196 case $(uname -s) in
197 Darwin)
198 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
199 ;;
200 Linux)
201 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
202 ;;
203 *)
204 ANDROID_EMULATOR_PREBUILTS=
205 ;;
206 esac
207 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700208 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200209 export ANDROID_EMULATOR_PREBUILTS
210 fi
211
Ying Wangaa1c9b52012-11-26 20:51:59 -0800212 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800213
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500214 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900215 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500216 if [ -n "$JAVA_HOME" ]; then
217 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900218 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
219 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500220 fi
221
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800222 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700223 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
224 export OUT=$ANDROID_PRODUCT_OUT
225
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700226 unset ANDROID_HOST_OUT
227 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
228
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800229 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700230 # TODO: fix the path
231 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
232}
233
234function printconfig()
235{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800236 T=$(gettop)
237 if [ ! "$T" ]; then
238 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
239 return
240 fi
241 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700242}
243
244function set_stuff_for_environment()
245{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800246 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500247 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800248 setpaths
249 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700250
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700252 # With this environment variable new GCC can apply colors to warnings/errors
253 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
Dan Albert4ae5d4b2014-10-31 16:23:08 -0700254 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255}
256
257function set_sequence_number()
258{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700259 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700260}
261
262function settitle()
263{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800264 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700265 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700266 local product=$TARGET_PRODUCT
267 local variant=$TARGET_BUILD_VARIANT
268 local apps=$TARGET_BUILD_APPS
269 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700270 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700271 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700272 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700273 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800274 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700275}
276
Kenny Root52aa81c2011-07-15 11:07:06 -0700277function addcompletions()
278{
279 local T dir f
280
281 # Keep us from trying to run in something that isn't bash.
282 if [ -z "${BASH_VERSION}" ]; then
283 return
284 fi
285
286 # Keep us from trying to run in bash that's too old.
287 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
288 return
289 fi
290
291 dir="sdk/bash_completion"
292 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700293 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700294 echo "including $f"
295 . $f
296 done
297 fi
298}
299
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300function choosetype()
301{
302 echo "Build type choices are:"
303 echo " 1. release"
304 echo " 2. debug"
305 echo
306
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800307 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700308 DEFAULT_NUM=1
309 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700310
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800311 export TARGET_BUILD_TYPE=
312 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700313 while [ -z $TARGET_BUILD_TYPE ]
314 do
315 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 if [ -z "$1" ] ; then
317 read ANSWER
318 else
319 echo $1
320 ANSWER=$1
321 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700322 case $ANSWER in
323 "")
324 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
325 ;;
326 1)
327 export TARGET_BUILD_TYPE=release
328 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800329 release)
330 export TARGET_BUILD_TYPE=release
331 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332 2)
333 export TARGET_BUILD_TYPE=debug
334 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335 debug)
336 export TARGET_BUILD_TYPE=debug
337 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338 *)
339 echo
340 echo "I didn't understand your response. Please try again."
341 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700342 ;;
343 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800344 if [ -n "$1" ] ; then
345 break
346 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 done
348
349 set_stuff_for_environment
350}
351
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800352#
353# This function isn't really right: It chooses a TARGET_PRODUCT
354# based on the list of boards. Usually, that gets you something
355# that kinda works with a generic product, but really, you should
356# pick a product by name.
357#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700358function chooseproduct()
359{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700360 if [ "x$TARGET_PRODUCT" != x ] ; then
361 default_value=$TARGET_PRODUCT
362 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700363 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700364 fi
365
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800366 export TARGET_PRODUCT=
367 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700368 while [ -z "$TARGET_PRODUCT" ]
369 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700370 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800371 if [ -z "$1" ] ; then
372 read ANSWER
373 else
374 echo $1
375 ANSWER=$1
376 fi
377
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700378 if [ -z "$ANSWER" ] ; then
379 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800380 else
381 if check_product $ANSWER
382 then
383 export TARGET_PRODUCT=$ANSWER
384 else
385 echo "** Not a valid product: $ANSWER"
386 fi
387 fi
388 if [ -n "$1" ] ; then
389 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700390 fi
391 done
392
393 set_stuff_for_environment
394}
395
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800396function choosevariant()
397{
398 echo "Variant choices are:"
399 local index=1
400 local v
401 for v in ${VARIANT_CHOICES[@]}
402 do
403 # The product name is the name of the directory containing
404 # the makefile we found, above.
405 echo " $index. $v"
406 index=$(($index+1))
407 done
408
409 local default_value=eng
410 local ANSWER
411
412 export TARGET_BUILD_VARIANT=
413 while [ -z "$TARGET_BUILD_VARIANT" ]
414 do
415 echo -n "Which would you like? [$default_value] "
416 if [ -z "$1" ] ; then
417 read ANSWER
418 else
419 echo $1
420 ANSWER=$1
421 fi
422
423 if [ -z "$ANSWER" ] ; then
424 export TARGET_BUILD_VARIANT=$default_value
425 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
426 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800427 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800428 fi
429 else
430 if check_variant $ANSWER
431 then
432 export TARGET_BUILD_VARIANT=$ANSWER
433 else
434 echo "** Not a valid variant: $ANSWER"
435 fi
436 fi
437 if [ -n "$1" ] ; then
438 break
439 fi
440 done
441}
442
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700443function choosecombo()
444{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700445 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446
447 echo
448 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700449 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700450
451 echo
452 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700453 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800454
455 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700456 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800457 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458}
459
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800460# Clear this variable. It will be built up again when the vendorsetup.sh
461# files are included at the end of this file.
462unset LUNCH_MENU_CHOICES
463function add_lunch_combo()
464{
465 local new_combo=$1
466 local c
467 for c in ${LUNCH_MENU_CHOICES[@]} ; do
468 if [ "$new_combo" = "$c" ] ; then
469 return
470 fi
471 done
472 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
473}
474
475# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700476add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800477add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000478add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800479add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000480add_lunch_combo aosp_x86-eng
481add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483function print_lunch_menu()
484{
485 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486 echo
487 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000488 if [ "$(uname)" = "Darwin" ] ; then
489 echo " (ohai, koush!)"
490 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700491 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000492 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
493 echo "Breakfast menu... pick a combo:"
494 else
495 echo "Lunch menu... pick a combo:"
496 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800497
498 local i=1
499 local choice
500 for choice in ${LUNCH_MENU_CHOICES[@]}
501 do
502 echo " $i. $choice"
503 i=$(($i+1))
504 done
505
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000506 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
507 echo "... and don't forget the bacon!"
508 fi
509
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700510 echo
511}
512
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000513function brunch()
514{
515 breakfast $*
516 if [ $? -eq 0 ]; then
517 mka bacon
518 else
519 echo "No such item in brunch menu. Try 'breakfast'"
520 return 1
521 fi
522 return $?
523}
524
525function breakfast()
526{
527 target=$1
528 CM_DEVICES_ONLY="true"
529 unset LUNCH_MENU_CHOICES
530 add_lunch_combo full-eng
531 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
532 do
533 echo "including $f"
534 . $f
535 done
536 unset f
537
538 if [ $# -eq 0 ]; then
539 # No arguments, so let's have the full menu
540 lunch
541 else
542 echo "z$target" | grep -q "-"
543 if [ $? -eq 0 ]; then
544 # A buildtype was specified, assume a full device name
545 lunch $target
546 else
547 # This is probably just the CM model name
548 lunch cm_$target-userdebug
549 fi
550 fi
551 return $?
552}
553
554alias bib=breakfast
555
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700556function lunch()
557{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800558 local answer
559
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700560 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800561 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700562 else
563 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700564 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800565 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700566 fi
567
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800568 local selection=
569
570 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700571 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700572 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800573 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
574 then
575 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
576 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800577 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800578 fi
579 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
580 then
581 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582 fi
583
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800584 if [ -z "$selection" ]
585 then
586 echo
587 echo "Invalid lunch combo: $answer"
588 return 1
589 fi
590
Joe Onoratoda12daf2010-06-09 18:18:31 -0700591 export TARGET_BUILD_APPS=
592
Jeff Browne33ba4c2011-07-11 22:11:46 -0700593 local product=$(echo -n $selection | sed -e "s/-.*$//")
594 check_product $product
595 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800596 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800597 # if we can't find a product, try to grab it off the CM github
598 T=$(gettop)
599 pushd $T > /dev/null
600 build/tools/roomservice.py $product
601 popd > /dev/null
602 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000603 else
604 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800605 fi
606 if [ $? -ne 0 ]
607 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700608 echo
609 echo "** Don't have a product spec for: '$product'"
610 echo "** Do you have the right repo manifest?"
611 product=
612 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800613
Jeff Browne33ba4c2011-07-11 22:11:46 -0700614 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
615 check_variant $variant
616 if [ $? -ne 0 ]
617 then
618 echo
619 echo "** Invalid variant: '$variant'"
620 echo "** Must be one of ${VARIANT_CHOICES[@]}"
621 variant=
622 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800623
Jeff Browne33ba4c2011-07-11 22:11:46 -0700624 if [ -z "$product" -o -z "$variant" ]
625 then
626 echo
627 return 1
628 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800629
Jeff Browne33ba4c2011-07-11 22:11:46 -0700630 export TARGET_PRODUCT=$product
631 export TARGET_BUILD_VARIANT=$variant
632 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700633
634 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800635
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700636 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800637 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700638}
639
Jeff Davidson513d7a42010-08-02 10:00:44 -0700640# Tab completion for lunch.
641function _lunch()
642{
643 local cur prev opts
644 COMPREPLY=()
645 cur="${COMP_WORDS[COMP_CWORD]}"
646 prev="${COMP_WORDS[COMP_CWORD-1]}"
647
648 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
649 return 0
650}
651complete -F _lunch lunch
652
Joe Onoratoda12daf2010-06-09 18:18:31 -0700653# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700654# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700655function tapas()
656{
Ying Wangb541ab62014-05-29 17:57:40 -0700657 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 -0700658 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700659 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
660 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 -0700661
Ying Wang67f02922012-08-22 10:25:20 -0700662 if [ $(echo $arch | wc -w) -gt 1 ]; then
663 echo "tapas: Error: Multiple build archs supplied: $arch"
664 return
665 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700666 if [ $(echo $variant | wc -w) -gt 1 ]; then
667 echo "tapas: Error: Multiple build variants supplied: $variant"
668 return
669 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700670 if [ $(echo $density | wc -w) -gt 1 ]; then
671 echo "tapas: Error: Multiple densities supplied: $density"
672 return
673 fi
Ying Wang67f02922012-08-22 10:25:20 -0700674
675 local product=full
676 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700677 x86) product=full_x86;;
678 mips) product=full_mips;;
679 armv5) product=generic_armv5;;
680 arm64) product=aosp_arm64;;
681 x86_64) product=aosp_x86_64;;
682 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700683 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700684 if [ -z "$variant" ]; then
685 variant=eng
686 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700687 if [ -z "$apps" ]; then
688 apps=all
689 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600690 if [ -z "$density" ]; then
691 density=alldpi
692 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700693
Ying Wang67f02922012-08-22 10:25:20 -0700694 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700695 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700696 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700697 export TARGET_BUILD_TYPE=release
698 export TARGET_BUILD_APPS=$apps
699
700 set_stuff_for_environment
701 printconfig
702}
703
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700704function gettop
705{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800706 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700707 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700708 # The following circumlocution ensures we remove symlinks from TOP.
709 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700710 else
711 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800712 # The following circumlocution (repeated below as well) ensures
713 # that we record the true directory name and not one that is
714 # faked up with symlink names.
715 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700716 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800717 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700718 T=
719 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800720 \cd ..
synergyb112a402013-07-05 19:47:47 -0700721 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700722 done
Ying Wang9cd17642012-12-13 10:52:07 -0800723 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700724 if [ -f "$T/$TOPFILE" ]; then
725 echo $T
726 fi
727 fi
728 fi
729}
730
Andrew Hsieh906cb782013-09-10 17:37:14 +0800731# Return driver for "make", if any (eg. static analyzer)
732function getdriver()
733{
734 local T="$1"
735 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
736 if [ -n "$WITH_STATIC_ANALYZER" ]; then
737 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800738$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
739--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800740--status-bugs \
741--top=$T"
742 fi
743}
744
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700745function m()
746{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800747 local T=$(gettop)
748 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700749 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800750 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700751 else
752 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700753 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700754 fi
755}
756
757function findmakefile()
758{
759 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800760 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700761 T=
762 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700763 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700764 if [ -f "$T/Android.mk" ]; then
765 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800766 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700767 return
768 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800769 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700770 done
Ying Wang9cd17642012-12-13 10:52:07 -0800771 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700772}
773
774function mm()
775{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800776 local T=$(gettop)
777 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700778 # If we're sitting in the root of the build tree, just do a
779 # normal make.
780 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800781 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700782 else
783 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800784 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700785 local MODULES=
786 local GET_INSTALL_PATH=
787 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700788 # Remove the path to top as the makefilepath needs to be relative
789 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700790 if [ ! "$T" ]; then
791 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700792 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793 elif [ ! "$M" ]; then
794 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700795 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700796 else
Ying Wanga7deb082013-08-16 13:24:47 -0700797 for ARG in $@; do
798 case $ARG in
799 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
800 esac
801 done
802 if [ -n "$GET_INSTALL_PATH" ]; then
803 MODULES=
804 ARGS=GET-INSTALL-PATH
805 else
806 MODULES=all_modules
807 ARGS=$@
808 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700809 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 -0700810 fi
811 fi
812}
813
814function mmm()
815{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800816 local T=$(gettop)
817 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700818 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800819 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800820 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800821 local ARGS=
822 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700823 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800824 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
825 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
826 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800827 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
828 if [ "$MODULES" = "" ]; then
829 MODULES=all_modules
830 fi
831 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700832 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700833 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
834 local TO_CHOP=`expr $TO_CHOP + 1`
835 local START=`PWD= /bin/pwd`
836 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700837 if [ "$MFILE" = "" ] ; then
838 MFILE=$DIR/Android.mk
839 else
840 MFILE=$MFILE/$DIR/Android.mk
841 fi
842 MAKEFILE="$MAKEFILE $MFILE"
843 else
Ying Wanga7deb082013-08-16 13:24:47 -0700844 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100845 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700846 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
847 *) echo "No Android.mk in $DIR."; return 1;;
848 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700849 fi
850 done
Ying Wanga7deb082013-08-16 13:24:47 -0700851 if [ -n "$GET_INSTALL_PATH" ]; then
852 ARGS=$GET_INSTALL_PATH
853 MODULES=
854 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800855 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 -0700856 else
857 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700858 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700859 fi
860}
861
Ying Wangb607f7b2013-02-08 18:01:04 -0800862function mma()
863{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800864 local T=$(gettop)
865 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800866 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800867 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800868 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800869 if [ ! "$T" ]; then
870 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700871 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800872 fi
873 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800874 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800875 fi
876}
877
878function mmma()
879{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800880 local T=$(gettop)
881 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800882 if [ "$T" ]; then
883 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
884 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
885 local MY_PWD=`PWD= /bin/pwd`
886 if [ "$MY_PWD" = "$T" ]; then
887 MY_PWD=
888 else
889 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
890 fi
891 local DIR=
892 local MODULE_PATHS=
893 local ARGS=
894 for DIR in $DIRS ; do
895 if [ -d $DIR ]; then
896 if [ "$MY_PWD" = "" ]; then
897 MODULE_PATHS="$MODULE_PATHS $DIR"
898 else
899 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
900 fi
901 else
902 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100903 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800904 *) echo "Couldn't find directory $DIR"; return 1;;
905 esac
906 fi
907 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800908 $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 -0800909 else
910 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700911 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800912 fi
913}
914
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700915function croot()
916{
917 T=$(gettop)
918 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800919 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700920 else
921 echo "Couldn't locate the top of the tree. Try setting TOP."
922 fi
923}
924
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700925function cproj()
926{
927 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700928 local HERE=$PWD
929 T=
930 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
931 T=$PWD
932 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800933 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700934 return
935 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800936 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700937 done
Ying Wang9cd17642012-12-13 10:52:07 -0800938 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700939 echo "can't find Android.mk"
940}
941
Daniel Sandler47e0a882013-07-30 13:23:52 -0400942# simplified version of ps; output in the form
943# <pid> <procname>
944function qpid() {
945 local prepend=''
946 local append=''
947 if [ "$1" = "--exact" ]; then
948 prepend=' '
949 append='$'
950 shift
951 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
952 echo "usage: qpid [[--exact] <process name|pid>"
953 return 255
954 fi
955
956 local EXE="$1"
957 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700958 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400959 else
960 adb shell ps \
961 | tr -d '\r' \
962 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
963 fi
964}
965
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966function pid()
967{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400968 local prepend=''
969 local append=''
970 if [ "$1" = "--exact" ]; then
971 prepend=' '
972 append='$'
973 shift
974 fi
975 local EXE="$1"
976 if [ "$EXE" ] ; then
977 local PID=`adb shell ps \
978 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700979 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400980 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
981 echo "$PID"
982 else
983 echo "usage: pid [--exact] <process name>"
984 return 255
985 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700986}
987
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800988# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700989# that has the core-file-size limit set correctly
990#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800991# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700992# if its core-file-size limit is not set already.
993# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
994
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800995function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700996{
997 echo "Getting root...";
998 adb root;
999 adb wait-for-device;
1000
1001 echo "Remounting root parition read-write...";
1002 adb shell mount -w -o remount -t rootfs rootfs;
1003 sleep 1;
1004 adb wait-for-device;
1005 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001006 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001007 adb shell chmod 0777 /cores;
1008
1009 echo "Granting SELinux permission to dump in /cores...";
1010 adb shell restorecon -R /cores;
1011
1012 echo "Set core pattern.";
1013 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1014
1015 echo "Done."
1016}
1017
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001018# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001019# $1 = PID of process (e.g., $(pid mediaserver))
1020#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001021# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001022# dump to actually be generated.
1023
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001024function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001025{
1026 local PID=$1;
1027 if [ -z "$PID" ]; then
1028 printf "Expecting a PID!\n";
1029 return;
1030 fi;
1031 echo "Setting core limit for $PID to infinite...";
1032 adb shell prlimit $PID 4 -1 -1
1033}
1034
1035# core - send SIGV and pull the core for process
1036# $1 = PID of process (e.g., $(pid mediaserver))
1037#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001038# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001039# enabled globally.
1040
1041function core()
1042{
1043 local PID=$1;
1044
1045 if [ -z "$PID" ]; then
1046 printf "Expecting a PID!\n";
1047 return;
1048 fi;
1049
1050 local CORENAME=core.$PID;
1051 local COREPATH=/cores/$CORENAME;
1052 local SIG=SEGV;
1053
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001054 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001055
1056 local done=0;
1057 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1058 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1059 adb shell kill -$SIG $PID;
1060 sleep 1;
1061 done;
1062
1063 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1064 echo "Done: core is under $COREPATH on device.";
1065}
1066
Christopher Tate744ee802009-11-12 15:33:08 -08001067# systemstack - dump the current stack trace of all threads in the system process
1068# to the usual ANR traces file
1069function systemstack()
1070{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001071 stacks system_server
1072}
1073
1074function stacks()
1075{
1076 if [[ $1 =~ ^[0-9]+$ ]] ; then
1077 local PID="$1"
1078 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001079 local PIDLIST="$(pid $1)"
1080 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1081 local PID="$PIDLIST"
1082 elif [ "$PIDLIST" ] ; then
1083 echo "more than one process: $1"
1084 else
1085 echo "no such process: $1"
1086 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001087 else
1088 echo "usage: stacks [pid|process name]"
1089 fi
1090
1091 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001092 # Determine whether the process is native
1093 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1094 # Dump stacks of Dalvik process
1095 local TRACES=/data/anr/traces.txt
1096 local ORIG=/data/anr/traces.orig
1097 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001098
Jeff Brownb12c2e52013-08-19 15:14:16 -07001099 # Keep original traces to avoid clobbering
1100 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001101
Jeff Brownb12c2e52013-08-19 15:14:16 -07001102 # Make sure we have a usable file
1103 adb shell touch $TRACES
1104 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001105
Jeff Brownb12c2e52013-08-19 15:14:16 -07001106 # Dump stacks and wait for dump to finish
1107 adb shell kill -3 $PID
1108 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001109
Jeff Brownb12c2e52013-08-19 15:14:16 -07001110 # Restore original stacks, and show current output
1111 adb shell mv $TRACES $TMP
1112 adb shell mv $ORIG $TRACES
1113 adb shell cat $TMP
1114 else
1115 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001116 local USE64BIT="$(is64bit $PID)"
1117 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001118 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001119 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001120}
1121
Michael Wrightaeed7212014-06-19 19:58:12 -07001122# Read the ELF header from /proc/$PID/exe to determine if the process is
1123# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001124function is64bit()
1125{
1126 local PID="$1"
1127 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001128 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001129 echo "64"
1130 else
1131 echo ""
1132 fi
1133 else
1134 echo ""
1135 fi
1136}
1137
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001138case `uname -s` in
1139 Darwin)
1140 function sgrep()
1141 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001142 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 -07001143 }
1144
1145 ;;
1146 *)
1147 function sgrep()
1148 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001149 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 -07001150 }
1151 ;;
1152esac
1153
Raghu Gandham8da43102012-07-25 19:57:22 -07001154function gettargetarch
1155{
1156 get_build_var TARGET_ARCH
1157}
1158
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001159function ggrep()
1160{
1161 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1162}
1163
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001164function jgrep()
1165{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001166 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 -07001167}
1168
1169function cgrep()
1170{
Dan Albert01961192014-11-22 10:16:01 -08001171 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 -07001172}
1173
1174function resgrep()
1175{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001176 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 -07001177}
1178
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001179function mangrep()
1180{
1181 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1182}
1183
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001184function sepgrep()
1185{
1186 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 "$@"
1187}
1188
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001189function rcgrep()
1190{
1191 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1192}
1193
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001194case `uname -s` in
1195 Darwin)
1196 function mgrep()
1197 {
Ying Wang324c2b22012-08-17 15:03:20 -07001198 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 -07001199 }
1200
1201 function treegrep()
1202 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001203 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 -07001204 }
1205
1206 ;;
1207 *)
1208 function mgrep()
1209 {
Ying Wang324c2b22012-08-17 15:03:20 -07001210 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 -07001211 }
1212
1213 function treegrep()
1214 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001215 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 -07001216 }
1217
1218 ;;
1219esac
1220
1221function getprebuilt
1222{
1223 get_abs_build_var ANDROID_PREBUILTS
1224}
1225
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001226function tracedmdump()
1227{
1228 T=$(gettop)
1229 if [ ! "$T" ]; then
1230 echo "Couldn't locate the top of the tree. Try setting TOP."
1231 return
1232 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001233 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001234 local arch=$(gettargetarch)
1235 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001237 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001238 if [ ! "$TRACE" ] ; then
1239 echo "usage: tracedmdump tracename"
1240 return
1241 fi
1242
Jack Veenstra60116fc2009-04-09 18:12:34 -07001243 if [ ! -r "$KERNEL" ] ; then
1244 echo "Error: cannot find kernel: '$KERNEL'"
1245 return
1246 fi
1247
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001248 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001249 if [ "$BASETRACE" = "$TRACE" ] ; then
1250 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1251 fi
1252
1253 echo "post-processing traces..."
1254 rm -f $TRACE/qtrace.dexlist
1255 post_trace $TRACE
1256 if [ $? -ne 0 ]; then
1257 echo "***"
1258 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1259 echo "***"
1260 return
1261 fi
1262 echo "generating dexlist output..."
1263 /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
1264 echo "generating dmtrace data..."
1265 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1266 echo "generating html file..."
1267 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1268 echo "done, see $TRACE/dmtrace.html for details"
1269 echo "or run:"
1270 echo " traceview $TRACE/dmtrace"
1271}
1272
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001273# communicate with a running device or emulator, set up necessary state,
1274# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001275function runhat()
1276{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001277 # process standard adb options
1278 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001279 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001280 adbTarget=$1
1281 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001282 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001283 adbTarget="$1 $2"
1284 shift 2
1285 fi
1286 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001287 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001288
1289 # runhat options
1290 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001291
1292 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001293 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001294 return
1295 fi
1296
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001297 # confirm hat is available
1298 if [ -z $(which hat) ]; then
1299 echo "hat is not available in this configuration."
1300 return
1301 fi
1302
Andy McFaddenb6289852010-07-12 08:00:19 -07001303 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001304 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001305 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001306 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001307 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001308 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001309 echo -n "> "
1310 read
1311
The Android Open Source Project88b60792009-03-03 19:28:42 -08001312 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001313
The Android Open Source Project88b60792009-03-03 19:28:42 -08001314 echo "Retrieving file $devFile..."
1315 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001316
The Android Open Source Project88b60792009-03-03 19:28:42 -08001317 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001318
The Android Open Source Project88b60792009-03-03 19:28:42 -08001319 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001320 echo "View the output by pointing your browser at http://localhost:7000/"
1321 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001322 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001323}
1324
1325function getbugreports()
1326{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001327 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001328
1329 if [ ! "$reports" ]; then
1330 echo "Could not locate any bugreports."
1331 return
1332 fi
1333
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001334 local report
1335 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001336 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001337 echo "/sdcard/bugreports/${report}"
1338 adb pull /sdcard/bugreports/${report} ${report}
1339 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001340 done
1341}
1342
Victoria Lease1b296b42012-08-21 15:44:06 -07001343function getsdcardpath()
1344{
1345 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1346}
1347
1348function getscreenshotpath()
1349{
1350 echo "$(getsdcardpath)/Pictures/Screenshots"
1351}
1352
1353function getlastscreenshot()
1354{
1355 local screenshot_path=$(getscreenshotpath)
1356 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1357 if [ "$screenshot" = "" ]; then
1358 echo "No screenshots found."
1359 return
1360 fi
1361 echo "${screenshot}"
1362 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1363}
1364
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001365function startviewserver()
1366{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001367 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001368 if [ $# -gt 0 ]; then
1369 port=$1
1370 fi
1371 adb shell service call window 1 i32 $port
1372}
1373
1374function stopviewserver()
1375{
1376 adb shell service call window 2
1377}
1378
1379function isviewserverstarted()
1380{
1381 adb shell service call window 3
1382}
1383
Romain Guyb84049a2010-10-04 16:56:11 -07001384function key_home()
1385{
1386 adb shell input keyevent 3
1387}
1388
1389function key_back()
1390{
1391 adb shell input keyevent 4
1392}
1393
1394function key_menu()
1395{
1396 adb shell input keyevent 82
1397}
1398
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001399function smoketest()
1400{
1401 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1402 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1403 return
1404 fi
1405 T=$(gettop)
1406 if [ ! "$T" ]; then
1407 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1408 return
1409 fi
1410
Ying Wang9cd17642012-12-13 10:52:07 -08001411 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001412 adb uninstall com.android.smoketest > /dev/null &&
1413 adb uninstall com.android.smoketest.tests > /dev/null &&
1414 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1415 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1416 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1417}
1418
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001419# simple shortcut to the runtest command
1420function runtest()
1421{
1422 T=$(gettop)
1423 if [ ! "$T" ]; then
1424 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1425 return
1426 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001427 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001428}
1429
The Android Open Source Project88b60792009-03-03 19:28:42 -08001430function godir () {
1431 if [[ -z "$1" ]]; then
1432 echo "Usage: godir <regex>"
1433 return
1434 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001435 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001436 if [[ ! -f $T/filelist ]]; then
1437 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001438 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001439 echo " Done"
1440 echo ""
1441 fi
1442 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001443 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001444 if [[ ${#lines[@]} = 0 ]]; then
1445 echo "Not found"
1446 return
1447 fi
1448 local pathname
1449 local choice
1450 if [[ ${#lines[@]} > 1 ]]; then
1451 while [[ -z "$pathname" ]]; do
1452 local index=1
1453 local line
1454 for line in ${lines[@]}; do
1455 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001456 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001457 done
1458 echo
1459 echo -n "Select one: "
1460 unset choice
1461 read choice
1462 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1463 echo "Invalid choice"
1464 continue
1465 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001466 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001467 done
1468 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001469 pathname=${lines[0]}
1470 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001471 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001472}
1473
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001474function cmremote()
1475{
1476 git remote rm cmremote 2> /dev/null
1477 if [ ! -d .git ]
1478 then
1479 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1480 fi
1481 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1482 if [ -z "$GERRIT_REMOTE" ]
1483 then
1484 echo Unable to set up the git remote, are you in the root of the repo?
1485 return 0
1486 fi
1487 CMUSER=`git config --get review.review.cyanogenmod.com.username`
1488 if [ -z "$CMUSER" ]
1489 then
1490 git remote add cmremote ssh://review.cyanogenmod.com:29418/$GERRIT_REMOTE
1491 else
1492 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.com:29418/$GERRIT_REMOTE
1493 fi
1494 echo You can now push to "cmremote".
1495}
1496
1497function cmgerrit() {
1498 if [ $# -eq 0 ]; then
1499 $FUNCNAME help
1500 return 1
1501 fi
1502 local user=`git config --get review.review.cyanogenmod.com.username`
1503 local review=`git config --get remote.github.review`
1504 local project=`git config --get remote.github.projectname`
1505 local command=$1
1506 shift
1507 case $command in
1508 help)
1509 if [ $# -eq 0 ]; then
1510 cat <<EOF
1511Usage:
1512 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1513
1514Commands:
1515 fetch Just fetch the change as FETCH_HEAD
1516 help Show this help, or for a specific command
1517 pull Pull a change into current branch
1518 push Push HEAD or a local branch to Gerrit for a specific branch
1519
1520Any other Git commands that support refname would work as:
1521 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1522
1523See '$FUNCNAME help COMMAND' for more information on a specific command.
1524
1525Example:
1526 $FUNCNAME checkout -b topic 1234/5
1527works as:
1528 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1529 && git checkout -b topic FETCH_HEAD
1530will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1531Patch-set 1 will be fetched if omitted.
1532EOF
1533 return
1534 fi
1535 case $1 in
1536 __cmg_*) echo "For internal use only." ;;
1537 changes|for)
1538 if [ "$FUNCNAME" = "cmgerrit" ]; then
1539 echo "'$FUNCNAME $1' is deprecated."
1540 fi
1541 ;;
1542 help) $FUNCNAME help ;;
1543 fetch|pull) cat <<EOF
1544usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1545
1546works as:
1547 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1548 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1549
1550Example:
1551 $FUNCNAME $1 1234
1552will $1 patch-set 1 of change 1234
1553EOF
1554 ;;
1555 push) cat <<EOF
1556usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1557
1558works as:
1559 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1560 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1561
1562Example:
1563 $FUNCNAME push fix6789:gingerbread
1564will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1565HEAD will be pushed from local if omitted.
1566EOF
1567 ;;
1568 *)
1569 $FUNCNAME __cmg_err_not_supported $1 && return
1570 cat <<EOF
1571usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1572
1573works as:
1574 git fetch http://DOMAIN/p/PROJECT \\
1575 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1576 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1577EOF
1578 ;;
1579 esac
1580 ;;
1581 __cmg_get_ref)
1582 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1583 local change_id patchset_id hash
1584 case $1 in
1585 */*)
1586 change_id=${1%%/*}
1587 patchset_id=${1#*/}
1588 ;;
1589 *)
1590 change_id=$1
1591 patchset_id=1
1592 ;;
1593 esac
1594 hash=$(($change_id % 100))
1595 case $hash in
1596 [0-9]) hash="0$hash" ;;
1597 esac
1598 echo "refs/changes/$hash/$change_id/$patchset_id"
1599 ;;
1600 fetch|pull)
1601 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1602 $FUNCNAME __cmg_err_not_repo && return 1
1603 local change=$1
1604 shift
1605 git $command $@ http://$review/p/$project \
1606 $($FUNCNAME __cmg_get_ref $change) || return 1
1607 ;;
1608 push)
1609 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1610 $FUNCNAME __cmg_err_not_repo && return 1
1611 if [ -z "$user" ]; then
1612 echo >&2 "Gerrit username not found."
1613 return 1
1614 fi
1615 local local_branch remote_branch
1616 case $1 in
1617 *:*)
1618 local_branch=${1%:*}
1619 remote_branch=${1##*:}
1620 ;;
1621 *)
1622 local_branch=HEAD
1623 remote_branch=$1
1624 ;;
1625 esac
1626 shift
1627 git push $@ ssh://$user@$review:29418/$project \
1628 $local_branch:refs/for/$remote_branch || return 1
1629 ;;
1630 changes|for)
1631 if [ "$FUNCNAME" = "cmgerrit" ]; then
1632 echo >&2 "'$FUNCNAME $command' is deprecated."
1633 fi
1634 ;;
1635 __cmg_err_no_arg)
1636 if [ $# -lt 2 ]; then
1637 echo >&2 "'$FUNCNAME $command' missing argument."
1638 elif [ $2 -eq 0 ]; then
1639 if [ -n "$3" ]; then
1640 $FUNCNAME help $1
1641 else
1642 echo >&2 "'$FUNCNAME $1' missing argument."
1643 fi
1644 else
1645 return 1
1646 fi
1647 ;;
1648 __cmg_err_not_repo)
1649 if [ -z "$review" -o -z "$project" ]; then
1650 echo >&2 "Not currently in any reviewable repository."
1651 else
1652 return 1
1653 fi
1654 ;;
1655 __cmg_err_not_supported)
1656 $FUNCNAME __cmg_err_no_arg $command $# && return
1657 case $1 in
1658 #TODO: filter more git commands that don't use refname
1659 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1660 echo >&2 "'$FUNCNAME $1' is not supported."
1661 ;;
1662 *) return 1 ;;
1663 esac
1664 ;;
1665 #TODO: other special cases?
1666 *)
1667 $FUNCNAME __cmg_err_not_supported $command && return 1
1668 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1669 $FUNCNAME __cmg_err_not_repo && return 1
1670 local args="$@"
1671 local change pre_args refs_arg post_args
1672 case "$args" in
1673 *--\ *)
1674 pre_args=${args%%-- *}
1675 post_args="-- ${args#*-- }"
1676 ;;
1677 *) pre_args="$args" ;;
1678 esac
1679 args=($pre_args)
1680 pre_args=
1681 if [ ${#args[@]} -gt 0 ]; then
1682 change=${args[${#args[@]}-1]}
1683 fi
1684 if [ ${#args[@]} -gt 1 ]; then
1685 pre_args=${args[0]}
1686 for ((i=1; i<${#args[@]}-1; i++)); do
1687 pre_args="$pre_args ${args[$i]}"
1688 done
1689 fi
1690 while ((1)); do
1691 case $change in
1692 ""|--)
1693 $FUNCNAME help $command
1694 return 1
1695 ;;
1696 *@*)
1697 if [ -z "$refs_arg" ]; then
1698 refs_arg="@${change#*@}"
1699 change=${change%%@*}
1700 fi
1701 ;;
1702 *~*)
1703 if [ -z "$refs_arg" ]; then
1704 refs_arg="~${change#*~}"
1705 change=${change%%~*}
1706 fi
1707 ;;
1708 *^*)
1709 if [ -z "$refs_arg" ]; then
1710 refs_arg="^${change#*^}"
1711 change=${change%%^*}
1712 fi
1713 ;;
1714 *:*)
1715 if [ -z "$refs_arg" ]; then
1716 refs_arg=":${change#*:}"
1717 change=${change%%:*}
1718 fi
1719 ;;
1720 *) break ;;
1721 esac
1722 done
1723 $FUNCNAME fetch $change \
1724 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1725 || return 1
1726 ;;
1727 esac
1728}
1729
1730function cmrebase() {
1731 local repo=$1
1732 local refs=$2
1733 local pwd="$(pwd)"
1734 local dir="$(gettop)/$repo"
1735
1736 if [ -z $repo ] || [ -z $refs ]; then
1737 echo "CyanogenMod Gerrit Rebase Usage: "
1738 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1739 echo " The patch IDs appear on the Gerrit commands that are offered."
1740 echo " They consist on a series of numbers and slashes, after the text"
1741 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1742 echo ""
1743 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1744 echo ""
1745 return
1746 fi
1747
1748 if [ ! -d $dir ]; then
1749 echo "Directory $dir doesn't exist in tree."
1750 return
1751 fi
1752 cd $dir
1753 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1754 echo "Starting branch..."
1755 repo start tmprebase .
1756 echo "Bringing it up to date..."
1757 repo sync .
1758 echo "Fetching change..."
1759 git fetch "http://review.cyanogenmod.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
1760 if [ "$?" != "0" ]; then
1761 echo "Error cherry-picking. Not uploading!"
1762 return
1763 fi
1764 echo "Uploading..."
1765 repo upload .
1766 echo "Cleaning up..."
1767 repo abandon tmprebase .
1768 cd $pwd
1769}
1770
1771function mka() {
1772 case `uname -s` in
1773 Darwin)
1774 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1775 ;;
1776 *)
1777 schedtool -B -n 1 -e ionice -n 1 make -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@"
1778 ;;
1779 esac
1780}
1781
1782function reposync() {
1783 case `uname -s` in
1784 Darwin)
1785 repo sync -j 4 "$@"
1786 ;;
1787 *)
1788 schedtool -B -n 1 -e ionice -n 1 repo sync -j 4 "$@"
1789 ;;
1790 esac
1791}
1792# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001793#
1794# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1795# For some reason, installing the JDK doesn't make it show up in the
1796# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001797function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001798 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001799 # we can reset it later, depending on the version of java the build
1800 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001801 #
1802 # If we don't do this, the JAVA_HOME value set by the first call to
1803 # build/envsetup.sh will persist forever.
1804 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1805 export JAVA_HOME=""
1806 fi
1807
Andy McFaddenbd960942010-06-24 12:52:51 -07001808 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01001809 case `uname -s` in
1810 Darwin)
1811 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1812 ;;
1813 *)
1814 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1815 ;;
1816 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001817
1818 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1819 # we can change it on the next envsetup.sh, if required.
1820 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001821 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001822}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001823
Alex Rayf0d08eb2013-03-08 15:15:06 -08001824# Print colored exit condition
1825function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001826 "$@"
1827 local retval=$?
1828 if [ $retval -ne 0 ]
1829 then
1830 echo -e "\e[0;31mFAILURE\e[00m"
1831 else
1832 echo -e "\e[0;32mSUCCESS\e[00m"
1833 fi
1834 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001835}
1836
Ying Wanged21d4c2014-08-24 22:14:19 -07001837function get_make_command()
1838{
1839 echo command make
1840}
1841
Ed Heylcc6be0a2014-06-18 14:55:58 -07001842function make()
1843{
1844 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001845 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001846 local ret=$?
1847 local end_time=$(date +"%s")
1848 local tdiff=$(($end_time-$start_time))
1849 local hours=$(($tdiff / 3600 ))
1850 local mins=$((($tdiff % 3600) / 60))
1851 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001852 local ncolors=$(tput colors 2>/dev/null)
1853 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
1854 color_failed="\e[0;31m"
1855 color_success="\e[0;32m"
1856 color_reset="\e[00m"
1857 else
1858 color_failed=""
1859 color_success=""
1860 color_reset=""
1861 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001862 echo
1863 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001864 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001865 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001866 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001867 fi
1868 if [ $hours -gt 0 ] ; then
1869 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1870 elif [ $mins -gt 0 ] ; then
1871 printf "(%02g:%02g (mm:ss))" $mins $secs
1872 elif [ $secs -gt 0 ] ; then
1873 printf "(%s seconds)" $secs
1874 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001875 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001876 echo
1877 return $ret
1878}
1879
Raphael Moll70a86b02011-06-20 16:03:14 -07001880if [ "x$SHELL" != "x/bin/bash" ]; then
1881 case `ps -o command -p $$` in
1882 *bash*)
1883 ;;
1884 *)
1885 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1886 ;;
1887 esac
1888fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001889
1890# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02001891for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
1892 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001893do
1894 echo "including $f"
1895 . $f
1896done
1897unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001898
1899addcompletions