blob: c5619e65cff9407a4d03a57bad205d9f5353d6bd [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.
Elliott Hughesf71c05a2020-03-06 16:46:59 -080011- tapas: tapas [<App1> <App2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
Anton Hanssonece9c482019-02-04 18:15:39 +000012- croot: Changes directory to the top of the tree, or a subdirectory thereof.
Steven Moreland62054a42018-12-06 10:11:40 -080013- m: Makes from the top of the tree.
Dan Willemsen67074fe2019-10-30 12:35:34 -070014- mm: Builds and installs all of the modules in the current directory, and their
15 dependencies.
16- mmm: Builds and installs all of the modules in the supplied directories, and their
17 dependencies.
Steven Moreland62054a42018-12-06 10:11:40 -080018 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Dan Willemsen67074fe2019-10-30 12:35:34 -070019- mma: Same as 'mm'
20- mmma: Same as 'mmm'
Steven Moreland62054a42018-12-06 10:11:40 -080021- provision: Flash device with all required partitions. Options will be passed on to fastboot.
22- cgrep: Greps on all local C/C++ files.
23- ggrep: Greps on all local Gradle files.
Orion Hodson831472d2019-10-25 11:35:15 +010024- gogrep: Greps on all local Go files.
Steven Moreland62054a42018-12-06 10:11:40 -080025- jgrep: Greps on all local Java files.
26- resgrep: Greps on all local res/*.xml files.
27- mangrep: Greps on all local AndroidManifest.xml files.
Jaewoong Jung892d0fe2019-05-04 10:06:28 -070028- mgrep: Greps on all local Makefiles and *.bp files.
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -060029- owngrep: Greps on all local OWNERS files.
Steven Moreland62054a42018-12-06 10:11:40 -080030- sepgrep: Greps on all local sepolicy files.
31- sgrep: Greps on all local source files.
32- godir: Go to the directory containing a file.
33- allmod: List all modules.
34- gomod: Go to the directory containing a module.
Rett Berg78d1c932019-01-24 14:34:23 -080035- pathmod: Get the directory containing a module.
Steven Morelandab25c7a2020-04-09 12:05:34 -070036- refreshmod: Refresh list of modules for allmod/gomod/pathmod.
Steven Moreland74114f12020-09-10 01:23:32 +000037- syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070038
Roland Levillain39341922015-10-20 12:48:19 +010039Environment options:
Steven Moreland115d1f52019-09-26 16:30:28 -070040- SANITIZE_HOST: Set to 'address' to use ASAN for all host modules.
Sasha Smundak9f27cc02019-01-31 13:25:31 -080041- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
Dan Albert4ae5d4b2014-10-31 16:23:08 -070042
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070043Look at the source to view more functions. The complete list is:
44EOF
Christopher Ferris55257d22017-03-23 11:08:58 -070045 local T=$(gettop)
46 local A=""
47 local i
Jacky Cao89483b82015-05-15 22:12:53 +080048 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 -070049 A="$A $i"
50 done
51 echo $A
52}
53
Ying Wang08800fd2016-03-03 20:57:21 -080054# Get all the build variables needed by this script in a single call to the build system.
Matt Alexanderd9c56562020-05-21 10:49:17 +000055function build_build_var_cache()
56{
Christopher Ferris55257d22017-03-23 11:08:58 -070057 local T=$(gettop)
Ying Wang08800fd2016-03-03 20:57:21 -080058 # Grep out the variable names from the script.
Jim Tanga881a252018-06-19 16:34:41 +080059 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' ' '`)
60 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 -080061 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
Steven Moreland05402962018-01-05 12:13:11 -080062 build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
Jim Tanga881a252018-06-19 16:34:41 +080063 --vars="${cached_vars[*]}" \
64 --abs-vars="${cached_abs_vars[*]}" \
Dan Willemsenaf88c412017-07-14 11:29:44 -070065 --var-prefix=var_cache_ \
66 --abs-var-prefix=abs_var_cache_`
Ying Wang08800fd2016-03-03 20:57:21 -080067 local ret=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +000068 if [ $ret -ne 0 ]
69 then
Ying Wang08800fd2016-03-03 20:57:21 -080070 unset build_dicts_script
71 return $ret
72 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -070073 # Execute the script to store the "<val>=<value>" pairs as shell variables.
Ying Wang08800fd2016-03-03 20:57:21 -080074 eval "$build_dicts_script"
Ying Wang08800fd2016-03-03 20:57:21 -080075 ret=$?
Ying Wangf0cb3972016-03-04 13:56:23 -080076 unset build_dicts_script
Matt Alexanderd9c56562020-05-21 10:49:17 +000077 if [ $ret -ne 0 ]
78 then
Ying Wang08800fd2016-03-03 20:57:21 -080079 return $ret
80 fi
81 BUILD_VAR_CACHE_READY="true"
82}
83
Ying Wangf0cb3972016-03-04 13:56:23 -080084# Delete the build var cache, so that we can still call into the build system
Ying Wang08800fd2016-03-03 20:57:21 -080085# to get build variables not listed in this script.
Matt Alexanderd9c56562020-05-21 10:49:17 +000086function destroy_build_var_cache()
87{
Ying Wang08800fd2016-03-03 20:57:21 -080088 unset BUILD_VAR_CACHE_READY
Christopher Ferris55257d22017-03-23 11:08:58 -070089 local v
Ying Wang08800fd2016-03-03 20:57:21 -080090 for v in $cached_vars; do
91 unset var_cache_$v
92 done
93 unset cached_vars
94 for v in $cached_abs_vars; do
95 unset abs_var_cache_$v
96 done
97 unset cached_abs_vars
98}
99
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700100# Get the value of a build variable as an absolute path.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000101function get_abs_build_var()
102{
103 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
104 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800105 eval "echo \"\${abs_var_cache_$1}\""
Matt Alexanderd9c56562020-05-21 10:49:17 +0000106 return
Ying Wang08800fd2016-03-03 20:57:21 -0800107 fi
108
Christopher Ferris55257d22017-03-23 11:08:58 -0700109 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700110 if [ ! "$T" ]; then
111 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
112 return
113 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700114 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700115}
116
117# Get the exact value of a build variable.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000118function get_build_var()
119{
120 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
121 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800122 eval "echo \"\${var_cache_$1}\""
Roland Levillain23c46cf2020-03-31 16:11:05 +0100123 return 0
Ying Wang08800fd2016-03-03 20:57:21 -0800124 fi
125
Christopher Ferris55257d22017-03-23 11:08:58 -0700126 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700127 if [ ! "$T" ]; then
128 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
Roland Levillain23c46cf2020-03-31 16:11:05 +0100129 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700130 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700131 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800132}
133
134# check to see if the supplied product is one we can build
Matt Alexanderd9c56562020-05-21 10:49:17 +0000135function check_product()
136{
Christopher Ferris55257d22017-03-23 11:08:58 -0700137 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800138 if [ ! "$T" ]; then
139 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
140 return
141 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700142 TARGET_PRODUCT=$1 \
143 TARGET_BUILD_VARIANT= \
144 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700145 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800146 get_build_var TARGET_DEVICE > /dev/null
147 # hide successful answers, but allow the errors to show
148}
149
150VARIANT_CHOICES=(user userdebug eng)
151
152# check to see if the supplied variant is valid
Matt Alexanderd9c56562020-05-21 10:49:17 +0000153function check_variant()
154{
Christopher Ferris55257d22017-03-23 11:08:58 -0700155 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800156 for v in ${VARIANT_CHOICES[@]}
157 do
Matt Alexanderd9c56562020-05-21 10:49:17 +0000158 if [ "$v" = "$1" ]
159 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800160 return 0
161 fi
162 done
163 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700164}
165
Matt Alexanderd9c56562020-05-21 10:49:17 +0000166function setpaths()
167{
Christopher Ferris55257d22017-03-23 11:08:58 -0700168 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700169 if [ ! "$T" ]; then
170 echo "Couldn't locate the top of the tree. Try setting TOP."
171 return
172 fi
173
174 ##################################################################
175 # #
176 # Read me before you modify this code #
177 # #
178 # This function sets ANDROID_BUILD_PATHS to what it is adding #
179 # to PATH, and the next time it is run, it removes that from #
180 # PATH. This is required so lunch can be run more than once #
181 # and still have working paths. #
182 # #
183 ##################################################################
184
Raphael Mollc639c782011-06-20 17:25:01 -0700185 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
186 # due to "C:\Program Files" being in the path.
187
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700188 # out with the old
Matt Alexanderd9c56562020-05-21 10:49:17 +0000189 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700190 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
191 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000192 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700193 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800194 # strip leading ':', if any
195 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500196 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700197
198 # and in with the new
Christopher Ferris55257d22017-03-23 11:08:58 -0700199 local prebuiltdir=$(getprebuilt)
200 local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700201
Ben Cheng8bc4c432012-11-16 13:29:13 -0800202 # defined in core/config.mk
Christopher Ferris55257d22017-03-23 11:08:58 -0700203 local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
204 local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800205 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800206
Raphael Mollc639c782011-06-20 17:25:01 -0700207 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800208 export ANDROID_TOOLCHAIN=
209 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200210 local ARCH=$(get_build_var TARGET_ARCH)
Christopher Ferris55257d22017-03-23 11:08:58 -0700211 local toolchaindir toolchaindir2=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200212 case $ARCH in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000213 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700214 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000215 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Pavel Chupinfd82a492012-11-26 09:50:07 +0400216 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000217 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200218 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000219 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
220 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700221 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200222 *)
223 echo "Can't find toolchain for unknown architecture: $ARCH"
224 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700225 ;;
226 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700227 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800228 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700229 fi
Raphael732936d2011-06-22 14:35:32 -0700230
Christopher Ferris55257d22017-03-23 11:08:58 -0700231 if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800232 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
233 fi
234
Jeff Vander Stoep5f50f052015-06-12 09:56:39 -0700235 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Yueyao Zhuefc786a2017-04-07 14:11:54 -0700236
237 # add kernel specific binaries
238 case $(uname -s) in
239 Linux)
240 export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
241 ;;
242 *)
243 ;;
244 esac
245
Torne (Richard Coles)0091bae2017-10-03 16:31:18 -0400246 ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN
247 if [ -n "$ANDROID_TOOLCHAIN_2ND_ARCH" ]; then
248 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH
249 fi
Yi Kongdfd00b12019-05-21 16:00:04 -0700250 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS
251
252 # Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS.
253 local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
254 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200255
Stephen Hinesaa8d72c2020-02-04 09:15:18 -0800256 # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds.
257 export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer
258
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200259 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
260 # to ensure that the corresponding 'emulator' binaries are used.
261 case $(uname -s) in
262 Darwin)
263 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
264 ;;
265 Linux)
266 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
267 ;;
268 *)
269 ANDROID_EMULATOR_PREBUILTS=
270 ;;
271 esac
272 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Yi Kongdfd00b12019-05-21 16:00:04 -0700273 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200274 export ANDROID_EMULATOR_PREBUILTS
275 fi
276
Jim Tangb3fda302018-12-22 10:24:55 +0800277 # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
278 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
Ryan Prichard8426a192019-07-15 18:05:29 -0700279 local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch"
280 local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch"
281 local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch"
282 export ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH:
Jim Tangb3fda302018-12-22 10:24:55 +0800283
Ryan Prichard8426a192019-07-15 18:05:29 -0700284 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800285
286 # out with the duplicate old
287 if [ -n $ANDROID_PYTHONPATH ]; then
288 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
289 fi
290 # and in with the new
291 export ANDROID_PYTHONPATH=$T/development/python-packages:
Jim Tangc4dba1d2019-07-25 16:54:27 +0800292 if [ -n $VENDOR_PYTHONPATH ]; then
293 ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
294 fi
Jim Tang22f4c322018-12-17 15:21:53 +0800295 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800296
Colin Crosse97e6932017-06-30 16:01:45 -0700297 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
298 export JAVA_HOME=$ANDROID_JAVA_HOME
299 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
300 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
301 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500302
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700304 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
305 export OUT=$ANDROID_PRODUCT_OUT
306
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700307 unset ANDROID_HOST_OUT
308 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
309
Simran Basidd050ed2017-02-13 13:46:48 -0800310 unset ANDROID_HOST_OUT_TESTCASES
311 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
312
313 unset ANDROID_TARGET_OUT_TESTCASES
314 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
315
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317 # TODO: fix the path
318 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
319}
320
Matt Alexanderd9c56562020-05-21 10:49:17 +0000321function printconfig()
322{
Christopher Ferris55257d22017-03-23 11:08:58 -0700323 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800324 if [ ! "$T" ]; then
325 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
326 return
327 fi
328 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700329}
330
Matt Alexanderd9c56562020-05-21 10:49:17 +0000331function set_stuff_for_environment()
332{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800333 setpaths
334 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700337 # With this environment variable new GCC can apply colors to warnings/errors
338 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339}
340
Matt Alexanderd9c56562020-05-21 10:49:17 +0000341function set_sequence_number()
342{
Colin Cross88737132017-03-21 17:41:03 -0700343 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700344}
345
Makoto Onukida971062018-06-18 10:15:19 -0700346# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
347function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800348 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700349 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800350 *:"$cmd":*)
351 return 1
352 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700353 esac
354 return 0
355}
356
Matt Alexanderd9c56562020-05-21 10:49:17 +0000357function addcompletions()
358{
Kenny Root52aa81c2011-07-15 11:07:06 -0700359 local T dir f
360
Jim Tanga881a252018-06-19 16:34:41 +0800361 # Keep us from trying to run in something that's neither bash nor zsh.
362 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700363 return
364 fi
365
366 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800367 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700368 return
369 fi
370
Jim Tanga881a252018-06-19 16:34:41 +0800371 local completion_files=(
372 system/core/adb/adb.bash
373 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800374 tools/asuite/asuite.sh
Jim Tanga881a252018-06-19 16:34:41 +0800375 )
Makoto Onukida971062018-06-18 10:15:19 -0700376 # Completion can be disabled selectively to allow users to use non-standard completion.
377 # e.g.
378 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
379 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800380 for f in ${completion_files[*]}; do
381 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700382 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700383 fi
384 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700385
Matt Alexanderd9c56562020-05-21 10:49:17 +0000386 if should_add_completion bit ; then
Makoto Onukida971062018-06-18 10:15:19 -0700387 complete -C "bit --tab" bit
388 fi
Anton Hanssonece9c482019-02-04 18:15:39 +0000389 if [ -z "$ZSH_VERSION" ]; then
390 # Doesn't work in zsh.
391 complete -o nospace -F _croot croot
392 fi
Jim Tanga881a252018-06-19 16:34:41 +0800393 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800394
dimitry73b84812018-12-11 18:06:00 +0100395 complete -F _complete_android_module_names gomod
396 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700397}
398
Matt Alexanderd9c56562020-05-21 10:49:17 +0000399function choosetype()
400{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700401 echo "Build type choices are:"
402 echo " 1. release"
403 echo " 2. debug"
404 echo
405
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800406 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700407 DEFAULT_NUM=1
408 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700409
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800410 export TARGET_BUILD_TYPE=
411 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700412 while [ -z $TARGET_BUILD_TYPE ]
413 do
414 echo -n "Which would you like? ["$DEFAULT_NUM"] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000415 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800416 read ANSWER
417 else
418 echo $1
419 ANSWER=$1
420 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700421 case $ANSWER in
422 "")
423 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
424 ;;
425 1)
426 export TARGET_BUILD_TYPE=release
427 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800428 release)
429 export TARGET_BUILD_TYPE=release
430 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700431 2)
432 export TARGET_BUILD_TYPE=debug
433 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800434 debug)
435 export TARGET_BUILD_TYPE=debug
436 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700437 *)
438 echo
439 echo "I didn't understand your response. Please try again."
440 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700441 ;;
442 esac
Matt Alexanderd9c56562020-05-21 10:49:17 +0000443 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800444 break
445 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446 done
447
Ying Wang08800fd2016-03-03 20:57:21 -0800448 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800450 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700451}
452
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800453#
454# This function isn't really right: It chooses a TARGET_PRODUCT
455# based on the list of boards. Usually, that gets you something
456# that kinda works with a generic product, but really, you should
457# pick a product by name.
458#
Matt Alexanderd9c56562020-05-21 10:49:17 +0000459function chooseproduct()
460{
Christopher Ferris55257d22017-03-23 11:08:58 -0700461 local default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000462 if [ "x$TARGET_PRODUCT" != x ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700463 default_value=$TARGET_PRODUCT
464 else
Ying Wang0a76df52015-06-08 11:57:26 -0700465 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700466 fi
467
Ying Wang08800fd2016-03-03 20:57:21 -0800468 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469 export TARGET_PRODUCT=
470 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471 while [ -z "$TARGET_PRODUCT" ]
472 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700473 echo -n "Which product would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000474 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800475 read ANSWER
476 else
477 echo $1
478 ANSWER=$1
479 fi
480
Matt Alexanderd9c56562020-05-21 10:49:17 +0000481 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700482 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800483 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000484 if check_product $ANSWER
485 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486 export TARGET_PRODUCT=$ANSWER
487 else
488 echo "** Not a valid product: $ANSWER"
489 fi
490 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000491 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700493 fi
494 done
495
Ying Wang08800fd2016-03-03 20:57:21 -0800496 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700497 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800498 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700499}
500
Matt Alexanderd9c56562020-05-21 10:49:17 +0000501function choosevariant()
502{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800503 echo "Variant choices are:"
504 local index=1
505 local v
506 for v in ${VARIANT_CHOICES[@]}
507 do
508 # The product name is the name of the directory containing
509 # the makefile we found, above.
510 echo " $index. $v"
511 index=$(($index+1))
512 done
513
514 local default_value=eng
515 local ANSWER
516
517 export TARGET_BUILD_VARIANT=
518 while [ -z "$TARGET_BUILD_VARIANT" ]
519 do
520 echo -n "Which would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000521 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522 read ANSWER
523 else
524 echo $1
525 ANSWER=$1
526 fi
527
Matt Alexanderd9c56562020-05-21 10:49:17 +0000528 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800529 export TARGET_BUILD_VARIANT=$default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000530 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
531 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Guillaume Chelfice000fd2019-10-03 12:02:46 +0200532 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800533 fi
534 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000535 if check_variant $ANSWER
536 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800537 export TARGET_BUILD_VARIANT=$ANSWER
538 else
539 echo "** Not a valid variant: $ANSWER"
540 fi
541 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000542 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800543 break
544 fi
545 done
546}
547
Matt Alexanderd9c56562020-05-21 10:49:17 +0000548function choosecombo()
549{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700550 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700551
552 echo
553 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700554 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700555
556 echo
557 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700558 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800559
560 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800561 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700562 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800563 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800564 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700565}
566
Matt Alexanderd9c56562020-05-21 10:49:17 +0000567function add_lunch_combo()
568{
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800569 if [ -n "$ZSH_VERSION" ]; then
570 echo -n "${funcfiletrace[1]}: "
571 else
572 echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
573 fi
574 echo "add_lunch_combo is obsolete. Use COMMON_LUNCH_CHOICES in your AndroidProducts.mk instead."
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800575}
576
Matt Alexanderd9c56562020-05-21 10:49:17 +0000577function print_lunch_menu()
578{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700579 local uname=$(uname)
Roland Levillain23c46cf2020-03-31 16:11:05 +0100580 local choices
581 choices=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES 2>/dev/null)
582 local ret=$?
583
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700584 echo
585 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700586 echo
Roland Levillain23c46cf2020-03-31 16:11:05 +0100587
Matt Alexanderd9c56562020-05-21 10:49:17 +0000588 if [ $ret -ne 0 ]
589 then
Roland Levillain23c46cf2020-03-31 16:11:05 +0100590 echo "Warning: Cannot display lunch menu."
591 echo
592 echo "Note: You can invoke lunch with an explicit target:"
593 echo
594 echo " usage: lunch [target]" >&2
595 echo
596 return
597 fi
598
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700599 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800600
601 local i=1
602 local choice
Dan Willemsen91763e92019-10-03 15:13:12 -0700603 for choice in $(echo $choices)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800604 do
605 echo " $i. $choice"
606 i=$(($i+1))
607 done
608
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700609 echo
610}
611
Matt Alexanderd9c56562020-05-21 10:49:17 +0000612function lunch()
613{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800614 local answer
615
Steven Moreland92793dc2020-02-25 18:30:18 -0800616 if [[ $# -gt 1 ]]; then
617 echo "usage: lunch [target]" >&2
618 return 1
619 fi
620
621 if [ "$1" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800622 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700623 else
624 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700625 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800626 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700627 fi
628
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800629 local selection=
630
Matt Alexanderd9c56562020-05-21 10:49:17 +0000631 if [ -z "$answer" ]
632 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700633 selection=aosp_arm-eng
Matt Alexanderd9c56562020-05-21 10:49:17 +0000634 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
635 then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800636 local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
Matt Alexanderd9c56562020-05-21 10:49:17 +0000637 if [ $answer -le ${#choices[@]} ]
638 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800639 # array in zsh starts from 1 instead of 0.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000640 if [ -n "$ZSH_VERSION" ]
641 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800642 selection=${choices[$(($answer))]}
643 else
644 selection=${choices[$(($answer-1))]}
645 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800646 fi
Colin Cross88737132017-03-21 17:41:03 -0700647 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800648 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649 fi
650
Joe Onoratoda12daf2010-06-09 18:18:31 -0700651 export TARGET_BUILD_APPS=
652
Colin Cross88737132017-03-21 17:41:03 -0700653 local product variant_and_version variant version
Colin Cross88737132017-03-21 17:41:03 -0700654 product=${selection%%-*} # Trim everything after first dash
655 variant_and_version=${selection#*-} # Trim everything up to first dash
656 if [ "$variant_and_version" != "$selection" ]; then
657 variant=${variant_and_version%%-*}
658 if [ "$variant" != "$variant_and_version" ]; then
659 version=${variant_and_version#*-}
660 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700661 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800662
Matt Alexanderd9c56562020-05-21 10:49:17 +0000663 if [ -z "$product" ]
664 then
Ying Wang08800fd2016-03-03 20:57:21 -0800665 echo
Colin Cross88737132017-03-21 17:41:03 -0700666 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700667 return 1
668 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800669
Colin Cross88737132017-03-21 17:41:03 -0700670 TARGET_PRODUCT=$product \
671 TARGET_BUILD_VARIANT=$variant \
672 TARGET_PLATFORM_VERSION=$version \
673 build_build_var_cache
Matt Alexanderd9c56562020-05-21 10:49:17 +0000674 if [ $? -ne 0 ]
675 then
Colin Cross88737132017-03-21 17:41:03 -0700676 return 1
677 fi
Colin Cross88737132017-03-21 17:41:03 -0700678 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
679 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700680 if [ -n "$version" ]; then
681 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
682 else
683 unset TARGET_PLATFORM_VERSION
684 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700685 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700686
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700687 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800688
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700689 set_stuff_for_environment
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700690 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800691 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700692}
693
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700694unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700695# Tab completion for lunch.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000696function _lunch()
697{
Jeff Davidson513d7a42010-08-02 10:00:44 -0700698 local cur prev opts
699 COMPREPLY=()
700 cur="${COMP_WORDS[COMP_CWORD]}"
701 prev="${COMP_WORDS[COMP_CWORD-1]}"
702
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700703 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800704 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700705 fi
706
707 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700708 return 0
709}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700710
Joe Onoratoda12daf2010-06-09 18:18:31 -0700711# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700712# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Matt Alexanderd9c56562020-05-21 10:49:17 +0000713function tapas()
714{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700715 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Elliott Hughesf71c05a2020-03-06 16:46:59 -0800716 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700717 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700718 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Elliott Hughesf71c05a2020-03-06 16:46:59 -0800719 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|arm64|x86_64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700720
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700721 if [ "$showHelp" != "" ]; then
722 $(gettop)/build/make/tapasHelp.sh
723 return
724 fi
725
Ying Wang67f02922012-08-22 10:25:20 -0700726 if [ $(echo $arch | wc -w) -gt 1 ]; then
727 echo "tapas: Error: Multiple build archs supplied: $arch"
728 return
729 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700730 if [ $(echo $variant | wc -w) -gt 1 ]; then
731 echo "tapas: Error: Multiple build variants supplied: $variant"
732 return
733 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700734 if [ $(echo $density | wc -w) -gt 1 ]; then
735 echo "tapas: Error: Multiple densities supplied: $density"
736 return
737 fi
Ying Wang67f02922012-08-22 10:25:20 -0700738
Ying Wang0a76df52015-06-08 11:57:26 -0700739 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700740 case $arch in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000741 x86) product=aosp_x86;;
742 arm64) product=aosp_arm64;;
743 x86_64) product=aosp_x86_64;;
Ying Wang67f02922012-08-22 10:25:20 -0700744 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700745 if [ -z "$variant" ]; then
746 variant=eng
747 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700748 if [ -z "$apps" ]; then
749 apps=all
750 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600751 if [ -z "$density" ]; then
752 density=alldpi
753 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700754
Ying Wang67f02922012-08-22 10:25:20 -0700755 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700756 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700757 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700758 export TARGET_BUILD_TYPE=release
759 export TARGET_BUILD_APPS=$apps
760
Ying Wang08800fd2016-03-03 20:57:21 -0800761 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700762 set_stuff_for_environment
763 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800764 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700765}
766
Matt Alexanderd9c56562020-05-21 10:49:17 +0000767function gettop
768{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700769 local TOPFILE=build/make/core/envsetup.mk
Matt Alexanderd9c56562020-05-21 10:49:17 +0000770 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700771 # The following circumlocution ensures we remove symlinks from TOP.
772 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700773 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000774 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800775 # The following circumlocution (repeated below as well) ensures
776 # that we record the true directory name and not one that is
777 # faked up with symlink names.
778 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800780 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700781 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700782 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800783 \cd ..
synergyb112a402013-07-05 19:47:47 -0700784 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700785 done
Ying Wang9cd17642012-12-13 10:52:07 -0800786 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700787 if [ -f "$T/$TOPFILE" ]; then
788 echo $T
789 fi
790 fi
791 fi
792}
793
Matt Alexanderd9c56562020-05-21 10:49:17 +0000794function croot()
795{
Christopher Ferris55257d22017-03-23 11:08:58 -0700796 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700798 if [ "$1" ]; then
799 \cd $(gettop)/$1
800 else
801 \cd $(gettop)
802 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700803 else
804 echo "Couldn't locate the top of the tree. Try setting TOP."
805 fi
806}
807
Matt Alexanderd9c56562020-05-21 10:49:17 +0000808function _croot()
809{
Anton Hanssonece9c482019-02-04 18:15:39 +0000810 local T=$(gettop)
811 if [ "$T" ]; then
812 local cur="${COMP_WORDS[COMP_CWORD]}"
813 k=0
814 for c in $(compgen -d ${T}/${cur}); do
815 COMPREPLY[k++]=${c#${T}/}/
816 done
817 fi
818}
819
Matt Alexanderd9c56562020-05-21 10:49:17 +0000820function cproj()
821{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700822 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700823 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700824 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700825 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
826 T=$PWD
827 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800828 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700829 return
830 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800831 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700832 done
Ying Wang9cd17642012-12-13 10:52:07 -0800833 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700834 echo "can't find Android.mk"
835}
836
Daniel Sandler47e0a882013-07-30 13:23:52 -0400837# simplified version of ps; output in the form
838# <pid> <procname>
839function qpid() {
840 local prepend=''
841 local append=''
Matt Alexanderd9c56562020-05-21 10:49:17 +0000842 if [ "$1" = "--exact" ]; then
Daniel Sandler47e0a882013-07-30 13:23:52 -0400843 prepend=' '
844 append='$'
845 shift
Matt Alexanderd9c56562020-05-21 10:49:17 +0000846 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -0800847 echo "usage: qpid [[--exact] <process name|pid>"
848 return 255
849 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -0400850
851 local EXE="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +0000852 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -0800853 qpid | \grep "$prepend$EXE$append"
854 else
855 adb shell ps \
856 | tr -d '\r' \
857 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
858 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -0400859}
860
Steven Moreland74114f12020-09-10 01:23:32 +0000861# syswrite - disable verity, reboot if needed, and remount image
862#
863# Easy way to make system.img/etc writable
864function syswrite() {
865 adb wait-for-device && adb root || return 1
866 if [[ $(adb disable-verity | grep "reboot") ]]; then
867 echo "rebooting"
868 adb reboot && adb wait-for-device && adb root || return 1
869 fi
870 adb wait-for-device && adb remount || return 1
871}
872
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800873# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700874# that has the core-file-size limit set correctly
875#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800876# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700877# if its core-file-size limit is not set already.
878# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
879
Matt Alexanderd9c56562020-05-21 10:49:17 +0000880function coredump_setup()
881{
882 echo "Getting root...";
883 adb root;
884 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700885
Matt Alexanderd9c56562020-05-21 10:49:17 +0000886 echo "Remounting root partition read-write...";
887 adb shell mount -w -o remount -t rootfs rootfs;
888 sleep 1;
889 adb wait-for-device;
890 adb shell mkdir -p /cores;
891 adb shell mount -t tmpfs tmpfs /cores;
892 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700893
Matt Alexanderd9c56562020-05-21 10:49:17 +0000894 echo "Granting SELinux permission to dump in /cores...";
895 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700896
Matt Alexanderd9c56562020-05-21 10:49:17 +0000897 echo "Set core pattern.";
898 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700899
Ying Wang08800fd2016-03-03 20:57:21 -0800900 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700901}
902
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800903# coredump_enable - enable core dumps for the specified process
Matt Alexanderd9c56562020-05-21 10:49:17 +0000904# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700905#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800906# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700907# dump to actually be generated.
908
Matt Alexanderd9c56562020-05-21 10:49:17 +0000909function coredump_enable()
910{
911 local PID=$1;
Ying Wang08800fd2016-03-03 20:57:21 -0800912 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +0000913 printf "Expecting a PID!\n";
914 return;
915 fi;
916 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -0800917 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700918}
919
920# core - send SIGV and pull the core for process
Matt Alexanderd9c56562020-05-21 10:49:17 +0000921# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700922#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800923# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700924# enabled globally.
925
Matt Alexanderd9c56562020-05-21 10:49:17 +0000926function core()
927{
928 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700929
Ying Wang08800fd2016-03-03 20:57:21 -0800930 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +0000931 printf "Expecting a PID!\n";
932 return;
933 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700934
Matt Alexanderd9c56562020-05-21 10:49:17 +0000935 local CORENAME=core.$PID;
936 local COREPATH=/cores/$CORENAME;
937 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700938
Matt Alexanderd9c56562020-05-21 10:49:17 +0000939 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700940
Matt Alexanderd9c56562020-05-21 10:49:17 +0000941 local done=0;
Ying Wang08800fd2016-03-03 20:57:21 -0800942 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
Matt Alexanderd9c56562020-05-21 10:49:17 +0000943 printf "\tSending SIG%s to %d...\n" $SIG $PID;
944 adb shell kill -$SIG $PID;
945 sleep 1;
946 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700947
Matt Alexanderd9c56562020-05-21 10:49:17 +0000948 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
949 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700950}
951
Christopher Tate744ee802009-11-12 15:33:08 -0800952# systemstack - dump the current stack trace of all threads in the system process
953# to the usual ANR traces file
Matt Alexanderd9c56562020-05-21 10:49:17 +0000954function systemstack()
955{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800956 stacks system_server
957}
958
Michael Wrightaeed7212014-06-19 19:58:12 -0700959# Read the ELF header from /proc/$PID/exe to determine if the process is
960# 64-bit.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000961function is64bit()
962{
Ben Chengfba67bf2014-02-25 10:27:07 -0800963 local PID="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +0000964 if [ "$PID" ] ; then
965 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800966 echo "64"
967 else
968 echo ""
969 fi
970 else
971 echo ""
972 fi
973}
974
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700975case `uname -s` in
976 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +0000977 function sgrep()
978 {
Christopher Tatee2fe9592020-03-05 11:34:16 -0800979 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|proto)' \
Mike Frysinger5e479732015-09-22 18:13:48 -0400980 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700981 }
Matt Alexanderd9c56562020-05-21 10:49:17 +0000982
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700983 ;;
984 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +0000985 function sgrep()
986 {
Christopher Tatee2fe9592020-03-05 11:34:16 -0800987 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|hpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\|proto\)' \
Mike Frysinger5e479732015-09-22 18:13:48 -0400988 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700989 }
990 ;;
991esac
992
Matt Alexanderd9c56562020-05-21 10:49:17 +0000993function gettargetarch
994{
Raghu Gandham8da43102012-07-25 19:57:22 -0700995 get_build_var TARGET_ARCH
996}
997
Matt Alexanderd9c56562020-05-21 10:49:17 +0000998function ggrep()
999{
Mike Frysinger5e479732015-09-22 18:13:48 -04001000 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1001 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001002}
1003
Matt Alexanderd9c56562020-05-21 10:49:17 +00001004function gogrep()
1005{
Orion Hodson831472d2019-10-25 11:35:15 +01001006 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
1007 -exec grep --color -n "$@" {} +
1008}
1009
Matt Alexanderd9c56562020-05-21 10:49:17 +00001010function jgrep()
1011{
Mike Frysinger5e479732015-09-22 18:13:48 -04001012 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1013 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001014}
1015
Matt Alexanderd9c56562020-05-21 10:49:17 +00001016function cgrep()
1017{
Mike Frysinger5e479732015-09-22 18:13:48 -04001018 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' \) \
1019 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001020}
1021
Matt Alexanderd9c56562020-05-21 10:49:17 +00001022function resgrep()
1023{
Christopher Ferris55257d22017-03-23 11:08:58 -07001024 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001025 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1026 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1027 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001028}
1029
Matt Alexanderd9c56562020-05-21 10:49:17 +00001030function mangrep()
1031{
Mike Frysinger5e479732015-09-22 18:13:48 -04001032 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1033 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001034}
1035
Matt Alexanderd9c56562020-05-21 10:49:17 +00001036function owngrep()
1037{
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -06001038 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
1039 -exec grep --color -n "$@" {} +
1040}
1041
Matt Alexanderd9c56562020-05-21 10:49:17 +00001042function sepgrep()
1043{
Mike Frysinger5e479732015-09-22 18:13:48 -04001044 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1045 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001046}
1047
Matt Alexanderd9c56562020-05-21 10:49:17 +00001048function rcgrep()
1049{
Mike Frysinger5e479732015-09-22 18:13:48 -04001050 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1051 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001052}
1053
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001054case `uname -s` in
1055 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001056 function mgrep()
1057 {
Orion Hodson831472d2019-10-25 11:35:15 +01001058 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regex '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001059 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001060 }
1061
Matt Alexanderd9c56562020-05-21 10:49:17 +00001062 function treegrep()
1063 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001064 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 -04001065 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001066 }
1067
1068 ;;
1069 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001070 function mgrep()
1071 {
Orion Hodson831472d2019-10-25 11:35:15 +01001072 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 '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001073 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001074 }
1075
Matt Alexanderd9c56562020-05-21 10:49:17 +00001076 function treegrep()
1077 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001078 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 -04001079 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001080 }
1081
1082 ;;
1083esac
1084
Matt Alexanderd9c56562020-05-21 10:49:17 +00001085function getprebuilt
1086{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001087 get_abs_build_var ANDROID_PREBUILTS
1088}
1089
Matt Alexanderd9c56562020-05-21 10:49:17 +00001090function tracedmdump()
1091{
Christopher Ferris55257d22017-03-23 11:08:58 -07001092 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001093 if [ ! "$T" ]; then
1094 echo "Couldn't locate the top of the tree. Try setting TOP."
1095 return
1096 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001097 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001098 local arch=$(gettargetarch)
1099 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001100
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001101 local TRACE=$1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001102 if [ ! "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001103 echo "usage: tracedmdump tracename"
1104 return
1105 fi
1106
Matt Alexanderd9c56562020-05-21 10:49:17 +00001107 if [ ! -r "$KERNEL" ] ; then
Jack Veenstra60116fc2009-04-09 18:12:34 -07001108 echo "Error: cannot find kernel: '$KERNEL'"
1109 return
1110 fi
1111
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001112 local BASETRACE=$(basename $TRACE)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001113 if [ "$BASETRACE" = "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001114 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1115 fi
1116
1117 echo "post-processing traces..."
1118 rm -f $TRACE/qtrace.dexlist
1119 post_trace $TRACE
1120 if [ $? -ne 0 ]; then
1121 echo "***"
1122 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1123 echo "***"
1124 return
1125 fi
1126 echo "generating dexlist output..."
1127 /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
1128 echo "generating dmtrace data..."
1129 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1130 echo "generating html file..."
1131 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1132 echo "done, see $TRACE/dmtrace.html for details"
1133 echo "or run:"
1134 echo " traceview $TRACE/dmtrace"
1135}
1136
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001137# communicate with a running device or emulator, set up necessary state,
1138# and run the hat command.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001139function runhat()
1140{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001141 # process standard adb options
1142 local adbTarget=""
Matt Alexanderd9c56562020-05-21 10:49:17 +00001143 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001144 adbTarget=$1
1145 shift 1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001146 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001147 adbTarget="$1 $2"
1148 shift 2
1149 fi
1150 local adbOptions=${adbTarget}
Matt Alexanderd9c56562020-05-21 10:49:17 +00001151 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001152
1153 # runhat options
1154 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001155
Matt Alexanderd9c56562020-05-21 10:49:17 +00001156 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001157 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001158 return
1159 fi
1160
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001161 # confirm hat is available
1162 if [ -z $(which hat) ]; then
1163 echo "hat is not available in this configuration."
1164 return
1165 fi
1166
Andy McFaddenb6289852010-07-12 08:00:19 -07001167 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001168 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001169 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001170 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001171 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001172 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001173 echo -n "> "
1174 read
1175
The Android Open Source Project88b60792009-03-03 19:28:42 -08001176 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001177
The Android Open Source Project88b60792009-03-03 19:28:42 -08001178 echo "Retrieving file $devFile..."
1179 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001180
The Android Open Source Project88b60792009-03-03 19:28:42 -08001181 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001182
The Android Open Source Project88b60792009-03-03 19:28:42 -08001183 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001184 echo "View the output by pointing your browser at http://localhost:7000/"
1185 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001186 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001187}
1188
Matt Alexanderd9c56562020-05-21 10:49:17 +00001189function getbugreports()
1190{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001191 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001192
1193 if [ ! "$reports" ]; then
1194 echo "Could not locate any bugreports."
1195 return
1196 fi
1197
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001198 local report
1199 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001200 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001201 echo "/sdcard/bugreports/${report}"
1202 adb pull /sdcard/bugreports/${report} ${report}
1203 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001204 done
1205}
1206
Matt Alexanderd9c56562020-05-21 10:49:17 +00001207function getsdcardpath()
1208{
Victoria Lease1b296b42012-08-21 15:44:06 -07001209 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1210}
1211
Matt Alexanderd9c56562020-05-21 10:49:17 +00001212function getscreenshotpath()
1213{
Victoria Lease1b296b42012-08-21 15:44:06 -07001214 echo "$(getsdcardpath)/Pictures/Screenshots"
1215}
1216
Matt Alexanderd9c56562020-05-21 10:49:17 +00001217function getlastscreenshot()
1218{
Victoria Lease1b296b42012-08-21 15:44:06 -07001219 local screenshot_path=$(getscreenshotpath)
1220 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
Matt Alexanderd9c56562020-05-21 10:49:17 +00001221 if [ "$screenshot" = "" ]; then
Victoria Lease1b296b42012-08-21 15:44:06 -07001222 echo "No screenshots found."
1223 return
1224 fi
1225 echo "${screenshot}"
1226 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1227}
1228
Matt Alexanderd9c56562020-05-21 10:49:17 +00001229function startviewserver()
1230{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001231 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001232 if [ $# -gt 0 ]; then
1233 port=$1
1234 fi
1235 adb shell service call window 1 i32 $port
1236}
1237
Matt Alexanderd9c56562020-05-21 10:49:17 +00001238function stopviewserver()
1239{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001240 adb shell service call window 2
1241}
1242
Matt Alexanderd9c56562020-05-21 10:49:17 +00001243function isviewserverstarted()
1244{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001245 adb shell service call window 3
1246}
1247
Matt Alexanderd9c56562020-05-21 10:49:17 +00001248function key_home()
1249{
Romain Guyb84049a2010-10-04 16:56:11 -07001250 adb shell input keyevent 3
1251}
1252
Matt Alexanderd9c56562020-05-21 10:49:17 +00001253function key_back()
1254{
Romain Guyb84049a2010-10-04 16:56:11 -07001255 adb shell input keyevent 4
1256}
1257
Matt Alexanderd9c56562020-05-21 10:49:17 +00001258function key_menu()
1259{
Romain Guyb84049a2010-10-04 16:56:11 -07001260 adb shell input keyevent 82
1261}
1262
Matt Alexanderd9c56562020-05-21 10:49:17 +00001263function smoketest()
1264{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001265 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1266 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1267 return
1268 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001269 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001270 if [ ! "$T" ]; then
1271 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1272 return
1273 fi
1274
Ying Wang9cd17642012-12-13 10:52:07 -08001275 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001276 adb uninstall com.android.smoketest > /dev/null &&
1277 adb uninstall com.android.smoketest.tests > /dev/null &&
1278 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1279 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1280 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1281}
1282
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001283# simple shortcut to the runtest command
Matt Alexanderd9c56562020-05-21 10:49:17 +00001284function runtest()
1285{
Christopher Ferris55257d22017-03-23 11:08:58 -07001286 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001287 if [ ! "$T" ]; then
1288 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1289 return
1290 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001291 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001292}
1293
The Android Open Source Project88b60792009-03-03 19:28:42 -08001294function godir () {
1295 if [[ -z "$1" ]]; then
1296 echo "Usage: godir <regex>"
1297 return
1298 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001299 local T=$(gettop)
1300 local FILELIST
Matt Alexanderd9c56562020-05-21 10:49:17 +00001301 if [ ! "$OUT_DIR" = "" ]; then
Brian Carlstromf2257422015-09-30 20:28:54 -07001302 mkdir -p $OUT_DIR
1303 FILELIST=$OUT_DIR/filelist
1304 else
1305 FILELIST=$T/filelist
1306 fi
1307 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001308 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001309 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001310 echo " Done"
1311 echo ""
1312 fi
1313 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001314 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
Matt Alexanderd9c56562020-05-21 10:49:17 +00001315 if [[ ${#lines[@]} = 0 ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001316 echo "Not found"
1317 return
1318 fi
1319 local pathname
1320 local choice
1321 if [[ ${#lines[@]} > 1 ]]; then
1322 while [[ -z "$pathname" ]]; do
1323 local index=1
1324 local line
1325 for line in ${lines[@]}; do
1326 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001327 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001328 done
1329 echo
1330 echo -n "Select one: "
1331 unset choice
1332 read choice
1333 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1334 echo "Invalid choice"
1335 continue
1336 fi
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001337 pathname=${lines[@]:$(($choice-1)):1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001338 done
1339 else
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001340 pathname=${lines[@]:0:1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001341 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001342 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001343}
1344
Steven Moreland62054a42018-12-06 10:11:40 -08001345# Update module-info.json in out.
1346function refreshmod() {
1347 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1348 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1349 return 1
1350 fi
1351
1352 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1353
1354 # for the output of the next command
1355 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1356
1357 # Note, can't use absolute path because of the way make works.
1358 m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \
1359 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1360}
1361
1362# List all modules for the current device, as cached in module-info.json. If any build change is
1363# made and it should be reflected in the output, you should run 'refreshmod' first.
1364function allmod() {
1365 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1366 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1367 return 1
1368 fi
1369
1370 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1371 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1372 refreshmod || return 1
1373 fi
1374
LuK1337b6a78192020-01-12 03:12:17 +01001375 python -c "import json; print('\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys())))"
Steven Moreland62054a42018-12-06 10:11:40 -08001376}
1377
Rett Berg78d1c932019-01-24 14:34:23 -08001378# Get the path of a specific module in the android tree, as cached in module-info.json. If any build change
Steven Moreland62054a42018-12-06 10:11:40 -08001379# is made, and it should be reflected in the output, you should run 'refreshmod' first.
Rett Berg78d1c932019-01-24 14:34:23 -08001380function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001381 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1382 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1383 return 1
1384 fi
1385
1386 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001387 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001388 return 1
1389 fi
1390
1391 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1392 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1393 refreshmod || return 1
1394 fi
1395
1396 local relpath=$(python -c "import json, os
1397module = '$1'
1398module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1399if module not in module_info:
1400 exit(1)
LuK1337b6a78192020-01-12 03:12:17 +01001401print(module_info[module]['path'][0])" 2>/dev/null)
Steven Moreland62054a42018-12-06 10:11:40 -08001402
1403 if [ -z "$relpath" ]; then
1404 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1405 return 1
1406 else
Rett Berg78d1c932019-01-24 14:34:23 -08001407 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001408 fi
1409}
1410
Rett Berg78d1c932019-01-24 14:34:23 -08001411# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1412# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1413function gomod() {
1414 if [[ $# -ne 1 ]]; then
1415 echo "usage: gomod <module>" >&2
1416 return 1
1417 fi
1418
1419 local path="$(pathmod $@)"
1420 if [ -z "$path" ]; then
1421 return 1
1422 fi
1423 cd $path
1424}
1425
dimitry73b84812018-12-11 18:06:00 +01001426function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001427 local word=${COMP_WORDS[COMP_CWORD]}
1428 COMPREPLY=( $(allmod | grep -E "^$word") )
1429}
1430
Alex Rayf0d08eb2013-03-08 15:15:06 -08001431# Print colored exit condition
1432function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001433 "$@"
1434 local retval=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +00001435 if [ $retval -ne 0 ]
1436 then
Jacky Cao89483b82015-05-15 22:12:53 +08001437 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001438 else
Jacky Cao89483b82015-05-15 22:12:53 +08001439 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001440 fi
1441 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001442}
1443
Matt Alexanderd9c56562020-05-21 10:49:17 +00001444function get_make_command()
1445{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001446 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1447 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001448 # Always use the real make if -C is passed in
1449 for arg in "$@"; do
1450 if [[ $arg == -C* ]]; then
1451 echo command make
1452 return
1453 fi
1454 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001455 echo build/soong/soong_ui.bash --make-mode
1456 else
1457 echo command make
1458 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001459}
1460
Matt Alexanderd9c56562020-05-21 10:49:17 +00001461function _wrap_build()
1462{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001463 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1464 "$@"
1465 return $?
1466 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001467 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001468 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001469 local ret=$?
1470 local end_time=$(date +"%s")
1471 local tdiff=$(($end_time-$start_time))
1472 local hours=$(($tdiff / 3600 ))
1473 local mins=$((($tdiff % 3600) / 60))
1474 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001475 local ncolors=$(tput colors 2>/dev/null)
1476 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001477 color_failed=$'\E'"[0;31m"
1478 color_success=$'\E'"[0;32m"
1479 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001480 else
1481 color_failed=""
1482 color_success=""
1483 color_reset=""
1484 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001485 echo
Matt Alexanderd9c56562020-05-21 10:49:17 +00001486 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001487 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001488 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001489 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001490 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +00001491 if [ $hours -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001492 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001493 elif [ $mins -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001494 printf "(%02g:%02g (mm:ss))" $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001495 elif [ $secs -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001496 printf "(%s seconds)" $secs
1497 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001498 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001499 echo
1500 return $ret
1501}
1502
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001503function _trigger_build()
1504(
1505 local -r bc="$1"; shift
1506 if T="$(gettop)"; then
1507 _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
1508 else
1509 echo "Couldn't locate the top of the tree. Try setting TOP."
1510 fi
1511)
1512
1513function m()
1514(
1515 _trigger_build "all-modules" "$@"
1516)
1517
1518function mm()
1519(
1520 _trigger_build "modules-in-a-dir-no-deps" "$@"
1521)
1522
1523function mmm()
1524(
1525 _trigger_build "modules-in-dirs-no-deps" "$@"
1526)
1527
1528function mma()
1529(
1530 _trigger_build "modules-in-a-dir" "$@"
1531)
1532
1533function mmma()
1534(
1535 _trigger_build "modules-in-dirs" "$@"
1536)
1537
Matt Alexanderd9c56562020-05-21 10:49:17 +00001538function make()
1539{
Dan Willemsene9842242017-07-28 13:00:13 -07001540 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001541}
1542
Matt Alexanderd9c56562020-05-21 10:49:17 +00001543function provision()
1544{
David Zeuthen1b126ff2015-09-30 17:10:48 -04001545 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1546 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1547 return 1
1548 fi
1549 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1550 echo "There is no provisioning script for the device." >&2
1551 return 1
1552 fi
1553
1554 # Check if user really wants to do this.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001555 if [ "$1" = "--no-confirmation" ]; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001556 shift 1
1557 else
1558 echo "This action will reflash your device."
1559 echo ""
1560 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1561 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001562 echo -n "Are you sure you want to do this (yes/no)? "
1563 read
Matt Alexanderd9c56562020-05-21 10:49:17 +00001564 if [[ "${REPLY}" != "yes" ]] ; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001565 echo "Not taking any action. Exiting." >&2
1566 return 1
1567 fi
1568 fi
1569 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1570}
1571
Jim Tanga881a252018-06-19 16:34:41 +08001572# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001573function enable_zsh_completion() {
1574 # Don't override user's options if bash-style completion is already enabled.
1575 if ! declare -f complete >/dev/null; then
1576 autoload -U compinit && compinit
1577 autoload -U bashcompinit && bashcompinit
1578 fi
Jim Tanga881a252018-06-19 16:34:41 +08001579}
1580
1581function validate_current_shell() {
1582 local current_sh="$(ps -o command -p $$)"
1583 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001584 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001585 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001586 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001587 *zsh*)
1588 function check_type() { type "$1"; }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001589 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001590 *)
Jim Tanga881a252018-06-19 16:34:41 +08001591 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 -07001592 ;;
1593 esac
Jim Tanga881a252018-06-19 16:34:41 +08001594}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001595
1596# Execute the contents of any vendorsetup.sh files we can find.
Dan Willemsend855a722019-02-12 15:52:36 -08001597# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
1598# load those.
1599#
1600# This allows loading only approved vendorsetup.sh files
Jim Tanga881a252018-06-19 16:34:41 +08001601function source_vendorsetup() {
Jim Tangc4dba1d2019-07-25 16:54:27 +08001602 unset VENDOR_PYTHONPATH
Dan Willemsend855a722019-02-12 15:52:36 -08001603 allowed=
1604 for f in $(find -L device vendor product -maxdepth 4 -name 'allowed-vendorsetup_sh-files' 2>/dev/null | sort); do
1605 if [ -n "$allowed" ]; then
1606 echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
1607 echo " $allowed"
1608 echo " $f"
1609 return
1610 fi
1611 allowed="$f"
1612 done
1613
1614 allowed_files=
1615 [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
Jim Tanga881a252018-06-19 16:34:41 +08001616 for dir in device vendor product; do
1617 for f in $(test -d $dir && \
1618 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001619
1620 if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
1621 echo "including $f"; . "$f"
1622 else
1623 echo "ignoring $f, not in $allowed"
1624 fi
Jim Tanga881a252018-06-19 16:34:41 +08001625 done
1626 done
1627}
Kenny Root52aa81c2011-07-15 11:07:06 -07001628
Jim Tanga881a252018-06-19 16:34:41 +08001629validate_current_shell
1630source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001631addcompletions