blob: a03f02de58c06242372885a620c18af5428554ba [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
Ying Wangaa1c9b52012-11-26 20:51:59 -0800270 export PATH=$ANDROID_BUILD_PATHS$PATH
Jim Tang22f4c322018-12-17 15:21:53 +0800271
272 # out with the duplicate old
273 if [ -n $ANDROID_PYTHONPATH ]; then
274 export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
275 fi
276 # and in with the new
277 export ANDROID_PYTHONPATH=$T/development/python-packages:
278 export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800279
Colin Crosse97e6932017-06-30 16:01:45 -0700280 export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
281 export JAVA_HOME=$ANDROID_JAVA_HOME
282 export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
283 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
284 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500285
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800286 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700287 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
288 export OUT=$ANDROID_PRODUCT_OUT
289
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700290 unset ANDROID_HOST_OUT
291 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
292
Simran Basidd050ed2017-02-13 13:46:48 -0800293 unset ANDROID_HOST_OUT_TESTCASES
294 export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
295
296 unset ANDROID_TARGET_OUT_TESTCASES
297 export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
298
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800299 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300 # TODO: fix the path
301 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
302}
303
304function printconfig()
305{
Christopher Ferris55257d22017-03-23 11:08:58 -0700306 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800307 if [ ! "$T" ]; then
308 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
309 return
310 fi
311 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700312}
313
314function set_stuff_for_environment()
315{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 setpaths
317 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700318
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800319 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700320 # With this environment variable new GCC can apply colors to warnings/errors
321 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 -0700322 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700323}
324
325function set_sequence_number()
326{
Colin Cross88737132017-03-21 17:41:03 -0700327 export BUILD_ENV_SEQUENCE_NUMBER=13
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700328}
329
Makoto Onukida971062018-06-18 10:15:19 -0700330# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
331function should_add_completion() {
Jim Tanga881a252018-06-19 16:34:41 +0800332 local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
Makoto Onukida971062018-06-18 10:15:19 -0700333 case :"$ENVSETUP_NO_COMPLETION": in
Jim Tanga881a252018-06-19 16:34:41 +0800334 *:"$cmd":*)
335 return 1
336 ;;
Makoto Onukida971062018-06-18 10:15:19 -0700337 esac
338 return 0
339}
340
Kenny Root52aa81c2011-07-15 11:07:06 -0700341function addcompletions()
342{
343 local T dir f
344
Jim Tanga881a252018-06-19 16:34:41 +0800345 # Keep us from trying to run in something that's neither bash nor zsh.
346 if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700347 return
348 fi
349
350 # Keep us from trying to run in bash that's too old.
Jim Tanga881a252018-06-19 16:34:41 +0800351 if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700352 return
353 fi
354
Jim Tanga881a252018-06-19 16:34:41 +0800355 local completion_files=(
356 system/core/adb/adb.bash
357 system/core/fastboot/fastboot.bash
Chen Xua1cc5582019-02-08 21:52:59 +0000358 tools/tradefederation/core/atest/atest_completion.sh
Jim Tanga881a252018-06-19 16:34:41 +0800359 )
Makoto Onukida971062018-06-18 10:15:19 -0700360 # Completion can be disabled selectively to allow users to use non-standard completion.
361 # e.g.
362 # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
363 # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
Jim Tanga881a252018-06-19 16:34:41 +0800364 for f in ${completion_files[*]}; do
365 if [ -f "$f" ] && should_add_completion "$f"; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700366 . $f
Elliott Hughesce18dd42018-04-03 13:49:48 -0700367 fi
368 done
Joe Onorato002a6c72016-10-20 16:39:49 -0700369
Makoto Onukida971062018-06-18 10:15:19 -0700370 if should_add_completion bit ; then
371 complete -C "bit --tab" bit
372 fi
Jim Tanga881a252018-06-19 16:34:41 +0800373 complete -F _lunch lunch
Steven Moreland62054a42018-12-06 10:11:40 -0800374
dimitry73b84812018-12-11 18:06:00 +0100375 complete -F _complete_android_module_names gomod
376 complete -F _complete_android_module_names m
Kenny Root52aa81c2011-07-15 11:07:06 -0700377}
378
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700379function choosetype()
380{
381 echo "Build type choices are:"
382 echo " 1. release"
383 echo " 2. debug"
384 echo
385
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800386 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700387 DEFAULT_NUM=1
388 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700389
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800390 export TARGET_BUILD_TYPE=
391 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700392 while [ -z $TARGET_BUILD_TYPE ]
393 do
394 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800395 if [ -z "$1" ] ; then
396 read ANSWER
397 else
398 echo $1
399 ANSWER=$1
400 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700401 case $ANSWER in
402 "")
403 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
404 ;;
405 1)
406 export TARGET_BUILD_TYPE=release
407 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800408 release)
409 export TARGET_BUILD_TYPE=release
410 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700411 2)
412 export TARGET_BUILD_TYPE=debug
413 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800414 debug)
415 export TARGET_BUILD_TYPE=debug
416 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700417 *)
418 echo
419 echo "I didn't understand your response. Please try again."
420 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700421 ;;
422 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800423 if [ -n "$1" ] ; then
424 break
425 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700426 done
427
Ying Wang08800fd2016-03-03 20:57:21 -0800428 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700429 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800430 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700431}
432
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800433#
434# This function isn't really right: It chooses a TARGET_PRODUCT
435# based on the list of boards. Usually, that gets you something
436# that kinda works with a generic product, but really, you should
437# pick a product by name.
438#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700439function chooseproduct()
440{
Christopher Ferris55257d22017-03-23 11:08:58 -0700441 local default_value
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700442 if [ "x$TARGET_PRODUCT" != x ] ; then
443 default_value=$TARGET_PRODUCT
444 else
Ying Wang0a76df52015-06-08 11:57:26 -0700445 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446 fi
447
Ying Wang08800fd2016-03-03 20:57:21 -0800448 export TARGET_BUILD_APPS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800449 export TARGET_PRODUCT=
450 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700451 while [ -z "$TARGET_PRODUCT" ]
452 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700453 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800454 if [ -z "$1" ] ; then
455 read ANSWER
456 else
457 echo $1
458 ANSWER=$1
459 fi
460
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461 if [ -z "$ANSWER" ] ; then
462 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800463 else
464 if check_product $ANSWER
465 then
466 export TARGET_PRODUCT=$ANSWER
467 else
468 echo "** Not a valid product: $ANSWER"
469 fi
470 fi
471 if [ -n "$1" ] ; then
472 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 fi
474 done
475
Ying Wang08800fd2016-03-03 20:57:21 -0800476 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700477 set_stuff_for_environment
Ying Wang08800fd2016-03-03 20:57:21 -0800478 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700479}
480
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800481function choosevariant()
482{
483 echo "Variant choices are:"
484 local index=1
485 local v
486 for v in ${VARIANT_CHOICES[@]}
487 do
488 # The product name is the name of the directory containing
489 # the makefile we found, above.
490 echo " $index. $v"
491 index=$(($index+1))
492 done
493
494 local default_value=eng
495 local ANSWER
496
497 export TARGET_BUILD_VARIANT=
498 while [ -z "$TARGET_BUILD_VARIANT" ]
499 do
500 echo -n "Which would you like? [$default_value] "
501 if [ -z "$1" ] ; then
502 read ANSWER
503 else
504 echo $1
505 ANSWER=$1
506 fi
507
508 if [ -z "$ANSWER" ] ; then
509 export TARGET_BUILD_VARIANT=$default_value
510 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
511 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800512 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800513 fi
514 else
515 if check_variant $ANSWER
516 then
517 export TARGET_BUILD_VARIANT=$ANSWER
518 else
519 echo "** Not a valid variant: $ANSWER"
520 fi
521 fi
522 if [ -n "$1" ] ; then
523 break
524 fi
525 done
526}
527
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700528function choosecombo()
529{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700530 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700531
532 echo
533 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700534 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700535
536 echo
537 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700538 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800539
540 echo
Ying Wang08800fd2016-03-03 20:57:21 -0800541 build_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700542 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800543 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800544 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700545}
546
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800547# Clear this variable. It will be built up again when the vendorsetup.sh
548# files are included at the end of this file.
549unset LUNCH_MENU_CHOICES
550function add_lunch_combo()
551{
552 local new_combo=$1
553 local c
554 for c in ${LUNCH_MENU_CHOICES[@]} ; do
555 if [ "$new_combo" = "$c" ] ; then
556 return
557 fi
558 done
559 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
560}
561
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700562function print_lunch_menu()
563{
564 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700565 echo
566 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700567 echo
568 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800569
570 local i=1
571 local choice
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700572 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 -0800573 do
574 echo " $i. $choice"
575 i=$(($i+1))
576 done
577
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700578 echo
579}
580
581function lunch()
582{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800583 local answer
584
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800586 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700587 else
588 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700589 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591 fi
592
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800593 local selection=
594
595 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700597 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
599 then
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700600 local choices=($(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES))
601 if [ $answer -le ${#choices[@]} ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800602 then
Jim Tang0e3397b2018-10-03 18:25:50 +0800603 # array in zsh starts from 1 instead of 0.
604 if [ -n "$ZSH_VERSION" ]
605 then
606 selection=${choices[$(($answer))]}
607 else
608 selection=${choices[$(($answer-1))]}
609 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800610 fi
Colin Cross88737132017-03-21 17:41:03 -0700611 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800612 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700613 fi
614
Joe Onoratoda12daf2010-06-09 18:18:31 -0700615 export TARGET_BUILD_APPS=
616
Colin Cross88737132017-03-21 17:41:03 -0700617 local product variant_and_version variant version
618
619 product=${selection%%-*} # Trim everything after first dash
620 variant_and_version=${selection#*-} # Trim everything up to first dash
621 if [ "$variant_and_version" != "$selection" ]; then
622 variant=${variant_and_version%%-*}
623 if [ "$variant" != "$variant_and_version" ]; then
624 version=${variant_and_version#*-}
625 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700626 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800627
Colin Cross88737132017-03-21 17:41:03 -0700628 if [ -z "$product" ]
Ying Wang08800fd2016-03-03 20:57:21 -0800629 then
630 echo
Colin Cross88737132017-03-21 17:41:03 -0700631 echo "Invalid lunch combo: $selection"
Jeff Browne33ba4c2011-07-11 22:11:46 -0700632 return 1
633 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800634
Colin Cross88737132017-03-21 17:41:03 -0700635 TARGET_PRODUCT=$product \
636 TARGET_BUILD_VARIANT=$variant \
637 TARGET_PLATFORM_VERSION=$version \
638 build_build_var_cache
639 if [ $? -ne 0 ]
640 then
641 return 1
642 fi
643
644 export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
645 export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
Colin Crossb105e362017-05-01 14:21:28 -0700646 if [ -n "$version" ]; then
647 export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
648 else
649 unset TARGET_PLATFORM_VERSION
650 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -0700651 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700652
653 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800654
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700655 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800656 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800657 destroy_build_var_cache
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658}
659
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700660unset COMMON_LUNCH_CHOICES_CACHE
Jeff Davidson513d7a42010-08-02 10:00:44 -0700661# Tab completion for lunch.
662function _lunch()
663{
664 local cur prev opts
665 COMPREPLY=()
666 cur="${COMP_WORDS[COMP_CWORD]}"
667 prev="${COMP_WORDS[COMP_CWORD-1]}"
668
Dan Willemsenaf2e1f82018-04-04 15:41:41 -0700669 if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
670 COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES)
671 fi
672
673 COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
Jeff Davidson513d7a42010-08-02 10:00:44 -0700674 return 0
675}
Jeff Davidson513d7a42010-08-02 10:00:44 -0700676
Joe Onoratoda12daf2010-06-09 18:18:31 -0700677# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700678# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700679function tapas()
680{
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700681 local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
Dan Willemsendd3a2732018-01-08 15:26:16 -0800682 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700683 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700684 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 -0800685 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 -0700686
Jeff Gaston9fb05d82017-08-21 18:27:00 -0700687 if [ "$showHelp" != "" ]; then
688 $(gettop)/build/make/tapasHelp.sh
689 return
690 fi
691
Ying Wang67f02922012-08-22 10:25:20 -0700692 if [ $(echo $arch | wc -w) -gt 1 ]; then
693 echo "tapas: Error: Multiple build archs supplied: $arch"
694 return
695 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700696 if [ $(echo $variant | wc -w) -gt 1 ]; then
697 echo "tapas: Error: Multiple build variants supplied: $variant"
698 return
699 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700700 if [ $(echo $density | wc -w) -gt 1 ]; then
701 echo "tapas: Error: Multiple densities supplied: $density"
702 return
703 fi
Ying Wang67f02922012-08-22 10:25:20 -0700704
Ying Wang0a76df52015-06-08 11:57:26 -0700705 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700706 case $arch in
Ying Wang0a76df52015-06-08 11:57:26 -0700707 x86) product=aosp_x86;;
708 mips) product=aosp_mips;;
Ying Wangb541ab62014-05-29 17:57:40 -0700709 arm64) product=aosp_arm64;;
710 x86_64) product=aosp_x86_64;;
711 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700712 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700713 if [ -z "$variant" ]; then
714 variant=eng
715 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700716 if [ -z "$apps" ]; then
717 apps=all
718 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600719 if [ -z "$density" ]; then
720 density=alldpi
721 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700722
Ying Wang67f02922012-08-22 10:25:20 -0700723 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700724 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700725 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700726 export TARGET_BUILD_TYPE=release
727 export TARGET_BUILD_APPS=$apps
728
Ying Wang08800fd2016-03-03 20:57:21 -0800729 build_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700730 set_stuff_for_environment
731 printconfig
Ying Wang08800fd2016-03-03 20:57:21 -0800732 destroy_build_var_cache
Joe Onoratoda12daf2010-06-09 18:18:31 -0700733}
734
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700735function gettop
736{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700737 local TOPFILE=build/make/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700738 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700739 # The following circumlocution ensures we remove symlinks from TOP.
740 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700741 else
742 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800743 # The following circumlocution (repeated below as well) ensures
744 # that we record the true directory name and not one that is
745 # faked up with symlink names.
746 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700747 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800748 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700749 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700750 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800751 \cd ..
synergyb112a402013-07-05 19:47:47 -0700752 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700753 done
Ying Wang9cd17642012-12-13 10:52:07 -0800754 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700755 if [ -f "$T/$TOPFILE" ]; then
756 echo $T
757 fi
758 fi
759 fi
760}
761
762function m()
763{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800764 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700765 if [ "$T" ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800766 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700767 else
768 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700769 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700770 fi
771}
772
773function findmakefile()
774{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700775 local TOPFILE=build/make/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800776 local HERE=$PWD
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800777 if [ "$1" ]; then
778 \cd $1
779 fi;
Christopher Ferris55257d22017-03-23 11:08:58 -0700780 local T=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700781 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700782 T=`PWD= /bin/pwd`
Colin Cross86425252016-05-26 15:32:15 -0700783 if [ -f "$T/Android.mk" -o -f "$T/Android.bp" ]; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800785 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700786 return
787 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800788 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700789 done
Ying Wang9cd17642012-12-13 10:52:07 -0800790 \cd $HERE
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700791 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792}
793
794function mm()
795{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800796 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797 # If we're sitting in the root of the build tree, just do a
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700798 # normal build.
799 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800800 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 else
802 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800803 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700804 local MODULES=
805 local GET_INSTALL_PATH=
806 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700807 # Remove the path to top as the makefilepath needs to be relative
808 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700809 if [ ! "$T" ]; then
810 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700811 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700812 elif [ ! "$M" ]; then
813 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700814 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700815 else
Christopher Ferris55257d22017-03-23 11:08:58 -0700816 local ARG
Ying Wanga7deb082013-08-16 13:24:47 -0700817 for ARG in $@; do
818 case $ARG in
819 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
820 esac
821 done
822 if [ -n "$GET_INSTALL_PATH" ]; then
823 MODULES=
Dan Willemsen53e38992016-08-11 17:20:33 -0700824 ARGS=GET-INSTALL-PATH-IN-$(dirname ${M})
825 ARGS=${ARGS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700826 else
Colin Cross86425252016-05-26 15:32:15 -0700827 MODULES=MODULES-IN-$(dirname ${M})
828 # Convert "/" to "-".
829 MODULES=${MODULES//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700830 ARGS=$@
831 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700832 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
833 MODULES=tidy_only
834 fi
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800835 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 -0700836 fi
837 fi
838}
839
840function mmm()
841{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800842 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700843 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800844 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800845 local MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700846 local MODULES_IN_PATHS=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800847 local ARGS=
848 local DIR TO_CHOP
Colin Cross86425252016-05-26 15:32:15 -0700849 local DIR_MODULES
Ying Wanga7deb082013-08-16 13:24:47 -0700850 local GET_INSTALL_PATH=
Dan Willemsen53e38992016-08-11 17:20:33 -0700851 local GET_INSTALL_PATHS=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800852 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
853 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
854 for DIR in $DIRS ; do
Colin Cross86425252016-05-26 15:32:15 -0700855 DIR_MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
Alon Albert68895a92011-11-30 12:40:19 -0800856 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
Colin Cross86425252016-05-26 15:32:15 -0700857 # Remove the leading ./ and trailing / if any exists.
858 DIR=${DIR#./}
859 DIR=${DIR%/}
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800860 local M
861 if [ "$DIR_MODULES" = "" ]; then
862 M=$(findmakefile $DIR)
863 else
864 # Only check the target directory if a module is specified.
865 if [ -f $DIR/Android.mk -o -f $DIR/Android.bp ]; then
866 local HERE=$PWD
867 cd $DIR
868 M=`PWD= /bin/pwd`
869 M=$M/Android.mk
870 cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700871 fi
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800872 fi
873 if [ "$M" ]; then
874 # Remove the path to top as the makefilepath needs to be relative
875 local M=`echo $M|sed 's:'$T'/::'`
Colin Cross4bfae062016-08-31 17:22:36 -0700876 if [ "$DIR_MODULES" = "" ]; then
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800877 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$(dirname ${M})"
878 GET_INSTALL_PATHS="$GET_INSTALL_PATHS GET-INSTALL-PATH-IN-$(dirname ${M})"
Colin Cross4bfae062016-08-31 17:22:36 -0700879 else
880 MODULES="$MODULES $DIR_MODULES"
881 fi
Jaewoong Jungb6112cd2019-01-02 13:36:48 -0800882 MAKEFILE="$MAKEFILE $M"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700883 else
Ying Wanga7deb082013-08-16 13:24:47 -0700884 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700885 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700886 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
Abhinav1997a72a6e72015-10-18 20:25:48 +0200887 *) if [ -d $DIR ]; then
888 echo "No Android.mk in $DIR.";
889 else
890 echo "Couldn't locate the directory $DIR";
891 fi
892 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700893 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700894 fi
895 done
Ying Wanga7deb082013-08-16 13:24:47 -0700896 if [ -n "$GET_INSTALL_PATH" ]; then
Dan Willemsen53e38992016-08-11 17:20:33 -0700897 ARGS=${GET_INSTALL_PATHS//\//-}
Ying Wanga7deb082013-08-16 13:24:47 -0700898 MODULES=
Colin Cross86425252016-05-26 15:32:15 -0700899 MODULES_IN_PATHS=
Ying Wanga7deb082013-08-16 13:24:47 -0700900 fi
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700901 if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then
902 MODULES=tidy_only
Colin Cross86425252016-05-26 15:32:15 -0700903 MODULES_IN_PATHS=
Chih-Hung Hsieha9a55c72016-03-31 16:30:23 -0700904 fi
Colin Cross86425252016-05-26 15:32:15 -0700905 # Convert "/" to "-".
906 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800907 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 -0700908 else
909 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700910 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700911 fi
912}
913
Ying Wangb607f7b2013-02-08 18:01:04 -0800914function mma()
915{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800916 local T=$(gettop)
Dan Willemsend41ec5a2017-07-12 16:14:50 -0700917 if [ -f build/soong/soong_ui.bash ]; then
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800918 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800919 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800920 if [ ! "$T" ]; then
921 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700922 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800923 fi
Steven Moreland3b99ecf2018-06-13 15:31:59 -0700924 local M=$(findmakefile || echo $(realpath $PWD)/Android.mk)
Colin Cross127fcea2016-09-01 15:30:18 -0700925 # Remove the path to top as the makefilepath needs to be relative
926 local M=`echo $M|sed 's:'$T'/::'`
927 local MODULES_IN_PATHS=MODULES-IN-$(dirname ${M})
Ying Wang61cd8842015-09-24 16:19:19 -0700928 # Convert "/" to "-".
929 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800930 _wrap_build $T/build/soong/soong_ui.bash --make-mode $@ $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800931 fi
932}
933
934function mmma()
935{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800936 local T=$(gettop)
Ying Wangb607f7b2013-02-08 18:01:04 -0800937 if [ "$T" ]; then
938 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
939 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
940 local MY_PWD=`PWD= /bin/pwd`
941 if [ "$MY_PWD" = "$T" ]; then
942 MY_PWD=
943 else
944 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
945 fi
946 local DIR=
Ying Wangcaeaa082015-09-23 16:08:55 -0700947 local MODULES_IN_PATHS=
Ying Wangb607f7b2013-02-08 18:01:04 -0800948 local ARGS=
949 for DIR in $DIRS ; do
950 if [ -d $DIR ]; then
Ying Wangcaeaa082015-09-23 16:08:55 -0700951 # Remove the leading ./ and trailing / if any exists.
952 DIR=${DIR#./}
953 DIR=${DIR%/}
954 if [ "$MY_PWD" != "" ]; then
955 DIR=$MY_PWD/$DIR
Ying Wangb607f7b2013-02-08 18:01:04 -0800956 fi
Ying Wang61cd8842015-09-24 16:19:19 -0700957 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
Ying Wangb607f7b2013-02-08 18:01:04 -0800958 else
959 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700960 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800961 *) echo "Couldn't find directory $DIR"; return 1;;
962 esac
963 fi
964 done
Ying Wang61cd8842015-09-24 16:19:19 -0700965 # Convert "/" to "-".
966 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
Chih-Hung Hsieh7ed0db82018-02-15 11:20:04 -0800967 _wrap_build $T/build/soong/soong_ui.bash --make-mode $DASH_ARGS $ARGS $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800968 else
969 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700970 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800971 fi
972}
973
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700974function croot()
975{
Christopher Ferris55257d22017-03-23 11:08:58 -0700976 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700977 if [ "$T" ]; then
Marie Janssen32ec50a2016-04-21 16:53:39 -0700978 if [ "$1" ]; then
979 \cd $(gettop)/$1
980 else
981 \cd $(gettop)
982 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700983 else
984 echo "Couldn't locate the top of the tree. Try setting TOP."
985 fi
986}
987
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700988function cproj()
989{
Colin Cross6cdc5d22017-10-20 11:37:33 -0700990 local TOPFILE=build/make/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700991 local HERE=$PWD
Christopher Ferris55257d22017-03-23 11:08:58 -0700992 local T=
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700993 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
994 T=$PWD
995 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800996 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700997 return
998 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800999 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001000 done
Ying Wang9cd17642012-12-13 10:52:07 -08001001 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001002 echo "can't find Android.mk"
1003}
1004
Daniel Sandler47e0a882013-07-30 13:23:52 -04001005# simplified version of ps; output in the form
1006# <pid> <procname>
1007function qpid() {
1008 local prepend=''
1009 local append=''
1010 if [ "$1" = "--exact" ]; then
1011 prepend=' '
1012 append='$'
1013 shift
1014 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
Ying Wang08800fd2016-03-03 20:57:21 -08001015 echo "usage: qpid [[--exact] <process name|pid>"
1016 return 255
1017 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001018
1019 local EXE="$1"
1020 if [ "$EXE" ] ; then
Ying Wang08800fd2016-03-03 20:57:21 -08001021 qpid | \grep "$prepend$EXE$append"
1022 else
1023 adb shell ps \
1024 | tr -d '\r' \
1025 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1026 fi
Daniel Sandler47e0a882013-07-30 13:23:52 -04001027}
1028
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001029# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001030# that has the core-file-size limit set correctly
1031#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001032# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001033# if its core-file-size limit is not set already.
1034# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1035
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001036function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001037{
Ying Wang08800fd2016-03-03 20:57:21 -08001038 echo "Getting root...";
1039 adb root;
1040 adb wait-for-device;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001041
Ying Wang08800fd2016-03-03 20:57:21 -08001042 echo "Remounting root partition read-write...";
1043 adb shell mount -w -o remount -t rootfs rootfs;
1044 sleep 1;
1045 adb wait-for-device;
1046 adb shell mkdir -p /cores;
1047 adb shell mount -t tmpfs tmpfs /cores;
1048 adb shell chmod 0777 /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001049
Ying Wang08800fd2016-03-03 20:57:21 -08001050 echo "Granting SELinux permission to dump in /cores...";
1051 adb shell restorecon -R /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001052
Ying Wang08800fd2016-03-03 20:57:21 -08001053 echo "Set core pattern.";
1054 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001055
Ying Wang08800fd2016-03-03 20:57:21 -08001056 echo "Done."
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001057}
1058
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001059# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001060# $1 = PID of process (e.g., $(pid mediaserver))
1061#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001062# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001063# dump to actually be generated.
1064
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001065function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001066{
Ying Wang08800fd2016-03-03 20:57:21 -08001067 local PID=$1;
1068 if [ -z "$PID" ]; then
1069 printf "Expecting a PID!\n";
1070 return;
1071 fi;
1072 echo "Setting core limit for $PID to infinite...";
Elliott Hughes910a3552016-03-07 13:53:53 -08001073 adb shell /system/bin/ulimit -p $PID -c unlimited
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001074}
1075
1076# core - send SIGV and pull the core for process
1077# $1 = PID of process (e.g., $(pid mediaserver))
1078#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001079# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001080# enabled globally.
1081
1082function core()
1083{
Ying Wang08800fd2016-03-03 20:57:21 -08001084 local PID=$1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001085
Ying Wang08800fd2016-03-03 20:57:21 -08001086 if [ -z "$PID" ]; then
1087 printf "Expecting a PID!\n";
1088 return;
1089 fi;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001090
Ying Wang08800fd2016-03-03 20:57:21 -08001091 local CORENAME=core.$PID;
1092 local COREPATH=/cores/$CORENAME;
1093 local SIG=SEGV;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001094
Ying Wang08800fd2016-03-03 20:57:21 -08001095 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001096
Ying Wang08800fd2016-03-03 20:57:21 -08001097 local done=0;
1098 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1099 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1100 adb shell kill -$SIG $PID;
1101 sleep 1;
1102 done;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001103
Ying Wang08800fd2016-03-03 20:57:21 -08001104 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1105 echo "Done: core is under $COREPATH on device.";
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001106}
1107
Christopher Tate744ee802009-11-12 15:33:08 -08001108# systemstack - dump the current stack trace of all threads in the system process
1109# to the usual ANR traces file
1110function systemstack()
1111{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001112 stacks system_server
1113}
1114
Michael Wrightaeed7212014-06-19 19:58:12 -07001115# Read the ELF header from /proc/$PID/exe to determine if the process is
1116# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001117function is64bit()
1118{
1119 local PID="$1"
1120 if [ "$PID" ] ; then
Elliott Hughesd3e47252018-11-15 16:32:14 -08001121 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001122 echo "64"
1123 else
1124 echo ""
1125 fi
1126 else
1127 echo ""
1128 fi
1129}
1130
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001131case `uname -s` in
1132 Darwin)
1133 function sgrep()
1134 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001135 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 -04001136 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001137 }
1138
1139 ;;
1140 *)
1141 function sgrep()
1142 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001143 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 -04001144 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001145 }
1146 ;;
1147esac
1148
Raghu Gandham8da43102012-07-25 19:57:22 -07001149function gettargetarch
1150{
1151 get_build_var TARGET_ARCH
1152}
1153
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001154function ggrep()
1155{
Mike Frysinger5e479732015-09-22 18:13:48 -04001156 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1157 -exec grep --color -n "$@" {} +
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001158}
1159
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001160function jgrep()
1161{
Mike Frysinger5e479732015-09-22 18:13:48 -04001162 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1163 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001164}
1165
1166function cgrep()
1167{
Mike Frysinger5e479732015-09-22 18:13:48 -04001168 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' \) \
1169 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001170}
1171
1172function resgrep()
1173{
Christopher Ferris55257d22017-03-23 11:08:58 -07001174 local dir
Mike Frysinger5e479732015-09-22 18:13:48 -04001175 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1176 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1177 done
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001178}
1179
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001180function mangrep()
1181{
Mike Frysinger5e479732015-09-22 18:13:48 -04001182 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1183 -exec grep --color -n "$@" {} +
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001184}
1185
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001186function sepgrep()
1187{
Mike Frysinger5e479732015-09-22 18:13:48 -04001188 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1189 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001190}
1191
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001192function rcgrep()
1193{
Mike Frysinger5e479732015-09-22 18:13:48 -04001194 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1195 -exec grep --color -n "$@" {} +
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001196}
1197
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001198case `uname -s` in
1199 Darwin)
1200 function mgrep()
1201 {
David Grossd1d6fc52017-05-10 10:49:44 -07001202 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 -04001203 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001204 }
1205
1206 function treegrep()
1207 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001208 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 -04001209 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001210 }
1211
1212 ;;
1213 *)
1214 function mgrep()
1215 {
David Grossd1d6fc52017-05-10 10:49:44 -07001216 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 -04001217 -exec grep --color -n "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001218 }
1219
1220 function treegrep()
1221 {
Aurelio Jargas67edd152018-11-06 17:25:11 +01001222 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 -04001223 -exec grep --color -n -i "$@" {} +
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001224 }
1225
1226 ;;
1227esac
1228
1229function getprebuilt
1230{
1231 get_abs_build_var ANDROID_PREBUILTS
1232}
1233
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001234function tracedmdump()
1235{
Christopher Ferris55257d22017-03-23 11:08:58 -07001236 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001237 if [ ! "$T" ]; then
1238 echo "Couldn't locate the top of the tree. Try setting TOP."
1239 return
1240 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001241 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001242 local arch=$(gettargetarch)
1243 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001244
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001245 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001246 if [ ! "$TRACE" ] ; then
1247 echo "usage: tracedmdump tracename"
1248 return
1249 fi
1250
Jack Veenstra60116fc2009-04-09 18:12:34 -07001251 if [ ! -r "$KERNEL" ] ; then
1252 echo "Error: cannot find kernel: '$KERNEL'"
1253 return
1254 fi
1255
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001256 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001257 if [ "$BASETRACE" = "$TRACE" ] ; then
1258 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1259 fi
1260
1261 echo "post-processing traces..."
1262 rm -f $TRACE/qtrace.dexlist
1263 post_trace $TRACE
1264 if [ $? -ne 0 ]; then
1265 echo "***"
1266 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1267 echo "***"
1268 return
1269 fi
1270 echo "generating dexlist output..."
1271 /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
1272 echo "generating dmtrace data..."
1273 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1274 echo "generating html file..."
1275 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1276 echo "done, see $TRACE/dmtrace.html for details"
1277 echo "or run:"
1278 echo " traceview $TRACE/dmtrace"
1279}
1280
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001281# communicate with a running device or emulator, set up necessary state,
1282# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001283function runhat()
1284{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001285 # process standard adb options
1286 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001287 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001288 adbTarget=$1
1289 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001290 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001291 adbTarget="$1 $2"
1292 shift 2
1293 fi
1294 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001295 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001296
1297 # runhat options
1298 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001299
1300 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001301 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001302 return
1303 fi
1304
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001305 # confirm hat is available
1306 if [ -z $(which hat) ]; then
1307 echo "hat is not available in this configuration."
1308 return
1309 fi
1310
Andy McFaddenb6289852010-07-12 08:00:19 -07001311 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001312 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001313 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001314 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001315 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001316 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001317 echo -n "> "
1318 read
1319
The Android Open Source Project88b60792009-03-03 19:28:42 -08001320 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001321
The Android Open Source Project88b60792009-03-03 19:28:42 -08001322 echo "Retrieving file $devFile..."
1323 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001324
The Android Open Source Project88b60792009-03-03 19:28:42 -08001325 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001326
The Android Open Source Project88b60792009-03-03 19:28:42 -08001327 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001328 echo "View the output by pointing your browser at http://localhost:7000/"
1329 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001330 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001331}
1332
1333function getbugreports()
1334{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001335 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001336
1337 if [ ! "$reports" ]; then
1338 echo "Could not locate any bugreports."
1339 return
1340 fi
1341
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001342 local report
1343 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001344 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001345 echo "/sdcard/bugreports/${report}"
1346 adb pull /sdcard/bugreports/${report} ${report}
1347 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001348 done
1349}
1350
Victoria Lease1b296b42012-08-21 15:44:06 -07001351function getsdcardpath()
1352{
1353 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1354}
1355
1356function getscreenshotpath()
1357{
1358 echo "$(getsdcardpath)/Pictures/Screenshots"
1359}
1360
1361function getlastscreenshot()
1362{
1363 local screenshot_path=$(getscreenshotpath)
1364 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1365 if [ "$screenshot" = "" ]; then
1366 echo "No screenshots found."
1367 return
1368 fi
1369 echo "${screenshot}"
1370 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1371}
1372
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001373function startviewserver()
1374{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001375 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001376 if [ $# -gt 0 ]; then
1377 port=$1
1378 fi
1379 adb shell service call window 1 i32 $port
1380}
1381
1382function stopviewserver()
1383{
1384 adb shell service call window 2
1385}
1386
1387function isviewserverstarted()
1388{
1389 adb shell service call window 3
1390}
1391
Romain Guyb84049a2010-10-04 16:56:11 -07001392function key_home()
1393{
1394 adb shell input keyevent 3
1395}
1396
1397function key_back()
1398{
1399 adb shell input keyevent 4
1400}
1401
1402function key_menu()
1403{
1404 adb shell input keyevent 82
1405}
1406
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001407function smoketest()
1408{
1409 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1410 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1411 return
1412 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001413 local T=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001414 if [ ! "$T" ]; then
1415 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1416 return
1417 fi
1418
Ying Wang9cd17642012-12-13 10:52:07 -08001419 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001420 adb uninstall com.android.smoketest > /dev/null &&
1421 adb uninstall com.android.smoketest.tests > /dev/null &&
1422 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1423 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1424 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1425}
1426
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001427# simple shortcut to the runtest command
1428function runtest()
1429{
Christopher Ferris55257d22017-03-23 11:08:58 -07001430 local T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001431 if [ ! "$T" ]; then
1432 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1433 return
1434 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001435 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001436}
1437
The Android Open Source Project88b60792009-03-03 19:28:42 -08001438function godir () {
1439 if [[ -z "$1" ]]; then
1440 echo "Usage: godir <regex>"
1441 return
1442 fi
Christopher Ferris55257d22017-03-23 11:08:58 -07001443 local T=$(gettop)
1444 local FILELIST
Brian Carlstromf2257422015-09-30 20:28:54 -07001445 if [ ! "$OUT_DIR" = "" ]; then
1446 mkdir -p $OUT_DIR
1447 FILELIST=$OUT_DIR/filelist
1448 else
1449 FILELIST=$T/filelist
1450 fi
1451 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001452 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001453 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001454 echo " Done"
1455 echo ""
1456 fi
1457 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001458 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001459 if [[ ${#lines[@]} = 0 ]]; then
1460 echo "Not found"
1461 return
1462 fi
1463 local pathname
1464 local choice
1465 if [[ ${#lines[@]} > 1 ]]; then
1466 while [[ -z "$pathname" ]]; do
1467 local index=1
1468 local line
1469 for line in ${lines[@]}; do
1470 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001471 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001472 done
1473 echo
1474 echo -n "Select one: "
1475 unset choice
1476 read choice
1477 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1478 echo "Invalid choice"
1479 continue
1480 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001481 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001482 done
1483 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001484 pathname=${lines[0]}
1485 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001486 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001487}
1488
Steven Moreland62054a42018-12-06 10:11:40 -08001489# Update module-info.json in out.
1490function refreshmod() {
1491 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1492 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1493 return 1
1494 fi
1495
1496 echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
1497
1498 # for the output of the next command
1499 mkdir -p $ANDROID_PRODUCT_OUT || return 1
1500
1501 # Note, can't use absolute path because of the way make works.
1502 m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \
1503 > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
1504}
1505
1506# List all modules for the current device, as cached in module-info.json. If any build change is
1507# made and it should be reflected in the output, you should run 'refreshmod' first.
1508function allmod() {
1509 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1510 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1511 return 1
1512 fi
1513
1514 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1515 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1516 refreshmod || return 1
1517 fi
1518
1519 python -c "import json; print '\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys()))"
1520}
1521
Rett Berg78d1c932019-01-24 14:34:23 -08001522# 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 -08001523# is made, and it should be reflected in the output, you should run 'refreshmod' first.
Rett Berg78d1c932019-01-24 14:34:23 -08001524function pathmod() {
Steven Moreland62054a42018-12-06 10:11:40 -08001525 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1526 echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
1527 return 1
1528 fi
1529
1530 if [[ $# -ne 1 ]]; then
Rett Berg78d1c932019-01-24 14:34:23 -08001531 echo "usage: pathmod <module>" >&2
Steven Moreland62054a42018-12-06 10:11:40 -08001532 return 1
1533 fi
1534
1535 if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
1536 echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
1537 refreshmod || return 1
1538 fi
1539
1540 local relpath=$(python -c "import json, os
1541module = '$1'
1542module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
1543if module not in module_info:
1544 exit(1)
1545print module_info[module]['path'][0]" 2>/dev/null)
1546
1547 if [ -z "$relpath" ]; then
1548 echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
1549 return 1
1550 else
Rett Berg78d1c932019-01-24 14:34:23 -08001551 echo "$ANDROID_BUILD_TOP/$relpath"
Steven Moreland62054a42018-12-06 10:11:40 -08001552 fi
1553}
1554
Rett Berg78d1c932019-01-24 14:34:23 -08001555# Go to a specific module in the android tree, as cached in module-info.json. If any build change
1556# is made, and it should be reflected in the output, you should run 'refreshmod' first.
1557function gomod() {
1558 if [[ $# -ne 1 ]]; then
1559 echo "usage: gomod <module>" >&2
1560 return 1
1561 fi
1562
1563 local path="$(pathmod $@)"
1564 if [ -z "$path" ]; then
1565 return 1
1566 fi
1567 cd $path
1568}
1569
dimitry73b84812018-12-11 18:06:00 +01001570function _complete_android_module_names() {
Steven Moreland62054a42018-12-06 10:11:40 -08001571 local word=${COMP_WORDS[COMP_CWORD]}
1572 COMPREPLY=( $(allmod | grep -E "^$word") )
1573}
1574
Alex Rayf0d08eb2013-03-08 15:15:06 -08001575# Print colored exit condition
1576function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001577 "$@"
1578 local retval=$?
1579 if [ $retval -ne 0 ]
1580 then
Jacky Cao89483b82015-05-15 22:12:53 +08001581 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001582 else
Jacky Cao89483b82015-05-15 22:12:53 +08001583 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001584 fi
1585 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001586}
1587
Ying Wanged21d4c2014-08-24 22:14:19 -07001588function get_make_command()
1589{
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001590 # If we're in the top of an Android tree, use soong_ui.bash instead of make
1591 if [ -f build/soong/soong_ui.bash ]; then
Dan Willemsene9842242017-07-28 13:00:13 -07001592 # Always use the real make if -C is passed in
1593 for arg in "$@"; do
1594 if [[ $arg == -C* ]]; then
1595 echo command make
1596 return
1597 fi
1598 done
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001599 echo build/soong/soong_ui.bash --make-mode
1600 else
1601 echo command make
1602 fi
Ying Wanged21d4c2014-08-24 22:14:19 -07001603}
1604
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001605function _wrap_build()
Ed Heylcc6be0a2014-06-18 14:55:58 -07001606{
Sasha Smundak9f27cc02019-01-31 13:25:31 -08001607 if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
1608 "$@"
1609 return $?
1610 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001611 local start_time=$(date +"%s")
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001612 "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001613 local ret=$?
1614 local end_time=$(date +"%s")
1615 local tdiff=$(($end_time-$start_time))
1616 local hours=$(($tdiff / 3600 ))
1617 local mins=$((($tdiff % 3600) / 60))
1618 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001619 local ncolors=$(tput colors 2>/dev/null)
1620 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001621 color_failed=$'\E'"[0;31m"
1622 color_success=$'\E'"[0;32m"
1623 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001624 else
1625 color_failed=""
1626 color_success=""
1627 color_reset=""
1628 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001629 echo
1630 if [ $ret -eq 0 ] ; then
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001631 echo -n "${color_success}#### build completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001632 else
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001633 echo -n "${color_failed}#### failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001634 fi
1635 if [ $hours -gt 0 ] ; then
1636 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1637 elif [ $mins -gt 0 ] ; then
1638 printf "(%02g:%02g (mm:ss))" $mins $secs
1639 elif [ $secs -gt 0 ] ; then
1640 printf "(%s seconds)" $secs
1641 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001642 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001643 echo
1644 return $ret
1645}
1646
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001647function make()
1648{
Dan Willemsene9842242017-07-28 13:00:13 -07001649 _wrap_build $(get_make_command "$@") "$@"
Dan Willemsend41ec5a2017-07-12 16:14:50 -07001650}
1651
David Zeuthen1b126ff2015-09-30 17:10:48 -04001652function provision()
1653{
1654 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1655 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1656 return 1
1657 fi
1658 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
1659 echo "There is no provisioning script for the device." >&2
1660 return 1
1661 fi
1662
1663 # Check if user really wants to do this.
1664 if [ "$1" = "--no-confirmation" ]; then
1665 shift 1
1666 else
1667 echo "This action will reflash your device."
1668 echo ""
1669 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
1670 echo ""
Marie Janssen4afc2c02015-11-10 10:41:15 -08001671 echo -n "Are you sure you want to do this (yes/no)? "
1672 read
David Zeuthen1b126ff2015-09-30 17:10:48 -04001673 if [[ "${REPLY}" != "yes" ]] ; then
1674 echo "Not taking any action. Exiting." >&2
1675 return 1
1676 fi
1677 fi
1678 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
1679}
1680
Chen Xua1cc5582019-02-08 21:52:59 +00001681function atest()
1682{
1683 # Let's use the built version over the prebuilt, then source code.
1684 local os_arch=$(get_build_var HOST_PREBUILT_TAG)
1685 local built_atest=${ANDROID_HOST_OUT}/bin/atest
1686 local prebuilt_atest="$(gettop)"/prebuilts/asuite/atest/$os_arch/atest
1687 if [[ -x $built_atest ]]; then
1688 $built_atest "$@"
1689 elif [[ -x $prebuilt_atest ]]; then
1690 $prebuilt_atest "$@"
1691 else
1692 # TODO: once prebuilt atest released, remove the source code section
1693 # and change the location of atest_completion.sh in addcompletions().
1694 "$(gettop)"/tools/tradefederation/core/atest/atest.py "$@"
1695 fi
1696}
1697
Jim Tanga881a252018-06-19 16:34:41 +08001698# Zsh needs bashcompinit called to support bash-style completion.
Patrik Fimmldf248e62018-10-15 18:15:12 +02001699function enable_zsh_completion() {
1700 # Don't override user's options if bash-style completion is already enabled.
1701 if ! declare -f complete >/dev/null; then
1702 autoload -U compinit && compinit
1703 autoload -U bashcompinit && bashcompinit
1704 fi
Jim Tanga881a252018-06-19 16:34:41 +08001705}
1706
1707function validate_current_shell() {
1708 local current_sh="$(ps -o command -p $$)"
1709 case "$current_sh" in
Raphael Moll70a86b02011-06-20 16:03:14 -07001710 *bash*)
Jim Tanga881a252018-06-19 16:34:41 +08001711 function check_type() { type -t "$1"; }
Raphael Moll70a86b02011-06-20 16:03:14 -07001712 ;;
Jim Tanga881a252018-06-19 16:34:41 +08001713 *zsh*)
1714 function check_type() { type "$1"; }
Patrik Fimmldf248e62018-10-15 18:15:12 +02001715 enable_zsh_completion ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001716 *)
Jim Tanga881a252018-06-19 16:34:41 +08001717 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 -07001718 ;;
1719 esac
Jim Tanga881a252018-06-19 16:34:41 +08001720}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001721
Chen Xua1cc5582019-02-08 21:52:59 +00001722function acloud()
1723{
1724 # Let's use the built version over the prebuilt.
1725 local built_acloud=${ANDROID_HOST_OUT}/bin/acloud
1726 if [ -f $built_acloud ]; then
1727 $built_acloud "$@"
1728 return $?
1729 fi
1730
1731 local host_os_arch=$(get_build_var HOST_PREBUILT_TAG)
1732 case $host_os_arch in
1733 linux-x86) "$(gettop)"/prebuilts/asuite/acloud/linux-x86/acloud "$@"
1734 ;;
1735 darwin-x86) "$(gettop)"/prebuilts/asuite/acloud/darwin-x86/acloud "$@"
1736 ;;
1737 *)
1738 echo "acloud is not supported on your host arch: $host_os_arch"
1739 ;;
1740 esac
1741}
1742
1743function aidegen()
1744{
1745 # Always use the prebuilt version.
1746 local host_os_arch=$(get_build_var HOST_PREBUILT_TAG)
1747 case $host_os_arch in
1748 linux-x86) "$(gettop)"/prebuilts/asuite/aidegen/linux-x86/aidegen "$@"
1749 ;;
1750 *)
1751 echo "aidegen is not supported on your host arch: $host_os_arch"
1752 ;;
1753 esac
1754}
1755
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001756# Execute the contents of any vendorsetup.sh files we can find.
Jim Tanga881a252018-06-19 16:34:41 +08001757function source_vendorsetup() {
1758 for dir in device vendor product; do
1759 for f in $(test -d $dir && \
1760 find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
1761 echo "including $f"; . $f
1762 done
1763 done
1764}
Kenny Root52aa81c2011-07-15 11:07:06 -07001765
Jim Tanga881a252018-06-19 16:34:41 +08001766validate_current_shell
1767source_vendorsetup
Kenny Root52aa81c2011-07-15 11:07:06 -07001768addcompletions