blob: 661155335965e06f65469600ebf49acb1795d8d7 [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
Ed Heylc811f292011-06-07 12:02:51 -0700129 unset ANDROID_HOST_OUT
130 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
131
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800132 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700133 # TODO: fix the path
134 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800135
136 # needed for OProfile to post-process collected samples
137 export OPROFILE_EVENTS_DIR=$prebuiltdir/oprofile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700138}
139
140function printconfig()
141{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800142 T=$(gettop)
143 if [ ! "$T" ]; then
144 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
145 return
146 fi
147 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700148}
149
150function set_stuff_for_environment()
151{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800152 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500153 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800154 setpaths
155 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700156
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800157 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700158}
159
160function set_sequence_number()
161{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700162 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700163}
164
165function settitle()
166{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800167 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700168 local product=$TARGET_PRODUCT
169 local variant=$TARGET_BUILD_VARIANT
170 local apps=$TARGET_BUILD_APPS
171 if [ -z "$apps" ]; then
172 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
173 else
174 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
175 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800176 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700177}
178
179case `uname -s` in
180 Linux)
181 function choosesim()
182 {
183 echo "Build for the simulator or the device?"
184 echo " 1. Device"
185 echo " 2. Simulator"
186 echo
187
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800188 export TARGET_SIMULATOR=
189 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700190 while [ -z $TARGET_SIMULATOR ]
191 do
192 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800193 if [ -z "$1" ] ; then
194 read ANSWER
195 else
196 echo $1
197 ANSWER=$1
198 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700199 case $ANSWER in
200 "")
201 export TARGET_SIMULATOR=false
202 ;;
203 1)
204 export TARGET_SIMULATOR=false
205 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800206 Device)
207 export TARGET_SIMULATOR=false
208 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700209 2)
210 export TARGET_SIMULATOR=true
211 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800212 Simulator)
213 export TARGET_SIMULATOR=true
214 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700215 *)
216 echo
217 echo "I didn't understand your response. Please try again."
218 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700219 ;;
220 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800221 if [ -n "$1" ] ; then
222 break
223 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700224 done
225
226 set_stuff_for_environment
227 }
228 ;;
229 *)
230 function choosesim()
231 {
232 echo "Only device builds are supported for" `uname -s`
233 echo " Forcing TARGET_SIMULATOR=false"
234 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800235 if [ -z "$1" ]
236 then
237 echo -n "Press enter: "
238 read
239 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700240
241 export TARGET_SIMULATOR=false
242 set_stuff_for_environment
243 }
244 ;;
245esac
246
247function choosetype()
248{
249 echo "Build type choices are:"
250 echo " 1. release"
251 echo " 2. debug"
252 echo
253
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800254 local DEFAULT_NUM DEFAULT_VALUE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255 if [ $TARGET_SIMULATOR = "false" ] ; then
256 DEFAULT_NUM=1
257 DEFAULT_VALUE=release
258 else
259 DEFAULT_NUM=2
260 DEFAULT_VALUE=debug
261 fi
262
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800263 export TARGET_BUILD_TYPE=
264 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700265 while [ -z $TARGET_BUILD_TYPE ]
266 do
267 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800268 if [ -z "$1" ] ; then
269 read ANSWER
270 else
271 echo $1
272 ANSWER=$1
273 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700274 case $ANSWER in
275 "")
276 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
277 ;;
278 1)
279 export TARGET_BUILD_TYPE=release
280 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800281 release)
282 export TARGET_BUILD_TYPE=release
283 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700284 2)
285 export TARGET_BUILD_TYPE=debug
286 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800287 debug)
288 export TARGET_BUILD_TYPE=debug
289 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700290 *)
291 echo
292 echo "I didn't understand your response. Please try again."
293 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700294 ;;
295 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800296 if [ -n "$1" ] ; then
297 break
298 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700299 done
300
301 set_stuff_for_environment
302}
303
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800304#
305# This function isn't really right: It chooses a TARGET_PRODUCT
306# based on the list of boards. Usually, that gets you something
307# that kinda works with a generic product, but really, you should
308# pick a product by name.
309#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700310function chooseproduct()
311{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700312 if [ "x$TARGET_PRODUCT" != x ] ; then
313 default_value=$TARGET_PRODUCT
314 else
315 if [ "$TARGET_SIMULATOR" = true ] ; then
316 default_value=sim
317 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700318 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319 fi
320 fi
321
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800322 export TARGET_PRODUCT=
323 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700324 while [ -z "$TARGET_PRODUCT" ]
325 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700326 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800327 if [ -z "$1" ] ; then
328 read ANSWER
329 else
330 echo $1
331 ANSWER=$1
332 fi
333
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700334 if [ -z "$ANSWER" ] ; then
335 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336 else
337 if check_product $ANSWER
338 then
339 export TARGET_PRODUCT=$ANSWER
340 else
341 echo "** Not a valid product: $ANSWER"
342 fi
343 fi
344 if [ -n "$1" ] ; then
345 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346 fi
347 done
348
349 set_stuff_for_environment
350}
351
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800352function choosevariant()
353{
354 echo "Variant choices are:"
355 local index=1
356 local v
357 for v in ${VARIANT_CHOICES[@]}
358 do
359 # The product name is the name of the directory containing
360 # the makefile we found, above.
361 echo " $index. $v"
362 index=$(($index+1))
363 done
364
365 local default_value=eng
366 local ANSWER
367
368 export TARGET_BUILD_VARIANT=
369 while [ -z "$TARGET_BUILD_VARIANT" ]
370 do
371 echo -n "Which would you like? [$default_value] "
372 if [ -z "$1" ] ; then
373 read ANSWER
374 else
375 echo $1
376 ANSWER=$1
377 fi
378
379 if [ -z "$ANSWER" ] ; then
380 export TARGET_BUILD_VARIANT=$default_value
381 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
382 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800383 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800384 fi
385 else
386 if check_variant $ANSWER
387 then
388 export TARGET_BUILD_VARIANT=$ANSWER
389 else
390 echo "** Not a valid variant: $ANSWER"
391 fi
392 fi
393 if [ -n "$1" ] ; then
394 break
395 fi
396 done
397}
398
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700399function choosecombo()
400{
401 choosesim $1
402
403 echo
404 echo
405 choosetype $2
406
407 echo
408 echo
409 chooseproduct $3
410
411 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800412 echo
413 choosevariant $4
414
415 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700416 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800417 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700418}
419
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800420# Clear this variable. It will be built up again when the vendorsetup.sh
421# files are included at the end of this file.
422unset LUNCH_MENU_CHOICES
423function add_lunch_combo()
424{
425 local new_combo=$1
426 local c
427 for c in ${LUNCH_MENU_CHOICES[@]} ; do
428 if [ "$new_combo" = "$c" ] ; then
429 return
430 fi
431 done
432 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
433}
434
435# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700436add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700437add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800438add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800439
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700440function print_lunch_menu()
441{
442 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700443 echo
444 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700445 echo
446 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800447
448 local i=1
449 local choice
450 for choice in ${LUNCH_MENU_CHOICES[@]}
451 do
452 echo " $i. $choice"
453 i=$(($i+1))
454 done
455
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700456 echo
457}
458
459function lunch()
460{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800461 local answer
462
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700463 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800464 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465 else
466 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700467 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800468 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700469 fi
470
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800471 local selection=
472
473 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700475 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476 elif [ "$answer" = "simulator" ]
477 then
478 selection=simulator
479 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
480 then
481 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
482 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800483 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800484 fi
485 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
486 then
487 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700488 fi
489
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490 if [ -z "$selection" ]
491 then
492 echo
493 echo "Invalid lunch combo: $answer"
494 return 1
495 fi
496
Joe Onoratoda12daf2010-06-09 18:18:31 -0700497 export TARGET_BUILD_APPS=
498
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499 # special case the simulator
500 if [ "$selection" = "simulator" ]
501 then
502 export TARGET_PRODUCT=sim
503 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700504 export TARGET_SIMULATOR=true
505 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506 else
507 local product=$(echo -n $selection | sed -e "s/-.*$//")
508 check_product $product
509 if [ $? -ne 0 ]
510 then
511 echo
512 echo "** Don't have a product spec for: '$product'"
513 echo "** Do you have the right repo manifest?"
514 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700515 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800516
517 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
518 check_variant $variant
519 if [ $? -ne 0 ]
520 then
521 echo
522 echo "** Invalid variant: '$variant'"
523 echo "** Must be one of ${VARIANT_CHOICES[@]}"
524 variant=
525 fi
526
527 if [ -z "$product" -o -z "$variant" ]
528 then
529 echo
530 return 1
531 fi
532
533 export TARGET_PRODUCT=$product
534 export TARGET_BUILD_VARIANT=$variant
535 export TARGET_SIMULATOR=false
536 export TARGET_BUILD_TYPE=release
537 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700538
539 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800540
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700541 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800542 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700543}
544
Jeff Davidson513d7a42010-08-02 10:00:44 -0700545# Tab completion for lunch.
546function _lunch()
547{
548 local cur prev opts
549 COMPREPLY=()
550 cur="${COMP_WORDS[COMP_CWORD]}"
551 prev="${COMP_WORDS[COMP_CWORD-1]}"
552
553 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
554 return 0
555}
556complete -F _lunch lunch
557
Joe Onoratoda12daf2010-06-09 18:18:31 -0700558# Configures the build to build unbundled apps.
559# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
560function tapas()
561{
562 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
563 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
564
565 if [ $(echo $variant | wc -w) -gt 1 ]; then
566 echo "tapas: Error: Multiple build variants supplied: $variant"
567 return
568 fi
569 if [ -z "$variant" ]; then
570 variant=eng
571 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700572 if [ -z "$apps" ]; then
573 apps=all
574 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700575
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700576 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700577 export TARGET_BUILD_VARIANT=$variant
578 export TARGET_SIMULATOR=false
579 export TARGET_BUILD_TYPE=release
580 export TARGET_BUILD_APPS=$apps
581
582 set_stuff_for_environment
583 printconfig
584}
585
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700586function gettop
587{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800588 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700589 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
590 echo $TOP
591 else
592 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800593 # The following circumlocution (repeated below as well) ensures
594 # that we record the true directory name and not one that is
595 # faked up with symlink names.
596 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700597 else
598 # We redirect cd to /dev/null in case it's aliased to
599 # a command that prints something as a side-effect
600 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800601 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700602 T=
603 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
604 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800605 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700606 done
607 cd $HERE > /dev/null
608 if [ -f "$T/$TOPFILE" ]; then
609 echo $T
610 fi
611 fi
612 fi
613}
614
615function m()
616{
617 T=$(gettop)
618 if [ "$T" ]; then
619 make -C $T $@
620 else
621 echo "Couldn't locate the top of the tree. Try setting TOP."
622 fi
623}
624
625function findmakefile()
626{
627 TOPFILE=build/core/envsetup.mk
628 # We redirect cd to /dev/null in case it's aliased to
629 # a command that prints something as a side-effect
630 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800631 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700632 T=
633 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
634 T=$PWD
635 if [ -f "$T/Android.mk" ]; then
636 echo $T/Android.mk
637 cd $HERE > /dev/null
638 return
639 fi
640 cd .. > /dev/null
641 done
642 cd $HERE > /dev/null
643}
644
645function mm()
646{
647 # If we're sitting in the root of the build tree, just do a
648 # normal make.
649 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
650 make $@
651 else
652 # Find the closest Android.mk file.
653 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800654 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700655 # Remove the path to top as the makefilepath needs to be relative
656 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657 if [ ! "$T" ]; then
658 echo "Couldn't locate the top of the tree. Try setting TOP."
659 elif [ ! "$M" ]; then
660 echo "Couldn't locate a makefile from the current directory."
661 else
Ying Wang01884142010-07-20 16:18:16 -0700662 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700663 fi
664 fi
665}
666
667function mmm()
668{
669 T=$(gettop)
670 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800671 local MAKEFILE=
672 local ARGS=
673 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800674 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
675 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
676 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700677 DIR=`echo $DIR | sed -e 's:/$::'`
678 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700679 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700680 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800681 START=`PWD= /bin/pwd`
682 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700683 if [ "$MFILE" = "" ] ; then
684 MFILE=$DIR/Android.mk
685 else
686 MFILE=$MFILE/$DIR/Android.mk
687 fi
688 MAKEFILE="$MAKEFILE $MFILE"
689 else
690 if [ "$DIR" = snod ]; then
691 ARGS="$ARGS snod"
692 elif [ "$DIR" = showcommands ]; then
693 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700694 elif [ "$DIR" = dist ]; then
695 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800696 elif [ "$DIR" = incrementaljavac ]; then
697 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700698 else
699 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400700 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700701 fi
702 fi
703 done
Ying Wang01884142010-07-20 16:18:16 -0700704 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700705 else
706 echo "Couldn't locate the top of the tree. Try setting TOP."
707 fi
708}
709
710function croot()
711{
712 T=$(gettop)
713 if [ "$T" ]; then
714 cd $(gettop)
715 else
716 echo "Couldn't locate the top of the tree. Try setting TOP."
717 fi
718}
719
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700720function cproj()
721{
722 TOPFILE=build/core/envsetup.mk
723 # We redirect cd to /dev/null in case it's aliased to
724 # a command that prints something as a side-effect
725 # (like pushd)
726 local HERE=$PWD
727 T=
728 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
729 T=$PWD
730 if [ -f "$T/Android.mk" ]; then
731 cd $T
732 return
733 fi
734 cd .. > /dev/null
735 done
736 cd $HERE > /dev/null
737 echo "can't find Android.mk"
738}
739
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700740function pid()
741{
742 local EXE="$1"
743 if [ "$EXE" ] ; then
744 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
745 echo "$PID"
746 else
747 echo "usage: pid name"
748 fi
749}
750
Christopher Tate744ee802009-11-12 15:33:08 -0800751# systemstack - dump the current stack trace of all threads in the system process
752# to the usual ANR traces file
753function systemstack()
754{
755 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
756}
757
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700758function gdbclient()
759{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800760 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
761 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
762 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
763 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
764 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700765 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
766 local EXE="$1"
767 if [ "$EXE" ] ; then
768 EXE=$1
769 else
770 EXE="app_process"
771 fi
772
773 local PORT="$2"
774 if [ "$PORT" ] ; then
775 PORT=$2
776 else
777 PORT=":5039"
778 fi
779
780 local PID
781 local PROG="$3"
782 if [ "$PROG" ] ; then
783 PID=`pid $3`
784 adb forward "tcp$PORT" "tcp$PORT"
785 adb shell gdbserver $PORT --attach $PID &
786 sleep 2
787 else
788 echo ""
789 echo "If you haven't done so already, do this first on the device:"
790 echo " gdbserver $PORT /system/bin/$EXE"
791 echo " or"
792 echo " gdbserver $PORT --attach $PID"
793 echo ""
794 fi
795
796 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
797 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
798 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
799 echo >>"$OUT_ROOT/gdbclient.cmds" ""
800
Jing Yu9d396e32010-07-29 15:07:31 -0700801 arm-linux-androideabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700802 else
803 echo "Unable to determine build system output dir."
804 fi
805
806}
807
808case `uname -s` in
809 Darwin)
810 function sgrep()
811 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100812 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 -0700813 }
814
815 ;;
816 *)
817 function sgrep()
818 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100819 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 -0700820 }
821 ;;
822esac
823
824function jgrep()
825{
826 find . -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
827}
828
829function cgrep()
830{
Ficus Kirkpatrick8889bdf2010-03-01 16:51:47 -0800831 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 -0700832}
833
834function resgrep()
835{
836 for dir in `find . -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
837}
838
839case `uname -s` in
840 Darwin)
841 function mgrep()
842 {
843 find -E . -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
844 }
845
846 function treegrep()
847 {
848 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
849 }
850
851 ;;
852 *)
853 function mgrep()
854 {
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800855 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 -0700856 }
857
858 function treegrep()
859 {
860 find . -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
861 }
862
863 ;;
864esac
865
866function getprebuilt
867{
868 get_abs_build_var ANDROID_PREBUILTS
869}
870
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700871function tracedmdump()
872{
873 T=$(gettop)
874 if [ ! "$T" ]; then
875 echo "Couldn't locate the top of the tree. Try setting TOP."
876 return
877 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800878 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700879 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700880
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800881 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700882 if [ ! "$TRACE" ] ; then
883 echo "usage: tracedmdump tracename"
884 return
885 fi
886
Jack Veenstra60116fc2009-04-09 18:12:34 -0700887 if [ ! -r "$KERNEL" ] ; then
888 echo "Error: cannot find kernel: '$KERNEL'"
889 return
890 fi
891
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800892 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700893 if [ "$BASETRACE" = "$TRACE" ] ; then
894 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
895 fi
896
897 echo "post-processing traces..."
898 rm -f $TRACE/qtrace.dexlist
899 post_trace $TRACE
900 if [ $? -ne 0 ]; then
901 echo "***"
902 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
903 echo "***"
904 return
905 fi
906 echo "generating dexlist output..."
907 /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
908 echo "generating dmtrace data..."
909 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
910 echo "generating html file..."
911 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
912 echo "done, see $TRACE/dmtrace.html for details"
913 echo "or run:"
914 echo " traceview $TRACE/dmtrace"
915}
916
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800917# communicate with a running device or emulator, set up necessary state,
918# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700919function runhat()
920{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800921 # process standard adb options
922 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700923 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800924 adbTarget=$1
925 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700926 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800927 adbTarget="$1 $2"
928 shift 2
929 fi
930 local adbOptions=${adbTarget}
931 echo adbOptions = ${adbOptions}
932
933 # runhat options
934 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700935
936 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700937 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700938 return
939 fi
940
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800941 # confirm hat is available
942 if [ -z $(which hat) ]; then
943 echo "hat is not available in this configuration."
944 return
945 fi
946
Andy McFaddenb6289852010-07-12 08:00:19 -0700947 # issue "am" command to cause the hprof dump
948 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700949 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700950 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800951 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700952 echo -n "> "
953 read
954
The Android Open Source Project88b60792009-03-03 19:28:42 -0800955 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700956
The Android Open Source Project88b60792009-03-03 19:28:42 -0800957 echo "Retrieving file $devFile..."
958 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700959
The Android Open Source Project88b60792009-03-03 19:28:42 -0800960 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700961
The Android Open Source Project88b60792009-03-03 19:28:42 -0800962 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700963 echo "View the output by pointing your browser at http://localhost:7000/"
964 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800965 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966}
967
968function getbugreports()
969{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800970 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700971
972 if [ ! "$reports" ]; then
973 echo "Could not locate any bugreports."
974 return
975 fi
976
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800977 local report
978 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700979 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800980 echo "/sdcard/bugreports/${report}"
981 adb pull /sdcard/bugreports/${report} ${report}
982 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700983 done
984}
985
986function startviewserver()
987{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800988 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700989 if [ $# -gt 0 ]; then
990 port=$1
991 fi
992 adb shell service call window 1 i32 $port
993}
994
995function stopviewserver()
996{
997 adb shell service call window 2
998}
999
1000function isviewserverstarted()
1001{
1002 adb shell service call window 3
1003}
1004
Romain Guyb84049a2010-10-04 16:56:11 -07001005function key_home()
1006{
1007 adb shell input keyevent 3
1008}
1009
1010function key_back()
1011{
1012 adb shell input keyevent 4
1013}
1014
1015function key_menu()
1016{
1017 adb shell input keyevent 82
1018}
1019
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001020function smoketest()
1021{
1022 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1023 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1024 return
1025 fi
1026 T=$(gettop)
1027 if [ ! "$T" ]; then
1028 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1029 return
1030 fi
1031
1032 (cd "$T" && mmm tests/SmokeTest) &&
1033 adb uninstall com.android.smoketest > /dev/null &&
1034 adb uninstall com.android.smoketest.tests > /dev/null &&
1035 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1036 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1037 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1038}
1039
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001040# simple shortcut to the runtest command
1041function runtest()
1042{
1043 T=$(gettop)
1044 if [ ! "$T" ]; then
1045 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1046 return
1047 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001048 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001049}
1050
The Android Open Source Project88b60792009-03-03 19:28:42 -08001051function godir () {
1052 if [[ -z "$1" ]]; then
1053 echo "Usage: godir <regex>"
1054 return
1055 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001056 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001057 if [[ ! -f $T/filelist ]]; then
1058 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001059 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001060 echo " Done"
1061 echo ""
1062 fi
1063 local lines
1064 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1065 if [[ ${#lines[@]} = 0 ]]; then
1066 echo "Not found"
1067 return
1068 fi
1069 local pathname
1070 local choice
1071 if [[ ${#lines[@]} > 1 ]]; then
1072 while [[ -z "$pathname" ]]; do
1073 local index=1
1074 local line
1075 for line in ${lines[@]}; do
1076 printf "%6s %s\n" "[$index]" $line
1077 index=$(($index + 1))
1078 done
1079 echo
1080 echo -n "Select one: "
1081 unset choice
1082 read choice
1083 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1084 echo "Invalid choice"
1085 continue
1086 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001087 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001088 done
1089 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001090 pathname=${lines[0]}
1091 fi
1092 cd $T/$pathname
1093}
1094
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001095# Force JAVA_HOME to point to java 1.6 if it isn't already set
1096function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001097 if [ ! "$JAVA_HOME" ]; then
1098 case `uname -s` in
1099 Darwin)
1100 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1101 ;;
1102 *)
1103 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1104 ;;
1105 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001106 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001107}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001108
Raphael Moll70a86b02011-06-20 16:03:14 -07001109if [ "x$SHELL" != "x/bin/bash" ]; then
1110 case `ps -o command -p $$` in
1111 *bash*)
1112 ;;
1113 *)
1114 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1115 ;;
1116 esac
1117fi
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