blob: c281bff7b7bfc6d8640d7944886d70f3b9d8616a [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 Bestasb744e742016-08-26 00:37:02 +030047EOF
48
49 __print_lineage_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 Bestasb744e742016-08-26 00:37:02 +030062 for i in `cat $T/build/envsetup.sh $T/vendor/lineage/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 Bestasb744e742016-08-26 00:37:02 +030073 cached_vars=(`cat $T/build/envsetup.sh $T/vendor/lineage/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/lineage/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 Stefani93102ff2017-08-17 21:21:23 +0200156 if (echo -n $1 | grep -q -e "^lineage_") ; then
157 LINEAGE_BUILD=$(echo -n $1 | sed -e 's/^lineage_//g')
158 else
159 LINEAGE_BUILD=
160 fi
161 export LINEAGE_BUILD
162
Jeff Browne33ba4c2011-07-11 22:11:46 -0700163 TARGET_PRODUCT=$1 \
164 TARGET_BUILD_VARIANT= \
165 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700166 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800167 get_build_var TARGET_DEVICE > /dev/null
168 # hide successful answers, but allow the errors to show
169}
170
171VARIANT_CHOICES=(user userdebug eng)
172
173# check to see if the supplied variant is valid
Matt Alexanderd9c56562020-05-21 10:49:17 +0000174function check_variant()
175{
Christopher Ferris55257d22017-03-23 11:08:58 -0700176 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800177 for v in ${VARIANT_CHOICES[@]}
178 do
Matt Alexanderd9c56562020-05-21 10:49:17 +0000179 if [ "$v" = "$1" ]
180 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800181 return 0
182 fi
183 done
184 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700185}
186
Matt Alexanderd9c56562020-05-21 10:49:17 +0000187function setpaths()
188{
Christopher Ferris55257d22017-03-23 11:08:58 -0700189 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700190 if [ ! "$T" ]; then
191 echo "Couldn't locate the top of the tree. Try setting TOP."
192 return
193 fi
194
195 ##################################################################
196 # #
197 # Read me before you modify this code #
198 # #
199 # This function sets ANDROID_BUILD_PATHS to what it is adding #
200 # to PATH, and the next time it is run, it removes that from #
201 # PATH. This is required so lunch can be run more than once #
202 # and still have working paths. #
203 # #
204 ##################################################################
205
Raphael Mollc639c782011-06-20 17:25:01 -0700206 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
207 # due to "C:\Program Files" being in the path.
208
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700209 # out with the old
Matt Alexanderd9c56562020-05-21 10:49:17 +0000210 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700211 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
212 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000213 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700214 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800215 # strip leading ':', if any
216 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500217 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700218
219 # and in with the new
Christopher Ferris55257d22017-03-23 11:08:58 -0700220 local prebuiltdir=$(getprebuilt)
221 local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700222
Ben Cheng8bc4c432012-11-16 13:29:13 -0800223 # defined in core/config.mk
Christopher Ferris55257d22017-03-23 11:08:58 -0700224 local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
225 local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800226 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800227
Raphael Mollc639c782011-06-20 17:25:01 -0700228 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800229 export ANDROID_TOOLCHAIN=
230 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200231 local ARCH=$(get_build_var TARGET_ARCH)
Christopher Ferris55257d22017-03-23 11:08:58 -0700232 local toolchaindir toolchaindir2=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200233 case $ARCH in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000234 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700235 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000236 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Pavel Chupinfd82a492012-11-26 09:50:07 +0400237 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000238 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200239 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000240 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
241 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700242 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200243 *)
244 echo "Can't find toolchain for unknown architecture: $ARCH"
245 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700246 ;;
247 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700248 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800249 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700250 fi
Raphael732936d2011-06-22 14:35:32 -0700251
Christopher Ferris55257d22017-03-23 11:08:58 -0700252 if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800253 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
254 fi
255
Dan Willemsen838dcec2021-09-30 22:40:34 +0000256 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Yueyao Zhuefc786a2017-04-07 14:11:54 -0700257
258 # add kernel specific binaries
259 case $(uname -s) in
260 Linux)
261 export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
262 ;;
263 *)
264 ;;
265 esac
266
Torne (Richard Coles)0091bae2017-10-03 16:31:18 -0400267 ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN
Martin Stjernholm6a012262021-11-24 14:56:15 +0000268 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH
Yi Kongdfd00b12019-05-21 16:00:04 -0700269 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS
270
271 # Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS.
272 local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
273 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200274
Stephen Hinesaa8d72c2020-02-04 09:15:18 -0800275 # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds.
276 export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer
277
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200278 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
279 # to ensure that the corresponding 'emulator' binaries are used.
280 case $(uname -s) in
281 Darwin)
282 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
283 ;;
284 Linux)
285 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
286 ;;
287 *)
288 ANDROID_EMULATOR_PREBUILTS=
289 ;;
290 esac
291 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Yi Kongdfd00b12019-05-21 16:00:04 -0700292 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200293 export ANDROID_EMULATOR_PREBUILTS
294 fi
295
Jim Tangb3fda302018-12-22 10:24:55 +0800296 # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
297 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
Ryan Prichard8426a192019-07-15 18:05:29 -0700298 local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch"
299 local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch"
300 local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch"
Martin Stjernholm6a012262021-11-24 14:56:15 +0000301 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH
Jim Tangb3fda302018-12-22 10:24:55 +0800302
Martin Stjernholm6a012262021-11-24 14:56:15 +0000303 export ANDROID_BUILD_PATHS=$(tr -s : <<<"${ANDROID_BUILD_PATHS}:")
Ryan Prichard8426a192019-07-15 18:05:29 -0700304 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800305
306 # out with the duplicate old
307 if [ -n $ANDROID_PYTHONPATH ]; then
308 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
309 fi
310 # and in with the new
311 export ANDROID_PYTHONPATH=$T/development/python-packages:
Jim Tangc4dba1d2019-07-25 16:54:27 +0800312 if [ -n $VENDOR_PYTHONPATH ]; then
313 ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
314 fi
Jim Tang22f4c322018-12-17 15:21:53 +0800315 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316
Colin Crosse97e6932017-06-30 16:01:45 -0700317 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
318 export JAVA_HOME=$ANDROID_JAVA_HOME
319 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
320 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
321 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500322
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800323 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700324 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
325 export OUT=$ANDROID_PRODUCT_OUT
326
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700327 unset ANDROID_HOST_OUT
328 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
329
Jiyong Parkc02b1c42020-11-03 11:06:39 +0900330 unset ANDROID_SOONG_HOST_OUT
331 export ANDROID_SOONG_HOST_OUT=$(get_abs_build_var SOONG_HOST_OUT)
332
Simran Basidd050ed2017-02-13 13:46:48 -0800333 unset ANDROID_HOST_OUT_TESTCASES
334 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
335
336 unset ANDROID_TARGET_OUT_TESTCASES
337 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
338
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800339 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700340 # TODO: fix the path
341 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
342}
343
Rupert Shuttleworth5d60d022020-10-25 05:20:03 +0000344function bazel()
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000345{
Jingwen Chen17d56992021-06-10 08:17:54 +0000346 if which bazel &>/dev/null; then
347 >&2 echo "NOTE: bazel() function sourced from Android's envsetup.sh is being used instead of $(which bazel)"
348 >&2 echo
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000349 fi
350
Jingwen Chen17d56992021-06-10 08:17:54 +0000351 local T="$(gettop)"
352 if [ ! "$T" ]; then
353 >&2 echo "Couldn't locate the top of the Android tree. Try setting TOP. This bazel() function cannot be used outside of the AOSP directory."
354 return
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000355 fi
356
Rupert Shuttleworth5d60d022020-10-25 05:20:03 +0000357 "$T/tools/bazel" "$@"
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000358}
359
Matt Alexanderd9c56562020-05-21 10:49:17 +0000360function printconfig()
361{
Christopher Ferris55257d22017-03-23 11:08:58 -0700362 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800363 if [ ! "$T" ]; then
364 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
365 return
366 fi
367 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700368}
369
Matt Alexanderd9c56562020-05-21 10:49:17 +0000370function set_stuff_for_environment()
371{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800372 setpaths
373 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700374
Ben Chengaac3f812013-08-13 14:38:15 -0700375 # With this environment variable new GCC can apply colors to warnings/errors
376 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 -0700377}
378
Matt Alexanderd9c56562020-05-21 10:49:17 +0000379function set_sequence_number()
380{
Colin Cross88737132017-03-21 17:41:03 -0700381 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700382}
383
Makoto Onukida971062018-06-18 10:15:19 -0700384# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
385function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800386 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700387 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800388 *:"$cmd":*)
389 return 1
390 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700391 esac
392 return 0
393}
394
Matt Alexanderd9c56562020-05-21 10:49:17 +0000395function addcompletions()
396{
Ben Taitelbaum8c2c9cf2020-09-22 16:45:05 -0700397 local f=
Kenny Root52aa81c2011-07-15 11:07:06 -0700398
Jim Tanga881a252018-06-19 16:34:41 +0800399 # Keep us from trying to run in something that's neither bash nor zsh.
400 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700401 return
402 fi
403
404 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800405 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700406 return
407 fi
408
Jim Tanga881a252018-06-19 16:34:41 +0800409 local completion_files=(
410 system/core/adb/adb.bash
411 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800412 tools/asuite/asuite.sh
Jim Tanga881a252018-06-19 16:34:41 +0800413 )
Makoto Onukida971062018-06-18 10:15:19 -0700414 # Completion can be disabled selectively to allow users to use non-standard completion.
415 # e.g.
416 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
417 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800418 for f in ${completion_files[*]}; do
419 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700420 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700421 fi
422 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700423
Matt Alexanderd9c56562020-05-21 10:49:17 +0000424 if should_add_completion bit ; then
Makoto Onukida971062018-06-18 10:15:19 -0700425 complete -C "bit --tab" bit
426 fi
Anton Hanssonece9c482019-02-04 18:15:39 +0000427 if [ -z "$ZSH_VERSION" ]; then
428 # Doesn't work in zsh.
429 complete -o nospace -F _croot croot
430 fi
Jim Tanga881a252018-06-19 16:34:41 +0800431 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800432
Cole Faust24c36db2021-01-23 02:39:37 +0000433 complete -F _complete_android_module_names pathmod
dimitry73b84812018-12-11 18:06:00 +0100434 complete -F _complete_android_module_names gomod
Cole Faust24c36db2021-01-23 02:39:37 +0000435 complete -F _complete_android_module_names outmod
436 complete -F _complete_android_module_names installmod
dimitry73b84812018-12-11 18:06:00 +0100437 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700438}
439
Joe Onorato824608c2022-04-08 11:06:16 -0700440function multitree_lunch_help()
441{
442 echo "usage: lunch PRODUCT-VARIANT" 1>&2
443 echo " Set up android build environment based on a product short name and variant" 1>&2
444 echo 1>&2
445 echo "lunch COMBO_FILE VARIANT" 1>&2
446 echo " Set up android build environment based on a specific lunch combo file" 1>&2
447 echo " and variant." 1>&2
448 echo 1>&2
449 echo "lunch --print [CONFIG]" 1>&2
450 echo " Print the contents of a configuration. If CONFIG is supplied, that config" 1>&2
451 echo " will be flattened and printed. If CONFIG is not supplied, the currently" 1>&2
452 echo " selected config will be printed. Returns 0 on success or nonzero on error." 1>&2
453 echo 1>&2
454 echo "lunch --list" 1>&2
455 echo " List all possible combo files available in the current tree" 1>&2
456 echo 1>&2
457 echo "lunch --help" 1>&2
458 echo "lunch -h" 1>&2
459 echo " Prints this message." 1>&2
460}
461
462function multitree_lunch()
463{
464 local code
465 local results
466 if $(echo "$1" | grep -q '^-') ; then
467 # Calls starting with a -- argument are passed directly and the function
468 # returns with the lunch.py exit code.
469 build/make/orchestrator/core/lunch.py "$@"
470 code=$?
471 if [[ $code -eq 2 ]] ; then
472 echo 1>&2
473 multitree_lunch_help
474 return $code
475 elif [[ $code -ne 0 ]] ; then
476 return $code
477 fi
478 else
479 # All other calls go through the --lunch variant of lunch.py
480 results=($(build/make/orchestrator/core/lunch.py --lunch "$@"))
481 code=$?
482 if [[ $code -eq 2 ]] ; then
483 echo 1>&2
484 multitree_lunch_help
485 return $code
486 elif [[ $code -ne 0 ]] ; then
487 return $code
488 fi
489
490 export TARGET_BUILD_COMBO=${results[0]}
491 export TARGET_BUILD_VARIANT=${results[1]}
492 fi
493}
494
Matt Alexanderd9c56562020-05-21 10:49:17 +0000495function choosetype()
496{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700497 echo "Build type choices are:"
498 echo " 1. release"
499 echo " 2. debug"
500 echo
501
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800502 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700503 DEFAULT_NUM=1
504 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700505
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506 export TARGET_BUILD_TYPE=
507 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 while [ -z $TARGET_BUILD_TYPE ]
509 do
510 echo -n "Which would you like? ["$DEFAULT_NUM"] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000511 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512 read ANSWER
513 else
514 echo $1
515 ANSWER=$1
516 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700517 case $ANSWER in
518 "")
519 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
520 ;;
521 1)
522 export TARGET_BUILD_TYPE=release
523 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800524 release)
525 export TARGET_BUILD_TYPE=release
526 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700527 2)
528 export TARGET_BUILD_TYPE=debug
529 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530 debug)
531 export TARGET_BUILD_TYPE=debug
532 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700533 *)
534 echo
535 echo "I didn't understand your response. Please try again."
536 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700537 ;;
538 esac
Matt Alexanderd9c56562020-05-21 10:49:17 +0000539 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800540 break
541 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700542 done
543
Ying Wang08800fd2016-03-03 20:57:21 -0800544 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700545 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800546 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700547}
548
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800549#
550# This function isn't really right: It chooses a TARGET_PRODUCT
551# based on the list of boards. Usually, that gets you something
552# that kinda works with a generic product, but really, you should
553# pick a product by name.
554#
Matt Alexanderd9c56562020-05-21 10:49:17 +0000555function chooseproduct()
556{
Christopher Ferris55257d22017-03-23 11:08:58 -0700557 local default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000558 if [ "x$TARGET_PRODUCT" != x ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700559 default_value=$TARGET_PRODUCT
560 else
Ying Wang0a76df52015-06-08 11:57:26 -0700561 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700562 fi
563
Ying Wang08800fd2016-03-03 20:57:21 -0800564 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800565 export TARGET_PRODUCT=
566 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700567 while [ -z "$TARGET_PRODUCT" ]
568 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700569 echo -n "Which product would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000570 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800571 read ANSWER
572 else
573 echo $1
574 ANSWER=$1
575 fi
576
Matt Alexanderd9c56562020-05-21 10:49:17 +0000577 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700578 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800579 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000580 if check_product $ANSWER
581 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800582 export TARGET_PRODUCT=$ANSWER
583 else
584 echo "** Not a valid product: $ANSWER"
585 fi
586 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000587 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800588 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700589 fi
590 done
591
Ying Wang08800fd2016-03-03 20:57:21 -0800592 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700593 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800594 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700595}
596
Matt Alexanderd9c56562020-05-21 10:49:17 +0000597function choosevariant()
598{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800599 echo "Variant choices are:"
600 local index=1
601 local v
602 for v in ${VARIANT_CHOICES[@]}
603 do
604 # The product name is the name of the directory containing
605 # the makefile we found, above.
606 echo " $index. $v"
607 index=$(($index+1))
608 done
609
610 local default_value=eng
611 local ANSWER
612
613 export TARGET_BUILD_VARIANT=
614 while [ -z "$TARGET_BUILD_VARIANT" ]
615 do
616 echo -n "Which would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000617 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800618 read ANSWER
619 else
620 echo $1
621 ANSWER=$1
622 fi
623
Matt Alexanderd9c56562020-05-21 10:49:17 +0000624 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800625 export TARGET_BUILD_VARIANT=$default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000626 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
627 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Guillaume Chelfice000fd2019-10-03 12:02:46 +0200628 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800629 fi
630 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000631 if check_variant $ANSWER
632 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800633 export TARGET_BUILD_VARIANT=$ANSWER
634 else
635 echo "** Not a valid variant: $ANSWER"
636 fi
637 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000638 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800639 break
640 fi
641 done
642}
643
Matt Alexanderd9c56562020-05-21 10:49:17 +0000644function choosecombo()
645{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700646 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700647
648 echo
649 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700650 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651
652 echo
653 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700654 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800655
656 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800657 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800659 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800660 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661}
662
Matt Alexanderd9c56562020-05-21 10:49:17 +0000663function add_lunch_combo()
664{
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800665 if [ -n "$ZSH_VERSION" ]; then
666 echo -n "${funcfiletrace[1]}: "
667 else
668 echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
669 fi
670 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 -0800671}
672
Matt Alexanderd9c56562020-05-21 10:49:17 +0000673function print_lunch_menu()
674{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700675 local uname=$(uname)
Roland Levillain23c46cf2020-03-31 16:11:05 +0100676 local choices
Colin Crossfa50d402021-04-22 13:05:41 -0700677 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 +0100678 local ret=$?
679
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700680 echo
681 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700682 echo
Roland Levillain23c46cf2020-03-31 16:11:05 +0100683
Matt Alexanderd9c56562020-05-21 10:49:17 +0000684 if [ $ret -ne 0 ]
685 then
Roland Levillain23c46cf2020-03-31 16:11:05 +0100686 echo "Warning: Cannot display lunch menu."
687 echo
688 echo "Note: You can invoke lunch with an explicit target:"
689 echo
690 echo " usage: lunch [target]" >&2
691 echo
692 return
693 fi
694
Will Burr40401202022-02-07 12:12:01 +0000695 echo "Lunch menu .. Here are the common combinations:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800696
697 local i=1
698 local choice
Dan Willemsen91763e92019-10-03 15:13:12 -0700699 for choice in $(echo $choices)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800700 do
701 echo " $i. $choice"
702 i=$(($i+1))
703 done
704
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700705 echo
706}
707
Matt Alexanderd9c56562020-05-21 10:49:17 +0000708function lunch()
709{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800710 local answer
711
Steven Moreland92793dc2020-02-25 18:30:18 -0800712 if [[ $# -gt 1 ]]; then
713 echo "usage: lunch [target]" >&2
714 return 1
715 fi
716
Will Burr40401202022-02-07 12:12:01 +0000717 local used_lunch_menu=0
718
Steven Moreland92793dc2020-02-25 18:30:18 -0800719 if [ "$1" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800720 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700721 else
722 print_lunch_menu
Will Burr40401202022-02-07 12:12:01 +0000723 echo "Which would you like? [aosp_arm-eng]"
724 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 -0800725 read answer
Will Burr40401202022-02-07 12:12:01 +0000726 used_lunch_menu=1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700727 fi
728
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800729 local selection=
730
Matt Alexanderd9c56562020-05-21 10:49:17 +0000731 if [ -z "$answer" ]
732 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700733 selection=aosp_arm-eng
Matt Alexanderd9c56562020-05-21 10:49:17 +0000734 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
735 then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800736 local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
Matt Alexanderd9c56562020-05-21 10:49:17 +0000737 if [ $answer -le ${#choices[@]} ]
738 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800739 # array in zsh starts from 1 instead of 0.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000740 if [ -n "$ZSH_VERSION" ]
741 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800742 selection=${choices[$(($answer))]}
743 else
744 selection=${choices[$(($answer-1))]}
745 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800746 fi
Colin Cross88737132017-03-21 17:41:03 -0700747 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800748 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700749 fi
750
Joe Onoratoda12daf2010-06-09 18:18:31 -0700751 export TARGET_BUILD_APPS=
752
Colin Cross88737132017-03-21 17:41:03 -0700753 local product variant_and_version variant version
Colin Cross88737132017-03-21 17:41:03 -0700754 product=${selection%%-*} # Trim everything after first dash
755 variant_and_version=${selection#*-} # Trim everything up to first dash
756 if [ "$variant_and_version" != "$selection" ]; then
757 variant=${variant_and_version%%-*}
758 if [ "$variant" != "$variant_and_version" ]; then
759 version=${variant_and_version#*-}
760 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700761 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800762
Matt Alexanderd9c56562020-05-21 10:49:17 +0000763 if [ -z "$product" ]
764 then
Ying Wang08800fd2016-03-03 20:57:21 -0800765 echo
Colin Cross88737132017-03-21 17:41:03 -0700766 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700767 return 1
768 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800769
Alexander Martinz5b3b55b2022-12-21 21:10:51 +0100770 check_product $product
Luca Stefani93102ff2017-08-17 21:21:23 +0200771
Colin Cross88737132017-03-21 17:41:03 -0700772 TARGET_PRODUCT=$product \
773 TARGET_BUILD_VARIANT=$variant \
774 TARGET_PLATFORM_VERSION=$version \
775 build_build_var_cache
Matt Alexanderd9c56562020-05-21 10:49:17 +0000776 if [ $? -ne 0 ]
777 then
Anton Hansson32fa7ee2021-06-14 17:09:58 +0100778 if [[ "$product" =~ .*_(eng|user|userdebug) ]]
779 then
780 echo "Did you mean -${product/*_/}? (dash instead of underscore)"
781 fi
Colin Cross88737132017-03-21 17:41:03 -0700782 return 1
783 fi
Colin Cross88737132017-03-21 17:41:03 -0700784 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
785 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700786 if [ -n "$version" ]; then
787 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
788 else
789 unset TARGET_PLATFORM_VERSION
790 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700791 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792
Will Burr40401202022-02-07 12:12:01 +0000793 if [ $used_lunch_menu -eq 1 ]; then
794 echo
795 echo "Hint: next time you can simply run 'lunch $selection'"
796 fi
797
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700798 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800799
Luca Stefani93102ff2017-08-17 21:21:23 +0200800 fixup_common_out_dir
801
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700802 set_stuff_for_environment
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700803 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800804 destroy_build_var_cache
Kousik Kumar41dacd12021-05-11 18:38:38 -0400805
806 if [[ -n "${CHECK_MU_CONFIG:-}" ]]; then
807 check_mu_config
808 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700809}
810
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700811unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700812# Tab completion for lunch.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000813function _lunch()
814{
Jeff Davidson513d7a42010-08-02 10:00:44 -0700815 local cur prev opts
816 COMPREPLY=()
817 cur="${COMP_WORDS[COMP_CWORD]}"
818 prev="${COMP_WORDS[COMP_CWORD-1]}"
819
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700820 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800821 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700822 fi
823
824 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700825 return 0
826}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700827
Joe Onoratoda12daf2010-06-09 18:18:31 -0700828# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700829# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Matt Alexanderd9c56562020-05-21 10:49:17 +0000830function tapas()
831{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700832 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Elliott Hughesf71c05a2020-03-06 16:46:59 -0800833 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700834 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700835 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 -0800836 local keys="$(echo $* | xargs -n 1 echo | \grep -E '^(devkeys)$' | xargs)"
837 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)"
838
Joe Onoratoda12daf2010-06-09 18:18:31 -0700839
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700840 if [ "$showHelp" != "" ]; then
841 $(gettop)/build/make/tapasHelp.sh
842 return
843 fi
844
Ying Wang67f02922012-08-22 10:25:20 -0700845 if [ $(echo $arch | wc -w) -gt 1 ]; then
846 echo "tapas: Error: Multiple build archs supplied: $arch"
847 return
848 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700849 if [ $(echo $variant | wc -w) -gt 1 ]; then
850 echo "tapas: Error: Multiple build variants supplied: $variant"
851 return
852 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700853 if [ $(echo $density | wc -w) -gt 1 ]; then
854 echo "tapas: Error: Multiple densities supplied: $density"
855 return
856 fi
Colin Cross7f49a672022-01-27 18:15:53 -0800857 if [ $(echo $keys | wc -w) -gt 1 ]; then
858 echo "tapas: Error: Multiple keys supplied: $keys"
859 return
860 fi
Ying Wang67f02922012-08-22 10:25:20 -0700861
Ying Wang0a76df52015-06-08 11:57:26 -0700862 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700863 case $arch in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000864 x86) product=aosp_x86;;
865 arm64) product=aosp_arm64;;
866 x86_64) product=aosp_x86_64;;
Ying Wang67f02922012-08-22 10:25:20 -0700867 esac
Colin Cross7f49a672022-01-27 18:15:53 -0800868 if [ -n "$keys" ]; then
869 product=${product/aosp_/aosp_${keys}_}
870 fi;
871
Joe Onoratoda12daf2010-06-09 18:18:31 -0700872 if [ -z "$variant" ]; then
873 variant=eng
874 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700875 if [ -z "$apps" ]; then
876 apps=all
877 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600878 if [ -z "$density" ]; then
879 density=alldpi
880 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700881
Ying Wang67f02922012-08-22 10:25:20 -0700882 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700883 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700884 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700885 export TARGET_BUILD_TYPE=release
886 export TARGET_BUILD_APPS=$apps
887
Ying Wang08800fd2016-03-03 20:57:21 -0800888 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700889 set_stuff_for_environment
890 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800891 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700892}
893
Martin Stjernholmf692c752021-04-12 00:01:10 +0100894# Configures the build to build unbundled Android modules (APEXes).
895# Run banchan with one or more module names (from apex{} modules).
896function banchan()
897{
898 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100899 local product="$(echo $* | xargs -n 1 echo | \grep -E '^(.*_)?(arm|x86|arm64|x86_64)$' | xargs)"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100900 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100901 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 +0100902
903 if [ "$showHelp" != "" ]; then
904 $(gettop)/build/make/banchanHelp.sh
905 return
906 fi
907
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100908 if [ -z "$product" ]; then
909 product=arm
910 elif [ $(echo $product | wc -w) -gt 1 ]; then
911 echo "banchan: Error: Multiple build archs or products supplied: $products"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100912 return
913 fi
914 if [ $(echo $variant | wc -w) -gt 1 ]; then
915 echo "banchan: Error: Multiple build variants supplied: $variant"
916 return
917 fi
918 if [ -z "$apps" ]; then
919 echo "banchan: Error: No modules supplied"
920 return
921 fi
922
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100923 case $product in
924 arm) product=module_arm;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100925 x86) product=module_x86;;
926 arm64) product=module_arm64;;
927 x86_64) product=module_x86_64;;
928 esac
929 if [ -z "$variant" ]; then
930 variant=eng
931 fi
932
933 export TARGET_PRODUCT=$product
934 export TARGET_BUILD_VARIANT=$variant
935 export TARGET_BUILD_DENSITY=alldpi
936 export TARGET_BUILD_TYPE=release
937
938 # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use
939 # case is different and it may diverge in the future.
940 export TARGET_BUILD_APPS=$apps
941
942 build_build_var_cache
943 set_stuff_for_environment
944 printconfig
945 destroy_build_var_cache
946}
947
Matt Alexanderd9c56562020-05-21 10:49:17 +0000948function gettop
949{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700950 local TOPFILE=build/make/core/envsetup.mk
Matt Alexanderd9c56562020-05-21 10:49:17 +0000951 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700952 # The following circumlocution ensures we remove symlinks from TOP.
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000953 (cd "$TOP"; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700954 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000955 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800956 # The following circumlocution (repeated below as well) ensures
957 # that we record the true directory name and not one that is
958 # faked up with symlink names.
959 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700960 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800961 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700962 local T=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000963 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800964 \cd ..
synergyb112a402013-07-05 19:47:47 -0700965 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966 done
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000967 \cd "$HERE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700968 if [ -f "$T/$TOPFILE" ]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000969 echo "$T"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700970 fi
971 fi
972 fi
973}
974
Matt Alexanderd9c56562020-05-21 10:49:17 +0000975function croot()
976{
Christopher Ferris55257d22017-03-23 11:08:58 -0700977 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700978 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700979 if [ "$1" ]; then
980 \cd $(gettop)/$1
981 else
982 \cd $(gettop)
983 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700984 else
985 echo "Couldn't locate the top of the tree. Try setting TOP."
986 fi
987}
988
Matt Alexanderd9c56562020-05-21 10:49:17 +0000989function _croot()
990{
Anton Hanssonece9c482019-02-04 18:15:39 +0000991 local T=$(gettop)
992 if [ "$T" ]; then
993 local cur="${COMP_WORDS[COMP_CWORD]}"
994 k=0
995 for c in $(compgen -d ${T}/${cur}); do
996 COMPREPLY[k++]=${c#${T}/}/
997 done
998 fi
999}
1000
Matt Alexanderd9c56562020-05-21 10:49:17 +00001001function cproj()
1002{
Colin Cross6cdc5d22017-10-20 11:37:33 -07001003 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001004 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -07001005 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001006 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1007 T=$PWD
1008 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001009 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001010 return
1011 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001012 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001013 done
Ying Wang9cd17642012-12-13 10:52:07 -08001014 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001015 echo "can't find Android.mk"
1016}
1017
Daniel Sandler47e0a882013-07-30 13:23:52 -04001018# simplified version of ps; output in the form
1019# <pid> <procname>
1020function qpid() {
1021 local prepend=''
1022 local append=''
Matt Alexanderd9c56562020-05-21 10:49:17 +00001023 if [ "$1" = "--exact" ]; then
Daniel Sandler47e0a882013-07-30 13:23:52 -04001024 prepend=' '
1025 append='$'
1026 shift
Matt Alexanderd9c56562020-05-21 10:49:17 +00001027 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001028 echo "usage: qpid [[--exact] <process name|pid>"
1029 return 255
1030 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001031
1032 local EXE="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001033 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001034 qpid | \grep "$prepend$EXE$append"
1035 else
1036 adb shell ps \
1037 | tr -d '\r' \
1038 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1039 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001040}
1041
Steven Moreland74114f12020-09-10 01:23:32 +00001042# syswrite - disable verity, reboot if needed, and remount image
1043#
1044# Easy way to make system.img/etc writable
1045function syswrite() {
1046 adb wait-for-device && adb root || return 1
1047 if [[ $(adb disable-verity | grep "reboot") ]]; then
1048 echo "rebooting"
1049 adb reboot && adb wait-for-device && adb root || return 1
1050 fi
1051 adb wait-for-device && adb remount || return 1
1052}
1053
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001054# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001055# that has the core-file-size limit set correctly
1056#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001057# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001058# if its core-file-size limit is not set already.
1059# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1060
Matt Alexanderd9c56562020-05-21 10:49:17 +00001061function coredump_setup()
1062{
1063 echo "Getting root...";
1064 adb root;
1065 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001066
Matt Alexanderd9c56562020-05-21 10:49:17 +00001067 echo "Remounting root partition read-write...";
1068 adb shell mount -w -o remount -t rootfs rootfs;
1069 sleep 1;
1070 adb wait-for-device;
1071 adb shell mkdir -p /cores;
1072 adb shell mount -t tmpfs tmpfs /cores;
1073 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001074
Matt Alexanderd9c56562020-05-21 10:49:17 +00001075 echo "Granting SELinux permission to dump in /cores...";
1076 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001077
Matt Alexanderd9c56562020-05-21 10:49:17 +00001078 echo "Set core pattern.";
1079 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001080
Ying Wang08800fd2016-03-03 20:57:21 -08001081 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001082}
1083
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001084# coredump_enable - enable core dumps for the specified 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 have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001088# dump to actually be generated.
1089
Matt Alexanderd9c56562020-05-21 10:49:17 +00001090function coredump_enable()
1091{
1092 local PID=$1;
Ying Wang08800fd2016-03-03 20:57:21 -08001093 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001094 printf "Expecting a PID!\n";
1095 return;
1096 fi;
1097 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001098 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001099}
1100
1101# core - send SIGV and pull the core for process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001102# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001103#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001104# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001105# enabled globally.
1106
Matt Alexanderd9c56562020-05-21 10:49:17 +00001107function core()
1108{
1109 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001110
Ying Wang08800fd2016-03-03 20:57:21 -08001111 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001112 printf "Expecting a PID!\n";
1113 return;
1114 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001115
Matt Alexanderd9c56562020-05-21 10:49:17 +00001116 local CORENAME=core.$PID;
1117 local COREPATH=/cores/$CORENAME;
1118 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001119
Matt Alexanderd9c56562020-05-21 10:49:17 +00001120 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001121
Matt Alexanderd9c56562020-05-21 10:49:17 +00001122 local done=0;
Ying Wang08800fd2016-03-03 20:57:21 -08001123 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
Matt Alexanderd9c56562020-05-21 10:49:17 +00001124 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1125 adb shell kill -$SIG $PID;
1126 sleep 1;
1127 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001128
Matt Alexanderd9c56562020-05-21 10:49:17 +00001129 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1130 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001131}
1132
Christopher Tate744ee802009-11-12 15:33:08 -08001133# systemstack - dump the current stack trace of all threads in the system process
1134# to the usual ANR traces file
Matt Alexanderd9c56562020-05-21 10:49:17 +00001135function systemstack()
1136{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001137 stacks system_server
1138}
1139
Michael Wrightaeed7212014-06-19 19:58:12 -07001140# Read the ELF header from /proc/$PID/exe to determine if the process is
1141# 64-bit.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001142function is64bit()
1143{
Ben Chengfba67bf2014-02-25 10:27:07 -08001144 local PID="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001145 if [ "$PID" ] ; then
1146 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001147 echo "64"
1148 else
1149 echo ""
1150 fi
1151 else
1152 echo ""
1153 fi
1154}
1155
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001156case `uname -s` in
1157 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001158 function sgrep()
1159 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001160 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 -04001161 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001162 }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001163
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001164 ;;
1165 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001166 function sgrep()
1167 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001168 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 -04001169 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001170 }
1171 ;;
1172esac
1173
Matt Alexanderd9c56562020-05-21 10:49:17 +00001174function gettargetarch
1175{
Raghu Gandham8da43102012-07-25 19:57:22 -07001176 get_build_var TARGET_ARCH
1177}
1178
Matt Alexanderd9c56562020-05-21 10:49:17 +00001179function ggrep()
1180{
Mike Frysinger5e479732015-09-22 18:13:48 -04001181 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1182 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001183}
1184
Matt Alexanderd9c56562020-05-21 10:49:17 +00001185function gogrep()
1186{
Orion Hodson831472d2019-10-25 11:35:15 +01001187 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
1188 -exec grep --color -n "$@" {} +
1189}
1190
Matt Alexanderd9c56562020-05-21 10:49:17 +00001191function jgrep()
1192{
Mike Frysinger5e479732015-09-22 18:13:48 -04001193 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1194 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001195}
1196
Alistair Delva176e5342021-02-22 13:31:26 -08001197function rsgrep()
Jeff Vander Stoep1431ab82021-02-02 19:18:26 +01001198{
1199 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rs" \
1200 -exec grep --color -n "$@" {} +
1201}
1202
Taesu Leeea0cecd2020-10-28 11:05:18 +09001203function ktgrep()
1204{
1205 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.kt" \
1206 -exec grep --color -n "$@" {} +
1207}
1208
Matt Alexanderd9c56562020-05-21 10:49:17 +00001209function cgrep()
1210{
Mike Frysinger5e479732015-09-22 18:13:48 -04001211 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' \) \
1212 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001213}
1214
Matt Alexanderd9c56562020-05-21 10:49:17 +00001215function resgrep()
1216{
Christopher Ferris55257d22017-03-23 11:08:58 -07001217 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001218 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1219 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1220 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001221}
1222
Matt Alexanderd9c56562020-05-21 10:49:17 +00001223function mangrep()
1224{
Mike Frysinger5e479732015-09-22 18:13:48 -04001225 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1226 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001227}
1228
Matt Alexanderd9c56562020-05-21 10:49:17 +00001229function owngrep()
1230{
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -06001231 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
1232 -exec grep --color -n "$@" {} +
1233}
1234
Matt Alexanderd9c56562020-05-21 10:49:17 +00001235function sepgrep()
1236{
Mike Frysinger5e479732015-09-22 18:13:48 -04001237 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1238 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001239}
1240
Matt Alexanderd9c56562020-05-21 10:49:17 +00001241function rcgrep()
1242{
Mike Frysinger5e479732015-09-22 18:13:48 -04001243 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1244 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001245}
1246
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001247case `uname -s` in
1248 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001249 function mgrep()
1250 {
Orion Hodson831472d2019-10-25 11:35:15 +01001251 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 -04001252 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001253 }
1254
Matt Alexanderd9c56562020-05-21 10:49:17 +00001255 function treegrep()
1256 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001257 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 -04001258 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001259 }
1260
1261 ;;
1262 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001263 function mgrep()
1264 {
Orion Hodson831472d2019-10-25 11:35:15 +01001265 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 -04001266 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001267 }
1268
Matt Alexanderd9c56562020-05-21 10:49:17 +00001269 function treegrep()
1270 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001271 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 -04001272 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001273 }
1274
1275 ;;
1276esac
1277
Matt Alexanderd9c56562020-05-21 10:49:17 +00001278function getprebuilt
1279{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001280 get_abs_build_var ANDROID_PREBUILTS
1281}
1282
Matt Alexanderd9c56562020-05-21 10:49:17 +00001283function tracedmdump()
1284{
Christopher Ferris55257d22017-03-23 11:08:58 -07001285 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001286 if [ ! "$T" ]; then
1287 echo "Couldn't locate the top of the tree. Try setting TOP."
1288 return
1289 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001290 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001291 local arch=$(gettargetarch)
1292 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001293
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001294 local TRACE=$1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001295 if [ ! "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001296 echo "usage: tracedmdump tracename"
1297 return
1298 fi
1299
Matt Alexanderd9c56562020-05-21 10:49:17 +00001300 if [ ! -r "$KERNEL" ] ; then
Jack Veenstra60116fc2009-04-09 18:12:34 -07001301 echo "Error: cannot find kernel: '$KERNEL'"
1302 return
1303 fi
1304
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001305 local BASETRACE=$(basename $TRACE)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001306 if [ "$BASETRACE" = "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001307 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1308 fi
1309
1310 echo "post-processing traces..."
1311 rm -f $TRACE/qtrace.dexlist
1312 post_trace $TRACE
1313 if [ $? -ne 0 ]; then
1314 echo "***"
1315 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1316 echo "***"
1317 return
1318 fi
1319 echo "generating dexlist output..."
1320 /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
1321 echo "generating dmtrace data..."
1322 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1323 echo "generating html file..."
1324 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1325 echo "done, see $TRACE/dmtrace.html for details"
1326 echo "or run:"
1327 echo " traceview $TRACE/dmtrace"
1328}
1329
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001330# communicate with a running device or emulator, set up necessary state,
1331# and run the hat command.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001332function runhat()
1333{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001334 # process standard adb options
1335 local adbTarget=""
Matt Alexanderd9c56562020-05-21 10:49:17 +00001336 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001337 adbTarget=$1
1338 shift 1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001339 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001340 adbTarget="$1 $2"
1341 shift 2
1342 fi
1343 local adbOptions=${adbTarget}
Matt Alexanderd9c56562020-05-21 10:49:17 +00001344 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001345
1346 # runhat options
1347 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001348
Matt Alexanderd9c56562020-05-21 10:49:17 +00001349 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001350 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001351 return
1352 fi
1353
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001354 # confirm hat is available
1355 if [ -z $(which hat) ]; then
1356 echo "hat is not available in this configuration."
1357 return
1358 fi
1359
Andy McFaddenb6289852010-07-12 08:00:19 -07001360 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001361 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001362 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001363 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001364 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001365 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001366 echo -n "> "
1367 read
1368
The Android Open Source Project88b60792009-03-03 19:28:42 -08001369 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001370
The Android Open Source Project88b60792009-03-03 19:28:42 -08001371 echo "Retrieving file $devFile..."
1372 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001373
The Android Open Source Project88b60792009-03-03 19:28:42 -08001374 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001375
The Android Open Source Project88b60792009-03-03 19:28:42 -08001376 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001377 echo "View the output by pointing your browser at http://localhost:7000/"
1378 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001379 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001380}
1381
Matt Alexanderd9c56562020-05-21 10:49:17 +00001382function getbugreports()
1383{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001384 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001385
1386 if [ ! "$reports" ]; then
1387 echo "Could not locate any bugreports."
1388 return
1389 fi
1390
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001391 local report
1392 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001393 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001394 echo "/sdcard/bugreports/${report}"
1395 adb pull /sdcard/bugreports/${report} ${report}
1396 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001397 done
1398}
1399
Matt Alexanderd9c56562020-05-21 10:49:17 +00001400function getsdcardpath()
1401{
Victoria Lease1b296b42012-08-21 15:44:06 -07001402 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1403}
1404
Matt Alexanderd9c56562020-05-21 10:49:17 +00001405function getscreenshotpath()
1406{
Victoria Lease1b296b42012-08-21 15:44:06 -07001407 echo "$(getsdcardpath)/Pictures/Screenshots"
1408}
1409
Matt Alexanderd9c56562020-05-21 10:49:17 +00001410function getlastscreenshot()
1411{
Victoria Lease1b296b42012-08-21 15:44:06 -07001412 local screenshot_path=$(getscreenshotpath)
1413 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 +00001414 if [ "$screenshot" = "" ]; then
Victoria Lease1b296b42012-08-21 15:44:06 -07001415 echo "No screenshots found."
1416 return
1417 fi
1418 echo "${screenshot}"
1419 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1420}
1421
Matt Alexanderd9c56562020-05-21 10:49:17 +00001422function startviewserver()
1423{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001424 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001425 if [ $# -gt 0 ]; then
1426 port=$1
1427 fi
1428 adb shell service call window 1 i32 $port
1429}
1430
Matt Alexanderd9c56562020-05-21 10:49:17 +00001431function stopviewserver()
1432{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001433 adb shell service call window 2
1434}
1435
Matt Alexanderd9c56562020-05-21 10:49:17 +00001436function isviewserverstarted()
1437{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001438 adb shell service call window 3
1439}
1440
Matt Alexanderd9c56562020-05-21 10:49:17 +00001441function key_home()
1442{
Romain Guyb84049a2010-10-04 16:56:11 -07001443 adb shell input keyevent 3
1444}
1445
Matt Alexanderd9c56562020-05-21 10:49:17 +00001446function key_back()
1447{
Romain Guyb84049a2010-10-04 16:56:11 -07001448 adb shell input keyevent 4
1449}
1450
Matt Alexanderd9c56562020-05-21 10:49:17 +00001451function key_menu()
1452{
Romain Guyb84049a2010-10-04 16:56:11 -07001453 adb shell input keyevent 82
1454}
1455
Matt Alexanderd9c56562020-05-21 10:49:17 +00001456function smoketest()
1457{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001458 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1459 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1460 return
1461 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001462 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001463 if [ ! "$T" ]; then
1464 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1465 return
1466 fi
1467
Ying Wang9cd17642012-12-13 10:52:07 -08001468 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001469 adb uninstall com.android.smoketest > /dev/null &&
1470 adb uninstall com.android.smoketest.tests > /dev/null &&
1471 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1472 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1473 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1474}
1475
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001476# simple shortcut to the runtest command
Matt Alexanderd9c56562020-05-21 10:49:17 +00001477function runtest()
1478{
Christopher Ferris55257d22017-03-23 11:08:58 -07001479 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001480 if [ ! "$T" ]; then
1481 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1482 return
1483 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001484 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001485}
1486
The Android Open Source Project88b60792009-03-03 19:28:42 -08001487function godir () {
1488 if [[ -z "$1" ]]; then
1489 echo "Usage: godir <regex>"
1490 return
1491 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001492 local T=$(gettop)
1493 local FILELIST
Matt Alexanderd9c56562020-05-21 10:49:17 +00001494 if [ ! "$OUT_DIR" = "" ]; then
Brian Carlstromf2257422015-09-30 20:28:54 -07001495 mkdir -p $OUT_DIR
1496 FILELIST=$OUT_DIR/filelist
1497 else
1498 FILELIST=$T/filelist
1499 fi
1500 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001501 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001502 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001503 echo " Done"
1504 echo ""
1505 fi
1506 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001507 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
Matt Alexanderd9c56562020-05-21 10:49:17 +00001508 if [[ ${#lines[@]} = 0 ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001509 echo "Not found"
1510 return
1511 fi
1512 local pathname
1513 local choice
1514 if [[ ${#lines[@]} > 1 ]]; then
1515 while [[ -z "$pathname" ]]; do
1516 local index=1
1517 local line
1518 for line in ${lines[@]}; do
1519 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001520 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001521 done
1522 echo
1523 echo -n "Select one: "
1524 unset choice
1525 read choice
1526 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1527 echo "Invalid choice"
1528 continue
1529 fi
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001530 pathname=${lines[@]:$(($choice-1)):1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001531 done
1532 else
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001533 pathname=${lines[@]:0:1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001534 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001535 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001536}
1537
Steven Moreland62054a42018-12-06 10:11:40 -08001538# Update module-info.json in out.
1539function refreshmod() {
1540 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1541 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1542 return 1
1543 fi
1544
1545 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1546
1547 # for the output of the next command
1548 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1549
1550 # Note, can't use absolute path because of the way make works.
Alessandro Astonec8771be2020-05-10 11:27:57 +02001551 m $(get_build_var PRODUCT_OUT)/module-info.json \
Steven Moreland62054a42018-12-06 10:11:40 -08001552 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1553}
1554
Cole Faust3e192382021-10-25 13:29:15 -07001555# Verifies that module-info.txt exists, returning nonzero if it doesn't.
Cole Faust24c36db2021-01-23 02:39:37 +00001556function verifymodinfo() {
Steven Moreland62054a42018-12-06 10:11:40 -08001557 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001558 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
1559 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1560 fi
Steven Moreland62054a42018-12-06 10:11:40 -08001561 return 1
1562 fi
1563
1564 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001565 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
Cole Faust3e192382021-10-25 13:29:15 -07001566 echo "Could not find module-info.json. Please run 'refreshmod' first." >&2
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001567 fi
1568 return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001569 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001570}
1571
1572# List all modules for the current device, as cached in module-info.json. If any build change is
1573# made and it should be reflected in the output, you should run 'refreshmod' first.
1574function allmod() {
1575 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001576
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001577 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 -08001578}
1579
Joe Onorato2c1aa472021-02-25 16:42:39 -08001580# Get the path of a specific module in the android tree, as cached in module-info.json.
1581# If any build change is made, and it should be reflected in the output, you should run
1582# 'refreshmod' first. Note: This is the inverse of dirmods.
Rett Berg78d1c932019-01-24 14:34:23 -08001583function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001584 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001585 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001586 return 1
1587 fi
1588
Cole Faust24c36db2021-01-23 02:39:37 +00001589 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001590
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001591 local relpath=$(python3 -c "import json, os
Steven Moreland62054a42018-12-06 10:11:40 -08001592module = '$1'
1593module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1594if module not in module_info:
1595 exit(1)
LuK1337b6a78192020-01-12 03:12:17 +01001596print(module_info[module]['path'][0])" 2>/dev/null)
Steven Moreland62054a42018-12-06 10:11:40 -08001597
1598 if [ -z "$relpath" ]; then
1599 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1600 return 1
1601 else
Rett Berg78d1c932019-01-24 14:34:23 -08001602 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001603 fi
1604}
1605
Joe Onorato2c1aa472021-02-25 16:42:39 -08001606# Get the path of a specific module in the android tree, as cached in module-info.json.
1607# If any build change is made, and it should be reflected in the output, you should run
1608# 'refreshmod' first. Note: This is the inverse of pathmod.
1609function dirmods() {
1610 if [[ $# -ne 1 ]]; then
1611 echo "usage: dirmods <path>" >&2
1612 return 1
1613 fi
1614
1615 verifymodinfo || return 1
1616
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001617 python3 -c "import json, os
Joe Onorato2c1aa472021-02-25 16:42:39 -08001618dir = '$1'
1619while dir.endswith('/'):
1620 dir = dir[:-1]
1621prefix = dir + '/'
1622module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1623results = set()
1624for m in module_info.values():
1625 for path in m.get(u'path', []):
1626 if path == dir or path.startswith(prefix):
1627 name = m.get(u'module_name')
1628 if name:
1629 results.add(name)
1630for name in sorted(results):
1631 print(name)
1632"
1633}
1634
1635
Rett Berg78d1c932019-01-24 14:34:23 -08001636# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1637# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1638function gomod() {
1639 if [[ $# -ne 1 ]]; then
1640 echo "usage: gomod <module>" >&2
1641 return 1
1642 fi
1643
1644 local path="$(pathmod $@)"
1645 if [ -z "$path" ]; then
1646 return 1
1647 fi
1648 cd $path
1649}
1650
Cole Faust24c36db2021-01-23 02:39:37 +00001651# Gets the list of a module's installed outputs, as cached in module-info.json.
1652# If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first.
1653function outmod() {
1654 if [[ $# -ne 1 ]]; then
1655 echo "usage: outmod <module>" >&2
1656 return 1
1657 fi
1658
1659 verifymodinfo || return 1
1660
1661 local relpath
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001662 relpath=$(python3 -c "import json, os
Cole Faust24c36db2021-01-23 02:39:37 +00001663module = '$1'
1664module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1665if module not in module_info:
1666 exit(1)
1667for output in module_info[module]['installed']:
1668 print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null)
1669
1670 if [ $? -ne 0 ]; then
1671 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2
1672 return 1
1673 elif [ ! -z "$relpath" ]; then
1674 echo "$relpath"
1675 fi
1676}
1677
1678# adb install a module's apk, as cached in module-info.json. If any build change
1679# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1680# Usage: installmod [adb install arguments] <module>
1681# For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk
1682function installmod() {
1683 if [[ $# -eq 0 ]]; then
1684 echo "usage: installmod [adb install arguments] <module>" >&2
Cole Faust3e192382021-10-25 13:29:15 -07001685 echo "" >&2
1686 echo "Only flags to be passed after the \"install\" in adb install are supported," >&2
1687 echo "with the exception of -s. If -s is passed it will be placed before the \"install\"." >&2
1688 echo "-s must be the first flag passed if it exists." >&2
Cole Faust24c36db2021-01-23 02:39:37 +00001689 return 1
1690 fi
1691
1692 local _path
1693 _path=$(outmod ${@:$#:1})
1694 if [ $? -ne 0 ]; then
1695 return 1
1696 fi
1697
1698 _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1)
1699 if [ -z "$_path" ]; then
1700 echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2
1701 return 1
1702 fi
Cole Faust3e192382021-10-25 13:29:15 -07001703 local serial_device=""
1704 if [[ "$1" == "-s" ]]; then
1705 if [[ $# -le 2 ]]; then
1706 echo "-s requires an argument" >&2
1707 return 1
1708 fi
1709 serial_device="-s $2"
1710 shift 2
1711 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001712 local length=$(( $# - 1 ))
Cole Faust3e192382021-10-25 13:29:15 -07001713 echo adb $serial_device install ${@:1:$length} $_path
1714 adb $serial_device install ${@:1:$length} $_path
Cole Faust24c36db2021-01-23 02:39:37 +00001715}
1716
dimitry73b84812018-12-11 18:06:00 +01001717function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001718 local word=${COMP_WORDS[COMP_CWORD]}
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001719 COMPREPLY=( $(QUIET_VERIFYMODINFO=true allmod | grep -E "^$word") )
Steven Moreland62054a42018-12-06 10:11:40 -08001720}
1721
Alex Rayf0d08eb2013-03-08 15:15:06 -08001722# Print colored exit condition
1723function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001724 "$@"
1725 local retval=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +00001726 if [ $retval -ne 0 ]
1727 then
Jacky Cao89483b82015-05-15 22:12:53 +08001728 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001729 else
Jacky Cao89483b82015-05-15 22:12:53 +08001730 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001731 fi
1732 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001733}
1734
Matt Alexanderd9c56562020-05-21 10:49:17 +00001735function get_make_command()
1736{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001737 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1738 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001739 # Always use the real make if -C is passed in
1740 for arg in "$@"; do
1741 if [[ $arg == -C* ]]; then
1742 echo command make
1743 return
1744 fi
1745 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001746 echo build/soong/soong_ui.bash --make-mode
1747 else
1748 echo command make
1749 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001750}
1751
Matt Alexanderd9c56562020-05-21 10:49:17 +00001752function _wrap_build()
1753{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001754 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1755 "$@"
1756 return $?
1757 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001758 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001759 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001760 local ret=$?
1761 local end_time=$(date +"%s")
1762 local tdiff=$(($end_time-$start_time))
1763 local hours=$(($tdiff / 3600 ))
1764 local mins=$((($tdiff % 3600) / 60))
1765 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001766 local ncolors=$(tput colors 2>/dev/null)
1767 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001768 color_failed=$'\E'"[0;31m"
1769 color_success=$'\E'"[0;32m"
Kousik Kumar09af2542021-08-19 16:13:32 -04001770 color_warning=$'\E'"[0;33m"
Jacky Cao89483b82015-05-15 22:12:53 +08001771 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001772 else
1773 color_failed=""
1774 color_success=""
1775 color_reset=""
1776 fi
Kousik Kumar09af2542021-08-19 16:13:32 -04001777
1778 if [[ "x${USE_RBE}" == "x" && $mins -gt 15 && "${ANDROID_BUILD_ENVIRONMENT_CONFIG}" == "googler" ]]; then
1779 echo
1780 echo "${color_warning}Start using RBE (http://go/build-fast) to get faster builds!${color_reset}"
1781 fi
1782
Ed Heylcc6be0a2014-06-18 14:55:58 -07001783 echo
Matt Alexanderd9c56562020-05-21 10:49:17 +00001784 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001785 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001786 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001787 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001788 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +00001789 if [ $hours -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001790 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001791 elif [ $mins -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001792 printf "(%02g:%02g (mm:ss))" $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001793 elif [ $secs -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001794 printf "(%s seconds)" $secs
1795 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001796 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001797 echo
1798 return $ret
1799}
1800
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001801function _trigger_build()
1802(
1803 local -r bc="$1"; shift
1804 if T="$(gettop)"; then
1805 _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
1806 else
Jingwen Chend728ee12021-05-18 06:02:53 +00001807 >&2 echo "Couldn't locate the top of the tree. Try setting TOP."
1808 return 1
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001809 fi
1810)
1811
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001812# Convenience entry point (like m) to use Bazel in AOSP.
Jingwen Chend728ee12021-05-18 06:02:53 +00001813function b()
1814(
1815 # Generate BUILD, bzl files into the synthetic Bazel workspace (out/soong/workspace).
Sam Delmerico9d67a902022-04-11 12:25:18 +00001816 _trigger_build "all-modules" bp2build USE_BAZEL_ANALYSIS= || return 1
Jingwen Chend728ee12021-05-18 06:02:53 +00001817 # Then, run Bazel using the synthetic workspace as the --package_path.
Sam Delmerico9d67a902022-04-11 12:25:18 +00001818 if [[ -z "$@" ]]; then
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001819 # If there are no args, show help.
Jingwen Chenbfa114d2021-06-17 05:42:43 +00001820 bazel help
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001821 else
1822 # Else, always run with the bp2build configuration, which sets Bazel's package path to the synthetic workspace.
Sam Delmerico9d67a902022-04-11 12:25:18 +00001823 bazel "$@" --config=bp2build
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001824 fi
Jingwen Chend728ee12021-05-18 06:02:53 +00001825)
1826
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001827function m()
1828(
1829 _trigger_build "all-modules" "$@"
1830)
1831
1832function mm()
1833(
1834 _trigger_build "modules-in-a-dir-no-deps" "$@"
1835)
1836
1837function mmm()
1838(
1839 _trigger_build "modules-in-dirs-no-deps" "$@"
1840)
1841
1842function mma()
1843(
1844 _trigger_build "modules-in-a-dir" "$@"
1845)
1846
1847function mmma()
1848(
1849 _trigger_build "modules-in-dirs" "$@"
1850)
1851
Matt Alexanderd9c56562020-05-21 10:49:17 +00001852function make()
1853{
Dan Willemsene9842242017-07-28 13:00:13 -07001854 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001855}
1856
Matt Alexanderd9c56562020-05-21 10:49:17 +00001857function provision()
1858{
David Zeuthen1b126ff2015-09-30 17:10:48 -04001859 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1860 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1861 return 1
1862 fi
1863 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1864 echo "There is no provisioning script for the device." >&2
1865 return 1
1866 fi
1867
1868 # Check if user really wants to do this.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001869 if [ "$1" = "--no-confirmation" ]; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001870 shift 1
1871 else
1872 echo "This action will reflash your device."
1873 echo ""
1874 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1875 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001876 echo -n "Are you sure you want to do this (yes/no)? "
1877 read
Matt Alexanderd9c56562020-05-21 10:49:17 +00001878 if [[ "${REPLY}" != "yes" ]] ; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001879 echo "Not taking any action. Exiting." >&2
1880 return 1
1881 fi
1882 fi
1883 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1884}
1885
Jim Tanga881a252018-06-19 16:34:41 +08001886# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001887function enable_zsh_completion() {
1888 # Don't override user's options if bash-style completion is already enabled.
1889 if ! declare -f complete >/dev/null; then
1890 autoload -U compinit && compinit
1891 autoload -U bashcompinit && bashcompinit
1892 fi
Jim Tanga881a252018-06-19 16:34:41 +08001893}
1894
1895function validate_current_shell() {
1896 local current_sh="$(ps -o command -p $$)"
1897 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001898 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001899 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001900 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001901 *zsh*)
1902 function check_type() { type "$1"; }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001903 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001904 *)
Jim Tanga881a252018-06-19 16:34:41 +08001905 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 -07001906 ;;
1907 esac
Jim Tanga881a252018-06-19 16:34:41 +08001908}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001909
1910# Execute the contents of any vendorsetup.sh files we can find.
Dan Willemsend855a722019-02-12 15:52:36 -08001911# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
1912# load those.
1913#
1914# This allows loading only approved vendorsetup.sh files
Jim Tanga881a252018-06-19 16:34:41 +08001915function source_vendorsetup() {
Jim Tangc4dba1d2019-07-25 16:54:27 +08001916 unset VENDOR_PYTHONPATH
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001917 local T="$(gettop)"
Dan Willemsend855a722019-02-12 15:52:36 -08001918 allowed=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001919 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 -08001920 if [ -n "$allowed" ]; then
1921 echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
1922 echo " $allowed"
1923 echo " $f"
1924 return
1925 fi
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001926 allowed="$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001927 done
1928
1929 allowed_files=
1930 [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
Jim Tanga881a252018-06-19 16:34:41 +08001931 for dir in device vendor product; do
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001932 for f in $(cd "$T" && test -d $dir && \
Jim Tanga881a252018-06-19 16:34:41 +08001933 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001934
1935 if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001936 echo "including $f"; . "$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001937 else
1938 echo "ignoring $f, not in $allowed"
1939 fi
Jim Tanga881a252018-06-19 16:34:41 +08001940 done
1941 done
1942}
Kenny Root52aa81c2011-07-15 11:07:06 -07001943
Dan Albertbab814f2020-08-26 15:34:53 -07001944function showcommands() {
1945 local T=$(gettop)
1946 if [[ -z "$TARGET_PRODUCT" ]]; then
1947 >&2 echo "TARGET_PRODUCT not set. Run lunch."
1948 return
1949 fi
1950 case $(uname -s) in
1951 Darwin)
1952 PREBUILT_NAME=darwin-x86
1953 ;;
1954 Linux)
1955 PREBUILT_NAME=linux-x86
1956 ;;
1957 *)
1958 >&2 echo Unknown host $(uname -s)
1959 return
1960 ;;
1961 esac
1962 if [[ -z "$OUT_DIR" ]]; then
1963 if [[ -z "$OUT_DIR_COMMON_BASE" ]]; then
1964 OUT_DIR=out
1965 else
1966 OUT_DIR=${OUT_DIR_COMMON_BASE}/${PWD##*/}
1967 fi
1968 fi
1969 if [[ "$1" == "--regenerate" ]]; then
1970 shift 1
1971 NINJA_ARGS="-t commands $@" m
1972 else
1973 (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \
1974 -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \
1975 -t commands "$@")
1976 fi
1977}
1978
Jim Tanga881a252018-06-19 16:34:41 +08001979validate_current_shell
1980source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001981addcompletions
Chirayu Desai798bc5e2013-03-19 17:50:37 +05301982
1983export ANDROID_BUILD_TOP=$(gettop)
Michael Bestasb744e742016-08-26 00:37:02 +03001984
1985. $ANDROID_BUILD_TOP/vendor/lineage/build/envsetup.sh