blob: 766ddb41e2422684bd4fd72b2837c67091358c6c [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Ying Wang67f02922012-08-22 10:25:20 -07004- lunch: lunch <product_name>-<build_variant>
Ying Wangb541ab62014-05-29 17:57:40 -07005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07006- croot: Changes directory to the top of the tree.
7- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08008- mm: Builds all of the modules in the current directory, but not their dependencies.
9- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000010 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080011- mma: Builds all of the modules in the current directory, and their dependencies.
12- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070013- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070014- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070015- jgrep: Greps on all local Java files.
16- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000017- mangrep: Greps on all local AndroidManifest.xml files.
18- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070019- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080020- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070021
Dan Albert4ae5d4b2014-10-31 16:23:08 -070022Environemnt options:
23- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
24 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
25 build is leak-check clean.
26
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070027Look at the source to view more functions. The complete list is:
28EOF
29 T=$(gettop)
30 local A
31 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070032 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070033 A="$A $i"
34 done
35 echo $A
36}
37
38# Get the value of a build variable as an absolute path.
39function get_abs_build_var()
40{
41 T=$(gettop)
42 if [ ! "$T" ]; then
43 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
44 return
45 fi
Ying Wang9cd17642012-12-13 10:52:07 -080046 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070047 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070048}
49
50# Get the exact value of a build variable.
51function get_build_var()
52{
53 T=$(gettop)
54 if [ ! "$T" ]; then
55 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
56 return
57 fi
Andrew Boie6905e212013-12-19 13:21:46 -080058 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070059 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080060}
61
62# check to see if the supplied product is one we can build
63function check_product()
64{
65 T=$(gettop)
66 if [ ! "$T" ]; then
67 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
68 return
69 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -070070 TARGET_PRODUCT=$1 \
71 TARGET_BUILD_VARIANT= \
72 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070073 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080074 get_build_var TARGET_DEVICE > /dev/null
75 # hide successful answers, but allow the errors to show
76}
77
78VARIANT_CHOICES=(user userdebug eng)
79
80# check to see if the supplied variant is valid
81function check_variant()
82{
83 for v in ${VARIANT_CHOICES[@]}
84 do
85 if [ "$v" = "$1" ]
86 then
87 return 0
88 fi
89 done
90 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070091}
92
93function setpaths()
94{
95 T=$(gettop)
96 if [ ! "$T" ]; then
97 echo "Couldn't locate the top of the tree. Try setting TOP."
98 return
99 fi
100
101 ##################################################################
102 # #
103 # Read me before you modify this code #
104 # #
105 # This function sets ANDROID_BUILD_PATHS to what it is adding #
106 # to PATH, and the next time it is run, it removes that from #
107 # PATH. This is required so lunch can be run more than once #
108 # and still have working paths. #
109 # #
110 ##################################################################
111
Raphael Mollc639c782011-06-20 17:25:01 -0700112 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
113 # due to "C:\Program Files" being in the path.
114
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700115 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700116 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700117 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
118 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700119 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700120 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800121 # strip leading ':', if any
122 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500123 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700124
125 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700126 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700127 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700128
Ben Cheng8bc4c432012-11-16 13:29:13 -0800129 # defined in core/config.mk
130 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700131 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800132 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800133
Raphael Mollc639c782011-06-20 17:25:01 -0700134 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800135 export ANDROID_TOOLCHAIN=
136 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200137 local ARCH=$(get_build_var TARGET_ARCH)
138 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400139 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700140 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400141 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
142 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800143 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200144 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800145 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700146 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700147 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700148 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000149 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200150 *)
151 echo "Can't find toolchain for unknown architecture: $ARCH"
152 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700153 ;;
154 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700155 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800156 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700157 fi
Raphael732936d2011-06-22 14:35:32 -0700158
Ben Chengfba67bf2014-02-25 10:27:07 -0800159 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
160 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
161 fi
162
163 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700164 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700165 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800166 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800167 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700168 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100169 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
170 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700171 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700172 ;;
173 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700174 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700175 ;;
176 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700177
Ying Wang564f9122013-03-29 17:40:14 -0700178 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wang2a859d52014-06-30 10:25:33 -0700179 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200180
181 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
182 # to ensure that the corresponding 'emulator' binaries are used.
183 case $(uname -s) in
184 Darwin)
185 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
186 ;;
187 Linux)
188 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
189 ;;
190 *)
191 ANDROID_EMULATOR_PREBUILTS=
192 ;;
193 esac
194 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700195 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200196 export ANDROID_EMULATOR_PREBUILTS
197 fi
198
Ying Wangaa1c9b52012-11-26 20:51:59 -0800199 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800200
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500201 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900202 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500203 if [ -n "$JAVA_HOME" ]; then
204 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900205 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
206 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500207 fi
208
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800209 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700210 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
211 export OUT=$ANDROID_PRODUCT_OUT
212
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700213 unset ANDROID_HOST_OUT
214 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
215
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800216 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700217 # TODO: fix the path
218 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
219}
220
221function printconfig()
222{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800223 T=$(gettop)
224 if [ ! "$T" ]; then
225 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
226 return
227 fi
228 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700229}
230
231function set_stuff_for_environment()
232{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800233 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500234 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800235 setpaths
236 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700237
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800238 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700239 # With this environment variable new GCC can apply colors to warnings/errors
240 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
Dan Albert4ae5d4b2014-10-31 16:23:08 -0700241 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700242}
243
244function set_sequence_number()
245{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700246 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700247}
248
249function settitle()
250{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700252 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700253 local product=$TARGET_PRODUCT
254 local variant=$TARGET_BUILD_VARIANT
255 local apps=$TARGET_BUILD_APPS
256 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700257 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700258 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700259 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700260 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800261 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700262}
263
Kenny Root52aa81c2011-07-15 11:07:06 -0700264function addcompletions()
265{
266 local T dir f
267
268 # Keep us from trying to run in something that isn't bash.
269 if [ -z "${BASH_VERSION}" ]; then
270 return
271 fi
272
273 # Keep us from trying to run in bash that's too old.
274 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
275 return
276 fi
277
278 dir="sdk/bash_completion"
279 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700280 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700281 echo "including $f"
282 . $f
283 done
284 fi
285}
286
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700287function choosetype()
288{
289 echo "Build type choices are:"
290 echo " 1. release"
291 echo " 2. debug"
292 echo
293
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800294 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700295 DEFAULT_NUM=1
296 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800298 export TARGET_BUILD_TYPE=
299 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300 while [ -z $TARGET_BUILD_TYPE ]
301 do
302 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303 if [ -z "$1" ] ; then
304 read ANSWER
305 else
306 echo $1
307 ANSWER=$1
308 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309 case $ANSWER in
310 "")
311 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
312 ;;
313 1)
314 export TARGET_BUILD_TYPE=release
315 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 release)
317 export TARGET_BUILD_TYPE=release
318 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319 2)
320 export TARGET_BUILD_TYPE=debug
321 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800322 debug)
323 export TARGET_BUILD_TYPE=debug
324 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325 *)
326 echo
327 echo "I didn't understand your response. Please try again."
328 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700329 ;;
330 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 if [ -n "$1" ] ; then
332 break
333 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700334 done
335
336 set_stuff_for_environment
337}
338
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800339#
340# This function isn't really right: It chooses a TARGET_PRODUCT
341# based on the list of boards. Usually, that gets you something
342# that kinda works with a generic product, but really, you should
343# pick a product by name.
344#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700345function chooseproduct()
346{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 if [ "x$TARGET_PRODUCT" != x ] ; then
348 default_value=$TARGET_PRODUCT
349 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700350 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700351 fi
352
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800353 export TARGET_PRODUCT=
354 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700355 while [ -z "$TARGET_PRODUCT" ]
356 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700357 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800358 if [ -z "$1" ] ; then
359 read ANSWER
360 else
361 echo $1
362 ANSWER=$1
363 fi
364
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700365 if [ -z "$ANSWER" ] ; then
366 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800367 else
368 if check_product $ANSWER
369 then
370 export TARGET_PRODUCT=$ANSWER
371 else
372 echo "** Not a valid product: $ANSWER"
373 fi
374 fi
375 if [ -n "$1" ] ; then
376 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700377 fi
378 done
379
380 set_stuff_for_environment
381}
382
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800383function choosevariant()
384{
385 echo "Variant choices are:"
386 local index=1
387 local v
388 for v in ${VARIANT_CHOICES[@]}
389 do
390 # The product name is the name of the directory containing
391 # the makefile we found, above.
392 echo " $index. $v"
393 index=$(($index+1))
394 done
395
396 local default_value=eng
397 local ANSWER
398
399 export TARGET_BUILD_VARIANT=
400 while [ -z "$TARGET_BUILD_VARIANT" ]
401 do
402 echo -n "Which would you like? [$default_value] "
403 if [ -z "$1" ] ; then
404 read ANSWER
405 else
406 echo $1
407 ANSWER=$1
408 fi
409
410 if [ -z "$ANSWER" ] ; then
411 export TARGET_BUILD_VARIANT=$default_value
412 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
413 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800414 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800415 fi
416 else
417 if check_variant $ANSWER
418 then
419 export TARGET_BUILD_VARIANT=$ANSWER
420 else
421 echo "** Not a valid variant: $ANSWER"
422 fi
423 fi
424 if [ -n "$1" ] ; then
425 break
426 fi
427 done
428}
429
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700430function choosecombo()
431{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700432 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700433
434 echo
435 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700436 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700437
438 echo
439 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700440 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800441
442 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700443 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800444 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700445}
446
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800447# Clear this variable. It will be built up again when the vendorsetup.sh
448# files are included at the end of this file.
449unset LUNCH_MENU_CHOICES
450function add_lunch_combo()
451{
452 local new_combo=$1
453 local c
454 for c in ${LUNCH_MENU_CHOICES[@]} ; do
455 if [ "$new_combo" = "$c" ] ; then
456 return
457 fi
458 done
459 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
460}
461
462# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700463add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800464add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000465add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800466add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000467add_lunch_combo aosp_x86-eng
468add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470function print_lunch_menu()
471{
472 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 echo
474 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475 echo
476 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477
478 local i=1
479 local choice
480 for choice in ${LUNCH_MENU_CHOICES[@]}
481 do
482 echo " $i. $choice"
483 i=$(($i+1))
484 done
485
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486 echo
487}
488
489function lunch()
490{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800491 local answer
492
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700493 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800494 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700495 else
496 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700497 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800498 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700499 fi
500
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800501 local selection=
502
503 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700504 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700505 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
507 then
508 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
509 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800510 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 fi
512 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
513 then
514 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700515 fi
516
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800517 if [ -z "$selection" ]
518 then
519 echo
520 echo "Invalid lunch combo: $answer"
521 return 1
522 fi
523
Joe Onoratoda12daf2010-06-09 18:18:31 -0700524 export TARGET_BUILD_APPS=
525
Jeff Browne33ba4c2011-07-11 22:11:46 -0700526 local product=$(echo -n $selection | sed -e "s/-.*$//")
527 check_product $product
528 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800529 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700530 echo
531 echo "** Don't have a product spec for: '$product'"
532 echo "** Do you have the right repo manifest?"
533 product=
534 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800535
Jeff Browne33ba4c2011-07-11 22:11:46 -0700536 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
537 check_variant $variant
538 if [ $? -ne 0 ]
539 then
540 echo
541 echo "** Invalid variant: '$variant'"
542 echo "** Must be one of ${VARIANT_CHOICES[@]}"
543 variant=
544 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800545
Jeff Browne33ba4c2011-07-11 22:11:46 -0700546 if [ -z "$product" -o -z "$variant" ]
547 then
548 echo
549 return 1
550 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800551
Jeff Browne33ba4c2011-07-11 22:11:46 -0700552 export TARGET_PRODUCT=$product
553 export TARGET_BUILD_VARIANT=$variant
554 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700555
556 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800557
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700558 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800559 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700560}
561
Jeff Davidson513d7a42010-08-02 10:00:44 -0700562# Tab completion for lunch.
563function _lunch()
564{
565 local cur prev opts
566 COMPREPLY=()
567 cur="${COMP_WORDS[COMP_CWORD]}"
568 prev="${COMP_WORDS[COMP_CWORD-1]}"
569
570 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
571 return 0
572}
573complete -F _lunch lunch
574
Joe Onoratoda12daf2010-06-09 18:18:31 -0700575# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700576# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700577function tapas()
578{
Ying Wangb541ab62014-05-29 17:57:40 -0700579 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700580 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700581 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
582 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 -0700583
Ying Wang67f02922012-08-22 10:25:20 -0700584 if [ $(echo $arch | wc -w) -gt 1 ]; then
585 echo "tapas: Error: Multiple build archs supplied: $arch"
586 return
587 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700588 if [ $(echo $variant | wc -w) -gt 1 ]; then
589 echo "tapas: Error: Multiple build variants supplied: $variant"
590 return
591 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700592 if [ $(echo $density | wc -w) -gt 1 ]; then
593 echo "tapas: Error: Multiple densities supplied: $density"
594 return
595 fi
Ying Wang67f02922012-08-22 10:25:20 -0700596
597 local product=full
598 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700599 x86) product=full_x86;;
600 mips) product=full_mips;;
601 armv5) product=generic_armv5;;
602 arm64) product=aosp_arm64;;
603 x86_64) product=aosp_x86_64;;
604 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700605 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700606 if [ -z "$variant" ]; then
607 variant=eng
608 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700609 if [ -z "$apps" ]; then
610 apps=all
611 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600612 if [ -z "$density" ]; then
613 density=alldpi
614 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700615
Ying Wang67f02922012-08-22 10:25:20 -0700616 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700617 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700618 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700619 export TARGET_BUILD_TYPE=release
620 export TARGET_BUILD_APPS=$apps
621
622 set_stuff_for_environment
623 printconfig
624}
625
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700626function gettop
627{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800628 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700629 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700630 # The following circumlocution ensures we remove symlinks from TOP.
631 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700632 else
633 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800634 # The following circumlocution (repeated below as well) ensures
635 # that we record the true directory name and not one that is
636 # faked up with symlink names.
637 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700638 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800639 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700640 T=
641 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800642 \cd ..
synergyb112a402013-07-05 19:47:47 -0700643 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700644 done
Ying Wang9cd17642012-12-13 10:52:07 -0800645 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700646 if [ -f "$T/$TOPFILE" ]; then
647 echo $T
648 fi
649 fi
650 fi
651}
652
Andrew Hsieh906cb782013-09-10 17:37:14 +0800653# Return driver for "make", if any (eg. static analyzer)
654function getdriver()
655{
656 local T="$1"
657 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
658 if [ -n "$WITH_STATIC_ANALYZER" ]; then
659 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800660$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
661--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800662--status-bugs \
663--top=$T"
664 fi
665}
666
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700667function m()
668{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800669 local T=$(gettop)
670 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700671 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800672 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700673 else
674 echo "Couldn't locate the top of the tree. Try setting TOP."
675 fi
676}
677
678function findmakefile()
679{
680 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800681 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700682 T=
683 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700684 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700685 if [ -f "$T/Android.mk" ]; then
686 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800687 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700688 return
689 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800690 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700691 done
Ying Wang9cd17642012-12-13 10:52:07 -0800692 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700693}
694
695function mm()
696{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800697 local T=$(gettop)
698 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700699 # If we're sitting in the root of the build tree, just do a
700 # normal make.
701 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800702 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700703 else
704 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800705 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700706 local MODULES=
707 local GET_INSTALL_PATH=
708 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700709 # Remove the path to top as the makefilepath needs to be relative
710 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700711 if [ ! "$T" ]; then
712 echo "Couldn't locate the top of the tree. Try setting TOP."
713 elif [ ! "$M" ]; then
714 echo "Couldn't locate a makefile from the current directory."
715 else
Ying Wanga7deb082013-08-16 13:24:47 -0700716 for ARG in $@; do
717 case $ARG in
718 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
719 esac
720 done
721 if [ -n "$GET_INSTALL_PATH" ]; then
722 MODULES=
723 ARGS=GET-INSTALL-PATH
724 else
725 MODULES=all_modules
726 ARGS=$@
727 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700728 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 -0700729 fi
730 fi
731}
732
733function mmm()
734{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800735 local T=$(gettop)
736 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700737 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800738 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800739 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800740 local ARGS=
741 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700742 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800743 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
744 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
745 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800746 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
747 if [ "$MODULES" = "" ]; then
748 MODULES=all_modules
749 fi
750 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700751 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700752 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
753 local TO_CHOP=`expr $TO_CHOP + 1`
754 local START=`PWD= /bin/pwd`
755 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700756 if [ "$MFILE" = "" ] ; then
757 MFILE=$DIR/Android.mk
758 else
759 MFILE=$MFILE/$DIR/Android.mk
760 fi
761 MAKEFILE="$MAKEFILE $MFILE"
762 else
Ying Wanga7deb082013-08-16 13:24:47 -0700763 case $DIR in
764 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
765 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
766 *) echo "No Android.mk in $DIR."; return 1;;
767 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700768 fi
769 done
Ying Wanga7deb082013-08-16 13:24:47 -0700770 if [ -n "$GET_INSTALL_PATH" ]; then
771 ARGS=$GET_INSTALL_PATH
772 MODULES=
773 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800774 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 -0700775 else
776 echo "Couldn't locate the top of the tree. Try setting TOP."
777 fi
778}
779
Ying Wangb607f7b2013-02-08 18:01:04 -0800780function mma()
781{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800782 local T=$(gettop)
783 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800784 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800785 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800786 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800787 if [ ! "$T" ]; then
788 echo "Couldn't locate the top of the tree. Try setting TOP."
789 fi
790 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800791 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800792 fi
793}
794
795function mmma()
796{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800797 local T=$(gettop)
798 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800799 if [ "$T" ]; then
800 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
801 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
802 local MY_PWD=`PWD= /bin/pwd`
803 if [ "$MY_PWD" = "$T" ]; then
804 MY_PWD=
805 else
806 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
807 fi
808 local DIR=
809 local MODULE_PATHS=
810 local ARGS=
811 for DIR in $DIRS ; do
812 if [ -d $DIR ]; then
813 if [ "$MY_PWD" = "" ]; then
814 MODULE_PATHS="$MODULE_PATHS $DIR"
815 else
816 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
817 fi
818 else
819 case $DIR in
820 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
821 *) echo "Couldn't find directory $DIR"; return 1;;
822 esac
823 fi
824 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800825 $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 -0800826 else
827 echo "Couldn't locate the top of the tree. Try setting TOP."
828 fi
829}
830
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700831function croot()
832{
833 T=$(gettop)
834 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800835 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700836 else
837 echo "Couldn't locate the top of the tree. Try setting TOP."
838 fi
839}
840
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700841function cproj()
842{
843 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700844 local HERE=$PWD
845 T=
846 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
847 T=$PWD
848 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800849 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700850 return
851 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800852 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700853 done
Ying Wang9cd17642012-12-13 10:52:07 -0800854 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700855 echo "can't find Android.mk"
856}
857
Daniel Sandler47e0a882013-07-30 13:23:52 -0400858# simplified version of ps; output in the form
859# <pid> <procname>
860function qpid() {
861 local prepend=''
862 local append=''
863 if [ "$1" = "--exact" ]; then
864 prepend=' '
865 append='$'
866 shift
867 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
868 echo "usage: qpid [[--exact] <process name|pid>"
869 return 255
870 fi
871
872 local EXE="$1"
873 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700874 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400875 else
876 adb shell ps \
877 | tr -d '\r' \
878 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
879 fi
880}
881
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700882function pid()
883{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400884 local prepend=''
885 local append=''
886 if [ "$1" = "--exact" ]; then
887 prepend=' '
888 append='$'
889 shift
890 fi
891 local EXE="$1"
892 if [ "$EXE" ] ; then
893 local PID=`adb shell ps \
894 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700895 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400896 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
897 echo "$PID"
898 else
899 echo "usage: pid [--exact] <process name>"
900 return 255
901 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700902}
903
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800904# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700905# that has the core-file-size limit set correctly
906#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800907# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700908# if its core-file-size limit is not set already.
909# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
910
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800911function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700912{
913 echo "Getting root...";
914 adb root;
915 adb wait-for-device;
916
917 echo "Remounting root parition read-write...";
918 adb shell mount -w -o remount -t rootfs rootfs;
919 sleep 1;
920 adb wait-for-device;
921 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -0800922 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700923 adb shell chmod 0777 /cores;
924
925 echo "Granting SELinux permission to dump in /cores...";
926 adb shell restorecon -R /cores;
927
928 echo "Set core pattern.";
929 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
930
931 echo "Done."
932}
933
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800934# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700935# $1 = PID of process (e.g., $(pid mediaserver))
936#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800937# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700938# dump to actually be generated.
939
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800940function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700941{
942 local PID=$1;
943 if [ -z "$PID" ]; then
944 printf "Expecting a PID!\n";
945 return;
946 fi;
947 echo "Setting core limit for $PID to infinite...";
948 adb shell prlimit $PID 4 -1 -1
949}
950
951# core - send SIGV and pull the core for process
952# $1 = PID of process (e.g., $(pid mediaserver))
953#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800954# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700955# enabled globally.
956
957function core()
958{
959 local PID=$1;
960
961 if [ -z "$PID" ]; then
962 printf "Expecting a PID!\n";
963 return;
964 fi;
965
966 local CORENAME=core.$PID;
967 local COREPATH=/cores/$CORENAME;
968 local SIG=SEGV;
969
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800970 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700971
972 local done=0;
973 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
974 printf "\tSending SIG%s to %d...\n" $SIG $PID;
975 adb shell kill -$SIG $PID;
976 sleep 1;
977 done;
978
979 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
980 echo "Done: core is under $COREPATH on device.";
981}
982
Christopher Tate744ee802009-11-12 15:33:08 -0800983# systemstack - dump the current stack trace of all threads in the system process
984# to the usual ANR traces file
985function systemstack()
986{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800987 stacks system_server
988}
989
990function stacks()
991{
992 if [[ $1 =~ ^[0-9]+$ ]] ; then
993 local PID="$1"
994 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700995 local PIDLIST="$(pid $1)"
996 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
997 local PID="$PIDLIST"
998 elif [ "$PIDLIST" ] ; then
999 echo "more than one process: $1"
1000 else
1001 echo "no such process: $1"
1002 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001003 else
1004 echo "usage: stacks [pid|process name]"
1005 fi
1006
1007 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001008 # Determine whether the process is native
1009 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1010 # Dump stacks of Dalvik process
1011 local TRACES=/data/anr/traces.txt
1012 local ORIG=/data/anr/traces.orig
1013 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001014
Jeff Brownb12c2e52013-08-19 15:14:16 -07001015 # Keep original traces to avoid clobbering
1016 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001017
Jeff Brownb12c2e52013-08-19 15:14:16 -07001018 # Make sure we have a usable file
1019 adb shell touch $TRACES
1020 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001021
Jeff Brownb12c2e52013-08-19 15:14:16 -07001022 # Dump stacks and wait for dump to finish
1023 adb shell kill -3 $PID
1024 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001025
Jeff Brownb12c2e52013-08-19 15:14:16 -07001026 # Restore original stacks, and show current output
1027 adb shell mv $TRACES $TMP
1028 adb shell mv $ORIG $TRACES
1029 adb shell cat $TMP
1030 else
1031 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001032 local USE64BIT="$(is64bit $PID)"
1033 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001034 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001035 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001036}
1037
John Michelau50200252012-11-09 11:48:04 -06001038function gdbwrapper()
1039{
Ben Chengfba67bf2014-02-25 10:27:07 -08001040 local GDB_CMD="$1"
1041 shift 1
1042 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -06001043}
1044
Brigid Smith0a2712d2014-05-28 14:36:43 -07001045function get_symbols_directory()
1046{
1047 echo $(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1048}
1049
Michael Wrightaeed7212014-06-19 19:58:12 -07001050# Read the ELF header from /proc/$PID/exe to determine if the process is
1051# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001052function is64bit()
1053{
1054 local PID="$1"
1055 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001056 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001057 echo "64"
1058 else
1059 echo ""
1060 fi
1061 else
1062 echo ""
1063 fi
1064}
1065
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001066function adb_get_product_device() {
Dmitriy Ivanov8cde5282014-11-12 14:16:12 -08001067 local candidate=`adb shell getprop ro.product.device | sed s/.$//`
1068 if [ -z $candidate ]; then
1069 candidate=`adb shell getprop ro.hardware | sed s/.$//`
1070 fi
1071 echo $candidate
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001072}
1073
1074# returns 0 when process is not traced
1075function adb_get_traced_by() {
1076 echo `adb shell cat /proc/$1/status | grep -e "^TracerPid:" | sed "s/^TracerPid:\t//" | sed s/.$//`
1077}
1078
1079function gdbclient() {
1080 # TODO:
1081 # 1. Check for ANDROID_SERIAL/multiple devices
1082 local PROCESS_NAME="n/a"
1083 local PID=$1
1084 local PORT=5039
1085 if [ -z "$PID" ]; then
1086 echo "Usage: gdbclient <pid|processname> [port number]"
1087 return -1
1088 fi
1089 local DEVICE=$(adb_get_product_device)
1090
1091 if [ -z "$DEVICE" ]; then
1092 echo "Error: Unable to get device name. Please check if device is connected and ANDROID_SERIAL is set."
1093 return -2
1094 fi
1095
1096 if [ -n "$2" ]; then
1097 PORT=$2
1098 fi
1099
1100 local ROOT=$(gettop)
1101 if [ -z "$ROOT" ]; then
1102 # This is for the situation with downloaded symbols (from the build server)
1103 # we check if they are available.
1104 ROOT=`realpath .`
1105 fi
1106
1107 local OUT_ROOT="$ROOT/out/target/product/$DEVICE"
1108 local SYMBOLS_DIR="$OUT_ROOT/symbols"
Dmitriy Ivanov8cde5282014-11-12 14:16:12 -08001109 local IS_TAPAS_USER="$(get_build_var TARGET_BUILD_APPS)"
1110 local TAPAS_SYMBOLS_DIR=
1111
1112 if [ $IS_TAPAS_USER ]; then
1113 TAPAS_SYMBOLS_DIR=$(get_symbols_directory)
1114 fi
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001115
1116 if [ ! -d $SYMBOLS_DIR ]; then
Dmitriy Ivanov8cde5282014-11-12 14:16:12 -08001117 if [ $IS_TAPAS_USER ]; then
1118 mkdir -p $SYMBOLS_DIR/system/bin
1119 else
1120 echo "Error: couldn't find symbols: $SYMBOLS_DIR does not exist or is not a directory."
1121 return -3
1122 fi
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001123 fi
1124
1125 # let's figure out which executable we are about to debug
1126
1127 # check if user specified a name -> resolve to pid
1128 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1129 PROCESS_NAME=$PID
1130 PID=$(pid --exact $PROCESS_NAME)
1131 if [ -z "$PID" ]; then
1132 echo "Error: couldn't resolve pid by process name: $PROCESS_NAME"
1133 return -4
Dmitriy Ivanovdfff1702015-01-22 13:22:17 -08001134 else
1135 echo "Resolved pid for $PROCESS_NAME is $PID"
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001136 fi
1137 fi
1138
1139 local EXE=`adb shell readlink /proc/$PID/exe | sed s/.$//`
Dmitriy Ivanovdfff1702015-01-22 13:22:17 -08001140
1141 if [ -z "$EXE" ]; then
1142 echo "Error: no such pid=$PID - is process still alive?"
1143 return -4
1144 fi
1145
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001146 local LOCAL_EXE_PATH=$SYMBOLS_DIR$EXE
1147
1148 if [ ! -f $LOCAL_EXE_PATH ]; then
Dmitriy Ivanov8cde5282014-11-12 14:16:12 -08001149 if [ $IS_TAPAS_USER ]; then
1150 adb pull $EXE $LOCAL_EXE_PATH
1151 else
1152 echo "Error: unable to find symbols for executable $EXE: file $LOCAL_EXE_PATH does not exist"
1153 return -5
1154 fi
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001155 fi
1156
1157 local USE64BIT=""
1158
1159 if [[ "$(file $LOCAL_EXE_PATH)" =~ 64-bit ]]; then
1160 USE64BIT="64"
1161 fi
1162
Dmitriy Ivanov8cde5282014-11-12 14:16:12 -08001163 # and now linker for tapas users...
1164 if [ -n "$IS_TAPAS_USER" -a ! -f "$SYMBOLS_DIR/system/bin/linker$USE64BIT" ]; then
1165 adb pull /system/bin/linker$USE64BIT $SYMBOLS_DIR/system/bin/linker$USE64BIT
1166 fi
1167
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001168 local GDB=
1169 local GDB64=
1170 local CPU_ABI=`adb shell getprop ro.product.cpu.abilist | sed s/.$//`
1171 # TODO: we assume these are available via $PATH
1172 if [[ $CPU_ABI =~ (^|,)arm64 ]]; then
1173 GDB=arm-linux-androideabi-gdb
1174 GDB64=aarch64-linux-android-gdb
1175 elif [[ $CPU_ABI =~ (^|,)arm ]]; then
1176 GDB=arm-linux-androideabi-gdb
1177 elif [[ $CPU_ABI =~ (^|,)x86_64 ]]; then
Pirama Arumuga Nainar8c346f62015-01-05 14:33:33 -08001178 GDB=x86_64-linux-android-gdb
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001179 elif [[ $CPU_ABI =~ (^|,)x86 ]]; then
Pirama Arumuga Nainar8c346f62015-01-05 14:33:33 -08001180 GDB=x86_64-linux-android-gdb
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001181 elif [[ $CPU_ABI =~ (^|,)mips64 ]]; then
1182 GDB=mipsel-linux-android-gdb
1183 GDB64=mips64el-linux-android-gdb
1184 elif [[ $CPU_ABI =~ (^|,)mips ]]; then
1185 GDB=mipsel-linux-android-gdb
1186 else
1187 echo "Error: unrecognized cpu.abilist: $CPU_ABI"
1188 return -6
1189 fi
1190
1191 # TODO: check if tracing process is gdbserver and not some random strace...
Dmitriy Ivanov8cde5282014-11-12 14:16:12 -08001192 if [ "$(adb_get_traced_by $PID)" -eq 0 ]; then
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001193 # start gdbserver
1194 echo "Starting gdbserver..."
1195 # TODO: check if adb is already listening $PORT
1196 # to avoid unnecessary calls
1197 echo ". adb forward for port=$PORT..."
1198 adb forward tcp:$PORT tcp:$PORT
1199 echo ". starting gdbserver to attach to pid=$PID..."
1200 adb shell gdbserver$USE64BIT :$PORT --attach $PID &
1201 echo ". give it couple of seconds to start..."
1202 sleep 2
1203 echo ". done"
1204 else
1205 echo "It looks like gdbserver is already attached to $PID (process is traced), trying to connect to it using local port=$PORT"
Dmitriy Ivanov8cde5282014-11-12 14:16:12 -08001206 adb forward tcp:$PORT tcp:$PORT
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001207 fi
1208
1209 local OUT_SO_SYMBOLS=$SYMBOLS_DIR/system/lib$USE64BIT
Dmitriy Ivanov8cde5282014-11-12 14:16:12 -08001210 local TAPAS_OUT_SO_SYMBOLS=$TAPAS_SYMBOLS_DIR/system/lib$USE64BIT
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001211 local OUT_VENDOR_SO_SYMBOLS=$SYMBOLS_DIR/vendor/lib$USE64BIT
1212 local ART_CMD=""
1213
Dmitriy Ivanov8cde5282014-11-12 14:16:12 -08001214 local SOLIB_SYSROOT=$SYMBOLS_DIR
1215 local SOLIB_SEARCHPATH=$OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl
1216
1217 if [ $IS_TAPAS_USER ]; then
1218 SOLIB_SYSROOT=$TAPAS_SYMBOLS_DIR:$SOLIB_SYSROOT
1219 SOLIB_SEARCHPATH=$TAPAS_OUT_SO_SYMBOLS:$SOLIB_SEARCHPATH
1220 fi
1221
1222 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $SOLIB_SYSROOT"
1223 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $SOLIB_SEARCHPATH"
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001224 local DALVIK_GDB_SCRIPT=$ROOT/development/scripts/gdb/dalvik.gdb
1225 if [ -f $DALVIK_GDB_SCRIPT ]; then
1226 echo >>"$OUT_ROOT/gdbclient.cmds" "source $DALVIK_GDB_SCRIPT"
1227 ART_CMD="art-on"
1228 else
1229 echo "Warning: couldn't find $DALVIK_GDB_SCRIPT - ART debugging options will not be available"
1230 fi
1231 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote :$PORT"
1232 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1233 echo >> "$OUT_ROOT/gdbclient.cmds" $ART_CMD
1234 fi
1235
1236 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1237
1238 local WHICH_GDB=$GDB
1239
1240 if [ -n "$USE64BIT" -a -n "$GDB64" ]; then
1241 WHICH_GDB=$GDB64
1242 fi
1243
1244 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$LOCAL_EXE_PATH"
1245}
1246
Ben Chengfba67bf2014-02-25 10:27:07 -08001247# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
1248# executable, set up the approriate gdbserver, then invokes the proper host
1249# gdb.
Dmitriy Ivanov9b8e4b32014-10-30 22:00:17 -07001250function gdbclient_old()
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001251{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001252 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1253 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1254 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
Colin Cross3655a682014-05-22 11:59:10 -07001255 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
Brigid Smith0a2712d2014-05-28 14:36:43 -07001256 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001257 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001258 local ARCH=$(get_build_var TARGET_ARCH)
1259 local GDB
1260 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001261 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -08001262 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Duane Sand3c4fcd82014-07-22 14:34:00 -07001263 mips|mips64) GDB=mips64el-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +00001264 x86) GDB=x86_64-linux-android-gdb;;
1265 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001266 *) echo "Unknown arch $ARCH"; return 1;;
1267 esac
1268
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001269 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1270 local EXE="$1"
1271 if [ "$EXE" ] ; then
1272 EXE=$1
Brigid Smith7a569a62014-06-20 14:12:12 -07001273 if [[ $EXE =~ ^[^/].* ]] ; then
1274 EXE="system/bin/"$EXE
1275 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001276 else
1277 EXE="app_process"
1278 fi
1279
1280 local PORT="$2"
1281 if [ "$PORT" ] ; then
1282 PORT=$2
1283 else
1284 PORT=":5039"
1285 fi
1286
Chris Craik20c136a2012-11-09 18:02:19 -08001287 local PID="$3"
1288 if [ "$PID" ] ; then
1289 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -07001290 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -08001291 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1292 # that likely didn't work because of returning multiple processes
1293 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001294 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001295 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1296 then
1297 echo "Couldn't resolve '$3' to single PID"
1298 return 1
1299 else
1300 echo ""
1301 echo "WARNING: multiple processes matching '$3' observed, using root process"
1302 echo ""
1303 fi
1304 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001305 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001306 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001307 local USE64BIT="$(is64bit $PID)"
1308 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001309 sleep 2
1310 else
1311 echo ""
1312 echo "If you haven't done so already, do this first on the device:"
1313 echo " gdbserver $PORT /system/bin/$EXE"
1314 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001315 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001316 echo ""
1317 fi
1318
Colin Cross84480ad2014-04-10 12:51:39 -07001319 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
Colin Crossa58f8e02014-06-20 13:33:36 -07001320 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
Colin Cross84480ad2014-04-10 12:51:39 -07001321
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001322 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Colin Cross3655a682014-05-22 11:59:10 -07001323 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl"
Ben Cheng72398162013-06-24 14:36:21 -07001324 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001325 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
Christopher Ferris855d27f2014-10-03 17:29:27 -07001326 # Enable special debugging for ART processes.
1327 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1328 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1329 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001330 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1331
Ben Chengfba67bf2014-02-25 10:27:07 -08001332 local WHICH_GDB=
1333 # 64-bit exe found
1334 if [ "$USE64BIT" != "" ] ; then
1335 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1336 # 32-bit exe / 32-bit platform
1337 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1338 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1339 # 32-bit exe / 64-bit platform
1340 else
1341 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1342 fi
Brigid Smith0a2712d2014-05-28 14:36:43 -07001343
Ben Chengfba67bf2014-02-25 10:27:07 -08001344 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001345 else
1346 echo "Unable to determine build system output dir."
1347 fi
1348
1349}
1350
1351case `uname -s` in
1352 Darwin)
1353 function sgrep()
1354 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001355 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 -07001356 }
1357
1358 ;;
1359 *)
1360 function sgrep()
1361 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001362 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 -07001363 }
1364 ;;
1365esac
1366
Raghu Gandham8da43102012-07-25 19:57:22 -07001367function gettargetarch
1368{
1369 get_build_var TARGET_ARCH
1370}
1371
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001372function ggrep()
1373{
1374 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1375}
1376
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001377function jgrep()
1378{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001379 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 -07001380}
1381
1382function cgrep()
1383{
Dan Albert01961192014-11-22 10:16:01 -08001384 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 -07001385}
1386
1387function resgrep()
1388{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001389 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 -07001390}
1391
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001392function mangrep()
1393{
1394 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1395}
1396
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001397function sepgrep()
1398{
1399 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 "$@"
1400}
1401
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001402case `uname -s` in
1403 Darwin)
1404 function mgrep()
1405 {
Ying Wang324c2b22012-08-17 15:03:20 -07001406 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 -07001407 }
1408
1409 function treegrep()
1410 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001411 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 -07001412 }
1413
1414 ;;
1415 *)
1416 function mgrep()
1417 {
Ying Wang324c2b22012-08-17 15:03:20 -07001418 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 -07001419 }
1420
1421 function treegrep()
1422 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001423 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 -07001424 }
1425
1426 ;;
1427esac
1428
1429function getprebuilt
1430{
1431 get_abs_build_var ANDROID_PREBUILTS
1432}
1433
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001434function tracedmdump()
1435{
1436 T=$(gettop)
1437 if [ ! "$T" ]; then
1438 echo "Couldn't locate the top of the tree. Try setting TOP."
1439 return
1440 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001441 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001442 local arch=$(gettargetarch)
1443 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001444
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001445 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001446 if [ ! "$TRACE" ] ; then
1447 echo "usage: tracedmdump tracename"
1448 return
1449 fi
1450
Jack Veenstra60116fc2009-04-09 18:12:34 -07001451 if [ ! -r "$KERNEL" ] ; then
1452 echo "Error: cannot find kernel: '$KERNEL'"
1453 return
1454 fi
1455
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001456 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001457 if [ "$BASETRACE" = "$TRACE" ] ; then
1458 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1459 fi
1460
1461 echo "post-processing traces..."
1462 rm -f $TRACE/qtrace.dexlist
1463 post_trace $TRACE
1464 if [ $? -ne 0 ]; then
1465 echo "***"
1466 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1467 echo "***"
1468 return
1469 fi
1470 echo "generating dexlist output..."
1471 /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
1472 echo "generating dmtrace data..."
1473 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1474 echo "generating html file..."
1475 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1476 echo "done, see $TRACE/dmtrace.html for details"
1477 echo "or run:"
1478 echo " traceview $TRACE/dmtrace"
1479}
1480
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001481# communicate with a running device or emulator, set up necessary state,
1482# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001483function runhat()
1484{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001485 # process standard adb options
1486 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001487 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001488 adbTarget=$1
1489 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001490 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001491 adbTarget="$1 $2"
1492 shift 2
1493 fi
1494 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001495 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001496
1497 # runhat options
1498 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001499
1500 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001501 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001502 return
1503 fi
1504
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001505 # confirm hat is available
1506 if [ -z $(which hat) ]; then
1507 echo "hat is not available in this configuration."
1508 return
1509 fi
1510
Andy McFaddenb6289852010-07-12 08:00:19 -07001511 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001512 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001513 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001514 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001515 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001516 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001517 echo -n "> "
1518 read
1519
The Android Open Source Project88b60792009-03-03 19:28:42 -08001520 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001521
The Android Open Source Project88b60792009-03-03 19:28:42 -08001522 echo "Retrieving file $devFile..."
1523 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001524
The Android Open Source Project88b60792009-03-03 19:28:42 -08001525 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001526
The Android Open Source Project88b60792009-03-03 19:28:42 -08001527 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001528 echo "View the output by pointing your browser at http://localhost:7000/"
1529 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001530 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001531}
1532
1533function getbugreports()
1534{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001535 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001536
1537 if [ ! "$reports" ]; then
1538 echo "Could not locate any bugreports."
1539 return
1540 fi
1541
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001542 local report
1543 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001544 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001545 echo "/sdcard/bugreports/${report}"
1546 adb pull /sdcard/bugreports/${report} ${report}
1547 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001548 done
1549}
1550
Victoria Lease1b296b42012-08-21 15:44:06 -07001551function getsdcardpath()
1552{
1553 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1554}
1555
1556function getscreenshotpath()
1557{
1558 echo "$(getsdcardpath)/Pictures/Screenshots"
1559}
1560
1561function getlastscreenshot()
1562{
1563 local screenshot_path=$(getscreenshotpath)
1564 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1565 if [ "$screenshot" = "" ]; then
1566 echo "No screenshots found."
1567 return
1568 fi
1569 echo "${screenshot}"
1570 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1571}
1572
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001573function startviewserver()
1574{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001575 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001576 if [ $# -gt 0 ]; then
1577 port=$1
1578 fi
1579 adb shell service call window 1 i32 $port
1580}
1581
1582function stopviewserver()
1583{
1584 adb shell service call window 2
1585}
1586
1587function isviewserverstarted()
1588{
1589 adb shell service call window 3
1590}
1591
Romain Guyb84049a2010-10-04 16:56:11 -07001592function key_home()
1593{
1594 adb shell input keyevent 3
1595}
1596
1597function key_back()
1598{
1599 adb shell input keyevent 4
1600}
1601
1602function key_menu()
1603{
1604 adb shell input keyevent 82
1605}
1606
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001607function smoketest()
1608{
1609 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1610 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1611 return
1612 fi
1613 T=$(gettop)
1614 if [ ! "$T" ]; then
1615 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1616 return
1617 fi
1618
Ying Wang9cd17642012-12-13 10:52:07 -08001619 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001620 adb uninstall com.android.smoketest > /dev/null &&
1621 adb uninstall com.android.smoketest.tests > /dev/null &&
1622 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1623 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1624 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1625}
1626
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001627# simple shortcut to the runtest command
1628function runtest()
1629{
1630 T=$(gettop)
1631 if [ ! "$T" ]; then
1632 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1633 return
1634 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001635 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001636}
1637
The Android Open Source Project88b60792009-03-03 19:28:42 -08001638function godir () {
1639 if [[ -z "$1" ]]; then
1640 echo "Usage: godir <regex>"
1641 return
1642 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001643 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001644 if [[ ! -f $T/filelist ]]; then
1645 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001646 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001647 echo " Done"
1648 echo ""
1649 fi
1650 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001651 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001652 if [[ ${#lines[@]} = 0 ]]; then
1653 echo "Not found"
1654 return
1655 fi
1656 local pathname
1657 local choice
1658 if [[ ${#lines[@]} > 1 ]]; then
1659 while [[ -z "$pathname" ]]; do
1660 local index=1
1661 local line
1662 for line in ${lines[@]}; do
1663 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001664 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001665 done
1666 echo
1667 echo -n "Select one: "
1668 unset choice
1669 read choice
1670 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1671 echo "Invalid choice"
1672 continue
1673 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001674 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001675 done
1676 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001677 pathname=${lines[0]}
1678 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001679 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001680}
1681
Neil Fuller46e00ea2014-10-16 10:23:03 +01001682# Force JAVA_HOME to point to java 1.7 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001683#
1684# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1685# For some reason, installing the JDK doesn't make it show up in the
1686# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001687function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001688 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001689 # we can reset it later, depending on the version of java the build
1690 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001691 #
1692 # If we don't do this, the JAVA_HOME value set by the first call to
1693 # build/envsetup.sh will persist forever.
1694 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1695 export JAVA_HOME=""
1696 fi
1697
Andy McFaddenbd960942010-06-24 12:52:51 -07001698 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01001699 case `uname -s` in
1700 Darwin)
1701 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1702 ;;
1703 *)
1704 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1705 ;;
1706 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001707
1708 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1709 # we can change it on the next envsetup.sh, if required.
1710 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001711 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001712}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001713
Alex Rayf0d08eb2013-03-08 15:15:06 -08001714# Print colored exit condition
1715function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001716 "$@"
1717 local retval=$?
1718 if [ $retval -ne 0 ]
1719 then
1720 echo -e "\e[0;31mFAILURE\e[00m"
1721 else
1722 echo -e "\e[0;32mSUCCESS\e[00m"
1723 fi
1724 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001725}
1726
Ying Wanged21d4c2014-08-24 22:14:19 -07001727function get_make_command()
1728{
1729 echo command make
1730}
1731
Ed Heylcc6be0a2014-06-18 14:55:58 -07001732function make()
1733{
1734 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001735 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001736 local ret=$?
1737 local end_time=$(date +"%s")
1738 local tdiff=$(($end_time-$start_time))
1739 local hours=$(($tdiff / 3600 ))
1740 local mins=$((($tdiff % 3600) / 60))
1741 local secs=$(($tdiff % 60))
1742 echo
1743 if [ $ret -eq 0 ] ; then
Dan Albertb59995d2014-11-08 22:41:52 -08001744 if [ $(uname) != "Darwin" ]; then
1745 echo -n -e "\e[0;32m#### make completed successfully "
1746 else
1747 echo -n -e "#### make completed successfully "
1748 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001749 else
Dan Albertb59995d2014-11-08 22:41:52 -08001750 if [ $(uname) != "Darwin" ]; then
1751 echo -n -e "\e[0;31m#### make failed to build some targets "
1752 else
1753 echo -n -e "#### make failed to build some targets "
1754 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001755 fi
1756 if [ $hours -gt 0 ] ; then
1757 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1758 elif [ $mins -gt 0 ] ; then
1759 printf "(%02g:%02g (mm:ss))" $mins $secs
1760 elif [ $secs -gt 0 ] ; then
1761 printf "(%s seconds)" $secs
1762 fi
Dan Albertb59995d2014-11-08 22:41:52 -08001763 if [ $(uname) != "Darwin" ]; then
1764 echo -e " ####\e[00m"
1765 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001766 echo
1767 return $ret
1768}
1769
Raphael Moll70a86b02011-06-20 16:03:14 -07001770if [ "x$SHELL" != "x/bin/bash" ]; then
1771 case `ps -o command -p $$` in
1772 *bash*)
1773 ;;
1774 *)
1775 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1776 ;;
1777 esac
1778fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001779
1780# Execute the contents of any vendorsetup.sh files we can find.
Ying Wang506410a2014-07-09 15:37:34 -07001781for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1782 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001783do
1784 echo "including $f"
1785 . $f
1786done
1787unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001788
1789addcompletions