blob: 1ff5f4a649a395b38685acd9a3f4007987a10471 [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Ying Wang67f02922012-08-22 10:25:20 -07004- lunch: lunch <product_name>-<build_variant>
Ying Wangb541ab62014-05-29 17:57:40 -07005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07006- croot: Changes directory to the top of the tree.
7- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08008- mm: Builds all of the modules in the current directory, but not their dependencies.
9- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000010 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080011- mma: Builds all of the modules in the current directory, and their dependencies.
12- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070013- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070014- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070015- jgrep: Greps on all local Java files.
16- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000017- mangrep: Greps on all local AndroidManifest.xml files.
William Roberts23a298b2015-07-12 17:06:38 -070018- mgrep: Greps on all local Makefiles files.
Trevor Drake9c889762015-01-30 04:42:21 +000019- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070020- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080021- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070022
Dan Albert4ae5d4b2014-10-31 16:23:08 -070023Environemnt options:
24- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
25 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
26 build is leak-check clean.
27
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070028Look at the source to view more functions. The complete list is:
29EOF
30 T=$(gettop)
31 local A
32 A=""
Jacky Cao89483b82015-05-15 22:12:53 +080033 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 -070034 A="$A $i"
35 done
36 echo $A
37}
38
39# Get the value of a build variable as an absolute path.
40function get_abs_build_var()
41{
42 T=$(gettop)
43 if [ ! "$T" ]; then
44 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
45 return
46 fi
Ying Wang9cd17642012-12-13 10:52:07 -080047 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070048 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070049}
50
51# Get the exact value of a build variable.
52function get_build_var()
53{
54 T=$(gettop)
55 if [ ! "$T" ]; then
56 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
57 return
58 fi
Andrew Boie6905e212013-12-19 13:21:46 -080059 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070060 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080061}
62
63# check to see if the supplied product is one we can build
64function check_product()
65{
66 T=$(gettop)
67 if [ ! "$T" ]; then
68 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
69 return
70 fi
Jeff Browne33ba4c2011-07-11 22:11:46 -070071 TARGET_PRODUCT=$1 \
72 TARGET_BUILD_VARIANT= \
73 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070074 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080075 get_build_var TARGET_DEVICE > /dev/null
76 # hide successful answers, but allow the errors to show
77}
78
79VARIANT_CHOICES=(user userdebug eng)
80
81# check to see if the supplied variant is valid
82function check_variant()
83{
84 for v in ${VARIANT_CHOICES[@]}
85 do
86 if [ "$v" = "$1" ]
87 then
88 return 0
89 fi
90 done
91 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070092}
93
94function setpaths()
95{
96 T=$(gettop)
97 if [ ! "$T" ]; then
98 echo "Couldn't locate the top of the tree. Try setting TOP."
99 return
100 fi
101
102 ##################################################################
103 # #
104 # Read me before you modify this code #
105 # #
106 # This function sets ANDROID_BUILD_PATHS to what it is adding #
107 # to PATH, and the next time it is run, it removes that from #
108 # PATH. This is required so lunch can be run more than once #
109 # and still have working paths. #
110 # #
111 ##################################################################
112
Raphael Mollc639c782011-06-20 17:25:01 -0700113 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
114 # due to "C:\Program Files" being in the path.
115
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700116 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700117 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700118 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
119 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700120 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700121 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800122 # strip leading ':', if any
123 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500124 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700125
126 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700127 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700128 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700129
Ben Cheng8bc4c432012-11-16 13:29:13 -0800130 # defined in core/config.mk
131 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700132 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800133 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800134
Raphael Mollc639c782011-06-20 17:25:01 -0700135 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800136 export ANDROID_TOOLCHAIN=
137 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200138 local ARCH=$(get_build_var TARGET_ARCH)
139 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400140 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700141 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400142 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
143 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800144 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200145 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800146 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700147 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700148 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700149 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000150 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200151 *)
152 echo "Can't find toolchain for unknown architecture: $ARCH"
153 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700154 ;;
155 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700156 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800157 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700158 fi
Raphael732936d2011-06-22 14:35:32 -0700159
Ben Chengfba67bf2014-02-25 10:27:07 -0800160 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
161 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
162 fi
163
Jeff Vander Stoep5f50f052015-06-12 09:56:39 -0700164 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang750396d2015-09-14 19:32:50 -0700165 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_DEV_SCRIPTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200166
167 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
168 # to ensure that the corresponding 'emulator' binaries are used.
169 case $(uname -s) in
170 Darwin)
171 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
172 ;;
173 Linux)
174 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
175 ;;
176 *)
177 ANDROID_EMULATOR_PREBUILTS=
178 ;;
179 esac
180 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700181 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200182 export ANDROID_EMULATOR_PREBUILTS
183 fi
184
Ying Wangaa1c9b52012-11-26 20:51:59 -0800185 export PATH=$ANDROID_BUILD_PATHS$PATH
Dan Albertf5caa3d2015-09-18 13:23:56 -0700186 export PYTHONPATH=$T/development/python-packages:$PYTHONPATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800187
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500188 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900189 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500190 if [ -n "$JAVA_HOME" ]; then
191 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900192 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
193 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500194 fi
195
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800196 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700197 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
198 export OUT=$ANDROID_PRODUCT_OUT
199
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700200 unset ANDROID_HOST_OUT
201 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
202
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800203 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700204 # TODO: fix the path
205 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
206}
207
208function printconfig()
209{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800210 T=$(gettop)
211 if [ ! "$T" ]; then
212 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
213 return
214 fi
215 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700216}
217
218function set_stuff_for_environment()
219{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800220 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500221 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800222 setpaths
223 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700224
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800225 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700226 # With this environment variable new GCC can apply colors to warnings/errors
227 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 -0700228 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700229}
230
231function set_sequence_number()
232{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700233 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700234}
235
236function settitle()
237{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800238 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700239 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700240 local product=$TARGET_PRODUCT
241 local variant=$TARGET_BUILD_VARIANT
242 local apps=$TARGET_BUILD_APPS
243 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700244 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700245 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700246 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700247 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800248 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700249}
250
Kenny Root52aa81c2011-07-15 11:07:06 -0700251function addcompletions()
252{
253 local T dir f
254
255 # Keep us from trying to run in something that isn't bash.
256 if [ -z "${BASH_VERSION}" ]; then
257 return
258 fi
259
260 # Keep us from trying to run in bash that's too old.
261 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
262 return
263 fi
264
265 dir="sdk/bash_completion"
266 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700267 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700268 echo "including $f"
269 . $f
270 done
271 fi
272}
273
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700274function choosetype()
275{
276 echo "Build type choices are:"
277 echo " 1. release"
278 echo " 2. debug"
279 echo
280
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800281 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700282 DEFAULT_NUM=1
283 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700284
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800285 export TARGET_BUILD_TYPE=
286 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700287 while [ -z $TARGET_BUILD_TYPE ]
288 do
289 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800290 if [ -z "$1" ] ; then
291 read ANSWER
292 else
293 echo $1
294 ANSWER=$1
295 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700296 case $ANSWER in
297 "")
298 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
299 ;;
300 1)
301 export TARGET_BUILD_TYPE=release
302 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303 release)
304 export TARGET_BUILD_TYPE=release
305 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700306 2)
307 export TARGET_BUILD_TYPE=debug
308 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800309 debug)
310 export TARGET_BUILD_TYPE=debug
311 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700312 *)
313 echo
314 echo "I didn't understand your response. Please try again."
315 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700316 ;;
317 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800318 if [ -n "$1" ] ; then
319 break
320 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321 done
322
323 set_stuff_for_environment
324}
325
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800326#
327# This function isn't really right: It chooses a TARGET_PRODUCT
328# based on the list of boards. Usually, that gets you something
329# that kinda works with a generic product, but really, you should
330# pick a product by name.
331#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332function chooseproduct()
333{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700334 if [ "x$TARGET_PRODUCT" != x ] ; then
335 default_value=$TARGET_PRODUCT
336 else
Ying Wang0a76df52015-06-08 11:57:26 -0700337 default_value=aosp_arm
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338 fi
339
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800340 export TARGET_PRODUCT=
341 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700342 while [ -z "$TARGET_PRODUCT" ]
343 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700344 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800345 if [ -z "$1" ] ; then
346 read ANSWER
347 else
348 echo $1
349 ANSWER=$1
350 fi
351
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700352 if [ -z "$ANSWER" ] ; then
353 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800354 else
355 if check_product $ANSWER
356 then
357 export TARGET_PRODUCT=$ANSWER
358 else
359 echo "** Not a valid product: $ANSWER"
360 fi
361 fi
362 if [ -n "$1" ] ; then
363 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700364 fi
365 done
366
367 set_stuff_for_environment
368}
369
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800370function choosevariant()
371{
372 echo "Variant choices are:"
373 local index=1
374 local v
375 for v in ${VARIANT_CHOICES[@]}
376 do
377 # The product name is the name of the directory containing
378 # the makefile we found, above.
379 echo " $index. $v"
380 index=$(($index+1))
381 done
382
383 local default_value=eng
384 local ANSWER
385
386 export TARGET_BUILD_VARIANT=
387 while [ -z "$TARGET_BUILD_VARIANT" ]
388 do
389 echo -n "Which would you like? [$default_value] "
390 if [ -z "$1" ] ; then
391 read ANSWER
392 else
393 echo $1
394 ANSWER=$1
395 fi
396
397 if [ -z "$ANSWER" ] ; then
398 export TARGET_BUILD_VARIANT=$default_value
399 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
400 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800401 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800402 fi
403 else
404 if check_variant $ANSWER
405 then
406 export TARGET_BUILD_VARIANT=$ANSWER
407 else
408 echo "** Not a valid variant: $ANSWER"
409 fi
410 fi
411 if [ -n "$1" ] ; then
412 break
413 fi
414 done
415}
416
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700417function choosecombo()
418{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700419 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700420
421 echo
422 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700423 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700424
425 echo
426 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700427 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800428
429 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700430 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800431 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700432}
433
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800434# Clear this variable. It will be built up again when the vendorsetup.sh
435# files are included at the end of this file.
436unset LUNCH_MENU_CHOICES
437function add_lunch_combo()
438{
439 local new_combo=$1
440 local c
441 for c in ${LUNCH_MENU_CHOICES[@]} ; do
442 if [ "$new_combo" = "$c" ] ; then
443 return
444 fi
445 done
446 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
447}
448
449# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700450add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800451add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000452add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800453add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000454add_lunch_combo aosp_x86-eng
455add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800456
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700457function print_lunch_menu()
458{
459 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700460 echo
461 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700462 echo
463 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800464
465 local i=1
466 local choice
467 for choice in ${LUNCH_MENU_CHOICES[@]}
468 do
469 echo " $i. $choice"
470 i=$(($i+1))
471 done
472
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 echo
474}
475
476function lunch()
477{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800478 local answer
479
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700480 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800481 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700482 else
483 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700484 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800485 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486 fi
487
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800488 local selection=
489
490 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700491 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700492 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800493 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
494 then
495 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
496 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800497 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800498 fi
499 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
500 then
501 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700502 fi
503
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 if [ -z "$selection" ]
505 then
506 echo
507 echo "Invalid lunch combo: $answer"
508 return 1
509 fi
510
Joe Onoratoda12daf2010-06-09 18:18:31 -0700511 export TARGET_BUILD_APPS=
512
Jeff Browne33ba4c2011-07-11 22:11:46 -0700513 local product=$(echo -n $selection | sed -e "s/-.*$//")
514 check_product $product
515 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800516 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700517 echo
518 echo "** Don't have a product spec for: '$product'"
519 echo "** Do you have the right repo manifest?"
520 product=
521 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522
Jeff Browne33ba4c2011-07-11 22:11:46 -0700523 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
524 check_variant $variant
525 if [ $? -ne 0 ]
526 then
527 echo
528 echo "** Invalid variant: '$variant'"
529 echo "** Must be one of ${VARIANT_CHOICES[@]}"
530 variant=
531 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800532
Jeff Browne33ba4c2011-07-11 22:11:46 -0700533 if [ -z "$product" -o -z "$variant" ]
534 then
535 echo
536 return 1
537 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800538
Jeff Browne33ba4c2011-07-11 22:11:46 -0700539 export TARGET_PRODUCT=$product
540 export TARGET_BUILD_VARIANT=$variant
541 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700542
543 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800544
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700545 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800546 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700547}
548
Jeff Davidson513d7a42010-08-02 10:00:44 -0700549# Tab completion for lunch.
550function _lunch()
551{
552 local cur prev opts
553 COMPREPLY=()
554 cur="${COMP_WORDS[COMP_CWORD]}"
555 prev="${COMP_WORDS[COMP_CWORD-1]}"
556
557 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
558 return 0
559}
560complete -F _lunch lunch
561
Joe Onoratoda12daf2010-06-09 18:18:31 -0700562# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700563# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700564function tapas()
565{
Ying Wangb541ab62014-05-29 17:57:40 -0700566 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700567 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700568 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
569 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700570
Ying Wang67f02922012-08-22 10:25:20 -0700571 if [ $(echo $arch | wc -w) -gt 1 ]; then
572 echo "tapas: Error: Multiple build archs supplied: $arch"
573 return
574 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700575 if [ $(echo $variant | wc -w) -gt 1 ]; then
576 echo "tapas: Error: Multiple build variants supplied: $variant"
577 return
578 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700579 if [ $(echo $density | wc -w) -gt 1 ]; then
580 echo "tapas: Error: Multiple densities supplied: $density"
581 return
582 fi
Ying Wang67f02922012-08-22 10:25:20 -0700583
Ying Wang0a76df52015-06-08 11:57:26 -0700584 local product=aosp_arm
Ying Wang67f02922012-08-22 10:25:20 -0700585 case $arch in
Ying Wang0a76df52015-06-08 11:57:26 -0700586 x86) product=aosp_x86;;
587 mips) product=aosp_mips;;
Ying Wangb541ab62014-05-29 17:57:40 -0700588 armv5) product=generic_armv5;;
589 arm64) product=aosp_arm64;;
590 x86_64) product=aosp_x86_64;;
591 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700592 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700593 if [ -z "$variant" ]; then
594 variant=eng
595 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700596 if [ -z "$apps" ]; then
597 apps=all
598 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600599 if [ -z "$density" ]; then
600 density=alldpi
601 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700602
Ying Wang67f02922012-08-22 10:25:20 -0700603 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700604 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700605 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700606 export TARGET_BUILD_TYPE=release
607 export TARGET_BUILD_APPS=$apps
608
609 set_stuff_for_environment
610 printconfig
611}
612
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700613function gettop
614{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800615 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700616 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700617 # The following circumlocution ensures we remove symlinks from TOP.
618 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700619 else
620 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800621 # The following circumlocution (repeated below as well) ensures
622 # that we record the true directory name and not one that is
623 # faked up with symlink names.
624 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700625 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800626 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700627 T=
628 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800629 \cd ..
synergyb112a402013-07-05 19:47:47 -0700630 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700631 done
Ying Wang9cd17642012-12-13 10:52:07 -0800632 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700633 if [ -f "$T/$TOPFILE" ]; then
634 echo $T
635 fi
636 fi
637 fi
638}
639
Andrew Hsieh906cb782013-09-10 17:37:14 +0800640# Return driver for "make", if any (eg. static analyzer)
641function getdriver()
642{
643 local T="$1"
644 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
645 if [ -n "$WITH_STATIC_ANALYZER" ]; then
646 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800647$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
648--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800649--status-bugs \
650--top=$T"
651 fi
652}
653
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700654function m()
655{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800656 local T=$(gettop)
657 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800659 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700660 else
661 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700662 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700663 fi
664}
665
666function findmakefile()
667{
668 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800669 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700670 T=
671 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700672 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700673 if [ -f "$T/Android.mk" ]; then
674 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800675 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700676 return
677 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800678 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700679 done
Ying Wang9cd17642012-12-13 10:52:07 -0800680 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700681}
682
683function mm()
684{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800685 local T=$(gettop)
686 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700687 # If we're sitting in the root of the build tree, just do a
688 # normal make.
689 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800690 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700691 else
692 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800693 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700694 local MODULES=
695 local GET_INSTALL_PATH=
696 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700697 # Remove the path to top as the makefilepath needs to be relative
698 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700699 if [ ! "$T" ]; then
700 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700701 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700702 elif [ ! "$M" ]; then
703 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700704 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700705 else
Ying Wanga7deb082013-08-16 13:24:47 -0700706 for ARG in $@; do
707 case $ARG in
708 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
709 esac
710 done
711 if [ -n "$GET_INSTALL_PATH" ]; then
712 MODULES=
713 ARGS=GET-INSTALL-PATH
714 else
715 MODULES=all_modules
716 ARGS=$@
717 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700718 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700719 fi
720 fi
721}
722
723function mmm()
724{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800725 local T=$(gettop)
726 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700727 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800728 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800729 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800730 local ARGS=
731 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700732 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800733 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
734 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
735 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800736 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
737 if [ "$MODULES" = "" ]; then
738 MODULES=all_modules
739 fi
740 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700741 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700742 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
743 local TO_CHOP=`expr $TO_CHOP + 1`
744 local START=`PWD= /bin/pwd`
745 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700746 if [ "$MFILE" = "" ] ; then
747 MFILE=$DIR/Android.mk
748 else
749 MFILE=$MFILE/$DIR/Android.mk
750 fi
751 MAKEFILE="$MAKEFILE $MFILE"
752 else
Ying Wanga7deb082013-08-16 13:24:47 -0700753 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700754 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700755 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
756 *) echo "No Android.mk in $DIR."; return 1;;
757 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700758 fi
759 done
Ying Wanga7deb082013-08-16 13:24:47 -0700760 if [ -n "$GET_INSTALL_PATH" ]; then
761 ARGS=$GET_INSTALL_PATH
762 MODULES=
763 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800764 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700765 else
766 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700767 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700768 fi
769}
770
Ying Wangb607f7b2013-02-08 18:01:04 -0800771function mma()
772{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800773 local T=$(gettop)
774 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800775 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800776 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800777 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800778 if [ ! "$T" ]; then
779 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700780 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800781 fi
782 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Ying Wangcaeaa082015-09-23 16:08:55 -0700783 $DRV make -C $T -f build/core/main.mk $@ MODULES-IN/$MY_PWD
Ying Wangb607f7b2013-02-08 18:01:04 -0800784 fi
785}
786
787function mmma()
788{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800789 local T=$(gettop)
790 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800791 if [ "$T" ]; then
792 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
793 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
794 local MY_PWD=`PWD= /bin/pwd`
795 if [ "$MY_PWD" = "$T" ]; then
796 MY_PWD=
797 else
798 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
799 fi
800 local DIR=
Ying Wangcaeaa082015-09-23 16:08:55 -0700801 local MODULES_IN_PATHS=
Ying Wangb607f7b2013-02-08 18:01:04 -0800802 local ARGS=
803 for DIR in $DIRS ; do
804 if [ -d $DIR ]; then
Ying Wangcaeaa082015-09-23 16:08:55 -0700805 # Remove the leading ./ and trailing / if any exists.
806 DIR=${DIR#./}
807 DIR=${DIR%/}
808 if [ "$MY_PWD" != "" ]; then
809 DIR=$MY_PWD/$DIR
Ying Wangb607f7b2013-02-08 18:01:04 -0800810 fi
Ying Wangcaeaa082015-09-23 16:08:55 -0700811 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN/$DIR"
Ying Wangb607f7b2013-02-08 18:01:04 -0800812 else
813 case $DIR in
Ying Wangcaeaa082015-09-23 16:08:55 -0700814 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800815 *) echo "Couldn't find directory $DIR"; return 1;;
816 esac
817 fi
818 done
Ying Wangcaeaa082015-09-23 16:08:55 -0700819 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS $MODULES_IN_PATHS
Ying Wangb607f7b2013-02-08 18:01:04 -0800820 else
821 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700822 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800823 fi
824}
825
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700826function croot()
827{
828 T=$(gettop)
829 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800830 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700831 else
832 echo "Couldn't locate the top of the tree. Try setting TOP."
833 fi
834}
835
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700836function cproj()
837{
838 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700839 local HERE=$PWD
840 T=
841 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
842 T=$PWD
843 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800844 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700845 return
846 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800847 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700848 done
Ying Wang9cd17642012-12-13 10:52:07 -0800849 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700850 echo "can't find Android.mk"
851}
852
Daniel Sandler47e0a882013-07-30 13:23:52 -0400853# simplified version of ps; output in the form
854# <pid> <procname>
855function qpid() {
856 local prepend=''
857 local append=''
858 if [ "$1" = "--exact" ]; then
859 prepend=' '
860 append='$'
861 shift
862 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
863 echo "usage: qpid [[--exact] <process name|pid>"
864 return 255
865 fi
866
867 local EXE="$1"
868 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700869 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400870 else
871 adb shell ps \
872 | tr -d '\r' \
873 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
874 fi
875}
876
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700877function pid()
878{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400879 local prepend=''
880 local append=''
881 if [ "$1" = "--exact" ]; then
882 prepend=' '
883 append='$'
884 shift
885 fi
886 local EXE="$1"
887 if [ "$EXE" ] ; then
888 local PID=`adb shell ps \
889 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700890 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400891 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
892 echo "$PID"
893 else
894 echo "usage: pid [--exact] <process name>"
895 return 255
896 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700897}
898
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800899# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700900# that has the core-file-size limit set correctly
901#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800902# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700903# if its core-file-size limit is not set already.
904# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
905
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800906function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700907{
908 echo "Getting root...";
909 adb root;
910 adb wait-for-device;
911
912 echo "Remounting root parition read-write...";
913 adb shell mount -w -o remount -t rootfs rootfs;
914 sleep 1;
915 adb wait-for-device;
916 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -0800917 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700918 adb shell chmod 0777 /cores;
919
920 echo "Granting SELinux permission to dump in /cores...";
921 adb shell restorecon -R /cores;
922
923 echo "Set core pattern.";
924 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
925
926 echo "Done."
927}
928
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800929# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700930# $1 = PID of process (e.g., $(pid mediaserver))
931#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800932# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700933# dump to actually be generated.
934
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800935function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700936{
937 local PID=$1;
938 if [ -z "$PID" ]; then
939 printf "Expecting a PID!\n";
940 return;
941 fi;
942 echo "Setting core limit for $PID to infinite...";
943 adb shell prlimit $PID 4 -1 -1
944}
945
946# core - send SIGV and pull the core for process
947# $1 = PID of process (e.g., $(pid mediaserver))
948#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800949# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700950# enabled globally.
951
952function core()
953{
954 local PID=$1;
955
956 if [ -z "$PID" ]; then
957 printf "Expecting a PID!\n";
958 return;
959 fi;
960
961 local CORENAME=core.$PID;
962 local COREPATH=/cores/$CORENAME;
963 local SIG=SEGV;
964
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800965 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700966
967 local done=0;
968 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
969 printf "\tSending SIG%s to %d...\n" $SIG $PID;
970 adb shell kill -$SIG $PID;
971 sleep 1;
972 done;
973
974 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
975 echo "Done: core is under $COREPATH on device.";
976}
977
Christopher Tate744ee802009-11-12 15:33:08 -0800978# systemstack - dump the current stack trace of all threads in the system process
979# to the usual ANR traces file
980function systemstack()
981{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800982 stacks system_server
983}
984
985function stacks()
986{
987 if [[ $1 =~ ^[0-9]+$ ]] ; then
988 local PID="$1"
989 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700990 local PIDLIST="$(pid $1)"
991 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
992 local PID="$PIDLIST"
993 elif [ "$PIDLIST" ] ; then
994 echo "more than one process: $1"
995 else
996 echo "no such process: $1"
997 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800998 else
999 echo "usage: stacks [pid|process name]"
1000 fi
1001
1002 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001003 # Determine whether the process is native
1004 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1005 # Dump stacks of Dalvik process
1006 local TRACES=/data/anr/traces.txt
1007 local ORIG=/data/anr/traces.orig
1008 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001009
Jeff Brownb12c2e52013-08-19 15:14:16 -07001010 # Keep original traces to avoid clobbering
1011 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001012
Jeff Brownb12c2e52013-08-19 15:14:16 -07001013 # Make sure we have a usable file
1014 adb shell touch $TRACES
1015 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001016
Jeff Brownb12c2e52013-08-19 15:14:16 -07001017 # Dump stacks and wait for dump to finish
1018 adb shell kill -3 $PID
1019 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001020
Jeff Brownb12c2e52013-08-19 15:14:16 -07001021 # Restore original stacks, and show current output
1022 adb shell mv $TRACES $TMP
1023 adb shell mv $ORIG $TRACES
1024 adb shell cat $TMP
1025 else
1026 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001027 local USE64BIT="$(is64bit $PID)"
1028 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001029 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001030 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001031}
1032
Michael Wrightaeed7212014-06-19 19:58:12 -07001033# Read the ELF header from /proc/$PID/exe to determine if the process is
1034# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001035function is64bit()
1036{
1037 local PID="$1"
1038 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001039 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001040 echo "64"
1041 else
1042 echo ""
1043 fi
1044 else
1045 echo ""
1046 fi
1047}
1048
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001049case `uname -s` in
1050 Darwin)
1051 function sgrep()
1052 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001053 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001054 }
1055
1056 ;;
1057 *)
1058 function sgrep()
1059 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001060 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001061 }
1062 ;;
1063esac
1064
Raghu Gandham8da43102012-07-25 19:57:22 -07001065function gettargetarch
1066{
1067 get_build_var TARGET_ARCH
1068}
1069
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001070function ggrep()
1071{
1072 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1073}
1074
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001075function jgrep()
1076{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001077 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001078}
1079
1080function cgrep()
1081{
Dan Albert01961192014-11-22 10:16:01 -08001082 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' \) -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001083}
1084
1085function resgrep()
1086{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001087 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001088}
1089
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001090function mangrep()
1091{
1092 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1093}
1094
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001095function sepgrep()
1096{
1097 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d -print0 | xargs -0 grep --color -n -r --exclude-dir=\.git "$@"
1098}
1099
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001100case `uname -s` in
1101 Darwin)
1102 function mgrep()
1103 {
Ying Wang324c2b22012-08-17 15:03:20 -07001104 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001105 }
1106
1107 function treegrep()
1108 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001109 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001110 }
1111
1112 ;;
1113 *)
1114 function mgrep()
1115 {
Ying Wang324c2b22012-08-17 15:03:20 -07001116 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001117 }
1118
1119 function treegrep()
1120 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001121 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001122 }
1123
1124 ;;
1125esac
1126
1127function getprebuilt
1128{
1129 get_abs_build_var ANDROID_PREBUILTS
1130}
1131
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001132function tracedmdump()
1133{
1134 T=$(gettop)
1135 if [ ! "$T" ]; then
1136 echo "Couldn't locate the top of the tree. Try setting TOP."
1137 return
1138 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001139 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001140 local arch=$(gettargetarch)
1141 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001142
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001143 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001144 if [ ! "$TRACE" ] ; then
1145 echo "usage: tracedmdump tracename"
1146 return
1147 fi
1148
Jack Veenstra60116fc2009-04-09 18:12:34 -07001149 if [ ! -r "$KERNEL" ] ; then
1150 echo "Error: cannot find kernel: '$KERNEL'"
1151 return
1152 fi
1153
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001154 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001155 if [ "$BASETRACE" = "$TRACE" ] ; then
1156 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1157 fi
1158
1159 echo "post-processing traces..."
1160 rm -f $TRACE/qtrace.dexlist
1161 post_trace $TRACE
1162 if [ $? -ne 0 ]; then
1163 echo "***"
1164 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1165 echo "***"
1166 return
1167 fi
1168 echo "generating dexlist output..."
1169 /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
1170 echo "generating dmtrace data..."
1171 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1172 echo "generating html file..."
1173 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1174 echo "done, see $TRACE/dmtrace.html for details"
1175 echo "or run:"
1176 echo " traceview $TRACE/dmtrace"
1177}
1178
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001179# communicate with a running device or emulator, set up necessary state,
1180# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001181function runhat()
1182{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001183 # process standard adb options
1184 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001185 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001186 adbTarget=$1
1187 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001188 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001189 adbTarget="$1 $2"
1190 shift 2
1191 fi
1192 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001193 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001194
1195 # runhat options
1196 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001197
1198 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001199 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001200 return
1201 fi
1202
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001203 # confirm hat is available
1204 if [ -z $(which hat) ]; then
1205 echo "hat is not available in this configuration."
1206 return
1207 fi
1208
Andy McFaddenb6289852010-07-12 08:00:19 -07001209 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001210 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001211 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001212 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001213 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001214 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001215 echo -n "> "
1216 read
1217
The Android Open Source Project88b60792009-03-03 19:28:42 -08001218 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001219
The Android Open Source Project88b60792009-03-03 19:28:42 -08001220 echo "Retrieving file $devFile..."
1221 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001222
The Android Open Source Project88b60792009-03-03 19:28:42 -08001223 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001224
The Android Open Source Project88b60792009-03-03 19:28:42 -08001225 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001226 echo "View the output by pointing your browser at http://localhost:7000/"
1227 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001228 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001229}
1230
1231function getbugreports()
1232{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001233 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001234
1235 if [ ! "$reports" ]; then
1236 echo "Could not locate any bugreports."
1237 return
1238 fi
1239
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001240 local report
1241 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001242 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001243 echo "/sdcard/bugreports/${report}"
1244 adb pull /sdcard/bugreports/${report} ${report}
1245 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001246 done
1247}
1248
Victoria Lease1b296b42012-08-21 15:44:06 -07001249function getsdcardpath()
1250{
1251 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1252}
1253
1254function getscreenshotpath()
1255{
1256 echo "$(getsdcardpath)/Pictures/Screenshots"
1257}
1258
1259function getlastscreenshot()
1260{
1261 local screenshot_path=$(getscreenshotpath)
1262 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1263 if [ "$screenshot" = "" ]; then
1264 echo "No screenshots found."
1265 return
1266 fi
1267 echo "${screenshot}"
1268 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1269}
1270
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001271function startviewserver()
1272{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001273 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001274 if [ $# -gt 0 ]; then
1275 port=$1
1276 fi
1277 adb shell service call window 1 i32 $port
1278}
1279
1280function stopviewserver()
1281{
1282 adb shell service call window 2
1283}
1284
1285function isviewserverstarted()
1286{
1287 adb shell service call window 3
1288}
1289
Romain Guyb84049a2010-10-04 16:56:11 -07001290function key_home()
1291{
1292 adb shell input keyevent 3
1293}
1294
1295function key_back()
1296{
1297 adb shell input keyevent 4
1298}
1299
1300function key_menu()
1301{
1302 adb shell input keyevent 82
1303}
1304
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001305function smoketest()
1306{
1307 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1308 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1309 return
1310 fi
1311 T=$(gettop)
1312 if [ ! "$T" ]; then
1313 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1314 return
1315 fi
1316
Ying Wang9cd17642012-12-13 10:52:07 -08001317 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001318 adb uninstall com.android.smoketest > /dev/null &&
1319 adb uninstall com.android.smoketest.tests > /dev/null &&
1320 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1321 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1322 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1323}
1324
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001325# simple shortcut to the runtest command
1326function runtest()
1327{
1328 T=$(gettop)
1329 if [ ! "$T" ]; then
1330 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1331 return
1332 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001333 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001334}
1335
The Android Open Source Project88b60792009-03-03 19:28:42 -08001336function godir () {
1337 if [[ -z "$1" ]]; then
1338 echo "Usage: godir <regex>"
1339 return
1340 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001341 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001342 if [[ ! -f $T/filelist ]]; then
1343 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001344 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001345 echo " Done"
1346 echo ""
1347 fi
1348 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001349 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001350 if [[ ${#lines[@]} = 0 ]]; then
1351 echo "Not found"
1352 return
1353 fi
1354 local pathname
1355 local choice
1356 if [[ ${#lines[@]} > 1 ]]; then
1357 while [[ -z "$pathname" ]]; do
1358 local index=1
1359 local line
1360 for line in ${lines[@]}; do
1361 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001362 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001363 done
1364 echo
1365 echo -n "Select one: "
1366 unset choice
1367 read choice
1368 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1369 echo "Invalid choice"
1370 continue
1371 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001372 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001373 done
1374 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001375 pathname=${lines[0]}
1376 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001377 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001378}
1379
Neil Fuller46e00ea2014-10-16 10:23:03 +01001380# Force JAVA_HOME to point to java 1.7 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001381#
1382# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1383# For some reason, installing the JDK doesn't make it show up in the
1384# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001385function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001386 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001387 # we can reset it later, depending on the version of java the build
1388 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001389 #
1390 # If we don't do this, the JAVA_HOME value set by the first call to
1391 # build/envsetup.sh will persist forever.
1392 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1393 export JAVA_HOME=""
1394 fi
1395
Andy McFaddenbd960942010-06-24 12:52:51 -07001396 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01001397 case `uname -s` in
1398 Darwin)
1399 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1400 ;;
1401 *)
1402 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1403 ;;
1404 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001405
1406 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1407 # we can change it on the next envsetup.sh, if required.
1408 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001409 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001410}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001411
Alex Rayf0d08eb2013-03-08 15:15:06 -08001412# Print colored exit condition
1413function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001414 "$@"
1415 local retval=$?
1416 if [ $retval -ne 0 ]
1417 then
Jacky Cao89483b82015-05-15 22:12:53 +08001418 echo $'\E'"[0;31mFAILURE\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001419 else
Jacky Cao89483b82015-05-15 22:12:53 +08001420 echo $'\E'"[0;32mSUCCESS\e[00m"
Michael Wrighteb733842013-03-08 17:34:02 -08001421 fi
1422 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001423}
1424
Ying Wanged21d4c2014-08-24 22:14:19 -07001425function get_make_command()
1426{
1427 echo command make
1428}
1429
Ed Heylcc6be0a2014-06-18 14:55:58 -07001430function make()
1431{
1432 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001433 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001434 local ret=$?
1435 local end_time=$(date +"%s")
1436 local tdiff=$(($end_time-$start_time))
1437 local hours=$(($tdiff / 3600 ))
1438 local mins=$((($tdiff % 3600) / 60))
1439 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001440 local ncolors=$(tput colors 2>/dev/null)
1441 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
Jacky Cao89483b82015-05-15 22:12:53 +08001442 color_failed=$'\E'"[0;31m"
1443 color_success=$'\E'"[0;32m"
1444 color_reset=$'\E'"[00m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001445 else
1446 color_failed=""
1447 color_success=""
1448 color_reset=""
1449 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001450 echo
1451 if [ $ret -eq 0 ] ; then
Jacky Cao89483b82015-05-15 22:12:53 +08001452 echo -n "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001453 else
Jacky Cao89483b82015-05-15 22:12:53 +08001454 echo -n "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001455 fi
1456 if [ $hours -gt 0 ] ; then
1457 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1458 elif [ $mins -gt 0 ] ; then
1459 printf "(%02g:%02g (mm:ss))" $mins $secs
1460 elif [ $secs -gt 0 ] ; then
1461 printf "(%s seconds)" $secs
1462 fi
Jacky Cao89483b82015-05-15 22:12:53 +08001463 echo " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001464 echo
1465 return $ret
1466}
1467
Raphael Moll70a86b02011-06-20 16:03:14 -07001468if [ "x$SHELL" != "x/bin/bash" ]; then
1469 case `ps -o command -p $$` in
1470 *bash*)
1471 ;;
1472 *)
1473 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1474 ;;
1475 esac
1476fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001477
1478# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02001479for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
1480 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001481do
1482 echo "including $f"
1483 . $f
1484done
1485unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001486
1487addcompletions