blob: be6061d67d406c0fc4d369e3e6304bac66d3b3e2 [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
Jeff Gastonc6dfc4e2017-05-30 17:12:37 -07003
4Run "m help" for help with the build system itself.
5
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08006Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Steven Moreland62054a42018-12-06 10:11:40 -08007- lunch: lunch <product_name>-<build_variant>
8 Selects <product_name> as the product to build, and <build_variant> as the variant to
9 build, and stores those selections in the environment to be read by subsequent
10 invocations of 'm' etc.
Elliott Hughesf71c05a2020-03-06 16:46:59 -080011- tapas: tapas [<App1> <App2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
Martin Stjernholmf692c752021-04-12 00:01:10 +010012 Sets up the build environment for building unbundled apps (APKs).
13- banchan: banchan <module1> [<module2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
14 Sets up the build environment for building unbundled modules (APEXes).
Anton Hanssonece9c482019-02-04 18:15:39 +000015- croot: Changes directory to the top of the tree, or a subdirectory thereof.
Steven Moreland62054a42018-12-06 10:11:40 -080016- m: Makes from the top of the tree.
Dan Willemsen67074fe2019-10-30 12:35:34 -070017- mm: Builds and installs all of the modules in the current directory, and their
18 dependencies.
19- mmm: Builds and installs all of the modules in the supplied directories, and their
20 dependencies.
Steven Moreland62054a42018-12-06 10:11:40 -080021 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Dan Willemsen67074fe2019-10-30 12:35:34 -070022- mma: Same as 'mm'
23- mmma: Same as 'mmm'
Steven Moreland62054a42018-12-06 10:11:40 -080024- provision: Flash device with all required partitions. Options will be passed on to fastboot.
25- cgrep: Greps on all local C/C++ files.
26- ggrep: Greps on all local Gradle files.
Orion Hodson831472d2019-10-25 11:35:15 +010027- gogrep: Greps on all local Go files.
Steven Moreland62054a42018-12-06 10:11:40 -080028- jgrep: Greps on all local Java files.
Taesu Leeea0cecd2020-10-28 11:05:18 +090029- ktgrep: Greps on all local Kotlin files.
Steven Moreland62054a42018-12-06 10:11:40 -080030- resgrep: Greps on all local res/*.xml files.
31- mangrep: Greps on all local AndroidManifest.xml files.
Jaewoong Jung892d0fe2019-05-04 10:06:28 -070032- mgrep: Greps on all local Makefiles and *.bp files.
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -060033- owngrep: Greps on all local OWNERS files.
Alistair Delva176e5342021-02-22 13:31:26 -080034- rsgrep: Greps on all local Rust files.
Steven Moreland62054a42018-12-06 10:11:40 -080035- sepgrep: Greps on all local sepolicy files.
36- sgrep: Greps on all local source files.
37- godir: Go to the directory containing a file.
38- allmod: List all modules.
39- gomod: Go to the directory containing a module.
Rett Berg78d1c932019-01-24 14:34:23 -080040- pathmod: Get the directory containing a module.
Cole Faust24c36db2021-01-23 02:39:37 +000041- outmod: Gets the location of a module's installed outputs with a certain extension.
Joe Onorato2c1aa472021-02-25 16:42:39 -080042- dirmods: Gets the modules defined in a given directory.
Cole Faust24c36db2021-01-23 02:39:37 +000043- installmod: Adb installs a module's built APK.
44- refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod.
Steven Moreland74114f12020-09-10 01:23:32 +000045- syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070046
Roland Levillain39341922015-10-20 12:48:19 +010047Environment options:
Steven Moreland115d1f52019-09-26 16:30:28 -070048- SANITIZE_HOST: Set to 'address' to use ASAN for all host modules.
Sasha Smundak9f27cc02019-01-31 13:25:31 -080049- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
Dan Albert4ae5d4b2014-10-31 16:23:08 -070050
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070051Look at the source to view more functions. The complete list is:
52EOF
Christopher Ferris55257d22017-03-23 11:08:58 -070053 local T=$(gettop)
54 local A=""
55 local i
Jacky Cao89483b82015-05-15 22:12:53 +080056 for i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070057 A="$A $i"
58 done
59 echo $A
60}
61
Ying Wang08800fd2016-03-03 20:57:21 -080062# Get all the build variables needed by this script in a single call to the build system.
Matt Alexanderd9c56562020-05-21 10:49:17 +000063function build_build_var_cache()
64{
Christopher Ferris55257d22017-03-23 11:08:58 -070065 local T=$(gettop)
Ying Wang08800fd2016-03-03 20:57:21 -080066 # Grep out the variable names from the script.
Jim Tanga881a252018-06-19 16:34:41 +080067 cached_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
68 cached_abs_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
Ying Wang08800fd2016-03-03 20:57:21 -080069 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
Steven Moreland05402962018-01-05 12:13:11 -080070 build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
Jim Tanga881a252018-06-19 16:34:41 +080071 --vars="${cached_vars[*]}" \
72 --abs-vars="${cached_abs_vars[*]}" \
Dan Willemsenaf88c412017-07-14 11:29:44 -070073 --var-prefix=var_cache_ \
74 --abs-var-prefix=abs_var_cache_`
Ying Wang08800fd2016-03-03 20:57:21 -080075 local ret=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +000076 if [ $ret -ne 0 ]
77 then
Ying Wang08800fd2016-03-03 20:57:21 -080078 unset build_dicts_script
79 return $ret
80 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -070081 # Execute the script to store the "<val>=<value>" pairs as shell variables.
Ying Wang08800fd2016-03-03 20:57:21 -080082 eval "$build_dicts_script"
Ying Wang08800fd2016-03-03 20:57:21 -080083 ret=$?
Ying Wangf0cb3972016-03-04 13:56:23 -080084 unset build_dicts_script
Matt Alexanderd9c56562020-05-21 10:49:17 +000085 if [ $ret -ne 0 ]
86 then
Ying Wang08800fd2016-03-03 20:57:21 -080087 return $ret
88 fi
89 BUILD_VAR_CACHE_READY="true"
90}
91
Ying Wangf0cb3972016-03-04 13:56:23 -080092# Delete the build var cache, so that we can still call into the build system
Ying Wang08800fd2016-03-03 20:57:21 -080093# to get build variables not listed in this script.
Matt Alexanderd9c56562020-05-21 10:49:17 +000094function destroy_build_var_cache()
95{
Ying Wang08800fd2016-03-03 20:57:21 -080096 unset BUILD_VAR_CACHE_READY
Christopher Ferris55257d22017-03-23 11:08:58 -070097 local v
Ying Wang08800fd2016-03-03 20:57:21 -080098 for v in $cached_vars; do
99 unset var_cache_$v
100 done
101 unset cached_vars
102 for v in $cached_abs_vars; do
103 unset abs_var_cache_$v
104 done
105 unset cached_abs_vars
106}
107
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700108# Get the value of a build variable as an absolute path.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000109function get_abs_build_var()
110{
111 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
112 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800113 eval "echo \"\${abs_var_cache_$1}\""
Timi0469c3f2021-04-15 16:41:18 +0200114 return
Ying Wang08800fd2016-03-03 20:57:21 -0800115 fi
116
Christopher Ferris55257d22017-03-23 11:08:58 -0700117 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700118 if [ ! "$T" ]; then
119 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
120 return
121 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700122 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700123}
124
125# Get the exact value of a build variable.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000126function get_build_var()
127{
128 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
129 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800130 eval "echo \"\${var_cache_$1}\""
Roland Levillain23c46cf2020-03-31 16:11:05 +0100131 return 0
Ying Wang08800fd2016-03-03 20:57:21 -0800132 fi
133
Christopher Ferris55257d22017-03-23 11:08:58 -0700134 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700135 if [ ! "$T" ]; then
136 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
Roland Levillain23c46cf2020-03-31 16:11:05 +0100137 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700138 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700139 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800140}
141
142# check to see if the supplied product is one we can build
Matt Alexanderd9c56562020-05-21 10:49:17 +0000143function check_product()
144{
Christopher Ferris55257d22017-03-23 11:08:58 -0700145 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800146 if [ ! "$T" ]; then
147 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
148 return
149 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700150 TARGET_PRODUCT=$1 \
151 TARGET_BUILD_VARIANT= \
152 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700153 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800154 get_build_var TARGET_DEVICE > /dev/null
155 # hide successful answers, but allow the errors to show
156}
157
158VARIANT_CHOICES=(user userdebug eng)
159
160# check to see if the supplied variant is valid
Matt Alexanderd9c56562020-05-21 10:49:17 +0000161function check_variant()
162{
Christopher Ferris55257d22017-03-23 11:08:58 -0700163 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800164 for v in ${VARIANT_CHOICES[@]}
165 do
Matt Alexanderd9c56562020-05-21 10:49:17 +0000166 if [ "$v" = "$1" ]
167 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800168 return 0
169 fi
170 done
171 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700172}
173
Matt Alexanderd9c56562020-05-21 10:49:17 +0000174function setpaths()
175{
Christopher Ferris55257d22017-03-23 11:08:58 -0700176 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700177 if [ ! "$T" ]; then
178 echo "Couldn't locate the top of the tree. Try setting TOP."
179 return
180 fi
181
182 ##################################################################
183 # #
184 # Read me before you modify this code #
185 # #
186 # This function sets ANDROID_BUILD_PATHS to what it is adding #
187 # to PATH, and the next time it is run, it removes that from #
188 # PATH. This is required so lunch can be run more than once #
189 # and still have working paths. #
190 # #
191 ##################################################################
192
Raphael Mollc639c782011-06-20 17:25:01 -0700193 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
194 # due to "C:\Program Files" being in the path.
195
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700196 # out with the old
Matt Alexanderd9c56562020-05-21 10:49:17 +0000197 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700198 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
199 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000200 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700201 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800202 # strip leading ':', if any
203 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500204 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700205
206 # and in with the new
Christopher Ferris55257d22017-03-23 11:08:58 -0700207 local prebuiltdir=$(getprebuilt)
208 local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700209
Ben Cheng8bc4c432012-11-16 13:29:13 -0800210 # defined in core/config.mk
Christopher Ferris55257d22017-03-23 11:08:58 -0700211 local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
212 local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800213 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800214
Raphael Mollc639c782011-06-20 17:25:01 -0700215 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800216 export ANDROID_TOOLCHAIN=
217 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200218 local ARCH=$(get_build_var TARGET_ARCH)
Christopher Ferris55257d22017-03-23 11:08:58 -0700219 local toolchaindir toolchaindir2=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200220 case $ARCH in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000221 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700222 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000223 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Pavel Chupinfd82a492012-11-26 09:50:07 +0400224 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000225 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200226 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000227 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
228 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700229 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200230 *)
231 echo "Can't find toolchain for unknown architecture: $ARCH"
232 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700233 ;;
234 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700235 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800236 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700237 fi
Raphael732936d2011-06-22 14:35:32 -0700238
Christopher Ferris55257d22017-03-23 11:08:58 -0700239 if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800240 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
241 fi
242
Dan Willemsen838dcec2021-09-30 22:40:34 +0000243 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Yueyao Zhuefc786a2017-04-07 14:11:54 -0700244
245 # add kernel specific binaries
246 case $(uname -s) in
247 Linux)
248 export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
249 ;;
250 *)
251 ;;
252 esac
253
Torne (Richard Coles)0091bae2017-10-03 16:31:18 -0400254 ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN
Martin Stjernholm6a012262021-11-24 14:56:15 +0000255 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH
Yi Kongdfd00b12019-05-21 16:00:04 -0700256 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS
257
258 # Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS.
259 local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
260 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200261
Stephen Hinesaa8d72c2020-02-04 09:15:18 -0800262 # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds.
263 export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer
264
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200265 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
266 # to ensure that the corresponding 'emulator' binaries are used.
267 case $(uname -s) in
268 Darwin)
269 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
270 ;;
271 Linux)
272 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
273 ;;
274 *)
275 ANDROID_EMULATOR_PREBUILTS=
276 ;;
277 esac
278 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Yi Kongdfd00b12019-05-21 16:00:04 -0700279 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200280 export ANDROID_EMULATOR_PREBUILTS
281 fi
282
Jim Tangb3fda302018-12-22 10:24:55 +0800283 # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
284 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
Ryan Prichard8426a192019-07-15 18:05:29 -0700285 local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch"
286 local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch"
287 local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch"
Martin Stjernholm6a012262021-11-24 14:56:15 +0000288 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH
Jim Tangb3fda302018-12-22 10:24:55 +0800289
Martin Stjernholm6a012262021-11-24 14:56:15 +0000290 export ANDROID_BUILD_PATHS=$(tr -s : <<<"${ANDROID_BUILD_PATHS}:")
Ryan Prichard8426a192019-07-15 18:05:29 -0700291 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800292
293 # out with the duplicate old
294 if [ -n $ANDROID_PYTHONPATH ]; then
295 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
296 fi
297 # and in with the new
298 export ANDROID_PYTHONPATH=$T/development/python-packages:
Jim Tangc4dba1d2019-07-25 16:54:27 +0800299 if [ -n $VENDOR_PYTHONPATH ]; then
300 ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
301 fi
Jim Tang22f4c322018-12-17 15:21:53 +0800302 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303
Colin Crosse97e6932017-06-30 16:01:45 -0700304 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
305 export JAVA_HOME=$ANDROID_JAVA_HOME
306 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
307 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
308 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500309
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800310 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700311 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
312 export OUT=$ANDROID_PRODUCT_OUT
313
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700314 unset ANDROID_HOST_OUT
315 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
316
Jiyong Parkc02b1c42020-11-03 11:06:39 +0900317 unset ANDROID_SOONG_HOST_OUT
318 export ANDROID_SOONG_HOST_OUT=$(get_abs_build_var SOONG_HOST_OUT)
319
Simran Basidd050ed2017-02-13 13:46:48 -0800320 unset ANDROID_HOST_OUT_TESTCASES
321 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
322
323 unset ANDROID_TARGET_OUT_TESTCASES
324 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
325
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800326 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700327 # TODO: fix the path
328 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
329}
330
Rupert Shuttleworth5d60d022020-10-25 05:20:03 +0000331function bazel()
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000332{
Jingwen Chen17d56992021-06-10 08:17:54 +0000333 if which bazel &>/dev/null; then
334 >&2 echo "NOTE: bazel() function sourced from Android's envsetup.sh is being used instead of $(which bazel)"
335 >&2 echo
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000336 fi
337
Jingwen Chen17d56992021-06-10 08:17:54 +0000338 local T="$(gettop)"
339 if [ ! "$T" ]; then
340 >&2 echo "Couldn't locate the top of the Android tree. Try setting TOP. This bazel() function cannot be used outside of the AOSP directory."
341 return
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000342 fi
343
Rupert Shuttleworth5d60d022020-10-25 05:20:03 +0000344 "$T/tools/bazel" "$@"
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000345}
346
Matt Alexanderd9c56562020-05-21 10:49:17 +0000347function printconfig()
348{
Christopher Ferris55257d22017-03-23 11:08:58 -0700349 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800350 if [ ! "$T" ]; then
351 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
352 return
353 fi
354 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700355}
356
Matt Alexanderd9c56562020-05-21 10:49:17 +0000357function set_stuff_for_environment()
358{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800359 setpaths
360 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700361
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800362 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700363 # With this environment variable new GCC can apply colors to warnings/errors
364 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700365}
366
Matt Alexanderd9c56562020-05-21 10:49:17 +0000367function set_sequence_number()
368{
Colin Cross88737132017-03-21 17:41:03 -0700369 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700370}
371
Makoto Onukida971062018-06-18 10:15:19 -0700372# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
373function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800374 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700375 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800376 *:"$cmd":*)
377 return 1
378 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700379 esac
380 return 0
381}
382
Matt Alexanderd9c56562020-05-21 10:49:17 +0000383function addcompletions()
384{
Ben Taitelbaum8c2c9cf2020-09-22 16:45:05 -0700385 local f=
Kenny Root52aa81c2011-07-15 11:07:06 -0700386
Jim Tanga881a252018-06-19 16:34:41 +0800387 # Keep us from trying to run in something that's neither bash nor zsh.
388 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700389 return
390 fi
391
392 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800393 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700394 return
395 fi
396
Jim Tanga881a252018-06-19 16:34:41 +0800397 local completion_files=(
398 system/core/adb/adb.bash
399 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800400 tools/asuite/asuite.sh
Jim Tanga881a252018-06-19 16:34:41 +0800401 )
Makoto Onukida971062018-06-18 10:15:19 -0700402 # Completion can be disabled selectively to allow users to use non-standard completion.
403 # e.g.
404 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
405 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800406 for f in ${completion_files[*]}; do
407 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700408 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700409 fi
410 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700411
Matt Alexanderd9c56562020-05-21 10:49:17 +0000412 if should_add_completion bit ; then
Makoto Onukida971062018-06-18 10:15:19 -0700413 complete -C "bit --tab" bit
414 fi
Anton Hanssonece9c482019-02-04 18:15:39 +0000415 if [ -z "$ZSH_VERSION" ]; then
416 # Doesn't work in zsh.
417 complete -o nospace -F _croot croot
418 fi
Jim Tanga881a252018-06-19 16:34:41 +0800419 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800420
Cole Faust24c36db2021-01-23 02:39:37 +0000421 complete -F _complete_android_module_names pathmod
dimitry73b84812018-12-11 18:06:00 +0100422 complete -F _complete_android_module_names gomod
Cole Faust24c36db2021-01-23 02:39:37 +0000423 complete -F _complete_android_module_names outmod
424 complete -F _complete_android_module_names installmod
dimitry73b84812018-12-11 18:06:00 +0100425 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700426}
427
Joe Onorato824608c2022-04-08 11:06:16 -0700428function multitree_lunch_help()
429{
430 echo "usage: lunch PRODUCT-VARIANT" 1>&2
431 echo " Set up android build environment based on a product short name and variant" 1>&2
432 echo 1>&2
433 echo "lunch COMBO_FILE VARIANT" 1>&2
434 echo " Set up android build environment based on a specific lunch combo file" 1>&2
435 echo " and variant." 1>&2
436 echo 1>&2
437 echo "lunch --print [CONFIG]" 1>&2
438 echo " Print the contents of a configuration. If CONFIG is supplied, that config" 1>&2
439 echo " will be flattened and printed. If CONFIG is not supplied, the currently" 1>&2
440 echo " selected config will be printed. Returns 0 on success or nonzero on error." 1>&2
441 echo 1>&2
442 echo "lunch --list" 1>&2
443 echo " List all possible combo files available in the current tree" 1>&2
444 echo 1>&2
445 echo "lunch --help" 1>&2
446 echo "lunch -h" 1>&2
447 echo " Prints this message." 1>&2
448}
449
450function multitree_lunch()
451{
452 local code
453 local results
454 if $(echo "$1" | grep -q '^-') ; then
455 # Calls starting with a -- argument are passed directly and the function
456 # returns with the lunch.py exit code.
457 build/make/orchestrator/core/lunch.py "$@"
458 code=$?
459 if [[ $code -eq 2 ]] ; then
460 echo 1>&2
461 multitree_lunch_help
462 return $code
463 elif [[ $code -ne 0 ]] ; then
464 return $code
465 fi
466 else
467 # All other calls go through the --lunch variant of lunch.py
468 results=($(build/make/orchestrator/core/lunch.py --lunch "$@"))
469 code=$?
470 if [[ $code -eq 2 ]] ; then
471 echo 1>&2
472 multitree_lunch_help
473 return $code
474 elif [[ $code -ne 0 ]] ; then
475 return $code
476 fi
477
478 export TARGET_BUILD_COMBO=${results[0]}
479 export TARGET_BUILD_VARIANT=${results[1]}
480 fi
481}
482
Matt Alexanderd9c56562020-05-21 10:49:17 +0000483function choosetype()
484{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700485 echo "Build type choices are:"
486 echo " 1. release"
487 echo " 2. debug"
488 echo
489
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700491 DEFAULT_NUM=1
492 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700493
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800494 export TARGET_BUILD_TYPE=
495 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700496 while [ -z $TARGET_BUILD_TYPE ]
497 do
498 echo -n "Which would you like? ["$DEFAULT_NUM"] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000499 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800500 read ANSWER
501 else
502 echo $1
503 ANSWER=$1
504 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700505 case $ANSWER in
506 "")
507 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
508 ;;
509 1)
510 export TARGET_BUILD_TYPE=release
511 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512 release)
513 export TARGET_BUILD_TYPE=release
514 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700515 2)
516 export TARGET_BUILD_TYPE=debug
517 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800518 debug)
519 export TARGET_BUILD_TYPE=debug
520 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700521 *)
522 echo
523 echo "I didn't understand your response. Please try again."
524 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700525 ;;
526 esac
Matt Alexanderd9c56562020-05-21 10:49:17 +0000527 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800528 break
529 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700530 done
531
Ying Wang08800fd2016-03-03 20:57:21 -0800532 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700533 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800534 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700535}
536
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800537#
538# This function isn't really right: It chooses a TARGET_PRODUCT
539# based on the list of boards. Usually, that gets you something
540# that kinda works with a generic product, but really, you should
541# pick a product by name.
542#
Matt Alexanderd9c56562020-05-21 10:49:17 +0000543function chooseproduct()
544{
Christopher Ferris55257d22017-03-23 11:08:58 -0700545 local default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000546 if [ "x$TARGET_PRODUCT" != x ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700547 default_value=$TARGET_PRODUCT
548 else
Ying Wang0a76df52015-06-08 11:57:26 -0700549 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700550 fi
551
Ying Wang08800fd2016-03-03 20:57:21 -0800552 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800553 export TARGET_PRODUCT=
554 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700555 while [ -z "$TARGET_PRODUCT" ]
556 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700557 echo -n "Which product would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000558 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800559 read ANSWER
560 else
561 echo $1
562 ANSWER=$1
563 fi
564
Matt Alexanderd9c56562020-05-21 10:49:17 +0000565 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700566 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800567 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000568 if check_product $ANSWER
569 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800570 export TARGET_PRODUCT=$ANSWER
571 else
572 echo "** Not a valid product: $ANSWER"
573 fi
574 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000575 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800576 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700577 fi
578 done
579
Ying Wang08800fd2016-03-03 20:57:21 -0800580 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800582 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700583}
584
Matt Alexanderd9c56562020-05-21 10:49:17 +0000585function choosevariant()
586{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587 echo "Variant choices are:"
588 local index=1
589 local v
590 for v in ${VARIANT_CHOICES[@]}
591 do
592 # The product name is the name of the directory containing
593 # the makefile we found, above.
594 echo " $index. $v"
595 index=$(($index+1))
596 done
597
598 local default_value=eng
599 local ANSWER
600
601 export TARGET_BUILD_VARIANT=
602 while [ -z "$TARGET_BUILD_VARIANT" ]
603 do
604 echo -n "Which would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000605 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800606 read ANSWER
607 else
608 echo $1
609 ANSWER=$1
610 fi
611
Matt Alexanderd9c56562020-05-21 10:49:17 +0000612 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800613 export TARGET_BUILD_VARIANT=$default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000614 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
615 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Guillaume Chelfice000fd2019-10-03 12:02:46 +0200616 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800617 fi
618 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000619 if check_variant $ANSWER
620 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800621 export TARGET_BUILD_VARIANT=$ANSWER
622 else
623 echo "** Not a valid variant: $ANSWER"
624 fi
625 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000626 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800627 break
628 fi
629 done
630}
631
Matt Alexanderd9c56562020-05-21 10:49:17 +0000632function choosecombo()
633{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700634 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700635
636 echo
637 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700638 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700639
640 echo
641 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700642 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800643
644 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800645 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700646 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800647 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800648 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649}
650
Matt Alexanderd9c56562020-05-21 10:49:17 +0000651function add_lunch_combo()
652{
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800653 if [ -n "$ZSH_VERSION" ]; then
654 echo -n "${funcfiletrace[1]}: "
655 else
656 echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
657 fi
658 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 -0800659}
660
Matt Alexanderd9c56562020-05-21 10:49:17 +0000661function print_lunch_menu()
662{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700663 local uname=$(uname)
Roland Levillain23c46cf2020-03-31 16:11:05 +0100664 local choices
Colin Crossfa50d402021-04-22 13:05:41 -0700665 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 +0100666 local ret=$?
667
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700668 echo
669 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700670 echo
Roland Levillain23c46cf2020-03-31 16:11:05 +0100671
Matt Alexanderd9c56562020-05-21 10:49:17 +0000672 if [ $ret -ne 0 ]
673 then
Roland Levillain23c46cf2020-03-31 16:11:05 +0100674 echo "Warning: Cannot display lunch menu."
675 echo
676 echo "Note: You can invoke lunch with an explicit target:"
677 echo
678 echo " usage: lunch [target]" >&2
679 echo
680 return
681 fi
682
Will Burr40401202022-02-07 12:12:01 +0000683 echo "Lunch menu .. Here are the common combinations:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800684
685 local i=1
686 local choice
Dan Willemsen91763e92019-10-03 15:13:12 -0700687 for choice in $(echo $choices)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800688 do
689 echo " $i. $choice"
690 i=$(($i+1))
691 done
692
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700693 echo
694}
695
Matt Alexanderd9c56562020-05-21 10:49:17 +0000696function lunch()
697{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800698 local answer
699
Steven Moreland92793dc2020-02-25 18:30:18 -0800700 if [[ $# -gt 1 ]]; then
701 echo "usage: lunch [target]" >&2
702 return 1
703 fi
704
Will Burr40401202022-02-07 12:12:01 +0000705 local used_lunch_menu=0
706
Steven Moreland92793dc2020-02-25 18:30:18 -0800707 if [ "$1" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800708 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700709 else
710 print_lunch_menu
Will Burr40401202022-02-07 12:12:01 +0000711 echo "Which would you like? [aosp_arm-eng]"
712 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 -0800713 read answer
Will Burr40401202022-02-07 12:12:01 +0000714 used_lunch_menu=1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700715 fi
716
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800717 local selection=
718
Matt Alexanderd9c56562020-05-21 10:49:17 +0000719 if [ -z "$answer" ]
720 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700721 selection=aosp_arm-eng
Matt Alexanderd9c56562020-05-21 10:49:17 +0000722 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
723 then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800724 local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
Matt Alexanderd9c56562020-05-21 10:49:17 +0000725 if [ $answer -le ${#choices[@]} ]
726 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800727 # array in zsh starts from 1 instead of 0.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000728 if [ -n "$ZSH_VERSION" ]
729 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800730 selection=${choices[$(($answer))]}
731 else
732 selection=${choices[$(($answer-1))]}
733 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800734 fi
Colin Cross88737132017-03-21 17:41:03 -0700735 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800736 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700737 fi
738
Joe Onoratoda12daf2010-06-09 18:18:31 -0700739 export TARGET_BUILD_APPS=
740
Colin Cross88737132017-03-21 17:41:03 -0700741 local product variant_and_version variant version
Colin Cross88737132017-03-21 17:41:03 -0700742 product=${selection%%-*} # Trim everything after first dash
743 variant_and_version=${selection#*-} # Trim everything up to first dash
744 if [ "$variant_and_version" != "$selection" ]; then
745 variant=${variant_and_version%%-*}
746 if [ "$variant" != "$variant_and_version" ]; then
747 version=${variant_and_version#*-}
748 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700749 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800750
Matt Alexanderd9c56562020-05-21 10:49:17 +0000751 if [ -z "$product" ]
752 then
Ying Wang08800fd2016-03-03 20:57:21 -0800753 echo
Colin Cross88737132017-03-21 17:41:03 -0700754 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700755 return 1
756 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800757
Colin Cross88737132017-03-21 17:41:03 -0700758 TARGET_PRODUCT=$product \
759 TARGET_BUILD_VARIANT=$variant \
760 TARGET_PLATFORM_VERSION=$version \
761 build_build_var_cache
Matt Alexanderd9c56562020-05-21 10:49:17 +0000762 if [ $? -ne 0 ]
763 then
Anton Hansson32fa7ee2021-06-14 17:09:58 +0100764 if [[ "$product" =~ .*_(eng|user|userdebug) ]]
765 then
766 echo "Did you mean -${product/*_/}? (dash instead of underscore)"
767 fi
Colin Cross88737132017-03-21 17:41:03 -0700768 return 1
769 fi
Colin Cross88737132017-03-21 17:41:03 -0700770 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
771 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700772 if [ -n "$version" ]; then
773 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
774 else
775 unset TARGET_PLATFORM_VERSION
776 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700777 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700778
Will Burr40401202022-02-07 12:12:01 +0000779 if [ $used_lunch_menu -eq 1 ]; then
780 echo
781 echo "Hint: next time you can simply run 'lunch $selection'"
782 fi
783
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700784 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800785
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700786 set_stuff_for_environment
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700787 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800788 destroy_build_var_cache
Kousik Kumar41dacd12021-05-11 18:38:38 -0400789
790 if [[ -n "${CHECK_MU_CONFIG:-}" ]]; then
791 check_mu_config
792 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793}
794
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700795unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700796# Tab completion for lunch.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000797function _lunch()
798{
Jeff Davidson513d7a42010-08-02 10:00:44 -0700799 local cur prev opts
800 COMPREPLY=()
801 cur="${COMP_WORDS[COMP_CWORD]}"
802 prev="${COMP_WORDS[COMP_CWORD-1]}"
803
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700804 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800805 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700806 fi
807
808 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700809 return 0
810}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700811
Joe Onoratoda12daf2010-06-09 18:18:31 -0700812# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700813# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Matt Alexanderd9c56562020-05-21 10:49:17 +0000814function tapas()
815{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700816 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Elliott Hughesf71c05a2020-03-06 16:46:59 -0800817 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700818 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700819 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 -0800820 local keys="$(echo $* | xargs -n 1 echo | \grep -E '^(devkeys)$' | xargs)"
821 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)"
822
Joe Onoratoda12daf2010-06-09 18:18:31 -0700823
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700824 if [ "$showHelp" != "" ]; then
825 $(gettop)/build/make/tapasHelp.sh
826 return
827 fi
828
Ying Wang67f02922012-08-22 10:25:20 -0700829 if [ $(echo $arch | wc -w) -gt 1 ]; then
830 echo "tapas: Error: Multiple build archs supplied: $arch"
831 return
832 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700833 if [ $(echo $variant | wc -w) -gt 1 ]; then
834 echo "tapas: Error: Multiple build variants supplied: $variant"
835 return
836 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700837 if [ $(echo $density | wc -w) -gt 1 ]; then
838 echo "tapas: Error: Multiple densities supplied: $density"
839 return
840 fi
Colin Cross7f49a672022-01-27 18:15:53 -0800841 if [ $(echo $keys | wc -w) -gt 1 ]; then
842 echo "tapas: Error: Multiple keys supplied: $keys"
843 return
844 fi
Ying Wang67f02922012-08-22 10:25:20 -0700845
Ying Wang0a76df52015-06-08 11:57:26 -0700846 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700847 case $arch in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000848 x86) product=aosp_x86;;
849 arm64) product=aosp_arm64;;
850 x86_64) product=aosp_x86_64;;
Ying Wang67f02922012-08-22 10:25:20 -0700851 esac
Colin Cross7f49a672022-01-27 18:15:53 -0800852 if [ -n "$keys" ]; then
853 product=${product/aosp_/aosp_${keys}_}
854 fi;
855
Joe Onoratoda12daf2010-06-09 18:18:31 -0700856 if [ -z "$variant" ]; then
857 variant=eng
858 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700859 if [ -z "$apps" ]; then
860 apps=all
861 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600862 if [ -z "$density" ]; then
863 density=alldpi
864 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700865
Ying Wang67f02922012-08-22 10:25:20 -0700866 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700867 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700868 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700869 export TARGET_BUILD_TYPE=release
870 export TARGET_BUILD_APPS=$apps
871
Ying Wang08800fd2016-03-03 20:57:21 -0800872 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700873 set_stuff_for_environment
874 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800875 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700876}
877
Martin Stjernholmf692c752021-04-12 00:01:10 +0100878# Configures the build to build unbundled Android modules (APEXes).
879# Run banchan with one or more module names (from apex{} modules).
880function banchan()
881{
882 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100883 local product="$(echo $* | xargs -n 1 echo | \grep -E '^(.*_)?(arm|x86|arm64|x86_64)$' | xargs)"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100884 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100885 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 +0100886
887 if [ "$showHelp" != "" ]; then
888 $(gettop)/build/make/banchanHelp.sh
889 return
890 fi
891
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100892 if [ -z "$product" ]; then
893 product=arm
894 elif [ $(echo $product | wc -w) -gt 1 ]; then
895 echo "banchan: Error: Multiple build archs or products supplied: $products"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100896 return
897 fi
898 if [ $(echo $variant | wc -w) -gt 1 ]; then
899 echo "banchan: Error: Multiple build variants supplied: $variant"
900 return
901 fi
902 if [ -z "$apps" ]; then
903 echo "banchan: Error: No modules supplied"
904 return
905 fi
906
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100907 case $product in
908 arm) product=module_arm;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100909 x86) product=module_x86;;
910 arm64) product=module_arm64;;
911 x86_64) product=module_x86_64;;
912 esac
913 if [ -z "$variant" ]; then
914 variant=eng
915 fi
916
917 export TARGET_PRODUCT=$product
918 export TARGET_BUILD_VARIANT=$variant
919 export TARGET_BUILD_DENSITY=alldpi
920 export TARGET_BUILD_TYPE=release
921
922 # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use
923 # case is different and it may diverge in the future.
924 export TARGET_BUILD_APPS=$apps
925
926 build_build_var_cache
927 set_stuff_for_environment
928 printconfig
929 destroy_build_var_cache
930}
931
Matt Alexanderd9c56562020-05-21 10:49:17 +0000932function gettop
933{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700934 local TOPFILE=build/make/core/envsetup.mk
Matt Alexanderd9c56562020-05-21 10:49:17 +0000935 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700936 # The following circumlocution ensures we remove symlinks from TOP.
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000937 (cd "$TOP"; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700938 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000939 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800940 # The following circumlocution (repeated below as well) ensures
941 # that we record the true directory name and not one that is
942 # faked up with symlink names.
943 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700944 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800945 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700946 local T=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000947 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800948 \cd ..
synergyb112a402013-07-05 19:47:47 -0700949 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700950 done
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000951 \cd "$HERE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700952 if [ -f "$T/$TOPFILE" ]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000953 echo "$T"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700954 fi
955 fi
956 fi
957}
958
Matt Alexanderd9c56562020-05-21 10:49:17 +0000959function croot()
960{
Christopher Ferris55257d22017-03-23 11:08:58 -0700961 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700962 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700963 if [ "$1" ]; then
964 \cd $(gettop)/$1
965 else
966 \cd $(gettop)
967 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700968 else
969 echo "Couldn't locate the top of the tree. Try setting TOP."
970 fi
971}
972
Matt Alexanderd9c56562020-05-21 10:49:17 +0000973function _croot()
974{
Anton Hanssonece9c482019-02-04 18:15:39 +0000975 local T=$(gettop)
976 if [ "$T" ]; then
977 local cur="${COMP_WORDS[COMP_CWORD]}"
978 k=0
979 for c in $(compgen -d ${T}/${cur}); do
980 COMPREPLY[k++]=${c#${T}/}/
981 done
982 fi
983}
984
Matt Alexanderd9c56562020-05-21 10:49:17 +0000985function cproj()
986{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700987 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700988 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700989 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700990 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
991 T=$PWD
992 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800993 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700994 return
995 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800996 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700997 done
Ying Wang9cd17642012-12-13 10:52:07 -0800998 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700999 echo "can't find Android.mk"
1000}
1001
Daniel Sandler47e0a882013-07-30 13:23:52 -04001002# simplified version of ps; output in the form
1003# <pid> <procname>
1004function qpid() {
1005 local prepend=''
1006 local append=''
Matt Alexanderd9c56562020-05-21 10:49:17 +00001007 if [ "$1" = "--exact" ]; then
Daniel Sandler47e0a882013-07-30 13:23:52 -04001008 prepend=' '
1009 append='$'
1010 shift
Matt Alexanderd9c56562020-05-21 10:49:17 +00001011 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001012 echo "usage: qpid [[--exact] <process name|pid>"
1013 return 255
1014 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001015
1016 local EXE="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001017 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001018 qpid | \grep "$prepend$EXE$append"
1019 else
1020 adb shell ps \
1021 | tr -d '\r' \
1022 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1023 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001024}
1025
Steven Moreland74114f12020-09-10 01:23:32 +00001026# syswrite - disable verity, reboot if needed, and remount image
1027#
1028# Easy way to make system.img/etc writable
1029function syswrite() {
1030 adb wait-for-device && adb root || return 1
1031 if [[ $(adb disable-verity | grep "reboot") ]]; then
1032 echo "rebooting"
1033 adb reboot && adb wait-for-device && adb root || return 1
1034 fi
1035 adb wait-for-device && adb remount || return 1
1036}
1037
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001038# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001039# that has the core-file-size limit set correctly
1040#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001041# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001042# if its core-file-size limit is not set already.
1043# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1044
Matt Alexanderd9c56562020-05-21 10:49:17 +00001045function coredump_setup()
1046{
1047 echo "Getting root...";
1048 adb root;
1049 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001050
Matt Alexanderd9c56562020-05-21 10:49:17 +00001051 echo "Remounting root partition read-write...";
1052 adb shell mount -w -o remount -t rootfs rootfs;
1053 sleep 1;
1054 adb wait-for-device;
1055 adb shell mkdir -p /cores;
1056 adb shell mount -t tmpfs tmpfs /cores;
1057 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001058
Matt Alexanderd9c56562020-05-21 10:49:17 +00001059 echo "Granting SELinux permission to dump in /cores...";
1060 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001061
Matt Alexanderd9c56562020-05-21 10:49:17 +00001062 echo "Set core pattern.";
1063 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001064
Ying Wang08800fd2016-03-03 20:57:21 -08001065 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001066}
1067
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001068# coredump_enable - enable core dumps for the specified process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001069# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001070#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001071# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001072# dump to actually be generated.
1073
Matt Alexanderd9c56562020-05-21 10:49:17 +00001074function coredump_enable()
1075{
1076 local PID=$1;
Ying Wang08800fd2016-03-03 20:57:21 -08001077 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001078 printf "Expecting a PID!\n";
1079 return;
1080 fi;
1081 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001082 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001083}
1084
1085# core - send SIGV and pull the core for process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001086# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001087#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001088# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001089# enabled globally.
1090
Matt Alexanderd9c56562020-05-21 10:49:17 +00001091function core()
1092{
1093 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001094
Ying Wang08800fd2016-03-03 20:57:21 -08001095 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001096 printf "Expecting a PID!\n";
1097 return;
1098 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001099
Matt Alexanderd9c56562020-05-21 10:49:17 +00001100 local CORENAME=core.$PID;
1101 local COREPATH=/cores/$CORENAME;
1102 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001103
Matt Alexanderd9c56562020-05-21 10:49:17 +00001104 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001105
Matt Alexanderd9c56562020-05-21 10:49:17 +00001106 local done=0;
Ying Wang08800fd2016-03-03 20:57:21 -08001107 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
Matt Alexanderd9c56562020-05-21 10:49:17 +00001108 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1109 adb shell kill -$SIG $PID;
1110 sleep 1;
1111 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001112
Matt Alexanderd9c56562020-05-21 10:49:17 +00001113 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1114 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001115}
1116
Christopher Tate744ee802009-11-12 15:33:08 -08001117# systemstack - dump the current stack trace of all threads in the system process
1118# to the usual ANR traces file
Matt Alexanderd9c56562020-05-21 10:49:17 +00001119function systemstack()
1120{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001121 stacks system_server
1122}
1123
Michael Wrightaeed7212014-06-19 19:58:12 -07001124# Read the ELF header from /proc/$PID/exe to determine if the process is
1125# 64-bit.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001126function is64bit()
1127{
Ben Chengfba67bf2014-02-25 10:27:07 -08001128 local PID="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001129 if [ "$PID" ] ; then
1130 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001131 echo "64"
1132 else
1133 echo ""
1134 fi
1135 else
1136 echo ""
1137 fi
1138}
1139
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001140case `uname -s` in
1141 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001142 function sgrep()
1143 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001144 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 -04001145 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001146 }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001147
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001148 ;;
1149 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001150 function sgrep()
1151 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001152 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 -04001153 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001154 }
1155 ;;
1156esac
1157
Matt Alexanderd9c56562020-05-21 10:49:17 +00001158function gettargetarch
1159{
Raghu Gandham8da43102012-07-25 19:57:22 -07001160 get_build_var TARGET_ARCH
1161}
1162
Matt Alexanderd9c56562020-05-21 10:49:17 +00001163function ggrep()
1164{
Mike Frysinger5e479732015-09-22 18:13:48 -04001165 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1166 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001167}
1168
Matt Alexanderd9c56562020-05-21 10:49:17 +00001169function gogrep()
1170{
Orion Hodson831472d2019-10-25 11:35:15 +01001171 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
1172 -exec grep --color -n "$@" {} +
1173}
1174
Matt Alexanderd9c56562020-05-21 10:49:17 +00001175function jgrep()
1176{
Mike Frysinger5e479732015-09-22 18:13:48 -04001177 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1178 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001179}
1180
Alistair Delva176e5342021-02-22 13:31:26 -08001181function rsgrep()
Jeff Vander Stoep1431ab82021-02-02 19:18:26 +01001182{
1183 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rs" \
1184 -exec grep --color -n "$@" {} +
1185}
1186
Taesu Leeea0cecd2020-10-28 11:05:18 +09001187function ktgrep()
1188{
1189 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.kt" \
1190 -exec grep --color -n "$@" {} +
1191}
1192
Matt Alexanderd9c56562020-05-21 10:49:17 +00001193function cgrep()
1194{
Mike Frysinger5e479732015-09-22 18:13:48 -04001195 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' \) \
1196 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001197}
1198
Matt Alexanderd9c56562020-05-21 10:49:17 +00001199function resgrep()
1200{
Christopher Ferris55257d22017-03-23 11:08:58 -07001201 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001202 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1203 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1204 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001205}
1206
Matt Alexanderd9c56562020-05-21 10:49:17 +00001207function mangrep()
1208{
Mike Frysinger5e479732015-09-22 18:13:48 -04001209 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1210 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001211}
1212
Matt Alexanderd9c56562020-05-21 10:49:17 +00001213function owngrep()
1214{
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -06001215 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
1216 -exec grep --color -n "$@" {} +
1217}
1218
Matt Alexanderd9c56562020-05-21 10:49:17 +00001219function sepgrep()
1220{
Mike Frysinger5e479732015-09-22 18:13:48 -04001221 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1222 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001223}
1224
Matt Alexanderd9c56562020-05-21 10:49:17 +00001225function rcgrep()
1226{
Mike Frysinger5e479732015-09-22 18:13:48 -04001227 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1228 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001229}
1230
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001231case `uname -s` in
1232 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001233 function mgrep()
1234 {
Orion Hodson831472d2019-10-25 11:35:15 +01001235 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 -04001236 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001237 }
1238
Matt Alexanderd9c56562020-05-21 10:49:17 +00001239 function treegrep()
1240 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001241 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 -04001242 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001243 }
1244
1245 ;;
1246 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001247 function mgrep()
1248 {
Orion Hodson831472d2019-10-25 11:35:15 +01001249 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 -04001250 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001251 }
1252
Matt Alexanderd9c56562020-05-21 10:49:17 +00001253 function treegrep()
1254 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001255 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 -04001256 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001257 }
1258
1259 ;;
1260esac
1261
Matt Alexanderd9c56562020-05-21 10:49:17 +00001262function getprebuilt
1263{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001264 get_abs_build_var ANDROID_PREBUILTS
1265}
1266
Matt Alexanderd9c56562020-05-21 10:49:17 +00001267function tracedmdump()
1268{
Christopher Ferris55257d22017-03-23 11:08:58 -07001269 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001270 if [ ! "$T" ]; then
1271 echo "Couldn't locate the top of the tree. Try setting TOP."
1272 return
1273 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001274 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001275 local arch=$(gettargetarch)
1276 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001277
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001278 local TRACE=$1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001279 if [ ! "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001280 echo "usage: tracedmdump tracename"
1281 return
1282 fi
1283
Matt Alexanderd9c56562020-05-21 10:49:17 +00001284 if [ ! -r "$KERNEL" ] ; then
Jack Veenstra60116fc2009-04-09 18:12:34 -07001285 echo "Error: cannot find kernel: '$KERNEL'"
1286 return
1287 fi
1288
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001289 local BASETRACE=$(basename $TRACE)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001290 if [ "$BASETRACE" = "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001291 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1292 fi
1293
1294 echo "post-processing traces..."
1295 rm -f $TRACE/qtrace.dexlist
1296 post_trace $TRACE
1297 if [ $? -ne 0 ]; then
1298 echo "***"
1299 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1300 echo "***"
1301 return
1302 fi
1303 echo "generating dexlist output..."
1304 /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
1305 echo "generating dmtrace data..."
1306 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1307 echo "generating html file..."
1308 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1309 echo "done, see $TRACE/dmtrace.html for details"
1310 echo "or run:"
1311 echo " traceview $TRACE/dmtrace"
1312}
1313
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001314# communicate with a running device or emulator, set up necessary state,
1315# and run the hat command.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001316function runhat()
1317{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001318 # process standard adb options
1319 local adbTarget=""
Matt Alexanderd9c56562020-05-21 10:49:17 +00001320 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001321 adbTarget=$1
1322 shift 1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001323 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001324 adbTarget="$1 $2"
1325 shift 2
1326 fi
1327 local adbOptions=${adbTarget}
Matt Alexanderd9c56562020-05-21 10:49:17 +00001328 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001329
1330 # runhat options
1331 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001332
Matt Alexanderd9c56562020-05-21 10:49:17 +00001333 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001334 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001335 return
1336 fi
1337
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001338 # confirm hat is available
1339 if [ -z $(which hat) ]; then
1340 echo "hat is not available in this configuration."
1341 return
1342 fi
1343
Andy McFaddenb6289852010-07-12 08:00:19 -07001344 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001345 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001346 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001347 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001348 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001349 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001350 echo -n "> "
1351 read
1352
The Android Open Source Project88b60792009-03-03 19:28:42 -08001353 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001354
The Android Open Source Project88b60792009-03-03 19:28:42 -08001355 echo "Retrieving file $devFile..."
1356 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001357
The Android Open Source Project88b60792009-03-03 19:28:42 -08001358 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001359
The Android Open Source Project88b60792009-03-03 19:28:42 -08001360 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001361 echo "View the output by pointing your browser at http://localhost:7000/"
1362 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001363 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001364}
1365
Matt Alexanderd9c56562020-05-21 10:49:17 +00001366function getbugreports()
1367{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001368 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001369
1370 if [ ! "$reports" ]; then
1371 echo "Could not locate any bugreports."
1372 return
1373 fi
1374
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001375 local report
1376 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001377 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001378 echo "/sdcard/bugreports/${report}"
1379 adb pull /sdcard/bugreports/${report} ${report}
1380 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001381 done
1382}
1383
Matt Alexanderd9c56562020-05-21 10:49:17 +00001384function getsdcardpath()
1385{
Victoria Lease1b296b42012-08-21 15:44:06 -07001386 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1387}
1388
Matt Alexanderd9c56562020-05-21 10:49:17 +00001389function getscreenshotpath()
1390{
Victoria Lease1b296b42012-08-21 15:44:06 -07001391 echo "$(getsdcardpath)/Pictures/Screenshots"
1392}
1393
Matt Alexanderd9c56562020-05-21 10:49:17 +00001394function getlastscreenshot()
1395{
Victoria Lease1b296b42012-08-21 15:44:06 -07001396 local screenshot_path=$(getscreenshotpath)
1397 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 +00001398 if [ "$screenshot" = "" ]; then
Victoria Lease1b296b42012-08-21 15:44:06 -07001399 echo "No screenshots found."
1400 return
1401 fi
1402 echo "${screenshot}"
1403 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1404}
1405
Matt Alexanderd9c56562020-05-21 10:49:17 +00001406function startviewserver()
1407{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001408 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001409 if [ $# -gt 0 ]; then
1410 port=$1
1411 fi
1412 adb shell service call window 1 i32 $port
1413}
1414
Matt Alexanderd9c56562020-05-21 10:49:17 +00001415function stopviewserver()
1416{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001417 adb shell service call window 2
1418}
1419
Matt Alexanderd9c56562020-05-21 10:49:17 +00001420function isviewserverstarted()
1421{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001422 adb shell service call window 3
1423}
1424
Matt Alexanderd9c56562020-05-21 10:49:17 +00001425function key_home()
1426{
Romain Guyb84049a2010-10-04 16:56:11 -07001427 adb shell input keyevent 3
1428}
1429
Matt Alexanderd9c56562020-05-21 10:49:17 +00001430function key_back()
1431{
Romain Guyb84049a2010-10-04 16:56:11 -07001432 adb shell input keyevent 4
1433}
1434
Matt Alexanderd9c56562020-05-21 10:49:17 +00001435function key_menu()
1436{
Romain Guyb84049a2010-10-04 16:56:11 -07001437 adb shell input keyevent 82
1438}
1439
Matt Alexanderd9c56562020-05-21 10:49:17 +00001440function smoketest()
1441{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001442 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1443 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1444 return
1445 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001446 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001447 if [ ! "$T" ]; then
1448 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1449 return
1450 fi
1451
Ying Wang9cd17642012-12-13 10:52:07 -08001452 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001453 adb uninstall com.android.smoketest > /dev/null &&
1454 adb uninstall com.android.smoketest.tests > /dev/null &&
1455 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1456 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1457 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1458}
1459
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001460# simple shortcut to the runtest command
Matt Alexanderd9c56562020-05-21 10:49:17 +00001461function runtest()
1462{
Christopher Ferris55257d22017-03-23 11:08:58 -07001463 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001464 if [ ! "$T" ]; then
1465 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1466 return
1467 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001468 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001469}
1470
The Android Open Source Project88b60792009-03-03 19:28:42 -08001471function godir () {
1472 if [[ -z "$1" ]]; then
1473 echo "Usage: godir <regex>"
1474 return
1475 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001476 local T=$(gettop)
1477 local FILELIST
Matt Alexanderd9c56562020-05-21 10:49:17 +00001478 if [ ! "$OUT_DIR" = "" ]; then
Brian Carlstromf2257422015-09-30 20:28:54 -07001479 mkdir -p $OUT_DIR
1480 FILELIST=$OUT_DIR/filelist
1481 else
1482 FILELIST=$T/filelist
1483 fi
1484 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001485 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001486 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001487 echo " Done"
1488 echo ""
1489 fi
1490 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001491 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
Matt Alexanderd9c56562020-05-21 10:49:17 +00001492 if [[ ${#lines[@]} = 0 ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001493 echo "Not found"
1494 return
1495 fi
1496 local pathname
1497 local choice
1498 if [[ ${#lines[@]} > 1 ]]; then
1499 while [[ -z "$pathname" ]]; do
1500 local index=1
1501 local line
1502 for line in ${lines[@]}; do
1503 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001504 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001505 done
1506 echo
1507 echo -n "Select one: "
1508 unset choice
1509 read choice
1510 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1511 echo "Invalid choice"
1512 continue
1513 fi
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001514 pathname=${lines[@]:$(($choice-1)):1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001515 done
1516 else
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001517 pathname=${lines[@]:0:1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001518 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001519 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001520}
1521
Steven Moreland62054a42018-12-06 10:11:40 -08001522# Update module-info.json in out.
1523function refreshmod() {
1524 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1525 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1526 return 1
1527 fi
1528
1529 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1530
1531 # for the output of the next command
1532 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1533
1534 # Note, can't use absolute path because of the way make works.
Alessandro Astonec8771be2020-05-10 11:27:57 +02001535 m $(get_build_var PRODUCT_OUT)/module-info.json \
Steven Moreland62054a42018-12-06 10:11:40 -08001536 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1537}
1538
Cole Faust3e192382021-10-25 13:29:15 -07001539# Verifies that module-info.txt exists, returning nonzero if it doesn't.
Cole Faust24c36db2021-01-23 02:39:37 +00001540function verifymodinfo() {
Steven Moreland62054a42018-12-06 10:11:40 -08001541 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001542 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
1543 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1544 fi
Steven Moreland62054a42018-12-06 10:11:40 -08001545 return 1
1546 fi
1547
1548 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001549 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
Cole Faust3e192382021-10-25 13:29:15 -07001550 echo "Could not find module-info.json. Please run 'refreshmod' first." >&2
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001551 fi
1552 return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001553 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001554}
1555
1556# List all modules for the current device, as cached in module-info.json. If any build change is
1557# made and it should be reflected in the output, you should run 'refreshmod' first.
1558function allmod() {
1559 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001560
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001561 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 -08001562}
1563
Joe Onorato2c1aa472021-02-25 16:42:39 -08001564# Get the path of a specific module in the android tree, as cached in module-info.json.
1565# If any build change is made, and it should be reflected in the output, you should run
1566# 'refreshmod' first. Note: This is the inverse of dirmods.
Rett Berg78d1c932019-01-24 14:34:23 -08001567function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001568 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001569 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001570 return 1
1571 fi
1572
Cole Faust24c36db2021-01-23 02:39:37 +00001573 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001574
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001575 local relpath=$(python3 -c "import json, os
Steven Moreland62054a42018-12-06 10:11:40 -08001576module = '$1'
1577module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1578if module not in module_info:
1579 exit(1)
LuK1337b6a78192020-01-12 03:12:17 +01001580print(module_info[module]['path'][0])" 2>/dev/null)
Steven Moreland62054a42018-12-06 10:11:40 -08001581
1582 if [ -z "$relpath" ]; then
1583 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1584 return 1
1585 else
Rett Berg78d1c932019-01-24 14:34:23 -08001586 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001587 fi
1588}
1589
Joe Onorato2c1aa472021-02-25 16:42:39 -08001590# Get the path of a specific module in the android tree, as cached in module-info.json.
1591# If any build change is made, and it should be reflected in the output, you should run
1592# 'refreshmod' first. Note: This is the inverse of pathmod.
1593function dirmods() {
1594 if [[ $# -ne 1 ]]; then
1595 echo "usage: dirmods <path>" >&2
1596 return 1
1597 fi
1598
1599 verifymodinfo || return 1
1600
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001601 python3 -c "import json, os
Joe Onorato2c1aa472021-02-25 16:42:39 -08001602dir = '$1'
1603while dir.endswith('/'):
1604 dir = dir[:-1]
1605prefix = dir + '/'
1606module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1607results = set()
1608for m in module_info.values():
1609 for path in m.get(u'path', []):
1610 if path == dir or path.startswith(prefix):
1611 name = m.get(u'module_name')
1612 if name:
1613 results.add(name)
1614for name in sorted(results):
1615 print(name)
1616"
1617}
1618
1619
Rett Berg78d1c932019-01-24 14:34:23 -08001620# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1621# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1622function gomod() {
1623 if [[ $# -ne 1 ]]; then
1624 echo "usage: gomod <module>" >&2
1625 return 1
1626 fi
1627
1628 local path="$(pathmod $@)"
1629 if [ -z "$path" ]; then
1630 return 1
1631 fi
1632 cd $path
1633}
1634
Cole Faust24c36db2021-01-23 02:39:37 +00001635# Gets the list of a module's installed outputs, as cached in module-info.json.
1636# If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first.
1637function outmod() {
1638 if [[ $# -ne 1 ]]; then
1639 echo "usage: outmod <module>" >&2
1640 return 1
1641 fi
1642
1643 verifymodinfo || return 1
1644
1645 local relpath
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001646 relpath=$(python3 -c "import json, os
Cole Faust24c36db2021-01-23 02:39:37 +00001647module = '$1'
1648module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1649if module not in module_info:
1650 exit(1)
1651for output in module_info[module]['installed']:
1652 print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null)
1653
1654 if [ $? -ne 0 ]; then
1655 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2
1656 return 1
1657 elif [ ! -z "$relpath" ]; then
1658 echo "$relpath"
1659 fi
1660}
1661
1662# adb install a module's apk, as cached in module-info.json. If any build change
1663# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1664# Usage: installmod [adb install arguments] <module>
1665# For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk
1666function installmod() {
1667 if [[ $# -eq 0 ]]; then
1668 echo "usage: installmod [adb install arguments] <module>" >&2
Cole Faust3e192382021-10-25 13:29:15 -07001669 echo "" >&2
1670 echo "Only flags to be passed after the \"install\" in adb install are supported," >&2
1671 echo "with the exception of -s. If -s is passed it will be placed before the \"install\"." >&2
1672 echo "-s must be the first flag passed if it exists." >&2
Cole Faust24c36db2021-01-23 02:39:37 +00001673 return 1
1674 fi
1675
1676 local _path
1677 _path=$(outmod ${@:$#:1})
1678 if [ $? -ne 0 ]; then
1679 return 1
1680 fi
1681
1682 _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1)
1683 if [ -z "$_path" ]; then
1684 echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2
1685 return 1
1686 fi
Cole Faust3e192382021-10-25 13:29:15 -07001687 local serial_device=""
1688 if [[ "$1" == "-s" ]]; then
1689 if [[ $# -le 2 ]]; then
1690 echo "-s requires an argument" >&2
1691 return 1
1692 fi
1693 serial_device="-s $2"
1694 shift 2
1695 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001696 local length=$(( $# - 1 ))
Cole Faust3e192382021-10-25 13:29:15 -07001697 echo adb $serial_device install ${@:1:$length} $_path
1698 adb $serial_device install ${@:1:$length} $_path
Cole Faust24c36db2021-01-23 02:39:37 +00001699}
1700
dimitry73b84812018-12-11 18:06:00 +01001701function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001702 local word=${COMP_WORDS[COMP_CWORD]}
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001703 COMPREPLY=( $(QUIET_VERIFYMODINFO=true allmod | grep -E "^$word") )
Steven Moreland62054a42018-12-06 10:11:40 -08001704}
1705
Alex Rayf0d08eb2013-03-08 15:15:06 -08001706# Print colored exit condition
1707function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001708 "$@"
1709 local retval=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +00001710 if [ $retval -ne 0 ]
1711 then
Jacky Cao89483b82015-05-15 22:12:53 +08001712 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001713 else
Jacky Cao89483b82015-05-15 22:12:53 +08001714 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001715 fi
1716 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001717}
1718
Matt Alexanderd9c56562020-05-21 10:49:17 +00001719function get_make_command()
1720{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001721 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1722 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001723 # Always use the real make if -C is passed in
1724 for arg in "$@"; do
1725 if [[ $arg == -C* ]]; then
1726 echo command make
1727 return
1728 fi
1729 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001730 echo build/soong/soong_ui.bash --make-mode
1731 else
1732 echo command make
1733 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001734}
1735
Matt Alexanderd9c56562020-05-21 10:49:17 +00001736function _wrap_build()
1737{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001738 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1739 "$@"
1740 return $?
1741 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001742 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001743 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001744 local ret=$?
1745 local end_time=$(date +"%s")
1746 local tdiff=$(($end_time-$start_time))
1747 local hours=$(($tdiff / 3600 ))
1748 local mins=$((($tdiff % 3600) / 60))
1749 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001750 local ncolors=$(tput colors 2>/dev/null)
1751 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001752 color_failed=$'\E'"[0;31m"
1753 color_success=$'\E'"[0;32m"
Kousik Kumar09af2542021-08-19 16:13:32 -04001754 color_warning=$'\E'"[0;33m"
Jacky Cao89483b82015-05-15 22:12:53 +08001755 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001756 else
1757 color_failed=""
1758 color_success=""
1759 color_reset=""
1760 fi
Kousik Kumar09af2542021-08-19 16:13:32 -04001761
1762 if [[ "x${USE_RBE}" == "x" && $mins -gt 15 && "${ANDROID_BUILD_ENVIRONMENT_CONFIG}" == "googler" ]]; then
1763 echo
1764 echo "${color_warning}Start using RBE (http://go/build-fast) to get faster builds!${color_reset}"
1765 fi
1766
Ed Heylcc6be0a2014-06-18 14:55:58 -07001767 echo
Matt Alexanderd9c56562020-05-21 10:49:17 +00001768 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001769 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001770 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001771 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001772 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +00001773 if [ $hours -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001774 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001775 elif [ $mins -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001776 printf "(%02g:%02g (mm:ss))" $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001777 elif [ $secs -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001778 printf "(%s seconds)" $secs
1779 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001780 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001781 echo
1782 return $ret
1783}
1784
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001785function _trigger_build()
1786(
1787 local -r bc="$1"; shift
1788 if T="$(gettop)"; then
1789 _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
1790 else
Jingwen Chend728ee12021-05-18 06:02:53 +00001791 >&2 echo "Couldn't locate the top of the tree. Try setting TOP."
1792 return 1
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001793 fi
1794)
1795
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001796# Convenience entry point (like m) to use Bazel in AOSP.
Jingwen Chend728ee12021-05-18 06:02:53 +00001797function b()
1798(
1799 # Generate BUILD, bzl files into the synthetic Bazel workspace (out/soong/workspace).
Sam Delmerico9d67a902022-04-11 12:25:18 +00001800 _trigger_build "all-modules" bp2build USE_BAZEL_ANALYSIS= || return 1
Jingwen Chend728ee12021-05-18 06:02:53 +00001801 # Then, run Bazel using the synthetic workspace as the --package_path.
Sam Delmerico9d67a902022-04-11 12:25:18 +00001802 if [[ -z "$@" ]]; then
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001803 # If there are no args, show help.
Jingwen Chenbfa114d2021-06-17 05:42:43 +00001804 bazel help
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001805 else
1806 # Else, always run with the bp2build configuration, which sets Bazel's package path to the synthetic workspace.
Sam Delmerico9d67a902022-04-11 12:25:18 +00001807 bazel "$@" --config=bp2build
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001808 fi
Jingwen Chend728ee12021-05-18 06:02:53 +00001809)
1810
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001811function m()
1812(
1813 _trigger_build "all-modules" "$@"
1814)
1815
1816function mm()
1817(
1818 _trigger_build "modules-in-a-dir-no-deps" "$@"
1819)
1820
1821function mmm()
1822(
1823 _trigger_build "modules-in-dirs-no-deps" "$@"
1824)
1825
1826function mma()
1827(
1828 _trigger_build "modules-in-a-dir" "$@"
1829)
1830
1831function mmma()
1832(
1833 _trigger_build "modules-in-dirs" "$@"
1834)
1835
Matt Alexanderd9c56562020-05-21 10:49:17 +00001836function make()
1837{
Dan Willemsene9842242017-07-28 13:00:13 -07001838 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001839}
1840
Matt Alexanderd9c56562020-05-21 10:49:17 +00001841function provision()
1842{
David Zeuthen1b126ff2015-09-30 17:10:48 -04001843 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1844 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1845 return 1
1846 fi
1847 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1848 echo "There is no provisioning script for the device." >&2
1849 return 1
1850 fi
1851
1852 # Check if user really wants to do this.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001853 if [ "$1" = "--no-confirmation" ]; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001854 shift 1
1855 else
1856 echo "This action will reflash your device."
1857 echo ""
1858 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1859 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001860 echo -n "Are you sure you want to do this (yes/no)? "
1861 read
Matt Alexanderd9c56562020-05-21 10:49:17 +00001862 if [[ "${REPLY}" != "yes" ]] ; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001863 echo "Not taking any action. Exiting." >&2
1864 return 1
1865 fi
1866 fi
1867 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1868}
1869
Jim Tanga881a252018-06-19 16:34:41 +08001870# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001871function enable_zsh_completion() {
1872 # Don't override user's options if bash-style completion is already enabled.
1873 if ! declare -f complete >/dev/null; then
1874 autoload -U compinit && compinit
1875 autoload -U bashcompinit && bashcompinit
1876 fi
Jim Tanga881a252018-06-19 16:34:41 +08001877}
1878
1879function validate_current_shell() {
1880 local current_sh="$(ps -o command -p $$)"
1881 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001882 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001883 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001884 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001885 *zsh*)
1886 function check_type() { type "$1"; }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001887 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001888 *)
Jim Tanga881a252018-06-19 16:34:41 +08001889 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 -07001890 ;;
1891 esac
Jim Tanga881a252018-06-19 16:34:41 +08001892}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001893
1894# Execute the contents of any vendorsetup.sh files we can find.
Dan Willemsend855a722019-02-12 15:52:36 -08001895# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
1896# load those.
1897#
1898# This allows loading only approved vendorsetup.sh files
Jim Tanga881a252018-06-19 16:34:41 +08001899function source_vendorsetup() {
Jim Tangc4dba1d2019-07-25 16:54:27 +08001900 unset VENDOR_PYTHONPATH
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001901 local T="$(gettop)"
Dan Willemsend855a722019-02-12 15:52:36 -08001902 allowed=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001903 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 -08001904 if [ -n "$allowed" ]; then
1905 echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
1906 echo " $allowed"
1907 echo " $f"
1908 return
1909 fi
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001910 allowed="$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001911 done
1912
1913 allowed_files=
1914 [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
Jim Tanga881a252018-06-19 16:34:41 +08001915 for dir in device vendor product; do
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001916 for f in $(cd "$T" && test -d $dir && \
Jim Tanga881a252018-06-19 16:34:41 +08001917 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001918
1919 if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001920 echo "including $f"; . "$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001921 else
1922 echo "ignoring $f, not in $allowed"
1923 fi
Jim Tanga881a252018-06-19 16:34:41 +08001924 done
1925 done
1926}
Kenny Root52aa81c2011-07-15 11:07:06 -07001927
Dan Albertbab814f2020-08-26 15:34:53 -07001928function showcommands() {
1929 local T=$(gettop)
1930 if [[ -z "$TARGET_PRODUCT" ]]; then
1931 >&2 echo "TARGET_PRODUCT not set. Run lunch."
1932 return
1933 fi
1934 case $(uname -s) in
1935 Darwin)
1936 PREBUILT_NAME=darwin-x86
1937 ;;
1938 Linux)
1939 PREBUILT_NAME=linux-x86
1940 ;;
1941 *)
1942 >&2 echo Unknown host $(uname -s)
1943 return
1944 ;;
1945 esac
1946 if [[ -z "$OUT_DIR" ]]; then
1947 if [[ -z "$OUT_DIR_COMMON_BASE" ]]; then
1948 OUT_DIR=out
1949 else
1950 OUT_DIR=${OUT_DIR_COMMON_BASE}/${PWD##*/}
1951 fi
1952 fi
1953 if [[ "$1" == "--regenerate" ]]; then
1954 shift 1
1955 NINJA_ARGS="-t commands $@" m
1956 else
1957 (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \
1958 -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \
1959 -t commands "$@")
1960 fi
1961}
1962
Jim Tanga881a252018-06-19 16:34:41 +08001963validate_current_shell
1964source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001965addcompletions