blob: 322e4881f995dee4885eccb1fc92f9cfc37e465c [file] [log] [blame]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001function help() {
2cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07004- croot: Changes directory to the top of the tree.
5- m: Makes from the top of the tree.
6- mm: Builds all of the modules in the current directory.
7- mmm: Builds all of the modules in the supplied directories.
8- cgrep: Greps on all local C/C++ files.
9- jgrep: Greps on all local Java files.
10- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080011- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070012
13Look at the source to view more functions. The complete list is:
14EOF
15 T=$(gettop)
16 local A
17 A=""
18 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
19 A="$A $i"
20 done
21 echo $A
22}
23
24# Get the value of a build variable as an absolute path.
25function get_abs_build_var()
26{
27 T=$(gettop)
28 if [ ! "$T" ]; then
29 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
30 return
31 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080032 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
33 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070034}
35
36# Get the exact value of a build variable.
37function get_build_var()
38{
39 T=$(gettop)
40 if [ ! "$T" ]; then
41 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
42 return
43 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080044 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
45 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1
46}
47
48# check to see if the supplied product is one we can build
49function check_product()
50{
51 T=$(gettop)
52 if [ ! "$T" ]; then
53 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
54 return
55 fi
56 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
57 TARGET_PRODUCT=$1 TARGET_BUILD_VARIANT= \
58 TARGET_SIMULATOR= TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070059 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080060 get_build_var TARGET_DEVICE > /dev/null
61 # hide successful answers, but allow the errors to show
62}
63
64VARIANT_CHOICES=(user userdebug eng)
65
66# check to see if the supplied variant is valid
67function check_variant()
68{
69 for v in ${VARIANT_CHOICES[@]}
70 do
71 if [ "$v" = "$1" ]
72 then
73 return 0
74 fi
75 done
76 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070077}
78
79function setpaths()
80{
81 T=$(gettop)
82 if [ ! "$T" ]; then
83 echo "Couldn't locate the top of the tree. Try setting TOP."
84 return
85 fi
86
87 ##################################################################
88 # #
89 # Read me before you modify this code #
90 # #
91 # This function sets ANDROID_BUILD_PATHS to what it is adding #
92 # to PATH, and the next time it is run, it removes that from #
93 # PATH. This is required so lunch can be run more than once #
94 # and still have working paths. #
95 # #
96 ##################################################################
97
Raphael Mollc639c782011-06-20 17:25:01 -070098 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
99 # due to "C:\Program Files" being in the path.
100
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700101 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700102 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700103 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
104 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700105 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500106 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
107 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700108
109 # and in with the new
110 CODE_REVIEWS=
111 prebuiltdir=$(getprebuilt)
Raphael Mollc639c782011-06-20 17:25:01 -0700112 toolchaindir=toolchain/arm-eabi-4.4.3/bin
113 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
114 if [ -d "$prebuiltdir/$toolchaindir" ]; then
115 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
116 else
117 export ANDROID_EABI_TOOLCHAIN=
118 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700119 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
120 export ANDROID_QTOOLS=$T/development/emulator/qtools
121 export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_EABI_TOOLCHAIN$CODE_REVIEWS
122 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800123
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500124 unset ANDROID_JAVA_TOOLCHAIN
125 if [ -n "$JAVA_HOME" ]; then
126 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
127 fi
128 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN
129 if [ -n "$ANDROID_PRE_BUILD_PATHS" ]; then
130 export PATH=$ANDROID_PRE_BUILD_PATHS:$PATH
131 fi
132
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800133 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700134 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
135 export OUT=$ANDROID_PRODUCT_OUT
136
Ed Heyl4f2297d2011-06-07 12:02:51 -0700137 unset ANDROID_HOST_OUT
138 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
139
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800140 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700141 # TODO: fix the path
142 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800143
144 # needed for OProfile to post-process collected samples
145 export OPROFILE_EVENTS_DIR=$prebuiltdir/oprofile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700146}
147
148function printconfig()
149{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800150 T=$(gettop)
151 if [ ! "$T" ]; then
152 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
153 return
154 fi
155 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700156}
157
158function set_stuff_for_environment()
159{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800160 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500161 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800162 setpaths
163 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700164
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800165 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700166}
167
168function set_sequence_number()
169{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700170 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700171}
172
173function settitle()
174{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800175 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700176 local product=$TARGET_PRODUCT
177 local variant=$TARGET_BUILD_VARIANT
178 local apps=$TARGET_BUILD_APPS
179 if [ -z "$apps" ]; then
180 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
181 else
182 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
183 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800184 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700185}
186
187case `uname -s` in
188 Linux)
189 function choosesim()
190 {
191 echo "Build for the simulator or the device?"
192 echo " 1. Device"
193 echo " 2. Simulator"
194 echo
195
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800196 export TARGET_SIMULATOR=
197 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700198 while [ -z $TARGET_SIMULATOR ]
199 do
200 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800201 if [ -z "$1" ] ; then
202 read ANSWER
203 else
204 echo $1
205 ANSWER=$1
206 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700207 case $ANSWER in
208 "")
209 export TARGET_SIMULATOR=false
210 ;;
211 1)
212 export TARGET_SIMULATOR=false
213 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800214 Device)
215 export TARGET_SIMULATOR=false
216 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700217 2)
218 export TARGET_SIMULATOR=true
219 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800220 Simulator)
221 export TARGET_SIMULATOR=true
222 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700223 *)
224 echo
225 echo "I didn't understand your response. Please try again."
226 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700227 ;;
228 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800229 if [ -n "$1" ] ; then
230 break
231 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700232 done
233
234 set_stuff_for_environment
235 }
236 ;;
237 *)
238 function choosesim()
239 {
240 echo "Only device builds are supported for" `uname -s`
241 echo " Forcing TARGET_SIMULATOR=false"
242 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800243 if [ -z "$1" ]
244 then
245 echo -n "Press enter: "
246 read
247 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700248
249 export TARGET_SIMULATOR=false
250 set_stuff_for_environment
251 }
252 ;;
253esac
254
255function choosetype()
256{
257 echo "Build type choices are:"
258 echo " 1. release"
259 echo " 2. debug"
260 echo
261
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800262 local DEFAULT_NUM DEFAULT_VALUE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263 if [ $TARGET_SIMULATOR = "false" ] ; then
264 DEFAULT_NUM=1
265 DEFAULT_VALUE=release
266 else
267 DEFAULT_NUM=2
268 DEFAULT_VALUE=debug
269 fi
270
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800271 export TARGET_BUILD_TYPE=
272 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700273 while [ -z $TARGET_BUILD_TYPE ]
274 do
275 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800276 if [ -z "$1" ] ; then
277 read ANSWER
278 else
279 echo $1
280 ANSWER=$1
281 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700282 case $ANSWER in
283 "")
284 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
285 ;;
286 1)
287 export TARGET_BUILD_TYPE=release
288 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800289 release)
290 export TARGET_BUILD_TYPE=release
291 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700292 2)
293 export TARGET_BUILD_TYPE=debug
294 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800295 debug)
296 export TARGET_BUILD_TYPE=debug
297 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700298 *)
299 echo
300 echo "I didn't understand your response. Please try again."
301 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700302 ;;
303 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800304 if [ -n "$1" ] ; then
305 break
306 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700307 done
308
309 set_stuff_for_environment
310}
311
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800312#
313# This function isn't really right: It chooses a TARGET_PRODUCT
314# based on the list of boards. Usually, that gets you something
315# that kinda works with a generic product, but really, you should
316# pick a product by name.
317#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700318function chooseproduct()
319{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700320 if [ "x$TARGET_PRODUCT" != x ] ; then
321 default_value=$TARGET_PRODUCT
322 else
323 if [ "$TARGET_SIMULATOR" = true ] ; then
324 default_value=sim
325 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700326 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700327 fi
328 fi
329
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800330 export TARGET_PRODUCT=
331 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332 while [ -z "$TARGET_PRODUCT" ]
333 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700334 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335 if [ -z "$1" ] ; then
336 read ANSWER
337 else
338 echo $1
339 ANSWER=$1
340 fi
341
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700342 if [ -z "$ANSWER" ] ; then
343 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800344 else
345 if check_product $ANSWER
346 then
347 export TARGET_PRODUCT=$ANSWER
348 else
349 echo "** Not a valid product: $ANSWER"
350 fi
351 fi
352 if [ -n "$1" ] ; then
353 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700354 fi
355 done
356
357 set_stuff_for_environment
358}
359
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800360function choosevariant()
361{
362 echo "Variant choices are:"
363 local index=1
364 local v
365 for v in ${VARIANT_CHOICES[@]}
366 do
367 # The product name is the name of the directory containing
368 # the makefile we found, above.
369 echo " $index. $v"
370 index=$(($index+1))
371 done
372
373 local default_value=eng
374 local ANSWER
375
376 export TARGET_BUILD_VARIANT=
377 while [ -z "$TARGET_BUILD_VARIANT" ]
378 do
379 echo -n "Which would you like? [$default_value] "
380 if [ -z "$1" ] ; then
381 read ANSWER
382 else
383 echo $1
384 ANSWER=$1
385 fi
386
387 if [ -z "$ANSWER" ] ; then
388 export TARGET_BUILD_VARIANT=$default_value
389 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
390 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800391 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800392 fi
393 else
394 if check_variant $ANSWER
395 then
396 export TARGET_BUILD_VARIANT=$ANSWER
397 else
398 echo "** Not a valid variant: $ANSWER"
399 fi
400 fi
401 if [ -n "$1" ] ; then
402 break
403 fi
404 done
405}
406
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700407function choosecombo()
408{
409 choosesim $1
410
411 echo
412 echo
413 choosetype $2
414
415 echo
416 echo
417 chooseproduct $3
418
419 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800420 echo
421 choosevariant $4
422
423 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700424 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800425 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700426}
427
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800428# Clear this variable. It will be built up again when the vendorsetup.sh
429# files are included at the end of this file.
430unset LUNCH_MENU_CHOICES
431function add_lunch_combo()
432{
433 local new_combo=$1
434 local c
435 for c in ${LUNCH_MENU_CHOICES[@]} ; do
436 if [ "$new_combo" = "$c" ] ; then
437 return
438 fi
439 done
440 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
441}
442
443# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700444add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700445add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800446add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800447
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700448function print_lunch_menu()
449{
450 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700451 echo
452 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700453 echo
454 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800455
456 local i=1
457 local choice
458 for choice in ${LUNCH_MENU_CHOICES[@]}
459 do
460 echo " $i. $choice"
461 i=$(($i+1))
462 done
463
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700464 echo
465}
466
467function lunch()
468{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469 local answer
470
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 else
474 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700475 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700477 fi
478
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479 local selection=
480
481 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700482 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700483 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800484 elif [ "$answer" = "simulator" ]
485 then
486 selection=simulator
487 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
488 then
489 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
490 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800491 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492 fi
493 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
494 then
495 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700496 fi
497
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800498 if [ -z "$selection" ]
499 then
500 echo
501 echo "Invalid lunch combo: $answer"
502 return 1
503 fi
504
Joe Onoratoda12daf2010-06-09 18:18:31 -0700505 export TARGET_BUILD_APPS=
506
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507 # special case the simulator
508 if [ "$selection" = "simulator" ]
509 then
510 export TARGET_PRODUCT=sim
511 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700512 export TARGET_SIMULATOR=true
513 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800514 else
515 local product=$(echo -n $selection | sed -e "s/-.*$//")
516 check_product $product
517 if [ $? -ne 0 ]
518 then
519 echo
520 echo "** Don't have a product spec for: '$product'"
521 echo "** Do you have the right repo manifest?"
522 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700523 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800524
525 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
526 check_variant $variant
527 if [ $? -ne 0 ]
528 then
529 echo
530 echo "** Invalid variant: '$variant'"
531 echo "** Must be one of ${VARIANT_CHOICES[@]}"
532 variant=
533 fi
534
535 if [ -z "$product" -o -z "$variant" ]
536 then
537 echo
538 return 1
539 fi
540
541 export TARGET_PRODUCT=$product
542 export TARGET_BUILD_VARIANT=$variant
543 export TARGET_SIMULATOR=false
544 export TARGET_BUILD_TYPE=release
545 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700546
547 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800548
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700549 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800550 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700551}
552
Joe Onoratoda12daf2010-06-09 18:18:31 -0700553# Configures the build to build unbundled apps.
554# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
555function tapas()
556{
557 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
558 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
559
560 if [ $(echo $variant | wc -w) -gt 1 ]; then
561 echo "tapas: Error: Multiple build variants supplied: $variant"
562 return
563 fi
564 if [ -z "$variant" ]; then
565 variant=eng
566 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700567 if [ -z "$apps" ]; then
568 apps=all
569 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700570
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700571 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700572 export TARGET_BUILD_VARIANT=$variant
573 export TARGET_SIMULATOR=false
574 export TARGET_BUILD_TYPE=release
575 export TARGET_BUILD_APPS=$apps
576
577 set_stuff_for_environment
578 printconfig
579}
580
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581function gettop
582{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800583 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700584 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
585 echo $TOP
586 else
587 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800588 # The following circumlocution (repeated below as well) ensures
589 # that we record the true directory name and not one that is
590 # faked up with symlink names.
591 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592 else
593 # We redirect cd to /dev/null in case it's aliased to
594 # a command that prints something as a side-effect
595 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800596 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700597 T=
598 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
599 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800600 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700601 done
602 cd $HERE > /dev/null
603 if [ -f "$T/$TOPFILE" ]; then
604 echo $T
605 fi
606 fi
607 fi
608}
609
610function m()
611{
612 T=$(gettop)
613 if [ "$T" ]; then
614 make -C $T $@
615 else
616 echo "Couldn't locate the top of the tree. Try setting TOP."
617 fi
618}
619
620function findmakefile()
621{
622 TOPFILE=build/core/envsetup.mk
623 # We redirect cd to /dev/null in case it's aliased to
624 # a command that prints something as a side-effect
625 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800626 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700627 T=
628 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
629 T=$PWD
630 if [ -f "$T/Android.mk" ]; then
631 echo $T/Android.mk
632 cd $HERE > /dev/null
633 return
634 fi
635 cd .. > /dev/null
636 done
637 cd $HERE > /dev/null
638}
639
640function mm()
641{
642 # If we're sitting in the root of the build tree, just do a
643 # normal make.
644 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
645 make $@
646 else
647 # Find the closest Android.mk file.
648 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800649 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700650 # Remove the path to top as the makefilepath needs to be relative
651 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700652 if [ ! "$T" ]; then
653 echo "Couldn't locate the top of the tree. Try setting TOP."
654 elif [ ! "$M" ]; then
655 echo "Couldn't locate a makefile from the current directory."
656 else
Ying Wang01884142010-07-20 16:18:16 -0700657 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658 fi
659 fi
660}
661
662function mmm()
663{
664 T=$(gettop)
665 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800666 local MAKEFILE=
667 local ARGS=
668 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800669 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
670 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
671 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672 DIR=`echo $DIR | sed -e 's:/$::'`
673 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700674 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700675 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800676 START=`PWD= /bin/pwd`
677 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700678 if [ "$MFILE" = "" ] ; then
679 MFILE=$DIR/Android.mk
680 else
681 MFILE=$MFILE/$DIR/Android.mk
682 fi
683 MAKEFILE="$MAKEFILE $MFILE"
684 else
685 if [ "$DIR" = snod ]; then
686 ARGS="$ARGS snod"
687 elif [ "$DIR" = showcommands ]; then
688 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700689 elif [ "$DIR" = dist ]; then
690 ARGS="$ARGS dist"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700691 else
692 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400693 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700694 fi
695 fi
696 done
Ying Wang01884142010-07-20 16:18:16 -0700697 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700698 else
699 echo "Couldn't locate the top of the tree. Try setting TOP."
700 fi
701}
702
703function croot()
704{
705 T=$(gettop)
706 if [ "$T" ]; then
707 cd $(gettop)
708 else
709 echo "Couldn't locate the top of the tree. Try setting TOP."
710 fi
711}
712
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700713function cproj()
714{
715 TOPFILE=build/core/envsetup.mk
716 # We redirect cd to /dev/null in case it's aliased to
717 # a command that prints something as a side-effect
718 # (like pushd)
719 local HERE=$PWD
720 T=
721 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
722 T=$PWD
723 if [ -f "$T/Android.mk" ]; then
724 cd $T
725 return
726 fi
727 cd .. > /dev/null
728 done
729 cd $HERE > /dev/null
730 echo "can't find Android.mk"
731}
732
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700733function pid()
734{
735 local EXE="$1"
736 if [ "$EXE" ] ; then
737 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
738 echo "$PID"
739 else
740 echo "usage: pid name"
741 fi
742}
743
Christopher Tate744ee802009-11-12 15:33:08 -0800744# systemstack - dump the current stack trace of all threads in the system process
745# to the usual ANR traces file
746function systemstack()
747{
748 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
749}
750
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700751function gdbclient()
752{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800753 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
754 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
755 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
756 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
757 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700758 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
759 local EXE="$1"
760 if [ "$EXE" ] ; then
761 EXE=$1
762 else
763 EXE="app_process"
764 fi
765
766 local PORT="$2"
767 if [ "$PORT" ] ; then
768 PORT=$2
769 else
770 PORT=":5039"
771 fi
772
773 local PID
774 local PROG="$3"
775 if [ "$PROG" ] ; then
776 PID=`pid $3`
777 adb forward "tcp$PORT" "tcp$PORT"
778 adb shell gdbserver $PORT --attach $PID &
779 sleep 2
780 else
781 echo ""
782 echo "If you haven't done so already, do this first on the device:"
783 echo " gdbserver $PORT /system/bin/$EXE"
784 echo " or"
785 echo " gdbserver $PORT --attach $PID"
786 echo ""
787 fi
788
789 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
790 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
791 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
792 echo >>"$OUT_ROOT/gdbclient.cmds" ""
793
794 arm-eabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
795 else
796 echo "Unable to determine build system output dir."
797 fi
798
799}
800
801case `uname -s` in
802 Darwin)
803 function sgrep()
804 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100805 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 -0700806 }
807
808 ;;
809 *)
810 function sgrep()
811 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100812 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 -0700813 }
814 ;;
815esac
816
817function jgrep()
818{
819 find . -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
820}
821
822function cgrep()
823{
Ficus Kirkpatrick8889bdf2010-03-01 16:51:47 -0800824 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 -0700825}
826
827function resgrep()
828{
829 for dir in `find . -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
830}
831
832case `uname -s` in
833 Darwin)
834 function mgrep()
835 {
836 find -E . -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
837 }
838
839 function treegrep()
840 {
841 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
842 }
843
844 ;;
845 *)
846 function mgrep()
847 {
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800848 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 -0700849 }
850
851 function treegrep()
852 {
853 find . -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
854 }
855
856 ;;
857esac
858
859function getprebuilt
860{
861 get_abs_build_var ANDROID_PREBUILTS
862}
863
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700864function tracedmdump()
865{
866 T=$(gettop)
867 if [ ! "$T" ]; then
868 echo "Couldn't locate the top of the tree. Try setting TOP."
869 return
870 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800871 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700872 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700873
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800874 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700875 if [ ! "$TRACE" ] ; then
876 echo "usage: tracedmdump tracename"
877 return
878 fi
879
Jack Veenstra60116fc2009-04-09 18:12:34 -0700880 if [ ! -r "$KERNEL" ] ; then
881 echo "Error: cannot find kernel: '$KERNEL'"
882 return
883 fi
884
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800885 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700886 if [ "$BASETRACE" = "$TRACE" ] ; then
887 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
888 fi
889
890 echo "post-processing traces..."
891 rm -f $TRACE/qtrace.dexlist
892 post_trace $TRACE
893 if [ $? -ne 0 ]; then
894 echo "***"
895 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
896 echo "***"
897 return
898 fi
899 echo "generating dexlist output..."
900 /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
901 echo "generating dmtrace data..."
902 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
903 echo "generating html file..."
904 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
905 echo "done, see $TRACE/dmtrace.html for details"
906 echo "or run:"
907 echo " traceview $TRACE/dmtrace"
908}
909
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800910# communicate with a running device or emulator, set up necessary state,
911# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700912function runhat()
913{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800914 # process standard adb options
915 local adbTarget=""
Chris Dearmanf0bcf422011-02-16 12:16:09 -0800916 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800917 adbTarget=$1
918 shift 1
Chris Dearmanf0bcf422011-02-16 12:16:09 -0800919 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800920 adbTarget="$1 $2"
921 shift 2
922 fi
923 local adbOptions=${adbTarget}
924 echo adbOptions = ${adbOptions}
925
926 # runhat options
927 local targetPid=$1
928 local outputFile=$2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700929
930 if [ "$targetPid" = "" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800931 echo "Usage: runhat [ -d | -e | -s serial ] target-pid [output-file]"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700932 return
933 fi
934
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800935 # confirm hat is available
936 if [ -z $(which hat) ]; then
937 echo "hat is not available in this configuration."
938 return
939 fi
940
941 adb ${adbOptions} shell >/dev/null mkdir /data/misc
942 adb ${adbOptions} shell chmod 777 /data/misc
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700943
The Android Open Source Project88b60792009-03-03 19:28:42 -0800944 # send a SIGUSR1 to cause the hprof dump
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700945 echo "Poking $targetPid and waiting for data..."
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800946 adb ${adbOptions} shell kill -10 $targetPid
The Android Open Source Project88b60792009-03-03 19:28:42 -0800947 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700948 echo -n "> "
949 read
950
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800951 local availFiles=( $(adb ${adbOptions} shell ls /data/misc | grep '^heap-dump' | sed -e 's/.*heap-dump-/heap-dump-/' | sort -r | tr '[:space:][:cntrl:]' ' ') )
The Android Open Source Project88b60792009-03-03 19:28:42 -0800952 local devFile=/data/misc/${availFiles[0]}
953 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700954
The Android Open Source Project88b60792009-03-03 19:28:42 -0800955 echo "Retrieving file $devFile..."
956 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700957
The Android Open Source Project88b60792009-03-03 19:28:42 -0800958 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700959
The Android Open Source Project88b60792009-03-03 19:28:42 -0800960 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700961 echo "View the output by pointing your browser at http://localhost:7000/"
962 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800963 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700964}
965
966function getbugreports()
967{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800968 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700969
970 if [ ! "$reports" ]; then
971 echo "Could not locate any bugreports."
972 return
973 fi
974
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800975 local report
976 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700977 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800978 echo "/sdcard/bugreports/${report}"
979 adb pull /sdcard/bugreports/${report} ${report}
980 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700981 done
982}
983
984function startviewserver()
985{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800986 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700987 if [ $# -gt 0 ]; then
988 port=$1
989 fi
990 adb shell service call window 1 i32 $port
991}
992
993function stopviewserver()
994{
995 adb shell service call window 2
996}
997
998function isviewserverstarted()
999{
1000 adb shell service call window 3
1001}
1002
1003function smoketest()
1004{
1005 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1006 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1007 return
1008 fi
1009 T=$(gettop)
1010 if [ ! "$T" ]; then
1011 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1012 return
1013 fi
1014
1015 (cd "$T" && mmm tests/SmokeTest) &&
1016 adb uninstall com.android.smoketest > /dev/null &&
1017 adb uninstall com.android.smoketest.tests > /dev/null &&
1018 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1019 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1020 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1021}
1022
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001023# simple shortcut to the runtest command
1024function runtest()
1025{
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
Brett Chabot3fb149d2009-10-21 20:05:26 -07001031 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001032}
1033
The Android Open Source Project88b60792009-03-03 19:28:42 -08001034function godir () {
1035 if [[ -z "$1" ]]; then
1036 echo "Usage: godir <regex>"
1037 return
1038 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001039 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001040 if [[ ! -f $T/filelist ]]; then
1041 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001042 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001043 echo " Done"
1044 echo ""
1045 fi
1046 local lines
1047 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1048 if [[ ${#lines[@]} = 0 ]]; then
1049 echo "Not found"
1050 return
1051 fi
1052 local pathname
1053 local choice
1054 if [[ ${#lines[@]} > 1 ]]; then
1055 while [[ -z "$pathname" ]]; do
1056 local index=1
1057 local line
1058 for line in ${lines[@]}; do
1059 printf "%6s %s\n" "[$index]" $line
1060 index=$(($index + 1))
1061 done
1062 echo
1063 echo -n "Select one: "
1064 unset choice
1065 read choice
1066 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1067 echo "Invalid choice"
1068 continue
1069 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001070 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001071 done
1072 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001073 pathname=${lines[0]}
1074 fi
1075 cd $T/$pathname
1076}
1077
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001078# Force JAVA_HOME to point to java 1.6 if it isn't already set
1079function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001080 if [ ! "$JAVA_HOME" ]; then
1081 case `uname -s` in
1082 Darwin)
1083 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1084 ;;
1085 *)
1086 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1087 ;;
1088 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001089 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001090}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001091
Raphael Moll70a86b02011-06-20 16:03:14 -07001092if [ "x$SHELL" != "x/bin/bash" ]; then
1093 case `ps -o command -p $$` in
1094 *bash*)
1095 ;;
1096 *)
1097 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1098 ;;
1099 esac
1100fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001101
1102# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001103for 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 -08001104do
1105 echo "including $f"
1106 . $f
1107done
1108unset f