blob: 55167c02378a910bfea589d19907476f761091ef [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
Jeff Gastonc6dfc4e2017-05-30 17:12:37 -07003
4Run "m help" for help with the build system itself.
5
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08006Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
David Zeuthen1b126ff2015-09-30 17:10:48 -04007- lunch: lunch <product_name>-<build_variant>
Jeff Gastonc6dfc4e2017-05-30 17:12:37 -07008 Selects <product_name> as the product to build, and <build_variant> as the variant to
9 build, and stores those selections in the environment to be read by subsequent
10 invocations of 'm' etc.
David Zeuthen1b126ff2015-09-30 17:10:48 -040011- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
12- croot: Changes directory to the top of the tree.
13- m: Makes from the top of the tree.
14- mm: Builds all of the modules in the current directory, but not their dependencies.
15- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
16 To limit the modules being built use the syntax: mmm dir/:target1,target2.
17- mma: Builds all of the modules in the current directory, and their dependencies.
18- mmma: Builds all of the modules in the supplied directories, and their dependencies.
19- provision: Flash device with all required partitions. Options will be passed on to fastboot.
20- cgrep: Greps on all local C/C++ files.
21- ggrep: Greps on all local Gradle files.
22- jgrep: Greps on all local Java files.
23- resgrep: Greps on all local res/*.xml files.
24- mangrep: Greps on all local AndroidManifest.xml files.
25- mgrep: Greps on all local Makefiles files.
26- sepgrep: Greps on all local sepolicy files.
27- sgrep: Greps on all local source files.
28- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070029
Roland Levillain39341922015-10-20 12:48:19 +010030Environment options:
Dan Albert4ae5d4b2014-10-31 16:23:08 -070031- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
32 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
33 build is leak-check clean.
34
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070035Look at the source to view more functions. The complete list is:
36EOF
Christopher Ferris55257d22017-03-23 11:08:58 -070037 local T=$(gettop)
38 local A=""
39 local i
Jacky Cao89483b82015-05-15 22:12:53 +080040 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 -070041 A="$A $i"
42 done
43 echo $A
44}
45
Ying Wang08800fd2016-03-03 20:57:21 -080046# Get all the build variables needed by this script in a single call to the build system.
47function build_build_var_cache()
48{
Christopher Ferris55257d22017-03-23 11:08:58 -070049 local T=$(gettop)
Ying Wang08800fd2016-03-03 20:57:21 -080050 # Grep out the variable names from the script.
51 cached_vars=`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`
52 cached_abs_vars=`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`
53 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
54 build_dicts_script=`\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
55 command make --no-print-directory -f build/core/config.mk \
56 dump-many-vars \
57 DUMP_MANY_VARS="$cached_vars" \
58 DUMP_MANY_ABS_VARS="$cached_abs_vars" \
59 DUMP_VAR_PREFIX="var_cache_" \
60 DUMP_ABS_VAR_PREFIX="abs_var_cache_"`
61 local ret=$?
62 if [ $ret -ne 0 ]
63 then
64 unset build_dicts_script
65 return $ret
66 fi
67 # Excute the script to store the "<val>=<value>" pairs as shell variables.
68 eval "$build_dicts_script"
Ying Wang08800fd2016-03-03 20:57:21 -080069 ret=$?
Ying Wangf0cb3972016-03-04 13:56:23 -080070 unset build_dicts_script
Ying Wang08800fd2016-03-03 20:57:21 -080071 if [ $ret -ne 0 ]
72 then
73 return $ret
74 fi
75 BUILD_VAR_CACHE_READY="true"
76}
77
Ying Wangf0cb3972016-03-04 13:56:23 -080078# Delete the build var cache, so that we can still call into the build system
Ying Wang08800fd2016-03-03 20:57:21 -080079# to get build variables not listed in this script.
80function destroy_build_var_cache()
81{
82 unset BUILD_VAR_CACHE_READY
Christopher Ferris55257d22017-03-23 11:08:58 -070083 local v
Ying Wang08800fd2016-03-03 20:57:21 -080084 for v in $cached_vars; do
85 unset var_cache_$v
86 done
87 unset cached_vars
88 for v in $cached_abs_vars; do
89 unset abs_var_cache_$v
90 done
91 unset cached_abs_vars
92}
93
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070094# Get the value of a build variable as an absolute path.
95function get_abs_build_var()
96{
Ying Wang08800fd2016-03-03 20:57:21 -080097 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
98 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -080099 eval "echo \"\${abs_var_cache_$1}\""
Ying Wang08800fd2016-03-03 20:57:21 -0800100 return
101 fi
102
Christopher Ferris55257d22017-03-23 11:08:58 -0700103 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700104 if [ ! "$T" ]; then
105 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
106 return
107 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800108 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -0700109 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700110}
111
112# Get the exact value of a build variable.
113function get_build_var()
114{
Ying Wang08800fd2016-03-03 20:57:21 -0800115 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
116 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800117 eval "echo \"\${var_cache_$1}\""
Ying Wang08800fd2016-03-03 20:57:21 -0800118 return
119 fi
120
Christopher Ferris55257d22017-03-23 11:08:58 -0700121 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700122 if [ ! "$T" ]; then
123 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
124 return
125 fi
Andrew Boie6905e212013-12-19 13:21:46 -0800126 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -0700127 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800128}
129
130# check to see if the supplied product is one we can build
131function check_product()
132{
Christopher Ferris55257d22017-03-23 11:08:58 -0700133 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800134 if [ ! "$T" ]; then
135 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
136 return
137 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700138 TARGET_PRODUCT=$1 \
139 TARGET_BUILD_VARIANT= \
140 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700141 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800142 get_build_var TARGET_DEVICE > /dev/null
143 # hide successful answers, but allow the errors to show
144}
145
146VARIANT_CHOICES=(user userdebug eng)
147
148# check to see if the supplied variant is valid
149function check_variant()
150{
Christopher Ferris55257d22017-03-23 11:08:58 -0700151 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800152 for v in ${VARIANT_CHOICES[@]}
153 do
154 if [ "$v" = "$1" ]
155 then
156 return 0
157 fi
158 done
159 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700160}
161
162function setpaths()
163{
Christopher Ferris55257d22017-03-23 11:08:58 -0700164 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700165 if [ ! "$T" ]; then
166 echo "Couldn't locate the top of the tree. Try setting TOP."
167 return
168 fi
169
170 ##################################################################
171 # #
172 # Read me before you modify this code #
173 # #
174 # This function sets ANDROID_BUILD_PATHS to what it is adding #
175 # to PATH, and the next time it is run, it removes that from #
176 # PATH. This is required so lunch can be run more than once #
177 # and still have working paths. #
178 # #
179 ##################################################################
180
Raphael Mollc639c782011-06-20 17:25:01 -0700181 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
182 # due to "C:\Program Files" being in the path.
183
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700184 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700185 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700186 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
187 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700188 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700189 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800190 # strip leading ':', if any
191 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500192 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700193
194 # and in with the new
Christopher Ferris55257d22017-03-23 11:08:58 -0700195 local prebuiltdir=$(getprebuilt)
196 local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700197
Ben Cheng8bc4c432012-11-16 13:29:13 -0800198 # defined in core/config.mk
Christopher Ferris55257d22017-03-23 11:08:58 -0700199 local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
200 local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800201 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800202
Raphael Mollc639c782011-06-20 17:25:01 -0700203 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800204 export ANDROID_TOOLCHAIN=
205 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200206 local ARCH=$(get_build_var TARGET_ARCH)
Christopher Ferris55257d22017-03-23 11:08:58 -0700207 local toolchaindir toolchaindir2=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200208 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400209 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700210 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400211 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
212 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800213 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200214 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800215 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700216 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700217 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700218 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000219 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200220 *)
221 echo "Can't find toolchain for unknown architecture: $ARCH"
222 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700223 ;;
224 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700225 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800226 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700227 fi
Raphael732936d2011-06-22 14:35:32 -0700228
Christopher Ferris55257d22017-03-23 11:08:58 -0700229 if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800230 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
231 fi
232
Jeff Vander Stoep5f50f052015-06-12 09:56:39 -0700233 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang750396d2015-09-14 19:32:50 -0700234 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 +0200235
236 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
237 # to ensure that the corresponding 'emulator' binaries are used.
238 case $(uname -s) in
239 Darwin)
240 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
241 ;;
242 Linux)
243 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
244 ;;
245 *)
246 ANDROID_EMULATOR_PREBUILTS=
247 ;;
248 esac
249 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700250 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200251 export ANDROID_EMULATOR_PREBUILTS
252 fi
253
Ying Wangaa1c9b52012-11-26 20:51:59 -0800254 export PATH=$ANDROID_BUILD_PATHS$PATH
Dan Albertf5caa3d2015-09-18 13:23:56 -0700255 export PYTHONPATH=$T/development/python-packages:$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800256
Colin Crosse97e6932017-06-30 16:01:45 -0700257 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
258 export JAVA_HOME=$ANDROID_JAVA_HOME
259 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
260 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
261 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500262
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800263 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700264 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
265 export OUT=$ANDROID_PRODUCT_OUT
266
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700267 unset ANDROID_HOST_OUT
268 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
269
Simran Basidd050ed2017-02-13 13:46:48 -0800270 unset ANDROID_HOST_OUT_TESTCASES
271 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
272
273 unset ANDROID_TARGET_OUT_TESTCASES
274 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
275
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800276 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700277 # TODO: fix the path
278 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
279}
280
281function printconfig()
282{
Christopher Ferris55257d22017-03-23 11:08:58 -0700283 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800284 if [ ! "$T" ]; then
285 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
286 return
287 fi
288 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700289}
290
291function set_stuff_for_environment()
292{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800293 settitle
294 setpaths
295 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700296
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800297 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700298 # With this environment variable new GCC can apply colors to warnings/errors
299 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 -0700300 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700301}
302
303function set_sequence_number()
304{
Colin Cross88737132017-03-21 17:41:03 -0700305 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700306}
307
308function settitle()
309{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800310 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700311 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700312 local product=$TARGET_PRODUCT
313 local variant=$TARGET_BUILD_VARIANT
314 local apps=$TARGET_BUILD_APPS
315 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700316 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700317 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700318 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700319 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800320 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321}
322
Kenny Root52aa81c2011-07-15 11:07:06 -0700323function addcompletions()
324{
325 local T dir f
326
327 # Keep us from trying to run in something that isn't bash.
328 if [ -z "${BASH_VERSION}" ]; then
329 return
330 fi
331
332 # Keep us from trying to run in bash that's too old.
333 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
334 return
335 fi
336
337 dir="sdk/bash_completion"
338 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700339 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700340 echo "including $f"
341 . $f
342 done
343 fi
344}
345
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346function choosetype()
347{
348 echo "Build type choices are:"
349 echo " 1. release"
350 echo " 2. debug"
351 echo
352
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800353 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700354 DEFAULT_NUM=1
355 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700356
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800357 export TARGET_BUILD_TYPE=
358 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700359 while [ -z $TARGET_BUILD_TYPE ]
360 do
361 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800362 if [ -z "$1" ] ; then
363 read ANSWER
364 else
365 echo $1
366 ANSWER=$1
367 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700368 case $ANSWER in
369 "")
370 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
371 ;;
372 1)
373 export TARGET_BUILD_TYPE=release
374 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800375 release)
376 export TARGET_BUILD_TYPE=release
377 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700378 2)
379 export TARGET_BUILD_TYPE=debug
380 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800381 debug)
382 export TARGET_BUILD_TYPE=debug
383 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700384 *)
385 echo
386 echo "I didn't understand your response. Please try again."
387 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700388 ;;
389 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800390 if [ -n "$1" ] ; then
391 break
392 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700393 done
394
Ying Wang08800fd2016-03-03 20:57:21 -0800395 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700396 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800397 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700398}
399
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800400#
401# This function isn't really right: It chooses a TARGET_PRODUCT
402# based on the list of boards. Usually, that gets you something
403# that kinda works with a generic product, but really, you should
404# pick a product by name.
405#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700406function chooseproduct()
407{
Christopher Ferris55257d22017-03-23 11:08:58 -0700408 local default_value
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700409 if [ "x$TARGET_PRODUCT" != x ] ; then
410 default_value=$TARGET_PRODUCT
411 else
Ying Wang0a76df52015-06-08 11:57:26 -0700412 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700413 fi
414
Ying Wang08800fd2016-03-03 20:57:21 -0800415 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800416 export TARGET_PRODUCT=
417 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700418 while [ -z "$TARGET_PRODUCT" ]
419 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700420 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800421 if [ -z "$1" ] ; then
422 read ANSWER
423 else
424 echo $1
425 ANSWER=$1
426 fi
427
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700428 if [ -z "$ANSWER" ] ; then
429 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800430 else
431 if check_product $ANSWER
432 then
433 export TARGET_PRODUCT=$ANSWER
434 else
435 echo "** Not a valid product: $ANSWER"
436 fi
437 fi
438 if [ -n "$1" ] ; then
439 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700440 fi
441 done
442
Ying Wang08800fd2016-03-03 20:57:21 -0800443 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800445 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446}
447
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800448function choosevariant()
449{
450 echo "Variant choices are:"
451 local index=1
452 local v
453 for v in ${VARIANT_CHOICES[@]}
454 do
455 # The product name is the name of the directory containing
456 # the makefile we found, above.
457 echo " $index. $v"
458 index=$(($index+1))
459 done
460
461 local default_value=eng
462 local ANSWER
463
464 export TARGET_BUILD_VARIANT=
465 while [ -z "$TARGET_BUILD_VARIANT" ]
466 do
467 echo -n "Which would you like? [$default_value] "
468 if [ -z "$1" ] ; then
469 read ANSWER
470 else
471 echo $1
472 ANSWER=$1
473 fi
474
475 if [ -z "$ANSWER" ] ; then
476 export TARGET_BUILD_VARIANT=$default_value
477 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
478 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800479 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480 fi
481 else
482 if check_variant $ANSWER
483 then
484 export TARGET_BUILD_VARIANT=$ANSWER
485 else
486 echo "** Not a valid variant: $ANSWER"
487 fi
488 fi
489 if [ -n "$1" ] ; then
490 break
491 fi
492 done
493}
494
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700495function choosecombo()
496{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700497 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700498
499 echo
500 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700501 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700502
503 echo
504 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700505 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506
507 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800508 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700509 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800510 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800511 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700512}
513
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800514# Clear this variable. It will be built up again when the vendorsetup.sh
515# files are included at the end of this file.
516unset LUNCH_MENU_CHOICES
517function add_lunch_combo()
518{
519 local new_combo=$1
520 local c
521 for c in ${LUNCH_MENU_CHOICES[@]} ; do
522 if [ "$new_combo" = "$c" ] ; then
523 return
524 fi
525 done
526 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
527}
528
529# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700530add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800531add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000532add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800533add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000534add_lunch_combo aosp_x86-eng
535add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800536
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700537function print_lunch_menu()
538{
539 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700540 echo
541 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700542 echo
543 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800544
545 local i=1
546 local choice
547 for choice in ${LUNCH_MENU_CHOICES[@]}
548 do
549 echo " $i. $choice"
550 i=$(($i+1))
551 done
552
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700553 echo
554}
555
556function lunch()
557{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800558 local answer
559
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700560 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800561 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700562 else
563 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700564 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800565 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700566 fi
567
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800568 local selection=
569
570 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700571 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700572 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800573 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
574 then
575 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
576 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800577 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800578 fi
Colin Cross88737132017-03-21 17:41:03 -0700579 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800580 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581 fi
582
Joe Onoratoda12daf2010-06-09 18:18:31 -0700583 export TARGET_BUILD_APPS=
584
Colin Cross88737132017-03-21 17:41:03 -0700585 local product variant_and_version variant version
586
587 product=${selection%%-*} # Trim everything after first dash
588 variant_and_version=${selection#*-} # Trim everything up to first dash
589 if [ "$variant_and_version" != "$selection" ]; then
590 variant=${variant_and_version%%-*}
591 if [ "$variant" != "$variant_and_version" ]; then
592 version=${variant_and_version#*-}
593 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700594 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800595
Colin Cross88737132017-03-21 17:41:03 -0700596 if [ -z "$product" ]
Ying Wang08800fd2016-03-03 20:57:21 -0800597 then
598 echo
Colin Cross88737132017-03-21 17:41:03 -0700599 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700600 return 1
601 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800602
Colin Cross88737132017-03-21 17:41:03 -0700603 TARGET_PRODUCT=$product \
604 TARGET_BUILD_VARIANT=$variant \
605 TARGET_PLATFORM_VERSION=$version \
606 build_build_var_cache
607 if [ $? -ne 0 ]
608 then
609 return 1
610 fi
611
612 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
613 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Cross1c1e1422017-05-01 14:21:28 -0700614 if [ -n "$version" ]; then
615 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
616 else
617 unset TARGET_PLATFORM_VERSION
618 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700619 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700620
621 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800622
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700623 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800624 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800625 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700626}
627
Jeff Davidson513d7a42010-08-02 10:00:44 -0700628# Tab completion for lunch.
629function _lunch()
630{
631 local cur prev opts
632 COMPREPLY=()
633 cur="${COMP_WORDS[COMP_CWORD]}"
634 prev="${COMP_WORDS[COMP_CWORD-1]}"
635
636 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
637 return 0
638}
639complete -F _lunch lunch
640
Joe Onoratoda12daf2010-06-09 18:18:31 -0700641# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700642# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700643function tapas()
644{
Ying Wangb541ab62014-05-29 17:57:40 -0700645 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 -0700646 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700647 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
648 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 -0700649
Ying Wang67f02922012-08-22 10:25:20 -0700650 if [ $(echo $arch | wc -w) -gt 1 ]; then
651 echo "tapas: Error: Multiple build archs supplied: $arch"
652 return
653 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700654 if [ $(echo $variant | wc -w) -gt 1 ]; then
655 echo "tapas: Error: Multiple build variants supplied: $variant"
656 return
657 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700658 if [ $(echo $density | wc -w) -gt 1 ]; then
659 echo "tapas: Error: Multiple densities supplied: $density"
660 return
661 fi
Ying Wang67f02922012-08-22 10:25:20 -0700662
Ying Wang0a76df52015-06-08 11:57:26 -0700663 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700664 case $arch in
Ying Wang0a76df52015-06-08 11:57:26 -0700665 x86) product=aosp_x86;;
666 mips) product=aosp_mips;;
Ying Wangb541ab62014-05-29 17:57:40 -0700667 armv5) product=generic_armv5;;
668 arm64) product=aosp_arm64;;
669 x86_64) product=aosp_x86_64;;
670 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700671 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700672 if [ -z "$variant" ]; then
673 variant=eng
674 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700675 if [ -z "$apps" ]; then
676 apps=all
677 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600678 if [ -z "$density" ]; then
679 density=alldpi
680 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700681
Ying Wang67f02922012-08-22 10:25:20 -0700682 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700683 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700684 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700685 export TARGET_BUILD_TYPE=release
686 export TARGET_BUILD_APPS=$apps
687
Ying Wang08800fd2016-03-03 20:57:21 -0800688 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700689 set_stuff_for_environment
690 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800691 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700692}
693
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700694function gettop
695{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800696 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700697 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700698 # The following circumlocution ensures we remove symlinks from TOP.
699 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700700 else
701 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800702 # The following circumlocution (repeated below as well) ensures
703 # that we record the true directory name and not one that is
704 # faked up with symlink names.
705 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700706 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800707 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700708 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700709 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800710 \cd ..
synergyb112a402013-07-05 19:47:47 -0700711 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700712 done
Ying Wang9cd17642012-12-13 10:52:07 -0800713 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700714 if [ -f "$T/$TOPFILE" ]; then
715 echo $T
716 fi
717 fi
718 fi
719}
720
Andrew Hsieh906cb782013-09-10 17:37:14 +0800721# Return driver for "make", if any (eg. static analyzer)
722function getdriver()
723{
724 local T="$1"
725 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
726 if [ -n "$WITH_STATIC_ANALYZER" ]; then
Chih-Hung Hsieh42d5c292016-02-24 16:42:15 -0800727 # Use scan-build to collect all static analyzer reports into directory
728 # /tmp/scan-build-yyyy-mm-dd-hhmmss-*
729 # The clang compiler passed by --use-analyzer here is not important.
730 # build/core/binary.mk will set CLANG_CXX and CLANG before calling
731 # c++-analyzer and ccc-analyzer.
732 local CLANG_VERSION=$(get_build_var LLVM_PREBUILTS_VERSION)
733 local BUILD_OS=$(get_build_var BUILD_OS)
734 local CLANG_DIR="$T/prebuilts/clang/host/${BUILD_OS}-x86/${CLANG_VERSION}"
Andrew Hsieh906cb782013-09-10 17:37:14 +0800735 echo "\
Chih-Hung Hsieh42d5c292016-02-24 16:42:15 -0800736${CLANG_DIR}/tools/scan-build/bin/scan-build \
737--use-analyzer ${CLANG_DIR}/bin/clang \
738--status-bugs"
Andrew Hsieh906cb782013-09-10 17:37:14 +0800739 fi
740}
741
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700742function m()
743{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800744 local T=$(gettop)
745 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700746 if [ "$T" ]; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700747 _wrap_build $DRV $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700748 else
749 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700750 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700751 fi
752}
753
754function findmakefile()
755{
Christopher Ferris55257d22017-03-23 11:08:58 -0700756 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800757 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700758 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700759 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700760 T=`PWD= /bin/pwd`
Colin Cross86425252016-05-26 15:32:15 -0700761 if [ -f "$T/Android.mk" -o -f "$T/Android.bp" ]; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700762 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800763 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700764 return
765 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800766 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700767 done
Ying Wang9cd17642012-12-13 10:52:07 -0800768 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700769}
770
771function mm()
772{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800773 local T=$(gettop)
774 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700775 # If we're sitting in the root of the build tree, just do a
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700776 # normal build.
777 if [ -f build/soong/soong_ui.bash ]; then
778 _wrap_build $DRV $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779 else
780 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800781 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700782 local MODULES=
783 local GET_INSTALL_PATH=
784 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700785 # Remove the path to top as the makefilepath needs to be relative
786 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700787 if [ ! "$T" ]; then
788 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700789 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700790 elif [ ! "$M" ]; then
791 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700792 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793 else
Christopher Ferris55257d22017-03-23 11:08:58 -0700794 local ARG
Ying Wanga7deb082013-08-16 13:24:47 -0700795 for ARG in $@; do
796 case $ARG in
797 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
798 esac
799 done
800 if [ -n "$GET_INSTALL_PATH" ]; then
801 MODULES=
Dan Willemsen53e38992016-08-11 17:20:33 -0700802 ARGS=GET-INSTALL-PATH-IN-$(dirname ${M})
803 ARGS=${ARGS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700804 else
Colin Cross86425252016-05-26 15:32:15 -0700805 MODULES=MODULES-IN-$(dirname ${M})
806 # Convert "/" to "-".
807 MODULES=${MODULES//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700808 ARGS=$@
809 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700810 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
811 MODULES=tidy_only
812 fi
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700813 ONE_SHOT_MAKEFILE=$M _wrap_build $DRV $T/build/soong/soong_ui.bash --make-mode $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700814 fi
815 fi
816}
817
818function mmm()
819{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800820 local T=$(gettop)
821 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700822 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800823 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800824 local MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700825 local MODULES_IN_PATHS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800826 local ARGS=
827 local DIR TO_CHOP
Colin Cross86425252016-05-26 15:32:15 -0700828 local DIR_MODULES
Ying Wanga7deb082013-08-16 13:24:47 -0700829 local GET_INSTALL_PATH=
Dan Willemsen53e38992016-08-11 17:20:33 -0700830 local GET_INSTALL_PATHS=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800831 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
832 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
833 for DIR in $DIRS ; do
Colin Cross86425252016-05-26 15:32:15 -0700834 DIR_MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
Alon Albert68895a92011-11-30 12:40:19 -0800835 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
Colin Cross86425252016-05-26 15:32:15 -0700836 # Remove the leading ./ and trailing / if any exists.
837 DIR=${DIR#./}
838 DIR=${DIR%/}
839 if [ -f $DIR/Android.mk -o -f $DIR/Android.bp ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700840 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
841 local TO_CHOP=`expr $TO_CHOP + 1`
842 local START=`PWD= /bin/pwd`
Colin Cross4bfae062016-08-31 17:22:36 -0700843 local MDIR=`echo $START | cut -c${TO_CHOP}-`
844 if [ "$MDIR" = "" ] ; then
845 MDIR=$DIR
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700846 else
Colin Cross4bfae062016-08-31 17:22:36 -0700847 MDIR=$MDIR/$DIR
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700848 fi
Colin Cross4bfae062016-08-31 17:22:36 -0700849 MDIR=${MDIR%/.}
850 if [ "$DIR_MODULES" = "" ]; then
851 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$MDIR"
852 GET_INSTALL_PATHS="$GET_INSTALL_PATHS GET-INSTALL-PATH-IN-$MDIR"
853 else
854 MODULES="$MODULES $DIR_MODULES"
855 fi
856 MAKEFILE="$MAKEFILE $MDIR/Android.mk"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700857 else
Ying Wanga7deb082013-08-16 13:24:47 -0700858 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700859 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700860 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
Abhinav1997a72a6e72015-10-18 20:25:48 +0200861 *) if [ -d $DIR ]; then
862 echo "No Android.mk in $DIR.";
863 else
864 echo "Couldn't locate the directory $DIR";
865 fi
866 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700867 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700868 fi
869 done
Ying Wanga7deb082013-08-16 13:24:47 -0700870 if [ -n "$GET_INSTALL_PATH" ]; then
Dan Willemsen53e38992016-08-11 17:20:33 -0700871 ARGS=${GET_INSTALL_PATHS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700872 MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700873 MODULES_IN_PATHS=
Ying Wanga7deb082013-08-16 13:24:47 -0700874 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700875 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
876 MODULES=tidy_only
Colin Cross86425252016-05-26 15:32:15 -0700877 MODULES_IN_PATHS=
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700878 fi
Colin Cross86425252016-05-26 15:32:15 -0700879 # Convert "/" to "-".
880 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700881 ONE_SHOT_MAKEFILE="$MAKEFILE" _wrap_build $DRV $T/build/soong/soong_ui.bash --make-mode $DASH_ARGS $MODULES $MODULES_IN_PATHS $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700882 else
883 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700884 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700885 fi
886}
887
Ying Wangb607f7b2013-02-08 18:01:04 -0800888function mma()
889{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800890 local T=$(gettop)
891 local DRV=$(getdriver $T)
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700892 if [ -f build/soong/soong_ui.bash ]; then
893 _wrap_build $DRV $T/build/soong/soong_ui.bash --make-mode $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800894 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800895 if [ ! "$T" ]; then
896 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700897 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800898 fi
Colin Cross127fcea2016-09-01 15:30:18 -0700899 local M=$(findmakefile)
900 # Remove the path to top as the makefilepath needs to be relative
901 local M=`echo $M|sed 's:'$T'/::'`
902 local MODULES_IN_PATHS=MODULES-IN-$(dirname ${M})
Ying Wang61cd8842015-09-24 16:19:19 -0700903 # Convert "/" to "-".
904 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700905 _wrap_build $DRV $T/build/soong/soong_ui.bash --make-mode $@ $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800906 fi
907}
908
909function mmma()
910{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800911 local T=$(gettop)
912 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800913 if [ "$T" ]; then
914 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
915 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
916 local MY_PWD=`PWD= /bin/pwd`
917 if [ "$MY_PWD" = "$T" ]; then
918 MY_PWD=
919 else
920 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
921 fi
922 local DIR=
Ying Wangcaeaa082015-09-23 16:08:55 -0700923 local MODULES_IN_PATHS=
Ying Wangb607f7b2013-02-08 18:01:04 -0800924 local ARGS=
925 for DIR in $DIRS ; do
926 if [ -d $DIR ]; then
Ying Wangcaeaa082015-09-23 16:08:55 -0700927 # Remove the leading ./ and trailing / if any exists.
928 DIR=${DIR#./}
929 DIR=${DIR%/}
930 if [ "$MY_PWD" != "" ]; then
931 DIR=$MY_PWD/$DIR
Ying Wangb607f7b2013-02-08 18:01:04 -0800932 fi
Ying Wang61cd8842015-09-24 16:19:19 -0700933 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
Ying Wangb607f7b2013-02-08 18:01:04 -0800934 else
935 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700936 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800937 *) echo "Couldn't find directory $DIR"; return 1;;
938 esac
939 fi
940 done
Ying Wang61cd8842015-09-24 16:19:19 -0700941 # Convert "/" to "-".
942 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700943 _wrap_build $DRV $T/build/soong/soong_ui.bash --make-mode $DASH_ARGS $ARGS $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800944 else
945 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700946 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800947 fi
948}
949
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700950function croot()
951{
Christopher Ferris55257d22017-03-23 11:08:58 -0700952 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700953 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700954 if [ "$1" ]; then
955 \cd $(gettop)/$1
956 else
957 \cd $(gettop)
958 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700959 else
960 echo "Couldn't locate the top of the tree. Try setting TOP."
961 fi
962}
963
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700964function cproj()
965{
Christopher Ferris55257d22017-03-23 11:08:58 -0700966 local TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700967 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700968 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700969 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
970 T=$PWD
971 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800972 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700973 return
974 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800975 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700976 done
Ying Wang9cd17642012-12-13 10:52:07 -0800977 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700978 echo "can't find Android.mk"
979}
980
Daniel Sandler47e0a882013-07-30 13:23:52 -0400981# simplified version of ps; output in the form
982# <pid> <procname>
983function qpid() {
984 local prepend=''
985 local append=''
986 if [ "$1" = "--exact" ]; then
987 prepend=' '
988 append='$'
989 shift
990 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -0800991 echo "usage: qpid [[--exact] <process name|pid>"
992 return 255
993 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -0400994
995 local EXE="$1"
996 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -0800997 qpid | \grep "$prepend$EXE$append"
998 else
999 adb shell ps \
1000 | tr -d '\r' \
1001 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1002 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001003}
1004
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001005function pid()
1006{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001007 local prepend=''
1008 local append=''
1009 if [ "$1" = "--exact" ]; then
1010 prepend=' '
1011 append='$'
1012 shift
1013 fi
1014 local EXE="$1"
1015 if [ "$EXE" ] ; then
1016 local PID=`adb shell ps \
1017 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001018 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001019 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1020 echo "$PID"
1021 else
1022 echo "usage: pid [--exact] <process name>"
Ying Wang08800fd2016-03-03 20:57:21 -08001023 return 255
Daniel Sandler47e0a882013-07-30 13:23:52 -04001024 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001025}
1026
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001027# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001028# that has the core-file-size limit set correctly
1029#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001030# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001031# if its core-file-size limit is not set already.
1032# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1033
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001034function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001035{
Ying Wang08800fd2016-03-03 20:57:21 -08001036 echo "Getting root...";
1037 adb root;
1038 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001039
Ying Wang08800fd2016-03-03 20:57:21 -08001040 echo "Remounting root partition read-write...";
1041 adb shell mount -w -o remount -t rootfs rootfs;
1042 sleep 1;
1043 adb wait-for-device;
1044 adb shell mkdir -p /cores;
1045 adb shell mount -t tmpfs tmpfs /cores;
1046 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001047
Ying Wang08800fd2016-03-03 20:57:21 -08001048 echo "Granting SELinux permission to dump in /cores...";
1049 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001050
Ying Wang08800fd2016-03-03 20:57:21 -08001051 echo "Set core pattern.";
1052 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001053
Ying Wang08800fd2016-03-03 20:57:21 -08001054 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001055}
1056
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001057# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001058# $1 = PID of process (e.g., $(pid mediaserver))
1059#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001060# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001061# dump to actually be generated.
1062
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001063function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001064{
Ying Wang08800fd2016-03-03 20:57:21 -08001065 local PID=$1;
1066 if [ -z "$PID" ]; then
1067 printf "Expecting a PID!\n";
1068 return;
1069 fi;
1070 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001071 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001072}
1073
1074# core - send SIGV and pull the core for process
1075# $1 = PID of process (e.g., $(pid mediaserver))
1076#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001077# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001078# enabled globally.
1079
1080function core()
1081{
Ying Wang08800fd2016-03-03 20:57:21 -08001082 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001083
Ying Wang08800fd2016-03-03 20:57:21 -08001084 if [ -z "$PID" ]; then
1085 printf "Expecting a PID!\n";
1086 return;
1087 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001088
Ying Wang08800fd2016-03-03 20:57:21 -08001089 local CORENAME=core.$PID;
1090 local COREPATH=/cores/$CORENAME;
1091 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001092
Ying Wang08800fd2016-03-03 20:57:21 -08001093 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001094
Ying Wang08800fd2016-03-03 20:57:21 -08001095 local done=0;
1096 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1097 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1098 adb shell kill -$SIG $PID;
1099 sleep 1;
1100 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001101
Ying Wang08800fd2016-03-03 20:57:21 -08001102 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1103 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001104}
1105
Christopher Tate744ee802009-11-12 15:33:08 -08001106# systemstack - dump the current stack trace of all threads in the system process
1107# to the usual ANR traces file
1108function systemstack()
1109{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001110 stacks system_server
1111}
1112
1113function stacks()
1114{
1115 if [[ $1 =~ ^[0-9]+$ ]] ; then
1116 local PID="$1"
1117 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001118 local PIDLIST="$(pid $1)"
1119 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1120 local PID="$PIDLIST"
1121 elif [ "$PIDLIST" ] ; then
1122 echo "more than one process: $1"
1123 else
1124 echo "no such process: $1"
1125 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001126 else
1127 echo "usage: stacks [pid|process name]"
1128 fi
1129
1130 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001131 # Determine whether the process is native
1132 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1133 # Dump stacks of Dalvik process
1134 local TRACES=/data/anr/traces.txt
1135 local ORIG=/data/anr/traces.orig
1136 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001137
Jeff Brownb12c2e52013-08-19 15:14:16 -07001138 # Keep original traces to avoid clobbering
1139 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001140
Jeff Brownb12c2e52013-08-19 15:14:16 -07001141 # Make sure we have a usable file
1142 adb shell touch $TRACES
1143 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001144
Jeff Brownb12c2e52013-08-19 15:14:16 -07001145 # Dump stacks and wait for dump to finish
1146 adb shell kill -3 $PID
1147 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001148
Jeff Brownb12c2e52013-08-19 15:14:16 -07001149 # Restore original stacks, and show current output
1150 adb shell mv $TRACES $TMP
1151 adb shell mv $ORIG $TRACES
1152 adb shell cat $TMP
1153 else
1154 # Dump stacks of native process
Josh Gao310b6ff2017-03-01 11:29:59 -08001155 adb shell debuggerd -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001156 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001157 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001158}
1159
Michael Wrightaeed7212014-06-19 19:58:12 -07001160# Read the ELF header from /proc/$PID/exe to determine if the process is
1161# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001162function is64bit()
1163{
1164 local PID="$1"
1165 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001166 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001167 echo "64"
1168 else
1169 echo ""
1170 fi
1171 else
1172 echo ""
1173 fi
1174}
1175
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001176case `uname -s` in
1177 Darwin)
1178 function sgrep()
1179 {
Keun Soo Yim3d484752016-02-19 11:06:58 -08001180 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl|vts)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001181 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001182 }
1183
1184 ;;
1185 *)
1186 function sgrep()
1187 {
Keun Soo Yim3d484752016-02-19 11:06:58 -08001188 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001189 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001190 }
1191 ;;
1192esac
1193
Raghu Gandham8da43102012-07-25 19:57:22 -07001194function gettargetarch
1195{
1196 get_build_var TARGET_ARCH
1197}
1198
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001199function ggrep()
1200{
Mike Frysinger5e479732015-09-22 18:13:48 -04001201 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1202 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001203}
1204
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001205function jgrep()
1206{
Mike Frysinger5e479732015-09-22 18:13:48 -04001207 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1208 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001209}
1210
1211function cgrep()
1212{
Mike Frysinger5e479732015-09-22 18:13:48 -04001213 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' \) \
1214 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001215}
1216
1217function resgrep()
1218{
Christopher Ferris55257d22017-03-23 11:08:58 -07001219 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001220 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1221 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1222 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001223}
1224
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001225function mangrep()
1226{
Mike Frysinger5e479732015-09-22 18:13:48 -04001227 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1228 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001229}
1230
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001231function sepgrep()
1232{
Mike Frysinger5e479732015-09-22 18:13:48 -04001233 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1234 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001235}
1236
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001237function rcgrep()
1238{
Mike Frysinger5e479732015-09-22 18:13:48 -04001239 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1240 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001241}
1242
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001243case `uname -s` in
1244 Darwin)
1245 function mgrep()
1246 {
David Grossd1d6fc52017-05-10 10:49:44 -07001247 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regex '(.*/)?soong/[^/]*.go' \) -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001248 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001249 }
1250
1251 function treegrep()
1252 {
Mike Frysinger5e479732015-09-22 18:13:48 -04001253 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' \
1254 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001255 }
1256
1257 ;;
1258 *)
1259 function mgrep()
1260 {
David Grossd1d6fc52017-05-10 10:49:44 -07001261 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regextype posix-extended -regex '(.*/)?soong/[^/]*.go' \) -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001262 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001263 }
1264
1265 function treegrep()
1266 {
Mike Frysinger5e479732015-09-22 18:13:48 -04001267 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f \
1268 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001269 }
1270
1271 ;;
1272esac
1273
1274function getprebuilt
1275{
1276 get_abs_build_var ANDROID_PREBUILTS
1277}
1278
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001279function tracedmdump()
1280{
Christopher Ferris55257d22017-03-23 11:08:58 -07001281 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001282 if [ ! "$T" ]; then
1283 echo "Couldn't locate the top of the tree. Try setting TOP."
1284 return
1285 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001286 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001287 local arch=$(gettargetarch)
1288 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001289
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001290 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001291 if [ ! "$TRACE" ] ; then
1292 echo "usage: tracedmdump tracename"
1293 return
1294 fi
1295
Jack Veenstra60116fc2009-04-09 18:12:34 -07001296 if [ ! -r "$KERNEL" ] ; then
1297 echo "Error: cannot find kernel: '$KERNEL'"
1298 return
1299 fi
1300
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001301 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001302 if [ "$BASETRACE" = "$TRACE" ] ; then
1303 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1304 fi
1305
1306 echo "post-processing traces..."
1307 rm -f $TRACE/qtrace.dexlist
1308 post_trace $TRACE
1309 if [ $? -ne 0 ]; then
1310 echo "***"
1311 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1312 echo "***"
1313 return
1314 fi
1315 echo "generating dexlist output..."
1316 /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
1317 echo "generating dmtrace data..."
1318 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1319 echo "generating html file..."
1320 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1321 echo "done, see $TRACE/dmtrace.html for details"
1322 echo "or run:"
1323 echo " traceview $TRACE/dmtrace"
1324}
1325
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001326# communicate with a running device or emulator, set up necessary state,
1327# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001328function runhat()
1329{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001330 # process standard adb options
1331 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001332 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001333 adbTarget=$1
1334 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001335 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001336 adbTarget="$1 $2"
1337 shift 2
1338 fi
1339 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001340 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001341
1342 # runhat options
1343 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001344
1345 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001346 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001347 return
1348 fi
1349
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001350 # confirm hat is available
1351 if [ -z $(which hat) ]; then
1352 echo "hat is not available in this configuration."
1353 return
1354 fi
1355
Andy McFaddenb6289852010-07-12 08:00:19 -07001356 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001357 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001358 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001359 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001360 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001361 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001362 echo -n "> "
1363 read
1364
The Android Open Source Project88b60792009-03-03 19:28:42 -08001365 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001366
The Android Open Source Project88b60792009-03-03 19:28:42 -08001367 echo "Retrieving file $devFile..."
1368 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001369
The Android Open Source Project88b60792009-03-03 19:28:42 -08001370 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001371
The Android Open Source Project88b60792009-03-03 19:28:42 -08001372 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001373 echo "View the output by pointing your browser at http://localhost:7000/"
1374 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001375 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001376}
1377
1378function getbugreports()
1379{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001380 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001381
1382 if [ ! "$reports" ]; then
1383 echo "Could not locate any bugreports."
1384 return
1385 fi
1386
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001387 local report
1388 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001389 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001390 echo "/sdcard/bugreports/${report}"
1391 adb pull /sdcard/bugreports/${report} ${report}
1392 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001393 done
1394}
1395
Victoria Lease1b296b42012-08-21 15:44:06 -07001396function getsdcardpath()
1397{
1398 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1399}
1400
1401function getscreenshotpath()
1402{
1403 echo "$(getsdcardpath)/Pictures/Screenshots"
1404}
1405
1406function getlastscreenshot()
1407{
1408 local screenshot_path=$(getscreenshotpath)
1409 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1410 if [ "$screenshot" = "" ]; then
1411 echo "No screenshots found."
1412 return
1413 fi
1414 echo "${screenshot}"
1415 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1416}
1417
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001418function startviewserver()
1419{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001420 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001421 if [ $# -gt 0 ]; then
1422 port=$1
1423 fi
1424 adb shell service call window 1 i32 $port
1425}
1426
1427function stopviewserver()
1428{
1429 adb shell service call window 2
1430}
1431
1432function isviewserverstarted()
1433{
1434 adb shell service call window 3
1435}
1436
Romain Guyb84049a2010-10-04 16:56:11 -07001437function key_home()
1438{
1439 adb shell input keyevent 3
1440}
1441
1442function key_back()
1443{
1444 adb shell input keyevent 4
1445}
1446
1447function key_menu()
1448{
1449 adb shell input keyevent 82
1450}
1451
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001452function smoketest()
1453{
1454 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1455 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1456 return
1457 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001458 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001459 if [ ! "$T" ]; then
1460 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1461 return
1462 fi
1463
Ying Wang9cd17642012-12-13 10:52:07 -08001464 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001465 adb uninstall com.android.smoketest > /dev/null &&
1466 adb uninstall com.android.smoketest.tests > /dev/null &&
1467 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1468 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1469 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1470}
1471
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001472# simple shortcut to the runtest command
1473function runtest()
1474{
Christopher Ferris55257d22017-03-23 11:08:58 -07001475 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001476 if [ ! "$T" ]; then
1477 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1478 return
1479 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001480 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001481}
1482
The Android Open Source Project88b60792009-03-03 19:28:42 -08001483function godir () {
1484 if [[ -z "$1" ]]; then
1485 echo "Usage: godir <regex>"
1486 return
1487 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001488 local T=$(gettop)
1489 local FILELIST
Brian Carlstromf2257422015-09-30 20:28:54 -07001490 if [ ! "$OUT_DIR" = "" ]; then
1491 mkdir -p $OUT_DIR
1492 FILELIST=$OUT_DIR/filelist
1493 else
1494 FILELIST=$T/filelist
1495 fi
1496 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001497 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001498 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001499 echo " Done"
1500 echo ""
1501 fi
1502 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001503 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001504 if [[ ${#lines[@]} = 0 ]]; then
1505 echo "Not found"
1506 return
1507 fi
1508 local pathname
1509 local choice
1510 if [[ ${#lines[@]} > 1 ]]; then
1511 while [[ -z "$pathname" ]]; do
1512 local index=1
1513 local line
1514 for line in ${lines[@]}; do
1515 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001516 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001517 done
1518 echo
1519 echo -n "Select one: "
1520 unset choice
1521 read choice
1522 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1523 echo "Invalid choice"
1524 continue
1525 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001526 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001527 done
1528 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001529 pathname=${lines[0]}
1530 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001531 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001532}
1533
Alex Rayf0d08eb2013-03-08 15:15:06 -08001534# Print colored exit condition
1535function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001536 "$@"
1537 local retval=$?
1538 if [ $retval -ne 0 ]
1539 then
Jacky Cao89483b82015-05-15 22:12:53 +08001540 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001541 else
Jacky Cao89483b82015-05-15 22:12:53 +08001542 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001543 fi
1544 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001545}
1546
Ying Wanged21d4c2014-08-24 22:14:19 -07001547function get_make_command()
1548{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001549 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1550 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001551 # Always use the real make if -C is passed in
1552 for arg in "$@"; do
1553 if [[ $arg == -C* ]]; then
1554 echo command make
1555 return
1556 fi
1557 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001558 echo build/soong/soong_ui.bash --make-mode
1559 else
1560 echo command make
1561 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001562}
1563
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001564function _wrap_build()
Ed Heylcc6be0a2014-06-18 14:55:58 -07001565{
1566 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001567 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001568 local ret=$?
1569 local end_time=$(date +"%s")
1570 local tdiff=$(($end_time-$start_time))
1571 local hours=$(($tdiff / 3600 ))
1572 local mins=$((($tdiff % 3600) / 60))
1573 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001574 local ncolors=$(tput colors 2>/dev/null)
1575 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001576 color_failed=$'\E'"[0;31m"
1577 color_success=$'\E'"[0;32m"
1578 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001579 else
1580 color_failed=""
1581 color_success=""
1582 color_reset=""
1583 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001584 echo
1585 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001586 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001587 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001588 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001589 fi
1590 if [ $hours -gt 0 ] ; then
1591 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1592 elif [ $mins -gt 0 ] ; then
1593 printf "(%02g:%02g (mm:ss))" $mins $secs
1594 elif [ $secs -gt 0 ] ; then
1595 printf "(%s seconds)" $secs
1596 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001597 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001598 echo
1599 return $ret
1600}
1601
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001602function make()
1603{
Dan Willemsene9842242017-07-28 13:00:13 -07001604 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001605}
1606
David Zeuthen1b126ff2015-09-30 17:10:48 -04001607function provision()
1608{
1609 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1610 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1611 return 1
1612 fi
1613 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1614 echo "There is no provisioning script for the device." >&2
1615 return 1
1616 fi
1617
1618 # Check if user really wants to do this.
1619 if [ "$1" = "--no-confirmation" ]; then
1620 shift 1
1621 else
1622 echo "This action will reflash your device."
1623 echo ""
1624 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1625 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001626 echo -n "Are you sure you want to do this (yes/no)? "
1627 read
David Zeuthen1b126ff2015-09-30 17:10:48 -04001628 if [[ "${REPLY}" != "yes" ]] ; then
1629 echo "Not taking any action. Exiting." >&2
1630 return 1
1631 fi
1632 fi
1633 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1634}
1635
Raphael Moll70a86b02011-06-20 16:03:14 -07001636if [ "x$SHELL" != "x/bin/bash" ]; then
1637 case `ps -o command -p $$` in
1638 *bash*)
1639 ;;
1640 *)
1641 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1642 ;;
1643 esac
1644fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001645
1646# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02001647for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
Lee Campbell455f6f42015-08-20 13:55:45 -07001648 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
1649 `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 -08001650do
1651 echo "including $f"
1652 . $f
1653done
1654unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001655
1656addcompletions