blob: d6b6bb4faa4cfb9bcc341045996676133f3cb804 [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]
12- croot: Changes directory to the top of the tree.
13- m: Makes from the top of the tree.
14- mm: Builds all of the modules in the current directory, but not their dependencies.
15- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
16 To limit the modules being built use the syntax: mmm dir/:target1,target2.
17- mma: Builds all of the modules in the current directory, and their dependencies.
18- mmma: Builds all of the modules in the supplied directories, and their dependencies.
19- provision: Flash device with all required partitions. Options will be passed on to fastboot.
20- cgrep: Greps on all local C/C++ files.
21- ggrep: Greps on all local Gradle files.
22- jgrep: Greps on all local Java files.
23- resgrep: Greps on all local res/*.xml files.
24- mangrep: Greps on all local AndroidManifest.xml files.
25- mgrep: Greps on all local Makefiles files.
26- sepgrep: Greps on all local sepolicy files.
27- sgrep: Greps on all local source files.
28- godir: Go to the directory containing a file.
29- allmod: List all modules.
30- gomod: Go to the directory containing a module.
Rett Berg78d1c932019-01-24 14:34:23 -080031- pathmod: Get the directory containing a module.
Steven Moreland62054a42018-12-06 10:11:40 -080032- refreshmod: Refresh list of modules for allmod/gomod.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070033
Roland Levillain39341922015-10-20 12:48:19 +010034Environment options:
Dan Albert4ae5d4b2014-10-31 16:23:08 -070035- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
36 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
37 build is leak-check clean.
Sasha Smundak9f27cc02019-01-31 13:25:31 -080038- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
Dan Albert4ae5d4b2014-10-31 16:23:08 -070039
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070040Look at the source to view more functions. The complete list is:
41EOF
Christopher Ferris55257d22017-03-23 11:08:58 -070042 local T=$(gettop)
43 local A=""
44 local i
Jacky Cao89483b82015-05-15 22:12:53 +080045 for i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070046 A="$A $i"
47 done
48 echo $A
49}
50
Ying Wang08800fd2016-03-03 20:57:21 -080051# Get all the build variables needed by this script in a single call to the build system.
52function build_build_var_cache()
53{
Christopher Ferris55257d22017-03-23 11:08:58 -070054 local T=$(gettop)
Ying Wang08800fd2016-03-03 20:57:21 -080055 # Grep out the variable names from the script.
Jim Tanga881a252018-06-19 16:34:41 +080056 cached_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
57 cached_abs_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
Ying Wang08800fd2016-03-03 20:57:21 -080058 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
Steven Moreland05402962018-01-05 12:13:11 -080059 build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
Jim Tanga881a252018-06-19 16:34:41 +080060 --vars="${cached_vars[*]}" \
61 --abs-vars="${cached_abs_vars[*]}" \
Dan Willemsenaf88c412017-07-14 11:29:44 -070062 --var-prefix=var_cache_ \
63 --abs-var-prefix=abs_var_cache_`
Ying Wang08800fd2016-03-03 20:57:21 -080064 local ret=$?
65 if [ $ret -ne 0 ]
66 then
67 unset build_dicts_script
68 return $ret
69 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -070070 # Execute the script to store the "<val>=<value>" pairs as shell variables.
Ying Wang08800fd2016-03-03 20:57:21 -080071 eval "$build_dicts_script"
Ying Wang08800fd2016-03-03 20:57:21 -080072 ret=$?
Ying Wangf0cb3972016-03-04 13:56:23 -080073 unset build_dicts_script
Ying Wang08800fd2016-03-03 20:57:21 -080074 if [ $ret -ne 0 ]
75 then
76 return $ret
77 fi
78 BUILD_VAR_CACHE_READY="true"
79}
80
Ying Wangf0cb3972016-03-04 13:56:23 -080081# Delete the build var cache, so that we can still call into the build system
Ying Wang08800fd2016-03-03 20:57:21 -080082# to get build variables not listed in this script.
83function destroy_build_var_cache()
84{
85 unset BUILD_VAR_CACHE_READY
Christopher Ferris55257d22017-03-23 11:08:58 -070086 local v
Ying Wang08800fd2016-03-03 20:57:21 -080087 for v in $cached_vars; do
88 unset var_cache_$v
89 done
90 unset cached_vars
91 for v in $cached_abs_vars; do
92 unset abs_var_cache_$v
93 done
94 unset cached_abs_vars
95}
96
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070097# Get the value of a build variable as an absolute path.
98function get_abs_build_var()
99{
Ying Wang08800fd2016-03-03 20:57:21 -0800100 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
101 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800102 eval "echo \"\${abs_var_cache_$1}\""
Ying Wang08800fd2016-03-03 20:57:21 -0800103 return
104 fi
105
Christopher Ferris55257d22017-03-23 11:08:58 -0700106 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700107 if [ ! "$T" ]; then
108 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
109 return
110 fi
Dan Willemsenaf88c412017-07-14 11:29:44 -0700111 (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700112}
113
114# Get the exact value of a build variable.
115function get_build_var()
116{
Ying Wang08800fd2016-03-03 20:57:21 -0800117 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
118 then
Vishwath Mohan7d35f002016-03-11 10:00:40 -0800119 eval "echo \"\${var_cache_$1}\""
Ying Wang08800fd2016-03-03 20:57:21 -0800120 return
121 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 $1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800129}
130
131# check to see if the supplied product is one we can build
132function check_product()
133{
Christopher Ferris55257d22017-03-23 11:08:58 -0700134 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800135 if [ ! "$T" ]; then
136 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
137 return
138 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700139 TARGET_PRODUCT=$1 \
140 TARGET_BUILD_VARIANT= \
141 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -0700142 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800143 get_build_var TARGET_DEVICE > /dev/null
144 # hide successful answers, but allow the errors to show
145}
146
147VARIANT_CHOICES=(user userdebug eng)
148
149# check to see if the supplied variant is valid
150function check_variant()
151{
Christopher Ferris55257d22017-03-23 11:08:58 -0700152 local v
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800153 for v in ${VARIANT_CHOICES[@]}
154 do
155 if [ "$v" = "$1" ]
156 then
157 return 0
158 fi
159 done
160 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700161}
162
163function setpaths()
164{
Christopher Ferris55257d22017-03-23 11:08:58 -0700165 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700166 if [ ! "$T" ]; then
167 echo "Couldn't locate the top of the tree. Try setting TOP."
168 return
169 fi
170
171 ##################################################################
172 # #
173 # Read me before you modify this code #
174 # #
175 # This function sets ANDROID_BUILD_PATHS to what it is adding #
176 # to PATH, and the next time it is run, it removes that from #
177 # PATH. This is required so lunch can be run more than once #
178 # and still have working paths. #
179 # #
180 ##################################################################
181
Raphael Mollc639c782011-06-20 17:25:01 -0700182 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
183 # due to "C:\Program Files" being in the path.
184
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700185 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700186 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700187 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
188 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700189 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700190 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800191 # strip leading ':', if any
192 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500193 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700194
195 # and in with the new
Christopher Ferris55257d22017-03-23 11:08:58 -0700196 local prebuiltdir=$(getprebuilt)
197 local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700198
Ben Cheng8bc4c432012-11-16 13:29:13 -0800199 # defined in core/config.mk
Christopher Ferris55257d22017-03-23 11:08:58 -0700200 local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
201 local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800202 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800203
Raphael Mollc639c782011-06-20 17:25:01 -0700204 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800205 export ANDROID_TOOLCHAIN=
206 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200207 local ARCH=$(get_build_var TARGET_ARCH)
Christopher Ferris55257d22017-03-23 11:08:58 -0700208 local toolchaindir toolchaindir2=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200209 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400210 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700211 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400212 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
213 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800214 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200215 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800216 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700217 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700218 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700219 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000220 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200221 *)
222 echo "Can't find toolchain for unknown architecture: $ARCH"
223 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700224 ;;
225 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700226 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800227 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700228 fi
Raphael732936d2011-06-22 14:35:32 -0700229
Christopher Ferris55257d22017-03-23 11:08:58 -0700230 if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800231 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
232 fi
233
Jeff Vander Stoep5f50f052015-06-12 09:56:39 -0700234 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Yueyao Zhuefc786a2017-04-07 14:11:54 -0700235
236 # add kernel specific binaries
237 case $(uname -s) in
238 Linux)
239 export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
240 ;;
241 *)
242 ;;
243 esac
244
Torne (Richard Coles)0091bae2017-10-03 16:31:18 -0400245 ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN
246 if [ -n "$ANDROID_TOOLCHAIN_2ND_ARCH" ]; then
247 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH
248 fi
249 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS:
250 export ANDROID_BUILD_PATHS
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200251
252 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
253 # to ensure that the corresponding 'emulator' binaries are used.
254 case $(uname -s) in
255 Darwin)
256 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
257 ;;
258 Linux)
259 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
260 ;;
261 *)
262 ANDROID_EMULATOR_PREBUILTS=
263 ;;
264 esac
265 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700266 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200267 export ANDROID_EMULATOR_PREBUILTS
268 fi
269
Jim Tangb3fda302018-12-22 10:24:55 +0800270 # Append asuite prebuilts path to ANDROID_BUILD_PATHS.
271 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
272 local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch:"
273 local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch:"
274 local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch:"
275 export ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ACLOUD_PATH$AIDEGEN_PATH$ATEST_PATH
276
Ying Wangaa1c9b52012-11-26 20:51:59 -0800277 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800278
279 # out with the duplicate old
280 if [ -n $ANDROID_PYTHONPATH ]; then
281 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
282 fi
283 # and in with the new
284 export ANDROID_PYTHONPATH=$T/development/python-packages:
285 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800286
Colin Crosse97e6932017-06-30 16:01:45 -0700287 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
288 export JAVA_HOME=$ANDROID_JAVA_HOME
289 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
290 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
291 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500292
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800293 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700294 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
295 export OUT=$ANDROID_PRODUCT_OUT
296
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700297 unset ANDROID_HOST_OUT
298 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
299
Simran Basidd050ed2017-02-13 13:46:48 -0800300 unset ANDROID_HOST_OUT_TESTCASES
301 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
302
303 unset ANDROID_TARGET_OUT_TESTCASES
304 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
305
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800306 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700307 # TODO: fix the path
308 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
309}
310
311function printconfig()
312{
Christopher Ferris55257d22017-03-23 11:08:58 -0700313 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800314 if [ ! "$T" ]; then
315 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
316 return
317 fi
318 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319}
320
321function set_stuff_for_environment()
322{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800323 setpaths
324 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800326 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700327 # With this environment variable new GCC can apply colors to warnings/errors
328 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
Dan Albert4ae5d4b2014-10-31 16:23:08 -0700329 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700330}
331
332function set_sequence_number()
333{
Colin Cross88737132017-03-21 17:41:03 -0700334 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335}
336
Makoto Onukida971062018-06-18 10:15:19 -0700337# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
338function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800339 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700340 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800341 *:"$cmd":*)
342 return 1
343 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700344 esac
345 return 0
346}
347
Kenny Root52aa81c2011-07-15 11:07:06 -0700348function addcompletions()
349{
350 local T dir f
351
Jim Tanga881a252018-06-19 16:34:41 +0800352 # Keep us from trying to run in something that's neither bash nor zsh.
353 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700354 return
355 fi
356
357 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800358 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700359 return
360 fi
361
Jim Tanga881a252018-06-19 16:34:41 +0800362 local completion_files=(
363 system/core/adb/adb.bash
364 system/core/fastboot/fastboot.bash
Jim Tangb3fda302018-12-22 10:24:55 +0800365 tools/asuite/asuite.sh
Jim Tanga881a252018-06-19 16:34:41 +0800366 )
Makoto Onukida971062018-06-18 10:15:19 -0700367 # Completion can be disabled selectively to allow users to use non-standard completion.
368 # e.g.
369 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
370 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800371 for f in ${completion_files[*]}; do
372 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700373 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700374 fi
375 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700376
Makoto Onukida971062018-06-18 10:15:19 -0700377 if should_add_completion bit ; then
378 complete -C "bit --tab" bit
379 fi
Jim Tanga881a252018-06-19 16:34:41 +0800380 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800381
dimitry73b84812018-12-11 18:06:00 +0100382 complete -F _complete_android_module_names gomod
383 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700384}
385
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700386function choosetype()
387{
388 echo "Build type choices are:"
389 echo " 1. release"
390 echo " 2. debug"
391 echo
392
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800393 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700394 DEFAULT_NUM=1
395 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700396
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800397 export TARGET_BUILD_TYPE=
398 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700399 while [ -z $TARGET_BUILD_TYPE ]
400 do
401 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800402 if [ -z "$1" ] ; then
403 read ANSWER
404 else
405 echo $1
406 ANSWER=$1
407 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700408 case $ANSWER in
409 "")
410 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
411 ;;
412 1)
413 export TARGET_BUILD_TYPE=release
414 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800415 release)
416 export TARGET_BUILD_TYPE=release
417 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700418 2)
419 export TARGET_BUILD_TYPE=debug
420 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800421 debug)
422 export TARGET_BUILD_TYPE=debug
423 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700424 *)
425 echo
426 echo "I didn't understand your response. Please try again."
427 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700428 ;;
429 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800430 if [ -n "$1" ] ; then
431 break
432 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700433 done
434
Ying Wang08800fd2016-03-03 20:57:21 -0800435 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700436 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800437 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700438}
439
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800440#
441# This function isn't really right: It chooses a TARGET_PRODUCT
442# based on the list of boards. Usually, that gets you something
443# that kinda works with a generic product, but really, you should
444# pick a product by name.
445#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446function chooseproduct()
447{
Christopher Ferris55257d22017-03-23 11:08:58 -0700448 local default_value
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449 if [ "x$TARGET_PRODUCT" != x ] ; then
450 default_value=$TARGET_PRODUCT
451 else
Ying Wang0a76df52015-06-08 11:57:26 -0700452 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700453 fi
454
Ying Wang08800fd2016-03-03 20:57:21 -0800455 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800456 export TARGET_PRODUCT=
457 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458 while [ -z "$TARGET_PRODUCT" ]
459 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700460 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800461 if [ -z "$1" ] ; then
462 read ANSWER
463 else
464 echo $1
465 ANSWER=$1
466 fi
467
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468 if [ -z "$ANSWER" ] ; then
469 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800470 else
471 if check_product $ANSWER
472 then
473 export TARGET_PRODUCT=$ANSWER
474 else
475 echo "** Not a valid product: $ANSWER"
476 fi
477 fi
478 if [ -n "$1" ] ; then
479 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700480 fi
481 done
482
Ying Wang08800fd2016-03-03 20:57:21 -0800483 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700484 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800485 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486}
487
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800488function choosevariant()
489{
490 echo "Variant choices are:"
491 local index=1
492 local v
493 for v in ${VARIANT_CHOICES[@]}
494 do
495 # The product name is the name of the directory containing
496 # the makefile we found, above.
497 echo " $index. $v"
498 index=$(($index+1))
499 done
500
501 local default_value=eng
502 local ANSWER
503
504 export TARGET_BUILD_VARIANT=
505 while [ -z "$TARGET_BUILD_VARIANT" ]
506 do
507 echo -n "Which would you like? [$default_value] "
508 if [ -z "$1" ] ; then
509 read ANSWER
510 else
511 echo $1
512 ANSWER=$1
513 fi
514
515 if [ -z "$ANSWER" ] ; then
516 export TARGET_BUILD_VARIANT=$default_value
517 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
518 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800519 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520 fi
521 else
522 if check_variant $ANSWER
523 then
524 export TARGET_BUILD_VARIANT=$ANSWER
525 else
526 echo "** Not a valid variant: $ANSWER"
527 fi
528 fi
529 if [ -n "$1" ] ; then
530 break
531 fi
532 done
533}
534
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700535function choosecombo()
536{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700537 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700538
539 echo
540 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700541 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700542
543 echo
544 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700545 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800546
547 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800548 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700549 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800550 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800551 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700552}
553
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800554# Clear this variable. It will be built up again when the vendorsetup.sh
555# files are included at the end of this file.
556unset LUNCH_MENU_CHOICES
557function add_lunch_combo()
558{
559 local new_combo=$1
560 local c
561 for c in ${LUNCH_MENU_CHOICES[@]} ; do
562 if [ "$new_combo" = "$c" ] ; then
563 return
564 fi
565 done
566 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
567}
568
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700569function print_lunch_menu()
570{
571 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700572 echo
573 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700574 echo
575 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800576
577 local i=1
578 local choice
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700579 for choice in $(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800580 do
581 echo " $i. $choice"
582 i=$(($i+1))
583 done
584
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585 echo
586}
587
588function lunch()
589{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 local answer
591
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800593 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700594 else
595 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700596 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800597 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700598 fi
599
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800600 local selection=
601
602 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700603 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700604 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800605 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
606 then
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700607 local choices=($(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES))
608 if [ $answer -le ${#choices[@]} ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800609 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800610 # array in zsh starts from 1 instead of 0.
611 if [ -n "$ZSH_VERSION" ]
612 then
613 selection=${choices[$(($answer))]}
614 else
615 selection=${choices[$(($answer-1))]}
616 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800617 fi
Colin Cross88737132017-03-21 17:41:03 -0700618 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800619 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700620 fi
621
Joe Onoratoda12daf2010-06-09 18:18:31 -0700622 export TARGET_BUILD_APPS=
623
Colin Cross88737132017-03-21 17:41:03 -0700624 local product variant_and_version variant version
625
626 product=${selection%%-*} # Trim everything after first dash
627 variant_and_version=${selection#*-} # Trim everything up to first dash
628 if [ "$variant_and_version" != "$selection" ]; then
629 variant=${variant_and_version%%-*}
630 if [ "$variant" != "$variant_and_version" ]; then
631 version=${variant_and_version#*-}
632 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700633 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800634
Colin Cross88737132017-03-21 17:41:03 -0700635 if [ -z "$product" ]
Ying Wang08800fd2016-03-03 20:57:21 -0800636 then
637 echo
Colin Cross88737132017-03-21 17:41:03 -0700638 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700639 return 1
640 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800641
Colin Cross88737132017-03-21 17:41:03 -0700642 TARGET_PRODUCT=$product \
643 TARGET_BUILD_VARIANT=$variant \
644 TARGET_PLATFORM_VERSION=$version \
645 build_build_var_cache
646 if [ $? -ne 0 ]
647 then
648 return 1
649 fi
650
651 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
652 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700653 if [ -n "$version" ]; then
654 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
655 else
656 unset TARGET_PLATFORM_VERSION
657 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700658 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659
660 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800661
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800663 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800664 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700665}
666
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700667unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700668# Tab completion for lunch.
669function _lunch()
670{
671 local cur prev opts
672 COMPREPLY=()
673 cur="${COMP_WORDS[COMP_CWORD]}"
674 prev="${COMP_WORDS[COMP_CWORD-1]}"
675
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700676 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
677 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES)
678 fi
679
680 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700681 return 0
682}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700683
Joe Onoratoda12daf2010-06-09 18:18:31 -0700684# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700685# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700686function tapas()
687{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700688 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Dan Willemsendd3a2732018-01-08 15:26:16 -0800689 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700690 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700691 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 -0800692 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 -0700693
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700694 if [ "$showHelp" != "" ]; then
695 $(gettop)/build/make/tapasHelp.sh
696 return
697 fi
698
Ying Wang67f02922012-08-22 10:25:20 -0700699 if [ $(echo $arch | wc -w) -gt 1 ]; then
700 echo "tapas: Error: Multiple build archs supplied: $arch"
701 return
702 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700703 if [ $(echo $variant | wc -w) -gt 1 ]; then
704 echo "tapas: Error: Multiple build variants supplied: $variant"
705 return
706 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700707 if [ $(echo $density | wc -w) -gt 1 ]; then
708 echo "tapas: Error: Multiple densities supplied: $density"
709 return
710 fi
Ying Wang67f02922012-08-22 10:25:20 -0700711
Ying Wang0a76df52015-06-08 11:57:26 -0700712 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700713 case $arch in
Ying Wang0a76df52015-06-08 11:57:26 -0700714 x86) product=aosp_x86;;
715 mips) product=aosp_mips;;
Ying Wangb541ab62014-05-29 17:57:40 -0700716 arm64) product=aosp_arm64;;
717 x86_64) product=aosp_x86_64;;
718 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700719 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700720 if [ -z "$variant" ]; then
721 variant=eng
722 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700723 if [ -z "$apps" ]; then
724 apps=all
725 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600726 if [ -z "$density" ]; then
727 density=alldpi
728 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700729
Ying Wang67f02922012-08-22 10:25:20 -0700730 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700731 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700732 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700733 export TARGET_BUILD_TYPE=release
734 export TARGET_BUILD_APPS=$apps
735
Ying Wang08800fd2016-03-03 20:57:21 -0800736 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700737 set_stuff_for_environment
738 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800739 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700740}
741
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700742function gettop
743{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700744 local TOPFILE=build/make/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700745 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700746 # The following circumlocution ensures we remove symlinks from TOP.
747 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700748 else
749 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800750 # The following circumlocution (repeated below as well) ensures
751 # that we record the true directory name and not one that is
752 # faked up with symlink names.
753 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700754 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800755 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700756 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700757 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800758 \cd ..
synergyb112a402013-07-05 19:47:47 -0700759 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700760 done
Ying Wang9cd17642012-12-13 10:52:07 -0800761 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700762 if [ -f "$T/$TOPFILE" ]; then
763 echo $T
764 fi
765 fi
766 fi
767}
768
769function m()
770{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800771 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700772 if [ "$T" ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800773 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700774 else
775 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700776 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700777 fi
778}
779
780function findmakefile()
781{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700782 local TOPFILE=build/make/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800783 local HERE=$PWD
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800784 if [ "$1" ]; then
785 \cd $1
786 fi;
Christopher Ferris55257d22017-03-23 11:08:58 -0700787 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700788 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700789 T=`PWD= /bin/pwd`
Colin Cross86425252016-05-26 15:32:15 -0700790 if [ -f "$T/Android.mk" -o -f "$T/Android.bp" ]; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800792 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793 return
794 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800795 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700796 done
Ying Wang9cd17642012-12-13 10:52:07 -0800797 \cd $HERE
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700798 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700799}
800
801function mm()
802{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800803 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700804 # If we're sitting in the root of the build tree, just do a
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700805 # normal build.
806 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800807 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700808 else
809 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800810 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700811 local MODULES=
812 local GET_INSTALL_PATH=
813 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700814 # Remove the path to top as the makefilepath needs to be relative
815 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700816 if [ ! "$T" ]; then
817 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700818 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700819 elif [ ! "$M" ]; then
820 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700821 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700822 else
Christopher Ferris55257d22017-03-23 11:08:58 -0700823 local ARG
Ying Wanga7deb082013-08-16 13:24:47 -0700824 for ARG in $@; do
825 case $ARG in
826 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
827 esac
828 done
829 if [ -n "$GET_INSTALL_PATH" ]; then
830 MODULES=
Dan Willemsen53e38992016-08-11 17:20:33 -0700831 ARGS=GET-INSTALL-PATH-IN-$(dirname ${M})
832 ARGS=${ARGS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700833 else
Colin Cross86425252016-05-26 15:32:15 -0700834 MODULES=MODULES-IN-$(dirname ${M})
835 # Convert "/" to "-".
836 MODULES=${MODULES//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700837 ARGS=$@
838 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700839 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
840 MODULES=tidy_only
841 fi
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800842 ONE_SHOT_MAKEFILE=$M _wrap_build $T/build/soong/soong_ui.bash --make-mode $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700843 fi
844 fi
845}
846
847function mmm()
848{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800849 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800851 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800852 local MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700853 local MODULES_IN_PATHS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800854 local ARGS=
855 local DIR TO_CHOP
Colin Cross86425252016-05-26 15:32:15 -0700856 local DIR_MODULES
Ying Wanga7deb082013-08-16 13:24:47 -0700857 local GET_INSTALL_PATH=
Dan Willemsen53e38992016-08-11 17:20:33 -0700858 local GET_INSTALL_PATHS=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800859 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
860 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
861 for DIR in $DIRS ; do
Colin Cross86425252016-05-26 15:32:15 -0700862 DIR_MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
Alon Albert68895a92011-11-30 12:40:19 -0800863 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
Colin Cross86425252016-05-26 15:32:15 -0700864 # Remove the leading ./ and trailing / if any exists.
865 DIR=${DIR#./}
866 DIR=${DIR%/}
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800867 local M
868 if [ "$DIR_MODULES" = "" ]; then
869 M=$(findmakefile $DIR)
870 else
871 # Only check the target directory if a module is specified.
872 if [ -f $DIR/Android.mk -o -f $DIR/Android.bp ]; then
873 local HERE=$PWD
874 cd $DIR
875 M=`PWD= /bin/pwd`
876 M=$M/Android.mk
877 cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700878 fi
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800879 fi
880 if [ "$M" ]; then
881 # Remove the path to top as the makefilepath needs to be relative
882 local M=`echo $M|sed 's:'$T'/::'`
Colin Cross4bfae062016-08-31 17:22:36 -0700883 if [ "$DIR_MODULES" = "" ]; then
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800884 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$(dirname ${M})"
885 GET_INSTALL_PATHS="$GET_INSTALL_PATHS GET-INSTALL-PATH-IN-$(dirname ${M})"
Colin Cross4bfae062016-08-31 17:22:36 -0700886 else
887 MODULES="$MODULES $DIR_MODULES"
888 fi
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800889 MAKEFILE="$MAKEFILE $M"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700890 else
Ying Wanga7deb082013-08-16 13:24:47 -0700891 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700892 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700893 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
Abhinav1997a72a6e72015-10-18 20:25:48 +0200894 *) if [ -d $DIR ]; then
895 echo "No Android.mk in $DIR.";
896 else
897 echo "Couldn't locate the directory $DIR";
898 fi
899 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700900 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700901 fi
902 done
Ying Wanga7deb082013-08-16 13:24:47 -0700903 if [ -n "$GET_INSTALL_PATH" ]; then
Dan Willemsen53e38992016-08-11 17:20:33 -0700904 ARGS=${GET_INSTALL_PATHS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700905 MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700906 MODULES_IN_PATHS=
Ying Wanga7deb082013-08-16 13:24:47 -0700907 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700908 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
909 MODULES=tidy_only
Colin Cross86425252016-05-26 15:32:15 -0700910 MODULES_IN_PATHS=
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700911 fi
Colin Cross86425252016-05-26 15:32:15 -0700912 # Convert "/" to "-".
913 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800914 ONE_SHOT_MAKEFILE="$MAKEFILE" _wrap_build $T/build/soong/soong_ui.bash --make-mode $DASH_ARGS $MODULES $MODULES_IN_PATHS $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700915 else
916 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700917 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700918 fi
919}
920
Ying Wangb607f7b2013-02-08 18:01:04 -0800921function mma()
922{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800923 local T=$(gettop)
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700924 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800925 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800926 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800927 if [ ! "$T" ]; then
928 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700929 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800930 fi
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700931 local M=$(findmakefile || echo $(realpath $PWD)/Android.mk)
Colin Cross127fcea2016-09-01 15:30:18 -0700932 # Remove the path to top as the makefilepath needs to be relative
933 local M=`echo $M|sed 's:'$T'/::'`
934 local MODULES_IN_PATHS=MODULES-IN-$(dirname ${M})
Ying Wang61cd8842015-09-24 16:19:19 -0700935 # Convert "/" to "-".
936 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800937 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@ $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800938 fi
939}
940
941function mmma()
942{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800943 local T=$(gettop)
Ying Wangb607f7b2013-02-08 18:01:04 -0800944 if [ "$T" ]; then
945 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
946 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
947 local MY_PWD=`PWD= /bin/pwd`
948 if [ "$MY_PWD" = "$T" ]; then
949 MY_PWD=
950 else
951 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
952 fi
953 local DIR=
Ying Wangcaeaa082015-09-23 16:08:55 -0700954 local MODULES_IN_PATHS=
Ying Wangb607f7b2013-02-08 18:01:04 -0800955 local ARGS=
956 for DIR in $DIRS ; do
957 if [ -d $DIR ]; then
Ying Wangcaeaa082015-09-23 16:08:55 -0700958 # Remove the leading ./ and trailing / if any exists.
959 DIR=${DIR#./}
960 DIR=${DIR%/}
961 if [ "$MY_PWD" != "" ]; then
962 DIR=$MY_PWD/$DIR
Ying Wangb607f7b2013-02-08 18:01:04 -0800963 fi
Ying Wang61cd8842015-09-24 16:19:19 -0700964 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
Ying Wangb607f7b2013-02-08 18:01:04 -0800965 else
966 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700967 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800968 *) echo "Couldn't find directory $DIR"; return 1;;
969 esac
970 fi
971 done
Ying Wang61cd8842015-09-24 16:19:19 -0700972 # Convert "/" to "-".
973 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800974 _wrap_build $T/build/soong/soong_ui.bash --make-mode $DASH_ARGS $ARGS $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800975 else
976 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700977 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800978 fi
979}
980
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700981function croot()
982{
Christopher Ferris55257d22017-03-23 11:08:58 -0700983 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700984 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700985 if [ "$1" ]; then
986 \cd $(gettop)/$1
987 else
988 \cd $(gettop)
989 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700990 else
991 echo "Couldn't locate the top of the tree. Try setting TOP."
992 fi
993}
994
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700995function cproj()
996{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700997 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700998 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700999 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001000 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1001 T=$PWD
1002 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001003 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001004 return
1005 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001006 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001007 done
Ying Wang9cd17642012-12-13 10:52:07 -08001008 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001009 echo "can't find Android.mk"
1010}
1011
Daniel Sandler47e0a882013-07-30 13:23:52 -04001012# simplified version of ps; output in the form
1013# <pid> <procname>
1014function qpid() {
1015 local prepend=''
1016 local append=''
1017 if [ "$1" = "--exact" ]; then
1018 prepend=' '
1019 append='$'
1020 shift
1021 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001022 echo "usage: qpid [[--exact] <process name|pid>"
1023 return 255
1024 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001025
1026 local EXE="$1"
1027 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001028 qpid | \grep "$prepend$EXE$append"
1029 else
1030 adb shell ps \
1031 | tr -d '\r' \
1032 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1033 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001034}
1035
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001036# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001037# that has the core-file-size limit set correctly
1038#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001039# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001040# if its core-file-size limit is not set already.
1041# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1042
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001043function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001044{
Ying Wang08800fd2016-03-03 20:57:21 -08001045 echo "Getting root...";
1046 adb root;
1047 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001048
Ying Wang08800fd2016-03-03 20:57:21 -08001049 echo "Remounting root partition read-write...";
1050 adb shell mount -w -o remount -t rootfs rootfs;
1051 sleep 1;
1052 adb wait-for-device;
1053 adb shell mkdir -p /cores;
1054 adb shell mount -t tmpfs tmpfs /cores;
1055 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001056
Ying Wang08800fd2016-03-03 20:57:21 -08001057 echo "Granting SELinux permission to dump in /cores...";
1058 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001059
Ying Wang08800fd2016-03-03 20:57:21 -08001060 echo "Set core pattern.";
1061 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001062
Ying Wang08800fd2016-03-03 20:57:21 -08001063 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001064}
1065
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001066# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001067# $1 = PID of process (e.g., $(pid mediaserver))
1068#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001069# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001070# dump to actually be generated.
1071
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001072function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001073{
Ying Wang08800fd2016-03-03 20:57:21 -08001074 local PID=$1;
1075 if [ -z "$PID" ]; then
1076 printf "Expecting a PID!\n";
1077 return;
1078 fi;
1079 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001080 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001081}
1082
1083# core - send SIGV and pull the core for process
1084# $1 = PID of process (e.g., $(pid mediaserver))
1085#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001086# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001087# enabled globally.
1088
1089function core()
1090{
Ying Wang08800fd2016-03-03 20:57:21 -08001091 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001092
Ying Wang08800fd2016-03-03 20:57:21 -08001093 if [ -z "$PID" ]; then
1094 printf "Expecting a PID!\n";
1095 return;
1096 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001097
Ying Wang08800fd2016-03-03 20:57:21 -08001098 local CORENAME=core.$PID;
1099 local COREPATH=/cores/$CORENAME;
1100 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001101
Ying Wang08800fd2016-03-03 20:57:21 -08001102 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001103
Ying Wang08800fd2016-03-03 20:57:21 -08001104 local done=0;
1105 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1106 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1107 adb shell kill -$SIG $PID;
1108 sleep 1;
1109 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001110
Ying Wang08800fd2016-03-03 20:57:21 -08001111 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1112 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001113}
1114
Christopher Tate744ee802009-11-12 15:33:08 -08001115# systemstack - dump the current stack trace of all threads in the system process
1116# to the usual ANR traces file
1117function systemstack()
1118{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001119 stacks system_server
1120}
1121
Michael Wrightaeed7212014-06-19 19:58:12 -07001122# Read the ELF header from /proc/$PID/exe to determine if the process is
1123# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001124function is64bit()
1125{
1126 local PID="$1"
1127 if [ "$PID" ] ; then
Elliott Hughesd3e47252018-11-15 16:32:14 -08001128 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001129 echo "64"
1130 else
1131 echo ""
1132 fi
1133 else
1134 echo ""
1135 fi
1136}
1137
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001138case `uname -s` in
1139 Darwin)
1140 function sgrep()
1141 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001142 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 -04001143 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001144 }
1145
1146 ;;
1147 *)
1148 function sgrep()
1149 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001150 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 -04001151 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001152 }
1153 ;;
1154esac
1155
Raghu Gandham8da43102012-07-25 19:57:22 -07001156function gettargetarch
1157{
1158 get_build_var TARGET_ARCH
1159}
1160
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001161function ggrep()
1162{
Mike Frysinger5e479732015-09-22 18:13:48 -04001163 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1164 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001165}
1166
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001167function jgrep()
1168{
Mike Frysinger5e479732015-09-22 18:13:48 -04001169 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1170 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001171}
1172
1173function cgrep()
1174{
Mike Frysinger5e479732015-09-22 18:13:48 -04001175 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' \) \
1176 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001177}
1178
1179function resgrep()
1180{
Christopher Ferris55257d22017-03-23 11:08:58 -07001181 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001182 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1183 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1184 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001185}
1186
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001187function mangrep()
1188{
Mike Frysinger5e479732015-09-22 18:13:48 -04001189 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1190 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001191}
1192
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001193function sepgrep()
1194{
Mike Frysinger5e479732015-09-22 18:13:48 -04001195 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1196 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001197}
1198
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001199function rcgrep()
1200{
Mike Frysinger5e479732015-09-22 18:13:48 -04001201 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1202 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001203}
1204
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001205case `uname -s` in
1206 Darwin)
1207 function mgrep()
1208 {
David Grossd1d6fc52017-05-10 10:49:44 -07001209 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regex '(.*/)?soong/[^/]*.go' \) -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001210 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001211 }
1212
1213 function treegrep()
1214 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001215 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 -04001216 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001217 }
1218
1219 ;;
1220 *)
1221 function mgrep()
1222 {
David Grossd1d6fc52017-05-10 10:49:44 -07001223 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 '(.*/)?soong/[^/]*.go' \) -type f \
Mike Frysinger5e479732015-09-22 18:13:48 -04001224 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001225 }
1226
1227 function treegrep()
1228 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001229 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 -04001230 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001231 }
1232
1233 ;;
1234esac
1235
1236function getprebuilt
1237{
1238 get_abs_build_var ANDROID_PREBUILTS
1239}
1240
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001241function tracedmdump()
1242{
Christopher Ferris55257d22017-03-23 11:08:58 -07001243 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001244 if [ ! "$T" ]; then
1245 echo "Couldn't locate the top of the tree. Try setting TOP."
1246 return
1247 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001248 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001249 local arch=$(gettargetarch)
1250 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001251
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001252 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001253 if [ ! "$TRACE" ] ; then
1254 echo "usage: tracedmdump tracename"
1255 return
1256 fi
1257
Jack Veenstra60116fc2009-04-09 18:12:34 -07001258 if [ ! -r "$KERNEL" ] ; then
1259 echo "Error: cannot find kernel: '$KERNEL'"
1260 return
1261 fi
1262
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001263 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001264 if [ "$BASETRACE" = "$TRACE" ] ; then
1265 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1266 fi
1267
1268 echo "post-processing traces..."
1269 rm -f $TRACE/qtrace.dexlist
1270 post_trace $TRACE
1271 if [ $? -ne 0 ]; then
1272 echo "***"
1273 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1274 echo "***"
1275 return
1276 fi
1277 echo "generating dexlist output..."
1278 /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
1279 echo "generating dmtrace data..."
1280 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1281 echo "generating html file..."
1282 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1283 echo "done, see $TRACE/dmtrace.html for details"
1284 echo "or run:"
1285 echo " traceview $TRACE/dmtrace"
1286}
1287
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001288# communicate with a running device or emulator, set up necessary state,
1289# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001290function runhat()
1291{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001292 # process standard adb options
1293 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001294 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001295 adbTarget=$1
1296 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001297 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001298 adbTarget="$1 $2"
1299 shift 2
1300 fi
1301 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001302 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001303
1304 # runhat options
1305 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001306
1307 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001308 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001309 return
1310 fi
1311
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001312 # confirm hat is available
1313 if [ -z $(which hat) ]; then
1314 echo "hat is not available in this configuration."
1315 return
1316 fi
1317
Andy McFaddenb6289852010-07-12 08:00:19 -07001318 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001319 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001320 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001321 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001322 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001323 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001324 echo -n "> "
1325 read
1326
The Android Open Source Project88b60792009-03-03 19:28:42 -08001327 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001328
The Android Open Source Project88b60792009-03-03 19:28:42 -08001329 echo "Retrieving file $devFile..."
1330 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001331
The Android Open Source Project88b60792009-03-03 19:28:42 -08001332 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001333
The Android Open Source Project88b60792009-03-03 19:28:42 -08001334 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001335 echo "View the output by pointing your browser at http://localhost:7000/"
1336 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001337 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001338}
1339
1340function getbugreports()
1341{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001342 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001343
1344 if [ ! "$reports" ]; then
1345 echo "Could not locate any bugreports."
1346 return
1347 fi
1348
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001349 local report
1350 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001351 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001352 echo "/sdcard/bugreports/${report}"
1353 adb pull /sdcard/bugreports/${report} ${report}
1354 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001355 done
1356}
1357
Victoria Lease1b296b42012-08-21 15:44:06 -07001358function getsdcardpath()
1359{
1360 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1361}
1362
1363function getscreenshotpath()
1364{
1365 echo "$(getsdcardpath)/Pictures/Screenshots"
1366}
1367
1368function getlastscreenshot()
1369{
1370 local screenshot_path=$(getscreenshotpath)
1371 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1372 if [ "$screenshot" = "" ]; then
1373 echo "No screenshots found."
1374 return
1375 fi
1376 echo "${screenshot}"
1377 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1378}
1379
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001380function startviewserver()
1381{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001382 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001383 if [ $# -gt 0 ]; then
1384 port=$1
1385 fi
1386 adb shell service call window 1 i32 $port
1387}
1388
1389function stopviewserver()
1390{
1391 adb shell service call window 2
1392}
1393
1394function isviewserverstarted()
1395{
1396 adb shell service call window 3
1397}
1398
Romain Guyb84049a2010-10-04 16:56:11 -07001399function key_home()
1400{
1401 adb shell input keyevent 3
1402}
1403
1404function key_back()
1405{
1406 adb shell input keyevent 4
1407}
1408
1409function key_menu()
1410{
1411 adb shell input keyevent 82
1412}
1413
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001414function smoketest()
1415{
1416 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1417 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1418 return
1419 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001420 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001421 if [ ! "$T" ]; then
1422 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1423 return
1424 fi
1425
Ying Wang9cd17642012-12-13 10:52:07 -08001426 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001427 adb uninstall com.android.smoketest > /dev/null &&
1428 adb uninstall com.android.smoketest.tests > /dev/null &&
1429 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1430 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1431 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1432}
1433
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001434# simple shortcut to the runtest command
1435function runtest()
1436{
Christopher Ferris55257d22017-03-23 11:08:58 -07001437 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001438 if [ ! "$T" ]; then
1439 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1440 return
1441 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001442 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001443}
1444
The Android Open Source Project88b60792009-03-03 19:28:42 -08001445function godir () {
1446 if [[ -z "$1" ]]; then
1447 echo "Usage: godir <regex>"
1448 return
1449 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001450 local T=$(gettop)
1451 local FILELIST
Brian Carlstromf2257422015-09-30 20:28:54 -07001452 if [ ! "$OUT_DIR" = "" ]; then
1453 mkdir -p $OUT_DIR
1454 FILELIST=$OUT_DIR/filelist
1455 else
1456 FILELIST=$T/filelist
1457 fi
1458 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001459 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001460 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001461 echo " Done"
1462 echo ""
1463 fi
1464 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001465 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001466 if [[ ${#lines[@]} = 0 ]]; then
1467 echo "Not found"
1468 return
1469 fi
1470 local pathname
1471 local choice
1472 if [[ ${#lines[@]} > 1 ]]; then
1473 while [[ -z "$pathname" ]]; do
1474 local index=1
1475 local line
1476 for line in ${lines[@]}; do
1477 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001478 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001479 done
1480 echo
1481 echo -n "Select one: "
1482 unset choice
1483 read choice
1484 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1485 echo "Invalid choice"
1486 continue
1487 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001488 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001489 done
1490 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001491 pathname=${lines[0]}
1492 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001493 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001494}
1495
Steven Moreland62054a42018-12-06 10:11:40 -08001496# Update module-info.json in out.
1497function refreshmod() {
1498 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1499 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1500 return 1
1501 fi
1502
1503 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1504
1505 # for the output of the next command
1506 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1507
1508 # Note, can't use absolute path because of the way make works.
1509 m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \
1510 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1511}
1512
1513# List all modules for the current device, as cached in module-info.json. If any build change is
1514# made and it should be reflected in the output, you should run 'refreshmod' first.
1515function allmod() {
1516 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1517 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1518 return 1
1519 fi
1520
1521 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1522 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1523 refreshmod || return 1
1524 fi
1525
1526 python -c "import json; print '\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys()))"
1527}
1528
Rett Berg78d1c932019-01-24 14:34:23 -08001529# 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 -08001530# is made, and it should be reflected in the output, you should run 'refreshmod' first.
Rett Berg78d1c932019-01-24 14:34:23 -08001531function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001532 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1533 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1534 return 1
1535 fi
1536
1537 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001538 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001539 return 1
1540 fi
1541
1542 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1543 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1544 refreshmod || return 1
1545 fi
1546
1547 local relpath=$(python -c "import json, os
1548module = '$1'
1549module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1550if module not in module_info:
1551 exit(1)
1552print module_info[module]['path'][0]" 2>/dev/null)
1553
1554 if [ -z "$relpath" ]; then
1555 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1556 return 1
1557 else
Rett Berg78d1c932019-01-24 14:34:23 -08001558 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001559 fi
1560}
1561
Rett Berg78d1c932019-01-24 14:34:23 -08001562# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1563# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1564function gomod() {
1565 if [[ $# -ne 1 ]]; then
1566 echo "usage: gomod <module>" >&2
1567 return 1
1568 fi
1569
1570 local path="$(pathmod $@)"
1571 if [ -z "$path" ]; then
1572 return 1
1573 fi
1574 cd $path
1575}
1576
dimitry73b84812018-12-11 18:06:00 +01001577function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001578 local word=${COMP_WORDS[COMP_CWORD]}
1579 COMPREPLY=( $(allmod | grep -E "^$word") )
1580}
1581
Alex Rayf0d08eb2013-03-08 15:15:06 -08001582# Print colored exit condition
1583function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001584 "$@"
1585 local retval=$?
1586 if [ $retval -ne 0 ]
1587 then
Jacky Cao89483b82015-05-15 22:12:53 +08001588 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001589 else
Jacky Cao89483b82015-05-15 22:12:53 +08001590 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001591 fi
1592 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001593}
1594
Ying Wanged21d4c2014-08-24 22:14:19 -07001595function get_make_command()
1596{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001597 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1598 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001599 # Always use the real make if -C is passed in
1600 for arg in "$@"; do
1601 if [[ $arg == -C* ]]; then
1602 echo command make
1603 return
1604 fi
1605 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001606 echo build/soong/soong_ui.bash --make-mode
1607 else
1608 echo command make
1609 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001610}
1611
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001612function _wrap_build()
Ed Heylcc6be0a2014-06-18 14:55:58 -07001613{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001614 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1615 "$@"
1616 return $?
1617 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001618 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001619 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001620 local ret=$?
1621 local end_time=$(date +"%s")
1622 local tdiff=$(($end_time-$start_time))
1623 local hours=$(($tdiff / 3600 ))
1624 local mins=$((($tdiff % 3600) / 60))
1625 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001626 local ncolors=$(tput colors 2>/dev/null)
1627 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001628 color_failed=$'\E'"[0;31m"
1629 color_success=$'\E'"[0;32m"
1630 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001631 else
1632 color_failed=""
1633 color_success=""
1634 color_reset=""
1635 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001636 echo
1637 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001638 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001639 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001640 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001641 fi
1642 if [ $hours -gt 0 ] ; then
1643 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1644 elif [ $mins -gt 0 ] ; then
1645 printf "(%02g:%02g (mm:ss))" $mins $secs
1646 elif [ $secs -gt 0 ] ; then
1647 printf "(%s seconds)" $secs
1648 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001649 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001650 echo
1651 return $ret
1652}
1653
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001654function make()
1655{
Dan Willemsene9842242017-07-28 13:00:13 -07001656 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001657}
1658
David Zeuthen1b126ff2015-09-30 17:10:48 -04001659function provision()
1660{
1661 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1662 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1663 return 1
1664 fi
1665 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1666 echo "There is no provisioning script for the device." >&2
1667 return 1
1668 fi
1669
1670 # Check if user really wants to do this.
1671 if [ "$1" = "--no-confirmation" ]; then
1672 shift 1
1673 else
1674 echo "This action will reflash your device."
1675 echo ""
1676 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1677 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001678 echo -n "Are you sure you want to do this (yes/no)? "
1679 read
David Zeuthen1b126ff2015-09-30 17:10:48 -04001680 if [[ "${REPLY}" != "yes" ]] ; then
1681 echo "Not taking any action. Exiting." >&2
1682 return 1
1683 fi
1684 fi
1685 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1686}
1687
Jim Tanga881a252018-06-19 16:34:41 +08001688# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001689function enable_zsh_completion() {
1690 # Don't override user's options if bash-style completion is already enabled.
1691 if ! declare -f complete >/dev/null; then
1692 autoload -U compinit && compinit
1693 autoload -U bashcompinit && bashcompinit
1694 fi
Jim Tanga881a252018-06-19 16:34:41 +08001695}
1696
1697function validate_current_shell() {
1698 local current_sh="$(ps -o command -p $$)"
1699 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001700 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001701 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001702 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001703 *zsh*)
1704 function check_type() { type "$1"; }
Patrik Fimmldf248e62018-10-15 18:15:12 +02001705 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001706 *)
Jim Tanga881a252018-06-19 16:34:41 +08001707 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 -07001708 ;;
1709 esac
Jim Tanga881a252018-06-19 16:34:41 +08001710}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001711
1712# Execute the contents of any vendorsetup.sh files we can find.
Jim Tanga881a252018-06-19 16:34:41 +08001713function source_vendorsetup() {
1714 for dir in device vendor product; do
1715 for f in $(test -d $dir && \
1716 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
1717 echo "including $f"; . $f
1718 done
1719 done
1720}
Kenny Root52aa81c2011-07-15 11:07:06 -07001721
Jim Tanga881a252018-06-19 16:34:41 +08001722validate_current_shell
1723source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001724addcompletions