blob: b49bb8a21e2b01ea31cb3e804aacf3b9ca97f44c [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]
Martin Stjernholmf692c752021-04-12 00:01:10 +010012 Sets up the build environment for building unbundled apps (APKs).
13- banchan: banchan <module1> [<module2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
14 Sets up the build environment for building unbundled modules (APEXes).
Anton Hanssonece9c482019-02-04 18:15:39 +000015- croot: Changes directory to the top of the tree, or a subdirectory thereof.
Steven Moreland62054a42018-12-06 10:11:40 -080016- m: Makes from the top of the tree.
Dan Willemsen67074fe2019-10-30 12:35:34 -070017- mm: Builds and installs all of the modules in the current directory, and their
18 dependencies.
19- mmm: Builds and installs all of the modules in the supplied directories, and their
20 dependencies.
Steven Moreland62054a42018-12-06 10:11:40 -080021 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Dan Willemsen67074fe2019-10-30 12:35:34 -070022- mma: Same as 'mm'
23- mmma: Same as 'mmm'
Steven Moreland62054a42018-12-06 10:11:40 -080024- provision: Flash device with all required partitions. Options will be passed on to fastboot.
25- cgrep: Greps on all local C/C++ files.
26- ggrep: Greps on all local Gradle files.
Orion Hodson831472d2019-10-25 11:35:15 +010027- gogrep: Greps on all local Go files.
Steven Moreland62054a42018-12-06 10:11:40 -080028- jgrep: Greps on all local Java files.
Taesu Leeea0cecd2020-10-28 11:05:18 +090029- ktgrep: Greps on all local Kotlin files.
Steven Moreland62054a42018-12-06 10:11:40 -080030- resgrep: Greps on all local res/*.xml files.
31- mangrep: Greps on all local AndroidManifest.xml files.
Jaewoong Jung892d0fe2019-05-04 10:06:28 -070032- mgrep: Greps on all local Makefiles and *.bp files.
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -060033- owngrep: Greps on all local OWNERS files.
Alistair Delva176e5342021-02-22 13:31:26 -080034- rsgrep: Greps on all local Rust files.
Steven Moreland62054a42018-12-06 10:11:40 -080035- sepgrep: Greps on all local sepolicy files.
36- sgrep: Greps on all local source files.
37- godir: Go to the directory containing a file.
38- allmod: List all modules.
39- gomod: Go to the directory containing a module.
Rett Berg78d1c932019-01-24 14:34:23 -080040- pathmod: Get the directory containing a module.
Cole Faust24c36db2021-01-23 02:39:37 +000041- outmod: Gets the location of a module's installed outputs with a certain extension.
Joe Onorato2c1aa472021-02-25 16:42:39 -080042- dirmods: Gets the modules defined in a given directory.
Cole Faust24c36db2021-01-23 02:39:37 +000043- installmod: Adb installs a module's built APK.
44- refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod.
Steven Moreland74114f12020-09-10 01:23:32 +000045- syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070046
Roland Levillain39341922015-10-20 12:48:19 +010047Environment options:
Steven Moreland115d1f52019-09-26 16:30:28 -070048- SANITIZE_HOST: Set to 'address' to use ASAN for all host modules.
Sasha Smundak9f27cc02019-01-31 13:25:31 -080049- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
Dan Albert4ae5d4b2014-10-31 16:23:08 -070050
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070051Look at the source to view more functions. The complete list is:
52EOF
Christopher Ferris55257d22017-03-23 11:08:58 -070053 local T=$(gettop)
54 local A=""
55 local i
Jacky Cao89483b82015-05-15 22:12:53 +080056 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 -070057 A="$A $i"
58 done
59 echo $A
60}
61
Ying Wang08800fd2016-03-03 20:57:21 -080062# Get all the build variables needed by this script in a single call to the build system.
Matt Alexanderd9c56562020-05-21 10:49:17 +000063function build_build_var_cache()
64{
Christopher Ferris55257d22017-03-23 11:08:58 -070065 local T=$(gettop)
Ying Wang08800fd2016-03-03 20:57:21 -080066 # Grep out the variable names from the script.
Jim Tanga881a252018-06-19 16:34:41 +080067 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' ' '`)
68 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 -080069 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
Steven Moreland05402962018-01-05 12:13:11 -080070 build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
Jim Tanga881a252018-06-19 16:34:41 +080071 --vars="${cached_vars[*]}" \
72 --abs-vars="${cached_abs_vars[*]}" \
Dan Willemsenaf88c412017-07-14 11:29:44 -070073 --var-prefix=var_cache_ \
74 --abs-var-prefix=abs_var_cache_`
Ying Wang08800fd2016-03-03 20:57:21 -080075 local ret=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +000076 if [ $ret -ne 0 ]
77 then
Ying Wang08800fd2016-03-03 20:57:21 -080078 unset build_dicts_script
79 return $ret
80 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -070081 # Execute the script to store the "<val>=<value>" pairs as shell variables.
Ying Wang08800fd2016-03-03 20:57:21 -080082 eval "$build_dicts_script"
Ying Wang08800fd2016-03-03 20:57:21 -080083 ret=$?
Ying Wangf0cb3972016-03-04 13:56:23 -080084 unset build_dicts_script
Matt Alexanderd9c56562020-05-21 10:49:17 +000085 if [ $ret -ne 0 ]
86 then
Ying Wang08800fd2016-03-03 20:57:21 -080087 return $ret
88 fi
89 BUILD_VAR_CACHE_READY="true"
90}
91
Ying Wangf0cb3972016-03-04 13:56:23 -080092# Delete the build var cache, so that we can still call into the build system
Ying Wang08800fd2016-03-03 20:57:21 -080093# to get build variables not listed in this script.
Matt Alexanderd9c56562020-05-21 10:49:17 +000094function destroy_build_var_cache()
95{
Ying Wang08800fd2016-03-03 20:57:21 -080096 unset BUILD_VAR_CACHE_READY
Christopher Ferris55257d22017-03-23 11:08:58 -070097 local v
Ying Wang08800fd2016-03-03 20:57:21 -080098 for v in $cached_vars; do
99 unset var_cache_$v
100 done
101 unset cached_vars
102 for v in $cached_abs_vars; do
103 unset abs_var_cache_$v
104 done
105 unset cached_abs_vars
106}
107
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700108# Get the value of a build variable as an absolute path.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000109function get_abs_build_var()
110{
111 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
112 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800113 eval "echo \"\${abs_var_cache_$1}\""
Timi0469c3f2021-04-15 16:41:18 +0200114 return
Ying Wang08800fd2016-03-03 20:57:21 -0800115 fi
116
Christopher Ferris55257d22017-03-23 11:08:58 -0700117 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700118 if [ ! "$T" ]; then
119 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
120 return
121 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700122 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700123}
124
125# Get the exact value of a build variable.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000126function get_build_var()
127{
128 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
129 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800130 eval "echo \"\${var_cache_$1}\""
Roland Levillain23c46cf2020-03-31 16:11:05 +0100131 return 0
Ying Wang08800fd2016-03-03 20:57:21 -0800132 fi
133
Christopher Ferris55257d22017-03-23 11:08:58 -0700134 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700135 if [ ! "$T" ]; then
136 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
Roland Levillain23c46cf2020-03-31 16:11:05 +0100137 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700138 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700139 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800140}
141
142# check to see if the supplied product is one we can build
Matt Alexanderd9c56562020-05-21 10:49:17 +0000143function check_product()
144{
Christopher Ferris55257d22017-03-23 11:08:58 -0700145 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800146 if [ ! "$T" ]; then
147 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
148 return
149 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700150 TARGET_PRODUCT=$1 \
151 TARGET_BUILD_VARIANT= \
152 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700153 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800154 get_build_var TARGET_DEVICE > /dev/null
155 # hide successful answers, but allow the errors to show
156}
157
158VARIANT_CHOICES=(user userdebug eng)
159
160# check to see if the supplied variant is valid
Matt Alexanderd9c56562020-05-21 10:49:17 +0000161function check_variant()
162{
Christopher Ferris55257d22017-03-23 11:08:58 -0700163 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800164 for v in ${VARIANT_CHOICES[@]}
165 do
Matt Alexanderd9c56562020-05-21 10:49:17 +0000166 if [ "$v" = "$1" ]
167 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800168 return 0
169 fi
170 done
171 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700172}
173
Matt Alexanderd9c56562020-05-21 10:49:17 +0000174function setpaths()
175{
Christopher Ferris55257d22017-03-23 11:08:58 -0700176 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700177 if [ ! "$T" ]; then
178 echo "Couldn't locate the top of the tree. Try setting TOP."
179 return
180 fi
181
182 ##################################################################
183 # #
184 # Read me before you modify this code #
185 # #
186 # This function sets ANDROID_BUILD_PATHS to what it is adding #
187 # to PATH, and the next time it is run, it removes that from #
188 # PATH. This is required so lunch can be run more than once #
189 # and still have working paths. #
190 # #
191 ##################################################################
192
Raphael Mollc639c782011-06-20 17:25:01 -0700193 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
194 # due to "C:\Program Files" being in the path.
195
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700196 # out with the old
Matt Alexanderd9c56562020-05-21 10:49:17 +0000197 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700198 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
199 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000200 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700201 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800202 # strip leading ':', if any
203 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500204 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700205
206 # and in with the new
Christopher Ferris55257d22017-03-23 11:08:58 -0700207 local prebuiltdir=$(getprebuilt)
208 local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700209
Ben Cheng8bc4c432012-11-16 13:29:13 -0800210 # defined in core/config.mk
Christopher Ferris55257d22017-03-23 11:08:58 -0700211 local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
212 local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800213 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800214
Raphael Mollc639c782011-06-20 17:25:01 -0700215 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800216 export ANDROID_TOOLCHAIN=
217 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200218 local ARCH=$(get_build_var TARGET_ARCH)
Christopher Ferris55257d22017-03-23 11:08:58 -0700219 local toolchaindir toolchaindir2=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200220 case $ARCH in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000221 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700222 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000223 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Pavel Chupinfd82a492012-11-26 09:50:07 +0400224 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000225 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200226 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000227 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
228 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700229 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200230 *)
231 echo "Can't find toolchain for unknown architecture: $ARCH"
232 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700233 ;;
234 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700235 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800236 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700237 fi
Raphael732936d2011-06-22 14:35:32 -0700238
Christopher Ferris55257d22017-03-23 11:08:58 -0700239 if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800240 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
241 fi
242
Dan Willemsen838dcec2021-09-30 22:40:34 +0000243 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Yueyao Zhuefc786a2017-04-07 14:11:54 -0700244
245 # add kernel specific binaries
246 case $(uname -s) in
247 Linux)
248 export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
249 ;;
250 *)
251 ;;
252 esac
253
Torne (Richard Coles)0091bae2017-10-03 16:31:18 -0400254 ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN
Martin Stjernholm6a012262021-11-24 14:56:15 +0000255 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH
Yi Kongdfd00b12019-05-21 16:00:04 -0700256 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS
257
258 # Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS.
259 local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
260 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200261
Stephen Hinesaa8d72c2020-02-04 09:15:18 -0800262 # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds.
263 export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer
264
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200265 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
266 # to ensure that the corresponding 'emulator' binaries are used.
267 case $(uname -s) in
268 Darwin)
269 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
270 ;;
271 Linux)
272 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
273 ;;
274 *)
275 ANDROID_EMULATOR_PREBUILTS=
276 ;;
277 esac
278 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Yi Kongdfd00b12019-05-21 16:00:04 -0700279 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200280 export ANDROID_EMULATOR_PREBUILTS
281 fi
282
Jim Tangb3fda302018-12-22 10:24:55 +0800283 # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
284 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
Ryan Prichard8426a192019-07-15 18:05:29 -0700285 local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch"
286 local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch"
287 local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch"
Martin Stjernholm6a012262021-11-24 14:56:15 +0000288 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH
Jim Tangb3fda302018-12-22 10:24:55 +0800289
Martin Stjernholm6a012262021-11-24 14:56:15 +0000290 export ANDROID_BUILD_PATHS=$(tr -s : <<<"${ANDROID_BUILD_PATHS}:")
Ryan Prichard8426a192019-07-15 18:05:29 -0700291 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800292
293 # out with the duplicate old
294 if [ -n $ANDROID_PYTHONPATH ]; then
295 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
296 fi
297 # and in with the new
298 export ANDROID_PYTHONPATH=$T/development/python-packages:
Jim Tangc4dba1d2019-07-25 16:54:27 +0800299 if [ -n $VENDOR_PYTHONPATH ]; then
300 ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
301 fi
Jim Tang22f4c322018-12-17 15:21:53 +0800302 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303
Colin Crosse97e6932017-06-30 16:01:45 -0700304 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
305 export JAVA_HOME=$ANDROID_JAVA_HOME
306 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
307 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
308 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500309
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800310 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700311 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
312 export OUT=$ANDROID_PRODUCT_OUT
313
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700314 unset ANDROID_HOST_OUT
315 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
316
Jiyong Parkc02b1c42020-11-03 11:06:39 +0900317 unset ANDROID_SOONG_HOST_OUT
318 export ANDROID_SOONG_HOST_OUT=$(get_abs_build_var SOONG_HOST_OUT)
319
Simran Basidd050ed2017-02-13 13:46:48 -0800320 unset ANDROID_HOST_OUT_TESTCASES
321 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
322
323 unset ANDROID_TARGET_OUT_TESTCASES
324 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
325
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800326 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700327 # TODO: fix the path
328 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
329}
330
Rupert Shuttleworth5d60d022020-10-25 05:20:03 +0000331function bazel()
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000332{
Jingwen Chen17d56992021-06-10 08:17:54 +0000333 if which bazel &>/dev/null; then
334 >&2 echo "NOTE: bazel() function sourced from Android's envsetup.sh is being used instead of $(which bazel)"
335 >&2 echo
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000336 fi
337
Jingwen Chen17d56992021-06-10 08:17:54 +0000338 local T="$(gettop)"
339 if [ ! "$T" ]; then
340 >&2 echo "Couldn't locate the top of the Android tree. Try setting TOP. This bazel() function cannot be used outside of the AOSP directory."
341 return
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000342 fi
343
Rupert Shuttleworth5d60d022020-10-25 05:20:03 +0000344 "$T/tools/bazel" "$@"
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000345}
346
Matt Alexanderd9c56562020-05-21 10:49:17 +0000347function printconfig()
348{
Christopher Ferris55257d22017-03-23 11:08:58 -0700349 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800350 if [ ! "$T" ]; then
351 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
352 return
353 fi
354 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700355}
356
Matt Alexanderd9c56562020-05-21 10:49:17 +0000357function set_stuff_for_environment()
358{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800359 setpaths
360 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700361
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800362 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700363 # With this environment variable new GCC can apply colors to warnings/errors
364 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 -0700365}
366
Matt Alexanderd9c56562020-05-21 10:49:17 +0000367function set_sequence_number()
368{
Colin Cross88737132017-03-21 17:41:03 -0700369 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700370}
371
Makoto Onukida971062018-06-18 10:15:19 -0700372# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
373function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800374 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700375 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800376 *:"$cmd":*)
377 return 1
378 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700379 esac
380 return 0
381}
382
Matt Alexanderd9c56562020-05-21 10:49:17 +0000383function addcompletions()
384{
Ben Taitelbaum8c2c9cf2020-09-22 16:45:05 -0700385 local f=
Kenny Root52aa81c2011-07-15 11:07:06 -0700386
Jim Tanga881a252018-06-19 16:34:41 +0800387 # Keep us from trying to run in something that's neither bash nor zsh.
388 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700389 return
390 fi
391
392 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800393 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700394 return
395 fi
396
Jim Tanga881a252018-06-19 16:34:41 +0800397 local completion_files=(
MÃ¥rten Kongstadcb5c73f2022-05-04 14:08:12 +0000398 packages/modules/adb/adb.bash
Jim Tanga881a252018-06-19 16:34:41 +0800399 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800400 tools/asuite/asuite.sh
Jim Tanga881a252018-06-19 16:34:41 +0800401 )
Makoto Onukida971062018-06-18 10:15:19 -0700402 # Completion can be disabled selectively to allow users to use non-standard completion.
403 # e.g.
404 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
405 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800406 for f in ${completion_files[*]}; do
MÃ¥rten Kongstadcb5c73f2022-05-04 14:08:12 +0000407 if [ ! -f "$f" ]; then
408 echo "Warning: completion file $f not found"
409 elif should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700410 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700411 fi
412 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700413
Matt Alexanderd9c56562020-05-21 10:49:17 +0000414 if should_add_completion bit ; then
Makoto Onukida971062018-06-18 10:15:19 -0700415 complete -C "bit --tab" bit
416 fi
Anton Hanssonece9c482019-02-04 18:15:39 +0000417 if [ -z "$ZSH_VERSION" ]; then
418 # Doesn't work in zsh.
419 complete -o nospace -F _croot croot
420 fi
Jim Tanga881a252018-06-19 16:34:41 +0800421 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800422
Cole Faust24c36db2021-01-23 02:39:37 +0000423 complete -F _complete_android_module_names pathmod
dimitry73b84812018-12-11 18:06:00 +0100424 complete -F _complete_android_module_names gomod
Cole Faust24c36db2021-01-23 02:39:37 +0000425 complete -F _complete_android_module_names outmod
426 complete -F _complete_android_module_names installmod
dimitry73b84812018-12-11 18:06:00 +0100427 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700428}
429
Joe Onorato824608c2022-04-08 11:06:16 -0700430function multitree_lunch_help()
431{
432 echo "usage: lunch PRODUCT-VARIANT" 1>&2
433 echo " Set up android build environment based on a product short name and variant" 1>&2
434 echo 1>&2
435 echo "lunch COMBO_FILE VARIANT" 1>&2
436 echo " Set up android build environment based on a specific lunch combo file" 1>&2
437 echo " and variant." 1>&2
438 echo 1>&2
439 echo "lunch --print [CONFIG]" 1>&2
440 echo " Print the contents of a configuration. If CONFIG is supplied, that config" 1>&2
441 echo " will be flattened and printed. If CONFIG is not supplied, the currently" 1>&2
442 echo " selected config will be printed. Returns 0 on success or nonzero on error." 1>&2
443 echo 1>&2
444 echo "lunch --list" 1>&2
445 echo " List all possible combo files available in the current tree" 1>&2
446 echo 1>&2
447 echo "lunch --help" 1>&2
448 echo "lunch -h" 1>&2
449 echo " Prints this message." 1>&2
450}
451
452function multitree_lunch()
453{
454 local code
455 local results
456 if $(echo "$1" | grep -q '^-') ; then
457 # Calls starting with a -- argument are passed directly and the function
458 # returns with the lunch.py exit code.
459 build/make/orchestrator/core/lunch.py "$@"
460 code=$?
461 if [[ $code -eq 2 ]] ; then
462 echo 1>&2
463 multitree_lunch_help
464 return $code
465 elif [[ $code -ne 0 ]] ; then
466 return $code
467 fi
468 else
469 # All other calls go through the --lunch variant of lunch.py
470 results=($(build/make/orchestrator/core/lunch.py --lunch "$@"))
471 code=$?
472 if [[ $code -eq 2 ]] ; then
473 echo 1>&2
474 multitree_lunch_help
475 return $code
476 elif [[ $code -ne 0 ]] ; then
477 return $code
478 fi
479
480 export TARGET_BUILD_COMBO=${results[0]}
481 export TARGET_BUILD_VARIANT=${results[1]}
482 fi
483}
484
Matt Alexanderd9c56562020-05-21 10:49:17 +0000485function choosetype()
486{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700487 echo "Build type choices are:"
488 echo " 1. release"
489 echo " 2. debug"
490 echo
491
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700493 DEFAULT_NUM=1
494 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700495
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800496 export TARGET_BUILD_TYPE=
497 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700498 while [ -z $TARGET_BUILD_TYPE ]
499 do
500 echo -n "Which would you like? ["$DEFAULT_NUM"] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000501 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800502 read ANSWER
503 else
504 echo $1
505 ANSWER=$1
506 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700507 case $ANSWER in
508 "")
509 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
510 ;;
511 1)
512 export TARGET_BUILD_TYPE=release
513 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800514 release)
515 export TARGET_BUILD_TYPE=release
516 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700517 2)
518 export TARGET_BUILD_TYPE=debug
519 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520 debug)
521 export TARGET_BUILD_TYPE=debug
522 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700523 *)
524 echo
525 echo "I didn't understand your response. Please try again."
526 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700527 ;;
528 esac
Matt Alexanderd9c56562020-05-21 10:49:17 +0000529 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530 break
531 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700532 done
533
Ying Wang08800fd2016-03-03 20:57:21 -0800534 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700535 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800536 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700537}
538
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800539#
540# This function isn't really right: It chooses a TARGET_PRODUCT
541# based on the list of boards. Usually, that gets you something
542# that kinda works with a generic product, but really, you should
543# pick a product by name.
544#
Matt Alexanderd9c56562020-05-21 10:49:17 +0000545function chooseproduct()
546{
Christopher Ferris55257d22017-03-23 11:08:58 -0700547 local default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000548 if [ "x$TARGET_PRODUCT" != x ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700549 default_value=$TARGET_PRODUCT
550 else
Ying Wang0a76df52015-06-08 11:57:26 -0700551 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700552 fi
553
Ying Wang08800fd2016-03-03 20:57:21 -0800554 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800555 export TARGET_PRODUCT=
556 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700557 while [ -z "$TARGET_PRODUCT" ]
558 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700559 echo -n "Which product would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000560 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800561 read ANSWER
562 else
563 echo $1
564 ANSWER=$1
565 fi
566
Matt Alexanderd9c56562020-05-21 10:49:17 +0000567 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700568 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800569 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000570 if check_product $ANSWER
571 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800572 export TARGET_PRODUCT=$ANSWER
573 else
574 echo "** Not a valid product: $ANSWER"
575 fi
576 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000577 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800578 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700579 fi
580 done
581
Ying Wang08800fd2016-03-03 20:57:21 -0800582 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700583 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800584 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585}
586
Matt Alexanderd9c56562020-05-21 10:49:17 +0000587function choosevariant()
588{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589 echo "Variant choices are:"
590 local index=1
591 local v
592 for v in ${VARIANT_CHOICES[@]}
593 do
594 # The product name is the name of the directory containing
595 # the makefile we found, above.
596 echo " $index. $v"
597 index=$(($index+1))
598 done
599
600 local default_value=eng
601 local ANSWER
602
603 export TARGET_BUILD_VARIANT=
604 while [ -z "$TARGET_BUILD_VARIANT" ]
605 do
606 echo -n "Which would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000607 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800608 read ANSWER
609 else
610 echo $1
611 ANSWER=$1
612 fi
613
Matt Alexanderd9c56562020-05-21 10:49:17 +0000614 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800615 export TARGET_BUILD_VARIANT=$default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000616 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
617 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Guillaume Chelfice000fd2019-10-03 12:02:46 +0200618 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800619 fi
620 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000621 if check_variant $ANSWER
622 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800623 export TARGET_BUILD_VARIANT=$ANSWER
624 else
625 echo "** Not a valid variant: $ANSWER"
626 fi
627 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000628 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800629 break
630 fi
631 done
632}
633
Matt Alexanderd9c56562020-05-21 10:49:17 +0000634function choosecombo()
635{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700636 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700637
638 echo
639 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700640 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700641
642 echo
643 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700644 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800645
646 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800647 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700648 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800649 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800650 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651}
652
Matt Alexanderd9c56562020-05-21 10:49:17 +0000653function add_lunch_combo()
654{
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800655 if [ -n "$ZSH_VERSION" ]; then
656 echo -n "${funcfiletrace[1]}: "
657 else
658 echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
659 fi
660 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 -0800661}
662
Matt Alexanderd9c56562020-05-21 10:49:17 +0000663function print_lunch_menu()
664{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700665 local uname=$(uname)
Roland Levillain23c46cf2020-03-31 16:11:05 +0100666 local choices
Colin Crossfa50d402021-04-22 13:05:41 -0700667 choices=$(TARGET_BUILD_APPS= TARGET_PRODUCT= TARGET_BUILD_VARIANT= get_build_var COMMON_LUNCH_CHOICES 2>/dev/null)
Roland Levillain23c46cf2020-03-31 16:11:05 +0100668 local ret=$?
669
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700670 echo
671 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672 echo
Roland Levillain23c46cf2020-03-31 16:11:05 +0100673
Matt Alexanderd9c56562020-05-21 10:49:17 +0000674 if [ $ret -ne 0 ]
675 then
Roland Levillain23c46cf2020-03-31 16:11:05 +0100676 echo "Warning: Cannot display lunch menu."
677 echo
678 echo "Note: You can invoke lunch with an explicit target:"
679 echo
680 echo " usage: lunch [target]" >&2
681 echo
682 return
683 fi
684
Will Burr40401202022-02-07 12:12:01 +0000685 echo "Lunch menu .. Here are the common combinations:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800686
687 local i=1
688 local choice
Dan Willemsen91763e92019-10-03 15:13:12 -0700689 for choice in $(echo $choices)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800690 do
691 echo " $i. $choice"
692 i=$(($i+1))
693 done
694
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700695 echo
696}
697
Matt Alexanderd9c56562020-05-21 10:49:17 +0000698function lunch()
699{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800700 local answer
701
Steven Moreland92793dc2020-02-25 18:30:18 -0800702 if [[ $# -gt 1 ]]; then
703 echo "usage: lunch [target]" >&2
704 return 1
705 fi
706
Will Burr40401202022-02-07 12:12:01 +0000707 local used_lunch_menu=0
708
Steven Moreland92793dc2020-02-25 18:30:18 -0800709 if [ "$1" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800710 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700711 else
712 print_lunch_menu
Will Burr40401202022-02-07 12:12:01 +0000713 echo "Which would you like? [aosp_arm-eng]"
714 echo -n "Pick from common choices above (e.g. 13) or specify your own (e.g. aosp_barbet-eng): "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800715 read answer
Will Burr40401202022-02-07 12:12:01 +0000716 used_lunch_menu=1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700717 fi
718
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800719 local selection=
720
Matt Alexanderd9c56562020-05-21 10:49:17 +0000721 if [ -z "$answer" ]
722 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700723 selection=aosp_arm-eng
Matt Alexanderd9c56562020-05-21 10:49:17 +0000724 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
725 then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800726 local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
Matt Alexanderd9c56562020-05-21 10:49:17 +0000727 if [ $answer -le ${#choices[@]} ]
728 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800729 # array in zsh starts from 1 instead of 0.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000730 if [ -n "$ZSH_VERSION" ]
731 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800732 selection=${choices[$(($answer))]}
733 else
734 selection=${choices[$(($answer-1))]}
735 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800736 fi
Colin Cross88737132017-03-21 17:41:03 -0700737 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800738 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700739 fi
740
Joe Onoratoda12daf2010-06-09 18:18:31 -0700741 export TARGET_BUILD_APPS=
742
Colin Cross88737132017-03-21 17:41:03 -0700743 local product variant_and_version variant version
Colin Cross88737132017-03-21 17:41:03 -0700744 product=${selection%%-*} # Trim everything after first dash
745 variant_and_version=${selection#*-} # Trim everything up to first dash
746 if [ "$variant_and_version" != "$selection" ]; then
747 variant=${variant_and_version%%-*}
748 if [ "$variant" != "$variant_and_version" ]; then
749 version=${variant_and_version#*-}
750 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700751 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800752
Matt Alexanderd9c56562020-05-21 10:49:17 +0000753 if [ -z "$product" ]
754 then
Ying Wang08800fd2016-03-03 20:57:21 -0800755 echo
Colin Cross88737132017-03-21 17:41:03 -0700756 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700757 return 1
758 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800759
Colin Cross88737132017-03-21 17:41:03 -0700760 TARGET_PRODUCT=$product \
761 TARGET_BUILD_VARIANT=$variant \
762 TARGET_PLATFORM_VERSION=$version \
763 build_build_var_cache
Matt Alexanderd9c56562020-05-21 10:49:17 +0000764 if [ $? -ne 0 ]
765 then
Anton Hansson32fa7ee2021-06-14 17:09:58 +0100766 if [[ "$product" =~ .*_(eng|user|userdebug) ]]
767 then
768 echo "Did you mean -${product/*_/}? (dash instead of underscore)"
769 fi
Colin Cross88737132017-03-21 17:41:03 -0700770 return 1
771 fi
Colin Cross88737132017-03-21 17:41:03 -0700772 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
773 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700774 if [ -n "$version" ]; then
775 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
776 else
777 unset TARGET_PLATFORM_VERSION
778 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700779 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700780
Will Burr40401202022-02-07 12:12:01 +0000781 if [ $used_lunch_menu -eq 1 ]; then
782 echo
783 echo "Hint: next time you can simply run 'lunch $selection'"
784 fi
785
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700786 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800787
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700788 set_stuff_for_environment
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700789 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800790 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791}
792
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700793unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700794# Tab completion for lunch.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000795function _lunch()
796{
Jeff Davidson513d7a42010-08-02 10:00:44 -0700797 local cur prev opts
798 COMPREPLY=()
799 cur="${COMP_WORDS[COMP_CWORD]}"
800 prev="${COMP_WORDS[COMP_CWORD-1]}"
801
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700802 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800803 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700804 fi
805
806 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700807 return 0
808}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700809
Joe Onoratoda12daf2010-06-09 18:18:31 -0700810# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700811# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Matt Alexanderd9c56562020-05-21 10:49:17 +0000812function tapas()
813{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700814 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Elliott Hughesf71c05a2020-03-06 16:46:59 -0800815 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700816 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700817 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 -0800818 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 -0700819
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700820 if [ "$showHelp" != "" ]; then
821 $(gettop)/build/make/tapasHelp.sh
822 return
823 fi
824
Ying Wang67f02922012-08-22 10:25:20 -0700825 if [ $(echo $arch | wc -w) -gt 1 ]; then
826 echo "tapas: Error: Multiple build archs supplied: $arch"
827 return
828 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700829 if [ $(echo $variant | wc -w) -gt 1 ]; then
830 echo "tapas: Error: Multiple build variants supplied: $variant"
831 return
832 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700833 if [ $(echo $density | wc -w) -gt 1 ]; then
834 echo "tapas: Error: Multiple densities supplied: $density"
835 return
836 fi
Ying Wang67f02922012-08-22 10:25:20 -0700837
Ying Wang0a76df52015-06-08 11:57:26 -0700838 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700839 case $arch in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000840 x86) product=aosp_x86;;
841 arm64) product=aosp_arm64;;
842 x86_64) product=aosp_x86_64;;
Ying Wang67f02922012-08-22 10:25:20 -0700843 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700844 if [ -z "$variant" ]; then
845 variant=eng
846 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700847 if [ -z "$apps" ]; then
848 apps=all
849 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600850 if [ -z "$density" ]; then
851 density=alldpi
852 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700853
Ying Wang67f02922012-08-22 10:25:20 -0700854 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700855 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700856 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700857 export TARGET_BUILD_TYPE=release
858 export TARGET_BUILD_APPS=$apps
859
Ying Wang08800fd2016-03-03 20:57:21 -0800860 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700861 set_stuff_for_environment
862 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800863 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700864}
865
Martin Stjernholmf692c752021-04-12 00:01:10 +0100866# Configures the build to build unbundled Android modules (APEXes).
867# Run banchan with one or more module names (from apex{} modules).
868function banchan()
869{
870 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100871 local product="$(echo $* | xargs -n 1 echo | \grep -E '^(.*_)?(arm|x86|arm64|x86_64)$' | xargs)"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100872 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100873 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|(.*_)?(arm|x86|arm64|x86_64))$' | xargs)"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100874
875 if [ "$showHelp" != "" ]; then
876 $(gettop)/build/make/banchanHelp.sh
877 return
878 fi
879
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100880 if [ -z "$product" ]; then
881 product=arm
882 elif [ $(echo $product | wc -w) -gt 1 ]; then
883 echo "banchan: Error: Multiple build archs or products supplied: $products"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100884 return
885 fi
886 if [ $(echo $variant | wc -w) -gt 1 ]; then
887 echo "banchan: Error: Multiple build variants supplied: $variant"
888 return
889 fi
890 if [ -z "$apps" ]; then
891 echo "banchan: Error: No modules supplied"
892 return
893 fi
894
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100895 case $product in
896 arm) product=module_arm;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100897 x86) product=module_x86;;
898 arm64) product=module_arm64;;
899 x86_64) product=module_x86_64;;
900 esac
901 if [ -z "$variant" ]; then
902 variant=eng
903 fi
904
905 export TARGET_PRODUCT=$product
906 export TARGET_BUILD_VARIANT=$variant
907 export TARGET_BUILD_DENSITY=alldpi
908 export TARGET_BUILD_TYPE=release
909
910 # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use
911 # case is different and it may diverge in the future.
912 export TARGET_BUILD_APPS=$apps
913
914 build_build_var_cache
915 set_stuff_for_environment
916 printconfig
917 destroy_build_var_cache
918}
919
Matt Alexanderd9c56562020-05-21 10:49:17 +0000920function gettop
921{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700922 local TOPFILE=build/make/core/envsetup.mk
Matt Alexanderd9c56562020-05-21 10:49:17 +0000923 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700924 # The following circumlocution ensures we remove symlinks from TOP.
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000925 (cd "$TOP"; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700926 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000927 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800928 # The following circumlocution (repeated below as well) ensures
929 # that we record the true directory name and not one that is
930 # faked up with symlink names.
931 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700932 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800933 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700934 local T=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000935 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800936 \cd ..
synergyb112a402013-07-05 19:47:47 -0700937 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700938 done
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000939 \cd "$HERE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700940 if [ -f "$T/$TOPFILE" ]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000941 echo "$T"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700942 fi
943 fi
944 fi
945}
946
Matt Alexanderd9c56562020-05-21 10:49:17 +0000947function croot()
948{
Christopher Ferris55257d22017-03-23 11:08:58 -0700949 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700950 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700951 if [ "$1" ]; then
952 \cd $(gettop)/$1
953 else
954 \cd $(gettop)
955 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700956 else
957 echo "Couldn't locate the top of the tree. Try setting TOP."
958 fi
959}
960
Matt Alexanderd9c56562020-05-21 10:49:17 +0000961function _croot()
962{
Anton Hanssonece9c482019-02-04 18:15:39 +0000963 local T=$(gettop)
964 if [ "$T" ]; then
965 local cur="${COMP_WORDS[COMP_CWORD]}"
966 k=0
967 for c in $(compgen -d ${T}/${cur}); do
968 COMPREPLY[k++]=${c#${T}/}/
969 done
970 fi
971}
972
Matt Alexanderd9c56562020-05-21 10:49:17 +0000973function cproj()
974{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700975 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700976 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700977 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700978 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
979 T=$PWD
980 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800981 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700982 return
983 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800984 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700985 done
Ying Wang9cd17642012-12-13 10:52:07 -0800986 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700987 echo "can't find Android.mk"
988}
989
Daniel Sandler47e0a882013-07-30 13:23:52 -0400990# simplified version of ps; output in the form
991# <pid> <procname>
992function qpid() {
993 local prepend=''
994 local append=''
Matt Alexanderd9c56562020-05-21 10:49:17 +0000995 if [ "$1" = "--exact" ]; then
Daniel Sandler47e0a882013-07-30 13:23:52 -0400996 prepend=' '
997 append='$'
998 shift
Matt Alexanderd9c56562020-05-21 10:49:17 +0000999 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001000 echo "usage: qpid [[--exact] <process name|pid>"
1001 return 255
1002 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001003
1004 local EXE="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001005 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001006 qpid | \grep "$prepend$EXE$append"
1007 else
1008 adb shell ps \
1009 | tr -d '\r' \
1010 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1011 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001012}
1013
Steven Moreland74114f12020-09-10 01:23:32 +00001014# syswrite - disable verity, reboot if needed, and remount image
1015#
1016# Easy way to make system.img/etc writable
1017function syswrite() {
1018 adb wait-for-device && adb root || return 1
1019 if [[ $(adb disable-verity | grep "reboot") ]]; then
1020 echo "rebooting"
1021 adb reboot && adb wait-for-device && adb root || return 1
1022 fi
1023 adb wait-for-device && adb remount || return 1
1024}
1025
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001026# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001027# that has the core-file-size limit set correctly
1028#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001029# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001030# if its core-file-size limit is not set already.
1031# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1032
Matt Alexanderd9c56562020-05-21 10:49:17 +00001033function coredump_setup()
1034{
1035 echo "Getting root...";
1036 adb root;
1037 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001038
Matt Alexanderd9c56562020-05-21 10:49:17 +00001039 echo "Remounting root partition read-write...";
1040 adb shell mount -w -o remount -t rootfs rootfs;
1041 sleep 1;
1042 adb wait-for-device;
1043 adb shell mkdir -p /cores;
1044 adb shell mount -t tmpfs tmpfs /cores;
1045 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001046
Matt Alexanderd9c56562020-05-21 10:49:17 +00001047 echo "Granting SELinux permission to dump in /cores...";
1048 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001049
Matt Alexanderd9c56562020-05-21 10:49:17 +00001050 echo "Set core pattern.";
1051 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001052
Ying Wang08800fd2016-03-03 20:57:21 -08001053 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001054}
1055
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001056# coredump_enable - enable core dumps for the specified process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001057# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001058#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001059# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001060# dump to actually be generated.
1061
Matt Alexanderd9c56562020-05-21 10:49:17 +00001062function coredump_enable()
1063{
1064 local PID=$1;
Ying Wang08800fd2016-03-03 20:57:21 -08001065 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001066 printf "Expecting a PID!\n";
1067 return;
1068 fi;
1069 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001070 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001071}
1072
1073# core - send SIGV and pull the core for process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001074# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001075#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001076# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001077# enabled globally.
1078
Matt Alexanderd9c56562020-05-21 10:49:17 +00001079function core()
1080{
1081 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001082
Ying Wang08800fd2016-03-03 20:57:21 -08001083 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001084 printf "Expecting a PID!\n";
1085 return;
1086 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001087
Matt Alexanderd9c56562020-05-21 10:49:17 +00001088 local CORENAME=core.$PID;
1089 local COREPATH=/cores/$CORENAME;
1090 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001091
Matt Alexanderd9c56562020-05-21 10:49:17 +00001092 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001093
Matt Alexanderd9c56562020-05-21 10:49:17 +00001094 local done=0;
Ying Wang08800fd2016-03-03 20:57:21 -08001095 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
Matt Alexanderd9c56562020-05-21 10:49:17 +00001096 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1097 adb shell kill -$SIG $PID;
1098 sleep 1;
1099 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001100
Matt Alexanderd9c56562020-05-21 10:49:17 +00001101 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1102 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001103}
1104
Christopher Tate744ee802009-11-12 15:33:08 -08001105# systemstack - dump the current stack trace of all threads in the system process
1106# to the usual ANR traces file
Matt Alexanderd9c56562020-05-21 10:49:17 +00001107function systemstack()
1108{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001109 stacks system_server
1110}
1111
Michael Wrightaeed7212014-06-19 19:58:12 -07001112# Read the ELF header from /proc/$PID/exe to determine if the process is
1113# 64-bit.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001114function is64bit()
1115{
Ben Chengfba67bf2014-02-25 10:27:07 -08001116 local PID="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001117 if [ "$PID" ] ; then
1118 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001119 echo "64"
1120 else
1121 echo ""
1122 fi
1123 else
1124 echo ""
1125 fi
1126}
1127
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001128case `uname -s` in
1129 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001130 function sgrep()
1131 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001132 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|hpp|S|java|kt|xml|sh|mk|aidl|vts|proto)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001133 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001134 }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001135
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001136 ;;
1137 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001138 function sgrep()
1139 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001140 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|hpp\|S\|java\|kt\|xml\|sh\|mk\|aidl\|vts\|proto\)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001141 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001142 }
1143 ;;
1144esac
1145
Matt Alexanderd9c56562020-05-21 10:49:17 +00001146function gettargetarch
1147{
Raghu Gandham8da43102012-07-25 19:57:22 -07001148 get_build_var TARGET_ARCH
1149}
1150
Matt Alexanderd9c56562020-05-21 10:49:17 +00001151function ggrep()
1152{
Mike Frysinger5e479732015-09-22 18:13:48 -04001153 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1154 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001155}
1156
Matt Alexanderd9c56562020-05-21 10:49:17 +00001157function gogrep()
1158{
Orion Hodson831472d2019-10-25 11:35:15 +01001159 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
1160 -exec grep --color -n "$@" {} +
1161}
1162
Matt Alexanderd9c56562020-05-21 10:49:17 +00001163function jgrep()
1164{
Mike Frysinger5e479732015-09-22 18:13:48 -04001165 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1166 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001167}
1168
Alistair Delva176e5342021-02-22 13:31:26 -08001169function rsgrep()
Jeff Vander Stoep1431ab82021-02-02 19:18:26 +01001170{
1171 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rs" \
1172 -exec grep --color -n "$@" {} +
1173}
1174
Taesu Leeea0cecd2020-10-28 11:05:18 +09001175function ktgrep()
1176{
1177 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.kt" \
1178 -exec grep --color -n "$@" {} +
1179}
1180
Matt Alexanderd9c56562020-05-21 10:49:17 +00001181function cgrep()
1182{
Mike Frysinger5e479732015-09-22 18:13:48 -04001183 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' \) \
1184 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001185}
1186
Matt Alexanderd9c56562020-05-21 10:49:17 +00001187function resgrep()
1188{
Christopher Ferris55257d22017-03-23 11:08:58 -07001189 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001190 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1191 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1192 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001193}
1194
Matt Alexanderd9c56562020-05-21 10:49:17 +00001195function mangrep()
1196{
Mike Frysinger5e479732015-09-22 18:13:48 -04001197 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1198 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001199}
1200
Matt Alexanderd9c56562020-05-21 10:49:17 +00001201function owngrep()
1202{
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -06001203 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
1204 -exec grep --color -n "$@" {} +
1205}
1206
Matt Alexanderd9c56562020-05-21 10:49:17 +00001207function sepgrep()
1208{
Mike Frysinger5e479732015-09-22 18:13:48 -04001209 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1210 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001211}
1212
Matt Alexanderd9c56562020-05-21 10:49:17 +00001213function rcgrep()
1214{
Mike Frysinger5e479732015-09-22 18:13:48 -04001215 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1216 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001217}
1218
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001219case `uname -s` in
1220 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001221 function mgrep()
1222 {
Orion Hodson831472d2019-10-25 11:35:15 +01001223 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 -04001224 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001225 }
1226
Matt Alexanderd9c56562020-05-21 10:49:17 +00001227 function treegrep()
1228 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001229 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|hpp|S|java|kt|xml)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001230 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001231 }
1232
1233 ;;
1234 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001235 function mgrep()
1236 {
Orion Hodson831472d2019-10-25 11:35:15 +01001237 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 -04001238 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001239 }
1240
Matt Alexanderd9c56562020-05-21 10:49:17 +00001241 function treegrep()
1242 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001243 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|hpp|S|java|kt|xml)' -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001244 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001245 }
1246
1247 ;;
1248esac
1249
Matt Alexanderd9c56562020-05-21 10:49:17 +00001250function getprebuilt
1251{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001252 get_abs_build_var ANDROID_PREBUILTS
1253}
1254
Matt Alexanderd9c56562020-05-21 10:49:17 +00001255function tracedmdump()
1256{
Christopher Ferris55257d22017-03-23 11:08:58 -07001257 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001258 if [ ! "$T" ]; then
1259 echo "Couldn't locate the top of the tree. Try setting TOP."
1260 return
1261 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001262 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001263 local arch=$(gettargetarch)
1264 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001265
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001266 local TRACE=$1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001267 if [ ! "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001268 echo "usage: tracedmdump tracename"
1269 return
1270 fi
1271
Matt Alexanderd9c56562020-05-21 10:49:17 +00001272 if [ ! -r "$KERNEL" ] ; then
Jack Veenstra60116fc2009-04-09 18:12:34 -07001273 echo "Error: cannot find kernel: '$KERNEL'"
1274 return
1275 fi
1276
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001277 local BASETRACE=$(basename $TRACE)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001278 if [ "$BASETRACE" = "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001279 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1280 fi
1281
1282 echo "post-processing traces..."
1283 rm -f $TRACE/qtrace.dexlist
1284 post_trace $TRACE
1285 if [ $? -ne 0 ]; then
1286 echo "***"
1287 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1288 echo "***"
1289 return
1290 fi
1291 echo "generating dexlist output..."
1292 /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
1293 echo "generating dmtrace data..."
1294 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1295 echo "generating html file..."
1296 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1297 echo "done, see $TRACE/dmtrace.html for details"
1298 echo "or run:"
1299 echo " traceview $TRACE/dmtrace"
1300}
1301
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001302# communicate with a running device or emulator, set up necessary state,
1303# and run the hat command.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001304function runhat()
1305{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001306 # process standard adb options
1307 local adbTarget=""
Matt Alexanderd9c56562020-05-21 10:49:17 +00001308 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001309 adbTarget=$1
1310 shift 1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001311 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001312 adbTarget="$1 $2"
1313 shift 2
1314 fi
1315 local adbOptions=${adbTarget}
Matt Alexanderd9c56562020-05-21 10:49:17 +00001316 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001317
1318 # runhat options
1319 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001320
Matt Alexanderd9c56562020-05-21 10:49:17 +00001321 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001322 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001323 return
1324 fi
1325
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001326 # confirm hat is available
1327 if [ -z $(which hat) ]; then
1328 echo "hat is not available in this configuration."
1329 return
1330 fi
1331
Andy McFaddenb6289852010-07-12 08:00:19 -07001332 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001333 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001334 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001335 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001336 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001337 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001338 echo -n "> "
1339 read
1340
The Android Open Source Project88b60792009-03-03 19:28:42 -08001341 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001342
The Android Open Source Project88b60792009-03-03 19:28:42 -08001343 echo "Retrieving file $devFile..."
1344 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001345
The Android Open Source Project88b60792009-03-03 19:28:42 -08001346 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001347
The Android Open Source Project88b60792009-03-03 19:28:42 -08001348 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001349 echo "View the output by pointing your browser at http://localhost:7000/"
1350 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001351 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001352}
1353
Matt Alexanderd9c56562020-05-21 10:49:17 +00001354function getbugreports()
1355{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001356 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001357
1358 if [ ! "$reports" ]; then
1359 echo "Could not locate any bugreports."
1360 return
1361 fi
1362
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001363 local report
1364 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001365 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001366 echo "/sdcard/bugreports/${report}"
1367 adb pull /sdcard/bugreports/${report} ${report}
1368 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001369 done
1370}
1371
Matt Alexanderd9c56562020-05-21 10:49:17 +00001372function getsdcardpath()
1373{
Victoria Lease1b296b42012-08-21 15:44:06 -07001374 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1375}
1376
Matt Alexanderd9c56562020-05-21 10:49:17 +00001377function getscreenshotpath()
1378{
Victoria Lease1b296b42012-08-21 15:44:06 -07001379 echo "$(getsdcardpath)/Pictures/Screenshots"
1380}
1381
Matt Alexanderd9c56562020-05-21 10:49:17 +00001382function getlastscreenshot()
1383{
Victoria Lease1b296b42012-08-21 15:44:06 -07001384 local screenshot_path=$(getscreenshotpath)
1385 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 +00001386 if [ "$screenshot" = "" ]; then
Victoria Lease1b296b42012-08-21 15:44:06 -07001387 echo "No screenshots found."
1388 return
1389 fi
1390 echo "${screenshot}"
1391 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1392}
1393
Matt Alexanderd9c56562020-05-21 10:49:17 +00001394function startviewserver()
1395{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001396 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001397 if [ $# -gt 0 ]; then
1398 port=$1
1399 fi
1400 adb shell service call window 1 i32 $port
1401}
1402
Matt Alexanderd9c56562020-05-21 10:49:17 +00001403function stopviewserver()
1404{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001405 adb shell service call window 2
1406}
1407
Matt Alexanderd9c56562020-05-21 10:49:17 +00001408function isviewserverstarted()
1409{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001410 adb shell service call window 3
1411}
1412
Matt Alexanderd9c56562020-05-21 10:49:17 +00001413function key_home()
1414{
Romain Guyb84049a2010-10-04 16:56:11 -07001415 adb shell input keyevent 3
1416}
1417
Matt Alexanderd9c56562020-05-21 10:49:17 +00001418function key_back()
1419{
Romain Guyb84049a2010-10-04 16:56:11 -07001420 adb shell input keyevent 4
1421}
1422
Matt Alexanderd9c56562020-05-21 10:49:17 +00001423function key_menu()
1424{
Romain Guyb84049a2010-10-04 16:56:11 -07001425 adb shell input keyevent 82
1426}
1427
Matt Alexanderd9c56562020-05-21 10:49:17 +00001428function smoketest()
1429{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001430 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1431 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1432 return
1433 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001434 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001435 if [ ! "$T" ]; then
1436 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1437 return
1438 fi
1439
Ying Wang9cd17642012-12-13 10:52:07 -08001440 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001441 adb uninstall com.android.smoketest > /dev/null &&
1442 adb uninstall com.android.smoketest.tests > /dev/null &&
1443 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1444 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1445 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1446}
1447
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001448# simple shortcut to the runtest command
Matt Alexanderd9c56562020-05-21 10:49:17 +00001449function runtest()
1450{
Christopher Ferris55257d22017-03-23 11:08:58 -07001451 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001452 if [ ! "$T" ]; then
1453 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1454 return
1455 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001456 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001457}
1458
The Android Open Source Project88b60792009-03-03 19:28:42 -08001459function godir () {
1460 if [[ -z "$1" ]]; then
1461 echo "Usage: godir <regex>"
1462 return
1463 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001464 local T=$(gettop)
1465 local FILELIST
Matt Alexanderd9c56562020-05-21 10:49:17 +00001466 if [ ! "$OUT_DIR" = "" ]; then
Brian Carlstromf2257422015-09-30 20:28:54 -07001467 mkdir -p $OUT_DIR
1468 FILELIST=$OUT_DIR/filelist
1469 else
1470 FILELIST=$T/filelist
1471 fi
1472 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001473 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001474 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001475 echo " Done"
1476 echo ""
1477 fi
1478 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001479 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
Matt Alexanderd9c56562020-05-21 10:49:17 +00001480 if [[ ${#lines[@]} = 0 ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001481 echo "Not found"
1482 return
1483 fi
1484 local pathname
1485 local choice
1486 if [[ ${#lines[@]} > 1 ]]; then
1487 while [[ -z "$pathname" ]]; do
1488 local index=1
1489 local line
1490 for line in ${lines[@]}; do
1491 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001492 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001493 done
1494 echo
1495 echo -n "Select one: "
1496 unset choice
1497 read choice
1498 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1499 echo "Invalid choice"
1500 continue
1501 fi
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001502 pathname=${lines[@]:$(($choice-1)):1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001503 done
1504 else
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001505 pathname=${lines[@]:0:1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001506 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001507 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001508}
1509
Steven Moreland62054a42018-12-06 10:11:40 -08001510# Update module-info.json in out.
1511function refreshmod() {
1512 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1513 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1514 return 1
1515 fi
1516
1517 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1518
1519 # for the output of the next command
1520 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1521
1522 # Note, can't use absolute path because of the way make works.
Alessandro Astonec8771be2020-05-10 11:27:57 +02001523 m $(get_build_var PRODUCT_OUT)/module-info.json \
Steven Moreland62054a42018-12-06 10:11:40 -08001524 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1525}
1526
Cole Faust3e192382021-10-25 13:29:15 -07001527# Verifies that module-info.txt exists, returning nonzero if it doesn't.
Cole Faust24c36db2021-01-23 02:39:37 +00001528function verifymodinfo() {
Steven Moreland62054a42018-12-06 10:11:40 -08001529 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001530 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
1531 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1532 fi
Steven Moreland62054a42018-12-06 10:11:40 -08001533 return 1
1534 fi
1535
1536 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001537 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
Cole Faust3e192382021-10-25 13:29:15 -07001538 echo "Could not find module-info.json. Please run 'refreshmod' first." >&2
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001539 fi
1540 return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001541 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001542}
1543
1544# List all modules for the current device, as cached in module-info.json. If any build change is
1545# made and it should be reflected in the output, you should run 'refreshmod' first.
1546function allmod() {
1547 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001548
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001549 python3 -c "import json; print('\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys())))"
Steven Moreland62054a42018-12-06 10:11:40 -08001550}
1551
Joe Onorato2c1aa472021-02-25 16:42:39 -08001552# Get the path of a specific module in the android tree, as cached in module-info.json.
1553# If any build change is made, and it should be reflected in the output, you should run
1554# 'refreshmod' first. Note: This is the inverse of dirmods.
Rett Berg78d1c932019-01-24 14:34:23 -08001555function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001556 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001557 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001558 return 1
1559 fi
1560
Cole Faust24c36db2021-01-23 02:39:37 +00001561 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001562
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001563 local relpath=$(python3 -c "import json, os
Steven Moreland62054a42018-12-06 10:11:40 -08001564module = '$1'
1565module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1566if module not in module_info:
1567 exit(1)
LuK1337b6a78192020-01-12 03:12:17 +01001568print(module_info[module]['path'][0])" 2>/dev/null)
Steven Moreland62054a42018-12-06 10:11:40 -08001569
1570 if [ -z "$relpath" ]; then
1571 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1572 return 1
1573 else
Rett Berg78d1c932019-01-24 14:34:23 -08001574 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001575 fi
1576}
1577
Joe Onorato2c1aa472021-02-25 16:42:39 -08001578# Get the path of a specific module in the android tree, as cached in module-info.json.
1579# If any build change is made, and it should be reflected in the output, you should run
1580# 'refreshmod' first. Note: This is the inverse of pathmod.
1581function dirmods() {
1582 if [[ $# -ne 1 ]]; then
1583 echo "usage: dirmods <path>" >&2
1584 return 1
1585 fi
1586
1587 verifymodinfo || return 1
1588
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001589 python3 -c "import json, os
Joe Onorato2c1aa472021-02-25 16:42:39 -08001590dir = '$1'
1591while dir.endswith('/'):
1592 dir = dir[:-1]
1593prefix = dir + '/'
1594module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1595results = set()
1596for m in module_info.values():
1597 for path in m.get(u'path', []):
1598 if path == dir or path.startswith(prefix):
1599 name = m.get(u'module_name')
1600 if name:
1601 results.add(name)
1602for name in sorted(results):
1603 print(name)
1604"
1605}
1606
1607
Rett Berg78d1c932019-01-24 14:34:23 -08001608# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1609# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1610function gomod() {
1611 if [[ $# -ne 1 ]]; then
1612 echo "usage: gomod <module>" >&2
1613 return 1
1614 fi
1615
1616 local path="$(pathmod $@)"
1617 if [ -z "$path" ]; then
1618 return 1
1619 fi
1620 cd $path
1621}
1622
Cole Faust24c36db2021-01-23 02:39:37 +00001623# Gets the list of a module's installed outputs, as cached in module-info.json.
1624# If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first.
1625function outmod() {
1626 if [[ $# -ne 1 ]]; then
1627 echo "usage: outmod <module>" >&2
1628 return 1
1629 fi
1630
1631 verifymodinfo || return 1
1632
1633 local relpath
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001634 relpath=$(python3 -c "import json, os
Cole Faust24c36db2021-01-23 02:39:37 +00001635module = '$1'
1636module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1637if module not in module_info:
1638 exit(1)
1639for output in module_info[module]['installed']:
1640 print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null)
1641
1642 if [ $? -ne 0 ]; then
1643 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2
1644 return 1
1645 elif [ ! -z "$relpath" ]; then
1646 echo "$relpath"
1647 fi
1648}
1649
1650# adb install a module's apk, as cached in module-info.json. If any build change
1651# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1652# Usage: installmod [adb install arguments] <module>
1653# For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk
1654function installmod() {
1655 if [[ $# -eq 0 ]]; then
1656 echo "usage: installmod [adb install arguments] <module>" >&2
Cole Faust3e192382021-10-25 13:29:15 -07001657 echo "" >&2
1658 echo "Only flags to be passed after the \"install\" in adb install are supported," >&2
1659 echo "with the exception of -s. If -s is passed it will be placed before the \"install\"." >&2
1660 echo "-s must be the first flag passed if it exists." >&2
Cole Faust24c36db2021-01-23 02:39:37 +00001661 return 1
1662 fi
1663
1664 local _path
1665 _path=$(outmod ${@:$#:1})
1666 if [ $? -ne 0 ]; then
1667 return 1
1668 fi
1669
1670 _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1)
1671 if [ -z "$_path" ]; then
1672 echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2
1673 return 1
1674 fi
Cole Faust3e192382021-10-25 13:29:15 -07001675 local serial_device=""
1676 if [[ "$1" == "-s" ]]; then
1677 if [[ $# -le 2 ]]; then
1678 echo "-s requires an argument" >&2
1679 return 1
1680 fi
1681 serial_device="-s $2"
1682 shift 2
1683 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001684 local length=$(( $# - 1 ))
Cole Faust3e192382021-10-25 13:29:15 -07001685 echo adb $serial_device install ${@:1:$length} $_path
1686 adb $serial_device install ${@:1:$length} $_path
Cole Faust24c36db2021-01-23 02:39:37 +00001687}
1688
dimitry73b84812018-12-11 18:06:00 +01001689function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001690 local word=${COMP_WORDS[COMP_CWORD]}
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001691 COMPREPLY=( $(QUIET_VERIFYMODINFO=true allmod | grep -E "^$word") )
Steven Moreland62054a42018-12-06 10:11:40 -08001692}
1693
Alex Rayf0d08eb2013-03-08 15:15:06 -08001694# Print colored exit condition
1695function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001696 "$@"
1697 local retval=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +00001698 if [ $retval -ne 0 ]
1699 then
Jacky Cao89483b82015-05-15 22:12:53 +08001700 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001701 else
Jacky Cao89483b82015-05-15 22:12:53 +08001702 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001703 fi
1704 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001705}
1706
Matt Alexanderd9c56562020-05-21 10:49:17 +00001707function get_make_command()
1708{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001709 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1710 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001711 # Always use the real make if -C is passed in
1712 for arg in "$@"; do
1713 if [[ $arg == -C* ]]; then
1714 echo command make
1715 return
1716 fi
1717 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001718 echo build/soong/soong_ui.bash --make-mode
1719 else
1720 echo command make
1721 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001722}
1723
Matt Alexanderd9c56562020-05-21 10:49:17 +00001724function _wrap_build()
1725{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001726 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1727 "$@"
1728 return $?
1729 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001730 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001731 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001732 local ret=$?
1733 local end_time=$(date +"%s")
1734 local tdiff=$(($end_time-$start_time))
1735 local hours=$(($tdiff / 3600 ))
1736 local mins=$((($tdiff % 3600) / 60))
1737 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001738 local ncolors=$(tput colors 2>/dev/null)
1739 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001740 color_failed=$'\E'"[0;31m"
1741 color_success=$'\E'"[0;32m"
Kousik Kumar09af2542021-08-19 16:13:32 -04001742 color_warning=$'\E'"[0;33m"
Jacky Cao89483b82015-05-15 22:12:53 +08001743 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001744 else
1745 color_failed=""
1746 color_success=""
1747 color_reset=""
1748 fi
Kousik Kumar09af2542021-08-19 16:13:32 -04001749
1750 if [[ "x${USE_RBE}" == "x" && $mins -gt 15 && "${ANDROID_BUILD_ENVIRONMENT_CONFIG}" == "googler" ]]; then
1751 echo
1752 echo "${color_warning}Start using RBE (http://go/build-fast) to get faster builds!${color_reset}"
1753 fi
1754
Ed Heylcc6be0a2014-06-18 14:55:58 -07001755 echo
Matt Alexanderd9c56562020-05-21 10:49:17 +00001756 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001757 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001758 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001759 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001760 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +00001761 if [ $hours -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001762 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001763 elif [ $mins -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001764 printf "(%02g:%02g (mm:ss))" $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001765 elif [ $secs -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001766 printf "(%s seconds)" $secs
1767 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001768 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001769 echo
1770 return $ret
1771}
1772
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001773function _trigger_build()
1774(
1775 local -r bc="$1"; shift
1776 if T="$(gettop)"; then
1777 _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
1778 else
Jingwen Chend728ee12021-05-18 06:02:53 +00001779 >&2 echo "Couldn't locate the top of the tree. Try setting TOP."
1780 return 1
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001781 fi
1782)
1783
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001784# Convenience entry point (like m) to use Bazel in AOSP.
Jingwen Chend728ee12021-05-18 06:02:53 +00001785function b()
1786(
1787 # Generate BUILD, bzl files into the synthetic Bazel workspace (out/soong/workspace).
Sam Delmerico9d67a902022-04-11 12:25:18 +00001788 _trigger_build "all-modules" bp2build USE_BAZEL_ANALYSIS= || return 1
Jingwen Chend728ee12021-05-18 06:02:53 +00001789 # Then, run Bazel using the synthetic workspace as the --package_path.
Sam Delmerico9d67a902022-04-11 12:25:18 +00001790 if [[ -z "$@" ]]; then
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001791 # If there are no args, show help.
Jingwen Chenbfa114d2021-06-17 05:42:43 +00001792 bazel help
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001793 else
1794 # Else, always run with the bp2build configuration, which sets Bazel's package path to the synthetic workspace.
Sam Delmerico9d67a902022-04-11 12:25:18 +00001795 bazel "$@" --config=bp2build
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001796 fi
Jingwen Chend728ee12021-05-18 06:02:53 +00001797)
1798
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001799function m()
1800(
1801 _trigger_build "all-modules" "$@"
1802)
1803
1804function mm()
1805(
1806 _trigger_build "modules-in-a-dir-no-deps" "$@"
1807)
1808
1809function mmm()
1810(
1811 _trigger_build "modules-in-dirs-no-deps" "$@"
1812)
1813
1814function mma()
1815(
1816 _trigger_build "modules-in-a-dir" "$@"
1817)
1818
1819function mmma()
1820(
1821 _trigger_build "modules-in-dirs" "$@"
1822)
1823
Matt Alexanderd9c56562020-05-21 10:49:17 +00001824function make()
1825{
Dan Willemsene9842242017-07-28 13:00:13 -07001826 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001827}
1828
Matt Alexanderd9c56562020-05-21 10:49:17 +00001829function provision()
1830{
David Zeuthen1b126ff2015-09-30 17:10:48 -04001831 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1832 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1833 return 1
1834 fi
1835 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1836 echo "There is no provisioning script for the device." >&2
1837 return 1
1838 fi
1839
1840 # Check if user really wants to do this.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001841 if [ "$1" = "--no-confirmation" ]; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001842 shift 1
1843 else
1844 echo "This action will reflash your device."
1845 echo ""
1846 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1847 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001848 echo -n "Are you sure you want to do this (yes/no)? "
1849 read
Matt Alexanderd9c56562020-05-21 10:49:17 +00001850 if [[ "${REPLY}" != "yes" ]] ; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001851 echo "Not taking any action. Exiting." >&2
1852 return 1
1853 fi
1854 fi
1855 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1856}
1857
Jim Tanga881a252018-06-19 16:34:41 +08001858# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001859function enable_zsh_completion() {
1860 # Don't override user's options if bash-style completion is already enabled.
1861 if ! declare -f complete >/dev/null; then
1862 autoload -U compinit && compinit
1863 autoload -U bashcompinit && bashcompinit
1864 fi
Jim Tanga881a252018-06-19 16:34:41 +08001865}
1866
1867function validate_current_shell() {
1868 local current_sh="$(ps -o command -p $$)"
1869 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001870 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001871 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001872 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001873 *zsh*)
1874 function check_type() { type "$1"; }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001875 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001876 *)
Jim Tanga881a252018-06-19 16:34:41 +08001877 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 -07001878 ;;
1879 esac
Jim Tanga881a252018-06-19 16:34:41 +08001880}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001881
1882# Execute the contents of any vendorsetup.sh files we can find.
Dan Willemsend855a722019-02-12 15:52:36 -08001883# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
1884# load those.
1885#
1886# This allows loading only approved vendorsetup.sh files
Jim Tanga881a252018-06-19 16:34:41 +08001887function source_vendorsetup() {
Jim Tangc4dba1d2019-07-25 16:54:27 +08001888 unset VENDOR_PYTHONPATH
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001889 local T="$(gettop)"
Dan Willemsend855a722019-02-12 15:52:36 -08001890 allowed=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001891 for f in $(cd "$T" && find -L device vendor product -maxdepth 4 -name 'allowed-vendorsetup_sh-files' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001892 if [ -n "$allowed" ]; then
1893 echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
1894 echo " $allowed"
1895 echo " $f"
1896 return
1897 fi
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001898 allowed="$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001899 done
1900
1901 allowed_files=
1902 [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
Jim Tanga881a252018-06-19 16:34:41 +08001903 for dir in device vendor product; do
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001904 for f in $(cd "$T" && test -d $dir && \
Jim Tanga881a252018-06-19 16:34:41 +08001905 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001906
1907 if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001908 echo "including $f"; . "$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001909 else
1910 echo "ignoring $f, not in $allowed"
1911 fi
Jim Tanga881a252018-06-19 16:34:41 +08001912 done
1913 done
1914}
Kenny Root52aa81c2011-07-15 11:07:06 -07001915
Dan Albertbab814f2020-08-26 15:34:53 -07001916function showcommands() {
1917 local T=$(gettop)
1918 if [[ -z "$TARGET_PRODUCT" ]]; then
1919 >&2 echo "TARGET_PRODUCT not set. Run lunch."
1920 return
1921 fi
1922 case $(uname -s) in
1923 Darwin)
1924 PREBUILT_NAME=darwin-x86
1925 ;;
1926 Linux)
1927 PREBUILT_NAME=linux-x86
1928 ;;
1929 *)
1930 >&2 echo Unknown host $(uname -s)
1931 return
1932 ;;
1933 esac
1934 if [[ -z "$OUT_DIR" ]]; then
1935 if [[ -z "$OUT_DIR_COMMON_BASE" ]]; then
1936 OUT_DIR=out
1937 else
1938 OUT_DIR=${OUT_DIR_COMMON_BASE}/${PWD##*/}
1939 fi
1940 fi
1941 if [[ "$1" == "--regenerate" ]]; then
1942 shift 1
1943 NINJA_ARGS="-t commands $@" m
1944 else
1945 (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \
1946 -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \
1947 -t commands "$@")
1948 fi
1949}
1950
Jim Tanga881a252018-06-19 16:34:41 +08001951validate_current_shell
1952source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001953addcompletions