blob: bbc345ab23b80a3a4ef464ac0d45b221eb0defa3 [file] [log] [blame]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001function help() {
2cat <<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 \
57 TARGET_PRODUCT=$1 TARGET_BUILD_VARIANT= \
58 TARGET_SIMULATOR= TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070059 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080060 get_build_var TARGET_DEVICE > /dev/null
61 # hide successful answers, but allow the errors to show
62}
63
64VARIANT_CHOICES=(user userdebug eng)
65
66# check to see if the supplied variant is valid
67function check_variant()
68{
69 for v in ${VARIANT_CHOICES[@]}
70 do
71 if [ "$v" = "$1" ]
72 then
73 return 0
74 fi
75 done
76 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070077}
78
79function setpaths()
80{
81 T=$(gettop)
82 if [ ! "$T" ]; then
83 echo "Couldn't locate the top of the tree. Try setting TOP."
84 return
85 fi
86
87 ##################################################################
88 # #
89 # Read me before you modify this code #
90 # #
91 # This function sets ANDROID_BUILD_PATHS to what it is adding #
92 # to PATH, and the next time it is run, it removes that from #
93 # PATH. This is required so lunch can be run more than once #
94 # and still have working paths. #
95 # #
96 ##################################################################
97
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070098 # out with the old
99 if [ -n $ANDROID_BUILD_PATHS ] ; then
100 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
101 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500102 if [ -n $ANDROID_PRE_BUILD_PATHS ] ; then
Kristian Monsenf6cb2d32011-04-15 15:43:23 +0100103 shopt -s extglob
104 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS?(:)/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500105 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700106
107 # and in with the new
108 CODE_REVIEWS=
109 prebuiltdir=$(getprebuilt)
Jing Yu9d396e32010-07-29 15:07:31 -0700110 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/toolchain/arm-linux-androideabi-4.4.x/bin
111 export ARM_EABI_TOOLCHAIN=$prebuiltdir/toolchain/arm-eabi-4.4.3/bin
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700112 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
113 export ANDROID_QTOOLS=$T/development/emulator/qtools
Jing Yu9d396e32010-07-29 15:07:31 -0700114 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 -0700115 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800116
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500117 unset ANDROID_JAVA_TOOLCHAIN
118 if [ -n "$JAVA_HOME" ]; then
119 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
120 fi
121 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN
122 if [ -n "$ANDROID_PRE_BUILD_PATHS" ]; then
123 export PATH=$ANDROID_PRE_BUILD_PATHS:$PATH
124 fi
125
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800126 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700127 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
128 export OUT=$ANDROID_PRODUCT_OUT
129
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700130 unset ANDROID_HOST_OUT
131 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
132
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800133 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700134 # TODO: fix the path
135 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
136}
137
138function printconfig()
139{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800140 T=$(gettop)
141 if [ ! "$T" ]; then
142 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
143 return
144 fi
145 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700146}
147
148function set_stuff_for_environment()
149{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800150 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500151 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800152 setpaths
153 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700154
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800155 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700156}
157
158function set_sequence_number()
159{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700160 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700161}
162
163function settitle()
164{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800165 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700166 local product=$TARGET_PRODUCT
167 local variant=$TARGET_BUILD_VARIANT
168 local apps=$TARGET_BUILD_APPS
169 if [ -z "$apps" ]; then
170 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
171 else
172 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
173 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800174 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700175}
176
177case `uname -s` in
178 Linux)
179 function choosesim()
180 {
181 echo "Build for the simulator or the device?"
182 echo " 1. Device"
183 echo " 2. Simulator"
184 echo
185
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800186 export TARGET_SIMULATOR=
187 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700188 while [ -z $TARGET_SIMULATOR ]
189 do
190 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800191 if [ -z "$1" ] ; then
192 read ANSWER
193 else
194 echo $1
195 ANSWER=$1
196 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700197 case $ANSWER in
198 "")
199 export TARGET_SIMULATOR=false
200 ;;
201 1)
202 export TARGET_SIMULATOR=false
203 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800204 Device)
205 export TARGET_SIMULATOR=false
206 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700207 2)
208 export TARGET_SIMULATOR=true
209 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800210 Simulator)
211 export TARGET_SIMULATOR=true
212 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700213 *)
214 echo
215 echo "I didn't understand your response. Please try again."
216 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700217 ;;
218 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800219 if [ -n "$1" ] ; then
220 break
221 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700222 done
223
224 set_stuff_for_environment
225 }
226 ;;
227 *)
228 function choosesim()
229 {
230 echo "Only device builds are supported for" `uname -s`
231 echo " Forcing TARGET_SIMULATOR=false"
232 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800233 if [ -z "$1" ]
234 then
235 echo -n "Press enter: "
236 read
237 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700238
239 export TARGET_SIMULATOR=false
240 set_stuff_for_environment
241 }
242 ;;
243esac
244
245function 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
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700253 if [ $TARGET_SIMULATOR = "false" ] ; then
254 DEFAULT_NUM=1
255 DEFAULT_VALUE=release
256 else
257 DEFAULT_NUM=2
258 DEFAULT_VALUE=debug
259 fi
260
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800261 export TARGET_BUILD_TYPE=
262 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263 while [ -z $TARGET_BUILD_TYPE ]
264 do
265 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800266 if [ -z "$1" ] ; then
267 read ANSWER
268 else
269 echo $1
270 ANSWER=$1
271 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700272 case $ANSWER in
273 "")
274 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
275 ;;
276 1)
277 export TARGET_BUILD_TYPE=release
278 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800279 release)
280 export TARGET_BUILD_TYPE=release
281 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700282 2)
283 export TARGET_BUILD_TYPE=debug
284 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800285 debug)
286 export TARGET_BUILD_TYPE=debug
287 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700288 *)
289 echo
290 echo "I didn't understand your response. Please try again."
291 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700292 ;;
293 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800294 if [ -n "$1" ] ; then
295 break
296 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297 done
298
299 set_stuff_for_environment
300}
301
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800302#
303# This function isn't really right: It chooses a TARGET_PRODUCT
304# based on the list of boards. Usually, that gets you something
305# that kinda works with a generic product, but really, you should
306# pick a product by name.
307#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700308function chooseproduct()
309{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700310 if [ "x$TARGET_PRODUCT" != x ] ; then
311 default_value=$TARGET_PRODUCT
312 else
313 if [ "$TARGET_SIMULATOR" = true ] ; then
314 default_value=sim
315 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700316 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317 fi
318 fi
319
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800320 export TARGET_PRODUCT=
321 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700322 while [ -z "$TARGET_PRODUCT" ]
323 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700324 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800325 if [ -z "$1" ] ; then
326 read ANSWER
327 else
328 echo $1
329 ANSWER=$1
330 fi
331
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332 if [ -z "$ANSWER" ] ; then
333 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800334 else
335 if check_product $ANSWER
336 then
337 export TARGET_PRODUCT=$ANSWER
338 else
339 echo "** Not a valid product: $ANSWER"
340 fi
341 fi
342 if [ -n "$1" ] ; then
343 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700344 fi
345 done
346
347 set_stuff_for_environment
348}
349
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800350function choosevariant()
351{
352 echo "Variant choices are:"
353 local index=1
354 local v
355 for v in ${VARIANT_CHOICES[@]}
356 do
357 # The product name is the name of the directory containing
358 # the makefile we found, above.
359 echo " $index. $v"
360 index=$(($index+1))
361 done
362
363 local default_value=eng
364 local ANSWER
365
366 export TARGET_BUILD_VARIANT=
367 while [ -z "$TARGET_BUILD_VARIANT" ]
368 do
369 echo -n "Which would you like? [$default_value] "
370 if [ -z "$1" ] ; then
371 read ANSWER
372 else
373 echo $1
374 ANSWER=$1
375 fi
376
377 if [ -z "$ANSWER" ] ; then
378 export TARGET_BUILD_VARIANT=$default_value
379 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
380 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800381 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800382 fi
383 else
384 if check_variant $ANSWER
385 then
386 export TARGET_BUILD_VARIANT=$ANSWER
387 else
388 echo "** Not a valid variant: $ANSWER"
389 fi
390 fi
391 if [ -n "$1" ] ; then
392 break
393 fi
394 done
395}
396
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700397function choosecombo()
398{
399 choosesim $1
400
401 echo
402 echo
403 choosetype $2
404
405 echo
406 echo
407 chooseproduct $3
408
409 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800410 echo
411 choosevariant $4
412
413 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700414 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800415 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700416}
417
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800418# Clear this variable. It will be built up again when the vendorsetup.sh
419# files are included at the end of this file.
420unset LUNCH_MENU_CHOICES
421function add_lunch_combo()
422{
423 local new_combo=$1
424 local c
425 for c in ${LUNCH_MENU_CHOICES[@]} ; do
426 if [ "$new_combo" = "$c" ] ; then
427 return
428 fi
429 done
430 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
431}
432
433# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700434add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700435add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800436add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800437
438# if we're on linux, add the simulator. There is a special case
439# in lunch to deal with the simulator
440if [ "$(uname)" = "Linux" ] ; then
441 add_lunch_combo simulator
442fi
443
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444function print_lunch_menu()
445{
446 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700447 echo
448 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449 echo
450 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800451
452 local i=1
453 local choice
454 for choice in ${LUNCH_MENU_CHOICES[@]}
455 do
456 echo " $i. $choice"
457 i=$(($i+1))
458 done
459
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700460 echo
461}
462
463function lunch()
464{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800465 local answer
466
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700467 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800468 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700469 else
470 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700471 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 fi
474
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800475 local selection=
476
477 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700479 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480 elif [ "$answer" = "simulator" ]
481 then
482 selection=simulator
483 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
484 then
485 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
486 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800487 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800488 fi
489 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
490 then
491 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700492 fi
493
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800494 if [ -z "$selection" ]
495 then
496 echo
497 echo "Invalid lunch combo: $answer"
498 return 1
499 fi
500
Joe Onoratoda12daf2010-06-09 18:18:31 -0700501 export TARGET_BUILD_APPS=
502
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800503 # special case the simulator
504 if [ "$selection" = "simulator" ]
505 then
506 export TARGET_PRODUCT=sim
507 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 export TARGET_SIMULATOR=true
509 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800510 else
511 local product=$(echo -n $selection | sed -e "s/-.*$//")
512 check_product $product
513 if [ $? -ne 0 ]
514 then
515 echo
516 echo "** Don't have a product spec for: '$product'"
517 echo "** Do you have the right repo manifest?"
518 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700519 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520
521 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
522 check_variant $variant
523 if [ $? -ne 0 ]
524 then
525 echo
526 echo "** Invalid variant: '$variant'"
527 echo "** Must be one of ${VARIANT_CHOICES[@]}"
528 variant=
529 fi
530
531 if [ -z "$product" -o -z "$variant" ]
532 then
533 echo
534 return 1
535 fi
536
537 export TARGET_PRODUCT=$product
538 export TARGET_BUILD_VARIANT=$variant
539 export TARGET_SIMULATOR=false
540 export TARGET_BUILD_TYPE=release
541 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700542
543 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800544
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700545 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800546 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700547}
548
Jeff Davidson513d7a42010-08-02 10:00:44 -0700549# Tab completion for lunch.
550function _lunch()
551{
552 local cur prev opts
553 COMPREPLY=()
554 cur="${COMP_WORDS[COMP_CWORD]}"
555 prev="${COMP_WORDS[COMP_CWORD-1]}"
556
557 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
558 return 0
559}
560complete -F _lunch lunch
561
Joe Onoratoda12daf2010-06-09 18:18:31 -0700562# Configures the build to build unbundled apps.
563# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
564function tapas()
565{
566 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
567 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
568
569 if [ $(echo $variant | wc -w) -gt 1 ]; then
570 echo "tapas: Error: Multiple build variants supplied: $variant"
571 return
572 fi
573 if [ -z "$variant" ]; then
574 variant=eng
575 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700576 if [ -z "$apps" ]; then
577 apps=all
578 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700579
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700580 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700581 export TARGET_BUILD_VARIANT=$variant
582 export TARGET_SIMULATOR=false
583 export TARGET_BUILD_TYPE=release
584 export TARGET_BUILD_APPS=$apps
585
586 set_stuff_for_environment
587 printconfig
588}
589
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590function gettop
591{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800592 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700593 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
594 echo $TOP
595 else
596 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800597 # The following circumlocution (repeated below as well) ensures
598 # that we record the true directory name and not one that is
599 # faked up with symlink names.
600 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700601 else
602 # We redirect cd to /dev/null in case it's aliased to
603 # a command that prints something as a side-effect
604 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800605 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700606 T=
607 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
608 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800609 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700610 done
611 cd $HERE > /dev/null
612 if [ -f "$T/$TOPFILE" ]; then
613 echo $T
614 fi
615 fi
616 fi
617}
618
619function m()
620{
621 T=$(gettop)
622 if [ "$T" ]; then
623 make -C $T $@
624 else
625 echo "Couldn't locate the top of the tree. Try setting TOP."
626 fi
627}
628
629function findmakefile()
630{
631 TOPFILE=build/core/envsetup.mk
632 # We redirect cd to /dev/null in case it's aliased to
633 # a command that prints something as a side-effect
634 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800635 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700636 T=
637 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
638 T=$PWD
639 if [ -f "$T/Android.mk" ]; then
640 echo $T/Android.mk
641 cd $HERE > /dev/null
642 return
643 fi
644 cd .. > /dev/null
645 done
646 cd $HERE > /dev/null
647}
648
649function mm()
650{
651 # If we're sitting in the root of the build tree, just do a
652 # normal make.
653 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
654 make $@
655 else
656 # Find the closest Android.mk file.
657 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800658 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700659 # Remove the path to top as the makefilepath needs to be relative
660 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661 if [ ! "$T" ]; then
662 echo "Couldn't locate the top of the tree. Try setting TOP."
663 elif [ ! "$M" ]; then
664 echo "Couldn't locate a makefile from the current directory."
665 else
Ying Wang01884142010-07-20 16:18:16 -0700666 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700667 fi
668 fi
669}
670
671function mmm()
672{
673 T=$(gettop)
674 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800675 local MAKEFILE=
676 local ARGS=
677 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800678 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
679 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
680 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700681 DIR=`echo $DIR | sed -e 's:/$::'`
682 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700683 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700684 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800685 START=`PWD= /bin/pwd`
686 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700687 if [ "$MFILE" = "" ] ; then
688 MFILE=$DIR/Android.mk
689 else
690 MFILE=$MFILE/$DIR/Android.mk
691 fi
692 MAKEFILE="$MAKEFILE $MFILE"
693 else
694 if [ "$DIR" = snod ]; then
695 ARGS="$ARGS snod"
696 elif [ "$DIR" = showcommands ]; then
697 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700698 elif [ "$DIR" = dist ]; then
699 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800700 elif [ "$DIR" = incrementaljavac ]; then
701 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700702 else
703 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400704 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700705 fi
706 fi
707 done
Ying Wang01884142010-07-20 16:18:16 -0700708 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_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
714function croot()
715{
716 T=$(gettop)
717 if [ "$T" ]; then
718 cd $(gettop)
719 else
720 echo "Couldn't locate the top of the tree. Try setting TOP."
721 fi
722}
723
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700724function cproj()
725{
726 TOPFILE=build/core/envsetup.mk
727 # We redirect cd to /dev/null in case it's aliased to
728 # a command that prints something as a side-effect
729 # (like pushd)
730 local HERE=$PWD
731 T=
732 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
733 T=$PWD
734 if [ -f "$T/Android.mk" ]; then
735 cd $T
736 return
737 fi
738 cd .. > /dev/null
739 done
740 cd $HERE > /dev/null
741 echo "can't find Android.mk"
742}
743
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700744function pid()
745{
746 local EXE="$1"
747 if [ "$EXE" ] ; then
748 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
749 echo "$PID"
750 else
751 echo "usage: pid name"
752 fi
753}
754
Christopher Tate744ee802009-11-12 15:33:08 -0800755# systemstack - dump the current stack trace of all threads in the system process
756# to the usual ANR traces file
757function systemstack()
758{
759 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
760}
761
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700762function gdbclient()
763{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800764 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
765 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
766 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
767 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
768 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700769 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
770 local EXE="$1"
771 if [ "$EXE" ] ; then
772 EXE=$1
773 else
774 EXE="app_process"
775 fi
776
777 local PORT="$2"
778 if [ "$PORT" ] ; then
779 PORT=$2
780 else
781 PORT=":5039"
782 fi
783
784 local PID
785 local PROG="$3"
786 if [ "$PROG" ] ; then
787 PID=`pid $3`
788 adb forward "tcp$PORT" "tcp$PORT"
789 adb shell gdbserver $PORT --attach $PID &
790 sleep 2
791 else
792 echo ""
793 echo "If you haven't done so already, do this first on the device:"
794 echo " gdbserver $PORT /system/bin/$EXE"
795 echo " or"
796 echo " gdbserver $PORT --attach $PID"
797 echo ""
798 fi
799
800 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
801 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
802 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
803 echo >>"$OUT_ROOT/gdbclient.cmds" ""
804
Jing Yu9d396e32010-07-29 15:07:31 -0700805 arm-linux-androideabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700806 else
807 echo "Unable to determine build system output dir."
808 fi
809
810}
811
812case `uname -s` in
813 Darwin)
814 function sgrep()
815 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700816 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 -0700817 }
818
819 ;;
820 *)
821 function sgrep()
822 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700823 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 -0700824 }
825 ;;
826esac
827
828function jgrep()
829{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700830 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 -0700831}
832
833function cgrep()
834{
Mike Dodd0c26d342011-04-07 13:29:06 -0700835 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 -0700836}
837
838function resgrep()
839{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700840 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 -0700841}
842
843case `uname -s` in
844 Darwin)
845 function mgrep()
846 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700847 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 -0700848 }
849
850 function treegrep()
851 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700852 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 -0700853 }
854
855 ;;
856 *)
857 function mgrep()
858 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700859 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 -0700860 }
861
862 function treegrep()
863 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700864 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 -0700865 }
866
867 ;;
868esac
869
870function getprebuilt
871{
872 get_abs_build_var ANDROID_PREBUILTS
873}
874
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700875function tracedmdump()
876{
877 T=$(gettop)
878 if [ ! "$T" ]; then
879 echo "Couldn't locate the top of the tree. Try setting TOP."
880 return
881 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800882 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700883 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700884
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800885 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700886 if [ ! "$TRACE" ] ; then
887 echo "usage: tracedmdump tracename"
888 return
889 fi
890
Jack Veenstra60116fc2009-04-09 18:12:34 -0700891 if [ ! -r "$KERNEL" ] ; then
892 echo "Error: cannot find kernel: '$KERNEL'"
893 return
894 fi
895
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800896 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700897 if [ "$BASETRACE" = "$TRACE" ] ; then
898 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
899 fi
900
901 echo "post-processing traces..."
902 rm -f $TRACE/qtrace.dexlist
903 post_trace $TRACE
904 if [ $? -ne 0 ]; then
905 echo "***"
906 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
907 echo "***"
908 return
909 fi
910 echo "generating dexlist output..."
911 /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
912 echo "generating dmtrace data..."
913 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
914 echo "generating html file..."
915 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
916 echo "done, see $TRACE/dmtrace.html for details"
917 echo "or run:"
918 echo " traceview $TRACE/dmtrace"
919}
920
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800921# communicate with a running device or emulator, set up necessary state,
922# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700923function runhat()
924{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800925 # process standard adb options
926 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700927 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800928 adbTarget=$1
929 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700930 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800931 adbTarget="$1 $2"
932 shift 2
933 fi
934 local adbOptions=${adbTarget}
935 echo adbOptions = ${adbOptions}
936
937 # runhat options
938 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700939
940 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700941 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700942 return
943 fi
944
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800945 # confirm hat is available
946 if [ -z $(which hat) ]; then
947 echo "hat is not available in this configuration."
948 return
949 fi
950
Andy McFaddenb6289852010-07-12 08:00:19 -0700951 # issue "am" command to cause the hprof dump
952 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700953 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700954 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800955 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700956 echo -n "> "
957 read
958
The Android Open Source Project88b60792009-03-03 19:28:42 -0800959 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700960
The Android Open Source Project88b60792009-03-03 19:28:42 -0800961 echo "Retrieving file $devFile..."
962 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700963
The Android Open Source Project88b60792009-03-03 19:28:42 -0800964 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700965
The Android Open Source Project88b60792009-03-03 19:28:42 -0800966 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967 echo "View the output by pointing your browser at http://localhost:7000/"
968 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800969 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700970}
971
972function getbugreports()
973{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800974 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700975
976 if [ ! "$reports" ]; then
977 echo "Could not locate any bugreports."
978 return
979 fi
980
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800981 local report
982 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700983 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800984 echo "/sdcard/bugreports/${report}"
985 adb pull /sdcard/bugreports/${report} ${report}
986 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700987 done
988}
989
990function startviewserver()
991{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800992 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700993 if [ $# -gt 0 ]; then
994 port=$1
995 fi
996 adb shell service call window 1 i32 $port
997}
998
999function stopviewserver()
1000{
1001 adb shell service call window 2
1002}
1003
1004function isviewserverstarted()
1005{
1006 adb shell service call window 3
1007}
1008
Romain Guyb84049a2010-10-04 16:56:11 -07001009function key_home()
1010{
1011 adb shell input keyevent 3
1012}
1013
1014function key_back()
1015{
1016 adb shell input keyevent 4
1017}
1018
1019function key_menu()
1020{
1021 adb shell input keyevent 82
1022}
1023
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001024function smoketest()
1025{
1026 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1027 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1028 return
1029 fi
1030 T=$(gettop)
1031 if [ ! "$T" ]; then
1032 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1033 return
1034 fi
1035
1036 (cd "$T" && mmm tests/SmokeTest) &&
1037 adb uninstall com.android.smoketest > /dev/null &&
1038 adb uninstall com.android.smoketest.tests > /dev/null &&
1039 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1040 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1041 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1042}
1043
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001044# simple shortcut to the runtest command
1045function runtest()
1046{
1047 T=$(gettop)
1048 if [ ! "$T" ]; then
1049 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1050 return
1051 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001052 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001053}
1054
The Android Open Source Project88b60792009-03-03 19:28:42 -08001055function godir () {
1056 if [[ -z "$1" ]]; then
1057 echo "Usage: godir <regex>"
1058 return
1059 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001060 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001061 if [[ ! -f $T/filelist ]]; then
1062 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001063 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001064 echo " Done"
1065 echo ""
1066 fi
1067 local lines
1068 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1069 if [[ ${#lines[@]} = 0 ]]; then
1070 echo "Not found"
1071 return
1072 fi
1073 local pathname
1074 local choice
1075 if [[ ${#lines[@]} > 1 ]]; then
1076 while [[ -z "$pathname" ]]; do
1077 local index=1
1078 local line
1079 for line in ${lines[@]}; do
1080 printf "%6s %s\n" "[$index]" $line
1081 index=$(($index + 1))
1082 done
1083 echo
1084 echo -n "Select one: "
1085 unset choice
1086 read choice
1087 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1088 echo "Invalid choice"
1089 continue
1090 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001091 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001092 done
1093 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001094 pathname=${lines[0]}
1095 fi
1096 cd $T/$pathname
1097}
1098
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001099# Force JAVA_HOME to point to java 1.6 if it isn't already set
1100function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001101 if [ ! "$JAVA_HOME" ]; then
1102 case `uname -s` in
1103 Darwin)
1104 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1105 ;;
1106 *)
1107 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1108 ;;
1109 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001110 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001111}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001112
Kan-Ru Chen07453762010-07-05 15:53:47 +08001113case `ps -o command -p $$` in
1114 *bash*)
1115 ;;
1116 *)
1117 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1118 ;;
1119esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001120
1121# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001122for 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 -08001123do
1124 echo "including $f"
1125 . $f
1126done
1127unset f