blob: e0b5748f4c68d18dd8d38e5cbb3c33aa81d162b5 [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
Doug Zongker29034982011-04-22 08:16:56 -0700103 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
104 # strip trailing ':', if any
105 export PATH=${PATH/%:/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500106 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700107
108 # and in with the new
109 CODE_REVIEWS=
110 prebuiltdir=$(getprebuilt)
Jing Yu9d396e32010-07-29 15:07:31 -0700111 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/toolchain/arm-linux-androideabi-4.4.x/bin
112 export ARM_EABI_TOOLCHAIN=$prebuiltdir/toolchain/arm-eabi-4.4.3/bin
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700113 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
114 export ANDROID_QTOOLS=$T/development/emulator/qtools
Jing Yu9d396e32010-07-29 15:07:31 -0700115 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 -0700116 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800117
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500118 unset ANDROID_JAVA_TOOLCHAIN
119 if [ -n "$JAVA_HOME" ]; then
120 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
121 fi
122 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN
123 if [ -n "$ANDROID_PRE_BUILD_PATHS" ]; then
124 export PATH=$ANDROID_PRE_BUILD_PATHS:$PATH
125 fi
126
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800127 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700128 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
129 export OUT=$ANDROID_PRODUCT_OUT
130
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700131 unset ANDROID_HOST_OUT
132 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
133
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800134 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700135 # TODO: fix the path
136 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
137}
138
139function printconfig()
140{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800141 T=$(gettop)
142 if [ ! "$T" ]; then
143 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
144 return
145 fi
146 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700147}
148
149function set_stuff_for_environment()
150{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800151 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500152 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800153 setpaths
154 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700155
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800156 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700157}
158
159function set_sequence_number()
160{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700161 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700162}
163
164function settitle()
165{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800166 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700167 local product=$TARGET_PRODUCT
168 local variant=$TARGET_BUILD_VARIANT
169 local apps=$TARGET_BUILD_APPS
170 if [ -z "$apps" ]; then
171 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
172 else
173 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
174 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800175 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700176}
177
178case `uname -s` in
179 Linux)
180 function choosesim()
181 {
182 echo "Build for the simulator or the device?"
183 echo " 1. Device"
184 echo " 2. Simulator"
185 echo
186
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800187 export TARGET_SIMULATOR=
188 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700189 while [ -z $TARGET_SIMULATOR ]
190 do
191 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800192 if [ -z "$1" ] ; then
193 read ANSWER
194 else
195 echo $1
196 ANSWER=$1
197 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700198 case $ANSWER in
199 "")
200 export TARGET_SIMULATOR=false
201 ;;
202 1)
203 export TARGET_SIMULATOR=false
204 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800205 Device)
206 export TARGET_SIMULATOR=false
207 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700208 2)
209 export TARGET_SIMULATOR=true
210 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800211 Simulator)
212 export TARGET_SIMULATOR=true
213 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700214 *)
215 echo
216 echo "I didn't understand your response. Please try again."
217 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700218 ;;
219 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800220 if [ -n "$1" ] ; then
221 break
222 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700223 done
224
225 set_stuff_for_environment
226 }
227 ;;
228 *)
229 function choosesim()
230 {
231 echo "Only device builds are supported for" `uname -s`
232 echo " Forcing TARGET_SIMULATOR=false"
233 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800234 if [ -z "$1" ]
235 then
236 echo -n "Press enter: "
237 read
238 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700239
240 export TARGET_SIMULATOR=false
241 set_stuff_for_environment
242 }
243 ;;
244esac
245
246function choosetype()
247{
248 echo "Build type choices are:"
249 echo " 1. release"
250 echo " 2. debug"
251 echo
252
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800253 local DEFAULT_NUM DEFAULT_VALUE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700254 if [ $TARGET_SIMULATOR = "false" ] ; then
255 DEFAULT_NUM=1
256 DEFAULT_VALUE=release
257 else
258 DEFAULT_NUM=2
259 DEFAULT_VALUE=debug
260 fi
261
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800262 export TARGET_BUILD_TYPE=
263 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700264 while [ -z $TARGET_BUILD_TYPE ]
265 do
266 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800267 if [ -z "$1" ] ; then
268 read ANSWER
269 else
270 echo $1
271 ANSWER=$1
272 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700273 case $ANSWER in
274 "")
275 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
276 ;;
277 1)
278 export TARGET_BUILD_TYPE=release
279 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800280 release)
281 export TARGET_BUILD_TYPE=release
282 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700283 2)
284 export TARGET_BUILD_TYPE=debug
285 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800286 debug)
287 export TARGET_BUILD_TYPE=debug
288 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700289 *)
290 echo
291 echo "I didn't understand your response. Please try again."
292 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700293 ;;
294 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800295 if [ -n "$1" ] ; then
296 break
297 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700298 done
299
300 set_stuff_for_environment
301}
302
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303#
304# This function isn't really right: It chooses a TARGET_PRODUCT
305# based on the list of boards. Usually, that gets you something
306# that kinda works with a generic product, but really, you should
307# pick a product by name.
308#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309function chooseproduct()
310{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700311 if [ "x$TARGET_PRODUCT" != x ] ; then
312 default_value=$TARGET_PRODUCT
313 else
314 if [ "$TARGET_SIMULATOR" = true ] ; then
315 default_value=sim
316 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700317 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700318 fi
319 fi
320
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800321 export TARGET_PRODUCT=
322 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700323 while [ -z "$TARGET_PRODUCT" ]
324 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700325 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800326 if [ -z "$1" ] ; then
327 read ANSWER
328 else
329 echo $1
330 ANSWER=$1
331 fi
332
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700333 if [ -z "$ANSWER" ] ; then
334 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335 else
336 if check_product $ANSWER
337 then
338 export TARGET_PRODUCT=$ANSWER
339 else
340 echo "** Not a valid product: $ANSWER"
341 fi
342 fi
343 if [ -n "$1" ] ; then
344 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700345 fi
346 done
347
348 set_stuff_for_environment
349}
350
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800351function choosevariant()
352{
353 echo "Variant choices are:"
354 local index=1
355 local v
356 for v in ${VARIANT_CHOICES[@]}
357 do
358 # The product name is the name of the directory containing
359 # the makefile we found, above.
360 echo " $index. $v"
361 index=$(($index+1))
362 done
363
364 local default_value=eng
365 local ANSWER
366
367 export TARGET_BUILD_VARIANT=
368 while [ -z "$TARGET_BUILD_VARIANT" ]
369 do
370 echo -n "Which would you like? [$default_value] "
371 if [ -z "$1" ] ; then
372 read ANSWER
373 else
374 echo $1
375 ANSWER=$1
376 fi
377
378 if [ -z "$ANSWER" ] ; then
379 export TARGET_BUILD_VARIANT=$default_value
380 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
381 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800382 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800383 fi
384 else
385 if check_variant $ANSWER
386 then
387 export TARGET_BUILD_VARIANT=$ANSWER
388 else
389 echo "** Not a valid variant: $ANSWER"
390 fi
391 fi
392 if [ -n "$1" ] ; then
393 break
394 fi
395 done
396}
397
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700398function choosecombo()
399{
400 choosesim $1
401
402 echo
403 echo
404 choosetype $2
405
406 echo
407 echo
408 chooseproduct $3
409
410 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800411 echo
412 choosevariant $4
413
414 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700415 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800416 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700417}
418
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800419# Clear this variable. It will be built up again when the vendorsetup.sh
420# files are included at the end of this file.
421unset LUNCH_MENU_CHOICES
422function add_lunch_combo()
423{
424 local new_combo=$1
425 local c
426 for c in ${LUNCH_MENU_CHOICES[@]} ; do
427 if [ "$new_combo" = "$c" ] ; then
428 return
429 fi
430 done
431 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
432}
433
434# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700435add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700436add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800437add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800438
439# if we're on linux, add the simulator. There is a special case
440# in lunch to deal with the simulator
441if [ "$(uname)" = "Linux" ] ; then
442 add_lunch_combo simulator
443fi
444
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700445function print_lunch_menu()
446{
447 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700448 echo
449 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700450 echo
451 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800452
453 local i=1
454 local choice
455 for choice in ${LUNCH_MENU_CHOICES[@]}
456 do
457 echo " $i. $choice"
458 i=$(($i+1))
459 done
460
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461 echo
462}
463
464function lunch()
465{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800466 local answer
467
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470 else
471 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700472 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800473 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474 fi
475
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476 local selection=
477
478 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700479 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700480 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800481 elif [ "$answer" = "simulator" ]
482 then
483 selection=simulator
484 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
485 then
486 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
487 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800488 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800489 fi
490 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
491 then
492 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700493 fi
494
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800495 if [ -z "$selection" ]
496 then
497 echo
498 echo "Invalid lunch combo: $answer"
499 return 1
500 fi
501
Joe Onoratoda12daf2010-06-09 18:18:31 -0700502 export TARGET_BUILD_APPS=
503
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 # special case the simulator
505 if [ "$selection" = "simulator" ]
506 then
507 export TARGET_PRODUCT=sim
508 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700509 export TARGET_SIMULATOR=true
510 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 else
512 local product=$(echo -n $selection | sed -e "s/-.*$//")
513 check_product $product
514 if [ $? -ne 0 ]
515 then
516 echo
517 echo "** Don't have a product spec for: '$product'"
518 echo "** Do you have the right repo manifest?"
519 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700520 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521
522 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
523 check_variant $variant
524 if [ $? -ne 0 ]
525 then
526 echo
527 echo "** Invalid variant: '$variant'"
528 echo "** Must be one of ${VARIANT_CHOICES[@]}"
529 variant=
530 fi
531
532 if [ -z "$product" -o -z "$variant" ]
533 then
534 echo
535 return 1
536 fi
537
538 export TARGET_PRODUCT=$product
539 export TARGET_BUILD_VARIANT=$variant
540 export TARGET_SIMULATOR=false
541 export TARGET_BUILD_TYPE=release
542 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700543
544 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800545
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700546 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800547 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700548}
549
Jeff Davidson513d7a42010-08-02 10:00:44 -0700550# Tab completion for lunch.
551function _lunch()
552{
553 local cur prev opts
554 COMPREPLY=()
555 cur="${COMP_WORDS[COMP_CWORD]}"
556 prev="${COMP_WORDS[COMP_CWORD-1]}"
557
558 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
559 return 0
560}
561complete -F _lunch lunch
562
Joe Onoratoda12daf2010-06-09 18:18:31 -0700563# Configures the build to build unbundled apps.
564# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
565function tapas()
566{
567 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
568 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
569
570 if [ $(echo $variant | wc -w) -gt 1 ]; then
571 echo "tapas: Error: Multiple build variants supplied: $variant"
572 return
573 fi
574 if [ -z "$variant" ]; then
575 variant=eng
576 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700577 if [ -z "$apps" ]; then
578 apps=all
579 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700580
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700581 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700582 export TARGET_BUILD_VARIANT=$variant
583 export TARGET_SIMULATOR=false
584 export TARGET_BUILD_TYPE=release
585 export TARGET_BUILD_APPS=$apps
586
587 set_stuff_for_environment
588 printconfig
589}
590
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591function gettop
592{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800593 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700594 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
595 echo $TOP
596 else
597 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800598 # The following circumlocution (repeated below as well) ensures
599 # that we record the true directory name and not one that is
600 # faked up with symlink names.
601 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700602 else
603 # We redirect cd to /dev/null in case it's aliased to
604 # a command that prints something as a side-effect
605 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800606 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700607 T=
608 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
609 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800610 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700611 done
612 cd $HERE > /dev/null
613 if [ -f "$T/$TOPFILE" ]; then
614 echo $T
615 fi
616 fi
617 fi
618}
619
620function m()
621{
622 T=$(gettop)
623 if [ "$T" ]; then
624 make -C $T $@
625 else
626 echo "Couldn't locate the top of the tree. Try setting TOP."
627 fi
628}
629
630function findmakefile()
631{
632 TOPFILE=build/core/envsetup.mk
633 # We redirect cd to /dev/null in case it's aliased to
634 # a command that prints something as a side-effect
635 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800636 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700637 T=
638 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
639 T=$PWD
640 if [ -f "$T/Android.mk" ]; then
641 echo $T/Android.mk
642 cd $HERE > /dev/null
643 return
644 fi
645 cd .. > /dev/null
646 done
647 cd $HERE > /dev/null
648}
649
650function mm()
651{
652 # If we're sitting in the root of the build tree, just do a
653 # normal make.
654 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
655 make $@
656 else
657 # Find the closest Android.mk file.
658 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800659 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700660 # Remove the path to top as the makefilepath needs to be relative
661 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662 if [ ! "$T" ]; then
663 echo "Couldn't locate the top of the tree. Try setting TOP."
664 elif [ ! "$M" ]; then
665 echo "Couldn't locate a makefile from the current directory."
666 else
Ying Wang01884142010-07-20 16:18:16 -0700667 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700668 fi
669 fi
670}
671
672function mmm()
673{
674 T=$(gettop)
675 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800676 local MAKEFILE=
677 local ARGS=
678 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800679 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
680 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
681 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700682 DIR=`echo $DIR | sed -e 's:/$::'`
683 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700684 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700685 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800686 START=`PWD= /bin/pwd`
687 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700688 if [ "$MFILE" = "" ] ; then
689 MFILE=$DIR/Android.mk
690 else
691 MFILE=$MFILE/$DIR/Android.mk
692 fi
693 MAKEFILE="$MAKEFILE $MFILE"
694 else
695 if [ "$DIR" = snod ]; then
696 ARGS="$ARGS snod"
697 elif [ "$DIR" = showcommands ]; then
698 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700699 elif [ "$DIR" = dist ]; then
700 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800701 elif [ "$DIR" = incrementaljavac ]; then
702 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700703 else
704 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400705 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700706 fi
707 fi
708 done
Ying Wang01884142010-07-20 16:18:16 -0700709 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700710 else
711 echo "Couldn't locate the top of the tree. Try setting TOP."
712 fi
713}
714
715function croot()
716{
717 T=$(gettop)
718 if [ "$T" ]; then
719 cd $(gettop)
720 else
721 echo "Couldn't locate the top of the tree. Try setting TOP."
722 fi
723}
724
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700725function cproj()
726{
727 TOPFILE=build/core/envsetup.mk
728 # We redirect cd to /dev/null in case it's aliased to
729 # a command that prints something as a side-effect
730 # (like pushd)
731 local HERE=$PWD
732 T=
733 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
734 T=$PWD
735 if [ -f "$T/Android.mk" ]; then
736 cd $T
737 return
738 fi
739 cd .. > /dev/null
740 done
741 cd $HERE > /dev/null
742 echo "can't find Android.mk"
743}
744
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700745function pid()
746{
747 local EXE="$1"
748 if [ "$EXE" ] ; then
749 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
750 echo "$PID"
751 else
752 echo "usage: pid name"
753 fi
754}
755
Christopher Tate744ee802009-11-12 15:33:08 -0800756# systemstack - dump the current stack trace of all threads in the system process
757# to the usual ANR traces file
758function systemstack()
759{
760 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
761}
762
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700763function gdbclient()
764{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800765 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
766 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
767 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
768 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
769 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700770 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
771 local EXE="$1"
772 if [ "$EXE" ] ; then
773 EXE=$1
774 else
775 EXE="app_process"
776 fi
777
778 local PORT="$2"
779 if [ "$PORT" ] ; then
780 PORT=$2
781 else
782 PORT=":5039"
783 fi
784
785 local PID
786 local PROG="$3"
787 if [ "$PROG" ] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700788 if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
789 PID="$3"
790 else
791 PID=`pid $3`
792 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793 adb forward "tcp$PORT" "tcp$PORT"
794 adb shell gdbserver $PORT --attach $PID &
795 sleep 2
796 else
797 echo ""
798 echo "If you haven't done so already, do this first on the device:"
799 echo " gdbserver $PORT /system/bin/$EXE"
800 echo " or"
801 echo " gdbserver $PORT --attach $PID"
802 echo ""
803 fi
804
805 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
806 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
807 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
808 echo >>"$OUT_ROOT/gdbclient.cmds" ""
809
Jing Yu9d396e32010-07-29 15:07:31 -0700810 arm-linux-androideabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700811 else
812 echo "Unable to determine build system output dir."
813 fi
814
815}
816
817case `uname -s` in
818 Darwin)
819 function sgrep()
820 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700821 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 -0700822 }
823
824 ;;
825 *)
826 function sgrep()
827 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700828 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 -0700829 }
830 ;;
831esac
832
833function jgrep()
834{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700835 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 -0700836}
837
838function cgrep()
839{
Mike Dodd0c26d342011-04-07 13:29:06 -0700840 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 -0700841}
842
843function resgrep()
844{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700845 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 -0700846}
847
848case `uname -s` in
849 Darwin)
850 function mgrep()
851 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700852 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 -0700853 }
854
855 function treegrep()
856 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700857 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 -0700858 }
859
860 ;;
861 *)
862 function mgrep()
863 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700864 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 -0700865 }
866
867 function treegrep()
868 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700869 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 -0700870 }
871
872 ;;
873esac
874
875function getprebuilt
876{
877 get_abs_build_var ANDROID_PREBUILTS
878}
879
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700880function tracedmdump()
881{
882 T=$(gettop)
883 if [ ! "$T" ]; then
884 echo "Couldn't locate the top of the tree. Try setting TOP."
885 return
886 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800887 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700888 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700889
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800890 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700891 if [ ! "$TRACE" ] ; then
892 echo "usage: tracedmdump tracename"
893 return
894 fi
895
Jack Veenstra60116fc2009-04-09 18:12:34 -0700896 if [ ! -r "$KERNEL" ] ; then
897 echo "Error: cannot find kernel: '$KERNEL'"
898 return
899 fi
900
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800901 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700902 if [ "$BASETRACE" = "$TRACE" ] ; then
903 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
904 fi
905
906 echo "post-processing traces..."
907 rm -f $TRACE/qtrace.dexlist
908 post_trace $TRACE
909 if [ $? -ne 0 ]; then
910 echo "***"
911 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
912 echo "***"
913 return
914 fi
915 echo "generating dexlist output..."
916 /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
917 echo "generating dmtrace data..."
918 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
919 echo "generating html file..."
920 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
921 echo "done, see $TRACE/dmtrace.html for details"
922 echo "or run:"
923 echo " traceview $TRACE/dmtrace"
924}
925
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800926# communicate with a running device or emulator, set up necessary state,
927# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700928function runhat()
929{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800930 # process standard adb options
931 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700932 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800933 adbTarget=$1
934 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700935 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800936 adbTarget="$1 $2"
937 shift 2
938 fi
939 local adbOptions=${adbTarget}
940 echo adbOptions = ${adbOptions}
941
942 # runhat options
943 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700944
945 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700946 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700947 return
948 fi
949
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800950 # confirm hat is available
951 if [ -z $(which hat) ]; then
952 echo "hat is not available in this configuration."
953 return
954 fi
955
Andy McFaddenb6289852010-07-12 08:00:19 -0700956 # issue "am" command to cause the hprof dump
957 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700958 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700959 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800960 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700961 echo -n "> "
962 read
963
The Android Open Source Project88b60792009-03-03 19:28:42 -0800964 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700965
The Android Open Source Project88b60792009-03-03 19:28:42 -0800966 echo "Retrieving file $devFile..."
967 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700968
The Android Open Source Project88b60792009-03-03 19:28:42 -0800969 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700970
The Android Open Source Project88b60792009-03-03 19:28:42 -0800971 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700972 echo "View the output by pointing your browser at http://localhost:7000/"
973 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800974 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700975}
976
977function getbugreports()
978{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800979 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700980
981 if [ ! "$reports" ]; then
982 echo "Could not locate any bugreports."
983 return
984 fi
985
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800986 local report
987 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700988 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800989 echo "/sdcard/bugreports/${report}"
990 adb pull /sdcard/bugreports/${report} ${report}
991 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700992 done
993}
994
995function startviewserver()
996{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800997 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700998 if [ $# -gt 0 ]; then
999 port=$1
1000 fi
1001 adb shell service call window 1 i32 $port
1002}
1003
1004function stopviewserver()
1005{
1006 adb shell service call window 2
1007}
1008
1009function isviewserverstarted()
1010{
1011 adb shell service call window 3
1012}
1013
Romain Guyb84049a2010-10-04 16:56:11 -07001014function key_home()
1015{
1016 adb shell input keyevent 3
1017}
1018
1019function key_back()
1020{
1021 adb shell input keyevent 4
1022}
1023
1024function key_menu()
1025{
1026 adb shell input keyevent 82
1027}
1028
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001029function smoketest()
1030{
1031 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1032 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1033 return
1034 fi
1035 T=$(gettop)
1036 if [ ! "$T" ]; then
1037 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1038 return
1039 fi
1040
1041 (cd "$T" && mmm tests/SmokeTest) &&
1042 adb uninstall com.android.smoketest > /dev/null &&
1043 adb uninstall com.android.smoketest.tests > /dev/null &&
1044 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1045 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1046 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1047}
1048
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001049# simple shortcut to the runtest command
1050function runtest()
1051{
1052 T=$(gettop)
1053 if [ ! "$T" ]; then
1054 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1055 return
1056 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001057 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001058}
1059
The Android Open Source Project88b60792009-03-03 19:28:42 -08001060function godir () {
1061 if [[ -z "$1" ]]; then
1062 echo "Usage: godir <regex>"
1063 return
1064 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001065 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001066 if [[ ! -f $T/filelist ]]; then
1067 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001068 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001069 echo " Done"
1070 echo ""
1071 fi
1072 local lines
Doug Zongker29034982011-04-22 08:16:56 -07001073 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001074 if [[ ${#lines[@]} = 0 ]]; then
1075 echo "Not found"
1076 return
1077 fi
1078 local pathname
1079 local choice
1080 if [[ ${#lines[@]} > 1 ]]; then
1081 while [[ -z "$pathname" ]]; do
1082 local index=1
1083 local line
1084 for line in ${lines[@]}; do
1085 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001086 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001087 done
1088 echo
1089 echo -n "Select one: "
1090 unset choice
1091 read choice
1092 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1093 echo "Invalid choice"
1094 continue
1095 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001096 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001097 done
1098 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001099 pathname=${lines[0]}
1100 fi
1101 cd $T/$pathname
1102}
1103
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001104# Force JAVA_HOME to point to java 1.6 if it isn't already set
1105function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001106 if [ ! "$JAVA_HOME" ]; then
1107 case `uname -s` in
1108 Darwin)
1109 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1110 ;;
1111 *)
1112 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1113 ;;
1114 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001115 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001116}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001117
Kan-Ru Chen07453762010-07-05 15:53:47 +08001118case `ps -o command -p $$` in
1119 *bash*)
1120 ;;
1121 *)
1122 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1123 ;;
1124esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001125
1126# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001127for 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 -08001128do
1129 echo "including $f"
1130 . $f
1131done
1132unset f