blob: 2faeed122db6ab963280370655b831a07a6e04e8 [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
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 Yu9d396e32010-07-29 15:07:31 -0700109 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/toolchain/arm-linux-androideabi-4.4.x/bin
110 export ARM_EABI_TOOLCHAIN=$prebuiltdir/toolchain/arm-eabi-4.4.3/bin
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700111 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
112 export ANDROID_QTOOLS=$T/development/emulator/qtools
Jing Yu9d396e32010-07-29 15:07:31 -0700113 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 -0700114 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800115
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500116 unset ANDROID_JAVA_TOOLCHAIN
117 if [ -n "$JAVA_HOME" ]; then
118 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
119 fi
120 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN
121 if [ -n "$ANDROID_PRE_BUILD_PATHS" ]; then
122 export PATH=$ANDROID_PRE_BUILD_PATHS:$PATH
123 fi
124
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800125 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700126 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
127 export OUT=$ANDROID_PRODUCT_OUT
128
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800129 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700130 # TODO: fix the path
131 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800132
133 # needed for OProfile to post-process collected samples
134 export OPROFILE_EVENTS_DIR=$prebuiltdir/oprofile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700135}
136
137function printconfig()
138{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800139 T=$(gettop)
140 if [ ! "$T" ]; then
141 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
142 return
143 fi
144 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700145}
146
147function set_stuff_for_environment()
148{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800149 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500150 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800151 setpaths
152 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700153
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800154 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700155}
156
157function set_sequence_number()
158{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700159 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700160}
161
162function settitle()
163{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800164 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700165 local product=$TARGET_PRODUCT
166 local variant=$TARGET_BUILD_VARIANT
167 local apps=$TARGET_BUILD_APPS
168 if [ -z "$apps" ]; then
169 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
170 else
171 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
172 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800173 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700174}
175
176case `uname -s` in
177 Linux)
178 function choosesim()
179 {
180 echo "Build for the simulator or the device?"
181 echo " 1. Device"
182 echo " 2. Simulator"
183 echo
184
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800185 export TARGET_SIMULATOR=
186 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700187 while [ -z $TARGET_SIMULATOR ]
188 do
189 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800190 if [ -z "$1" ] ; then
191 read ANSWER
192 else
193 echo $1
194 ANSWER=$1
195 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700196 case $ANSWER in
197 "")
198 export TARGET_SIMULATOR=false
199 ;;
200 1)
201 export TARGET_SIMULATOR=false
202 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800203 Device)
204 export TARGET_SIMULATOR=false
205 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700206 2)
207 export TARGET_SIMULATOR=true
208 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800209 Simulator)
210 export TARGET_SIMULATOR=true
211 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700212 *)
213 echo
214 echo "I didn't understand your response. Please try again."
215 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700216 ;;
217 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800218 if [ -n "$1" ] ; then
219 break
220 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700221 done
222
223 set_stuff_for_environment
224 }
225 ;;
226 *)
227 function choosesim()
228 {
229 echo "Only device builds are supported for" `uname -s`
230 echo " Forcing TARGET_SIMULATOR=false"
231 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800232 if [ -z "$1" ]
233 then
234 echo -n "Press enter: "
235 read
236 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700237
238 export TARGET_SIMULATOR=false
239 set_stuff_for_environment
240 }
241 ;;
242esac
243
244function choosetype()
245{
246 echo "Build type choices are:"
247 echo " 1. release"
248 echo " 2. debug"
249 echo
250
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 local DEFAULT_NUM DEFAULT_VALUE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700252 if [ $TARGET_SIMULATOR = "false" ] ; then
253 DEFAULT_NUM=1
254 DEFAULT_VALUE=release
255 else
256 DEFAULT_NUM=2
257 DEFAULT_VALUE=debug
258 fi
259
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800260 export TARGET_BUILD_TYPE=
261 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700262 while [ -z $TARGET_BUILD_TYPE ]
263 do
264 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800265 if [ -z "$1" ] ; then
266 read ANSWER
267 else
268 echo $1
269 ANSWER=$1
270 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700271 case $ANSWER in
272 "")
273 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
274 ;;
275 1)
276 export TARGET_BUILD_TYPE=release
277 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800278 release)
279 export TARGET_BUILD_TYPE=release
280 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700281 2)
282 export TARGET_BUILD_TYPE=debug
283 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800284 debug)
285 export TARGET_BUILD_TYPE=debug
286 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700287 *)
288 echo
289 echo "I didn't understand your response. Please try again."
290 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700291 ;;
292 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800293 if [ -n "$1" ] ; then
294 break
295 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700296 done
297
298 set_stuff_for_environment
299}
300
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800301#
302# This function isn't really right: It chooses a TARGET_PRODUCT
303# based on the list of boards. Usually, that gets you something
304# that kinda works with a generic product, but really, you should
305# pick a product by name.
306#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700307function chooseproduct()
308{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309 if [ "x$TARGET_PRODUCT" != x ] ; then
310 default_value=$TARGET_PRODUCT
311 else
312 if [ "$TARGET_SIMULATOR" = true ] ; then
313 default_value=sim
314 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700315 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700316 fi
317 fi
318
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800319 export TARGET_PRODUCT=
320 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321 while [ -z "$TARGET_PRODUCT" ]
322 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700323 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800324 if [ -z "$1" ] ; then
325 read ANSWER
326 else
327 echo $1
328 ANSWER=$1
329 fi
330
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700331 if [ -z "$ANSWER" ] ; then
332 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800333 else
334 if check_product $ANSWER
335 then
336 export TARGET_PRODUCT=$ANSWER
337 else
338 echo "** Not a valid product: $ANSWER"
339 fi
340 fi
341 if [ -n "$1" ] ; then
342 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700343 fi
344 done
345
346 set_stuff_for_environment
347}
348
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800349function choosevariant()
350{
351 echo "Variant choices are:"
352 local index=1
353 local v
354 for v in ${VARIANT_CHOICES[@]}
355 do
356 # The product name is the name of the directory containing
357 # the makefile we found, above.
358 echo " $index. $v"
359 index=$(($index+1))
360 done
361
362 local default_value=eng
363 local ANSWER
364
365 export TARGET_BUILD_VARIANT=
366 while [ -z "$TARGET_BUILD_VARIANT" ]
367 do
368 echo -n "Which would you like? [$default_value] "
369 if [ -z "$1" ] ; then
370 read ANSWER
371 else
372 echo $1
373 ANSWER=$1
374 fi
375
376 if [ -z "$ANSWER" ] ; then
377 export TARGET_BUILD_VARIANT=$default_value
378 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
379 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800380 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800381 fi
382 else
383 if check_variant $ANSWER
384 then
385 export TARGET_BUILD_VARIANT=$ANSWER
386 else
387 echo "** Not a valid variant: $ANSWER"
388 fi
389 fi
390 if [ -n "$1" ] ; then
391 break
392 fi
393 done
394}
395
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700396function choosecombo()
397{
398 choosesim $1
399
400 echo
401 echo
402 choosetype $2
403
404 echo
405 echo
406 chooseproduct $3
407
408 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800409 echo
410 choosevariant $4
411
412 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700413 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800414 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700415}
416
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800417# Clear this variable. It will be built up again when the vendorsetup.sh
418# files are included at the end of this file.
419unset LUNCH_MENU_CHOICES
420function add_lunch_combo()
421{
422 local new_combo=$1
423 local c
424 for c in ${LUNCH_MENU_CHOICES[@]} ; do
425 if [ "$new_combo" = "$c" ] ; then
426 return
427 fi
428 done
429 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
430}
431
432# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700433add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700434add_lunch_combo full_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800435
436# if we're on linux, add the simulator. There is a special case
437# in lunch to deal with the simulator
438if [ "$(uname)" = "Linux" ] ; then
439 add_lunch_combo simulator
440fi
441
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700442function print_lunch_menu()
443{
444 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700445 echo
446 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700447 echo
448 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800449
450 local i=1
451 local choice
452 for choice in ${LUNCH_MENU_CHOICES[@]}
453 do
454 echo " $i. $choice"
455 i=$(($i+1))
456 done
457
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458 echo
459}
460
461function lunch()
462{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800463 local answer
464
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800466 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700467 else
468 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700469 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800470 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471 fi
472
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800473 local selection=
474
475 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700476 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700477 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800478 elif [ "$answer" = "simulator" ]
479 then
480 selection=simulator
481 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
482 then
483 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
484 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800485 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486 fi
487 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
488 then
489 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700490 fi
491
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492 if [ -z "$selection" ]
493 then
494 echo
495 echo "Invalid lunch combo: $answer"
496 return 1
497 fi
498
Joe Onoratoda12daf2010-06-09 18:18:31 -0700499 export TARGET_BUILD_APPS=
500
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800501 # special case the simulator
502 if [ "$selection" = "simulator" ]
503 then
504 export TARGET_PRODUCT=sim
505 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506 export TARGET_SIMULATOR=true
507 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800508 else
509 local product=$(echo -n $selection | sed -e "s/-.*$//")
510 check_product $product
511 if [ $? -ne 0 ]
512 then
513 echo
514 echo "** Don't have a product spec for: '$product'"
515 echo "** Do you have the right repo manifest?"
516 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700517 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800518
519 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
520 check_variant $variant
521 if [ $? -ne 0 ]
522 then
523 echo
524 echo "** Invalid variant: '$variant'"
525 echo "** Must be one of ${VARIANT_CHOICES[@]}"
526 variant=
527 fi
528
529 if [ -z "$product" -o -z "$variant" ]
530 then
531 echo
532 return 1
533 fi
534
535 export TARGET_PRODUCT=$product
536 export TARGET_BUILD_VARIANT=$variant
537 export TARGET_SIMULATOR=false
538 export TARGET_BUILD_TYPE=release
539 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700540
541 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800542
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700543 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800544 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700545}
546
Jeff Davidson513d7a42010-08-02 10:00:44 -0700547# Tab completion for lunch.
548function _lunch()
549{
550 local cur prev opts
551 COMPREPLY=()
552 cur="${COMP_WORDS[COMP_CWORD]}"
553 prev="${COMP_WORDS[COMP_CWORD-1]}"
554
555 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
556 return 0
557}
558complete -F _lunch lunch
559
Joe Onoratoda12daf2010-06-09 18:18:31 -0700560# Configures the build to build unbundled apps.
561# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
562function tapas()
563{
564 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
565 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
566
567 if [ $(echo $variant | wc -w) -gt 1 ]; then
568 echo "tapas: Error: Multiple build variants supplied: $variant"
569 return
570 fi
571 if [ -z "$variant" ]; then
572 variant=eng
573 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700574 if [ -z "$apps" ]; then
575 apps=all
576 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700577
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700578 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700579 export TARGET_BUILD_VARIANT=$variant
580 export TARGET_SIMULATOR=false
581 export TARGET_BUILD_TYPE=release
582 export TARGET_BUILD_APPS=$apps
583
584 set_stuff_for_environment
585 printconfig
586}
587
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700588function gettop
589{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
592 echo $TOP
593 else
594 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800595 # The following circumlocution (repeated below as well) ensures
596 # that we record the true directory name and not one that is
597 # faked up with symlink names.
598 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700599 else
600 # We redirect cd to /dev/null in case it's aliased to
601 # a command that prints something as a side-effect
602 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 T=
605 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
606 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800607 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700608 done
609 cd $HERE > /dev/null
610 if [ -f "$T/$TOPFILE" ]; then
611 echo $T
612 fi
613 fi
614 fi
615}
616
617function m()
618{
619 T=$(gettop)
620 if [ "$T" ]; then
621 make -C $T $@
622 else
623 echo "Couldn't locate the top of the tree. Try setting TOP."
624 fi
625}
626
627function findmakefile()
628{
629 TOPFILE=build/core/envsetup.mk
630 # We redirect cd to /dev/null in case it's aliased to
631 # a command that prints something as a side-effect
632 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800633 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700634 T=
635 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
636 T=$PWD
637 if [ -f "$T/Android.mk" ]; then
638 echo $T/Android.mk
639 cd $HERE > /dev/null
640 return
641 fi
642 cd .. > /dev/null
643 done
644 cd $HERE > /dev/null
645}
646
647function mm()
648{
649 # If we're sitting in the root of the build tree, just do a
650 # normal make.
651 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
652 make $@
653 else
654 # Find the closest Android.mk file.
655 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800656 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700657 # Remove the path to top as the makefilepath needs to be relative
658 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659 if [ ! "$T" ]; then
660 echo "Couldn't locate the top of the tree. Try setting TOP."
661 elif [ ! "$M" ]; then
662 echo "Couldn't locate a makefile from the current directory."
663 else
Ying Wang01884142010-07-20 16:18:16 -0700664 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700665 fi
666 fi
667}
668
669function mmm()
670{
671 T=$(gettop)
672 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800673 local MAKEFILE=
674 local ARGS=
675 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800676 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
677 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
678 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700679 DIR=`echo $DIR | sed -e 's:/$::'`
680 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700681 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700682 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800683 START=`PWD= /bin/pwd`
684 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700685 if [ "$MFILE" = "" ] ; then
686 MFILE=$DIR/Android.mk
687 else
688 MFILE=$MFILE/$DIR/Android.mk
689 fi
690 MAKEFILE="$MAKEFILE $MFILE"
691 else
692 if [ "$DIR" = snod ]; then
693 ARGS="$ARGS snod"
694 elif [ "$DIR" = showcommands ]; then
695 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700696 elif [ "$DIR" = dist ]; then
697 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800698 elif [ "$DIR" = incrementaljavac ]; then
699 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700700 else
701 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400702 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700703 fi
704 fi
705 done
Ying Wang01884142010-07-20 16:18:16 -0700706 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700707 else
708 echo "Couldn't locate the top of the tree. Try setting TOP."
709 fi
710}
711
712function croot()
713{
714 T=$(gettop)
715 if [ "$T" ]; then
716 cd $(gettop)
717 else
718 echo "Couldn't locate the top of the tree. Try setting TOP."
719 fi
720}
721
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700722function cproj()
723{
724 TOPFILE=build/core/envsetup.mk
725 # We redirect cd to /dev/null in case it's aliased to
726 # a command that prints something as a side-effect
727 # (like pushd)
728 local HERE=$PWD
729 T=
730 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
731 T=$PWD
732 if [ -f "$T/Android.mk" ]; then
733 cd $T
734 return
735 fi
736 cd .. > /dev/null
737 done
738 cd $HERE > /dev/null
739 echo "can't find Android.mk"
740}
741
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700742function pid()
743{
744 local EXE="$1"
745 if [ "$EXE" ] ; then
746 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
747 echo "$PID"
748 else
749 echo "usage: pid name"
750 fi
751}
752
Christopher Tate744ee802009-11-12 15:33:08 -0800753# systemstack - dump the current stack trace of all threads in the system process
754# to the usual ANR traces file
755function systemstack()
756{
757 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
758}
759
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700760function gdbclient()
761{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800762 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
763 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
764 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
765 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
766 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700767 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
768 local EXE="$1"
769 if [ "$EXE" ] ; then
770 EXE=$1
771 else
772 EXE="app_process"
773 fi
774
775 local PORT="$2"
776 if [ "$PORT" ] ; then
777 PORT=$2
778 else
779 PORT=":5039"
780 fi
781
782 local PID
783 local PROG="$3"
784 if [ "$PROG" ] ; then
785 PID=`pid $3`
786 adb forward "tcp$PORT" "tcp$PORT"
787 adb shell gdbserver $PORT --attach $PID &
788 sleep 2
789 else
790 echo ""
791 echo "If you haven't done so already, do this first on the device:"
792 echo " gdbserver $PORT /system/bin/$EXE"
793 echo " or"
794 echo " gdbserver $PORT --attach $PID"
795 echo ""
796 fi
797
798 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
799 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
800 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
801 echo >>"$OUT_ROOT/gdbclient.cmds" ""
802
Jing Yu9d396e32010-07-29 15:07:31 -0700803 arm-linux-androideabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700804 else
805 echo "Unable to determine build system output dir."
806 fi
807
808}
809
810case `uname -s` in
811 Darwin)
812 function sgrep()
813 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100814 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 -0700815 }
816
817 ;;
818 *)
819 function sgrep()
820 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100821 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 -0700822 }
823 ;;
824esac
825
826function jgrep()
827{
828 find . -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
829}
830
831function cgrep()
832{
Ficus Kirkpatrick8889bdf2010-03-01 16:51:47 -0800833 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 -0700834}
835
836function resgrep()
837{
838 for dir in `find . -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
839}
840
841case `uname -s` in
842 Darwin)
843 function mgrep()
844 {
845 find -E . -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
846 }
847
848 function treegrep()
849 {
850 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
851 }
852
853 ;;
854 *)
855 function mgrep()
856 {
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800857 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 -0700858 }
859
860 function treegrep()
861 {
862 find . -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
863 }
864
865 ;;
866esac
867
868function getprebuilt
869{
870 get_abs_build_var ANDROID_PREBUILTS
871}
872
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700873function tracedmdump()
874{
875 T=$(gettop)
876 if [ ! "$T" ]; then
877 echo "Couldn't locate the top of the tree. Try setting TOP."
878 return
879 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800880 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700881 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700882
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800883 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700884 if [ ! "$TRACE" ] ; then
885 echo "usage: tracedmdump tracename"
886 return
887 fi
888
Jack Veenstra60116fc2009-04-09 18:12:34 -0700889 if [ ! -r "$KERNEL" ] ; then
890 echo "Error: cannot find kernel: '$KERNEL'"
891 return
892 fi
893
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800894 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700895 if [ "$BASETRACE" = "$TRACE" ] ; then
896 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
897 fi
898
899 echo "post-processing traces..."
900 rm -f $TRACE/qtrace.dexlist
901 post_trace $TRACE
902 if [ $? -ne 0 ]; then
903 echo "***"
904 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
905 echo "***"
906 return
907 fi
908 echo "generating dexlist output..."
909 /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
910 echo "generating dmtrace data..."
911 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
912 echo "generating html file..."
913 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
914 echo "done, see $TRACE/dmtrace.html for details"
915 echo "or run:"
916 echo " traceview $TRACE/dmtrace"
917}
918
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800919# communicate with a running device or emulator, set up necessary state,
920# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700921function runhat()
922{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800923 # process standard adb options
924 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700925 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800926 adbTarget=$1
927 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700928 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800929 adbTarget="$1 $2"
930 shift 2
931 fi
932 local adbOptions=${adbTarget}
933 echo adbOptions = ${adbOptions}
934
935 # runhat options
936 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700937
938 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700939 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700940 return
941 fi
942
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800943 # confirm hat is available
944 if [ -z $(which hat) ]; then
945 echo "hat is not available in this configuration."
946 return
947 fi
948
Andy McFaddenb6289852010-07-12 08:00:19 -0700949 # issue "am" command to cause the hprof dump
950 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700951 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700952 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800953 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700954 echo -n "> "
955 read
956
The Android Open Source Project88b60792009-03-03 19:28:42 -0800957 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700958
The Android Open Source Project88b60792009-03-03 19:28:42 -0800959 echo "Retrieving file $devFile..."
960 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700961
The Android Open Source Project88b60792009-03-03 19:28:42 -0800962 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700963
The Android Open Source Project88b60792009-03-03 19:28:42 -0800964 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700965 echo "View the output by pointing your browser at http://localhost:7000/"
966 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800967 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700968}
969
970function getbugreports()
971{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800972 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700973
974 if [ ! "$reports" ]; then
975 echo "Could not locate any bugreports."
976 return
977 fi
978
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800979 local report
980 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700981 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800982 echo "/sdcard/bugreports/${report}"
983 adb pull /sdcard/bugreports/${report} ${report}
984 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700985 done
986}
987
988function startviewserver()
989{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800990 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700991 if [ $# -gt 0 ]; then
992 port=$1
993 fi
994 adb shell service call window 1 i32 $port
995}
996
997function stopviewserver()
998{
999 adb shell service call window 2
1000}
1001
1002function isviewserverstarted()
1003{
1004 adb shell service call window 3
1005}
1006
Romain Guyb84049a2010-10-04 16:56:11 -07001007function key_home()
1008{
1009 adb shell input keyevent 3
1010}
1011
1012function key_back()
1013{
1014 adb shell input keyevent 4
1015}
1016
1017function key_menu()
1018{
1019 adb shell input keyevent 82
1020}
1021
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001022function smoketest()
1023{
1024 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1025 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1026 return
1027 fi
1028 T=$(gettop)
1029 if [ ! "$T" ]; then
1030 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1031 return
1032 fi
1033
1034 (cd "$T" && mmm tests/SmokeTest) &&
1035 adb uninstall com.android.smoketest > /dev/null &&
1036 adb uninstall com.android.smoketest.tests > /dev/null &&
1037 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1038 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1039 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1040}
1041
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001042# simple shortcut to the runtest command
1043function runtest()
1044{
1045 T=$(gettop)
1046 if [ ! "$T" ]; then
1047 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1048 return
1049 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001050 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001051}
1052
The Android Open Source Project88b60792009-03-03 19:28:42 -08001053function godir () {
1054 if [[ -z "$1" ]]; then
1055 echo "Usage: godir <regex>"
1056 return
1057 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001058 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001059 if [[ ! -f $T/filelist ]]; then
1060 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001061 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001062 echo " Done"
1063 echo ""
1064 fi
1065 local lines
1066 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1067 if [[ ${#lines[@]} = 0 ]]; then
1068 echo "Not found"
1069 return
1070 fi
1071 local pathname
1072 local choice
1073 if [[ ${#lines[@]} > 1 ]]; then
1074 while [[ -z "$pathname" ]]; do
1075 local index=1
1076 local line
1077 for line in ${lines[@]}; do
1078 printf "%6s %s\n" "[$index]" $line
1079 index=$(($index + 1))
1080 done
1081 echo
1082 echo -n "Select one: "
1083 unset choice
1084 read choice
1085 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1086 echo "Invalid choice"
1087 continue
1088 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001089 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001090 done
1091 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001092 pathname=${lines[0]}
1093 fi
1094 cd $T/$pathname
1095}
1096
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001097# Force JAVA_HOME to point to java 1.6 if it isn't already set
1098function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001099 if [ ! "$JAVA_HOME" ]; then
1100 case `uname -s` in
1101 Darwin)
1102 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1103 ;;
1104 *)
1105 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1106 ;;
1107 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001108 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001109}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001110
Kan-Ru Chen07453762010-07-05 15:53:47 +08001111case `ps -o command -p $$` in
1112 *bash*)
1113 ;;
1114 *)
1115 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1116 ;;
1117esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001118
1119# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001120for 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 -08001121do
1122 echo "including $f"
1123 . $f
1124done
1125unset f