blob: 4730ca7aa487c67832b680faa0c7b69920cbd2fd [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.
11- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|arm64|x86_64|mips64] [eng|userdebug|user]
Anton Hanssonece9c482019-02-04 18:15:39 +000012- croot: Changes directory to the top of the tree, or a subdirectory thereof.
Steven Moreland62054a42018-12-06 10:11:40 -080013- m: Makes from the top of the tree.
Dan Willemsen67074fe2019-10-30 12:35:34 -070014- mm: Builds and installs all of the modules in the current directory, and their
15 dependencies.
16- mmm: Builds and installs all of the modules in the supplied directories, and their
17 dependencies.
Steven Moreland62054a42018-12-06 10:11:40 -080018 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Dan Willemsen67074fe2019-10-30 12:35:34 -070019- mma: Same as 'mm'
20- mmma: Same as 'mmm'
Steven Moreland62054a42018-12-06 10:11:40 -080021- provision: Flash device with all required partitions. Options will be passed on to fastboot.
22- cgrep: Greps on all local C/C++ files.
23- ggrep: Greps on all local Gradle files.
Orion Hodson831472d2019-10-25 11:35:15 +010024- gogrep: Greps on all local Go files.
Steven Moreland62054a42018-12-06 10:11:40 -080025- jgrep: Greps on all local Java files.
26- resgrep: Greps on all local res/*.xml files.
27- mangrep: Greps on all local AndroidManifest.xml files.
Jaewoong Jung892d0fe2019-05-04 10:06:28 -070028- mgrep: Greps on all local Makefiles and *.bp files.
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -060029- owngrep: Greps on all local OWNERS files.
Steven Moreland62054a42018-12-06 10:11:40 -080030- sepgrep: Greps on all local sepolicy files.
31- sgrep: Greps on all local source files.
32- godir: Go to the directory containing a file.
33- allmod: List all modules.
34- gomod: Go to the directory containing a module.
Rett Berg78d1c932019-01-24 14:34:23 -080035- pathmod: Get the directory containing a module.
Steven Moreland62054a42018-12-06 10:11:40 -080036- refreshmod: Refresh list of modules for allmod/gomod.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070037
Michael Bestas83c04522016-08-26 00:37:02 +030038EOF
39
40 __print_bliss_functions_help
41
42cat <<EOF
43
Roland Levillain39341922015-10-20 12:48:19 +010044Environment options:
Steven Moreland115d1f52019-09-26 16:30:28 -070045- SANITIZE_HOST: Set to 'address' to use ASAN for all host modules.
Sasha Smundak9f27cc02019-01-31 13:25:31 -080046- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
Dan Albert4ae5d4b2014-10-31 16:23:08 -070047
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070048Look at the source to view more functions. The complete list is:
49EOF
Christopher Ferris55257d22017-03-23 11:08:58 -070050 local T=$(gettop)
51 local A=""
52 local i
Michael Bestas83c04522016-08-26 00:37:02 +030053 for i in `cat $T/build/envsetup.sh $T/vendor/bliss/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070054 A="$A $i"
55 done
56 echo $A
57}
58
Ying Wang08800fd2016-03-03 20:57:21 -080059# Get all the build variables needed by this script in a single call to the build system.
60function build_build_var_cache()
61{
Christopher Ferris55257d22017-03-23 11:08:58 -070062 local T=$(gettop)
Ying Wang08800fd2016-03-03 20:57:21 -080063 # Grep out the variable names from the script.
Michael Bestas83c04522016-08-26 00:37:02 +030064 cached_vars=(`cat $T/build/envsetup.sh $T/vendor/bliss/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
65 cached_abs_vars=(`cat $T/build/envsetup.sh $T/vendor/bliss/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
Ying Wang08800fd2016-03-03 20:57:21 -080066 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
Steven Moreland05402962018-01-05 12:13:11 -080067 build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
Jim Tanga881a252018-06-19 16:34:41 +080068 --vars="${cached_vars[*]}" \
69 --abs-vars="${cached_abs_vars[*]}" \
Dan Willemsenaf88c412017-07-14 11:29:44 -070070 --var-prefix=var_cache_ \
71 --abs-var-prefix=abs_var_cache_`
Ying Wang08800fd2016-03-03 20:57:21 -080072 local ret=$?
73 if [ $ret -ne 0 ]
74 then
75 unset build_dicts_script
76 return $ret
77 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -070078 # Execute the script to store the "<val>=<value>" pairs as shell variables.
Ying Wang08800fd2016-03-03 20:57:21 -080079 eval "$build_dicts_script"
Ying Wang08800fd2016-03-03 20:57:21 -080080 ret=$?
Ying Wangf0cb3972016-03-04 13:56:23 -080081 unset build_dicts_script
Ying Wang08800fd2016-03-03 20:57:21 -080082 if [ $ret -ne 0 ]
83 then
84 return $ret
85 fi
86 BUILD_VAR_CACHE_READY="true"
87}
88
Ying Wangf0cb3972016-03-04 13:56:23 -080089# Delete the build var cache, so that we can still call into the build system
Ying Wang08800fd2016-03-03 20:57:21 -080090# to get build variables not listed in this script.
91function destroy_build_var_cache()
92{
93 unset BUILD_VAR_CACHE_READY
Christopher Ferris55257d22017-03-23 11:08:58 -070094 local v
Ying Wang08800fd2016-03-03 20:57:21 -080095 for v in $cached_vars; do
96 unset var_cache_$v
97 done
98 unset cached_vars
99 for v in $cached_abs_vars; do
100 unset abs_var_cache_$v
101 done
102 unset cached_abs_vars
103}
104
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700105# Get the value of a build variable as an absolute path.
106function get_abs_build_var()
107{
Ying Wang08800fd2016-03-03 20:57:21 -0800108 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
109 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800110 eval "echo \"\${abs_var_cache_$1}\""
Ying Wang08800fd2016-03-03 20:57:21 -0800111 return
112 fi
113
Christopher Ferris55257d22017-03-23 11:08:58 -0700114 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700115 if [ ! "$T" ]; then
116 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
117 return
118 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700119 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700120}
121
122# Get the exact value of a build variable.
123function get_build_var()
124{
Ying Wang08800fd2016-03-03 20:57:21 -0800125 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
126 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800127 eval "echo \"\${var_cache_$1}\""
Ying Wang08800fd2016-03-03 20:57:21 -0800128 return
129 fi
130
Christopher Ferris55257d22017-03-23 11:08:58 -0700131 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700132 if [ ! "$T" ]; then
133 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
134 return
135 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700136 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800137}
138
139# check to see if the supplied product is one we can build
140function check_product()
141{
Christopher Ferris55257d22017-03-23 11:08:58 -0700142 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800143 if [ ! "$T" ]; then
144 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
145 return
146 fi
Luca Stefania269e342017-08-17 21:21:23 +0200147 if (echo -n $1 | grep -q -e "^bliss_") ; then
148 BLISS_BUILD=$(echo -n $1 | sed -e 's/^bliss_//g')
149 else
150 BLISS_BUILD=
151 fi
152 export BLISS_BUILD
153
Jeff Browne33ba4c2011-07-11 22:11:46 -0700154 TARGET_PRODUCT=$1 \
155 TARGET_BUILD_VARIANT= \
156 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700157 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800158 get_build_var TARGET_DEVICE > /dev/null
159 # hide successful answers, but allow the errors to show
160}
161
162VARIANT_CHOICES=(user userdebug eng)
163
164# check to see if the supplied variant is valid
165function check_variant()
166{
Christopher Ferris55257d22017-03-23 11:08:58 -0700167 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800168 for v in ${VARIANT_CHOICES[@]}
169 do
170 if [ "$v" = "$1" ]
171 then
172 return 0
173 fi
174 done
175 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700176}
177
178function setpaths()
179{
Christopher Ferris55257d22017-03-23 11:08:58 -0700180 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700181 if [ ! "$T" ]; then
182 echo "Couldn't locate the top of the tree. Try setting TOP."
183 return
184 fi
185
186 ##################################################################
187 # #
188 # Read me before you modify this code #
189 # #
190 # This function sets ANDROID_BUILD_PATHS to what it is adding #
191 # to PATH, and the next time it is run, it removes that from #
192 # PATH. This is required so lunch can be run more than once #
193 # and still have working paths. #
194 # #
195 ##################################################################
196
Raphael Mollc639c782011-06-20 17:25:01 -0700197 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
198 # due to "C:\Program Files" being in the path.
199
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700200 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700201 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700202 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
203 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700204 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700205 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800206 # strip leading ':', if any
207 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500208 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700209
210 # and in with the new
Christopher Ferris55257d22017-03-23 11:08:58 -0700211 local prebuiltdir=$(getprebuilt)
212 local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700213
Ben Cheng8bc4c432012-11-16 13:29:13 -0800214 # defined in core/config.mk
Christopher Ferris55257d22017-03-23 11:08:58 -0700215 local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
216 local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800217 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800218
Raphael Mollc639c782011-06-20 17:25:01 -0700219 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800220 export ANDROID_TOOLCHAIN=
221 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200222 local ARCH=$(get_build_var TARGET_ARCH)
Christopher Ferris55257d22017-03-23 11:08:58 -0700223 local toolchaindir toolchaindir2=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200224 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400225 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700226 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400227 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
228 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800229 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200230 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800231 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700232 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700233 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700234 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000235 ;;
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
Jeff Vander Stoep5f50f052015-06-12 09:56:39 -0700249 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
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
261 if [ -n "$ANDROID_TOOLCHAIN_2ND_ARCH" ]; then
262 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH
263 fi
Yi Kongdfd00b12019-05-21 16:00:04 -0700264 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS
265
266 # Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS.
267 local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
268 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200269
Stephen Hinesaa8d72c2020-02-04 09:15:18 -0800270 # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds.
271 export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer
272
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200273 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
274 # to ensure that the corresponding 'emulator' binaries are used.
275 case $(uname -s) in
276 Darwin)
277 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
278 ;;
279 Linux)
280 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
281 ;;
282 *)
283 ANDROID_EMULATOR_PREBUILTS=
284 ;;
285 esac
286 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Yi Kongdfd00b12019-05-21 16:00:04 -0700287 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200288 export ANDROID_EMULATOR_PREBUILTS
289 fi
290
Jim Tangb3fda302018-12-22 10:24:55 +0800291 # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
292 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
Ryan Prichard8426a192019-07-15 18:05:29 -0700293 local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch"
294 local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch"
295 local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch"
296 export ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH:
Jim Tangb3fda302018-12-22 10:24:55 +0800297
Ryan Prichard8426a192019-07-15 18:05:29 -0700298 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800299
300 # out with the duplicate old
301 if [ -n $ANDROID_PYTHONPATH ]; then
302 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
303 fi
304 # and in with the new
305 export ANDROID_PYTHONPATH=$T/development/python-packages:
Jim Tangc4dba1d2019-07-25 16:54:27 +0800306 if [ -n $VENDOR_PYTHONPATH ]; then
307 ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
308 fi
Jim Tang22f4c322018-12-17 15:21:53 +0800309 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800310
Colin Crosse97e6932017-06-30 16:01:45 -0700311 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
312 export JAVA_HOME=$ANDROID_JAVA_HOME
313 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
314 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
315 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500316
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800317 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700318 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
319 export OUT=$ANDROID_PRODUCT_OUT
320
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700321 unset ANDROID_HOST_OUT
322 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
323
Simran Basidd050ed2017-02-13 13:46:48 -0800324 unset ANDROID_HOST_OUT_TESTCASES
325 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
326
327 unset ANDROID_TARGET_OUT_TESTCASES
328 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
329
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800330 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700331 # TODO: fix the path
332 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
333}
334
335function printconfig()
336{
Christopher Ferris55257d22017-03-23 11:08:58 -0700337 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800338 if [ ! "$T" ]; then
339 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
340 return
341 fi
342 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700343}
344
345function set_stuff_for_environment()
346{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800347 setpaths
348 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700349
Ben Chengaac3f812013-08-13 14:38:15 -0700350 # With this environment variable new GCC can apply colors to warnings/errors
351 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 -0700352}
353
354function set_sequence_number()
355{
Colin Cross88737132017-03-21 17:41:03 -0700356 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700357}
358
Makoto Onukida971062018-06-18 10:15:19 -0700359# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
360function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800361 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700362 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800363 *:"$cmd":*)
364 return 1
365 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700366 esac
367 return 0
368}
369
Kenny Root52aa81c2011-07-15 11:07:06 -0700370function addcompletions()
371{
372 local T dir f
373
Jim Tanga881a252018-06-19 16:34:41 +0800374 # Keep us from trying to run in something that's neither bash nor zsh.
375 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700376 return
377 fi
378
379 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800380 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700381 return
382 fi
383
Jim Tanga881a252018-06-19 16:34:41 +0800384 local completion_files=(
385 system/core/adb/adb.bash
386 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800387 tools/asuite/asuite.sh
Jim Tanga881a252018-06-19 16:34:41 +0800388 )
Makoto Onukida971062018-06-18 10:15:19 -0700389 # Completion can be disabled selectively to allow users to use non-standard completion.
390 # e.g.
391 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
392 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800393 for f in ${completion_files[*]}; do
394 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700395 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700396 fi
397 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700398
Makoto Onukida971062018-06-18 10:15:19 -0700399 if should_add_completion bit ; then
400 complete -C "bit --tab" bit
401 fi
Anton Hanssonece9c482019-02-04 18:15:39 +0000402 if [ -z "$ZSH_VERSION" ]; then
403 # Doesn't work in zsh.
404 complete -o nospace -F _croot croot
405 fi
Jim Tanga881a252018-06-19 16:34:41 +0800406 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800407
dimitry73b84812018-12-11 18:06:00 +0100408 complete -F _complete_android_module_names gomod
409 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700410}
411
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700412function choosetype()
413{
414 echo "Build type choices are:"
415 echo " 1. release"
416 echo " 2. debug"
417 echo
418
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800419 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700420 DEFAULT_NUM=1
421 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700422
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800423 export TARGET_BUILD_TYPE=
424 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700425 while [ -z $TARGET_BUILD_TYPE ]
426 do
427 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800428 if [ -z "$1" ] ; then
429 read ANSWER
430 else
431 echo $1
432 ANSWER=$1
433 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700434 case $ANSWER in
435 "")
436 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
437 ;;
438 1)
439 export TARGET_BUILD_TYPE=release
440 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800441 release)
442 export TARGET_BUILD_TYPE=release
443 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444 2)
445 export TARGET_BUILD_TYPE=debug
446 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800447 debug)
448 export TARGET_BUILD_TYPE=debug
449 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700450 *)
451 echo
452 echo "I didn't understand your response. Please try again."
453 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700454 ;;
455 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800456 if [ -n "$1" ] ; then
457 break
458 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700459 done
460
Ying Wang08800fd2016-03-03 20:57:21 -0800461 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700462 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800463 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700464}
465
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800466#
467# This function isn't really right: It chooses a TARGET_PRODUCT
468# based on the list of boards. Usually, that gets you something
469# that kinda works with a generic product, but really, you should
470# pick a product by name.
471#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700472function chooseproduct()
473{
Christopher Ferris55257d22017-03-23 11:08:58 -0700474 local default_value
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475 if [ "x$TARGET_PRODUCT" != x ] ; then
476 default_value=$TARGET_PRODUCT
477 else
Ying Wang0a76df52015-06-08 11:57:26 -0700478 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700479 fi
480
Ying Wang08800fd2016-03-03 20:57:21 -0800481 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482 export TARGET_PRODUCT=
483 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700484 while [ -z "$TARGET_PRODUCT" ]
485 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700486 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800487 if [ -z "$1" ] ; then
488 read ANSWER
489 else
490 echo $1
491 ANSWER=$1
492 fi
493
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700494 if [ -z "$ANSWER" ] ; then
495 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800496 else
497 if check_product $ANSWER
498 then
499 export TARGET_PRODUCT=$ANSWER
500 else
501 echo "** Not a valid product: $ANSWER"
502 fi
503 fi
504 if [ -n "$1" ] ; then
505 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506 fi
507 done
508
Ying Wang08800fd2016-03-03 20:57:21 -0800509 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700510 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800511 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700512}
513
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800514function choosevariant()
515{
516 echo "Variant choices are:"
517 local index=1
518 local v
519 for v in ${VARIANT_CHOICES[@]}
520 do
521 # The product name is the name of the directory containing
522 # the makefile we found, above.
523 echo " $index. $v"
524 index=$(($index+1))
525 done
526
527 local default_value=eng
528 local ANSWER
529
530 export TARGET_BUILD_VARIANT=
531 while [ -z "$TARGET_BUILD_VARIANT" ]
532 do
533 echo -n "Which would you like? [$default_value] "
534 if [ -z "$1" ] ; then
535 read ANSWER
536 else
537 echo $1
538 ANSWER=$1
539 fi
540
541 if [ -z "$ANSWER" ] ; then
542 export TARGET_BUILD_VARIANT=$default_value
543 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
544 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Guillaume Chelfice000fd2019-10-03 12:02:46 +0200545 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800546 fi
547 else
548 if check_variant $ANSWER
549 then
550 export TARGET_BUILD_VARIANT=$ANSWER
551 else
552 echo "** Not a valid variant: $ANSWER"
553 fi
554 fi
555 if [ -n "$1" ] ; then
556 break
557 fi
558 done
559}
560
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700561function choosecombo()
562{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700563 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700564
565 echo
566 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700567 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700568
569 echo
570 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700571 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800572
573 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800574 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700575 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800576 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800577 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700578}
579
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800580function add_lunch_combo()
581{
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800582 if [ -n "$ZSH_VERSION" ]; then
583 echo -n "${funcfiletrace[1]}: "
584 else
585 echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
586 fi
587 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 -0800588}
589
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590function print_lunch_menu()
591{
592 local uname=$(uname)
Colin Crosscb8337d2019-09-23 12:52:32 -0700593 local choices=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700594 echo
595 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596 echo
597 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598
599 local i=1
600 local choice
Dan Willemsen91763e92019-10-03 15:13:12 -0700601 for choice in $(echo $choices)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800602 do
603 echo " $i. $choice"
604 i=$(($i+1))
605 done
606
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700607 echo
608}
609
610function lunch()
611{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800612 local answer
613
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700614 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800615 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700616 else
617 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700618 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800619 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700620 fi
621
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800622 local selection=
623
624 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700625 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700626 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800627 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
628 then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800629 local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700630 if [ $answer -le ${#choices[@]} ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800631 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800632 # array in zsh starts from 1 instead of 0.
633 if [ -n "$ZSH_VERSION" ]
634 then
635 selection=${choices[$(($answer))]}
636 else
637 selection=${choices[$(($answer-1))]}
638 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800639 fi
Colin Cross88737132017-03-21 17:41:03 -0700640 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800641 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700642 fi
643
Joe Onoratoda12daf2010-06-09 18:18:31 -0700644 export TARGET_BUILD_APPS=
645
Colin Cross88737132017-03-21 17:41:03 -0700646 local product variant_and_version variant version
647
648 product=${selection%%-*} # Trim everything after first dash
649 variant_and_version=${selection#*-} # Trim everything up to first dash
650 if [ "$variant_and_version" != "$selection" ]; then
651 variant=${variant_and_version%%-*}
652 if [ "$variant" != "$variant_and_version" ]; then
653 version=${variant_and_version#*-}
654 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700655 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800656
Colin Cross88737132017-03-21 17:41:03 -0700657 if [ -z "$product" ]
Ying Wang08800fd2016-03-03 20:57:21 -0800658 then
659 echo
Colin Cross88737132017-03-21 17:41:03 -0700660 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700661 return 1
662 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800663
Luca Stefania269e342017-08-17 21:21:23 +0200664 check_product $product
Koushik Duttab897c5d2017-08-23 16:13:18 +0200665 if [ $? -ne 0 ]
666 then
667 # if we can't find a product, try to grab it off the BlissRoms-Devices GitHub
668 T=$(gettop)
669 cd $T > /dev/null
670 vendor/bliss/build/tools/roomservice.py $product
671 cd - > /dev/null
672 check_product $product
673 else
674 T=$(gettop)
675 cd $T > /dev/null
676 vendor/bliss/build/tools/roomservice.py $product true
677 cd - > /dev/null
678 fi
Luca Stefania269e342017-08-17 21:21:23 +0200679
Colin Cross88737132017-03-21 17:41:03 -0700680 TARGET_PRODUCT=$product \
681 TARGET_BUILD_VARIANT=$variant \
682 TARGET_PLATFORM_VERSION=$version \
683 build_build_var_cache
684 if [ $? -ne 0 ]
685 then
Koushik Duttab897c5d2017-08-23 16:13:18 +0200686 echo
687 echo "** Don't have a product spec for: '$product'"
688 echo "** Do you have the right repo manifest?"
689 product=
690 fi
691
692 if [ -z "$product" -o -z "$variant" ]
693 then
694 echo
Colin Cross88737132017-03-21 17:41:03 -0700695 return 1
696 fi
697
698 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
699 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700700 if [ -n "$version" ]; then
701 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
702 else
703 unset TARGET_PLATFORM_VERSION
704 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700705 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700706
707 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800708
Luca Stefania269e342017-08-17 21:21:23 +0200709 fixup_common_out_dir
710
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700711 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800712 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800713 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700714}
715
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700716unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700717# Tab completion for lunch.
718function _lunch()
719{
720 local cur prev opts
721 COMPREPLY=()
722 cur="${COMP_WORDS[COMP_CWORD]}"
723 prev="${COMP_WORDS[COMP_CWORD-1]}"
724
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700725 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
Dan Willemsen5436c7e2019-02-11 21:31:47 -0800726 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700727 fi
728
729 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700730 return 0
731}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700732
Joe Onoratoda12daf2010-06-09 18:18:31 -0700733# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700734# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700735function tapas()
736{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700737 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Dan Willemsendd3a2732018-01-08 15:26:16 -0800738 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700739 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700740 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Dan Willemsendd3a2732018-01-08 15:26:16 -0800741 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700742
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700743 if [ "$showHelp" != "" ]; then
744 $(gettop)/build/make/tapasHelp.sh
745 return
746 fi
747
Ying Wang67f02922012-08-22 10:25:20 -0700748 if [ $(echo $arch | wc -w) -gt 1 ]; then
749 echo "tapas: Error: Multiple build archs supplied: $arch"
750 return
751 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700752 if [ $(echo $variant | wc -w) -gt 1 ]; then
753 echo "tapas: Error: Multiple build variants supplied: $variant"
754 return
755 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700756 if [ $(echo $density | wc -w) -gt 1 ]; then
757 echo "tapas: Error: Multiple densities supplied: $density"
758 return
759 fi
Ying Wang67f02922012-08-22 10:25:20 -0700760
Ying Wang0a76df52015-06-08 11:57:26 -0700761 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700762 case $arch in
Ying Wang0a76df52015-06-08 11:57:26 -0700763 x86) product=aosp_x86;;
764 mips) product=aosp_mips;;
Ying Wangb541ab62014-05-29 17:57:40 -0700765 arm64) product=aosp_arm64;;
766 x86_64) product=aosp_x86_64;;
767 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700768 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700769 if [ -z "$variant" ]; then
770 variant=eng
771 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700772 if [ -z "$apps" ]; then
773 apps=all
774 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600775 if [ -z "$density" ]; then
776 density=alldpi
777 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700778
Ying Wang67f02922012-08-22 10:25:20 -0700779 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700780 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700781 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700782 export TARGET_BUILD_TYPE=release
783 export TARGET_BUILD_APPS=$apps
784
Ying Wang08800fd2016-03-03 20:57:21 -0800785 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700786 set_stuff_for_environment
787 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800788 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700789}
790
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791function gettop
792{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700793 local TOPFILE=build/make/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700794 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700795 # The following circumlocution ensures we remove symlinks from TOP.
796 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797 else
798 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800799 # The following circumlocution (repeated below as well) ensures
800 # that we record the true directory name and not one that is
801 # faked up with symlink names.
802 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700803 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800804 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700805 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700806 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800807 \cd ..
synergyb112a402013-07-05 19:47:47 -0700808 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700809 done
Ying Wang9cd17642012-12-13 10:52:07 -0800810 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700811 if [ -f "$T/$TOPFILE" ]; then
812 echo $T
813 fi
814 fi
815 fi
816}
817
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700818function croot()
819{
Christopher Ferris55257d22017-03-23 11:08:58 -0700820 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700821 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700822 if [ "$1" ]; then
823 \cd $(gettop)/$1
824 else
825 \cd $(gettop)
826 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700827 else
828 echo "Couldn't locate the top of the tree. Try setting TOP."
829 fi
830}
831
Anton Hanssonece9c482019-02-04 18:15:39 +0000832function _croot()
833{
834 local T=$(gettop)
835 if [ "$T" ]; then
836 local cur="${COMP_WORDS[COMP_CWORD]}"
837 k=0
838 for c in $(compgen -d ${T}/${cur}); do
839 COMPREPLY[k++]=${c#${T}/}/
840 done
841 fi
842}
843
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700844function cproj()
845{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700846 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700847 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700848 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700849 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
850 T=$PWD
851 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800852 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700853 return
854 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800855 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700856 done
Ying Wang9cd17642012-12-13 10:52:07 -0800857 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700858 echo "can't find Android.mk"
859}
860
Daniel Sandler47e0a882013-07-30 13:23:52 -0400861# simplified version of ps; output in the form
862# <pid> <procname>
863function qpid() {
864 local prepend=''
865 local append=''
866 if [ "$1" = "--exact" ]; then
867 prepend=' '
868 append='$'
869 shift
870 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -0800871 echo "usage: qpid [[--exact] <process name|pid>"
872 return 255
873 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -0400874
875 local EXE="$1"
876 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -0800877 qpid | \grep "$prepend$EXE$append"
878 else
879 adb shell ps \
880 | tr -d '\r' \
881 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
882 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -0400883}
884
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800885# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700886# that has the core-file-size limit set correctly
887#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800888# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700889# if its core-file-size limit is not set already.
890# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
891
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800892function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700893{
Ying Wang08800fd2016-03-03 20:57:21 -0800894 echo "Getting root...";
895 adb root;
896 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700897
Ying Wang08800fd2016-03-03 20:57:21 -0800898 echo "Remounting root partition read-write...";
899 adb shell mount -w -o remount -t rootfs rootfs;
900 sleep 1;
901 adb wait-for-device;
902 adb shell mkdir -p /cores;
903 adb shell mount -t tmpfs tmpfs /cores;
904 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700905
Ying Wang08800fd2016-03-03 20:57:21 -0800906 echo "Granting SELinux permission to dump in /cores...";
907 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700908
Ying Wang08800fd2016-03-03 20:57:21 -0800909 echo "Set core pattern.";
910 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700911
Ying Wang08800fd2016-03-03 20:57:21 -0800912 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700913}
914
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800915# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700916# $1 = PID of process (e.g., $(pid mediaserver))
917#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800918# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700919# dump to actually be generated.
920
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800921function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700922{
Ying Wang08800fd2016-03-03 20:57:21 -0800923 local PID=$1;
924 if [ -z "$PID" ]; then
925 printf "Expecting a PID!\n";
926 return;
927 fi;
928 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -0800929 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700930}
931
932# core - send SIGV and pull the core for process
933# $1 = PID of process (e.g., $(pid mediaserver))
934#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800935# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700936# enabled globally.
937
938function core()
939{
Ying Wang08800fd2016-03-03 20:57:21 -0800940 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700941
Ying Wang08800fd2016-03-03 20:57:21 -0800942 if [ -z "$PID" ]; then
943 printf "Expecting a PID!\n";
944 return;
945 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700946
Ying Wang08800fd2016-03-03 20:57:21 -0800947 local CORENAME=core.$PID;
948 local COREPATH=/cores/$CORENAME;
949 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700950
Ying Wang08800fd2016-03-03 20:57:21 -0800951 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700952
Ying Wang08800fd2016-03-03 20:57:21 -0800953 local done=0;
954 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
955 printf "\tSending SIG%s to %d...\n" $SIG $PID;
956 adb shell kill -$SIG $PID;
957 sleep 1;
958 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700959
Ying Wang08800fd2016-03-03 20:57:21 -0800960 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
961 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700962}
963
Christopher Tate744ee802009-11-12 15:33:08 -0800964# systemstack - dump the current stack trace of all threads in the system process
965# to the usual ANR traces file
966function systemstack()
967{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800968 stacks system_server
969}
970
Michael Wrightaeed7212014-06-19 19:58:12 -0700971# Read the ELF header from /proc/$PID/exe to determine if the process is
972# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -0800973function is64bit()
974{
975 local PID="$1"
976 if [ "$PID" ] ; then
Elliott Hughesd3e47252018-11-15 16:32:14 -0800977 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800978 echo "64"
979 else
980 echo ""
981 fi
982 else
983 echo ""
984 fi
985}
986
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700987case `uname -s` in
988 Darwin)
989 function sgrep()
990 {
Aurelio Jargas67edd152018-11-06 17:25:11 +0100991 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|hpp|S|java|xml|sh|mk|aidl|vts)' \
Mike Frysinger5e479732015-09-22 18:13:48 -0400992 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700993 }
994
995 ;;
996 *)
997 function sgrep()
998 {
Aurelio Jargas67edd152018-11-06 17:25:11 +0100999 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|hpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001000 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001001 }
1002 ;;
1003esac
1004
Raghu Gandham8da43102012-07-25 19:57:22 -07001005function gettargetarch
1006{
1007 get_build_var TARGET_ARCH
1008}
1009
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001010function ggrep()
1011{
Mike Frysinger5e479732015-09-22 18:13:48 -04001012 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1013 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001014}
1015
Orion Hodson831472d2019-10-25 11:35:15 +01001016function gogrep()
1017{
1018 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
1019 -exec grep --color -n "$@" {} +
1020}
1021
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001022function jgrep()
1023{
Mike Frysinger5e479732015-09-22 18:13:48 -04001024 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1025 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001026}
1027
1028function cgrep()
1029{
Mike Frysinger5e479732015-09-22 18:13:48 -04001030 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' \) \
1031 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001032}
1033
1034function resgrep()
1035{
Christopher Ferris55257d22017-03-23 11:08:58 -07001036 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001037 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1038 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1039 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001040}
1041
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001042function mangrep()
1043{
Mike Frysinger5e479732015-09-22 18:13:48 -04001044 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1045 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001046}
1047
Jeff Sharkeyf17cddf2019-08-21 12:51:26 -06001048function owngrep()
1049{
1050 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
1051 -exec grep --color -n "$@" {} +
1052}
1053
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001054function sepgrep()
1055{
Mike Frysinger5e479732015-09-22 18:13:48 -04001056 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1057 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001058}
1059
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001060function rcgrep()
1061{
Mike Frysinger5e479732015-09-22 18:13:48 -04001062 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1063 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001064}
1065
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001066case `uname -s` in
1067 Darwin)
1068 function mgrep()
1069 {
Orion Hodson831472d2019-10-25 11:35:15 +01001070 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 -04001071 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001072 }
1073
1074 function treegrep()
1075 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001076 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|hpp|S|java|xml)' \
Mike Frysinger5e479732015-09-22 18:13:48 -04001077 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001078 }
1079
1080 ;;
1081 *)
1082 function mgrep()
1083 {
Orion Hodson831472d2019-10-25 11:35:15 +01001084 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 -04001085 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001086 }
1087
1088 function treegrep()
1089 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001090 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|hpp|S|java|xml)' -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001091 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001092 }
1093
1094 ;;
1095esac
1096
1097function getprebuilt
1098{
1099 get_abs_build_var ANDROID_PREBUILTS
1100}
1101
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001102function tracedmdump()
1103{
Christopher Ferris55257d22017-03-23 11:08:58 -07001104 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001105 if [ ! "$T" ]; then
1106 echo "Couldn't locate the top of the tree. Try setting TOP."
1107 return
1108 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001109 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001110 local arch=$(gettargetarch)
1111 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001112
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001113 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001114 if [ ! "$TRACE" ] ; then
1115 echo "usage: tracedmdump tracename"
1116 return
1117 fi
1118
Jack Veenstra60116fc2009-04-09 18:12:34 -07001119 if [ ! -r "$KERNEL" ] ; then
1120 echo "Error: cannot find kernel: '$KERNEL'"
1121 return
1122 fi
1123
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001124 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001125 if [ "$BASETRACE" = "$TRACE" ] ; then
1126 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1127 fi
1128
1129 echo "post-processing traces..."
1130 rm -f $TRACE/qtrace.dexlist
1131 post_trace $TRACE
1132 if [ $? -ne 0 ]; then
1133 echo "***"
1134 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1135 echo "***"
1136 return
1137 fi
1138 echo "generating dexlist output..."
1139 /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
1140 echo "generating dmtrace data..."
1141 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1142 echo "generating html file..."
1143 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1144 echo "done, see $TRACE/dmtrace.html for details"
1145 echo "or run:"
1146 echo " traceview $TRACE/dmtrace"
1147}
1148
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001149# communicate with a running device or emulator, set up necessary state,
1150# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001151function runhat()
1152{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001153 # process standard adb options
1154 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001155 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001156 adbTarget=$1
1157 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001158 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001159 adbTarget="$1 $2"
1160 shift 2
1161 fi
1162 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001163 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001164
1165 # runhat options
1166 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001167
1168 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001169 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001170 return
1171 fi
1172
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001173 # confirm hat is available
1174 if [ -z $(which hat) ]; then
1175 echo "hat is not available in this configuration."
1176 return
1177 fi
1178
Andy McFaddenb6289852010-07-12 08:00:19 -07001179 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001180 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001181 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001182 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001183 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001184 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001185 echo -n "> "
1186 read
1187
The Android Open Source Project88b60792009-03-03 19:28:42 -08001188 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001189
The Android Open Source Project88b60792009-03-03 19:28:42 -08001190 echo "Retrieving file $devFile..."
1191 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001192
The Android Open Source Project88b60792009-03-03 19:28:42 -08001193 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001194
The Android Open Source Project88b60792009-03-03 19:28:42 -08001195 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001196 echo "View the output by pointing your browser at http://localhost:7000/"
1197 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001198 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001199}
1200
1201function getbugreports()
1202{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001203 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001204
1205 if [ ! "$reports" ]; then
1206 echo "Could not locate any bugreports."
1207 return
1208 fi
1209
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001210 local report
1211 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001212 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001213 echo "/sdcard/bugreports/${report}"
1214 adb pull /sdcard/bugreports/${report} ${report}
1215 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001216 done
1217}
1218
Victoria Lease1b296b42012-08-21 15:44:06 -07001219function getsdcardpath()
1220{
1221 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1222}
1223
1224function getscreenshotpath()
1225{
1226 echo "$(getsdcardpath)/Pictures/Screenshots"
1227}
1228
1229function getlastscreenshot()
1230{
1231 local screenshot_path=$(getscreenshotpath)
1232 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1233 if [ "$screenshot" = "" ]; then
1234 echo "No screenshots found."
1235 return
1236 fi
1237 echo "${screenshot}"
1238 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1239}
1240
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001241function startviewserver()
1242{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001243 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001244 if [ $# -gt 0 ]; then
1245 port=$1
1246 fi
1247 adb shell service call window 1 i32 $port
1248}
1249
1250function stopviewserver()
1251{
1252 adb shell service call window 2
1253}
1254
1255function isviewserverstarted()
1256{
1257 adb shell service call window 3
1258}
1259
Romain Guyb84049a2010-10-04 16:56:11 -07001260function key_home()
1261{
1262 adb shell input keyevent 3
1263}
1264
1265function key_back()
1266{
1267 adb shell input keyevent 4
1268}
1269
1270function key_menu()
1271{
1272 adb shell input keyevent 82
1273}
1274
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001275function smoketest()
1276{
1277 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1278 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1279 return
1280 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001281 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001282 if [ ! "$T" ]; then
1283 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1284 return
1285 fi
1286
Ying Wang9cd17642012-12-13 10:52:07 -08001287 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001288 adb uninstall com.android.smoketest > /dev/null &&
1289 adb uninstall com.android.smoketest.tests > /dev/null &&
1290 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1291 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1292 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1293}
1294
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001295# simple shortcut to the runtest command
1296function runtest()
1297{
Christopher Ferris55257d22017-03-23 11:08:58 -07001298 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001299 if [ ! "$T" ]; then
1300 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1301 return
1302 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001303 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001304}
1305
The Android Open Source Project88b60792009-03-03 19:28:42 -08001306function godir () {
1307 if [[ -z "$1" ]]; then
1308 echo "Usage: godir <regex>"
1309 return
1310 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001311 local T=$(gettop)
1312 local FILELIST
Brian Carlstromf2257422015-09-30 20:28:54 -07001313 if [ ! "$OUT_DIR" = "" ]; then
1314 mkdir -p $OUT_DIR
1315 FILELIST=$OUT_DIR/filelist
1316 else
1317 FILELIST=$T/filelist
1318 fi
1319 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001320 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001321 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001322 echo " Done"
1323 echo ""
1324 fi
1325 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001326 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001327 if [[ ${#lines[@]} = 0 ]]; then
1328 echo "Not found"
1329 return
1330 fi
1331 local pathname
1332 local choice
1333 if [[ ${#lines[@]} > 1 ]]; then
1334 while [[ -z "$pathname" ]]; do
1335 local index=1
1336 local line
1337 for line in ${lines[@]}; do
1338 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001339 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001340 done
1341 echo
1342 echo -n "Select one: "
1343 unset choice
1344 read choice
1345 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1346 echo "Invalid choice"
1347 continue
1348 fi
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001349 pathname=${lines[@]:$(($choice-1)):1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001350 done
1351 else
Guillaume Chelfice000fd2019-10-03 12:02:46 +02001352 pathname=${lines[@]:0:1}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001353 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001354 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001355}
1356
Steven Moreland62054a42018-12-06 10:11:40 -08001357# Update module-info.json in out.
1358function refreshmod() {
1359 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1360 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1361 return 1
1362 fi
1363
1364 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1365
1366 # for the output of the next command
1367 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1368
1369 # Note, can't use absolute path because of the way make works.
1370 m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \
1371 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1372}
1373
1374# List all modules for the current device, as cached in module-info.json. If any build change is
1375# made and it should be reflected in the output, you should run 'refreshmod' first.
1376function allmod() {
1377 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1378 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1379 return 1
1380 fi
1381
1382 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1383 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1384 refreshmod || return 1
1385 fi
1386
LuK1337b6a78192020-01-12 03:12:17 +01001387 python -c "import json; print('\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys())))"
Steven Moreland62054a42018-12-06 10:11:40 -08001388}
1389
Rett Berg78d1c932019-01-24 14:34:23 -08001390# Get the path of a specific module in the android tree, as cached in module-info.json. If any build change
Steven Moreland62054a42018-12-06 10:11:40 -08001391# is made, and it should be reflected in the output, you should run 'refreshmod' first.
Rett Berg78d1c932019-01-24 14:34:23 -08001392function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001393 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1394 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1395 return 1
1396 fi
1397
1398 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001399 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001400 return 1
1401 fi
1402
1403 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1404 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1405 refreshmod || return 1
1406 fi
1407
1408 local relpath=$(python -c "import json, os
1409module = '$1'
1410module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1411if module not in module_info:
1412 exit(1)
LuK1337b6a78192020-01-12 03:12:17 +01001413print(module_info[module]['path'][0])" 2>/dev/null)
Steven Moreland62054a42018-12-06 10:11:40 -08001414
1415 if [ -z "$relpath" ]; then
1416 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1417 return 1
1418 else
Rett Berg78d1c932019-01-24 14:34:23 -08001419 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001420 fi
1421}
1422
Rett Berg78d1c932019-01-24 14:34:23 -08001423# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1424# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1425function gomod() {
1426 if [[ $# -ne 1 ]]; then
1427 echo "usage: gomod <module>" >&2
1428 return 1
1429 fi
1430
1431 local path="$(pathmod $@)"
1432 if [ -z "$path" ]; then
1433 return 1
1434 fi
1435 cd $path
1436}
1437
dimitry73b84812018-12-11 18:06:00 +01001438function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001439 local word=${COMP_WORDS[COMP_CWORD]}
1440 COMPREPLY=( $(allmod | grep -E "^$word") )
1441}
1442
Alex Rayf0d08eb2013-03-08 15:15:06 -08001443# Print colored exit condition
1444function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001445 "$@"
1446 local retval=$?
1447 if [ $retval -ne 0 ]
1448 then
Jacky Cao89483b82015-05-15 22:12:53 +08001449 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001450 else
Jacky Cao89483b82015-05-15 22:12:53 +08001451 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001452 fi
1453 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001454}
1455
Ying Wanged21d4c2014-08-24 22:14:19 -07001456function get_make_command()
1457{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001458 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1459 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001460 # Always use the real make if -C is passed in
1461 for arg in "$@"; do
1462 if [[ $arg == -C* ]]; then
1463 echo command make
1464 return
1465 fi
1466 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001467 echo build/soong/soong_ui.bash --make-mode
1468 else
1469 echo command make
1470 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001471}
1472
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001473function _wrap_build()
Ed Heylcc6be0a2014-06-18 14:55:58 -07001474{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001475 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1476 "$@"
1477 return $?
1478 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001479 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001480 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001481 local ret=$?
1482 local end_time=$(date +"%s")
1483 local tdiff=$(($end_time-$start_time))
1484 local hours=$(($tdiff / 3600 ))
1485 local mins=$((($tdiff % 3600) / 60))
1486 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001487 local ncolors=$(tput colors 2>/dev/null)
1488 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001489 color_failed=$'\E'"[0;31m"
1490 color_success=$'\E'"[0;32m"
1491 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001492 else
1493 color_failed=""
1494 color_success=""
1495 color_reset=""
1496 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001497 echo
1498 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001499 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001500 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001501 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001502 fi
1503 if [ $hours -gt 0 ] ; then
1504 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1505 elif [ $mins -gt 0 ] ; then
1506 printf "(%02g:%02g (mm:ss))" $mins $secs
1507 elif [ $secs -gt 0 ] ; then
1508 printf "(%s seconds)" $secs
1509 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001510 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001511 echo
1512 return $ret
1513}
1514
Patrice Arrudafa7204b2019-06-20 23:40:33 +00001515function _trigger_build()
1516(
1517 local -r bc="$1"; shift
1518 if T="$(gettop)"; then
1519 _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
1520 else
1521 echo "Couldn't locate the top of the tree. Try setting TOP."
1522 fi
1523)
1524
1525function m()
1526(
1527 _trigger_build "all-modules" "$@"
1528)
1529
1530function mm()
1531(
1532 _trigger_build "modules-in-a-dir-no-deps" "$@"
1533)
1534
1535function mmm()
1536(
1537 _trigger_build "modules-in-dirs-no-deps" "$@"
1538)
1539
1540function mma()
1541(
1542 _trigger_build "modules-in-a-dir" "$@"
1543)
1544
1545function mmma()
1546(
1547 _trigger_build "modules-in-dirs" "$@"
1548)
1549
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001550function make()
1551{
Dan Willemsene9842242017-07-28 13:00:13 -07001552 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001553}
1554
David Zeuthen1b126ff2015-09-30 17:10:48 -04001555function provision()
1556{
1557 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1558 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1559 return 1
1560 fi
1561 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1562 echo "There is no provisioning script for the device." >&2
1563 return 1
1564 fi
1565
1566 # Check if user really wants to do this.
1567 if [ "$1" = "--no-confirmation" ]; then
1568 shift 1
1569 else
1570 echo "This action will reflash your device."
1571 echo ""
1572 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1573 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001574 echo -n "Are you sure you want to do this (yes/no)? "
1575 read
David Zeuthen1b126ff2015-09-30 17:10:48 -04001576 if [[ "${REPLY}" != "yes" ]] ; then
1577 echo "Not taking any action. Exiting." >&2
1578 return 1
1579 fi
1580 fi
1581 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1582}
1583
Jim Tanga881a252018-06-19 16:34:41 +08001584# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001585function enable_zsh_completion() {
1586 # Don't override user's options if bash-style completion is already enabled.
1587 if ! declare -f complete >/dev/null; then
1588 autoload -U compinit && compinit
1589 autoload -U bashcompinit && bashcompinit
1590 fi
Jim Tanga881a252018-06-19 16:34:41 +08001591}
1592
Khalid Zubair636f1112016-02-08 16:27:55 -08001593
1594function __detect_shell() {
1595 case `ps -o command -p $$` in
1596 *bash*)
1597 echo bash
1598 ;;
1599 *zsh*)
1600 echo zsh
1601 ;;
1602 *)
1603 echo unknown
1604 return 1
1605 ;;
1606 esac
1607 return
1608}
1609
Jim Tanga881a252018-06-19 16:34:41 +08001610function validate_current_shell() {
1611 local current_sh="$(ps -o command -p $$)"
1612 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001613 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001614 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001615 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001616 *zsh*)
1617 function check_type() { type "$1"; }
Patrik Fimmldf248e62018-10-15 18:15:12 +02001618 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001619 *)
Jim Tanga881a252018-06-19 16:34:41 +08001620 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 -07001621 ;;
1622 esac
Jim Tanga881a252018-06-19 16:34:41 +08001623}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001624
1625# Execute the contents of any vendorsetup.sh files we can find.
Dan Willemsend855a722019-02-12 15:52:36 -08001626# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
1627# load those.
1628#
1629# This allows loading only approved vendorsetup.sh files
Jim Tanga881a252018-06-19 16:34:41 +08001630function source_vendorsetup() {
Jim Tangc4dba1d2019-07-25 16:54:27 +08001631 unset VENDOR_PYTHONPATH
Dan Willemsend855a722019-02-12 15:52:36 -08001632 allowed=
1633 for f in $(find -L device vendor product -maxdepth 4 -name 'allowed-vendorsetup_sh-files' 2>/dev/null | sort); do
1634 if [ -n "$allowed" ]; then
1635 echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
1636 echo " $allowed"
1637 echo " $f"
1638 return
1639 fi
1640 allowed="$f"
1641 done
1642
1643 allowed_files=
1644 [ -n "$allowed" ] && allowed_files=$(cat "$allowed")
Jim Tanga881a252018-06-19 16:34:41 +08001645 for dir in device vendor product; do
1646 for f in $(test -d $dir && \
1647 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
Dan Willemsend855a722019-02-12 15:52:36 -08001648
1649 if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
1650 echo "including $f"; . "$f"
1651 else
1652 echo "ignoring $f, not in $allowed"
1653 fi
Jim Tanga881a252018-06-19 16:34:41 +08001654 done
1655 done
1656}
Kenny Root52aa81c2011-07-15 11:07:06 -07001657
Jim Tanga881a252018-06-19 16:34:41 +08001658validate_current_shell
1659source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001660addcompletions
Chirayu Desai9c26dc02013-03-19 17:50:37 +05301661
ganeshi4u8dcf6bb2019-09-06 18:31:15 +02001662# check and set ccache path on envsetup
1663if [ -z ${CCACHE_EXEC} ]; then
1664 ccache_path=$(which ccache)
1665 if [ ! -z "$ccache_path" ]; then
1666 export CCACHE_EXEC="$ccache_path"
1667 echo "ccache found and CCACHE_EXEC has been set to : $ccache_path"
1668 else
1669 echo "ccache not found/installed!"
1670 fi
1671fi
1672
Chirayu Desai9c26dc02013-03-19 17:50:37 +05301673export ANDROID_BUILD_TOP=$(gettop)
Michael Bestas83c04522016-08-26 00:37:02 +03001674
1675. $ANDROID_BUILD_TOP/vendor/bliss/build/envsetup.sh