blob: dee328a4735ce3b49f66a1bc41cae839690866f0 [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
121 x86) toolchaindir=x86/i686-android-linux-4.4.3/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 ;;
125 *)
126 echo "Can't find toolchain for unknown architecture: $ARCH"
127 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700128 ;;
129 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700130 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
131 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700132 fi
Raphael732936d2011-06-22 14:35:32 -0700133
Ying Wang08f5e9a2012-04-17 18:10:11 -0700134 export ARM_EABI_TOOLCHAIN=
135 case $ARCH in
136 x86) toolchaindir=x86/i686-eabi-4.4.3/bin
137 ;;
138 arm) toolchaindir=arm/arm-eabi-4.6/bin
139 ;;
140 *)
141 echo "Can't find toolchain for unknown architecture: $ARCH"
142 toolchaindir=xxxxxxxxx
143 ;;
144 esac
145 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
146 export ARM_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
147 fi
148
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700149 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
150 export ANDROID_QTOOLS=$T/development/emulator/qtools
Jing Yu9d396e32010-07-29 15:07:31 -0700151 export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ARM_EABI_TOOLCHAIN$CODE_REVIEWS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700152 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800153
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500154 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900155 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500156 if [ -n "$JAVA_HOME" ]; then
157 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900158 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
159 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500160 fi
161
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800162 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700163 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
164 export OUT=$ANDROID_PRODUCT_OUT
165
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700166 unset ANDROID_HOST_OUT
167 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
168
Ben Cheng057fde12011-11-28 13:55:14 -0800169 # needed for processing samples collected by perf counters
170 unset OPROFILE_EVENTS_DIR
171 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
172
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800173 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700174 # TODO: fix the path
175 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
176}
177
178function printconfig()
179{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800180 T=$(gettop)
181 if [ ! "$T" ]; then
182 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
183 return
184 fi
185 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700186}
187
188function set_stuff_for_environment()
189{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800190 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500191 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800192 setpaths
193 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700194
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800195 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700196}
197
198function set_sequence_number()
199{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700200 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700201}
202
203function settitle()
204{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800205 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700206 local product=$TARGET_PRODUCT
207 local variant=$TARGET_BUILD_VARIANT
208 local apps=$TARGET_BUILD_APPS
209 if [ -z "$apps" ]; then
210 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
211 else
212 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
213 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800214 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700215}
216
Kenny Root52aa81c2011-07-15 11:07:06 -0700217function addcompletions()
218{
219 local T dir f
220
221 # Keep us from trying to run in something that isn't bash.
222 if [ -z "${BASH_VERSION}" ]; then
223 return
224 fi
225
226 # Keep us from trying to run in bash that's too old.
227 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
228 return
229 fi
230
231 dir="sdk/bash_completion"
232 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700233 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700234 echo "including $f"
235 . $f
236 done
237 fi
238}
239
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700240function choosetype()
241{
242 echo "Build type choices are:"
243 echo " 1. release"
244 echo " 2. debug"
245 echo
246
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800247 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700248 DEFAULT_NUM=1
249 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700250
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 export TARGET_BUILD_TYPE=
252 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700253 while [ -z $TARGET_BUILD_TYPE ]
254 do
255 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800256 if [ -z "$1" ] ; then
257 read ANSWER
258 else
259 echo $1
260 ANSWER=$1
261 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700262 case $ANSWER in
263 "")
264 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
265 ;;
266 1)
267 export TARGET_BUILD_TYPE=release
268 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800269 release)
270 export TARGET_BUILD_TYPE=release
271 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700272 2)
273 export TARGET_BUILD_TYPE=debug
274 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800275 debug)
276 export TARGET_BUILD_TYPE=debug
277 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700278 *)
279 echo
280 echo "I didn't understand your response. Please try again."
281 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700282 ;;
283 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800284 if [ -n "$1" ] ; then
285 break
286 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700287 done
288
289 set_stuff_for_environment
290}
291
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800292#
293# This function isn't really right: It chooses a TARGET_PRODUCT
294# based on the list of boards. Usually, that gets you something
295# that kinda works with a generic product, but really, you should
296# pick a product by name.
297#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700298function chooseproduct()
299{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300 if [ "x$TARGET_PRODUCT" != x ] ; then
301 default_value=$TARGET_PRODUCT
302 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700303 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700304 fi
305
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800306 export TARGET_PRODUCT=
307 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700308 while [ -z "$TARGET_PRODUCT" ]
309 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700310 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800311 if [ -z "$1" ] ; then
312 read ANSWER
313 else
314 echo $1
315 ANSWER=$1
316 fi
317
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700318 if [ -z "$ANSWER" ] ; then
319 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800320 else
321 if check_product $ANSWER
322 then
323 export TARGET_PRODUCT=$ANSWER
324 else
325 echo "** Not a valid product: $ANSWER"
326 fi
327 fi
328 if [ -n "$1" ] ; then
329 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700330 fi
331 done
332
333 set_stuff_for_environment
334}
335
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336function choosevariant()
337{
338 echo "Variant choices are:"
339 local index=1
340 local v
341 for v in ${VARIANT_CHOICES[@]}
342 do
343 # The product name is the name of the directory containing
344 # the makefile we found, above.
345 echo " $index. $v"
346 index=$(($index+1))
347 done
348
349 local default_value=eng
350 local ANSWER
351
352 export TARGET_BUILD_VARIANT=
353 while [ -z "$TARGET_BUILD_VARIANT" ]
354 do
355 echo -n "Which would you like? [$default_value] "
356 if [ -z "$1" ] ; then
357 read ANSWER
358 else
359 echo $1
360 ANSWER=$1
361 fi
362
363 if [ -z "$ANSWER" ] ; then
364 export TARGET_BUILD_VARIANT=$default_value
365 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
366 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800367 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800368 fi
369 else
370 if check_variant $ANSWER
371 then
372 export TARGET_BUILD_VARIANT=$ANSWER
373 else
374 echo "** Not a valid variant: $ANSWER"
375 fi
376 fi
377 if [ -n "$1" ] ; then
378 break
379 fi
380 done
381}
382
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700383function choosecombo()
384{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700385 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700386
387 echo
388 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700389 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700390
391 echo
392 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700393 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800394
395 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700396 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800397 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700398}
399
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800400# Clear this variable. It will be built up again when the vendorsetup.sh
401# files are included at the end of this file.
402unset LUNCH_MENU_CHOICES
403function add_lunch_combo()
404{
405 local new_combo=$1
406 local c
407 for c in ${LUNCH_MENU_CHOICES[@]} ; do
408 if [ "$new_combo" = "$c" ] ; then
409 return
410 fi
411 done
412 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
413}
414
415# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700416add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700417add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800418add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800419
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700420function print_lunch_menu()
421{
422 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700423 echo
424 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700425 echo
426 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800427
428 local i=1
429 local choice
430 for choice in ${LUNCH_MENU_CHOICES[@]}
431 do
432 echo " $i. $choice"
433 i=$(($i+1))
434 done
435
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700436 echo
437}
438
439function lunch()
440{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800441 local answer
442
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700443 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800444 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700445 else
446 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700447 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800448 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449 fi
450
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800451 local selection=
452
453 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700454 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700455 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800456 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
457 then
458 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
459 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800460 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800461 fi
462 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
463 then
464 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465 fi
466
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800467 if [ -z "$selection" ]
468 then
469 echo
470 echo "Invalid lunch combo: $answer"
471 return 1
472 fi
473
Joe Onoratoda12daf2010-06-09 18:18:31 -0700474 export TARGET_BUILD_APPS=
475
Jeff Browne33ba4c2011-07-11 22:11:46 -0700476 local product=$(echo -n $selection | sed -e "s/-.*$//")
477 check_product $product
478 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700480 echo
481 echo "** Don't have a product spec for: '$product'"
482 echo "** Do you have the right repo manifest?"
483 product=
484 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800485
Jeff Browne33ba4c2011-07-11 22:11:46 -0700486 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
487 check_variant $variant
488 if [ $? -ne 0 ]
489 then
490 echo
491 echo "** Invalid variant: '$variant'"
492 echo "** Must be one of ${VARIANT_CHOICES[@]}"
493 variant=
494 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800495
Jeff Browne33ba4c2011-07-11 22:11:46 -0700496 if [ -z "$product" -o -z "$variant" ]
497 then
498 echo
499 return 1
500 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800501
Jeff Browne33ba4c2011-07-11 22:11:46 -0700502 export TARGET_PRODUCT=$product
503 export TARGET_BUILD_VARIANT=$variant
504 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700505
506 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800509 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700510}
511
Jeff Davidson513d7a42010-08-02 10:00:44 -0700512# Tab completion for lunch.
513function _lunch()
514{
515 local cur prev opts
516 COMPREPLY=()
517 cur="${COMP_WORDS[COMP_CWORD]}"
518 prev="${COMP_WORDS[COMP_CWORD-1]}"
519
520 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
521 return 0
522}
523complete -F _lunch lunch
524
Joe Onoratoda12daf2010-06-09 18:18:31 -0700525# Configures the build to build unbundled apps.
526# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
527function tapas()
528{
Jeff Hamilton293f9392011-11-18 17:15:25 -0600529 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
530 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng)$'))
Joe Onoratoda12daf2010-06-09 18:18:31 -0700531
532 if [ $(echo $variant | wc -w) -gt 1 ]; then
533 echo "tapas: Error: Multiple build variants supplied: $variant"
534 return
535 fi
536 if [ -z "$variant" ]; then
537 variant=eng
538 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700539 if [ -z "$apps" ]; then
540 apps=all
541 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700542
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700543 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700544 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700545 export TARGET_BUILD_TYPE=release
546 export TARGET_BUILD_APPS=$apps
547
548 set_stuff_for_environment
549 printconfig
550}
551
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700552function gettop
553{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800554 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700555 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
556 echo $TOP
557 else
558 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800559 # The following circumlocution (repeated below as well) ensures
560 # that we record the true directory name and not one that is
561 # faked up with symlink names.
562 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700563 else
564 # We redirect cd to /dev/null in case it's aliased to
565 # a command that prints something as a side-effect
566 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800567 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700568 T=
569 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
570 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800571 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700572 done
573 cd $HERE > /dev/null
574 if [ -f "$T/$TOPFILE" ]; then
575 echo $T
576 fi
577 fi
578 fi
579}
580
581function m()
582{
583 T=$(gettop)
584 if [ "$T" ]; then
585 make -C $T $@
586 else
587 echo "Couldn't locate the top of the tree. Try setting TOP."
588 fi
589}
590
591function findmakefile()
592{
593 TOPFILE=build/core/envsetup.mk
594 # We redirect cd to /dev/null in case it's aliased to
595 # a command that prints something as a side-effect
596 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800597 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700598 T=
599 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
600 T=$PWD
601 if [ -f "$T/Android.mk" ]; then
602 echo $T/Android.mk
603 cd $HERE > /dev/null
604 return
605 fi
606 cd .. > /dev/null
607 done
608 cd $HERE > /dev/null
609}
610
611function mm()
612{
613 # If we're sitting in the root of the build tree, just do a
614 # normal make.
615 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
616 make $@
617 else
618 # Find the closest Android.mk file.
619 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800620 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700621 # Remove the path to top as the makefilepath needs to be relative
622 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700623 if [ ! "$T" ]; then
624 echo "Couldn't locate the top of the tree. Try setting TOP."
625 elif [ ! "$M" ]; then
626 echo "Couldn't locate a makefile from the current directory."
627 else
Ying Wang01884142010-07-20 16:18:16 -0700628 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700629 fi
630 fi
631}
632
633function mmm()
634{
635 T=$(gettop)
636 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800637 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800638 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800639 local ARGS=
640 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800641 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
642 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
643 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800644 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
645 if [ "$MODULES" = "" ]; then
646 MODULES=all_modules
647 fi
648 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700650 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800652 START=`PWD= /bin/pwd`
653 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700654 if [ "$MFILE" = "" ] ; then
655 MFILE=$DIR/Android.mk
656 else
657 MFILE=$MFILE/$DIR/Android.mk
658 fi
659 MAKEFILE="$MAKEFILE $MFILE"
660 else
661 if [ "$DIR" = snod ]; then
662 ARGS="$ARGS snod"
663 elif [ "$DIR" = showcommands ]; then
664 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700665 elif [ "$DIR" = dist ]; then
666 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800667 elif [ "$DIR" = incrementaljavac ]; then
668 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700669 else
670 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400671 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672 fi
673 fi
674 done
Alon Albert68895a92011-11-30 12:40:19 -0800675 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700676 else
677 echo "Couldn't locate the top of the tree. Try setting TOP."
678 fi
679}
680
681function croot()
682{
683 T=$(gettop)
684 if [ "$T" ]; then
685 cd $(gettop)
686 else
687 echo "Couldn't locate the top of the tree. Try setting TOP."
688 fi
689}
690
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700691function cproj()
692{
693 TOPFILE=build/core/envsetup.mk
694 # We redirect cd to /dev/null in case it's aliased to
695 # a command that prints something as a side-effect
696 # (like pushd)
697 local HERE=$PWD
698 T=
699 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
700 T=$PWD
701 if [ -f "$T/Android.mk" ]; then
702 cd $T
703 return
704 fi
705 cd .. > /dev/null
706 done
707 cd $HERE > /dev/null
708 echo "can't find Android.mk"
709}
710
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700711function pid()
712{
713 local EXE="$1"
714 if [ "$EXE" ] ; then
715 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
716 echo "$PID"
717 else
718 echo "usage: pid name"
719 fi
720}
721
Christopher Tate744ee802009-11-12 15:33:08 -0800722# systemstack - dump the current stack trace of all threads in the system process
723# to the usual ANR traces file
724function systemstack()
725{
726 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
727}
728
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700729function gdbclient()
730{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800731 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
732 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
733 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
734 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
735 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800736 local ARCH=$(get_build_var TARGET_ARCH)
737 local GDB
738 case "$ARCH" in
739 x86) GDB=i686-android-linux-gdb;;
740 arm) GDB=arm-linux-androideabi-gdb;;
741 *) echo "Unknown arch $ARCH"; return 1;;
742 esac
743
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700744 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
745 local EXE="$1"
746 if [ "$EXE" ] ; then
747 EXE=$1
748 else
749 EXE="app_process"
750 fi
751
752 local PORT="$2"
753 if [ "$PORT" ] ; then
754 PORT=$2
755 else
756 PORT=":5039"
757 fi
758
759 local PID
760 local PROG="$3"
761 if [ "$PROG" ] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700762 if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
763 PID="$3"
764 else
765 PID=`pid $3`
766 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700767 adb forward "tcp$PORT" "tcp$PORT"
768 adb shell gdbserver $PORT --attach $PID &
769 sleep 2
770 else
771 echo ""
772 echo "If you haven't done so already, do this first on the device:"
773 echo " gdbserver $PORT /system/bin/$EXE"
774 echo " or"
775 echo " gdbserver $PORT --attach $PID"
776 echo ""
777 fi
778
779 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Kenny Root9bf081e2012-03-26 12:38:16 -0700780 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 -0700781 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
782 echo >>"$OUT_ROOT/gdbclient.cmds" ""
783
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200784 $ANDROID_TOOLCHAIN/$GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700785 else
786 echo "Unable to determine build system output dir."
787 fi
788
789}
790
791case `uname -s` in
792 Darwin)
793 function sgrep()
794 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700795 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 -0700796 }
797
798 ;;
799 *)
800 function sgrep()
801 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700802 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 -0700803 }
804 ;;
805esac
806
807function jgrep()
808{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700809 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 -0700810}
811
812function cgrep()
813{
Mike Dodd0c26d342011-04-07 13:29:06 -0700814 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 -0700815}
816
817function resgrep()
818{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700819 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 -0700820}
821
822case `uname -s` in
823 Darwin)
824 function mgrep()
825 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700826 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 -0700827 }
828
829 function treegrep()
830 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700831 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 -0700832 }
833
834 ;;
835 *)
836 function mgrep()
837 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700838 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 -0700839 }
840
841 function treegrep()
842 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700843 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 -0700844 }
845
846 ;;
847esac
848
849function getprebuilt
850{
851 get_abs_build_var ANDROID_PREBUILTS
852}
853
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700854function tracedmdump()
855{
856 T=$(gettop)
857 if [ ! "$T" ]; then
858 echo "Couldn't locate the top of the tree. Try setting TOP."
859 return
860 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800861 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700862 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700863
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800864 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700865 if [ ! "$TRACE" ] ; then
866 echo "usage: tracedmdump tracename"
867 return
868 fi
869
Jack Veenstra60116fc2009-04-09 18:12:34 -0700870 if [ ! -r "$KERNEL" ] ; then
871 echo "Error: cannot find kernel: '$KERNEL'"
872 return
873 fi
874
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800875 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700876 if [ "$BASETRACE" = "$TRACE" ] ; then
877 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
878 fi
879
880 echo "post-processing traces..."
881 rm -f $TRACE/qtrace.dexlist
882 post_trace $TRACE
883 if [ $? -ne 0 ]; then
884 echo "***"
885 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
886 echo "***"
887 return
888 fi
889 echo "generating dexlist output..."
890 /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
891 echo "generating dmtrace data..."
892 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
893 echo "generating html file..."
894 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
895 echo "done, see $TRACE/dmtrace.html for details"
896 echo "or run:"
897 echo " traceview $TRACE/dmtrace"
898}
899
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800900# communicate with a running device or emulator, set up necessary state,
901# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700902function runhat()
903{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800904 # process standard adb options
905 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700906 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800907 adbTarget=$1
908 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700909 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800910 adbTarget="$1 $2"
911 shift 2
912 fi
913 local adbOptions=${adbTarget}
914 echo adbOptions = ${adbOptions}
915
916 # runhat options
917 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700918
919 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700920 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700921 return
922 fi
923
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800924 # confirm hat is available
925 if [ -z $(which hat) ]; then
926 echo "hat is not available in this configuration."
927 return
928 fi
929
Andy McFaddenb6289852010-07-12 08:00:19 -0700930 # issue "am" command to cause the hprof dump
931 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700932 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700933 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800934 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700935 echo -n "> "
936 read
937
The Android Open Source Project88b60792009-03-03 19:28:42 -0800938 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700939
The Android Open Source Project88b60792009-03-03 19:28:42 -0800940 echo "Retrieving file $devFile..."
941 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700942
The Android Open Source Project88b60792009-03-03 19:28:42 -0800943 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700944
The Android Open Source Project88b60792009-03-03 19:28:42 -0800945 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700946 echo "View the output by pointing your browser at http://localhost:7000/"
947 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -0800948 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700949}
950
951function getbugreports()
952{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800953 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700954
955 if [ ! "$reports" ]; then
956 echo "Could not locate any bugreports."
957 return
958 fi
959
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800960 local report
961 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700962 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800963 echo "/sdcard/bugreports/${report}"
964 adb pull /sdcard/bugreports/${report} ${report}
965 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966 done
967}
968
969function startviewserver()
970{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800971 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700972 if [ $# -gt 0 ]; then
973 port=$1
974 fi
975 adb shell service call window 1 i32 $port
976}
977
978function stopviewserver()
979{
980 adb shell service call window 2
981}
982
983function isviewserverstarted()
984{
985 adb shell service call window 3
986}
987
Romain Guyb84049a2010-10-04 16:56:11 -0700988function key_home()
989{
990 adb shell input keyevent 3
991}
992
993function key_back()
994{
995 adb shell input keyevent 4
996}
997
998function key_menu()
999{
1000 adb shell input keyevent 82
1001}
1002
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001003function smoketest()
1004{
1005 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1006 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1007 return
1008 fi
1009 T=$(gettop)
1010 if [ ! "$T" ]; then
1011 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1012 return
1013 fi
1014
1015 (cd "$T" && mmm tests/SmokeTest) &&
1016 adb uninstall com.android.smoketest > /dev/null &&
1017 adb uninstall com.android.smoketest.tests > /dev/null &&
1018 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1019 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1020 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1021}
1022
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001023# simple shortcut to the runtest command
1024function runtest()
1025{
1026 T=$(gettop)
1027 if [ ! "$T" ]; then
1028 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1029 return
1030 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001031 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001032}
1033
The Android Open Source Project88b60792009-03-03 19:28:42 -08001034function godir () {
1035 if [[ -z "$1" ]]; then
1036 echo "Usage: godir <regex>"
1037 return
1038 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001039 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001040 if [[ ! -f $T/filelist ]]; then
1041 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001042 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001043 echo " Done"
1044 echo ""
1045 fi
1046 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001047 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001048 if [[ ${#lines[@]} = 0 ]]; then
1049 echo "Not found"
1050 return
1051 fi
1052 local pathname
1053 local choice
1054 if [[ ${#lines[@]} > 1 ]]; then
1055 while [[ -z "$pathname" ]]; do
1056 local index=1
1057 local line
1058 for line in ${lines[@]}; do
1059 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001060 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001061 done
1062 echo
1063 echo -n "Select one: "
1064 unset choice
1065 read choice
1066 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1067 echo "Invalid choice"
1068 continue
1069 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001070 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001071 done
1072 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001073 pathname=${lines[0]}
1074 fi
1075 cd $T/$pathname
1076}
1077
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001078# Force JAVA_HOME to point to java 1.6 if it isn't already set
1079function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001080 if [ ! "$JAVA_HOME" ]; then
1081 case `uname -s` in
1082 Darwin)
1083 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1084 ;;
1085 *)
1086 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1087 ;;
1088 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001089 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001090}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001091
Raphael Moll70a86b02011-06-20 16:03:14 -07001092if [ "x$SHELL" != "x/bin/bash" ]; then
1093 case `ps -o command -p $$` in
1094 *bash*)
1095 ;;
1096 *)
1097 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1098 ;;
1099 esac
1100fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001101
1102# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001103for 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 -08001104do
1105 echo "including $f"
1106 . $f
1107done
1108unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001109
1110addcompletions