blob: 44ae65939d064e5ea345859a0888de967728c2d0 [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
Jim Tang22f4c322018-12-17 15:21:53 +0800269
270 # out with the duplicate old
271 if [ -n $ANDROID_PYTHONPATH ]; then
272 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
273 fi
274 # and in with the new
275 export ANDROID_PYTHONPATH=$T/development/python-packages:
276 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800277
Colin Crosse97e6932017-06-30 16:01:45 -0700278 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
279 export JAVA_HOME=$ANDROID_JAVA_HOME
280 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
281 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
282 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500283
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800284 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700285 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
286 export OUT=$ANDROID_PRODUCT_OUT
287
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700288 unset ANDROID_HOST_OUT
289 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
290
Simran Basidd050ed2017-02-13 13:46:48 -0800291 unset ANDROID_HOST_OUT_TESTCASES
292 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
293
294 unset ANDROID_TARGET_OUT_TESTCASES
295 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
296
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800297 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700298 # TODO: fix the path
299 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
300}
301
302function printconfig()
303{
Christopher Ferris55257d22017-03-23 11:08:58 -0700304 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800305 if [ ! "$T" ]; then
306 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
307 return
308 fi
309 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700310}
311
312function set_stuff_for_environment()
313{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800314 setpaths
315 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700316
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800317 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700318 # With this environment variable new GCC can apply colors to warnings/errors
319 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 -0700320 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321}
322
323function set_sequence_number()
324{
Colin Cross88737132017-03-21 17:41:03 -0700325 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700326}
327
Makoto Onukida971062018-06-18 10:15:19 -0700328# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
329function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800330 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700331 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800332 *:"$cmd":*)
333 return 1
334 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700335 esac
336 return 0
337}
338
Kenny Root52aa81c2011-07-15 11:07:06 -0700339function addcompletions()
340{
341 local T dir f
342
Jim Tanga881a252018-06-19 16:34:41 +0800343 # Keep us from trying to run in something that's neither bash nor zsh.
344 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700345 return
346 fi
347
348 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800349 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700350 return
351 fi
352
Jim Tanga881a252018-06-19 16:34:41 +0800353 local completion_files=(
354 system/core/adb/adb.bash
355 system/core/fastboot/fastboot.bash
356 tools/tradefederation/core/atest/atest_completion.sh
357 )
Makoto Onukida971062018-06-18 10:15:19 -0700358 # Completion can be disabled selectively to allow users to use non-standard completion.
359 # e.g.
360 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
361 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800362 for f in ${completion_files[*]}; do
363 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700364 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700365 fi
366 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700367
Makoto Onukida971062018-06-18 10:15:19 -0700368 if should_add_completion bit ; then
369 complete -C "bit --tab" bit
370 fi
Jim Tanga881a252018-06-19 16:34:41 +0800371 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800372
dimitry73b84812018-12-11 18:06:00 +0100373 complete -F _complete_android_module_names gomod
374 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700375}
376
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700377function choosetype()
378{
379 echo "Build type choices are:"
380 echo " 1. release"
381 echo " 2. debug"
382 echo
383
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800384 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700385 DEFAULT_NUM=1
386 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700387
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800388 export TARGET_BUILD_TYPE=
389 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700390 while [ -z $TARGET_BUILD_TYPE ]
391 do
392 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800393 if [ -z "$1" ] ; then
394 read ANSWER
395 else
396 echo $1
397 ANSWER=$1
398 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700399 case $ANSWER in
400 "")
401 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
402 ;;
403 1)
404 export TARGET_BUILD_TYPE=release
405 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800406 release)
407 export TARGET_BUILD_TYPE=release
408 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700409 2)
410 export TARGET_BUILD_TYPE=debug
411 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800412 debug)
413 export TARGET_BUILD_TYPE=debug
414 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700415 *)
416 echo
417 echo "I didn't understand your response. Please try again."
418 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700419 ;;
420 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800421 if [ -n "$1" ] ; then
422 break
423 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700424 done
425
Ying Wang08800fd2016-03-03 20:57:21 -0800426 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700427 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800428 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700429}
430
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800431#
432# This function isn't really right: It chooses a TARGET_PRODUCT
433# based on the list of boards. Usually, that gets you something
434# that kinda works with a generic product, but really, you should
435# pick a product by name.
436#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700437function chooseproduct()
438{
Christopher Ferris55257d22017-03-23 11:08:58 -0700439 local default_value
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700440 if [ "x$TARGET_PRODUCT" != x ] ; then
441 default_value=$TARGET_PRODUCT
442 else
Ying Wang0a76df52015-06-08 11:57:26 -0700443 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444 fi
445
Ying Wang08800fd2016-03-03 20:57:21 -0800446 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800447 export TARGET_PRODUCT=
448 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449 while [ -z "$TARGET_PRODUCT" ]
450 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700451 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800452 if [ -z "$1" ] ; then
453 read ANSWER
454 else
455 echo $1
456 ANSWER=$1
457 fi
458
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700459 if [ -z "$ANSWER" ] ; then
460 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800461 else
462 if check_product $ANSWER
463 then
464 export TARGET_PRODUCT=$ANSWER
465 else
466 echo "** Not a valid product: $ANSWER"
467 fi
468 fi
469 if [ -n "$1" ] ; then
470 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471 fi
472 done
473
Ying Wang08800fd2016-03-03 20:57:21 -0800474 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800476 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700477}
478
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479function choosevariant()
480{
481 echo "Variant choices are:"
482 local index=1
483 local v
484 for v in ${VARIANT_CHOICES[@]}
485 do
486 # The product name is the name of the directory containing
487 # the makefile we found, above.
488 echo " $index. $v"
489 index=$(($index+1))
490 done
491
492 local default_value=eng
493 local ANSWER
494
495 export TARGET_BUILD_VARIANT=
496 while [ -z "$TARGET_BUILD_VARIANT" ]
497 do
498 echo -n "Which would you like? [$default_value] "
499 if [ -z "$1" ] ; then
500 read ANSWER
501 else
502 echo $1
503 ANSWER=$1
504 fi
505
506 if [ -z "$ANSWER" ] ; then
507 export TARGET_BUILD_VARIANT=$default_value
508 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
509 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800510 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 fi
512 else
513 if check_variant $ANSWER
514 then
515 export TARGET_BUILD_VARIANT=$ANSWER
516 else
517 echo "** Not a valid variant: $ANSWER"
518 fi
519 fi
520 if [ -n "$1" ] ; then
521 break
522 fi
523 done
524}
525
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700526function choosecombo()
527{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700528 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700529
530 echo
531 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700532 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700533
534 echo
535 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700536 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800537
538 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800539 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700540 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800541 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800542 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700543}
544
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800545# Clear this variable. It will be built up again when the vendorsetup.sh
546# files are included at the end of this file.
547unset LUNCH_MENU_CHOICES
548function add_lunch_combo()
549{
550 local new_combo=$1
551 local c
552 for c in ${LUNCH_MENU_CHOICES[@]} ; do
553 if [ "$new_combo" = "$c" ] ; then
554 return
555 fi
556 done
557 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
558}
559
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700560function print_lunch_menu()
561{
562 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700563 echo
564 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700565 echo
566 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800567
568 local i=1
569 local choice
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700570 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 -0800571 do
572 echo " $i. $choice"
573 i=$(($i+1))
574 done
575
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700576 echo
577}
578
579function lunch()
580{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800581 local answer
582
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700583 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800584 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585 else
586 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700587 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800588 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700589 fi
590
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800591 local selection=
592
593 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700594 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700595 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800596 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
597 then
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700598 local choices=($(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES))
599 if [ $answer -le ${#choices[@]} ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800600 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800601 # array in zsh starts from 1 instead of 0.
602 if [ -n "$ZSH_VERSION" ]
603 then
604 selection=${choices[$(($answer))]}
605 else
606 selection=${choices[$(($answer-1))]}
607 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800608 fi
Colin Cross88737132017-03-21 17:41:03 -0700609 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800610 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700611 fi
612
Joe Onoratoda12daf2010-06-09 18:18:31 -0700613 export TARGET_BUILD_APPS=
614
Colin Cross88737132017-03-21 17:41:03 -0700615 local product variant_and_version variant version
616
617 product=${selection%%-*} # Trim everything after first dash
618 variant_and_version=${selection#*-} # Trim everything up to first dash
619 if [ "$variant_and_version" != "$selection" ]; then
620 variant=${variant_and_version%%-*}
621 if [ "$variant" != "$variant_and_version" ]; then
622 version=${variant_and_version#*-}
623 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700624 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800625
Colin Cross88737132017-03-21 17:41:03 -0700626 if [ -z "$product" ]
Ying Wang08800fd2016-03-03 20:57:21 -0800627 then
628 echo
Colin Cross88737132017-03-21 17:41:03 -0700629 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700630 return 1
631 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800632
Colin Cross88737132017-03-21 17:41:03 -0700633 TARGET_PRODUCT=$product \
634 TARGET_BUILD_VARIANT=$variant \
635 TARGET_PLATFORM_VERSION=$version \
636 build_build_var_cache
637 if [ $? -ne 0 ]
638 then
639 return 1
640 fi
641
642 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
643 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700644 if [ -n "$version" ]; then
645 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
646 else
647 unset TARGET_PLATFORM_VERSION
648 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700649 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700650
651 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800652
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800654 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800655 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700656}
657
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700658unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700659# Tab completion for lunch.
660function _lunch()
661{
662 local cur prev opts
663 COMPREPLY=()
664 cur="${COMP_WORDS[COMP_CWORD]}"
665 prev="${COMP_WORDS[COMP_CWORD-1]}"
666
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700667 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
668 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES)
669 fi
670
671 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700672 return 0
673}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700674
Joe Onoratoda12daf2010-06-09 18:18:31 -0700675# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700676# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700677function tapas()
678{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700679 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Dan Willemsendd3a2732018-01-08 15:26:16 -0800680 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700681 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700682 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 -0800683 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 -0700684
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700685 if [ "$showHelp" != "" ]; then
686 $(gettop)/build/make/tapasHelp.sh
687 return
688 fi
689
Ying Wang67f02922012-08-22 10:25:20 -0700690 if [ $(echo $arch | wc -w) -gt 1 ]; then
691 echo "tapas: Error: Multiple build archs supplied: $arch"
692 return
693 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700694 if [ $(echo $variant | wc -w) -gt 1 ]; then
695 echo "tapas: Error: Multiple build variants supplied: $variant"
696 return
697 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700698 if [ $(echo $density | wc -w) -gt 1 ]; then
699 echo "tapas: Error: Multiple densities supplied: $density"
700 return
701 fi
Ying Wang67f02922012-08-22 10:25:20 -0700702
Ying Wang0a76df52015-06-08 11:57:26 -0700703 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700704 case $arch in
Ying Wang0a76df52015-06-08 11:57:26 -0700705 x86) product=aosp_x86;;
706 mips) product=aosp_mips;;
Ying Wangb541ab62014-05-29 17:57:40 -0700707 arm64) product=aosp_arm64;;
708 x86_64) product=aosp_x86_64;;
709 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700710 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700711 if [ -z "$variant" ]; then
712 variant=eng
713 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700714 if [ -z "$apps" ]; then
715 apps=all
716 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600717 if [ -z "$density" ]; then
718 density=alldpi
719 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700720
Ying Wang67f02922012-08-22 10:25:20 -0700721 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700722 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700723 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700724 export TARGET_BUILD_TYPE=release
725 export TARGET_BUILD_APPS=$apps
726
Ying Wang08800fd2016-03-03 20:57:21 -0800727 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700728 set_stuff_for_environment
729 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800730 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700731}
732
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700733function gettop
734{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700735 local TOPFILE=build/make/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700736 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700737 # The following circumlocution ensures we remove symlinks from TOP.
738 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700739 else
740 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800741 # The following circumlocution (repeated below as well) ensures
742 # that we record the true directory name and not one that is
743 # faked up with symlink names.
744 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700745 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800746 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700747 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700748 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800749 \cd ..
synergyb112a402013-07-05 19:47:47 -0700750 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700751 done
Ying Wang9cd17642012-12-13 10:52:07 -0800752 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700753 if [ -f "$T/$TOPFILE" ]; then
754 echo $T
755 fi
756 fi
757 fi
758}
759
760function m()
761{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800762 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700763 if [ "$T" ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800764 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700765 else
766 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700767 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700768 fi
769}
770
771function findmakefile()
772{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700773 local TOPFILE=build/make/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800774 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700775 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700776 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700777 T=`PWD= /bin/pwd`
Colin Cross86425252016-05-26 15:32:15 -0700778 if [ -f "$T/Android.mk" -o -f "$T/Android.bp" ]; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800780 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700781 return
782 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800783 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784 done
Ying Wang9cd17642012-12-13 10:52:07 -0800785 \cd $HERE
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700786 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700787}
788
789function mm()
790{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800791 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792 # If we're sitting in the root of the build tree, just do a
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700793 # normal build.
794 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800795 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700796 else
797 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800798 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700799 local MODULES=
800 local GET_INSTALL_PATH=
801 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700802 # Remove the path to top as the makefilepath needs to be relative
803 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700804 if [ ! "$T" ]; then
805 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700806 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700807 elif [ ! "$M" ]; then
808 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700809 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700810 else
Christopher Ferris55257d22017-03-23 11:08:58 -0700811 local ARG
Ying Wanga7deb082013-08-16 13:24:47 -0700812 for ARG in $@; do
813 case $ARG in
814 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
815 esac
816 done
817 if [ -n "$GET_INSTALL_PATH" ]; then
818 MODULES=
Dan Willemsen53e38992016-08-11 17:20:33 -0700819 ARGS=GET-INSTALL-PATH-IN-$(dirname ${M})
820 ARGS=${ARGS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700821 else
Colin Cross86425252016-05-26 15:32:15 -0700822 MODULES=MODULES-IN-$(dirname ${M})
823 # Convert "/" to "-".
824 MODULES=${MODULES//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700825 ARGS=$@
826 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700827 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
828 MODULES=tidy_only
829 fi
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800830 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 -0700831 fi
832 fi
833}
834
835function mmm()
836{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800837 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700838 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800839 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800840 local MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700841 local MODULES_IN_PATHS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800842 local ARGS=
843 local DIR TO_CHOP
Colin Cross86425252016-05-26 15:32:15 -0700844 local DIR_MODULES
Ying Wanga7deb082013-08-16 13:24:47 -0700845 local GET_INSTALL_PATH=
Dan Willemsen53e38992016-08-11 17:20:33 -0700846 local GET_INSTALL_PATHS=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800847 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
848 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
849 for DIR in $DIRS ; do
Colin Cross86425252016-05-26 15:32:15 -0700850 DIR_MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
Alon Albert68895a92011-11-30 12:40:19 -0800851 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
Colin Cross86425252016-05-26 15:32:15 -0700852 # Remove the leading ./ and trailing / if any exists.
853 DIR=${DIR#./}
854 DIR=${DIR%/}
855 if [ -f $DIR/Android.mk -o -f $DIR/Android.bp ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700856 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
857 local TO_CHOP=`expr $TO_CHOP + 1`
858 local START=`PWD= /bin/pwd`
Colin Cross4bfae062016-08-31 17:22:36 -0700859 local MDIR=`echo $START | cut -c${TO_CHOP}-`
860 if [ "$MDIR" = "" ] ; then
861 MDIR=$DIR
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700862 else
Colin Cross4bfae062016-08-31 17:22:36 -0700863 MDIR=$MDIR/$DIR
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700864 fi
Colin Cross4bfae062016-08-31 17:22:36 -0700865 MDIR=${MDIR%/.}
866 if [ "$DIR_MODULES" = "" ]; then
867 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$MDIR"
868 GET_INSTALL_PATHS="$GET_INSTALL_PATHS GET-INSTALL-PATH-IN-$MDIR"
869 else
870 MODULES="$MODULES $DIR_MODULES"
871 fi
872 MAKEFILE="$MAKEFILE $MDIR/Android.mk"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700873 else
Ying Wanga7deb082013-08-16 13:24:47 -0700874 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700875 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700876 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
Abhinav1997a72a6e72015-10-18 20:25:48 +0200877 *) if [ -d $DIR ]; then
878 echo "No Android.mk in $DIR.";
879 else
880 echo "Couldn't locate the directory $DIR";
881 fi
882 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700883 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700884 fi
885 done
Ying Wanga7deb082013-08-16 13:24:47 -0700886 if [ -n "$GET_INSTALL_PATH" ]; then
Dan Willemsen53e38992016-08-11 17:20:33 -0700887 ARGS=${GET_INSTALL_PATHS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700888 MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700889 MODULES_IN_PATHS=
Ying Wanga7deb082013-08-16 13:24:47 -0700890 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700891 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
892 MODULES=tidy_only
Colin Cross86425252016-05-26 15:32:15 -0700893 MODULES_IN_PATHS=
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700894 fi
Colin Cross86425252016-05-26 15:32:15 -0700895 # Convert "/" to "-".
896 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800897 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 -0700898 else
899 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700900 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700901 fi
902}
903
Ying Wangb607f7b2013-02-08 18:01:04 -0800904function mma()
905{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800906 local T=$(gettop)
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700907 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800908 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800909 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800910 if [ ! "$T" ]; then
911 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700912 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800913 fi
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700914 local M=$(findmakefile || echo $(realpath $PWD)/Android.mk)
Colin Cross127fcea2016-09-01 15:30:18 -0700915 # Remove the path to top as the makefilepath needs to be relative
916 local M=`echo $M|sed 's:'$T'/::'`
917 local MODULES_IN_PATHS=MODULES-IN-$(dirname ${M})
Ying Wang61cd8842015-09-24 16:19:19 -0700918 # Convert "/" to "-".
919 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800920 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@ $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800921 fi
922}
923
924function mmma()
925{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800926 local T=$(gettop)
Ying Wangb607f7b2013-02-08 18:01:04 -0800927 if [ "$T" ]; then
928 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
929 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
930 local MY_PWD=`PWD= /bin/pwd`
931 if [ "$MY_PWD" = "$T" ]; then
932 MY_PWD=
933 else
934 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
935 fi
936 local DIR=
Ying Wangcaeaa082015-09-23 16:08:55 -0700937 local MODULES_IN_PATHS=
Ying Wangb607f7b2013-02-08 18:01:04 -0800938 local ARGS=
939 for DIR in $DIRS ; do
940 if [ -d $DIR ]; then
Ying Wangcaeaa082015-09-23 16:08:55 -0700941 # Remove the leading ./ and trailing / if any exists.
942 DIR=${DIR#./}
943 DIR=${DIR%/}
944 if [ "$MY_PWD" != "" ]; then
945 DIR=$MY_PWD/$DIR
Ying Wangb607f7b2013-02-08 18:01:04 -0800946 fi
Ying Wang61cd8842015-09-24 16:19:19 -0700947 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
Ying Wangb607f7b2013-02-08 18:01:04 -0800948 else
949 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700950 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800951 *) echo "Couldn't find directory $DIR"; return 1;;
952 esac
953 fi
954 done
Ying Wang61cd8842015-09-24 16:19:19 -0700955 # Convert "/" to "-".
956 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800957 _wrap_build $T/build/soong/soong_ui.bash --make-mode $DASH_ARGS $ARGS $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800958 else
959 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700960 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800961 fi
962}
963
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700964function croot()
965{
Christopher Ferris55257d22017-03-23 11:08:58 -0700966 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700968 if [ "$1" ]; then
969 \cd $(gettop)/$1
970 else
971 \cd $(gettop)
972 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700973 else
974 echo "Couldn't locate the top of the tree. Try setting TOP."
975 fi
976}
977
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700978function cproj()
979{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700980 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700981 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700982 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700983 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
984 T=$PWD
985 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800986 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700987 return
988 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800989 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700990 done
Ying Wang9cd17642012-12-13 10:52:07 -0800991 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700992 echo "can't find Android.mk"
993}
994
Daniel Sandler47e0a882013-07-30 13:23:52 -0400995# simplified version of ps; output in the form
996# <pid> <procname>
997function qpid() {
998 local prepend=''
999 local append=''
1000 if [ "$1" = "--exact" ]; then
1001 prepend=' '
1002 append='$'
1003 shift
1004 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001005 echo "usage: qpid [[--exact] <process name|pid>"
1006 return 255
1007 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001008
1009 local EXE="$1"
1010 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001011 qpid | \grep "$prepend$EXE$append"
1012 else
1013 adb shell ps \
1014 | tr -d '\r' \
1015 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1016 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001017}
1018
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001019# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001020# that has the core-file-size limit set correctly
1021#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001022# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001023# if its core-file-size limit is not set already.
1024# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1025
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001026function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001027{
Ying Wang08800fd2016-03-03 20:57:21 -08001028 echo "Getting root...";
1029 adb root;
1030 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001031
Ying Wang08800fd2016-03-03 20:57:21 -08001032 echo "Remounting root partition read-write...";
1033 adb shell mount -w -o remount -t rootfs rootfs;
1034 sleep 1;
1035 adb wait-for-device;
1036 adb shell mkdir -p /cores;
1037 adb shell mount -t tmpfs tmpfs /cores;
1038 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001039
Ying Wang08800fd2016-03-03 20:57:21 -08001040 echo "Granting SELinux permission to dump in /cores...";
1041 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001042
Ying Wang08800fd2016-03-03 20:57:21 -08001043 echo "Set core pattern.";
1044 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001045
Ying Wang08800fd2016-03-03 20:57:21 -08001046 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001047}
1048
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001049# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001050# $1 = PID of process (e.g., $(pid mediaserver))
1051#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001052# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001053# dump to actually be generated.
1054
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001055function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001056{
Ying Wang08800fd2016-03-03 20:57:21 -08001057 local PID=$1;
1058 if [ -z "$PID" ]; then
1059 printf "Expecting a PID!\n";
1060 return;
1061 fi;
1062 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001063 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001064}
1065
1066# core - send SIGV and pull the core for process
1067# $1 = PID of process (e.g., $(pid mediaserver))
1068#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001069# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001070# enabled globally.
1071
1072function core()
1073{
Ying Wang08800fd2016-03-03 20:57:21 -08001074 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001075
Ying Wang08800fd2016-03-03 20:57:21 -08001076 if [ -z "$PID" ]; then
1077 printf "Expecting a PID!\n";
1078 return;
1079 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001080
Ying Wang08800fd2016-03-03 20:57:21 -08001081 local CORENAME=core.$PID;
1082 local COREPATH=/cores/$CORENAME;
1083 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001084
Ying Wang08800fd2016-03-03 20:57:21 -08001085 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001086
Ying Wang08800fd2016-03-03 20:57:21 -08001087 local done=0;
1088 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1089 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1090 adb shell kill -$SIG $PID;
1091 sleep 1;
1092 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001093
Ying Wang08800fd2016-03-03 20:57:21 -08001094 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1095 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001096}
1097
Christopher Tate744ee802009-11-12 15:33:08 -08001098# systemstack - dump the current stack trace of all threads in the system process
1099# to the usual ANR traces file
1100function systemstack()
1101{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001102 stacks system_server
1103}
1104
Michael Wrightaeed7212014-06-19 19:58:12 -07001105# Read the ELF header from /proc/$PID/exe to determine if the process is
1106# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001107function is64bit()
1108{
1109 local PID="$1"
1110 if [ "$PID" ] ; then
Elliott Hughesd3e47252018-11-15 16:32:14 -08001111 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001112 echo "64"
1113 else
1114 echo ""
1115 fi
1116 else
1117 echo ""
1118 fi
1119}
1120
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001121case `uname -s` in
1122 Darwin)
1123 function sgrep()
1124 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001125 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 -04001126 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001127 }
1128
1129 ;;
1130 *)
1131 function sgrep()
1132 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001133 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 -04001134 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001135 }
1136 ;;
1137esac
1138
Raghu Gandham8da43102012-07-25 19:57:22 -07001139function gettargetarch
1140{
1141 get_build_var TARGET_ARCH
1142}
1143
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001144function ggrep()
1145{
Mike Frysinger5e479732015-09-22 18:13:48 -04001146 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1147 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001148}
1149
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001150function jgrep()
1151{
Mike Frysinger5e479732015-09-22 18:13:48 -04001152 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1153 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001154}
1155
1156function cgrep()
1157{
Mike Frysinger5e479732015-09-22 18:13:48 -04001158 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' \) \
1159 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001160}
1161
1162function resgrep()
1163{
Christopher Ferris55257d22017-03-23 11:08:58 -07001164 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001165 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1166 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1167 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001168}
1169
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001170function mangrep()
1171{
Mike Frysinger5e479732015-09-22 18:13:48 -04001172 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1173 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001174}
1175
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001176function sepgrep()
1177{
Mike Frysinger5e479732015-09-22 18:13:48 -04001178 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1179 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001180}
1181
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001182function rcgrep()
1183{
Mike Frysinger5e479732015-09-22 18:13:48 -04001184 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1185 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001186}
1187
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001188case `uname -s` in
1189 Darwin)
1190 function mgrep()
1191 {
David Grossd1d6fc52017-05-10 10:49:44 -07001192 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 -04001193 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001194 }
1195
1196 function treegrep()
1197 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001198 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 -04001199 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001200 }
1201
1202 ;;
1203 *)
1204 function mgrep()
1205 {
David Grossd1d6fc52017-05-10 10:49:44 -07001206 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 -04001207 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001208 }
1209
1210 function treegrep()
1211 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001212 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 -04001213 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001214 }
1215
1216 ;;
1217esac
1218
1219function getprebuilt
1220{
1221 get_abs_build_var ANDROID_PREBUILTS
1222}
1223
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001224function tracedmdump()
1225{
Christopher Ferris55257d22017-03-23 11:08:58 -07001226 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001227 if [ ! "$T" ]; then
1228 echo "Couldn't locate the top of the tree. Try setting TOP."
1229 return
1230 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001231 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001232 local arch=$(gettargetarch)
1233 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001234
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001235 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236 if [ ! "$TRACE" ] ; then
1237 echo "usage: tracedmdump tracename"
1238 return
1239 fi
1240
Jack Veenstra60116fc2009-04-09 18:12:34 -07001241 if [ ! -r "$KERNEL" ] ; then
1242 echo "Error: cannot find kernel: '$KERNEL'"
1243 return
1244 fi
1245
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001246 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001247 if [ "$BASETRACE" = "$TRACE" ] ; then
1248 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1249 fi
1250
1251 echo "post-processing traces..."
1252 rm -f $TRACE/qtrace.dexlist
1253 post_trace $TRACE
1254 if [ $? -ne 0 ]; then
1255 echo "***"
1256 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1257 echo "***"
1258 return
1259 fi
1260 echo "generating dexlist output..."
1261 /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
1262 echo "generating dmtrace data..."
1263 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1264 echo "generating html file..."
1265 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1266 echo "done, see $TRACE/dmtrace.html for details"
1267 echo "or run:"
1268 echo " traceview $TRACE/dmtrace"
1269}
1270
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001271# communicate with a running device or emulator, set up necessary state,
1272# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001273function runhat()
1274{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001275 # process standard adb options
1276 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001277 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001278 adbTarget=$1
1279 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001280 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001281 adbTarget="$1 $2"
1282 shift 2
1283 fi
1284 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001285 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001286
1287 # runhat options
1288 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001289
1290 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001291 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001292 return
1293 fi
1294
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001295 # confirm hat is available
1296 if [ -z $(which hat) ]; then
1297 echo "hat is not available in this configuration."
1298 return
1299 fi
1300
Andy McFaddenb6289852010-07-12 08:00:19 -07001301 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001302 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001303 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001304 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001305 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001306 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001307 echo -n "> "
1308 read
1309
The Android Open Source Project88b60792009-03-03 19:28:42 -08001310 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001311
The Android Open Source Project88b60792009-03-03 19:28:42 -08001312 echo "Retrieving file $devFile..."
1313 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001314
The Android Open Source Project88b60792009-03-03 19:28:42 -08001315 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001316
The Android Open Source Project88b60792009-03-03 19:28:42 -08001317 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001318 echo "View the output by pointing your browser at http://localhost:7000/"
1319 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001320 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001321}
1322
1323function getbugreports()
1324{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001325 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001326
1327 if [ ! "$reports" ]; then
1328 echo "Could not locate any bugreports."
1329 return
1330 fi
1331
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001332 local report
1333 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001334 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001335 echo "/sdcard/bugreports/${report}"
1336 adb pull /sdcard/bugreports/${report} ${report}
1337 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001338 done
1339}
1340
Victoria Lease1b296b42012-08-21 15:44:06 -07001341function getsdcardpath()
1342{
1343 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1344}
1345
1346function getscreenshotpath()
1347{
1348 echo "$(getsdcardpath)/Pictures/Screenshots"
1349}
1350
1351function getlastscreenshot()
1352{
1353 local screenshot_path=$(getscreenshotpath)
1354 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1355 if [ "$screenshot" = "" ]; then
1356 echo "No screenshots found."
1357 return
1358 fi
1359 echo "${screenshot}"
1360 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1361}
1362
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001363function startviewserver()
1364{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001365 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001366 if [ $# -gt 0 ]; then
1367 port=$1
1368 fi
1369 adb shell service call window 1 i32 $port
1370}
1371
1372function stopviewserver()
1373{
1374 adb shell service call window 2
1375}
1376
1377function isviewserverstarted()
1378{
1379 adb shell service call window 3
1380}
1381
Romain Guyb84049a2010-10-04 16:56:11 -07001382function key_home()
1383{
1384 adb shell input keyevent 3
1385}
1386
1387function key_back()
1388{
1389 adb shell input keyevent 4
1390}
1391
1392function key_menu()
1393{
1394 adb shell input keyevent 82
1395}
1396
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001397function smoketest()
1398{
1399 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1400 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1401 return
1402 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001403 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001404 if [ ! "$T" ]; then
1405 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1406 return
1407 fi
1408
Ying Wang9cd17642012-12-13 10:52:07 -08001409 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001410 adb uninstall com.android.smoketest > /dev/null &&
1411 adb uninstall com.android.smoketest.tests > /dev/null &&
1412 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1413 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1414 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1415}
1416
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001417# simple shortcut to the runtest command
1418function runtest()
1419{
Christopher Ferris55257d22017-03-23 11:08:58 -07001420 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001421 if [ ! "$T" ]; then
1422 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1423 return
1424 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001425 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001426}
1427
The Android Open Source Project88b60792009-03-03 19:28:42 -08001428function godir () {
1429 if [[ -z "$1" ]]; then
1430 echo "Usage: godir <regex>"
1431 return
1432 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001433 local T=$(gettop)
1434 local FILELIST
Brian Carlstromf2257422015-09-30 20:28:54 -07001435 if [ ! "$OUT_DIR" = "" ]; then
1436 mkdir -p $OUT_DIR
1437 FILELIST=$OUT_DIR/filelist
1438 else
1439 FILELIST=$T/filelist
1440 fi
1441 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001442 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001443 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001444 echo " Done"
1445 echo ""
1446 fi
1447 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001448 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001449 if [[ ${#lines[@]} = 0 ]]; then
1450 echo "Not found"
1451 return
1452 fi
1453 local pathname
1454 local choice
1455 if [[ ${#lines[@]} > 1 ]]; then
1456 while [[ -z "$pathname" ]]; do
1457 local index=1
1458 local line
1459 for line in ${lines[@]}; do
1460 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001461 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001462 done
1463 echo
1464 echo -n "Select one: "
1465 unset choice
1466 read choice
1467 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1468 echo "Invalid choice"
1469 continue
1470 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001471 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001472 done
1473 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001474 pathname=${lines[0]}
1475 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001476 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001477}
1478
Steven Moreland62054a42018-12-06 10:11:40 -08001479# Update module-info.json in out.
1480function refreshmod() {
1481 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1482 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1483 return 1
1484 fi
1485
1486 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1487
1488 # for the output of the next command
1489 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1490
1491 # Note, can't use absolute path because of the way make works.
1492 m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \
1493 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1494}
1495
1496# List all modules for the current device, as cached in module-info.json. If any build change is
1497# made and it should be reflected in the output, you should run 'refreshmod' first.
1498function allmod() {
1499 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1500 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1501 return 1
1502 fi
1503
1504 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1505 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1506 refreshmod || return 1
1507 fi
1508
1509 python -c "import json; print '\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys()))"
1510}
1511
1512# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1513# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1514function gomod() {
1515 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1516 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1517 return 1
1518 fi
1519
1520 if [[ $# -ne 1 ]]; then
1521 echo "usage: gomod <module>" >&2
1522 return 1
1523 fi
1524
1525 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1526 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1527 refreshmod || return 1
1528 fi
1529
1530 local relpath=$(python -c "import json, os
1531module = '$1'
1532module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1533if module not in module_info:
1534 exit(1)
1535print module_info[module]['path'][0]" 2>/dev/null)
1536
1537 if [ -z "$relpath" ]; then
1538 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1539 return 1
1540 else
1541 cd $ANDROID_BUILD_TOP/$relpath
1542 fi
1543}
1544
dimitry73b84812018-12-11 18:06:00 +01001545function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001546 local word=${COMP_WORDS[COMP_CWORD]}
1547 COMPREPLY=( $(allmod | grep -E "^$word") )
1548}
1549
Alex Rayf0d08eb2013-03-08 15:15:06 -08001550# Print colored exit condition
1551function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001552 "$@"
1553 local retval=$?
1554 if [ $retval -ne 0 ]
1555 then
Jacky Cao89483b82015-05-15 22:12:53 +08001556 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001557 else
Jacky Cao89483b82015-05-15 22:12:53 +08001558 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001559 fi
1560 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001561}
1562
Ying Wanged21d4c2014-08-24 22:14:19 -07001563function get_make_command()
1564{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001565 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1566 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001567 # Always use the real make if -C is passed in
1568 for arg in "$@"; do
1569 if [[ $arg == -C* ]]; then
1570 echo command make
1571 return
1572 fi
1573 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001574 echo build/soong/soong_ui.bash --make-mode
1575 else
1576 echo command make
1577 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001578}
1579
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001580function _wrap_build()
Ed Heylcc6be0a2014-06-18 14:55:58 -07001581{
1582 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001583 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001584 local ret=$?
1585 local end_time=$(date +"%s")
1586 local tdiff=$(($end_time-$start_time))
1587 local hours=$(($tdiff / 3600 ))
1588 local mins=$((($tdiff % 3600) / 60))
1589 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001590 local ncolors=$(tput colors 2>/dev/null)
1591 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001592 color_failed=$'\E'"[0;31m"
1593 color_success=$'\E'"[0;32m"
1594 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001595 else
1596 color_failed=""
1597 color_success=""
1598 color_reset=""
1599 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001600 echo
1601 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001602 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001603 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001604 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001605 fi
1606 if [ $hours -gt 0 ] ; then
1607 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1608 elif [ $mins -gt 0 ] ; then
1609 printf "(%02g:%02g (mm:ss))" $mins $secs
1610 elif [ $secs -gt 0 ] ; then
1611 printf "(%s seconds)" $secs
1612 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001613 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001614 echo
1615 return $ret
1616}
1617
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001618function make()
1619{
Dan Willemsene9842242017-07-28 13:00:13 -07001620 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001621}
1622
David Zeuthen1b126ff2015-09-30 17:10:48 -04001623function provision()
1624{
1625 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1626 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1627 return 1
1628 fi
1629 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1630 echo "There is no provisioning script for the device." >&2
1631 return 1
1632 fi
1633
1634 # Check if user really wants to do this.
1635 if [ "$1" = "--no-confirmation" ]; then
1636 shift 1
1637 else
1638 echo "This action will reflash your device."
1639 echo ""
1640 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1641 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001642 echo -n "Are you sure you want to do this (yes/no)? "
1643 read
David Zeuthen1b126ff2015-09-30 17:10:48 -04001644 if [[ "${REPLY}" != "yes" ]] ; then
1645 echo "Not taking any action. Exiting." >&2
1646 return 1
1647 fi
1648 fi
1649 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1650}
1651
Simran Basi424b8762017-08-23 12:03:04 -07001652function atest()
1653{
Jim Tangf258e7e2018-11-01 18:00:05 +08001654 # Let's use the built version over the prebuilt, then source code.
1655 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
1656 local built_atest=${ANDROID_HOST_OUT}/bin/atest
1657 local prebuilt_atest="$(gettop)"/prebuilts/asuite/atest/$os_arch/atest
1658 if [[ -x $built_atest ]]; then
1659 $built_atest "$@"
1660 elif [[ -x $prebuilt_atest ]]; then
1661 $prebuilt_atest "$@"
1662 else
1663 # TODO: once prebuilt atest released, remove the source code section
1664 # and change the location of atest_completion.sh in addcompletions().
1665 "$(gettop)"/tools/tradefederation/core/atest/atest.py "$@"
1666 fi
Simran Basi424b8762017-08-23 12:03:04 -07001667}
1668
Jim Tanga881a252018-06-19 16:34:41 +08001669# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001670function enable_zsh_completion() {
1671 # Don't override user's options if bash-style completion is already enabled.
1672 if ! declare -f complete >/dev/null; then
1673 autoload -U compinit && compinit
1674 autoload -U bashcompinit && bashcompinit
1675 fi
Jim Tanga881a252018-06-19 16:34:41 +08001676}
1677
1678function validate_current_shell() {
1679 local current_sh="$(ps -o command -p $$)"
1680 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001681 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001682 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001683 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001684 *zsh*)
1685 function check_type() { type "$1"; }
Patrik Fimmldf248e62018-10-15 18:15:12 +02001686 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001687 *)
Jim Tanga881a252018-06-19 16:34:41 +08001688 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 -07001689 ;;
1690 esac
Jim Tanga881a252018-06-19 16:34:41 +08001691}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001692
Kevin Chengbf89aff2018-05-22 14:07:50 -07001693function acloud()
1694{
1695 # Let's use the built version over the prebuilt.
1696 local built_acloud=${ANDROID_HOST_OUT}/bin/acloud
1697 if [ -f $built_acloud ]; then
1698 $built_acloud "$@"
1699 return $?
1700 fi
1701
1702 local host_os_arch=$(get_build_var HOST_PREBUILT_TAG)
1703 case $host_os_arch in
1704 linux-x86) "$(gettop)"/prebuilts/asuite/acloud/linux-x86/acloud "$@"
1705 ;;
1706 *)
1707 echo "acloud is not supported on your host arch: $host_os_arch"
1708 ;;
1709 esac
1710}
1711
patricktu345c9ae2018-11-29 15:25:40 +08001712function aidegen()
1713{
1714 # Always use the prebuilt version.
1715 local host_os_arch=$(get_build_var HOST_PREBUILT_TAG)
1716 case $host_os_arch in
1717 linux-x86) "$(gettop)"/prebuilts/asuite/aidegen/linux-x86/aidegen "$@"
1718 ;;
1719 *)
1720 echo "aidegen is not supported on your host arch: $host_os_arch"
1721 ;;
1722 esac
1723}
1724
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001725# Execute the contents of any vendorsetup.sh files we can find.
Jim Tanga881a252018-06-19 16:34:41 +08001726function source_vendorsetup() {
1727 for dir in device vendor product; do
1728 for f in $(test -d $dir && \
1729 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
1730 echo "including $f"; . $f
1731 done
1732 done
1733}
Kenny Root52aa81c2011-07-15 11:07:06 -07001734
Jim Tanga881a252018-06-19 16:34:41 +08001735validate_current_shell
1736source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001737addcompletions