blob: cba01be1112bc76d69a02ed85a0ebb3a1b1f642a [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.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070013- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070014- jgrep: Greps on all local Java files.
15- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080016- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070017
18Look at the source to view more functions. The complete list is:
19EOF
20 T=$(gettop)
21 local A
22 A=""
23 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
24 A="$A $i"
25 done
26 echo $A
27}
28
29# Get the value of a build variable as an absolute path.
30function get_abs_build_var()
31{
32 T=$(gettop)
33 if [ ! "$T" ]; then
34 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
35 return
36 fi
Ying Wang9cd17642012-12-13 10:52:07 -080037 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Brian Carlstrom177285a2010-04-06 13:22:02 -070038 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070039}
40
41# Get the exact value of a build variable.
42function get_build_var()
43{
44 T=$(gettop)
45 if [ ! "$T" ]; then
46 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
47 return
48 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080049 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
50 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1
51}
52
53# check to see if the supplied product is one we can build
54function check_product()
55{
56 T=$(gettop)
57 if [ ! "$T" ]; then
58 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
59 return
60 fi
61 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Jeff Browne33ba4c2011-07-11 22:11:46 -070062 TARGET_PRODUCT=$1 \
63 TARGET_BUILD_VARIANT= \
64 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070065 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080066 get_build_var TARGET_DEVICE > /dev/null
67 # hide successful answers, but allow the errors to show
68}
69
70VARIANT_CHOICES=(user userdebug eng)
71
72# check to see if the supplied variant is valid
73function check_variant()
74{
75 for v in ${VARIANT_CHOICES[@]}
76 do
77 if [ "$v" = "$1" ]
78 then
79 return 0
80 fi
81 done
82 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070083}
84
85function setpaths()
86{
87 T=$(gettop)
88 if [ ! "$T" ]; then
89 echo "Couldn't locate the top of the tree. Try setting TOP."
90 return
91 fi
92
93 ##################################################################
94 # #
95 # Read me before you modify this code #
96 # #
97 # This function sets ANDROID_BUILD_PATHS to what it is adding #
98 # to PATH, and the next time it is run, it removes that from #
99 # PATH. This is required so lunch can be run more than once #
100 # and still have working paths. #
101 # #
102 ##################################################################
103
Raphael Mollc639c782011-06-20 17:25:01 -0700104 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
105 # due to "C:\Program Files" being in the path.
106
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700107 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700108 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700109 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
110 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700111 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700112 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800113 # strip leading ':', if any
114 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500115 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700116
117 # and in with the new
118 CODE_REVIEWS=
119 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700120 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700121
Ben Cheng8bc4c432012-11-16 13:29:13 -0800122 # defined in core/config.mk
123 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800124 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800125
Raphael Mollc639c782011-06-20 17:25:01 -0700126 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Raphael732936d2011-06-22 14:35:32 -0700127 export ANDROID_EABI_TOOLCHAIN=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200128 local ARCH=$(get_build_var TARGET_ARCH)
129 case $ARCH in
Ben Cheng054ffd22012-12-11 14:01:10 -0800130 x86) toolchaindir=x86/i686-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700131 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800132 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200133 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800134 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700135 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200136 *)
137 echo "Can't find toolchain for unknown architecture: $ARCH"
138 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700139 ;;
140 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700141 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
142 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700143 fi
Raphael732936d2011-06-22 14:35:32 -0700144
Bruce Beare42ced6d2012-07-17 21:40:01 -0700145 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700146 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700147 arm)
Ben Cheng8bc4c432012-11-16 13:29:13 -0800148 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700149 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
150 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
151 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
152 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700153 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700154 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
155 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700156 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700157 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700158 ;;
159 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700160
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700161 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
162 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700163 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wangaa1c9b52012-11-26 20:51:59 -0800164 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
165 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800166
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500167 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900168 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500169 if [ -n "$JAVA_HOME" ]; then
170 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900171 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
172 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500173 fi
174
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800175 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700176 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
177 export OUT=$ANDROID_PRODUCT_OUT
178
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700179 unset ANDROID_HOST_OUT
180 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
181
Ben Cheng057fde12011-11-28 13:55:14 -0800182 # needed for processing samples collected by perf counters
183 unset OPROFILE_EVENTS_DIR
184 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
185
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800186 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700187 # TODO: fix the path
188 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
189}
190
191function printconfig()
192{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800193 T=$(gettop)
194 if [ ! "$T" ]; then
195 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
196 return
197 fi
198 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700199}
200
201function set_stuff_for_environment()
202{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800203 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500204 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800205 setpaths
206 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700207
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800208 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700209}
210
211function set_sequence_number()
212{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700213 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700214}
215
216function settitle()
217{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800218 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700219 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700220 local product=$TARGET_PRODUCT
221 local variant=$TARGET_BUILD_VARIANT
222 local apps=$TARGET_BUILD_APPS
223 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700224 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700225 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700226 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700227 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800228 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700229}
230
Kenny Root52aa81c2011-07-15 11:07:06 -0700231function addcompletions()
232{
233 local T dir f
234
235 # Keep us from trying to run in something that isn't bash.
236 if [ -z "${BASH_VERSION}" ]; then
237 return
238 fi
239
240 # Keep us from trying to run in bash that's too old.
241 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
242 return
243 fi
244
245 dir="sdk/bash_completion"
246 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700247 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700248 echo "including $f"
249 . $f
250 done
251 fi
252}
253
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700254function choosetype()
255{
256 echo "Build type choices are:"
257 echo " 1. release"
258 echo " 2. debug"
259 echo
260
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800261 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700262 DEFAULT_NUM=1
263 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700264
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800265 export TARGET_BUILD_TYPE=
266 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700267 while [ -z $TARGET_BUILD_TYPE ]
268 do
269 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800270 if [ -z "$1" ] ; then
271 read ANSWER
272 else
273 echo $1
274 ANSWER=$1
275 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700276 case $ANSWER in
277 "")
278 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
279 ;;
280 1)
281 export TARGET_BUILD_TYPE=release
282 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800283 release)
284 export TARGET_BUILD_TYPE=release
285 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700286 2)
287 export TARGET_BUILD_TYPE=debug
288 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800289 debug)
290 export TARGET_BUILD_TYPE=debug
291 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700292 *)
293 echo
294 echo "I didn't understand your response. Please try again."
295 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700296 ;;
297 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800298 if [ -n "$1" ] ; then
299 break
300 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700301 done
302
303 set_stuff_for_environment
304}
305
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800306#
307# This function isn't really right: It chooses a TARGET_PRODUCT
308# based on the list of boards. Usually, that gets you something
309# that kinda works with a generic product, but really, you should
310# pick a product by name.
311#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700312function chooseproduct()
313{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700314 if [ "x$TARGET_PRODUCT" != x ] ; then
315 default_value=$TARGET_PRODUCT
316 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700317 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700318 fi
319
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800320 export TARGET_PRODUCT=
321 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700322 while [ -z "$TARGET_PRODUCT" ]
323 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700324 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800325 if [ -z "$1" ] ; then
326 read ANSWER
327 else
328 echo $1
329 ANSWER=$1
330 fi
331
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332 if [ -z "$ANSWER" ] ; then
333 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800334 else
335 if check_product $ANSWER
336 then
337 export TARGET_PRODUCT=$ANSWER
338 else
339 echo "** Not a valid product: $ANSWER"
340 fi
341 fi
342 if [ -n "$1" ] ; then
343 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700344 fi
345 done
346
347 set_stuff_for_environment
348}
349
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800350function choosevariant()
351{
352 echo "Variant choices are:"
353 local index=1
354 local v
355 for v in ${VARIANT_CHOICES[@]}
356 do
357 # The product name is the name of the directory containing
358 # the makefile we found, above.
359 echo " $index. $v"
360 index=$(($index+1))
361 done
362
363 local default_value=eng
364 local ANSWER
365
366 export TARGET_BUILD_VARIANT=
367 while [ -z "$TARGET_BUILD_VARIANT" ]
368 do
369 echo -n "Which would you like? [$default_value] "
370 if [ -z "$1" ] ; then
371 read ANSWER
372 else
373 echo $1
374 ANSWER=$1
375 fi
376
377 if [ -z "$ANSWER" ] ; then
378 export TARGET_BUILD_VARIANT=$default_value
379 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
380 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800381 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800382 fi
383 else
384 if check_variant $ANSWER
385 then
386 export TARGET_BUILD_VARIANT=$ANSWER
387 else
388 echo "** Not a valid variant: $ANSWER"
389 fi
390 fi
391 if [ -n "$1" ] ; then
392 break
393 fi
394 done
395}
396
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700397function choosecombo()
398{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700399 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700400
401 echo
402 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700403 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700404
405 echo
406 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700407 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800408
409 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700410 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800411 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700412}
413
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800414# Clear this variable. It will be built up again when the vendorsetup.sh
415# files are included at the end of this file.
416unset LUNCH_MENU_CHOICES
417function add_lunch_combo()
418{
419 local new_combo=$1
420 local c
421 for c in ${LUNCH_MENU_CHOICES[@]} ; do
422 if [ "$new_combo" = "$c" ] ; then
423 return
424 fi
425 done
426 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
427}
428
429# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700430add_lunch_combo aosp_arm-eng
431add_lunch_combo aosp_x86-eng
432add_lunch_combo aosp_mips-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800433add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800434
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700435function print_lunch_menu()
436{
437 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700438 echo
439 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700440 echo
441 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800442
443 local i=1
444 local choice
445 for choice in ${LUNCH_MENU_CHOICES[@]}
446 do
447 echo " $i. $choice"
448 i=$(($i+1))
449 done
450
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700451 echo
452}
453
454function lunch()
455{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800456 local answer
457
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800459 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700460 else
461 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700462 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800463 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700464 fi
465
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800466 local selection=
467
468 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700469 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700470 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800471 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
472 then
473 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
474 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800475 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476 fi
477 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
478 then
479 selection=$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 if [ -z "$selection" ]
483 then
484 echo
485 echo "Invalid lunch combo: $answer"
486 return 1
487 fi
488
Joe Onoratoda12daf2010-06-09 18:18:31 -0700489 export TARGET_BUILD_APPS=
490
Jeff Browne33ba4c2011-07-11 22:11:46 -0700491 local product=$(echo -n $selection | sed -e "s/-.*$//")
492 check_product $product
493 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800494 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700495 echo
496 echo "** Don't have a product spec for: '$product'"
497 echo "** Do you have the right repo manifest?"
498 product=
499 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800500
Jeff Browne33ba4c2011-07-11 22:11:46 -0700501 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
502 check_variant $variant
503 if [ $? -ne 0 ]
504 then
505 echo
506 echo "** Invalid variant: '$variant'"
507 echo "** Must be one of ${VARIANT_CHOICES[@]}"
508 variant=
509 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800510
Jeff Browne33ba4c2011-07-11 22:11:46 -0700511 if [ -z "$product" -o -z "$variant" ]
512 then
513 echo
514 return 1
515 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800516
Jeff Browne33ba4c2011-07-11 22:11:46 -0700517 export TARGET_PRODUCT=$product
518 export TARGET_BUILD_VARIANT=$variant
519 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700520
521 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700523 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800524 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700525}
526
Jeff Davidson513d7a42010-08-02 10:00:44 -0700527# Tab completion for lunch.
528function _lunch()
529{
530 local cur prev opts
531 COMPREPLY=()
532 cur="${COMP_WORDS[COMP_CWORD]}"
533 prev="${COMP_WORDS[COMP_CWORD-1]}"
534
535 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
536 return 0
537}
538complete -F _lunch lunch
539
Joe Onoratoda12daf2010-06-09 18:18:31 -0700540# Configures the build to build unbundled apps.
541# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
542function tapas()
543{
Ying Wangf05c4f72013-01-31 11:16:57 -0800544 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600545 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800546 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 -0700547
Ying Wang67f02922012-08-22 10:25:20 -0700548 if [ $(echo $arch | wc -w) -gt 1 ]; then
549 echo "tapas: Error: Multiple build archs supplied: $arch"
550 return
551 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700552 if [ $(echo $variant | wc -w) -gt 1 ]; then
553 echo "tapas: Error: Multiple build variants supplied: $variant"
554 return
555 fi
Ying Wang67f02922012-08-22 10:25:20 -0700556
557 local product=full
558 case $arch in
559 x86) product=full_x86;;
560 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800561 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700562 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700563 if [ -z "$variant" ]; then
564 variant=eng
565 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700566 if [ -z "$apps" ]; then
567 apps=all
568 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700569
Ying Wang67f02922012-08-22 10:25:20 -0700570 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700571 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700572 export TARGET_BUILD_TYPE=release
573 export TARGET_BUILD_APPS=$apps
574
575 set_stuff_for_environment
576 printconfig
577}
578
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700579function gettop
580{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800581 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
583 echo $TOP
584 else
585 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800586 # The following circumlocution (repeated below as well) ensures
587 # that we record the true directory name and not one that is
588 # faked up with symlink names.
589 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800591 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592 T=
593 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800594 \cd ..
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800595 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596 done
Ying Wang9cd17642012-12-13 10:52:07 -0800597 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700598 if [ -f "$T/$TOPFILE" ]; then
599 echo $T
600 fi
601 fi
602 fi
603}
604
605function m()
606{
607 T=$(gettop)
608 if [ "$T" ]; then
Joe Onoratofa72a602013-01-11 12:49:04 -0800609 make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700610 else
611 echo "Couldn't locate the top of the tree. Try setting TOP."
612 fi
613}
614
615function findmakefile()
616{
617 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800618 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700619 T=
620 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700621 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700622 if [ -f "$T/Android.mk" ]; then
623 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800624 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700625 return
626 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800627 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700628 done
Ying Wang9cd17642012-12-13 10:52:07 -0800629 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700630}
631
632function mm()
633{
634 # If we're sitting in the root of the build tree, just do a
635 # normal make.
636 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
637 make $@
638 else
639 # Find the closest Android.mk file.
640 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800641 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700642 local MODULES=
643 local GET_INSTALL_PATH=
644 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700645 # Remove the path to top as the makefilepath needs to be relative
646 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700647 if [ ! "$T" ]; then
648 echo "Couldn't locate the top of the tree. Try setting TOP."
649 elif [ ! "$M" ]; then
650 echo "Couldn't locate a makefile from the current directory."
651 else
Ying Wanga7deb082013-08-16 13:24:47 -0700652 for ARG in $@; do
653 case $ARG in
654 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
655 esac
656 done
657 if [ -n "$GET_INSTALL_PATH" ]; then
658 MODULES=
659 ARGS=GET-INSTALL-PATH
660 else
661 MODULES=all_modules
662 ARGS=$@
663 fi
664 ONE_SHOT_MAKEFILE=$M make -C $T -f build/core/main.mk $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700665 fi
666 fi
667}
668
669function mmm()
670{
671 T=$(gettop)
672 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800673 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800674 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800675 local ARGS=
676 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700677 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800678 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
679 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
680 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800681 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
682 if [ "$MODULES" = "" ]; then
683 MODULES=all_modules
684 fi
685 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700686 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700687 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
688 local TO_CHOP=`expr $TO_CHOP + 1`
689 local START=`PWD= /bin/pwd`
690 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700691 if [ "$MFILE" = "" ] ; then
692 MFILE=$DIR/Android.mk
693 else
694 MFILE=$MFILE/$DIR/Android.mk
695 fi
696 MAKEFILE="$MAKEFILE $MFILE"
697 else
Ying Wanga7deb082013-08-16 13:24:47 -0700698 case $DIR in
699 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
700 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
701 *) echo "No Android.mk in $DIR."; return 1;;
702 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700703 fi
704 done
Ying Wanga7deb082013-08-16 13:24:47 -0700705 if [ -n "$GET_INSTALL_PATH" ]; then
706 ARGS=$GET_INSTALL_PATH
707 MODULES=
708 fi
Joe Onoratofa72a602013-01-11 12:49:04 -0800709 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700710 else
711 echo "Couldn't locate the top of the tree. Try setting TOP."
712 fi
713}
714
Ying Wangb607f7b2013-02-08 18:01:04 -0800715function mma()
716{
717 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
718 make $@
719 else
720 T=$(gettop)
721 if [ ! "$T" ]; then
722 echo "Couldn't locate the top of the tree. Try setting TOP."
723 fi
724 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
725 make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
726 fi
727}
728
729function mmma()
730{
731 T=$(gettop)
732 if [ "$T" ]; then
733 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
734 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
735 local MY_PWD=`PWD= /bin/pwd`
736 if [ "$MY_PWD" = "$T" ]; then
737 MY_PWD=
738 else
739 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
740 fi
741 local DIR=
742 local MODULE_PATHS=
743 local ARGS=
744 for DIR in $DIRS ; do
745 if [ -d $DIR ]; then
746 if [ "$MY_PWD" = "" ]; then
747 MODULE_PATHS="$MODULE_PATHS $DIR"
748 else
749 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
750 fi
751 else
752 case $DIR in
753 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
754 *) echo "Couldn't find directory $DIR"; return 1;;
755 esac
756 fi
757 done
758 make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
759 else
760 echo "Couldn't locate the top of the tree. Try setting TOP."
761 fi
762}
763
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700764function croot()
765{
766 T=$(gettop)
767 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800768 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700769 else
770 echo "Couldn't locate the top of the tree. Try setting TOP."
771 fi
772}
773
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700774function cproj()
775{
776 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700777 local HERE=$PWD
778 T=
779 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
780 T=$PWD
781 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800782 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700783 return
784 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800785 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700786 done
Ying Wang9cd17642012-12-13 10:52:07 -0800787 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700788 echo "can't find Android.mk"
789}
790
Daniel Sandler47e0a882013-07-30 13:23:52 -0400791# simplified version of ps; output in the form
792# <pid> <procname>
793function qpid() {
794 local prepend=''
795 local append=''
796 if [ "$1" = "--exact" ]; then
797 prepend=' '
798 append='$'
799 shift
800 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
801 echo "usage: qpid [[--exact] <process name|pid>"
802 return 255
803 fi
804
805 local EXE="$1"
806 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700807 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400808 else
809 adb shell ps \
810 | tr -d '\r' \
811 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
812 fi
813}
814
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700815function pid()
816{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400817 local prepend=''
818 local append=''
819 if [ "$1" = "--exact" ]; then
820 prepend=' '
821 append='$'
822 shift
823 fi
824 local EXE="$1"
825 if [ "$EXE" ] ; then
826 local PID=`adb shell ps \
827 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700828 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400829 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
830 echo "$PID"
831 else
832 echo "usage: pid [--exact] <process name>"
833 return 255
834 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700835}
836
Christopher Tate744ee802009-11-12 15:33:08 -0800837# systemstack - dump the current stack trace of all threads in the system process
838# to the usual ANR traces file
839function systemstack()
840{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800841 stacks system_server
842}
843
844function stacks()
845{
846 if [[ $1 =~ ^[0-9]+$ ]] ; then
847 local PID="$1"
848 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700849 local PIDLIST="$(pid $1)"
850 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
851 local PID="$PIDLIST"
852 elif [ "$PIDLIST" ] ; then
853 echo "more than one process: $1"
854 else
855 echo "no such process: $1"
856 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800857 else
858 echo "usage: stacks [pid|process name]"
859 fi
860
861 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700862 # Determine whether the process is native
863 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
864 # Dump stacks of Dalvik process
865 local TRACES=/data/anr/traces.txt
866 local ORIG=/data/anr/traces.orig
867 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800868
Jeff Brownb12c2e52013-08-19 15:14:16 -0700869 # Keep original traces to avoid clobbering
870 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800871
Jeff Brownb12c2e52013-08-19 15:14:16 -0700872 # Make sure we have a usable file
873 adb shell touch $TRACES
874 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800875
Jeff Brownb12c2e52013-08-19 15:14:16 -0700876 # Dump stacks and wait for dump to finish
877 adb shell kill -3 $PID
878 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800879
Jeff Brownb12c2e52013-08-19 15:14:16 -0700880 # Restore original stacks, and show current output
881 adb shell mv $TRACES $TMP
882 adb shell mv $ORIG $TRACES
883 adb shell cat $TMP
884 else
885 # Dump stacks of native process
886 adb shell debuggerd -b $PID
887 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800888 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800889}
890
John Michelau50200252012-11-09 11:48:04 -0600891function gdbwrapper()
892{
893 $ANDROID_TOOLCHAIN/$GDB -x "$@"
894}
895
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700896function gdbclient()
897{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800898 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
899 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
900 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
901 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
902 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800903 local ARCH=$(get_build_var TARGET_ARCH)
904 local GDB
905 case "$ARCH" in
Jean-Baptiste Querufeec98b2012-05-16 13:18:39 -0700906 x86) GDB=i686-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800907 arm) GDB=arm-linux-androideabi-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700908 mips) GDB=mipsel-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800909 *) echo "Unknown arch $ARCH"; return 1;;
910 esac
911
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700912 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
913 local EXE="$1"
914 if [ "$EXE" ] ; then
915 EXE=$1
916 else
917 EXE="app_process"
918 fi
919
920 local PORT="$2"
921 if [ "$PORT" ] ; then
922 PORT=$2
923 else
924 PORT=":5039"
925 fi
926
Chris Craik20c136a2012-11-09 18:02:19 -0800927 local PID="$3"
928 if [ "$PID" ] ; then
929 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700930 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800931 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
932 # that likely didn't work because of returning multiple processes
933 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -0700934 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -0800935 if [[ ! "$PID" =~ ^[0-9]+$ ]]
936 then
937 echo "Couldn't resolve '$3' to single PID"
938 return 1
939 else
940 echo ""
941 echo "WARNING: multiple processes matching '$3' observed, using root process"
942 echo ""
943 fi
944 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -0700945 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700946 adb forward "tcp$PORT" "tcp$PORT"
947 adb shell gdbserver $PORT --attach $PID &
948 sleep 2
949 else
950 echo ""
951 echo "If you haven't done so already, do this first on the device:"
952 echo " gdbserver $PORT /system/bin/$EXE"
953 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -0800954 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700955 echo ""
956 fi
957
958 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Chris Dearman6858d512012-02-02 14:16:52 -0800959 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$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 -0700960 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700961 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
962 echo >>"$OUT_ROOT/gdbclient.cmds" ""
963
John Michelau50200252012-11-09 11:48:04 -0600964 gdbwrapper "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700965 else
966 echo "Unable to determine build system output dir."
967 fi
968
969}
970
971case `uname -s` in
972 Darwin)
973 function sgrep()
974 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700975 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 -0700976 }
977
978 ;;
979 *)
980 function sgrep()
981 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700982 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 -0700983 }
984 ;;
985esac
986
Raghu Gandham8da43102012-07-25 19:57:22 -0700987function gettargetarch
988{
989 get_build_var TARGET_ARCH
990}
991
Jon Boekenoogencbca56f2014-04-07 10:57:38 -0700992function ggrep()
993{
994 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
995}
996
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700997function jgrep()
998{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700999 find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001000}
1001
1002function cgrep()
1003{
Mike Dodd0c26d342011-04-07 13:29:06 -07001004 find . -name .repo -prune -o -name .git -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 -07001005}
1006
1007function resgrep()
1008{
Joe Onoratof50e84b2011-03-15 14:15:46 -07001009 for dir in `find . -name .repo -prune -o -name .git -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 -07001010}
1011
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001012function mangrep()
1013{
1014 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1015}
1016
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001017function sepgrep()
1018{
1019 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 "$@"
1020}
1021
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001022case `uname -s` in
1023 Darwin)
1024 function mgrep()
1025 {
Ying Wang324c2b22012-08-17 15:03:20 -07001026 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 -07001027 }
1028
1029 function treegrep()
1030 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001031 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 -07001032 }
1033
1034 ;;
1035 *)
1036 function mgrep()
1037 {
Ying Wang324c2b22012-08-17 15:03:20 -07001038 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 -07001039 }
1040
1041 function treegrep()
1042 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001043 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 -07001044 }
1045
1046 ;;
1047esac
1048
1049function getprebuilt
1050{
1051 get_abs_build_var ANDROID_PREBUILTS
1052}
1053
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001054function tracedmdump()
1055{
1056 T=$(gettop)
1057 if [ ! "$T" ]; then
1058 echo "Couldn't locate the top of the tree. Try setting TOP."
1059 return
1060 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001061 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001062 local arch=$(gettargetarch)
1063 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001064
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001065 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001066 if [ ! "$TRACE" ] ; then
1067 echo "usage: tracedmdump tracename"
1068 return
1069 fi
1070
Jack Veenstra60116fc2009-04-09 18:12:34 -07001071 if [ ! -r "$KERNEL" ] ; then
1072 echo "Error: cannot find kernel: '$KERNEL'"
1073 return
1074 fi
1075
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001076 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001077 if [ "$BASETRACE" = "$TRACE" ] ; then
1078 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1079 fi
1080
1081 echo "post-processing traces..."
1082 rm -f $TRACE/qtrace.dexlist
1083 post_trace $TRACE
1084 if [ $? -ne 0 ]; then
1085 echo "***"
1086 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1087 echo "***"
1088 return
1089 fi
1090 echo "generating dexlist output..."
1091 /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
1092 echo "generating dmtrace data..."
1093 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1094 echo "generating html file..."
1095 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1096 echo "done, see $TRACE/dmtrace.html for details"
1097 echo "or run:"
1098 echo " traceview $TRACE/dmtrace"
1099}
1100
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001101# communicate with a running device or emulator, set up necessary state,
1102# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001103function runhat()
1104{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001105 # process standard adb options
1106 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001107 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001108 adbTarget=$1
1109 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001110 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001111 adbTarget="$1 $2"
1112 shift 2
1113 fi
1114 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001115 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001116
1117 # runhat options
1118 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001119
1120 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001121 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001122 return
1123 fi
1124
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001125 # confirm hat is available
1126 if [ -z $(which hat) ]; then
1127 echo "hat is not available in this configuration."
1128 return
1129 fi
1130
Andy McFaddenb6289852010-07-12 08:00:19 -07001131 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001132 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001133 local devFile=$sdcard/hprof-$targetPid
1134 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001135 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001136 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001137 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001138 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001139 echo -n "> "
1140 read
1141
The Android Open Source Project88b60792009-03-03 19:28:42 -08001142 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001143
The Android Open Source Project88b60792009-03-03 19:28:42 -08001144 echo "Retrieving file $devFile..."
1145 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001146
The Android Open Source Project88b60792009-03-03 19:28:42 -08001147 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001148
The Android Open Source Project88b60792009-03-03 19:28:42 -08001149 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001150 echo "View the output by pointing your browser at http://localhost:7000/"
1151 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001152 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001153}
1154
1155function getbugreports()
1156{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001157 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001158
1159 if [ ! "$reports" ]; then
1160 echo "Could not locate any bugreports."
1161 return
1162 fi
1163
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001164 local report
1165 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001166 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001167 echo "/sdcard/bugreports/${report}"
1168 adb pull /sdcard/bugreports/${report} ${report}
1169 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001170 done
1171}
1172
Victoria Lease1b296b42012-08-21 15:44:06 -07001173function getsdcardpath()
1174{
1175 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1176}
1177
1178function getscreenshotpath()
1179{
1180 echo "$(getsdcardpath)/Pictures/Screenshots"
1181}
1182
1183function getlastscreenshot()
1184{
1185 local screenshot_path=$(getscreenshotpath)
1186 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1187 if [ "$screenshot" = "" ]; then
1188 echo "No screenshots found."
1189 return
1190 fi
1191 echo "${screenshot}"
1192 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1193}
1194
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001195function startviewserver()
1196{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001197 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001198 if [ $# -gt 0 ]; then
1199 port=$1
1200 fi
1201 adb shell service call window 1 i32 $port
1202}
1203
1204function stopviewserver()
1205{
1206 adb shell service call window 2
1207}
1208
1209function isviewserverstarted()
1210{
1211 adb shell service call window 3
1212}
1213
Romain Guyb84049a2010-10-04 16:56:11 -07001214function key_home()
1215{
1216 adb shell input keyevent 3
1217}
1218
1219function key_back()
1220{
1221 adb shell input keyevent 4
1222}
1223
1224function key_menu()
1225{
1226 adb shell input keyevent 82
1227}
1228
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001229function smoketest()
1230{
1231 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1232 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1233 return
1234 fi
1235 T=$(gettop)
1236 if [ ! "$T" ]; then
1237 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1238 return
1239 fi
1240
Ying Wang9cd17642012-12-13 10:52:07 -08001241 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001242 adb uninstall com.android.smoketest > /dev/null &&
1243 adb uninstall com.android.smoketest.tests > /dev/null &&
1244 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1245 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1246 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1247}
1248
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001249# simple shortcut to the runtest command
1250function runtest()
1251{
1252 T=$(gettop)
1253 if [ ! "$T" ]; then
1254 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1255 return
1256 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001257 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001258}
1259
The Android Open Source Project88b60792009-03-03 19:28:42 -08001260function godir () {
1261 if [[ -z "$1" ]]; then
1262 echo "Usage: godir <regex>"
1263 return
1264 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001265 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001266 if [[ ! -f $T/filelist ]]; then
1267 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001268 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001269 echo " Done"
1270 echo ""
1271 fi
1272 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001273 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001274 if [[ ${#lines[@]} = 0 ]]; then
1275 echo "Not found"
1276 return
1277 fi
1278 local pathname
1279 local choice
1280 if [[ ${#lines[@]} > 1 ]]; then
1281 while [[ -z "$pathname" ]]; do
1282 local index=1
1283 local line
1284 for line in ${lines[@]}; do
1285 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001286 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001287 done
1288 echo
1289 echo -n "Select one: "
1290 unset choice
1291 read choice
1292 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1293 echo "Invalid choice"
1294 continue
1295 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001296 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001297 done
1298 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001299 pathname=${lines[0]}
1300 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001301 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001302}
1303
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001304# Force JAVA_HOME to point to java 1.6 if it isn't already set
1305function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001306 if [ ! "$JAVA_HOME" ]; then
1307 case `uname -s` in
1308 Darwin)
1309 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1310 ;;
1311 *)
1312 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1313 ;;
1314 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001315 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001316}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001317
Alex Rayf0d08eb2013-03-08 15:15:06 -08001318# Print colored exit condition
1319function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001320 "$@"
1321 local retval=$?
1322 if [ $retval -ne 0 ]
1323 then
1324 echo -e "\e[0;31mFAILURE\e[00m"
1325 else
1326 echo -e "\e[0;32mSUCCESS\e[00m"
1327 fi
1328 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001329}
1330
Raphael Moll70a86b02011-06-20 16:03:14 -07001331if [ "x$SHELL" != "x/bin/bash" ]; then
1332 case `ps -o command -p $$` in
1333 *bash*)
1334 ;;
1335 *)
1336 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1337 ;;
1338 esac
1339fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001340
1341# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001342for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1343 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001344do
1345 echo "including $f"
1346 . $f
1347done
1348unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001349
1350addcompletions