blob: 2da629d48b7d55f62ede16077fbd52635a65330c [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:
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07004- croot: Changes directory to the top of the tree.
5- m: Makes from the top of the tree.
6- mm: Builds all of the modules in the current directory.
7- mmm: Builds all of the modules in the supplied directories.
8- cgrep: Greps on all local C/C++ files.
9- jgrep: Greps on all local Java files.
10- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080011- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070012
13Look at the source to view more functions. The complete list is:
14EOF
15 T=$(gettop)
16 local A
17 A=""
18 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
19 A="$A $i"
20 done
21 echo $A
22}
23
24# Get the value of a build variable as an absolute path.
25function get_abs_build_var()
26{
27 T=$(gettop)
28 if [ ! "$T" ]; then
29 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
30 return
31 fi
Brian Carlstrom177285a2010-04-06 13:22:02 -070032 (cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
33 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070034}
35
36# Get the exact value of a build variable.
37function get_build_var()
38{
39 T=$(gettop)
40 if [ ! "$T" ]; then
41 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
42 return
43 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080044 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
45 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1
46}
47
48# check to see if the supplied product is one we can build
49function check_product()
50{
51 T=$(gettop)
52 if [ ! "$T" ]; then
53 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
54 return
55 fi
56 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Jeff Browne33ba4c2011-07-11 22:11:46 -070057 TARGET_PRODUCT=$1 \
58 TARGET_BUILD_VARIANT= \
59 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070060 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080061 get_build_var TARGET_DEVICE > /dev/null
62 # hide successful answers, but allow the errors to show
63}
64
65VARIANT_CHOICES=(user userdebug eng)
66
67# check to see if the supplied variant is valid
68function check_variant()
69{
70 for v in ${VARIANT_CHOICES[@]}
71 do
72 if [ "$v" = "$1" ]
73 then
74 return 0
75 fi
76 done
77 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070078}
79
80function setpaths()
81{
82 T=$(gettop)
83 if [ ! "$T" ]; then
84 echo "Couldn't locate the top of the tree. Try setting TOP."
85 return
86 fi
87
88 ##################################################################
89 # #
90 # Read me before you modify this code #
91 # #
92 # This function sets ANDROID_BUILD_PATHS to what it is adding #
93 # to PATH, and the next time it is run, it removes that from #
94 # PATH. This is required so lunch can be run more than once #
95 # and still have working paths. #
96 # #
97 ##################################################################
98
Raphael Mollc639c782011-06-20 17:25:01 -070099 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
100 # due to "C:\Program Files" being in the path.
101
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700102 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700103 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700104 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
105 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700106 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700107 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
108 # strip trailing ':', if any
109 export PATH=${PATH/%:/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500110 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700111
112 # and in with the new
113 CODE_REVIEWS=
114 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700115 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700116
Raphael Mollc639c782011-06-20 17:25:01 -0700117 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Raphael732936d2011-06-22 14:35:32 -0700118 export ANDROID_EABI_TOOLCHAIN=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200119 local ARCH=$(get_build_var TARGET_ARCH)
120 case $ARCH in
H.J. Lu402d7f32012-04-29 07:34:54 -0700121 x86) toolchaindir=x86/i686-linux-android-4.6/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700122 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200123 arm) toolchaindir=arm/arm-linux-androideabi-4.6/bin
124 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700125 mips) toolchaindir=mips/mipsel-linux-android-4.6/bin
126 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200127 *)
128 echo "Can't find toolchain for unknown architecture: $ARCH"
129 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700130 ;;
131 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700132 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
133 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700134 fi
Raphael732936d2011-06-22 14:35:32 -0700135
Bruce Beare42ced6d2012-07-17 21:40:01 -0700136 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700137 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700138 arm)
139 toolchaindir=arm/arm-eabi-4.6/bin
140 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
141 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
142 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
143 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700144 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700145 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
146 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700147 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700148 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700149 ;;
150 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700151
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700152 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
153 export ANDROID_QTOOLS=$T/development/emulator/qtools
Robert Greenwalt0987f032012-04-27 10:02:37 -0700154 export ANDROID_DEV_SCRIPTS=$T/development/scripts
Bruce Beare42ced6d2012-07-17 21:40:01 -0700155 export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700156 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800157
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500158 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900159 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500160 if [ -n "$JAVA_HOME" ]; then
161 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900162 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
163 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500164 fi
165
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800166 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700167 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
168 export OUT=$ANDROID_PRODUCT_OUT
169
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700170 unset ANDROID_HOST_OUT
171 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
172
Ben Cheng057fde12011-11-28 13:55:14 -0800173 # needed for processing samples collected by perf counters
174 unset OPROFILE_EVENTS_DIR
175 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
176
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800177 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700178 # TODO: fix the path
179 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
180}
181
182function printconfig()
183{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800184 T=$(gettop)
185 if [ ! "$T" ]; then
186 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
187 return
188 fi
189 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700190}
191
192function set_stuff_for_environment()
193{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800194 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500195 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800196 setpaths
197 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700198
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800199 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700200}
201
202function set_sequence_number()
203{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700204 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700205}
206
207function settitle()
208{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800209 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700210 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700211 local product=$TARGET_PRODUCT
212 local variant=$TARGET_BUILD_VARIANT
213 local apps=$TARGET_BUILD_APPS
214 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700215 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700216 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700217 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700218 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800219 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700220}
221
Kenny Root52aa81c2011-07-15 11:07:06 -0700222function addcompletions()
223{
224 local T dir f
225
226 # Keep us from trying to run in something that isn't bash.
227 if [ -z "${BASH_VERSION}" ]; then
228 return
229 fi
230
231 # Keep us from trying to run in bash that's too old.
232 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
233 return
234 fi
235
236 dir="sdk/bash_completion"
237 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700238 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700239 echo "including $f"
240 . $f
241 done
242 fi
243}
244
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700245function choosetype()
246{
247 echo "Build type choices are:"
248 echo " 1. release"
249 echo " 2. debug"
250 echo
251
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800252 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700253 DEFAULT_NUM=1
254 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800256 export TARGET_BUILD_TYPE=
257 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700258 while [ -z $TARGET_BUILD_TYPE ]
259 do
260 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800261 if [ -z "$1" ] ; then
262 read ANSWER
263 else
264 echo $1
265 ANSWER=$1
266 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700267 case $ANSWER in
268 "")
269 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
270 ;;
271 1)
272 export TARGET_BUILD_TYPE=release
273 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800274 release)
275 export TARGET_BUILD_TYPE=release
276 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700277 2)
278 export TARGET_BUILD_TYPE=debug
279 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800280 debug)
281 export TARGET_BUILD_TYPE=debug
282 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700283 *)
284 echo
285 echo "I didn't understand your response. Please try again."
286 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700287 ;;
288 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800289 if [ -n "$1" ] ; then
290 break
291 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700292 done
293
294 set_stuff_for_environment
295}
296
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800297#
298# This function isn't really right: It chooses a TARGET_PRODUCT
299# based on the list of boards. Usually, that gets you something
300# that kinda works with a generic product, but really, you should
301# pick a product by name.
302#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700303function chooseproduct()
304{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700305 if [ "x$TARGET_PRODUCT" != x ] ; then
306 default_value=$TARGET_PRODUCT
307 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700308 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309 fi
310
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800311 export TARGET_PRODUCT=
312 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700313 while [ -z "$TARGET_PRODUCT" ]
314 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700315 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 if [ -z "$1" ] ; then
317 read ANSWER
318 else
319 echo $1
320 ANSWER=$1
321 fi
322
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700323 if [ -z "$ANSWER" ] ; then
324 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800325 else
326 if check_product $ANSWER
327 then
328 export TARGET_PRODUCT=$ANSWER
329 else
330 echo "** Not a valid product: $ANSWER"
331 fi
332 fi
333 if [ -n "$1" ] ; then
334 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335 fi
336 done
337
338 set_stuff_for_environment
339}
340
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800341function choosevariant()
342{
343 echo "Variant choices are:"
344 local index=1
345 local v
346 for v in ${VARIANT_CHOICES[@]}
347 do
348 # The product name is the name of the directory containing
349 # the makefile we found, above.
350 echo " $index. $v"
351 index=$(($index+1))
352 done
353
354 local default_value=eng
355 local ANSWER
356
357 export TARGET_BUILD_VARIANT=
358 while [ -z "$TARGET_BUILD_VARIANT" ]
359 do
360 echo -n "Which would you like? [$default_value] "
361 if [ -z "$1" ] ; then
362 read ANSWER
363 else
364 echo $1
365 ANSWER=$1
366 fi
367
368 if [ -z "$ANSWER" ] ; then
369 export TARGET_BUILD_VARIANT=$default_value
370 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
371 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800372 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800373 fi
374 else
375 if check_variant $ANSWER
376 then
377 export TARGET_BUILD_VARIANT=$ANSWER
378 else
379 echo "** Not a valid variant: $ANSWER"
380 fi
381 fi
382 if [ -n "$1" ] ; then
383 break
384 fi
385 done
386}
387
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700388function choosecombo()
389{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700390 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700391
392 echo
393 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700394 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700395
396 echo
397 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700398 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800399
400 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700401 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800402 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700403}
404
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800405# Clear this variable. It will be built up again when the vendorsetup.sh
406# files are included at the end of this file.
407unset LUNCH_MENU_CHOICES
408function add_lunch_combo()
409{
410 local new_combo=$1
411 local c
412 for c in ${LUNCH_MENU_CHOICES[@]} ; do
413 if [ "$new_combo" = "$c" ] ; then
414 return
415 fi
416 done
417 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
418}
419
420# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700421add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700422add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800423add_lunch_combo vbox_x86-eng
Raghu Gandham8da43102012-07-25 19:57:22 -0700424add_lunch_combo full_mips-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800425
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700426function print_lunch_menu()
427{
428 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700429 echo
430 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700431 echo
432 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800433
434 local i=1
435 local choice
436 for choice in ${LUNCH_MENU_CHOICES[@]}
437 do
438 echo " $i. $choice"
439 i=$(($i+1))
440 done
441
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700442 echo
443}
444
445function lunch()
446{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800447 local answer
448
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800450 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700451 else
452 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700453 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800454 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700455 fi
456
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800457 local selection=
458
459 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700460 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700461 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800462 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
463 then
464 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
465 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800466 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800467 fi
468 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
469 then
470 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471 fi
472
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800473 if [ -z "$selection" ]
474 then
475 echo
476 echo "Invalid lunch combo: $answer"
477 return 1
478 fi
479
Joe Onoratoda12daf2010-06-09 18:18:31 -0700480 export TARGET_BUILD_APPS=
481
Jeff Browne33ba4c2011-07-11 22:11:46 -0700482 local product=$(echo -n $selection | sed -e "s/-.*$//")
483 check_product $product
484 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800485 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700486 echo
487 echo "** Don't have a product spec for: '$product'"
488 echo "** Do you have the right repo manifest?"
489 product=
490 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800491
Jeff Browne33ba4c2011-07-11 22:11:46 -0700492 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
493 check_variant $variant
494 if [ $? -ne 0 ]
495 then
496 echo
497 echo "** Invalid variant: '$variant'"
498 echo "** Must be one of ${VARIANT_CHOICES[@]}"
499 variant=
500 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800501
Jeff Browne33ba4c2011-07-11 22:11:46 -0700502 if [ -z "$product" -o -z "$variant" ]
503 then
504 echo
505 return 1
506 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507
Jeff Browne33ba4c2011-07-11 22:11:46 -0700508 export TARGET_PRODUCT=$product
509 export TARGET_BUILD_VARIANT=$variant
510 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700511
512 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800513
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700514 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800515 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700516}
517
Jeff Davidson513d7a42010-08-02 10:00:44 -0700518# Tab completion for lunch.
519function _lunch()
520{
521 local cur prev opts
522 COMPREPLY=()
523 cur="${COMP_WORDS[COMP_CWORD]}"
524 prev="${COMP_WORDS[COMP_CWORD-1]}"
525
526 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
527 return 0
528}
529complete -F _lunch lunch
530
Joe Onoratoda12daf2010-06-09 18:18:31 -0700531# Configures the build to build unbundled apps.
532# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
533function tapas()
534{
Jeff Hamilton293f9392011-11-18 17:15:25 -0600535 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
536 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng)$'))
Joe Onoratoda12daf2010-06-09 18:18:31 -0700537
538 if [ $(echo $variant | wc -w) -gt 1 ]; then
539 echo "tapas: Error: Multiple build variants supplied: $variant"
540 return
541 fi
542 if [ -z "$variant" ]; then
543 variant=eng
544 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700545 if [ -z "$apps" ]; then
546 apps=all
547 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700548
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700549 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700550 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700551 export TARGET_BUILD_TYPE=release
552 export TARGET_BUILD_APPS=$apps
553
554 set_stuff_for_environment
555 printconfig
556}
557
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700558function gettop
559{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800560 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700561 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
562 echo $TOP
563 else
564 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800565 # The following circumlocution (repeated below as well) ensures
566 # that we record the true directory name and not one that is
567 # faked up with symlink names.
568 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700569 else
570 # We redirect cd to /dev/null in case it's aliased to
571 # a command that prints something as a side-effect
572 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800573 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700574 T=
575 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
576 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800577 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700578 done
579 cd $HERE > /dev/null
580 if [ -f "$T/$TOPFILE" ]; then
581 echo $T
582 fi
583 fi
584 fi
585}
586
587function m()
588{
589 T=$(gettop)
590 if [ "$T" ]; then
591 make -C $T $@
592 else
593 echo "Couldn't locate the top of the tree. Try setting TOP."
594 fi
595}
596
597function findmakefile()
598{
599 TOPFILE=build/core/envsetup.mk
600 # We redirect cd to /dev/null in case it's aliased to
601 # a command that prints something as a side-effect
602 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 T=
605 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
606 T=$PWD
607 if [ -f "$T/Android.mk" ]; then
608 echo $T/Android.mk
609 cd $HERE > /dev/null
610 return
611 fi
612 cd .. > /dev/null
613 done
614 cd $HERE > /dev/null
615}
616
617function mm()
618{
619 # If we're sitting in the root of the build tree, just do a
620 # normal make.
621 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
622 make $@
623 else
624 # Find the closest Android.mk file.
625 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800626 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700627 # Remove the path to top as the makefilepath needs to be relative
628 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700629 if [ ! "$T" ]; then
630 echo "Couldn't locate the top of the tree. Try setting TOP."
631 elif [ ! "$M" ]; then
632 echo "Couldn't locate a makefile from the current directory."
633 else
Ying Wang01884142010-07-20 16:18:16 -0700634 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700635 fi
636 fi
637}
638
639function mmm()
640{
641 T=$(gettop)
642 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800643 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800644 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800645 local ARGS=
646 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800647 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
648 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
649 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800650 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
651 if [ "$MODULES" = "" ]; then
652 MODULES=all_modules
653 fi
654 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700655 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700656 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800658 START=`PWD= /bin/pwd`
659 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700660 if [ "$MFILE" = "" ] ; then
661 MFILE=$DIR/Android.mk
662 else
663 MFILE=$MFILE/$DIR/Android.mk
664 fi
665 MAKEFILE="$MAKEFILE $MFILE"
666 else
667 if [ "$DIR" = snod ]; then
668 ARGS="$ARGS snod"
669 elif [ "$DIR" = showcommands ]; then
670 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700671 elif [ "$DIR" = dist ]; then
672 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800673 elif [ "$DIR" = incrementaljavac ]; then
674 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700675 else
676 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400677 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700678 fi
679 fi
680 done
Alon Albert68895a92011-11-30 12:40:19 -0800681 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700682 else
683 echo "Couldn't locate the top of the tree. Try setting TOP."
684 fi
685}
686
687function croot()
688{
689 T=$(gettop)
690 if [ "$T" ]; then
691 cd $(gettop)
692 else
693 echo "Couldn't locate the top of the tree. Try setting TOP."
694 fi
695}
696
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700697function cproj()
698{
699 TOPFILE=build/core/envsetup.mk
700 # We redirect cd to /dev/null in case it's aliased to
701 # a command that prints something as a side-effect
702 # (like pushd)
703 local HERE=$PWD
704 T=
705 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
706 T=$PWD
707 if [ -f "$T/Android.mk" ]; then
708 cd $T
709 return
710 fi
711 cd .. > /dev/null
712 done
713 cd $HERE > /dev/null
714 echo "can't find Android.mk"
715}
716
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700717function pid()
718{
719 local EXE="$1"
720 if [ "$EXE" ] ; then
721 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
722 echo "$PID"
723 else
724 echo "usage: pid name"
725 fi
726}
727
Christopher Tate744ee802009-11-12 15:33:08 -0800728# systemstack - dump the current stack trace of all threads in the system process
729# to the usual ANR traces file
730function systemstack()
731{
732 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
733}
734
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700735function gdbclient()
736{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800737 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
738 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
739 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
740 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
741 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800742 local ARCH=$(get_build_var TARGET_ARCH)
743 local GDB
744 case "$ARCH" in
Jean-Baptiste Querufeec98b2012-05-16 13:18:39 -0700745 x86) GDB=i686-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800746 arm) GDB=arm-linux-androideabi-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700747 mips) GDB=mipsel-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800748 *) echo "Unknown arch $ARCH"; return 1;;
749 esac
750
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700751 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
752 local EXE="$1"
753 if [ "$EXE" ] ; then
754 EXE=$1
755 else
756 EXE="app_process"
757 fi
758
759 local PORT="$2"
760 if [ "$PORT" ] ; then
761 PORT=$2
762 else
763 PORT=":5039"
764 fi
765
766 local PID
767 local PROG="$3"
768 if [ "$PROG" ] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700769 if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
770 PID="$3"
771 else
772 PID=`pid $3`
773 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700774 adb forward "tcp$PORT" "tcp$PORT"
775 adb shell gdbserver $PORT --attach $PID &
776 sleep 2
777 else
778 echo ""
779 echo "If you haven't done so already, do this first on the device:"
780 echo " gdbserver $PORT /system/bin/$EXE"
781 echo " or"
782 echo " gdbserver $PORT --attach $PID"
783 echo ""
784 fi
785
786 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Kenny Root9bf081e2012-03-26 12:38:16 -0700787 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700788 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
789 echo >>"$OUT_ROOT/gdbclient.cmds" ""
790
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200791 $ANDROID_TOOLCHAIN/$GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792 else
793 echo "Unable to determine build system output dir."
794 fi
795
796}
797
798case `uname -s` in
799 Darwin)
800 function sgrep()
801 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700802 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 -0700803 }
804
805 ;;
806 *)
807 function sgrep()
808 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700809 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 -0700810 }
811 ;;
812esac
813
Raghu Gandham8da43102012-07-25 19:57:22 -0700814function gettargetarch
815{
816 get_build_var TARGET_ARCH
817}
818
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700819function jgrep()
820{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700821 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 -0700822}
823
824function cgrep()
825{
Mike Dodd0c26d342011-04-07 13:29:06 -0700826 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 -0700827}
828
829function resgrep()
830{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700831 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 -0700832}
833
834case `uname -s` in
835 Darwin)
836 function mgrep()
837 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700838 find -E . -name .repo -prune -o -name .git -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 -0700839 }
840
841 function treegrep()
842 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700843 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 -0700844 }
845
846 ;;
847 *)
848 function mgrep()
849 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700850 find . -name .repo -prune -o -name .git -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 -0700851 }
852
853 function treegrep()
854 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700855 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 -0700856 }
857
858 ;;
859esac
860
861function getprebuilt
862{
863 get_abs_build_var ANDROID_PREBUILTS
864}
865
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700866function tracedmdump()
867{
868 T=$(gettop)
869 if [ ! "$T" ]; then
870 echo "Couldn't locate the top of the tree. Try setting TOP."
871 return
872 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800873 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -0700874 local arch=$(gettargetarch)
875 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700876
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800877 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700878 if [ ! "$TRACE" ] ; then
879 echo "usage: tracedmdump tracename"
880 return
881 fi
882
Jack Veenstra60116fc2009-04-09 18:12:34 -0700883 if [ ! -r "$KERNEL" ] ; then
884 echo "Error: cannot find kernel: '$KERNEL'"
885 return
886 fi
887
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800888 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700889 if [ "$BASETRACE" = "$TRACE" ] ; then
890 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
891 fi
892
893 echo "post-processing traces..."
894 rm -f $TRACE/qtrace.dexlist
895 post_trace $TRACE
896 if [ $? -ne 0 ]; then
897 echo "***"
898 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
899 echo "***"
900 return
901 fi
902 echo "generating dexlist output..."
903 /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
904 echo "generating dmtrace data..."
905 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
906 echo "generating html file..."
907 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
908 echo "done, see $TRACE/dmtrace.html for details"
909 echo "or run:"
910 echo " traceview $TRACE/dmtrace"
911}
912
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800913# communicate with a running device or emulator, set up necessary state,
914# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700915function runhat()
916{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800917 # process standard adb options
918 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700919 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800920 adbTarget=$1
921 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700922 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800923 adbTarget="$1 $2"
924 shift 2
925 fi
926 local adbOptions=${adbTarget}
927 echo adbOptions = ${adbOptions}
928
929 # runhat options
930 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700931
932 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700933 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700934 return
935 fi
936
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800937 # confirm hat is available
938 if [ -z $(which hat) ]; then
939 echo "hat is not available in this configuration."
940 return
941 fi
942
Andy McFaddenb6289852010-07-12 08:00:19 -0700943 # issue "am" command to cause the hprof dump
944 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700945 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700946 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800947 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700948 echo -n "> "
949 read
950
The Android Open Source Project88b60792009-03-03 19:28:42 -0800951 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700952
The Android Open Source Project88b60792009-03-03 19:28:42 -0800953 echo "Retrieving file $devFile..."
954 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700955
The Android Open Source Project88b60792009-03-03 19:28:42 -0800956 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700957
The Android Open Source Project88b60792009-03-03 19:28:42 -0800958 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700959 echo "View the output by pointing your browser at http://localhost:7000/"
960 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -0800961 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700962}
963
964function getbugreports()
965{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800966 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967
968 if [ ! "$reports" ]; then
969 echo "Could not locate any bugreports."
970 return
971 fi
972
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800973 local report
974 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700975 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800976 echo "/sdcard/bugreports/${report}"
977 adb pull /sdcard/bugreports/${report} ${report}
978 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700979 done
980}
981
982function startviewserver()
983{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800984 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700985 if [ $# -gt 0 ]; then
986 port=$1
987 fi
988 adb shell service call window 1 i32 $port
989}
990
991function stopviewserver()
992{
993 adb shell service call window 2
994}
995
996function isviewserverstarted()
997{
998 adb shell service call window 3
999}
1000
Romain Guyb84049a2010-10-04 16:56:11 -07001001function key_home()
1002{
1003 adb shell input keyevent 3
1004}
1005
1006function key_back()
1007{
1008 adb shell input keyevent 4
1009}
1010
1011function key_menu()
1012{
1013 adb shell input keyevent 82
1014}
1015
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001016function smoketest()
1017{
1018 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1019 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1020 return
1021 fi
1022 T=$(gettop)
1023 if [ ! "$T" ]; then
1024 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1025 return
1026 fi
1027
1028 (cd "$T" && mmm tests/SmokeTest) &&
1029 adb uninstall com.android.smoketest > /dev/null &&
1030 adb uninstall com.android.smoketest.tests > /dev/null &&
1031 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1032 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1033 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1034}
1035
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001036# simple shortcut to the runtest command
1037function runtest()
1038{
1039 T=$(gettop)
1040 if [ ! "$T" ]; then
1041 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1042 return
1043 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001044 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001045}
1046
The Android Open Source Project88b60792009-03-03 19:28:42 -08001047function godir () {
1048 if [[ -z "$1" ]]; then
1049 echo "Usage: godir <regex>"
1050 return
1051 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001052 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001053 if [[ ! -f $T/filelist ]]; then
1054 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001055 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001056 echo " Done"
1057 echo ""
1058 fi
1059 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001060 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001061 if [[ ${#lines[@]} = 0 ]]; then
1062 echo "Not found"
1063 return
1064 fi
1065 local pathname
1066 local choice
1067 if [[ ${#lines[@]} > 1 ]]; then
1068 while [[ -z "$pathname" ]]; do
1069 local index=1
1070 local line
1071 for line in ${lines[@]}; do
1072 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001073 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001074 done
1075 echo
1076 echo -n "Select one: "
1077 unset choice
1078 read choice
1079 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1080 echo "Invalid choice"
1081 continue
1082 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001083 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001084 done
1085 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001086 pathname=${lines[0]}
1087 fi
1088 cd $T/$pathname
1089}
1090
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001091# Force JAVA_HOME to point to java 1.6 if it isn't already set
1092function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001093 if [ ! "$JAVA_HOME" ]; then
1094 case `uname -s` in
1095 Darwin)
1096 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1097 ;;
1098 *)
1099 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1100 ;;
1101 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001102 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001103}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001104
Raphael Moll70a86b02011-06-20 16:03:14 -07001105if [ "x$SHELL" != "x/bin/bash" ]; then
1106 case `ps -o command -p $$` in
1107 *bash*)
1108 ;;
1109 *)
1110 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1111 ;;
1112 esac
1113fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001114
1115# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001116for f in `/bin/ls vendor/*/vendorsetup.sh vendor/*/*/vendorsetup.sh device/*/*/vendorsetup.sh 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001117do
1118 echo "including $f"
1119 . $f
1120done
1121unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001122
1123addcompletions