blob: d20d8745b36d8405989f2440bbc53ddd0b8a4372 [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
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100704function eat()
705{
706 if [ "$OUT" ] ; then
707 MODVERSION=`sed -n -e'/ro\.cm\.version/s/.*=//p' $OUT/system/build.prop`
708 ZIPFILE=cm-$MODVERSION.zip
709 ZIPPATH=$OUT/$ZIPFILE
710 if [ ! -f $ZIPPATH ] ; then
711 echo "Nothing to eat"
712 return 1
713 fi
714 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
715 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
716 echo "No device is online. Waiting for one..."
717 echo "Please connect USB and/or enable USB debugging"
718 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
719 sleep 1
720 done
721 echo "Device Found.."
722 fi
723 # if adbd isn't root we can't write to /cache/recovery/
724 adb root
725 sleep 1
726 adb wait-for-device
727 SZ=`stat -c %s $ZIPPATH`
728 CACHESIZE=`adb shell busybox df -PB1 /cache | grep /cache | tr -s ' ' | cut -d ' ' -f 4`
729 if [ $CACHESIZE -gt $SZ ];
730 then
731 PUSHDIR=/cache/
732 DIR=cache
733 else
734 PUSHDIR=/storage/sdcard0/
735 # Optional path for sdcard0 in recovery
736 [ -z "$1" ] && DIR=sdcard/0 || DIR=$1
737 fi
738 echo "Pushing $ZIPFILE to $PUSHDIR"
739 if adb push $ZIPPATH $PUSHDIR ; then
740 cat << EOF > /tmp/command
741--update_package=/$DIR/$ZIPFILE
742EOF
743 if adb push /tmp/command /cache/recovery/ ; then
744 echo "Rebooting into recovery for installation"
745 adb reboot recovery
746 fi
747 rm /tmp/command
748 fi
749 else
750 echo "Nothing to eat"
751 return 1
752 fi
753 return $?
754}
755
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700756function gettop
757{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800758 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700759 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700760 # The following circumlocution ensures we remove symlinks from TOP.
761 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700762 else
763 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800764 # The following circumlocution (repeated below as well) ensures
765 # that we record the true directory name and not one that is
766 # faked up with symlink names.
767 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700768 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800769 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700770 T=
771 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800772 \cd ..
synergyb112a402013-07-05 19:47:47 -0700773 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700774 done
Ying Wang9cd17642012-12-13 10:52:07 -0800775 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700776 if [ -f "$T/$TOPFILE" ]; then
777 echo $T
778 fi
779 fi
780 fi
781}
782
Andrew Hsieh906cb782013-09-10 17:37:14 +0800783# Return driver for "make", if any (eg. static analyzer)
784function getdriver()
785{
786 local T="$1"
787 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
788 if [ -n "$WITH_STATIC_ANALYZER" ]; then
789 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800790$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
791--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800792--status-bugs \
793--top=$T"
794 fi
795}
796
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797function m()
798{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800799 local T=$(gettop)
800 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800802 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700803 else
804 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700805 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700806 fi
807}
808
809function findmakefile()
810{
811 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800812 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700813 T=
814 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700815 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700816 if [ -f "$T/Android.mk" ]; then
817 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800818 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700819 return
820 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800821 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700822 done
Ying Wang9cd17642012-12-13 10:52:07 -0800823 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700824}
825
826function mm()
827{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800828 local T=$(gettop)
829 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700830 # If we're sitting in the root of the build tree, just do a
831 # normal make.
832 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800833 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700834 else
835 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800836 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700837 local MODULES=
838 local GET_INSTALL_PATH=
839 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700840 # Remove the path to top as the makefilepath needs to be relative
841 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700842 if [ ! "$T" ]; then
843 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700844 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845 elif [ ! "$M" ]; then
846 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700847 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700848 else
Ying Wanga7deb082013-08-16 13:24:47 -0700849 for ARG in $@; do
850 case $ARG in
851 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
852 esac
853 done
854 if [ -n "$GET_INSTALL_PATH" ]; then
855 MODULES=
856 ARGS=GET-INSTALL-PATH
857 else
858 MODULES=all_modules
859 ARGS=$@
860 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700861 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 -0700862 fi
863 fi
864}
865
866function mmm()
867{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800868 local T=$(gettop)
869 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700870 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800871 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800872 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800873 local ARGS=
874 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700875 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800876 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
877 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
878 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800879 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
880 if [ "$MODULES" = "" ]; then
881 MODULES=all_modules
882 fi
883 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700884 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700885 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
886 local TO_CHOP=`expr $TO_CHOP + 1`
887 local START=`PWD= /bin/pwd`
888 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700889 if [ "$MFILE" = "" ] ; then
890 MFILE=$DIR/Android.mk
891 else
892 MFILE=$MFILE/$DIR/Android.mk
893 fi
894 MAKEFILE="$MAKEFILE $MFILE"
895 else
Ying Wanga7deb082013-08-16 13:24:47 -0700896 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100897 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700898 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
899 *) echo "No Android.mk in $DIR."; return 1;;
900 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700901 fi
902 done
Ying Wanga7deb082013-08-16 13:24:47 -0700903 if [ -n "$GET_INSTALL_PATH" ]; then
904 ARGS=$GET_INSTALL_PATH
905 MODULES=
906 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800907 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 -0700908 else
909 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700910 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700911 fi
912}
913
Ying Wangb607f7b2013-02-08 18:01:04 -0800914function mma()
915{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800916 local T=$(gettop)
917 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800918 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800919 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800920 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800921 if [ ! "$T" ]; then
922 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700923 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800924 fi
925 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800926 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800927 fi
928}
929
930function mmma()
931{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800932 local T=$(gettop)
933 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800934 if [ "$T" ]; then
935 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
936 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
937 local MY_PWD=`PWD= /bin/pwd`
938 if [ "$MY_PWD" = "$T" ]; then
939 MY_PWD=
940 else
941 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
942 fi
943 local DIR=
944 local MODULE_PATHS=
945 local ARGS=
946 for DIR in $DIRS ; do
947 if [ -d $DIR ]; then
948 if [ "$MY_PWD" = "" ]; then
949 MODULE_PATHS="$MODULE_PATHS $DIR"
950 else
951 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
952 fi
953 else
954 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100955 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800956 *) echo "Couldn't find directory $DIR"; return 1;;
957 esac
958 fi
959 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800960 $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 -0800961 else
962 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700963 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800964 fi
965}
966
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967function croot()
968{
969 T=$(gettop)
970 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800971 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700972 else
973 echo "Couldn't locate the top of the tree. Try setting TOP."
974 fi
975}
976
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700977function cproj()
978{
979 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700980 local HERE=$PWD
981 T=
982 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
983 T=$PWD
984 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800985 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700986 return
987 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800988 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700989 done
Ying Wang9cd17642012-12-13 10:52:07 -0800990 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700991 echo "can't find Android.mk"
992}
993
Daniel Sandler47e0a882013-07-30 13:23:52 -0400994# simplified version of ps; output in the form
995# <pid> <procname>
996function qpid() {
997 local prepend=''
998 local append=''
999 if [ "$1" = "--exact" ]; then
1000 prepend=' '
1001 append='$'
1002 shift
1003 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1004 echo "usage: qpid [[--exact] <process name|pid>"
1005 return 255
1006 fi
1007
1008 local EXE="$1"
1009 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001010 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001011 else
1012 adb shell ps \
1013 | tr -d '\r' \
1014 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1015 fi
1016}
1017
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001018function pid()
1019{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001020 local prepend=''
1021 local append=''
1022 if [ "$1" = "--exact" ]; then
1023 prepend=' '
1024 append='$'
1025 shift
1026 fi
1027 local EXE="$1"
1028 if [ "$EXE" ] ; then
1029 local PID=`adb shell ps \
1030 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001031 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001032 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1033 echo "$PID"
1034 else
1035 echo "usage: pid [--exact] <process name>"
1036 return 255
1037 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001038}
1039
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001040# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001041# that has the core-file-size limit set correctly
1042#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001043# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001044# if its core-file-size limit is not set already.
1045# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1046
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001047function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001048{
1049 echo "Getting root...";
1050 adb root;
1051 adb wait-for-device;
1052
1053 echo "Remounting root parition read-write...";
1054 adb shell mount -w -o remount -t rootfs rootfs;
1055 sleep 1;
1056 adb wait-for-device;
1057 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001058 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001059 adb shell chmod 0777 /cores;
1060
1061 echo "Granting SELinux permission to dump in /cores...";
1062 adb shell restorecon -R /cores;
1063
1064 echo "Set core pattern.";
1065 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1066
1067 echo "Done."
1068}
1069
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001070# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001071# $1 = PID of process (e.g., $(pid mediaserver))
1072#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001073# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001074# dump to actually be generated.
1075
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001076function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001077{
1078 local PID=$1;
1079 if [ -z "$PID" ]; then
1080 printf "Expecting a PID!\n";
1081 return;
1082 fi;
1083 echo "Setting core limit for $PID to infinite...";
1084 adb shell prlimit $PID 4 -1 -1
1085}
1086
1087# core - send SIGV and pull the core for process
1088# $1 = PID of process (e.g., $(pid mediaserver))
1089#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001090# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001091# enabled globally.
1092
1093function core()
1094{
1095 local PID=$1;
1096
1097 if [ -z "$PID" ]; then
1098 printf "Expecting a PID!\n";
1099 return;
1100 fi;
1101
1102 local CORENAME=core.$PID;
1103 local COREPATH=/cores/$CORENAME;
1104 local SIG=SEGV;
1105
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001106 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001107
1108 local done=0;
1109 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1110 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1111 adb shell kill -$SIG $PID;
1112 sleep 1;
1113 done;
1114
1115 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1116 echo "Done: core is under $COREPATH on device.";
1117}
1118
Christopher Tate744ee802009-11-12 15:33:08 -08001119# systemstack - dump the current stack trace of all threads in the system process
1120# to the usual ANR traces file
1121function systemstack()
1122{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001123 stacks system_server
1124}
1125
1126function stacks()
1127{
1128 if [[ $1 =~ ^[0-9]+$ ]] ; then
1129 local PID="$1"
1130 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001131 local PIDLIST="$(pid $1)"
1132 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1133 local PID="$PIDLIST"
1134 elif [ "$PIDLIST" ] ; then
1135 echo "more than one process: $1"
1136 else
1137 echo "no such process: $1"
1138 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001139 else
1140 echo "usage: stacks [pid|process name]"
1141 fi
1142
1143 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001144 # Determine whether the process is native
1145 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1146 # Dump stacks of Dalvik process
1147 local TRACES=/data/anr/traces.txt
1148 local ORIG=/data/anr/traces.orig
1149 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001150
Jeff Brownb12c2e52013-08-19 15:14:16 -07001151 # Keep original traces to avoid clobbering
1152 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001153
Jeff Brownb12c2e52013-08-19 15:14:16 -07001154 # Make sure we have a usable file
1155 adb shell touch $TRACES
1156 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001157
Jeff Brownb12c2e52013-08-19 15:14:16 -07001158 # Dump stacks and wait for dump to finish
1159 adb shell kill -3 $PID
1160 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001161
Jeff Brownb12c2e52013-08-19 15:14:16 -07001162 # Restore original stacks, and show current output
1163 adb shell mv $TRACES $TMP
1164 adb shell mv $ORIG $TRACES
1165 adb shell cat $TMP
1166 else
1167 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001168 local USE64BIT="$(is64bit $PID)"
1169 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001170 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001171 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001172}
1173
Michael Wrightaeed7212014-06-19 19:58:12 -07001174# Read the ELF header from /proc/$PID/exe to determine if the process is
1175# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001176function is64bit()
1177{
1178 local PID="$1"
1179 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001180 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001181 echo "64"
1182 else
1183 echo ""
1184 fi
1185 else
1186 echo ""
1187 fi
1188}
1189
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001190case `uname -s` in
1191 Darwin)
1192 function sgrep()
1193 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001194 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 -07001195 }
1196
1197 ;;
1198 *)
1199 function sgrep()
1200 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001201 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 -07001202 }
1203 ;;
1204esac
1205
Raghu Gandham8da43102012-07-25 19:57:22 -07001206function gettargetarch
1207{
1208 get_build_var TARGET_ARCH
1209}
1210
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001211function ggrep()
1212{
1213 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1214}
1215
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001216function jgrep()
1217{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001218 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 -07001219}
1220
1221function cgrep()
1222{
Dan Albert01961192014-11-22 10:16:01 -08001223 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 -07001224}
1225
1226function resgrep()
1227{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001228 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 -07001229}
1230
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001231function mangrep()
1232{
1233 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1234}
1235
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001236function sepgrep()
1237{
1238 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 "$@"
1239}
1240
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001241function rcgrep()
1242{
1243 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1244}
1245
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001246case `uname -s` in
1247 Darwin)
1248 function mgrep()
1249 {
Ying Wang324c2b22012-08-17 15:03:20 -07001250 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 -07001251 }
1252
1253 function treegrep()
1254 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001255 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 -07001256 }
1257
1258 ;;
1259 *)
1260 function mgrep()
1261 {
Ying Wang324c2b22012-08-17 15:03:20 -07001262 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 -07001263 }
1264
1265 function treegrep()
1266 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001267 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 -07001268 }
1269
1270 ;;
1271esac
1272
1273function getprebuilt
1274{
1275 get_abs_build_var ANDROID_PREBUILTS
1276}
1277
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001278function tracedmdump()
1279{
1280 T=$(gettop)
1281 if [ ! "$T" ]; then
1282 echo "Couldn't locate the top of the tree. Try setting TOP."
1283 return
1284 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001285 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001286 local arch=$(gettargetarch)
1287 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001288
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001289 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001290 if [ ! "$TRACE" ] ; then
1291 echo "usage: tracedmdump tracename"
1292 return
1293 fi
1294
Jack Veenstra60116fc2009-04-09 18:12:34 -07001295 if [ ! -r "$KERNEL" ] ; then
1296 echo "Error: cannot find kernel: '$KERNEL'"
1297 return
1298 fi
1299
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001300 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001301 if [ "$BASETRACE" = "$TRACE" ] ; then
1302 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1303 fi
1304
1305 echo "post-processing traces..."
1306 rm -f $TRACE/qtrace.dexlist
1307 post_trace $TRACE
1308 if [ $? -ne 0 ]; then
1309 echo "***"
1310 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1311 echo "***"
1312 return
1313 fi
1314 echo "generating dexlist output..."
1315 /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
1316 echo "generating dmtrace data..."
1317 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1318 echo "generating html file..."
1319 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1320 echo "done, see $TRACE/dmtrace.html for details"
1321 echo "or run:"
1322 echo " traceview $TRACE/dmtrace"
1323}
1324
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001325# communicate with a running device or emulator, set up necessary state,
1326# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001327function runhat()
1328{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001329 # process standard adb options
1330 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001331 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001332 adbTarget=$1
1333 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001334 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001335 adbTarget="$1 $2"
1336 shift 2
1337 fi
1338 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001339 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001340
1341 # runhat options
1342 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001343
1344 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001345 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001346 return
1347 fi
1348
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001349 # confirm hat is available
1350 if [ -z $(which hat) ]; then
1351 echo "hat is not available in this configuration."
1352 return
1353 fi
1354
Andy McFaddenb6289852010-07-12 08:00:19 -07001355 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001356 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001357 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001358 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001359 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001360 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001361 echo -n "> "
1362 read
1363
The Android Open Source Project88b60792009-03-03 19:28:42 -08001364 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001365
The Android Open Source Project88b60792009-03-03 19:28:42 -08001366 echo "Retrieving file $devFile..."
1367 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001368
The Android Open Source Project88b60792009-03-03 19:28:42 -08001369 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001370
The Android Open Source Project88b60792009-03-03 19:28:42 -08001371 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001372 echo "View the output by pointing your browser at http://localhost:7000/"
1373 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001374 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001375}
1376
1377function getbugreports()
1378{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001379 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001380
1381 if [ ! "$reports" ]; then
1382 echo "Could not locate any bugreports."
1383 return
1384 fi
1385
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001386 local report
1387 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001388 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001389 echo "/sdcard/bugreports/${report}"
1390 adb pull /sdcard/bugreports/${report} ${report}
1391 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001392 done
1393}
1394
Victoria Lease1b296b42012-08-21 15:44:06 -07001395function getsdcardpath()
1396{
1397 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1398}
1399
1400function getscreenshotpath()
1401{
1402 echo "$(getsdcardpath)/Pictures/Screenshots"
1403}
1404
1405function getlastscreenshot()
1406{
1407 local screenshot_path=$(getscreenshotpath)
1408 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1409 if [ "$screenshot" = "" ]; then
1410 echo "No screenshots found."
1411 return
1412 fi
1413 echo "${screenshot}"
1414 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1415}
1416
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001417function startviewserver()
1418{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001419 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001420 if [ $# -gt 0 ]; then
1421 port=$1
1422 fi
1423 adb shell service call window 1 i32 $port
1424}
1425
1426function stopviewserver()
1427{
1428 adb shell service call window 2
1429}
1430
1431function isviewserverstarted()
1432{
1433 adb shell service call window 3
1434}
1435
Romain Guyb84049a2010-10-04 16:56:11 -07001436function key_home()
1437{
1438 adb shell input keyevent 3
1439}
1440
1441function key_back()
1442{
1443 adb shell input keyevent 4
1444}
1445
1446function key_menu()
1447{
1448 adb shell input keyevent 82
1449}
1450
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001451function smoketest()
1452{
1453 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1454 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1455 return
1456 fi
1457 T=$(gettop)
1458 if [ ! "$T" ]; then
1459 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1460 return
1461 fi
1462
Ying Wang9cd17642012-12-13 10:52:07 -08001463 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001464 adb uninstall com.android.smoketest > /dev/null &&
1465 adb uninstall com.android.smoketest.tests > /dev/null &&
1466 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1467 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1468 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1469}
1470
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001471# simple shortcut to the runtest command
1472function runtest()
1473{
1474 T=$(gettop)
1475 if [ ! "$T" ]; then
1476 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1477 return
1478 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001479 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001480}
1481
The Android Open Source Project88b60792009-03-03 19:28:42 -08001482function godir () {
1483 if [[ -z "$1" ]]; then
1484 echo "Usage: godir <regex>"
1485 return
1486 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001487 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001488 if [[ ! -f $T/filelist ]]; then
1489 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001490 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001491 echo " Done"
1492 echo ""
1493 fi
1494 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001495 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001496 if [[ ${#lines[@]} = 0 ]]; then
1497 echo "Not found"
1498 return
1499 fi
1500 local pathname
1501 local choice
1502 if [[ ${#lines[@]} > 1 ]]; then
1503 while [[ -z "$pathname" ]]; do
1504 local index=1
1505 local line
1506 for line in ${lines[@]}; do
1507 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001508 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001509 done
1510 echo
1511 echo -n "Select one: "
1512 unset choice
1513 read choice
1514 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1515 echo "Invalid choice"
1516 continue
1517 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001518 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001519 done
1520 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001521 pathname=${lines[0]}
1522 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001523 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001524}
1525
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001526function cmremote()
1527{
1528 git remote rm cmremote 2> /dev/null
1529 if [ ! -d .git ]
1530 then
1531 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1532 fi
1533 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1534 if [ -z "$GERRIT_REMOTE" ]
1535 then
1536 echo Unable to set up the git remote, are you in the root of the repo?
1537 return 0
1538 fi
1539 CMUSER=`git config --get review.review.cyanogenmod.com.username`
1540 if [ -z "$CMUSER" ]
1541 then
1542 git remote add cmremote ssh://review.cyanogenmod.com:29418/$GERRIT_REMOTE
1543 else
1544 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.com:29418/$GERRIT_REMOTE
1545 fi
1546 echo You can now push to "cmremote".
1547}
1548
1549function cmgerrit() {
1550 if [ $# -eq 0 ]; then
1551 $FUNCNAME help
1552 return 1
1553 fi
1554 local user=`git config --get review.review.cyanogenmod.com.username`
1555 local review=`git config --get remote.github.review`
1556 local project=`git config --get remote.github.projectname`
1557 local command=$1
1558 shift
1559 case $command in
1560 help)
1561 if [ $# -eq 0 ]; then
1562 cat <<EOF
1563Usage:
1564 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1565
1566Commands:
1567 fetch Just fetch the change as FETCH_HEAD
1568 help Show this help, or for a specific command
1569 pull Pull a change into current branch
1570 push Push HEAD or a local branch to Gerrit for a specific branch
1571
1572Any other Git commands that support refname would work as:
1573 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1574
1575See '$FUNCNAME help COMMAND' for more information on a specific command.
1576
1577Example:
1578 $FUNCNAME checkout -b topic 1234/5
1579works as:
1580 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1581 && git checkout -b topic FETCH_HEAD
1582will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1583Patch-set 1 will be fetched if omitted.
1584EOF
1585 return
1586 fi
1587 case $1 in
1588 __cmg_*) echo "For internal use only." ;;
1589 changes|for)
1590 if [ "$FUNCNAME" = "cmgerrit" ]; then
1591 echo "'$FUNCNAME $1' is deprecated."
1592 fi
1593 ;;
1594 help) $FUNCNAME help ;;
1595 fetch|pull) cat <<EOF
1596usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1597
1598works as:
1599 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1600 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1601
1602Example:
1603 $FUNCNAME $1 1234
1604will $1 patch-set 1 of change 1234
1605EOF
1606 ;;
1607 push) cat <<EOF
1608usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1609
1610works as:
1611 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1612 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1613
1614Example:
1615 $FUNCNAME push fix6789:gingerbread
1616will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1617HEAD will be pushed from local if omitted.
1618EOF
1619 ;;
1620 *)
1621 $FUNCNAME __cmg_err_not_supported $1 && return
1622 cat <<EOF
1623usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1624
1625works as:
1626 git fetch http://DOMAIN/p/PROJECT \\
1627 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1628 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1629EOF
1630 ;;
1631 esac
1632 ;;
1633 __cmg_get_ref)
1634 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1635 local change_id patchset_id hash
1636 case $1 in
1637 */*)
1638 change_id=${1%%/*}
1639 patchset_id=${1#*/}
1640 ;;
1641 *)
1642 change_id=$1
1643 patchset_id=1
1644 ;;
1645 esac
1646 hash=$(($change_id % 100))
1647 case $hash in
1648 [0-9]) hash="0$hash" ;;
1649 esac
1650 echo "refs/changes/$hash/$change_id/$patchset_id"
1651 ;;
1652 fetch|pull)
1653 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1654 $FUNCNAME __cmg_err_not_repo && return 1
1655 local change=$1
1656 shift
1657 git $command $@ http://$review/p/$project \
1658 $($FUNCNAME __cmg_get_ref $change) || return 1
1659 ;;
1660 push)
1661 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1662 $FUNCNAME __cmg_err_not_repo && return 1
1663 if [ -z "$user" ]; then
1664 echo >&2 "Gerrit username not found."
1665 return 1
1666 fi
1667 local local_branch remote_branch
1668 case $1 in
1669 *:*)
1670 local_branch=${1%:*}
1671 remote_branch=${1##*:}
1672 ;;
1673 *)
1674 local_branch=HEAD
1675 remote_branch=$1
1676 ;;
1677 esac
1678 shift
1679 git push $@ ssh://$user@$review:29418/$project \
1680 $local_branch:refs/for/$remote_branch || return 1
1681 ;;
1682 changes|for)
1683 if [ "$FUNCNAME" = "cmgerrit" ]; then
1684 echo >&2 "'$FUNCNAME $command' is deprecated."
1685 fi
1686 ;;
1687 __cmg_err_no_arg)
1688 if [ $# -lt 2 ]; then
1689 echo >&2 "'$FUNCNAME $command' missing argument."
1690 elif [ $2 -eq 0 ]; then
1691 if [ -n "$3" ]; then
1692 $FUNCNAME help $1
1693 else
1694 echo >&2 "'$FUNCNAME $1' missing argument."
1695 fi
1696 else
1697 return 1
1698 fi
1699 ;;
1700 __cmg_err_not_repo)
1701 if [ -z "$review" -o -z "$project" ]; then
1702 echo >&2 "Not currently in any reviewable repository."
1703 else
1704 return 1
1705 fi
1706 ;;
1707 __cmg_err_not_supported)
1708 $FUNCNAME __cmg_err_no_arg $command $# && return
1709 case $1 in
1710 #TODO: filter more git commands that don't use refname
1711 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1712 echo >&2 "'$FUNCNAME $1' is not supported."
1713 ;;
1714 *) return 1 ;;
1715 esac
1716 ;;
1717 #TODO: other special cases?
1718 *)
1719 $FUNCNAME __cmg_err_not_supported $command && return 1
1720 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1721 $FUNCNAME __cmg_err_not_repo && return 1
1722 local args="$@"
1723 local change pre_args refs_arg post_args
1724 case "$args" in
1725 *--\ *)
1726 pre_args=${args%%-- *}
1727 post_args="-- ${args#*-- }"
1728 ;;
1729 *) pre_args="$args" ;;
1730 esac
1731 args=($pre_args)
1732 pre_args=
1733 if [ ${#args[@]} -gt 0 ]; then
1734 change=${args[${#args[@]}-1]}
1735 fi
1736 if [ ${#args[@]} -gt 1 ]; then
1737 pre_args=${args[0]}
1738 for ((i=1; i<${#args[@]}-1; i++)); do
1739 pre_args="$pre_args ${args[$i]}"
1740 done
1741 fi
1742 while ((1)); do
1743 case $change in
1744 ""|--)
1745 $FUNCNAME help $command
1746 return 1
1747 ;;
1748 *@*)
1749 if [ -z "$refs_arg" ]; then
1750 refs_arg="@${change#*@}"
1751 change=${change%%@*}
1752 fi
1753 ;;
1754 *~*)
1755 if [ -z "$refs_arg" ]; then
1756 refs_arg="~${change#*~}"
1757 change=${change%%~*}
1758 fi
1759 ;;
1760 *^*)
1761 if [ -z "$refs_arg" ]; then
1762 refs_arg="^${change#*^}"
1763 change=${change%%^*}
1764 fi
1765 ;;
1766 *:*)
1767 if [ -z "$refs_arg" ]; then
1768 refs_arg=":${change#*:}"
1769 change=${change%%:*}
1770 fi
1771 ;;
1772 *) break ;;
1773 esac
1774 done
1775 $FUNCNAME fetch $change \
1776 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1777 || return 1
1778 ;;
1779 esac
1780}
1781
1782function cmrebase() {
1783 local repo=$1
1784 local refs=$2
1785 local pwd="$(pwd)"
1786 local dir="$(gettop)/$repo"
1787
1788 if [ -z $repo ] || [ -z $refs ]; then
1789 echo "CyanogenMod Gerrit Rebase Usage: "
1790 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1791 echo " The patch IDs appear on the Gerrit commands that are offered."
1792 echo " They consist on a series of numbers and slashes, after the text"
1793 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1794 echo ""
1795 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1796 echo ""
1797 return
1798 fi
1799
1800 if [ ! -d $dir ]; then
1801 echo "Directory $dir doesn't exist in tree."
1802 return
1803 fi
1804 cd $dir
1805 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1806 echo "Starting branch..."
1807 repo start tmprebase .
1808 echo "Bringing it up to date..."
1809 repo sync .
1810 echo "Fetching change..."
1811 git fetch "http://review.cyanogenmod.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
1812 if [ "$?" != "0" ]; then
1813 echo "Error cherry-picking. Not uploading!"
1814 return
1815 fi
1816 echo "Uploading..."
1817 repo upload .
1818 echo "Cleaning up..."
1819 repo abandon tmprebase .
1820 cd $pwd
1821}
1822
1823function mka() {
1824 case `uname -s` in
1825 Darwin)
1826 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1827 ;;
1828 *)
1829 schedtool -B -n 1 -e ionice -n 1 make -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@"
1830 ;;
1831 esac
1832}
1833
1834function reposync() {
1835 case `uname -s` in
1836 Darwin)
1837 repo sync -j 4 "$@"
1838 ;;
1839 *)
1840 schedtool -B -n 1 -e ionice -n 1 repo sync -j 4 "$@"
1841 ;;
1842 esac
1843}
1844# 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 +00001845#
1846# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1847# For some reason, installing the JDK doesn't make it show up in the
1848# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001849function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001850 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001851 # we can reset it later, depending on the version of java the build
1852 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001853 #
1854 # If we don't do this, the JAVA_HOME value set by the first call to
1855 # build/envsetup.sh will persist forever.
1856 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1857 export JAVA_HOME=""
1858 fi
1859
Andy McFaddenbd960942010-06-24 12:52:51 -07001860 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01001861 case `uname -s` in
1862 Darwin)
1863 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1864 ;;
1865 *)
1866 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1867 ;;
1868 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001869
1870 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1871 # we can change it on the next envsetup.sh, if required.
1872 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001873 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001874}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001875
Alex Rayf0d08eb2013-03-08 15:15:06 -08001876# Print colored exit condition
1877function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001878 "$@"
1879 local retval=$?
1880 if [ $retval -ne 0 ]
1881 then
1882 echo -e "\e[0;31mFAILURE\e[00m"
1883 else
1884 echo -e "\e[0;32mSUCCESS\e[00m"
1885 fi
1886 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001887}
1888
Ying Wanged21d4c2014-08-24 22:14:19 -07001889function get_make_command()
1890{
1891 echo command make
1892}
1893
Ed Heylcc6be0a2014-06-18 14:55:58 -07001894function make()
1895{
1896 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001897 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001898 local ret=$?
1899 local end_time=$(date +"%s")
1900 local tdiff=$(($end_time-$start_time))
1901 local hours=$(($tdiff / 3600 ))
1902 local mins=$((($tdiff % 3600) / 60))
1903 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001904 local ncolors=$(tput colors 2>/dev/null)
1905 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
1906 color_failed="\e[0;31m"
1907 color_success="\e[0;32m"
1908 color_reset="\e[00m"
1909 else
1910 color_failed=""
1911 color_success=""
1912 color_reset=""
1913 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001914 echo
1915 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001916 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001917 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001918 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001919 fi
1920 if [ $hours -gt 0 ] ; then
1921 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1922 elif [ $mins -gt 0 ] ; then
1923 printf "(%02g:%02g (mm:ss))" $mins $secs
1924 elif [ $secs -gt 0 ] ; then
1925 printf "(%s seconds)" $secs
1926 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001927 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001928 echo
1929 return $ret
1930}
1931
Raphael Moll70a86b02011-06-20 16:03:14 -07001932if [ "x$SHELL" != "x/bin/bash" ]; then
1933 case `ps -o command -p $$` in
1934 *bash*)
1935 ;;
1936 *)
1937 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1938 ;;
1939 esac
1940fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001941
1942# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02001943for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
1944 `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 -08001945do
1946 echo "including $f"
1947 . $f
1948done
1949unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001950
1951addcompletions