blob: 561083d38c191bd47d5f0600ef90c7d16623b898 [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:
Steven Moreland62054a42018-12-06 10:11:40 -08007- lunch: lunch <product_name>-<build_variant>
8 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.
11- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|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.
29- allmod: List all modules.
30- gomod: Go to the directory containing a module.
31- refreshmod: Refresh list of modules for allmod/gomod.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070032
Roland Levillain39341922015-10-20 12:48:19 +010033Environment options:
Dan Albert4ae5d4b2014-10-31 16:23:08 -070034- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
35 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
36 build is leak-check clean.
37
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070038Look at the source to view more functions. The complete list is:
39EOF
Christopher Ferris55257d22017-03-23 11:08:58 -070040 local T=$(gettop)
41 local A=""
42 local i
Jacky Cao89483b82015-05-15 22:12:53 +080043 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 -070044 A="$A $i"
45 done
46 echo $A
47}
48
Ying Wang08800fd2016-03-03 20:57:21 -080049# Get all the build variables needed by this script in a single call to the build system.
50function build_build_var_cache()
51{
Christopher Ferris55257d22017-03-23 11:08:58 -070052 local T=$(gettop)
Ying Wang08800fd2016-03-03 20:57:21 -080053 # Grep out the variable names from the script.
Jim Tanga881a252018-06-19 16:34:41 +080054 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' ' '`)
55 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' ' '`)
Ying Wang08800fd2016-03-03 20:57:21 -080056 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
Steven Moreland05402962018-01-05 12:13:11 -080057 build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
Jim Tanga881a252018-06-19 16:34:41 +080058 --vars="${cached_vars[*]}" \
59 --abs-vars="${cached_abs_vars[*]}" \
Dan Willemsenaf88c412017-07-14 11:29:44 -070060 --var-prefix=var_cache_ \
61 --abs-var-prefix=abs_var_cache_`
Ying Wang08800fd2016-03-03 20:57:21 -080062 local ret=$?
63 if [ $ret -ne 0 ]
64 then
65 unset build_dicts_script
66 return $ret
67 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -070068 # Execute the script to store the "<val>=<value>" pairs as shell variables.
Ying Wang08800fd2016-03-03 20:57:21 -080069 eval "$build_dicts_script"
Ying Wang08800fd2016-03-03 20:57:21 -080070 ret=$?
Ying Wangf0cb3972016-03-04 13:56:23 -080071 unset build_dicts_script
Ying Wang08800fd2016-03-03 20:57:21 -080072 if [ $ret -ne 0 ]
73 then
74 return $ret
75 fi
76 BUILD_VAR_CACHE_READY="true"
77}
78
Ying Wangf0cb3972016-03-04 13:56:23 -080079# Delete the build var cache, so that we can still call into the build system
Ying Wang08800fd2016-03-03 20:57:21 -080080# to get build variables not listed in this script.
81function destroy_build_var_cache()
82{
83 unset BUILD_VAR_CACHE_READY
Christopher Ferris55257d22017-03-23 11:08:58 -070084 local v
Ying Wang08800fd2016-03-03 20:57:21 -080085 for v in $cached_vars; do
86 unset var_cache_$v
87 done
88 unset cached_vars
89 for v in $cached_abs_vars; do
90 unset abs_var_cache_$v
91 done
92 unset cached_abs_vars
93}
94
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070095# Get the value of a build variable as an absolute path.
96function get_abs_build_var()
97{
Ying Wang08800fd2016-03-03 20:57:21 -080098 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
99 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800100 eval "echo \"\${abs_var_cache_$1}\""
Ying Wang08800fd2016-03-03 20:57:21 -0800101 return
102 fi
103
Christopher Ferris55257d22017-03-23 11:08:58 -0700104 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700105 if [ ! "$T" ]; then
106 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
107 return
108 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700109 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --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
Dan Willemsenaf88c412017-07-14 11:29:44 -0700126 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800127}
128
129# check to see if the supplied product is one we can build
130function check_product()
131{
Christopher Ferris55257d22017-03-23 11:08:58 -0700132 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800133 if [ ! "$T" ]; then
134 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
135 return
136 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700137 TARGET_PRODUCT=$1 \
138 TARGET_BUILD_VARIANT= \
139 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700140 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800141 get_build_var TARGET_DEVICE > /dev/null
142 # hide successful answers, but allow the errors to show
143}
144
145VARIANT_CHOICES=(user userdebug eng)
146
147# check to see if the supplied variant is valid
148function check_variant()
149{
Christopher Ferris55257d22017-03-23 11:08:58 -0700150 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800151 for v in ${VARIANT_CHOICES[@]}
152 do
153 if [ "$v" = "$1" ]
154 then
155 return 0
156 fi
157 done
158 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700159}
160
161function setpaths()
162{
Christopher Ferris55257d22017-03-23 11:08:58 -0700163 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700164 if [ ! "$T" ]; then
165 echo "Couldn't locate the top of the tree. Try setting TOP."
166 return
167 fi
168
169 ##################################################################
170 # #
171 # Read me before you modify this code #
172 # #
173 # This function sets ANDROID_BUILD_PATHS to what it is adding #
174 # to PATH, and the next time it is run, it removes that from #
175 # PATH. This is required so lunch can be run more than once #
176 # and still have working paths. #
177 # #
178 ##################################################################
179
Raphael Mollc639c782011-06-20 17:25:01 -0700180 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
181 # due to "C:\Program Files" being in the path.
182
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700183 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700184 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700185 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
186 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700187 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700188 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800189 # strip leading ':', if any
190 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500191 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700192
193 # and in with the new
Christopher Ferris55257d22017-03-23 11:08:58 -0700194 local prebuiltdir=$(getprebuilt)
195 local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700196
Ben Cheng8bc4c432012-11-16 13:29:13 -0800197 # defined in core/config.mk
Christopher Ferris55257d22017-03-23 11:08:58 -0700198 local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
199 local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800200 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800201
Raphael Mollc639c782011-06-20 17:25:01 -0700202 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800203 export ANDROID_TOOLCHAIN=
204 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200205 local ARCH=$(get_build_var TARGET_ARCH)
Christopher Ferris55257d22017-03-23 11:08:58 -0700206 local toolchaindir toolchaindir2=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200207 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400208 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700209 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400210 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
211 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800212 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200213 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800214 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700215 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700216 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700217 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000218 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200219 *)
220 echo "Can't find toolchain for unknown architecture: $ARCH"
221 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700222 ;;
223 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700224 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800225 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700226 fi
Raphael732936d2011-06-22 14:35:32 -0700227
Christopher Ferris55257d22017-03-23 11:08:58 -0700228 if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800229 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
230 fi
231
Jeff Vander Stoep5f50f052015-06-12 09:56:39 -0700232 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Yueyao Zhuefc786a2017-04-07 14:11:54 -0700233
234 # add kernel specific binaries
235 case $(uname -s) in
236 Linux)
237 export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
238 ;;
239 *)
240 ;;
241 esac
242
Torne (Richard Coles)0091bae2017-10-03 16:31:18 -0400243 ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN
244 if [ -n "$ANDROID_TOOLCHAIN_2ND_ARCH" ]; then
245 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH
246 fi
247 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS:
248 export ANDROID_BUILD_PATHS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200249
250 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
251 # to ensure that the corresponding 'emulator' binaries are used.
252 case $(uname -s) in
253 Darwin)
254 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
255 ;;
256 Linux)
257 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
258 ;;
259 *)
260 ANDROID_EMULATOR_PREBUILTS=
261 ;;
262 esac
263 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700264 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200265 export ANDROID_EMULATOR_PREBUILTS
266 fi
267
Ying Wangaa1c9b52012-11-26 20:51:59 -0800268 export PATH=$ANDROID_BUILD_PATHS$PATH
Dan Albertf5caa3d2015-09-18 13:23:56 -0700269 export PYTHONPATH=$T/development/python-packages:$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800270
Colin Crosse97e6932017-06-30 16:01:45 -0700271 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
272 export JAVA_HOME=$ANDROID_JAVA_HOME
273 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
274 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
275 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500276
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800277 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700278 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
279 export OUT=$ANDROID_PRODUCT_OUT
280
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700281 unset ANDROID_HOST_OUT
282 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
283
Simran Basidd050ed2017-02-13 13:46:48 -0800284 unset ANDROID_HOST_OUT_TESTCASES
285 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
286
287 unset ANDROID_TARGET_OUT_TESTCASES
288 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
289
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800290 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700291 # TODO: fix the path
292 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
293}
294
295function printconfig()
296{
Christopher Ferris55257d22017-03-23 11:08:58 -0700297 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800298 if [ ! "$T" ]; then
299 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
300 return
301 fi
302 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700303}
304
305function set_stuff_for_environment()
306{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800307 setpaths
308 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800310 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700311 # With this environment variable new GCC can apply colors to warnings/errors
312 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 -0700313 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700314}
315
316function set_sequence_number()
317{
Colin Cross88737132017-03-21 17:41:03 -0700318 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319}
320
Makoto Onukida971062018-06-18 10:15:19 -0700321# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
322function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800323 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700324 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800325 *:"$cmd":*)
326 return 1
327 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700328 esac
329 return 0
330}
331
Kenny Root52aa81c2011-07-15 11:07:06 -0700332function addcompletions()
333{
334 local T dir f
335
Jim Tanga881a252018-06-19 16:34:41 +0800336 # Keep us from trying to run in something that's neither bash nor zsh.
337 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700338 return
339 fi
340
341 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800342 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700343 return
344 fi
345
Jim Tanga881a252018-06-19 16:34:41 +0800346 local completion_files=(
347 system/core/adb/adb.bash
348 system/core/fastboot/fastboot.bash
349 tools/tradefederation/core/atest/atest_completion.sh
350 )
Makoto Onukida971062018-06-18 10:15:19 -0700351 # Completion can be disabled selectively to allow users to use non-standard completion.
352 # e.g.
353 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
354 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800355 for f in ${completion_files[*]}; do
356 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700357 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700358 fi
359 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700360
Makoto Onukida971062018-06-18 10:15:19 -0700361 if should_add_completion bit ; then
362 complete -C "bit --tab" bit
363 fi
Jim Tanga881a252018-06-19 16:34:41 +0800364 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800365
dimitry73b84812018-12-11 18:06:00 +0100366 complete -F _complete_android_module_names gomod
367 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700368}
369
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700370function choosetype()
371{
372 echo "Build type choices are:"
373 echo " 1. release"
374 echo " 2. debug"
375 echo
376
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800377 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700378 DEFAULT_NUM=1
379 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700380
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800381 export TARGET_BUILD_TYPE=
382 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700383 while [ -z $TARGET_BUILD_TYPE ]
384 do
385 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800386 if [ -z "$1" ] ; then
387 read ANSWER
388 else
389 echo $1
390 ANSWER=$1
391 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700392 case $ANSWER in
393 "")
394 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
395 ;;
396 1)
397 export TARGET_BUILD_TYPE=release
398 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800399 release)
400 export TARGET_BUILD_TYPE=release
401 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700402 2)
403 export TARGET_BUILD_TYPE=debug
404 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800405 debug)
406 export TARGET_BUILD_TYPE=debug
407 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700408 *)
409 echo
410 echo "I didn't understand your response. Please try again."
411 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700412 ;;
413 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800414 if [ -n "$1" ] ; then
415 break
416 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700417 done
418
Ying Wang08800fd2016-03-03 20:57:21 -0800419 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700420 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800421 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700422}
423
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800424#
425# This function isn't really right: It chooses a TARGET_PRODUCT
426# based on the list of boards. Usually, that gets you something
427# that kinda works with a generic product, but really, you should
428# pick a product by name.
429#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700430function chooseproduct()
431{
Christopher Ferris55257d22017-03-23 11:08:58 -0700432 local default_value
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700433 if [ "x$TARGET_PRODUCT" != x ] ; then
434 default_value=$TARGET_PRODUCT
435 else
Ying Wang0a76df52015-06-08 11:57:26 -0700436 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700437 fi
438
Ying Wang08800fd2016-03-03 20:57:21 -0800439 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800440 export TARGET_PRODUCT=
441 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700442 while [ -z "$TARGET_PRODUCT" ]
443 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700444 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800445 if [ -z "$1" ] ; then
446 read ANSWER
447 else
448 echo $1
449 ANSWER=$1
450 fi
451
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700452 if [ -z "$ANSWER" ] ; then
453 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800454 else
455 if check_product $ANSWER
456 then
457 export TARGET_PRODUCT=$ANSWER
458 else
459 echo "** Not a valid product: $ANSWER"
460 fi
461 fi
462 if [ -n "$1" ] ; then
463 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700464 fi
465 done
466
Ying Wang08800fd2016-03-03 20:57:21 -0800467 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800469 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470}
471
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472function choosevariant()
473{
474 echo "Variant choices are:"
475 local index=1
476 local v
477 for v in ${VARIANT_CHOICES[@]}
478 do
479 # The product name is the name of the directory containing
480 # the makefile we found, above.
481 echo " $index. $v"
482 index=$(($index+1))
483 done
484
485 local default_value=eng
486 local ANSWER
487
488 export TARGET_BUILD_VARIANT=
489 while [ -z "$TARGET_BUILD_VARIANT" ]
490 do
491 echo -n "Which would you like? [$default_value] "
492 if [ -z "$1" ] ; then
493 read ANSWER
494 else
495 echo $1
496 ANSWER=$1
497 fi
498
499 if [ -z "$ANSWER" ] ; then
500 export TARGET_BUILD_VARIANT=$default_value
501 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
502 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800503 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 fi
505 else
506 if check_variant $ANSWER
507 then
508 export TARGET_BUILD_VARIANT=$ANSWER
509 else
510 echo "** Not a valid variant: $ANSWER"
511 fi
512 fi
513 if [ -n "$1" ] ; then
514 break
515 fi
516 done
517}
518
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700519function choosecombo()
520{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700521 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700522
523 echo
524 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700525 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700526
527 echo
528 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700529 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530
531 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800532 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700533 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800534 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800535 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700536}
537
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800538# Clear this variable. It will be built up again when the vendorsetup.sh
539# files are included at the end of this file.
540unset LUNCH_MENU_CHOICES
541function add_lunch_combo()
542{
543 local new_combo=$1
544 local c
545 for c in ${LUNCH_MENU_CHOICES[@]} ; do
546 if [ "$new_combo" = "$c" ] ; then
547 return
548 fi
549 done
550 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
551}
552
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700553function print_lunch_menu()
554{
555 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700556 echo
557 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700558 echo
559 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800560
561 local i=1
562 local choice
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700563 for choice in $(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800564 do
565 echo " $i. $choice"
566 i=$(($i+1))
567 done
568
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700569 echo
570}
571
572function lunch()
573{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800574 local answer
575
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700576 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800577 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700578 else
579 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700580 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800581 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582 fi
583
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800584 local selection=
585
586 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700587 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700588 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
590 then
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700591 local choices=($(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES))
592 if [ $answer -le ${#choices[@]} ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800593 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800594 # array in zsh starts from 1 instead of 0.
595 if [ -n "$ZSH_VERSION" ]
596 then
597 selection=${choices[$(($answer))]}
598 else
599 selection=${choices[$(($answer-1))]}
600 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800601 fi
Colin Cross88737132017-03-21 17:41:03 -0700602 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 fi
605
Joe Onoratoda12daf2010-06-09 18:18:31 -0700606 export TARGET_BUILD_APPS=
607
Colin Cross88737132017-03-21 17:41:03 -0700608 local product variant_and_version variant version
609
610 product=${selection%%-*} # Trim everything after first dash
611 variant_and_version=${selection#*-} # Trim everything up to first dash
612 if [ "$variant_and_version" != "$selection" ]; then
613 variant=${variant_and_version%%-*}
614 if [ "$variant" != "$variant_and_version" ]; then
615 version=${variant_and_version#*-}
616 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700617 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800618
Colin Cross88737132017-03-21 17:41:03 -0700619 if [ -z "$product" ]
Ying Wang08800fd2016-03-03 20:57:21 -0800620 then
621 echo
Colin Cross88737132017-03-21 17:41:03 -0700622 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700623 return 1
624 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800625
Colin Cross88737132017-03-21 17:41:03 -0700626 TARGET_PRODUCT=$product \
627 TARGET_BUILD_VARIANT=$variant \
628 TARGET_PLATFORM_VERSION=$version \
629 build_build_var_cache
630 if [ $? -ne 0 ]
631 then
632 return 1
633 fi
634
635 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
636 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700637 if [ -n "$version" ]; then
638 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
639 else
640 unset TARGET_PLATFORM_VERSION
641 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700642 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700643
644 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800645
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700646 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800647 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800648 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649}
650
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700651unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700652# Tab completion for lunch.
653function _lunch()
654{
655 local cur prev opts
656 COMPREPLY=()
657 cur="${COMP_WORDS[COMP_CWORD]}"
658 prev="${COMP_WORDS[COMP_CWORD-1]}"
659
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700660 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
661 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES)
662 fi
663
664 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700665 return 0
666}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700667
Joe Onoratoda12daf2010-06-09 18:18:31 -0700668# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700669# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700670function tapas()
671{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700672 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Dan Willemsendd3a2732018-01-08 15:26:16 -0800673 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700674 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700675 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Dan Willemsendd3a2732018-01-08 15:26:16 -0800676 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700677
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700678 if [ "$showHelp" != "" ]; then
679 $(gettop)/build/make/tapasHelp.sh
680 return
681 fi
682
Ying Wang67f02922012-08-22 10:25:20 -0700683 if [ $(echo $arch | wc -w) -gt 1 ]; then
684 echo "tapas: Error: Multiple build archs supplied: $arch"
685 return
686 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700687 if [ $(echo $variant | wc -w) -gt 1 ]; then
688 echo "tapas: Error: Multiple build variants supplied: $variant"
689 return
690 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700691 if [ $(echo $density | wc -w) -gt 1 ]; then
692 echo "tapas: Error: Multiple densities supplied: $density"
693 return
694 fi
Ying Wang67f02922012-08-22 10:25:20 -0700695
Ying Wang0a76df52015-06-08 11:57:26 -0700696 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700697 case $arch in
Ying Wang0a76df52015-06-08 11:57:26 -0700698 x86) product=aosp_x86;;
699 mips) product=aosp_mips;;
Ying Wangb541ab62014-05-29 17:57:40 -0700700 arm64) product=aosp_arm64;;
701 x86_64) product=aosp_x86_64;;
702 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700703 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700704 if [ -z "$variant" ]; then
705 variant=eng
706 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700707 if [ -z "$apps" ]; then
708 apps=all
709 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600710 if [ -z "$density" ]; then
711 density=alldpi
712 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700713
Ying Wang67f02922012-08-22 10:25:20 -0700714 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700715 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700716 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700717 export TARGET_BUILD_TYPE=release
718 export TARGET_BUILD_APPS=$apps
719
Ying Wang08800fd2016-03-03 20:57:21 -0800720 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700721 set_stuff_for_environment
722 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800723 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700724}
725
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700726function gettop
727{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700728 local TOPFILE=build/make/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700729 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700730 # The following circumlocution ensures we remove symlinks from TOP.
731 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700732 else
733 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800734 # The following circumlocution (repeated below as well) ensures
735 # that we record the true directory name and not one that is
736 # faked up with symlink names.
737 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700738 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800739 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700740 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700741 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800742 \cd ..
synergyb112a402013-07-05 19:47:47 -0700743 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700744 done
Ying Wang9cd17642012-12-13 10:52:07 -0800745 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700746 if [ -f "$T/$TOPFILE" ]; then
747 echo $T
748 fi
749 fi
750 fi
751}
752
753function m()
754{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800755 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700756 if [ "$T" ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800757 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700758 else
759 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700760 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700761 fi
762}
763
764function findmakefile()
765{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700766 local TOPFILE=build/make/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800767 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700768 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700769 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700770 T=`PWD= /bin/pwd`
Colin Cross86425252016-05-26 15:32:15 -0700771 if [ -f "$T/Android.mk" -o -f "$T/Android.bp" ]; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700772 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800773 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700774 return
775 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800776 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700777 done
Ying Wang9cd17642012-12-13 10:52:07 -0800778 \cd $HERE
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700779 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700780}
781
782function mm()
783{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800784 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700785 # If we're sitting in the root of the build tree, just do a
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700786 # normal build.
787 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800788 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700789 else
790 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800791 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700792 local MODULES=
793 local GET_INSTALL_PATH=
794 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700795 # Remove the path to top as the makefilepath needs to be relative
796 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797 if [ ! "$T" ]; then
798 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700799 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700800 elif [ ! "$M" ]; then
801 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700802 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700803 else
Christopher Ferris55257d22017-03-23 11:08:58 -0700804 local ARG
Ying Wanga7deb082013-08-16 13:24:47 -0700805 for ARG in $@; do
806 case $ARG in
807 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
808 esac
809 done
810 if [ -n "$GET_INSTALL_PATH" ]; then
811 MODULES=
Dan Willemsen53e38992016-08-11 17:20:33 -0700812 ARGS=GET-INSTALL-PATH-IN-$(dirname ${M})
813 ARGS=${ARGS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700814 else
Colin Cross86425252016-05-26 15:32:15 -0700815 MODULES=MODULES-IN-$(dirname ${M})
816 # Convert "/" to "-".
817 MODULES=${MODULES//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700818 ARGS=$@
819 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700820 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
821 MODULES=tidy_only
822 fi
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800823 ONE_SHOT_MAKEFILE=$M _wrap_build $T/build/soong/soong_ui.bash --make-mode $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700824 fi
825 fi
826}
827
828function mmm()
829{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800830 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700831 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800832 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800833 local MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700834 local MODULES_IN_PATHS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800835 local ARGS=
836 local DIR TO_CHOP
Colin Cross86425252016-05-26 15:32:15 -0700837 local DIR_MODULES
Ying Wanga7deb082013-08-16 13:24:47 -0700838 local GET_INSTALL_PATH=
Dan Willemsen53e38992016-08-11 17:20:33 -0700839 local GET_INSTALL_PATHS=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800840 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
841 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
842 for DIR in $DIRS ; do
Colin Cross86425252016-05-26 15:32:15 -0700843 DIR_MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
Alon Albert68895a92011-11-30 12:40:19 -0800844 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
Colin Cross86425252016-05-26 15:32:15 -0700845 # Remove the leading ./ and trailing / if any exists.
846 DIR=${DIR#./}
847 DIR=${DIR%/}
848 if [ -f $DIR/Android.mk -o -f $DIR/Android.bp ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700849 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
850 local TO_CHOP=`expr $TO_CHOP + 1`
851 local START=`PWD= /bin/pwd`
Colin Cross4bfae062016-08-31 17:22:36 -0700852 local MDIR=`echo $START | cut -c${TO_CHOP}-`
853 if [ "$MDIR" = "" ] ; then
854 MDIR=$DIR
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855 else
Colin Cross4bfae062016-08-31 17:22:36 -0700856 MDIR=$MDIR/$DIR
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700857 fi
Colin Cross4bfae062016-08-31 17:22:36 -0700858 MDIR=${MDIR%/.}
859 if [ "$DIR_MODULES" = "" ]; then
860 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$MDIR"
861 GET_INSTALL_PATHS="$GET_INSTALL_PATHS GET-INSTALL-PATH-IN-$MDIR"
862 else
863 MODULES="$MODULES $DIR_MODULES"
864 fi
865 MAKEFILE="$MAKEFILE $MDIR/Android.mk"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700866 else
Ying Wanga7deb082013-08-16 13:24:47 -0700867 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700868 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700869 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
Abhinav1997a72a6e72015-10-18 20:25:48 +0200870 *) if [ -d $DIR ]; then
871 echo "No Android.mk in $DIR.";
872 else
873 echo "Couldn't locate the directory $DIR";
874 fi
875 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700876 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700877 fi
878 done
Ying Wanga7deb082013-08-16 13:24:47 -0700879 if [ -n "$GET_INSTALL_PATH" ]; then
Dan Willemsen53e38992016-08-11 17:20:33 -0700880 ARGS=${GET_INSTALL_PATHS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700881 MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700882 MODULES_IN_PATHS=
Ying Wanga7deb082013-08-16 13:24:47 -0700883 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700884 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
885 MODULES=tidy_only
Colin Cross86425252016-05-26 15:32:15 -0700886 MODULES_IN_PATHS=
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700887 fi
Colin Cross86425252016-05-26 15:32:15 -0700888 # Convert "/" to "-".
889 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800890 ONE_SHOT_MAKEFILE="$MAKEFILE" _wrap_build $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 -0700891 else
892 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700893 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700894 fi
895}
896
Ying Wangb607f7b2013-02-08 18:01:04 -0800897function mma()
898{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800899 local T=$(gettop)
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700900 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800901 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800902 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800903 if [ ! "$T" ]; then
904 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700905 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800906 fi
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700907 local M=$(findmakefile || echo $(realpath $PWD)/Android.mk)
Colin Cross127fcea2016-09-01 15:30:18 -0700908 # Remove the path to top as the makefilepath needs to be relative
909 local M=`echo $M|sed 's:'$T'/::'`
910 local MODULES_IN_PATHS=MODULES-IN-$(dirname ${M})
Ying Wang61cd8842015-09-24 16:19:19 -0700911 # Convert "/" to "-".
912 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800913 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@ $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800914 fi
915}
916
917function mmma()
918{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800919 local T=$(gettop)
Ying Wangb607f7b2013-02-08 18:01:04 -0800920 if [ "$T" ]; then
921 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
922 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
923 local MY_PWD=`PWD= /bin/pwd`
924 if [ "$MY_PWD" = "$T" ]; then
925 MY_PWD=
926 else
927 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
928 fi
929 local DIR=
Ying Wangcaeaa082015-09-23 16:08:55 -0700930 local MODULES_IN_PATHS=
Ying Wangb607f7b2013-02-08 18:01:04 -0800931 local ARGS=
932 for DIR in $DIRS ; do
933 if [ -d $DIR ]; then
Ying Wangcaeaa082015-09-23 16:08:55 -0700934 # Remove the leading ./ and trailing / if any exists.
935 DIR=${DIR#./}
936 DIR=${DIR%/}
937 if [ "$MY_PWD" != "" ]; then
938 DIR=$MY_PWD/$DIR
Ying Wangb607f7b2013-02-08 18:01:04 -0800939 fi
Ying Wang61cd8842015-09-24 16:19:19 -0700940 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
Ying Wangb607f7b2013-02-08 18:01:04 -0800941 else
942 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700943 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800944 *) echo "Couldn't find directory $DIR"; return 1;;
945 esac
946 fi
947 done
Ying Wang61cd8842015-09-24 16:19:19 -0700948 # Convert "/" to "-".
949 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800950 _wrap_build $T/build/soong/soong_ui.bash --make-mode $DASH_ARGS $ARGS $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800951 else
952 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700953 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800954 fi
955}
956
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700957function croot()
958{
Christopher Ferris55257d22017-03-23 11:08:58 -0700959 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700960 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700961 if [ "$1" ]; then
962 \cd $(gettop)/$1
963 else
964 \cd $(gettop)
965 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966 else
967 echo "Couldn't locate the top of the tree. Try setting TOP."
968 fi
969}
970
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700971function cproj()
972{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700973 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700974 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700975 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700976 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
977 T=$PWD
978 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800979 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700980 return
981 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800982 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700983 done
Ying Wang9cd17642012-12-13 10:52:07 -0800984 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700985 echo "can't find Android.mk"
986}
987
Daniel Sandler47e0a882013-07-30 13:23:52 -0400988# simplified version of ps; output in the form
989# <pid> <procname>
990function qpid() {
991 local prepend=''
992 local append=''
993 if [ "$1" = "--exact" ]; then
994 prepend=' '
995 append='$'
996 shift
997 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -0800998 echo "usage: qpid [[--exact] <process name|pid>"
999 return 255
1000 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001001
1002 local EXE="$1"
1003 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001004 qpid | \grep "$prepend$EXE$append"
1005 else
1006 adb shell ps \
1007 | tr -d '\r' \
1008 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1009 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001010}
1011
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001012# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001013# that has the core-file-size limit set correctly
1014#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001015# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001016# if its core-file-size limit is not set already.
1017# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1018
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001019function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001020{
Ying Wang08800fd2016-03-03 20:57:21 -08001021 echo "Getting root...";
1022 adb root;
1023 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001024
Ying Wang08800fd2016-03-03 20:57:21 -08001025 echo "Remounting root partition read-write...";
1026 adb shell mount -w -o remount -t rootfs rootfs;
1027 sleep 1;
1028 adb wait-for-device;
1029 adb shell mkdir -p /cores;
1030 adb shell mount -t tmpfs tmpfs /cores;
1031 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001032
Ying Wang08800fd2016-03-03 20:57:21 -08001033 echo "Granting SELinux permission to dump in /cores...";
1034 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001035
Ying Wang08800fd2016-03-03 20:57:21 -08001036 echo "Set core pattern.";
1037 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001038
Ying Wang08800fd2016-03-03 20:57:21 -08001039 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001040}
1041
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001042# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001043# $1 = PID of process (e.g., $(pid mediaserver))
1044#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001045# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001046# dump to actually be generated.
1047
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001048function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001049{
Ying Wang08800fd2016-03-03 20:57:21 -08001050 local PID=$1;
1051 if [ -z "$PID" ]; then
1052 printf "Expecting a PID!\n";
1053 return;
1054 fi;
1055 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001056 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001057}
1058
1059# core - send SIGV and pull the core for process
1060# $1 = PID of process (e.g., $(pid mediaserver))
1061#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001062# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001063# enabled globally.
1064
1065function core()
1066{
Ying Wang08800fd2016-03-03 20:57:21 -08001067 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001068
Ying Wang08800fd2016-03-03 20:57:21 -08001069 if [ -z "$PID" ]; then
1070 printf "Expecting a PID!\n";
1071 return;
1072 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001073
Ying Wang08800fd2016-03-03 20:57:21 -08001074 local CORENAME=core.$PID;
1075 local COREPATH=/cores/$CORENAME;
1076 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001077
Ying Wang08800fd2016-03-03 20:57:21 -08001078 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001079
Ying Wang08800fd2016-03-03 20:57:21 -08001080 local done=0;
1081 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1082 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1083 adb shell kill -$SIG $PID;
1084 sleep 1;
1085 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001086
Ying Wang08800fd2016-03-03 20:57:21 -08001087 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1088 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001089}
1090
Christopher Tate744ee802009-11-12 15:33:08 -08001091# systemstack - dump the current stack trace of all threads in the system process
1092# to the usual ANR traces file
1093function systemstack()
1094{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001095 stacks system_server
1096}
1097
Michael Wrightaeed7212014-06-19 19:58:12 -07001098# Read the ELF header from /proc/$PID/exe to determine if the process is
1099# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001100function is64bit()
1101{
1102 local PID="$1"
1103 if [ "$PID" ] ; then
Elliott Hughesd3e47252018-11-15 16:32:14 -08001104 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001105 echo "64"
1106 else
1107 echo ""
1108 fi
1109 else
1110 echo ""
1111 fi
1112}
1113
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001114case `uname -s` in
1115 Darwin)
1116 function sgrep()
1117 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001118 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|hpp|S|java|xml|sh|mk|aidl|vts)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001119 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001120 }
1121
1122 ;;
1123 *)
1124 function sgrep()
1125 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001126 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|hpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001127 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001128 }
1129 ;;
1130esac
1131
Raghu Gandham8da43102012-07-25 19:57:22 -07001132function gettargetarch
1133{
1134 get_build_var TARGET_ARCH
1135}
1136
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001137function ggrep()
1138{
Mike Frysinger5e479732015-09-22 18:13:48 -04001139 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1140 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001141}
1142
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001143function jgrep()
1144{
Mike Frysinger5e479732015-09-22 18:13:48 -04001145 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1146 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001147}
1148
1149function cgrep()
1150{
Mike Frysinger5e479732015-09-22 18:13:48 -04001151 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' \) \
1152 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001153}
1154
1155function resgrep()
1156{
Christopher Ferris55257d22017-03-23 11:08:58 -07001157 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001158 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1159 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1160 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001161}
1162
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001163function mangrep()
1164{
Mike Frysinger5e479732015-09-22 18:13:48 -04001165 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1166 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001167}
1168
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001169function sepgrep()
1170{
Mike Frysinger5e479732015-09-22 18:13:48 -04001171 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1172 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001173}
1174
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001175function rcgrep()
1176{
Mike Frysinger5e479732015-09-22 18:13:48 -04001177 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1178 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001179}
1180
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001181case `uname -s` in
1182 Darwin)
1183 function mgrep()
1184 {
David Grossd1d6fc52017-05-10 10:49:44 -07001185 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 -04001186 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001187 }
1188
1189 function treegrep()
1190 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001191 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|hpp|S|java|xml)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001192 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001193 }
1194
1195 ;;
1196 *)
1197 function mgrep()
1198 {
David Grossd1d6fc52017-05-10 10:49:44 -07001199 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 -04001200 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001201 }
1202
1203 function treegrep()
1204 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001205 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|hpp|S|java|xml)' -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001206 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001207 }
1208
1209 ;;
1210esac
1211
1212function getprebuilt
1213{
1214 get_abs_build_var ANDROID_PREBUILTS
1215}
1216
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001217function tracedmdump()
1218{
Christopher Ferris55257d22017-03-23 11:08:58 -07001219 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001220 if [ ! "$T" ]; then
1221 echo "Couldn't locate the top of the tree. Try setting TOP."
1222 return
1223 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001224 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001225 local arch=$(gettargetarch)
1226 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001227
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001228 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001229 if [ ! "$TRACE" ] ; then
1230 echo "usage: tracedmdump tracename"
1231 return
1232 fi
1233
Jack Veenstra60116fc2009-04-09 18:12:34 -07001234 if [ ! -r "$KERNEL" ] ; then
1235 echo "Error: cannot find kernel: '$KERNEL'"
1236 return
1237 fi
1238
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001239 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001240 if [ "$BASETRACE" = "$TRACE" ] ; then
1241 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1242 fi
1243
1244 echo "post-processing traces..."
1245 rm -f $TRACE/qtrace.dexlist
1246 post_trace $TRACE
1247 if [ $? -ne 0 ]; then
1248 echo "***"
1249 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1250 echo "***"
1251 return
1252 fi
1253 echo "generating dexlist output..."
1254 /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
1255 echo "generating dmtrace data..."
1256 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1257 echo "generating html file..."
1258 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1259 echo "done, see $TRACE/dmtrace.html for details"
1260 echo "or run:"
1261 echo " traceview $TRACE/dmtrace"
1262}
1263
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001264# communicate with a running device or emulator, set up necessary state,
1265# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001266function runhat()
1267{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001268 # process standard adb options
1269 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001270 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001271 adbTarget=$1
1272 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001273 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001274 adbTarget="$1 $2"
1275 shift 2
1276 fi
1277 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001278 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001279
1280 # runhat options
1281 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001282
1283 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001284 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001285 return
1286 fi
1287
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001288 # confirm hat is available
1289 if [ -z $(which hat) ]; then
1290 echo "hat is not available in this configuration."
1291 return
1292 fi
1293
Andy McFaddenb6289852010-07-12 08:00:19 -07001294 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001295 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001296 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001297 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001298 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001299 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001300 echo -n "> "
1301 read
1302
The Android Open Source Project88b60792009-03-03 19:28:42 -08001303 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001304
The Android Open Source Project88b60792009-03-03 19:28:42 -08001305 echo "Retrieving file $devFile..."
1306 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001307
The Android Open Source Project88b60792009-03-03 19:28:42 -08001308 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001309
The Android Open Source Project88b60792009-03-03 19:28:42 -08001310 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001311 echo "View the output by pointing your browser at http://localhost:7000/"
1312 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001313 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001314}
1315
1316function getbugreports()
1317{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001318 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001319
1320 if [ ! "$reports" ]; then
1321 echo "Could not locate any bugreports."
1322 return
1323 fi
1324
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001325 local report
1326 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001327 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001328 echo "/sdcard/bugreports/${report}"
1329 adb pull /sdcard/bugreports/${report} ${report}
1330 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001331 done
1332}
1333
Victoria Lease1b296b42012-08-21 15:44:06 -07001334function getsdcardpath()
1335{
1336 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1337}
1338
1339function getscreenshotpath()
1340{
1341 echo "$(getsdcardpath)/Pictures/Screenshots"
1342}
1343
1344function getlastscreenshot()
1345{
1346 local screenshot_path=$(getscreenshotpath)
1347 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1348 if [ "$screenshot" = "" ]; then
1349 echo "No screenshots found."
1350 return
1351 fi
1352 echo "${screenshot}"
1353 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1354}
1355
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001356function startviewserver()
1357{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001358 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001359 if [ $# -gt 0 ]; then
1360 port=$1
1361 fi
1362 adb shell service call window 1 i32 $port
1363}
1364
1365function stopviewserver()
1366{
1367 adb shell service call window 2
1368}
1369
1370function isviewserverstarted()
1371{
1372 adb shell service call window 3
1373}
1374
Romain Guyb84049a2010-10-04 16:56:11 -07001375function key_home()
1376{
1377 adb shell input keyevent 3
1378}
1379
1380function key_back()
1381{
1382 adb shell input keyevent 4
1383}
1384
1385function key_menu()
1386{
1387 adb shell input keyevent 82
1388}
1389
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001390function smoketest()
1391{
1392 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1393 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1394 return
1395 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001396 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001397 if [ ! "$T" ]; then
1398 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1399 return
1400 fi
1401
Ying Wang9cd17642012-12-13 10:52:07 -08001402 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001403 adb uninstall com.android.smoketest > /dev/null &&
1404 adb uninstall com.android.smoketest.tests > /dev/null &&
1405 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1406 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1407 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1408}
1409
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001410# simple shortcut to the runtest command
1411function runtest()
1412{
Christopher Ferris55257d22017-03-23 11:08:58 -07001413 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001414 if [ ! "$T" ]; then
1415 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1416 return
1417 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001418 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001419}
1420
The Android Open Source Project88b60792009-03-03 19:28:42 -08001421function godir () {
1422 if [[ -z "$1" ]]; then
1423 echo "Usage: godir <regex>"
1424 return
1425 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001426 local T=$(gettop)
1427 local FILELIST
Brian Carlstromf2257422015-09-30 20:28:54 -07001428 if [ ! "$OUT_DIR" = "" ]; then
1429 mkdir -p $OUT_DIR
1430 FILELIST=$OUT_DIR/filelist
1431 else
1432 FILELIST=$T/filelist
1433 fi
1434 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001435 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001436 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001437 echo " Done"
1438 echo ""
1439 fi
1440 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001441 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001442 if [[ ${#lines[@]} = 0 ]]; then
1443 echo "Not found"
1444 return
1445 fi
1446 local pathname
1447 local choice
1448 if [[ ${#lines[@]} > 1 ]]; then
1449 while [[ -z "$pathname" ]]; do
1450 local index=1
1451 local line
1452 for line in ${lines[@]}; do
1453 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001454 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001455 done
1456 echo
1457 echo -n "Select one: "
1458 unset choice
1459 read choice
1460 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1461 echo "Invalid choice"
1462 continue
1463 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001464 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001465 done
1466 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001467 pathname=${lines[0]}
1468 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001469 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001470}
1471
Steven Moreland62054a42018-12-06 10:11:40 -08001472# Update module-info.json in out.
1473function refreshmod() {
1474 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1475 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1476 return 1
1477 fi
1478
1479 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1480
1481 # for the output of the next command
1482 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1483
1484 # Note, can't use absolute path because of the way make works.
1485 m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \
1486 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1487}
1488
1489# List all modules for the current device, as cached in module-info.json. If any build change is
1490# made and it should be reflected in the output, you should run 'refreshmod' first.
1491function allmod() {
1492 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1493 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1494 return 1
1495 fi
1496
1497 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1498 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1499 refreshmod || return 1
1500 fi
1501
1502 python -c "import json; print '\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys()))"
1503}
1504
1505# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1506# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1507function gomod() {
1508 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1509 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1510 return 1
1511 fi
1512
1513 if [[ $# -ne 1 ]]; then
1514 echo "usage: gomod <module>" >&2
1515 return 1
1516 fi
1517
1518 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1519 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1520 refreshmod || return 1
1521 fi
1522
1523 local relpath=$(python -c "import json, os
1524module = '$1'
1525module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1526if module not in module_info:
1527 exit(1)
1528print module_info[module]['path'][0]" 2>/dev/null)
1529
1530 if [ -z "$relpath" ]; then
1531 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1532 return 1
1533 else
1534 cd $ANDROID_BUILD_TOP/$relpath
1535 fi
1536}
1537
dimitry73b84812018-12-11 18:06:00 +01001538function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001539 local word=${COMP_WORDS[COMP_CWORD]}
1540 COMPREPLY=( $(allmod | grep -E "^$word") )
1541}
1542
Alex Rayf0d08eb2013-03-08 15:15:06 -08001543# Print colored exit condition
1544function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001545 "$@"
1546 local retval=$?
1547 if [ $retval -ne 0 ]
1548 then
Jacky Cao89483b82015-05-15 22:12:53 +08001549 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001550 else
Jacky Cao89483b82015-05-15 22:12:53 +08001551 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001552 fi
1553 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001554}
1555
Ying Wanged21d4c2014-08-24 22:14:19 -07001556function get_make_command()
1557{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001558 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1559 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001560 # Always use the real make if -C is passed in
1561 for arg in "$@"; do
1562 if [[ $arg == -C* ]]; then
1563 echo command make
1564 return
1565 fi
1566 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001567 echo build/soong/soong_ui.bash --make-mode
1568 else
1569 echo command make
1570 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001571}
1572
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001573function _wrap_build()
Ed Heylcc6be0a2014-06-18 14:55:58 -07001574{
1575 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001576 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001577 local ret=$?
1578 local end_time=$(date +"%s")
1579 local tdiff=$(($end_time-$start_time))
1580 local hours=$(($tdiff / 3600 ))
1581 local mins=$((($tdiff % 3600) / 60))
1582 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001583 local ncolors=$(tput colors 2>/dev/null)
1584 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001585 color_failed=$'\E'"[0;31m"
1586 color_success=$'\E'"[0;32m"
1587 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001588 else
1589 color_failed=""
1590 color_success=""
1591 color_reset=""
1592 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001593 echo
1594 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001595 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001596 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001597 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001598 fi
1599 if [ $hours -gt 0 ] ; then
1600 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1601 elif [ $mins -gt 0 ] ; then
1602 printf "(%02g:%02g (mm:ss))" $mins $secs
1603 elif [ $secs -gt 0 ] ; then
1604 printf "(%s seconds)" $secs
1605 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001606 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001607 echo
1608 return $ret
1609}
1610
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001611function make()
1612{
Dan Willemsene9842242017-07-28 13:00:13 -07001613 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001614}
1615
David Zeuthen1b126ff2015-09-30 17:10:48 -04001616function provision()
1617{
1618 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1619 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1620 return 1
1621 fi
1622 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1623 echo "There is no provisioning script for the device." >&2
1624 return 1
1625 fi
1626
1627 # Check if user really wants to do this.
1628 if [ "$1" = "--no-confirmation" ]; then
1629 shift 1
1630 else
1631 echo "This action will reflash your device."
1632 echo ""
1633 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1634 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001635 echo -n "Are you sure you want to do this (yes/no)? "
1636 read
David Zeuthen1b126ff2015-09-30 17:10:48 -04001637 if [[ "${REPLY}" != "yes" ]] ; then
1638 echo "Not taking any action. Exiting." >&2
1639 return 1
1640 fi
1641 fi
1642 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1643}
1644
Simran Basi424b8762017-08-23 12:03:04 -07001645function atest()
1646{
Jim Tangf258e7e2018-11-01 18:00:05 +08001647 # Let's use the built version over the prebuilt, then source code.
1648 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
1649 local built_atest=${ANDROID_HOST_OUT}/bin/atest
1650 local prebuilt_atest="$(gettop)"/prebuilts/asuite/atest/$os_arch/atest
1651 if [[ -x $built_atest ]]; then
1652 $built_atest "$@"
1653 elif [[ -x $prebuilt_atest ]]; then
1654 $prebuilt_atest "$@"
1655 else
1656 # TODO: once prebuilt atest released, remove the source code section
1657 # and change the location of atest_completion.sh in addcompletions().
1658 "$(gettop)"/tools/tradefederation/core/atest/atest.py "$@"
1659 fi
Simran Basi424b8762017-08-23 12:03:04 -07001660}
1661
Jim Tanga881a252018-06-19 16:34:41 +08001662# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001663function enable_zsh_completion() {
1664 # Don't override user's options if bash-style completion is already enabled.
1665 if ! declare -f complete >/dev/null; then
1666 autoload -U compinit && compinit
1667 autoload -U bashcompinit && bashcompinit
1668 fi
Jim Tanga881a252018-06-19 16:34:41 +08001669}
1670
1671function validate_current_shell() {
1672 local current_sh="$(ps -o command -p $$)"
1673 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001674 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001675 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001676 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001677 *zsh*)
1678 function check_type() { type "$1"; }
Patrik Fimmldf248e62018-10-15 18:15:12 +02001679 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001680 *)
Jim Tanga881a252018-06-19 16:34:41 +08001681 echo -e "WARNING: Only bash and zsh are supported.\nUse of other shell would lead to erroneous results."
Raphael Moll70a86b02011-06-20 16:03:14 -07001682 ;;
1683 esac
Jim Tanga881a252018-06-19 16:34:41 +08001684}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001685
Kevin Chengbf89aff2018-05-22 14:07:50 -07001686function acloud()
1687{
1688 # Let's use the built version over the prebuilt.
1689 local built_acloud=${ANDROID_HOST_OUT}/bin/acloud
1690 if [ -f $built_acloud ]; then
1691 $built_acloud "$@"
1692 return $?
1693 fi
1694
1695 local host_os_arch=$(get_build_var HOST_PREBUILT_TAG)
1696 case $host_os_arch in
1697 linux-x86) "$(gettop)"/prebuilts/asuite/acloud/linux-x86/acloud "$@"
1698 ;;
1699 *)
1700 echo "acloud is not supported on your host arch: $host_os_arch"
1701 ;;
1702 esac
1703}
1704
patricktu345c9ae2018-11-29 15:25:40 +08001705function aidegen()
1706{
1707 # Always use the prebuilt version.
1708 local host_os_arch=$(get_build_var HOST_PREBUILT_TAG)
1709 case $host_os_arch in
1710 linux-x86) "$(gettop)"/prebuilts/asuite/aidegen/linux-x86/aidegen "$@"
1711 ;;
1712 *)
1713 echo "aidegen is not supported on your host arch: $host_os_arch"
1714 ;;
1715 esac
1716}
1717
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001718# Execute the contents of any vendorsetup.sh files we can find.
Jim Tanga881a252018-06-19 16:34:41 +08001719function source_vendorsetup() {
1720 for dir in device vendor product; do
1721 for f in $(test -d $dir && \
1722 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
1723 echo "including $f"; . $f
1724 done
1725 done
1726}
Kenny Root52aa81c2011-07-15 11:07:06 -07001727
Jim Tanga881a252018-06-19 16:34:41 +08001728validate_current_shell
1729source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001730addcompletions