blob: 21b5aa70816b4bfd1562807e9920d8ffebba1ae4 [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
Jim Tangdda51d42018-12-22 10:24:55 +0800268 # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
269 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
270 local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch:"
271 local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch:"
272 local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch:"
273 export ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ACLOUD_PATH$AIDEGEN_PATH$ATEST_PATH
274
Ying Wangaa1c9b52012-11-26 20:51:59 -0800275 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800276
277 # out with the duplicate old
278 if [ -n $ANDROID_PYTHONPATH ]; then
279 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
280 fi
281 # and in with the new
282 export ANDROID_PYTHONPATH=$T/development/python-packages:
283 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800284
Colin Crosse97e6932017-06-30 16:01:45 -0700285 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
286 export JAVA_HOME=$ANDROID_JAVA_HOME
287 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
288 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
289 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500290
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800291 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700292 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
293 export OUT=$ANDROID_PRODUCT_OUT
294
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700295 unset ANDROID_HOST_OUT
296 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
297
Simran Basidd050ed2017-02-13 13:46:48 -0800298 unset ANDROID_HOST_OUT_TESTCASES
299 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
300
301 unset ANDROID_TARGET_OUT_TESTCASES
302 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
303
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800304 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700305 # TODO: fix the path
306 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
307}
308
309function printconfig()
310{
Christopher Ferris55257d22017-03-23 11:08:58 -0700311 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800312 if [ ! "$T" ]; then
313 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
314 return
315 fi
316 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317}
318
319function set_stuff_for_environment()
320{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800321 setpaths
322 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700323
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800324 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700325 # With this environment variable new GCC can apply colors to warnings/errors
326 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 -0700327 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700328}
329
330function set_sequence_number()
331{
Colin Cross88737132017-03-21 17:41:03 -0700332 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700333}
334
Makoto Onukida971062018-06-18 10:15:19 -0700335# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
336function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800337 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700338 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800339 *:"$cmd":*)
340 return 1
341 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700342 esac
343 return 0
344}
345
Kenny Root52aa81c2011-07-15 11:07:06 -0700346function addcompletions()
347{
348 local T dir f
349
Jim Tanga881a252018-06-19 16:34:41 +0800350 # Keep us from trying to run in something that's neither bash nor zsh.
351 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700352 return
353 fi
354
355 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800356 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700357 return
358 fi
359
Jim Tanga881a252018-06-19 16:34:41 +0800360 local completion_files=(
361 system/core/adb/adb.bash
362 system/core/fastboot/fastboot.bash
Jim Tangdda51d42018-12-22 10:24:55 +0800363 tools/asuite/asuite.sh
Jim Tanga881a252018-06-19 16:34:41 +0800364 )
Makoto Onukida971062018-06-18 10:15:19 -0700365 # Completion can be disabled selectively to allow users to use non-standard completion.
366 # e.g.
367 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
368 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800369 for f in ${completion_files[*]}; do
370 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700371 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700372 fi
373 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700374
Makoto Onukida971062018-06-18 10:15:19 -0700375 if should_add_completion bit ; then
376 complete -C "bit --tab" bit
377 fi
Jim Tanga881a252018-06-19 16:34:41 +0800378 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800379
dimitry73b84812018-12-11 18:06:00 +0100380 complete -F _complete_android_module_names gomod
381 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700382}
383
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700384function choosetype()
385{
386 echo "Build type choices are:"
387 echo " 1. release"
388 echo " 2. debug"
389 echo
390
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800391 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700392 DEFAULT_NUM=1
393 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700394
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800395 export TARGET_BUILD_TYPE=
396 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700397 while [ -z $TARGET_BUILD_TYPE ]
398 do
399 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800400 if [ -z "$1" ] ; then
401 read ANSWER
402 else
403 echo $1
404 ANSWER=$1
405 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700406 case $ANSWER in
407 "")
408 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
409 ;;
410 1)
411 export TARGET_BUILD_TYPE=release
412 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800413 release)
414 export TARGET_BUILD_TYPE=release
415 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700416 2)
417 export TARGET_BUILD_TYPE=debug
418 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800419 debug)
420 export TARGET_BUILD_TYPE=debug
421 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700422 *)
423 echo
424 echo "I didn't understand your response. Please try again."
425 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700426 ;;
427 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800428 if [ -n "$1" ] ; then
429 break
430 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700431 done
432
Ying Wang08800fd2016-03-03 20:57:21 -0800433 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700434 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800435 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700436}
437
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800438#
439# This function isn't really right: It chooses a TARGET_PRODUCT
440# based on the list of boards. Usually, that gets you something
441# that kinda works with a generic product, but really, you should
442# pick a product by name.
443#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444function chooseproduct()
445{
Christopher Ferris55257d22017-03-23 11:08:58 -0700446 local default_value
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700447 if [ "x$TARGET_PRODUCT" != x ] ; then
448 default_value=$TARGET_PRODUCT
449 else
Ying Wang0a76df52015-06-08 11:57:26 -0700450 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700451 fi
452
Ying Wang08800fd2016-03-03 20:57:21 -0800453 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800454 export TARGET_PRODUCT=
455 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700456 while [ -z "$TARGET_PRODUCT" ]
457 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700458 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800459 if [ -z "$1" ] ; then
460 read ANSWER
461 else
462 echo $1
463 ANSWER=$1
464 fi
465
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700466 if [ -z "$ANSWER" ] ; then
467 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800468 else
469 if check_product $ANSWER
470 then
471 export TARGET_PRODUCT=$ANSWER
472 else
473 echo "** Not a valid product: $ANSWER"
474 fi
475 fi
476 if [ -n "$1" ] ; then
477 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478 fi
479 done
480
Ying Wang08800fd2016-03-03 20:57:21 -0800481 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700482 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800483 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700484}
485
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486function choosevariant()
487{
488 echo "Variant choices are:"
489 local index=1
490 local v
491 for v in ${VARIANT_CHOICES[@]}
492 do
493 # The product name is the name of the directory containing
494 # the makefile we found, above.
495 echo " $index. $v"
496 index=$(($index+1))
497 done
498
499 local default_value=eng
500 local ANSWER
501
502 export TARGET_BUILD_VARIANT=
503 while [ -z "$TARGET_BUILD_VARIANT" ]
504 do
505 echo -n "Which would you like? [$default_value] "
506 if [ -z "$1" ] ; then
507 read ANSWER
508 else
509 echo $1
510 ANSWER=$1
511 fi
512
513 if [ -z "$ANSWER" ] ; then
514 export TARGET_BUILD_VARIANT=$default_value
515 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
516 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800517 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800518 fi
519 else
520 if check_variant $ANSWER
521 then
522 export TARGET_BUILD_VARIANT=$ANSWER
523 else
524 echo "** Not a valid variant: $ANSWER"
525 fi
526 fi
527 if [ -n "$1" ] ; then
528 break
529 fi
530 done
531}
532
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700533function choosecombo()
534{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700535 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700536
537 echo
538 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700539 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700540
541 echo
542 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700543 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800544
545 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800546 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700547 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800548 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800549 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700550}
551
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800552# Clear this variable. It will be built up again when the vendorsetup.sh
553# files are included at the end of this file.
554unset LUNCH_MENU_CHOICES
555function add_lunch_combo()
556{
557 local new_combo=$1
558 local c
559 for c in ${LUNCH_MENU_CHOICES[@]} ; do
560 if [ "$new_combo" = "$c" ] ; then
561 return
562 fi
563 done
564 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
565}
566
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700567function print_lunch_menu()
568{
569 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700570 echo
571 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700572 echo
573 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800574
575 local i=1
576 local choice
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700577 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 -0800578 do
579 echo " $i. $choice"
580 i=$(($i+1))
581 done
582
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700583 echo
584}
585
586function lunch()
587{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800588 local answer
589
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800591 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592 else
593 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700594 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800595 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596 fi
597
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598 local selection=
599
600 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700601 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700602 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
604 then
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700605 local choices=($(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES))
606 if [ $answer -le ${#choices[@]} ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800607 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800608 # array in zsh starts from 1 instead of 0.
609 if [ -n "$ZSH_VERSION" ]
610 then
611 selection=${choices[$(($answer))]}
612 else
613 selection=${choices[$(($answer-1))]}
614 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800615 fi
Colin Cross88737132017-03-21 17:41:03 -0700616 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800617 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700618 fi
619
Joe Onoratoda12daf2010-06-09 18:18:31 -0700620 export TARGET_BUILD_APPS=
621
Colin Cross88737132017-03-21 17:41:03 -0700622 local product variant_and_version variant version
623
624 product=${selection%%-*} # Trim everything after first dash
625 variant_and_version=${selection#*-} # Trim everything up to first dash
626 if [ "$variant_and_version" != "$selection" ]; then
627 variant=${variant_and_version%%-*}
628 if [ "$variant" != "$variant_and_version" ]; then
629 version=${variant_and_version#*-}
630 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700631 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800632
Colin Cross88737132017-03-21 17:41:03 -0700633 if [ -z "$product" ]
Ying Wang08800fd2016-03-03 20:57:21 -0800634 then
635 echo
Colin Cross88737132017-03-21 17:41:03 -0700636 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700637 return 1
638 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800639
Colin Cross88737132017-03-21 17:41:03 -0700640 TARGET_PRODUCT=$product \
641 TARGET_BUILD_VARIANT=$variant \
642 TARGET_PLATFORM_VERSION=$version \
643 build_build_var_cache
644 if [ $? -ne 0 ]
645 then
646 return 1
647 fi
648
649 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
650 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700651 if [ -n "$version" ]; then
652 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
653 else
654 unset TARGET_PLATFORM_VERSION
655 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700656 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657
658 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800659
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700660 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800661 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800662 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700663}
664
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700665unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700666# Tab completion for lunch.
667function _lunch()
668{
669 local cur prev opts
670 COMPREPLY=()
671 cur="${COMP_WORDS[COMP_CWORD]}"
672 prev="${COMP_WORDS[COMP_CWORD-1]}"
673
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700674 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
675 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES)
676 fi
677
678 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700679 return 0
680}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700681
Joe Onoratoda12daf2010-06-09 18:18:31 -0700682# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700683# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700684function tapas()
685{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700686 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Dan Willemsendd3a2732018-01-08 15:26:16 -0800687 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700688 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700689 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 -0800690 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 -0700691
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700692 if [ "$showHelp" != "" ]; then
693 $(gettop)/build/make/tapasHelp.sh
694 return
695 fi
696
Ying Wang67f02922012-08-22 10:25:20 -0700697 if [ $(echo $arch | wc -w) -gt 1 ]; then
698 echo "tapas: Error: Multiple build archs supplied: $arch"
699 return
700 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700701 if [ $(echo $variant | wc -w) -gt 1 ]; then
702 echo "tapas: Error: Multiple build variants supplied: $variant"
703 return
704 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700705 if [ $(echo $density | wc -w) -gt 1 ]; then
706 echo "tapas: Error: Multiple densities supplied: $density"
707 return
708 fi
Ying Wang67f02922012-08-22 10:25:20 -0700709
Ying Wang0a76df52015-06-08 11:57:26 -0700710 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700711 case $arch in
Ying Wang0a76df52015-06-08 11:57:26 -0700712 x86) product=aosp_x86;;
713 mips) product=aosp_mips;;
Ying Wangb541ab62014-05-29 17:57:40 -0700714 arm64) product=aosp_arm64;;
715 x86_64) product=aosp_x86_64;;
716 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700717 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700718 if [ -z "$variant" ]; then
719 variant=eng
720 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700721 if [ -z "$apps" ]; then
722 apps=all
723 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600724 if [ -z "$density" ]; then
725 density=alldpi
726 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700727
Ying Wang67f02922012-08-22 10:25:20 -0700728 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700729 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700730 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700731 export TARGET_BUILD_TYPE=release
732 export TARGET_BUILD_APPS=$apps
733
Ying Wang08800fd2016-03-03 20:57:21 -0800734 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700735 set_stuff_for_environment
736 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800737 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700738}
739
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700740function gettop
741{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700742 local TOPFILE=build/make/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700743 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700744 # The following circumlocution ensures we remove symlinks from TOP.
745 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700746 else
747 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800748 # The following circumlocution (repeated below as well) ensures
749 # that we record the true directory name and not one that is
750 # faked up with symlink names.
751 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700752 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800753 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700754 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700755 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800756 \cd ..
synergyb112a402013-07-05 19:47:47 -0700757 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700758 done
Ying Wang9cd17642012-12-13 10:52:07 -0800759 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700760 if [ -f "$T/$TOPFILE" ]; then
761 echo $T
762 fi
763 fi
764 fi
765}
766
767function m()
768{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800769 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700770 if [ "$T" ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800771 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700772 else
773 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700774 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700775 fi
776}
777
778function findmakefile()
779{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700780 local TOPFILE=build/make/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800781 local HERE=$PWD
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800782 if [ "$1" ]; then
783 \cd $1
784 fi;
Christopher Ferris55257d22017-03-23 11:08:58 -0700785 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700786 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700787 T=`PWD= /bin/pwd`
Colin Cross86425252016-05-26 15:32:15 -0700788 if [ -f "$T/Android.mk" -o -f "$T/Android.bp" ]; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700789 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800790 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791 return
792 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800793 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700794 done
Ying Wang9cd17642012-12-13 10:52:07 -0800795 \cd $HERE
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700796 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797}
798
799function mm()
800{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800801 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700802 # If we're sitting in the root of the build tree, just do a
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700803 # normal build.
804 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800805 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700806 else
807 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800808 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700809 local MODULES=
810 local GET_INSTALL_PATH=
811 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700812 # Remove the path to top as the makefilepath needs to be relative
813 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700814 if [ ! "$T" ]; then
815 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700816 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700817 elif [ ! "$M" ]; then
818 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700819 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700820 else
Christopher Ferris55257d22017-03-23 11:08:58 -0700821 local ARG
Ying Wanga7deb082013-08-16 13:24:47 -0700822 for ARG in $@; do
823 case $ARG in
824 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
825 esac
826 done
827 if [ -n "$GET_INSTALL_PATH" ]; then
828 MODULES=
Dan Willemsen53e38992016-08-11 17:20:33 -0700829 ARGS=GET-INSTALL-PATH-IN-$(dirname ${M})
830 ARGS=${ARGS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700831 else
Colin Cross86425252016-05-26 15:32:15 -0700832 MODULES=MODULES-IN-$(dirname ${M})
833 # Convert "/" to "-".
834 MODULES=${MODULES//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700835 ARGS=$@
836 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700837 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
838 MODULES=tidy_only
839 fi
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800840 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 -0700841 fi
842 fi
843}
844
845function mmm()
846{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800847 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700848 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800849 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800850 local MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700851 local MODULES_IN_PATHS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800852 local ARGS=
853 local DIR TO_CHOP
Colin Cross86425252016-05-26 15:32:15 -0700854 local DIR_MODULES
Ying Wanga7deb082013-08-16 13:24:47 -0700855 local GET_INSTALL_PATH=
Dan Willemsen53e38992016-08-11 17:20:33 -0700856 local GET_INSTALL_PATHS=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800857 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
858 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
859 for DIR in $DIRS ; do
Colin Cross86425252016-05-26 15:32:15 -0700860 DIR_MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
Alon Albert68895a92011-11-30 12:40:19 -0800861 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
Colin Cross86425252016-05-26 15:32:15 -0700862 # Remove the leading ./ and trailing / if any exists.
863 DIR=${DIR#./}
864 DIR=${DIR%/}
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800865 local M
866 if [ "$DIR_MODULES" = "" ]; then
867 M=$(findmakefile $DIR)
868 else
869 # Only check the target directory if a module is specified.
870 if [ -f $DIR/Android.mk -o -f $DIR/Android.bp ]; then
871 local HERE=$PWD
872 cd $DIR
873 M=`PWD= /bin/pwd`
874 M=$M/Android.mk
875 cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700876 fi
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800877 fi
878 if [ "$M" ]; then
879 # Remove the path to top as the makefilepath needs to be relative
880 local M=`echo $M|sed 's:'$T'/::'`
Colin Cross4bfae062016-08-31 17:22:36 -0700881 if [ "$DIR_MODULES" = "" ]; then
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800882 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$(dirname ${M})"
883 GET_INSTALL_PATHS="$GET_INSTALL_PATHS GET-INSTALL-PATH-IN-$(dirname ${M})"
Colin Cross4bfae062016-08-31 17:22:36 -0700884 else
885 MODULES="$MODULES $DIR_MODULES"
886 fi
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800887 MAKEFILE="$MAKEFILE $M"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700888 else
Ying Wanga7deb082013-08-16 13:24:47 -0700889 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700890 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700891 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
Abhinav1997a72a6e72015-10-18 20:25:48 +0200892 *) if [ -d $DIR ]; then
893 echo "No Android.mk in $DIR.";
894 else
895 echo "Couldn't locate the directory $DIR";
896 fi
897 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700898 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700899 fi
900 done
Ying Wanga7deb082013-08-16 13:24:47 -0700901 if [ -n "$GET_INSTALL_PATH" ]; then
Dan Willemsen53e38992016-08-11 17:20:33 -0700902 ARGS=${GET_INSTALL_PATHS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700903 MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700904 MODULES_IN_PATHS=
Ying Wanga7deb082013-08-16 13:24:47 -0700905 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700906 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
907 MODULES=tidy_only
Colin Cross86425252016-05-26 15:32:15 -0700908 MODULES_IN_PATHS=
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700909 fi
Colin Cross86425252016-05-26 15:32:15 -0700910 # Convert "/" to "-".
911 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800912 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 -0700913 else
914 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700915 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700916 fi
917}
918
Ying Wangb607f7b2013-02-08 18:01:04 -0800919function mma()
920{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800921 local T=$(gettop)
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700922 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800923 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800924 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800925 if [ ! "$T" ]; then
926 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700927 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800928 fi
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700929 local M=$(findmakefile || echo $(realpath $PWD)/Android.mk)
Colin Cross127fcea2016-09-01 15:30:18 -0700930 # Remove the path to top as the makefilepath needs to be relative
931 local M=`echo $M|sed 's:'$T'/::'`
932 local MODULES_IN_PATHS=MODULES-IN-$(dirname ${M})
Ying Wang61cd8842015-09-24 16:19:19 -0700933 # Convert "/" to "-".
934 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800935 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@ $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800936 fi
937}
938
939function mmma()
940{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800941 local T=$(gettop)
Ying Wangb607f7b2013-02-08 18:01:04 -0800942 if [ "$T" ]; then
943 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
944 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
945 local MY_PWD=`PWD= /bin/pwd`
946 if [ "$MY_PWD" = "$T" ]; then
947 MY_PWD=
948 else
949 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
950 fi
951 local DIR=
Ying Wangcaeaa082015-09-23 16:08:55 -0700952 local MODULES_IN_PATHS=
Ying Wangb607f7b2013-02-08 18:01:04 -0800953 local ARGS=
954 for DIR in $DIRS ; do
955 if [ -d $DIR ]; then
Ying Wangcaeaa082015-09-23 16:08:55 -0700956 # Remove the leading ./ and trailing / if any exists.
957 DIR=${DIR#./}
958 DIR=${DIR%/}
959 if [ "$MY_PWD" != "" ]; then
960 DIR=$MY_PWD/$DIR
Ying Wangb607f7b2013-02-08 18:01:04 -0800961 fi
Ying Wang61cd8842015-09-24 16:19:19 -0700962 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
Ying Wangb607f7b2013-02-08 18:01:04 -0800963 else
964 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700965 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800966 *) echo "Couldn't find directory $DIR"; return 1;;
967 esac
968 fi
969 done
Ying Wang61cd8842015-09-24 16:19:19 -0700970 # Convert "/" to "-".
971 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800972 _wrap_build $T/build/soong/soong_ui.bash --make-mode $DASH_ARGS $ARGS $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800973 else
974 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700975 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800976 fi
977}
978
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700979function croot()
980{
Christopher Ferris55257d22017-03-23 11:08:58 -0700981 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700982 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700983 if [ "$1" ]; then
984 \cd $(gettop)/$1
985 else
986 \cd $(gettop)
987 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700988 else
989 echo "Couldn't locate the top of the tree. Try setting TOP."
990 fi
991}
992
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700993function cproj()
994{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700995 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700996 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700997 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700998 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
999 T=$PWD
1000 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001001 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001002 return
1003 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001004 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001005 done
Ying Wang9cd17642012-12-13 10:52:07 -08001006 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001007 echo "can't find Android.mk"
1008}
1009
Daniel Sandler47e0a882013-07-30 13:23:52 -04001010# simplified version of ps; output in the form
1011# <pid> <procname>
1012function qpid() {
1013 local prepend=''
1014 local append=''
1015 if [ "$1" = "--exact" ]; then
1016 prepend=' '
1017 append='$'
1018 shift
1019 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001020 echo "usage: qpid [[--exact] <process name|pid>"
1021 return 255
1022 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001023
1024 local EXE="$1"
1025 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001026 qpid | \grep "$prepend$EXE$append"
1027 else
1028 adb shell ps \
1029 | tr -d '\r' \
1030 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1031 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001032}
1033
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001034# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001035# that has the core-file-size limit set correctly
1036#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001037# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001038# if its core-file-size limit is not set already.
1039# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1040
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001041function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001042{
Ying Wang08800fd2016-03-03 20:57:21 -08001043 echo "Getting root...";
1044 adb root;
1045 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001046
Ying Wang08800fd2016-03-03 20:57:21 -08001047 echo "Remounting root partition read-write...";
1048 adb shell mount -w -o remount -t rootfs rootfs;
1049 sleep 1;
1050 adb wait-for-device;
1051 adb shell mkdir -p /cores;
1052 adb shell mount -t tmpfs tmpfs /cores;
1053 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001054
Ying Wang08800fd2016-03-03 20:57:21 -08001055 echo "Granting SELinux permission to dump in /cores...";
1056 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001057
Ying Wang08800fd2016-03-03 20:57:21 -08001058 echo "Set core pattern.";
1059 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001060
Ying Wang08800fd2016-03-03 20:57:21 -08001061 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001062}
1063
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001064# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001065# $1 = PID of process (e.g., $(pid mediaserver))
1066#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001067# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001068# dump to actually be generated.
1069
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001070function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001071{
Ying Wang08800fd2016-03-03 20:57:21 -08001072 local PID=$1;
1073 if [ -z "$PID" ]; then
1074 printf "Expecting a PID!\n";
1075 return;
1076 fi;
1077 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001078 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001079}
1080
1081# core - send SIGV and pull the core for process
1082# $1 = PID of process (e.g., $(pid mediaserver))
1083#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001084# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001085# enabled globally.
1086
1087function core()
1088{
Ying Wang08800fd2016-03-03 20:57:21 -08001089 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001090
Ying Wang08800fd2016-03-03 20:57:21 -08001091 if [ -z "$PID" ]; then
1092 printf "Expecting a PID!\n";
1093 return;
1094 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001095
Ying Wang08800fd2016-03-03 20:57:21 -08001096 local CORENAME=core.$PID;
1097 local COREPATH=/cores/$CORENAME;
1098 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001099
Ying Wang08800fd2016-03-03 20:57:21 -08001100 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001101
Ying Wang08800fd2016-03-03 20:57:21 -08001102 local done=0;
1103 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1104 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1105 adb shell kill -$SIG $PID;
1106 sleep 1;
1107 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001108
Ying Wang08800fd2016-03-03 20:57:21 -08001109 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1110 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001111}
1112
Christopher Tate744ee802009-11-12 15:33:08 -08001113# systemstack - dump the current stack trace of all threads in the system process
1114# to the usual ANR traces file
1115function systemstack()
1116{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001117 stacks system_server
1118}
1119
Michael Wrightaeed7212014-06-19 19:58:12 -07001120# Read the ELF header from /proc/$PID/exe to determine if the process is
1121# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001122function is64bit()
1123{
1124 local PID="$1"
1125 if [ "$PID" ] ; then
Elliott Hughesd3e47252018-11-15 16:32:14 -08001126 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001127 echo "64"
1128 else
1129 echo ""
1130 fi
1131 else
1132 echo ""
1133 fi
1134}
1135
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001136case `uname -s` in
1137 Darwin)
1138 function sgrep()
1139 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001140 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 -04001141 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001142 }
1143
1144 ;;
1145 *)
1146 function sgrep()
1147 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001148 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 -04001149 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001150 }
1151 ;;
1152esac
1153
Raghu Gandham8da43102012-07-25 19:57:22 -07001154function gettargetarch
1155{
1156 get_build_var TARGET_ARCH
1157}
1158
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001159function ggrep()
1160{
Mike Frysinger5e479732015-09-22 18:13:48 -04001161 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1162 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001163}
1164
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001165function jgrep()
1166{
Mike Frysinger5e479732015-09-22 18:13:48 -04001167 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1168 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001169}
1170
1171function cgrep()
1172{
Mike Frysinger5e479732015-09-22 18:13:48 -04001173 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' \) \
1174 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001175}
1176
1177function resgrep()
1178{
Christopher Ferris55257d22017-03-23 11:08:58 -07001179 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001180 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1181 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1182 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001183}
1184
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001185function mangrep()
1186{
Mike Frysinger5e479732015-09-22 18:13:48 -04001187 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1188 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001189}
1190
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001191function sepgrep()
1192{
Mike Frysinger5e479732015-09-22 18:13:48 -04001193 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1194 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001195}
1196
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001197function rcgrep()
1198{
Mike Frysinger5e479732015-09-22 18:13:48 -04001199 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1200 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001201}
1202
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001203case `uname -s` in
1204 Darwin)
1205 function mgrep()
1206 {
David Grossd1d6fc52017-05-10 10:49:44 -07001207 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 -04001208 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001209 }
1210
1211 function treegrep()
1212 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001213 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 -04001214 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001215 }
1216
1217 ;;
1218 *)
1219 function mgrep()
1220 {
David Grossd1d6fc52017-05-10 10:49:44 -07001221 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 -04001222 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001223 }
1224
1225 function treegrep()
1226 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001227 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 -04001228 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001229 }
1230
1231 ;;
1232esac
1233
1234function getprebuilt
1235{
1236 get_abs_build_var ANDROID_PREBUILTS
1237}
1238
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001239function tracedmdump()
1240{
Christopher Ferris55257d22017-03-23 11:08:58 -07001241 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001242 if [ ! "$T" ]; then
1243 echo "Couldn't locate the top of the tree. Try setting TOP."
1244 return
1245 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001246 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001247 local arch=$(gettargetarch)
1248 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001249
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001250 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001251 if [ ! "$TRACE" ] ; then
1252 echo "usage: tracedmdump tracename"
1253 return
1254 fi
1255
Jack Veenstra60116fc2009-04-09 18:12:34 -07001256 if [ ! -r "$KERNEL" ] ; then
1257 echo "Error: cannot find kernel: '$KERNEL'"
1258 return
1259 fi
1260
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001261 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001262 if [ "$BASETRACE" = "$TRACE" ] ; then
1263 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1264 fi
1265
1266 echo "post-processing traces..."
1267 rm -f $TRACE/qtrace.dexlist
1268 post_trace $TRACE
1269 if [ $? -ne 0 ]; then
1270 echo "***"
1271 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1272 echo "***"
1273 return
1274 fi
1275 echo "generating dexlist output..."
1276 /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
1277 echo "generating dmtrace data..."
1278 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1279 echo "generating html file..."
1280 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1281 echo "done, see $TRACE/dmtrace.html for details"
1282 echo "or run:"
1283 echo " traceview $TRACE/dmtrace"
1284}
1285
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001286# communicate with a running device or emulator, set up necessary state,
1287# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001288function runhat()
1289{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001290 # process standard adb options
1291 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001292 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001293 adbTarget=$1
1294 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001295 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001296 adbTarget="$1 $2"
1297 shift 2
1298 fi
1299 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001300 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001301
1302 # runhat options
1303 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001304
1305 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001306 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001307 return
1308 fi
1309
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001310 # confirm hat is available
1311 if [ -z $(which hat) ]; then
1312 echo "hat is not available in this configuration."
1313 return
1314 fi
1315
Andy McFaddenb6289852010-07-12 08:00:19 -07001316 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001317 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001318 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001319 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001320 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001321 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001322 echo -n "> "
1323 read
1324
The Android Open Source Project88b60792009-03-03 19:28:42 -08001325 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001326
The Android Open Source Project88b60792009-03-03 19:28:42 -08001327 echo "Retrieving file $devFile..."
1328 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001329
The Android Open Source Project88b60792009-03-03 19:28:42 -08001330 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001331
The Android Open Source Project88b60792009-03-03 19:28:42 -08001332 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001333 echo "View the output by pointing your browser at http://localhost:7000/"
1334 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001335 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001336}
1337
1338function getbugreports()
1339{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001340 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001341
1342 if [ ! "$reports" ]; then
1343 echo "Could not locate any bugreports."
1344 return
1345 fi
1346
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001347 local report
1348 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001349 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001350 echo "/sdcard/bugreports/${report}"
1351 adb pull /sdcard/bugreports/${report} ${report}
1352 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001353 done
1354}
1355
Victoria Lease1b296b42012-08-21 15:44:06 -07001356function getsdcardpath()
1357{
1358 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1359}
1360
1361function getscreenshotpath()
1362{
1363 echo "$(getsdcardpath)/Pictures/Screenshots"
1364}
1365
1366function getlastscreenshot()
1367{
1368 local screenshot_path=$(getscreenshotpath)
1369 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1370 if [ "$screenshot" = "" ]; then
1371 echo "No screenshots found."
1372 return
1373 fi
1374 echo "${screenshot}"
1375 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1376}
1377
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001378function startviewserver()
1379{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001380 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001381 if [ $# -gt 0 ]; then
1382 port=$1
1383 fi
1384 adb shell service call window 1 i32 $port
1385}
1386
1387function stopviewserver()
1388{
1389 adb shell service call window 2
1390}
1391
1392function isviewserverstarted()
1393{
1394 adb shell service call window 3
1395}
1396
Romain Guyb84049a2010-10-04 16:56:11 -07001397function key_home()
1398{
1399 adb shell input keyevent 3
1400}
1401
1402function key_back()
1403{
1404 adb shell input keyevent 4
1405}
1406
1407function key_menu()
1408{
1409 adb shell input keyevent 82
1410}
1411
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001412function smoketest()
1413{
1414 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1415 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1416 return
1417 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001418 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001419 if [ ! "$T" ]; then
1420 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1421 return
1422 fi
1423
Ying Wang9cd17642012-12-13 10:52:07 -08001424 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001425 adb uninstall com.android.smoketest > /dev/null &&
1426 adb uninstall com.android.smoketest.tests > /dev/null &&
1427 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1428 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1429 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1430}
1431
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001432# simple shortcut to the runtest command
1433function runtest()
1434{
Christopher Ferris55257d22017-03-23 11:08:58 -07001435 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001436 if [ ! "$T" ]; then
1437 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1438 return
1439 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001440 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001441}
1442
The Android Open Source Project88b60792009-03-03 19:28:42 -08001443function godir () {
1444 if [[ -z "$1" ]]; then
1445 echo "Usage: godir <regex>"
1446 return
1447 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001448 local T=$(gettop)
1449 local FILELIST
Brian Carlstromf2257422015-09-30 20:28:54 -07001450 if [ ! "$OUT_DIR" = "" ]; then
1451 mkdir -p $OUT_DIR
1452 FILELIST=$OUT_DIR/filelist
1453 else
1454 FILELIST=$T/filelist
1455 fi
1456 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001457 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001458 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001459 echo " Done"
1460 echo ""
1461 fi
1462 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001463 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001464 if [[ ${#lines[@]} = 0 ]]; then
1465 echo "Not found"
1466 return
1467 fi
1468 local pathname
1469 local choice
1470 if [[ ${#lines[@]} > 1 ]]; then
1471 while [[ -z "$pathname" ]]; do
1472 local index=1
1473 local line
1474 for line in ${lines[@]}; do
1475 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001476 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001477 done
1478 echo
1479 echo -n "Select one: "
1480 unset choice
1481 read choice
1482 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1483 echo "Invalid choice"
1484 continue
1485 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001486 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001487 done
1488 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001489 pathname=${lines[0]}
1490 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001491 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001492}
1493
Steven Moreland62054a42018-12-06 10:11:40 -08001494# Update module-info.json in out.
1495function refreshmod() {
1496 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1497 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1498 return 1
1499 fi
1500
1501 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1502
1503 # for the output of the next command
1504 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1505
1506 # Note, can't use absolute path because of the way make works.
1507 m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \
1508 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1509}
1510
1511# List all modules for the current device, as cached in module-info.json. If any build change is
1512# made and it should be reflected in the output, you should run 'refreshmod' first.
1513function allmod() {
1514 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1515 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1516 return 1
1517 fi
1518
1519 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1520 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1521 refreshmod || return 1
1522 fi
1523
1524 python -c "import json; print '\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys()))"
1525}
1526
1527# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1528# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1529function gomod() {
1530 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1531 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1532 return 1
1533 fi
1534
1535 if [[ $# -ne 1 ]]; then
1536 echo "usage: gomod <module>" >&2
1537 return 1
1538 fi
1539
1540 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1541 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1542 refreshmod || return 1
1543 fi
1544
1545 local relpath=$(python -c "import json, os
1546module = '$1'
1547module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1548if module not in module_info:
1549 exit(1)
1550print module_info[module]['path'][0]" 2>/dev/null)
1551
1552 if [ -z "$relpath" ]; then
1553 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1554 return 1
1555 else
1556 cd $ANDROID_BUILD_TOP/$relpath
1557 fi
1558}
1559
dimitry73b84812018-12-11 18:06:00 +01001560function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001561 local word=${COMP_WORDS[COMP_CWORD]}
1562 COMPREPLY=( $(allmod | grep -E "^$word") )
1563}
1564
Alex Rayf0d08eb2013-03-08 15:15:06 -08001565# Print colored exit condition
1566function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001567 "$@"
1568 local retval=$?
1569 if [ $retval -ne 0 ]
1570 then
Jacky Cao89483b82015-05-15 22:12:53 +08001571 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001572 else
Jacky Cao89483b82015-05-15 22:12:53 +08001573 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001574 fi
1575 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001576}
1577
Ying Wanged21d4c2014-08-24 22:14:19 -07001578function get_make_command()
1579{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001580 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1581 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001582 # Always use the real make if -C is passed in
1583 for arg in "$@"; do
1584 if [[ $arg == -C* ]]; then
1585 echo command make
1586 return
1587 fi
1588 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001589 echo build/soong/soong_ui.bash --make-mode
1590 else
1591 echo command make
1592 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001593}
1594
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001595function _wrap_build()
Ed Heylcc6be0a2014-06-18 14:55:58 -07001596{
1597 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001598 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001599 local ret=$?
1600 local end_time=$(date +"%s")
1601 local tdiff=$(($end_time-$start_time))
1602 local hours=$(($tdiff / 3600 ))
1603 local mins=$((($tdiff % 3600) / 60))
1604 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001605 local ncolors=$(tput colors 2>/dev/null)
1606 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001607 color_failed=$'\E'"[0;31m"
1608 color_success=$'\E'"[0;32m"
1609 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001610 else
1611 color_failed=""
1612 color_success=""
1613 color_reset=""
1614 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001615 echo
1616 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001617 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001618 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001619 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001620 fi
1621 if [ $hours -gt 0 ] ; then
1622 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1623 elif [ $mins -gt 0 ] ; then
1624 printf "(%02g:%02g (mm:ss))" $mins $secs
1625 elif [ $secs -gt 0 ] ; then
1626 printf "(%s seconds)" $secs
1627 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001628 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001629 echo
1630 return $ret
1631}
1632
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001633function make()
1634{
Dan Willemsene9842242017-07-28 13:00:13 -07001635 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001636}
1637
David Zeuthen1b126ff2015-09-30 17:10:48 -04001638function provision()
1639{
1640 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1641 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1642 return 1
1643 fi
1644 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1645 echo "There is no provisioning script for the device." >&2
1646 return 1
1647 fi
1648
1649 # Check if user really wants to do this.
1650 if [ "$1" = "--no-confirmation" ]; then
1651 shift 1
1652 else
1653 echo "This action will reflash your device."
1654 echo ""
1655 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1656 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001657 echo -n "Are you sure you want to do this (yes/no)? "
1658 read
David Zeuthen1b126ff2015-09-30 17:10:48 -04001659 if [[ "${REPLY}" != "yes" ]] ; then
1660 echo "Not taking any action. Exiting." >&2
1661 return 1
1662 fi
1663 fi
1664 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1665}
1666
Jim Tanga881a252018-06-19 16:34:41 +08001667# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001668function enable_zsh_completion() {
1669 # Don't override user's options if bash-style completion is already enabled.
1670 if ! declare -f complete >/dev/null; then
1671 autoload -U compinit && compinit
1672 autoload -U bashcompinit && bashcompinit
1673 fi
Jim Tanga881a252018-06-19 16:34:41 +08001674}
1675
1676function validate_current_shell() {
1677 local current_sh="$(ps -o command -p $$)"
1678 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001679 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001680 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001681 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001682 *zsh*)
1683 function check_type() { type "$1"; }
Patrik Fimmldf248e62018-10-15 18:15:12 +02001684 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001685 *)
Jim Tanga881a252018-06-19 16:34:41 +08001686 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 -07001687 ;;
1688 esac
Jim Tanga881a252018-06-19 16:34:41 +08001689}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001690
1691# Execute the contents of any vendorsetup.sh files we can find.
Jim Tanga881a252018-06-19 16:34:41 +08001692function source_vendorsetup() {
1693 for dir in device vendor product; do
1694 for f in $(test -d $dir && \
1695 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
1696 echo "including $f"; . $f
1697 done
1698 done
1699}
Kenny Root52aa81c2011-07-15 11:07:06 -07001700
Jim Tanga881a252018-06-19 16:34:41 +08001701validate_current_shell
1702source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001703addcompletions