blob: 042a058a6e470120c2ff1bf4f6f13951c22df1ba [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
Jeff Browne33ba4c2011-07-11 22:11:46 -0700156 TARGET_PRODUCT=$1 \
157 TARGET_BUILD_VARIANT= \
158 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700159 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800160 get_build_var TARGET_DEVICE > /dev/null
161 # hide successful answers, but allow the errors to show
162}
163
164VARIANT_CHOICES=(user userdebug eng)
165
166# check to see if the supplied variant is valid
Matt Alexanderd9c56562020-05-21 10:49:17 +0000167function check_variant()
168{
Christopher Ferris55257d22017-03-23 11:08:58 -0700169 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800170 for v in ${VARIANT_CHOICES[@]}
171 do
Matt Alexanderd9c56562020-05-21 10:49:17 +0000172 if [ "$v" = "$1" ]
173 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800174 return 0
175 fi
176 done
177 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700178}
179
Matt Alexanderd9c56562020-05-21 10:49:17 +0000180function setpaths()
181{
Christopher Ferris55257d22017-03-23 11:08:58 -0700182 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700183 if [ ! "$T" ]; then
184 echo "Couldn't locate the top of the tree. Try setting TOP."
185 return
186 fi
187
188 ##################################################################
189 # #
190 # Read me before you modify this code #
191 # #
192 # This function sets ANDROID_BUILD_PATHS to what it is adding #
193 # to PATH, and the next time it is run, it removes that from #
194 # PATH. This is required so lunch can be run more than once #
195 # and still have working paths. #
196 # #
197 ##################################################################
198
Raphael Mollc639c782011-06-20 17:25:01 -0700199 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
200 # due to "C:\Program Files" being in the path.
201
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700202 # out with the old
Matt Alexanderd9c56562020-05-21 10:49:17 +0000203 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700204 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
205 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000206 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700207 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800208 # strip leading ':', if any
209 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500210 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700211
212 # and in with the new
Christopher Ferris55257d22017-03-23 11:08:58 -0700213 local prebuiltdir=$(getprebuilt)
214 local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700215
Ben Cheng8bc4c432012-11-16 13:29:13 -0800216 # defined in core/config.mk
Christopher Ferris55257d22017-03-23 11:08:58 -0700217 local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
218 local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800219 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800220
Raphael Mollc639c782011-06-20 17:25:01 -0700221 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800222 export ANDROID_TOOLCHAIN=
223 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200224 local ARCH=$(get_build_var TARGET_ARCH)
Christopher Ferris55257d22017-03-23 11:08:58 -0700225 local toolchaindir toolchaindir2=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200226 case $ARCH in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000227 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700228 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000229 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Pavel Chupinfd82a492012-11-26 09:50:07 +0400230 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000231 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200232 ;;
Matt Alexanderd9c56562020-05-21 10:49:17 +0000233 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
234 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700235 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200236 *)
237 echo "Can't find toolchain for unknown architecture: $ARCH"
238 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700239 ;;
240 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700241 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800242 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700243 fi
Raphael732936d2011-06-22 14:35:32 -0700244
Christopher Ferris55257d22017-03-23 11:08:58 -0700245 if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800246 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
247 fi
248
Dan Willemsen838dcec2021-09-30 22:40:34 +0000249 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Yueyao Zhuefc786a2017-04-07 14:11:54 -0700250
251 # add kernel specific binaries
252 case $(uname -s) in
253 Linux)
254 export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
255 ;;
256 *)
257 ;;
258 esac
259
Torne (Richard Coles)0091bae2017-10-03 16:31:18 -0400260 ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN
Martin Stjernholm6a012262021-11-24 14:56:15 +0000261 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH
Yi Kongdfd00b12019-05-21 16:00:04 -0700262 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS
263
264 # Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS.
265 local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
266 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200267
Stephen Hinesaa8d72c2020-02-04 09:15:18 -0800268 # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds.
269 export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer
270
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200271 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
272 # to ensure that the corresponding 'emulator' binaries are used.
273 case $(uname -s) in
274 Darwin)
275 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
276 ;;
277 Linux)
278 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
279 ;;
280 *)
281 ANDROID_EMULATOR_PREBUILTS=
282 ;;
283 esac
284 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Yi Kongdfd00b12019-05-21 16:00:04 -0700285 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200286 export ANDROID_EMULATOR_PREBUILTS
287 fi
288
Jim Tangb3fda302018-12-22 10:24:55 +0800289 # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
290 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
Ryan Prichard8426a192019-07-15 18:05:29 -0700291 local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch"
292 local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch"
293 local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch"
Martin Stjernholm6a012262021-11-24 14:56:15 +0000294 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH
Jim Tangb3fda302018-12-22 10:24:55 +0800295
Martin Stjernholm6a012262021-11-24 14:56:15 +0000296 export ANDROID_BUILD_PATHS=$(tr -s : <<<"${ANDROID_BUILD_PATHS}:")
Ryan Prichard8426a192019-07-15 18:05:29 -0700297 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800298
299 # out with the duplicate old
300 if [ -n $ANDROID_PYTHONPATH ]; then
301 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
302 fi
303 # and in with the new
304 export ANDROID_PYTHONPATH=$T/development/python-packages:
Jim Tangc4dba1d2019-07-25 16:54:27 +0800305 if [ -n $VENDOR_PYTHONPATH ]; then
306 ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
307 fi
Jim Tang22f4c322018-12-17 15:21:53 +0800308 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800309
Colin Crosse97e6932017-06-30 16:01:45 -0700310 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
311 export JAVA_HOME=$ANDROID_JAVA_HOME
312 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
313 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
314 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500315
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
318 export OUT=$ANDROID_PRODUCT_OUT
319
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700320 unset ANDROID_HOST_OUT
321 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
322
Jiyong Parkc02b1c42020-11-03 11:06:39 +0900323 unset ANDROID_SOONG_HOST_OUT
324 export ANDROID_SOONG_HOST_OUT=$(get_abs_build_var SOONG_HOST_OUT)
325
Simran Basidd050ed2017-02-13 13:46:48 -0800326 unset ANDROID_HOST_OUT_TESTCASES
327 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
328
329 unset ANDROID_TARGET_OUT_TESTCASES
330 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
331
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700333 # TODO: fix the path
334 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
335}
336
Rupert Shuttleworth5d60d022020-10-25 05:20:03 +0000337function bazel()
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000338{
Jingwen Chen17d56992021-06-10 08:17:54 +0000339 if which bazel &>/dev/null; then
340 >&2 echo "NOTE: bazel() function sourced from Android's envsetup.sh is being used instead of $(which bazel)"
341 >&2 echo
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000342 fi
343
Jingwen Chen17d56992021-06-10 08:17:54 +0000344 local T="$(gettop)"
345 if [ ! "$T" ]; then
346 >&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."
347 return
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000348 fi
349
Rupert Shuttleworth5d60d022020-10-25 05:20:03 +0000350 "$T/tools/bazel" "$@"
Rupert Shuttleworth131fa7d2020-10-12 13:41:12 +0000351}
352
Matt Alexanderd9c56562020-05-21 10:49:17 +0000353function printconfig()
354{
Christopher Ferris55257d22017-03-23 11:08:58 -0700355 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800356 if [ ! "$T" ]; then
357 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
358 return
359 fi
360 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700361}
362
Matt Alexanderd9c56562020-05-21 10:49:17 +0000363function set_stuff_for_environment()
364{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800365 setpaths
366 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700367
Ben Chengaac3f812013-08-13 14:38:15 -0700368 # With this environment variable new GCC can apply colors to warnings/errors
369 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 -0700370}
371
Matt Alexanderd9c56562020-05-21 10:49:17 +0000372function set_sequence_number()
373{
Colin Cross88737132017-03-21 17:41:03 -0700374 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700375}
376
Makoto Onukida971062018-06-18 10:15:19 -0700377# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
378function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800379 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700380 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800381 *:"$cmd":*)
382 return 1
383 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700384 esac
385 return 0
386}
387
Matt Alexanderd9c56562020-05-21 10:49:17 +0000388function addcompletions()
389{
Ben Taitelbaum8c2c9cf2020-09-22 16:45:05 -0700390 local f=
Kenny Root52aa81c2011-07-15 11:07:06 -0700391
Jim Tanga881a252018-06-19 16:34:41 +0800392 # Keep us from trying to run in something that's neither bash nor zsh.
393 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700394 return
395 fi
396
397 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800398 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700399 return
400 fi
401
Jim Tanga881a252018-06-19 16:34:41 +0800402 local completion_files=(
403 system/core/adb/adb.bash
404 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800405 tools/asuite/asuite.sh
Jim Tanga881a252018-06-19 16:34:41 +0800406 )
Makoto Onukida971062018-06-18 10:15:19 -0700407 # Completion can be disabled selectively to allow users to use non-standard completion.
408 # e.g.
409 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
410 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800411 for f in ${completion_files[*]}; do
412 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700413 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700414 fi
415 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700416
Matt Alexanderd9c56562020-05-21 10:49:17 +0000417 if should_add_completion bit ; then
Makoto Onukida971062018-06-18 10:15:19 -0700418 complete -C "bit --tab" bit
419 fi
Anton Hanssonece9c482019-02-04 18:15:39 +0000420 if [ -z "$ZSH_VERSION" ]; then
421 # Doesn't work in zsh.
422 complete -o nospace -F _croot croot
423 fi
Jim Tanga881a252018-06-19 16:34:41 +0800424 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800425
Cole Faust24c36db2021-01-23 02:39:37 +0000426 complete -F _complete_android_module_names pathmod
dimitry73b84812018-12-11 18:06:00 +0100427 complete -F _complete_android_module_names gomod
Cole Faust24c36db2021-01-23 02:39:37 +0000428 complete -F _complete_android_module_names outmod
429 complete -F _complete_android_module_names installmod
dimitry73b84812018-12-11 18:06:00 +0100430 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700431}
432
Joe Onorato824608c2022-04-08 11:06:16 -0700433function multitree_lunch_help()
434{
435 echo "usage: lunch PRODUCT-VARIANT" 1>&2
436 echo " Set up android build environment based on a product short name and variant" 1>&2
437 echo 1>&2
438 echo "lunch COMBO_FILE VARIANT" 1>&2
439 echo " Set up android build environment based on a specific lunch combo file" 1>&2
440 echo " and variant." 1>&2
441 echo 1>&2
442 echo "lunch --print [CONFIG]" 1>&2
443 echo " Print the contents of a configuration. If CONFIG is supplied, that config" 1>&2
444 echo " will be flattened and printed. If CONFIG is not supplied, the currently" 1>&2
445 echo " selected config will be printed. Returns 0 on success or nonzero on error." 1>&2
446 echo 1>&2
447 echo "lunch --list" 1>&2
448 echo " List all possible combo files available in the current tree" 1>&2
449 echo 1>&2
450 echo "lunch --help" 1>&2
451 echo "lunch -h" 1>&2
452 echo " Prints this message." 1>&2
453}
454
455function multitree_lunch()
456{
457 local code
458 local results
459 if $(echo "$1" | grep -q '^-') ; then
460 # Calls starting with a -- argument are passed directly and the function
461 # returns with the lunch.py exit code.
462 build/make/orchestrator/core/lunch.py "$@"
463 code=$?
464 if [[ $code -eq 2 ]] ; then
465 echo 1>&2
466 multitree_lunch_help
467 return $code
468 elif [[ $code -ne 0 ]] ; then
469 return $code
470 fi
471 else
472 # All other calls go through the --lunch variant of lunch.py
473 results=($(build/make/orchestrator/core/lunch.py --lunch "$@"))
474 code=$?
475 if [[ $code -eq 2 ]] ; then
476 echo 1>&2
477 multitree_lunch_help
478 return $code
479 elif [[ $code -ne 0 ]] ; then
480 return $code
481 fi
482
483 export TARGET_BUILD_COMBO=${results[0]}
484 export TARGET_BUILD_VARIANT=${results[1]}
485 fi
486}
487
Matt Alexanderd9c56562020-05-21 10:49:17 +0000488function choosetype()
489{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700490 echo "Build type choices are:"
491 echo " 1. release"
492 echo " 2. debug"
493 echo
494
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800495 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700496 DEFAULT_NUM=1
497 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700498
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499 export TARGET_BUILD_TYPE=
500 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700501 while [ -z $TARGET_BUILD_TYPE ]
502 do
503 echo -n "Which would you like? ["$DEFAULT_NUM"] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000504 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800505 read ANSWER
506 else
507 echo $1
508 ANSWER=$1
509 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700510 case $ANSWER in
511 "")
512 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
513 ;;
514 1)
515 export TARGET_BUILD_TYPE=release
516 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800517 release)
518 export TARGET_BUILD_TYPE=release
519 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700520 2)
521 export TARGET_BUILD_TYPE=debug
522 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800523 debug)
524 export TARGET_BUILD_TYPE=debug
525 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700526 *)
527 echo
528 echo "I didn't understand your response. Please try again."
529 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700530 ;;
531 esac
Matt Alexanderd9c56562020-05-21 10:49:17 +0000532 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800533 break
534 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700535 done
536
Ying Wang08800fd2016-03-03 20:57:21 -0800537 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700538 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800539 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700540}
541
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800542#
543# This function isn't really right: It chooses a TARGET_PRODUCT
544# based on the list of boards. Usually, that gets you something
545# that kinda works with a generic product, but really, you should
546# pick a product by name.
547#
Matt Alexanderd9c56562020-05-21 10:49:17 +0000548function chooseproduct()
549{
Christopher Ferris55257d22017-03-23 11:08:58 -0700550 local default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000551 if [ "x$TARGET_PRODUCT" != x ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700552 default_value=$TARGET_PRODUCT
553 else
Ying Wang0a76df52015-06-08 11:57:26 -0700554 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700555 fi
556
Ying Wang08800fd2016-03-03 20:57:21 -0800557 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800558 export TARGET_PRODUCT=
559 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700560 while [ -z "$TARGET_PRODUCT" ]
561 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700562 echo -n "Which product would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000563 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800564 read ANSWER
565 else
566 echo $1
567 ANSWER=$1
568 fi
569
Matt Alexanderd9c56562020-05-21 10:49:17 +0000570 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700571 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800572 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000573 if check_product $ANSWER
574 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800575 export TARGET_PRODUCT=$ANSWER
576 else
577 echo "** Not a valid product: $ANSWER"
578 fi
579 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000580 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800581 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582 fi
583 done
584
Ying Wang08800fd2016-03-03 20:57:21 -0800585 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700586 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800587 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700588}
589
Matt Alexanderd9c56562020-05-21 10:49:17 +0000590function choosevariant()
591{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800592 echo "Variant choices are:"
593 local index=1
594 local v
595 for v in ${VARIANT_CHOICES[@]}
596 do
597 # The product name is the name of the directory containing
598 # the makefile we found, above.
599 echo " $index. $v"
600 index=$(($index+1))
601 done
602
603 local default_value=eng
604 local ANSWER
605
606 export TARGET_BUILD_VARIANT=
607 while [ -z "$TARGET_BUILD_VARIANT" ]
608 do
609 echo -n "Which would you like? [$default_value] "
Matt Alexanderd9c56562020-05-21 10:49:17 +0000610 if [ -z "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800611 read ANSWER
612 else
613 echo $1
614 ANSWER=$1
615 fi
616
Matt Alexanderd9c56562020-05-21 10:49:17 +0000617 if [ -z "$ANSWER" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800618 export TARGET_BUILD_VARIANT=$default_value
Matt Alexanderd9c56562020-05-21 10:49:17 +0000619 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
620 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Guillaume Chelfice000fd2019-10-03 12:02:46 +0200621 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800622 fi
623 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000624 if check_variant $ANSWER
625 then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800626 export TARGET_BUILD_VARIANT=$ANSWER
627 else
628 echo "** Not a valid variant: $ANSWER"
629 fi
630 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +0000631 if [ -n "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800632 break
633 fi
634 done
635}
636
Matt Alexanderd9c56562020-05-21 10:49:17 +0000637function choosecombo()
638{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700639 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700640
641 echo
642 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700643 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700644
645 echo
646 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700647 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800648
649 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800650 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800652 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800653 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700654}
655
Matt Alexanderd9c56562020-05-21 10:49:17 +0000656function add_lunch_combo()
657{
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800658 if [ -n "$ZSH_VERSION" ]; then
659 echo -n "${funcfiletrace[1]}: "
660 else
661 echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
662 fi
663 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 -0800664}
665
Matt Alexanderd9c56562020-05-21 10:49:17 +0000666function print_lunch_menu()
667{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700668 local uname=$(uname)
Roland Levillain23c46cf2020-03-31 16:11:05 +0100669 local choices
Colin Crossfa50d402021-04-22 13:05:41 -0700670 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 +0100671 local ret=$?
672
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700673 echo
674 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700675 echo
Roland Levillain23c46cf2020-03-31 16:11:05 +0100676
Matt Alexanderd9c56562020-05-21 10:49:17 +0000677 if [ $ret -ne 0 ]
678 then
Roland Levillain23c46cf2020-03-31 16:11:05 +0100679 echo "Warning: Cannot display lunch menu."
680 echo
681 echo "Note: You can invoke lunch with an explicit target:"
682 echo
683 echo " usage: lunch [target]" >&2
684 echo
685 return
686 fi
687
Will Burr40401202022-02-07 12:12:01 +0000688 echo "Lunch menu .. Here are the common combinations:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800689
690 local i=1
691 local choice
Dan Willemsen91763e92019-10-03 15:13:12 -0700692 for choice in $(echo $choices)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800693 do
694 echo " $i. $choice"
695 i=$(($i+1))
696 done
697
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700698 echo
699}
700
Matt Alexanderd9c56562020-05-21 10:49:17 +0000701function lunch()
702{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800703 local answer
704
Steven Moreland92793dc2020-02-25 18:30:18 -0800705 if [[ $# -gt 1 ]]; then
706 echo "usage: lunch [target]" >&2
707 return 1
708 fi
709
Will Burr40401202022-02-07 12:12:01 +0000710 local used_lunch_menu=0
711
Steven Moreland92793dc2020-02-25 18:30:18 -0800712 if [ "$1" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800713 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700714 else
715 print_lunch_menu
Will Burr40401202022-02-07 12:12:01 +0000716 echo "Which would you like? [aosp_arm-eng]"
717 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 -0800718 read answer
Will Burr40401202022-02-07 12:12:01 +0000719 used_lunch_menu=1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700720 fi
721
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800722 local selection=
723
Matt Alexanderd9c56562020-05-21 10:49:17 +0000724 if [ -z "$answer" ]
725 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700726 selection=aosp_arm-eng
Matt Alexanderd9c56562020-05-21 10:49:17 +0000727 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
728 then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800729 local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
Matt Alexanderd9c56562020-05-21 10:49:17 +0000730 if [ $answer -le ${#choices[@]} ]
731 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800732 # array in zsh starts from 1 instead of 0.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000733 if [ -n "$ZSH_VERSION" ]
734 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800735 selection=${choices[$(($answer))]}
736 else
737 selection=${choices[$(($answer-1))]}
738 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800739 fi
Colin Cross88737132017-03-21 17:41:03 -0700740 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800741 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700742 fi
743
Joe Onoratoda12daf2010-06-09 18:18:31 -0700744 export TARGET_BUILD_APPS=
745
Colin Cross88737132017-03-21 17:41:03 -0700746 local product variant_and_version variant version
Colin Cross88737132017-03-21 17:41:03 -0700747 product=${selection%%-*} # Trim everything after first dash
748 variant_and_version=${selection#*-} # Trim everything up to first dash
749 if [ "$variant_and_version" != "$selection" ]; then
750 variant=${variant_and_version%%-*}
751 if [ "$variant" != "$variant_and_version" ]; then
752 version=${variant_and_version#*-}
753 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700754 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800755
Matt Alexanderd9c56562020-05-21 10:49:17 +0000756 if [ -z "$product" ]
757 then
Ying Wang08800fd2016-03-03 20:57:21 -0800758 echo
Colin Cross88737132017-03-21 17:41:03 -0700759 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700760 return 1
761 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800762
Colin Cross88737132017-03-21 17:41:03 -0700763 TARGET_PRODUCT=$product \
764 TARGET_BUILD_VARIANT=$variant \
765 TARGET_PLATFORM_VERSION=$version \
766 build_build_var_cache
Matt Alexanderd9c56562020-05-21 10:49:17 +0000767 if [ $? -ne 0 ]
768 then
Anton Hansson32fa7ee2021-06-14 17:09:58 +0100769 if [[ "$product" =~ .*_(eng|user|userdebug) ]]
770 then
771 echo "Did you mean -${product/*_/}? (dash instead of underscore)"
772 fi
Colin Cross88737132017-03-21 17:41:03 -0700773 return 1
774 fi
Colin Cross88737132017-03-21 17:41:03 -0700775 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
776 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700777 if [ -n "$version" ]; then
778 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
779 else
780 unset TARGET_PLATFORM_VERSION
781 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700782 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700783
Will Burr40401202022-02-07 12:12:01 +0000784 if [ $used_lunch_menu -eq 1 ]; then
785 echo
786 echo "Hint: next time you can simply run 'lunch $selection'"
787 fi
788
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700789 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800790
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791 set_stuff_for_environment
Sasha Smundak90d07bc2020-06-04 10:48:15 -0700792 [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800793 destroy_build_var_cache
Kousik Kumar41dacd12021-05-11 18:38:38 -0400794
795 if [[ -n "${CHECK_MU_CONFIG:-}" ]]; then
796 check_mu_config
797 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700798}
799
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700800unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700801# Tab completion for lunch.
Matt Alexanderd9c56562020-05-21 10:49:17 +0000802function _lunch()
803{
Jeff Davidson513d7a42010-08-02 10:00:44 -0700804 local cur prev opts
805 COMPREPLY=()
806 cur="${COMP_WORDS[COMP_CWORD]}"
807 prev="${COMP_WORDS[COMP_CWORD-1]}"
808
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700809 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800810 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700811 fi
812
813 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700814 return 0
815}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700816
Joe Onoratoda12daf2010-06-09 18:18:31 -0700817# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700818# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Matt Alexanderd9c56562020-05-21 10:49:17 +0000819function tapas()
820{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700821 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Elliott Hughesf71c05a2020-03-06 16:46:59 -0800822 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700823 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700824 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 -0800825 local keys="$(echo $* | xargs -n 1 echo | \grep -E '^(devkeys)$' | xargs)"
826 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)"
827
Joe Onoratoda12daf2010-06-09 18:18:31 -0700828
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700829 if [ "$showHelp" != "" ]; then
830 $(gettop)/build/make/tapasHelp.sh
831 return
832 fi
833
Ying Wang67f02922012-08-22 10:25:20 -0700834 if [ $(echo $arch | wc -w) -gt 1 ]; then
835 echo "tapas: Error: Multiple build archs supplied: $arch"
836 return
837 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700838 if [ $(echo $variant | wc -w) -gt 1 ]; then
839 echo "tapas: Error: Multiple build variants supplied: $variant"
840 return
841 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700842 if [ $(echo $density | wc -w) -gt 1 ]; then
843 echo "tapas: Error: Multiple densities supplied: $density"
844 return
845 fi
Colin Cross7f49a672022-01-27 18:15:53 -0800846 if [ $(echo $keys | wc -w) -gt 1 ]; then
847 echo "tapas: Error: Multiple keys supplied: $keys"
848 return
849 fi
Ying Wang67f02922012-08-22 10:25:20 -0700850
Ying Wang0a76df52015-06-08 11:57:26 -0700851 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700852 case $arch in
Matt Alexanderd9c56562020-05-21 10:49:17 +0000853 x86) product=aosp_x86;;
854 arm64) product=aosp_arm64;;
855 x86_64) product=aosp_x86_64;;
Ying Wang67f02922012-08-22 10:25:20 -0700856 esac
Colin Cross7f49a672022-01-27 18:15:53 -0800857 if [ -n "$keys" ]; then
858 product=${product/aosp_/aosp_${keys}_}
859 fi;
860
Joe Onoratoda12daf2010-06-09 18:18:31 -0700861 if [ -z "$variant" ]; then
862 variant=eng
863 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700864 if [ -z "$apps" ]; then
865 apps=all
866 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600867 if [ -z "$density" ]; then
868 density=alldpi
869 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700870
Ying Wang67f02922012-08-22 10:25:20 -0700871 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700872 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700873 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700874 export TARGET_BUILD_TYPE=release
875 export TARGET_BUILD_APPS=$apps
876
Ying Wang08800fd2016-03-03 20:57:21 -0800877 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700878 set_stuff_for_environment
879 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800880 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700881}
882
Martin Stjernholmf692c752021-04-12 00:01:10 +0100883# Configures the build to build unbundled Android modules (APEXes).
884# Run banchan with one or more module names (from apex{} modules).
885function banchan()
886{
887 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100888 local product="$(echo $* | xargs -n 1 echo | \grep -E '^(.*_)?(arm|x86|arm64|x86_64)$' | xargs)"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100889 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100890 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 +0100891
892 if [ "$showHelp" != "" ]; then
893 $(gettop)/build/make/banchanHelp.sh
894 return
895 fi
896
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100897 if [ -z "$product" ]; then
898 product=arm
899 elif [ $(echo $product | wc -w) -gt 1 ]; then
900 echo "banchan: Error: Multiple build archs or products supplied: $products"
Martin Stjernholmf692c752021-04-12 00:01:10 +0100901 return
902 fi
903 if [ $(echo $variant | wc -w) -gt 1 ]; then
904 echo "banchan: Error: Multiple build variants supplied: $variant"
905 return
906 fi
907 if [ -z "$apps" ]; then
908 echo "banchan: Error: No modules supplied"
909 return
910 fi
911
Martin Stjernholm2b8d9232021-04-16 20:45:03 +0100912 case $product in
913 arm) product=module_arm;;
Martin Stjernholmf692c752021-04-12 00:01:10 +0100914 x86) product=module_x86;;
915 arm64) product=module_arm64;;
916 x86_64) product=module_x86_64;;
917 esac
918 if [ -z "$variant" ]; then
919 variant=eng
920 fi
921
922 export TARGET_PRODUCT=$product
923 export TARGET_BUILD_VARIANT=$variant
924 export TARGET_BUILD_DENSITY=alldpi
925 export TARGET_BUILD_TYPE=release
926
927 # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use
928 # case is different and it may diverge in the future.
929 export TARGET_BUILD_APPS=$apps
930
931 build_build_var_cache
932 set_stuff_for_environment
933 printconfig
934 destroy_build_var_cache
935}
936
Matt Alexanderd9c56562020-05-21 10:49:17 +0000937function gettop
938{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700939 local TOPFILE=build/make/core/envsetup.mk
Matt Alexanderd9c56562020-05-21 10:49:17 +0000940 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700941 # The following circumlocution ensures we remove symlinks from TOP.
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000942 (cd "$TOP"; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700943 else
Matt Alexanderd9c56562020-05-21 10:49:17 +0000944 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800945 # The following circumlocution (repeated below as well) ensures
946 # that we record the true directory name and not one that is
947 # faked up with symlink names.
948 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700949 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800950 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700951 local T=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000952 while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800953 \cd ..
synergyb112a402013-07-05 19:47:47 -0700954 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700955 done
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000956 \cd "$HERE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700957 if [ -f "$T/$TOPFILE" ]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +0000958 echo "$T"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700959 fi
960 fi
961 fi
962}
963
Matt Alexanderd9c56562020-05-21 10:49:17 +0000964function croot()
965{
Christopher Ferris55257d22017-03-23 11:08:58 -0700966 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700968 if [ "$1" ]; then
969 \cd $(gettop)/$1
970 else
971 \cd $(gettop)
972 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700973 else
974 echo "Couldn't locate the top of the tree. Try setting TOP."
975 fi
976}
977
Matt Alexanderd9c56562020-05-21 10:49:17 +0000978function _croot()
979{
Anton Hanssonece9c482019-02-04 18:15:39 +0000980 local T=$(gettop)
981 if [ "$T" ]; then
982 local cur="${COMP_WORDS[COMP_CWORD]}"
983 k=0
984 for c in $(compgen -d ${T}/${cur}); do
985 COMPREPLY[k++]=${c#${T}/}/
986 done
987 fi
988}
989
Matt Alexanderd9c56562020-05-21 10:49:17 +0000990function cproj()
991{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700992 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700993 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700994 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700995 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
996 T=$PWD
997 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800998 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700999 return
1000 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001001 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001002 done
Ying Wang9cd17642012-12-13 10:52:07 -08001003 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001004 echo "can't find Android.mk"
1005}
1006
Daniel Sandler47e0a882013-07-30 13:23:52 -04001007# simplified version of ps; output in the form
1008# <pid> <procname>
1009function qpid() {
1010 local prepend=''
1011 local append=''
Matt Alexanderd9c56562020-05-21 10:49:17 +00001012 if [ "$1" = "--exact" ]; then
Daniel Sandler47e0a882013-07-30 13:23:52 -04001013 prepend=' '
1014 append='$'
1015 shift
Matt Alexanderd9c56562020-05-21 10:49:17 +00001016 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001017 echo "usage: qpid [[--exact] <process name|pid>"
1018 return 255
1019 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001020
1021 local EXE="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001022 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001023 qpid | \grep "$prepend$EXE$append"
1024 else
1025 adb shell ps \
1026 | tr -d '\r' \
1027 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1028 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001029}
1030
Steven Moreland74114f12020-09-10 01:23:32 +00001031# syswrite - disable verity, reboot if needed, and remount image
1032#
1033# Easy way to make system.img/etc writable
1034function syswrite() {
1035 adb wait-for-device && adb root || return 1
1036 if [[ $(adb disable-verity | grep "reboot") ]]; then
1037 echo "rebooting"
1038 adb reboot && adb wait-for-device && adb root || return 1
1039 fi
1040 adb wait-for-device && adb remount || return 1
1041}
1042
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001043# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001044# that has the core-file-size limit set correctly
1045#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001046# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001047# if its core-file-size limit is not set already.
1048# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1049
Matt Alexanderd9c56562020-05-21 10:49:17 +00001050function coredump_setup()
1051{
1052 echo "Getting root...";
1053 adb root;
1054 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001055
Matt Alexanderd9c56562020-05-21 10:49:17 +00001056 echo "Remounting root partition read-write...";
1057 adb shell mount -w -o remount -t rootfs rootfs;
1058 sleep 1;
1059 adb wait-for-device;
1060 adb shell mkdir -p /cores;
1061 adb shell mount -t tmpfs tmpfs /cores;
1062 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001063
Matt Alexanderd9c56562020-05-21 10:49:17 +00001064 echo "Granting SELinux permission to dump in /cores...";
1065 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001066
Matt Alexanderd9c56562020-05-21 10:49:17 +00001067 echo "Set core pattern.";
1068 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001069
Ying Wang08800fd2016-03-03 20:57:21 -08001070 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001071}
1072
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001073# coredump_enable - enable core dumps for the specified process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001074# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001075#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001076# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001077# dump to actually be generated.
1078
Matt Alexanderd9c56562020-05-21 10:49:17 +00001079function coredump_enable()
1080{
1081 local PID=$1;
Ying Wang08800fd2016-03-03 20:57:21 -08001082 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001083 printf "Expecting a PID!\n";
1084 return;
1085 fi;
1086 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001087 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001088}
1089
1090# core - send SIGV and pull the core for process
Matt Alexanderd9c56562020-05-21 10:49:17 +00001091# $1 = PID of process (e.g., $(pid mediaserver))
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001092#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001093# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001094# enabled globally.
1095
Matt Alexanderd9c56562020-05-21 10:49:17 +00001096function core()
1097{
1098 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001099
Ying Wang08800fd2016-03-03 20:57:21 -08001100 if [ -z "$PID" ]; then
Matt Alexanderd9c56562020-05-21 10:49:17 +00001101 printf "Expecting a PID!\n";
1102 return;
1103 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001104
Matt Alexanderd9c56562020-05-21 10:49:17 +00001105 local CORENAME=core.$PID;
1106 local COREPATH=/cores/$CORENAME;
1107 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001108
Matt Alexanderd9c56562020-05-21 10:49:17 +00001109 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001110
Matt Alexanderd9c56562020-05-21 10:49:17 +00001111 local done=0;
Ying Wang08800fd2016-03-03 20:57:21 -08001112 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
Matt Alexanderd9c56562020-05-21 10:49:17 +00001113 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1114 adb shell kill -$SIG $PID;
1115 sleep 1;
1116 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001117
Matt Alexanderd9c56562020-05-21 10:49:17 +00001118 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1119 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001120}
1121
Christopher Tate744ee802009-11-12 15:33:08 -08001122# systemstack - dump the current stack trace of all threads in the system process
1123# to the usual ANR traces file
Matt Alexanderd9c56562020-05-21 10:49:17 +00001124function systemstack()
1125{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001126 stacks system_server
1127}
1128
Michael Wrightaeed7212014-06-19 19:58:12 -07001129# Read the ELF header from /proc/$PID/exe to determine if the process is
1130# 64-bit.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001131function is64bit()
1132{
Ben Chengfba67bf2014-02-25 10:27:07 -08001133 local PID="$1"
Matt Alexanderd9c56562020-05-21 10:49:17 +00001134 if [ "$PID" ] ; then
1135 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001136 echo "64"
1137 else
1138 echo ""
1139 fi
1140 else
1141 echo ""
1142 fi
1143}
1144
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001145case `uname -s` in
1146 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001147 function sgrep()
1148 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001149 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 -04001150 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001151 }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001152
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001153 ;;
1154 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001155 function sgrep()
1156 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001157 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 -04001158 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001159 }
1160 ;;
1161esac
1162
Matt Alexanderd9c56562020-05-21 10:49:17 +00001163function gettargetarch
1164{
Raghu Gandham8da43102012-07-25 19:57:22 -07001165 get_build_var TARGET_ARCH
1166}
1167
Matt Alexanderd9c56562020-05-21 10:49:17 +00001168function ggrep()
1169{
Mike Frysinger5e479732015-09-22 18:13:48 -04001170 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1171 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001172}
1173
Matt Alexanderd9c56562020-05-21 10:49:17 +00001174function gogrep()
1175{
Orion Hodson831472d2019-10-25 11:35:15 +01001176 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
1177 -exec grep --color -n "$@" {} +
1178}
1179
Matt Alexanderd9c56562020-05-21 10:49:17 +00001180function jgrep()
1181{
Mike Frysinger5e479732015-09-22 18:13:48 -04001182 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1183 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001184}
1185
Alistair Delva176e5342021-02-22 13:31:26 -08001186function rsgrep()
Jeff Vander Stoep1431ab82021-02-02 19:18:26 +01001187{
1188 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rs" \
1189 -exec grep --color -n "$@" {} +
1190}
1191
Taesu Leeea0cecd2020-10-28 11:05:18 +09001192function ktgrep()
1193{
1194 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.kt" \
1195 -exec grep --color -n "$@" {} +
1196}
1197
Matt Alexanderd9c56562020-05-21 10:49:17 +00001198function cgrep()
1199{
Mike Frysinger5e479732015-09-22 18:13:48 -04001200 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' \) \
1201 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001202}
1203
Matt Alexanderd9c56562020-05-21 10:49:17 +00001204function resgrep()
1205{
Christopher Ferris55257d22017-03-23 11:08:58 -07001206 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001207 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1208 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1209 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001210}
1211
Matt Alexanderd9c56562020-05-21 10:49:17 +00001212function mangrep()
1213{
Mike Frysinger5e479732015-09-22 18:13:48 -04001214 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1215 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001216}
1217
Matt Alexanderd9c56562020-05-21 10:49:17 +00001218function owngrep()
1219{
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -06001220 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
1221 -exec grep --color -n "$@" {} +
1222}
1223
Matt Alexanderd9c56562020-05-21 10:49:17 +00001224function sepgrep()
1225{
Mike Frysinger5e479732015-09-22 18:13:48 -04001226 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1227 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001228}
1229
Matt Alexanderd9c56562020-05-21 10:49:17 +00001230function rcgrep()
1231{
Mike Frysinger5e479732015-09-22 18:13:48 -04001232 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1233 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001234}
1235
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236case `uname -s` in
1237 Darwin)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001238 function mgrep()
1239 {
Orion Hodson831472d2019-10-25 11:35:15 +01001240 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regex '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001241 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001242 }
1243
Matt Alexanderd9c56562020-05-21 10:49:17 +00001244 function treegrep()
1245 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001246 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|hpp|S|java|kt|xml)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001247 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001248 }
1249
1250 ;;
1251 *)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001252 function mgrep()
1253 {
Orion Hodson831472d2019-10-25 11:35:15 +01001254 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regextype posix-extended -regex '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001255 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001256 }
1257
Matt Alexanderd9c56562020-05-21 10:49:17 +00001258 function treegrep()
1259 {
Taesu Leeea0cecd2020-10-28 11:05:18 +09001260 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|hpp|S|java|kt|xml)' -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001261 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001262 }
1263
1264 ;;
1265esac
1266
Matt Alexanderd9c56562020-05-21 10:49:17 +00001267function getprebuilt
1268{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001269 get_abs_build_var ANDROID_PREBUILTS
1270}
1271
Matt Alexanderd9c56562020-05-21 10:49:17 +00001272function tracedmdump()
1273{
Christopher Ferris55257d22017-03-23 11:08:58 -07001274 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001275 if [ ! "$T" ]; then
1276 echo "Couldn't locate the top of the tree. Try setting TOP."
1277 return
1278 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001279 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001280 local arch=$(gettargetarch)
1281 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001282
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001283 local TRACE=$1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001284 if [ ! "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001285 echo "usage: tracedmdump tracename"
1286 return
1287 fi
1288
Matt Alexanderd9c56562020-05-21 10:49:17 +00001289 if [ ! -r "$KERNEL" ] ; then
Jack Veenstra60116fc2009-04-09 18:12:34 -07001290 echo "Error: cannot find kernel: '$KERNEL'"
1291 return
1292 fi
1293
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001294 local BASETRACE=$(basename $TRACE)
Matt Alexanderd9c56562020-05-21 10:49:17 +00001295 if [ "$BASETRACE" = "$TRACE" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001296 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1297 fi
1298
1299 echo "post-processing traces..."
1300 rm -f $TRACE/qtrace.dexlist
1301 post_trace $TRACE
1302 if [ $? -ne 0 ]; then
1303 echo "***"
1304 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1305 echo "***"
1306 return
1307 fi
1308 echo "generating dexlist output..."
1309 /bin/ls $ANDROID_PRODUCT_OUT/system/framework/*.jar $ANDROID_PRODUCT_OUT/system/app/*.apk $ANDROID_PRODUCT_OUT/data/app/*.apk 2>/dev/null | xargs dexlist > $TRACE/qtrace.dexlist
1310 echo "generating dmtrace data..."
1311 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1312 echo "generating html file..."
1313 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1314 echo "done, see $TRACE/dmtrace.html for details"
1315 echo "or run:"
1316 echo " traceview $TRACE/dmtrace"
1317}
1318
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001319# communicate with a running device or emulator, set up necessary state,
1320# and run the hat command.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001321function runhat()
1322{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001323 # process standard adb options
1324 local adbTarget=""
Matt Alexanderd9c56562020-05-21 10:49:17 +00001325 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001326 adbTarget=$1
1327 shift 1
Matt Alexanderd9c56562020-05-21 10:49:17 +00001328 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001329 adbTarget="$1 $2"
1330 shift 2
1331 fi
1332 local adbOptions=${adbTarget}
Matt Alexanderd9c56562020-05-21 10:49:17 +00001333 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001334
1335 # runhat options
1336 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001337
Matt Alexanderd9c56562020-05-21 10:49:17 +00001338 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001339 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001340 return
1341 fi
1342
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001343 # confirm hat is available
1344 if [ -z $(which hat) ]; then
1345 echo "hat is not available in this configuration."
1346 return
1347 fi
1348
Andy McFaddenb6289852010-07-12 08:00:19 -07001349 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001350 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001351 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001352 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001353 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001354 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001355 echo -n "> "
1356 read
1357
The Android Open Source Project88b60792009-03-03 19:28:42 -08001358 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001359
The Android Open Source Project88b60792009-03-03 19:28:42 -08001360 echo "Retrieving file $devFile..."
1361 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001362
The Android Open Source Project88b60792009-03-03 19:28:42 -08001363 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001364
The Android Open Source Project88b60792009-03-03 19:28:42 -08001365 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001366 echo "View the output by pointing your browser at http://localhost:7000/"
1367 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001368 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001369}
1370
Matt Alexanderd9c56562020-05-21 10:49:17 +00001371function getbugreports()
1372{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001373 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001374
1375 if [ ! "$reports" ]; then
1376 echo "Could not locate any bugreports."
1377 return
1378 fi
1379
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001380 local report
1381 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001382 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001383 echo "/sdcard/bugreports/${report}"
1384 adb pull /sdcard/bugreports/${report} ${report}
1385 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001386 done
1387}
1388
Matt Alexanderd9c56562020-05-21 10:49:17 +00001389function getsdcardpath()
1390{
Victoria Lease1b296b42012-08-21 15:44:06 -07001391 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1392}
1393
Matt Alexanderd9c56562020-05-21 10:49:17 +00001394function getscreenshotpath()
1395{
Victoria Lease1b296b42012-08-21 15:44:06 -07001396 echo "$(getsdcardpath)/Pictures/Screenshots"
1397}
1398
Matt Alexanderd9c56562020-05-21 10:49:17 +00001399function getlastscreenshot()
1400{
Victoria Lease1b296b42012-08-21 15:44:06 -07001401 local screenshot_path=$(getscreenshotpath)
1402 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
Matt Alexanderd9c56562020-05-21 10:49:17 +00001403 if [ "$screenshot" = "" ]; then
Victoria Lease1b296b42012-08-21 15:44:06 -07001404 echo "No screenshots found."
1405 return
1406 fi
1407 echo "${screenshot}"
1408 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1409}
1410
Matt Alexanderd9c56562020-05-21 10:49:17 +00001411function startviewserver()
1412{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001413 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001414 if [ $# -gt 0 ]; then
1415 port=$1
1416 fi
1417 adb shell service call window 1 i32 $port
1418}
1419
Matt Alexanderd9c56562020-05-21 10:49:17 +00001420function stopviewserver()
1421{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001422 adb shell service call window 2
1423}
1424
Matt Alexanderd9c56562020-05-21 10:49:17 +00001425function isviewserverstarted()
1426{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001427 adb shell service call window 3
1428}
1429
Matt Alexanderd9c56562020-05-21 10:49:17 +00001430function key_home()
1431{
Romain Guyb84049a2010-10-04 16:56:11 -07001432 adb shell input keyevent 3
1433}
1434
Matt Alexanderd9c56562020-05-21 10:49:17 +00001435function key_back()
1436{
Romain Guyb84049a2010-10-04 16:56:11 -07001437 adb shell input keyevent 4
1438}
1439
Matt Alexanderd9c56562020-05-21 10:49:17 +00001440function key_menu()
1441{
Romain Guyb84049a2010-10-04 16:56:11 -07001442 adb shell input keyevent 82
1443}
1444
Matt Alexanderd9c56562020-05-21 10:49:17 +00001445function smoketest()
1446{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001447 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1448 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1449 return
1450 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001451 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001452 if [ ! "$T" ]; then
1453 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1454 return
1455 fi
1456
Ying Wang9cd17642012-12-13 10:52:07 -08001457 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001458 adb uninstall com.android.smoketest > /dev/null &&
1459 adb uninstall com.android.smoketest.tests > /dev/null &&
1460 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1461 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1462 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1463}
1464
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001465# simple shortcut to the runtest command
Matt Alexanderd9c56562020-05-21 10:49:17 +00001466function runtest()
1467{
Christopher Ferris55257d22017-03-23 11:08:58 -07001468 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001469 if [ ! "$T" ]; then
1470 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1471 return
1472 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001473 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001474}
1475
The Android Open Source Project88b60792009-03-03 19:28:42 -08001476function godir () {
1477 if [[ -z "$1" ]]; then
1478 echo "Usage: godir <regex>"
1479 return
1480 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001481 local T=$(gettop)
1482 local FILELIST
Matt Alexanderd9c56562020-05-21 10:49:17 +00001483 if [ ! "$OUT_DIR" = "" ]; then
Brian Carlstromf2257422015-09-30 20:28:54 -07001484 mkdir -p $OUT_DIR
1485 FILELIST=$OUT_DIR/filelist
1486 else
1487 FILELIST=$T/filelist
1488 fi
1489 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001490 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001491 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001492 echo " Done"
1493 echo ""
1494 fi
1495 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001496 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
Matt Alexanderd9c56562020-05-21 10:49:17 +00001497 if [[ ${#lines[@]} = 0 ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001498 echo "Not found"
1499 return
1500 fi
1501 local pathname
1502 local choice
1503 if [[ ${#lines[@]} > 1 ]]; then
1504 while [[ -z "$pathname" ]]; do
1505 local index=1
1506 local line
1507 for line in ${lines[@]}; do
1508 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001509 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001510 done
1511 echo
1512 echo -n "Select one: "
1513 unset choice
1514 read choice
1515 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1516 echo "Invalid choice"
1517 continue
1518 fi
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001519 pathname=${lines[@]:$(($choice-1)):1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001520 done
1521 else
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001522 pathname=${lines[@]:0:1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001523 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001524 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001525}
1526
Steven Moreland62054a42018-12-06 10:11:40 -08001527# Update module-info.json in out.
1528function refreshmod() {
1529 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1530 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1531 return 1
1532 fi
1533
1534 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1535
1536 # for the output of the next command
1537 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1538
1539 # Note, can't use absolute path because of the way make works.
Alessandro Astonec8771be2020-05-10 11:27:57 +02001540 m $(get_build_var PRODUCT_OUT)/module-info.json \
Steven Moreland62054a42018-12-06 10:11:40 -08001541 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1542}
1543
Cole Faust3e192382021-10-25 13:29:15 -07001544# Verifies that module-info.txt exists, returning nonzero if it doesn't.
Cole Faust24c36db2021-01-23 02:39:37 +00001545function verifymodinfo() {
Steven Moreland62054a42018-12-06 10:11:40 -08001546 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001547 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
1548 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1549 fi
Steven Moreland62054a42018-12-06 10:11:40 -08001550 return 1
1551 fi
1552
1553 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001554 if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then
Cole Faust3e192382021-10-25 13:29:15 -07001555 echo "Could not find module-info.json. Please run 'refreshmod' first." >&2
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001556 fi
1557 return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001558 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001559}
1560
1561# List all modules for the current device, as cached in module-info.json. If any build change is
1562# made and it should be reflected in the output, you should run 'refreshmod' first.
1563function allmod() {
1564 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001565
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001566 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 -08001567}
1568
Joe Onorato2c1aa472021-02-25 16:42:39 -08001569# Get the path of a specific module in the android tree, as cached in module-info.json.
1570# If any build change is made, and it should be reflected in the output, you should run
1571# 'refreshmod' first. Note: This is the inverse of dirmods.
Rett Berg78d1c932019-01-24 14:34:23 -08001572function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001573 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001574 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001575 return 1
1576 fi
1577
Cole Faust24c36db2021-01-23 02:39:37 +00001578 verifymodinfo || return 1
Steven Moreland62054a42018-12-06 10:11:40 -08001579
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001580 local relpath=$(python3 -c "import json, os
Steven Moreland62054a42018-12-06 10:11:40 -08001581module = '$1'
1582module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1583if module not in module_info:
1584 exit(1)
LuK1337b6a78192020-01-12 03:12:17 +01001585print(module_info[module]['path'][0])" 2>/dev/null)
Steven Moreland62054a42018-12-06 10:11:40 -08001586
1587 if [ -z "$relpath" ]; then
1588 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1589 return 1
1590 else
Rett Berg78d1c932019-01-24 14:34:23 -08001591 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001592 fi
1593}
1594
Joe Onorato2c1aa472021-02-25 16:42:39 -08001595# Get the path of a specific module in the android tree, as cached in module-info.json.
1596# If any build change is made, and it should be reflected in the output, you should run
1597# 'refreshmod' first. Note: This is the inverse of pathmod.
1598function dirmods() {
1599 if [[ $# -ne 1 ]]; then
1600 echo "usage: dirmods <path>" >&2
1601 return 1
1602 fi
1603
1604 verifymodinfo || return 1
1605
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001606 python3 -c "import json, os
Joe Onorato2c1aa472021-02-25 16:42:39 -08001607dir = '$1'
1608while dir.endswith('/'):
1609 dir = dir[:-1]
1610prefix = dir + '/'
1611module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1612results = set()
1613for m in module_info.values():
1614 for path in m.get(u'path', []):
1615 if path == dir or path.startswith(prefix):
1616 name = m.get(u'module_name')
1617 if name:
1618 results.add(name)
1619for name in sorted(results):
1620 print(name)
1621"
1622}
1623
1624
Rett Berg78d1c932019-01-24 14:34:23 -08001625# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1626# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1627function gomod() {
1628 if [[ $# -ne 1 ]]; then
1629 echo "usage: gomod <module>" >&2
1630 return 1
1631 fi
1632
1633 local path="$(pathmod $@)"
1634 if [ -z "$path" ]; then
1635 return 1
1636 fi
1637 cd $path
1638}
1639
Cole Faust24c36db2021-01-23 02:39:37 +00001640# Gets the list of a module's installed outputs, as cached in module-info.json.
1641# If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first.
1642function outmod() {
1643 if [[ $# -ne 1 ]]; then
1644 echo "usage: outmod <module>" >&2
1645 return 1
1646 fi
1647
1648 verifymodinfo || return 1
1649
1650 local relpath
Joe Onorato4acbe3b2021-04-29 15:31:42 -07001651 relpath=$(python3 -c "import json, os
Cole Faust24c36db2021-01-23 02:39:37 +00001652module = '$1'
1653module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1654if module not in module_info:
1655 exit(1)
1656for output in module_info[module]['installed']:
1657 print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null)
1658
1659 if [ $? -ne 0 ]; then
1660 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2
1661 return 1
1662 elif [ ! -z "$relpath" ]; then
1663 echo "$relpath"
1664 fi
1665}
1666
1667# adb install a module's apk, as cached in module-info.json. If any build change
1668# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1669# Usage: installmod [adb install arguments] <module>
1670# For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk
1671function installmod() {
1672 if [[ $# -eq 0 ]]; then
1673 echo "usage: installmod [adb install arguments] <module>" >&2
Cole Faust3e192382021-10-25 13:29:15 -07001674 echo "" >&2
1675 echo "Only flags to be passed after the \"install\" in adb install are supported," >&2
1676 echo "with the exception of -s. If -s is passed it will be placed before the \"install\"." >&2
1677 echo "-s must be the first flag passed if it exists." >&2
Cole Faust24c36db2021-01-23 02:39:37 +00001678 return 1
1679 fi
1680
1681 local _path
1682 _path=$(outmod ${@:$#:1})
1683 if [ $? -ne 0 ]; then
1684 return 1
1685 fi
1686
1687 _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1)
1688 if [ -z "$_path" ]; then
1689 echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2
1690 return 1
1691 fi
Cole Faust3e192382021-10-25 13:29:15 -07001692 local serial_device=""
1693 if [[ "$1" == "-s" ]]; then
1694 if [[ $# -le 2 ]]; then
1695 echo "-s requires an argument" >&2
1696 return 1
1697 fi
1698 serial_device="-s $2"
1699 shift 2
1700 fi
Cole Faust24c36db2021-01-23 02:39:37 +00001701 local length=$(( $# - 1 ))
Cole Faust3e192382021-10-25 13:29:15 -07001702 echo adb $serial_device install ${@:1:$length} $_path
1703 adb $serial_device install ${@:1:$length} $_path
Cole Faust24c36db2021-01-23 02:39:37 +00001704}
1705
dimitry73b84812018-12-11 18:06:00 +01001706function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001707 local word=${COMP_WORDS[COMP_CWORD]}
Joe Onorato0bac4fe2021-04-07 08:51:28 -07001708 COMPREPLY=( $(QUIET_VERIFYMODINFO=true allmod | grep -E "^$word") )
Steven Moreland62054a42018-12-06 10:11:40 -08001709}
1710
Alex Rayf0d08eb2013-03-08 15:15:06 -08001711# Print colored exit condition
1712function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001713 "$@"
1714 local retval=$?
Matt Alexanderd9c56562020-05-21 10:49:17 +00001715 if [ $retval -ne 0 ]
1716 then
Jacky Cao89483b82015-05-15 22:12:53 +08001717 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001718 else
Jacky Cao89483b82015-05-15 22:12:53 +08001719 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001720 fi
1721 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001722}
1723
Matt Alexanderd9c56562020-05-21 10:49:17 +00001724function get_make_command()
1725{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001726 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1727 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001728 # Always use the real make if -C is passed in
1729 for arg in "$@"; do
1730 if [[ $arg == -C* ]]; then
1731 echo command make
1732 return
1733 fi
1734 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001735 echo build/soong/soong_ui.bash --make-mode
1736 else
1737 echo command make
1738 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001739}
1740
Matt Alexanderd9c56562020-05-21 10:49:17 +00001741function _wrap_build()
1742{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001743 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1744 "$@"
1745 return $?
1746 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001747 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001748 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001749 local ret=$?
1750 local end_time=$(date +"%s")
1751 local tdiff=$(($end_time-$start_time))
1752 local hours=$(($tdiff / 3600 ))
1753 local mins=$((($tdiff % 3600) / 60))
1754 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001755 local ncolors=$(tput colors 2>/dev/null)
1756 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001757 color_failed=$'\E'"[0;31m"
1758 color_success=$'\E'"[0;32m"
Kousik Kumar09af2542021-08-19 16:13:32 -04001759 color_warning=$'\E'"[0;33m"
Jacky Cao89483b82015-05-15 22:12:53 +08001760 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001761 else
1762 color_failed=""
1763 color_success=""
1764 color_reset=""
1765 fi
Kousik Kumar09af2542021-08-19 16:13:32 -04001766
1767 if [[ "x${USE_RBE}" == "x" && $mins -gt 15 && "${ANDROID_BUILD_ENVIRONMENT_CONFIG}" == "googler" ]]; then
1768 echo
1769 echo "${color_warning}Start using RBE (http://go/build-fast) to get faster builds!${color_reset}"
1770 fi
1771
Ed Heylcc6be0a2014-06-18 14:55:58 -07001772 echo
Matt Alexanderd9c56562020-05-21 10:49:17 +00001773 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001774 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001775 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001776 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001777 fi
Matt Alexanderd9c56562020-05-21 10:49:17 +00001778 if [ $hours -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001779 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001780 elif [ $mins -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001781 printf "(%02g:%02g (mm:ss))" $mins $secs
Matt Alexanderd9c56562020-05-21 10:49:17 +00001782 elif [ $secs -gt 0 ] ; then
Ed Heylcc6be0a2014-06-18 14:55:58 -07001783 printf "(%s seconds)" $secs
1784 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001785 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001786 echo
1787 return $ret
1788}
1789
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001790function _trigger_build()
1791(
1792 local -r bc="$1"; shift
1793 if T="$(gettop)"; then
1794 _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
1795 else
Jingwen Chend728ee12021-05-18 06:02:53 +00001796 >&2 echo "Couldn't locate the top of the tree. Try setting TOP."
1797 return 1
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001798 fi
1799)
1800
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001801# Convenience entry point (like m) to use Bazel in AOSP.
Jingwen Chend728ee12021-05-18 06:02:53 +00001802function b()
1803(
1804 # Generate BUILD, bzl files into the synthetic Bazel workspace (out/soong/workspace).
Sam Delmerico9d67a902022-04-11 12:25:18 +00001805 _trigger_build "all-modules" bp2build USE_BAZEL_ANALYSIS= || return 1
Jingwen Chend728ee12021-05-18 06:02:53 +00001806 # Then, run Bazel using the synthetic workspace as the --package_path.
Sam Delmerico9d67a902022-04-11 12:25:18 +00001807 if [[ -z "$@" ]]; then
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001808 # If there are no args, show help.
Jingwen Chenbfa114d2021-06-17 05:42:43 +00001809 bazel help
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001810 else
1811 # Else, always run with the bp2build configuration, which sets Bazel's package path to the synthetic workspace.
Sam Delmerico9d67a902022-04-11 12:25:18 +00001812 bazel "$@" --config=bp2build
Jingwen Chen69f9ed12021-06-16 09:44:26 +00001813 fi
Jingwen Chend728ee12021-05-18 06:02:53 +00001814)
1815
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001816function m()
1817(
1818 _trigger_build "all-modules" "$@"
1819)
1820
1821function mm()
1822(
1823 _trigger_build "modules-in-a-dir-no-deps" "$@"
1824)
1825
1826function mmm()
1827(
1828 _trigger_build "modules-in-dirs-no-deps" "$@"
1829)
1830
1831function mma()
1832(
1833 _trigger_build "modules-in-a-dir" "$@"
1834)
1835
1836function mmma()
1837(
1838 _trigger_build "modules-in-dirs" "$@"
1839)
1840
Matt Alexanderd9c56562020-05-21 10:49:17 +00001841function make()
1842{
Dan Willemsene9842242017-07-28 13:00:13 -07001843 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001844}
1845
Matt Alexanderd9c56562020-05-21 10:49:17 +00001846function provision()
1847{
David Zeuthen1b126ff2015-09-30 17:10:48 -04001848 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1849 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1850 return 1
1851 fi
1852 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1853 echo "There is no provisioning script for the device." >&2
1854 return 1
1855 fi
1856
1857 # Check if user really wants to do this.
Matt Alexanderd9c56562020-05-21 10:49:17 +00001858 if [ "$1" = "--no-confirmation" ]; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001859 shift 1
1860 else
1861 echo "This action will reflash your device."
1862 echo ""
1863 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1864 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001865 echo -n "Are you sure you want to do this (yes/no)? "
1866 read
Matt Alexanderd9c56562020-05-21 10:49:17 +00001867 if [[ "${REPLY}" != "yes" ]] ; then
David Zeuthen1b126ff2015-09-30 17:10:48 -04001868 echo "Not taking any action. Exiting." >&2
1869 return 1
1870 fi
1871 fi
1872 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1873}
1874
Jim Tanga881a252018-06-19 16:34:41 +08001875# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001876function enable_zsh_completion() {
1877 # Don't override user's options if bash-style completion is already enabled.
1878 if ! declare -f complete >/dev/null; then
1879 autoload -U compinit && compinit
1880 autoload -U bashcompinit && bashcompinit
1881 fi
Jim Tanga881a252018-06-19 16:34:41 +08001882}
1883
1884function validate_current_shell() {
1885 local current_sh="$(ps -o command -p $$)"
1886 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001887 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001888 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001889 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001890 *zsh*)
1891 function check_type() { type "$1"; }
Matt Alexanderd9c56562020-05-21 10:49:17 +00001892 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001893 *)
Jim Tanga881a252018-06-19 16:34:41 +08001894 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 -07001895 ;;
1896 esac
Jim Tanga881a252018-06-19 16:34:41 +08001897}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001898
1899# Execute the contents of any vendorsetup.sh files we can find.
Dan Willemsend855a722019-02-12 15:52:36 -08001900# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
1901# load those.
1902#
1903# This allows loading only approved vendorsetup.sh files
Jim Tanga881a252018-06-19 16:34:41 +08001904function source_vendorsetup() {
Jim Tangc4dba1d2019-07-25 16:54:27 +08001905 unset VENDOR_PYTHONPATH
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001906 local T="$(gettop)"
Dan Willemsend855a722019-02-12 15:52:36 -08001907 allowed=
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001908 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 -08001909 if [ -n "$allowed" ]; then
1910 echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
1911 echo " $allowed"
1912 echo " $f"
1913 return
1914 fi
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001915 allowed="$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001916 done
1917
1918 allowed_files=
1919 [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
Jim Tanga881a252018-06-19 16:34:41 +08001920 for dir in device vendor product; do
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001921 for f in $(cd "$T" && test -d $dir && \
Jim Tanga881a252018-06-19 16:34:41 +08001922 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001923
1924 if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
Patrice Arrudaaa4b8242020-10-12 21:29:14 +00001925 echo "including $f"; . "$T/$f"
Dan Willemsend855a722019-02-12 15:52:36 -08001926 else
1927 echo "ignoring $f, not in $allowed"
1928 fi
Jim Tanga881a252018-06-19 16:34:41 +08001929 done
1930 done
1931}
Kenny Root52aa81c2011-07-15 11:07:06 -07001932
Dan Albertbab814f2020-08-26 15:34:53 -07001933function showcommands() {
1934 local T=$(gettop)
1935 if [[ -z "$TARGET_PRODUCT" ]]; then
1936 >&2 echo "TARGET_PRODUCT not set. Run lunch."
1937 return
1938 fi
1939 case $(uname -s) in
1940 Darwin)
1941 PREBUILT_NAME=darwin-x86
1942 ;;
1943 Linux)
1944 PREBUILT_NAME=linux-x86
1945 ;;
1946 *)
1947 >&2 echo Unknown host $(uname -s)
1948 return
1949 ;;
1950 esac
1951 if [[ -z "$OUT_DIR" ]]; then
1952 if [[ -z "$OUT_DIR_COMMON_BASE" ]]; then
1953 OUT_DIR=out
1954 else
1955 OUT_DIR=${OUT_DIR_COMMON_BASE}/${PWD##*/}
1956 fi
1957 fi
1958 if [[ "$1" == "--regenerate" ]]; then
1959 shift 1
1960 NINJA_ARGS="-t commands $@" m
1961 else
1962 (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \
1963 -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \
1964 -t commands "$@")
1965 fi
1966}
1967
Jim Tanga881a252018-06-19 16:34:41 +08001968validate_current_shell
1969source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001970addcompletions
Chirayu Desai798bc5e2013-03-19 17:50:37 +05301971
1972export ANDROID_BUILD_TOP=$(gettop)
Michael Bestasb744e742016-08-26 00:37:02 +03001973
1974. $ANDROID_BUILD_TOP/vendor/lineage/build/envsetup.sh