blob: d95c9de0183fe514959d4db00756b1432c6d0cea [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.
DroidFreak32a2781982020-11-26 11:30:19 -050038- pygrep: Greps on all local Python files.
Steven Moreland62054a42018-12-06 10:11:40 -080039- godir: Go to the directory containing a file.
40- allmod: List all modules.
41- gomod: Go to the directory containing a module.
Jingwen Chen83eeebb2022-10-05 02:27:07 +000042- bmod: Get the Bazel label of a Soong module if it is converted with bp2build.
Rett Berg78d1c932019-01-24 14:34:23 -080043- pathmod: Get the directory containing a module.
Cole Faust24c36db2021-01-23 02:39:37 +000044- outmod: Gets the location of a module's installed outputs with a certain extension.
Joe Onorato2c1aa472021-02-25 16:42:39 -080045- dirmods: Gets the modules defined in a given directory.
Cole Faust24c36db2021-01-23 02:39:37 +000046- installmod: Adb installs a module's built APK.
47- refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod.
Steven Moreland74114f12020-09-10 01:23:32 +000048- syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070049
Roland Levillain39341922015-10-20 12:48:19 +010050Environment options:
Steven Moreland115d1f52019-09-26 16:30:28 -070051- SANITIZE_HOST: Set to 'address' to use ASAN for all host modules.
Sasha Smundak9f27cc02019-01-31 13:25:31 -080052- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
Dan Albert4ae5d4b2014-10-31 16:23:08 -070053
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070054Look at the source to view more functions. The complete list is:
55EOF
Christopher Ferris55257d22017-03-23 11:08:58 -070056 local T=$(gettop)
57 local A=""
58 local i
Jacky Cao89483b82015-05-15 22:12:53 +080059 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 -070060 A="$A $i"
61 done
62 echo $A
63}
64
Ying Wang08800fd2016-03-03 20:57:21 -080065# Get all the build variables needed by this script in a single call to the build system.
Matt Alexanderd9c56562020-05-21 10:49:17 +000066function build_build_var_cache()
67{
Christopher Ferris55257d22017-03-23 11:08:58 -070068 local T=$(gettop)
Ying Wang08800fd2016-03-03 20:57:21 -080069 # Grep out the variable names from the script.
Jim Tanga881a252018-06-19 16:34:41 +080070 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' ' '`)
71 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 -080072 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
Steven Moreland05402962018-01-05 12:13:11 -080073 build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
Jim Tanga881a252018-06-19 16:34:41 +080074 --vars="${cached_vars[*]}" \
75 --abs-vars="${cached_abs_vars[*]}" \
Dan Willemsenaf88c412017-07-14 11:29:44 -070076 --var-prefix=var_cache_ \
77 --abs-var-prefix=abs_var_cache_`
Ying Wang08800fd2016-03-03 20:57:21 -080078 local ret=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +000079 if [ $ret -ne 0 ]
80 then
Ying Wang08800fd2016-03-03 20:57:21 -080081 unset build_dicts_script
82 return $ret
83 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -070084 # Execute the script to store the "<val>=<value>" pairs as shell variables.
Ying Wang08800fd2016-03-03 20:57:21 -080085 eval "$build_dicts_script"
Ying Wang08800fd2016-03-03 20:57:21 -080086 ret=$?
Ying Wangf0cb3972016-03-04 13:56:23 -080087 unset build_dicts_script
Matt Alexanderd9c56562020-05-21 10:49:17 +000088 if [ $ret -ne 0 ]
89 then
Ying Wang08800fd2016-03-03 20:57:21 -080090 return $ret
91 fi
92 BUILD_VAR_CACHE_READY="true"
93}
94
Ying Wangf0cb3972016-03-04 13:56:23 -080095# Delete the build var cache, so that we can still call into the build system
Ying Wang08800fd2016-03-03 20:57:21 -080096# to get build variables not listed in this script.
Matt Alexanderd9c56562020-05-21 10:49:17 +000097function destroy_build_var_cache()
98{
Ying Wang08800fd2016-03-03 20:57:21 -080099 unset BUILD_VAR_CACHE_READY
Christopher Ferris55257d22017-03-23 11:08:58 -0700100 local v
Ying Wang08800fd2016-03-03 20:57:21 -0800101 for v in $cached_vars; do
102 unset var_cache_$v
103 done
104 unset cached_vars
105 for v in $cached_abs_vars; do
106 unset abs_var_cache_$v
107 done
108 unset cached_abs_vars
109}
110
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700111# Get the value of a build variable as an absolute path.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000112function get_abs_build_var()
113{
114 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
115 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800116 eval "echo \"\${abs_var_cache_$1}\""
Timi0469c3f2021-04-15 16:41:18 +0200117 return
Ying Wang08800fd2016-03-03 20:57:21 -0800118 fi
119
Christopher Ferris55257d22017-03-23 11:08:58 -0700120 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700121 if [ ! "$T" ]; then
122 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
123 return
124 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700125 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700126}
127
128# Get the exact value of a build variable.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000129function get_build_var()
130{
131 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
132 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800133 eval "echo \"\${var_cache_$1}\""
Roland Levillain23c46cf2020-03-31 16:11:05 +0100134 return 0
Ying Wang08800fd2016-03-03 20:57:21 -0800135 fi
136
Christopher Ferris55257d22017-03-23 11:08:58 -0700137 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700138 if [ ! "$T" ]; then
139 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
Roland Levillain23c46cf2020-03-31 16:11:05 +0100140 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700141 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700142 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800143}
144
145# check to see if the supplied product is one we can build
Matt Alexanderd9c56562020-05-21 10:49:17 +0000146function check_product()
147{
Christopher Ferris55257d22017-03-23 11:08:58 -0700148 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800149 if [ ! "$T" ]; then
150 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
151 return
152 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700153 TARGET_PRODUCT=$1 \
154 TARGET_BUILD_VARIANT= \
155 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700156 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800157 get_build_var TARGET_DEVICE > /dev/null
158 # hide successful answers, but allow the errors to show
159}
160
161VARIANT_CHOICES=(user userdebug eng)
162
163# check to see if the supplied variant is valid
Matt Alexanderd9c56562020-05-21 10:49:17 +0000164function check_variant()
165{
Christopher Ferris55257d22017-03-23 11:08:58 -0700166 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800167 for v in ${VARIANT_CHOICES[@]}
168 do
Matt Alexanderd9c56562020-05-21 10:49:17 +0000169 if [ "$v" = "$1" ]
170 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800171 return 0
172 fi
173 done
174 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700175}
176
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800177
178# Add directories to PATH that are dependent on the lunch target.
179# For directories that are not lunch-specific, add them in set_global_paths
180function set_lunch_paths()
Matt Alexanderd9c56562020-05-21 10:49:17 +0000181{
Christopher Ferris55257d22017-03-23 11:08:58 -0700182 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700183 if [ ! "$T" ]; then
184 echo "Couldn't locate the top of the tree. Try setting TOP."
185 return
186 fi
187
188 ##################################################################
189 # #
190 # Read me before you modify this code #
191 # #
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800192 # This function sets ANDROID_LUNCH_BUILD_PATHS to what it is #
193 # adding to PATH, and the next time it is run, it removes that #
194 # from PATH. This is required so lunch can be run more than #
195 # once and still have working paths. #
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700196 # #
197 ##################################################################
198
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800199 # Note: on windows/cygwin, ANDROID_LUNCH_BUILD_PATHS will contain spaces
Raphael Mollc639c782011-06-20 17:25:01 -0700200 # due to "C:\Program Files" being in the path.
201
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800202 # Handle compat with the old ANDROID_BUILD_PATHS variable.
203 # TODO: Remove this after we think everyone has lunched again.
204 if [ -z "$ANDROID_LUNCH_BUILD_PATHS" -a -n "$ANDROID_BUILD_PATHS" ] ; then
205 ANDROID_LUNCH_BUILD_PATHS="$ANDROID_BUILD_PATHS"
206 ANDROID_BUILD_PATHS=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700207 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000208 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700209 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800210 # strip leading ':', if any
211 export PATH=${PATH/:%/}
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800212 ANDROID_PRE_BUILD_PATHS=
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500213 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700214
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800215 # Out with the old...
216 if [ -n "$ANDROID_LUNCH_BUILD_PATHS" ] ; then
217 export PATH=${PATH/$ANDROID_LUNCH_BUILD_PATHS/}
218 fi
Ben Chengfba67bf2014-02-25 10:27:07 -0800219
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800220 # And in with the new...
221 ANDROID_LUNCH_BUILD_PATHS=$(get_abs_build_var SOONG_HOST_OUT_EXECUTABLES)
222 ANDROID_LUNCH_BUILD_PATHS+=:$(get_abs_build_var HOST_OUT_EXECUTABLES)
Yueyao Zhuefc786a2017-04-07 14:11:54 -0700223
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800224 # Append llvm binutils prebuilts path to ANDROID_LUNCH_BUILD_PATHS.
Yi Kongdfd00b12019-05-21 16:00:04 -0700225 local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800226 ANDROID_LUNCH_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
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800231 # Append asuite prebuilts path to ANDROID_LUNCH_BUILD_PATHS.
Jim Tangb3fda302018-12-22 10:24:55 +0800232 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800233 ANDROID_LUNCH_BUILD_PATHS+=:$T/prebuilts/asuite/acloud/$os_arch
234 ANDROID_LUNCH_BUILD_PATHS+=:$T/prebuilts/asuite/aidegen/$os_arch
235 ANDROID_LUNCH_BUILD_PATHS+=:$T/prebuilts/asuite/atest/$os_arch
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800236
Colin Crosse97e6932017-06-30 16:01:45 -0700237 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
238 export JAVA_HOME=$ANDROID_JAVA_HOME
239 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800240 ANDROID_LUNCH_BUILD_PATHS+=:$ANDROID_JAVA_TOOLCHAIN
241
242 # Fix up PYTHONPATH
243 if [ -n $ANDROID_PYTHONPATH ]; then
244 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
245 fi
246 export ANDROID_PYTHONPATH=$T/development/python-packages:
247 if [ -n $VENDOR_PYTHONPATH ]; then
248 ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
249 fi
250 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500251
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800252 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700253 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
254 export OUT=$ANDROID_PRODUCT_OUT
255
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700256 unset ANDROID_HOST_OUT
257 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
258
Jiyong Parkc02b1c42020-11-03 11:06:39 +0900259 unset ANDROID_SOONG_HOST_OUT
260 export ANDROID_SOONG_HOST_OUT=$(get_abs_build_var SOONG_HOST_OUT)
261
Simran Basidd050ed2017-02-13 13:46:48 -0800262 unset ANDROID_HOST_OUT_TESTCASES
263 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
264
265 unset ANDROID_TARGET_OUT_TESTCASES
266 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
267
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800268 # Finally, set PATH
269 export PATH=$ANDROID_LUNCH_BUILD_PATHS$PATH
270}
271
272# Add directories to PATH that are NOT dependent on the lunch target.
273# For directories that are lunch-specific, add them in set_lunch_paths
274function set_global_paths()
275{
276 local T=$(gettop)
277 if [ ! "$T" ]; then
278 echo "Couldn't locate the top of the tree. Try setting TOP."
279 return
280 fi
281
282 ##################################################################
283 # #
284 # Read me before you modify this code #
285 # #
286 # This function sets ANDROID_GLOBAL_BUILD_PATHS to what it is #
287 # adding to PATH, and the next time it is run, it removes that #
288 # from PATH. This is required so envsetup.sh can be sourced #
289 # more than once and still have working paths. #
290 # #
291 ##################################################################
292
293 # Out with the old...
294 if [ -n "$ANDROID_GLOBAL_BUILD_PATHS" ] ; then
295 export PATH=${PATH/$ANDROID_GLOBAL_BUILD_PATHS/}
296 fi
297
298 # And in with the new...
299 ANDROID_GLOBAL_BUILD_PATHS=$T/build/bazel/bin
300 ANDRID_GLOBAL_BUILD_PATHS+=$T/development/scripts:$T/prebuilts/devtools/tools
301
302 # add kernel specific binaries
303 if [ $(uname -s) = Linux ] ; then
304 ANDROID_GLOBAL_BUILD_PATHS+=:$T/prebuilts/misc/linux-x86/dtc
305 ANDROID_GLOBAL_BUILD_PATHS+=:$T/prebuilts/misc/linux-x86/libufdt
306 fi
307
308 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
309 # to ensure that the corresponding 'emulator' binaries are used.
310 case $(uname -s) in
311 Darwin)
312 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
313 ;;
314 Linux)
315 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
316 ;;
317 *)
318 ANDROID_EMULATOR_PREBUILTS=
319 ;;
320 esac
321 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
322 ANDROID_GLOBAL_BUILD_PATHS+=:$ANDROID_EMULATOR_PREBUILTS
323 export ANDROID_EMULATOR_PREBUILTS
324 fi
325
326 # Finally, set PATH
327 export PATH=$ANDROID_GLOBAL_BUILD_PATHS$PATH
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700328}
329
Matt Alexanderd9c56562020-05-21 10:49:17 +0000330function printconfig()
331{
Christopher Ferris55257d22017-03-23 11:08:58 -0700332 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800333 if [ ! "$T" ]; then
334 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
335 return
336 fi
337 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338}
339
Matt Alexanderd9c56562020-05-21 10:49:17 +0000340function set_stuff_for_environment()
341{
Joe Onorato7c3a77f2022-12-05 13:05:14 -0800342 set_lunch_paths
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800343 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700344
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800345 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346}
347
Matt Alexanderd9c56562020-05-21 10:49:17 +0000348function set_sequence_number()
349{
Colin Cross88737132017-03-21 17:41:03 -0700350 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700351}
352
Makoto Onukida971062018-06-18 10:15:19 -0700353# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
354function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800355 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700356 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800357 *:"$cmd":*)
358 return 1
359 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700360 esac
361 return 0
362}
363
Matt Alexanderd9c56562020-05-21 10:49:17 +0000364function addcompletions()
365{
Ben Taitelbaum8c2c9cf2020-09-22 16:45:05 -0700366 local f=
Kenny Root52aa81c2011-07-15 11:07:06 -0700367
Jim Tanga881a252018-06-19 16:34:41 +0800368 # Keep us from trying to run in something that's neither bash nor zsh.
369 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700370 return
371 fi
372
373 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800374 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700375 return
376 fi
377
Jim Tanga881a252018-06-19 16:34:41 +0800378 local completion_files=(
MÃ¥rten Kongstadcb5c73f2022-05-04 14:08:12 +0000379 packages/modules/adb/adb.bash
Jim Tanga881a252018-06-19 16:34:41 +0800380 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800381 tools/asuite/asuite.sh
Chris Parsonsa2972972022-08-31 15:04:38 -0400382 prebuilts/bazel/common/bazel-complete.bash
Jim Tanga881a252018-06-19 16:34:41 +0800383 )
Makoto Onukida971062018-06-18 10:15:19 -0700384 # Completion can be disabled selectively to allow users to use non-standard completion.
385 # e.g.
386 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
387 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Usta Shrestha1433fb32022-05-13 14:49:40 -0400388 local T=$(gettop)
Jim Tanga881a252018-06-19 16:34:41 +0800389 for f in ${completion_files[*]}; do
Usta Shrestha1433fb32022-05-13 14:49:40 -0400390 f="$T/$f"
MÃ¥rten Kongstadcb5c73f2022-05-04 14:08:12 +0000391 if [ ! -f "$f" ]; then
392 echo "Warning: completion file $f not found"
393 elif should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700394 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700395 fi
396 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700397
Matt Alexanderd9c56562020-05-21 10:49:17 +0000398 if should_add_completion bit ; then
Makoto Onukida971062018-06-18 10:15:19 -0700399 complete -C "bit --tab" bit
400 fi
Anton Hanssonece9c482019-02-04 18:15:39 +0000401 if [ -z "$ZSH_VERSION" ]; then
402 # Doesn't work in zsh.
403 complete -o nospace -F _croot croot
Chris Parsonsa2972972022-08-31 15:04:38 -0400404 # TODO(b/244559459): Support b autocompletion for zsh
405 complete -F _bazel__complete -o nospace b
Anton Hanssonece9c482019-02-04 18:15:39 +0000406 fi
Jim Tanga881a252018-06-19 16:34:41 +0800407 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800408
Cole Faust24c36db2021-01-23 02:39:37 +0000409 complete -F _complete_android_module_names pathmod
dimitry73b84812018-12-11 18:06:00 +0100410 complete -F _complete_android_module_names gomod
Cole Faust24c36db2021-01-23 02:39:37 +0000411 complete -F _complete_android_module_names outmod
412 complete -F _complete_android_module_names installmod
Jingwen Chen83eeebb2022-10-05 02:27:07 +0000413 complete -F _complete_android_module_names bmod
dimitry73b84812018-12-11 18:06:00 +0100414 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700415}
416
Joe Onorato824608c2022-04-08 11:06:16 -0700417function multitree_lunch_help()
418{
419 echo "usage: lunch PRODUCT-VARIANT" 1>&2
420 echo " Set up android build environment based on a product short name and variant" 1>&2
421 echo 1>&2
422 echo "lunch COMBO_FILE VARIANT" 1>&2
423 echo " Set up android build environment based on a specific lunch combo file" 1>&2
424 echo " and variant." 1>&2
425 echo 1>&2
426 echo "lunch --print [CONFIG]" 1>&2
427 echo " Print the contents of a configuration. If CONFIG is supplied, that config" 1>&2
428 echo " will be flattened and printed. If CONFIG is not supplied, the currently" 1>&2
429 echo " selected config will be printed. Returns 0 on success or nonzero on error." 1>&2
430 echo 1>&2
431 echo "lunch --list" 1>&2
432 echo " List all possible combo files available in the current tree" 1>&2
433 echo 1>&2
434 echo "lunch --help" 1>&2
435 echo "lunch -h" 1>&2
436 echo " Prints this message." 1>&2
437}
438
439function multitree_lunch()
440{
441 local code
442 local results
LaMont Jonesc39e5022022-06-23 19:09:06 +0000443 # Lunch must be run in the topdir, but this way we get a clear error
444 # message, instead of FileNotFound.
445 local T=$(multitree_gettop)
446 if [ -n "$T" ]; then
LaMont Jones5151ddc2022-10-13 23:05:15 +0000447 "$T/orchestrator/build/orchestrator/core/lunch.py" "$@"
LaMont Jonesc39e5022022-06-23 19:09:06 +0000448 else
449 _multitree_lunch_error
450 return 1
451 fi
Joe Onorato824608c2022-04-08 11:06:16 -0700452 if $(echo "$1" | grep -q '^-') ; then
453 # Calls starting with a -- argument are passed directly and the function
454 # returns with the lunch.py exit code.
Spandan Dasca762052022-09-21 00:08:34 +0000455 "${T}/orchestrator/build/orchestrator/core/lunch.py" "$@"
Joe Onorato824608c2022-04-08 11:06:16 -0700456 code=$?
457 if [[ $code -eq 2 ]] ; then
458 echo 1>&2
459 multitree_lunch_help
460 return $code
461 elif [[ $code -ne 0 ]] ; then
462 return $code
463 fi
464 else
465 # All other calls go through the --lunch variant of lunch.py
Spandan Dasca762052022-09-21 00:08:34 +0000466 results=($(${T}/orchestrator/build/orchestrator/core/lunch.py --lunch "$@"))
Joe Onorato824608c2022-04-08 11:06:16 -0700467 code=$?
468 if [[ $code -eq 2 ]] ; then
469 echo 1>&2
470 multitree_lunch_help
471 return $code
472 elif [[ $code -ne 0 ]] ; then
473 return $code
474 fi
475
476 export TARGET_BUILD_COMBO=${results[0]}
477 export TARGET_BUILD_VARIANT=${results[1]}
478 fi
479}
480
Matt Alexanderd9c56562020-05-21 10:49:17 +0000481function choosetype()
482{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483 echo "Build type choices are:"
484 echo " 1. release"
485 echo " 2. debug"
486 echo
487
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800488 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700489 DEFAULT_NUM=1
490 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700491
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492 export TARGET_BUILD_TYPE=
493 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700494 while [ -z $TARGET_BUILD_TYPE ]
495 do
496 echo -n "Which would you like? ["$DEFAULT_NUM"] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000497 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800498 read ANSWER
499 else
500 echo $1
501 ANSWER=$1
502 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700503 case $ANSWER in
504 "")
505 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
506 ;;
507 1)
508 export TARGET_BUILD_TYPE=release
509 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800510 release)
511 export TARGET_BUILD_TYPE=release
512 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700513 2)
514 export TARGET_BUILD_TYPE=debug
515 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800516 debug)
517 export TARGET_BUILD_TYPE=debug
518 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700519 *)
520 echo
521 echo "I didn't understand your response. Please try again."
522 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700523 ;;
524 esac
Matt Alexanderd9c56562020-05-21 10:49:17 +0000525 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800526 break
527 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700528 done
529
Ying Wang08800fd2016-03-03 20:57:21 -0800530 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700531 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800532 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700533}
534
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800535#
536# This function isn't really right: It chooses a TARGET_PRODUCT
537# based on the list of boards. Usually, that gets you something
538# that kinda works with a generic product, but really, you should
539# pick a product by name.
540#
Matt Alexanderd9c56562020-05-21 10:49:17 +0000541function chooseproduct()
542{
Christopher Ferris55257d22017-03-23 11:08:58 -0700543 local default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000544 if [ "x$TARGET_PRODUCT" != x ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700545 default_value=$TARGET_PRODUCT
546 else
Ying Wang0a76df52015-06-08 11:57:26 -0700547 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700548 fi
549
Ying Wang08800fd2016-03-03 20:57:21 -0800550 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800551 export TARGET_PRODUCT=
552 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700553 while [ -z "$TARGET_PRODUCT" ]
554 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700555 echo -n "Which product would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000556 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800557 read ANSWER
558 else
559 echo $1
560 ANSWER=$1
561 fi
562
Matt Alexanderd9c56562020-05-21 10:49:17 +0000563 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700564 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800565 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000566 if check_product $ANSWER
567 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800568 export TARGET_PRODUCT=$ANSWER
569 else
570 echo "** Not a valid product: $ANSWER"
571 fi
572 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000573 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800574 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700575 fi
576 done
577
Ying Wang08800fd2016-03-03 20:57:21 -0800578 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700579 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800580 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581}
582
Matt Alexanderd9c56562020-05-21 10:49:17 +0000583function choosevariant()
584{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800585 echo "Variant choices are:"
586 local index=1
587 local v
588 for v in ${VARIANT_CHOICES[@]}
589 do
590 # The product name is the name of the directory containing
591 # the makefile we found, above.
592 echo " $index. $v"
593 index=$(($index+1))
594 done
595
596 local default_value=eng
597 local ANSWER
598
599 export TARGET_BUILD_VARIANT=
600 while [ -z "$TARGET_BUILD_VARIANT" ]
601 do
602 echo -n "Which would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000603 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800604 read ANSWER
605 else
606 echo $1
607 ANSWER=$1
608 fi
609
Matt Alexanderd9c56562020-05-21 10:49:17 +0000610 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800611 export TARGET_BUILD_VARIANT=$default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000612 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
613 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Guillaume Chelfice000fd2019-10-03 12:02:46 +0200614 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800615 fi
616 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000617 if check_variant $ANSWER
618 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800619 export TARGET_BUILD_VARIANT=$ANSWER
620 else
621 echo "** Not a valid variant: $ANSWER"
622 fi
623 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000624 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800625 break
626 fi
627 done
628}
629
Matt Alexanderd9c56562020-05-21 10:49:17 +0000630function choosecombo()
631{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700632 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700633
634 echo
635 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700636 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700637
638 echo
639 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700640 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800641
642 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800643 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700644 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800645 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800646 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700647}
648
Matt Alexanderd9c56562020-05-21 10:49:17 +0000649function add_lunch_combo()
650{
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800651 if [ -n "$ZSH_VERSION" ]; then
652 echo -n "${funcfiletrace[1]}: "
653 else
654 echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
655 fi
656 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 -0800657}
658
Matt Alexanderd9c56562020-05-21 10:49:17 +0000659function print_lunch_menu()
660{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661 local uname=$(uname)
Roland Levillain23c46cf2020-03-31 16:11:05 +0100662 local choices
Colin Crossfa50d402021-04-22 13:05:41 -0700663 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 +0100664 local ret=$?
665
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700666 echo
667 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700668 echo
Roland Levillain23c46cf2020-03-31 16:11:05 +0100669
Matt Alexanderd9c56562020-05-21 10:49:17 +0000670 if [ $ret -ne 0 ]
671 then
Roland Levillain23c46cf2020-03-31 16:11:05 +0100672 echo "Warning: Cannot display lunch menu."
673 echo
674 echo "Note: You can invoke lunch with an explicit target:"
675 echo
676 echo " usage: lunch [target]" >&2
677 echo
678 return
679 fi
680
Will Burr40401202022-02-07 12:12:01 +0000681 echo "Lunch menu .. Here are the common combinations:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800682
683 local i=1
684 local choice
Dan Willemsen91763e92019-10-03 15:13:12 -0700685 for choice in $(echo $choices)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800686 do
687 echo " $i. $choice"
688 i=$(($i+1))
689 done
690
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700691 echo
692}
693
Matt Alexanderd9c56562020-05-21 10:49:17 +0000694function lunch()
695{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800696 local answer
697
Steven Moreland92793dc2020-02-25 18:30:18 -0800698 if [[ $# -gt 1 ]]; then
699 echo "usage: lunch [target]" >&2
700 return 1
701 fi
702
Will Burr40401202022-02-07 12:12:01 +0000703 local used_lunch_menu=0
704
Steven Moreland92793dc2020-02-25 18:30:18 -0800705 if [ "$1" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800706 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700707 else
708 print_lunch_menu
Will Burr40401202022-02-07 12:12:01 +0000709 echo "Which would you like? [aosp_arm-eng]"
710 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 -0800711 read answer
Will Burr40401202022-02-07 12:12:01 +0000712 used_lunch_menu=1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700713 fi
714
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800715 local selection=
716
Matt Alexanderd9c56562020-05-21 10:49:17 +0000717 if [ -z "$answer" ]
718 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700719 selection=aosp_arm-eng
Matt Alexanderd9c56562020-05-21 10:49:17 +0000720 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
721 then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800722 local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
Matt Alexanderd9c56562020-05-21 10:49:17 +0000723 if [ $answer -le ${#choices[@]} ]
724 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800725 # array in zsh starts from 1 instead of 0.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000726 if [ -n "$ZSH_VERSION" ]
727 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800728 selection=${choices[$(($answer))]}
729 else
730 selection=${choices[$(($answer-1))]}
731 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800732 fi
Colin Cross88737132017-03-21 17:41:03 -0700733 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800734 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700735 fi
736
Joe Onoratoda12daf2010-06-09 18:18:31 -0700737 export TARGET_BUILD_APPS=
738
Colin Cross88737132017-03-21 17:41:03 -0700739 local product variant_and_version variant version
Colin Cross88737132017-03-21 17:41:03 -0700740 product=${selection%%-*} # Trim everything after first dash
741 variant_and_version=${selection#*-} # Trim everything up to first dash
742 if [ "$variant_and_version" != "$selection" ]; then
743 variant=${variant_and_version%%-*}
744 if [ "$variant" != "$variant_and_version" ]; then
745 version=${variant_and_version#*-}
746 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700747 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800748
Matt Alexanderd9c56562020-05-21 10:49:17 +0000749 if [ -z "$product" ]
750 then
Ying Wang08800fd2016-03-03 20:57:21 -0800751 echo
Colin Cross88737132017-03-21 17:41:03 -0700752 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700753 return 1
754 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800755
Colin Cross88737132017-03-21 17:41:03 -0700756 TARGET_PRODUCT=$product \
757 TARGET_BUILD_VARIANT=$variant \
758 TARGET_PLATFORM_VERSION=$version \
759 build_build_var_cache
Matt Alexanderd9c56562020-05-21 10:49:17 +0000760 if [ $? -ne 0 ]
761 then
Anton Hansson32fa7ee2021-06-14 17:09:58 +0100762 if [[ "$product" =~ .*_(eng|user|userdebug) ]]
763 then
764 echo "Did you mean -${product/*_/}? (dash instead of underscore)"
765 fi
Colin Cross88737132017-03-21 17:41:03 -0700766 return 1
767 fi
Colin Cross88737132017-03-21 17:41:03 -0700768 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
769 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700770 if [ -n "$version" ]; then
771 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
772 else
773 unset TARGET_PLATFORM_VERSION
774 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700775 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700776
Will Burr40401202022-02-07 12:12:01 +0000777 if [ $used_lunch_menu -eq 1 ]; then
778 echo
779 echo "Hint: next time you can simply run 'lunch $selection'"
780 fi
781
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700782 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800783
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784 set_stuff_for_environment
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700785 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800786 destroy_build_var_cache
Kousik Kumar41dacd12021-05-11 18:38:38 -0400787
788 if [[ -n "${CHECK_MU_CONFIG:-}" ]]; then
789 check_mu_config
790 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791}
792
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700793unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700794# Tab completion for lunch.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000795function _lunch()
796{
Jeff Davidson513d7a42010-08-02 10:00:44 -0700797 local cur prev opts
798 COMPREPLY=()
799 cur="${COMP_WORDS[COMP_CWORD]}"
800 prev="${COMP_WORDS[COMP_CWORD-1]}"
801
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700802 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800803 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700804 fi
805
806 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700807 return 0
808}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700809
Joe Onoratoda12daf2010-06-09 18:18:31 -0700810# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700811# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Matt Alexanderd9c56562020-05-21 10:49:17 +0000812function tapas()
813{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700814 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Elliott Hughesf71c05a2020-03-06 16:46:59 -0800815 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700816 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700817 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Colin Cross7f49a672022-01-27 18:15:53 -0800818 local keys="$(echo $* | xargs -n 1 echo | \grep -E '^(devkeys)$' | xargs)"
819 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)"
820
Joe Onoratoda12daf2010-06-09 18:18:31 -0700821
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700822 if [ "$showHelp" != "" ]; then
823 $(gettop)/build/make/tapasHelp.sh
824 return
825 fi
826
Ying Wang67f02922012-08-22 10:25:20 -0700827 if [ $(echo $arch | wc -w) -gt 1 ]; then
828 echo "tapas: Error: Multiple build archs supplied: $arch"
829 return
830 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700831 if [ $(echo $variant | wc -w) -gt 1 ]; then
832 echo "tapas: Error: Multiple build variants supplied: $variant"
833 return
834 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700835 if [ $(echo $density | wc -w) -gt 1 ]; then
836 echo "tapas: Error: Multiple densities supplied: $density"
837 return
838 fi
Colin Cross7f49a672022-01-27 18:15:53 -0800839 if [ $(echo $keys | wc -w) -gt 1 ]; then
840 echo "tapas: Error: Multiple keys supplied: $keys"
841 return
842 fi
Ying Wang67f02922012-08-22 10:25:20 -0700843
Ying Wang0a76df52015-06-08 11:57:26 -0700844 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700845 case $arch in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000846 x86) product=aosp_x86;;
847 arm64) product=aosp_arm64;;
848 x86_64) product=aosp_x86_64;;
Ying Wang67f02922012-08-22 10:25:20 -0700849 esac
Colin Cross7f49a672022-01-27 18:15:53 -0800850 if [ -n "$keys" ]; then
851 product=${product/aosp_/aosp_${keys}_}
852 fi;
853
Joe Onoratoda12daf2010-06-09 18:18:31 -0700854 if [ -z "$variant" ]; then
855 variant=eng
856 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700857 if [ -z "$apps" ]; then
858 apps=all
859 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600860 if [ -z "$density" ]; then
861 density=alldpi
862 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700863
Ying Wang67f02922012-08-22 10:25:20 -0700864 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700865 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700866 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700867 export TARGET_BUILD_TYPE=release
868 export TARGET_BUILD_APPS=$apps
869
Ying Wang08800fd2016-03-03 20:57:21 -0800870 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700871 set_stuff_for_environment
872 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800873 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700874}
875
Martin Stjernholmf692c752021-04-12 00:01:10 +0100876# Configures the build to build unbundled Android modules (APEXes).
877# Run banchan with one or more module names (from apex{} modules).
878function banchan()
879{
880 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Anton Hansson90ac61c2022-09-06 14:36:00 +0000881 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 +0100882 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100883 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 +0100884
885 if [ "$showHelp" != "" ]; then
886 $(gettop)/build/make/banchanHelp.sh
887 return
888 fi
889
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100890 if [ -z "$product" ]; then
Anton Hansson0328e322022-05-24 15:47:40 +0000891 product=arm64
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100892 elif [ $(echo $product | wc -w) -gt 1 ]; then
893 echo "banchan: Error: Multiple build archs or products supplied: $products"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100894 return
895 fi
896 if [ $(echo $variant | wc -w) -gt 1 ]; then
897 echo "banchan: Error: Multiple build variants supplied: $variant"
898 return
899 fi
900 if [ -z "$apps" ]; then
901 echo "banchan: Error: No modules supplied"
902 return
903 fi
904
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100905 case $product in
906 arm) product=module_arm;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100907 x86) product=module_x86;;
908 arm64) product=module_arm64;;
909 x86_64) product=module_x86_64;;
Anton Hansson90ac61c2022-09-06 14:36:00 +0000910 arm64only) product=module_arm64only;;
911 x86_64only) product=module_x86_64only;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100912 esac
913 if [ -z "$variant" ]; then
914 variant=eng
915 fi
916
917 export TARGET_PRODUCT=$product
918 export TARGET_BUILD_VARIANT=$variant
919 export TARGET_BUILD_DENSITY=alldpi
920 export TARGET_BUILD_TYPE=release
921
922 # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use
923 # case is different and it may diverge in the future.
924 export TARGET_BUILD_APPS=$apps
925
926 build_build_var_cache
927 set_stuff_for_environment
928 printconfig
929 destroy_build_var_cache
930}
931
Matt Alexanderd9c56562020-05-21 10:49:17 +0000932function gettop
933{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700934 local TOPFILE=build/make/core/envsetup.mk
Matt Alexanderd9c56562020-05-21 10:49:17 +0000935 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700936 # The following circumlocution ensures we remove symlinks from TOP.
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000937 (cd "$TOP"; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700938 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000939 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800940 # The following circumlocution (repeated below as well) ensures
941 # that we record the true directory name and not one that is
942 # faked up with symlink names.
943 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700944 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800945 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700946 local T=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000947 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800948 \cd ..
synergyb112a402013-07-05 19:47:47 -0700949 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700950 done
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000951 \cd "$HERE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700952 if [ -f "$T/$TOPFILE" ]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000953 echo "$T"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700954 fi
955 fi
956 fi
957}
958
Joe Onorato7cf6f972022-05-11 21:39:57 -0700959# TODO: Merge into gettop as part of launching multitree
960function multitree_gettop
961{
Spandan Dasca762052022-09-21 00:08:34 +0000962 local TOPFILE=orchestrator/build/make/core/envsetup.mk
Joe Onorato7cf6f972022-05-11 21:39:57 -0700963 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
964 # The following circumlocution ensures we remove symlinks from TOP.
965 (cd "$TOP"; PWD= /bin/pwd)
966 else
967 if [ -f $TOPFILE ] ; then
968 # The following circumlocution (repeated below as well) ensures
969 # that we record the true directory name and not one that is
970 # faked up with symlink names.
971 PWD= /bin/pwd
972 else
973 local HERE=$PWD
974 local T=
975 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
976 \cd ..
977 T=`PWD= /bin/pwd -P`
978 done
979 \cd "$HERE"
980 if [ -f "$T/$TOPFILE" ]; then
981 echo "$T"
982 fi
983 fi
984 fi
985}
986
Matt Alexanderd9c56562020-05-21 10:49:17 +0000987function croot()
988{
Christopher Ferris55257d22017-03-23 11:08:58 -0700989 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700990 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700991 if [ "$1" ]; then
992 \cd $(gettop)/$1
993 else
994 \cd $(gettop)
995 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700996 else
997 echo "Couldn't locate the top of the tree. Try setting TOP."
998 fi
999}
1000
Matt Alexanderd9c56562020-05-21 10:49:17 +00001001function _croot()
1002{
Anton Hanssonece9c482019-02-04 18:15:39 +00001003 local T=$(gettop)
1004 if [ "$T" ]; then
1005 local cur="${COMP_WORDS[COMP_CWORD]}"
1006 k=0
1007 for c in $(compgen -d ${T}/${cur}); do
1008 COMPREPLY[k++]=${c#${T}/}/
1009 done
1010 fi
1011}
1012
Matt Alexanderd9c56562020-05-21 10:49:17 +00001013function cproj()
1014{
Colin Cross6cdc5d22017-10-20 11:37:33 -07001015 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001016 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -07001017 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001018 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1019 T=$PWD
1020 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001021 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001022 return
1023 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001024 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001025 done
Ying Wang9cd17642012-12-13 10:52:07 -08001026 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001027 echo "can't find Android.mk"
1028}
1029
Daniel Sandler47e0a882013-07-30 13:23:52 -04001030# simplified version of ps; output in the form
1031# <pid> <procname>
1032function qpid() {
1033 local prepend=''
1034 local append=''
Matt Alexanderd9c56562020-05-21 10:49:17 +00001035 if [ "$1" = "--exact" ]; then
Daniel Sandler47e0a882013-07-30 13:23:52 -04001036 prepend=' '
1037 append='$'
1038 shift
Matt Alexanderd9c56562020-05-21 10:49:17 +00001039 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001040 echo "usage: qpid [[--exact] <process name|pid>"
1041 return 255
1042 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001043
1044 local EXE="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001045 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001046 qpid | \grep "$prepend$EXE$append"
1047 else
1048 adb shell ps \
1049 | tr -d '\r' \
1050 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1051 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001052}
1053
Steven Moreland74114f12020-09-10 01:23:32 +00001054# syswrite - disable verity, reboot if needed, and remount image
1055#
1056# Easy way to make system.img/etc writable
1057function syswrite() {
1058 adb wait-for-device && adb root || return 1
Frederick Maylee59a8792022-08-22 22:40:23 +00001059 if [[ $(adb disable-verity | grep -i "reboot") ]]; then
Steven Moreland74114f12020-09-10 01:23:32 +00001060 echo "rebooting"
1061 adb reboot && adb wait-for-device && adb root || return 1
1062 fi
1063 adb wait-for-device && adb remount || return 1
1064}
1065
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001066# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001067# that has the core-file-size limit set correctly
1068#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001069# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001070# if its core-file-size limit is not set already.
1071# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1072
Matt Alexanderd9c56562020-05-21 10:49:17 +00001073function coredump_setup()
1074{
1075 echo "Getting root...";
1076 adb root;
1077 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001078
Matt Alexanderd9c56562020-05-21 10:49:17 +00001079 echo "Remounting root partition read-write...";
1080 adb shell mount -w -o remount -t rootfs rootfs;
1081 sleep 1;
1082 adb wait-for-device;
1083 adb shell mkdir -p /cores;
1084 adb shell mount -t tmpfs tmpfs /cores;
1085 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001086
Matt Alexanderd9c56562020-05-21 10:49:17 +00001087 echo "Granting SELinux permission to dump in /cores...";
1088 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001089
Matt Alexanderd9c56562020-05-21 10:49:17 +00001090 echo "Set core pattern.";
1091 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001092
Ying Wang08800fd2016-03-03 20:57:21 -08001093 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001094}
1095
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001096# coredump_enable - enable core dumps for the specified process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001097# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001098#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001099# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001100# dump to actually be generated.
1101
Matt Alexanderd9c56562020-05-21 10:49:17 +00001102function coredump_enable()
1103{
1104 local PID=$1;
Ying Wang08800fd2016-03-03 20:57:21 -08001105 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001106 printf "Expecting a PID!\n";
1107 return;
1108 fi;
1109 echo "Setting core limit for $PID to infinite...";
xi yuaddf4832022-05-26 12:41:21 +00001110 adb shell /system/bin/ulimit -P $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001111}
1112
1113# core - send SIGV and pull the core for process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001114# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001115#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001116# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001117# enabled globally.
1118
Matt Alexanderd9c56562020-05-21 10:49:17 +00001119function core()
1120{
1121 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001122
Ying Wang08800fd2016-03-03 20:57:21 -08001123 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001124 printf "Expecting a PID!\n";
1125 return;
1126 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001127
Matt Alexanderd9c56562020-05-21 10:49:17 +00001128 local CORENAME=core.$PID;
1129 local COREPATH=/cores/$CORENAME;
1130 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001131
Matt Alexanderd9c56562020-05-21 10:49:17 +00001132 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001133
Matt Alexanderd9c56562020-05-21 10:49:17 +00001134 local done=0;
Ying Wang08800fd2016-03-03 20:57:21 -08001135 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
Matt Alexanderd9c56562020-05-21 10:49:17 +00001136 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1137 adb shell kill -$SIG $PID;
1138 sleep 1;
1139 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001140
Matt Alexanderd9c56562020-05-21 10:49:17 +00001141 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1142 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001143}
1144
Christopher Tate744ee802009-11-12 15:33:08 -08001145# systemstack - dump the current stack trace of all threads in the system process
1146# to the usual ANR traces file
Matt Alexanderd9c56562020-05-21 10:49:17 +00001147function systemstack()
1148{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001149 stacks system_server
1150}
1151
Michael Wrightaeed7212014-06-19 19:58:12 -07001152# Read the ELF header from /proc/$PID/exe to determine if the process is
1153# 64-bit.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001154function is64bit()
1155{
Ben Chengfba67bf2014-02-25 10:27:07 -08001156 local PID="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001157 if [ "$PID" ] ; then
1158 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001159 echo "64"
1160 else
1161 echo ""
1162 fi
1163 else
1164 echo ""
1165 fi
1166}
1167
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001168case `uname -s` in
1169 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001170 function sgrep()
1171 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001172 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 -04001173 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001174 }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001175
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001176 ;;
1177 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001178 function sgrep()
1179 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001180 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 -04001181 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001182 }
1183 ;;
1184esac
1185
Matt Alexanderd9c56562020-05-21 10:49:17 +00001186function gettargetarch
1187{
Raghu Gandham8da43102012-07-25 19:57:22 -07001188 get_build_var TARGET_ARCH
1189}
1190
Matt Alexanderd9c56562020-05-21 10:49:17 +00001191function ggrep()
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 "*\.gradle" \
1194 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001195}
1196
Matt Alexanderd9c56562020-05-21 10:49:17 +00001197function gogrep()
1198{
Orion Hodson831472d2019-10-25 11:35:15 +01001199 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
1200 -exec grep --color -n "$@" {} +
1201}
1202
Matt Alexanderd9c56562020-05-21 10:49:17 +00001203function jgrep()
1204{
Mike Frysinger5e479732015-09-22 18:13:48 -04001205 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1206 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001207}
1208
Alistair Delva176e5342021-02-22 13:31:26 -08001209function rsgrep()
Jeff Vander Stoep1431ab82021-02-02 19:18:26 +01001210{
1211 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rs" \
1212 -exec grep --color -n "$@" {} +
1213}
1214
Taesu Leeea0cecd2020-10-28 11:05:18 +09001215function ktgrep()
1216{
1217 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.kt" \
1218 -exec grep --color -n "$@" {} +
1219}
1220
Matt Alexanderd9c56562020-05-21 10:49:17 +00001221function cgrep()
1222{
Mike Frysinger5e479732015-09-22 18:13:48 -04001223 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' \) \
1224 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001225}
1226
Matt Alexanderd9c56562020-05-21 10:49:17 +00001227function resgrep()
1228{
Christopher Ferris55257d22017-03-23 11:08:58 -07001229 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001230 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1231 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1232 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001233}
1234
Matt Alexanderd9c56562020-05-21 10:49:17 +00001235function mangrep()
1236{
Mike Frysinger5e479732015-09-22 18:13:48 -04001237 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1238 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001239}
1240
Matt Alexanderd9c56562020-05-21 10:49:17 +00001241function owngrep()
1242{
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -06001243 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
1244 -exec grep --color -n "$@" {} +
1245}
1246
Matt Alexanderd9c56562020-05-21 10:49:17 +00001247function sepgrep()
1248{
Mike Frysinger5e479732015-09-22 18:13:48 -04001249 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1250 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001251}
1252
Matt Alexanderd9c56562020-05-21 10:49:17 +00001253function rcgrep()
1254{
Mike Frysinger5e479732015-09-22 18:13:48 -04001255 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1256 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001257}
1258
DroidFreak32a2781982020-11-26 11:30:19 -05001259function pygrep()
1260{
1261 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.py" \
1262 -exec grep --color -n "$@" {} +
1263}
1264
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001265case `uname -s` in
1266 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001267 function mgrep()
1268 {
Orion Hodson831472d2019-10-25 11:35:15 +01001269 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 -04001270 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001271 }
1272
Matt Alexanderd9c56562020-05-21 10:49:17 +00001273 function treegrep()
1274 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001275 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 -04001276 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001277 }
1278
1279 ;;
1280 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001281 function mgrep()
1282 {
Orion Hodson831472d2019-10-25 11:35:15 +01001283 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 -04001284 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001285 }
1286
Matt Alexanderd9c56562020-05-21 10:49:17 +00001287 function treegrep()
1288 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001289 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 -04001290 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001291 }
1292
1293 ;;
1294esac
1295
Matt Alexanderd9c56562020-05-21 10:49:17 +00001296function getprebuilt
1297{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001298 get_abs_build_var ANDROID_PREBUILTS
1299}
1300
Matt Alexanderd9c56562020-05-21 10:49:17 +00001301function tracedmdump()
1302{
Christopher Ferris55257d22017-03-23 11:08:58 -07001303 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001304 if [ ! "$T" ]; then
1305 echo "Couldn't locate the top of the tree. Try setting TOP."
1306 return
1307 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001308 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001309 local arch=$(gettargetarch)
1310 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001311
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001312 local TRACE=$1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001313 if [ ! "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001314 echo "usage: tracedmdump tracename"
1315 return
1316 fi
1317
Matt Alexanderd9c56562020-05-21 10:49:17 +00001318 if [ ! -r "$KERNEL" ] ; then
Jack Veenstra60116fc2009-04-09 18:12:34 -07001319 echo "Error: cannot find kernel: '$KERNEL'"
1320 return
1321 fi
1322
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001323 local BASETRACE=$(basename $TRACE)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001324 if [ "$BASETRACE" = "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001325 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1326 fi
1327
1328 echo "post-processing traces..."
1329 rm -f $TRACE/qtrace.dexlist
1330 post_trace $TRACE
1331 if [ $? -ne 0 ]; then
1332 echo "***"
1333 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1334 echo "***"
1335 return
1336 fi
1337 echo "generating dexlist output..."
1338 /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
1339 echo "generating dmtrace data..."
1340 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1341 echo "generating html file..."
1342 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1343 echo "done, see $TRACE/dmtrace.html for details"
1344 echo "or run:"
1345 echo " traceview $TRACE/dmtrace"
1346}
1347
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001348# communicate with a running device or emulator, set up necessary state,
1349# and run the hat command.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001350function runhat()
1351{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001352 # process standard adb options
1353 local adbTarget=""
Matt Alexanderd9c56562020-05-21 10:49:17 +00001354 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001355 adbTarget=$1
1356 shift 1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001357 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001358 adbTarget="$1 $2"
1359 shift 2
1360 fi
1361 local adbOptions=${adbTarget}
Matt Alexanderd9c56562020-05-21 10:49:17 +00001362 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001363
1364 # runhat options
1365 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001366
Matt Alexanderd9c56562020-05-21 10:49:17 +00001367 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001368 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001369 return
1370 fi
1371
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001372 # confirm hat is available
1373 if [ -z $(which hat) ]; then
1374 echo "hat is not available in this configuration."
1375 return
1376 fi
1377
Andy McFaddenb6289852010-07-12 08:00:19 -07001378 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001379 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001380 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001381 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001382 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001383 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001384 echo -n "> "
1385 read
1386
The Android Open Source Project88b60792009-03-03 19:28:42 -08001387 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001388
The Android Open Source Project88b60792009-03-03 19:28:42 -08001389 echo "Retrieving file $devFile..."
1390 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001391
The Android Open Source Project88b60792009-03-03 19:28:42 -08001392 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001393
The Android Open Source Project88b60792009-03-03 19:28:42 -08001394 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001395 echo "View the output by pointing your browser at http://localhost:7000/"
1396 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001397 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001398}
1399
Matt Alexanderd9c56562020-05-21 10:49:17 +00001400function getbugreports()
1401{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001402 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001403
1404 if [ ! "$reports" ]; then
1405 echo "Could not locate any bugreports."
1406 return
1407 fi
1408
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001409 local report
1410 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001411 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001412 echo "/sdcard/bugreports/${report}"
1413 adb pull /sdcard/bugreports/${report} ${report}
1414 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001415 done
1416}
1417
Matt Alexanderd9c56562020-05-21 10:49:17 +00001418function getsdcardpath()
1419{
Victoria Lease1b296b42012-08-21 15:44:06 -07001420 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1421}
1422
Matt Alexanderd9c56562020-05-21 10:49:17 +00001423function getscreenshotpath()
1424{
Victoria Lease1b296b42012-08-21 15:44:06 -07001425 echo "$(getsdcardpath)/Pictures/Screenshots"
1426}
1427
Matt Alexanderd9c56562020-05-21 10:49:17 +00001428function getlastscreenshot()
1429{
Victoria Lease1b296b42012-08-21 15:44:06 -07001430 local screenshot_path=$(getscreenshotpath)
1431 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 +00001432 if [ "$screenshot" = "" ]; then
Victoria Lease1b296b42012-08-21 15:44:06 -07001433 echo "No screenshots found."
1434 return
1435 fi
1436 echo "${screenshot}"
1437 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1438}
1439
Matt Alexanderd9c56562020-05-21 10:49:17 +00001440function startviewserver()
1441{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001442 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001443 if [ $# -gt 0 ]; then
1444 port=$1
1445 fi
1446 adb shell service call window 1 i32 $port
1447}
1448
Matt Alexanderd9c56562020-05-21 10:49:17 +00001449function stopviewserver()
1450{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001451 adb shell service call window 2
1452}
1453
Matt Alexanderd9c56562020-05-21 10:49:17 +00001454function isviewserverstarted()
1455{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001456 adb shell service call window 3
1457}
1458
Matt Alexanderd9c56562020-05-21 10:49:17 +00001459function key_home()
1460{
Romain Guyb84049a2010-10-04 16:56:11 -07001461 adb shell input keyevent 3
1462}
1463
Matt Alexanderd9c56562020-05-21 10:49:17 +00001464function key_back()
1465{
Romain Guyb84049a2010-10-04 16:56:11 -07001466 adb shell input keyevent 4
1467}
1468
Matt Alexanderd9c56562020-05-21 10:49:17 +00001469function key_menu()
1470{
Romain Guyb84049a2010-10-04 16:56:11 -07001471 adb shell input keyevent 82
1472}
1473
Matt Alexanderd9c56562020-05-21 10:49:17 +00001474function smoketest()
1475{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001476 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1477 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1478 return
1479 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001480 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001481 if [ ! "$T" ]; then
1482 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1483 return
1484 fi
1485
Ying Wang9cd17642012-12-13 10:52:07 -08001486 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001487 adb uninstall com.android.smoketest > /dev/null &&
1488 adb uninstall com.android.smoketest.tests > /dev/null &&
1489 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1490 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1491 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1492}
1493
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001494# simple shortcut to the runtest command
Matt Alexanderd9c56562020-05-21 10:49:17 +00001495function runtest()
1496{
Christopher Ferris55257d22017-03-23 11:08:58 -07001497 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001498 if [ ! "$T" ]; then
1499 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1500 return
1501 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001502 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001503}
1504
The Android Open Source Project88b60792009-03-03 19:28:42 -08001505function godir () {
1506 if [[ -z "$1" ]]; then
1507 echo "Usage: godir <regex>"
1508 return
1509 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001510 local T=$(gettop)
1511 local FILELIST
Matt Alexanderd9c56562020-05-21 10:49:17 +00001512 if [ ! "$OUT_DIR" = "" ]; then
Brian Carlstromf2257422015-09-30 20:28:54 -07001513 mkdir -p $OUT_DIR
1514 FILELIST=$OUT_DIR/filelist
1515 else
1516 FILELIST=$T/filelist
1517 fi
1518 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001519 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001520 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001521 echo " Done"
1522 echo ""
1523 fi
1524 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001525 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
Matt Alexanderd9c56562020-05-21 10:49:17 +00001526 if [[ ${#lines[@]} = 0 ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001527 echo "Not found"
1528 return
1529 fi
1530 local pathname
1531 local choice
1532 if [[ ${#lines[@]} > 1 ]]; then
1533 while [[ -z "$pathname" ]]; do
1534 local index=1
1535 local line
1536 for line in ${lines[@]}; do
1537 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001538 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001539 done
1540 echo
1541 echo -n "Select one: "
1542 unset choice
1543 read choice
1544 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1545 echo "Invalid choice"
1546 continue
1547 fi
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001548 pathname=${lines[@]:$(($choice-1)):1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001549 done
1550 else
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001551 pathname=${lines[@]:0:1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001552 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001553 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001554}
1555
Steven Moreland62054a42018-12-06 10:11:40 -08001556# Update module-info.json in out.
1557function refreshmod() {
1558 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1559 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1560 return 1
1561 fi
1562
1563 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1564
1565 # for the output of the next command
1566 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1567
1568 # Note, can't use absolute path because of the way make works.
Alessandro Astonec8771be2020-05-10 11:27:57 +02001569 m $(get_build_var PRODUCT_OUT)/module-info.json \
Steven Moreland62054a42018-12-06 10:11:40 -08001570 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1571}
1572
Cole Faust3e192382021-10-25 13:29:15 -07001573# Verifies that module-info.txt exists, returning nonzero if it doesn't.
Cole Faust24c36db2021-01-23 02:39:37 +00001574function verifymodinfo() {
Steven Moreland62054a42018-12-06 10:11:40 -08001575 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001576 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
1577 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1578 fi
Steven Moreland62054a42018-12-06 10:11:40 -08001579 return 1
1580 fi
1581
1582 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001583 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
Cole Faust3e192382021-10-25 13:29:15 -07001584 echo "Could not find module-info.json. Please run 'refreshmod' first." >&2
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001585 fi
1586 return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001587 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001588}
1589
Cole Faust5d825b72022-10-26 18:16:44 -07001590# List all modules for the current device, as cached in all_modules.txt. If any build change is
1591# made and it should be reflected in the output, you should run `m nothing` first.
Cole Faust24c36db2021-01-23 02:39:37 +00001592function allmod() {
Cole Faust5d825b72022-10-26 18:16:44 -07001593 cat $ANDROID_PRODUCT_OUT/all_modules.txt 2>/dev/null
Steven Moreland62054a42018-12-06 10:11:40 -08001594}
1595
Jingwen Chen83eeebb2022-10-05 02:27:07 +00001596# Return the Bazel label of a Soong module if it is converted with bp2build.
1597function bmod()
1598(
1599 if [ $# -ne 1 ]; then
1600 echo "usage: bmod <module>" >&2
1601 return 1
1602 fi
1603
1604 # We could run bp2build here, but it might trigger bp2build invalidation
1605 # when used with `b` (e.g. --run_soong_tests) and/or add unnecessary waiting
1606 # time overhead.
1607 #
1608 # For a snappy result, use the latest generated version in soong_injection,
1609 # and ask users to run m bp2build if it doesn't exist.
Jingwen Chenacdcaa02022-10-13 07:24:24 +00001610 converted_json="$(get_abs_build_var OUT_DIR)/soong/soong_injection/metrics/converted_modules_path_map.json"
Jingwen Chen83eeebb2022-10-05 02:27:07 +00001611
Jingwen Chenacdcaa02022-10-13 07:24:24 +00001612 if [ ! -f ${converted_json} ]; then
Jingwen Chen83eeebb2022-10-05 02:27:07 +00001613 echo "bp2build files not found. Have you ran 'm bp2build'?" >&2
1614 return 1
1615 fi
1616
1617 local target_label=$(python3 -c "import json
1618module = '$1'
1619converted_json='$converted_json'
1620bp2build_converted_map = json.load(open(converted_json))
1621if module not in bp2build_converted_map:
1622 exit(1)
1623print(bp2build_converted_map[module] + ':' + module)")
1624
1625 if [ -z "${target_label}" ]; then
1626 echo "$1 is not converted to Bazel." >&2
1627 return 1
1628 else
1629 echo "${target_label}"
1630 fi
1631)
1632
Joe Onorato2c1aa472021-02-25 16:42:39 -08001633# Get the path of a specific module in the android tree, as cached in module-info.json.
1634# If any build change is made, and it should be reflected in the output, you should run
1635# 'refreshmod' first. Note: This is the inverse of dirmods.
Rett Berg78d1c932019-01-24 14:34:23 -08001636function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001637 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001638 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001639 return 1
1640 fi
1641
Cole Faust24c36db2021-01-23 02:39:37 +00001642 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001643
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001644 local relpath=$(python3 -c "import json, os
Steven Moreland62054a42018-12-06 10:11:40 -08001645module = '$1'
1646module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1647if module not in module_info:
1648 exit(1)
LuK1337b6a78192020-01-12 03:12:17 +01001649print(module_info[module]['path'][0])" 2>/dev/null)
Steven Moreland62054a42018-12-06 10:11:40 -08001650
1651 if [ -z "$relpath" ]; then
1652 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1653 return 1
1654 else
Rett Berg78d1c932019-01-24 14:34:23 -08001655 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001656 fi
1657}
1658
Joe Onorato2c1aa472021-02-25 16:42:39 -08001659# Get the path of a specific module in the android tree, as cached in module-info.json.
1660# If any build change is made, and it should be reflected in the output, you should run
1661# 'refreshmod' first. Note: This is the inverse of pathmod.
1662function dirmods() {
1663 if [[ $# -ne 1 ]]; then
1664 echo "usage: dirmods <path>" >&2
1665 return 1
1666 fi
1667
1668 verifymodinfo || return 1
1669
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001670 python3 -c "import json, os
Joe Onorato2c1aa472021-02-25 16:42:39 -08001671dir = '$1'
1672while dir.endswith('/'):
1673 dir = dir[:-1]
1674prefix = dir + '/'
1675module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1676results = set()
1677for m in module_info.values():
1678 for path in m.get(u'path', []):
1679 if path == dir or path.startswith(prefix):
1680 name = m.get(u'module_name')
1681 if name:
1682 results.add(name)
1683for name in sorted(results):
1684 print(name)
1685"
1686}
1687
1688
Rett Berg78d1c932019-01-24 14:34:23 -08001689# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1690# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1691function gomod() {
1692 if [[ $# -ne 1 ]]; then
1693 echo "usage: gomod <module>" >&2
1694 return 1
1695 fi
1696
1697 local path="$(pathmod $@)"
1698 if [ -z "$path" ]; then
1699 return 1
1700 fi
1701 cd $path
1702}
1703
Cole Faust24c36db2021-01-23 02:39:37 +00001704# Gets the list of a module's installed outputs, as cached in module-info.json.
1705# If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first.
1706function outmod() {
1707 if [[ $# -ne 1 ]]; then
1708 echo "usage: outmod <module>" >&2
1709 return 1
1710 fi
1711
1712 verifymodinfo || return 1
1713
1714 local relpath
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001715 relpath=$(python3 -c "import json, os
Cole Faust24c36db2021-01-23 02:39:37 +00001716module = '$1'
1717module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1718if module not in module_info:
1719 exit(1)
1720for output in module_info[module]['installed']:
1721 print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null)
1722
1723 if [ $? -ne 0 ]; then
1724 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2
1725 return 1
1726 elif [ ! -z "$relpath" ]; then
1727 echo "$relpath"
1728 fi
1729}
1730
1731# adb install a module's apk, as cached in module-info.json. If any build change
1732# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1733# Usage: installmod [adb install arguments] <module>
1734# For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk
1735function installmod() {
1736 if [[ $# -eq 0 ]]; then
1737 echo "usage: installmod [adb install arguments] <module>" >&2
Cole Faust3e192382021-10-25 13:29:15 -07001738 echo "" >&2
1739 echo "Only flags to be passed after the \"install\" in adb install are supported," >&2
1740 echo "with the exception of -s. If -s is passed it will be placed before the \"install\"." >&2
1741 echo "-s must be the first flag passed if it exists." >&2
Cole Faust24c36db2021-01-23 02:39:37 +00001742 return 1
1743 fi
1744
1745 local _path
1746 _path=$(outmod ${@:$#:1})
1747 if [ $? -ne 0 ]; then
1748 return 1
1749 fi
1750
1751 _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1)
1752 if [ -z "$_path" ]; then
1753 echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2
1754 return 1
1755 fi
Cole Faust3e192382021-10-25 13:29:15 -07001756 local serial_device=""
1757 if [[ "$1" == "-s" ]]; then
1758 if [[ $# -le 2 ]]; then
1759 echo "-s requires an argument" >&2
1760 return 1
1761 fi
1762 serial_device="-s $2"
1763 shift 2
1764 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001765 local length=$(( $# - 1 ))
Cole Faust3e192382021-10-25 13:29:15 -07001766 echo adb $serial_device install ${@:1:$length} $_path
1767 adb $serial_device install ${@:1:$length} $_path
Cole Faust24c36db2021-01-23 02:39:37 +00001768}
1769
dimitry73b84812018-12-11 18:06:00 +01001770function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001771 local word=${COMP_WORDS[COMP_CWORD]}
Cole Faust5d825b72022-10-26 18:16:44 -07001772 COMPREPLY=( $(allmod | grep -E "^$word") )
Steven Moreland62054a42018-12-06 10:11:40 -08001773}
1774
Alex Rayf0d08eb2013-03-08 15:15:06 -08001775# Print colored exit condition
1776function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001777 "$@"
1778 local retval=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +00001779 if [ $retval -ne 0 ]
1780 then
Jacky Cao89483b82015-05-15 22:12:53 +08001781 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001782 else
Jacky Cao89483b82015-05-15 22:12:53 +08001783 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001784 fi
1785 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001786}
1787
Matt Alexanderd9c56562020-05-21 10:49:17 +00001788function get_make_command()
1789{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001790 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1791 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001792 # Always use the real make if -C is passed in
1793 for arg in "$@"; do
1794 if [[ $arg == -C* ]]; then
1795 echo command make
1796 return
1797 fi
1798 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001799 echo build/soong/soong_ui.bash --make-mode
1800 else
1801 echo command make
1802 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001803}
1804
Matt Alexanderd9c56562020-05-21 10:49:17 +00001805function _wrap_build()
1806{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001807 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1808 "$@"
1809 return $?
1810 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001811 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001812 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001813 local ret=$?
1814 local end_time=$(date +"%s")
1815 local tdiff=$(($end_time-$start_time))
1816 local hours=$(($tdiff / 3600 ))
1817 local mins=$((($tdiff % 3600) / 60))
1818 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001819 local ncolors=$(tput colors 2>/dev/null)
1820 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001821 color_failed=$'\E'"[0;31m"
1822 color_success=$'\E'"[0;32m"
Kousik Kumar09af2542021-08-19 16:13:32 -04001823 color_warning=$'\E'"[0;33m"
Jacky Cao89483b82015-05-15 22:12:53 +08001824 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001825 else
1826 color_failed=""
1827 color_success=""
1828 color_reset=""
1829 fi
Kousik Kumar09af2542021-08-19 16:13:32 -04001830
1831 if [[ "x${USE_RBE}" == "x" && $mins -gt 15 && "${ANDROID_BUILD_ENVIRONMENT_CONFIG}" == "googler" ]]; then
1832 echo
1833 echo "${color_warning}Start using RBE (http://go/build-fast) to get faster builds!${color_reset}"
1834 fi
1835
Ed Heylcc6be0a2014-06-18 14:55:58 -07001836 echo
Matt Alexanderd9c56562020-05-21 10:49:17 +00001837 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001838 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001839 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001840 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001841 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +00001842 if [ $hours -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001843 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001844 elif [ $mins -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001845 printf "(%02g:%02g (mm:ss))" $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001846 elif [ $secs -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001847 printf "(%s seconds)" $secs
1848 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001849 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001850 echo
1851 return $ret
1852}
1853
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001854function _trigger_build()
1855(
1856 local -r bc="$1"; shift
LaMont Jonesc39e5022022-06-23 19:09:06 +00001857 local T=$(gettop)
1858 if [ -n "$T" ]; then
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001859 _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
1860 else
Jingwen Chend728ee12021-05-18 06:02:53 +00001861 >&2 echo "Couldn't locate the top of the tree. Try setting TOP."
1862 return 1
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001863 fi
1864)
1865
1866function m()
1867(
1868 _trigger_build "all-modules" "$@"
1869)
1870
1871function mm()
1872(
1873 _trigger_build "modules-in-a-dir-no-deps" "$@"
1874)
1875
1876function mmm()
1877(
1878 _trigger_build "modules-in-dirs-no-deps" "$@"
1879)
1880
1881function mma()
1882(
1883 _trigger_build "modules-in-a-dir" "$@"
1884)
1885
1886function mmma()
1887(
1888 _trigger_build "modules-in-dirs" "$@"
1889)
1890
Matt Alexanderd9c56562020-05-21 10:49:17 +00001891function make()
1892{
Dan Willemsene9842242017-07-28 13:00:13 -07001893 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001894}
1895
Joe Onorato7cf6f972022-05-11 21:39:57 -07001896function _multitree_lunch_error()
1897{
1898 >&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."
1899}
1900
1901function multitree_build()
1902{
LaMont Jonesc39e5022022-06-23 19:09:06 +00001903 local T=$(multitree_gettop)
1904 if [ -n "$T" ]; then
Spandan Dasca762052022-09-21 00:08:34 +00001905 "$T/orchestrator/build/orchestrator/core/orchestrator.py" "$@"
Joe Onorato7cf6f972022-05-11 21:39:57 -07001906 else
1907 _multitree_lunch_error
1908 return 1
1909 fi
1910}
1911
Matt Alexanderd9c56562020-05-21 10:49:17 +00001912function provision()
1913{
David Zeuthen1b126ff2015-09-30 17:10:48 -04001914 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1915 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1916 return 1
1917 fi
1918 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1919 echo "There is no provisioning script for the device." >&2
1920 return 1
1921 fi
1922
1923 # Check if user really wants to do this.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001924 if [ "$1" = "--no-confirmation" ]; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001925 shift 1
1926 else
1927 echo "This action will reflash your device."
1928 echo ""
1929 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1930 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001931 echo -n "Are you sure you want to do this (yes/no)? "
1932 read
Matt Alexanderd9c56562020-05-21 10:49:17 +00001933 if [[ "${REPLY}" != "yes" ]] ; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001934 echo "Not taking any action. Exiting." >&2
1935 return 1
1936 fi
1937 fi
1938 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1939}
1940
Jim Tanga881a252018-06-19 16:34:41 +08001941# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001942function enable_zsh_completion() {
1943 # Don't override user's options if bash-style completion is already enabled.
1944 if ! declare -f complete >/dev/null; then
1945 autoload -U compinit && compinit
1946 autoload -U bashcompinit && bashcompinit
1947 fi
Jim Tanga881a252018-06-19 16:34:41 +08001948}
1949
1950function validate_current_shell() {
1951 local current_sh="$(ps -o command -p $$)"
1952 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001953 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001954 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001955 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001956 *zsh*)
1957 function check_type() { type "$1"; }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001958 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001959 *)
Jim Tanga881a252018-06-19 16:34:41 +08001960 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 -07001961 ;;
1962 esac
Jim Tanga881a252018-06-19 16:34:41 +08001963}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001964
1965# Execute the contents of any vendorsetup.sh files we can find.
Dan Willemsend855a722019-02-12 15:52:36 -08001966# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
1967# load those.
1968#
1969# This allows loading only approved vendorsetup.sh files
Jim Tanga881a252018-06-19 16:34:41 +08001970function source_vendorsetup() {
Jim Tangc4dba1d2019-07-25 16:54:27 +08001971 unset VENDOR_PYTHONPATH
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001972 local T="$(gettop)"
Dan Willemsend855a722019-02-12 15:52:36 -08001973 allowed=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001974 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 -08001975 if [ -n "$allowed" ]; then
1976 echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
1977 echo " $allowed"
1978 echo " $f"
1979 return
1980 fi
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001981 allowed="$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001982 done
1983
1984 allowed_files=
1985 [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
Jim Tanga881a252018-06-19 16:34:41 +08001986 for dir in device vendor product; do
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001987 for f in $(cd "$T" && test -d $dir && \
Jim Tanga881a252018-06-19 16:34:41 +08001988 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001989
1990 if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001991 echo "including $f"; . "$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001992 else
1993 echo "ignoring $f, not in $allowed"
1994 fi
Jim Tanga881a252018-06-19 16:34:41 +08001995 done
1996 done
1997}
Kenny Root52aa81c2011-07-15 11:07:06 -07001998
Dan Albertbab814f2020-08-26 15:34:53 -07001999function showcommands() {
2000 local T=$(gettop)
2001 if [[ -z "$TARGET_PRODUCT" ]]; then
2002 >&2 echo "TARGET_PRODUCT not set. Run lunch."
2003 return
2004 fi
2005 case $(uname -s) in
2006 Darwin)
2007 PREBUILT_NAME=darwin-x86
2008 ;;
2009 Linux)
2010 PREBUILT_NAME=linux-x86
2011 ;;
2012 *)
2013 >&2 echo Unknown host $(uname -s)
2014 return
2015 ;;
2016 esac
Jingwen Chenacdcaa02022-10-13 07:24:24 +00002017 OUT_DIR="$(get_abs_build_var OUT_DIR)"
Dan Albertbab814f2020-08-26 15:34:53 -07002018 if [[ "$1" == "--regenerate" ]]; then
2019 shift 1
2020 NINJA_ARGS="-t commands $@" m
2021 else
2022 (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \
2023 -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \
2024 -t commands "$@")
2025 fi
2026}
2027
Cole Faust45844ab2022-08-30 13:59:07 -07002028function avbtool() {
2029 if [[ ! -f "$ANDROID_SOONG_HOST_OUT"/bin/avbtool ]]; then
2030 m avbtool
2031 fi
2032 "$ANDROID_SOONG_HOST_OUT"/bin/avbtool $@
2033}
2034
Jim Tanga881a252018-06-19 16:34:41 +08002035validate_current_shell
Joe Onorato7c3a77f2022-12-05 13:05:14 -08002036set_global_paths
Jim Tanga881a252018-06-19 16:34:41 +08002037source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07002038addcompletions
Joe Onorato7c3a77f2022-12-05 13:05:14 -08002039