blob: f86081d0533b96f44898398c8afc62632077f1ac [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 \
Brian Carlstrom177285a2010-04-06 13:22:02 -070037 make --no-print-directory -C "$T" -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
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080048 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
49 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1
50}
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.
Raphael732936d2011-06-22 14:35:32 -0700126 export ANDROID_EABI_TOOLCHAIN=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200127 local ARCH=$(get_build_var TARGET_ARCH)
128 case $ARCH in
Ben Cheng054ffd22012-12-11 14:01:10 -0800129 x86) toolchaindir=x86/i686-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700130 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800131 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200132 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800133 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700134 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200135 *)
136 echo "Can't find toolchain for unknown architecture: $ARCH"
137 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700138 ;;
139 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700140 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
141 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700142 fi
Raphael732936d2011-06-22 14:35:32 -0700143
Bruce Beare42ced6d2012-07-17 21:40:01 -0700144 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700145 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700146 arm)
Ben Cheng8bc4c432012-11-16 13:29:13 -0800147 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700148 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
149 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
150 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
151 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700152 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700153 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
154 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700155 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700156 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700157 ;;
158 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700159
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700160 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
161 export ANDROID_QTOOLS=$T/development/emulator/qtools
Ying Wang564f9122013-03-29 17:40:14 -0700162 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wangaa1c9b52012-11-26 20:51:59 -0800163 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
164 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800165
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500166 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900167 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500168 if [ -n "$JAVA_HOME" ]; then
169 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900170 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
171 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500172 fi
173
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800174 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700175 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
176 export OUT=$ANDROID_PRODUCT_OUT
177
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700178 unset ANDROID_HOST_OUT
179 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
180
Ben Cheng057fde12011-11-28 13:55:14 -0800181 # needed for processing samples collected by perf counters
182 unset OPROFILE_EVENTS_DIR
183 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
184
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800185 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700186 # TODO: fix the path
187 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
188}
189
190function printconfig()
191{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800192 T=$(gettop)
193 if [ ! "$T" ]; then
194 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
195 return
196 fi
197 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700198}
199
200function set_stuff_for_environment()
201{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800202 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500203 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800204 setpaths
205 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700206
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800207 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700208}
209
210function set_sequence_number()
211{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700212 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700213}
214
215function settitle()
216{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800217 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700218 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700219 local product=$TARGET_PRODUCT
220 local variant=$TARGET_BUILD_VARIANT
221 local apps=$TARGET_BUILD_APPS
222 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700223 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700224 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700225 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700226 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800227 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700228}
229
Kenny Root52aa81c2011-07-15 11:07:06 -0700230function addcompletions()
231{
232 local T dir f
233
234 # Keep us from trying to run in something that isn't bash.
235 if [ -z "${BASH_VERSION}" ]; then
236 return
237 fi
238
239 # Keep us from trying to run in bash that's too old.
240 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
241 return
242 fi
243
244 dir="sdk/bash_completion"
245 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700246 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700247 echo "including $f"
248 . $f
249 done
250 fi
251}
252
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700253function choosetype()
254{
255 echo "Build type choices are:"
256 echo " 1. release"
257 echo " 2. debug"
258 echo
259
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800260 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700261 DEFAULT_NUM=1
262 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800264 export TARGET_BUILD_TYPE=
265 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700266 while [ -z $TARGET_BUILD_TYPE ]
267 do
268 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800269 if [ -z "$1" ] ; then
270 read ANSWER
271 else
272 echo $1
273 ANSWER=$1
274 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700275 case $ANSWER in
276 "")
277 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
278 ;;
279 1)
280 export TARGET_BUILD_TYPE=release
281 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800282 release)
283 export TARGET_BUILD_TYPE=release
284 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700285 2)
286 export TARGET_BUILD_TYPE=debug
287 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800288 debug)
289 export TARGET_BUILD_TYPE=debug
290 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700291 *)
292 echo
293 echo "I didn't understand your response. Please try again."
294 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700295 ;;
296 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800297 if [ -n "$1" ] ; then
298 break
299 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300 done
301
302 set_stuff_for_environment
303}
304
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800305#
306# This function isn't really right: It chooses a TARGET_PRODUCT
307# based on the list of boards. Usually, that gets you something
308# that kinda works with a generic product, but really, you should
309# pick a product by name.
310#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700311function chooseproduct()
312{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700313 if [ "x$TARGET_PRODUCT" != x ] ; then
314 default_value=$TARGET_PRODUCT
315 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700316 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317 fi
318
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800319 export TARGET_PRODUCT=
320 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321 while [ -z "$TARGET_PRODUCT" ]
322 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700323 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800324 if [ -z "$1" ] ; then
325 read ANSWER
326 else
327 echo $1
328 ANSWER=$1
329 fi
330
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700331 if [ -z "$ANSWER" ] ; then
332 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800333 else
334 if check_product $ANSWER
335 then
336 export TARGET_PRODUCT=$ANSWER
337 else
338 echo "** Not a valid product: $ANSWER"
339 fi
340 fi
341 if [ -n "$1" ] ; then
342 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700343 fi
344 done
345
346 set_stuff_for_environment
347}
348
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800349function choosevariant()
350{
351 echo "Variant choices are:"
352 local index=1
353 local v
354 for v in ${VARIANT_CHOICES[@]}
355 do
356 # The product name is the name of the directory containing
357 # the makefile we found, above.
358 echo " $index. $v"
359 index=$(($index+1))
360 done
361
362 local default_value=eng
363 local ANSWER
364
365 export TARGET_BUILD_VARIANT=
366 while [ -z "$TARGET_BUILD_VARIANT" ]
367 do
368 echo -n "Which would you like? [$default_value] "
369 if [ -z "$1" ] ; then
370 read ANSWER
371 else
372 echo $1
373 ANSWER=$1
374 fi
375
376 if [ -z "$ANSWER" ] ; then
377 export TARGET_BUILD_VARIANT=$default_value
378 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
379 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800380 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800381 fi
382 else
383 if check_variant $ANSWER
384 then
385 export TARGET_BUILD_VARIANT=$ANSWER
386 else
387 echo "** Not a valid variant: $ANSWER"
388 fi
389 fi
390 if [ -n "$1" ] ; then
391 break
392 fi
393 done
394}
395
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700396function choosecombo()
397{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700398 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700399
400 echo
401 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700402 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700403
404 echo
405 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700406 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800407
408 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700409 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800410 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700411}
412
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800413# Clear this variable. It will be built up again when the vendorsetup.sh
414# files are included at the end of this file.
415unset LUNCH_MENU_CHOICES
416function add_lunch_combo()
417{
418 local new_combo=$1
419 local c
420 for c in ${LUNCH_MENU_CHOICES[@]} ; do
421 if [ "$new_combo" = "$c" ] ; then
422 return
423 fi
424 done
425 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
426}
427
428# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700429add_lunch_combo aosp_arm-eng
430add_lunch_combo aosp_x86-eng
431add_lunch_combo aosp_mips-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800432add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800433
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700434function print_lunch_menu()
435{
436 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700437 echo
438 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700439 echo
440 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800441
442 local i=1
443 local choice
444 for choice in ${LUNCH_MENU_CHOICES[@]}
445 do
446 echo " $i. $choice"
447 i=$(($i+1))
448 done
449
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700450 echo
451}
452
453function lunch()
454{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800455 local answer
456
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700457 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800458 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700459 else
460 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700461 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800462 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700463 fi
464
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800465 local selection=
466
467 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700469 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800470 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
471 then
472 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
473 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800474 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800475 fi
476 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
477 then
478 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700479 fi
480
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800481 if [ -z "$selection" ]
482 then
483 echo
484 echo "Invalid lunch combo: $answer"
485 return 1
486 fi
487
Joe Onoratoda12daf2010-06-09 18:18:31 -0700488 export TARGET_BUILD_APPS=
489
Jeff Browne33ba4c2011-07-11 22:11:46 -0700490 local product=$(echo -n $selection | sed -e "s/-.*$//")
491 check_product $product
492 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800493 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700494 echo
495 echo "** Don't have a product spec for: '$product'"
496 echo "** Do you have the right repo manifest?"
497 product=
498 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499
Jeff Browne33ba4c2011-07-11 22:11:46 -0700500 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
501 check_variant $variant
502 if [ $? -ne 0 ]
503 then
504 echo
505 echo "** Invalid variant: '$variant'"
506 echo "** Must be one of ${VARIANT_CHOICES[@]}"
507 variant=
508 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800509
Jeff Browne33ba4c2011-07-11 22:11:46 -0700510 if [ -z "$product" -o -z "$variant" ]
511 then
512 echo
513 return 1
514 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800515
Jeff Browne33ba4c2011-07-11 22:11:46 -0700516 export TARGET_PRODUCT=$product
517 export TARGET_BUILD_VARIANT=$variant
518 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700519
520 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700522 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800523 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700524}
525
Jeff Davidson513d7a42010-08-02 10:00:44 -0700526# Tab completion for lunch.
527function _lunch()
528{
529 local cur prev opts
530 COMPREPLY=()
531 cur="${COMP_WORDS[COMP_CWORD]}"
532 prev="${COMP_WORDS[COMP_CWORD-1]}"
533
534 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
535 return 0
536}
537complete -F _lunch lunch
538
Joe Onoratoda12daf2010-06-09 18:18:31 -0700539# Configures the build to build unbundled apps.
540# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
541function tapas()
542{
Ying Wangf05c4f72013-01-31 11:16:57 -0800543 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600544 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800545 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 -0700546
Ying Wang67f02922012-08-22 10:25:20 -0700547 if [ $(echo $arch | wc -w) -gt 1 ]; then
548 echo "tapas: Error: Multiple build archs supplied: $arch"
549 return
550 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700551 if [ $(echo $variant | wc -w) -gt 1 ]; then
552 echo "tapas: Error: Multiple build variants supplied: $variant"
553 return
554 fi
Ying Wang67f02922012-08-22 10:25:20 -0700555
556 local product=full
557 case $arch in
558 x86) product=full_x86;;
559 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800560 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700561 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700562 if [ -z "$variant" ]; then
563 variant=eng
564 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700565 if [ -z "$apps" ]; then
566 apps=all
567 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700568
Ying Wang67f02922012-08-22 10:25:20 -0700569 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700570 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700571 export TARGET_BUILD_TYPE=release
572 export TARGET_BUILD_APPS=$apps
573
574 set_stuff_for_environment
575 printconfig
576}
577
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700578function gettop
579{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800580 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
582 echo $TOP
583 else
584 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800585 # The following circumlocution (repeated below as well) ensures
586 # that we record the true directory name and not one that is
587 # faked up with symlink names.
588 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700589 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591 T=
592 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800593 \cd ..
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800594 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700595 done
Ying Wang9cd17642012-12-13 10:52:07 -0800596 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700597 if [ -f "$T/$TOPFILE" ]; then
598 echo $T
599 fi
600 fi
601 fi
602}
603
604function m()
605{
606 T=$(gettop)
607 if [ "$T" ]; then
Joe Onoratofa72a602013-01-11 12:49:04 -0800608 make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700609 else
610 echo "Couldn't locate the top of the tree. Try setting TOP."
611 fi
612}
613
614function findmakefile()
615{
616 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800617 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700618 T=
619 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700620 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700621 if [ -f "$T/Android.mk" ]; then
622 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800623 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700624 return
625 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800626 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700627 done
Ying Wang9cd17642012-12-13 10:52:07 -0800628 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700629}
630
631function mm()
632{
633 # If we're sitting in the root of the build tree, just do a
634 # normal make.
635 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
636 make $@
637 else
638 # Find the closest Android.mk file.
639 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800640 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700641 local MODULES=
642 local GET_INSTALL_PATH=
643 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700644 # Remove the path to top as the makefilepath needs to be relative
645 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700646 if [ ! "$T" ]; then
647 echo "Couldn't locate the top of the tree. Try setting TOP."
648 elif [ ! "$M" ]; then
649 echo "Couldn't locate a makefile from the current directory."
650 else
Ying Wanga7deb082013-08-16 13:24:47 -0700651 for ARG in $@; do
652 case $ARG in
653 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
654 esac
655 done
656 if [ -n "$GET_INSTALL_PATH" ]; then
657 MODULES=
658 ARGS=GET-INSTALL-PATH
659 else
660 MODULES=all_modules
661 ARGS=$@
662 fi
663 ONE_SHOT_MAKEFILE=$M make -C $T -f build/core/main.mk $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700664 fi
665 fi
666}
667
668function mmm()
669{
670 T=$(gettop)
671 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800672 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800673 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800674 local ARGS=
675 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700676 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800677 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
678 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
679 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800680 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
681 if [ "$MODULES" = "" ]; then
682 MODULES=all_modules
683 fi
684 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700685 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700686 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
687 local TO_CHOP=`expr $TO_CHOP + 1`
688 local START=`PWD= /bin/pwd`
689 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700690 if [ "$MFILE" = "" ] ; then
691 MFILE=$DIR/Android.mk
692 else
693 MFILE=$MFILE/$DIR/Android.mk
694 fi
695 MAKEFILE="$MAKEFILE $MFILE"
696 else
Ying Wanga7deb082013-08-16 13:24:47 -0700697 case $DIR in
698 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
699 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
700 *) echo "No Android.mk in $DIR."; return 1;;
701 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700702 fi
703 done
Ying Wanga7deb082013-08-16 13:24:47 -0700704 if [ -n "$GET_INSTALL_PATH" ]; then
705 ARGS=$GET_INSTALL_PATH
706 MODULES=
707 fi
Joe Onoratofa72a602013-01-11 12:49:04 -0800708 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 -0700709 else
710 echo "Couldn't locate the top of the tree. Try setting TOP."
711 fi
712}
713
Ying Wangb607f7b2013-02-08 18:01:04 -0800714function mma()
715{
716 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
717 make $@
718 else
719 T=$(gettop)
720 if [ ! "$T" ]; then
721 echo "Couldn't locate the top of the tree. Try setting TOP."
722 fi
723 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
724 make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
725 fi
726}
727
728function mmma()
729{
730 T=$(gettop)
731 if [ "$T" ]; then
732 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
733 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
734 local MY_PWD=`PWD= /bin/pwd`
735 if [ "$MY_PWD" = "$T" ]; then
736 MY_PWD=
737 else
738 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
739 fi
740 local DIR=
741 local MODULE_PATHS=
742 local ARGS=
743 for DIR in $DIRS ; do
744 if [ -d $DIR ]; then
745 if [ "$MY_PWD" = "" ]; then
746 MODULE_PATHS="$MODULE_PATHS $DIR"
747 else
748 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
749 fi
750 else
751 case $DIR in
752 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
753 *) echo "Couldn't find directory $DIR"; return 1;;
754 esac
755 fi
756 done
757 make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
758 else
759 echo "Couldn't locate the top of the tree. Try setting TOP."
760 fi
761}
762
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700763function croot()
764{
765 T=$(gettop)
766 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800767 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700768 else
769 echo "Couldn't locate the top of the tree. Try setting TOP."
770 fi
771}
772
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700773function cproj()
774{
775 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700776 local HERE=$PWD
777 T=
778 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
779 T=$PWD
780 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800781 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700782 return
783 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800784 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700785 done
Ying Wang9cd17642012-12-13 10:52:07 -0800786 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700787 echo "can't find Android.mk"
788}
789
Daniel Sandler47e0a882013-07-30 13:23:52 -0400790# simplified version of ps; output in the form
791# <pid> <procname>
792function qpid() {
793 local prepend=''
794 local append=''
795 if [ "$1" = "--exact" ]; then
796 prepend=' '
797 append='$'
798 shift
799 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
800 echo "usage: qpid [[--exact] <process name|pid>"
801 return 255
802 fi
803
804 local EXE="$1"
805 if [ "$EXE" ] ; then
806 qpid | grep "$prepend$EXE$append"
807 else
808 adb shell ps \
809 | tr -d '\r' \
810 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
811 fi
812}
813
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700814function pid()
815{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400816 local prepend=''
817 local append=''
818 if [ "$1" = "--exact" ]; then
819 prepend=' '
820 append='$'
821 shift
822 fi
823 local EXE="$1"
824 if [ "$EXE" ] ; then
825 local PID=`adb shell ps \
826 | tr -d '\r' \
827 | grep "$prepend$EXE$append" \
828 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
829 echo "$PID"
830 else
831 echo "usage: pid [--exact] <process name>"
832 return 255
833 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700834}
835
Christopher Tate744ee802009-11-12 15:33:08 -0800836# systemstack - dump the current stack trace of all threads in the system process
837# to the usual ANR traces file
838function systemstack()
839{
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800840 stacks system_server
841}
842
843function stacks()
844{
845 if [[ $1 =~ ^[0-9]+$ ]] ; then
846 local PID="$1"
847 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700848 local PIDLIST="$(pid $1)"
849 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
850 local PID="$PIDLIST"
851 elif [ "$PIDLIST" ] ; then
852 echo "more than one process: $1"
853 else
854 echo "no such process: $1"
855 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800856 else
857 echo "usage: stacks [pid|process name]"
858 fi
859
860 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -0700861 # Determine whether the process is native
862 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
863 # Dump stacks of Dalvik process
864 local TRACES=/data/anr/traces.txt
865 local ORIG=/data/anr/traces.orig
866 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800867
Jeff Brownb12c2e52013-08-19 15:14:16 -0700868 # Keep original traces to avoid clobbering
869 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800870
Jeff Brownb12c2e52013-08-19 15:14:16 -0700871 # Make sure we have a usable file
872 adb shell touch $TRACES
873 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800874
Jeff Brownb12c2e52013-08-19 15:14:16 -0700875 # Dump stacks and wait for dump to finish
876 adb shell kill -3 $PID
877 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800878
Jeff Brownb12c2e52013-08-19 15:14:16 -0700879 # Restore original stacks, and show current output
880 adb shell mv $TRACES $TMP
881 adb shell mv $ORIG $TRACES
882 adb shell cat $TMP
883 else
884 # Dump stacks of native process
885 adb shell debuggerd -b $PID
886 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -0800887 fi
Christopher Tate744ee802009-11-12 15:33:08 -0800888}
889
John Michelau50200252012-11-09 11:48:04 -0600890function gdbwrapper()
891{
892 $ANDROID_TOOLCHAIN/$GDB -x "$@"
893}
894
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700895function gdbclient()
896{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800897 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
898 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
899 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
900 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
901 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800902 local ARCH=$(get_build_var TARGET_ARCH)
903 local GDB
904 case "$ARCH" in
Jean-Baptiste Querufeec98b2012-05-16 13:18:39 -0700905 x86) GDB=i686-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800906 arm) GDB=arm-linux-androideabi-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700907 mips) GDB=mipsel-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800908 *) echo "Unknown arch $ARCH"; return 1;;
909 esac
910
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700911 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
912 local EXE="$1"
913 if [ "$EXE" ] ; then
914 EXE=$1
915 else
916 EXE="app_process"
917 fi
918
919 local PORT="$2"
920 if [ "$PORT" ] ; then
921 PORT=$2
922 else
923 PORT=":5039"
924 fi
925
Chris Craik20c136a2012-11-09 18:02:19 -0800926 local PID="$3"
927 if [ "$PID" ] ; then
928 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700929 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800930 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
931 # that likely didn't work because of returning multiple processes
932 # try again, filtering by root processes (don't contain colon)
933 PID=`adb shell ps | grep $3 | grep -v ":" | awk '{print $2}'`
934 if [[ ! "$PID" =~ ^[0-9]+$ ]]
935 then
936 echo "Couldn't resolve '$3' to single PID"
937 return 1
938 else
939 echo ""
940 echo "WARNING: multiple processes matching '$3' observed, using root process"
941 echo ""
942 fi
943 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -0700944 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700945 adb forward "tcp$PORT" "tcp$PORT"
946 adb shell gdbserver $PORT --attach $PID &
947 sleep 2
948 else
949 echo ""
950 echo "If you haven't done so already, do this first on the device:"
951 echo " gdbserver $PORT /system/bin/$EXE"
952 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -0800953 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700954 echo ""
955 fi
956
957 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Chris Dearman6858d512012-02-02 14:16:52 -0800958 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 -0700959 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700960 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
961 echo >>"$OUT_ROOT/gdbclient.cmds" ""
962
John Michelau50200252012-11-09 11:48:04 -0600963 gdbwrapper "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700964 else
965 echo "Unable to determine build system output dir."
966 fi
967
968}
969
970case `uname -s` in
971 Darwin)
972 function sgrep()
973 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700974 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 -0700975 }
976
977 ;;
978 *)
979 function sgrep()
980 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700981 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 -0700982 }
983 ;;
984esac
985
Raghu Gandham8da43102012-07-25 19:57:22 -0700986function gettargetarch
987{
988 get_build_var TARGET_ARCH
989}
990
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700991function jgrep()
992{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700993 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 -0700994}
995
996function cgrep()
997{
Mike Dodd0c26d342011-04-07 13:29:06 -0700998 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 -0700999}
1000
1001function resgrep()
1002{
Joe Onoratof50e84b2011-03-15 14:15:46 -07001003 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 -07001004}
1005
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001006function mangrep()
1007{
1008 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1009}
1010
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001011function sepgrep()
1012{
1013 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 "$@"
1014}
1015
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001016case `uname -s` in
1017 Darwin)
1018 function mgrep()
1019 {
Ying Wang324c2b22012-08-17 15:03:20 -07001020 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 -07001021 }
1022
1023 function treegrep()
1024 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001025 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 -07001026 }
1027
1028 ;;
1029 *)
1030 function mgrep()
1031 {
Ying Wang324c2b22012-08-17 15:03:20 -07001032 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 -07001033 }
1034
1035 function treegrep()
1036 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001037 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 -07001038 }
1039
1040 ;;
1041esac
1042
1043function getprebuilt
1044{
1045 get_abs_build_var ANDROID_PREBUILTS
1046}
1047
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001048function tracedmdump()
1049{
1050 T=$(gettop)
1051 if [ ! "$T" ]; then
1052 echo "Couldn't locate the top of the tree. Try setting TOP."
1053 return
1054 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001055 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001056 local arch=$(gettargetarch)
1057 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001058
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001059 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001060 if [ ! "$TRACE" ] ; then
1061 echo "usage: tracedmdump tracename"
1062 return
1063 fi
1064
Jack Veenstra60116fc2009-04-09 18:12:34 -07001065 if [ ! -r "$KERNEL" ] ; then
1066 echo "Error: cannot find kernel: '$KERNEL'"
1067 return
1068 fi
1069
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001070 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001071 if [ "$BASETRACE" = "$TRACE" ] ; then
1072 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1073 fi
1074
1075 echo "post-processing traces..."
1076 rm -f $TRACE/qtrace.dexlist
1077 post_trace $TRACE
1078 if [ $? -ne 0 ]; then
1079 echo "***"
1080 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1081 echo "***"
1082 return
1083 fi
1084 echo "generating dexlist output..."
1085 /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
1086 echo "generating dmtrace data..."
1087 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1088 echo "generating html file..."
1089 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1090 echo "done, see $TRACE/dmtrace.html for details"
1091 echo "or run:"
1092 echo " traceview $TRACE/dmtrace"
1093}
1094
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001095# communicate with a running device or emulator, set up necessary state,
1096# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001097function runhat()
1098{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001099 # process standard adb options
1100 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001101 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001102 adbTarget=$1
1103 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001104 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001105 adbTarget="$1 $2"
1106 shift 2
1107 fi
1108 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001109 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001110
1111 # runhat options
1112 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001113
1114 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001115 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001116 return
1117 fi
1118
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001119 # confirm hat is available
1120 if [ -z $(which hat) ]; then
1121 echo "hat is not available in this configuration."
1122 return
1123 fi
1124
Andy McFaddenb6289852010-07-12 08:00:19 -07001125 # issue "am" command to cause the hprof dump
Christopher Ferris764b4f82013-05-20 16:30:10 -07001126 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001127 local devFile=$sdcard/hprof-$targetPid
1128 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001129 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001130 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001131 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001132 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001133 echo -n "> "
1134 read
1135
The Android Open Source Project88b60792009-03-03 19:28:42 -08001136 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001137
The Android Open Source Project88b60792009-03-03 19:28:42 -08001138 echo "Retrieving file $devFile..."
1139 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001140
The Android Open Source Project88b60792009-03-03 19:28:42 -08001141 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001142
The Android Open Source Project88b60792009-03-03 19:28:42 -08001143 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001144 echo "View the output by pointing your browser at http://localhost:7000/"
1145 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001146 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001147}
1148
1149function getbugreports()
1150{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001151 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001152
1153 if [ ! "$reports" ]; then
1154 echo "Could not locate any bugreports."
1155 return
1156 fi
1157
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001158 local report
1159 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001160 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001161 echo "/sdcard/bugreports/${report}"
1162 adb pull /sdcard/bugreports/${report} ${report}
1163 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001164 done
1165}
1166
Victoria Lease1b296b42012-08-21 15:44:06 -07001167function getsdcardpath()
1168{
1169 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1170}
1171
1172function getscreenshotpath()
1173{
1174 echo "$(getsdcardpath)/Pictures/Screenshots"
1175}
1176
1177function getlastscreenshot()
1178{
1179 local screenshot_path=$(getscreenshotpath)
1180 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1181 if [ "$screenshot" = "" ]; then
1182 echo "No screenshots found."
1183 return
1184 fi
1185 echo "${screenshot}"
1186 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1187}
1188
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001189function startviewserver()
1190{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001191 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001192 if [ $# -gt 0 ]; then
1193 port=$1
1194 fi
1195 adb shell service call window 1 i32 $port
1196}
1197
1198function stopviewserver()
1199{
1200 adb shell service call window 2
1201}
1202
1203function isviewserverstarted()
1204{
1205 adb shell service call window 3
1206}
1207
Romain Guyb84049a2010-10-04 16:56:11 -07001208function key_home()
1209{
1210 adb shell input keyevent 3
1211}
1212
1213function key_back()
1214{
1215 adb shell input keyevent 4
1216}
1217
1218function key_menu()
1219{
1220 adb shell input keyevent 82
1221}
1222
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001223function smoketest()
1224{
1225 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1226 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1227 return
1228 fi
1229 T=$(gettop)
1230 if [ ! "$T" ]; then
1231 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1232 return
1233 fi
1234
Ying Wang9cd17642012-12-13 10:52:07 -08001235 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001236 adb uninstall com.android.smoketest > /dev/null &&
1237 adb uninstall com.android.smoketest.tests > /dev/null &&
1238 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1239 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1240 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1241}
1242
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001243# simple shortcut to the runtest command
1244function runtest()
1245{
1246 T=$(gettop)
1247 if [ ! "$T" ]; then
1248 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1249 return
1250 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001251 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001252}
1253
The Android Open Source Project88b60792009-03-03 19:28:42 -08001254function godir () {
1255 if [[ -z "$1" ]]; then
1256 echo "Usage: godir <regex>"
1257 return
1258 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001259 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001260 if [[ ! -f $T/filelist ]]; then
1261 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001262 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001263 echo " Done"
1264 echo ""
1265 fi
1266 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001267 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001268 if [[ ${#lines[@]} = 0 ]]; then
1269 echo "Not found"
1270 return
1271 fi
1272 local pathname
1273 local choice
1274 if [[ ${#lines[@]} > 1 ]]; then
1275 while [[ -z "$pathname" ]]; do
1276 local index=1
1277 local line
1278 for line in ${lines[@]}; do
1279 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001280 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001281 done
1282 echo
1283 echo -n "Select one: "
1284 unset choice
1285 read choice
1286 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1287 echo "Invalid choice"
1288 continue
1289 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001290 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001291 done
1292 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001293 pathname=${lines[0]}
1294 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001295 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001296}
1297
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001298# Force JAVA_HOME to point to java 1.6 if it isn't already set
1299function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001300 if [ ! "$JAVA_HOME" ]; then
1301 case `uname -s` in
1302 Darwin)
1303 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1304 ;;
1305 *)
1306 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1307 ;;
1308 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001309 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001310}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001311
Alex Rayf0d08eb2013-03-08 15:15:06 -08001312# Print colored exit condition
1313function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001314 "$@"
1315 local retval=$?
1316 if [ $retval -ne 0 ]
1317 then
1318 echo -e "\e[0;31mFAILURE\e[00m"
1319 else
1320 echo -e "\e[0;32mSUCCESS\e[00m"
1321 fi
1322 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001323}
1324
Raphael Moll70a86b02011-06-20 16:03:14 -07001325if [ "x$SHELL" != "x/bin/bash" ]; then
1326 case `ps -o command -p $$` in
1327 *bash*)
1328 ;;
1329 *)
1330 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1331 ;;
1332 esac
1333fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001334
1335# Execute the contents of any vendorsetup.sh files we can find.
Guilhem IMBERTON58570e72012-10-04 14:26:57 +02001336for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1337 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001338do
1339 echo "including $f"
1340 . $f
1341done
1342unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001343
1344addcompletions