blob: 3709999ff4bd1906c1b57dd000cbd502b3d48a84 [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
Matt Alexanderd9c56562020-05-21 10:49:17 +0000177function setpaths()
178{
Christopher Ferris55257d22017-03-23 11:08:58 -0700179 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700180 if [ ! "$T" ]; then
181 echo "Couldn't locate the top of the tree. Try setting TOP."
182 return
183 fi
184
185 ##################################################################
186 # #
187 # Read me before you modify this code #
188 # #
189 # This function sets ANDROID_BUILD_PATHS to what it is adding #
190 # to PATH, and the next time it is run, it removes that from #
191 # PATH. This is required so lunch can be run more than once #
192 # and still have working paths. #
193 # #
194 ##################################################################
195
Raphael Mollc639c782011-06-20 17:25:01 -0700196 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
197 # due to "C:\Program Files" being in the path.
198
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700199 # out with the old
Matt Alexanderd9c56562020-05-21 10:49:17 +0000200 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700201 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
202 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000203 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700204 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800205 # strip leading ':', if any
206 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500207 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700208
209 # and in with the new
Ben Chengfba67bf2014-02-25 10:27:07 -0800210
Dan Willemsen838dcec2021-09-30 22:40:34 +0000211 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Yueyao Zhuefc786a2017-04-07 14:11:54 -0700212
213 # add kernel specific binaries
214 case $(uname -s) in
215 Linux)
216 export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
217 ;;
218 *)
219 ;;
220 esac
221
Colin Crossc0b01042022-10-05 12:03:03 -0700222 ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS)
Yi Kongdfd00b12019-05-21 16:00:04 -0700223 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS
224
225 # Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS.
226 local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
227 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200228
Stephen Hinesaa8d72c2020-02-04 09:15:18 -0800229 # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds.
230 export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer
231
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200232 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
233 # to ensure that the corresponding 'emulator' binaries are used.
234 case $(uname -s) in
235 Darwin)
236 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
237 ;;
238 Linux)
239 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
240 ;;
241 *)
242 ANDROID_EMULATOR_PREBUILTS=
243 ;;
244 esac
245 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Yi Kongdfd00b12019-05-21 16:00:04 -0700246 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200247 export ANDROID_EMULATOR_PREBUILTS
248 fi
249
Jim Tangb3fda302018-12-22 10:24:55 +0800250 # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
251 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
Ryan Prichard8426a192019-07-15 18:05:29 -0700252 local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch"
253 local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch"
254 local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch"
Martin Stjernholm6a012262021-11-24 14:56:15 +0000255 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH
Jim Tangb3fda302018-12-22 10:24:55 +0800256
Joe Onorato404fde52022-10-24 04:35:48 -0700257 # Build system
258 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$T/build/bazel/bin
259
Martin Stjernholm6a012262021-11-24 14:56:15 +0000260 export ANDROID_BUILD_PATHS=$(tr -s : <<<"${ANDROID_BUILD_PATHS}:")
Ryan Prichard8426a192019-07-15 18:05:29 -0700261 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800262
263 # out with the duplicate old
264 if [ -n $ANDROID_PYTHONPATH ]; then
265 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
266 fi
267 # and in with the new
268 export ANDROID_PYTHONPATH=$T/development/python-packages:
Jim Tangc4dba1d2019-07-25 16:54:27 +0800269 if [ -n $VENDOR_PYTHONPATH ]; then
270 ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
271 fi
Jim Tang22f4c322018-12-17 15:21:53 +0800272 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800273
Colin Crosse97e6932017-06-30 16:01:45 -0700274 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
275 export JAVA_HOME=$ANDROID_JAVA_HOME
276 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
277 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
278 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500279
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800280 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700281 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
282 export OUT=$ANDROID_PRODUCT_OUT
283
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700284 unset ANDROID_HOST_OUT
285 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
286
Jiyong Parkc02b1c42020-11-03 11:06:39 +0900287 unset ANDROID_SOONG_HOST_OUT
288 export ANDROID_SOONG_HOST_OUT=$(get_abs_build_var SOONG_HOST_OUT)
289
Simran Basidd050ed2017-02-13 13:46:48 -0800290 unset ANDROID_HOST_OUT_TESTCASES
291 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
292
293 unset ANDROID_TARGET_OUT_TESTCASES
294 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
295
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800296 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297 # TODO: fix the path
298 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
299}
300
Matt Alexanderd9c56562020-05-21 10:49:17 +0000301function printconfig()
302{
Christopher Ferris55257d22017-03-23 11:08:58 -0700303 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800304 if [ ! "$T" ]; then
305 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
306 return
307 fi
308 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309}
310
Matt Alexanderd9c56562020-05-21 10:49:17 +0000311function set_stuff_for_environment()
312{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800313 setpaths
314 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317}
318
Matt Alexanderd9c56562020-05-21 10:49:17 +0000319function set_sequence_number()
320{
Colin Cross88737132017-03-21 17:41:03 -0700321 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700322}
323
Makoto Onukida971062018-06-18 10:15:19 -0700324# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
325function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800326 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700327 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800328 *:"$cmd":*)
329 return 1
330 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700331 esac
332 return 0
333}
334
Matt Alexanderd9c56562020-05-21 10:49:17 +0000335function addcompletions()
336{
Ben Taitelbaum8c2c9cf2020-09-22 16:45:05 -0700337 local f=
Kenny Root52aa81c2011-07-15 11:07:06 -0700338
Jim Tanga881a252018-06-19 16:34:41 +0800339 # Keep us from trying to run in something that's neither bash nor zsh.
340 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700341 return
342 fi
343
344 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800345 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700346 return
347 fi
348
Jim Tanga881a252018-06-19 16:34:41 +0800349 local completion_files=(
MÃ¥rten Kongstadcb5c73f2022-05-04 14:08:12 +0000350 packages/modules/adb/adb.bash
Jim Tanga881a252018-06-19 16:34:41 +0800351 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800352 tools/asuite/asuite.sh
Chris Parsonsa2972972022-08-31 15:04:38 -0400353 prebuilts/bazel/common/bazel-complete.bash
Jim Tanga881a252018-06-19 16:34:41 +0800354 )
Makoto Onukida971062018-06-18 10:15:19 -0700355 # Completion can be disabled selectively to allow users to use non-standard completion.
356 # e.g.
357 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
358 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Usta Shrestha1433fb32022-05-13 14:49:40 -0400359 local T=$(gettop)
Jim Tanga881a252018-06-19 16:34:41 +0800360 for f in ${completion_files[*]}; do
Usta Shrestha1433fb32022-05-13 14:49:40 -0400361 f="$T/$f"
MÃ¥rten Kongstadcb5c73f2022-05-04 14:08:12 +0000362 if [ ! -f "$f" ]; then
363 echo "Warning: completion file $f not found"
364 elif should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700365 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700366 fi
367 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700368
Matt Alexanderd9c56562020-05-21 10:49:17 +0000369 if should_add_completion bit ; then
Makoto Onukida971062018-06-18 10:15:19 -0700370 complete -C "bit --tab" bit
371 fi
Anton Hanssonece9c482019-02-04 18:15:39 +0000372 if [ -z "$ZSH_VERSION" ]; then
373 # Doesn't work in zsh.
374 complete -o nospace -F _croot croot
Chris Parsonsa2972972022-08-31 15:04:38 -0400375 # TODO(b/244559459): Support b autocompletion for zsh
376 complete -F _bazel__complete -o nospace b
Anton Hanssonece9c482019-02-04 18:15:39 +0000377 fi
Jim Tanga881a252018-06-19 16:34:41 +0800378 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800379
Cole Faust24c36db2021-01-23 02:39:37 +0000380 complete -F _complete_android_module_names pathmod
dimitry73b84812018-12-11 18:06:00 +0100381 complete -F _complete_android_module_names gomod
Cole Faust24c36db2021-01-23 02:39:37 +0000382 complete -F _complete_android_module_names outmod
383 complete -F _complete_android_module_names installmod
Jingwen Chen83eeebb2022-10-05 02:27:07 +0000384 complete -F _complete_android_module_names bmod
dimitry73b84812018-12-11 18:06:00 +0100385 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700386}
387
Joe Onorato824608c2022-04-08 11:06:16 -0700388function multitree_lunch_help()
389{
390 echo "usage: lunch PRODUCT-VARIANT" 1>&2
391 echo " Set up android build environment based on a product short name and variant" 1>&2
392 echo 1>&2
393 echo "lunch COMBO_FILE VARIANT" 1>&2
394 echo " Set up android build environment based on a specific lunch combo file" 1>&2
395 echo " and variant." 1>&2
396 echo 1>&2
397 echo "lunch --print [CONFIG]" 1>&2
398 echo " Print the contents of a configuration. If CONFIG is supplied, that config" 1>&2
399 echo " will be flattened and printed. If CONFIG is not supplied, the currently" 1>&2
400 echo " selected config will be printed. Returns 0 on success or nonzero on error." 1>&2
401 echo 1>&2
402 echo "lunch --list" 1>&2
403 echo " List all possible combo files available in the current tree" 1>&2
404 echo 1>&2
405 echo "lunch --help" 1>&2
406 echo "lunch -h" 1>&2
407 echo " Prints this message." 1>&2
408}
409
410function multitree_lunch()
411{
412 local code
413 local results
LaMont Jonesc39e5022022-06-23 19:09:06 +0000414 # Lunch must be run in the topdir, but this way we get a clear error
415 # message, instead of FileNotFound.
416 local T=$(multitree_gettop)
417 if [ -n "$T" ]; then
LaMont Jones5151ddc2022-10-13 23:05:15 +0000418 "$T/orchestrator/build/orchestrator/core/lunch.py" "$@"
LaMont Jonesc39e5022022-06-23 19:09:06 +0000419 else
420 _multitree_lunch_error
421 return 1
422 fi
Joe Onorato824608c2022-04-08 11:06:16 -0700423 if $(echo "$1" | grep -q '^-') ; then
424 # Calls starting with a -- argument are passed directly and the function
425 # returns with the lunch.py exit code.
Spandan Dasca762052022-09-21 00:08:34 +0000426 "${T}/orchestrator/build/orchestrator/core/lunch.py" "$@"
Joe Onorato824608c2022-04-08 11:06:16 -0700427 code=$?
428 if [[ $code -eq 2 ]] ; then
429 echo 1>&2
430 multitree_lunch_help
431 return $code
432 elif [[ $code -ne 0 ]] ; then
433 return $code
434 fi
435 else
436 # All other calls go through the --lunch variant of lunch.py
Spandan Dasca762052022-09-21 00:08:34 +0000437 results=($(${T}/orchestrator/build/orchestrator/core/lunch.py --lunch "$@"))
Joe Onorato824608c2022-04-08 11:06:16 -0700438 code=$?
439 if [[ $code -eq 2 ]] ; then
440 echo 1>&2
441 multitree_lunch_help
442 return $code
443 elif [[ $code -ne 0 ]] ; then
444 return $code
445 fi
446
447 export TARGET_BUILD_COMBO=${results[0]}
448 export TARGET_BUILD_VARIANT=${results[1]}
449 fi
450}
451
Matt Alexanderd9c56562020-05-21 10:49:17 +0000452function choosetype()
453{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700454 echo "Build type choices are:"
455 echo " 1. release"
456 echo " 2. debug"
457 echo
458
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800459 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700460 DEFAULT_NUM=1
461 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700462
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800463 export TARGET_BUILD_TYPE=
464 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465 while [ -z $TARGET_BUILD_TYPE ]
466 do
467 echo -n "Which would you like? ["$DEFAULT_NUM"] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000468 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469 read ANSWER
470 else
471 echo $1
472 ANSWER=$1
473 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474 case $ANSWER in
475 "")
476 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
477 ;;
478 1)
479 export TARGET_BUILD_TYPE=release
480 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800481 release)
482 export TARGET_BUILD_TYPE=release
483 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700484 2)
485 export TARGET_BUILD_TYPE=debug
486 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800487 debug)
488 export TARGET_BUILD_TYPE=debug
489 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700490 *)
491 echo
492 echo "I didn't understand your response. Please try again."
493 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700494 ;;
495 esac
Matt Alexanderd9c56562020-05-21 10:49:17 +0000496 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800497 break
498 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700499 done
500
Ying Wang08800fd2016-03-03 20:57:21 -0800501 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700502 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800503 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700504}
505
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506#
507# This function isn't really right: It chooses a TARGET_PRODUCT
508# based on the list of boards. Usually, that gets you something
509# that kinda works with a generic product, but really, you should
510# pick a product by name.
511#
Matt Alexanderd9c56562020-05-21 10:49:17 +0000512function chooseproduct()
513{
Christopher Ferris55257d22017-03-23 11:08:58 -0700514 local default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000515 if [ "x$TARGET_PRODUCT" != x ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700516 default_value=$TARGET_PRODUCT
517 else
Ying Wang0a76df52015-06-08 11:57:26 -0700518 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700519 fi
520
Ying Wang08800fd2016-03-03 20:57:21 -0800521 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522 export TARGET_PRODUCT=
523 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700524 while [ -z "$TARGET_PRODUCT" ]
525 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700526 echo -n "Which product would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000527 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800528 read ANSWER
529 else
530 echo $1
531 ANSWER=$1
532 fi
533
Matt Alexanderd9c56562020-05-21 10:49:17 +0000534 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700535 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800536 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000537 if check_product $ANSWER
538 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800539 export TARGET_PRODUCT=$ANSWER
540 else
541 echo "** Not a valid product: $ANSWER"
542 fi
543 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000544 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800545 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700546 fi
547 done
548
Ying Wang08800fd2016-03-03 20:57:21 -0800549 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700550 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800551 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700552}
553
Matt Alexanderd9c56562020-05-21 10:49:17 +0000554function choosevariant()
555{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800556 echo "Variant choices are:"
557 local index=1
558 local v
559 for v in ${VARIANT_CHOICES[@]}
560 do
561 # The product name is the name of the directory containing
562 # the makefile we found, above.
563 echo " $index. $v"
564 index=$(($index+1))
565 done
566
567 local default_value=eng
568 local ANSWER
569
570 export TARGET_BUILD_VARIANT=
571 while [ -z "$TARGET_BUILD_VARIANT" ]
572 do
573 echo -n "Which would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000574 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800575 read ANSWER
576 else
577 echo $1
578 ANSWER=$1
579 fi
580
Matt Alexanderd9c56562020-05-21 10:49:17 +0000581 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800582 export TARGET_BUILD_VARIANT=$default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000583 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
584 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Guillaume Chelfice000fd2019-10-03 12:02:46 +0200585 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800586 fi
587 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000588 if check_variant $ANSWER
589 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 export TARGET_BUILD_VARIANT=$ANSWER
591 else
592 echo "** Not a valid variant: $ANSWER"
593 fi
594 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000595 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800596 break
597 fi
598 done
599}
600
Matt Alexanderd9c56562020-05-21 10:49:17 +0000601function choosecombo()
602{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700603 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604
605 echo
606 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700607 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700608
609 echo
610 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700611 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800612
613 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800614 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700615 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800616 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800617 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700618}
619
Matt Alexanderd9c56562020-05-21 10:49:17 +0000620function add_lunch_combo()
621{
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800622 if [ -n "$ZSH_VERSION" ]; then
623 echo -n "${funcfiletrace[1]}: "
624 else
625 echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
626 fi
627 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 -0800628}
629
Matt Alexanderd9c56562020-05-21 10:49:17 +0000630function print_lunch_menu()
631{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700632 local uname=$(uname)
Roland Levillain23c46cf2020-03-31 16:11:05 +0100633 local choices
Colin Crossfa50d402021-04-22 13:05:41 -0700634 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 +0100635 local ret=$?
636
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700637 echo
638 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700639 echo
Roland Levillain23c46cf2020-03-31 16:11:05 +0100640
Matt Alexanderd9c56562020-05-21 10:49:17 +0000641 if [ $ret -ne 0 ]
642 then
Roland Levillain23c46cf2020-03-31 16:11:05 +0100643 echo "Warning: Cannot display lunch menu."
644 echo
645 echo "Note: You can invoke lunch with an explicit target:"
646 echo
647 echo " usage: lunch [target]" >&2
648 echo
649 return
650 fi
651
Will Burr40401202022-02-07 12:12:01 +0000652 echo "Lunch menu .. Here are the common combinations:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800653
654 local i=1
655 local choice
Dan Willemsen91763e92019-10-03 15:13:12 -0700656 for choice in $(echo $choices)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800657 do
658 echo " $i. $choice"
659 i=$(($i+1))
660 done
661
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662 echo
663}
664
Matt Alexanderd9c56562020-05-21 10:49:17 +0000665function lunch()
666{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800667 local answer
668
Steven Moreland92793dc2020-02-25 18:30:18 -0800669 if [[ $# -gt 1 ]]; then
670 echo "usage: lunch [target]" >&2
671 return 1
672 fi
673
Will Burr40401202022-02-07 12:12:01 +0000674 local used_lunch_menu=0
675
Steven Moreland92793dc2020-02-25 18:30:18 -0800676 if [ "$1" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800677 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700678 else
679 print_lunch_menu
Will Burr40401202022-02-07 12:12:01 +0000680 echo "Which would you like? [aosp_arm-eng]"
681 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 -0800682 read answer
Will Burr40401202022-02-07 12:12:01 +0000683 used_lunch_menu=1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700684 fi
685
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800686 local selection=
687
Matt Alexanderd9c56562020-05-21 10:49:17 +0000688 if [ -z "$answer" ]
689 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700690 selection=aosp_arm-eng
Matt Alexanderd9c56562020-05-21 10:49:17 +0000691 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
692 then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800693 local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
Matt Alexanderd9c56562020-05-21 10:49:17 +0000694 if [ $answer -le ${#choices[@]} ]
695 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800696 # array in zsh starts from 1 instead of 0.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000697 if [ -n "$ZSH_VERSION" ]
698 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800699 selection=${choices[$(($answer))]}
700 else
701 selection=${choices[$(($answer-1))]}
702 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800703 fi
Colin Cross88737132017-03-21 17:41:03 -0700704 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800705 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700706 fi
707
Joe Onoratoda12daf2010-06-09 18:18:31 -0700708 export TARGET_BUILD_APPS=
709
Colin Cross88737132017-03-21 17:41:03 -0700710 local product variant_and_version variant version
Colin Cross88737132017-03-21 17:41:03 -0700711 product=${selection%%-*} # Trim everything after first dash
712 variant_and_version=${selection#*-} # Trim everything up to first dash
713 if [ "$variant_and_version" != "$selection" ]; then
714 variant=${variant_and_version%%-*}
715 if [ "$variant" != "$variant_and_version" ]; then
716 version=${variant_and_version#*-}
717 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700718 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800719
Matt Alexanderd9c56562020-05-21 10:49:17 +0000720 if [ -z "$product" ]
721 then
Ying Wang08800fd2016-03-03 20:57:21 -0800722 echo
Colin Cross88737132017-03-21 17:41:03 -0700723 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700724 return 1
725 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800726
Colin Cross88737132017-03-21 17:41:03 -0700727 TARGET_PRODUCT=$product \
728 TARGET_BUILD_VARIANT=$variant \
729 TARGET_PLATFORM_VERSION=$version \
730 build_build_var_cache
Matt Alexanderd9c56562020-05-21 10:49:17 +0000731 if [ $? -ne 0 ]
732 then
Anton Hansson32fa7ee2021-06-14 17:09:58 +0100733 if [[ "$product" =~ .*_(eng|user|userdebug) ]]
734 then
735 echo "Did you mean -${product/*_/}? (dash instead of underscore)"
736 fi
Colin Cross88737132017-03-21 17:41:03 -0700737 return 1
738 fi
Colin Cross88737132017-03-21 17:41:03 -0700739 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
740 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700741 if [ -n "$version" ]; then
742 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
743 else
744 unset TARGET_PLATFORM_VERSION
745 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700746 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700747
Will Burr40401202022-02-07 12:12:01 +0000748 if [ $used_lunch_menu -eq 1 ]; then
749 echo
750 echo "Hint: next time you can simply run 'lunch $selection'"
751 fi
752
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700753 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800754
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700755 set_stuff_for_environment
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700756 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800757 destroy_build_var_cache
Kousik Kumar41dacd12021-05-11 18:38:38 -0400758
759 if [[ -n "${CHECK_MU_CONFIG:-}" ]]; then
760 check_mu_config
761 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700762}
763
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700764unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700765# Tab completion for lunch.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000766function _lunch()
767{
Jeff Davidson513d7a42010-08-02 10:00:44 -0700768 local cur prev opts
769 COMPREPLY=()
770 cur="${COMP_WORDS[COMP_CWORD]}"
771 prev="${COMP_WORDS[COMP_CWORD-1]}"
772
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700773 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800774 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700775 fi
776
777 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700778 return 0
779}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700780
Joe Onoratoda12daf2010-06-09 18:18:31 -0700781# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700782# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Matt Alexanderd9c56562020-05-21 10:49:17 +0000783function tapas()
784{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700785 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Elliott Hughesf71c05a2020-03-06 16:46:59 -0800786 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700787 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700788 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 -0800789 local keys="$(echo $* | xargs -n 1 echo | \grep -E '^(devkeys)$' | xargs)"
790 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)"
791
Joe Onoratoda12daf2010-06-09 18:18:31 -0700792
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700793 if [ "$showHelp" != "" ]; then
794 $(gettop)/build/make/tapasHelp.sh
795 return
796 fi
797
Ying Wang67f02922012-08-22 10:25:20 -0700798 if [ $(echo $arch | wc -w) -gt 1 ]; then
799 echo "tapas: Error: Multiple build archs supplied: $arch"
800 return
801 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700802 if [ $(echo $variant | wc -w) -gt 1 ]; then
803 echo "tapas: Error: Multiple build variants supplied: $variant"
804 return
805 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700806 if [ $(echo $density | wc -w) -gt 1 ]; then
807 echo "tapas: Error: Multiple densities supplied: $density"
808 return
809 fi
Colin Cross7f49a672022-01-27 18:15:53 -0800810 if [ $(echo $keys | wc -w) -gt 1 ]; then
811 echo "tapas: Error: Multiple keys supplied: $keys"
812 return
813 fi
Ying Wang67f02922012-08-22 10:25:20 -0700814
Ying Wang0a76df52015-06-08 11:57:26 -0700815 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700816 case $arch in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000817 x86) product=aosp_x86;;
818 arm64) product=aosp_arm64;;
819 x86_64) product=aosp_x86_64;;
Ying Wang67f02922012-08-22 10:25:20 -0700820 esac
Colin Cross7f49a672022-01-27 18:15:53 -0800821 if [ -n "$keys" ]; then
822 product=${product/aosp_/aosp_${keys}_}
823 fi;
824
Joe Onoratoda12daf2010-06-09 18:18:31 -0700825 if [ -z "$variant" ]; then
826 variant=eng
827 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700828 if [ -z "$apps" ]; then
829 apps=all
830 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600831 if [ -z "$density" ]; then
832 density=alldpi
833 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700834
Ying Wang67f02922012-08-22 10:25:20 -0700835 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700836 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700837 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700838 export TARGET_BUILD_TYPE=release
839 export TARGET_BUILD_APPS=$apps
840
Ying Wang08800fd2016-03-03 20:57:21 -0800841 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700842 set_stuff_for_environment
843 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800844 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700845}
846
Martin Stjernholmf692c752021-04-12 00:01:10 +0100847# Configures the build to build unbundled Android modules (APEXes).
848# Run banchan with one or more module names (from apex{} modules).
849function banchan()
850{
851 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Anton Hansson90ac61c2022-09-06 14:36:00 +0000852 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 +0100853 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100854 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 +0100855
856 if [ "$showHelp" != "" ]; then
857 $(gettop)/build/make/banchanHelp.sh
858 return
859 fi
860
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100861 if [ -z "$product" ]; then
Anton Hansson0328e322022-05-24 15:47:40 +0000862 product=arm64
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100863 elif [ $(echo $product | wc -w) -gt 1 ]; then
864 echo "banchan: Error: Multiple build archs or products supplied: $products"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100865 return
866 fi
867 if [ $(echo $variant | wc -w) -gt 1 ]; then
868 echo "banchan: Error: Multiple build variants supplied: $variant"
869 return
870 fi
871 if [ -z "$apps" ]; then
872 echo "banchan: Error: No modules supplied"
873 return
874 fi
875
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100876 case $product in
877 arm) product=module_arm;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100878 x86) product=module_x86;;
879 arm64) product=module_arm64;;
880 x86_64) product=module_x86_64;;
Anton Hansson90ac61c2022-09-06 14:36:00 +0000881 arm64only) product=module_arm64only;;
882 x86_64only) product=module_x86_64only;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100883 esac
884 if [ -z "$variant" ]; then
885 variant=eng
886 fi
887
888 export TARGET_PRODUCT=$product
889 export TARGET_BUILD_VARIANT=$variant
890 export TARGET_BUILD_DENSITY=alldpi
891 export TARGET_BUILD_TYPE=release
892
893 # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use
894 # case is different and it may diverge in the future.
895 export TARGET_BUILD_APPS=$apps
896
897 build_build_var_cache
898 set_stuff_for_environment
899 printconfig
900 destroy_build_var_cache
901}
902
Matt Alexanderd9c56562020-05-21 10:49:17 +0000903function gettop
904{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700905 local TOPFILE=build/make/core/envsetup.mk
Matt Alexanderd9c56562020-05-21 10:49:17 +0000906 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700907 # The following circumlocution ensures we remove symlinks from TOP.
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000908 (cd "$TOP"; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700909 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000910 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800911 # The following circumlocution (repeated below as well) ensures
912 # that we record the true directory name and not one that is
913 # faked up with symlink names.
914 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700915 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800916 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700917 local T=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000918 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800919 \cd ..
synergyb112a402013-07-05 19:47:47 -0700920 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700921 done
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000922 \cd "$HERE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700923 if [ -f "$T/$TOPFILE" ]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000924 echo "$T"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700925 fi
926 fi
927 fi
928}
929
Joe Onorato7cf6f972022-05-11 21:39:57 -0700930# TODO: Merge into gettop as part of launching multitree
931function multitree_gettop
932{
Spandan Dasca762052022-09-21 00:08:34 +0000933 local TOPFILE=orchestrator/build/make/core/envsetup.mk
Joe Onorato7cf6f972022-05-11 21:39:57 -0700934 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
935 # The following circumlocution ensures we remove symlinks from TOP.
936 (cd "$TOP"; PWD= /bin/pwd)
937 else
938 if [ -f $TOPFILE ] ; then
939 # The following circumlocution (repeated below as well) ensures
940 # that we record the true directory name and not one that is
941 # faked up with symlink names.
942 PWD= /bin/pwd
943 else
944 local HERE=$PWD
945 local T=
946 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
947 \cd ..
948 T=`PWD= /bin/pwd -P`
949 done
950 \cd "$HERE"
951 if [ -f "$T/$TOPFILE" ]; then
952 echo "$T"
953 fi
954 fi
955 fi
956}
957
Matt Alexanderd9c56562020-05-21 10:49:17 +0000958function croot()
959{
Christopher Ferris55257d22017-03-23 11:08:58 -0700960 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700961 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700962 if [ "$1" ]; then
963 \cd $(gettop)/$1
964 else
965 \cd $(gettop)
966 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967 else
968 echo "Couldn't locate the top of the tree. Try setting TOP."
969 fi
970}
971
Matt Alexanderd9c56562020-05-21 10:49:17 +0000972function _croot()
973{
Anton Hanssonece9c482019-02-04 18:15:39 +0000974 local T=$(gettop)
975 if [ "$T" ]; then
976 local cur="${COMP_WORDS[COMP_CWORD]}"
977 k=0
978 for c in $(compgen -d ${T}/${cur}); do
979 COMPREPLY[k++]=${c#${T}/}/
980 done
981 fi
982}
983
Matt Alexanderd9c56562020-05-21 10:49:17 +0000984function cproj()
985{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700986 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700987 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700988 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700989 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
990 T=$PWD
991 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800992 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700993 return
994 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800995 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700996 done
Ying Wang9cd17642012-12-13 10:52:07 -0800997 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700998 echo "can't find Android.mk"
999}
1000
Daniel Sandler47e0a882013-07-30 13:23:52 -04001001# simplified version of ps; output in the form
1002# <pid> <procname>
1003function qpid() {
1004 local prepend=''
1005 local append=''
Matt Alexanderd9c56562020-05-21 10:49:17 +00001006 if [ "$1" = "--exact" ]; then
Daniel Sandler47e0a882013-07-30 13:23:52 -04001007 prepend=' '
1008 append='$'
1009 shift
Matt Alexanderd9c56562020-05-21 10:49:17 +00001010 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001011 echo "usage: qpid [[--exact] <process name|pid>"
1012 return 255
1013 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001014
1015 local EXE="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001016 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001017 qpid | \grep "$prepend$EXE$append"
1018 else
1019 adb shell ps \
1020 | tr -d '\r' \
1021 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1022 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001023}
1024
Steven Moreland74114f12020-09-10 01:23:32 +00001025# syswrite - disable verity, reboot if needed, and remount image
1026#
1027# Easy way to make system.img/etc writable
1028function syswrite() {
1029 adb wait-for-device && adb root || return 1
Frederick Maylee59a8792022-08-22 22:40:23 +00001030 if [[ $(adb disable-verity | grep -i "reboot") ]]; then
Steven Moreland74114f12020-09-10 01:23:32 +00001031 echo "rebooting"
1032 adb reboot && adb wait-for-device && adb root || return 1
1033 fi
1034 adb wait-for-device && adb remount || return 1
1035}
1036
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001037# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001038# that has the core-file-size limit set correctly
1039#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001040# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001041# if its core-file-size limit is not set already.
1042# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1043
Matt Alexanderd9c56562020-05-21 10:49:17 +00001044function coredump_setup()
1045{
1046 echo "Getting root...";
1047 adb root;
1048 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001049
Matt Alexanderd9c56562020-05-21 10:49:17 +00001050 echo "Remounting root partition read-write...";
1051 adb shell mount -w -o remount -t rootfs rootfs;
1052 sleep 1;
1053 adb wait-for-device;
1054 adb shell mkdir -p /cores;
1055 adb shell mount -t tmpfs tmpfs /cores;
1056 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001057
Matt Alexanderd9c56562020-05-21 10:49:17 +00001058 echo "Granting SELinux permission to dump in /cores...";
1059 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001060
Matt Alexanderd9c56562020-05-21 10:49:17 +00001061 echo "Set core pattern.";
1062 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001063
Ying Wang08800fd2016-03-03 20:57:21 -08001064 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001065}
1066
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001067# coredump_enable - enable core dumps for the specified process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001068# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001069#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001070# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001071# dump to actually be generated.
1072
Matt Alexanderd9c56562020-05-21 10:49:17 +00001073function coredump_enable()
1074{
1075 local PID=$1;
Ying Wang08800fd2016-03-03 20:57:21 -08001076 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001077 printf "Expecting a PID!\n";
1078 return;
1079 fi;
1080 echo "Setting core limit for $PID to infinite...";
xi yuaddf4832022-05-26 12:41:21 +00001081 adb shell /system/bin/ulimit -P $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001082}
1083
1084# core - send SIGV and pull the core for process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001085# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001086#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001087# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001088# enabled globally.
1089
Matt Alexanderd9c56562020-05-21 10:49:17 +00001090function core()
1091{
1092 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001093
Ying Wang08800fd2016-03-03 20:57:21 -08001094 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001095 printf "Expecting a PID!\n";
1096 return;
1097 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001098
Matt Alexanderd9c56562020-05-21 10:49:17 +00001099 local CORENAME=core.$PID;
1100 local COREPATH=/cores/$CORENAME;
1101 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001102
Matt Alexanderd9c56562020-05-21 10:49:17 +00001103 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001104
Matt Alexanderd9c56562020-05-21 10:49:17 +00001105 local done=0;
Ying Wang08800fd2016-03-03 20:57:21 -08001106 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
Matt Alexanderd9c56562020-05-21 10:49:17 +00001107 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1108 adb shell kill -$SIG $PID;
1109 sleep 1;
1110 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001111
Matt Alexanderd9c56562020-05-21 10:49:17 +00001112 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1113 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001114}
1115
Christopher Tate744ee802009-11-12 15:33:08 -08001116# systemstack - dump the current stack trace of all threads in the system process
1117# to the usual ANR traces file
Matt Alexanderd9c56562020-05-21 10:49:17 +00001118function systemstack()
1119{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001120 stacks system_server
1121}
1122
Michael Wrightaeed7212014-06-19 19:58:12 -07001123# Read the ELF header from /proc/$PID/exe to determine if the process is
1124# 64-bit.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001125function is64bit()
1126{
Ben Chengfba67bf2014-02-25 10:27:07 -08001127 local PID="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001128 if [ "$PID" ] ; then
1129 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001130 echo "64"
1131 else
1132 echo ""
1133 fi
1134 else
1135 echo ""
1136 fi
1137}
1138
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001139case `uname -s` in
1140 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001141 function sgrep()
1142 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001143 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|hpp|S|java|kt|xml|sh|mk|aidl|vts|proto)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001144 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001145 }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001146
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001147 ;;
1148 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001149 function sgrep()
1150 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001151 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|hpp\|S\|java\|kt\|xml\|sh\|mk\|aidl\|vts\|proto\)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001152 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001153 }
1154 ;;
1155esac
1156
Matt Alexanderd9c56562020-05-21 10:49:17 +00001157function gettargetarch
1158{
Raghu Gandham8da43102012-07-25 19:57:22 -07001159 get_build_var TARGET_ARCH
1160}
1161
Matt Alexanderd9c56562020-05-21 10:49:17 +00001162function ggrep()
1163{
Mike Frysinger5e479732015-09-22 18:13:48 -04001164 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1165 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001166}
1167
Matt Alexanderd9c56562020-05-21 10:49:17 +00001168function gogrep()
1169{
Orion Hodson831472d2019-10-25 11:35:15 +01001170 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
1171 -exec grep --color -n "$@" {} +
1172}
1173
Matt Alexanderd9c56562020-05-21 10:49:17 +00001174function jgrep()
1175{
Mike Frysinger5e479732015-09-22 18:13:48 -04001176 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1177 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001178}
1179
Alistair Delva176e5342021-02-22 13:31:26 -08001180function rsgrep()
Jeff Vander Stoep1431ab82021-02-02 19:18:26 +01001181{
1182 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rs" \
1183 -exec grep --color -n "$@" {} +
1184}
1185
Taesu Leeea0cecd2020-10-28 11:05:18 +09001186function ktgrep()
1187{
1188 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.kt" \
1189 -exec grep --color -n "$@" {} +
1190}
1191
Matt Alexanderd9c56562020-05-21 10:49:17 +00001192function cgrep()
1193{
Mike Frysinger5e479732015-09-22 18:13:48 -04001194 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) \
1195 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001196}
1197
Matt Alexanderd9c56562020-05-21 10:49:17 +00001198function resgrep()
1199{
Christopher Ferris55257d22017-03-23 11:08:58 -07001200 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001201 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1202 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1203 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001204}
1205
Matt Alexanderd9c56562020-05-21 10:49:17 +00001206function mangrep()
1207{
Mike Frysinger5e479732015-09-22 18:13:48 -04001208 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1209 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001210}
1211
Matt Alexanderd9c56562020-05-21 10:49:17 +00001212function owngrep()
1213{
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -06001214 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
1215 -exec grep --color -n "$@" {} +
1216}
1217
Matt Alexanderd9c56562020-05-21 10:49:17 +00001218function sepgrep()
1219{
Mike Frysinger5e479732015-09-22 18:13:48 -04001220 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1221 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001222}
1223
Matt Alexanderd9c56562020-05-21 10:49:17 +00001224function rcgrep()
1225{
Mike Frysinger5e479732015-09-22 18:13:48 -04001226 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1227 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001228}
1229
DroidFreak32a2781982020-11-26 11:30:19 -05001230function pygrep()
1231{
1232 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.py" \
1233 -exec grep --color -n "$@" {} +
1234}
1235
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236case `uname -s` in
1237 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001238 function mgrep()
1239 {
Orion Hodson831472d2019-10-25 11:35:15 +01001240 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 -04001241 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001242 }
1243
Matt Alexanderd9c56562020-05-21 10:49:17 +00001244 function treegrep()
1245 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001246 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 -04001247 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001248 }
1249
1250 ;;
1251 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001252 function mgrep()
1253 {
Orion Hodson831472d2019-10-25 11:35:15 +01001254 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 -04001255 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001256 }
1257
Matt Alexanderd9c56562020-05-21 10:49:17 +00001258 function treegrep()
1259 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001260 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 -04001261 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001262 }
1263
1264 ;;
1265esac
1266
Matt Alexanderd9c56562020-05-21 10:49:17 +00001267function getprebuilt
1268{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001269 get_abs_build_var ANDROID_PREBUILTS
1270}
1271
Matt Alexanderd9c56562020-05-21 10:49:17 +00001272function tracedmdump()
1273{
Christopher Ferris55257d22017-03-23 11:08:58 -07001274 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001275 if [ ! "$T" ]; then
1276 echo "Couldn't locate the top of the tree. Try setting TOP."
1277 return
1278 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001279 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001280 local arch=$(gettargetarch)
1281 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001282
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001283 local TRACE=$1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001284 if [ ! "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001285 echo "usage: tracedmdump tracename"
1286 return
1287 fi
1288
Matt Alexanderd9c56562020-05-21 10:49:17 +00001289 if [ ! -r "$KERNEL" ] ; then
Jack Veenstra60116fc2009-04-09 18:12:34 -07001290 echo "Error: cannot find kernel: '$KERNEL'"
1291 return
1292 fi
1293
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001294 local BASETRACE=$(basename $TRACE)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001295 if [ "$BASETRACE" = "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001296 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1297 fi
1298
1299 echo "post-processing traces..."
1300 rm -f $TRACE/qtrace.dexlist
1301 post_trace $TRACE
1302 if [ $? -ne 0 ]; then
1303 echo "***"
1304 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1305 echo "***"
1306 return
1307 fi
1308 echo "generating dexlist output..."
1309 /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
1310 echo "generating dmtrace data..."
1311 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1312 echo "generating html file..."
1313 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1314 echo "done, see $TRACE/dmtrace.html for details"
1315 echo "or run:"
1316 echo " traceview $TRACE/dmtrace"
1317}
1318
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001319# communicate with a running device or emulator, set up necessary state,
1320# and run the hat command.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001321function runhat()
1322{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001323 # process standard adb options
1324 local adbTarget=""
Matt Alexanderd9c56562020-05-21 10:49:17 +00001325 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001326 adbTarget=$1
1327 shift 1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001328 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001329 adbTarget="$1 $2"
1330 shift 2
1331 fi
1332 local adbOptions=${adbTarget}
Matt Alexanderd9c56562020-05-21 10:49:17 +00001333 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001334
1335 # runhat options
1336 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001337
Matt Alexanderd9c56562020-05-21 10:49:17 +00001338 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001339 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001340 return
1341 fi
1342
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001343 # confirm hat is available
1344 if [ -z $(which hat) ]; then
1345 echo "hat is not available in this configuration."
1346 return
1347 fi
1348
Andy McFaddenb6289852010-07-12 08:00:19 -07001349 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001350 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001351 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001352 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001353 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001354 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001355 echo -n "> "
1356 read
1357
The Android Open Source Project88b60792009-03-03 19:28:42 -08001358 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001359
The Android Open Source Project88b60792009-03-03 19:28:42 -08001360 echo "Retrieving file $devFile..."
1361 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001362
The Android Open Source Project88b60792009-03-03 19:28:42 -08001363 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001364
The Android Open Source Project88b60792009-03-03 19:28:42 -08001365 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001366 echo "View the output by pointing your browser at http://localhost:7000/"
1367 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001368 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001369}
1370
Matt Alexanderd9c56562020-05-21 10:49:17 +00001371function getbugreports()
1372{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001373 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001374
1375 if [ ! "$reports" ]; then
1376 echo "Could not locate any bugreports."
1377 return
1378 fi
1379
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001380 local report
1381 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001382 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001383 echo "/sdcard/bugreports/${report}"
1384 adb pull /sdcard/bugreports/${report} ${report}
1385 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001386 done
1387}
1388
Matt Alexanderd9c56562020-05-21 10:49:17 +00001389function getsdcardpath()
1390{
Victoria Lease1b296b42012-08-21 15:44:06 -07001391 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1392}
1393
Matt Alexanderd9c56562020-05-21 10:49:17 +00001394function getscreenshotpath()
1395{
Victoria Lease1b296b42012-08-21 15:44:06 -07001396 echo "$(getsdcardpath)/Pictures/Screenshots"
1397}
1398
Matt Alexanderd9c56562020-05-21 10:49:17 +00001399function getlastscreenshot()
1400{
Victoria Lease1b296b42012-08-21 15:44:06 -07001401 local screenshot_path=$(getscreenshotpath)
1402 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 +00001403 if [ "$screenshot" = "" ]; then
Victoria Lease1b296b42012-08-21 15:44:06 -07001404 echo "No screenshots found."
1405 return
1406 fi
1407 echo "${screenshot}"
1408 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1409}
1410
Matt Alexanderd9c56562020-05-21 10:49:17 +00001411function startviewserver()
1412{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001413 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001414 if [ $# -gt 0 ]; then
1415 port=$1
1416 fi
1417 adb shell service call window 1 i32 $port
1418}
1419
Matt Alexanderd9c56562020-05-21 10:49:17 +00001420function stopviewserver()
1421{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001422 adb shell service call window 2
1423}
1424
Matt Alexanderd9c56562020-05-21 10:49:17 +00001425function isviewserverstarted()
1426{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001427 adb shell service call window 3
1428}
1429
Matt Alexanderd9c56562020-05-21 10:49:17 +00001430function key_home()
1431{
Romain Guyb84049a2010-10-04 16:56:11 -07001432 adb shell input keyevent 3
1433}
1434
Matt Alexanderd9c56562020-05-21 10:49:17 +00001435function key_back()
1436{
Romain Guyb84049a2010-10-04 16:56:11 -07001437 adb shell input keyevent 4
1438}
1439
Matt Alexanderd9c56562020-05-21 10:49:17 +00001440function key_menu()
1441{
Romain Guyb84049a2010-10-04 16:56:11 -07001442 adb shell input keyevent 82
1443}
1444
Matt Alexanderd9c56562020-05-21 10:49:17 +00001445function smoketest()
1446{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001447 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1448 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1449 return
1450 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001451 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001452 if [ ! "$T" ]; then
1453 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1454 return
1455 fi
1456
Ying Wang9cd17642012-12-13 10:52:07 -08001457 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001458 adb uninstall com.android.smoketest > /dev/null &&
1459 adb uninstall com.android.smoketest.tests > /dev/null &&
1460 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1461 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1462 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1463}
1464
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001465# simple shortcut to the runtest command
Matt Alexanderd9c56562020-05-21 10:49:17 +00001466function runtest()
1467{
Christopher Ferris55257d22017-03-23 11:08:58 -07001468 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001469 if [ ! "$T" ]; then
1470 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1471 return
1472 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001473 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001474}
1475
The Android Open Source Project88b60792009-03-03 19:28:42 -08001476function godir () {
1477 if [[ -z "$1" ]]; then
1478 echo "Usage: godir <regex>"
1479 return
1480 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001481 local T=$(gettop)
1482 local FILELIST
Matt Alexanderd9c56562020-05-21 10:49:17 +00001483 if [ ! "$OUT_DIR" = "" ]; then
Brian Carlstromf2257422015-09-30 20:28:54 -07001484 mkdir -p $OUT_DIR
1485 FILELIST=$OUT_DIR/filelist
1486 else
1487 FILELIST=$T/filelist
1488 fi
1489 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001490 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001491 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001492 echo " Done"
1493 echo ""
1494 fi
1495 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001496 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
Matt Alexanderd9c56562020-05-21 10:49:17 +00001497 if [[ ${#lines[@]} = 0 ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001498 echo "Not found"
1499 return
1500 fi
1501 local pathname
1502 local choice
1503 if [[ ${#lines[@]} > 1 ]]; then
1504 while [[ -z "$pathname" ]]; do
1505 local index=1
1506 local line
1507 for line in ${lines[@]}; do
1508 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001509 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001510 done
1511 echo
1512 echo -n "Select one: "
1513 unset choice
1514 read choice
1515 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1516 echo "Invalid choice"
1517 continue
1518 fi
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001519 pathname=${lines[@]:$(($choice-1)):1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001520 done
1521 else
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001522 pathname=${lines[@]:0:1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001523 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001524 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001525}
1526
Steven Moreland62054a42018-12-06 10:11:40 -08001527# Update module-info.json in out.
1528function refreshmod() {
1529 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1530 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1531 return 1
1532 fi
1533
1534 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1535
1536 # for the output of the next command
1537 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1538
1539 # Note, can't use absolute path because of the way make works.
Alessandro Astonec8771be2020-05-10 11:27:57 +02001540 m $(get_build_var PRODUCT_OUT)/module-info.json \
Steven Moreland62054a42018-12-06 10:11:40 -08001541 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1542}
1543
Cole Faust3e192382021-10-25 13:29:15 -07001544# Verifies that module-info.txt exists, returning nonzero if it doesn't.
Cole Faust24c36db2021-01-23 02:39:37 +00001545function verifymodinfo() {
Steven Moreland62054a42018-12-06 10:11:40 -08001546 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001547 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
1548 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1549 fi
Steven Moreland62054a42018-12-06 10:11:40 -08001550 return 1
1551 fi
1552
1553 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001554 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
Cole Faust3e192382021-10-25 13:29:15 -07001555 echo "Could not find module-info.json. Please run 'refreshmod' first." >&2
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001556 fi
1557 return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001558 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001559}
1560
Cole Faust5d825b72022-10-26 18:16:44 -07001561# List all modules for the current device, as cached in all_modules.txt. If any build change is
1562# made and it should be reflected in the output, you should run `m nothing` first.
Cole Faust24c36db2021-01-23 02:39:37 +00001563function allmod() {
Cole Faust5d825b72022-10-26 18:16:44 -07001564 cat $ANDROID_PRODUCT_OUT/all_modules.txt 2>/dev/null
Steven Moreland62054a42018-12-06 10:11:40 -08001565}
1566
Jingwen Chen83eeebb2022-10-05 02:27:07 +00001567# Return the Bazel label of a Soong module if it is converted with bp2build.
1568function bmod()
1569(
1570 if [ $# -ne 1 ]; then
1571 echo "usage: bmod <module>" >&2
1572 return 1
1573 fi
1574
1575 # We could run bp2build here, but it might trigger bp2build invalidation
1576 # when used with `b` (e.g. --run_soong_tests) and/or add unnecessary waiting
1577 # time overhead.
1578 #
1579 # For a snappy result, use the latest generated version in soong_injection,
1580 # and ask users to run m bp2build if it doesn't exist.
Jingwen Chenacdcaa02022-10-13 07:24:24 +00001581 converted_json="$(get_abs_build_var OUT_DIR)/soong/soong_injection/metrics/converted_modules_path_map.json"
Jingwen Chen83eeebb2022-10-05 02:27:07 +00001582
Jingwen Chenacdcaa02022-10-13 07:24:24 +00001583 if [ ! -f ${converted_json} ]; then
Jingwen Chen83eeebb2022-10-05 02:27:07 +00001584 echo "bp2build files not found. Have you ran 'm bp2build'?" >&2
1585 return 1
1586 fi
1587
1588 local target_label=$(python3 -c "import json
1589module = '$1'
1590converted_json='$converted_json'
1591bp2build_converted_map = json.load(open(converted_json))
1592if module not in bp2build_converted_map:
1593 exit(1)
1594print(bp2build_converted_map[module] + ':' + module)")
1595
1596 if [ -z "${target_label}" ]; then
1597 echo "$1 is not converted to Bazel." >&2
1598 return 1
1599 else
1600 echo "${target_label}"
1601 fi
1602)
1603
Joe Onorato2c1aa472021-02-25 16:42:39 -08001604# Get the path of a specific module in the android tree, as cached in module-info.json.
1605# If any build change is made, and it should be reflected in the output, you should run
1606# 'refreshmod' first. Note: This is the inverse of dirmods.
Rett Berg78d1c932019-01-24 14:34:23 -08001607function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001608 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001609 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001610 return 1
1611 fi
1612
Cole Faust24c36db2021-01-23 02:39:37 +00001613 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001614
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001615 local relpath=$(python3 -c "import json, os
Steven Moreland62054a42018-12-06 10:11:40 -08001616module = '$1'
1617module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1618if module not in module_info:
1619 exit(1)
LuK1337b6a78192020-01-12 03:12:17 +01001620print(module_info[module]['path'][0])" 2>/dev/null)
Steven Moreland62054a42018-12-06 10:11:40 -08001621
1622 if [ -z "$relpath" ]; then
1623 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1624 return 1
1625 else
Rett Berg78d1c932019-01-24 14:34:23 -08001626 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001627 fi
1628}
1629
Joe Onorato2c1aa472021-02-25 16:42:39 -08001630# Get the path of a specific module in the android tree, as cached in module-info.json.
1631# If any build change is made, and it should be reflected in the output, you should run
1632# 'refreshmod' first. Note: This is the inverse of pathmod.
1633function dirmods() {
1634 if [[ $# -ne 1 ]]; then
1635 echo "usage: dirmods <path>" >&2
1636 return 1
1637 fi
1638
1639 verifymodinfo || return 1
1640
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001641 python3 -c "import json, os
Joe Onorato2c1aa472021-02-25 16:42:39 -08001642dir = '$1'
1643while dir.endswith('/'):
1644 dir = dir[:-1]
1645prefix = dir + '/'
1646module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1647results = set()
1648for m in module_info.values():
1649 for path in m.get(u'path', []):
1650 if path == dir or path.startswith(prefix):
1651 name = m.get(u'module_name')
1652 if name:
1653 results.add(name)
1654for name in sorted(results):
1655 print(name)
1656"
1657}
1658
1659
Rett Berg78d1c932019-01-24 14:34:23 -08001660# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1661# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1662function gomod() {
1663 if [[ $# -ne 1 ]]; then
1664 echo "usage: gomod <module>" >&2
1665 return 1
1666 fi
1667
1668 local path="$(pathmod $@)"
1669 if [ -z "$path" ]; then
1670 return 1
1671 fi
1672 cd $path
1673}
1674
Cole Faust24c36db2021-01-23 02:39:37 +00001675# Gets the list of a module's installed outputs, as cached in module-info.json.
1676# If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first.
1677function outmod() {
1678 if [[ $# -ne 1 ]]; then
1679 echo "usage: outmod <module>" >&2
1680 return 1
1681 fi
1682
1683 verifymodinfo || return 1
1684
1685 local relpath
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001686 relpath=$(python3 -c "import json, os
Cole Faust24c36db2021-01-23 02:39:37 +00001687module = '$1'
1688module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1689if module not in module_info:
1690 exit(1)
1691for output in module_info[module]['installed']:
1692 print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null)
1693
1694 if [ $? -ne 0 ]; then
1695 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2
1696 return 1
1697 elif [ ! -z "$relpath" ]; then
1698 echo "$relpath"
1699 fi
1700}
1701
1702# adb install a module's apk, as cached in module-info.json. If any build change
1703# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1704# Usage: installmod [adb install arguments] <module>
1705# For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk
1706function installmod() {
1707 if [[ $# -eq 0 ]]; then
1708 echo "usage: installmod [adb install arguments] <module>" >&2
Cole Faust3e192382021-10-25 13:29:15 -07001709 echo "" >&2
1710 echo "Only flags to be passed after the \"install\" in adb install are supported," >&2
1711 echo "with the exception of -s. If -s is passed it will be placed before the \"install\"." >&2
1712 echo "-s must be the first flag passed if it exists." >&2
Cole Faust24c36db2021-01-23 02:39:37 +00001713 return 1
1714 fi
1715
1716 local _path
1717 _path=$(outmod ${@:$#:1})
1718 if [ $? -ne 0 ]; then
1719 return 1
1720 fi
1721
1722 _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1)
1723 if [ -z "$_path" ]; then
1724 echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2
1725 return 1
1726 fi
Cole Faust3e192382021-10-25 13:29:15 -07001727 local serial_device=""
1728 if [[ "$1" == "-s" ]]; then
1729 if [[ $# -le 2 ]]; then
1730 echo "-s requires an argument" >&2
1731 return 1
1732 fi
1733 serial_device="-s $2"
1734 shift 2
1735 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001736 local length=$(( $# - 1 ))
Cole Faust3e192382021-10-25 13:29:15 -07001737 echo adb $serial_device install ${@:1:$length} $_path
1738 adb $serial_device install ${@:1:$length} $_path
Cole Faust24c36db2021-01-23 02:39:37 +00001739}
1740
dimitry73b84812018-12-11 18:06:00 +01001741function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001742 local word=${COMP_WORDS[COMP_CWORD]}
Cole Faust5d825b72022-10-26 18:16:44 -07001743 COMPREPLY=( $(allmod | grep -E "^$word") )
Steven Moreland62054a42018-12-06 10:11:40 -08001744}
1745
Alex Rayf0d08eb2013-03-08 15:15:06 -08001746# Print colored exit condition
1747function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001748 "$@"
1749 local retval=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +00001750 if [ $retval -ne 0 ]
1751 then
Jacky Cao89483b82015-05-15 22:12:53 +08001752 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001753 else
Jacky Cao89483b82015-05-15 22:12:53 +08001754 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001755 fi
1756 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001757}
1758
Matt Alexanderd9c56562020-05-21 10:49:17 +00001759function get_make_command()
1760{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001761 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1762 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001763 # Always use the real make if -C is passed in
1764 for arg in "$@"; do
1765 if [[ $arg == -C* ]]; then
1766 echo command make
1767 return
1768 fi
1769 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001770 echo build/soong/soong_ui.bash --make-mode
1771 else
1772 echo command make
1773 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001774}
1775
Matt Alexanderd9c56562020-05-21 10:49:17 +00001776function _wrap_build()
1777{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001778 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1779 "$@"
1780 return $?
1781 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001782 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001783 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001784 local ret=$?
1785 local end_time=$(date +"%s")
1786 local tdiff=$(($end_time-$start_time))
1787 local hours=$(($tdiff / 3600 ))
1788 local mins=$((($tdiff % 3600) / 60))
1789 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001790 local ncolors=$(tput colors 2>/dev/null)
1791 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001792 color_failed=$'\E'"[0;31m"
1793 color_success=$'\E'"[0;32m"
Kousik Kumar09af2542021-08-19 16:13:32 -04001794 color_warning=$'\E'"[0;33m"
Jacky Cao89483b82015-05-15 22:12:53 +08001795 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001796 else
1797 color_failed=""
1798 color_success=""
1799 color_reset=""
1800 fi
Kousik Kumar09af2542021-08-19 16:13:32 -04001801
1802 if [[ "x${USE_RBE}" == "x" && $mins -gt 15 && "${ANDROID_BUILD_ENVIRONMENT_CONFIG}" == "googler" ]]; then
1803 echo
1804 echo "${color_warning}Start using RBE (http://go/build-fast) to get faster builds!${color_reset}"
1805 fi
1806
Ed Heylcc6be0a2014-06-18 14:55:58 -07001807 echo
Matt Alexanderd9c56562020-05-21 10:49:17 +00001808 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001809 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001810 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001811 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001812 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +00001813 if [ $hours -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001814 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001815 elif [ $mins -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001816 printf "(%02g:%02g (mm:ss))" $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001817 elif [ $secs -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001818 printf "(%s seconds)" $secs
1819 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001820 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001821 echo
1822 return $ret
1823}
1824
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001825function _trigger_build()
1826(
1827 local -r bc="$1"; shift
LaMont Jonesc39e5022022-06-23 19:09:06 +00001828 local T=$(gettop)
1829 if [ -n "$T" ]; then
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001830 _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
1831 else
Jingwen Chend728ee12021-05-18 06:02:53 +00001832 >&2 echo "Couldn't locate the top of the tree. Try setting TOP."
1833 return 1
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001834 fi
1835)
1836
1837function m()
1838(
1839 _trigger_build "all-modules" "$@"
1840)
1841
1842function mm()
1843(
1844 _trigger_build "modules-in-a-dir-no-deps" "$@"
1845)
1846
1847function mmm()
1848(
1849 _trigger_build "modules-in-dirs-no-deps" "$@"
1850)
1851
1852function mma()
1853(
1854 _trigger_build "modules-in-a-dir" "$@"
1855)
1856
1857function mmma()
1858(
1859 _trigger_build "modules-in-dirs" "$@"
1860)
1861
Matt Alexanderd9c56562020-05-21 10:49:17 +00001862function make()
1863{
Dan Willemsene9842242017-07-28 13:00:13 -07001864 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001865}
1866
Joe Onorato7cf6f972022-05-11 21:39:57 -07001867function _multitree_lunch_error()
1868{
1869 >&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."
1870}
1871
1872function multitree_build()
1873{
LaMont Jonesc39e5022022-06-23 19:09:06 +00001874 local T=$(multitree_gettop)
1875 if [ -n "$T" ]; then
Spandan Dasca762052022-09-21 00:08:34 +00001876 "$T/orchestrator/build/orchestrator/core/orchestrator.py" "$@"
Joe Onorato7cf6f972022-05-11 21:39:57 -07001877 else
1878 _multitree_lunch_error
1879 return 1
1880 fi
1881}
1882
Matt Alexanderd9c56562020-05-21 10:49:17 +00001883function provision()
1884{
David Zeuthen1b126ff2015-09-30 17:10:48 -04001885 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1886 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1887 return 1
1888 fi
1889 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1890 echo "There is no provisioning script for the device." >&2
1891 return 1
1892 fi
1893
1894 # Check if user really wants to do this.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001895 if [ "$1" = "--no-confirmation" ]; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001896 shift 1
1897 else
1898 echo "This action will reflash your device."
1899 echo ""
1900 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1901 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001902 echo -n "Are you sure you want to do this (yes/no)? "
1903 read
Matt Alexanderd9c56562020-05-21 10:49:17 +00001904 if [[ "${REPLY}" != "yes" ]] ; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001905 echo "Not taking any action. Exiting." >&2
1906 return 1
1907 fi
1908 fi
1909 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1910}
1911
Jim Tanga881a252018-06-19 16:34:41 +08001912# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001913function enable_zsh_completion() {
1914 # Don't override user's options if bash-style completion is already enabled.
1915 if ! declare -f complete >/dev/null; then
1916 autoload -U compinit && compinit
1917 autoload -U bashcompinit && bashcompinit
1918 fi
Jim Tanga881a252018-06-19 16:34:41 +08001919}
1920
1921function validate_current_shell() {
1922 local current_sh="$(ps -o command -p $$)"
1923 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001924 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001925 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001926 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001927 *zsh*)
1928 function check_type() { type "$1"; }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001929 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001930 *)
Jim Tanga881a252018-06-19 16:34:41 +08001931 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 -07001932 ;;
1933 esac
Jim Tanga881a252018-06-19 16:34:41 +08001934}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001935
1936# Execute the contents of any vendorsetup.sh files we can find.
Dan Willemsend855a722019-02-12 15:52:36 -08001937# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
1938# load those.
1939#
1940# This allows loading only approved vendorsetup.sh files
Jim Tanga881a252018-06-19 16:34:41 +08001941function source_vendorsetup() {
Jim Tangc4dba1d2019-07-25 16:54:27 +08001942 unset VENDOR_PYTHONPATH
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001943 local T="$(gettop)"
Dan Willemsend855a722019-02-12 15:52:36 -08001944 allowed=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001945 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 -08001946 if [ -n "$allowed" ]; then
1947 echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
1948 echo " $allowed"
1949 echo " $f"
1950 return
1951 fi
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001952 allowed="$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001953 done
1954
1955 allowed_files=
1956 [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
Jim Tanga881a252018-06-19 16:34:41 +08001957 for dir in device vendor product; do
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001958 for f in $(cd "$T" && test -d $dir && \
Jim Tanga881a252018-06-19 16:34:41 +08001959 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001960
1961 if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001962 echo "including $f"; . "$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001963 else
1964 echo "ignoring $f, not in $allowed"
1965 fi
Jim Tanga881a252018-06-19 16:34:41 +08001966 done
1967 done
1968}
Kenny Root52aa81c2011-07-15 11:07:06 -07001969
Dan Albertbab814f2020-08-26 15:34:53 -07001970function showcommands() {
1971 local T=$(gettop)
1972 if [[ -z "$TARGET_PRODUCT" ]]; then
1973 >&2 echo "TARGET_PRODUCT not set. Run lunch."
1974 return
1975 fi
1976 case $(uname -s) in
1977 Darwin)
1978 PREBUILT_NAME=darwin-x86
1979 ;;
1980 Linux)
1981 PREBUILT_NAME=linux-x86
1982 ;;
1983 *)
1984 >&2 echo Unknown host $(uname -s)
1985 return
1986 ;;
1987 esac
Jingwen Chenacdcaa02022-10-13 07:24:24 +00001988 OUT_DIR="$(get_abs_build_var OUT_DIR)"
Dan Albertbab814f2020-08-26 15:34:53 -07001989 if [[ "$1" == "--regenerate" ]]; then
1990 shift 1
1991 NINJA_ARGS="-t commands $@" m
1992 else
1993 (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \
1994 -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \
1995 -t commands "$@")
1996 fi
1997}
1998
Cole Faust45844ab2022-08-30 13:59:07 -07001999function avbtool() {
2000 if [[ ! -f "$ANDROID_SOONG_HOST_OUT"/bin/avbtool ]]; then
2001 m avbtool
2002 fi
2003 "$ANDROID_SOONG_HOST_OUT"/bin/avbtool $@
2004}
2005
Jim Tanga881a252018-06-19 16:34:41 +08002006validate_current_shell
2007source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07002008addcompletions