blob: f875d0b3030bdabcb5e3811691da1176739c30de [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
Jeff Gastonc6dfc4e2017-05-30 17:12:37 -07003
4Run "m help" for help with the build system itself.
5
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08006Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Steven Moreland62054a42018-12-06 10:11:40 -08007- lunch: lunch <product_name>-<build_variant>
8 Selects <product_name> as the product to build, and <build_variant> as the variant to
9 build, and stores those selections in the environment to be read by subsequent
10 invocations of 'm' etc.
Elliott Hughesf71c05a2020-03-06 16:46:59 -080011- tapas: tapas [<App1> <App2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
Martin Stjernholmf692c752021-04-12 00:01:10 +010012 Sets up the build environment for building unbundled apps (APKs).
13- banchan: banchan <module1> [<module2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
14 Sets up the build environment for building unbundled modules (APEXes).
Anton Hanssonece9c482019-02-04 18:15:39 +000015- croot: Changes directory to the top of the tree, or a subdirectory thereof.
Steven Moreland62054a42018-12-06 10:11:40 -080016- m: Makes from the top of the tree.
Dan Willemsen67074fe2019-10-30 12:35:34 -070017- mm: Builds and installs all of the modules in the current directory, and their
18 dependencies.
19- mmm: Builds and installs all of the modules in the supplied directories, and their
20 dependencies.
Steven Moreland62054a42018-12-06 10:11:40 -080021 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Dan Willemsen67074fe2019-10-30 12:35:34 -070022- mma: Same as 'mm'
23- mmma: Same as 'mmm'
Steven Moreland62054a42018-12-06 10:11:40 -080024- provision: Flash device with all required partitions. Options will be passed on to fastboot.
25- cgrep: Greps on all local C/C++ files.
26- ggrep: Greps on all local Gradle files.
Orion Hodson831472d2019-10-25 11:35:15 +010027- gogrep: Greps on all local Go files.
Steven Moreland62054a42018-12-06 10:11:40 -080028- jgrep: Greps on all local Java files.
Taesu Leeea0cecd2020-10-28 11:05:18 +090029- ktgrep: Greps on all local Kotlin files.
Steven Moreland62054a42018-12-06 10:11:40 -080030- resgrep: Greps on all local res/*.xml files.
31- mangrep: Greps on all local AndroidManifest.xml files.
Jaewoong Jung892d0fe2019-05-04 10:06:28 -070032- mgrep: Greps on all local Makefiles and *.bp files.
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -060033- owngrep: Greps on all local OWNERS files.
Alistair Delva176e5342021-02-22 13:31:26 -080034- rsgrep: Greps on all local Rust files.
Steven Moreland62054a42018-12-06 10:11:40 -080035- sepgrep: Greps on all local sepolicy files.
36- sgrep: Greps on all local source files.
37- godir: Go to the directory containing a file.
38- allmod: List all modules.
39- gomod: Go to the directory containing a module.
Rett Berg78d1c932019-01-24 14:34:23 -080040- pathmod: Get the directory containing a module.
Cole Faust24c36db2021-01-23 02:39:37 +000041- outmod: Gets the location of a module's installed outputs with a certain extension.
Joe Onorato2c1aa472021-02-25 16:42:39 -080042- dirmods: Gets the modules defined in a given directory.
Cole Faust24c36db2021-01-23 02:39:37 +000043- installmod: Adb installs a module's built APK.
44- refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod.
Steven Moreland74114f12020-09-10 01:23:32 +000045- syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070046
Michael Bestas64020242016-08-26 00:37:02 +030047EOF
48
49 __print_bliss_functions_help
50
51cat <<EOF
52
Roland Levillain39341922015-10-20 12:48:19 +010053Environment options:
Steven Moreland115d1f52019-09-26 16:30:28 -070054- SANITIZE_HOST: Set to 'address' to use ASAN for all host modules.
Sasha Smundak9f27cc02019-01-31 13:25:31 -080055- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
Dan Albert4ae5d4b2014-10-31 16:23:08 -070056
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070057Look at the source to view more functions. The complete list is:
58EOF
Christopher Ferris55257d22017-03-23 11:08:58 -070059 local T=$(gettop)
60 local A=""
61 local i
Michael Bestas64020242016-08-26 00:37:02 +030062 for i in `cat $T/build/envsetup.sh $T/vendor/bliss/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 -070063 A="$A $i"
64 done
65 echo $A
66}
67
Ying Wang08800fd2016-03-03 20:57:21 -080068# Get all the build variables needed by this script in a single call to the build system.
Matt Alexanderd9c56562020-05-21 10:49:17 +000069function build_build_var_cache()
70{
Christopher Ferris55257d22017-03-23 11:08:58 -070071 local T=$(gettop)
Ying Wang08800fd2016-03-03 20:57:21 -080072 # Grep out the variable names from the script.
Michael Bestas64020242016-08-26 00:37:02 +030073 cached_vars=(`cat $T/build/envsetup.sh $T/vendor/bliss/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
74 cached_abs_vars=(`cat $T/build/envsetup.sh $T/vendor/bliss/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 -080075 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
Steven Moreland05402962018-01-05 12:13:11 -080076 build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
Jim Tanga881a252018-06-19 16:34:41 +080077 --vars="${cached_vars[*]}" \
78 --abs-vars="${cached_abs_vars[*]}" \
Dan Willemsenaf88c412017-07-14 11:29:44 -070079 --var-prefix=var_cache_ \
80 --abs-var-prefix=abs_var_cache_`
Ying Wang08800fd2016-03-03 20:57:21 -080081 local ret=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +000082 if [ $ret -ne 0 ]
83 then
Ying Wang08800fd2016-03-03 20:57:21 -080084 unset build_dicts_script
85 return $ret
86 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -070087 # Execute the script to store the "<val>=<value>" pairs as shell variables.
Ying Wang08800fd2016-03-03 20:57:21 -080088 eval "$build_dicts_script"
Ying Wang08800fd2016-03-03 20:57:21 -080089 ret=$?
Ying Wangf0cb3972016-03-04 13:56:23 -080090 unset build_dicts_script
Matt Alexanderd9c56562020-05-21 10:49:17 +000091 if [ $ret -ne 0 ]
92 then
Ying Wang08800fd2016-03-03 20:57:21 -080093 return $ret
94 fi
95 BUILD_VAR_CACHE_READY="true"
96}
97
Ying Wangf0cb3972016-03-04 13:56:23 -080098# Delete the build var cache, so that we can still call into the build system
Ying Wang08800fd2016-03-03 20:57:21 -080099# to get build variables not listed in this script.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000100function destroy_build_var_cache()
101{
Ying Wang08800fd2016-03-03 20:57:21 -0800102 unset BUILD_VAR_CACHE_READY
Christopher Ferris55257d22017-03-23 11:08:58 -0700103 local v
Ying Wang08800fd2016-03-03 20:57:21 -0800104 for v in $cached_vars; do
105 unset var_cache_$v
106 done
107 unset cached_vars
108 for v in $cached_abs_vars; do
109 unset abs_var_cache_$v
110 done
111 unset cached_abs_vars
112}
113
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700114# Get the value of a build variable as an absolute path.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000115function get_abs_build_var()
116{
117 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
118 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800119 eval "echo \"\${abs_var_cache_$1}\""
Timi0469c3f2021-04-15 16:41:18 +0200120 return
Ying Wang08800fd2016-03-03 20:57:21 -0800121 fi
122
Christopher Ferris55257d22017-03-23 11:08:58 -0700123 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700124 if [ ! "$T" ]; then
125 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
126 return
127 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700128 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700129}
130
131# Get the exact value of a build variable.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000132function get_build_var()
133{
134 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
135 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800136 eval "echo \"\${var_cache_$1}\""
Roland Levillain23c46cf2020-03-31 16:11:05 +0100137 return 0
Ying Wang08800fd2016-03-03 20:57:21 -0800138 fi
139
Christopher Ferris55257d22017-03-23 11:08:58 -0700140 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700141 if [ ! "$T" ]; then
142 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
Roland Levillain23c46cf2020-03-31 16:11:05 +0100143 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700144 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700145 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800146}
147
148# check to see if the supplied product is one we can build
Matt Alexanderd9c56562020-05-21 10:49:17 +0000149function check_product()
150{
Christopher Ferris55257d22017-03-23 11:08:58 -0700151 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800152 if [ ! "$T" ]; then
153 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
154 return
155 fi
Luca Stefani94c2fbe2017-08-17 21:21:23 +0200156 if (echo -n $1 | grep -q -e "^bliss_") ; then
157 BLISS_BUILD=$(echo -n $1 | sed -e 's/^bliss_//g')
158 export BUILD_NUMBER=$( (date +%s%N ; echo $BLISS_BUILD; hostname) | openssl sha1 | sed -e 's/.*=//g; s/ //g' | cut -c1-10 )
159 else
160 BLISS_BUILD=
161 fi
162 export BLISS_BUILD
163
Jeff Browne33ba4c2011-07-11 22:11:46 -0700164 TARGET_PRODUCT=$1 \
165 TARGET_BUILD_VARIANT= \
166 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700167 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800168 get_build_var TARGET_DEVICE > /dev/null
169 # hide successful answers, but allow the errors to show
170}
171
172VARIANT_CHOICES=(user userdebug eng)
173
174# check to see if the supplied variant is valid
Matt Alexanderd9c56562020-05-21 10:49:17 +0000175function check_variant()
176{
Christopher Ferris55257d22017-03-23 11:08:58 -0700177 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800178 for v in ${VARIANT_CHOICES[@]}
179 do
Matt Alexanderd9c56562020-05-21 10:49:17 +0000180 if [ "$v" = "$1" ]
181 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800182 return 0
183 fi
184 done
185 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700186}
187
Matt Alexanderd9c56562020-05-21 10:49:17 +0000188function setpaths()
189{
Christopher Ferris55257d22017-03-23 11:08:58 -0700190 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700191 if [ ! "$T" ]; then
192 echo "Couldn't locate the top of the tree. Try setting TOP."
193 return
194 fi
195
196 ##################################################################
197 # #
198 # Read me before you modify this code #
199 # #
200 # This function sets ANDROID_BUILD_PATHS to what it is adding #
201 # to PATH, and the next time it is run, it removes that from #
202 # PATH. This is required so lunch can be run more than once #
203 # and still have working paths. #
204 # #
205 ##################################################################
206
Raphael Mollc639c782011-06-20 17:25:01 -0700207 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
208 # due to "C:\Program Files" being in the path.
209
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700210 # out with the old
Matt Alexanderd9c56562020-05-21 10:49:17 +0000211 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700212 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
213 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000214 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700215 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800216 # strip leading ':', if any
217 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500218 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700219
220 # and in with the new
Christopher Ferris55257d22017-03-23 11:08:58 -0700221 local prebuiltdir=$(getprebuilt)
222 local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700223
Ben Cheng8bc4c432012-11-16 13:29:13 -0800224 # defined in core/config.mk
Christopher Ferris55257d22017-03-23 11:08:58 -0700225 local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
226 local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800227 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800228
Raphael Mollc639c782011-06-20 17:25:01 -0700229 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800230 export ANDROID_TOOLCHAIN=
231 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200232 local ARCH=$(get_build_var TARGET_ARCH)
Christopher Ferris55257d22017-03-23 11:08:58 -0700233 local toolchaindir toolchaindir2=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200234 case $ARCH in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000235 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700236 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000237 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Pavel Chupinfd82a492012-11-26 09:50:07 +0400238 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000239 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200240 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000241 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
242 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700243 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200244 *)
245 echo "Can't find toolchain for unknown architecture: $ARCH"
246 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700247 ;;
248 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700249 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800250 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700251 fi
Raphael732936d2011-06-22 14:35:32 -0700252
Christopher Ferris55257d22017-03-23 11:08:58 -0700253 if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800254 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
255 fi
256
Jeff Vander Stoep5f50f052015-06-12 09:56:39 -0700257 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Yueyao Zhuefc786a2017-04-07 14:11:54 -0700258
259 # add kernel specific binaries
260 case $(uname -s) in
261 Linux)
262 export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
263 ;;
264 *)
265 ;;
266 esac
267
Torne (Richard Coles)0091bae2017-10-03 16:31:18 -0400268 ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN
269 if [ -n "$ANDROID_TOOLCHAIN_2ND_ARCH" ]; then
270 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH
271 fi
Yi Kongdfd00b12019-05-21 16:00:04 -0700272 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS
273
274 # Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS.
275 local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
276 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200277
Stephen Hinesaa8d72c2020-02-04 09:15:18 -0800278 # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds.
279 export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer
280
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200281 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
282 # to ensure that the corresponding 'emulator' binaries are used.
283 case $(uname -s) in
284 Darwin)
285 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
286 ;;
287 Linux)
288 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
289 ;;
290 *)
291 ANDROID_EMULATOR_PREBUILTS=
292 ;;
293 esac
294 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Yi Kongdfd00b12019-05-21 16:00:04 -0700295 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200296 export ANDROID_EMULATOR_PREBUILTS
297 fi
298
Jim Tangb3fda302018-12-22 10:24:55 +0800299 # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
300 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
Ryan Prichard8426a192019-07-15 18:05:29 -0700301 local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch"
302 local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch"
303 local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch"
304 export ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH:
Jim Tangb3fda302018-12-22 10:24:55 +0800305
Ryan Prichard8426a192019-07-15 18:05:29 -0700306 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800307
308 # out with the duplicate old
309 if [ -n $ANDROID_PYTHONPATH ]; then
310 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
311 fi
312 # and in with the new
313 export ANDROID_PYTHONPATH=$T/development/python-packages:
Jim Tangc4dba1d2019-07-25 16:54:27 +0800314 if [ -n $VENDOR_PYTHONPATH ]; then
315 ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
316 fi
Jim Tang22f4c322018-12-17 15:21:53 +0800317 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800318
Colin Crosse97e6932017-06-30 16:01:45 -0700319 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
320 export JAVA_HOME=$ANDROID_JAVA_HOME
321 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
322 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
323 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500324
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800325 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700326 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
327 export OUT=$ANDROID_PRODUCT_OUT
328
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700329 unset ANDROID_HOST_OUT
330 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
331
Jiyong Parkc02b1c42020-11-03 11:06:39 +0900332 unset ANDROID_SOONG_HOST_OUT
333 export ANDROID_SOONG_HOST_OUT=$(get_abs_build_var SOONG_HOST_OUT)
334
Simran Basidd050ed2017-02-13 13:46:48 -0800335 unset ANDROID_HOST_OUT_TESTCASES
336 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
337
338 unset ANDROID_TARGET_OUT_TESTCASES
339 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
340
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800341 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700342 # TODO: fix the path
343 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
344}
345
Rupert Shuttleworth5d60d022020-10-25 05:20:03 +0000346function bazel()
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000347{
348 local T="$(gettop)"
349 if [ ! "$T" ]; then
350 echo "Couldn't locate the top of the tree. Try setting TOP."
351 return
352 fi
353
Rupert Shuttleworth5d60d022020-10-25 05:20:03 +0000354 if which bazel &>/dev/null; then
Jingwen Chenc8b5e192020-12-14 10:28:33 -0500355 >&2 echo "NOTE: bazel() function sourced from envsetup.sh is being used instead of $(which bazel)"
356 >&2 echo
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000357 fi
358
Rupert Shuttleworth5d60d022020-10-25 05:20:03 +0000359 "$T/tools/bazel" "$@"
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000360}
361
Matt Alexanderd9c56562020-05-21 10:49:17 +0000362function printconfig()
363{
Christopher Ferris55257d22017-03-23 11:08:58 -0700364 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800365 if [ ! "$T" ]; then
366 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
367 return
368 fi
369 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700370}
371
Matt Alexanderd9c56562020-05-21 10:49:17 +0000372function set_stuff_for_environment()
373{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800374 setpaths
375 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700376
Ben Chengaac3f812013-08-13 14:38:15 -0700377 # With this environment variable new GCC can apply colors to warnings/errors
378 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700379}
380
Matt Alexanderd9c56562020-05-21 10:49:17 +0000381function set_sequence_number()
382{
Colin Cross88737132017-03-21 17:41:03 -0700383 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700384}
385
Makoto Onukida971062018-06-18 10:15:19 -0700386# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
387function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800388 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700389 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800390 *:"$cmd":*)
391 return 1
392 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700393 esac
394 return 0
395}
396
Matt Alexanderd9c56562020-05-21 10:49:17 +0000397function addcompletions()
398{
Ben Taitelbaum8c2c9cf2020-09-22 16:45:05 -0700399 local f=
Kenny Root52aa81c2011-07-15 11:07:06 -0700400
Jim Tanga881a252018-06-19 16:34:41 +0800401 # Keep us from trying to run in something that's neither bash nor zsh.
402 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700403 return
404 fi
405
406 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800407 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700408 return
409 fi
410
Jim Tanga881a252018-06-19 16:34:41 +0800411 local completion_files=(
412 system/core/adb/adb.bash
413 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800414 tools/asuite/asuite.sh
Jim Tanga881a252018-06-19 16:34:41 +0800415 )
Makoto Onukida971062018-06-18 10:15:19 -0700416 # Completion can be disabled selectively to allow users to use non-standard completion.
417 # e.g.
418 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
419 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800420 for f in ${completion_files[*]}; do
421 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700422 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700423 fi
424 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700425
Matt Alexanderd9c56562020-05-21 10:49:17 +0000426 if should_add_completion bit ; then
Makoto Onukida971062018-06-18 10:15:19 -0700427 complete -C "bit --tab" bit
428 fi
Anton Hanssonece9c482019-02-04 18:15:39 +0000429 if [ -z "$ZSH_VERSION" ]; then
430 # Doesn't work in zsh.
431 complete -o nospace -F _croot croot
432 fi
Jim Tanga881a252018-06-19 16:34:41 +0800433 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800434
Cole Faust24c36db2021-01-23 02:39:37 +0000435 complete -F _complete_android_module_names pathmod
dimitry73b84812018-12-11 18:06:00 +0100436 complete -F _complete_android_module_names gomod
Cole Faust24c36db2021-01-23 02:39:37 +0000437 complete -F _complete_android_module_names outmod
438 complete -F _complete_android_module_names installmod
dimitry73b84812018-12-11 18:06:00 +0100439 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700440}
441
Matt Alexanderd9c56562020-05-21 10:49:17 +0000442function choosetype()
443{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444 echo "Build type choices are:"
445 echo " 1. release"
446 echo " 2. debug"
447 echo
448
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800449 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700450 DEFAULT_NUM=1
451 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700452
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800453 export TARGET_BUILD_TYPE=
454 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700455 while [ -z $TARGET_BUILD_TYPE ]
456 do
457 echo -n "Which would you like? ["$DEFAULT_NUM"] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000458 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800459 read ANSWER
460 else
461 echo $1
462 ANSWER=$1
463 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700464 case $ANSWER in
465 "")
466 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
467 ;;
468 1)
469 export TARGET_BUILD_TYPE=release
470 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800471 release)
472 export TARGET_BUILD_TYPE=release
473 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474 2)
475 export TARGET_BUILD_TYPE=debug
476 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477 debug)
478 export TARGET_BUILD_TYPE=debug
479 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700480 *)
481 echo
482 echo "I didn't understand your response. Please try again."
483 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700484 ;;
485 esac
Matt Alexanderd9c56562020-05-21 10:49:17 +0000486 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800487 break
488 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700489 done
490
Ying Wang08800fd2016-03-03 20:57:21 -0800491 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700492 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800493 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700494}
495
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800496#
497# This function isn't really right: It chooses a TARGET_PRODUCT
498# based on the list of boards. Usually, that gets you something
499# that kinda works with a generic product, but really, you should
500# pick a product by name.
501#
Matt Alexanderd9c56562020-05-21 10:49:17 +0000502function chooseproduct()
503{
Christopher Ferris55257d22017-03-23 11:08:58 -0700504 local default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000505 if [ "x$TARGET_PRODUCT" != x ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506 default_value=$TARGET_PRODUCT
507 else
Ying Wang0a76df52015-06-08 11:57:26 -0700508 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700509 fi
510
Ying Wang08800fd2016-03-03 20:57:21 -0800511 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512 export TARGET_PRODUCT=
513 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700514 while [ -z "$TARGET_PRODUCT" ]
515 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700516 echo -n "Which product would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000517 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800518 read ANSWER
519 else
520 echo $1
521 ANSWER=$1
522 fi
523
Matt Alexanderd9c56562020-05-21 10:49:17 +0000524 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700525 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800526 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000527 if check_product $ANSWER
528 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800529 export TARGET_PRODUCT=$ANSWER
530 else
531 echo "** Not a valid product: $ANSWER"
532 fi
533 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000534 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800535 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700536 fi
537 done
538
Ying Wang08800fd2016-03-03 20:57:21 -0800539 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700540 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800541 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700542}
543
Matt Alexanderd9c56562020-05-21 10:49:17 +0000544function choosevariant()
545{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800546 echo "Variant choices are:"
547 local index=1
548 local v
549 for v in ${VARIANT_CHOICES[@]}
550 do
551 # The product name is the name of the directory containing
552 # the makefile we found, above.
553 echo " $index. $v"
554 index=$(($index+1))
555 done
556
557 local default_value=eng
558 local ANSWER
559
560 export TARGET_BUILD_VARIANT=
561 while [ -z "$TARGET_BUILD_VARIANT" ]
562 do
563 echo -n "Which would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000564 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800565 read ANSWER
566 else
567 echo $1
568 ANSWER=$1
569 fi
570
Matt Alexanderd9c56562020-05-21 10:49:17 +0000571 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800572 export TARGET_BUILD_VARIANT=$default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000573 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
574 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Guillaume Chelfice000fd2019-10-03 12:02:46 +0200575 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800576 fi
577 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000578 if check_variant $ANSWER
579 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800580 export TARGET_BUILD_VARIANT=$ANSWER
581 else
582 echo "** Not a valid variant: $ANSWER"
583 fi
584 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000585 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800586 break
587 fi
588 done
589}
590
Matt Alexanderd9c56562020-05-21 10:49:17 +0000591function choosecombo()
592{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700593 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700594
595 echo
596 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700597 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700598
599 echo
600 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700601 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800602
603 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800604 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700605 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800606 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800607 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700608}
609
Matt Alexanderd9c56562020-05-21 10:49:17 +0000610function add_lunch_combo()
611{
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800612 if [ -n "$ZSH_VERSION" ]; then
613 echo -n "${funcfiletrace[1]}: "
614 else
615 echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
616 fi
617 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 -0800618}
619
Matt Alexanderd9c56562020-05-21 10:49:17 +0000620function print_lunch_menu()
621{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700622 local uname=$(uname)
Roland Levillain23c46cf2020-03-31 16:11:05 +0100623 local choices
Colin Crossfa50d402021-04-22 13:05:41 -0700624 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 +0100625 local ret=$?
626
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700627 echo
628 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700629 echo
Roland Levillain23c46cf2020-03-31 16:11:05 +0100630
Matt Alexanderd9c56562020-05-21 10:49:17 +0000631 if [ $ret -ne 0 ]
632 then
Roland Levillain23c46cf2020-03-31 16:11:05 +0100633 echo "Warning: Cannot display lunch menu."
634 echo
635 echo "Note: You can invoke lunch with an explicit target:"
636 echo
637 echo " usage: lunch [target]" >&2
638 echo
639 return
640 fi
641
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700642 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800643
644 local i=1
645 local choice
Dan Willemsen91763e92019-10-03 15:13:12 -0700646 for choice in $(echo $choices)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800647 do
648 echo " $i. $choice"
649 i=$(($i+1))
650 done
651
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700652 echo
653}
654
Matt Alexanderd9c56562020-05-21 10:49:17 +0000655function lunch()
656{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800657 local answer
658
Steven Moreland92793dc2020-02-25 18:30:18 -0800659 if [[ $# -gt 1 ]]; then
660 echo "usage: lunch [target]" >&2
661 return 1
662 fi
663
664 if [ "$1" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800665 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700666 else
667 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700668 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800669 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700670 fi
671
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800672 local selection=
673
Matt Alexanderd9c56562020-05-21 10:49:17 +0000674 if [ -z "$answer" ]
675 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700676 selection=aosp_arm-eng
Matt Alexanderd9c56562020-05-21 10:49:17 +0000677 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
678 then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800679 local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
Matt Alexanderd9c56562020-05-21 10:49:17 +0000680 if [ $answer -le ${#choices[@]} ]
681 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800682 # array in zsh starts from 1 instead of 0.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000683 if [ -n "$ZSH_VERSION" ]
684 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800685 selection=${choices[$(($answer))]}
686 else
687 selection=${choices[$(($answer-1))]}
688 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800689 fi
Colin Cross88737132017-03-21 17:41:03 -0700690 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800691 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700692 fi
693
Joe Onoratoda12daf2010-06-09 18:18:31 -0700694 export TARGET_BUILD_APPS=
695
Colin Cross88737132017-03-21 17:41:03 -0700696 local product variant_and_version variant version
Colin Cross88737132017-03-21 17:41:03 -0700697 product=${selection%%-*} # Trim everything after first dash
698 variant_and_version=${selection#*-} # Trim everything up to first dash
699 if [ "$variant_and_version" != "$selection" ]; then
700 variant=${variant_and_version%%-*}
701 if [ "$variant" != "$variant_and_version" ]; then
702 version=${variant_and_version#*-}
703 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700704 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800705
Matt Alexanderd9c56562020-05-21 10:49:17 +0000706 if [ -z "$product" ]
707 then
Ying Wang08800fd2016-03-03 20:57:21 -0800708 echo
Colin Cross88737132017-03-21 17:41:03 -0700709 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700710 return 1
711 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800712
Luca Stefani94c2fbe2017-08-17 21:21:23 +0200713 check_product $product
714
Colin Cross88737132017-03-21 17:41:03 -0700715 TARGET_PRODUCT=$product \
716 TARGET_BUILD_VARIANT=$variant \
717 TARGET_PLATFORM_VERSION=$version \
718 build_build_var_cache
Matt Alexanderd9c56562020-05-21 10:49:17 +0000719 if [ $? -ne 0 ]
720 then
cybojenix5a611282017-09-17 15:58:06 -0400721 # if we can't find the product, try to grab it from our github
722 T=$(gettop)
723 pushd $T > /dev/null
724 $T/vendor/bliss/build/tools/roomservice.py $product
725 popd > /dev/null
726 check_product $product
727 else
728 T=$(gettop)
729 pushd $T > /dev/null
730 $T/vendor/bliss/build/tools/roomservice.py $product true
731 popd > /dev/null
732 fi
733 if [ $? -ne 0 ]
734 then
735 echo
736 echo "** Don't have a product spec for: '$product'"
737 echo "** Do you have the right repo manifest?"
738 product=
739 fi
740
Jackeagle3b4a25f2022-04-24 00:30:44 -0400741 checkofficial $target
742
cybojenix5a611282017-09-17 15:58:06 -0400743 if [ -z "$product" -o -z "$variant" ]
744 then
745 echo
Colin Cross88737132017-03-21 17:41:03 -0700746 return 1
747 fi
Colin Cross88737132017-03-21 17:41:03 -0700748 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
749 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700750 if [ -n "$version" ]; then
751 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
752 else
753 unset TARGET_PLATFORM_VERSION
754 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700755 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700756
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700757 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800758
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700759 set_stuff_for_environment
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700760 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800761 destroy_build_var_cache
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)"
Elliott Hughesf71c05a2020-03-06 16:46:59 -0800789 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)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700790
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700791 if [ "$showHelp" != "" ]; then
792 $(gettop)/build/make/tapasHelp.sh
793 return
794 fi
795
Ying Wang67f02922012-08-22 10:25:20 -0700796 if [ $(echo $arch | wc -w) -gt 1 ]; then
797 echo "tapas: Error: Multiple build archs supplied: $arch"
798 return
799 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700800 if [ $(echo $variant | wc -w) -gt 1 ]; then
801 echo "tapas: Error: Multiple build variants supplied: $variant"
802 return
803 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700804 if [ $(echo $density | wc -w) -gt 1 ]; then
805 echo "tapas: Error: Multiple densities supplied: $density"
806 return
807 fi
Ying Wang67f02922012-08-22 10:25:20 -0700808
Ying Wang0a76df52015-06-08 11:57:26 -0700809 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700810 case $arch in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000811 x86) product=aosp_x86;;
812 arm64) product=aosp_arm64;;
813 x86_64) product=aosp_x86_64;;
Ying Wang67f02922012-08-22 10:25:20 -0700814 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700815 if [ -z "$variant" ]; then
816 variant=eng
817 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700818 if [ -z "$apps" ]; then
819 apps=all
820 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600821 if [ -z "$density" ]; then
822 density=alldpi
823 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700824
Ying Wang67f02922012-08-22 10:25:20 -0700825 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700826 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700827 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700828 export TARGET_BUILD_TYPE=release
829 export TARGET_BUILD_APPS=$apps
830
Ying Wang08800fd2016-03-03 20:57:21 -0800831 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700832 set_stuff_for_environment
833 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800834 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700835}
836
Martin Stjernholmf692c752021-04-12 00:01:10 +0100837# Configures the build to build unbundled Android modules (APEXes).
838# Run banchan with one or more module names (from apex{} modules).
839function banchan()
840{
841 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100842 local product="$(echo $* | xargs -n 1 echo | \grep -E '^(.*_)?(arm|x86|arm64|x86_64)$' | xargs)"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100843 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100844 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 +0100845
846 if [ "$showHelp" != "" ]; then
847 $(gettop)/build/make/banchanHelp.sh
848 return
849 fi
850
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100851 if [ -z "$product" ]; then
852 product=arm
853 elif [ $(echo $product | wc -w) -gt 1 ]; then
854 echo "banchan: Error: Multiple build archs or products supplied: $products"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100855 return
856 fi
857 if [ $(echo $variant | wc -w) -gt 1 ]; then
858 echo "banchan: Error: Multiple build variants supplied: $variant"
859 return
860 fi
861 if [ -z "$apps" ]; then
862 echo "banchan: Error: No modules supplied"
863 return
864 fi
865
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100866 case $product in
867 arm) product=module_arm;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100868 x86) product=module_x86;;
869 arm64) product=module_arm64;;
870 x86_64) product=module_x86_64;;
871 esac
872 if [ -z "$variant" ]; then
873 variant=eng
874 fi
875
876 export TARGET_PRODUCT=$product
877 export TARGET_BUILD_VARIANT=$variant
878 export TARGET_BUILD_DENSITY=alldpi
879 export TARGET_BUILD_TYPE=release
880
881 # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use
882 # case is different and it may diverge in the future.
883 export TARGET_BUILD_APPS=$apps
884
885 build_build_var_cache
886 set_stuff_for_environment
887 printconfig
888 destroy_build_var_cache
889}
890
Matt Alexanderd9c56562020-05-21 10:49:17 +0000891function gettop
892{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700893 local TOPFILE=build/make/core/envsetup.mk
Matt Alexanderd9c56562020-05-21 10:49:17 +0000894 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700895 # The following circumlocution ensures we remove symlinks from TOP.
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000896 (cd "$TOP"; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700897 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000898 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800899 # The following circumlocution (repeated below as well) ensures
900 # that we record the true directory name and not one that is
901 # faked up with symlink names.
902 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700903 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800904 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700905 local T=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000906 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800907 \cd ..
synergyb112a402013-07-05 19:47:47 -0700908 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700909 done
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000910 \cd "$HERE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700911 if [ -f "$T/$TOPFILE" ]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000912 echo "$T"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700913 fi
914 fi
915 fi
916}
917
Matt Alexanderd9c56562020-05-21 10:49:17 +0000918function croot()
919{
Christopher Ferris55257d22017-03-23 11:08:58 -0700920 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700921 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700922 if [ "$1" ]; then
923 \cd $(gettop)/$1
924 else
925 \cd $(gettop)
926 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700927 else
928 echo "Couldn't locate the top of the tree. Try setting TOP."
929 fi
930}
931
Matt Alexanderd9c56562020-05-21 10:49:17 +0000932function _croot()
933{
Anton Hanssonece9c482019-02-04 18:15:39 +0000934 local T=$(gettop)
935 if [ "$T" ]; then
936 local cur="${COMP_WORDS[COMP_CWORD]}"
937 k=0
938 for c in $(compgen -d ${T}/${cur}); do
939 COMPREPLY[k++]=${c#${T}/}/
940 done
941 fi
942}
943
Matt Alexanderd9c56562020-05-21 10:49:17 +0000944function cproj()
945{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700946 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700947 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700948 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700949 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
950 T=$PWD
951 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800952 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700953 return
954 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800955 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700956 done
Ying Wang9cd17642012-12-13 10:52:07 -0800957 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700958 echo "can't find Android.mk"
959}
960
Daniel Sandler47e0a882013-07-30 13:23:52 -0400961# simplified version of ps; output in the form
962# <pid> <procname>
963function qpid() {
964 local prepend=''
965 local append=''
Matt Alexanderd9c56562020-05-21 10:49:17 +0000966 if [ "$1" = "--exact" ]; then
Daniel Sandler47e0a882013-07-30 13:23:52 -0400967 prepend=' '
968 append='$'
969 shift
Matt Alexanderd9c56562020-05-21 10:49:17 +0000970 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -0800971 echo "usage: qpid [[--exact] <process name|pid>"
972 return 255
973 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -0400974
975 local EXE="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +0000976 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -0800977 qpid | \grep "$prepend$EXE$append"
978 else
979 adb shell ps \
980 | tr -d '\r' \
981 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
982 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -0400983}
984
Steven Moreland74114f12020-09-10 01:23:32 +0000985# syswrite - disable verity, reboot if needed, and remount image
986#
987# Easy way to make system.img/etc writable
988function syswrite() {
989 adb wait-for-device && adb root || return 1
990 if [[ $(adb disable-verity | grep "reboot") ]]; then
991 echo "rebooting"
992 adb reboot && adb wait-for-device && adb root || return 1
993 fi
994 adb wait-for-device && adb remount || return 1
995}
996
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800997# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700998# that has the core-file-size limit set correctly
999#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001000# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001001# if its core-file-size limit is not set already.
1002# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1003
Matt Alexanderd9c56562020-05-21 10:49:17 +00001004function coredump_setup()
1005{
1006 echo "Getting root...";
1007 adb root;
1008 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001009
Matt Alexanderd9c56562020-05-21 10:49:17 +00001010 echo "Remounting root partition read-write...";
1011 adb shell mount -w -o remount -t rootfs rootfs;
1012 sleep 1;
1013 adb wait-for-device;
1014 adb shell mkdir -p /cores;
1015 adb shell mount -t tmpfs tmpfs /cores;
1016 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001017
Matt Alexanderd9c56562020-05-21 10:49:17 +00001018 echo "Granting SELinux permission to dump in /cores...";
1019 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001020
Matt Alexanderd9c56562020-05-21 10:49:17 +00001021 echo "Set core pattern.";
1022 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001023
Ying Wang08800fd2016-03-03 20:57:21 -08001024 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001025}
1026
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001027# coredump_enable - enable core dumps for the specified process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001028# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001029#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001030# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001031# dump to actually be generated.
1032
Matt Alexanderd9c56562020-05-21 10:49:17 +00001033function coredump_enable()
1034{
1035 local PID=$1;
Ying Wang08800fd2016-03-03 20:57:21 -08001036 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001037 printf "Expecting a PID!\n";
1038 return;
1039 fi;
1040 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001041 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001042}
1043
1044# core - send SIGV and pull the core for process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001045# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001046#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001047# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001048# enabled globally.
1049
Matt Alexanderd9c56562020-05-21 10:49:17 +00001050function core()
1051{
1052 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001053
Ying Wang08800fd2016-03-03 20:57:21 -08001054 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001055 printf "Expecting a PID!\n";
1056 return;
1057 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001058
Matt Alexanderd9c56562020-05-21 10:49:17 +00001059 local CORENAME=core.$PID;
1060 local COREPATH=/cores/$CORENAME;
1061 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001062
Matt Alexanderd9c56562020-05-21 10:49:17 +00001063 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001064
Matt Alexanderd9c56562020-05-21 10:49:17 +00001065 local done=0;
Ying Wang08800fd2016-03-03 20:57:21 -08001066 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
Matt Alexanderd9c56562020-05-21 10:49:17 +00001067 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1068 adb shell kill -$SIG $PID;
1069 sleep 1;
1070 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001071
Matt Alexanderd9c56562020-05-21 10:49:17 +00001072 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1073 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001074}
1075
Christopher Tate744ee802009-11-12 15:33:08 -08001076# systemstack - dump the current stack trace of all threads in the system process
1077# to the usual ANR traces file
Matt Alexanderd9c56562020-05-21 10:49:17 +00001078function systemstack()
1079{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001080 stacks system_server
1081}
1082
Michael Wrightaeed7212014-06-19 19:58:12 -07001083# Read the ELF header from /proc/$PID/exe to determine if the process is
1084# 64-bit.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001085function is64bit()
1086{
Ben Chengfba67bf2014-02-25 10:27:07 -08001087 local PID="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001088 if [ "$PID" ] ; then
1089 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001090 echo "64"
1091 else
1092 echo ""
1093 fi
1094 else
1095 echo ""
1096 fi
1097}
1098
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001099case `uname -s` in
1100 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001101 function sgrep()
1102 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001103 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 -04001104 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001105 }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001106
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001107 ;;
1108 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001109 function sgrep()
1110 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001111 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 -04001112 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001113 }
1114 ;;
1115esac
1116
Matt Alexanderd9c56562020-05-21 10:49:17 +00001117function gettargetarch
1118{
Raghu Gandham8da43102012-07-25 19:57:22 -07001119 get_build_var TARGET_ARCH
1120}
1121
Matt Alexanderd9c56562020-05-21 10:49:17 +00001122function ggrep()
1123{
Mike Frysinger5e479732015-09-22 18:13:48 -04001124 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1125 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001126}
1127
Matt Alexanderd9c56562020-05-21 10:49:17 +00001128function gogrep()
1129{
Orion Hodson831472d2019-10-25 11:35:15 +01001130 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
1131 -exec grep --color -n "$@" {} +
1132}
1133
Matt Alexanderd9c56562020-05-21 10:49:17 +00001134function jgrep()
1135{
Mike Frysinger5e479732015-09-22 18:13:48 -04001136 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1137 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001138}
1139
Alistair Delva176e5342021-02-22 13:31:26 -08001140function rsgrep()
Jeff Vander Stoep1431ab82021-02-02 19:18:26 +01001141{
1142 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rs" \
1143 -exec grep --color -n "$@" {} +
1144}
1145
Taesu Leeea0cecd2020-10-28 11:05:18 +09001146function ktgrep()
1147{
1148 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.kt" \
1149 -exec grep --color -n "$@" {} +
1150}
1151
Matt Alexanderd9c56562020-05-21 10:49:17 +00001152function cgrep()
1153{
Mike Frysinger5e479732015-09-22 18:13:48 -04001154 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' \) \
1155 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001156}
1157
Matt Alexanderd9c56562020-05-21 10:49:17 +00001158function resgrep()
1159{
Christopher Ferris55257d22017-03-23 11:08:58 -07001160 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001161 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1162 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1163 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001164}
1165
Matt Alexanderd9c56562020-05-21 10:49:17 +00001166function mangrep()
1167{
Mike Frysinger5e479732015-09-22 18:13:48 -04001168 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1169 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001170}
1171
Matt Alexanderd9c56562020-05-21 10:49:17 +00001172function owngrep()
1173{
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -06001174 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
1175 -exec grep --color -n "$@" {} +
1176}
1177
Matt Alexanderd9c56562020-05-21 10:49:17 +00001178function sepgrep()
1179{
Mike Frysinger5e479732015-09-22 18:13:48 -04001180 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1181 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001182}
1183
Matt Alexanderd9c56562020-05-21 10:49:17 +00001184function rcgrep()
1185{
Mike Frysinger5e479732015-09-22 18:13:48 -04001186 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1187 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001188}
1189
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001190case `uname -s` in
1191 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001192 function mgrep()
1193 {
Orion Hodson831472d2019-10-25 11:35:15 +01001194 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 -04001195 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001196 }
1197
Matt Alexanderd9c56562020-05-21 10:49:17 +00001198 function treegrep()
1199 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001200 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 -04001201 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001202 }
1203
1204 ;;
1205 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001206 function mgrep()
1207 {
Orion Hodson831472d2019-10-25 11:35:15 +01001208 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 -04001209 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001210 }
1211
Matt Alexanderd9c56562020-05-21 10:49:17 +00001212 function treegrep()
1213 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001214 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 -04001215 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001216 }
1217
1218 ;;
1219esac
1220
Matt Alexanderd9c56562020-05-21 10:49:17 +00001221function getprebuilt
1222{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001223 get_abs_build_var ANDROID_PREBUILTS
1224}
1225
Matt Alexanderd9c56562020-05-21 10:49:17 +00001226function tracedmdump()
1227{
Christopher Ferris55257d22017-03-23 11:08:58 -07001228 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001229 if [ ! "$T" ]; then
1230 echo "Couldn't locate the top of the tree. Try setting TOP."
1231 return
1232 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001233 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001234 local arch=$(gettargetarch)
1235 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001237 local TRACE=$1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001238 if [ ! "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001239 echo "usage: tracedmdump tracename"
1240 return
1241 fi
1242
Matt Alexanderd9c56562020-05-21 10:49:17 +00001243 if [ ! -r "$KERNEL" ] ; then
Jack Veenstra60116fc2009-04-09 18:12:34 -07001244 echo "Error: cannot find kernel: '$KERNEL'"
1245 return
1246 fi
1247
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001248 local BASETRACE=$(basename $TRACE)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001249 if [ "$BASETRACE" = "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001250 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1251 fi
1252
1253 echo "post-processing traces..."
1254 rm -f $TRACE/qtrace.dexlist
1255 post_trace $TRACE
1256 if [ $? -ne 0 ]; then
1257 echo "***"
1258 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1259 echo "***"
1260 return
1261 fi
1262 echo "generating dexlist output..."
1263 /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
1264 echo "generating dmtrace data..."
1265 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1266 echo "generating html file..."
1267 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1268 echo "done, see $TRACE/dmtrace.html for details"
1269 echo "or run:"
1270 echo " traceview $TRACE/dmtrace"
1271}
1272
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001273# communicate with a running device or emulator, set up necessary state,
1274# and run the hat command.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001275function runhat()
1276{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001277 # process standard adb options
1278 local adbTarget=""
Matt Alexanderd9c56562020-05-21 10:49:17 +00001279 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001280 adbTarget=$1
1281 shift 1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001282 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001283 adbTarget="$1 $2"
1284 shift 2
1285 fi
1286 local adbOptions=${adbTarget}
Matt Alexanderd9c56562020-05-21 10:49:17 +00001287 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001288
1289 # runhat options
1290 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001291
Matt Alexanderd9c56562020-05-21 10:49:17 +00001292 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001293 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001294 return
1295 fi
1296
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001297 # confirm hat is available
1298 if [ -z $(which hat) ]; then
1299 echo "hat is not available in this configuration."
1300 return
1301 fi
1302
Andy McFaddenb6289852010-07-12 08:00:19 -07001303 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001304 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001305 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001306 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001307 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001308 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001309 echo -n "> "
1310 read
1311
The Android Open Source Project88b60792009-03-03 19:28:42 -08001312 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001313
The Android Open Source Project88b60792009-03-03 19:28:42 -08001314 echo "Retrieving file $devFile..."
1315 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001316
The Android Open Source Project88b60792009-03-03 19:28:42 -08001317 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001318
The Android Open Source Project88b60792009-03-03 19:28:42 -08001319 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001320 echo "View the output by pointing your browser at http://localhost:7000/"
1321 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001322 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001323}
1324
Matt Alexanderd9c56562020-05-21 10:49:17 +00001325function getbugreports()
1326{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001327 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001328
1329 if [ ! "$reports" ]; then
1330 echo "Could not locate any bugreports."
1331 return
1332 fi
1333
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001334 local report
1335 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001336 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001337 echo "/sdcard/bugreports/${report}"
1338 adb pull /sdcard/bugreports/${report} ${report}
1339 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001340 done
1341}
1342
Matt Alexanderd9c56562020-05-21 10:49:17 +00001343function getsdcardpath()
1344{
Victoria Lease1b296b42012-08-21 15:44:06 -07001345 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1346}
1347
Matt Alexanderd9c56562020-05-21 10:49:17 +00001348function getscreenshotpath()
1349{
Victoria Lease1b296b42012-08-21 15:44:06 -07001350 echo "$(getsdcardpath)/Pictures/Screenshots"
1351}
1352
Matt Alexanderd9c56562020-05-21 10:49:17 +00001353function getlastscreenshot()
1354{
Victoria Lease1b296b42012-08-21 15:44:06 -07001355 local screenshot_path=$(getscreenshotpath)
1356 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 +00001357 if [ "$screenshot" = "" ]; then
Victoria Lease1b296b42012-08-21 15:44:06 -07001358 echo "No screenshots found."
1359 return
1360 fi
1361 echo "${screenshot}"
1362 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1363}
1364
Matt Alexanderd9c56562020-05-21 10:49:17 +00001365function startviewserver()
1366{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001367 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001368 if [ $# -gt 0 ]; then
1369 port=$1
1370 fi
1371 adb shell service call window 1 i32 $port
1372}
1373
Matt Alexanderd9c56562020-05-21 10:49:17 +00001374function stopviewserver()
1375{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001376 adb shell service call window 2
1377}
1378
Matt Alexanderd9c56562020-05-21 10:49:17 +00001379function isviewserverstarted()
1380{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001381 adb shell service call window 3
1382}
1383
Matt Alexanderd9c56562020-05-21 10:49:17 +00001384function key_home()
1385{
Romain Guyb84049a2010-10-04 16:56:11 -07001386 adb shell input keyevent 3
1387}
1388
Matt Alexanderd9c56562020-05-21 10:49:17 +00001389function key_back()
1390{
Romain Guyb84049a2010-10-04 16:56:11 -07001391 adb shell input keyevent 4
1392}
1393
Matt Alexanderd9c56562020-05-21 10:49:17 +00001394function key_menu()
1395{
Romain Guyb84049a2010-10-04 16:56:11 -07001396 adb shell input keyevent 82
1397}
1398
Matt Alexanderd9c56562020-05-21 10:49:17 +00001399function smoketest()
1400{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001401 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1402 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1403 return
1404 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001405 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001406 if [ ! "$T" ]; then
1407 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1408 return
1409 fi
1410
Ying Wang9cd17642012-12-13 10:52:07 -08001411 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001412 adb uninstall com.android.smoketest > /dev/null &&
1413 adb uninstall com.android.smoketest.tests > /dev/null &&
1414 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1415 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1416 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1417}
1418
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001419# simple shortcut to the runtest command
Matt Alexanderd9c56562020-05-21 10:49:17 +00001420function runtest()
1421{
Christopher Ferris55257d22017-03-23 11:08:58 -07001422 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001423 if [ ! "$T" ]; then
1424 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1425 return
1426 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001427 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001428}
1429
The Android Open Source Project88b60792009-03-03 19:28:42 -08001430function godir () {
1431 if [[ -z "$1" ]]; then
1432 echo "Usage: godir <regex>"
1433 return
1434 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001435 local T=$(gettop)
1436 local FILELIST
Matt Alexanderd9c56562020-05-21 10:49:17 +00001437 if [ ! "$OUT_DIR" = "" ]; then
Brian Carlstromf2257422015-09-30 20:28:54 -07001438 mkdir -p $OUT_DIR
1439 FILELIST=$OUT_DIR/filelist
1440 else
1441 FILELIST=$T/filelist
1442 fi
1443 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001444 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001445 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001446 echo " Done"
1447 echo ""
1448 fi
1449 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001450 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
Matt Alexanderd9c56562020-05-21 10:49:17 +00001451 if [[ ${#lines[@]} = 0 ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001452 echo "Not found"
1453 return
1454 fi
1455 local pathname
1456 local choice
1457 if [[ ${#lines[@]} > 1 ]]; then
1458 while [[ -z "$pathname" ]]; do
1459 local index=1
1460 local line
1461 for line in ${lines[@]}; do
1462 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001463 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001464 done
1465 echo
1466 echo -n "Select one: "
1467 unset choice
1468 read choice
1469 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1470 echo "Invalid choice"
1471 continue
1472 fi
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001473 pathname=${lines[@]:$(($choice-1)):1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001474 done
1475 else
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001476 pathname=${lines[@]:0:1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001477 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001478 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001479}
1480
Steven Moreland62054a42018-12-06 10:11:40 -08001481# Update module-info.json in out.
1482function refreshmod() {
1483 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1484 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1485 return 1
1486 fi
1487
1488 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1489
1490 # for the output of the next command
1491 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1492
1493 # Note, can't use absolute path because of the way make works.
Alessandro Astonec8771be2020-05-10 11:27:57 +02001494 m $(get_build_var PRODUCT_OUT)/module-info.json \
Steven Moreland62054a42018-12-06 10:11:40 -08001495 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1496}
1497
Cole Faust24c36db2021-01-23 02:39:37 +00001498# Verifies that module-info.txt exists, creating it if it doesn't.
1499function verifymodinfo() {
Steven Moreland62054a42018-12-06 10:11:40 -08001500 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001501 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
1502 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1503 fi
Steven Moreland62054a42018-12-06 10:11:40 -08001504 return 1
1505 fi
1506
1507 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001508 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
1509 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1510 fi
1511 return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001512 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001513}
1514
1515# List all modules for the current device, as cached in module-info.json. If any build change is
1516# made and it should be reflected in the output, you should run 'refreshmod' first.
1517function allmod() {
1518 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001519
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001520 python3 -c "import json; print('\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys())))"
Steven Moreland62054a42018-12-06 10:11:40 -08001521}
1522
Joe Onorato2c1aa472021-02-25 16:42:39 -08001523# Get the path of a specific module in the android tree, as cached in module-info.json.
1524# If any build change is made, and it should be reflected in the output, you should run
1525# 'refreshmod' first. Note: This is the inverse of dirmods.
Rett Berg78d1c932019-01-24 14:34:23 -08001526function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001527 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001528 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001529 return 1
1530 fi
1531
Cole Faust24c36db2021-01-23 02:39:37 +00001532 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001533
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001534 local relpath=$(python3 -c "import json, os
Steven Moreland62054a42018-12-06 10:11:40 -08001535module = '$1'
1536module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1537if module not in module_info:
1538 exit(1)
LuK1337b6a78192020-01-12 03:12:17 +01001539print(module_info[module]['path'][0])" 2>/dev/null)
Steven Moreland62054a42018-12-06 10:11:40 -08001540
1541 if [ -z "$relpath" ]; then
1542 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1543 return 1
1544 else
Rett Berg78d1c932019-01-24 14:34:23 -08001545 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001546 fi
1547}
1548
Joe Onorato2c1aa472021-02-25 16:42:39 -08001549# Get the path of a specific module in the android tree, as cached in module-info.json.
1550# If any build change is made, and it should be reflected in the output, you should run
1551# 'refreshmod' first. Note: This is the inverse of pathmod.
1552function dirmods() {
1553 if [[ $# -ne 1 ]]; then
1554 echo "usage: dirmods <path>" >&2
1555 return 1
1556 fi
1557
1558 verifymodinfo || return 1
1559
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001560 python3 -c "import json, os
Joe Onorato2c1aa472021-02-25 16:42:39 -08001561dir = '$1'
1562while dir.endswith('/'):
1563 dir = dir[:-1]
1564prefix = dir + '/'
1565module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1566results = set()
1567for m in module_info.values():
1568 for path in m.get(u'path', []):
1569 if path == dir or path.startswith(prefix):
1570 name = m.get(u'module_name')
1571 if name:
1572 results.add(name)
1573for name in sorted(results):
1574 print(name)
1575"
1576}
1577
1578
Rett Berg78d1c932019-01-24 14:34:23 -08001579# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1580# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1581function gomod() {
1582 if [[ $# -ne 1 ]]; then
1583 echo "usage: gomod <module>" >&2
1584 return 1
1585 fi
1586
1587 local path="$(pathmod $@)"
1588 if [ -z "$path" ]; then
1589 return 1
1590 fi
1591 cd $path
1592}
1593
Cole Faust24c36db2021-01-23 02:39:37 +00001594# Gets the list of a module's installed outputs, as cached in module-info.json.
1595# If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first.
1596function outmod() {
1597 if [[ $# -ne 1 ]]; then
1598 echo "usage: outmod <module>" >&2
1599 return 1
1600 fi
1601
1602 verifymodinfo || return 1
1603
1604 local relpath
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001605 relpath=$(python3 -c "import json, os
Cole Faust24c36db2021-01-23 02:39:37 +00001606module = '$1'
1607module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1608if module not in module_info:
1609 exit(1)
1610for output in module_info[module]['installed']:
1611 print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null)
1612
1613 if [ $? -ne 0 ]; then
1614 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2
1615 return 1
1616 elif [ ! -z "$relpath" ]; then
1617 echo "$relpath"
1618 fi
1619}
1620
1621# adb install a module's apk, as cached in module-info.json. If any build change
1622# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1623# Usage: installmod [adb install arguments] <module>
1624# For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk
1625function installmod() {
1626 if [[ $# -eq 0 ]]; then
1627 echo "usage: installmod [adb install arguments] <module>" >&2
1628 return 1
1629 fi
1630
1631 local _path
1632 _path=$(outmod ${@:$#:1})
1633 if [ $? -ne 0 ]; then
1634 return 1
1635 fi
1636
1637 _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1)
1638 if [ -z "$_path" ]; then
1639 echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2
1640 return 1
1641 fi
1642 local length=$(( $# - 1 ))
1643 echo adb install ${@:1:$length} $_path
1644 adb install ${@:1:$length} $_path
1645}
1646
dimitry73b84812018-12-11 18:06:00 +01001647function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001648 local word=${COMP_WORDS[COMP_CWORD]}
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001649 COMPREPLY=( $(QUIET_VERIFYMODINFO=true allmod | grep -E "^$word") )
Steven Moreland62054a42018-12-06 10:11:40 -08001650}
1651
Alex Rayf0d08eb2013-03-08 15:15:06 -08001652# Print colored exit condition
1653function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001654 "$@"
1655 local retval=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +00001656 if [ $retval -ne 0 ]
1657 then
Jacky Cao89483b82015-05-15 22:12:53 +08001658 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001659 else
Jacky Cao89483b82015-05-15 22:12:53 +08001660 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001661 fi
1662 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001663}
1664
Matt Alexanderd9c56562020-05-21 10:49:17 +00001665function get_make_command()
1666{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001667 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1668 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001669 # Always use the real make if -C is passed in
1670 for arg in "$@"; do
1671 if [[ $arg == -C* ]]; then
1672 echo command make
1673 return
1674 fi
1675 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001676 echo build/soong/soong_ui.bash --make-mode
1677 else
1678 echo command make
1679 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001680}
1681
Matt Alexanderd9c56562020-05-21 10:49:17 +00001682function _wrap_build()
1683{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001684 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1685 "$@"
1686 return $?
1687 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001688 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001689 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001690 local ret=$?
1691 local end_time=$(date +"%s")
1692 local tdiff=$(($end_time-$start_time))
1693 local hours=$(($tdiff / 3600 ))
1694 local mins=$((($tdiff % 3600) / 60))
1695 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001696 local ncolors=$(tput colors 2>/dev/null)
1697 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001698 color_failed=$'\E'"[0;31m"
1699 color_success=$'\E'"[0;32m"
1700 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001701 else
1702 color_failed=""
1703 color_success=""
1704 color_reset=""
1705 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001706 echo
Matt Alexanderd9c56562020-05-21 10:49:17 +00001707 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001708 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001709 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001710 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001711 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +00001712 if [ $hours -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001713 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001714 elif [ $mins -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001715 printf "(%02g:%02g (mm:ss))" $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001716 elif [ $secs -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001717 printf "(%s seconds)" $secs
1718 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001719 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001720 echo
1721 return $ret
1722}
1723
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001724function _trigger_build()
1725(
1726 local -r bc="$1"; shift
1727 if T="$(gettop)"; then
1728 _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
1729 else
1730 echo "Couldn't locate the top of the tree. Try setting TOP."
1731 fi
1732)
1733
1734function m()
1735(
1736 _trigger_build "all-modules" "$@"
1737)
1738
1739function mm()
1740(
1741 _trigger_build "modules-in-a-dir-no-deps" "$@"
1742)
1743
1744function mmm()
1745(
1746 _trigger_build "modules-in-dirs-no-deps" "$@"
1747)
1748
1749function mma()
1750(
1751 _trigger_build "modules-in-a-dir" "$@"
1752)
1753
1754function mmma()
1755(
1756 _trigger_build "modules-in-dirs" "$@"
1757)
1758
Matt Alexanderd9c56562020-05-21 10:49:17 +00001759function make()
1760{
Dan Willemsene9842242017-07-28 13:00:13 -07001761 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001762}
1763
Matt Alexanderd9c56562020-05-21 10:49:17 +00001764function provision()
1765{
David Zeuthen1b126ff2015-09-30 17:10:48 -04001766 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1767 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1768 return 1
1769 fi
1770 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1771 echo "There is no provisioning script for the device." >&2
1772 return 1
1773 fi
1774
1775 # Check if user really wants to do this.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001776 if [ "$1" = "--no-confirmation" ]; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001777 shift 1
1778 else
1779 echo "This action will reflash your device."
1780 echo ""
1781 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1782 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001783 echo -n "Are you sure you want to do this (yes/no)? "
1784 read
Matt Alexanderd9c56562020-05-21 10:49:17 +00001785 if [[ "${REPLY}" != "yes" ]] ; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001786 echo "Not taking any action. Exiting." >&2
1787 return 1
1788 fi
1789 fi
1790 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1791}
1792
Jim Tanga881a252018-06-19 16:34:41 +08001793# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001794function enable_zsh_completion() {
1795 # Don't override user's options if bash-style completion is already enabled.
1796 if ! declare -f complete >/dev/null; then
1797 autoload -U compinit && compinit
1798 autoload -U bashcompinit && bashcompinit
1799 fi
Jim Tanga881a252018-06-19 16:34:41 +08001800}
1801
1802function validate_current_shell() {
1803 local current_sh="$(ps -o command -p $$)"
1804 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001805 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001806 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001807 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001808 *zsh*)
1809 function check_type() { type "$1"; }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001810 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001811 *)
Jim Tanga881a252018-06-19 16:34:41 +08001812 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 -07001813 ;;
1814 esac
Jim Tanga881a252018-06-19 16:34:41 +08001815}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001816
1817# Execute the contents of any vendorsetup.sh files we can find.
Dan Willemsend855a722019-02-12 15:52:36 -08001818# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
1819# load those.
1820#
1821# This allows loading only approved vendorsetup.sh files
Jim Tanga881a252018-06-19 16:34:41 +08001822function source_vendorsetup() {
Jim Tangc4dba1d2019-07-25 16:54:27 +08001823 unset VENDOR_PYTHONPATH
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001824 local T="$(gettop)"
Dan Willemsend855a722019-02-12 15:52:36 -08001825 allowed=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001826 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 -08001827 if [ -n "$allowed" ]; then
1828 echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
1829 echo " $allowed"
1830 echo " $f"
1831 return
1832 fi
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001833 allowed="$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001834 done
1835
1836 allowed_files=
1837 [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
Jim Tanga881a252018-06-19 16:34:41 +08001838 for dir in device vendor product; do
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001839 for f in $(cd "$T" && test -d $dir && \
Jim Tanga881a252018-06-19 16:34:41 +08001840 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001841
1842 if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001843 echo "including $f"; . "$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001844 else
1845 echo "ignoring $f, not in $allowed"
1846 fi
Jim Tanga881a252018-06-19 16:34:41 +08001847 done
1848 done
1849}
Kenny Root52aa81c2011-07-15 11:07:06 -07001850
Dan Albertbab814f2020-08-26 15:34:53 -07001851function showcommands() {
1852 local T=$(gettop)
1853 if [[ -z "$TARGET_PRODUCT" ]]; then
1854 >&2 echo "TARGET_PRODUCT not set. Run lunch."
1855 return
1856 fi
1857 case $(uname -s) in
1858 Darwin)
1859 PREBUILT_NAME=darwin-x86
1860 ;;
1861 Linux)
1862 PREBUILT_NAME=linux-x86
1863 ;;
1864 *)
1865 >&2 echo Unknown host $(uname -s)
1866 return
1867 ;;
1868 esac
1869 if [[ -z "$OUT_DIR" ]]; then
1870 if [[ -z "$OUT_DIR_COMMON_BASE" ]]; then
1871 OUT_DIR=out
1872 else
1873 OUT_DIR=${OUT_DIR_COMMON_BASE}/${PWD##*/}
1874 fi
1875 fi
1876 if [[ "$1" == "--regenerate" ]]; then
1877 shift 1
1878 NINJA_ARGS="-t commands $@" m
1879 else
1880 (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \
1881 -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \
1882 -t commands "$@")
1883 fi
1884}
1885
Jim Tanga881a252018-06-19 16:34:41 +08001886validate_current_shell
1887source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001888addcompletions
Chirayu Desaic0da18c2013-03-19 17:50:37 +05301889
1890export ANDROID_BUILD_TOP=$(gettop)
Michael Bestas64020242016-08-26 00:37:02 +03001891
1892. $ANDROID_BUILD_TOP/vendor/bliss/build/envsetup.sh