blob: 62a64b6059b725ecccb6984ce665d5b84c1964ce [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
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800775 if [ "$1" ]; then
776 \cd $1
777 fi;
Christopher Ferris55257d22017-03-23 11:08:58 -0700778 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700780 T=`PWD= /bin/pwd`
Colin Cross86425252016-05-26 15:32:15 -0700781 if [ -f "$T/Android.mk" -o -f "$T/Android.bp" ]; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700782 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800783 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784 return
785 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800786 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700787 done
Ying Wang9cd17642012-12-13 10:52:07 -0800788 \cd $HERE
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700789 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700790}
791
792function mm()
793{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800794 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700795 # If we're sitting in the root of the build tree, just do a
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700796 # normal build.
797 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800798 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700799 else
800 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800801 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700802 local MODULES=
803 local GET_INSTALL_PATH=
804 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700805 # Remove the path to top as the makefilepath needs to be relative
806 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700807 if [ ! "$T" ]; then
808 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700809 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700810 elif [ ! "$M" ]; then
811 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700812 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700813 else
Christopher Ferris55257d22017-03-23 11:08:58 -0700814 local ARG
Ying Wanga7deb082013-08-16 13:24:47 -0700815 for ARG in $@; do
816 case $ARG in
817 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
818 esac
819 done
820 if [ -n "$GET_INSTALL_PATH" ]; then
821 MODULES=
Dan Willemsen53e38992016-08-11 17:20:33 -0700822 ARGS=GET-INSTALL-PATH-IN-$(dirname ${M})
823 ARGS=${ARGS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700824 else
Colin Cross86425252016-05-26 15:32:15 -0700825 MODULES=MODULES-IN-$(dirname ${M})
826 # Convert "/" to "-".
827 MODULES=${MODULES//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700828 ARGS=$@
829 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700830 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
831 MODULES=tidy_only
832 fi
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800833 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 -0700834 fi
835 fi
836}
837
838function mmm()
839{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800840 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700841 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800842 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800843 local MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700844 local MODULES_IN_PATHS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800845 local ARGS=
846 local DIR TO_CHOP
Colin Cross86425252016-05-26 15:32:15 -0700847 local DIR_MODULES
Ying Wanga7deb082013-08-16 13:24:47 -0700848 local GET_INSTALL_PATH=
Dan Willemsen53e38992016-08-11 17:20:33 -0700849 local GET_INSTALL_PATHS=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800850 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
851 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
852 for DIR in $DIRS ; do
Colin Cross86425252016-05-26 15:32:15 -0700853 DIR_MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
Alon Albert68895a92011-11-30 12:40:19 -0800854 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
Colin Cross86425252016-05-26 15:32:15 -0700855 # Remove the leading ./ and trailing / if any exists.
856 DIR=${DIR#./}
857 DIR=${DIR%/}
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800858 local M
859 if [ "$DIR_MODULES" = "" ]; then
860 M=$(findmakefile $DIR)
861 else
862 # Only check the target directory if a module is specified.
863 if [ -f $DIR/Android.mk -o -f $DIR/Android.bp ]; then
864 local HERE=$PWD
865 cd $DIR
866 M=`PWD= /bin/pwd`
867 M=$M/Android.mk
868 cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700869 fi
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800870 fi
871 if [ "$M" ]; then
872 # Remove the path to top as the makefilepath needs to be relative
873 local M=`echo $M|sed 's:'$T'/::'`
Colin Cross4bfae062016-08-31 17:22:36 -0700874 if [ "$DIR_MODULES" = "" ]; then
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800875 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$(dirname ${M})"
876 GET_INSTALL_PATHS="$GET_INSTALL_PATHS GET-INSTALL-PATH-IN-$(dirname ${M})"
Colin Cross4bfae062016-08-31 17:22:36 -0700877 else
878 MODULES="$MODULES $DIR_MODULES"
879 fi
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800880 MAKEFILE="$MAKEFILE $M"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700881 else
Ying Wanga7deb082013-08-16 13:24:47 -0700882 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700883 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700884 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
Abhinav1997a72a6e72015-10-18 20:25:48 +0200885 *) if [ -d $DIR ]; then
886 echo "No Android.mk in $DIR.";
887 else
888 echo "Couldn't locate the directory $DIR";
889 fi
890 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700891 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700892 fi
893 done
Ying Wanga7deb082013-08-16 13:24:47 -0700894 if [ -n "$GET_INSTALL_PATH" ]; then
Dan Willemsen53e38992016-08-11 17:20:33 -0700895 ARGS=${GET_INSTALL_PATHS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700896 MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700897 MODULES_IN_PATHS=
Ying Wanga7deb082013-08-16 13:24:47 -0700898 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700899 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
900 MODULES=tidy_only
Colin Cross86425252016-05-26 15:32:15 -0700901 MODULES_IN_PATHS=
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700902 fi
Colin Cross86425252016-05-26 15:32:15 -0700903 # Convert "/" to "-".
904 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800905 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 -0700906 else
907 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700908 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700909 fi
910}
911
Ying Wangb607f7b2013-02-08 18:01:04 -0800912function mma()
913{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800914 local T=$(gettop)
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700915 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800916 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800917 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800918 if [ ! "$T" ]; then
919 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700920 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800921 fi
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700922 local M=$(findmakefile || echo $(realpath $PWD)/Android.mk)
Colin Cross127fcea2016-09-01 15:30:18 -0700923 # Remove the path to top as the makefilepath needs to be relative
924 local M=`echo $M|sed 's:'$T'/::'`
925 local MODULES_IN_PATHS=MODULES-IN-$(dirname ${M})
Ying Wang61cd8842015-09-24 16:19:19 -0700926 # Convert "/" to "-".
927 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800928 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@ $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800929 fi
930}
931
932function mmma()
933{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800934 local T=$(gettop)
Ying Wangb607f7b2013-02-08 18:01:04 -0800935 if [ "$T" ]; then
936 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
937 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
938 local MY_PWD=`PWD= /bin/pwd`
939 if [ "$MY_PWD" = "$T" ]; then
940 MY_PWD=
941 else
942 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
943 fi
944 local DIR=
Ying Wangcaeaa082015-09-23 16:08:55 -0700945 local MODULES_IN_PATHS=
Ying Wangb607f7b2013-02-08 18:01:04 -0800946 local ARGS=
947 for DIR in $DIRS ; do
948 if [ -d $DIR ]; then
Ying Wangcaeaa082015-09-23 16:08:55 -0700949 # Remove the leading ./ and trailing / if any exists.
950 DIR=${DIR#./}
951 DIR=${DIR%/}
952 if [ "$MY_PWD" != "" ]; then
953 DIR=$MY_PWD/$DIR
Ying Wangb607f7b2013-02-08 18:01:04 -0800954 fi
Ying Wang61cd8842015-09-24 16:19:19 -0700955 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
Ying Wangb607f7b2013-02-08 18:01:04 -0800956 else
957 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700958 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800959 *) echo "Couldn't find directory $DIR"; return 1;;
960 esac
961 fi
962 done
Ying Wang61cd8842015-09-24 16:19:19 -0700963 # Convert "/" to "-".
964 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800965 _wrap_build $T/build/soong/soong_ui.bash --make-mode $DASH_ARGS $ARGS $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800966 else
967 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700968 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800969 fi
970}
971
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700972function croot()
973{
Christopher Ferris55257d22017-03-23 11:08:58 -0700974 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700975 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700976 if [ "$1" ]; then
977 \cd $(gettop)/$1
978 else
979 \cd $(gettop)
980 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700981 else
982 echo "Couldn't locate the top of the tree. Try setting TOP."
983 fi
984}
985
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700986function cproj()
987{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700988 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700989 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700990 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700991 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
992 T=$PWD
993 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800994 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700995 return
996 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800997 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700998 done
Ying Wang9cd17642012-12-13 10:52:07 -0800999 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001000 echo "can't find Android.mk"
1001}
1002
Daniel Sandler47e0a882013-07-30 13:23:52 -04001003# simplified version of ps; output in the form
1004# <pid> <procname>
1005function qpid() {
1006 local prepend=''
1007 local append=''
1008 if [ "$1" = "--exact" ]; then
1009 prepend=' '
1010 append='$'
1011 shift
1012 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001013 echo "usage: qpid [[--exact] <process name|pid>"
1014 return 255
1015 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001016
1017 local EXE="$1"
1018 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001019 qpid | \grep "$prepend$EXE$append"
1020 else
1021 adb shell ps \
1022 | tr -d '\r' \
1023 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1024 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001025}
1026
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001027# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001028# that has the core-file-size limit set correctly
1029#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001030# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001031# if its core-file-size limit is not set already.
1032# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1033
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001034function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001035{
Ying Wang08800fd2016-03-03 20:57:21 -08001036 echo "Getting root...";
1037 adb root;
1038 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001039
Ying Wang08800fd2016-03-03 20:57:21 -08001040 echo "Remounting root partition read-write...";
1041 adb shell mount -w -o remount -t rootfs rootfs;
1042 sleep 1;
1043 adb wait-for-device;
1044 adb shell mkdir -p /cores;
1045 adb shell mount -t tmpfs tmpfs /cores;
1046 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001047
Ying Wang08800fd2016-03-03 20:57:21 -08001048 echo "Granting SELinux permission to dump in /cores...";
1049 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001050
Ying Wang08800fd2016-03-03 20:57:21 -08001051 echo "Set core pattern.";
1052 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001053
Ying Wang08800fd2016-03-03 20:57:21 -08001054 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001055}
1056
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001057# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001058# $1 = PID of process (e.g., $(pid mediaserver))
1059#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001060# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001061# dump to actually be generated.
1062
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001063function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001064{
Ying Wang08800fd2016-03-03 20:57:21 -08001065 local PID=$1;
1066 if [ -z "$PID" ]; then
1067 printf "Expecting a PID!\n";
1068 return;
1069 fi;
1070 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001071 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001072}
1073
1074# core - send SIGV and pull the core for process
1075# $1 = PID of process (e.g., $(pid mediaserver))
1076#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001077# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001078# enabled globally.
1079
1080function core()
1081{
Ying Wang08800fd2016-03-03 20:57:21 -08001082 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001083
Ying Wang08800fd2016-03-03 20:57:21 -08001084 if [ -z "$PID" ]; then
1085 printf "Expecting a PID!\n";
1086 return;
1087 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001088
Ying Wang08800fd2016-03-03 20:57:21 -08001089 local CORENAME=core.$PID;
1090 local COREPATH=/cores/$CORENAME;
1091 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001092
Ying Wang08800fd2016-03-03 20:57:21 -08001093 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001094
Ying Wang08800fd2016-03-03 20:57:21 -08001095 local done=0;
1096 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1097 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1098 adb shell kill -$SIG $PID;
1099 sleep 1;
1100 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001101
Ying Wang08800fd2016-03-03 20:57:21 -08001102 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1103 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001104}
1105
Christopher Tate744ee802009-11-12 15:33:08 -08001106# systemstack - dump the current stack trace of all threads in the system process
1107# to the usual ANR traces file
1108function systemstack()
1109{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001110 stacks system_server
1111}
1112
Michael Wrightaeed7212014-06-19 19:58:12 -07001113# Read the ELF header from /proc/$PID/exe to determine if the process is
1114# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001115function is64bit()
1116{
1117 local PID="$1"
1118 if [ "$PID" ] ; then
Elliott Hughesd3e47252018-11-15 16:32:14 -08001119 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001120 echo "64"
1121 else
1122 echo ""
1123 fi
1124 else
1125 echo ""
1126 fi
1127}
1128
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001129case `uname -s` in
1130 Darwin)
1131 function sgrep()
1132 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001133 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 -04001134 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001135 }
1136
1137 ;;
1138 *)
1139 function sgrep()
1140 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001141 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 -04001142 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001143 }
1144 ;;
1145esac
1146
Raghu Gandham8da43102012-07-25 19:57:22 -07001147function gettargetarch
1148{
1149 get_build_var TARGET_ARCH
1150}
1151
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001152function ggrep()
1153{
Mike Frysinger5e479732015-09-22 18:13:48 -04001154 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1155 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001156}
1157
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001158function jgrep()
1159{
Mike Frysinger5e479732015-09-22 18:13:48 -04001160 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1161 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001162}
1163
1164function cgrep()
1165{
Mike Frysinger5e479732015-09-22 18:13:48 -04001166 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' \) \
1167 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001168}
1169
1170function resgrep()
1171{
Christopher Ferris55257d22017-03-23 11:08:58 -07001172 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001173 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1174 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1175 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001176}
1177
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001178function mangrep()
1179{
Mike Frysinger5e479732015-09-22 18:13:48 -04001180 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1181 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001182}
1183
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001184function sepgrep()
1185{
Mike Frysinger5e479732015-09-22 18:13:48 -04001186 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1187 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001188}
1189
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001190function rcgrep()
1191{
Mike Frysinger5e479732015-09-22 18:13:48 -04001192 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1193 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001194}
1195
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001196case `uname -s` in
1197 Darwin)
1198 function mgrep()
1199 {
David Grossd1d6fc52017-05-10 10:49:44 -07001200 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 -04001201 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001202 }
1203
1204 function treegrep()
1205 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001206 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 -04001207 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001208 }
1209
1210 ;;
1211 *)
1212 function mgrep()
1213 {
David Grossd1d6fc52017-05-10 10:49:44 -07001214 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 -04001215 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001216 }
1217
1218 function treegrep()
1219 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001220 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 -04001221 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001222 }
1223
1224 ;;
1225esac
1226
1227function getprebuilt
1228{
1229 get_abs_build_var ANDROID_PREBUILTS
1230}
1231
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001232function tracedmdump()
1233{
Christopher Ferris55257d22017-03-23 11:08:58 -07001234 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001235 if [ ! "$T" ]; then
1236 echo "Couldn't locate the top of the tree. Try setting TOP."
1237 return
1238 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001239 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001240 local arch=$(gettargetarch)
1241 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001242
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001243 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001244 if [ ! "$TRACE" ] ; then
1245 echo "usage: tracedmdump tracename"
1246 return
1247 fi
1248
Jack Veenstra60116fc2009-04-09 18:12:34 -07001249 if [ ! -r "$KERNEL" ] ; then
1250 echo "Error: cannot find kernel: '$KERNEL'"
1251 return
1252 fi
1253
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001254 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001255 if [ "$BASETRACE" = "$TRACE" ] ; then
1256 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1257 fi
1258
1259 echo "post-processing traces..."
1260 rm -f $TRACE/qtrace.dexlist
1261 post_trace $TRACE
1262 if [ $? -ne 0 ]; then
1263 echo "***"
1264 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1265 echo "***"
1266 return
1267 fi
1268 echo "generating dexlist output..."
1269 /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
1270 echo "generating dmtrace data..."
1271 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1272 echo "generating html file..."
1273 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1274 echo "done, see $TRACE/dmtrace.html for details"
1275 echo "or run:"
1276 echo " traceview $TRACE/dmtrace"
1277}
1278
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001279# communicate with a running device or emulator, set up necessary state,
1280# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001281function runhat()
1282{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001283 # process standard adb options
1284 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001285 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001286 adbTarget=$1
1287 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001288 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001289 adbTarget="$1 $2"
1290 shift 2
1291 fi
1292 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001293 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001294
1295 # runhat options
1296 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001297
1298 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001299 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001300 return
1301 fi
1302
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001303 # confirm hat is available
1304 if [ -z $(which hat) ]; then
1305 echo "hat is not available in this configuration."
1306 return
1307 fi
1308
Andy McFaddenb6289852010-07-12 08:00:19 -07001309 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001310 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001311 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001312 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001313 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001314 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001315 echo -n "> "
1316 read
1317
The Android Open Source Project88b60792009-03-03 19:28:42 -08001318 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001319
The Android Open Source Project88b60792009-03-03 19:28:42 -08001320 echo "Retrieving file $devFile..."
1321 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001322
The Android Open Source Project88b60792009-03-03 19:28:42 -08001323 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001324
The Android Open Source Project88b60792009-03-03 19:28:42 -08001325 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001326 echo "View the output by pointing your browser at http://localhost:7000/"
1327 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001328 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001329}
1330
1331function getbugreports()
1332{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001333 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001334
1335 if [ ! "$reports" ]; then
1336 echo "Could not locate any bugreports."
1337 return
1338 fi
1339
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001340 local report
1341 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001342 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001343 echo "/sdcard/bugreports/${report}"
1344 adb pull /sdcard/bugreports/${report} ${report}
1345 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001346 done
1347}
1348
Victoria Lease1b296b42012-08-21 15:44:06 -07001349function getsdcardpath()
1350{
1351 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1352}
1353
1354function getscreenshotpath()
1355{
1356 echo "$(getsdcardpath)/Pictures/Screenshots"
1357}
1358
1359function getlastscreenshot()
1360{
1361 local screenshot_path=$(getscreenshotpath)
1362 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1363 if [ "$screenshot" = "" ]; then
1364 echo "No screenshots found."
1365 return
1366 fi
1367 echo "${screenshot}"
1368 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1369}
1370
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001371function startviewserver()
1372{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001373 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001374 if [ $# -gt 0 ]; then
1375 port=$1
1376 fi
1377 adb shell service call window 1 i32 $port
1378}
1379
1380function stopviewserver()
1381{
1382 adb shell service call window 2
1383}
1384
1385function isviewserverstarted()
1386{
1387 adb shell service call window 3
1388}
1389
Romain Guyb84049a2010-10-04 16:56:11 -07001390function key_home()
1391{
1392 adb shell input keyevent 3
1393}
1394
1395function key_back()
1396{
1397 adb shell input keyevent 4
1398}
1399
1400function key_menu()
1401{
1402 adb shell input keyevent 82
1403}
1404
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001405function smoketest()
1406{
1407 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1408 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1409 return
1410 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001411 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001412 if [ ! "$T" ]; then
1413 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1414 return
1415 fi
1416
Ying Wang9cd17642012-12-13 10:52:07 -08001417 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001418 adb uninstall com.android.smoketest > /dev/null &&
1419 adb uninstall com.android.smoketest.tests > /dev/null &&
1420 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1421 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1422 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1423}
1424
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001425# simple shortcut to the runtest command
1426function runtest()
1427{
Christopher Ferris55257d22017-03-23 11:08:58 -07001428 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001429 if [ ! "$T" ]; then
1430 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1431 return
1432 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001433 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001434}
1435
The Android Open Source Project88b60792009-03-03 19:28:42 -08001436function godir () {
1437 if [[ -z "$1" ]]; then
1438 echo "Usage: godir <regex>"
1439 return
1440 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001441 local T=$(gettop)
1442 local FILELIST
Brian Carlstromf2257422015-09-30 20:28:54 -07001443 if [ ! "$OUT_DIR" = "" ]; then
1444 mkdir -p $OUT_DIR
1445 FILELIST=$OUT_DIR/filelist
1446 else
1447 FILELIST=$T/filelist
1448 fi
1449 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001450 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001451 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001452 echo " Done"
1453 echo ""
1454 fi
1455 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001456 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001457 if [[ ${#lines[@]} = 0 ]]; then
1458 echo "Not found"
1459 return
1460 fi
1461 local pathname
1462 local choice
1463 if [[ ${#lines[@]} > 1 ]]; then
1464 while [[ -z "$pathname" ]]; do
1465 local index=1
1466 local line
1467 for line in ${lines[@]}; do
1468 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001469 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001470 done
1471 echo
1472 echo -n "Select one: "
1473 unset choice
1474 read choice
1475 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1476 echo "Invalid choice"
1477 continue
1478 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001479 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001480 done
1481 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001482 pathname=${lines[0]}
1483 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001484 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001485}
1486
Steven Moreland62054a42018-12-06 10:11:40 -08001487# Update module-info.json in out.
1488function refreshmod() {
1489 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1490 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1491 return 1
1492 fi
1493
1494 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1495
1496 # for the output of the next command
1497 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1498
1499 # Note, can't use absolute path because of the way make works.
1500 m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \
1501 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1502}
1503
1504# List all modules for the current device, as cached in module-info.json. If any build change is
1505# made and it should be reflected in the output, you should run 'refreshmod' first.
1506function allmod() {
1507 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1508 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1509 return 1
1510 fi
1511
1512 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1513 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1514 refreshmod || return 1
1515 fi
1516
1517 python -c "import json; print '\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys()))"
1518}
1519
1520# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1521# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1522function gomod() {
1523 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1524 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1525 return 1
1526 fi
1527
1528 if [[ $# -ne 1 ]]; then
1529 echo "usage: gomod <module>" >&2
1530 return 1
1531 fi
1532
1533 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1534 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1535 refreshmod || return 1
1536 fi
1537
1538 local relpath=$(python -c "import json, os
1539module = '$1'
1540module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1541if module not in module_info:
1542 exit(1)
1543print module_info[module]['path'][0]" 2>/dev/null)
1544
1545 if [ -z "$relpath" ]; then
1546 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1547 return 1
1548 else
1549 cd $ANDROID_BUILD_TOP/$relpath
1550 fi
1551}
1552
dimitry73b84812018-12-11 18:06:00 +01001553function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001554 local word=${COMP_WORDS[COMP_CWORD]}
1555 COMPREPLY=( $(allmod | grep -E "^$word") )
1556}
1557
Alex Rayf0d08eb2013-03-08 15:15:06 -08001558# Print colored exit condition
1559function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001560 "$@"
1561 local retval=$?
1562 if [ $retval -ne 0 ]
1563 then
Jacky Cao89483b82015-05-15 22:12:53 +08001564 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001565 else
Jacky Cao89483b82015-05-15 22:12:53 +08001566 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001567 fi
1568 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001569}
1570
Ying Wanged21d4c2014-08-24 22:14:19 -07001571function get_make_command()
1572{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001573 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1574 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001575 # Always use the real make if -C is passed in
1576 for arg in "$@"; do
1577 if [[ $arg == -C* ]]; then
1578 echo command make
1579 return
1580 fi
1581 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001582 echo build/soong/soong_ui.bash --make-mode
1583 else
1584 echo command make
1585 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001586}
1587
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001588function _wrap_build()
Ed Heylcc6be0a2014-06-18 14:55:58 -07001589{
1590 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001591 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001592 local ret=$?
1593 local end_time=$(date +"%s")
1594 local tdiff=$(($end_time-$start_time))
1595 local hours=$(($tdiff / 3600 ))
1596 local mins=$((($tdiff % 3600) / 60))
1597 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001598 local ncolors=$(tput colors 2>/dev/null)
1599 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001600 color_failed=$'\E'"[0;31m"
1601 color_success=$'\E'"[0;32m"
1602 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001603 else
1604 color_failed=""
1605 color_success=""
1606 color_reset=""
1607 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001608 echo
1609 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001610 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001611 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001612 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001613 fi
1614 if [ $hours -gt 0 ] ; then
1615 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1616 elif [ $mins -gt 0 ] ; then
1617 printf "(%02g:%02g (mm:ss))" $mins $secs
1618 elif [ $secs -gt 0 ] ; then
1619 printf "(%s seconds)" $secs
1620 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001621 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001622 echo
1623 return $ret
1624}
1625
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001626function make()
1627{
Dan Willemsene9842242017-07-28 13:00:13 -07001628 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001629}
1630
David Zeuthen1b126ff2015-09-30 17:10:48 -04001631function provision()
1632{
1633 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1634 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1635 return 1
1636 fi
1637 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1638 echo "There is no provisioning script for the device." >&2
1639 return 1
1640 fi
1641
1642 # Check if user really wants to do this.
1643 if [ "$1" = "--no-confirmation" ]; then
1644 shift 1
1645 else
1646 echo "This action will reflash your device."
1647 echo ""
1648 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1649 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001650 echo -n "Are you sure you want to do this (yes/no)? "
1651 read
David Zeuthen1b126ff2015-09-30 17:10:48 -04001652 if [[ "${REPLY}" != "yes" ]] ; then
1653 echo "Not taking any action. Exiting." >&2
1654 return 1
1655 fi
1656 fi
1657 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1658}
1659
Simran Basi424b8762017-08-23 12:03:04 -07001660function atest()
1661{
Jim Tangf258e7e2018-11-01 18:00:05 +08001662 # Let's use the built version over the prebuilt, then source code.
1663 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
1664 local built_atest=${ANDROID_HOST_OUT}/bin/atest
1665 local prebuilt_atest="$(gettop)"/prebuilts/asuite/atest/$os_arch/atest
1666 if [[ -x $built_atest ]]; then
1667 $built_atest "$@"
1668 elif [[ -x $prebuilt_atest ]]; then
1669 $prebuilt_atest "$@"
1670 else
1671 # TODO: once prebuilt atest released, remove the source code section
1672 # and change the location of atest_completion.sh in addcompletions().
1673 "$(gettop)"/tools/tradefederation/core/atest/atest.py "$@"
1674 fi
Simran Basi424b8762017-08-23 12:03:04 -07001675}
1676
Jim Tanga881a252018-06-19 16:34:41 +08001677# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001678function enable_zsh_completion() {
1679 # Don't override user's options if bash-style completion is already enabled.
1680 if ! declare -f complete >/dev/null; then
1681 autoload -U compinit && compinit
1682 autoload -U bashcompinit && bashcompinit
1683 fi
Jim Tanga881a252018-06-19 16:34:41 +08001684}
1685
1686function validate_current_shell() {
1687 local current_sh="$(ps -o command -p $$)"
1688 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001689 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001690 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001691 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001692 *zsh*)
1693 function check_type() { type "$1"; }
Patrik Fimmldf248e62018-10-15 18:15:12 +02001694 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001695 *)
Jim Tanga881a252018-06-19 16:34:41 +08001696 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 -07001697 ;;
1698 esac
Jim Tanga881a252018-06-19 16:34:41 +08001699}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001700
Kevin Chengbf89aff2018-05-22 14:07:50 -07001701function acloud()
1702{
1703 # Let's use the built version over the prebuilt.
1704 local built_acloud=${ANDROID_HOST_OUT}/bin/acloud
1705 if [ -f $built_acloud ]; then
1706 $built_acloud "$@"
1707 return $?
1708 fi
1709
1710 local host_os_arch=$(get_build_var HOST_PREBUILT_TAG)
1711 case $host_os_arch in
1712 linux-x86) "$(gettop)"/prebuilts/asuite/acloud/linux-x86/acloud "$@"
1713 ;;
1714 *)
1715 echo "acloud is not supported on your host arch: $host_os_arch"
1716 ;;
1717 esac
1718}
1719
patricktu345c9ae2018-11-29 15:25:40 +08001720function aidegen()
1721{
1722 # Always use the prebuilt version.
1723 local host_os_arch=$(get_build_var HOST_PREBUILT_TAG)
1724 case $host_os_arch in
1725 linux-x86) "$(gettop)"/prebuilts/asuite/aidegen/linux-x86/aidegen "$@"
1726 ;;
1727 *)
1728 echo "aidegen is not supported on your host arch: $host_os_arch"
1729 ;;
1730 esac
1731}
1732
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001733# Execute the contents of any vendorsetup.sh files we can find.
Jim Tanga881a252018-06-19 16:34:41 +08001734function source_vendorsetup() {
1735 for dir in device vendor product; do
1736 for f in $(test -d $dir && \
1737 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
1738 echo "including $f"; . $f
1739 done
1740 done
1741}
Kenny Root52aa81c2011-07-15 11:07:06 -07001742
Jim Tanga881a252018-06-19 16:34:41 +08001743validate_current_shell
1744source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001745addcompletions