blob: fe262f6ab82c2fab899035aa67de7e6225b19f34 [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
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080032 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
103 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
104 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700105
106 # and in with the new
107 CODE_REVIEWS=
108 prebuiltdir=$(getprebuilt)
Jing Yuada132a2010-06-16 20:17:19 -0700109 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/toolchain/arm-eabi-4.4.3/bin
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700110 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
111 export ANDROID_QTOOLS=$T/development/emulator/qtools
112 export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_EABI_TOOLCHAIN$CODE_REVIEWS
113 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800114
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500115 unset ANDROID_JAVA_TOOLCHAIN
116 if [ -n "$JAVA_HOME" ]; then
117 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
118 fi
119 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN
120 if [ -n "$ANDROID_PRE_BUILD_PATHS" ]; then
121 export PATH=$ANDROID_PRE_BUILD_PATHS:$PATH
122 fi
123
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800124 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700125 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
126 export OUT=$ANDROID_PRODUCT_OUT
127
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800128 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700129 # TODO: fix the path
130 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800131
132 # needed for OProfile to post-process collected samples
133 export OPROFILE_EVENTS_DIR=$prebuiltdir/oprofile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700134}
135
136function printconfig()
137{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800138 T=$(gettop)
139 if [ ! "$T" ]; then
140 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
141 return
142 fi
143 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700144}
145
146function set_stuff_for_environment()
147{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800148 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500149 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800150 setpaths
151 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700152
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800153 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700154}
155
156function set_sequence_number()
157{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700158 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700159}
160
161function settitle()
162{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800163 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700164 local product=$TARGET_PRODUCT
165 local variant=$TARGET_BUILD_VARIANT
166 local apps=$TARGET_BUILD_APPS
167 if [ -z "$apps" ]; then
168 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
169 else
170 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
171 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800172 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700173}
174
175case `uname -s` in
176 Linux)
177 function choosesim()
178 {
179 echo "Build for the simulator or the device?"
180 echo " 1. Device"
181 echo " 2. Simulator"
182 echo
183
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800184 export TARGET_SIMULATOR=
185 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700186 while [ -z $TARGET_SIMULATOR ]
187 do
188 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800189 if [ -z "$1" ] ; then
190 read ANSWER
191 else
192 echo $1
193 ANSWER=$1
194 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700195 case $ANSWER in
196 "")
197 export TARGET_SIMULATOR=false
198 ;;
199 1)
200 export TARGET_SIMULATOR=false
201 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800202 Device)
203 export TARGET_SIMULATOR=false
204 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700205 2)
206 export TARGET_SIMULATOR=true
207 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800208 Simulator)
209 export TARGET_SIMULATOR=true
210 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700211 *)
212 echo
213 echo "I didn't understand your response. Please try again."
214 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700215 ;;
216 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800217 if [ -n "$1" ] ; then
218 break
219 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700220 done
221
222 set_stuff_for_environment
223 }
224 ;;
225 *)
226 function choosesim()
227 {
228 echo "Only device builds are supported for" `uname -s`
229 echo " Forcing TARGET_SIMULATOR=false"
230 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800231 if [ -z "$1" ]
232 then
233 echo -n "Press enter: "
234 read
235 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700236
237 export TARGET_SIMULATOR=false
238 set_stuff_for_environment
239 }
240 ;;
241esac
242
243function choosetype()
244{
245 echo "Build type choices are:"
246 echo " 1. release"
247 echo " 2. debug"
248 echo
249
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800250 local DEFAULT_NUM DEFAULT_VALUE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700251 if [ $TARGET_SIMULATOR = "false" ] ; then
252 DEFAULT_NUM=1
253 DEFAULT_VALUE=release
254 else
255 DEFAULT_NUM=2
256 DEFAULT_VALUE=debug
257 fi
258
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800259 export TARGET_BUILD_TYPE=
260 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700261 while [ -z $TARGET_BUILD_TYPE ]
262 do
263 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800264 if [ -z "$1" ] ; then
265 read ANSWER
266 else
267 echo $1
268 ANSWER=$1
269 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700270 case $ANSWER in
271 "")
272 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
273 ;;
274 1)
275 export TARGET_BUILD_TYPE=release
276 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800277 release)
278 export TARGET_BUILD_TYPE=release
279 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700280 2)
281 export TARGET_BUILD_TYPE=debug
282 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800283 debug)
284 export TARGET_BUILD_TYPE=debug
285 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700286 *)
287 echo
288 echo "I didn't understand your response. Please try again."
289 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700290 ;;
291 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800292 if [ -n "$1" ] ; then
293 break
294 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700295 done
296
297 set_stuff_for_environment
298}
299
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800300#
301# This function isn't really right: It chooses a TARGET_PRODUCT
302# based on the list of boards. Usually, that gets you something
303# that kinda works with a generic product, but really, you should
304# pick a product by name.
305#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700306function chooseproduct()
307{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700308 if [ "x$TARGET_PRODUCT" != x ] ; then
309 default_value=$TARGET_PRODUCT
310 else
311 if [ "$TARGET_SIMULATOR" = true ] ; then
312 default_value=sim
313 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700314 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315 fi
316 fi
317
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800318 export TARGET_PRODUCT=
319 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700320 while [ -z "$TARGET_PRODUCT" ]
321 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700322 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800323 if [ -z "$1" ] ; then
324 read ANSWER
325 else
326 echo $1
327 ANSWER=$1
328 fi
329
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700330 if [ -z "$ANSWER" ] ; then
331 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332 else
333 if check_product $ANSWER
334 then
335 export TARGET_PRODUCT=$ANSWER
336 else
337 echo "** Not a valid product: $ANSWER"
338 fi
339 fi
340 if [ -n "$1" ] ; then
341 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700342 fi
343 done
344
345 set_stuff_for_environment
346}
347
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800348function choosevariant()
349{
350 echo "Variant choices are:"
351 local index=1
352 local v
353 for v in ${VARIANT_CHOICES[@]}
354 do
355 # The product name is the name of the directory containing
356 # the makefile we found, above.
357 echo " $index. $v"
358 index=$(($index+1))
359 done
360
361 local default_value=eng
362 local ANSWER
363
364 export TARGET_BUILD_VARIANT=
365 while [ -z "$TARGET_BUILD_VARIANT" ]
366 do
367 echo -n "Which would you like? [$default_value] "
368 if [ -z "$1" ] ; then
369 read ANSWER
370 else
371 echo $1
372 ANSWER=$1
373 fi
374
375 if [ -z "$ANSWER" ] ; then
376 export TARGET_BUILD_VARIANT=$default_value
377 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
378 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800379 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800380 fi
381 else
382 if check_variant $ANSWER
383 then
384 export TARGET_BUILD_VARIANT=$ANSWER
385 else
386 echo "** Not a valid variant: $ANSWER"
387 fi
388 fi
389 if [ -n "$1" ] ; then
390 break
391 fi
392 done
393}
394
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700395function choosecombo()
396{
397 choosesim $1
398
399 echo
400 echo
401 choosetype $2
402
403 echo
404 echo
405 chooseproduct $3
406
407 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800408 echo
409 choosevariant $4
410
411 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700412 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800413 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700414}
415
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800416# Clear this variable. It will be built up again when the vendorsetup.sh
417# files are included at the end of this file.
418unset LUNCH_MENU_CHOICES
419function add_lunch_combo()
420{
421 local new_combo=$1
422 local c
423 for c in ${LUNCH_MENU_CHOICES[@]} ; do
424 if [ "$new_combo" = "$c" ] ; then
425 return
426 fi
427 done
428 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
429}
430
431# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700432add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700433add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800434add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800435
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700436function print_lunch_menu()
437{
438 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700439 echo
440 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700441 echo
442 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800443
444 local i=1
445 local choice
446 for choice in ${LUNCH_MENU_CHOICES[@]}
447 do
448 echo " $i. $choice"
449 i=$(($i+1))
450 done
451
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700452 echo
453}
454
455function lunch()
456{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800457 local answer
458
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700459 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800460 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461 else
462 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700463 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800464 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465 fi
466
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800467 local selection=
468
469 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700471 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472 elif [ "$answer" = "simulator" ]
473 then
474 selection=simulator
475 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
476 then
477 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
478 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800479 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480 fi
481 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
482 then
483 selection=$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 if [ -z "$selection" ]
487 then
488 echo
489 echo "Invalid lunch combo: $answer"
490 return 1
491 fi
492
Joe Onoratoda12daf2010-06-09 18:18:31 -0700493 export TARGET_BUILD_APPS=
494
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800495 # special case the simulator
496 if [ "$selection" = "simulator" ]
497 then
498 export TARGET_PRODUCT=sim
499 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700500 export TARGET_SIMULATOR=true
501 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800502 else
503 local product=$(echo -n $selection | sed -e "s/-.*$//")
504 check_product $product
505 if [ $? -ne 0 ]
506 then
507 echo
508 echo "** Don't have a product spec for: '$product'"
509 echo "** Do you have the right repo manifest?"
510 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700511 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512
513 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
514 check_variant $variant
515 if [ $? -ne 0 ]
516 then
517 echo
518 echo "** Invalid variant: '$variant'"
519 echo "** Must be one of ${VARIANT_CHOICES[@]}"
520 variant=
521 fi
522
523 if [ -z "$product" -o -z "$variant" ]
524 then
525 echo
526 return 1
527 fi
528
529 export TARGET_PRODUCT=$product
530 export TARGET_BUILD_VARIANT=$variant
531 export TARGET_SIMULATOR=false
532 export TARGET_BUILD_TYPE=release
533 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700534
535 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800536
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700537 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800538 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700539}
540
Joe Onoratoda12daf2010-06-09 18:18:31 -0700541# Configures the build to build unbundled apps.
542# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
543function tapas()
544{
545 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
546 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
547
548 if [ $(echo $variant | wc -w) -gt 1 ]; then
549 echo "tapas: Error: Multiple build variants supplied: $variant"
550 return
551 fi
552 if [ -z "$variant" ]; then
553 variant=eng
554 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700555 if [ -z "$apps" ]; then
556 apps=all
557 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700558
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700559 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700560 export TARGET_BUILD_VARIANT=$variant
561 export TARGET_SIMULATOR=false
562 export TARGET_BUILD_TYPE=release
563 export TARGET_BUILD_APPS=$apps
564
565 set_stuff_for_environment
566 printconfig
567}
568
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700569function gettop
570{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800571 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700572 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
573 echo $TOP
574 else
575 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800576 # The following circumlocution (repeated below as well) ensures
577 # that we record the true directory name and not one that is
578 # faked up with symlink names.
579 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700580 else
581 # We redirect cd to /dev/null in case it's aliased to
582 # a command that prints something as a side-effect
583 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800584 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585 T=
586 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
587 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800588 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700589 done
590 cd $HERE > /dev/null
591 if [ -f "$T/$TOPFILE" ]; then
592 echo $T
593 fi
594 fi
595 fi
596}
597
598function m()
599{
600 T=$(gettop)
601 if [ "$T" ]; then
602 make -C $T $@
603 else
604 echo "Couldn't locate the top of the tree. Try setting TOP."
605 fi
606}
607
608function findmakefile()
609{
610 TOPFILE=build/core/envsetup.mk
611 # We redirect cd to /dev/null in case it's aliased to
612 # a command that prints something as a side-effect
613 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800614 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700615 T=
616 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
617 T=$PWD
618 if [ -f "$T/Android.mk" ]; then
619 echo $T/Android.mk
620 cd $HERE > /dev/null
621 return
622 fi
623 cd .. > /dev/null
624 done
625 cd $HERE > /dev/null
626}
627
628function mm()
629{
630 # If we're sitting in the root of the build tree, just do a
631 # normal make.
632 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
633 make $@
634 else
635 # Find the closest Android.mk file.
636 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800637 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700638 # Remove the path to top as the makefilepath needs to be relative
639 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700640 if [ ! "$T" ]; then
641 echo "Couldn't locate the top of the tree. Try setting TOP."
642 elif [ ! "$M" ]; then
643 echo "Couldn't locate a makefile from the current directory."
644 else
Ying Wang01884142010-07-20 16:18:16 -0700645 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700646 fi
647 fi
648}
649
650function mmm()
651{
652 T=$(gettop)
653 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800654 local MAKEFILE=
655 local ARGS=
656 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800657 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
658 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
659 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700660 DIR=`echo $DIR | sed -e 's:/$::'`
661 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700662 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700663 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800664 START=`PWD= /bin/pwd`
665 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700666 if [ "$MFILE" = "" ] ; then
667 MFILE=$DIR/Android.mk
668 else
669 MFILE=$MFILE/$DIR/Android.mk
670 fi
671 MAKEFILE="$MAKEFILE $MFILE"
672 else
673 if [ "$DIR" = snod ]; then
674 ARGS="$ARGS snod"
675 elif [ "$DIR" = showcommands ]; then
676 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700677 elif [ "$DIR" = dist ]; then
678 ARGS="$ARGS dist"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700679 else
680 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400681 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700682 fi
683 fi
684 done
Ying Wang01884142010-07-20 16:18:16 -0700685 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700686 else
687 echo "Couldn't locate the top of the tree. Try setting TOP."
688 fi
689}
690
691function croot()
692{
693 T=$(gettop)
694 if [ "$T" ]; then
695 cd $(gettop)
696 else
697 echo "Couldn't locate the top of the tree. Try setting TOP."
698 fi
699}
700
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700701function cproj()
702{
703 TOPFILE=build/core/envsetup.mk
704 # We redirect cd to /dev/null in case it's aliased to
705 # a command that prints something as a side-effect
706 # (like pushd)
707 local HERE=$PWD
708 T=
709 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
710 T=$PWD
711 if [ -f "$T/Android.mk" ]; then
712 cd $T
713 return
714 fi
715 cd .. > /dev/null
716 done
717 cd $HERE > /dev/null
718 echo "can't find Android.mk"
719}
720
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700721function pid()
722{
723 local EXE="$1"
724 if [ "$EXE" ] ; then
725 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
726 echo "$PID"
727 else
728 echo "usage: pid name"
729 fi
730}
731
Christopher Tate744ee802009-11-12 15:33:08 -0800732# systemstack - dump the current stack trace of all threads in the system process
733# to the usual ANR traces file
734function systemstack()
735{
736 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
737}
738
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700739function gdbclient()
740{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800741 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
742 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
743 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
744 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
745 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700746 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
747 local EXE="$1"
748 if [ "$EXE" ] ; then
749 EXE=$1
750 else
751 EXE="app_process"
752 fi
753
754 local PORT="$2"
755 if [ "$PORT" ] ; then
756 PORT=$2
757 else
758 PORT=":5039"
759 fi
760
761 local PID
762 local PROG="$3"
763 if [ "$PROG" ] ; then
764 PID=`pid $3`
765 adb forward "tcp$PORT" "tcp$PORT"
766 adb shell gdbserver $PORT --attach $PID &
767 sleep 2
768 else
769 echo ""
770 echo "If you haven't done so already, do this first on the device:"
771 echo " gdbserver $PORT /system/bin/$EXE"
772 echo " or"
773 echo " gdbserver $PORT --attach $PID"
774 echo ""
775 fi
776
777 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
778 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
779 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
780 echo >>"$OUT_ROOT/gdbclient.cmds" ""
781
782 arm-eabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
783 else
784 echo "Unable to determine build system output dir."
785 fi
786
787}
788
789case `uname -s` in
790 Darwin)
791 function sgrep()
792 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100793 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 -0700794 }
795
796 ;;
797 *)
798 function sgrep()
799 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100800 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 -0700801 }
802 ;;
803esac
804
805function jgrep()
806{
807 find . -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
808}
809
810function cgrep()
811{
Ficus Kirkpatrick8889bdf2010-03-01 16:51:47 -0800812 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 -0700813}
814
815function resgrep()
816{
817 for dir in `find . -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
818}
819
820case `uname -s` in
821 Darwin)
822 function mgrep()
823 {
824 find -E . -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
825 }
826
827 function treegrep()
828 {
829 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
830 }
831
832 ;;
833 *)
834 function mgrep()
835 {
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800836 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 -0700837 }
838
839 function treegrep()
840 {
841 find . -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
842 }
843
844 ;;
845esac
846
847function getprebuilt
848{
849 get_abs_build_var ANDROID_PREBUILTS
850}
851
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700852function tracedmdump()
853{
854 T=$(gettop)
855 if [ ! "$T" ]; then
856 echo "Couldn't locate the top of the tree. Try setting TOP."
857 return
858 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800859 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700860 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700861
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800862 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700863 if [ ! "$TRACE" ] ; then
864 echo "usage: tracedmdump tracename"
865 return
866 fi
867
Jack Veenstra60116fc2009-04-09 18:12:34 -0700868 if [ ! -r "$KERNEL" ] ; then
869 echo "Error: cannot find kernel: '$KERNEL'"
870 return
871 fi
872
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800873 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700874 if [ "$BASETRACE" = "$TRACE" ] ; then
875 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
876 fi
877
878 echo "post-processing traces..."
879 rm -f $TRACE/qtrace.dexlist
880 post_trace $TRACE
881 if [ $? -ne 0 ]; then
882 echo "***"
883 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
884 echo "***"
885 return
886 fi
887 echo "generating dexlist output..."
888 /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
889 echo "generating dmtrace data..."
890 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
891 echo "generating html file..."
892 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
893 echo "done, see $TRACE/dmtrace.html for details"
894 echo "or run:"
895 echo " traceview $TRACE/dmtrace"
896}
897
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800898# communicate with a running device or emulator, set up necessary state,
899# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700900function runhat()
901{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800902 # process standard adb options
903 local adbTarget=""
Chris Dearmanf0bcf422011-02-16 12:16:09 -0800904 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800905 adbTarget=$1
906 shift 1
Chris Dearmanf0bcf422011-02-16 12:16:09 -0800907 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800908 adbTarget="$1 $2"
909 shift 2
910 fi
911 local adbOptions=${adbTarget}
912 echo adbOptions = ${adbOptions}
913
914 # runhat options
915 local targetPid=$1
916 local outputFile=$2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700917
918 if [ "$targetPid" = "" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800919 echo "Usage: runhat [ -d | -e | -s serial ] target-pid [output-file]"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700920 return
921 fi
922
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800923 # confirm hat is available
924 if [ -z $(which hat) ]; then
925 echo "hat is not available in this configuration."
926 return
927 fi
928
929 adb ${adbOptions} shell >/dev/null mkdir /data/misc
930 adb ${adbOptions} shell chmod 777 /data/misc
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700931
The Android Open Source Project88b60792009-03-03 19:28:42 -0800932 # send a SIGUSR1 to cause the hprof dump
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700933 echo "Poking $targetPid and waiting for data..."
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800934 adb ${adbOptions} shell kill -10 $targetPid
The Android Open Source Project88b60792009-03-03 19:28:42 -0800935 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700936 echo -n "> "
937 read
938
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800939 local availFiles=( $(adb ${adbOptions} shell ls /data/misc | grep '^heap-dump' | sed -e 's/.*heap-dump-/heap-dump-/' | sort -r | tr '[:space:][:cntrl:]' ' ') )
The Android Open Source Project88b60792009-03-03 19:28:42 -0800940 local devFile=/data/misc/${availFiles[0]}
941 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700942
The Android Open Source Project88b60792009-03-03 19:28:42 -0800943 echo "Retrieving file $devFile..."
944 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700945
The Android Open Source Project88b60792009-03-03 19:28:42 -0800946 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700947
The Android Open Source Project88b60792009-03-03 19:28:42 -0800948 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700949 echo "View the output by pointing your browser at http://localhost:7000/"
950 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800951 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700952}
953
954function getbugreports()
955{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800956 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700957
958 if [ ! "$reports" ]; then
959 echo "Could not locate any bugreports."
960 return
961 fi
962
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800963 local report
964 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700965 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800966 echo "/sdcard/bugreports/${report}"
967 adb pull /sdcard/bugreports/${report} ${report}
968 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700969 done
970}
971
972function startviewserver()
973{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800974 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700975 if [ $# -gt 0 ]; then
976 port=$1
977 fi
978 adb shell service call window 1 i32 $port
979}
980
981function stopviewserver()
982{
983 adb shell service call window 2
984}
985
986function isviewserverstarted()
987{
988 adb shell service call window 3
989}
990
991function smoketest()
992{
993 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
994 echo "Couldn't locate output files. Try running 'lunch' first." >&2
995 return
996 fi
997 T=$(gettop)
998 if [ ! "$T" ]; then
999 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1000 return
1001 fi
1002
1003 (cd "$T" && mmm tests/SmokeTest) &&
1004 adb uninstall com.android.smoketest > /dev/null &&
1005 adb uninstall com.android.smoketest.tests > /dev/null &&
1006 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1007 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1008 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1009}
1010
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001011# simple shortcut to the runtest command
1012function runtest()
1013{
1014 T=$(gettop)
1015 if [ ! "$T" ]; then
1016 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1017 return
1018 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001019 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001020}
1021
The Android Open Source Project88b60792009-03-03 19:28:42 -08001022function godir () {
1023 if [[ -z "$1" ]]; then
1024 echo "Usage: godir <regex>"
1025 return
1026 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001027 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001028 if [[ ! -f $T/filelist ]]; then
1029 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001030 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001031 echo " Done"
1032 echo ""
1033 fi
1034 local lines
1035 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1036 if [[ ${#lines[@]} = 0 ]]; then
1037 echo "Not found"
1038 return
1039 fi
1040 local pathname
1041 local choice
1042 if [[ ${#lines[@]} > 1 ]]; then
1043 while [[ -z "$pathname" ]]; do
1044 local index=1
1045 local line
1046 for line in ${lines[@]}; do
1047 printf "%6s %s\n" "[$index]" $line
1048 index=$(($index + 1))
1049 done
1050 echo
1051 echo -n "Select one: "
1052 unset choice
1053 read choice
1054 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1055 echo "Invalid choice"
1056 continue
1057 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001058 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001059 done
1060 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001061 pathname=${lines[0]}
1062 fi
1063 cd $T/$pathname
1064}
1065
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001066# Force JAVA_HOME to point to java 1.6 if it isn't already set
1067function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001068 if [ ! "$JAVA_HOME" ]; then
1069 case `uname -s` in
1070 Darwin)
1071 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1072 ;;
1073 *)
1074 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1075 ;;
1076 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001077 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001078}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001079
Raphael Moll70a86b02011-06-20 16:03:14 -07001080if [ "x$SHELL" != "x/bin/bash" ]; then
1081 case `ps -o command -p $$` in
1082 *bash*)
1083 ;;
1084 *)
1085 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1086 ;;
1087 esac
1088fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001089
1090# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001091for 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 -08001092do
1093 echo "including $f"
1094 . $f
1095done
1096unset f