blob: 9489d21e0a6dd8ef06434a27e679a4a3ff9a334e [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:
David Zeuthen1b126ff2015-09-30 17:10:48 -04004- lunch: lunch <product_name>-<build_variant>
5- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
6- croot: Changes directory to the top of the tree.
7- m: Makes from the top of the tree.
8- 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.
10 To limit the modules being built use the syntax: mmm dir/:target1,target2.
11- 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.
13- provision: Flash device with all required partitions. Options will be passed on to fastboot.
14- cgrep: Greps on all local C/C++ files.
15- ggrep: Greps on all local Gradle files.
16- jgrep: Greps on all local Java files.
17- resgrep: Greps on all local res/*.xml files.
18- mangrep: Greps on all local AndroidManifest.xml files.
19- mgrep: Greps on all local Makefiles files.
20- sepgrep: Greps on all local sepolicy files.
21- sgrep: Greps on all local source files.
22- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070023
Roland Levillain39341922015-10-20 12:48:19 +010024Environment options:
Dan Albert4ae5d4b2014-10-31 16:23:08 -070025- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
26 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
27 build is leak-check clean.
28
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070029Look at the source to view more functions. The complete list is:
30EOF
31 T=$(gettop)
32 local A
33 A=""
Jacky Cao89483b82015-05-15 22:12:53 +080034 for i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070035 A="$A $i"
36 done
37 echo $A
38}
39
40# Get the value of a build variable as an absolute path.
41function get_abs_build_var()
42{
43 T=$(gettop)
44 if [ ! "$T" ]; then
45 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
46 return
47 fi
Ying Wang9cd17642012-12-13 10:52:07 -080048 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070049 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070050}
51
52# Get the exact value of a build variable.
53function get_build_var()
54{
55 T=$(gettop)
56 if [ ! "$T" ]; then
57 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
58 return
59 fi
Andrew Boie6905e212013-12-19 13:21:46 -080060 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070061 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080062}
63
64# check to see if the supplied product is one we can build
65function check_product()
66{
67 T=$(gettop)
68 if [ ! "$T" ]; then
69 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
70 return
71 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -070072 TARGET_PRODUCT=$1 \
73 TARGET_BUILD_VARIANT= \
74 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070075 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080076 get_build_var TARGET_DEVICE > /dev/null
77 # hide successful answers, but allow the errors to show
78}
79
80VARIANT_CHOICES=(user userdebug eng)
81
82# check to see if the supplied variant is valid
83function check_variant()
84{
85 for v in ${VARIANT_CHOICES[@]}
86 do
87 if [ "$v" = "$1" ]
88 then
89 return 0
90 fi
91 done
92 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070093}
94
95function setpaths()
96{
97 T=$(gettop)
98 if [ ! "$T" ]; then
99 echo "Couldn't locate the top of the tree. Try setting TOP."
100 return
101 fi
102
103 ##################################################################
104 # #
105 # Read me before you modify this code #
106 # #
107 # This function sets ANDROID_BUILD_PATHS to what it is adding #
108 # to PATH, and the next time it is run, it removes that from #
109 # PATH. This is required so lunch can be run more than once #
110 # and still have working paths. #
111 # #
112 ##################################################################
113
Raphael Mollc639c782011-06-20 17:25:01 -0700114 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
115 # due to "C:\Program Files" being in the path.
116
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700117 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700118 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700119 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
120 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700121 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700122 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800123 # strip leading ':', if any
124 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500125 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700126
127 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700128 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700129 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700130
Ben Cheng8bc4c432012-11-16 13:29:13 -0800131 # defined in core/config.mk
132 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700133 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800134 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800135
Raphael Mollc639c782011-06-20 17:25:01 -0700136 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800137 export ANDROID_TOOLCHAIN=
138 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200139 local ARCH=$(get_build_var TARGET_ARCH)
140 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400141 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700142 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400143 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
144 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800145 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200146 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800147 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700148 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700149 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700150 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000151 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200152 *)
153 echo "Can't find toolchain for unknown architecture: $ARCH"
154 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700155 ;;
156 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700157 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800158 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700159 fi
Raphael732936d2011-06-22 14:35:32 -0700160
Ben Chengfba67bf2014-02-25 10:27:07 -0800161 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
162 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
163 fi
164
Jeff Vander Stoep5f50f052015-06-12 09:56:39 -0700165 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang750396d2015-09-14 19:32:50 -0700166 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_DEV_SCRIPTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200167
168 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
169 # to ensure that the corresponding 'emulator' binaries are used.
170 case $(uname -s) in
171 Darwin)
172 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
173 ;;
174 Linux)
175 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
176 ;;
177 *)
178 ANDROID_EMULATOR_PREBUILTS=
179 ;;
180 esac
181 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700182 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200183 export ANDROID_EMULATOR_PREBUILTS
184 fi
185
Ying Wangaa1c9b52012-11-26 20:51:59 -0800186 export PATH=$ANDROID_BUILD_PATHS$PATH
Dan Albertf5caa3d2015-09-18 13:23:56 -0700187 export PYTHONPATH=$T/development/python-packages:$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800188
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500189 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900190 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500191 if [ -n "$JAVA_HOME" ]; then
192 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900193 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
194 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500195 fi
196
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800197 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700198 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
199 export OUT=$ANDROID_PRODUCT_OUT
200
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700201 unset ANDROID_HOST_OUT
202 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
203
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800204 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700205 # TODO: fix the path
206 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
207}
208
209function printconfig()
210{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800211 T=$(gettop)
212 if [ ! "$T" ]; then
213 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
214 return
215 fi
216 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700217}
218
219function set_stuff_for_environment()
220{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800221 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500222 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800223 setpaths
224 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700225
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800226 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700227 # With this environment variable new GCC can apply colors to warnings/errors
228 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 -0700229 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700230}
231
232function set_sequence_number()
233{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700234 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700235}
236
237function settitle()
238{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800239 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700240 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700241 local product=$TARGET_PRODUCT
242 local variant=$TARGET_BUILD_VARIANT
243 local apps=$TARGET_BUILD_APPS
244 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700245 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700246 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700247 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700248 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800249 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700250}
251
Kenny Root52aa81c2011-07-15 11:07:06 -0700252function addcompletions()
253{
254 local T dir f
255
256 # Keep us from trying to run in something that isn't bash.
257 if [ -z "${BASH_VERSION}" ]; then
258 return
259 fi
260
261 # Keep us from trying to run in bash that's too old.
262 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
263 return
264 fi
265
266 dir="sdk/bash_completion"
267 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700268 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700269 echo "including $f"
270 . $f
271 done
272 fi
273}
274
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700275function choosetype()
276{
277 echo "Build type choices are:"
278 echo " 1. release"
279 echo " 2. debug"
280 echo
281
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800282 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700283 DEFAULT_NUM=1
284 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700285
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800286 export TARGET_BUILD_TYPE=
287 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700288 while [ -z $TARGET_BUILD_TYPE ]
289 do
290 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800291 if [ -z "$1" ] ; then
292 read ANSWER
293 else
294 echo $1
295 ANSWER=$1
296 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297 case $ANSWER in
298 "")
299 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
300 ;;
301 1)
302 export TARGET_BUILD_TYPE=release
303 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800304 release)
305 export TARGET_BUILD_TYPE=release
306 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700307 2)
308 export TARGET_BUILD_TYPE=debug
309 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800310 debug)
311 export TARGET_BUILD_TYPE=debug
312 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700313 *)
314 echo
315 echo "I didn't understand your response. Please try again."
316 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317 ;;
318 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800319 if [ -n "$1" ] ; then
320 break
321 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700322 done
323
324 set_stuff_for_environment
325}
326
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800327#
328# This function isn't really right: It chooses a TARGET_PRODUCT
329# based on the list of boards. Usually, that gets you something
330# that kinda works with a generic product, but really, you should
331# pick a product by name.
332#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700333function chooseproduct()
334{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335 if [ "x$TARGET_PRODUCT" != x ] ; then
336 default_value=$TARGET_PRODUCT
337 else
Ying Wang0a76df52015-06-08 11:57:26 -0700338 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339 fi
340
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800341 export TARGET_PRODUCT=
342 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700343 while [ -z "$TARGET_PRODUCT" ]
344 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700345 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800346 if [ -z "$1" ] ; then
347 read ANSWER
348 else
349 echo $1
350 ANSWER=$1
351 fi
352
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700353 if [ -z "$ANSWER" ] ; then
354 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800355 else
356 if check_product $ANSWER
357 then
358 export TARGET_PRODUCT=$ANSWER
359 else
360 echo "** Not a valid product: $ANSWER"
361 fi
362 fi
363 if [ -n "$1" ] ; then
364 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700365 fi
366 done
367
368 set_stuff_for_environment
369}
370
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800371function choosevariant()
372{
373 echo "Variant choices are:"
374 local index=1
375 local v
376 for v in ${VARIANT_CHOICES[@]}
377 do
378 # The product name is the name of the directory containing
379 # the makefile we found, above.
380 echo " $index. $v"
381 index=$(($index+1))
382 done
383
384 local default_value=eng
385 local ANSWER
386
387 export TARGET_BUILD_VARIANT=
388 while [ -z "$TARGET_BUILD_VARIANT" ]
389 do
390 echo -n "Which would you like? [$default_value] "
391 if [ -z "$1" ] ; then
392 read ANSWER
393 else
394 echo $1
395 ANSWER=$1
396 fi
397
398 if [ -z "$ANSWER" ] ; then
399 export TARGET_BUILD_VARIANT=$default_value
400 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
401 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800402 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800403 fi
404 else
405 if check_variant $ANSWER
406 then
407 export TARGET_BUILD_VARIANT=$ANSWER
408 else
409 echo "** Not a valid variant: $ANSWER"
410 fi
411 fi
412 if [ -n "$1" ] ; then
413 break
414 fi
415 done
416}
417
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700418function choosecombo()
419{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700420 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700421
422 echo
423 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700424 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700425
426 echo
427 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700428 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800429
430 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700431 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800432 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700433}
434
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800435# Clear this variable. It will be built up again when the vendorsetup.sh
436# files are included at the end of this file.
437unset LUNCH_MENU_CHOICES
438function add_lunch_combo()
439{
440 local new_combo=$1
441 local c
442 for c in ${LUNCH_MENU_CHOICES[@]} ; do
443 if [ "$new_combo" = "$c" ] ; then
444 return
445 fi
446 done
447 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
448}
449
450# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700451add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800452add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000453add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800454add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000455add_lunch_combo aosp_x86-eng
456add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800457
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458function print_lunch_menu()
459{
460 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461 echo
462 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700463 echo
464 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800465
466 local i=1
467 local choice
468 for choice in ${LUNCH_MENU_CHOICES[@]}
469 do
470 echo " $i. $choice"
471 i=$(($i+1))
472 done
473
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474 echo
475}
476
477function lunch()
478{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479 local answer
480
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700481 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483 else
484 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700485 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700487 fi
488
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800489 local selection=
490
491 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700492 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700493 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800494 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
495 then
496 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
497 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800498 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499 fi
500 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
501 then
502 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700503 fi
504
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800505 if [ -z "$selection" ]
506 then
507 echo
508 echo "Invalid lunch combo: $answer"
509 return 1
510 fi
511
Joe Onoratoda12daf2010-06-09 18:18:31 -0700512 export TARGET_BUILD_APPS=
513
Jeff Browne33ba4c2011-07-11 22:11:46 -0700514 local product=$(echo -n $selection | sed -e "s/-.*$//")
515 check_product $product
516 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800517 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700518 echo
519 echo "** Don't have a product spec for: '$product'"
520 echo "** Do you have the right repo manifest?"
521 product=
522 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800523
Jeff Browne33ba4c2011-07-11 22:11:46 -0700524 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
525 check_variant $variant
526 if [ $? -ne 0 ]
527 then
528 echo
529 echo "** Invalid variant: '$variant'"
530 echo "** Must be one of ${VARIANT_CHOICES[@]}"
531 variant=
532 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800533
Jeff Browne33ba4c2011-07-11 22:11:46 -0700534 if [ -z "$product" -o -z "$variant" ]
535 then
536 echo
537 return 1
538 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800539
Jeff Browne33ba4c2011-07-11 22:11:46 -0700540 export TARGET_PRODUCT=$product
541 export TARGET_BUILD_VARIANT=$variant
542 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700543
544 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800545
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700546 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800547 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700548}
549
Jeff Davidson513d7a42010-08-02 10:00:44 -0700550# Tab completion for lunch.
551function _lunch()
552{
553 local cur prev opts
554 COMPREPLY=()
555 cur="${COMP_WORDS[COMP_CWORD]}"
556 prev="${COMP_WORDS[COMP_CWORD-1]}"
557
558 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
559 return 0
560}
561complete -F _lunch lunch
562
Joe Onoratoda12daf2010-06-09 18:18:31 -0700563# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700564# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700565function tapas()
566{
Ying Wangb541ab62014-05-29 17:57:40 -0700567 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 -0700568 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700569 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
570 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 -0700571
Ying Wang67f02922012-08-22 10:25:20 -0700572 if [ $(echo $arch | wc -w) -gt 1 ]; then
573 echo "tapas: Error: Multiple build archs supplied: $arch"
574 return
575 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700576 if [ $(echo $variant | wc -w) -gt 1 ]; then
577 echo "tapas: Error: Multiple build variants supplied: $variant"
578 return
579 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700580 if [ $(echo $density | wc -w) -gt 1 ]; then
581 echo "tapas: Error: Multiple densities supplied: $density"
582 return
583 fi
Ying Wang67f02922012-08-22 10:25:20 -0700584
Ying Wang0a76df52015-06-08 11:57:26 -0700585 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700586 case $arch in
Ying Wang0a76df52015-06-08 11:57:26 -0700587 x86) product=aosp_x86;;
588 mips) product=aosp_mips;;
Ying Wangb541ab62014-05-29 17:57:40 -0700589 armv5) product=generic_armv5;;
590 arm64) product=aosp_arm64;;
591 x86_64) product=aosp_x86_64;;
592 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700593 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700594 if [ -z "$variant" ]; then
595 variant=eng
596 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700597 if [ -z "$apps" ]; then
598 apps=all
599 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600600 if [ -z "$density" ]; then
601 density=alldpi
602 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700603
Ying Wang67f02922012-08-22 10:25:20 -0700604 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700605 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700606 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700607 export TARGET_BUILD_TYPE=release
608 export TARGET_BUILD_APPS=$apps
609
610 set_stuff_for_environment
611 printconfig
612}
613
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700614function gettop
615{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800616 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700617 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700618 # The following circumlocution ensures we remove symlinks from TOP.
619 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700620 else
621 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800622 # The following circumlocution (repeated below as well) ensures
623 # that we record the true directory name and not one that is
624 # faked up with symlink names.
625 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700626 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800627 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700628 T=
629 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800630 \cd ..
synergyb112a402013-07-05 19:47:47 -0700631 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700632 done
Ying Wang9cd17642012-12-13 10:52:07 -0800633 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700634 if [ -f "$T/$TOPFILE" ]; then
635 echo $T
636 fi
637 fi
638 fi
639}
640
Andrew Hsieh906cb782013-09-10 17:37:14 +0800641# Return driver for "make", if any (eg. static analyzer)
642function getdriver()
643{
644 local T="$1"
645 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
646 if [ -n "$WITH_STATIC_ANALYZER" ]; then
Chih-Hung Hsieh42d5c292016-02-24 16:42:15 -0800647 # Use scan-build to collect all static analyzer reports into directory
648 # /tmp/scan-build-yyyy-mm-dd-hhmmss-*
649 # The clang compiler passed by --use-analyzer here is not important.
650 # build/core/binary.mk will set CLANG_CXX and CLANG before calling
651 # c++-analyzer and ccc-analyzer.
652 local CLANG_VERSION=$(get_build_var LLVM_PREBUILTS_VERSION)
653 local BUILD_OS=$(get_build_var BUILD_OS)
654 local CLANG_DIR="$T/prebuilts/clang/host/${BUILD_OS}-x86/${CLANG_VERSION}"
Andrew Hsieh906cb782013-09-10 17:37:14 +0800655 echo "\
Chih-Hung Hsieh42d5c292016-02-24 16:42:15 -0800656${CLANG_DIR}/tools/scan-build/bin/scan-build \
657--use-analyzer ${CLANG_DIR}/bin/clang \
658--status-bugs"
Andrew Hsieh906cb782013-09-10 17:37:14 +0800659 fi
660}
661
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662function m()
663{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800664 local T=$(gettop)
665 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700666 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800667 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700668 else
669 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700670 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700671 fi
672}
673
674function findmakefile()
675{
676 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800677 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700678 T=
679 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700680 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700681 if [ -f "$T/Android.mk" ]; then
682 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800683 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700684 return
685 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800686 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700687 done
Ying Wang9cd17642012-12-13 10:52:07 -0800688 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700689}
690
691function mm()
692{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800693 local T=$(gettop)
694 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700695 # If we're sitting in the root of the build tree, just do a
696 # normal make.
697 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800698 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700699 else
700 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800701 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700702 local MODULES=
703 local GET_INSTALL_PATH=
704 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700705 # Remove the path to top as the makefilepath needs to be relative
706 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700707 if [ ! "$T" ]; then
708 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700709 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700710 elif [ ! "$M" ]; then
711 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700712 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700713 else
Ying Wanga7deb082013-08-16 13:24:47 -0700714 for ARG in $@; do
715 case $ARG in
716 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
717 esac
718 done
719 if [ -n "$GET_INSTALL_PATH" ]; then
720 MODULES=
721 ARGS=GET-INSTALL-PATH
722 else
723 MODULES=all_modules
724 ARGS=$@
725 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700726 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 -0700727 fi
728 fi
729}
730
731function mmm()
732{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800733 local T=$(gettop)
734 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700735 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800736 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800737 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800738 local ARGS=
739 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700740 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800741 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
742 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
743 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800744 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
745 if [ "$MODULES" = "" ]; then
746 MODULES=all_modules
747 fi
748 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700749 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700750 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
751 local TO_CHOP=`expr $TO_CHOP + 1`
752 local START=`PWD= /bin/pwd`
753 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700754 if [ "$MFILE" = "" ] ; then
755 MFILE=$DIR/Android.mk
756 else
757 MFILE=$MFILE/$DIR/Android.mk
758 fi
759 MAKEFILE="$MAKEFILE $MFILE"
760 else
Ying Wanga7deb082013-08-16 13:24:47 -0700761 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700762 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700763 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
Abhinav1997a72a6e72015-10-18 20:25:48 +0200764 *) if [ -d $DIR ]; then
765 echo "No Android.mk in $DIR.";
766 else
767 echo "Couldn't locate the directory $DIR";
768 fi
769 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700770 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700771 fi
772 done
Ying Wanga7deb082013-08-16 13:24:47 -0700773 if [ -n "$GET_INSTALL_PATH" ]; then
774 ARGS=$GET_INSTALL_PATH
775 MODULES=
776 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800777 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 -0700778 else
779 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700780 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700781 fi
782}
783
Ying Wangb607f7b2013-02-08 18:01:04 -0800784function mma()
785{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800786 local T=$(gettop)
787 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800788 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800789 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800790 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800791 if [ ! "$T" ]; then
792 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700793 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800794 fi
795 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Ying Wang61cd8842015-09-24 16:19:19 -0700796 local MODULES_IN_PATHS=MODULES-IN-$MY_PWD
797 # Convert "/" to "-".
798 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
799 $DRV make -C $T -f build/core/main.mk $@ $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800800 fi
801}
802
803function mmma()
804{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800805 local T=$(gettop)
806 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800807 if [ "$T" ]; then
808 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
809 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
810 local MY_PWD=`PWD= /bin/pwd`
811 if [ "$MY_PWD" = "$T" ]; then
812 MY_PWD=
813 else
814 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
815 fi
816 local DIR=
Ying Wangcaeaa082015-09-23 16:08:55 -0700817 local MODULES_IN_PATHS=
Ying Wangb607f7b2013-02-08 18:01:04 -0800818 local ARGS=
819 for DIR in $DIRS ; do
820 if [ -d $DIR ]; then
Ying Wangcaeaa082015-09-23 16:08:55 -0700821 # Remove the leading ./ and trailing / if any exists.
822 DIR=${DIR#./}
823 DIR=${DIR%/}
824 if [ "$MY_PWD" != "" ]; then
825 DIR=$MY_PWD/$DIR
Ying Wangb607f7b2013-02-08 18:01:04 -0800826 fi
Ying Wang61cd8842015-09-24 16:19:19 -0700827 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
Ying Wangb607f7b2013-02-08 18:01:04 -0800828 else
829 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700830 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800831 *) echo "Couldn't find directory $DIR"; return 1;;
832 esac
833 fi
834 done
Ying Wang61cd8842015-09-24 16:19:19 -0700835 # Convert "/" to "-".
836 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Ying Wangcaeaa082015-09-23 16:08:55 -0700837 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800838 else
839 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700840 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800841 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
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800917# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700918# that has the core-file-size limit set correctly
919#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800920# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700921# if its core-file-size limit is not set already.
922# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
923
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800924function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700925{
926 echo "Getting root...";
927 adb root;
928 adb wait-for-device;
929
Roland Levillain39341922015-10-20 12:48:19 +0100930 echo "Remounting root partition read-write...";
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700931 adb shell mount -w -o remount -t rootfs rootfs;
932 sleep 1;
933 adb wait-for-device;
934 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -0800935 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700936 adb shell chmod 0777 /cores;
937
938 echo "Granting SELinux permission to dump in /cores...";
939 adb shell restorecon -R /cores;
940
941 echo "Set core pattern.";
942 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
943
944 echo "Done."
945}
946
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800947# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700948# $1 = PID of process (e.g., $(pid mediaserver))
949#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800950# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700951# dump to actually be generated.
952
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800953function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700954{
955 local PID=$1;
956 if [ -z "$PID" ]; then
957 printf "Expecting a PID!\n";
958 return;
959 fi;
960 echo "Setting core limit for $PID to infinite...";
961 adb shell prlimit $PID 4 -1 -1
962}
963
964# core - send SIGV and pull the core for process
965# $1 = PID of process (e.g., $(pid mediaserver))
966#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800967# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700968# enabled globally.
969
970function core()
971{
972 local PID=$1;
973
974 if [ -z "$PID" ]; then
975 printf "Expecting a PID!\n";
976 return;
977 fi;
978
979 local CORENAME=core.$PID;
980 local COREPATH=/cores/$CORENAME;
981 local SIG=SEGV;
982
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800983 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700984
985 local done=0;
986 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
987 printf "\tSending SIG%s to %d...\n" $SIG $PID;
988 adb shell kill -$SIG $PID;
989 sleep 1;
990 done;
991
992 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
993 echo "Done: core is under $COREPATH on device.";
994}
995
Christopher Tate744ee802009-11-12 15:33:08 -0800996# systemstack - dump the current stack trace of all threads in the system process
997# to the usual ANR traces file
998function systemstack()
999{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001000 stacks system_server
1001}
1002
1003function stacks()
1004{
1005 if [[ $1 =~ ^[0-9]+$ ]] ; then
1006 local PID="$1"
1007 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001008 local PIDLIST="$(pid $1)"
1009 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1010 local PID="$PIDLIST"
1011 elif [ "$PIDLIST" ] ; then
1012 echo "more than one process: $1"
1013 else
1014 echo "no such process: $1"
1015 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001016 else
1017 echo "usage: stacks [pid|process name]"
1018 fi
1019
1020 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001021 # Determine whether the process is native
1022 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1023 # Dump stacks of Dalvik process
1024 local TRACES=/data/anr/traces.txt
1025 local ORIG=/data/anr/traces.orig
1026 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001027
Jeff Brownb12c2e52013-08-19 15:14:16 -07001028 # Keep original traces to avoid clobbering
1029 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001030
Jeff Brownb12c2e52013-08-19 15:14:16 -07001031 # Make sure we have a usable file
1032 adb shell touch $TRACES
1033 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001034
Jeff Brownb12c2e52013-08-19 15:14:16 -07001035 # Dump stacks and wait for dump to finish
1036 adb shell kill -3 $PID
1037 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001038
Jeff Brownb12c2e52013-08-19 15:14:16 -07001039 # Restore original stacks, and show current output
1040 adb shell mv $TRACES $TMP
1041 adb shell mv $ORIG $TRACES
1042 adb shell cat $TMP
1043 else
1044 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001045 local USE64BIT="$(is64bit $PID)"
1046 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001047 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001048 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001049}
1050
Michael Wrightaeed7212014-06-19 19:58:12 -07001051# Read the ELF header from /proc/$PID/exe to determine if the process is
1052# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001053function is64bit()
1054{
1055 local PID="$1"
1056 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001057 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001058 echo "64"
1059 else
1060 echo ""
1061 fi
1062 else
1063 echo ""
1064 fi
1065}
1066
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001067case `uname -s` in
1068 Darwin)
1069 function sgrep()
1070 {
Mike Frysinger5e479732015-09-22 18:13:48 -04001071 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' \
1072 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001073 }
1074
1075 ;;
1076 *)
1077 function sgrep()
1078 {
Mike Frysinger5e479732015-09-22 18:13:48 -04001079 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\)' \
1080 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001081 }
1082 ;;
1083esac
1084
Raghu Gandham8da43102012-07-25 19:57:22 -07001085function gettargetarch
1086{
1087 get_build_var TARGET_ARCH
1088}
1089
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001090function ggrep()
1091{
Mike Frysinger5e479732015-09-22 18:13:48 -04001092 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1093 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001094}
1095
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001096function jgrep()
1097{
Mike Frysinger5e479732015-09-22 18:13:48 -04001098 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1099 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001100}
1101
1102function cgrep()
1103{
Mike Frysinger5e479732015-09-22 18:13:48 -04001104 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' \) \
1105 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001106}
1107
1108function resgrep()
1109{
Mike Frysinger5e479732015-09-22 18:13:48 -04001110 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1111 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1112 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001113}
1114
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001115function mangrep()
1116{
Mike Frysinger5e479732015-09-22 18:13:48 -04001117 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1118 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001119}
1120
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001121function sepgrep()
1122{
Mike Frysinger5e479732015-09-22 18:13:48 -04001123 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1124 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001125}
1126
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001127function rcgrep()
1128{
Mike Frysinger5e479732015-09-22 18:13:48 -04001129 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1130 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001131}
1132
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001133case `uname -s` in
1134 Darwin)
1135 function mgrep()
1136 {
Mike Frysinger5e479732015-09-22 18:13:48 -04001137 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' \
1138 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001139 }
1140
1141 function treegrep()
1142 {
Mike Frysinger5e479732015-09-22 18:13:48 -04001143 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' \
1144 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001145 }
1146
1147 ;;
1148 *)
1149 function mgrep()
1150 {
Mike Frysinger5e479732015-09-22 18:13:48 -04001151 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f \
1152 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001153 }
1154
1155 function treegrep()
1156 {
Mike Frysinger5e479732015-09-22 18:13:48 -04001157 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f \
1158 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001159 }
1160
1161 ;;
1162esac
1163
1164function getprebuilt
1165{
1166 get_abs_build_var ANDROID_PREBUILTS
1167}
1168
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001169function tracedmdump()
1170{
1171 T=$(gettop)
1172 if [ ! "$T" ]; then
1173 echo "Couldn't locate the top of the tree. Try setting TOP."
1174 return
1175 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001176 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001177 local arch=$(gettargetarch)
1178 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001179
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001180 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001181 if [ ! "$TRACE" ] ; then
1182 echo "usage: tracedmdump tracename"
1183 return
1184 fi
1185
Jack Veenstra60116fc2009-04-09 18:12:34 -07001186 if [ ! -r "$KERNEL" ] ; then
1187 echo "Error: cannot find kernel: '$KERNEL'"
1188 return
1189 fi
1190
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001191 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001192 if [ "$BASETRACE" = "$TRACE" ] ; then
1193 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1194 fi
1195
1196 echo "post-processing traces..."
1197 rm -f $TRACE/qtrace.dexlist
1198 post_trace $TRACE
1199 if [ $? -ne 0 ]; then
1200 echo "***"
1201 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1202 echo "***"
1203 return
1204 fi
1205 echo "generating dexlist output..."
1206 /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
1207 echo "generating dmtrace data..."
1208 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1209 echo "generating html file..."
1210 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1211 echo "done, see $TRACE/dmtrace.html for details"
1212 echo "or run:"
1213 echo " traceview $TRACE/dmtrace"
1214}
1215
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001216# communicate with a running device or emulator, set up necessary state,
1217# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001218function runhat()
1219{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001220 # process standard adb options
1221 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001222 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001223 adbTarget=$1
1224 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001225 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001226 adbTarget="$1 $2"
1227 shift 2
1228 fi
1229 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001230 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001231
1232 # runhat options
1233 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001234
1235 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001236 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001237 return
1238 fi
1239
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001240 # confirm hat is available
1241 if [ -z $(which hat) ]; then
1242 echo "hat is not available in this configuration."
1243 return
1244 fi
1245
Andy McFaddenb6289852010-07-12 08:00:19 -07001246 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001247 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001248 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001249 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001250 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001251 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001252 echo -n "> "
1253 read
1254
The Android Open Source Project88b60792009-03-03 19:28:42 -08001255 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001256
The Android Open Source Project88b60792009-03-03 19:28:42 -08001257 echo "Retrieving file $devFile..."
1258 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001259
The Android Open Source Project88b60792009-03-03 19:28:42 -08001260 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001261
The Android Open Source Project88b60792009-03-03 19:28:42 -08001262 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001263 echo "View the output by pointing your browser at http://localhost:7000/"
1264 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001265 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001266}
1267
1268function getbugreports()
1269{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001270 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001271
1272 if [ ! "$reports" ]; then
1273 echo "Could not locate any bugreports."
1274 return
1275 fi
1276
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001277 local report
1278 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001279 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001280 echo "/sdcard/bugreports/${report}"
1281 adb pull /sdcard/bugreports/${report} ${report}
1282 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001283 done
1284}
1285
Victoria Lease1b296b42012-08-21 15:44:06 -07001286function getsdcardpath()
1287{
1288 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1289}
1290
1291function getscreenshotpath()
1292{
1293 echo "$(getsdcardpath)/Pictures/Screenshots"
1294}
1295
1296function getlastscreenshot()
1297{
1298 local screenshot_path=$(getscreenshotpath)
1299 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1300 if [ "$screenshot" = "" ]; then
1301 echo "No screenshots found."
1302 return
1303 fi
1304 echo "${screenshot}"
1305 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1306}
1307
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001308function startviewserver()
1309{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001310 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001311 if [ $# -gt 0 ]; then
1312 port=$1
1313 fi
1314 adb shell service call window 1 i32 $port
1315}
1316
1317function stopviewserver()
1318{
1319 adb shell service call window 2
1320}
1321
1322function isviewserverstarted()
1323{
1324 adb shell service call window 3
1325}
1326
Romain Guyb84049a2010-10-04 16:56:11 -07001327function key_home()
1328{
1329 adb shell input keyevent 3
1330}
1331
1332function key_back()
1333{
1334 adb shell input keyevent 4
1335}
1336
1337function key_menu()
1338{
1339 adb shell input keyevent 82
1340}
1341
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001342function smoketest()
1343{
1344 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1345 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1346 return
1347 fi
1348 T=$(gettop)
1349 if [ ! "$T" ]; then
1350 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1351 return
1352 fi
1353
Ying Wang9cd17642012-12-13 10:52:07 -08001354 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001355 adb uninstall com.android.smoketest > /dev/null &&
1356 adb uninstall com.android.smoketest.tests > /dev/null &&
1357 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1358 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1359 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1360}
1361
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001362# simple shortcut to the runtest command
1363function runtest()
1364{
1365 T=$(gettop)
1366 if [ ! "$T" ]; then
1367 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1368 return
1369 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001370 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001371}
1372
The Android Open Source Project88b60792009-03-03 19:28:42 -08001373function godir () {
1374 if [[ -z "$1" ]]; then
1375 echo "Usage: godir <regex>"
1376 return
1377 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001378 T=$(gettop)
Brian Carlstromf2257422015-09-30 20:28:54 -07001379 if [ ! "$OUT_DIR" = "" ]; then
1380 mkdir -p $OUT_DIR
1381 FILELIST=$OUT_DIR/filelist
1382 else
1383 FILELIST=$T/filelist
1384 fi
1385 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001386 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001387 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001388 echo " Done"
1389 echo ""
1390 fi
1391 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001392 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001393 if [[ ${#lines[@]} = 0 ]]; then
1394 echo "Not found"
1395 return
1396 fi
1397 local pathname
1398 local choice
1399 if [[ ${#lines[@]} > 1 ]]; then
1400 while [[ -z "$pathname" ]]; do
1401 local index=1
1402 local line
1403 for line in ${lines[@]}; do
1404 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001405 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001406 done
1407 echo
1408 echo -n "Select one: "
1409 unset choice
1410 read choice
1411 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1412 echo "Invalid choice"
1413 continue
1414 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001415 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001416 done
1417 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001418 pathname=${lines[0]}
1419 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001420 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001421}
1422
Neil Fuller91e012c2015-11-19 15:51:47 +00001423# Force JAVA_HOME to point to java 1.7/1.8 if it isn't already set.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001424function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001425 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001426 # we can reset it later, depending on the version of java the build
1427 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001428 #
1429 # If we don't do this, the JAVA_HOME value set by the first call to
1430 # build/envsetup.sh will persist forever.
1431 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1432 export JAVA_HOME=""
1433 fi
1434
Andy McFaddenbd960942010-06-24 12:52:51 -07001435 if [ ! "$JAVA_HOME" ]; then
Neil Fuller1f495b82016-01-25 17:12:41 +00001436 if [ -n "$LEGACY_USE_JAVA7" ]; then
1437 echo Warning: Support for JDK 7 will be dropped. Switch to JDK 8.
Neil Fuller91e012c2015-11-19 15:51:47 +00001438 case `uname -s` in
1439 Darwin)
1440 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1441 ;;
1442 *)
1443 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1444 ;;
1445 esac
1446 else
1447 case `uname -s` in
1448 Darwin)
1449 export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
1450 ;;
1451 *)
1452 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
1453 ;;
1454 esac
1455 fi
Narayan Kamath9260bba2014-01-17 10:05:25 +00001456
1457 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1458 # we can change it on the next envsetup.sh, if required.
1459 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001460 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001461}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001462
Alex Rayf0d08eb2013-03-08 15:15:06 -08001463# Print colored exit condition
1464function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001465 "$@"
1466 local retval=$?
1467 if [ $retval -ne 0 ]
1468 then
Jacky Cao89483b82015-05-15 22:12:53 +08001469 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001470 else
Jacky Cao89483b82015-05-15 22:12:53 +08001471 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001472 fi
1473 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001474}
1475
Ying Wanged21d4c2014-08-24 22:14:19 -07001476function get_make_command()
1477{
1478 echo command make
1479}
1480
Ed Heylcc6be0a2014-06-18 14:55:58 -07001481function make()
1482{
1483 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001484 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001485 local ret=$?
1486 local end_time=$(date +"%s")
1487 local tdiff=$(($end_time-$start_time))
1488 local hours=$(($tdiff / 3600 ))
1489 local mins=$((($tdiff % 3600) / 60))
1490 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001491 local ncolors=$(tput colors 2>/dev/null)
1492 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001493 color_failed=$'\E'"[0;31m"
1494 color_success=$'\E'"[0;32m"
1495 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001496 else
1497 color_failed=""
1498 color_success=""
1499 color_reset=""
1500 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001501 echo
1502 if [ $ret -eq 0 ] ; then
Jacky Cao89483b82015-05-15 22:12:53 +08001503 echo -n "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001504 else
Jacky Cao89483b82015-05-15 22:12:53 +08001505 echo -n "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001506 fi
1507 if [ $hours -gt 0 ] ; then
1508 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1509 elif [ $mins -gt 0 ] ; then
1510 printf "(%02g:%02g (mm:ss))" $mins $secs
1511 elif [ $secs -gt 0 ] ; then
1512 printf "(%s seconds)" $secs
1513 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001514 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001515 echo
1516 return $ret
1517}
1518
David Zeuthen1b126ff2015-09-30 17:10:48 -04001519function provision()
1520{
1521 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1522 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1523 return 1
1524 fi
1525 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1526 echo "There is no provisioning script for the device." >&2
1527 return 1
1528 fi
1529
1530 # Check if user really wants to do this.
1531 if [ "$1" = "--no-confirmation" ]; then
1532 shift 1
1533 else
1534 echo "This action will reflash your device."
1535 echo ""
1536 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1537 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001538 echo -n "Are you sure you want to do this (yes/no)? "
1539 read
David Zeuthen1b126ff2015-09-30 17:10:48 -04001540 if [[ "${REPLY}" != "yes" ]] ; then
1541 echo "Not taking any action. Exiting." >&2
1542 return 1
1543 fi
1544 fi
1545 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1546}
1547
Raphael Moll70a86b02011-06-20 16:03:14 -07001548if [ "x$SHELL" != "x/bin/bash" ]; then
1549 case `ps -o command -p $$` in
1550 *bash*)
1551 ;;
1552 *)
1553 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1554 ;;
1555 esac
1556fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001557
1558# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02001559for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
Lee Campbell455f6f42015-08-20 13:55:45 -07001560 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
1561 `test -d product && find -L product -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001562do
1563 echo "including $f"
1564 . $f
1565done
1566unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001567
1568addcompletions