blob: f80257353207622106eaf8a344b9785d7c4746b7 [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
Ben Chengaac3f812013-08-13 14:38:15 -0700362 # With this environment variable new GCC can apply colors to warnings/errors
363 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 -0700364}
365
Matt Alexanderd9c56562020-05-21 10:49:17 +0000366function set_sequence_number()
367{
Colin Cross88737132017-03-21 17:41:03 -0700368 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700369}
370
Makoto Onukida971062018-06-18 10:15:19 -0700371# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
372function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800373 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700374 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800375 *:"$cmd":*)
376 return 1
377 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700378 esac
379 return 0
380}
381
Matt Alexanderd9c56562020-05-21 10:49:17 +0000382function addcompletions()
383{
Ben Taitelbaum8c2c9cf2020-09-22 16:45:05 -0700384 local f=
Kenny Root52aa81c2011-07-15 11:07:06 -0700385
Jim Tanga881a252018-06-19 16:34:41 +0800386 # Keep us from trying to run in something that's neither bash nor zsh.
387 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700388 return
389 fi
390
391 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800392 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700393 return
394 fi
395
Jim Tanga881a252018-06-19 16:34:41 +0800396 local completion_files=(
397 system/core/adb/adb.bash
398 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800399 tools/asuite/asuite.sh
Jim Tanga881a252018-06-19 16:34:41 +0800400 )
Makoto Onukida971062018-06-18 10:15:19 -0700401 # Completion can be disabled selectively to allow users to use non-standard completion.
402 # e.g.
403 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
404 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800405 for f in ${completion_files[*]}; do
406 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700407 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700408 fi
409 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700410
Matt Alexanderd9c56562020-05-21 10:49:17 +0000411 if should_add_completion bit ; then
Makoto Onukida971062018-06-18 10:15:19 -0700412 complete -C "bit --tab" bit
413 fi
Anton Hanssonece9c482019-02-04 18:15:39 +0000414 if [ -z "$ZSH_VERSION" ]; then
415 # Doesn't work in zsh.
416 complete -o nospace -F _croot croot
417 fi
Jim Tanga881a252018-06-19 16:34:41 +0800418 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800419
Cole Faust24c36db2021-01-23 02:39:37 +0000420 complete -F _complete_android_module_names pathmod
dimitry73b84812018-12-11 18:06:00 +0100421 complete -F _complete_android_module_names gomod
Cole Faust24c36db2021-01-23 02:39:37 +0000422 complete -F _complete_android_module_names outmod
423 complete -F _complete_android_module_names installmod
dimitry73b84812018-12-11 18:06:00 +0100424 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700425}
426
Joe Onorato824608c2022-04-08 11:06:16 -0700427function multitree_lunch_help()
428{
429 echo "usage: lunch PRODUCT-VARIANT" 1>&2
430 echo " Set up android build environment based on a product short name and variant" 1>&2
431 echo 1>&2
432 echo "lunch COMBO_FILE VARIANT" 1>&2
433 echo " Set up android build environment based on a specific lunch combo file" 1>&2
434 echo " and variant." 1>&2
435 echo 1>&2
436 echo "lunch --print [CONFIG]" 1>&2
437 echo " Print the contents of a configuration. If CONFIG is supplied, that config" 1>&2
438 echo " will be flattened and printed. If CONFIG is not supplied, the currently" 1>&2
439 echo " selected config will be printed. Returns 0 on success or nonzero on error." 1>&2
440 echo 1>&2
441 echo "lunch --list" 1>&2
442 echo " List all possible combo files available in the current tree" 1>&2
443 echo 1>&2
444 echo "lunch --help" 1>&2
445 echo "lunch -h" 1>&2
446 echo " Prints this message." 1>&2
447}
448
449function multitree_lunch()
450{
451 local code
452 local results
453 if $(echo "$1" | grep -q '^-') ; then
454 # Calls starting with a -- argument are passed directly and the function
455 # returns with the lunch.py exit code.
456 build/make/orchestrator/core/lunch.py "$@"
457 code=$?
458 if [[ $code -eq 2 ]] ; then
459 echo 1>&2
460 multitree_lunch_help
461 return $code
462 elif [[ $code -ne 0 ]] ; then
463 return $code
464 fi
465 else
466 # All other calls go through the --lunch variant of lunch.py
467 results=($(build/make/orchestrator/core/lunch.py --lunch "$@"))
468 code=$?
469 if [[ $code -eq 2 ]] ; then
470 echo 1>&2
471 multitree_lunch_help
472 return $code
473 elif [[ $code -ne 0 ]] ; then
474 return $code
475 fi
476
477 export TARGET_BUILD_COMBO=${results[0]}
478 export TARGET_BUILD_VARIANT=${results[1]}
479 fi
480}
481
Matt Alexanderd9c56562020-05-21 10:49:17 +0000482function choosetype()
483{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700484 echo "Build type choices are:"
485 echo " 1. release"
486 echo " 2. debug"
487 echo
488
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800489 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700490 DEFAULT_NUM=1
491 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700492
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800493 export TARGET_BUILD_TYPE=
494 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700495 while [ -z $TARGET_BUILD_TYPE ]
496 do
497 echo -n "Which would you like? ["$DEFAULT_NUM"] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000498 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499 read ANSWER
500 else
501 echo $1
502 ANSWER=$1
503 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700504 case $ANSWER in
505 "")
506 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
507 ;;
508 1)
509 export TARGET_BUILD_TYPE=release
510 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 release)
512 export TARGET_BUILD_TYPE=release
513 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700514 2)
515 export TARGET_BUILD_TYPE=debug
516 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800517 debug)
518 export TARGET_BUILD_TYPE=debug
519 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700520 *)
521 echo
522 echo "I didn't understand your response. Please try again."
523 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700524 ;;
525 esac
Matt Alexanderd9c56562020-05-21 10:49:17 +0000526 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800527 break
528 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700529 done
530
Ying Wang08800fd2016-03-03 20:57:21 -0800531 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700532 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800533 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700534}
535
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800536#
537# This function isn't really right: It chooses a TARGET_PRODUCT
538# based on the list of boards. Usually, that gets you something
539# that kinda works with a generic product, but really, you should
540# pick a product by name.
541#
Matt Alexanderd9c56562020-05-21 10:49:17 +0000542function chooseproduct()
543{
Christopher Ferris55257d22017-03-23 11:08:58 -0700544 local default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000545 if [ "x$TARGET_PRODUCT" != x ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700546 default_value=$TARGET_PRODUCT
547 else
Ying Wang0a76df52015-06-08 11:57:26 -0700548 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700549 fi
550
Ying Wang08800fd2016-03-03 20:57:21 -0800551 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800552 export TARGET_PRODUCT=
553 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700554 while [ -z "$TARGET_PRODUCT" ]
555 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700556 echo -n "Which product would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000557 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800558 read ANSWER
559 else
560 echo $1
561 ANSWER=$1
562 fi
563
Matt Alexanderd9c56562020-05-21 10:49:17 +0000564 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700565 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800566 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000567 if check_product $ANSWER
568 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800569 export TARGET_PRODUCT=$ANSWER
570 else
571 echo "** Not a valid product: $ANSWER"
572 fi
573 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000574 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800575 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700576 fi
577 done
578
Ying Wang08800fd2016-03-03 20:57:21 -0800579 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700580 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800581 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582}
583
Matt Alexanderd9c56562020-05-21 10:49:17 +0000584function choosevariant()
585{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800586 echo "Variant choices are:"
587 local index=1
588 local v
589 for v in ${VARIANT_CHOICES[@]}
590 do
591 # The product name is the name of the directory containing
592 # the makefile we found, above.
593 echo " $index. $v"
594 index=$(($index+1))
595 done
596
597 local default_value=eng
598 local ANSWER
599
600 export TARGET_BUILD_VARIANT=
601 while [ -z "$TARGET_BUILD_VARIANT" ]
602 do
603 echo -n "Which would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000604 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800605 read ANSWER
606 else
607 echo $1
608 ANSWER=$1
609 fi
610
Matt Alexanderd9c56562020-05-21 10:49:17 +0000611 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800612 export TARGET_BUILD_VARIANT=$default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000613 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
614 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Guillaume Chelfice000fd2019-10-03 12:02:46 +0200615 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800616 fi
617 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000618 if check_variant $ANSWER
619 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800620 export TARGET_BUILD_VARIANT=$ANSWER
621 else
622 echo "** Not a valid variant: $ANSWER"
623 fi
624 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000625 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800626 break
627 fi
628 done
629}
630
Matt Alexanderd9c56562020-05-21 10:49:17 +0000631function choosecombo()
632{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700633 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700634
635 echo
636 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700637 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700638
639 echo
640 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700641 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800642
643 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800644 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700645 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800646 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800647 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700648}
649
Matt Alexanderd9c56562020-05-21 10:49:17 +0000650function add_lunch_combo()
651{
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800652 if [ -n "$ZSH_VERSION" ]; then
653 echo -n "${funcfiletrace[1]}: "
654 else
655 echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
656 fi
657 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 -0800658}
659
Matt Alexanderd9c56562020-05-21 10:49:17 +0000660function print_lunch_menu()
661{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662 local uname=$(uname)
Roland Levillain23c46cf2020-03-31 16:11:05 +0100663 local choices
Colin Crossfa50d402021-04-22 13:05:41 -0700664 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 +0100665 local ret=$?
666
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700667 echo
668 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700669 echo
Roland Levillain23c46cf2020-03-31 16:11:05 +0100670
Matt Alexanderd9c56562020-05-21 10:49:17 +0000671 if [ $ret -ne 0 ]
672 then
Roland Levillain23c46cf2020-03-31 16:11:05 +0100673 echo "Warning: Cannot display lunch menu."
674 echo
675 echo "Note: You can invoke lunch with an explicit target:"
676 echo
677 echo " usage: lunch [target]" >&2
678 echo
679 return
680 fi
681
Will Burr40401202022-02-07 12:12:01 +0000682 echo "Lunch menu .. Here are the common combinations:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800683
684 local i=1
685 local choice
Dan Willemsen91763e92019-10-03 15:13:12 -0700686 for choice in $(echo $choices)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800687 do
688 echo " $i. $choice"
689 i=$(($i+1))
690 done
691
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700692 echo
693}
694
Matt Alexanderd9c56562020-05-21 10:49:17 +0000695function lunch()
696{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800697 local answer
698
Steven Moreland92793dc2020-02-25 18:30:18 -0800699 if [[ $# -gt 1 ]]; then
700 echo "usage: lunch [target]" >&2
701 return 1
702 fi
703
Will Burr40401202022-02-07 12:12:01 +0000704 local used_lunch_menu=0
705
Steven Moreland92793dc2020-02-25 18:30:18 -0800706 if [ "$1" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800707 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700708 else
709 print_lunch_menu
Will Burr40401202022-02-07 12:12:01 +0000710 echo "Which would you like? [aosp_arm-eng]"
711 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 -0800712 read answer
Will Burr40401202022-02-07 12:12:01 +0000713 used_lunch_menu=1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700714 fi
715
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800716 local selection=
717
Matt Alexanderd9c56562020-05-21 10:49:17 +0000718 if [ -z "$answer" ]
719 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700720 selection=aosp_arm-eng
Matt Alexanderd9c56562020-05-21 10:49:17 +0000721 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
722 then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800723 local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
Matt Alexanderd9c56562020-05-21 10:49:17 +0000724 if [ $answer -le ${#choices[@]} ]
725 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800726 # array in zsh starts from 1 instead of 0.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000727 if [ -n "$ZSH_VERSION" ]
728 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800729 selection=${choices[$(($answer))]}
730 else
731 selection=${choices[$(($answer-1))]}
732 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800733 fi
Colin Cross88737132017-03-21 17:41:03 -0700734 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800735 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700736 fi
737
Joe Onoratoda12daf2010-06-09 18:18:31 -0700738 export TARGET_BUILD_APPS=
739
Colin Cross88737132017-03-21 17:41:03 -0700740 local product variant_and_version variant version
Colin Cross88737132017-03-21 17:41:03 -0700741 product=${selection%%-*} # Trim everything after first dash
742 variant_and_version=${selection#*-} # Trim everything up to first dash
743 if [ "$variant_and_version" != "$selection" ]; then
744 variant=${variant_and_version%%-*}
745 if [ "$variant" != "$variant_and_version" ]; then
746 version=${variant_and_version#*-}
747 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700748 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800749
Matt Alexanderd9c56562020-05-21 10:49:17 +0000750 if [ -z "$product" ]
751 then
Ying Wang08800fd2016-03-03 20:57:21 -0800752 echo
Colin Cross88737132017-03-21 17:41:03 -0700753 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700754 return 1
755 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800756
Colin Cross88737132017-03-21 17:41:03 -0700757 TARGET_PRODUCT=$product \
758 TARGET_BUILD_VARIANT=$variant \
759 TARGET_PLATFORM_VERSION=$version \
760 build_build_var_cache
Matt Alexanderd9c56562020-05-21 10:49:17 +0000761 if [ $? -ne 0 ]
762 then
Anton Hansson32fa7ee2021-06-14 17:09:58 +0100763 if [[ "$product" =~ .*_(eng|user|userdebug) ]]
764 then
765 echo "Did you mean -${product/*_/}? (dash instead of underscore)"
766 fi
Colin Cross88737132017-03-21 17:41:03 -0700767 return 1
768 fi
Colin Cross88737132017-03-21 17:41:03 -0700769 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
770 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700771 if [ -n "$version" ]; then
772 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
773 else
774 unset TARGET_PLATFORM_VERSION
775 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700776 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700777
Will Burr40401202022-02-07 12:12:01 +0000778 if [ $used_lunch_menu -eq 1 ]; then
779 echo
780 echo "Hint: next time you can simply run 'lunch $selection'"
781 fi
782
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700783 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800784
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700785 set_stuff_for_environment
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700786 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800787 destroy_build_var_cache
Kousik Kumar41dacd12021-05-11 18:38:38 -0400788
789 if [[ -n "${CHECK_MU_CONFIG:-}" ]]; then
790 check_mu_config
791 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792}
793
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700794unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700795# Tab completion for lunch.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000796function _lunch()
797{
Jeff Davidson513d7a42010-08-02 10:00:44 -0700798 local cur prev opts
799 COMPREPLY=()
800 cur="${COMP_WORDS[COMP_CWORD]}"
801 prev="${COMP_WORDS[COMP_CWORD-1]}"
802
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700803 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800804 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700805 fi
806
807 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700808 return 0
809}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700810
Joe Onoratoda12daf2010-06-09 18:18:31 -0700811# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700812# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Matt Alexanderd9c56562020-05-21 10:49:17 +0000813function tapas()
814{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700815 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Elliott Hughesf71c05a2020-03-06 16:46:59 -0800816 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700817 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700818 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Colin Cross7f49a672022-01-27 18:15:53 -0800819 local keys="$(echo $* | xargs -n 1 echo | \grep -E '^(devkeys)$' | xargs)"
820 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|devkeys)$' | xargs)"
821
Joe Onoratoda12daf2010-06-09 18:18:31 -0700822
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700823 if [ "$showHelp" != "" ]; then
824 $(gettop)/build/make/tapasHelp.sh
825 return
826 fi
827
Ying Wang67f02922012-08-22 10:25:20 -0700828 if [ $(echo $arch | wc -w) -gt 1 ]; then
829 echo "tapas: Error: Multiple build archs supplied: $arch"
830 return
831 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700832 if [ $(echo $variant | wc -w) -gt 1 ]; then
833 echo "tapas: Error: Multiple build variants supplied: $variant"
834 return
835 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700836 if [ $(echo $density | wc -w) -gt 1 ]; then
837 echo "tapas: Error: Multiple densities supplied: $density"
838 return
839 fi
Colin Cross7f49a672022-01-27 18:15:53 -0800840 if [ $(echo $keys | wc -w) -gt 1 ]; then
841 echo "tapas: Error: Multiple keys supplied: $keys"
842 return
843 fi
Ying Wang67f02922012-08-22 10:25:20 -0700844
Ying Wang0a76df52015-06-08 11:57:26 -0700845 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700846 case $arch in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000847 x86) product=aosp_x86;;
848 arm64) product=aosp_arm64;;
849 x86_64) product=aosp_x86_64;;
Ying Wang67f02922012-08-22 10:25:20 -0700850 esac
Colin Cross7f49a672022-01-27 18:15:53 -0800851 if [ -n "$keys" ]; then
852 product=${product/aosp_/aosp_${keys}_}
853 fi;
854
Joe Onoratoda12daf2010-06-09 18:18:31 -0700855 if [ -z "$variant" ]; then
856 variant=eng
857 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700858 if [ -z "$apps" ]; then
859 apps=all
860 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600861 if [ -z "$density" ]; then
862 density=alldpi
863 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700864
Ying Wang67f02922012-08-22 10:25:20 -0700865 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700866 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700867 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700868 export TARGET_BUILD_TYPE=release
869 export TARGET_BUILD_APPS=$apps
870
Ying Wang08800fd2016-03-03 20:57:21 -0800871 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700872 set_stuff_for_environment
873 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800874 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700875}
876
Martin Stjernholmf692c752021-04-12 00:01:10 +0100877# Configures the build to build unbundled Android modules (APEXes).
878# Run banchan with one or more module names (from apex{} modules).
879function banchan()
880{
881 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100882 local product="$(echo $* | xargs -n 1 echo | \grep -E '^(.*_)?(arm|x86|arm64|x86_64)$' | xargs)"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100883 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100884 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 +0100885
886 if [ "$showHelp" != "" ]; then
887 $(gettop)/build/make/banchanHelp.sh
888 return
889 fi
890
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100891 if [ -z "$product" ]; then
892 product=arm
893 elif [ $(echo $product | wc -w) -gt 1 ]; then
894 echo "banchan: Error: Multiple build archs or products supplied: $products"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100895 return
896 fi
897 if [ $(echo $variant | wc -w) -gt 1 ]; then
898 echo "banchan: Error: Multiple build variants supplied: $variant"
899 return
900 fi
901 if [ -z "$apps" ]; then
902 echo "banchan: Error: No modules supplied"
903 return
904 fi
905
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100906 case $product in
907 arm) product=module_arm;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100908 x86) product=module_x86;;
909 arm64) product=module_arm64;;
910 x86_64) product=module_x86_64;;
911 esac
912 if [ -z "$variant" ]; then
913 variant=eng
914 fi
915
916 export TARGET_PRODUCT=$product
917 export TARGET_BUILD_VARIANT=$variant
918 export TARGET_BUILD_DENSITY=alldpi
919 export TARGET_BUILD_TYPE=release
920
921 # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use
922 # case is different and it may diverge in the future.
923 export TARGET_BUILD_APPS=$apps
924
925 build_build_var_cache
926 set_stuff_for_environment
927 printconfig
928 destroy_build_var_cache
929}
930
Matt Alexanderd9c56562020-05-21 10:49:17 +0000931function gettop
932{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700933 local TOPFILE=build/make/core/envsetup.mk
Matt Alexanderd9c56562020-05-21 10:49:17 +0000934 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700935 # The following circumlocution ensures we remove symlinks from TOP.
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000936 (cd "$TOP"; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700937 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000938 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800939 # The following circumlocution (repeated below as well) ensures
940 # that we record the true directory name and not one that is
941 # faked up with symlink names.
942 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700943 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800944 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700945 local T=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000946 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800947 \cd ..
synergyb112a402013-07-05 19:47:47 -0700948 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700949 done
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000950 \cd "$HERE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700951 if [ -f "$T/$TOPFILE" ]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000952 echo "$T"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700953 fi
954 fi
955 fi
956}
957
Matt Alexanderd9c56562020-05-21 10:49:17 +0000958function croot()
959{
Christopher Ferris55257d22017-03-23 11:08:58 -0700960 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700961 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700962 if [ "$1" ]; then
963 \cd $(gettop)/$1
964 else
965 \cd $(gettop)
966 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967 else
968 echo "Couldn't locate the top of the tree. Try setting TOP."
969 fi
970}
971
Matt Alexanderd9c56562020-05-21 10:49:17 +0000972function _croot()
973{
Anton Hanssonece9c482019-02-04 18:15:39 +0000974 local T=$(gettop)
975 if [ "$T" ]; then
976 local cur="${COMP_WORDS[COMP_CWORD]}"
977 k=0
978 for c in $(compgen -d ${T}/${cur}); do
979 COMPREPLY[k++]=${c#${T}/}/
980 done
981 fi
982}
983
Matt Alexanderd9c56562020-05-21 10:49:17 +0000984function cproj()
985{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700986 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700987 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700988 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700989 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
990 T=$PWD
991 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800992 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700993 return
994 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800995 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700996 done
Ying Wang9cd17642012-12-13 10:52:07 -0800997 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700998 echo "can't find Android.mk"
999}
1000
Daniel Sandler47e0a882013-07-30 13:23:52 -04001001# simplified version of ps; output in the form
1002# <pid> <procname>
1003function qpid() {
1004 local prepend=''
1005 local append=''
Matt Alexanderd9c56562020-05-21 10:49:17 +00001006 if [ "$1" = "--exact" ]; then
Daniel Sandler47e0a882013-07-30 13:23:52 -04001007 prepend=' '
1008 append='$'
1009 shift
Matt Alexanderd9c56562020-05-21 10:49:17 +00001010 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001011 echo "usage: qpid [[--exact] <process name|pid>"
1012 return 255
1013 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001014
1015 local EXE="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001016 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001017 qpid | \grep "$prepend$EXE$append"
1018 else
1019 adb shell ps \
1020 | tr -d '\r' \
1021 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1022 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001023}
1024
Steven Moreland74114f12020-09-10 01:23:32 +00001025# syswrite - disable verity, reboot if needed, and remount image
1026#
1027# Easy way to make system.img/etc writable
1028function syswrite() {
1029 adb wait-for-device && adb root || return 1
1030 if [[ $(adb disable-verity | grep "reboot") ]]; then
1031 echo "rebooting"
1032 adb reboot && adb wait-for-device && adb root || return 1
1033 fi
1034 adb wait-for-device && adb remount || return 1
1035}
1036
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001037# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001038# that has the core-file-size limit set correctly
1039#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001040# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001041# if its core-file-size limit is not set already.
1042# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1043
Matt Alexanderd9c56562020-05-21 10:49:17 +00001044function coredump_setup()
1045{
1046 echo "Getting root...";
1047 adb root;
1048 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001049
Matt Alexanderd9c56562020-05-21 10:49:17 +00001050 echo "Remounting root partition read-write...";
1051 adb shell mount -w -o remount -t rootfs rootfs;
1052 sleep 1;
1053 adb wait-for-device;
1054 adb shell mkdir -p /cores;
1055 adb shell mount -t tmpfs tmpfs /cores;
1056 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001057
Matt Alexanderd9c56562020-05-21 10:49:17 +00001058 echo "Granting SELinux permission to dump in /cores...";
1059 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001060
Matt Alexanderd9c56562020-05-21 10:49:17 +00001061 echo "Set core pattern.";
1062 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001063
Ying Wang08800fd2016-03-03 20:57:21 -08001064 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001065}
1066
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001067# coredump_enable - enable core dumps for the specified process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001068# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001069#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001070# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001071# dump to actually be generated.
1072
Matt Alexanderd9c56562020-05-21 10:49:17 +00001073function coredump_enable()
1074{
1075 local PID=$1;
Ying Wang08800fd2016-03-03 20:57:21 -08001076 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001077 printf "Expecting a PID!\n";
1078 return;
1079 fi;
1080 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001081 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001082}
1083
1084# core - send SIGV and pull the core for process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001085# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001086#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001087# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001088# enabled globally.
1089
Matt Alexanderd9c56562020-05-21 10:49:17 +00001090function core()
1091{
1092 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001093
Ying Wang08800fd2016-03-03 20:57:21 -08001094 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001095 printf "Expecting a PID!\n";
1096 return;
1097 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001098
Matt Alexanderd9c56562020-05-21 10:49:17 +00001099 local CORENAME=core.$PID;
1100 local COREPATH=/cores/$CORENAME;
1101 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001102
Matt Alexanderd9c56562020-05-21 10:49:17 +00001103 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001104
Matt Alexanderd9c56562020-05-21 10:49:17 +00001105 local done=0;
Ying Wang08800fd2016-03-03 20:57:21 -08001106 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
Matt Alexanderd9c56562020-05-21 10:49:17 +00001107 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1108 adb shell kill -$SIG $PID;
1109 sleep 1;
1110 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001111
Matt Alexanderd9c56562020-05-21 10:49:17 +00001112 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1113 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001114}
1115
Christopher Tate744ee802009-11-12 15:33:08 -08001116# systemstack - dump the current stack trace of all threads in the system process
1117# to the usual ANR traces file
Matt Alexanderd9c56562020-05-21 10:49:17 +00001118function systemstack()
1119{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001120 stacks system_server
1121}
1122
Michael Wrightaeed7212014-06-19 19:58:12 -07001123# Read the ELF header from /proc/$PID/exe to determine if the process is
1124# 64-bit.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001125function is64bit()
1126{
Ben Chengfba67bf2014-02-25 10:27:07 -08001127 local PID="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001128 if [ "$PID" ] ; then
1129 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001130 echo "64"
1131 else
1132 echo ""
1133 fi
1134 else
1135 echo ""
1136 fi
1137}
1138
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001139case `uname -s` in
1140 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001141 function sgrep()
1142 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001143 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 -04001144 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001145 }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001146
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001147 ;;
1148 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001149 function sgrep()
1150 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001151 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 -04001152 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001153 }
1154 ;;
1155esac
1156
Matt Alexanderd9c56562020-05-21 10:49:17 +00001157function gettargetarch
1158{
Raghu Gandham8da43102012-07-25 19:57:22 -07001159 get_build_var TARGET_ARCH
1160}
1161
Matt Alexanderd9c56562020-05-21 10:49:17 +00001162function ggrep()
1163{
Mike Frysinger5e479732015-09-22 18:13:48 -04001164 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1165 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001166}
1167
Matt Alexanderd9c56562020-05-21 10:49:17 +00001168function gogrep()
1169{
Orion Hodson831472d2019-10-25 11:35:15 +01001170 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
1171 -exec grep --color -n "$@" {} +
1172}
1173
Matt Alexanderd9c56562020-05-21 10:49:17 +00001174function jgrep()
1175{
Mike Frysinger5e479732015-09-22 18:13:48 -04001176 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1177 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001178}
1179
Alistair Delva176e5342021-02-22 13:31:26 -08001180function rsgrep()
Jeff Vander Stoep1431ab82021-02-02 19:18:26 +01001181{
1182 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rs" \
1183 -exec grep --color -n "$@" {} +
1184}
1185
Taesu Leeea0cecd2020-10-28 11:05:18 +09001186function ktgrep()
1187{
1188 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.kt" \
1189 -exec grep --color -n "$@" {} +
1190}
1191
Matt Alexanderd9c56562020-05-21 10:49:17 +00001192function cgrep()
1193{
Mike Frysinger5e479732015-09-22 18:13:48 -04001194 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' \) \
1195 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001196}
1197
Matt Alexanderd9c56562020-05-21 10:49:17 +00001198function resgrep()
1199{
Christopher Ferris55257d22017-03-23 11:08:58 -07001200 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001201 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1202 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1203 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001204}
1205
Matt Alexanderd9c56562020-05-21 10:49:17 +00001206function mangrep()
1207{
Mike Frysinger5e479732015-09-22 18:13:48 -04001208 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1209 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001210}
1211
Matt Alexanderd9c56562020-05-21 10:49:17 +00001212function owngrep()
1213{
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -06001214 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
1215 -exec grep --color -n "$@" {} +
1216}
1217
Matt Alexanderd9c56562020-05-21 10:49:17 +00001218function sepgrep()
1219{
Mike Frysinger5e479732015-09-22 18:13:48 -04001220 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1221 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001222}
1223
Matt Alexanderd9c56562020-05-21 10:49:17 +00001224function rcgrep()
1225{
Mike Frysinger5e479732015-09-22 18:13:48 -04001226 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1227 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001228}
1229
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001230case `uname -s` in
1231 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001232 function mgrep()
1233 {
Orion Hodson831472d2019-10-25 11:35:15 +01001234 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 -04001235 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236 }
1237
Matt Alexanderd9c56562020-05-21 10:49:17 +00001238 function treegrep()
1239 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001240 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 -04001241 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001242 }
1243
1244 ;;
1245 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001246 function mgrep()
1247 {
Orion Hodson831472d2019-10-25 11:35:15 +01001248 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 -04001249 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001250 }
1251
Matt Alexanderd9c56562020-05-21 10:49:17 +00001252 function treegrep()
1253 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001254 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 -04001255 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001256 }
1257
1258 ;;
1259esac
1260
Matt Alexanderd9c56562020-05-21 10:49:17 +00001261function getprebuilt
1262{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001263 get_abs_build_var ANDROID_PREBUILTS
1264}
1265
Matt Alexanderd9c56562020-05-21 10:49:17 +00001266function tracedmdump()
1267{
Christopher Ferris55257d22017-03-23 11:08:58 -07001268 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001269 if [ ! "$T" ]; then
1270 echo "Couldn't locate the top of the tree. Try setting TOP."
1271 return
1272 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001273 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001274 local arch=$(gettargetarch)
1275 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001276
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001277 local TRACE=$1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001278 if [ ! "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001279 echo "usage: tracedmdump tracename"
1280 return
1281 fi
1282
Matt Alexanderd9c56562020-05-21 10:49:17 +00001283 if [ ! -r "$KERNEL" ] ; then
Jack Veenstra60116fc2009-04-09 18:12:34 -07001284 echo "Error: cannot find kernel: '$KERNEL'"
1285 return
1286 fi
1287
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001288 local BASETRACE=$(basename $TRACE)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001289 if [ "$BASETRACE" = "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001290 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1291 fi
1292
1293 echo "post-processing traces..."
1294 rm -f $TRACE/qtrace.dexlist
1295 post_trace $TRACE
1296 if [ $? -ne 0 ]; then
1297 echo "***"
1298 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1299 echo "***"
1300 return
1301 fi
1302 echo "generating dexlist output..."
1303 /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
1304 echo "generating dmtrace data..."
1305 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1306 echo "generating html file..."
1307 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1308 echo "done, see $TRACE/dmtrace.html for details"
1309 echo "or run:"
1310 echo " traceview $TRACE/dmtrace"
1311}
1312
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001313# communicate with a running device or emulator, set up necessary state,
1314# and run the hat command.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001315function runhat()
1316{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001317 # process standard adb options
1318 local adbTarget=""
Matt Alexanderd9c56562020-05-21 10:49:17 +00001319 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001320 adbTarget=$1
1321 shift 1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001322 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001323 adbTarget="$1 $2"
1324 shift 2
1325 fi
1326 local adbOptions=${adbTarget}
Matt Alexanderd9c56562020-05-21 10:49:17 +00001327 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001328
1329 # runhat options
1330 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001331
Matt Alexanderd9c56562020-05-21 10:49:17 +00001332 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001333 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001334 return
1335 fi
1336
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001337 # confirm hat is available
1338 if [ -z $(which hat) ]; then
1339 echo "hat is not available in this configuration."
1340 return
1341 fi
1342
Andy McFaddenb6289852010-07-12 08:00:19 -07001343 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001344 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001345 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001346 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001347 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001348 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001349 echo -n "> "
1350 read
1351
The Android Open Source Project88b60792009-03-03 19:28:42 -08001352 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001353
The Android Open Source Project88b60792009-03-03 19:28:42 -08001354 echo "Retrieving file $devFile..."
1355 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001356
The Android Open Source Project88b60792009-03-03 19:28:42 -08001357 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001358
The Android Open Source Project88b60792009-03-03 19:28:42 -08001359 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001360 echo "View the output by pointing your browser at http://localhost:7000/"
1361 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001362 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001363}
1364
Matt Alexanderd9c56562020-05-21 10:49:17 +00001365function getbugreports()
1366{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001367 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001368
1369 if [ ! "$reports" ]; then
1370 echo "Could not locate any bugreports."
1371 return
1372 fi
1373
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001374 local report
1375 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001376 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001377 echo "/sdcard/bugreports/${report}"
1378 adb pull /sdcard/bugreports/${report} ${report}
1379 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001380 done
1381}
1382
Matt Alexanderd9c56562020-05-21 10:49:17 +00001383function getsdcardpath()
1384{
Victoria Lease1b296b42012-08-21 15:44:06 -07001385 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1386}
1387
Matt Alexanderd9c56562020-05-21 10:49:17 +00001388function getscreenshotpath()
1389{
Victoria Lease1b296b42012-08-21 15:44:06 -07001390 echo "$(getsdcardpath)/Pictures/Screenshots"
1391}
1392
Matt Alexanderd9c56562020-05-21 10:49:17 +00001393function getlastscreenshot()
1394{
Victoria Lease1b296b42012-08-21 15:44:06 -07001395 local screenshot_path=$(getscreenshotpath)
1396 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 +00001397 if [ "$screenshot" = "" ]; then
Victoria Lease1b296b42012-08-21 15:44:06 -07001398 echo "No screenshots found."
1399 return
1400 fi
1401 echo "${screenshot}"
1402 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1403}
1404
Matt Alexanderd9c56562020-05-21 10:49:17 +00001405function startviewserver()
1406{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001407 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001408 if [ $# -gt 0 ]; then
1409 port=$1
1410 fi
1411 adb shell service call window 1 i32 $port
1412}
1413
Matt Alexanderd9c56562020-05-21 10:49:17 +00001414function stopviewserver()
1415{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001416 adb shell service call window 2
1417}
1418
Matt Alexanderd9c56562020-05-21 10:49:17 +00001419function isviewserverstarted()
1420{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001421 adb shell service call window 3
1422}
1423
Matt Alexanderd9c56562020-05-21 10:49:17 +00001424function key_home()
1425{
Romain Guyb84049a2010-10-04 16:56:11 -07001426 adb shell input keyevent 3
1427}
1428
Matt Alexanderd9c56562020-05-21 10:49:17 +00001429function key_back()
1430{
Romain Guyb84049a2010-10-04 16:56:11 -07001431 adb shell input keyevent 4
1432}
1433
Matt Alexanderd9c56562020-05-21 10:49:17 +00001434function key_menu()
1435{
Romain Guyb84049a2010-10-04 16:56:11 -07001436 adb shell input keyevent 82
1437}
1438
Matt Alexanderd9c56562020-05-21 10:49:17 +00001439function smoketest()
1440{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001441 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1442 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1443 return
1444 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001445 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001446 if [ ! "$T" ]; then
1447 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1448 return
1449 fi
1450
Ying Wang9cd17642012-12-13 10:52:07 -08001451 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001452 adb uninstall com.android.smoketest > /dev/null &&
1453 adb uninstall com.android.smoketest.tests > /dev/null &&
1454 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1455 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1456 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1457}
1458
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001459# simple shortcut to the runtest command
Matt Alexanderd9c56562020-05-21 10:49:17 +00001460function runtest()
1461{
Christopher Ferris55257d22017-03-23 11:08:58 -07001462 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001463 if [ ! "$T" ]; then
1464 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1465 return
1466 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001467 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001468}
1469
The Android Open Source Project88b60792009-03-03 19:28:42 -08001470function godir () {
1471 if [[ -z "$1" ]]; then
1472 echo "Usage: godir <regex>"
1473 return
1474 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001475 local T=$(gettop)
1476 local FILELIST
Matt Alexanderd9c56562020-05-21 10:49:17 +00001477 if [ ! "$OUT_DIR" = "" ]; then
Brian Carlstromf2257422015-09-30 20:28:54 -07001478 mkdir -p $OUT_DIR
1479 FILELIST=$OUT_DIR/filelist
1480 else
1481 FILELIST=$T/filelist
1482 fi
1483 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001484 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001485 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001486 echo " Done"
1487 echo ""
1488 fi
1489 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001490 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
Matt Alexanderd9c56562020-05-21 10:49:17 +00001491 if [[ ${#lines[@]} = 0 ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001492 echo "Not found"
1493 return
1494 fi
1495 local pathname
1496 local choice
1497 if [[ ${#lines[@]} > 1 ]]; then
1498 while [[ -z "$pathname" ]]; do
1499 local index=1
1500 local line
1501 for line in ${lines[@]}; do
1502 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001503 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001504 done
1505 echo
1506 echo -n "Select one: "
1507 unset choice
1508 read choice
1509 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1510 echo "Invalid choice"
1511 continue
1512 fi
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001513 pathname=${lines[@]:$(($choice-1)):1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001514 done
1515 else
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001516 pathname=${lines[@]:0:1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001517 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001518 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001519}
1520
Steven Moreland62054a42018-12-06 10:11:40 -08001521# Update module-info.json in out.
1522function refreshmod() {
1523 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1524 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1525 return 1
1526 fi
1527
1528 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1529
1530 # for the output of the next command
1531 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1532
1533 # Note, can't use absolute path because of the way make works.
Alessandro Astonec8771be2020-05-10 11:27:57 +02001534 m $(get_build_var PRODUCT_OUT)/module-info.json \
Steven Moreland62054a42018-12-06 10:11:40 -08001535 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1536}
1537
Cole Faust3e192382021-10-25 13:29:15 -07001538# Verifies that module-info.txt exists, returning nonzero if it doesn't.
Cole Faust24c36db2021-01-23 02:39:37 +00001539function verifymodinfo() {
Steven Moreland62054a42018-12-06 10:11:40 -08001540 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001541 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
1542 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1543 fi
Steven Moreland62054a42018-12-06 10:11:40 -08001544 return 1
1545 fi
1546
1547 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001548 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
Cole Faust3e192382021-10-25 13:29:15 -07001549 echo "Could not find module-info.json. Please run 'refreshmod' first." >&2
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001550 fi
1551 return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001552 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001553}
1554
1555# List all modules for the current device, as cached in module-info.json. If any build change is
1556# made and it should be reflected in the output, you should run 'refreshmod' first.
1557function allmod() {
1558 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001559
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001560 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 -08001561}
1562
Joe Onorato2c1aa472021-02-25 16:42:39 -08001563# Get the path of a specific module in the android tree, as cached in module-info.json.
1564# If any build change is made, and it should be reflected in the output, you should run
1565# 'refreshmod' first. Note: This is the inverse of dirmods.
Rett Berg78d1c932019-01-24 14:34:23 -08001566function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001567 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001568 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001569 return 1
1570 fi
1571
Cole Faust24c36db2021-01-23 02:39:37 +00001572 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001573
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001574 local relpath=$(python3 -c "import json, os
Steven Moreland62054a42018-12-06 10:11:40 -08001575module = '$1'
1576module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1577if module not in module_info:
1578 exit(1)
LuK1337b6a78192020-01-12 03:12:17 +01001579print(module_info[module]['path'][0])" 2>/dev/null)
Steven Moreland62054a42018-12-06 10:11:40 -08001580
1581 if [ -z "$relpath" ]; then
1582 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1583 return 1
1584 else
Rett Berg78d1c932019-01-24 14:34:23 -08001585 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001586 fi
1587}
1588
Joe Onorato2c1aa472021-02-25 16:42:39 -08001589# Get the path of a specific module in the android tree, as cached in module-info.json.
1590# If any build change is made, and it should be reflected in the output, you should run
1591# 'refreshmod' first. Note: This is the inverse of pathmod.
1592function dirmods() {
1593 if [[ $# -ne 1 ]]; then
1594 echo "usage: dirmods <path>" >&2
1595 return 1
1596 fi
1597
1598 verifymodinfo || return 1
1599
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001600 python3 -c "import json, os
Joe Onorato2c1aa472021-02-25 16:42:39 -08001601dir = '$1'
1602while dir.endswith('/'):
1603 dir = dir[:-1]
1604prefix = dir + '/'
1605module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1606results = set()
1607for m in module_info.values():
1608 for path in m.get(u'path', []):
1609 if path == dir or path.startswith(prefix):
1610 name = m.get(u'module_name')
1611 if name:
1612 results.add(name)
1613for name in sorted(results):
1614 print(name)
1615"
1616}
1617
1618
Rett Berg78d1c932019-01-24 14:34:23 -08001619# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1620# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1621function gomod() {
1622 if [[ $# -ne 1 ]]; then
1623 echo "usage: gomod <module>" >&2
1624 return 1
1625 fi
1626
1627 local path="$(pathmod $@)"
1628 if [ -z "$path" ]; then
1629 return 1
1630 fi
1631 cd $path
1632}
1633
Cole Faust24c36db2021-01-23 02:39:37 +00001634# Gets the list of a module's installed outputs, as cached in module-info.json.
1635# If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first.
1636function outmod() {
1637 if [[ $# -ne 1 ]]; then
1638 echo "usage: outmod <module>" >&2
1639 return 1
1640 fi
1641
1642 verifymodinfo || return 1
1643
1644 local relpath
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001645 relpath=$(python3 -c "import json, os
Cole Faust24c36db2021-01-23 02:39:37 +00001646module = '$1'
1647module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1648if module not in module_info:
1649 exit(1)
1650for output in module_info[module]['installed']:
1651 print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null)
1652
1653 if [ $? -ne 0 ]; then
1654 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2
1655 return 1
1656 elif [ ! -z "$relpath" ]; then
1657 echo "$relpath"
1658 fi
1659}
1660
1661# adb install a module's apk, as cached in module-info.json. If any build change
1662# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1663# Usage: installmod [adb install arguments] <module>
1664# For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk
1665function installmod() {
1666 if [[ $# -eq 0 ]]; then
1667 echo "usage: installmod [adb install arguments] <module>" >&2
Cole Faust3e192382021-10-25 13:29:15 -07001668 echo "" >&2
1669 echo "Only flags to be passed after the \"install\" in adb install are supported," >&2
1670 echo "with the exception of -s. If -s is passed it will be placed before the \"install\"." >&2
1671 echo "-s must be the first flag passed if it exists." >&2
Cole Faust24c36db2021-01-23 02:39:37 +00001672 return 1
1673 fi
1674
1675 local _path
1676 _path=$(outmod ${@:$#:1})
1677 if [ $? -ne 0 ]; then
1678 return 1
1679 fi
1680
1681 _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1)
1682 if [ -z "$_path" ]; then
1683 echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2
1684 return 1
1685 fi
Cole Faust3e192382021-10-25 13:29:15 -07001686 local serial_device=""
1687 if [[ "$1" == "-s" ]]; then
1688 if [[ $# -le 2 ]]; then
1689 echo "-s requires an argument" >&2
1690 return 1
1691 fi
1692 serial_device="-s $2"
1693 shift 2
1694 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001695 local length=$(( $# - 1 ))
Cole Faust3e192382021-10-25 13:29:15 -07001696 echo adb $serial_device install ${@:1:$length} $_path
1697 adb $serial_device install ${@:1:$length} $_path
Cole Faust24c36db2021-01-23 02:39:37 +00001698}
1699
dimitry73b84812018-12-11 18:06:00 +01001700function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001701 local word=${COMP_WORDS[COMP_CWORD]}
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001702 COMPREPLY=( $(QUIET_VERIFYMODINFO=true allmod | grep -E "^$word") )
Steven Moreland62054a42018-12-06 10:11:40 -08001703}
1704
Alex Rayf0d08eb2013-03-08 15:15:06 -08001705# Print colored exit condition
1706function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001707 "$@"
1708 local retval=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +00001709 if [ $retval -ne 0 ]
1710 then
Jacky Cao89483b82015-05-15 22:12:53 +08001711 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001712 else
Jacky Cao89483b82015-05-15 22:12:53 +08001713 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001714 fi
1715 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001716}
1717
Matt Alexanderd9c56562020-05-21 10:49:17 +00001718function get_make_command()
1719{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001720 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1721 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001722 # Always use the real make if -C is passed in
1723 for arg in "$@"; do
1724 if [[ $arg == -C* ]]; then
1725 echo command make
1726 return
1727 fi
1728 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001729 echo build/soong/soong_ui.bash --make-mode
1730 else
1731 echo command make
1732 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001733}
1734
Matt Alexanderd9c56562020-05-21 10:49:17 +00001735function _wrap_build()
1736{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001737 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1738 "$@"
1739 return $?
1740 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001741 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001742 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001743 local ret=$?
1744 local end_time=$(date +"%s")
1745 local tdiff=$(($end_time-$start_time))
1746 local hours=$(($tdiff / 3600 ))
1747 local mins=$((($tdiff % 3600) / 60))
1748 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001749 local ncolors=$(tput colors 2>/dev/null)
1750 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001751 color_failed=$'\E'"[0;31m"
1752 color_success=$'\E'"[0;32m"
Kousik Kumar09af2542021-08-19 16:13:32 -04001753 color_warning=$'\E'"[0;33m"
Jacky Cao89483b82015-05-15 22:12:53 +08001754 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001755 else
1756 color_failed=""
1757 color_success=""
1758 color_reset=""
1759 fi
Kousik Kumar09af2542021-08-19 16:13:32 -04001760
1761 if [[ "x${USE_RBE}" == "x" && $mins -gt 15 && "${ANDROID_BUILD_ENVIRONMENT_CONFIG}" == "googler" ]]; then
1762 echo
1763 echo "${color_warning}Start using RBE (http://go/build-fast) to get faster builds!${color_reset}"
1764 fi
1765
Ed Heylcc6be0a2014-06-18 14:55:58 -07001766 echo
Matt Alexanderd9c56562020-05-21 10:49:17 +00001767 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001768 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001769 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001770 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001771 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +00001772 if [ $hours -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001773 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001774 elif [ $mins -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001775 printf "(%02g:%02g (mm:ss))" $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001776 elif [ $secs -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001777 printf "(%s seconds)" $secs
1778 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001779 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001780 echo
1781 return $ret
1782}
1783
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001784function _trigger_build()
1785(
1786 local -r bc="$1"; shift
1787 if T="$(gettop)"; then
1788 _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
1789 else
Jingwen Chend728ee12021-05-18 06:02:53 +00001790 >&2 echo "Couldn't locate the top of the tree. Try setting TOP."
1791 return 1
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001792 fi
1793)
1794
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001795# Convenience entry point (like m) to use Bazel in AOSP.
Jingwen Chend728ee12021-05-18 06:02:53 +00001796function b()
1797(
1798 # Generate BUILD, bzl files into the synthetic Bazel workspace (out/soong/workspace).
Sam Delmerico9d67a902022-04-11 12:25:18 +00001799 _trigger_build "all-modules" bp2build USE_BAZEL_ANALYSIS= || return 1
Jingwen Chend728ee12021-05-18 06:02:53 +00001800 # Then, run Bazel using the synthetic workspace as the --package_path.
Sam Delmerico9d67a902022-04-11 12:25:18 +00001801 if [[ -z "$@" ]]; then
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001802 # If there are no args, show help.
Jingwen Chenbfa114d2021-06-17 05:42:43 +00001803 bazel help
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001804 else
1805 # Else, always run with the bp2build configuration, which sets Bazel's package path to the synthetic workspace.
Sam Delmerico9d67a902022-04-11 12:25:18 +00001806 bazel "$@" --config=bp2build
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001807 fi
Jingwen Chend728ee12021-05-18 06:02:53 +00001808)
1809
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001810function m()
1811(
1812 _trigger_build "all-modules" "$@"
1813)
1814
1815function mm()
1816(
1817 _trigger_build "modules-in-a-dir-no-deps" "$@"
1818)
1819
1820function mmm()
1821(
1822 _trigger_build "modules-in-dirs-no-deps" "$@"
1823)
1824
1825function mma()
1826(
1827 _trigger_build "modules-in-a-dir" "$@"
1828)
1829
1830function mmma()
1831(
1832 _trigger_build "modules-in-dirs" "$@"
1833)
1834
Matt Alexanderd9c56562020-05-21 10:49:17 +00001835function make()
1836{
Dan Willemsene9842242017-07-28 13:00:13 -07001837 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001838}
1839
Matt Alexanderd9c56562020-05-21 10:49:17 +00001840function provision()
1841{
David Zeuthen1b126ff2015-09-30 17:10:48 -04001842 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1843 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1844 return 1
1845 fi
1846 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1847 echo "There is no provisioning script for the device." >&2
1848 return 1
1849 fi
1850
1851 # Check if user really wants to do this.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001852 if [ "$1" = "--no-confirmation" ]; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001853 shift 1
1854 else
1855 echo "This action will reflash your device."
1856 echo ""
1857 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1858 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001859 echo -n "Are you sure you want to do this (yes/no)? "
1860 read
Matt Alexanderd9c56562020-05-21 10:49:17 +00001861 if [[ "${REPLY}" != "yes" ]] ; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001862 echo "Not taking any action. Exiting." >&2
1863 return 1
1864 fi
1865 fi
1866 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1867}
1868
Jim Tanga881a252018-06-19 16:34:41 +08001869# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001870function enable_zsh_completion() {
1871 # Don't override user's options if bash-style completion is already enabled.
1872 if ! declare -f complete >/dev/null; then
1873 autoload -U compinit && compinit
1874 autoload -U bashcompinit && bashcompinit
1875 fi
Jim Tanga881a252018-06-19 16:34:41 +08001876}
1877
1878function validate_current_shell() {
1879 local current_sh="$(ps -o command -p $$)"
1880 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001881 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001882 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001883 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001884 *zsh*)
1885 function check_type() { type "$1"; }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001886 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001887 *)
Jim Tanga881a252018-06-19 16:34:41 +08001888 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 -07001889 ;;
1890 esac
Jim Tanga881a252018-06-19 16:34:41 +08001891}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001892
1893# Execute the contents of any vendorsetup.sh files we can find.
Dan Willemsend855a722019-02-12 15:52:36 -08001894# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
1895# load those.
1896#
1897# This allows loading only approved vendorsetup.sh files
Jim Tanga881a252018-06-19 16:34:41 +08001898function source_vendorsetup() {
Jim Tangc4dba1d2019-07-25 16:54:27 +08001899 unset VENDOR_PYTHONPATH
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001900 local T="$(gettop)"
Dan Willemsend855a722019-02-12 15:52:36 -08001901 allowed=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001902 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 -08001903 if [ -n "$allowed" ]; then
1904 echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
1905 echo " $allowed"
1906 echo " $f"
1907 return
1908 fi
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001909 allowed="$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001910 done
1911
1912 allowed_files=
1913 [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
Jim Tanga881a252018-06-19 16:34:41 +08001914 for dir in device vendor product; do
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001915 for f in $(cd "$T" && test -d $dir && \
Jim Tanga881a252018-06-19 16:34:41 +08001916 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001917
1918 if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001919 echo "including $f"; . "$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001920 else
1921 echo "ignoring $f, not in $allowed"
1922 fi
Jim Tanga881a252018-06-19 16:34:41 +08001923 done
1924 done
1925}
Kenny Root52aa81c2011-07-15 11:07:06 -07001926
Dan Albertbab814f2020-08-26 15:34:53 -07001927function showcommands() {
1928 local T=$(gettop)
1929 if [[ -z "$TARGET_PRODUCT" ]]; then
1930 >&2 echo "TARGET_PRODUCT not set. Run lunch."
1931 return
1932 fi
1933 case $(uname -s) in
1934 Darwin)
1935 PREBUILT_NAME=darwin-x86
1936 ;;
1937 Linux)
1938 PREBUILT_NAME=linux-x86
1939 ;;
1940 *)
1941 >&2 echo Unknown host $(uname -s)
1942 return
1943 ;;
1944 esac
1945 if [[ -z "$OUT_DIR" ]]; then
1946 if [[ -z "$OUT_DIR_COMMON_BASE" ]]; then
1947 OUT_DIR=out
1948 else
1949 OUT_DIR=${OUT_DIR_COMMON_BASE}/${PWD##*/}
1950 fi
1951 fi
1952 if [[ "$1" == "--regenerate" ]]; then
1953 shift 1
1954 NINJA_ARGS="-t commands $@" m
1955 else
1956 (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \
1957 -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \
1958 -t commands "$@")
1959 fi
1960}
1961
Jim Tanga881a252018-06-19 16:34:41 +08001962validate_current_shell
1963source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001964addcompletions
Chirayu Desai798bc5e2013-03-19 17:50:37 +05301965
1966export ANDROID_BUILD_TOP=$(gettop)