blob: a65d39b9854ed8cd8ce340cfaaf9c7434cac5c23 [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
Raphael Mollc639c782011-06-20 17:25:01 -070098 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
99 # due to "C:\Program Files" being in the path.
100
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700101 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700102 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700103 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
104 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700105 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500106 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
107 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700108
109 # and in with the new
110 CODE_REVIEWS=
111 prebuiltdir=$(getprebuilt)
Raphael732936d2011-06-22 14:35:32 -0700112
Raphael Mollc639c782011-06-20 17:25:01 -0700113 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Raphael732936d2011-06-22 14:35:32 -0700114 export ANDROID_EABI_TOOLCHAIN=
115 toolchaindir=toolchain/arm-linux-androideabi-4.4.x/bin
Raphael Mollc639c782011-06-20 17:25:01 -0700116 if [ -d "$prebuiltdir/$toolchaindir" ]; then
117 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700118 fi
Raphael732936d2011-06-22 14:35:32 -0700119
120 export ARM_EABI_TOOLCHAIN=
121 toolchaindir=toolchain/arm-eabi-4.4.3/bin
122 if [ -d "$prebuiltdir/$toolchaindir" ]; then
123 export ARM_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
124 fi
125
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700126 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
127 export ANDROID_QTOOLS=$T/development/emulator/qtools
Jing Yu9d396e32010-07-29 15:07:31 -0700128 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 -0700129 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800130
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500131 unset ANDROID_JAVA_TOOLCHAIN
132 if [ -n "$JAVA_HOME" ]; then
133 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
134 fi
135 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN
136 if [ -n "$ANDROID_PRE_BUILD_PATHS" ]; then
137 export PATH=$ANDROID_PRE_BUILD_PATHS:$PATH
138 fi
139
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800140 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700141 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
142 export OUT=$ANDROID_PRODUCT_OUT
143
Ed Heylc811f292011-06-07 12:02:51 -0700144 unset ANDROID_HOST_OUT
145 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
146
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800147 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700148 # TODO: fix the path
149 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800150
151 # needed for OProfile to post-process collected samples
152 export OPROFILE_EVENTS_DIR=$prebuiltdir/oprofile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700153}
154
155function printconfig()
156{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800157 T=$(gettop)
158 if [ ! "$T" ]; then
159 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
160 return
161 fi
162 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700163}
164
165function set_stuff_for_environment()
166{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800167 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500168 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800169 setpaths
170 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700171
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800172 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700173}
174
175function set_sequence_number()
176{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700177 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700178}
179
180function settitle()
181{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800182 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700183 local product=$TARGET_PRODUCT
184 local variant=$TARGET_BUILD_VARIANT
185 local apps=$TARGET_BUILD_APPS
186 if [ -z "$apps" ]; then
187 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
188 else
189 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
190 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800191 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700192}
193
194case `uname -s` in
195 Linux)
196 function choosesim()
197 {
198 echo "Build for the simulator or the device?"
199 echo " 1. Device"
200 echo " 2. Simulator"
201 echo
202
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800203 export TARGET_SIMULATOR=
204 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700205 while [ -z $TARGET_SIMULATOR ]
206 do
207 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800208 if [ -z "$1" ] ; then
209 read ANSWER
210 else
211 echo $1
212 ANSWER=$1
213 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700214 case $ANSWER in
215 "")
216 export TARGET_SIMULATOR=false
217 ;;
218 1)
219 export TARGET_SIMULATOR=false
220 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800221 Device)
222 export TARGET_SIMULATOR=false
223 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700224 2)
225 export TARGET_SIMULATOR=true
226 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800227 Simulator)
228 export TARGET_SIMULATOR=true
229 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700230 *)
231 echo
232 echo "I didn't understand your response. Please try again."
233 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700234 ;;
235 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800236 if [ -n "$1" ] ; then
237 break
238 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700239 done
240
241 set_stuff_for_environment
242 }
243 ;;
244 *)
245 function choosesim()
246 {
247 echo "Only device builds are supported for" `uname -s`
248 echo " Forcing TARGET_SIMULATOR=false"
249 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800250 if [ -z "$1" ]
251 then
252 echo -n "Press enter: "
253 read
254 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255
256 export TARGET_SIMULATOR=false
257 set_stuff_for_environment
258 }
259 ;;
260esac
261
262function choosetype()
263{
264 echo "Build type choices are:"
265 echo " 1. release"
266 echo " 2. debug"
267 echo
268
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800269 local DEFAULT_NUM DEFAULT_VALUE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700270 if [ $TARGET_SIMULATOR = "false" ] ; then
271 DEFAULT_NUM=1
272 DEFAULT_VALUE=release
273 else
274 DEFAULT_NUM=2
275 DEFAULT_VALUE=debug
276 fi
277
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800278 export TARGET_BUILD_TYPE=
279 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700280 while [ -z $TARGET_BUILD_TYPE ]
281 do
282 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800283 if [ -z "$1" ] ; then
284 read ANSWER
285 else
286 echo $1
287 ANSWER=$1
288 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700289 case $ANSWER in
290 "")
291 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
292 ;;
293 1)
294 export TARGET_BUILD_TYPE=release
295 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800296 release)
297 export TARGET_BUILD_TYPE=release
298 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700299 2)
300 export TARGET_BUILD_TYPE=debug
301 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800302 debug)
303 export TARGET_BUILD_TYPE=debug
304 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700305 *)
306 echo
307 echo "I didn't understand your response. Please try again."
308 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309 ;;
310 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800311 if [ -n "$1" ] ; then
312 break
313 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700314 done
315
316 set_stuff_for_environment
317}
318
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800319#
320# This function isn't really right: It chooses a TARGET_PRODUCT
321# based on the list of boards. Usually, that gets you something
322# that kinda works with a generic product, but really, you should
323# pick a product by name.
324#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325function chooseproduct()
326{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700327 if [ "x$TARGET_PRODUCT" != x ] ; then
328 default_value=$TARGET_PRODUCT
329 else
330 if [ "$TARGET_SIMULATOR" = true ] ; then
331 default_value=sim
332 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700333 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700334 fi
335 fi
336
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800337 export TARGET_PRODUCT=
338 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339 while [ -z "$TARGET_PRODUCT" ]
340 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700341 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800342 if [ -z "$1" ] ; then
343 read ANSWER
344 else
345 echo $1
346 ANSWER=$1
347 fi
348
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700349 if [ -z "$ANSWER" ] ; then
350 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800351 else
352 if check_product $ANSWER
353 then
354 export TARGET_PRODUCT=$ANSWER
355 else
356 echo "** Not a valid product: $ANSWER"
357 fi
358 fi
359 if [ -n "$1" ] ; then
360 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700361 fi
362 done
363
364 set_stuff_for_environment
365}
366
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800367function choosevariant()
368{
369 echo "Variant choices are:"
370 local index=1
371 local v
372 for v in ${VARIANT_CHOICES[@]}
373 do
374 # The product name is the name of the directory containing
375 # the makefile we found, above.
376 echo " $index. $v"
377 index=$(($index+1))
378 done
379
380 local default_value=eng
381 local ANSWER
382
383 export TARGET_BUILD_VARIANT=
384 while [ -z "$TARGET_BUILD_VARIANT" ]
385 do
386 echo -n "Which would you like? [$default_value] "
387 if [ -z "$1" ] ; then
388 read ANSWER
389 else
390 echo $1
391 ANSWER=$1
392 fi
393
394 if [ -z "$ANSWER" ] ; then
395 export TARGET_BUILD_VARIANT=$default_value
396 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
397 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800398 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800399 fi
400 else
401 if check_variant $ANSWER
402 then
403 export TARGET_BUILD_VARIANT=$ANSWER
404 else
405 echo "** Not a valid variant: $ANSWER"
406 fi
407 fi
408 if [ -n "$1" ] ; then
409 break
410 fi
411 done
412}
413
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700414function choosecombo()
415{
416 choosesim $1
417
418 echo
419 echo
420 choosetype $2
421
422 echo
423 echo
424 chooseproduct $3
425
426 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800427 echo
428 choosevariant $4
429
430 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700431 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800432 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700433}
434
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800435# Clear this variable. It will be built up again when the vendorsetup.sh
436# files are included at the end of this file.
437unset LUNCH_MENU_CHOICES
438function add_lunch_combo()
439{
440 local new_combo=$1
441 local c
442 for c in ${LUNCH_MENU_CHOICES[@]} ; do
443 if [ "$new_combo" = "$c" ] ; then
444 return
445 fi
446 done
447 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
448}
449
450# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700451add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700452add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800453add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800454
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700455function print_lunch_menu()
456{
457 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458 echo
459 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700460 echo
461 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800462
463 local i=1
464 local choice
465 for choice in ${LUNCH_MENU_CHOICES[@]}
466 do
467 echo " $i. $choice"
468 i=$(($i+1))
469 done
470
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471 echo
472}
473
474function lunch()
475{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476 local answer
477
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700480 else
481 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700482 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800483 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700484 fi
485
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486 local selection=
487
488 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700489 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700490 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800491 elif [ "$answer" = "simulator" ]
492 then
493 selection=simulator
494 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
495 then
496 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
497 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800498 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499 fi
500 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
501 then
502 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700503 fi
504
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800505 if [ -z "$selection" ]
506 then
507 echo
508 echo "Invalid lunch combo: $answer"
509 return 1
510 fi
511
Joe Onoratoda12daf2010-06-09 18:18:31 -0700512 export TARGET_BUILD_APPS=
513
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800514 # special case the simulator
515 if [ "$selection" = "simulator" ]
516 then
517 export TARGET_PRODUCT=sim
518 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700519 export TARGET_SIMULATOR=true
520 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521 else
522 local product=$(echo -n $selection | sed -e "s/-.*$//")
523 check_product $product
524 if [ $? -ne 0 ]
525 then
526 echo
527 echo "** Don't have a product spec for: '$product'"
528 echo "** Do you have the right repo manifest?"
529 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700530 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800531
532 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
533 check_variant $variant
534 if [ $? -ne 0 ]
535 then
536 echo
537 echo "** Invalid variant: '$variant'"
538 echo "** Must be one of ${VARIANT_CHOICES[@]}"
539 variant=
540 fi
541
542 if [ -z "$product" -o -z "$variant" ]
543 then
544 echo
545 return 1
546 fi
547
548 export TARGET_PRODUCT=$product
549 export TARGET_BUILD_VARIANT=$variant
550 export TARGET_SIMULATOR=false
551 export TARGET_BUILD_TYPE=release
552 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700553
554 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800555
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700556 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800557 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700558}
559
Jeff Davidson513d7a42010-08-02 10:00:44 -0700560# Tab completion for lunch.
561function _lunch()
562{
563 local cur prev opts
564 COMPREPLY=()
565 cur="${COMP_WORDS[COMP_CWORD]}"
566 prev="${COMP_WORDS[COMP_CWORD-1]}"
567
568 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
569 return 0
570}
571complete -F _lunch lunch
572
Joe Onoratoda12daf2010-06-09 18:18:31 -0700573# Configures the build to build unbundled apps.
574# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
575function tapas()
576{
577 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
578 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
579
580 if [ $(echo $variant | wc -w) -gt 1 ]; then
581 echo "tapas: Error: Multiple build variants supplied: $variant"
582 return
583 fi
584 if [ -z "$variant" ]; then
585 variant=eng
586 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700587 if [ -z "$apps" ]; then
588 apps=all
589 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700590
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700591 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700592 export TARGET_BUILD_VARIANT=$variant
593 export TARGET_SIMULATOR=false
594 export TARGET_BUILD_TYPE=release
595 export TARGET_BUILD_APPS=$apps
596
597 set_stuff_for_environment
598 printconfig
599}
600
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700601function gettop
602{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
605 echo $TOP
606 else
607 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800608 # The following circumlocution (repeated below as well) ensures
609 # that we record the true directory name and not one that is
610 # faked up with symlink names.
611 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700612 else
613 # We redirect cd to /dev/null in case it's aliased to
614 # a command that prints something as a side-effect
615 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800616 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700617 T=
618 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
619 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800620 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700621 done
622 cd $HERE > /dev/null
623 if [ -f "$T/$TOPFILE" ]; then
624 echo $T
625 fi
626 fi
627 fi
628}
629
630function m()
631{
632 T=$(gettop)
633 if [ "$T" ]; then
634 make -C $T $@
635 else
636 echo "Couldn't locate the top of the tree. Try setting TOP."
637 fi
638}
639
640function findmakefile()
641{
642 TOPFILE=build/core/envsetup.mk
643 # We redirect cd to /dev/null in case it's aliased to
644 # a command that prints something as a side-effect
645 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800646 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700647 T=
648 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
649 T=$PWD
650 if [ -f "$T/Android.mk" ]; then
651 echo $T/Android.mk
652 cd $HERE > /dev/null
653 return
654 fi
655 cd .. > /dev/null
656 done
657 cd $HERE > /dev/null
658}
659
660function mm()
661{
662 # If we're sitting in the root of the build tree, just do a
663 # normal make.
664 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
665 make $@
666 else
667 # Find the closest Android.mk file.
668 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800669 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700670 # Remove the path to top as the makefilepath needs to be relative
671 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672 if [ ! "$T" ]; then
673 echo "Couldn't locate the top of the tree. Try setting TOP."
674 elif [ ! "$M" ]; then
675 echo "Couldn't locate a makefile from the current directory."
676 else
Ying Wang01884142010-07-20 16:18:16 -0700677 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700678 fi
679 fi
680}
681
682function mmm()
683{
684 T=$(gettop)
685 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800686 local MAKEFILE=
687 local ARGS=
688 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800689 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
690 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
691 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700692 DIR=`echo $DIR | sed -e 's:/$::'`
693 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700694 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700695 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800696 START=`PWD= /bin/pwd`
697 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700698 if [ "$MFILE" = "" ] ; then
699 MFILE=$DIR/Android.mk
700 else
701 MFILE=$MFILE/$DIR/Android.mk
702 fi
703 MAKEFILE="$MAKEFILE $MFILE"
704 else
705 if [ "$DIR" = snod ]; then
706 ARGS="$ARGS snod"
707 elif [ "$DIR" = showcommands ]; then
708 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700709 elif [ "$DIR" = dist ]; then
710 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800711 elif [ "$DIR" = incrementaljavac ]; then
712 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700713 else
714 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400715 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700716 fi
717 fi
718 done
Ying Wang01884142010-07-20 16:18:16 -0700719 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700720 else
721 echo "Couldn't locate the top of the tree. Try setting TOP."
722 fi
723}
724
725function croot()
726{
727 T=$(gettop)
728 if [ "$T" ]; then
729 cd $(gettop)
730 else
731 echo "Couldn't locate the top of the tree. Try setting TOP."
732 fi
733}
734
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700735function cproj()
736{
737 TOPFILE=build/core/envsetup.mk
738 # We redirect cd to /dev/null in case it's aliased to
739 # a command that prints something as a side-effect
740 # (like pushd)
741 local HERE=$PWD
742 T=
743 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
744 T=$PWD
745 if [ -f "$T/Android.mk" ]; then
746 cd $T
747 return
748 fi
749 cd .. > /dev/null
750 done
751 cd $HERE > /dev/null
752 echo "can't find Android.mk"
753}
754
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700755function pid()
756{
757 local EXE="$1"
758 if [ "$EXE" ] ; then
759 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
760 echo "$PID"
761 else
762 echo "usage: pid name"
763 fi
764}
765
Christopher Tate744ee802009-11-12 15:33:08 -0800766# systemstack - dump the current stack trace of all threads in the system process
767# to the usual ANR traces file
768function systemstack()
769{
770 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
771}
772
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700773function gdbclient()
774{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800775 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
776 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
777 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
778 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
779 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700780 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
781 local EXE="$1"
782 if [ "$EXE" ] ; then
783 EXE=$1
784 else
785 EXE="app_process"
786 fi
787
788 local PORT="$2"
789 if [ "$PORT" ] ; then
790 PORT=$2
791 else
792 PORT=":5039"
793 fi
794
795 local PID
796 local PROG="$3"
797 if [ "$PROG" ] ; then
798 PID=`pid $3`
799 adb forward "tcp$PORT" "tcp$PORT"
800 adb shell gdbserver $PORT --attach $PID &
801 sleep 2
802 else
803 echo ""
804 echo "If you haven't done so already, do this first on the device:"
805 echo " gdbserver $PORT /system/bin/$EXE"
806 echo " or"
807 echo " gdbserver $PORT --attach $PID"
808 echo ""
809 fi
810
811 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
812 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
813 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
814 echo >>"$OUT_ROOT/gdbclient.cmds" ""
815
Jing Yu9d396e32010-07-29 15:07:31 -0700816 arm-linux-androideabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700817 else
818 echo "Unable to determine build system output dir."
819 fi
820
821}
822
823case `uname -s` in
824 Darwin)
825 function sgrep()
826 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100827 find -E . -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 -0700828 }
829
830 ;;
831 *)
832 function sgrep()
833 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100834 find . -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 -0700835 }
836 ;;
837esac
838
839function jgrep()
840{
841 find . -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
842}
843
844function cgrep()
845{
Ficus Kirkpatrick8889bdf2010-03-01 16:51:47 -0800846 find . -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 -0700847}
848
849function resgrep()
850{
851 for dir in `find . -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
852}
853
854case `uname -s` in
855 Darwin)
856 function mgrep()
857 {
858 find -E . -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
859 }
860
861 function treegrep()
862 {
863 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
864 }
865
866 ;;
867 *)
868 function mgrep()
869 {
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800870 find . -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 -0700871 }
872
873 function treegrep()
874 {
875 find . -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
876 }
877
878 ;;
879esac
880
881function getprebuilt
882{
883 get_abs_build_var ANDROID_PREBUILTS
884}
885
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700886function tracedmdump()
887{
888 T=$(gettop)
889 if [ ! "$T" ]; then
890 echo "Couldn't locate the top of the tree. Try setting TOP."
891 return
892 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800893 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700894 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700895
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800896 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700897 if [ ! "$TRACE" ] ; then
898 echo "usage: tracedmdump tracename"
899 return
900 fi
901
Jack Veenstra60116fc2009-04-09 18:12:34 -0700902 if [ ! -r "$KERNEL" ] ; then
903 echo "Error: cannot find kernel: '$KERNEL'"
904 return
905 fi
906
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800907 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700908 if [ "$BASETRACE" = "$TRACE" ] ; then
909 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
910 fi
911
912 echo "post-processing traces..."
913 rm -f $TRACE/qtrace.dexlist
914 post_trace $TRACE
915 if [ $? -ne 0 ]; then
916 echo "***"
917 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
918 echo "***"
919 return
920 fi
921 echo "generating dexlist output..."
922 /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
923 echo "generating dmtrace data..."
924 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
925 echo "generating html file..."
926 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
927 echo "done, see $TRACE/dmtrace.html for details"
928 echo "or run:"
929 echo " traceview $TRACE/dmtrace"
930}
931
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800932# communicate with a running device or emulator, set up necessary state,
933# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700934function runhat()
935{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800936 # process standard adb options
937 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700938 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800939 adbTarget=$1
940 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700941 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800942 adbTarget="$1 $2"
943 shift 2
944 fi
945 local adbOptions=${adbTarget}
946 echo adbOptions = ${adbOptions}
947
948 # runhat options
949 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700950
951 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700952 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700953 return
954 fi
955
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800956 # confirm hat is available
957 if [ -z $(which hat) ]; then
958 echo "hat is not available in this configuration."
959 return
960 fi
961
Andy McFaddenb6289852010-07-12 08:00:19 -0700962 # issue "am" command to cause the hprof dump
963 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700964 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700965 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800966 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967 echo -n "> "
968 read
969
The Android Open Source Project88b60792009-03-03 19:28:42 -0800970 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700971
The Android Open Source Project88b60792009-03-03 19:28:42 -0800972 echo "Retrieving file $devFile..."
973 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700974
The Android Open Source Project88b60792009-03-03 19:28:42 -0800975 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700976
The Android Open Source Project88b60792009-03-03 19:28:42 -0800977 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700978 echo "View the output by pointing your browser at http://localhost:7000/"
979 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800980 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700981}
982
983function getbugreports()
984{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800985 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700986
987 if [ ! "$reports" ]; then
988 echo "Could not locate any bugreports."
989 return
990 fi
991
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800992 local report
993 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700994 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800995 echo "/sdcard/bugreports/${report}"
996 adb pull /sdcard/bugreports/${report} ${report}
997 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700998 done
999}
1000
1001function startviewserver()
1002{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001003 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001004 if [ $# -gt 0 ]; then
1005 port=$1
1006 fi
1007 adb shell service call window 1 i32 $port
1008}
1009
1010function stopviewserver()
1011{
1012 adb shell service call window 2
1013}
1014
1015function isviewserverstarted()
1016{
1017 adb shell service call window 3
1018}
1019
Romain Guyb84049a2010-10-04 16:56:11 -07001020function key_home()
1021{
1022 adb shell input keyevent 3
1023}
1024
1025function key_back()
1026{
1027 adb shell input keyevent 4
1028}
1029
1030function key_menu()
1031{
1032 adb shell input keyevent 82
1033}
1034
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001035function smoketest()
1036{
1037 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1038 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1039 return
1040 fi
1041 T=$(gettop)
1042 if [ ! "$T" ]; then
1043 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1044 return
1045 fi
1046
1047 (cd "$T" && mmm tests/SmokeTest) &&
1048 adb uninstall com.android.smoketest > /dev/null &&
1049 adb uninstall com.android.smoketest.tests > /dev/null &&
1050 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1051 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1052 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1053}
1054
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001055# simple shortcut to the runtest command
1056function runtest()
1057{
1058 T=$(gettop)
1059 if [ ! "$T" ]; then
1060 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1061 return
1062 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001063 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001064}
1065
The Android Open Source Project88b60792009-03-03 19:28:42 -08001066function godir () {
1067 if [[ -z "$1" ]]; then
1068 echo "Usage: godir <regex>"
1069 return
1070 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001071 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001072 if [[ ! -f $T/filelist ]]; then
1073 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001074 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001075 echo " Done"
1076 echo ""
1077 fi
1078 local lines
1079 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1080 if [[ ${#lines[@]} = 0 ]]; then
1081 echo "Not found"
1082 return
1083 fi
1084 local pathname
1085 local choice
1086 if [[ ${#lines[@]} > 1 ]]; then
1087 while [[ -z "$pathname" ]]; do
1088 local index=1
1089 local line
1090 for line in ${lines[@]}; do
1091 printf "%6s %s\n" "[$index]" $line
1092 index=$(($index + 1))
1093 done
1094 echo
1095 echo -n "Select one: "
1096 unset choice
1097 read choice
1098 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1099 echo "Invalid choice"
1100 continue
1101 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001102 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001103 done
1104 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001105 pathname=${lines[0]}
1106 fi
1107 cd $T/$pathname
1108}
1109
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001110# Force JAVA_HOME to point to java 1.6 if it isn't already set
1111function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001112 if [ ! "$JAVA_HOME" ]; then
1113 case `uname -s` in
1114 Darwin)
1115 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1116 ;;
1117 *)
1118 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1119 ;;
1120 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001121 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001122}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001123
Raphael Moll70a86b02011-06-20 16:03:14 -07001124if [ "x$SHELL" != "x/bin/bash" ]; then
1125 case `ps -o command -p $$` in
1126 *bash*)
1127 ;;
1128 *)
1129 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1130 ;;
1131 esac
1132fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001133
1134# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001135for 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 -08001136do
1137 echo "including $f"
1138 . $f
1139done
1140unset f