blob: 4c1aeaac608d2dda011dfb381ad137d731371bb3 [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).
Anton Hansson90ac61c2022-09-06 14:36:00 +000013- banchan: banchan <module1> [<module2> ...] [arm|x86|arm64|x86_64|arm64_only|x86_64only] \
14 [eng|userdebug|user]
Martin Stjernholmf692c752021-04-12 00:01:10 +010015 Sets up the build environment for building unbundled modules (APEXes).
Anton Hanssonece9c482019-02-04 18:15:39 +000016- croot: Changes directory to the top of the tree, or a subdirectory thereof.
Steven Moreland62054a42018-12-06 10:11:40 -080017- m: Makes from the top of the tree.
Dan Willemsen67074fe2019-10-30 12:35:34 -070018- mm: Builds and installs all of the modules in the current directory, and their
19 dependencies.
20- mmm: Builds and installs all of the modules in the supplied directories, and their
21 dependencies.
Steven Moreland62054a42018-12-06 10:11:40 -080022 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Dan Willemsen67074fe2019-10-30 12:35:34 -070023- mma: Same as 'mm'
24- mmma: Same as 'mmm'
Steven Moreland62054a42018-12-06 10:11:40 -080025- provision: Flash device with all required partitions. Options will be passed on to fastboot.
26- cgrep: Greps on all local C/C++ files.
27- ggrep: Greps on all local Gradle files.
Orion Hodson831472d2019-10-25 11:35:15 +010028- gogrep: Greps on all local Go files.
Steven Moreland62054a42018-12-06 10:11:40 -080029- jgrep: Greps on all local Java files.
Taesu Leeea0cecd2020-10-28 11:05:18 +090030- ktgrep: Greps on all local Kotlin files.
Steven Moreland62054a42018-12-06 10:11:40 -080031- resgrep: Greps on all local res/*.xml files.
32- mangrep: Greps on all local AndroidManifest.xml files.
Jaewoong Jung892d0fe2019-05-04 10:06:28 -070033- mgrep: Greps on all local Makefiles and *.bp files.
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -060034- owngrep: Greps on all local OWNERS files.
Alistair Delva176e5342021-02-22 13:31:26 -080035- rsgrep: Greps on all local Rust files.
Steven Moreland62054a42018-12-06 10:11:40 -080036- sepgrep: Greps on all local sepolicy files.
37- sgrep: Greps on all local source files.
38- godir: Go to the directory containing a file.
39- allmod: List all modules.
40- gomod: Go to the directory containing a module.
Jingwen Chen83eeebb2022-10-05 02:27:07 +000041- bmod: Get the Bazel label of a Soong module if it is converted with bp2build.
Rett Berg78d1c932019-01-24 14:34:23 -080042- pathmod: Get the directory containing a module.
Cole Faust24c36db2021-01-23 02:39:37 +000043- outmod: Gets the location of a module's installed outputs with a certain extension.
Joe Onorato2c1aa472021-02-25 16:42:39 -080044- dirmods: Gets the modules defined in a given directory.
Cole Faust24c36db2021-01-23 02:39:37 +000045- installmod: Adb installs a module's built APK.
46- refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod.
Steven Moreland74114f12020-09-10 01:23:32 +000047- syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070048
Roland Levillain39341922015-10-20 12:48:19 +010049Environment options:
Steven Moreland115d1f52019-09-26 16:30:28 -070050- SANITIZE_HOST: Set to 'address' to use ASAN for all host modules.
Sasha Smundak9f27cc02019-01-31 13:25:31 -080051- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
Dan Albert4ae5d4b2014-10-31 16:23:08 -070052
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070053Look at the source to view more functions. The complete list is:
54EOF
Christopher Ferris55257d22017-03-23 11:08:58 -070055 local T=$(gettop)
56 local A=""
57 local i
Jacky Cao89483b82015-05-15 22:12:53 +080058 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 -070059 A="$A $i"
60 done
61 echo $A
62}
63
Ying Wang08800fd2016-03-03 20:57:21 -080064# Get all the build variables needed by this script in a single call to the build system.
Matt Alexanderd9c56562020-05-21 10:49:17 +000065function build_build_var_cache()
66{
Christopher Ferris55257d22017-03-23 11:08:58 -070067 local T=$(gettop)
Ying Wang08800fd2016-03-03 20:57:21 -080068 # Grep out the variable names from the script.
Jim Tanga881a252018-06-19 16:34:41 +080069 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' ' '`)
70 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 -080071 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
Steven Moreland05402962018-01-05 12:13:11 -080072 build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
Jim Tanga881a252018-06-19 16:34:41 +080073 --vars="${cached_vars[*]}" \
74 --abs-vars="${cached_abs_vars[*]}" \
Dan Willemsenaf88c412017-07-14 11:29:44 -070075 --var-prefix=var_cache_ \
76 --abs-var-prefix=abs_var_cache_`
Ying Wang08800fd2016-03-03 20:57:21 -080077 local ret=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +000078 if [ $ret -ne 0 ]
79 then
Ying Wang08800fd2016-03-03 20:57:21 -080080 unset build_dicts_script
81 return $ret
82 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -070083 # Execute the script to store the "<val>=<value>" pairs as shell variables.
Ying Wang08800fd2016-03-03 20:57:21 -080084 eval "$build_dicts_script"
Ying Wang08800fd2016-03-03 20:57:21 -080085 ret=$?
Ying Wangf0cb3972016-03-04 13:56:23 -080086 unset build_dicts_script
Matt Alexanderd9c56562020-05-21 10:49:17 +000087 if [ $ret -ne 0 ]
88 then
Ying Wang08800fd2016-03-03 20:57:21 -080089 return $ret
90 fi
91 BUILD_VAR_CACHE_READY="true"
92}
93
Ying Wangf0cb3972016-03-04 13:56:23 -080094# Delete the build var cache, so that we can still call into the build system
Ying Wang08800fd2016-03-03 20:57:21 -080095# to get build variables not listed in this script.
Matt Alexanderd9c56562020-05-21 10:49:17 +000096function destroy_build_var_cache()
97{
Ying Wang08800fd2016-03-03 20:57:21 -080098 unset BUILD_VAR_CACHE_READY
Christopher Ferris55257d22017-03-23 11:08:58 -070099 local v
Ying Wang08800fd2016-03-03 20:57:21 -0800100 for v in $cached_vars; do
101 unset var_cache_$v
102 done
103 unset cached_vars
104 for v in $cached_abs_vars; do
105 unset abs_var_cache_$v
106 done
107 unset cached_abs_vars
108}
109
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700110# Get the value of a build variable as an absolute path.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000111function get_abs_build_var()
112{
113 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
114 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800115 eval "echo \"\${abs_var_cache_$1}\""
Timi0469c3f2021-04-15 16:41:18 +0200116 return
Ying Wang08800fd2016-03-03 20:57:21 -0800117 fi
118
Christopher Ferris55257d22017-03-23 11:08:58 -0700119 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700120 if [ ! "$T" ]; then
121 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
122 return
123 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700124 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700125}
126
127# Get the exact value of a build variable.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000128function get_build_var()
129{
130 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
131 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800132 eval "echo \"\${var_cache_$1}\""
Roland Levillain23c46cf2020-03-31 16:11:05 +0100133 return 0
Ying Wang08800fd2016-03-03 20:57:21 -0800134 fi
135
Christopher Ferris55257d22017-03-23 11:08:58 -0700136 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700137 if [ ! "$T" ]; then
138 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
Roland Levillain23c46cf2020-03-31 16:11:05 +0100139 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700140 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700141 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800142}
143
144# check to see if the supplied product is one we can build
Matt Alexanderd9c56562020-05-21 10:49:17 +0000145function check_product()
146{
Christopher Ferris55257d22017-03-23 11:08:58 -0700147 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800148 if [ ! "$T" ]; then
149 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
150 return
151 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700152 TARGET_PRODUCT=$1 \
153 TARGET_BUILD_VARIANT= \
154 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700155 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800156 get_build_var TARGET_DEVICE > /dev/null
157 # hide successful answers, but allow the errors to show
158}
159
160VARIANT_CHOICES=(user userdebug eng)
161
162# check to see if the supplied variant is valid
Matt Alexanderd9c56562020-05-21 10:49:17 +0000163function check_variant()
164{
Christopher Ferris55257d22017-03-23 11:08:58 -0700165 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800166 for v in ${VARIANT_CHOICES[@]}
167 do
Matt Alexanderd9c56562020-05-21 10:49:17 +0000168 if [ "$v" = "$1" ]
169 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800170 return 0
171 fi
172 done
173 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700174}
175
Matt Alexanderd9c56562020-05-21 10:49:17 +0000176function setpaths()
177{
Christopher Ferris55257d22017-03-23 11:08:58 -0700178 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700179 if [ ! "$T" ]; then
180 echo "Couldn't locate the top of the tree. Try setting TOP."
181 return
182 fi
183
184 ##################################################################
185 # #
186 # Read me before you modify this code #
187 # #
188 # This function sets ANDROID_BUILD_PATHS to what it is adding #
189 # to PATH, and the next time it is run, it removes that from #
190 # PATH. This is required so lunch can be run more than once #
191 # and still have working paths. #
192 # #
193 ##################################################################
194
Raphael Mollc639c782011-06-20 17:25:01 -0700195 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
196 # due to "C:\Program Files" being in the path.
197
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700198 # out with the old
Matt Alexanderd9c56562020-05-21 10:49:17 +0000199 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700200 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
201 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000202 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700203 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800204 # strip leading ':', if any
205 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500206 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700207
208 # and in with the new
Ben Chengfba67bf2014-02-25 10:27:07 -0800209
Dan Willemsen838dcec2021-09-30 22:40:34 +0000210 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Yueyao Zhuefc786a2017-04-07 14:11:54 -0700211
212 # add kernel specific binaries
213 case $(uname -s) in
214 Linux)
215 export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
216 ;;
217 *)
218 ;;
219 esac
220
Colin Crossc0b01042022-10-05 12:03:03 -0700221 ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS)
Yi Kongdfd00b12019-05-21 16:00:04 -0700222 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS
223
224 # Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS.
225 local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
226 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200227
Stephen Hinesaa8d72c2020-02-04 09:15:18 -0800228 # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds.
229 export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer
230
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200231 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
232 # to ensure that the corresponding 'emulator' binaries are used.
233 case $(uname -s) in
234 Darwin)
235 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
236 ;;
237 Linux)
238 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
239 ;;
240 *)
241 ANDROID_EMULATOR_PREBUILTS=
242 ;;
243 esac
244 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Yi Kongdfd00b12019-05-21 16:00:04 -0700245 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200246 export ANDROID_EMULATOR_PREBUILTS
247 fi
248
Jim Tangb3fda302018-12-22 10:24:55 +0800249 # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
250 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
Ryan Prichard8426a192019-07-15 18:05:29 -0700251 local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch"
252 local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch"
253 local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch"
Martin Stjernholm6a012262021-11-24 14:56:15 +0000254 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH
Jim Tangb3fda302018-12-22 10:24:55 +0800255
Joe Onorato404fde52022-10-24 04:35:48 -0700256 # Build system
257 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$T/build/bazel/bin
258
Martin Stjernholm6a012262021-11-24 14:56:15 +0000259 export ANDROID_BUILD_PATHS=$(tr -s : <<<"${ANDROID_BUILD_PATHS}:")
Ryan Prichard8426a192019-07-15 18:05:29 -0700260 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800261
262 # out with the duplicate old
263 if [ -n $ANDROID_PYTHONPATH ]; then
264 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
265 fi
266 # and in with the new
267 export ANDROID_PYTHONPATH=$T/development/python-packages:
Jim Tangc4dba1d2019-07-25 16:54:27 +0800268 if [ -n $VENDOR_PYTHONPATH ]; then
269 ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
270 fi
Jim Tang22f4c322018-12-17 15:21:53 +0800271 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800272
Colin Crosse97e6932017-06-30 16:01:45 -0700273 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
274 export JAVA_HOME=$ANDROID_JAVA_HOME
275 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
276 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
277 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500278
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800279 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700280 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
281 export OUT=$ANDROID_PRODUCT_OUT
282
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700283 unset ANDROID_HOST_OUT
284 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
285
Jiyong Parkc02b1c42020-11-03 11:06:39 +0900286 unset ANDROID_SOONG_HOST_OUT
287 export ANDROID_SOONG_HOST_OUT=$(get_abs_build_var SOONG_HOST_OUT)
288
Simran Basidd050ed2017-02-13 13:46:48 -0800289 unset ANDROID_HOST_OUT_TESTCASES
290 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
291
292 unset ANDROID_TARGET_OUT_TESTCASES
293 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
294
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800295 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700296 # TODO: fix the path
297 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
298}
299
Matt Alexanderd9c56562020-05-21 10:49:17 +0000300function printconfig()
301{
Christopher Ferris55257d22017-03-23 11:08:58 -0700302 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303 if [ ! "$T" ]; then
304 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
305 return
306 fi
307 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700308}
309
Matt Alexanderd9c56562020-05-21 10:49:17 +0000310function set_stuff_for_environment()
311{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800312 setpaths
313 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700314
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800315 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700316}
317
Matt Alexanderd9c56562020-05-21 10:49:17 +0000318function set_sequence_number()
319{
Colin Cross88737132017-03-21 17:41:03 -0700320 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321}
322
Makoto Onukida971062018-06-18 10:15:19 -0700323# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
324function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800325 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700326 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800327 *:"$cmd":*)
328 return 1
329 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700330 esac
331 return 0
332}
333
Matt Alexanderd9c56562020-05-21 10:49:17 +0000334function addcompletions()
335{
Ben Taitelbaum8c2c9cf2020-09-22 16:45:05 -0700336 local f=
Kenny Root52aa81c2011-07-15 11:07:06 -0700337
Jim Tanga881a252018-06-19 16:34:41 +0800338 # Keep us from trying to run in something that's neither bash nor zsh.
339 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700340 return
341 fi
342
343 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800344 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700345 return
346 fi
347
Jim Tanga881a252018-06-19 16:34:41 +0800348 local completion_files=(
MÃ¥rten Kongstadcb5c73f2022-05-04 14:08:12 +0000349 packages/modules/adb/adb.bash
Jim Tanga881a252018-06-19 16:34:41 +0800350 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800351 tools/asuite/asuite.sh
Chris Parsonsa2972972022-08-31 15:04:38 -0400352 prebuilts/bazel/common/bazel-complete.bash
Jim Tanga881a252018-06-19 16:34:41 +0800353 )
Makoto Onukida971062018-06-18 10:15:19 -0700354 # Completion can be disabled selectively to allow users to use non-standard completion.
355 # e.g.
356 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
357 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Usta Shrestha1433fb32022-05-13 14:49:40 -0400358 local T=$(gettop)
Jim Tanga881a252018-06-19 16:34:41 +0800359 for f in ${completion_files[*]}; do
Usta Shrestha1433fb32022-05-13 14:49:40 -0400360 f="$T/$f"
MÃ¥rten Kongstadcb5c73f2022-05-04 14:08:12 +0000361 if [ ! -f "$f" ]; then
362 echo "Warning: completion file $f not found"
363 elif should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700364 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700365 fi
366 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700367
Matt Alexanderd9c56562020-05-21 10:49:17 +0000368 if should_add_completion bit ; then
Makoto Onukida971062018-06-18 10:15:19 -0700369 complete -C "bit --tab" bit
370 fi
Anton Hanssonece9c482019-02-04 18:15:39 +0000371 if [ -z "$ZSH_VERSION" ]; then
372 # Doesn't work in zsh.
373 complete -o nospace -F _croot croot
Chris Parsonsa2972972022-08-31 15:04:38 -0400374 # TODO(b/244559459): Support b autocompletion for zsh
375 complete -F _bazel__complete -o nospace b
Anton Hanssonece9c482019-02-04 18:15:39 +0000376 fi
Jim Tanga881a252018-06-19 16:34:41 +0800377 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800378
Cole Faust24c36db2021-01-23 02:39:37 +0000379 complete -F _complete_android_module_names pathmod
dimitry73b84812018-12-11 18:06:00 +0100380 complete -F _complete_android_module_names gomod
Cole Faust24c36db2021-01-23 02:39:37 +0000381 complete -F _complete_android_module_names outmod
382 complete -F _complete_android_module_names installmod
Jingwen Chen83eeebb2022-10-05 02:27:07 +0000383 complete -F _complete_android_module_names bmod
dimitry73b84812018-12-11 18:06:00 +0100384 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700385}
386
Joe Onorato824608c2022-04-08 11:06:16 -0700387function multitree_lunch_help()
388{
389 echo "usage: lunch PRODUCT-VARIANT" 1>&2
390 echo " Set up android build environment based on a product short name and variant" 1>&2
391 echo 1>&2
392 echo "lunch COMBO_FILE VARIANT" 1>&2
393 echo " Set up android build environment based on a specific lunch combo file" 1>&2
394 echo " and variant." 1>&2
395 echo 1>&2
396 echo "lunch --print [CONFIG]" 1>&2
397 echo " Print the contents of a configuration. If CONFIG is supplied, that config" 1>&2
398 echo " will be flattened and printed. If CONFIG is not supplied, the currently" 1>&2
399 echo " selected config will be printed. Returns 0 on success or nonzero on error." 1>&2
400 echo 1>&2
401 echo "lunch --list" 1>&2
402 echo " List all possible combo files available in the current tree" 1>&2
403 echo 1>&2
404 echo "lunch --help" 1>&2
405 echo "lunch -h" 1>&2
406 echo " Prints this message." 1>&2
407}
408
409function multitree_lunch()
410{
411 local code
412 local results
LaMont Jonesc39e5022022-06-23 19:09:06 +0000413 # Lunch must be run in the topdir, but this way we get a clear error
414 # message, instead of FileNotFound.
415 local T=$(multitree_gettop)
416 if [ -n "$T" ]; then
LaMont Jones5151ddc2022-10-13 23:05:15 +0000417 "$T/orchestrator/build/orchestrator/core/lunch.py" "$@"
LaMont Jonesc39e5022022-06-23 19:09:06 +0000418 else
419 _multitree_lunch_error
420 return 1
421 fi
Joe Onorato824608c2022-04-08 11:06:16 -0700422 if $(echo "$1" | grep -q '^-') ; then
423 # Calls starting with a -- argument are passed directly and the function
424 # returns with the lunch.py exit code.
Spandan Dasca762052022-09-21 00:08:34 +0000425 "${T}/orchestrator/build/orchestrator/core/lunch.py" "$@"
Joe Onorato824608c2022-04-08 11:06:16 -0700426 code=$?
427 if [[ $code -eq 2 ]] ; then
428 echo 1>&2
429 multitree_lunch_help
430 return $code
431 elif [[ $code -ne 0 ]] ; then
432 return $code
433 fi
434 else
435 # All other calls go through the --lunch variant of lunch.py
Spandan Dasca762052022-09-21 00:08:34 +0000436 results=($(${T}/orchestrator/build/orchestrator/core/lunch.py --lunch "$@"))
Joe Onorato824608c2022-04-08 11:06:16 -0700437 code=$?
438 if [[ $code -eq 2 ]] ; then
439 echo 1>&2
440 multitree_lunch_help
441 return $code
442 elif [[ $code -ne 0 ]] ; then
443 return $code
444 fi
445
446 export TARGET_BUILD_COMBO=${results[0]}
447 export TARGET_BUILD_VARIANT=${results[1]}
448 fi
449}
450
Matt Alexanderd9c56562020-05-21 10:49:17 +0000451function choosetype()
452{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700453 echo "Build type choices are:"
454 echo " 1. release"
455 echo " 2. debug"
456 echo
457
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800458 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700459 DEFAULT_NUM=1
460 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800462 export TARGET_BUILD_TYPE=
463 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700464 while [ -z $TARGET_BUILD_TYPE ]
465 do
466 echo -n "Which would you like? ["$DEFAULT_NUM"] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000467 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800468 read ANSWER
469 else
470 echo $1
471 ANSWER=$1
472 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 case $ANSWER in
474 "")
475 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
476 ;;
477 1)
478 export TARGET_BUILD_TYPE=release
479 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480 release)
481 export TARGET_BUILD_TYPE=release
482 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483 2)
484 export TARGET_BUILD_TYPE=debug
485 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486 debug)
487 export TARGET_BUILD_TYPE=debug
488 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700489 *)
490 echo
491 echo "I didn't understand your response. Please try again."
492 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700493 ;;
494 esac
Matt Alexanderd9c56562020-05-21 10:49:17 +0000495 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800496 break
497 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700498 done
499
Ying Wang08800fd2016-03-03 20:57:21 -0800500 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700501 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800502 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700503}
504
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800505#
506# This function isn't really right: It chooses a TARGET_PRODUCT
507# based on the list of boards. Usually, that gets you something
508# that kinda works with a generic product, but really, you should
509# pick a product by name.
510#
Matt Alexanderd9c56562020-05-21 10:49:17 +0000511function chooseproduct()
512{
Christopher Ferris55257d22017-03-23 11:08:58 -0700513 local default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000514 if [ "x$TARGET_PRODUCT" != x ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700515 default_value=$TARGET_PRODUCT
516 else
Ying Wang0a76df52015-06-08 11:57:26 -0700517 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700518 fi
519
Ying Wang08800fd2016-03-03 20:57:21 -0800520 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521 export TARGET_PRODUCT=
522 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700523 while [ -z "$TARGET_PRODUCT" ]
524 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700525 echo -n "Which product would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000526 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800527 read ANSWER
528 else
529 echo $1
530 ANSWER=$1
531 fi
532
Matt Alexanderd9c56562020-05-21 10:49:17 +0000533 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700534 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800535 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000536 if check_product $ANSWER
537 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800538 export TARGET_PRODUCT=$ANSWER
539 else
540 echo "** Not a valid product: $ANSWER"
541 fi
542 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000543 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800544 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700545 fi
546 done
547
Ying Wang08800fd2016-03-03 20:57:21 -0800548 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700549 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800550 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700551}
552
Matt Alexanderd9c56562020-05-21 10:49:17 +0000553function choosevariant()
554{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800555 echo "Variant choices are:"
556 local index=1
557 local v
558 for v in ${VARIANT_CHOICES[@]}
559 do
560 # The product name is the name of the directory containing
561 # the makefile we found, above.
562 echo " $index. $v"
563 index=$(($index+1))
564 done
565
566 local default_value=eng
567 local ANSWER
568
569 export TARGET_BUILD_VARIANT=
570 while [ -z "$TARGET_BUILD_VARIANT" ]
571 do
572 echo -n "Which would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000573 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800574 read ANSWER
575 else
576 echo $1
577 ANSWER=$1
578 fi
579
Matt Alexanderd9c56562020-05-21 10:49:17 +0000580 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800581 export TARGET_BUILD_VARIANT=$default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000582 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
583 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Guillaume Chelfice000fd2019-10-03 12:02:46 +0200584 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800585 fi
586 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000587 if check_variant $ANSWER
588 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589 export TARGET_BUILD_VARIANT=$ANSWER
590 else
591 echo "** Not a valid variant: $ANSWER"
592 fi
593 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000594 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800595 break
596 fi
597 done
598}
599
Matt Alexanderd9c56562020-05-21 10:49:17 +0000600function choosecombo()
601{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700602 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700603
604 echo
605 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700606 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700607
608 echo
609 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700610 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800611
612 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800613 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700614 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800615 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800616 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700617}
618
Matt Alexanderd9c56562020-05-21 10:49:17 +0000619function add_lunch_combo()
620{
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800621 if [ -n "$ZSH_VERSION" ]; then
622 echo -n "${funcfiletrace[1]}: "
623 else
624 echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
625 fi
626 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 -0800627}
628
Matt Alexanderd9c56562020-05-21 10:49:17 +0000629function print_lunch_menu()
630{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700631 local uname=$(uname)
Roland Levillain23c46cf2020-03-31 16:11:05 +0100632 local choices
Colin Crossfa50d402021-04-22 13:05:41 -0700633 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 +0100634 local ret=$?
635
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700636 echo
637 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700638 echo
Roland Levillain23c46cf2020-03-31 16:11:05 +0100639
Matt Alexanderd9c56562020-05-21 10:49:17 +0000640 if [ $ret -ne 0 ]
641 then
Roland Levillain23c46cf2020-03-31 16:11:05 +0100642 echo "Warning: Cannot display lunch menu."
643 echo
644 echo "Note: You can invoke lunch with an explicit target:"
645 echo
646 echo " usage: lunch [target]" >&2
647 echo
648 return
649 fi
650
Will Burr40401202022-02-07 12:12:01 +0000651 echo "Lunch menu .. Here are the common combinations:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800652
653 local i=1
654 local choice
Dan Willemsen91763e92019-10-03 15:13:12 -0700655 for choice in $(echo $choices)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800656 do
657 echo " $i. $choice"
658 i=$(($i+1))
659 done
660
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661 echo
662}
663
Matt Alexanderd9c56562020-05-21 10:49:17 +0000664function lunch()
665{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800666 local answer
667
Steven Moreland92793dc2020-02-25 18:30:18 -0800668 if [[ $# -gt 1 ]]; then
669 echo "usage: lunch [target]" >&2
670 return 1
671 fi
672
Will Burr40401202022-02-07 12:12:01 +0000673 local used_lunch_menu=0
674
Steven Moreland92793dc2020-02-25 18:30:18 -0800675 if [ "$1" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800676 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700677 else
678 print_lunch_menu
Will Burr40401202022-02-07 12:12:01 +0000679 echo "Which would you like? [aosp_arm-eng]"
680 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 -0800681 read answer
Will Burr40401202022-02-07 12:12:01 +0000682 used_lunch_menu=1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700683 fi
684
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800685 local selection=
686
Matt Alexanderd9c56562020-05-21 10:49:17 +0000687 if [ -z "$answer" ]
688 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700689 selection=aosp_arm-eng
Matt Alexanderd9c56562020-05-21 10:49:17 +0000690 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
691 then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800692 local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
Matt Alexanderd9c56562020-05-21 10:49:17 +0000693 if [ $answer -le ${#choices[@]} ]
694 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800695 # array in zsh starts from 1 instead of 0.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000696 if [ -n "$ZSH_VERSION" ]
697 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800698 selection=${choices[$(($answer))]}
699 else
700 selection=${choices[$(($answer-1))]}
701 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800702 fi
Colin Cross88737132017-03-21 17:41:03 -0700703 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800704 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700705 fi
706
Joe Onoratoda12daf2010-06-09 18:18:31 -0700707 export TARGET_BUILD_APPS=
708
Colin Cross88737132017-03-21 17:41:03 -0700709 local product variant_and_version variant version
Colin Cross88737132017-03-21 17:41:03 -0700710 product=${selection%%-*} # Trim everything after first dash
711 variant_and_version=${selection#*-} # Trim everything up to first dash
712 if [ "$variant_and_version" != "$selection" ]; then
713 variant=${variant_and_version%%-*}
714 if [ "$variant" != "$variant_and_version" ]; then
715 version=${variant_and_version#*-}
716 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700717 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800718
Matt Alexanderd9c56562020-05-21 10:49:17 +0000719 if [ -z "$product" ]
720 then
Ying Wang08800fd2016-03-03 20:57:21 -0800721 echo
Colin Cross88737132017-03-21 17:41:03 -0700722 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700723 return 1
724 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800725
Colin Cross88737132017-03-21 17:41:03 -0700726 TARGET_PRODUCT=$product \
727 TARGET_BUILD_VARIANT=$variant \
728 TARGET_PLATFORM_VERSION=$version \
729 build_build_var_cache
Matt Alexanderd9c56562020-05-21 10:49:17 +0000730 if [ $? -ne 0 ]
731 then
Anton Hansson32fa7ee2021-06-14 17:09:58 +0100732 if [[ "$product" =~ .*_(eng|user|userdebug) ]]
733 then
734 echo "Did you mean -${product/*_/}? (dash instead of underscore)"
735 fi
Colin Cross88737132017-03-21 17:41:03 -0700736 return 1
737 fi
Colin Cross88737132017-03-21 17:41:03 -0700738 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
739 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700740 if [ -n "$version" ]; then
741 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
742 else
743 unset TARGET_PLATFORM_VERSION
744 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700745 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700746
Will Burr40401202022-02-07 12:12:01 +0000747 if [ $used_lunch_menu -eq 1 ]; then
748 echo
749 echo "Hint: next time you can simply run 'lunch $selection'"
750 fi
751
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700752 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800753
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700754 set_stuff_for_environment
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700755 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800756 destroy_build_var_cache
Kousik Kumar41dacd12021-05-11 18:38:38 -0400757
758 if [[ -n "${CHECK_MU_CONFIG:-}" ]]; then
759 check_mu_config
760 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700761}
762
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700763unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700764# Tab completion for lunch.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000765function _lunch()
766{
Jeff Davidson513d7a42010-08-02 10:00:44 -0700767 local cur prev opts
768 COMPREPLY=()
769 cur="${COMP_WORDS[COMP_CWORD]}"
770 prev="${COMP_WORDS[COMP_CWORD-1]}"
771
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700772 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800773 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700774 fi
775
776 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700777 return 0
778}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700779
Joe Onoratoda12daf2010-06-09 18:18:31 -0700780# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700781# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Matt Alexanderd9c56562020-05-21 10:49:17 +0000782function tapas()
783{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700784 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Elliott Hughesf71c05a2020-03-06 16:46:59 -0800785 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700786 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700787 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 -0800788 local keys="$(echo $* | xargs -n 1 echo | \grep -E '^(devkeys)$' | xargs)"
789 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)"
790
Joe Onoratoda12daf2010-06-09 18:18:31 -0700791
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700792 if [ "$showHelp" != "" ]; then
793 $(gettop)/build/make/tapasHelp.sh
794 return
795 fi
796
Ying Wang67f02922012-08-22 10:25:20 -0700797 if [ $(echo $arch | wc -w) -gt 1 ]; then
798 echo "tapas: Error: Multiple build archs supplied: $arch"
799 return
800 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700801 if [ $(echo $variant | wc -w) -gt 1 ]; then
802 echo "tapas: Error: Multiple build variants supplied: $variant"
803 return
804 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700805 if [ $(echo $density | wc -w) -gt 1 ]; then
806 echo "tapas: Error: Multiple densities supplied: $density"
807 return
808 fi
Colin Cross7f49a672022-01-27 18:15:53 -0800809 if [ $(echo $keys | wc -w) -gt 1 ]; then
810 echo "tapas: Error: Multiple keys supplied: $keys"
811 return
812 fi
Ying Wang67f02922012-08-22 10:25:20 -0700813
Ying Wang0a76df52015-06-08 11:57:26 -0700814 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700815 case $arch in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000816 x86) product=aosp_x86;;
817 arm64) product=aosp_arm64;;
818 x86_64) product=aosp_x86_64;;
Ying Wang67f02922012-08-22 10:25:20 -0700819 esac
Colin Cross7f49a672022-01-27 18:15:53 -0800820 if [ -n "$keys" ]; then
821 product=${product/aosp_/aosp_${keys}_}
822 fi;
823
Joe Onoratoda12daf2010-06-09 18:18:31 -0700824 if [ -z "$variant" ]; then
825 variant=eng
826 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700827 if [ -z "$apps" ]; then
828 apps=all
829 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600830 if [ -z "$density" ]; then
831 density=alldpi
832 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700833
Ying Wang67f02922012-08-22 10:25:20 -0700834 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700835 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700836 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700837 export TARGET_BUILD_TYPE=release
838 export TARGET_BUILD_APPS=$apps
839
Ying Wang08800fd2016-03-03 20:57:21 -0800840 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700841 set_stuff_for_environment
842 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800843 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700844}
845
Martin Stjernholmf692c752021-04-12 00:01:10 +0100846# Configures the build to build unbundled Android modules (APEXes).
847# Run banchan with one or more module names (from apex{} modules).
848function banchan()
849{
850 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Anton Hansson90ac61c2022-09-06 14:36:00 +0000851 local product="$(echo $* | xargs -n 1 echo | \grep -E '^(.*_)?(arm|x86|arm64|x86_64|arm64only|x86_64only)$' | xargs)"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100852 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100853 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 +0100854
855 if [ "$showHelp" != "" ]; then
856 $(gettop)/build/make/banchanHelp.sh
857 return
858 fi
859
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100860 if [ -z "$product" ]; then
Anton Hansson0328e322022-05-24 15:47:40 +0000861 product=arm64
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100862 elif [ $(echo $product | wc -w) -gt 1 ]; then
863 echo "banchan: Error: Multiple build archs or products supplied: $products"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100864 return
865 fi
866 if [ $(echo $variant | wc -w) -gt 1 ]; then
867 echo "banchan: Error: Multiple build variants supplied: $variant"
868 return
869 fi
870 if [ -z "$apps" ]; then
871 echo "banchan: Error: No modules supplied"
872 return
873 fi
874
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100875 case $product in
876 arm) product=module_arm;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100877 x86) product=module_x86;;
878 arm64) product=module_arm64;;
879 x86_64) product=module_x86_64;;
Anton Hansson90ac61c2022-09-06 14:36:00 +0000880 arm64only) product=module_arm64only;;
881 x86_64only) product=module_x86_64only;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100882 esac
883 if [ -z "$variant" ]; then
884 variant=eng
885 fi
886
887 export TARGET_PRODUCT=$product
888 export TARGET_BUILD_VARIANT=$variant
889 export TARGET_BUILD_DENSITY=alldpi
890 export TARGET_BUILD_TYPE=release
891
892 # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use
893 # case is different and it may diverge in the future.
894 export TARGET_BUILD_APPS=$apps
895
896 build_build_var_cache
897 set_stuff_for_environment
898 printconfig
899 destroy_build_var_cache
900}
901
Matt Alexanderd9c56562020-05-21 10:49:17 +0000902function gettop
903{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700904 local TOPFILE=build/make/core/envsetup.mk
Matt Alexanderd9c56562020-05-21 10:49:17 +0000905 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700906 # The following circumlocution ensures we remove symlinks from TOP.
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000907 (cd "$TOP"; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700908 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000909 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800910 # The following circumlocution (repeated below as well) ensures
911 # that we record the true directory name and not one that is
912 # faked up with symlink names.
913 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700914 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800915 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700916 local T=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000917 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800918 \cd ..
synergyb112a402013-07-05 19:47:47 -0700919 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700920 done
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000921 \cd "$HERE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700922 if [ -f "$T/$TOPFILE" ]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000923 echo "$T"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700924 fi
925 fi
926 fi
927}
928
Joe Onorato7cf6f972022-05-11 21:39:57 -0700929# TODO: Merge into gettop as part of launching multitree
930function multitree_gettop
931{
Spandan Dasca762052022-09-21 00:08:34 +0000932 local TOPFILE=orchestrator/build/make/core/envsetup.mk
Joe Onorato7cf6f972022-05-11 21:39:57 -0700933 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
934 # The following circumlocution ensures we remove symlinks from TOP.
935 (cd "$TOP"; PWD= /bin/pwd)
936 else
937 if [ -f $TOPFILE ] ; then
938 # The following circumlocution (repeated below as well) ensures
939 # that we record the true directory name and not one that is
940 # faked up with symlink names.
941 PWD= /bin/pwd
942 else
943 local HERE=$PWD
944 local T=
945 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
946 \cd ..
947 T=`PWD= /bin/pwd -P`
948 done
949 \cd "$HERE"
950 if [ -f "$T/$TOPFILE" ]; then
951 echo "$T"
952 fi
953 fi
954 fi
955}
956
Matt Alexanderd9c56562020-05-21 10:49:17 +0000957function croot()
958{
Christopher Ferris55257d22017-03-23 11:08:58 -0700959 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700960 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700961 if [ "$1" ]; then
962 \cd $(gettop)/$1
963 else
964 \cd $(gettop)
965 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966 else
967 echo "Couldn't locate the top of the tree. Try setting TOP."
968 fi
969}
970
Matt Alexanderd9c56562020-05-21 10:49:17 +0000971function _croot()
972{
Anton Hanssonece9c482019-02-04 18:15:39 +0000973 local T=$(gettop)
974 if [ "$T" ]; then
975 local cur="${COMP_WORDS[COMP_CWORD]}"
976 k=0
977 for c in $(compgen -d ${T}/${cur}); do
978 COMPREPLY[k++]=${c#${T}/}/
979 done
980 fi
981}
982
Matt Alexanderd9c56562020-05-21 10:49:17 +0000983function cproj()
984{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700985 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700986 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700987 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700988 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
989 T=$PWD
990 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800991 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700992 return
993 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800994 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700995 done
Ying Wang9cd17642012-12-13 10:52:07 -0800996 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700997 echo "can't find Android.mk"
998}
999
Daniel Sandler47e0a882013-07-30 13:23:52 -04001000# simplified version of ps; output in the form
1001# <pid> <procname>
1002function qpid() {
1003 local prepend=''
1004 local append=''
Matt Alexanderd9c56562020-05-21 10:49:17 +00001005 if [ "$1" = "--exact" ]; then
Daniel Sandler47e0a882013-07-30 13:23:52 -04001006 prepend=' '
1007 append='$'
1008 shift
Matt Alexanderd9c56562020-05-21 10:49:17 +00001009 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001010 echo "usage: qpid [[--exact] <process name|pid>"
1011 return 255
1012 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001013
1014 local EXE="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001015 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001016 qpid | \grep "$prepend$EXE$append"
1017 else
1018 adb shell ps \
1019 | tr -d '\r' \
1020 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1021 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001022}
1023
Steven Moreland74114f12020-09-10 01:23:32 +00001024# syswrite - disable verity, reboot if needed, and remount image
1025#
1026# Easy way to make system.img/etc writable
1027function syswrite() {
1028 adb wait-for-device && adb root || return 1
Frederick Maylee59a8792022-08-22 22:40:23 +00001029 if [[ $(adb disable-verity | grep -i "reboot") ]]; then
Steven Moreland74114f12020-09-10 01:23:32 +00001030 echo "rebooting"
1031 adb reboot && adb wait-for-device && adb root || return 1
1032 fi
1033 adb wait-for-device && adb remount || return 1
1034}
1035
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001036# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001037# that has the core-file-size limit set correctly
1038#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001039# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001040# if its core-file-size limit is not set already.
1041# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1042
Matt Alexanderd9c56562020-05-21 10:49:17 +00001043function coredump_setup()
1044{
1045 echo "Getting root...";
1046 adb root;
1047 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001048
Matt Alexanderd9c56562020-05-21 10:49:17 +00001049 echo "Remounting root partition read-write...";
1050 adb shell mount -w -o remount -t rootfs rootfs;
1051 sleep 1;
1052 adb wait-for-device;
1053 adb shell mkdir -p /cores;
1054 adb shell mount -t tmpfs tmpfs /cores;
1055 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001056
Matt Alexanderd9c56562020-05-21 10:49:17 +00001057 echo "Granting SELinux permission to dump in /cores...";
1058 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001059
Matt Alexanderd9c56562020-05-21 10:49:17 +00001060 echo "Set core pattern.";
1061 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001062
Ying Wang08800fd2016-03-03 20:57:21 -08001063 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001064}
1065
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001066# coredump_enable - enable core dumps for the specified process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001067# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001068#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001069# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001070# dump to actually be generated.
1071
Matt Alexanderd9c56562020-05-21 10:49:17 +00001072function coredump_enable()
1073{
1074 local PID=$1;
Ying Wang08800fd2016-03-03 20:57:21 -08001075 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001076 printf "Expecting a PID!\n";
1077 return;
1078 fi;
1079 echo "Setting core limit for $PID to infinite...";
xi yuaddf4832022-05-26 12:41:21 +00001080 adb shell /system/bin/ulimit -P $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001081}
1082
1083# core - send SIGV and pull the core for process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001084# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001085#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001086# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001087# enabled globally.
1088
Matt Alexanderd9c56562020-05-21 10:49:17 +00001089function core()
1090{
1091 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001092
Ying Wang08800fd2016-03-03 20:57:21 -08001093 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001094 printf "Expecting a PID!\n";
1095 return;
1096 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001097
Matt Alexanderd9c56562020-05-21 10:49:17 +00001098 local CORENAME=core.$PID;
1099 local COREPATH=/cores/$CORENAME;
1100 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001101
Matt Alexanderd9c56562020-05-21 10:49:17 +00001102 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001103
Matt Alexanderd9c56562020-05-21 10:49:17 +00001104 local done=0;
Ying Wang08800fd2016-03-03 20:57:21 -08001105 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
Matt Alexanderd9c56562020-05-21 10:49:17 +00001106 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1107 adb shell kill -$SIG $PID;
1108 sleep 1;
1109 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001110
Matt Alexanderd9c56562020-05-21 10:49:17 +00001111 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1112 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001113}
1114
Christopher Tate744ee802009-11-12 15:33:08 -08001115# systemstack - dump the current stack trace of all threads in the system process
1116# to the usual ANR traces file
Matt Alexanderd9c56562020-05-21 10:49:17 +00001117function systemstack()
1118{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001119 stacks system_server
1120}
1121
Michael Wrightaeed7212014-06-19 19:58:12 -07001122# Read the ELF header from /proc/$PID/exe to determine if the process is
1123# 64-bit.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001124function is64bit()
1125{
Ben Chengfba67bf2014-02-25 10:27:07 -08001126 local PID="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001127 if [ "$PID" ] ; then
1128 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001129 echo "64"
1130 else
1131 echo ""
1132 fi
1133 else
1134 echo ""
1135 fi
1136}
1137
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001138case `uname -s` in
1139 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001140 function sgrep()
1141 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001142 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 -04001143 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001144 }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001145
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001146 ;;
1147 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001148 function sgrep()
1149 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001150 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 -04001151 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001152 }
1153 ;;
1154esac
1155
Matt Alexanderd9c56562020-05-21 10:49:17 +00001156function gettargetarch
1157{
Raghu Gandham8da43102012-07-25 19:57:22 -07001158 get_build_var TARGET_ARCH
1159}
1160
Matt Alexanderd9c56562020-05-21 10:49:17 +00001161function ggrep()
1162{
Mike Frysinger5e479732015-09-22 18:13:48 -04001163 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1164 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001165}
1166
Matt Alexanderd9c56562020-05-21 10:49:17 +00001167function gogrep()
1168{
Orion Hodson831472d2019-10-25 11:35:15 +01001169 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
1170 -exec grep --color -n "$@" {} +
1171}
1172
Matt Alexanderd9c56562020-05-21 10:49:17 +00001173function jgrep()
1174{
Mike Frysinger5e479732015-09-22 18:13:48 -04001175 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1176 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001177}
1178
Alistair Delva176e5342021-02-22 13:31:26 -08001179function rsgrep()
Jeff Vander Stoep1431ab82021-02-02 19:18:26 +01001180{
1181 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rs" \
1182 -exec grep --color -n "$@" {} +
1183}
1184
Taesu Leeea0cecd2020-10-28 11:05:18 +09001185function ktgrep()
1186{
1187 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.kt" \
1188 -exec grep --color -n "$@" {} +
1189}
1190
Matt Alexanderd9c56562020-05-21 10:49:17 +00001191function cgrep()
1192{
Mike Frysinger5e479732015-09-22 18:13:48 -04001193 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' \) \
1194 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001195}
1196
Matt Alexanderd9c56562020-05-21 10:49:17 +00001197function resgrep()
1198{
Christopher Ferris55257d22017-03-23 11:08:58 -07001199 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001200 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1201 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1202 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001203}
1204
Matt Alexanderd9c56562020-05-21 10:49:17 +00001205function mangrep()
1206{
Mike Frysinger5e479732015-09-22 18:13:48 -04001207 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1208 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001209}
1210
Matt Alexanderd9c56562020-05-21 10:49:17 +00001211function owngrep()
1212{
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -06001213 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
1214 -exec grep --color -n "$@" {} +
1215}
1216
Matt Alexanderd9c56562020-05-21 10:49:17 +00001217function sepgrep()
1218{
Mike Frysinger5e479732015-09-22 18:13:48 -04001219 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1220 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001221}
1222
Matt Alexanderd9c56562020-05-21 10:49:17 +00001223function rcgrep()
1224{
Mike Frysinger5e479732015-09-22 18:13:48 -04001225 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1226 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001227}
1228
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001229case `uname -s` in
1230 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001231 function mgrep()
1232 {
Orion Hodson831472d2019-10-25 11:35:15 +01001233 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 -04001234 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001235 }
1236
Matt Alexanderd9c56562020-05-21 10:49:17 +00001237 function treegrep()
1238 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001239 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 -04001240 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001241 }
1242
1243 ;;
1244 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001245 function mgrep()
1246 {
Orion Hodson831472d2019-10-25 11:35:15 +01001247 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 -04001248 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001249 }
1250
Matt Alexanderd9c56562020-05-21 10:49:17 +00001251 function treegrep()
1252 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001253 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 -04001254 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001255 }
1256
1257 ;;
1258esac
1259
Matt Alexanderd9c56562020-05-21 10:49:17 +00001260function getprebuilt
1261{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001262 get_abs_build_var ANDROID_PREBUILTS
1263}
1264
Matt Alexanderd9c56562020-05-21 10:49:17 +00001265function tracedmdump()
1266{
Christopher Ferris55257d22017-03-23 11:08:58 -07001267 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001268 if [ ! "$T" ]; then
1269 echo "Couldn't locate the top of the tree. Try setting TOP."
1270 return
1271 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001272 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001273 local arch=$(gettargetarch)
1274 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001275
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001276 local TRACE=$1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001277 if [ ! "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001278 echo "usage: tracedmdump tracename"
1279 return
1280 fi
1281
Matt Alexanderd9c56562020-05-21 10:49:17 +00001282 if [ ! -r "$KERNEL" ] ; then
Jack Veenstra60116fc2009-04-09 18:12:34 -07001283 echo "Error: cannot find kernel: '$KERNEL'"
1284 return
1285 fi
1286
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001287 local BASETRACE=$(basename $TRACE)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001288 if [ "$BASETRACE" = "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001289 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1290 fi
1291
1292 echo "post-processing traces..."
1293 rm -f $TRACE/qtrace.dexlist
1294 post_trace $TRACE
1295 if [ $? -ne 0 ]; then
1296 echo "***"
1297 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1298 echo "***"
1299 return
1300 fi
1301 echo "generating dexlist output..."
1302 /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
1303 echo "generating dmtrace data..."
1304 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1305 echo "generating html file..."
1306 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1307 echo "done, see $TRACE/dmtrace.html for details"
1308 echo "or run:"
1309 echo " traceview $TRACE/dmtrace"
1310}
1311
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001312# communicate with a running device or emulator, set up necessary state,
1313# and run the hat command.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001314function runhat()
1315{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001316 # process standard adb options
1317 local adbTarget=""
Matt Alexanderd9c56562020-05-21 10:49:17 +00001318 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001319 adbTarget=$1
1320 shift 1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001321 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001322 adbTarget="$1 $2"
1323 shift 2
1324 fi
1325 local adbOptions=${adbTarget}
Matt Alexanderd9c56562020-05-21 10:49:17 +00001326 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001327
1328 # runhat options
1329 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001330
Matt Alexanderd9c56562020-05-21 10:49:17 +00001331 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001332 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001333 return
1334 fi
1335
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001336 # confirm hat is available
1337 if [ -z $(which hat) ]; then
1338 echo "hat is not available in this configuration."
1339 return
1340 fi
1341
Andy McFaddenb6289852010-07-12 08:00:19 -07001342 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001343 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001344 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001345 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001346 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001347 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001348 echo -n "> "
1349 read
1350
The Android Open Source Project88b60792009-03-03 19:28:42 -08001351 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001352
The Android Open Source Project88b60792009-03-03 19:28:42 -08001353 echo "Retrieving file $devFile..."
1354 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001355
The Android Open Source Project88b60792009-03-03 19:28:42 -08001356 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001357
The Android Open Source Project88b60792009-03-03 19:28:42 -08001358 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001359 echo "View the output by pointing your browser at http://localhost:7000/"
1360 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001361 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001362}
1363
Matt Alexanderd9c56562020-05-21 10:49:17 +00001364function getbugreports()
1365{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001366 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001367
1368 if [ ! "$reports" ]; then
1369 echo "Could not locate any bugreports."
1370 return
1371 fi
1372
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001373 local report
1374 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001375 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001376 echo "/sdcard/bugreports/${report}"
1377 adb pull /sdcard/bugreports/${report} ${report}
1378 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001379 done
1380}
1381
Matt Alexanderd9c56562020-05-21 10:49:17 +00001382function getsdcardpath()
1383{
Victoria Lease1b296b42012-08-21 15:44:06 -07001384 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1385}
1386
Matt Alexanderd9c56562020-05-21 10:49:17 +00001387function getscreenshotpath()
1388{
Victoria Lease1b296b42012-08-21 15:44:06 -07001389 echo "$(getsdcardpath)/Pictures/Screenshots"
1390}
1391
Matt Alexanderd9c56562020-05-21 10:49:17 +00001392function getlastscreenshot()
1393{
Victoria Lease1b296b42012-08-21 15:44:06 -07001394 local screenshot_path=$(getscreenshotpath)
1395 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 +00001396 if [ "$screenshot" = "" ]; then
Victoria Lease1b296b42012-08-21 15:44:06 -07001397 echo "No screenshots found."
1398 return
1399 fi
1400 echo "${screenshot}"
1401 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1402}
1403
Matt Alexanderd9c56562020-05-21 10:49:17 +00001404function startviewserver()
1405{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001406 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001407 if [ $# -gt 0 ]; then
1408 port=$1
1409 fi
1410 adb shell service call window 1 i32 $port
1411}
1412
Matt Alexanderd9c56562020-05-21 10:49:17 +00001413function stopviewserver()
1414{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001415 adb shell service call window 2
1416}
1417
Matt Alexanderd9c56562020-05-21 10:49:17 +00001418function isviewserverstarted()
1419{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001420 adb shell service call window 3
1421}
1422
Matt Alexanderd9c56562020-05-21 10:49:17 +00001423function key_home()
1424{
Romain Guyb84049a2010-10-04 16:56:11 -07001425 adb shell input keyevent 3
1426}
1427
Matt Alexanderd9c56562020-05-21 10:49:17 +00001428function key_back()
1429{
Romain Guyb84049a2010-10-04 16:56:11 -07001430 adb shell input keyevent 4
1431}
1432
Matt Alexanderd9c56562020-05-21 10:49:17 +00001433function key_menu()
1434{
Romain Guyb84049a2010-10-04 16:56:11 -07001435 adb shell input keyevent 82
1436}
1437
Matt Alexanderd9c56562020-05-21 10:49:17 +00001438function smoketest()
1439{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001440 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1441 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1442 return
1443 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001444 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001445 if [ ! "$T" ]; then
1446 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1447 return
1448 fi
1449
Ying Wang9cd17642012-12-13 10:52:07 -08001450 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001451 adb uninstall com.android.smoketest > /dev/null &&
1452 adb uninstall com.android.smoketest.tests > /dev/null &&
1453 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1454 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1455 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1456}
1457
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001458# simple shortcut to the runtest command
Matt Alexanderd9c56562020-05-21 10:49:17 +00001459function runtest()
1460{
Christopher Ferris55257d22017-03-23 11:08:58 -07001461 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001462 if [ ! "$T" ]; then
1463 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1464 return
1465 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001466 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001467}
1468
The Android Open Source Project88b60792009-03-03 19:28:42 -08001469function godir () {
1470 if [[ -z "$1" ]]; then
1471 echo "Usage: godir <regex>"
1472 return
1473 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001474 local T=$(gettop)
1475 local FILELIST
Matt Alexanderd9c56562020-05-21 10:49:17 +00001476 if [ ! "$OUT_DIR" = "" ]; then
Brian Carlstromf2257422015-09-30 20:28:54 -07001477 mkdir -p $OUT_DIR
1478 FILELIST=$OUT_DIR/filelist
1479 else
1480 FILELIST=$T/filelist
1481 fi
1482 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001483 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001484 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001485 echo " Done"
1486 echo ""
1487 fi
1488 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001489 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
Matt Alexanderd9c56562020-05-21 10:49:17 +00001490 if [[ ${#lines[@]} = 0 ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001491 echo "Not found"
1492 return
1493 fi
1494 local pathname
1495 local choice
1496 if [[ ${#lines[@]} > 1 ]]; then
1497 while [[ -z "$pathname" ]]; do
1498 local index=1
1499 local line
1500 for line in ${lines[@]}; do
1501 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001502 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001503 done
1504 echo
1505 echo -n "Select one: "
1506 unset choice
1507 read choice
1508 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1509 echo "Invalid choice"
1510 continue
1511 fi
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001512 pathname=${lines[@]:$(($choice-1)):1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001513 done
1514 else
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001515 pathname=${lines[@]:0:1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001516 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001517 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001518}
1519
Steven Moreland62054a42018-12-06 10:11:40 -08001520# Update module-info.json in out.
1521function refreshmod() {
1522 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1523 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1524 return 1
1525 fi
1526
1527 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1528
1529 # for the output of the next command
1530 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1531
1532 # Note, can't use absolute path because of the way make works.
Alessandro Astonec8771be2020-05-10 11:27:57 +02001533 m $(get_build_var PRODUCT_OUT)/module-info.json \
Steven Moreland62054a42018-12-06 10:11:40 -08001534 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1535}
1536
Cole Faust3e192382021-10-25 13:29:15 -07001537# Verifies that module-info.txt exists, returning nonzero if it doesn't.
Cole Faust24c36db2021-01-23 02:39:37 +00001538function verifymodinfo() {
Steven Moreland62054a42018-12-06 10:11:40 -08001539 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001540 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
1541 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1542 fi
Steven Moreland62054a42018-12-06 10:11:40 -08001543 return 1
1544 fi
1545
1546 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001547 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
Cole Faust3e192382021-10-25 13:29:15 -07001548 echo "Could not find module-info.json. Please run 'refreshmod' first." >&2
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001549 fi
1550 return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001551 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001552}
1553
Cole Faust5d825b72022-10-26 18:16:44 -07001554# List all modules for the current device, as cached in all_modules.txt. If any build change is
1555# made and it should be reflected in the output, you should run `m nothing` first.
Cole Faust24c36db2021-01-23 02:39:37 +00001556function allmod() {
Cole Faust5d825b72022-10-26 18:16:44 -07001557 cat $ANDROID_PRODUCT_OUT/all_modules.txt 2>/dev/null
Steven Moreland62054a42018-12-06 10:11:40 -08001558}
1559
Jingwen Chen83eeebb2022-10-05 02:27:07 +00001560# Return the Bazel label of a Soong module if it is converted with bp2build.
1561function bmod()
1562(
1563 if [ $# -ne 1 ]; then
1564 echo "usage: bmod <module>" >&2
1565 return 1
1566 fi
1567
1568 # We could run bp2build here, but it might trigger bp2build invalidation
1569 # when used with `b` (e.g. --run_soong_tests) and/or add unnecessary waiting
1570 # time overhead.
1571 #
1572 # For a snappy result, use the latest generated version in soong_injection,
1573 # and ask users to run m bp2build if it doesn't exist.
Jingwen Chenacdcaa02022-10-13 07:24:24 +00001574 converted_json="$(get_abs_build_var OUT_DIR)/soong/soong_injection/metrics/converted_modules_path_map.json"
Jingwen Chen83eeebb2022-10-05 02:27:07 +00001575
Jingwen Chenacdcaa02022-10-13 07:24:24 +00001576 if [ ! -f ${converted_json} ]; then
Jingwen Chen83eeebb2022-10-05 02:27:07 +00001577 echo "bp2build files not found. Have you ran 'm bp2build'?" >&2
1578 return 1
1579 fi
1580
1581 local target_label=$(python3 -c "import json
1582module = '$1'
1583converted_json='$converted_json'
1584bp2build_converted_map = json.load(open(converted_json))
1585if module not in bp2build_converted_map:
1586 exit(1)
1587print(bp2build_converted_map[module] + ':' + module)")
1588
1589 if [ -z "${target_label}" ]; then
1590 echo "$1 is not converted to Bazel." >&2
1591 return 1
1592 else
1593 echo "${target_label}"
1594 fi
1595)
1596
Joe Onorato2c1aa472021-02-25 16:42:39 -08001597# Get the path of a specific module in the android tree, as cached in module-info.json.
1598# If any build change is made, and it should be reflected in the output, you should run
1599# 'refreshmod' first. Note: This is the inverse of dirmods.
Rett Berg78d1c932019-01-24 14:34:23 -08001600function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001601 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001602 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001603 return 1
1604 fi
1605
Cole Faust24c36db2021-01-23 02:39:37 +00001606 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001607
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001608 local relpath=$(python3 -c "import json, os
Steven Moreland62054a42018-12-06 10:11:40 -08001609module = '$1'
1610module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1611if module not in module_info:
1612 exit(1)
LuK1337b6a78192020-01-12 03:12:17 +01001613print(module_info[module]['path'][0])" 2>/dev/null)
Steven Moreland62054a42018-12-06 10:11:40 -08001614
1615 if [ -z "$relpath" ]; then
1616 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1617 return 1
1618 else
Rett Berg78d1c932019-01-24 14:34:23 -08001619 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001620 fi
1621}
1622
Joe Onorato2c1aa472021-02-25 16:42:39 -08001623# Get the path of a specific module in the android tree, as cached in module-info.json.
1624# If any build change is made, and it should be reflected in the output, you should run
1625# 'refreshmod' first. Note: This is the inverse of pathmod.
1626function dirmods() {
1627 if [[ $# -ne 1 ]]; then
1628 echo "usage: dirmods <path>" >&2
1629 return 1
1630 fi
1631
1632 verifymodinfo || return 1
1633
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001634 python3 -c "import json, os
Joe Onorato2c1aa472021-02-25 16:42:39 -08001635dir = '$1'
1636while dir.endswith('/'):
1637 dir = dir[:-1]
1638prefix = dir + '/'
1639module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1640results = set()
1641for m in module_info.values():
1642 for path in m.get(u'path', []):
1643 if path == dir or path.startswith(prefix):
1644 name = m.get(u'module_name')
1645 if name:
1646 results.add(name)
1647for name in sorted(results):
1648 print(name)
1649"
1650}
1651
1652
Rett Berg78d1c932019-01-24 14:34:23 -08001653# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1654# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1655function gomod() {
1656 if [[ $# -ne 1 ]]; then
1657 echo "usage: gomod <module>" >&2
1658 return 1
1659 fi
1660
1661 local path="$(pathmod $@)"
1662 if [ -z "$path" ]; then
1663 return 1
1664 fi
1665 cd $path
1666}
1667
Cole Faust24c36db2021-01-23 02:39:37 +00001668# Gets the list of a module's installed outputs, as cached in module-info.json.
1669# If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first.
1670function outmod() {
1671 if [[ $# -ne 1 ]]; then
1672 echo "usage: outmod <module>" >&2
1673 return 1
1674 fi
1675
1676 verifymodinfo || return 1
1677
1678 local relpath
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001679 relpath=$(python3 -c "import json, os
Cole Faust24c36db2021-01-23 02:39:37 +00001680module = '$1'
1681module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1682if module not in module_info:
1683 exit(1)
1684for output in module_info[module]['installed']:
1685 print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null)
1686
1687 if [ $? -ne 0 ]; then
1688 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2
1689 return 1
1690 elif [ ! -z "$relpath" ]; then
1691 echo "$relpath"
1692 fi
1693}
1694
1695# adb install a module's apk, as cached in module-info.json. If any build change
1696# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1697# Usage: installmod [adb install arguments] <module>
1698# For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk
1699function installmod() {
1700 if [[ $# -eq 0 ]]; then
1701 echo "usage: installmod [adb install arguments] <module>" >&2
Cole Faust3e192382021-10-25 13:29:15 -07001702 echo "" >&2
1703 echo "Only flags to be passed after the \"install\" in adb install are supported," >&2
1704 echo "with the exception of -s. If -s is passed it will be placed before the \"install\"." >&2
1705 echo "-s must be the first flag passed if it exists." >&2
Cole Faust24c36db2021-01-23 02:39:37 +00001706 return 1
1707 fi
1708
1709 local _path
1710 _path=$(outmod ${@:$#:1})
1711 if [ $? -ne 0 ]; then
1712 return 1
1713 fi
1714
1715 _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1)
1716 if [ -z "$_path" ]; then
1717 echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2
1718 return 1
1719 fi
Cole Faust3e192382021-10-25 13:29:15 -07001720 local serial_device=""
1721 if [[ "$1" == "-s" ]]; then
1722 if [[ $# -le 2 ]]; then
1723 echo "-s requires an argument" >&2
1724 return 1
1725 fi
1726 serial_device="-s $2"
1727 shift 2
1728 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001729 local length=$(( $# - 1 ))
Cole Faust3e192382021-10-25 13:29:15 -07001730 echo adb $serial_device install ${@:1:$length} $_path
1731 adb $serial_device install ${@:1:$length} $_path
Cole Faust24c36db2021-01-23 02:39:37 +00001732}
1733
dimitry73b84812018-12-11 18:06:00 +01001734function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001735 local word=${COMP_WORDS[COMP_CWORD]}
Cole Faust5d825b72022-10-26 18:16:44 -07001736 COMPREPLY=( $(allmod | grep -E "^$word") )
Steven Moreland62054a42018-12-06 10:11:40 -08001737}
1738
Alex Rayf0d08eb2013-03-08 15:15:06 -08001739# Print colored exit condition
1740function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001741 "$@"
1742 local retval=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +00001743 if [ $retval -ne 0 ]
1744 then
Jacky Cao89483b82015-05-15 22:12:53 +08001745 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001746 else
Jacky Cao89483b82015-05-15 22:12:53 +08001747 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001748 fi
1749 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001750}
1751
Matt Alexanderd9c56562020-05-21 10:49:17 +00001752function get_make_command()
1753{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001754 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1755 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001756 # Always use the real make if -C is passed in
1757 for arg in "$@"; do
1758 if [[ $arg == -C* ]]; then
1759 echo command make
1760 return
1761 fi
1762 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001763 echo build/soong/soong_ui.bash --make-mode
1764 else
1765 echo command make
1766 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001767}
1768
Matt Alexanderd9c56562020-05-21 10:49:17 +00001769function _wrap_build()
1770{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001771 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1772 "$@"
1773 return $?
1774 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001775 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001776 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001777 local ret=$?
1778 local end_time=$(date +"%s")
1779 local tdiff=$(($end_time-$start_time))
1780 local hours=$(($tdiff / 3600 ))
1781 local mins=$((($tdiff % 3600) / 60))
1782 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001783 local ncolors=$(tput colors 2>/dev/null)
1784 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001785 color_failed=$'\E'"[0;31m"
1786 color_success=$'\E'"[0;32m"
Kousik Kumar09af2542021-08-19 16:13:32 -04001787 color_warning=$'\E'"[0;33m"
Jacky Cao89483b82015-05-15 22:12:53 +08001788 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001789 else
1790 color_failed=""
1791 color_success=""
1792 color_reset=""
1793 fi
Kousik Kumar09af2542021-08-19 16:13:32 -04001794
1795 if [[ "x${USE_RBE}" == "x" && $mins -gt 15 && "${ANDROID_BUILD_ENVIRONMENT_CONFIG}" == "googler" ]]; then
1796 echo
1797 echo "${color_warning}Start using RBE (http://go/build-fast) to get faster builds!${color_reset}"
1798 fi
1799
Ed Heylcc6be0a2014-06-18 14:55:58 -07001800 echo
Matt Alexanderd9c56562020-05-21 10:49:17 +00001801 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001802 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001803 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001804 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001805 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +00001806 if [ $hours -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001807 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001808 elif [ $mins -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001809 printf "(%02g:%02g (mm:ss))" $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001810 elif [ $secs -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001811 printf "(%s seconds)" $secs
1812 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001813 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001814 echo
1815 return $ret
1816}
1817
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001818function _trigger_build()
1819(
1820 local -r bc="$1"; shift
LaMont Jonesc39e5022022-06-23 19:09:06 +00001821 local T=$(gettop)
1822 if [ -n "$T" ]; then
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001823 _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
1824 else
Jingwen Chend728ee12021-05-18 06:02:53 +00001825 >&2 echo "Couldn't locate the top of the tree. Try setting TOP."
1826 return 1
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001827 fi
1828)
1829
1830function m()
1831(
1832 _trigger_build "all-modules" "$@"
1833)
1834
1835function mm()
1836(
1837 _trigger_build "modules-in-a-dir-no-deps" "$@"
1838)
1839
1840function mmm()
1841(
1842 _trigger_build "modules-in-dirs-no-deps" "$@"
1843)
1844
1845function mma()
1846(
1847 _trigger_build "modules-in-a-dir" "$@"
1848)
1849
1850function mmma()
1851(
1852 _trigger_build "modules-in-dirs" "$@"
1853)
1854
Matt Alexanderd9c56562020-05-21 10:49:17 +00001855function make()
1856{
Dan Willemsene9842242017-07-28 13:00:13 -07001857 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001858}
1859
Joe Onorato7cf6f972022-05-11 21:39:57 -07001860function _multitree_lunch_error()
1861{
1862 >&2 echo "Couldn't locate the top of the tree. Please run \'source build/envsetup.sh\' and multitree_lunch from the root of your workspace."
1863}
1864
1865function multitree_build()
1866{
LaMont Jonesc39e5022022-06-23 19:09:06 +00001867 local T=$(multitree_gettop)
1868 if [ -n "$T" ]; then
Spandan Dasca762052022-09-21 00:08:34 +00001869 "$T/orchestrator/build/orchestrator/core/orchestrator.py" "$@"
Joe Onorato7cf6f972022-05-11 21:39:57 -07001870 else
1871 _multitree_lunch_error
1872 return 1
1873 fi
1874}
1875
Matt Alexanderd9c56562020-05-21 10:49:17 +00001876function provision()
1877{
David Zeuthen1b126ff2015-09-30 17:10:48 -04001878 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1879 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1880 return 1
1881 fi
1882 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1883 echo "There is no provisioning script for the device." >&2
1884 return 1
1885 fi
1886
1887 # Check if user really wants to do this.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001888 if [ "$1" = "--no-confirmation" ]; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001889 shift 1
1890 else
1891 echo "This action will reflash your device."
1892 echo ""
1893 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1894 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001895 echo -n "Are you sure you want to do this (yes/no)? "
1896 read
Matt Alexanderd9c56562020-05-21 10:49:17 +00001897 if [[ "${REPLY}" != "yes" ]] ; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001898 echo "Not taking any action. Exiting." >&2
1899 return 1
1900 fi
1901 fi
1902 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1903}
1904
Jim Tanga881a252018-06-19 16:34:41 +08001905# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001906function enable_zsh_completion() {
1907 # Don't override user's options if bash-style completion is already enabled.
1908 if ! declare -f complete >/dev/null; then
1909 autoload -U compinit && compinit
1910 autoload -U bashcompinit && bashcompinit
1911 fi
Jim Tanga881a252018-06-19 16:34:41 +08001912}
1913
1914function validate_current_shell() {
1915 local current_sh="$(ps -o command -p $$)"
1916 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001917 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001918 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001919 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001920 *zsh*)
1921 function check_type() { type "$1"; }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001922 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001923 *)
Jim Tanga881a252018-06-19 16:34:41 +08001924 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 -07001925 ;;
1926 esac
Jim Tanga881a252018-06-19 16:34:41 +08001927}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001928
1929# Execute the contents of any vendorsetup.sh files we can find.
Dan Willemsend855a722019-02-12 15:52:36 -08001930# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
1931# load those.
1932#
1933# This allows loading only approved vendorsetup.sh files
Jim Tanga881a252018-06-19 16:34:41 +08001934function source_vendorsetup() {
Jim Tangc4dba1d2019-07-25 16:54:27 +08001935 unset VENDOR_PYTHONPATH
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001936 local T="$(gettop)"
Dan Willemsend855a722019-02-12 15:52:36 -08001937 allowed=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001938 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 -08001939 if [ -n "$allowed" ]; then
1940 echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
1941 echo " $allowed"
1942 echo " $f"
1943 return
1944 fi
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001945 allowed="$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001946 done
1947
1948 allowed_files=
1949 [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
Jim Tanga881a252018-06-19 16:34:41 +08001950 for dir in device vendor product; do
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001951 for f in $(cd "$T" && test -d $dir && \
Jim Tanga881a252018-06-19 16:34:41 +08001952 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001953
1954 if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001955 echo "including $f"; . "$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001956 else
1957 echo "ignoring $f, not in $allowed"
1958 fi
Jim Tanga881a252018-06-19 16:34:41 +08001959 done
1960 done
1961}
Kenny Root52aa81c2011-07-15 11:07:06 -07001962
Dan Albertbab814f2020-08-26 15:34:53 -07001963function showcommands() {
1964 local T=$(gettop)
1965 if [[ -z "$TARGET_PRODUCT" ]]; then
1966 >&2 echo "TARGET_PRODUCT not set. Run lunch."
1967 return
1968 fi
1969 case $(uname -s) in
1970 Darwin)
1971 PREBUILT_NAME=darwin-x86
1972 ;;
1973 Linux)
1974 PREBUILT_NAME=linux-x86
1975 ;;
1976 *)
1977 >&2 echo Unknown host $(uname -s)
1978 return
1979 ;;
1980 esac
Jingwen Chenacdcaa02022-10-13 07:24:24 +00001981 OUT_DIR="$(get_abs_build_var OUT_DIR)"
Dan Albertbab814f2020-08-26 15:34:53 -07001982 if [[ "$1" == "--regenerate" ]]; then
1983 shift 1
1984 NINJA_ARGS="-t commands $@" m
1985 else
1986 (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \
1987 -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \
1988 -t commands "$@")
1989 fi
1990}
1991
Cole Faust45844ab2022-08-30 13:59:07 -07001992function avbtool() {
1993 if [[ ! -f "$ANDROID_SOONG_HOST_OUT"/bin/avbtool ]]; then
1994 m avbtool
1995 fi
1996 "$ANDROID_SOONG_HOST_OUT"/bin/avbtool $@
1997}
1998
Jim Tanga881a252018-06-19 16:34:41 +08001999validate_current_shell
2000source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07002001addcompletions