blob: 0cf4ef46888407d16734848e30fb47a46baa73f2 [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
Kenny Root52aa81c2011-07-15 11:07:06 -0700184function addcompletions()
185{
186 local T dir f
187
188 # Keep us from trying to run in something that isn't bash.
189 if [ -z "${BASH_VERSION}" ]; then
190 return
191 fi
192
193 # Keep us from trying to run in bash that's too old.
194 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
195 return
196 fi
197
198 dir="sdk/bash_completion"
199 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700200 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700201 echo "including $f"
202 . $f
203 done
204 fi
205}
206
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700207case `uname -s` in
208 Linux)
209 function choosesim()
210 {
211 echo "Build for the simulator or the device?"
212 echo " 1. Device"
213 echo " 2. Simulator"
214 echo
215
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800216 export TARGET_SIMULATOR=
217 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700218 while [ -z $TARGET_SIMULATOR ]
219 do
220 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800221 if [ -z "$1" ] ; then
222 read ANSWER
223 else
224 echo $1
225 ANSWER=$1
226 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700227 case $ANSWER in
228 "")
229 export TARGET_SIMULATOR=false
230 ;;
231 1)
232 export TARGET_SIMULATOR=false
233 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800234 Device)
235 export TARGET_SIMULATOR=false
236 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700237 2)
238 export TARGET_SIMULATOR=true
239 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800240 Simulator)
241 export TARGET_SIMULATOR=true
242 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700243 *)
244 echo
245 echo "I didn't understand your response. Please try again."
246 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700247 ;;
248 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800249 if [ -n "$1" ] ; then
250 break
251 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700252 done
253
254 set_stuff_for_environment
255 }
256 ;;
257 *)
258 function choosesim()
259 {
260 echo "Only device builds are supported for" `uname -s`
261 echo " Forcing TARGET_SIMULATOR=false"
262 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800263 if [ -z "$1" ]
264 then
265 echo -n "Press enter: "
266 read
267 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700268
269 export TARGET_SIMULATOR=false
270 set_stuff_for_environment
271 }
272 ;;
273esac
274
275function choosetype()
276{
277 echo "Build type choices are:"
278 echo " 1. release"
279 echo " 2. debug"
280 echo
281
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800282 local DEFAULT_NUM DEFAULT_VALUE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700283 if [ $TARGET_SIMULATOR = "false" ] ; then
284 DEFAULT_NUM=1
285 DEFAULT_VALUE=release
286 else
287 DEFAULT_NUM=2
288 DEFAULT_VALUE=debug
289 fi
290
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800291 export TARGET_BUILD_TYPE=
292 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700293 while [ -z $TARGET_BUILD_TYPE ]
294 do
295 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800296 if [ -z "$1" ] ; then
297 read ANSWER
298 else
299 echo $1
300 ANSWER=$1
301 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700302 case $ANSWER in
303 "")
304 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
305 ;;
306 1)
307 export TARGET_BUILD_TYPE=release
308 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800309 release)
310 export TARGET_BUILD_TYPE=release
311 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700312 2)
313 export TARGET_BUILD_TYPE=debug
314 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800315 debug)
316 export TARGET_BUILD_TYPE=debug
317 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700318 *)
319 echo
320 echo "I didn't understand your response. Please try again."
321 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700322 ;;
323 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800324 if [ -n "$1" ] ; then
325 break
326 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700327 done
328
329 set_stuff_for_environment
330}
331
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332#
333# This function isn't really right: It chooses a TARGET_PRODUCT
334# based on the list of boards. Usually, that gets you something
335# that kinda works with a generic product, but really, you should
336# pick a product by name.
337#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338function chooseproduct()
339{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700340 if [ "x$TARGET_PRODUCT" != x ] ; then
341 default_value=$TARGET_PRODUCT
342 else
343 if [ "$TARGET_SIMULATOR" = true ] ; then
344 default_value=sim
345 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700346 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 fi
348 fi
349
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800350 export TARGET_PRODUCT=
351 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700352 while [ -z "$TARGET_PRODUCT" ]
353 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700354 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800355 if [ -z "$1" ] ; then
356 read ANSWER
357 else
358 echo $1
359 ANSWER=$1
360 fi
361
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700362 if [ -z "$ANSWER" ] ; then
363 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800364 else
365 if check_product $ANSWER
366 then
367 export TARGET_PRODUCT=$ANSWER
368 else
369 echo "** Not a valid product: $ANSWER"
370 fi
371 fi
372 if [ -n "$1" ] ; then
373 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700374 fi
375 done
376
377 set_stuff_for_environment
378}
379
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800380function choosevariant()
381{
382 echo "Variant choices are:"
383 local index=1
384 local v
385 for v in ${VARIANT_CHOICES[@]}
386 do
387 # The product name is the name of the directory containing
388 # the makefile we found, above.
389 echo " $index. $v"
390 index=$(($index+1))
391 done
392
393 local default_value=eng
394 local ANSWER
395
396 export TARGET_BUILD_VARIANT=
397 while [ -z "$TARGET_BUILD_VARIANT" ]
398 do
399 echo -n "Which would you like? [$default_value] "
400 if [ -z "$1" ] ; then
401 read ANSWER
402 else
403 echo $1
404 ANSWER=$1
405 fi
406
407 if [ -z "$ANSWER" ] ; then
408 export TARGET_BUILD_VARIANT=$default_value
409 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
410 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800411 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800412 fi
413 else
414 if check_variant $ANSWER
415 then
416 export TARGET_BUILD_VARIANT=$ANSWER
417 else
418 echo "** Not a valid variant: $ANSWER"
419 fi
420 fi
421 if [ -n "$1" ] ; then
422 break
423 fi
424 done
425}
426
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700427function choosecombo()
428{
429 choosesim $1
430
431 echo
432 echo
433 choosetype $2
434
435 echo
436 echo
437 chooseproduct $3
438
439 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800440 echo
441 choosevariant $4
442
443 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800445 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446}
447
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800448# Clear this variable. It will be built up again when the vendorsetup.sh
449# files are included at the end of this file.
450unset LUNCH_MENU_CHOICES
451function add_lunch_combo()
452{
453 local new_combo=$1
454 local c
455 for c in ${LUNCH_MENU_CHOICES[@]} ; do
456 if [ "$new_combo" = "$c" ] ; then
457 return
458 fi
459 done
460 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
461}
462
463# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700464add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700465add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800466add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800467
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468function print_lunch_menu()
469{
470 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471 echo
472 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 echo
474 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800475
476 local i=1
477 local choice
478 for choice in ${LUNCH_MENU_CHOICES[@]}
479 do
480 echo " $i. $choice"
481 i=$(($i+1))
482 done
483
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700484 echo
485}
486
487function lunch()
488{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800489 local answer
490
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700491 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700493 else
494 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700495 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800496 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700497 fi
498
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499 local selection=
500
501 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700502 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700503 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 elif [ "$answer" = "simulator" ]
505 then
506 selection=simulator
507 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
508 then
509 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
510 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800511 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512 fi
513 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
514 then
515 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700516 fi
517
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800518 if [ -z "$selection" ]
519 then
520 echo
521 echo "Invalid lunch combo: $answer"
522 return 1
523 fi
524
Joe Onoratoda12daf2010-06-09 18:18:31 -0700525 export TARGET_BUILD_APPS=
526
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800527 # special case the simulator
528 if [ "$selection" = "simulator" ]
529 then
530 export TARGET_PRODUCT=sim
531 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700532 export TARGET_SIMULATOR=true
533 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800534 else
535 local product=$(echo -n $selection | sed -e "s/-.*$//")
536 check_product $product
537 if [ $? -ne 0 ]
538 then
539 echo
540 echo "** Don't have a product spec for: '$product'"
541 echo "** Do you have the right repo manifest?"
542 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700543 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800544
545 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
546 check_variant $variant
547 if [ $? -ne 0 ]
548 then
549 echo
550 echo "** Invalid variant: '$variant'"
551 echo "** Must be one of ${VARIANT_CHOICES[@]}"
552 variant=
553 fi
554
555 if [ -z "$product" -o -z "$variant" ]
556 then
557 echo
558 return 1
559 fi
560
561 export TARGET_PRODUCT=$product
562 export TARGET_BUILD_VARIANT=$variant
563 export TARGET_SIMULATOR=false
564 export TARGET_BUILD_TYPE=release
565 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700566
567 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800568
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700569 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800570 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700571}
572
Joe Onoratoda12daf2010-06-09 18:18:31 -0700573# Configures the build to build unbundled apps.
574# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
575function tapas()
576{
577 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
578 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
579
580 if [ $(echo $variant | wc -w) -gt 1 ]; then
581 echo "tapas: Error: Multiple build variants supplied: $variant"
582 return
583 fi
584 if [ -z "$variant" ]; then
585 variant=eng
586 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700587 if [ -z "$apps" ]; then
588 apps=all
589 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700590
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700591 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700592 export TARGET_BUILD_VARIANT=$variant
593 export TARGET_SIMULATOR=false
594 export TARGET_BUILD_TYPE=release
595 export TARGET_BUILD_APPS=$apps
596
597 set_stuff_for_environment
598 printconfig
599}
600
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700601function gettop
602{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
605 echo $TOP
606 else
607 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800608 # The following circumlocution (repeated below as well) ensures
609 # that we record the true directory name and not one that is
610 # faked up with symlink names.
611 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700612 else
613 # We redirect cd to /dev/null in case it's aliased to
614 # a command that prints something as a side-effect
615 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800616 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700617 T=
618 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
619 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800620 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700621 done
622 cd $HERE > /dev/null
623 if [ -f "$T/$TOPFILE" ]; then
624 echo $T
625 fi
626 fi
627 fi
628}
629
630function m()
631{
632 T=$(gettop)
633 if [ "$T" ]; then
634 make -C $T $@
635 else
636 echo "Couldn't locate the top of the tree. Try setting TOP."
637 fi
638}
639
640function findmakefile()
641{
642 TOPFILE=build/core/envsetup.mk
643 # We redirect cd to /dev/null in case it's aliased to
644 # a command that prints something as a side-effect
645 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800646 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700647 T=
648 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
649 T=$PWD
650 if [ -f "$T/Android.mk" ]; then
651 echo $T/Android.mk
652 cd $HERE > /dev/null
653 return
654 fi
655 cd .. > /dev/null
656 done
657 cd $HERE > /dev/null
658}
659
660function mm()
661{
662 # If we're sitting in the root of the build tree, just do a
663 # normal make.
664 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
665 make $@
666 else
667 # Find the closest Android.mk file.
668 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800669 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700670 # Remove the path to top as the makefilepath needs to be relative
671 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672 if [ ! "$T" ]; then
673 echo "Couldn't locate the top of the tree. Try setting TOP."
674 elif [ ! "$M" ]; then
675 echo "Couldn't locate a makefile from the current directory."
676 else
Ying Wang01884142010-07-20 16:18:16 -0700677 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700678 fi
679 fi
680}
681
682function mmm()
683{
684 T=$(gettop)
685 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800686 local MAKEFILE=
687 local ARGS=
688 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800689 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
690 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
691 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700692 DIR=`echo $DIR | sed -e 's:/$::'`
693 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700694 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700695 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800696 START=`PWD= /bin/pwd`
697 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700698 if [ "$MFILE" = "" ] ; then
699 MFILE=$DIR/Android.mk
700 else
701 MFILE=$MFILE/$DIR/Android.mk
702 fi
703 MAKEFILE="$MAKEFILE $MFILE"
704 else
705 if [ "$DIR" = snod ]; then
706 ARGS="$ARGS snod"
707 elif [ "$DIR" = showcommands ]; then
708 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700709 elif [ "$DIR" = dist ]; then
710 ARGS="$ARGS dist"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700711 else
712 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400713 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700714 fi
715 fi
716 done
Ying Wang01884142010-07-20 16:18:16 -0700717 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700718 else
719 echo "Couldn't locate the top of the tree. Try setting TOP."
720 fi
721}
722
723function croot()
724{
725 T=$(gettop)
726 if [ "$T" ]; then
727 cd $(gettop)
728 else
729 echo "Couldn't locate the top of the tree. Try setting TOP."
730 fi
731}
732
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700733function cproj()
734{
735 TOPFILE=build/core/envsetup.mk
736 # We redirect cd to /dev/null in case it's aliased to
737 # a command that prints something as a side-effect
738 # (like pushd)
739 local HERE=$PWD
740 T=
741 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
742 T=$PWD
743 if [ -f "$T/Android.mk" ]; then
744 cd $T
745 return
746 fi
747 cd .. > /dev/null
748 done
749 cd $HERE > /dev/null
750 echo "can't find Android.mk"
751}
752
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700753function pid()
754{
755 local EXE="$1"
756 if [ "$EXE" ] ; then
757 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
758 echo "$PID"
759 else
760 echo "usage: pid name"
761 fi
762}
763
Christopher Tate744ee802009-11-12 15:33:08 -0800764# systemstack - dump the current stack trace of all threads in the system process
765# to the usual ANR traces file
766function systemstack()
767{
768 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
769}
770
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700771function gdbclient()
772{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800773 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
774 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
775 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
776 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
777 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700778 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
779 local EXE="$1"
780 if [ "$EXE" ] ; then
781 EXE=$1
782 else
783 EXE="app_process"
784 fi
785
786 local PORT="$2"
787 if [ "$PORT" ] ; then
788 PORT=$2
789 else
790 PORT=":5039"
791 fi
792
793 local PID
794 local PROG="$3"
795 if [ "$PROG" ] ; then
796 PID=`pid $3`
797 adb forward "tcp$PORT" "tcp$PORT"
798 adb shell gdbserver $PORT --attach $PID &
799 sleep 2
800 else
801 echo ""
802 echo "If you haven't done so already, do this first on the device:"
803 echo " gdbserver $PORT /system/bin/$EXE"
804 echo " or"
805 echo " gdbserver $PORT --attach $PID"
806 echo ""
807 fi
808
809 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
810 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
811 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
812 echo >>"$OUT_ROOT/gdbclient.cmds" ""
813
814 arm-eabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
815 else
816 echo "Unable to determine build system output dir."
817 fi
818
819}
820
821case `uname -s` in
822 Darwin)
823 function sgrep()
824 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100825 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 -0700826 }
827
828 ;;
829 *)
830 function sgrep()
831 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100832 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 -0700833 }
834 ;;
835esac
836
837function jgrep()
838{
839 find . -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
840}
841
842function cgrep()
843{
Ficus Kirkpatrick8889bdf2010-03-01 16:51:47 -0800844 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 -0700845}
846
847function resgrep()
848{
849 for dir in `find . -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
850}
851
852case `uname -s` in
853 Darwin)
854 function mgrep()
855 {
856 find -E . -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
857 }
858
859 function treegrep()
860 {
861 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
862 }
863
864 ;;
865 *)
866 function mgrep()
867 {
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800868 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 -0700869 }
870
871 function treegrep()
872 {
873 find . -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
874 }
875
876 ;;
877esac
878
879function getprebuilt
880{
881 get_abs_build_var ANDROID_PREBUILTS
882}
883
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700884function tracedmdump()
885{
886 T=$(gettop)
887 if [ ! "$T" ]; then
888 echo "Couldn't locate the top of the tree. Try setting TOP."
889 return
890 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800891 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700892 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700893
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800894 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700895 if [ ! "$TRACE" ] ; then
896 echo "usage: tracedmdump tracename"
897 return
898 fi
899
Jack Veenstra60116fc2009-04-09 18:12:34 -0700900 if [ ! -r "$KERNEL" ] ; then
901 echo "Error: cannot find kernel: '$KERNEL'"
902 return
903 fi
904
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800905 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700906 if [ "$BASETRACE" = "$TRACE" ] ; then
907 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
908 fi
909
910 echo "post-processing traces..."
911 rm -f $TRACE/qtrace.dexlist
912 post_trace $TRACE
913 if [ $? -ne 0 ]; then
914 echo "***"
915 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
916 echo "***"
917 return
918 fi
919 echo "generating dexlist output..."
920 /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
921 echo "generating dmtrace data..."
922 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
923 echo "generating html file..."
924 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
925 echo "done, see $TRACE/dmtrace.html for details"
926 echo "or run:"
927 echo " traceview $TRACE/dmtrace"
928}
929
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800930# communicate with a running device or emulator, set up necessary state,
931# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700932function runhat()
933{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800934 # process standard adb options
935 local adbTarget=""
Chris Dearmanf0bcf422011-02-16 12:16:09 -0800936 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800937 adbTarget=$1
938 shift 1
Chris Dearmanf0bcf422011-02-16 12:16:09 -0800939 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800940 adbTarget="$1 $2"
941 shift 2
942 fi
943 local adbOptions=${adbTarget}
944 echo adbOptions = ${adbOptions}
945
946 # runhat options
947 local targetPid=$1
948 local outputFile=$2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700949
950 if [ "$targetPid" = "" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800951 echo "Usage: runhat [ -d | -e | -s serial ] target-pid [output-file]"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700952 return
953 fi
954
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800955 # confirm hat is available
956 if [ -z $(which hat) ]; then
957 echo "hat is not available in this configuration."
958 return
959 fi
960
961 adb ${adbOptions} shell >/dev/null mkdir /data/misc
962 adb ${adbOptions} shell chmod 777 /data/misc
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700963
The Android Open Source Project88b60792009-03-03 19:28:42 -0800964 # send a SIGUSR1 to cause the hprof dump
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700965 echo "Poking $targetPid and waiting for data..."
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800966 adb ${adbOptions} shell kill -10 $targetPid
The Android Open Source Project88b60792009-03-03 19:28:42 -0800967 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700968 echo -n "> "
969 read
970
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800971 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 -0800972 local devFile=/data/misc/${availFiles[0]}
973 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700974
The Android Open Source Project88b60792009-03-03 19:28:42 -0800975 echo "Retrieving file $devFile..."
976 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700977
The Android Open Source Project88b60792009-03-03 19:28:42 -0800978 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700979
The Android Open Source Project88b60792009-03-03 19:28:42 -0800980 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700981 echo "View the output by pointing your browser at http://localhost:7000/"
982 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800983 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700984}
985
986function getbugreports()
987{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800988 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700989
990 if [ ! "$reports" ]; then
991 echo "Could not locate any bugreports."
992 return
993 fi
994
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800995 local report
996 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700997 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800998 echo "/sdcard/bugreports/${report}"
999 adb pull /sdcard/bugreports/${report} ${report}
1000 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001001 done
1002}
1003
1004function startviewserver()
1005{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001006 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001007 if [ $# -gt 0 ]; then
1008 port=$1
1009 fi
1010 adb shell service call window 1 i32 $port
1011}
1012
1013function stopviewserver()
1014{
1015 adb shell service call window 2
1016}
1017
1018function isviewserverstarted()
1019{
1020 adb shell service call window 3
1021}
1022
1023function smoketest()
1024{
1025 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1026 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1027 return
1028 fi
1029 T=$(gettop)
1030 if [ ! "$T" ]; then
1031 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1032 return
1033 fi
1034
1035 (cd "$T" && mmm tests/SmokeTest) &&
1036 adb uninstall com.android.smoketest > /dev/null &&
1037 adb uninstall com.android.smoketest.tests > /dev/null &&
1038 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1039 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1040 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1041}
1042
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001043# simple shortcut to the runtest command
1044function runtest()
1045{
1046 T=$(gettop)
1047 if [ ! "$T" ]; then
1048 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1049 return
1050 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001051 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001052}
1053
The Android Open Source Project88b60792009-03-03 19:28:42 -08001054function godir () {
1055 if [[ -z "$1" ]]; then
1056 echo "Usage: godir <regex>"
1057 return
1058 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001059 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001060 if [[ ! -f $T/filelist ]]; then
1061 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001062 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001063 echo " Done"
1064 echo ""
1065 fi
1066 local lines
1067 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1068 if [[ ${#lines[@]} = 0 ]]; then
1069 echo "Not found"
1070 return
1071 fi
1072 local pathname
1073 local choice
1074 if [[ ${#lines[@]} > 1 ]]; then
1075 while [[ -z "$pathname" ]]; do
1076 local index=1
1077 local line
1078 for line in ${lines[@]}; do
1079 printf "%6s %s\n" "[$index]" $line
1080 index=$(($index + 1))
1081 done
1082 echo
1083 echo -n "Select one: "
1084 unset choice
1085 read choice
1086 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1087 echo "Invalid choice"
1088 continue
1089 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001090 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001091 done
1092 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001093 pathname=${lines[0]}
1094 fi
1095 cd $T/$pathname
1096}
1097
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001098# Force JAVA_HOME to point to java 1.6 if it isn't already set
1099function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001100 if [ ! "$JAVA_HOME" ]; then
1101 case `uname -s` in
1102 Darwin)
1103 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1104 ;;
1105 *)
1106 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1107 ;;
1108 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001109 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001110}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001111
Raphael Moll70a86b02011-06-20 16:03:14 -07001112if [ "x$SHELL" != "x/bin/bash" ]; then
1113 case `ps -o command -p $$` in
1114 *bash*)
1115 ;;
1116 *)
1117 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1118 ;;
1119 esac
1120fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001121
1122# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001123for 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 -08001124do
1125 echo "including $f"
1126 . $f
1127done
1128unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001129
1130addcompletions