blob: 8f9479af5ffd51df84acbca8b07c627f25828061 [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
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800137 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700138 # TODO: fix the path
139 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800140
141 # needed for OProfile to post-process collected samples
142 export OPROFILE_EVENTS_DIR=$prebuiltdir/oprofile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700143}
144
145function printconfig()
146{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800147 T=$(gettop)
148 if [ ! "$T" ]; then
149 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
150 return
151 fi
152 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700153}
154
155function set_stuff_for_environment()
156{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800157 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500158 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800159 setpaths
160 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700161
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800162 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700163}
164
165function set_sequence_number()
166{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700167 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700168}
169
170function settitle()
171{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800172 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700173 local product=$TARGET_PRODUCT
174 local variant=$TARGET_BUILD_VARIANT
175 local apps=$TARGET_BUILD_APPS
176 if [ -z "$apps" ]; then
177 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
178 else
179 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
180 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800181 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700182}
183
184case `uname -s` in
185 Linux)
186 function choosesim()
187 {
188 echo "Build for the simulator or the device?"
189 echo " 1. Device"
190 echo " 2. Simulator"
191 echo
192
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800193 export TARGET_SIMULATOR=
194 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700195 while [ -z $TARGET_SIMULATOR ]
196 do
197 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800198 if [ -z "$1" ] ; then
199 read ANSWER
200 else
201 echo $1
202 ANSWER=$1
203 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700204 case $ANSWER in
205 "")
206 export TARGET_SIMULATOR=false
207 ;;
208 1)
209 export TARGET_SIMULATOR=false
210 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800211 Device)
212 export TARGET_SIMULATOR=false
213 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700214 2)
215 export TARGET_SIMULATOR=true
216 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800217 Simulator)
218 export TARGET_SIMULATOR=true
219 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700220 *)
221 echo
222 echo "I didn't understand your response. Please try again."
223 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700224 ;;
225 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800226 if [ -n "$1" ] ; then
227 break
228 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700229 done
230
231 set_stuff_for_environment
232 }
233 ;;
234 *)
235 function choosesim()
236 {
237 echo "Only device builds are supported for" `uname -s`
238 echo " Forcing TARGET_SIMULATOR=false"
239 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800240 if [ -z "$1" ]
241 then
242 echo -n "Press enter: "
243 read
244 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700245
246 export TARGET_SIMULATOR=false
247 set_stuff_for_environment
248 }
249 ;;
250esac
251
252function choosetype()
253{
254 echo "Build type choices are:"
255 echo " 1. release"
256 echo " 2. debug"
257 echo
258
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800259 local DEFAULT_NUM DEFAULT_VALUE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700260 if [ $TARGET_SIMULATOR = "false" ] ; then
261 DEFAULT_NUM=1
262 DEFAULT_VALUE=release
263 else
264 DEFAULT_NUM=2
265 DEFAULT_VALUE=debug
266 fi
267
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800268 export TARGET_BUILD_TYPE=
269 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700270 while [ -z $TARGET_BUILD_TYPE ]
271 do
272 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800273 if [ -z "$1" ] ; then
274 read ANSWER
275 else
276 echo $1
277 ANSWER=$1
278 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700279 case $ANSWER in
280 "")
281 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
282 ;;
283 1)
284 export TARGET_BUILD_TYPE=release
285 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800286 release)
287 export TARGET_BUILD_TYPE=release
288 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700289 2)
290 export TARGET_BUILD_TYPE=debug
291 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800292 debug)
293 export TARGET_BUILD_TYPE=debug
294 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700295 *)
296 echo
297 echo "I didn't understand your response. Please try again."
298 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700299 ;;
300 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800301 if [ -n "$1" ] ; then
302 break
303 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700304 done
305
306 set_stuff_for_environment
307}
308
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800309#
310# This function isn't really right: It chooses a TARGET_PRODUCT
311# based on the list of boards. Usually, that gets you something
312# that kinda works with a generic product, but really, you should
313# pick a product by name.
314#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315function chooseproduct()
316{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317 if [ "x$TARGET_PRODUCT" != x ] ; then
318 default_value=$TARGET_PRODUCT
319 else
320 if [ "$TARGET_SIMULATOR" = true ] ; then
321 default_value=sim
322 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700323 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700324 fi
325 fi
326
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800327 export TARGET_PRODUCT=
328 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700329 while [ -z "$TARGET_PRODUCT" ]
330 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700331 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332 if [ -z "$1" ] ; then
333 read ANSWER
334 else
335 echo $1
336 ANSWER=$1
337 fi
338
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339 if [ -z "$ANSWER" ] ; then
340 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800341 else
342 if check_product $ANSWER
343 then
344 export TARGET_PRODUCT=$ANSWER
345 else
346 echo "** Not a valid product: $ANSWER"
347 fi
348 fi
349 if [ -n "$1" ] ; then
350 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700351 fi
352 done
353
354 set_stuff_for_environment
355}
356
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800357function choosevariant()
358{
359 echo "Variant choices are:"
360 local index=1
361 local v
362 for v in ${VARIANT_CHOICES[@]}
363 do
364 # The product name is the name of the directory containing
365 # the makefile we found, above.
366 echo " $index. $v"
367 index=$(($index+1))
368 done
369
370 local default_value=eng
371 local ANSWER
372
373 export TARGET_BUILD_VARIANT=
374 while [ -z "$TARGET_BUILD_VARIANT" ]
375 do
376 echo -n "Which would you like? [$default_value] "
377 if [ -z "$1" ] ; then
378 read ANSWER
379 else
380 echo $1
381 ANSWER=$1
382 fi
383
384 if [ -z "$ANSWER" ] ; then
385 export TARGET_BUILD_VARIANT=$default_value
386 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
387 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800388 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800389 fi
390 else
391 if check_variant $ANSWER
392 then
393 export TARGET_BUILD_VARIANT=$ANSWER
394 else
395 echo "** Not a valid variant: $ANSWER"
396 fi
397 fi
398 if [ -n "$1" ] ; then
399 break
400 fi
401 done
402}
403
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700404function choosecombo()
405{
406 choosesim $1
407
408 echo
409 echo
410 choosetype $2
411
412 echo
413 echo
414 chooseproduct $3
415
416 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800417 echo
418 choosevariant $4
419
420 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700421 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800422 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700423}
424
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800425# Clear this variable. It will be built up again when the vendorsetup.sh
426# files are included at the end of this file.
427unset LUNCH_MENU_CHOICES
428function add_lunch_combo()
429{
430 local new_combo=$1
431 local c
432 for c in ${LUNCH_MENU_CHOICES[@]} ; do
433 if [ "$new_combo" = "$c" ] ; then
434 return
435 fi
436 done
437 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
438}
439
440# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700441add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700442add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800443add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800444
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700445function print_lunch_menu()
446{
447 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700448 echo
449 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700450 echo
451 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800452
453 local i=1
454 local choice
455 for choice in ${LUNCH_MENU_CHOICES[@]}
456 do
457 echo " $i. $choice"
458 i=$(($i+1))
459 done
460
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461 echo
462}
463
464function lunch()
465{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800466 local answer
467
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470 else
471 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700472 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800473 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474 fi
475
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476 local selection=
477
478 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700479 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700480 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800481 elif [ "$answer" = "simulator" ]
482 then
483 selection=simulator
484 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
485 then
486 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
487 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800488 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800489 fi
490 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
491 then
492 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700493 fi
494
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800495 if [ -z "$selection" ]
496 then
497 echo
498 echo "Invalid lunch combo: $answer"
499 return 1
500 fi
501
Joe Onoratoda12daf2010-06-09 18:18:31 -0700502 export TARGET_BUILD_APPS=
503
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 # special case the simulator
505 if [ "$selection" = "simulator" ]
506 then
507 export TARGET_PRODUCT=sim
508 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700509 export TARGET_SIMULATOR=true
510 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 else
512 local product=$(echo -n $selection | sed -e "s/-.*$//")
513 check_product $product
514 if [ $? -ne 0 ]
515 then
516 echo
517 echo "** Don't have a product spec for: '$product'"
518 echo "** Do you have the right repo manifest?"
519 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700520 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521
522 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
523 check_variant $variant
524 if [ $? -ne 0 ]
525 then
526 echo
527 echo "** Invalid variant: '$variant'"
528 echo "** Must be one of ${VARIANT_CHOICES[@]}"
529 variant=
530 fi
531
532 if [ -z "$product" -o -z "$variant" ]
533 then
534 echo
535 return 1
536 fi
537
538 export TARGET_PRODUCT=$product
539 export TARGET_BUILD_VARIANT=$variant
540 export TARGET_SIMULATOR=false
541 export TARGET_BUILD_TYPE=release
542 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700543
544 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800545
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700546 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800547 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700548}
549
Joe Onoratoda12daf2010-06-09 18:18:31 -0700550# Configures the build to build unbundled apps.
551# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
552function tapas()
553{
554 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
555 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
556
557 if [ $(echo $variant | wc -w) -gt 1 ]; then
558 echo "tapas: Error: Multiple build variants supplied: $variant"
559 return
560 fi
561 if [ -z "$variant" ]; then
562 variant=eng
563 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700564 if [ -z "$apps" ]; then
565 apps=all
566 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700567
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700568 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700569 export TARGET_BUILD_VARIANT=$variant
570 export TARGET_SIMULATOR=false
571 export TARGET_BUILD_TYPE=release
572 export TARGET_BUILD_APPS=$apps
573
574 set_stuff_for_environment
575 printconfig
576}
577
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700578function gettop
579{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800580 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
582 echo $TOP
583 else
584 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800585 # The following circumlocution (repeated below as well) ensures
586 # that we record the true directory name and not one that is
587 # faked up with symlink names.
588 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700589 else
590 # We redirect cd to /dev/null in case it's aliased to
591 # a command that prints something as a side-effect
592 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800593 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700594 T=
595 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
596 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800597 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700598 done
599 cd $HERE > /dev/null
600 if [ -f "$T/$TOPFILE" ]; then
601 echo $T
602 fi
603 fi
604 fi
605}
606
607function m()
608{
609 T=$(gettop)
610 if [ "$T" ]; then
611 make -C $T $@
612 else
613 echo "Couldn't locate the top of the tree. Try setting TOP."
614 fi
615}
616
617function findmakefile()
618{
619 TOPFILE=build/core/envsetup.mk
620 # We redirect cd to /dev/null in case it's aliased to
621 # a command that prints something as a side-effect
622 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800623 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700624 T=
625 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
626 T=$PWD
627 if [ -f "$T/Android.mk" ]; then
628 echo $T/Android.mk
629 cd $HERE > /dev/null
630 return
631 fi
632 cd .. > /dev/null
633 done
634 cd $HERE > /dev/null
635}
636
637function mm()
638{
639 # If we're sitting in the root of the build tree, just do a
640 # normal make.
641 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
642 make $@
643 else
644 # Find the closest Android.mk file.
645 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800646 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700647 # Remove the path to top as the makefilepath needs to be relative
648 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649 if [ ! "$T" ]; then
650 echo "Couldn't locate the top of the tree. Try setting TOP."
651 elif [ ! "$M" ]; then
652 echo "Couldn't locate a makefile from the current directory."
653 else
Ying Wang01884142010-07-20 16:18:16 -0700654 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700655 fi
656 fi
657}
658
659function mmm()
660{
661 T=$(gettop)
662 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800663 local MAKEFILE=
664 local ARGS=
665 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800666 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
667 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
668 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700669 DIR=`echo $DIR | sed -e 's:/$::'`
670 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700671 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800673 START=`PWD= /bin/pwd`
674 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700675 if [ "$MFILE" = "" ] ; then
676 MFILE=$DIR/Android.mk
677 else
678 MFILE=$MFILE/$DIR/Android.mk
679 fi
680 MAKEFILE="$MAKEFILE $MFILE"
681 else
682 if [ "$DIR" = snod ]; then
683 ARGS="$ARGS snod"
684 elif [ "$DIR" = showcommands ]; then
685 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700686 elif [ "$DIR" = dist ]; then
687 ARGS="$ARGS dist"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700688 else
689 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400690 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700691 fi
692 fi
693 done
Ying Wang01884142010-07-20 16:18:16 -0700694 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700695 else
696 echo "Couldn't locate the top of the tree. Try setting TOP."
697 fi
698}
699
700function croot()
701{
702 T=$(gettop)
703 if [ "$T" ]; then
704 cd $(gettop)
705 else
706 echo "Couldn't locate the top of the tree. Try setting TOP."
707 fi
708}
709
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700710function cproj()
711{
712 TOPFILE=build/core/envsetup.mk
713 # We redirect cd to /dev/null in case it's aliased to
714 # a command that prints something as a side-effect
715 # (like pushd)
716 local HERE=$PWD
717 T=
718 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
719 T=$PWD
720 if [ -f "$T/Android.mk" ]; then
721 cd $T
722 return
723 fi
724 cd .. > /dev/null
725 done
726 cd $HERE > /dev/null
727 echo "can't find Android.mk"
728}
729
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700730function pid()
731{
732 local EXE="$1"
733 if [ "$EXE" ] ; then
734 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
735 echo "$PID"
736 else
737 echo "usage: pid name"
738 fi
739}
740
Christopher Tate744ee802009-11-12 15:33:08 -0800741# systemstack - dump the current stack trace of all threads in the system process
742# to the usual ANR traces file
743function systemstack()
744{
745 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
746}
747
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700748function gdbclient()
749{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800750 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
751 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
752 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
753 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
754 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700755 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
756 local EXE="$1"
757 if [ "$EXE" ] ; then
758 EXE=$1
759 else
760 EXE="app_process"
761 fi
762
763 local PORT="$2"
764 if [ "$PORT" ] ; then
765 PORT=$2
766 else
767 PORT=":5039"
768 fi
769
770 local PID
771 local PROG="$3"
772 if [ "$PROG" ] ; then
773 PID=`pid $3`
774 adb forward "tcp$PORT" "tcp$PORT"
775 adb shell gdbserver $PORT --attach $PID &
776 sleep 2
777 else
778 echo ""
779 echo "If you haven't done so already, do this first on the device:"
780 echo " gdbserver $PORT /system/bin/$EXE"
781 echo " or"
782 echo " gdbserver $PORT --attach $PID"
783 echo ""
784 fi
785
786 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
787 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
788 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
789 echo >>"$OUT_ROOT/gdbclient.cmds" ""
790
791 arm-eabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
792 else
793 echo "Unable to determine build system output dir."
794 fi
795
796}
797
798case `uname -s` in
799 Darwin)
800 function sgrep()
801 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100802 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 -0700803 }
804
805 ;;
806 *)
807 function sgrep()
808 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100809 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 -0700810 }
811 ;;
812esac
813
814function jgrep()
815{
816 find . -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
817}
818
819function cgrep()
820{
Ficus Kirkpatrick8889bdf2010-03-01 16:51:47 -0800821 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 -0700822}
823
824function resgrep()
825{
826 for dir in `find . -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
827}
828
829case `uname -s` in
830 Darwin)
831 function mgrep()
832 {
833 find -E . -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
834 }
835
836 function treegrep()
837 {
838 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
839 }
840
841 ;;
842 *)
843 function mgrep()
844 {
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800845 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 -0700846 }
847
848 function treegrep()
849 {
850 find . -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
851 }
852
853 ;;
854esac
855
856function getprebuilt
857{
858 get_abs_build_var ANDROID_PREBUILTS
859}
860
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700861function tracedmdump()
862{
863 T=$(gettop)
864 if [ ! "$T" ]; then
865 echo "Couldn't locate the top of the tree. Try setting TOP."
866 return
867 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800868 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700869 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700870
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800871 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700872 if [ ! "$TRACE" ] ; then
873 echo "usage: tracedmdump tracename"
874 return
875 fi
876
Jack Veenstra60116fc2009-04-09 18:12:34 -0700877 if [ ! -r "$KERNEL" ] ; then
878 echo "Error: cannot find kernel: '$KERNEL'"
879 return
880 fi
881
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800882 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700883 if [ "$BASETRACE" = "$TRACE" ] ; then
884 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
885 fi
886
887 echo "post-processing traces..."
888 rm -f $TRACE/qtrace.dexlist
889 post_trace $TRACE
890 if [ $? -ne 0 ]; then
891 echo "***"
892 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
893 echo "***"
894 return
895 fi
896 echo "generating dexlist output..."
897 /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
898 echo "generating dmtrace data..."
899 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
900 echo "generating html file..."
901 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
902 echo "done, see $TRACE/dmtrace.html for details"
903 echo "or run:"
904 echo " traceview $TRACE/dmtrace"
905}
906
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800907# communicate with a running device or emulator, set up necessary state,
908# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700909function runhat()
910{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800911 # process standard adb options
912 local adbTarget=""
Chris Dearmanf0bcf422011-02-16 12:16:09 -0800913 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800914 adbTarget=$1
915 shift 1
Chris Dearmanf0bcf422011-02-16 12:16:09 -0800916 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800917 adbTarget="$1 $2"
918 shift 2
919 fi
920 local adbOptions=${adbTarget}
921 echo adbOptions = ${adbOptions}
922
923 # runhat options
924 local targetPid=$1
925 local outputFile=$2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700926
927 if [ "$targetPid" = "" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800928 echo "Usage: runhat [ -d | -e | -s serial ] target-pid [output-file]"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700929 return
930 fi
931
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800932 # confirm hat is available
933 if [ -z $(which hat) ]; then
934 echo "hat is not available in this configuration."
935 return
936 fi
937
938 adb ${adbOptions} shell >/dev/null mkdir /data/misc
939 adb ${adbOptions} shell chmod 777 /data/misc
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700940
The Android Open Source Project88b60792009-03-03 19:28:42 -0800941 # send a SIGUSR1 to cause the hprof dump
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700942 echo "Poking $targetPid and waiting for data..."
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800943 adb ${adbOptions} shell kill -10 $targetPid
The Android Open Source Project88b60792009-03-03 19:28:42 -0800944 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700945 echo -n "> "
946 read
947
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800948 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 -0800949 local devFile=/data/misc/${availFiles[0]}
950 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700951
The Android Open Source Project88b60792009-03-03 19:28:42 -0800952 echo "Retrieving file $devFile..."
953 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700954
The Android Open Source Project88b60792009-03-03 19:28:42 -0800955 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700956
The Android Open Source Project88b60792009-03-03 19:28:42 -0800957 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700958 echo "View the output by pointing your browser at http://localhost:7000/"
959 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800960 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700961}
962
963function getbugreports()
964{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800965 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966
967 if [ ! "$reports" ]; then
968 echo "Could not locate any bugreports."
969 return
970 fi
971
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800972 local report
973 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700974 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800975 echo "/sdcard/bugreports/${report}"
976 adb pull /sdcard/bugreports/${report} ${report}
977 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700978 done
979}
980
981function startviewserver()
982{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800983 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700984 if [ $# -gt 0 ]; then
985 port=$1
986 fi
987 adb shell service call window 1 i32 $port
988}
989
990function stopviewserver()
991{
992 adb shell service call window 2
993}
994
995function isviewserverstarted()
996{
997 adb shell service call window 3
998}
999
1000function smoketest()
1001{
1002 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1003 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1004 return
1005 fi
1006 T=$(gettop)
1007 if [ ! "$T" ]; then
1008 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1009 return
1010 fi
1011
1012 (cd "$T" && mmm tests/SmokeTest) &&
1013 adb uninstall com.android.smoketest > /dev/null &&
1014 adb uninstall com.android.smoketest.tests > /dev/null &&
1015 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1016 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1017 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1018}
1019
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001020# simple shortcut to the runtest command
1021function runtest()
1022{
1023 T=$(gettop)
1024 if [ ! "$T" ]; then
1025 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1026 return
1027 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001028 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001029}
1030
The Android Open Source Project88b60792009-03-03 19:28:42 -08001031function godir () {
1032 if [[ -z "$1" ]]; then
1033 echo "Usage: godir <regex>"
1034 return
1035 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001036 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001037 if [[ ! -f $T/filelist ]]; then
1038 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001039 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001040 echo " Done"
1041 echo ""
1042 fi
1043 local lines
1044 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1045 if [[ ${#lines[@]} = 0 ]]; then
1046 echo "Not found"
1047 return
1048 fi
1049 local pathname
1050 local choice
1051 if [[ ${#lines[@]} > 1 ]]; then
1052 while [[ -z "$pathname" ]]; do
1053 local index=1
1054 local line
1055 for line in ${lines[@]}; do
1056 printf "%6s %s\n" "[$index]" $line
1057 index=$(($index + 1))
1058 done
1059 echo
1060 echo -n "Select one: "
1061 unset choice
1062 read choice
1063 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1064 echo "Invalid choice"
1065 continue
1066 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001067 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001068 done
1069 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001070 pathname=${lines[0]}
1071 fi
1072 cd $T/$pathname
1073}
1074
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001075# Force JAVA_HOME to point to java 1.6 if it isn't already set
1076function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001077 if [ ! "$JAVA_HOME" ]; then
1078 case `uname -s` in
1079 Darwin)
1080 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1081 ;;
1082 *)
1083 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1084 ;;
1085 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001086 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001087}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001088
Raphael Moll70a86b02011-06-20 16:03:14 -07001089if [ "x$SHELL" != "x/bin/bash" ]; then
1090 case `ps -o command -p $$` in
1091 *bash*)
1092 ;;
1093 *)
1094 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1095 ;;
1096 esac
1097fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001098
1099# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001100for 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 -08001101do
1102 echo "including $f"
1103 . $f
1104done
1105unset f