blob: 305866e33fd360817c182e60fd064244f770cf9d [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 \
Jeff Browne33ba4c2011-07-11 22:11:46 -070057 TARGET_PRODUCT=$1 \
58 TARGET_BUILD_VARIANT= \
59 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070060 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080061 get_build_var TARGET_DEVICE > /dev/null
62 # hide successful answers, but allow the errors to show
63}
64
65VARIANT_CHOICES=(user userdebug eng)
66
67# check to see if the supplied variant is valid
68function check_variant()
69{
70 for v in ${VARIANT_CHOICES[@]}
71 do
72 if [ "$v" = "$1" ]
73 then
74 return 0
75 fi
76 done
77 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070078}
79
80function setpaths()
81{
82 T=$(gettop)
83 if [ ! "$T" ]; then
84 echo "Couldn't locate the top of the tree. Try setting TOP."
85 return
86 fi
87
88 ##################################################################
89 # #
90 # Read me before you modify this code #
91 # #
92 # This function sets ANDROID_BUILD_PATHS to what it is adding #
93 # to PATH, and the next time it is run, it removes that from #
94 # PATH. This is required so lunch can be run more than once #
95 # and still have working paths. #
96 # #
97 ##################################################################
98
Raphael Mollc639c782011-06-20 17:25:01 -070099 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
100 # due to "C:\Program Files" being in the path.
101
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700102 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700103 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700104 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
105 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700106 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700107 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
108 # strip trailing ':', if any
109 export PATH=${PATH/%:/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500110 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700111
112 # and in with the new
113 CODE_REVIEWS=
114 prebuiltdir=$(getprebuilt)
Raphael732936d2011-06-22 14:35:32 -0700115
Raphael Mollc639c782011-06-20 17:25:01 -0700116 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Raphael732936d2011-06-22 14:35:32 -0700117 export ANDROID_EABI_TOOLCHAIN=
118 toolchaindir=toolchain/arm-linux-androideabi-4.4.x/bin
Raphael Mollc639c782011-06-20 17:25:01 -0700119 if [ -d "$prebuiltdir/$toolchaindir" ]; then
120 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700121 fi
Raphael732936d2011-06-22 14:35:32 -0700122
123 export ARM_EABI_TOOLCHAIN=
124 toolchaindir=toolchain/arm-eabi-4.4.3/bin
125 if [ -d "$prebuiltdir/$toolchaindir" ]; then
126 export ARM_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
127 fi
128
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700129 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
130 export ANDROID_QTOOLS=$T/development/emulator/qtools
Jing Yu9d396e32010-07-29 15:07:31 -0700131 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 -0700132 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800133
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500134 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900135 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500136 if [ -n "$JAVA_HOME" ]; then
137 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900138 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
139 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500140 fi
141
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800142 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700143 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
144 export OUT=$ANDROID_PRODUCT_OUT
145
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700146 unset ANDROID_HOST_OUT
147 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
148
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800149 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700150 # TODO: fix the path
151 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
152}
153
154function printconfig()
155{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800156 T=$(gettop)
157 if [ ! "$T" ]; then
158 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
159 return
160 fi
161 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700162}
163
164function set_stuff_for_environment()
165{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800166 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500167 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800168 setpaths
169 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700170
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800171 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700172}
173
174function set_sequence_number()
175{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700176 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700177}
178
179function settitle()
180{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800181 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700182 local product=$TARGET_PRODUCT
183 local variant=$TARGET_BUILD_VARIANT
184 local apps=$TARGET_BUILD_APPS
185 if [ -z "$apps" ]; then
186 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
187 else
188 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
189 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800190 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700191}
192
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700193function choosetype()
194{
195 echo "Build type choices are:"
196 echo " 1. release"
197 echo " 2. debug"
198 echo
199
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800200 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700201 DEFAULT_NUM=1
202 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700203
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800204 export TARGET_BUILD_TYPE=
205 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700206 while [ -z $TARGET_BUILD_TYPE ]
207 do
208 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800209 if [ -z "$1" ] ; then
210 read ANSWER
211 else
212 echo $1
213 ANSWER=$1
214 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700215 case $ANSWER in
216 "")
217 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
218 ;;
219 1)
220 export TARGET_BUILD_TYPE=release
221 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800222 release)
223 export TARGET_BUILD_TYPE=release
224 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700225 2)
226 export TARGET_BUILD_TYPE=debug
227 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800228 debug)
229 export TARGET_BUILD_TYPE=debug
230 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700231 *)
232 echo
233 echo "I didn't understand your response. Please try again."
234 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700235 ;;
236 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800237 if [ -n "$1" ] ; then
238 break
239 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700240 done
241
242 set_stuff_for_environment
243}
244
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800245#
246# This function isn't really right: It chooses a TARGET_PRODUCT
247# based on the list of boards. Usually, that gets you something
248# that kinda works with a generic product, but really, you should
249# pick a product by name.
250#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700251function chooseproduct()
252{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700253 if [ "x$TARGET_PRODUCT" != x ] ; then
254 default_value=$TARGET_PRODUCT
255 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700256 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700257 fi
258
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800259 export TARGET_PRODUCT=
260 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700261 while [ -z "$TARGET_PRODUCT" ]
262 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700263 echo -n "Which product would you like? [$default_value] "
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
270
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700271 if [ -z "$ANSWER" ] ; then
272 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800273 else
274 if check_product $ANSWER
275 then
276 export TARGET_PRODUCT=$ANSWER
277 else
278 echo "** Not a valid product: $ANSWER"
279 fi
280 fi
281 if [ -n "$1" ] ; then
282 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700283 fi
284 done
285
286 set_stuff_for_environment
287}
288
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800289function choosevariant()
290{
291 echo "Variant choices are:"
292 local index=1
293 local v
294 for v in ${VARIANT_CHOICES[@]}
295 do
296 # The product name is the name of the directory containing
297 # the makefile we found, above.
298 echo " $index. $v"
299 index=$(($index+1))
300 done
301
302 local default_value=eng
303 local ANSWER
304
305 export TARGET_BUILD_VARIANT=
306 while [ -z "$TARGET_BUILD_VARIANT" ]
307 do
308 echo -n "Which would you like? [$default_value] "
309 if [ -z "$1" ] ; then
310 read ANSWER
311 else
312 echo $1
313 ANSWER=$1
314 fi
315
316 if [ -z "$ANSWER" ] ; then
317 export TARGET_BUILD_VARIANT=$default_value
318 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
319 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800320 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800321 fi
322 else
323 if check_variant $ANSWER
324 then
325 export TARGET_BUILD_VARIANT=$ANSWER
326 else
327 echo "** Not a valid variant: $ANSWER"
328 fi
329 fi
330 if [ -n "$1" ] ; then
331 break
332 fi
333 done
334}
335
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700336function choosecombo()
337{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700338 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339
340 echo
341 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700342 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700343
344 echo
345 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700346 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800347
348 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700349 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800350 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700351}
352
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800353# Clear this variable. It will be built up again when the vendorsetup.sh
354# files are included at the end of this file.
355unset LUNCH_MENU_CHOICES
356function add_lunch_combo()
357{
358 local new_combo=$1
359 local c
360 for c in ${LUNCH_MENU_CHOICES[@]} ; do
361 if [ "$new_combo" = "$c" ] ; then
362 return
363 fi
364 done
365 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
366}
367
368# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700369add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700370add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800371add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800372
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700373function print_lunch_menu()
374{
375 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700376 echo
377 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700378 echo
379 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800380
381 local i=1
382 local choice
383 for choice in ${LUNCH_MENU_CHOICES[@]}
384 do
385 echo " $i. $choice"
386 i=$(($i+1))
387 done
388
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700389 echo
390}
391
392function lunch()
393{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800394 local answer
395
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700396 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800397 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700398 else
399 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700400 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800401 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700402 fi
403
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800404 local selection=
405
406 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700407 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700408 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800409 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
410 then
411 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
412 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800413 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800414 fi
415 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
416 then
417 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700418 fi
419
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800420 if [ -z "$selection" ]
421 then
422 echo
423 echo "Invalid lunch combo: $answer"
424 return 1
425 fi
426
Joe Onoratoda12daf2010-06-09 18:18:31 -0700427 export TARGET_BUILD_APPS=
428
Jeff Browne33ba4c2011-07-11 22:11:46 -0700429 local product=$(echo -n $selection | sed -e "s/-.*$//")
430 check_product $product
431 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800432 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700433 echo
434 echo "** Don't have a product spec for: '$product'"
435 echo "** Do you have the right repo manifest?"
436 product=
437 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800438
Jeff Browne33ba4c2011-07-11 22:11:46 -0700439 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
440 check_variant $variant
441 if [ $? -ne 0 ]
442 then
443 echo
444 echo "** Invalid variant: '$variant'"
445 echo "** Must be one of ${VARIANT_CHOICES[@]}"
446 variant=
447 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800448
Jeff Browne33ba4c2011-07-11 22:11:46 -0700449 if [ -z "$product" -o -z "$variant" ]
450 then
451 echo
452 return 1
453 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800454
Jeff Browne33ba4c2011-07-11 22:11:46 -0700455 export TARGET_PRODUCT=$product
456 export TARGET_BUILD_VARIANT=$variant
457 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458
459 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800460
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800462 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700463}
464
Jeff Davidson513d7a42010-08-02 10:00:44 -0700465# Tab completion for lunch.
466function _lunch()
467{
468 local cur prev opts
469 COMPREPLY=()
470 cur="${COMP_WORDS[COMP_CWORD]}"
471 prev="${COMP_WORDS[COMP_CWORD-1]}"
472
473 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
474 return 0
475}
476complete -F _lunch lunch
477
Joe Onoratoda12daf2010-06-09 18:18:31 -0700478# Configures the build to build unbundled apps.
479# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
480function tapas()
481{
482 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
483 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
484
485 if [ $(echo $variant | wc -w) -gt 1 ]; then
486 echo "tapas: Error: Multiple build variants supplied: $variant"
487 return
488 fi
489 if [ -z "$variant" ]; then
490 variant=eng
491 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700492 if [ -z "$apps" ]; then
493 apps=all
494 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700495
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700496 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700497 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700498 export TARGET_BUILD_TYPE=release
499 export TARGET_BUILD_APPS=$apps
500
501 set_stuff_for_environment
502 printconfig
503}
504
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700505function gettop
506{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
509 echo $TOP
510 else
511 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800512 # The following circumlocution (repeated below as well) ensures
513 # that we record the true directory name and not one that is
514 # faked up with symlink names.
515 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700516 else
517 # We redirect cd to /dev/null in case it's aliased to
518 # a command that prints something as a side-effect
519 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700521 T=
522 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
523 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800524 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700525 done
526 cd $HERE > /dev/null
527 if [ -f "$T/$TOPFILE" ]; then
528 echo $T
529 fi
530 fi
531 fi
532}
533
534function m()
535{
536 T=$(gettop)
537 if [ "$T" ]; then
538 make -C $T $@
539 else
540 echo "Couldn't locate the top of the tree. Try setting TOP."
541 fi
542}
543
544function findmakefile()
545{
546 TOPFILE=build/core/envsetup.mk
547 # We redirect cd to /dev/null in case it's aliased to
548 # a command that prints something as a side-effect
549 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800550 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700551 T=
552 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
553 T=$PWD
554 if [ -f "$T/Android.mk" ]; then
555 echo $T/Android.mk
556 cd $HERE > /dev/null
557 return
558 fi
559 cd .. > /dev/null
560 done
561 cd $HERE > /dev/null
562}
563
564function mm()
565{
566 # If we're sitting in the root of the build tree, just do a
567 # normal make.
568 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
569 make $@
570 else
571 # Find the closest Android.mk file.
572 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800573 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700574 # Remove the path to top as the makefilepath needs to be relative
575 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700576 if [ ! "$T" ]; then
577 echo "Couldn't locate the top of the tree. Try setting TOP."
578 elif [ ! "$M" ]; then
579 echo "Couldn't locate a makefile from the current directory."
580 else
Ying Wang01884142010-07-20 16:18:16 -0700581 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582 fi
583 fi
584}
585
586function mmm()
587{
588 T=$(gettop)
589 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 local MAKEFILE=
591 local ARGS=
592 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800593 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
594 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
595 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596 DIR=`echo $DIR | sed -e 's:/$::'`
597 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700598 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700599 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800600 START=`PWD= /bin/pwd`
601 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700602 if [ "$MFILE" = "" ] ; then
603 MFILE=$DIR/Android.mk
604 else
605 MFILE=$MFILE/$DIR/Android.mk
606 fi
607 MAKEFILE="$MAKEFILE $MFILE"
608 else
609 if [ "$DIR" = snod ]; then
610 ARGS="$ARGS snod"
611 elif [ "$DIR" = showcommands ]; then
612 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700613 elif [ "$DIR" = dist ]; then
614 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800615 elif [ "$DIR" = incrementaljavac ]; then
616 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700617 else
618 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400619 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700620 fi
621 fi
622 done
Ying Wang01884142010-07-20 16:18:16 -0700623 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700624 else
625 echo "Couldn't locate the top of the tree. Try setting TOP."
626 fi
627}
628
629function croot()
630{
631 T=$(gettop)
632 if [ "$T" ]; then
633 cd $(gettop)
634 else
635 echo "Couldn't locate the top of the tree. Try setting TOP."
636 fi
637}
638
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700639function cproj()
640{
641 TOPFILE=build/core/envsetup.mk
642 # We redirect cd to /dev/null in case it's aliased to
643 # a command that prints something as a side-effect
644 # (like pushd)
645 local HERE=$PWD
646 T=
647 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
648 T=$PWD
649 if [ -f "$T/Android.mk" ]; then
650 cd $T
651 return
652 fi
653 cd .. > /dev/null
654 done
655 cd $HERE > /dev/null
656 echo "can't find Android.mk"
657}
658
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659function pid()
660{
661 local EXE="$1"
662 if [ "$EXE" ] ; then
663 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
664 echo "$PID"
665 else
666 echo "usage: pid name"
667 fi
668}
669
Christopher Tate744ee802009-11-12 15:33:08 -0800670# systemstack - dump the current stack trace of all threads in the system process
671# to the usual ANR traces file
672function systemstack()
673{
674 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
675}
676
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700677function gdbclient()
678{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800679 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
680 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
681 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
682 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
683 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700684 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
685 local EXE="$1"
686 if [ "$EXE" ] ; then
687 EXE=$1
688 else
689 EXE="app_process"
690 fi
691
692 local PORT="$2"
693 if [ "$PORT" ] ; then
694 PORT=$2
695 else
696 PORT=":5039"
697 fi
698
699 local PID
700 local PROG="$3"
701 if [ "$PROG" ] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700702 if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
703 PID="$3"
704 else
705 PID=`pid $3`
706 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700707 adb forward "tcp$PORT" "tcp$PORT"
708 adb shell gdbserver $PORT --attach $PID &
709 sleep 2
710 else
711 echo ""
712 echo "If you haven't done so already, do this first on the device:"
713 echo " gdbserver $PORT /system/bin/$EXE"
714 echo " or"
715 echo " gdbserver $PORT --attach $PID"
716 echo ""
717 fi
718
719 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
720 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
721 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
722 echo >>"$OUT_ROOT/gdbclient.cmds" ""
723
Jing Yu9d396e32010-07-29 15:07:31 -0700724 arm-linux-androideabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700725 else
726 echo "Unable to determine build system output dir."
727 fi
728
729}
730
731case `uname -s` in
732 Darwin)
733 function sgrep()
734 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700735 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml|sh|mk)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700736 }
737
738 ;;
739 *)
740 function sgrep()
741 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700742 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cpp\|S\|java\|xml\|sh\|mk\)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700743 }
744 ;;
745esac
746
747function jgrep()
748{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700749 find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700750}
751
752function cgrep()
753{
Mike Dodd0c26d342011-04-07 13:29:06 -0700754 find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700755}
756
757function resgrep()
758{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700759 for dir in `find . -name .repo -prune -o -name .git -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700760}
761
762case `uname -s` in
763 Darwin)
764 function mgrep()
765 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700766 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700767 }
768
769 function treegrep()
770 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700771 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700772 }
773
774 ;;
775 *)
776 function mgrep()
777 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700778 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779 }
780
781 function treegrep()
782 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700783 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784 }
785
786 ;;
787esac
788
789function getprebuilt
790{
791 get_abs_build_var ANDROID_PREBUILTS
792}
793
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700794function tracedmdump()
795{
796 T=$(gettop)
797 if [ ! "$T" ]; then
798 echo "Couldn't locate the top of the tree. Try setting TOP."
799 return
800 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800801 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700802 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700803
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800804 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700805 if [ ! "$TRACE" ] ; then
806 echo "usage: tracedmdump tracename"
807 return
808 fi
809
Jack Veenstra60116fc2009-04-09 18:12:34 -0700810 if [ ! -r "$KERNEL" ] ; then
811 echo "Error: cannot find kernel: '$KERNEL'"
812 return
813 fi
814
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800815 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700816 if [ "$BASETRACE" = "$TRACE" ] ; then
817 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
818 fi
819
820 echo "post-processing traces..."
821 rm -f $TRACE/qtrace.dexlist
822 post_trace $TRACE
823 if [ $? -ne 0 ]; then
824 echo "***"
825 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
826 echo "***"
827 return
828 fi
829 echo "generating dexlist output..."
830 /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
831 echo "generating dmtrace data..."
832 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
833 echo "generating html file..."
834 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
835 echo "done, see $TRACE/dmtrace.html for details"
836 echo "or run:"
837 echo " traceview $TRACE/dmtrace"
838}
839
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800840# communicate with a running device or emulator, set up necessary state,
841# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700842function runhat()
843{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800844 # process standard adb options
845 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700846 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800847 adbTarget=$1
848 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700849 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800850 adbTarget="$1 $2"
851 shift 2
852 fi
853 local adbOptions=${adbTarget}
854 echo adbOptions = ${adbOptions}
855
856 # runhat options
857 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700858
859 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700860 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700861 return
862 fi
863
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800864 # confirm hat is available
865 if [ -z $(which hat) ]; then
866 echo "hat is not available in this configuration."
867 return
868 fi
869
Andy McFaddenb6289852010-07-12 08:00:19 -0700870 # issue "am" command to cause the hprof dump
871 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700872 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700873 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800874 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700875 echo -n "> "
876 read
877
The Android Open Source Project88b60792009-03-03 19:28:42 -0800878 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700879
The Android Open Source Project88b60792009-03-03 19:28:42 -0800880 echo "Retrieving file $devFile..."
881 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700882
The Android Open Source Project88b60792009-03-03 19:28:42 -0800883 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700884
The Android Open Source Project88b60792009-03-03 19:28:42 -0800885 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700886 echo "View the output by pointing your browser at http://localhost:7000/"
887 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800888 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700889}
890
891function getbugreports()
892{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800893 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700894
895 if [ ! "$reports" ]; then
896 echo "Could not locate any bugreports."
897 return
898 fi
899
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800900 local report
901 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700902 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800903 echo "/sdcard/bugreports/${report}"
904 adb pull /sdcard/bugreports/${report} ${report}
905 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700906 done
907}
908
909function startviewserver()
910{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800911 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700912 if [ $# -gt 0 ]; then
913 port=$1
914 fi
915 adb shell service call window 1 i32 $port
916}
917
918function stopviewserver()
919{
920 adb shell service call window 2
921}
922
923function isviewserverstarted()
924{
925 adb shell service call window 3
926}
927
Romain Guyb84049a2010-10-04 16:56:11 -0700928function key_home()
929{
930 adb shell input keyevent 3
931}
932
933function key_back()
934{
935 adb shell input keyevent 4
936}
937
938function key_menu()
939{
940 adb shell input keyevent 82
941}
942
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700943function smoketest()
944{
945 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
946 echo "Couldn't locate output files. Try running 'lunch' first." >&2
947 return
948 fi
949 T=$(gettop)
950 if [ ! "$T" ]; then
951 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
952 return
953 fi
954
955 (cd "$T" && mmm tests/SmokeTest) &&
956 adb uninstall com.android.smoketest > /dev/null &&
957 adb uninstall com.android.smoketest.tests > /dev/null &&
958 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
959 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
960 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
961}
962
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800963# simple shortcut to the runtest command
964function runtest()
965{
966 T=$(gettop)
967 if [ ! "$T" ]; then
968 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
969 return
970 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -0700971 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -0700972}
973
The Android Open Source Project88b60792009-03-03 19:28:42 -0800974function godir () {
975 if [[ -z "$1" ]]; then
976 echo "Usage: godir <regex>"
977 return
978 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -0800979 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800980 if [[ ! -f $T/filelist ]]; then
981 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -0800982 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800983 echo " Done"
984 echo ""
985 fi
986 local lines
Doug Zongker29034982011-04-22 08:16:56 -0700987 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800988 if [[ ${#lines[@]} = 0 ]]; then
989 echo "Not found"
990 return
991 fi
992 local pathname
993 local choice
994 if [[ ${#lines[@]} > 1 ]]; then
995 while [[ -z "$pathname" ]]; do
996 local index=1
997 local line
998 for line in ${lines[@]}; do
999 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001000 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001001 done
1002 echo
1003 echo -n "Select one: "
1004 unset choice
1005 read choice
1006 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1007 echo "Invalid choice"
1008 continue
1009 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001010 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001011 done
1012 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001013 pathname=${lines[0]}
1014 fi
1015 cd $T/$pathname
1016}
1017
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001018# Force JAVA_HOME to point to java 1.6 if it isn't already set
1019function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001020 if [ ! "$JAVA_HOME" ]; then
1021 case `uname -s` in
1022 Darwin)
1023 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1024 ;;
1025 *)
1026 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1027 ;;
1028 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001029 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001030}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001031
Raphael Moll70a86b02011-06-20 16:03:14 -07001032if [ "x$SHELL" != "x/bin/bash" ]; then
1033 case `ps -o command -p $$` in
1034 *bash*)
1035 ;;
1036 *)
1037 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1038 ;;
1039 esac
1040fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001041
1042# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001043for 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 -08001044do
1045 echo "including $f"
1046 . $f
1047done
1048unset f