blob: dfd16179d140a8ecc7f65bd8da7440f844f4b9b0 [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 Wangf05c4f72013-01-31 11:16:57 -08005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [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.
10- mma: Builds all of the modules in the current directory, and their dependencies.
11- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070012- cgrep: Greps on all local C/C++ files.
13- jgrep: Greps on all local Java files.
14- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080015- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070016
17Look at the source to view more functions. The complete list is:
18EOF
19 T=$(gettop)
20 local A
21 A=""
22 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
23 A="$A $i"
24 done
25 echo $A
26}
27
28# Get the value of a build variable as an absolute path.
29function get_abs_build_var()
30{
31 T=$(gettop)
32 if [ ! "$T" ]; then
33 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
34 return
35 fi
Ying Wang9cd17642012-12-13 10:52:07 -080036 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Andrew Boie6905e212013-12-19 13:21:46 -080037 make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070038}
39
40# Get the exact value of a build variable.
41function get_build_var()
42{
43 T=$(gettop)
44 if [ ! "$T" ]; then
45 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
46 return
47 fi
Andrew Boie6905e212013-12-19 13:21:46 -080048 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
49 make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080050}
51
52# check to see if the supplied product is one we can build
53function check_product()
54{
55 T=$(gettop)
56 if [ ! "$T" ]; then
57 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
58 return
59 fi
60 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Jeff Browne33ba4c2011-07-11 22:11:46 -070061 TARGET_PRODUCT=$1 \
62 TARGET_BUILD_VARIANT= \
63 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070064 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080065 get_build_var TARGET_DEVICE > /dev/null
66 # hide successful answers, but allow the errors to show
67}
68
69VARIANT_CHOICES=(user userdebug eng)
70
71# check to see if the supplied variant is valid
72function check_variant()
73{
74 for v in ${VARIANT_CHOICES[@]}
75 do
76 if [ "$v" = "$1" ]
77 then
78 return 0
79 fi
80 done
81 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070082}
83
84function setpaths()
85{
86 T=$(gettop)
87 if [ ! "$T" ]; then
88 echo "Couldn't locate the top of the tree. Try setting TOP."
89 return
90 fi
91
92 ##################################################################
93 # #
94 # Read me before you modify this code #
95 # #
96 # This function sets ANDROID_BUILD_PATHS to what it is adding #
97 # to PATH, and the next time it is run, it removes that from #
98 # PATH. This is required so lunch can be run more than once #
99 # and still have working paths. #
100 # #
101 ##################################################################
102
Raphael Mollc639c782011-06-20 17:25:01 -0700103 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
104 # due to "C:\Program Files" being in the path.
105
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700106 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700107 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700108 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
109 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700110 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700111 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800112 # strip leading ':', if any
113 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500114 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700115
116 # and in with the new
117 CODE_REVIEWS=
118 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700119 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700120
Ben Cheng8bc4c432012-11-16 13:29:13 -0800121 # defined in core/config.mk
122 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800123 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800124
Raphael Mollc639c782011-06-20 17:25:01 -0700125 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800126 export ANDROID_TOOLCHAIN=
127 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200128 local ARCH=$(get_build_var TARGET_ARCH)
129 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400130 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700131 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400132 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
133 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800134 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200135 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800136 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
137 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700138 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800139 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700140 ;;
Chris Dearman1efd9e42014-02-03 15:01:24 -0800141 mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000142 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200143 *)
144 echo "Can't find toolchain for unknown architecture: $ARCH"
145 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700146 ;;
147 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700148 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800149 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700150 fi
Raphael732936d2011-06-22 14:35:32 -0700151
Ben Chengfba67bf2014-02-25 10:27:07 -0800152 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
153 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
154 fi
155
156 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700157 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700158 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800159 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800160 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700161 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800162 ANDROID_KERNEL_TOOLCHAIN_PATH="$gccprebuiltdir/$toolchaindir"
163 export ARM_EABI_TOOLCHAIN=$ANDROID_KERNEL_TOOLCHAIN_PATH
Bruce Beare42ced6d2012-07-17 21:40:01 -0700164 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700165 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700166 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
167 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700168 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700169 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700170 ;;
171 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700172
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700173 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700174 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ben Chengfba67bf2014-02-25 10:27:07 -0800175 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_KERNEL_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
Ying Wangaa1c9b52012-11-26 20:51:59 -0800176 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800177
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500178 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900179 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500180 if [ -n "$JAVA_HOME" ]; then
181 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900182 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
183 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500184 fi
185
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800186 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700187 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
188 export OUT=$ANDROID_PRODUCT_OUT
189
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700190 unset ANDROID_HOST_OUT
191 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
192
Ben Cheng057fde12011-11-28 13:55:14 -0800193 # needed for processing samples collected by perf counters
194 unset OPROFILE_EVENTS_DIR
195 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
196
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800197 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700198 # TODO: fix the path
199 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
200}
201
202function printconfig()
203{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800204 T=$(gettop)
205 if [ ! "$T" ]; then
206 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
207 return
208 fi
209 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700210}
211
212function set_stuff_for_environment()
213{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800214 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500215 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800216 setpaths
217 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700218
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800219 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700220 # With this environment variable new GCC can apply colors to warnings/errors
221 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700222}
223
224function set_sequence_number()
225{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700226 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700227}
228
229function settitle()
230{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800231 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700232 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700233 local product=$TARGET_PRODUCT
234 local variant=$TARGET_BUILD_VARIANT
235 local apps=$TARGET_BUILD_APPS
236 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700237 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700238 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700239 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700240 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800241 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700242}
243
Kenny Root52aa81c2011-07-15 11:07:06 -0700244function addcompletions()
245{
246 local T dir f
247
248 # Keep us from trying to run in something that isn't bash.
249 if [ -z "${BASH_VERSION}" ]; then
250 return
251 fi
252
253 # Keep us from trying to run in bash that's too old.
254 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
255 return
256 fi
257
258 dir="sdk/bash_completion"
259 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700260 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700261 echo "including $f"
262 . $f
263 done
264 fi
265}
266
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700267function choosetype()
268{
269 echo "Build type choices are:"
270 echo " 1. release"
271 echo " 2. debug"
272 echo
273
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800274 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700275 DEFAULT_NUM=1
276 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700277
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800278 export TARGET_BUILD_TYPE=
279 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700280 while [ -z $TARGET_BUILD_TYPE ]
281 do
282 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800283 if [ -z "$1" ] ; then
284 read ANSWER
285 else
286 echo $1
287 ANSWER=$1
288 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700289 case $ANSWER in
290 "")
291 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
292 ;;
293 1)
294 export TARGET_BUILD_TYPE=release
295 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800296 release)
297 export TARGET_BUILD_TYPE=release
298 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700299 2)
300 export TARGET_BUILD_TYPE=debug
301 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800302 debug)
303 export TARGET_BUILD_TYPE=debug
304 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700305 *)
306 echo
307 echo "I didn't understand your response. Please try again."
308 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309 ;;
310 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800311 if [ -n "$1" ] ; then
312 break
313 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700314 done
315
316 set_stuff_for_environment
317}
318
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800319#
320# This function isn't really right: It chooses a TARGET_PRODUCT
321# based on the list of boards. Usually, that gets you something
322# that kinda works with a generic product, but really, you should
323# pick a product by name.
324#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325function chooseproduct()
326{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700327 if [ "x$TARGET_PRODUCT" != x ] ; then
328 default_value=$TARGET_PRODUCT
329 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700330 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700331 fi
332
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800333 export TARGET_PRODUCT=
334 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335 while [ -z "$TARGET_PRODUCT" ]
336 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700337 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800338 if [ -z "$1" ] ; then
339 read ANSWER
340 else
341 echo $1
342 ANSWER=$1
343 fi
344
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700345 if [ -z "$ANSWER" ] ; then
346 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800347 else
348 if check_product $ANSWER
349 then
350 export TARGET_PRODUCT=$ANSWER
351 else
352 echo "** Not a valid product: $ANSWER"
353 fi
354 fi
355 if [ -n "$1" ] ; then
356 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700357 fi
358 done
359
360 set_stuff_for_environment
361}
362
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800363function choosevariant()
364{
365 echo "Variant choices are:"
366 local index=1
367 local v
368 for v in ${VARIANT_CHOICES[@]}
369 do
370 # The product name is the name of the directory containing
371 # the makefile we found, above.
372 echo " $index. $v"
373 index=$(($index+1))
374 done
375
376 local default_value=eng
377 local ANSWER
378
379 export TARGET_BUILD_VARIANT=
380 while [ -z "$TARGET_BUILD_VARIANT" ]
381 do
382 echo -n "Which would you like? [$default_value] "
383 if [ -z "$1" ] ; then
384 read ANSWER
385 else
386 echo $1
387 ANSWER=$1
388 fi
389
390 if [ -z "$ANSWER" ] ; then
391 export TARGET_BUILD_VARIANT=$default_value
392 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
393 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800394 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800395 fi
396 else
397 if check_variant $ANSWER
398 then
399 export TARGET_BUILD_VARIANT=$ANSWER
400 else
401 echo "** Not a valid variant: $ANSWER"
402 fi
403 fi
404 if [ -n "$1" ] ; then
405 break
406 fi
407 done
408}
409
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700410function choosecombo()
411{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700412 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700413
414 echo
415 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700416 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700417
418 echo
419 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700420 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800421
422 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700423 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800424 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700425}
426
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800427# Clear this variable. It will be built up again when the vendorsetup.sh
428# files are included at the end of this file.
429unset LUNCH_MENU_CHOICES
430function add_lunch_combo()
431{
432 local new_combo=$1
433 local c
434 for c in ${LUNCH_MENU_CHOICES[@]} ; do
435 if [ "$new_combo" = "$c" ] ; then
436 return
437 fi
438 done
439 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
440}
441
442# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700443add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800444add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000445add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800446add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000447add_lunch_combo aosp_x86-eng
448add_lunch_combo aosp_x86_64-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800449add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800450
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700451function print_lunch_menu()
452{
453 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700454 echo
455 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700456 echo
457 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800458
459 local i=1
460 local choice
461 for choice in ${LUNCH_MENU_CHOICES[@]}
462 do
463 echo " $i. $choice"
464 i=$(($i+1))
465 done
466
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700467 echo
468}
469
470function lunch()
471{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472 local answer
473
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800475 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700476 else
477 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700478 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700480 fi
481
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482 local selection=
483
484 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700485 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700486 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800487 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
488 then
489 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
490 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800491 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492 fi
493 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
494 then
495 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700496 fi
497
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800498 if [ -z "$selection" ]
499 then
500 echo
501 echo "Invalid lunch combo: $answer"
502 return 1
503 fi
504
Joe Onoratoda12daf2010-06-09 18:18:31 -0700505 export TARGET_BUILD_APPS=
506
Jeff Browne33ba4c2011-07-11 22:11:46 -0700507 local product=$(echo -n $selection | sed -e "s/-.*$//")
508 check_product $product
509 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800510 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700511 echo
512 echo "** Don't have a product spec for: '$product'"
513 echo "** Do you have the right repo manifest?"
514 product=
515 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800516
Jeff Browne33ba4c2011-07-11 22:11:46 -0700517 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
518 check_variant $variant
519 if [ $? -ne 0 ]
520 then
521 echo
522 echo "** Invalid variant: '$variant'"
523 echo "** Must be one of ${VARIANT_CHOICES[@]}"
524 variant=
525 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800526
Jeff Browne33ba4c2011-07-11 22:11:46 -0700527 if [ -z "$product" -o -z "$variant" ]
528 then
529 echo
530 return 1
531 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800532
Jeff Browne33ba4c2011-07-11 22:11:46 -0700533 export TARGET_PRODUCT=$product
534 export TARGET_BUILD_VARIANT=$variant
535 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700536
537 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800538
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700539 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800540 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700541}
542
Jeff Davidson513d7a42010-08-02 10:00:44 -0700543# Tab completion for lunch.
544function _lunch()
545{
546 local cur prev opts
547 COMPREPLY=()
548 cur="${COMP_WORDS[COMP_CWORD]}"
549 prev="${COMP_WORDS[COMP_CWORD-1]}"
550
551 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
552 return 0
553}
554complete -F _lunch lunch
555
Joe Onoratoda12daf2010-06-09 18:18:31 -0700556# Configures the build to build unbundled apps.
557# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
558function tapas()
559{
Ying Wangf05c4f72013-01-31 11:16:57 -0800560 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600561 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800562 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5)$'))
Joe Onoratoda12daf2010-06-09 18:18:31 -0700563
Ying Wang67f02922012-08-22 10:25:20 -0700564 if [ $(echo $arch | wc -w) -gt 1 ]; then
565 echo "tapas: Error: Multiple build archs supplied: $arch"
566 return
567 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700568 if [ $(echo $variant | wc -w) -gt 1 ]; then
569 echo "tapas: Error: Multiple build variants supplied: $variant"
570 return
571 fi
Ying Wang67f02922012-08-22 10:25:20 -0700572
573 local product=full
574 case $arch in
575 x86) product=full_x86;;
576 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800577 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700578 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700579 if [ -z "$variant" ]; then
580 variant=eng
581 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700582 if [ -z "$apps" ]; then
583 apps=all
584 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700585
Ying Wang67f02922012-08-22 10:25:20 -0700586 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700587 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700588 export TARGET_BUILD_TYPE=release
589 export TARGET_BUILD_APPS=$apps
590
591 set_stuff_for_environment
592 printconfig
593}
594
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700595function gettop
596{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800597 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700598 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
599 echo $TOP
600 else
601 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800602 # The following circumlocution (repeated below as well) ensures
603 # that we record the true directory name and not one that is
604 # faked up with symlink names.
605 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700606 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800607 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700608 T=
609 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800610 \cd ..
synergyb112a402013-07-05 19:47:47 -0700611 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700612 done
Ying Wang9cd17642012-12-13 10:52:07 -0800613 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700614 if [ -f "$T/$TOPFILE" ]; then
615 echo $T
616 fi
617 fi
618 fi
619}
620
Andrew Hsieh906cb782013-09-10 17:37:14 +0800621# Return driver for "make", if any (eg. static analyzer)
622function getdriver()
623{
624 local T="$1"
625 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
626 if [ -n "$WITH_STATIC_ANALYZER" ]; then
627 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800628$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
629--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800630--status-bugs \
631--top=$T"
632 fi
633}
634
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700635function m()
636{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800637 local T=$(gettop)
638 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700639 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800640 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700641 else
642 echo "Couldn't locate the top of the tree. Try setting TOP."
643 fi
644}
645
646function findmakefile()
647{
648 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800649 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700650 T=
651 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700652 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653 if [ -f "$T/Android.mk" ]; then
654 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800655 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700656 return
657 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800658 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659 done
Ying Wang9cd17642012-12-13 10:52:07 -0800660 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661}
662
663function mm()
664{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800665 local T=$(gettop)
666 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700667 # If we're sitting in the root of the build tree, just do a
668 # normal make.
669 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800670 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700671 else
672 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800673 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700674 local MODULES=
675 local GET_INSTALL_PATH=
676 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700677 # Remove the path to top as the makefilepath needs to be relative
678 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700679 if [ ! "$T" ]; then
680 echo "Couldn't locate the top of the tree. Try setting TOP."
681 elif [ ! "$M" ]; then
682 echo "Couldn't locate a makefile from the current directory."
683 else
Ying Wanga7deb082013-08-16 13:24:47 -0700684 for ARG in $@; do
685 case $ARG in
686 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
687 esac
688 done
689 if [ -n "$GET_INSTALL_PATH" ]; then
690 MODULES=
691 ARGS=GET-INSTALL-PATH
692 else
693 MODULES=all_modules
694 ARGS=$@
695 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700696 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 -0700697 fi
698 fi
699}
700
701function mmm()
702{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800703 local T=$(gettop)
704 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700705 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800706 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800707 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800708 local ARGS=
709 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700710 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800711 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
712 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
713 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800714 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
715 if [ "$MODULES" = "" ]; then
716 MODULES=all_modules
717 fi
718 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700719 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700720 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
721 local TO_CHOP=`expr $TO_CHOP + 1`
722 local START=`PWD= /bin/pwd`
723 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700724 if [ "$MFILE" = "" ] ; then
725 MFILE=$DIR/Android.mk
726 else
727 MFILE=$MFILE/$DIR/Android.mk
728 fi
729 MAKEFILE="$MAKEFILE $MFILE"
730 else
Ying Wanga7deb082013-08-16 13:24:47 -0700731 case $DIR in
732 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
733 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
734 *) echo "No Android.mk in $DIR."; return 1;;
735 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700736 fi
737 done
Ying Wanga7deb082013-08-16 13:24:47 -0700738 if [ -n "$GET_INSTALL_PATH" ]; then
739 ARGS=$GET_INSTALL_PATH
740 MODULES=
741 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800742 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 -0700743 else
744 echo "Couldn't locate the top of the tree. Try setting TOP."
745 fi
746}
747
Ying Wangb607f7b2013-02-08 18:01:04 -0800748function mma()
749{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800750 local T=$(gettop)
751 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800752 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800753 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800754 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800755 if [ ! "$T" ]; then
756 echo "Couldn't locate the top of the tree. Try setting TOP."
757 fi
758 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800759 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800760 fi
761}
762
763function mmma()
764{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800765 local T=$(gettop)
766 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800767 if [ "$T" ]; then
768 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
769 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
770 local MY_PWD=`PWD= /bin/pwd`
771 if [ "$MY_PWD" = "$T" ]; then
772 MY_PWD=
773 else
774 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
775 fi
776 local DIR=
777 local MODULE_PATHS=
778 local ARGS=
779 for DIR in $DIRS ; do
780 if [ -d $DIR ]; then
781 if [ "$MY_PWD" = "" ]; then
782 MODULE_PATHS="$MODULE_PATHS $DIR"
783 else
784 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
785 fi
786 else
787 case $DIR in
788 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
789 *) echo "Couldn't find directory $DIR"; return 1;;
790 esac
791 fi
792 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800793 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
Ying Wangb607f7b2013-02-08 18:01:04 -0800794 else
795 echo "Couldn't locate the top of the tree. Try setting TOP."
796 fi
797}
798
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700799function croot()
800{
801 T=$(gettop)
802 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800803 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700804 else
805 echo "Couldn't locate the top of the tree. Try setting TOP."
806 fi
807}
808
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700809function cproj()
810{
811 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700812 local HERE=$PWD
813 T=
814 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
815 T=$PWD
816 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800817 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700818 return
819 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800820 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700821 done
Ying Wang9cd17642012-12-13 10:52:07 -0800822 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700823 echo "can't find Android.mk"
824}
825
Daniel Sandler47e0a882013-07-30 13:23:52 -0400826# simplified version of ps; output in the form
827# <pid> <procname>
828function qpid() {
829 local prepend=''
830 local append=''
831 if [ "$1" = "--exact" ]; then
832 prepend=' '
833 append='$'
834 shift
835 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
836 echo "usage: qpid [[--exact] <process name|pid>"
837 return 255
838 fi
839
840 local EXE="$1"
841 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700842 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400843 else
844 adb shell ps \
845 | tr -d '\r' \
846 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
847 fi
848}
849
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850function pid()
851{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400852 local prepend=''
853 local append=''
854 if [ "$1" = "--exact" ]; then
855 prepend=' '
856 append='$'
857 shift
858 fi
859 local EXE="$1"
860 if [ "$EXE" ] ; then
861 local PID=`adb shell ps \
862 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700863 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400864 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
865 echo "$PID"
866 else
867 echo "usage: pid [--exact] <process name>"
868 return 255
869 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700870}
871
Christopher Tate744ee802009-11-12 15:33:08 -0800872# systemstack - dump the current stack trace of all threads in the system process
873# to the usual ANR traces file
874function systemstack()
875{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800876 stacks system_server
877}
878
879function stacks()
880{
881 if [[ $1 =~ ^[0-9]+$ ]] ; then
882 local PID="$1"
883 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700884 local PIDLIST="$(pid $1)"
885 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
886 local PID="$PIDLIST"
887 elif [ "$PIDLIST" ] ; then
888 echo "more than one process: $1"
889 else
890 echo "no such process: $1"
891 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800892 else
893 echo "usage: stacks [pid|process name]"
894 fi
895
896 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700897 # Determine whether the process is native
898 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
899 # Dump stacks of Dalvik process
900 local TRACES=/data/anr/traces.txt
901 local ORIG=/data/anr/traces.orig
902 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800903
Jeff Brownb12c2e52013-08-19 15:14:16 -0700904 # Keep original traces to avoid clobbering
905 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800906
Jeff Brownb12c2e52013-08-19 15:14:16 -0700907 # Make sure we have a usable file
908 adb shell touch $TRACES
909 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800910
Jeff Brownb12c2e52013-08-19 15:14:16 -0700911 # Dump stacks and wait for dump to finish
912 adb shell kill -3 $PID
913 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800914
Jeff Brownb12c2e52013-08-19 15:14:16 -0700915 # Restore original stacks, and show current output
916 adb shell mv $TRACES $TMP
917 adb shell mv $ORIG $TRACES
918 adb shell cat $TMP
919 else
920 # Dump stacks of native process
921 adb shell debuggerd -b $PID
922 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800923 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800924}
925
John Michelau50200252012-11-09 11:48:04 -0600926function gdbwrapper()
927{
Ben Chengfba67bf2014-02-25 10:27:07 -0800928 local GDB_CMD="$1"
929 shift 1
930 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -0600931}
932
Ben Chengfba67bf2014-02-25 10:27:07 -0800933# process the symbolic link of /proc/$PID/exe and use the host file tool to
934# determine whether it is a 32-bit or 64-bit executable. It returns "" or "64"
935# which can be conveniently used as suffix.
936function is64bit()
937{
938 local PID="$1"
939 if [ "$PID" ] ; then
940 local EXE=`adb shell ls -l /proc/$PID/exe \
941 | tr -d '\r' \
942 | cut -d'>' -f2 \
943 | tr -d ' ' \
944 | cut -d'/' -f4`
945
946 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
947 local IS64BIT=`file $OUT_EXE_SYMBOLS/$EXE | grep "64-bit"`
948 if [ "$IS64BIT" != "" ]; then
949 echo "64"
950 else
951 echo ""
952 fi
953 else
954 echo ""
955 fi
956}
957
958# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
959# executable, set up the approriate gdbserver, then invokes the proper host
960# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700961function gdbclient()
962{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800963 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
964 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
965 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
966 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
967 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800968 local ARCH=$(get_build_var TARGET_ARCH)
969 local GDB
970 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800971 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800972 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700973 mips) GDB=mipsel-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000974 mips64) GDB=mipsel-linux-android-gdb;;
975 x86) GDB=x86_64-linux-android-gdb;;
976 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800977 *) echo "Unknown arch $ARCH"; return 1;;
978 esac
979
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700980 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
981 local EXE="$1"
982 if [ "$EXE" ] ; then
983 EXE=$1
984 else
985 EXE="app_process"
986 fi
987
988 local PORT="$2"
989 if [ "$PORT" ] ; then
990 PORT=$2
991 else
992 PORT=":5039"
993 fi
994
Chris Craik20c136a2012-11-09 18:02:19 -0800995 local PID="$3"
996 if [ "$PID" ] ; then
997 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700998 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800999 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1000 # that likely didn't work because of returning multiple processes
1001 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001002 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001003 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1004 then
1005 echo "Couldn't resolve '$3' to single PID"
1006 return 1
1007 else
1008 echo ""
1009 echo "WARNING: multiple processes matching '$3' observed, using root process"
1010 echo ""
1011 fi
1012 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001013 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001014 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001015 local USE64BIT="$(is64bit $PID)"
1016 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001017 sleep 2
1018 else
1019 echo ""
1020 echo "If you haven't done so already, do this first on the device:"
1021 echo " gdbserver $PORT /system/bin/$EXE"
1022 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001023 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001024 echo ""
1025 fi
1026
1027 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Ben Chengfba67bf2014-02-25 10:27:07 -08001028 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS$USE64BIT:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx"
Ben Cheng72398162013-06-24 14:36:21 -07001029 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001030 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1031 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1032
Ben Chengfba67bf2014-02-25 10:27:07 -08001033 local WHICH_GDB=
1034 # 64-bit exe found
1035 if [ "$USE64BIT" != "" ] ; then
1036 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1037 # 32-bit exe / 32-bit platform
1038 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1039 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1040 # 32-bit exe / 64-bit platform
1041 else
1042 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1043 fi
1044 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001045 else
1046 echo "Unable to determine build system output dir."
1047 fi
1048
1049}
1050
1051case `uname -s` in
1052 Darwin)
1053 function sgrep()
1054 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001055 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml|sh|mk)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001056 }
1057
1058 ;;
1059 *)
1060 function sgrep()
1061 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001062 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cpp\|S\|java\|xml\|sh\|mk\)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001063 }
1064 ;;
1065esac
1066
Raghu Gandham8da43102012-07-25 19:57:22 -07001067function gettargetarch
1068{
1069 get_build_var TARGET_ARCH
1070}
1071
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001072function jgrep()
1073{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001074 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 -07001075}
1076
1077function cgrep()
1078{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001079 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' \) -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001080}
1081
1082function resgrep()
1083{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001084 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 -07001085}
1086
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001087function mangrep()
1088{
1089 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1090}
1091
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001092function sepgrep()
1093{
1094 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 "$@"
1095}
1096
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001097case `uname -s` in
1098 Darwin)
1099 function mgrep()
1100 {
Ying Wang324c2b22012-08-17 15:03:20 -07001101 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 -07001102 }
1103
1104 function treegrep()
1105 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001106 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 -07001107 }
1108
1109 ;;
1110 *)
1111 function mgrep()
1112 {
Ying Wang324c2b22012-08-17 15:03:20 -07001113 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 -07001114 }
1115
1116 function treegrep()
1117 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001118 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 -07001119 }
1120
1121 ;;
1122esac
1123
1124function getprebuilt
1125{
1126 get_abs_build_var ANDROID_PREBUILTS
1127}
1128
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001129function tracedmdump()
1130{
1131 T=$(gettop)
1132 if [ ! "$T" ]; then
1133 echo "Couldn't locate the top of the tree. Try setting TOP."
1134 return
1135 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001136 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001137 local arch=$(gettargetarch)
1138 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001139
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001140 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001141 if [ ! "$TRACE" ] ; then
1142 echo "usage: tracedmdump tracename"
1143 return
1144 fi
1145
Jack Veenstra60116fc2009-04-09 18:12:34 -07001146 if [ ! -r "$KERNEL" ] ; then
1147 echo "Error: cannot find kernel: '$KERNEL'"
1148 return
1149 fi
1150
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001151 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001152 if [ "$BASETRACE" = "$TRACE" ] ; then
1153 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1154 fi
1155
1156 echo "post-processing traces..."
1157 rm -f $TRACE/qtrace.dexlist
1158 post_trace $TRACE
1159 if [ $? -ne 0 ]; then
1160 echo "***"
1161 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1162 echo "***"
1163 return
1164 fi
1165 echo "generating dexlist output..."
1166 /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
1167 echo "generating dmtrace data..."
1168 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1169 echo "generating html file..."
1170 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1171 echo "done, see $TRACE/dmtrace.html for details"
1172 echo "or run:"
1173 echo " traceview $TRACE/dmtrace"
1174}
1175
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001176# communicate with a running device or emulator, set up necessary state,
1177# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001178function runhat()
1179{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001180 # process standard adb options
1181 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001182 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001183 adbTarget=$1
1184 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001185 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001186 adbTarget="$1 $2"
1187 shift 2
1188 fi
1189 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001190 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001191
1192 # runhat options
1193 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001194
1195 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001196 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001197 return
1198 fi
1199
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001200 # confirm hat is available
1201 if [ -z $(which hat) ]; then
1202 echo "hat is not available in this configuration."
1203 return
1204 fi
1205
Andy McFaddenb6289852010-07-12 08:00:19 -07001206 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001207 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001208 local devFile=$sdcard/hprof-$targetPid
1209 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001210 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001211 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001212 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001213 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001214 echo -n "> "
1215 read
1216
The Android Open Source Project88b60792009-03-03 19:28:42 -08001217 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001218
The Android Open Source Project88b60792009-03-03 19:28:42 -08001219 echo "Retrieving file $devFile..."
1220 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001221
The Android Open Source Project88b60792009-03-03 19:28:42 -08001222 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001223
The Android Open Source Project88b60792009-03-03 19:28:42 -08001224 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001225 echo "View the output by pointing your browser at http://localhost:7000/"
1226 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001227 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001228}
1229
1230function getbugreports()
1231{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001232 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001233
1234 if [ ! "$reports" ]; then
1235 echo "Could not locate any bugreports."
1236 return
1237 fi
1238
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001239 local report
1240 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001241 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001242 echo "/sdcard/bugreports/${report}"
1243 adb pull /sdcard/bugreports/${report} ${report}
1244 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001245 done
1246}
1247
Victoria Lease1b296b42012-08-21 15:44:06 -07001248function getsdcardpath()
1249{
1250 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1251}
1252
1253function getscreenshotpath()
1254{
1255 echo "$(getsdcardpath)/Pictures/Screenshots"
1256}
1257
1258function getlastscreenshot()
1259{
1260 local screenshot_path=$(getscreenshotpath)
1261 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1262 if [ "$screenshot" = "" ]; then
1263 echo "No screenshots found."
1264 return
1265 fi
1266 echo "${screenshot}"
1267 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1268}
1269
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001270function startviewserver()
1271{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001272 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001273 if [ $# -gt 0 ]; then
1274 port=$1
1275 fi
1276 adb shell service call window 1 i32 $port
1277}
1278
1279function stopviewserver()
1280{
1281 adb shell service call window 2
1282}
1283
1284function isviewserverstarted()
1285{
1286 adb shell service call window 3
1287}
1288
Romain Guyb84049a2010-10-04 16:56:11 -07001289function key_home()
1290{
1291 adb shell input keyevent 3
1292}
1293
1294function key_back()
1295{
1296 adb shell input keyevent 4
1297}
1298
1299function key_menu()
1300{
1301 adb shell input keyevent 82
1302}
1303
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001304function smoketest()
1305{
1306 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1307 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1308 return
1309 fi
1310 T=$(gettop)
1311 if [ ! "$T" ]; then
1312 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1313 return
1314 fi
1315
Ying Wang9cd17642012-12-13 10:52:07 -08001316 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001317 adb uninstall com.android.smoketest > /dev/null &&
1318 adb uninstall com.android.smoketest.tests > /dev/null &&
1319 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1320 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1321 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1322}
1323
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001324# simple shortcut to the runtest command
1325function runtest()
1326{
1327 T=$(gettop)
1328 if [ ! "$T" ]; then
1329 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1330 return
1331 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001332 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001333}
1334
The Android Open Source Project88b60792009-03-03 19:28:42 -08001335function godir () {
1336 if [[ -z "$1" ]]; then
1337 echo "Usage: godir <regex>"
1338 return
1339 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001340 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001341 if [[ ! -f $T/filelist ]]; then
1342 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001343 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001344 echo " Done"
1345 echo ""
1346 fi
1347 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001348 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001349 if [[ ${#lines[@]} = 0 ]]; then
1350 echo "Not found"
1351 return
1352 fi
1353 local pathname
1354 local choice
1355 if [[ ${#lines[@]} > 1 ]]; then
1356 while [[ -z "$pathname" ]]; do
1357 local index=1
1358 local line
1359 for line in ${lines[@]}; do
1360 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001361 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001362 done
1363 echo
1364 echo -n "Select one: "
1365 unset choice
1366 read choice
1367 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1368 echo "Invalid choice"
1369 continue
1370 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001371 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001372 done
1373 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001374 pathname=${lines[0]}
1375 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001376 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001377}
1378
Narayan Kamath9260bba2014-01-17 10:05:25 +00001379# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1380#
1381# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1382# For some reason, installing the JDK doesn't make it show up in the
1383# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001384function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001385 # Clear the existing JAVA_HOME value if we set it ourselves, so that
1386 # we can reset it later, depending on the value of EXPERIMENTAL_USE_JAVA7.
1387 #
1388 # If we don't do this, the JAVA_HOME value set by the first call to
1389 # build/envsetup.sh will persist forever.
1390 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1391 export JAVA_HOME=""
1392 fi
1393
Andy McFaddenbd960942010-06-24 12:52:51 -07001394 if [ ! "$JAVA_HOME" ]; then
Narayan Kamath9260bba2014-01-17 10:05:25 +00001395 if [ ! "$EXPERIMENTAL_USE_JAVA7" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001396 case `uname -s` in
1397 Darwin)
1398 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1399 ;;
1400 *)
1401 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1402 ;;
1403 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001404 else
1405 case `uname -s` in
1406 Darwin)
1407 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
1408 ;;
1409 *)
1410 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1411 ;;
1412 esac
1413 fi
1414
1415 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1416 # we can change it on the next envsetup.sh, if required.
1417 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001418 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001419}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001420
Alex Rayf0d08eb2013-03-08 15:15:06 -08001421# Print colored exit condition
1422function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001423 "$@"
1424 local retval=$?
1425 if [ $retval -ne 0 ]
1426 then
1427 echo -e "\e[0;31mFAILURE\e[00m"
1428 else
1429 echo -e "\e[0;32mSUCCESS\e[00m"
1430 fi
1431 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001432}
1433
Raphael Moll70a86b02011-06-20 16:03:14 -07001434if [ "x$SHELL" != "x/bin/bash" ]; then
1435 case `ps -o command -p $$` in
1436 *bash*)
1437 ;;
1438 *)
1439 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1440 ;;
1441 esac
1442fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001443
1444# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001445for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1446 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001447do
1448 echo "including $f"
1449 . $f
1450done
1451unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001452
1453addcompletions