blob: d909ae880f3d9aeb94dae0019c9f96214a82f366 [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.
Jeff Brown46cbd202014-07-26 15:15:41 -070017- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080018- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070019
20Look at the source to view more functions. The complete list is:
21EOF
22 T=$(gettop)
23 local A
24 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070025 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 -070026 A="$A $i"
27 done
28 echo $A
29}
30
31# Get the value of a build variable as an absolute path.
32function get_abs_build_var()
33{
34 T=$(gettop)
35 if [ ! "$T" ]; then
36 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
37 return
38 fi
Ying Wang9cd17642012-12-13 10:52:07 -080039 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070040 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070041}
42
43# Get the exact value of a build variable.
44function get_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
Andrew Boie6905e212013-12-19 13:21:46 -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-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080053}
54
55# check to see if the supplied product is one we can build
56function check_product()
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
Jeff Browne33ba4c2011-07-11 22:11:46 -070063 TARGET_PRODUCT=$1 \
64 TARGET_BUILD_VARIANT= \
65 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070066 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080067 get_build_var TARGET_DEVICE > /dev/null
68 # hide successful answers, but allow the errors to show
69}
70
71VARIANT_CHOICES=(user userdebug eng)
72
73# check to see if the supplied variant is valid
74function check_variant()
75{
76 for v in ${VARIANT_CHOICES[@]}
77 do
78 if [ "$v" = "$1" ]
79 then
80 return 0
81 fi
82 done
83 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070084}
85
86function setpaths()
87{
88 T=$(gettop)
89 if [ ! "$T" ]; then
90 echo "Couldn't locate the top of the tree. Try setting TOP."
91 return
92 fi
93
94 ##################################################################
95 # #
96 # Read me before you modify this code #
97 # #
98 # This function sets ANDROID_BUILD_PATHS to what it is adding #
99 # to PATH, and the next time it is run, it removes that from #
100 # PATH. This is required so lunch can be run more than once #
101 # and still have working paths. #
102 # #
103 ##################################################################
104
Raphael Mollc639c782011-06-20 17:25:01 -0700105 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
106 # due to "C:\Program Files" being in the path.
107
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700108 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700109 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700110 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
111 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700112 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700113 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800114 # strip leading ':', if any
115 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500116 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700117
118 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700119 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700120 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700121
Ben Cheng8bc4c432012-11-16 13:29:13 -0800122 # defined in core/config.mk
123 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700124 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800125 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800126
Raphael Mollc639c782011-06-20 17:25:01 -0700127 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800128 export ANDROID_TOOLCHAIN=
129 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200130 local ARCH=$(get_build_var TARGET_ARCH)
131 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400132 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700133 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400134 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
135 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800136 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200137 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800138 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700139 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700140 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700141 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000142 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200143 *)
144 echo "Can't find toolchain for unknown architecture: $ARCH"
145 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700146 ;;
147 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700148 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800149 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700150 fi
Raphael732936d2011-06-22 14:35:32 -0700151
Ben Chengfba67bf2014-02-25 10:27:07 -0800152 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
153 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
154 fi
155
156 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700157 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700158 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800159 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800160 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700161 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100162 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
163 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700164 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700165 ;;
166 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700167 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700168 ;;
169 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700170
Ying Wang564f9122013-03-29 17:40:14 -0700171 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wang2a859d52014-06-30 10:25:33 -0700172 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 +0200173
174 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
175 # to ensure that the corresponding 'emulator' binaries are used.
176 case $(uname -s) in
177 Darwin)
178 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
179 ;;
180 Linux)
181 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
182 ;;
183 *)
184 ANDROID_EMULATOR_PREBUILTS=
185 ;;
186 esac
187 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700188 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200189 export ANDROID_EMULATOR_PREBUILTS
190 fi
191
Ying Wangaa1c9b52012-11-26 20:51:59 -0800192 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800193
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500194 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900195 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500196 if [ -n "$JAVA_HOME" ]; then
197 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900198 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
199 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500200 fi
201
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800202 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700203 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
204 export OUT=$ANDROID_PRODUCT_OUT
205
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700206 unset ANDROID_HOST_OUT
207 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
208
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800209 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700210 # TODO: fix the path
211 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
212}
213
214function printconfig()
215{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800216 T=$(gettop)
217 if [ ! "$T" ]; then
218 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
219 return
220 fi
221 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700222}
223
224function set_stuff_for_environment()
225{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800226 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500227 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800228 setpaths
229 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700230
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800231 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700232 # With this environment variable new GCC can apply colors to warnings/errors
233 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700234}
235
236function set_sequence_number()
237{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700238 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700239}
240
241function settitle()
242{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800243 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700244 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700245 local product=$TARGET_PRODUCT
246 local variant=$TARGET_BUILD_VARIANT
247 local apps=$TARGET_BUILD_APPS
248 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700249 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700250 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700251 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700252 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800253 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700254}
255
Kenny Root52aa81c2011-07-15 11:07:06 -0700256function addcompletions()
257{
258 local T dir f
259
260 # Keep us from trying to run in something that isn't bash.
261 if [ -z "${BASH_VERSION}" ]; then
262 return
263 fi
264
265 # Keep us from trying to run in bash that's too old.
266 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
267 return
268 fi
269
270 dir="sdk/bash_completion"
271 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700272 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700273 echo "including $f"
274 . $f
275 done
276 fi
277}
278
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700279function choosetype()
280{
281 echo "Build type choices are:"
282 echo " 1. release"
283 echo " 2. debug"
284 echo
285
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800286 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700287 DEFAULT_NUM=1
288 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700289
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800290 export TARGET_BUILD_TYPE=
291 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700292 while [ -z $TARGET_BUILD_TYPE ]
293 do
294 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800295 if [ -z "$1" ] ; then
296 read ANSWER
297 else
298 echo $1
299 ANSWER=$1
300 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700301 case $ANSWER in
302 "")
303 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
304 ;;
305 1)
306 export TARGET_BUILD_TYPE=release
307 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800308 release)
309 export TARGET_BUILD_TYPE=release
310 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700311 2)
312 export TARGET_BUILD_TYPE=debug
313 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800314 debug)
315 export TARGET_BUILD_TYPE=debug
316 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317 *)
318 echo
319 echo "I didn't understand your response. Please try again."
320 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321 ;;
322 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800323 if [ -n "$1" ] ; then
324 break
325 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700326 done
327
328 set_stuff_for_environment
329}
330
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331#
332# This function isn't really right: It chooses a TARGET_PRODUCT
333# based on the list of boards. Usually, that gets you something
334# that kinda works with a generic product, but really, you should
335# pick a product by name.
336#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700337function chooseproduct()
338{
wangxlf9562e12015-01-27 19:58:05 +0800339# Find the list of all products by looking for all AndroidProducts.mk files under the
340# device/, vendor/ and build/target/product/ directories and look for the format
341# LOCAL_DIR/<ProductSpecificFile.mk> and extract the name ProductSpecificFile from it.
342# This will give the list of all products that can be built using choosecombo
343 local -a prodlist
344
345# Find all AndroidProducts.mk files under the dirs device/, build/target/ and vendor/
346# Extract lines containing .mk from them
347# Extract lines containing LOCAL_DIR
348# Extract the name of the product specific file
349
350
351 prodlist=(`/usr/bin/find device/fairphone_devices device/qcom/msm8974 -name AndroidProducts.mk 2>/dev/null | \
352 xargs grep -h \.mk| grep LOCAL_DIR| cut -d'/' -f2|cut -d' ' -f1|sort|uniq|cut -d'.' -f1`)
353
354 local index=1
355 local p
356 echo "Product choices are:"
357 for p in ${prodlist[@]}
358 do
359 echo " $index. $p"
360 let "index = $index + 1"
361 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700362 if [ "x$TARGET_PRODUCT" != x ] ; then
363 default_value=$TARGET_PRODUCT
364 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700365 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700366 fi
367
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800368 export TARGET_PRODUCT=
369 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700370 while [ -z "$TARGET_PRODUCT" ]
371 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700372 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800373 if [ -z "$1" ] ; then
374 read ANSWER
375 else
376 echo $1
377 ANSWER=$1
378 fi
379
wangxlf9562e12015-01-27 19:58:05 +0800380 if [ -z "$ANSWER" ] ; then
381 export TARGET_PRODUCT=$default_value
382 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
383 local poo=`echo -n $ANSWER`
384 if [ $poo -le ${#prodlist[@]} ] ; then
385 export TARGET_PRODUCT=${prodlist[$(($ANSWER-1))]}
386 else
387 echo "** Bad product selection: $ANSWER"
388 fi
389 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800390 if check_product $ANSWER
391 then
392 export TARGET_PRODUCT=$ANSWER
393 else
394 echo "** Not a valid product: $ANSWER"
395 fi
396 fi
397 if [ -n "$1" ] ; then
398 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700399 fi
400 done
401
402 set_stuff_for_environment
403}
404
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800405function choosevariant()
406{
407 echo "Variant choices are:"
408 local index=1
409 local v
410 for v in ${VARIANT_CHOICES[@]}
411 do
412 # The product name is the name of the directory containing
413 # the makefile we found, above.
414 echo " $index. $v"
415 index=$(($index+1))
416 done
417
418 local default_value=eng
419 local ANSWER
420
421 export TARGET_BUILD_VARIANT=
422 while [ -z "$TARGET_BUILD_VARIANT" ]
423 do
424 echo -n "Which would you like? [$default_value] "
425 if [ -z "$1" ] ; then
426 read ANSWER
427 else
428 echo $1
429 ANSWER=$1
430 fi
431
432 if [ -z "$ANSWER" ] ; then
433 export TARGET_BUILD_VARIANT=$default_value
434 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
435 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800436 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800437 fi
438 else
439 if check_variant $ANSWER
440 then
441 export TARGET_BUILD_VARIANT=$ANSWER
442 else
443 echo "** Not a valid variant: $ANSWER"
444 fi
445 fi
446 if [ -n "$1" ] ; then
447 break
448 fi
449 done
450}
451
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700452function choosecombo()
453{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700454 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700455
456 echo
457 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700458 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700459
460 echo
461 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700462 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800463
464 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800466 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700467}
468
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469# Clear this variable. It will be built up again when the vendorsetup.sh
470# files are included at the end of this file.
471unset LUNCH_MENU_CHOICES
472function add_lunch_combo()
473{
474 local new_combo=$1
475 local c
476 for c in ${LUNCH_MENU_CHOICES[@]} ; do
477 if [ "$new_combo" = "$c" ] ; then
478 return
479 fi
480 done
481 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
482}
483
484# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700485add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800486add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000487add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800488add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000489add_lunch_combo aosp_x86-eng
490add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800491
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700492function print_lunch_menu()
493{
494 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700495 echo
496 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700497 echo
498 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499
500 local i=1
501 local choice
502 for choice in ${LUNCH_MENU_CHOICES[@]}
503 do
504 echo " $i. $choice"
505 i=$(($i+1))
506 done
507
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 echo
509}
510
511function lunch()
512{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800513 local answer
514
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700515 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800516 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700517 else
518 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700519 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700521 fi
522
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800523 local selection=
524
525 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700526 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700527 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800528 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
529 then
530 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
531 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800532 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800533 fi
534 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
535 then
536 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700537 fi
538
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800539 if [ -z "$selection" ]
540 then
541 echo
542 echo "Invalid lunch combo: $answer"
543 return 1
544 fi
545
Joe Onoratoda12daf2010-06-09 18:18:31 -0700546 export TARGET_BUILD_APPS=
547
Jeff Browne33ba4c2011-07-11 22:11:46 -0700548 local product=$(echo -n $selection | sed -e "s/-.*$//")
549 check_product $product
550 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800551 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700552 echo
553 echo "** Don't have a product spec for: '$product'"
554 echo "** Do you have the right repo manifest?"
555 product=
556 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800557
Jeff Browne33ba4c2011-07-11 22:11:46 -0700558 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
559 check_variant $variant
560 if [ $? -ne 0 ]
561 then
562 echo
563 echo "** Invalid variant: '$variant'"
564 echo "** Must be one of ${VARIANT_CHOICES[@]}"
565 variant=
566 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800567
Jeff Browne33ba4c2011-07-11 22:11:46 -0700568 if [ -z "$product" -o -z "$variant" ]
569 then
570 echo
571 return 1
572 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800573
Jeff Browne33ba4c2011-07-11 22:11:46 -0700574 export TARGET_PRODUCT=$product
575 export TARGET_BUILD_VARIANT=$variant
576 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700577
578 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800579
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700580 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800581 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582}
583
Jeff Davidson513d7a42010-08-02 10:00:44 -0700584# Tab completion for lunch.
585function _lunch()
586{
587 local cur prev opts
588 COMPREPLY=()
589 cur="${COMP_WORDS[COMP_CWORD]}"
590 prev="${COMP_WORDS[COMP_CWORD-1]}"
591
592 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
593 return 0
594}
595complete -F _lunch lunch
596
Joe Onoratoda12daf2010-06-09 18:18:31 -0700597# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700598# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700599function tapas()
600{
Ying Wangb541ab62014-05-29 17:57:40 -0700601 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 -0700602 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Ying Wangb541ab62014-05-29 17:57:40 -0700603 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700604
Ying Wang67f02922012-08-22 10:25:20 -0700605 if [ $(echo $arch | wc -w) -gt 1 ]; then
606 echo "tapas: Error: Multiple build archs supplied: $arch"
607 return
608 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700609 if [ $(echo $variant | wc -w) -gt 1 ]; then
610 echo "tapas: Error: Multiple build variants supplied: $variant"
611 return
612 fi
Ying Wang67f02922012-08-22 10:25:20 -0700613
614 local product=full
615 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700616 x86) product=full_x86;;
617 mips) product=full_mips;;
618 armv5) product=generic_armv5;;
619 arm64) product=aosp_arm64;;
620 x86_64) product=aosp_x86_64;;
621 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700622 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700623 if [ -z "$variant" ]; then
624 variant=eng
625 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700626 if [ -z "$apps" ]; then
627 apps=all
628 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700629
Ying Wang67f02922012-08-22 10:25:20 -0700630 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700631 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700632 export TARGET_BUILD_TYPE=release
633 export TARGET_BUILD_APPS=$apps
634
635 set_stuff_for_environment
636 printconfig
637}
638
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700639function gettop
640{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800641 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700642 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700643 # The following circumlocution ensures we remove symlinks from TOP.
644 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700645 else
646 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800647 # The following circumlocution (repeated below as well) ensures
648 # that we record the true directory name and not one that is
649 # faked up with symlink names.
650 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800652 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653 T=
654 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800655 \cd ..
synergyb112a402013-07-05 19:47:47 -0700656 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657 done
Ying Wang9cd17642012-12-13 10:52:07 -0800658 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659 if [ -f "$T/$TOPFILE" ]; then
660 echo $T
661 fi
662 fi
663 fi
664}
665
Andrew Hsieh906cb782013-09-10 17:37:14 +0800666# Return driver for "make", if any (eg. static analyzer)
667function getdriver()
668{
669 local T="$1"
670 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
671 if [ -n "$WITH_STATIC_ANALYZER" ]; then
672 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800673$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
674--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800675--status-bugs \
676--top=$T"
677 fi
678}
679
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700680function m()
681{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800682 local T=$(gettop)
683 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700684 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800685 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700686 else
687 echo "Couldn't locate the top of the tree. Try setting TOP."
688 fi
689}
690
691function findmakefile()
692{
693 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800694 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700695 T=
696 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700697 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700698 if [ -f "$T/Android.mk" ]; then
699 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800700 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700701 return
702 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800703 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700704 done
Ying Wang9cd17642012-12-13 10:52:07 -0800705 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700706}
707
708function mm()
709{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800710 local T=$(gettop)
711 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700712 # If we're sitting in the root of the build tree, just do a
713 # normal make.
714 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800715 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700716 else
717 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800718 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700719 local MODULES=
720 local GET_INSTALL_PATH=
721 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700722 # Remove the path to top as the makefilepath needs to be relative
723 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700724 if [ ! "$T" ]; then
725 echo "Couldn't locate the top of the tree. Try setting TOP."
726 elif [ ! "$M" ]; then
727 echo "Couldn't locate a makefile from the current directory."
728 else
Ying Wanga7deb082013-08-16 13:24:47 -0700729 for ARG in $@; do
730 case $ARG in
731 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
732 esac
733 done
734 if [ -n "$GET_INSTALL_PATH" ]; then
735 MODULES=
736 ARGS=GET-INSTALL-PATH
737 else
738 MODULES=all_modules
739 ARGS=$@
740 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700741 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 -0700742 fi
743 fi
744}
745
746function mmm()
747{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800748 local T=$(gettop)
749 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700750 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800751 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800752 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800753 local ARGS=
754 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700755 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800756 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
757 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
758 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800759 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
760 if [ "$MODULES" = "" ]; then
761 MODULES=all_modules
762 fi
763 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700764 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700765 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
766 local TO_CHOP=`expr $TO_CHOP + 1`
767 local START=`PWD= /bin/pwd`
768 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700769 if [ "$MFILE" = "" ] ; then
770 MFILE=$DIR/Android.mk
771 else
772 MFILE=$MFILE/$DIR/Android.mk
773 fi
774 MAKEFILE="$MAKEFILE $MFILE"
775 else
Ying Wanga7deb082013-08-16 13:24:47 -0700776 case $DIR in
777 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
778 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
779 *) echo "No Android.mk in $DIR."; return 1;;
780 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700781 fi
782 done
Ying Wanga7deb082013-08-16 13:24:47 -0700783 if [ -n "$GET_INSTALL_PATH" ]; then
784 ARGS=$GET_INSTALL_PATH
785 MODULES=
786 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800787 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 -0700788 else
789 echo "Couldn't locate the top of the tree. Try setting TOP."
790 fi
791}
792
Ying Wangb607f7b2013-02-08 18:01:04 -0800793function mma()
794{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800795 local T=$(gettop)
796 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800797 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800798 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800799 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800800 if [ ! "$T" ]; then
801 echo "Couldn't locate the top of the tree. Try setting TOP."
802 fi
803 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800804 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800805 fi
806}
807
808function mmma()
809{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800810 local T=$(gettop)
811 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800812 if [ "$T" ]; then
813 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
814 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
815 local MY_PWD=`PWD= /bin/pwd`
816 if [ "$MY_PWD" = "$T" ]; then
817 MY_PWD=
818 else
819 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
820 fi
821 local DIR=
822 local MODULE_PATHS=
823 local ARGS=
824 for DIR in $DIRS ; do
825 if [ -d $DIR ]; then
826 if [ "$MY_PWD" = "" ]; then
827 MODULE_PATHS="$MODULE_PATHS $DIR"
828 else
829 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
830 fi
831 else
832 case $DIR in
833 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
834 *) echo "Couldn't find directory $DIR"; return 1;;
835 esac
836 fi
837 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800838 $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 -0800839 else
840 echo "Couldn't locate the top of the tree. Try setting TOP."
841 fi
842}
843
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700844function croot()
845{
846 T=$(gettop)
847 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800848 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700849 else
850 echo "Couldn't locate the top of the tree. Try setting TOP."
851 fi
852}
853
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700854function cproj()
855{
856 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700857 local HERE=$PWD
858 T=
859 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
860 T=$PWD
861 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800862 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700863 return
864 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800865 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700866 done
Ying Wang9cd17642012-12-13 10:52:07 -0800867 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700868 echo "can't find Android.mk"
869}
870
Daniel Sandler47e0a882013-07-30 13:23:52 -0400871# simplified version of ps; output in the form
872# <pid> <procname>
873function qpid() {
874 local prepend=''
875 local append=''
876 if [ "$1" = "--exact" ]; then
877 prepend=' '
878 append='$'
879 shift
880 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
881 echo "usage: qpid [[--exact] <process name|pid>"
882 return 255
883 fi
884
885 local EXE="$1"
886 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700887 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400888 else
889 adb shell ps \
890 | tr -d '\r' \
891 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
892 fi
893}
894
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700895function pid()
896{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400897 local prepend=''
898 local append=''
899 if [ "$1" = "--exact" ]; then
900 prepend=' '
901 append='$'
902 shift
903 fi
904 local EXE="$1"
905 if [ "$EXE" ] ; then
906 local PID=`adb shell ps \
907 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700908 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400909 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
910 echo "$PID"
911 else
912 echo "usage: pid [--exact] <process name>"
913 return 255
914 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700915}
916
Christopher Tate744ee802009-11-12 15:33:08 -0800917# systemstack - dump the current stack trace of all threads in the system process
918# to the usual ANR traces file
919function systemstack()
920{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800921 stacks system_server
922}
923
924function stacks()
925{
926 if [[ $1 =~ ^[0-9]+$ ]] ; then
927 local PID="$1"
928 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700929 local PIDLIST="$(pid $1)"
930 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
931 local PID="$PIDLIST"
932 elif [ "$PIDLIST" ] ; then
933 echo "more than one process: $1"
934 else
935 echo "no such process: $1"
936 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800937 else
938 echo "usage: stacks [pid|process name]"
939 fi
940
941 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700942 # Determine whether the process is native
943 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
944 # Dump stacks of Dalvik process
945 local TRACES=/data/anr/traces.txt
946 local ORIG=/data/anr/traces.orig
947 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800948
Jeff Brownb12c2e52013-08-19 15:14:16 -0700949 # Keep original traces to avoid clobbering
950 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800951
Jeff Brownb12c2e52013-08-19 15:14:16 -0700952 # Make sure we have a usable file
953 adb shell touch $TRACES
954 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800955
Jeff Brownb12c2e52013-08-19 15:14:16 -0700956 # Dump stacks and wait for dump to finish
957 adb shell kill -3 $PID
958 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800959
Jeff Brownb12c2e52013-08-19 15:14:16 -0700960 # Restore original stacks, and show current output
961 adb shell mv $TRACES $TMP
962 adb shell mv $ORIG $TRACES
963 adb shell cat $TMP
964 else
965 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -0700966 local USE64BIT="$(is64bit $PID)"
967 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -0700968 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800969 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800970}
971
John Michelau50200252012-11-09 11:48:04 -0600972function gdbwrapper()
973{
Ben Chengfba67bf2014-02-25 10:27:07 -0800974 local GDB_CMD="$1"
975 shift 1
976 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -0600977}
978
Brigid Smith0a2712d2014-05-28 14:36:43 -0700979function get_symbols_directory()
980{
981 echo $(get_abs_build_var TARGET_OUT_UNSTRIPPED)
982}
983
Michael Wrightaeed7212014-06-19 19:58:12 -0700984# Read the ELF header from /proc/$PID/exe to determine if the process is
985# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -0800986function is64bit()
987{
988 local PID="$1"
989 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -0700990 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800991 echo "64"
992 else
993 echo ""
994 fi
995 else
996 echo ""
997 fi
998}
999
1000# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
1001# executable, set up the approriate gdbserver, then invokes the proper host
1002# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001003function gdbclient()
1004{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001005 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1006 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1007 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
Colin Cross3655a682014-05-22 11:59:10 -07001008 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
Brigid Smith0a2712d2014-05-28 14:36:43 -07001009 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001010 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001011 local ARCH=$(get_build_var TARGET_ARCH)
1012 local GDB
1013 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001014 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -08001015 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Duane Sand3c4fcd82014-07-22 14:34:00 -07001016 mips|mips64) GDB=mips64el-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +00001017 x86) GDB=x86_64-linux-android-gdb;;
1018 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001019 *) echo "Unknown arch $ARCH"; return 1;;
1020 esac
1021
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001022 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1023 local EXE="$1"
1024 if [ "$EXE" ] ; then
1025 EXE=$1
Brigid Smith7a569a62014-06-20 14:12:12 -07001026 if [[ $EXE =~ ^[^/].* ]] ; then
1027 EXE="system/bin/"$EXE
1028 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001029 else
1030 EXE="app_process"
1031 fi
1032
1033 local PORT="$2"
1034 if [ "$PORT" ] ; then
1035 PORT=$2
1036 else
1037 PORT=":5039"
1038 fi
1039
Chris Craik20c136a2012-11-09 18:02:19 -08001040 local PID="$3"
1041 if [ "$PID" ] ; then
1042 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -07001043 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -08001044 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1045 # that likely didn't work because of returning multiple processes
1046 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001047 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001048 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1049 then
1050 echo "Couldn't resolve '$3' to single PID"
1051 return 1
1052 else
1053 echo ""
1054 echo "WARNING: multiple processes matching '$3' observed, using root process"
1055 echo ""
1056 fi
1057 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001058 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001059 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001060 local USE64BIT="$(is64bit $PID)"
1061 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001062 sleep 2
1063 else
1064 echo ""
1065 echo "If you haven't done so already, do this first on the device:"
1066 echo " gdbserver $PORT /system/bin/$EXE"
1067 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001068 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001069 echo ""
1070 fi
1071
Colin Cross84480ad2014-04-10 12:51:39 -07001072 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
Colin Crossa58f8e02014-06-20 13:33:36 -07001073 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
Colin Cross84480ad2014-04-10 12:51:39 -07001074
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001075 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Colin Cross3655a682014-05-22 11:59:10 -07001076 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 -07001077 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001078 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
Christopher Ferris855d27f2014-10-03 17:29:27 -07001079 # Enable special debugging for ART processes.
1080 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1081 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1082 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001083 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1084
Ben Chengfba67bf2014-02-25 10:27:07 -08001085 local WHICH_GDB=
1086 # 64-bit exe found
1087 if [ "$USE64BIT" != "" ] ; then
1088 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1089 # 32-bit exe / 32-bit platform
1090 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1091 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1092 # 32-bit exe / 64-bit platform
1093 else
1094 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1095 fi
Brigid Smith0a2712d2014-05-28 14:36:43 -07001096
Ben Chengfba67bf2014-02-25 10:27:07 -08001097 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001098 else
1099 echo "Unable to determine build system output dir."
1100 fi
1101
1102}
1103
1104case `uname -s` in
1105 Darwin)
1106 function sgrep()
1107 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001108 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 -07001109 }
1110
1111 ;;
1112 *)
1113 function sgrep()
1114 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001115 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 -07001116 }
1117 ;;
1118esac
1119
Raghu Gandham8da43102012-07-25 19:57:22 -07001120function gettargetarch
1121{
1122 get_build_var TARGET_ARCH
1123}
1124
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001125function ggrep()
1126{
1127 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1128}
1129
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001130function jgrep()
1131{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001132 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 -07001133}
1134
1135function cgrep()
1136{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001137 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' \) -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001138}
1139
1140function resgrep()
1141{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001142 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 -07001143}
1144
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001145function mangrep()
1146{
1147 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1148}
1149
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001150function sepgrep()
1151{
1152 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 "$@"
1153}
1154
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001155case `uname -s` in
1156 Darwin)
1157 function mgrep()
1158 {
Ying Wang324c2b22012-08-17 15:03:20 -07001159 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 -07001160 }
1161
1162 function treegrep()
1163 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001164 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 -07001165 }
1166
1167 ;;
1168 *)
1169 function mgrep()
1170 {
Ying Wang324c2b22012-08-17 15:03:20 -07001171 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 -07001172 }
1173
1174 function treegrep()
1175 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001176 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 -07001177 }
1178
1179 ;;
1180esac
1181
1182function getprebuilt
1183{
1184 get_abs_build_var ANDROID_PREBUILTS
1185}
1186
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001187function tracedmdump()
1188{
1189 T=$(gettop)
1190 if [ ! "$T" ]; then
1191 echo "Couldn't locate the top of the tree. Try setting TOP."
1192 return
1193 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001194 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001195 local arch=$(gettargetarch)
1196 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001197
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001198 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001199 if [ ! "$TRACE" ] ; then
1200 echo "usage: tracedmdump tracename"
1201 return
1202 fi
1203
Jack Veenstra60116fc2009-04-09 18:12:34 -07001204 if [ ! -r "$KERNEL" ] ; then
1205 echo "Error: cannot find kernel: '$KERNEL'"
1206 return
1207 fi
1208
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001209 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001210 if [ "$BASETRACE" = "$TRACE" ] ; then
1211 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1212 fi
1213
1214 echo "post-processing traces..."
1215 rm -f $TRACE/qtrace.dexlist
1216 post_trace $TRACE
1217 if [ $? -ne 0 ]; then
1218 echo "***"
1219 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1220 echo "***"
1221 return
1222 fi
1223 echo "generating dexlist output..."
1224 /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
1225 echo "generating dmtrace data..."
1226 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1227 echo "generating html file..."
1228 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1229 echo "done, see $TRACE/dmtrace.html for details"
1230 echo "or run:"
1231 echo " traceview $TRACE/dmtrace"
1232}
1233
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001234# communicate with a running device or emulator, set up necessary state,
1235# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236function runhat()
1237{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001238 # process standard adb options
1239 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001240 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001241 adbTarget=$1
1242 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001243 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001244 adbTarget="$1 $2"
1245 shift 2
1246 fi
1247 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001248 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001249
1250 # runhat options
1251 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001252
1253 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001254 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001255 return
1256 fi
1257
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001258 # confirm hat is available
1259 if [ -z $(which hat) ]; then
1260 echo "hat is not available in this configuration."
1261 return
1262 fi
1263
Andy McFaddenb6289852010-07-12 08:00:19 -07001264 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001265 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001266 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001267 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001268 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001269 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001270 echo -n "> "
1271 read
1272
The Android Open Source Project88b60792009-03-03 19:28:42 -08001273 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001274
The Android Open Source Project88b60792009-03-03 19:28:42 -08001275 echo "Retrieving file $devFile..."
1276 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001277
The Android Open Source Project88b60792009-03-03 19:28:42 -08001278 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001279
The Android Open Source Project88b60792009-03-03 19:28:42 -08001280 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001281 echo "View the output by pointing your browser at http://localhost:7000/"
1282 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001283 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001284}
1285
1286function getbugreports()
1287{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001288 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001289
1290 if [ ! "$reports" ]; then
1291 echo "Could not locate any bugreports."
1292 return
1293 fi
1294
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001295 local report
1296 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001297 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001298 echo "/sdcard/bugreports/${report}"
1299 adb pull /sdcard/bugreports/${report} ${report}
1300 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001301 done
1302}
1303
Victoria Lease1b296b42012-08-21 15:44:06 -07001304function getsdcardpath()
1305{
1306 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1307}
1308
1309function getscreenshotpath()
1310{
1311 echo "$(getsdcardpath)/Pictures/Screenshots"
1312}
1313
1314function getlastscreenshot()
1315{
1316 local screenshot_path=$(getscreenshotpath)
1317 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1318 if [ "$screenshot" = "" ]; then
1319 echo "No screenshots found."
1320 return
1321 fi
1322 echo "${screenshot}"
1323 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1324}
1325
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001326function startviewserver()
1327{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001328 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001329 if [ $# -gt 0 ]; then
1330 port=$1
1331 fi
1332 adb shell service call window 1 i32 $port
1333}
1334
1335function stopviewserver()
1336{
1337 adb shell service call window 2
1338}
1339
1340function isviewserverstarted()
1341{
1342 adb shell service call window 3
1343}
1344
Romain Guyb84049a2010-10-04 16:56:11 -07001345function key_home()
1346{
1347 adb shell input keyevent 3
1348}
1349
1350function key_back()
1351{
1352 adb shell input keyevent 4
1353}
1354
1355function key_menu()
1356{
1357 adb shell input keyevent 82
1358}
1359
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001360function smoketest()
1361{
1362 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1363 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1364 return
1365 fi
1366 T=$(gettop)
1367 if [ ! "$T" ]; then
1368 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1369 return
1370 fi
1371
Ying Wang9cd17642012-12-13 10:52:07 -08001372 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001373 adb uninstall com.android.smoketest > /dev/null &&
1374 adb uninstall com.android.smoketest.tests > /dev/null &&
1375 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1376 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1377 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1378}
1379
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001380# simple shortcut to the runtest command
1381function runtest()
1382{
1383 T=$(gettop)
1384 if [ ! "$T" ]; then
1385 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1386 return
1387 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001388 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001389}
1390
The Android Open Source Project88b60792009-03-03 19:28:42 -08001391function godir () {
1392 if [[ -z "$1" ]]; then
1393 echo "Usage: godir <regex>"
1394 return
1395 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001396 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001397 if [[ ! -f $T/filelist ]]; then
1398 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001399 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001400 echo " Done"
1401 echo ""
1402 fi
1403 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001404 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001405 if [[ ${#lines[@]} = 0 ]]; then
1406 echo "Not found"
1407 return
1408 fi
1409 local pathname
1410 local choice
1411 if [[ ${#lines[@]} > 1 ]]; then
1412 while [[ -z "$pathname" ]]; do
1413 local index=1
1414 local line
1415 for line in ${lines[@]}; do
1416 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001417 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001418 done
1419 echo
1420 echo -n "Select one: "
1421 unset choice
1422 read choice
1423 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1424 echo "Invalid choice"
1425 continue
1426 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001427 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001428 done
1429 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001430 pathname=${lines[0]}
1431 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001432 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001433}
1434
Narayan Kamath9260bba2014-01-17 10:05:25 +00001435# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1436#
1437# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1438# For some reason, installing the JDK doesn't make it show up in the
1439# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001440function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001441 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001442 # we can reset it later, depending on the version of java the build
1443 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001444 #
1445 # If we don't do this, the JAVA_HOME value set by the first call to
1446 # build/envsetup.sh will persist forever.
1447 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1448 export JAVA_HOME=""
1449 fi
1450
Andy McFaddenbd960942010-06-24 12:52:51 -07001451 if [ ! "$JAVA_HOME" ]; then
Narayan Kamathc84889b2014-04-01 14:16:26 +01001452 if [ -n "$LEGACY_USE_JAVA6" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001453 case `uname -s` in
1454 Darwin)
1455 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1456 ;;
1457 *)
1458 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1459 ;;
1460 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001461 else
1462 case `uname -s` in
1463 Darwin)
Jason Parks13b2e192014-04-28 13:32:10 -05001464 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
Narayan Kamath9260bba2014-01-17 10:05:25 +00001465 ;;
1466 *)
1467 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1468 ;;
1469 esac
1470 fi
1471
1472 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1473 # we can change it on the next envsetup.sh, if required.
1474 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001475 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001476}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001477
Alex Rayf0d08eb2013-03-08 15:15:06 -08001478# Print colored exit condition
1479function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001480 "$@"
1481 local retval=$?
1482 if [ $retval -ne 0 ]
1483 then
1484 echo -e "\e[0;31mFAILURE\e[00m"
1485 else
1486 echo -e "\e[0;32mSUCCESS\e[00m"
1487 fi
1488 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001489}
1490
Ying Wanged21d4c2014-08-24 22:14:19 -07001491function get_make_command()
1492{
1493 echo command make
1494}
1495
Ed Heylcc6be0a2014-06-18 14:55:58 -07001496function make()
1497{
1498 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001499 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001500 local ret=$?
1501 local end_time=$(date +"%s")
1502 local tdiff=$(($end_time-$start_time))
1503 local hours=$(($tdiff / 3600 ))
1504 local mins=$((($tdiff % 3600) / 60))
1505 local secs=$(($tdiff % 60))
1506 echo
1507 if [ $ret -eq 0 ] ; then
Ed Heylc6d11f82014-06-27 13:32:39 -07001508 echo -n -e "#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001509 else
Ed Heylc6d11f82014-06-27 13:32:39 -07001510 echo -n -e "#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001511 fi
1512 if [ $hours -gt 0 ] ; then
1513 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1514 elif [ $mins -gt 0 ] ; then
1515 printf "(%02g:%02g (mm:ss))" $mins $secs
1516 elif [ $secs -gt 0 ] ; then
1517 printf "(%s seconds)" $secs
1518 fi
Ed Heylc6d11f82014-06-27 13:32:39 -07001519 echo -e " ####"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001520 echo
1521 return $ret
1522}
1523
1524
1525
Raphael Moll70a86b02011-06-20 16:03:14 -07001526if [ "x$SHELL" != "x/bin/bash" ]; then
1527 case `ps -o command -p $$` in
1528 *bash*)
1529 ;;
1530 *)
1531 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1532 ;;
1533 esac
1534fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001535
1536# Execute the contents of any vendorsetup.sh files we can find.
Ying Wang506410a2014-07-09 15:37:34 -07001537for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1538 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001539do
1540 echo "including $f"
1541 . $f
1542done
1543unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001544
1545addcompletions