blob: f5aee90e1b37ce1c63e868ff7870d97aec061a50 [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
Kenny Root52aa81c2011-07-15 11:07:06 -0700187function addcompletions()
188{
189 local T dir f
190
191 # Keep us from trying to run in something that isn't bash.
192 if [ -z "${BASH_VERSION}" ]; then
193 return
194 fi
195
196 # Keep us from trying to run in bash that's too old.
197 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
198 return
199 fi
200
201 dir="sdk/bash_completion"
202 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700203 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700204 echo "including $f"
205 . $f
206 done
207 fi
208}
209
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700210case `uname -s` in
211 Linux)
212 function choosesim()
213 {
214 echo "Build for the simulator or the device?"
215 echo " 1. Device"
216 echo " 2. Simulator"
217 echo
218
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800219 export TARGET_SIMULATOR=
220 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700221 while [ -z $TARGET_SIMULATOR ]
222 do
223 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800224 if [ -z "$1" ] ; then
225 read ANSWER
226 else
227 echo $1
228 ANSWER=$1
229 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700230 case $ANSWER in
231 "")
232 export TARGET_SIMULATOR=false
233 ;;
234 1)
235 export TARGET_SIMULATOR=false
236 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800237 Device)
238 export TARGET_SIMULATOR=false
239 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700240 2)
241 export TARGET_SIMULATOR=true
242 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800243 Simulator)
244 export TARGET_SIMULATOR=true
245 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700246 *)
247 echo
248 echo "I didn't understand your response. Please try again."
249 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700250 ;;
251 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800252 if [ -n "$1" ] ; then
253 break
254 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255 done
256
257 set_stuff_for_environment
258 }
259 ;;
260 *)
261 function choosesim()
262 {
263 echo "Only device builds are supported for" `uname -s`
264 echo " Forcing TARGET_SIMULATOR=false"
265 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800266 if [ -z "$1" ]
267 then
268 echo -n "Press enter: "
269 read
270 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700271
272 export TARGET_SIMULATOR=false
273 set_stuff_for_environment
274 }
275 ;;
276esac
277
278function choosetype()
279{
280 echo "Build type choices are:"
281 echo " 1. release"
282 echo " 2. debug"
283 echo
284
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800285 local DEFAULT_NUM DEFAULT_VALUE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700286 if [ $TARGET_SIMULATOR = "false" ] ; then
287 DEFAULT_NUM=1
288 DEFAULT_VALUE=release
289 else
290 DEFAULT_NUM=2
291 DEFAULT_VALUE=debug
292 fi
293
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800294 export TARGET_BUILD_TYPE=
295 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700296 while [ -z $TARGET_BUILD_TYPE ]
297 do
298 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800299 if [ -z "$1" ] ; then
300 read ANSWER
301 else
302 echo $1
303 ANSWER=$1
304 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700305 case $ANSWER in
306 "")
307 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
308 ;;
309 1)
310 export TARGET_BUILD_TYPE=release
311 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800312 release)
313 export TARGET_BUILD_TYPE=release
314 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315 2)
316 export TARGET_BUILD_TYPE=debug
317 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800318 debug)
319 export TARGET_BUILD_TYPE=debug
320 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321 *)
322 echo
323 echo "I didn't understand your response. Please try again."
324 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325 ;;
326 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800327 if [ -n "$1" ] ; then
328 break
329 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700330 done
331
332 set_stuff_for_environment
333}
334
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335#
336# This function isn't really right: It chooses a TARGET_PRODUCT
337# based on the list of boards. Usually, that gets you something
338# that kinda works with a generic product, but really, you should
339# pick a product by name.
340#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700341function chooseproduct()
342{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700343 if [ "x$TARGET_PRODUCT" != x ] ; then
344 default_value=$TARGET_PRODUCT
345 else
346 if [ "$TARGET_SIMULATOR" = true ] ; then
347 default_value=sim
348 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700349 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700350 fi
351 fi
352
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800353 export TARGET_PRODUCT=
354 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700355 while [ -z "$TARGET_PRODUCT" ]
356 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700357 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800358 if [ -z "$1" ] ; then
359 read ANSWER
360 else
361 echo $1
362 ANSWER=$1
363 fi
364
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700365 if [ -z "$ANSWER" ] ; then
366 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800367 else
368 if check_product $ANSWER
369 then
370 export TARGET_PRODUCT=$ANSWER
371 else
372 echo "** Not a valid product: $ANSWER"
373 fi
374 fi
375 if [ -n "$1" ] ; then
376 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700377 fi
378 done
379
380 set_stuff_for_environment
381}
382
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800383function choosevariant()
384{
385 echo "Variant choices are:"
386 local index=1
387 local v
388 for v in ${VARIANT_CHOICES[@]}
389 do
390 # The product name is the name of the directory containing
391 # the makefile we found, above.
392 echo " $index. $v"
393 index=$(($index+1))
394 done
395
396 local default_value=eng
397 local ANSWER
398
399 export TARGET_BUILD_VARIANT=
400 while [ -z "$TARGET_BUILD_VARIANT" ]
401 do
402 echo -n "Which would you like? [$default_value] "
403 if [ -z "$1" ] ; then
404 read ANSWER
405 else
406 echo $1
407 ANSWER=$1
408 fi
409
410 if [ -z "$ANSWER" ] ; then
411 export TARGET_BUILD_VARIANT=$default_value
412 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
413 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800414 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800415 fi
416 else
417 if check_variant $ANSWER
418 then
419 export TARGET_BUILD_VARIANT=$ANSWER
420 else
421 echo "** Not a valid variant: $ANSWER"
422 fi
423 fi
424 if [ -n "$1" ] ; then
425 break
426 fi
427 done
428}
429
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700430function choosecombo()
431{
432 choosesim $1
433
434 echo
435 echo
436 choosetype $2
437
438 echo
439 echo
440 chooseproduct $3
441
442 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800443 echo
444 choosevariant $4
445
446 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700447 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800448 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700449}
450
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800451# Clear this variable. It will be built up again when the vendorsetup.sh
452# files are included at the end of this file.
453unset LUNCH_MENU_CHOICES
454function add_lunch_combo()
455{
456 local new_combo=$1
457 local c
458 for c in ${LUNCH_MENU_CHOICES[@]} ; do
459 if [ "$new_combo" = "$c" ] ; then
460 return
461 fi
462 done
463 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
464}
465
466# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700467add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700468add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800469add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800470
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471function print_lunch_menu()
472{
473 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474 echo
475 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700476 echo
477 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800478
479 local i=1
480 local choice
481 for choice in ${LUNCH_MENU_CHOICES[@]}
482 do
483 echo " $i. $choice"
484 i=$(($i+1))
485 done
486
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700487 echo
488}
489
490function lunch()
491{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492 local answer
493
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700494 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800495 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700496 else
497 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700498 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700500 fi
501
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800502 local selection=
503
504 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700505 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700506 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507 elif [ "$answer" = "simulator" ]
508 then
509 selection=simulator
510 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
511 then
512 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
513 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800514 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800515 fi
516 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
517 then
518 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700519 fi
520
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521 if [ -z "$selection" ]
522 then
523 echo
524 echo "Invalid lunch combo: $answer"
525 return 1
526 fi
527
Joe Onoratoda12daf2010-06-09 18:18:31 -0700528 export TARGET_BUILD_APPS=
529
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530 # special case the simulator
531 if [ "$selection" = "simulator" ]
532 then
533 export TARGET_PRODUCT=sim
534 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700535 export TARGET_SIMULATOR=true
536 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800537 else
538 local product=$(echo -n $selection | sed -e "s/-.*$//")
539 check_product $product
540 if [ $? -ne 0 ]
541 then
542 echo
543 echo "** Don't have a product spec for: '$product'"
544 echo "** Do you have the right repo manifest?"
545 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700546 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800547
548 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
549 check_variant $variant
550 if [ $? -ne 0 ]
551 then
552 echo
553 echo "** Invalid variant: '$variant'"
554 echo "** Must be one of ${VARIANT_CHOICES[@]}"
555 variant=
556 fi
557
558 if [ -z "$product" -o -z "$variant" ]
559 then
560 echo
561 return 1
562 fi
563
564 export TARGET_PRODUCT=$product
565 export TARGET_BUILD_VARIANT=$variant
566 export TARGET_SIMULATOR=false
567 export TARGET_BUILD_TYPE=release
568 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700569
570 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800571
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700572 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800573 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700574}
575
Joe Onoratoda12daf2010-06-09 18:18:31 -0700576# Configures the build to build unbundled apps.
577# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
578function tapas()
579{
580 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
581 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
582
583 if [ $(echo $variant | wc -w) -gt 1 ]; then
584 echo "tapas: Error: Multiple build variants supplied: $variant"
585 return
586 fi
587 if [ -z "$variant" ]; then
588 variant=eng
589 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700590 if [ -z "$apps" ]; then
591 apps=all
592 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700593
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700594 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700595 export TARGET_BUILD_VARIANT=$variant
596 export TARGET_SIMULATOR=false
597 export TARGET_BUILD_TYPE=release
598 export TARGET_BUILD_APPS=$apps
599
600 set_stuff_for_environment
601 printconfig
602}
603
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604function gettop
605{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800606 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700607 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
608 echo $TOP
609 else
610 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800611 # The following circumlocution (repeated below as well) ensures
612 # that we record the true directory name and not one that is
613 # faked up with symlink names.
614 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700615 else
616 # We redirect cd to /dev/null in case it's aliased to
617 # a command that prints something as a side-effect
618 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800619 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700620 T=
621 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
622 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800623 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700624 done
625 cd $HERE > /dev/null
626 if [ -f "$T/$TOPFILE" ]; then
627 echo $T
628 fi
629 fi
630 fi
631}
632
633function m()
634{
635 T=$(gettop)
636 if [ "$T" ]; then
637 make -C $T $@
638 else
639 echo "Couldn't locate the top of the tree. Try setting TOP."
640 fi
641}
642
643function findmakefile()
644{
645 TOPFILE=build/core/envsetup.mk
646 # We redirect cd to /dev/null in case it's aliased to
647 # a command that prints something as a side-effect
648 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800649 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700650 T=
651 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
652 T=$PWD
653 if [ -f "$T/Android.mk" ]; then
654 echo $T/Android.mk
655 cd $HERE > /dev/null
656 return
657 fi
658 cd .. > /dev/null
659 done
660 cd $HERE > /dev/null
661}
662
663function mm()
664{
665 # If we're sitting in the root of the build tree, just do a
666 # normal make.
667 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
668 make $@
669 else
670 # Find the closest Android.mk file.
671 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800672 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700673 # Remove the path to top as the makefilepath needs to be relative
674 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700675 if [ ! "$T" ]; then
676 echo "Couldn't locate the top of the tree. Try setting TOP."
677 elif [ ! "$M" ]; then
678 echo "Couldn't locate a makefile from the current directory."
679 else
Ying Wang01884142010-07-20 16:18:16 -0700680 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700681 fi
682 fi
683}
684
685function mmm()
686{
687 T=$(gettop)
688 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800689 local MAKEFILE=
690 local ARGS=
691 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800692 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
693 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
694 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700695 DIR=`echo $DIR | sed -e 's:/$::'`
696 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700697 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700698 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800699 START=`PWD= /bin/pwd`
700 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700701 if [ "$MFILE" = "" ] ; then
702 MFILE=$DIR/Android.mk
703 else
704 MFILE=$MFILE/$DIR/Android.mk
705 fi
706 MAKEFILE="$MAKEFILE $MFILE"
707 else
708 if [ "$DIR" = snod ]; then
709 ARGS="$ARGS snod"
710 elif [ "$DIR" = showcommands ]; then
711 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700712 elif [ "$DIR" = dist ]; then
713 ARGS="$ARGS dist"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700714 else
715 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400716 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700717 fi
718 fi
719 done
Ying Wang01884142010-07-20 16:18:16 -0700720 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700721 else
722 echo "Couldn't locate the top of the tree. Try setting TOP."
723 fi
724}
725
726function croot()
727{
728 T=$(gettop)
729 if [ "$T" ]; then
730 cd $(gettop)
731 else
732 echo "Couldn't locate the top of the tree. Try setting TOP."
733 fi
734}
735
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700736function cproj()
737{
738 TOPFILE=build/core/envsetup.mk
739 # We redirect cd to /dev/null in case it's aliased to
740 # a command that prints something as a side-effect
741 # (like pushd)
742 local HERE=$PWD
743 T=
744 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
745 T=$PWD
746 if [ -f "$T/Android.mk" ]; then
747 cd $T
748 return
749 fi
750 cd .. > /dev/null
751 done
752 cd $HERE > /dev/null
753 echo "can't find Android.mk"
754}
755
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700756function pid()
757{
758 local EXE="$1"
759 if [ "$EXE" ] ; then
760 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
761 echo "$PID"
762 else
763 echo "usage: pid name"
764 fi
765}
766
Christopher Tate744ee802009-11-12 15:33:08 -0800767# systemstack - dump the current stack trace of all threads in the system process
768# to the usual ANR traces file
769function systemstack()
770{
771 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
772}
773
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700774function gdbclient()
775{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800776 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
777 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
778 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
779 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
780 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700781 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
782 local EXE="$1"
783 if [ "$EXE" ] ; then
784 EXE=$1
785 else
786 EXE="app_process"
787 fi
788
789 local PORT="$2"
790 if [ "$PORT" ] ; then
791 PORT=$2
792 else
793 PORT=":5039"
794 fi
795
796 local PID
797 local PROG="$3"
798 if [ "$PROG" ] ; then
799 PID=`pid $3`
800 adb forward "tcp$PORT" "tcp$PORT"
801 adb shell gdbserver $PORT --attach $PID &
802 sleep 2
803 else
804 echo ""
805 echo "If you haven't done so already, do this first on the device:"
806 echo " gdbserver $PORT /system/bin/$EXE"
807 echo " or"
808 echo " gdbserver $PORT --attach $PID"
809 echo ""
810 fi
811
812 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
813 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
814 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
815 echo >>"$OUT_ROOT/gdbclient.cmds" ""
816
817 arm-eabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
818 else
819 echo "Unable to determine build system output dir."
820 fi
821
822}
823
824case `uname -s` in
825 Darwin)
826 function sgrep()
827 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100828 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 -0700829 }
830
831 ;;
832 *)
833 function sgrep()
834 {
Benno Leslie5ef878a2009-02-27 21:04:08 +1100835 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 -0700836 }
837 ;;
838esac
839
840function jgrep()
841{
842 find . -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
843}
844
845function cgrep()
846{
Ficus Kirkpatrick8889bdf2010-03-01 16:51:47 -0800847 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 -0700848}
849
850function resgrep()
851{
852 for dir in `find . -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
853}
854
855case `uname -s` in
856 Darwin)
857 function mgrep()
858 {
859 find -E . -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
860 }
861
862 function treegrep()
863 {
864 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
865 }
866
867 ;;
868 *)
869 function mgrep()
870 {
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800871 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 -0700872 }
873
874 function treegrep()
875 {
876 find . -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
877 }
878
879 ;;
880esac
881
882function getprebuilt
883{
884 get_abs_build_var ANDROID_PREBUILTS
885}
886
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700887function tracedmdump()
888{
889 T=$(gettop)
890 if [ ! "$T" ]; then
891 echo "Couldn't locate the top of the tree. Try setting TOP."
892 return
893 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800894 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700895 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700896
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800897 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700898 if [ ! "$TRACE" ] ; then
899 echo "usage: tracedmdump tracename"
900 return
901 fi
902
Jack Veenstra60116fc2009-04-09 18:12:34 -0700903 if [ ! -r "$KERNEL" ] ; then
904 echo "Error: cannot find kernel: '$KERNEL'"
905 return
906 fi
907
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800908 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700909 if [ "$BASETRACE" = "$TRACE" ] ; then
910 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
911 fi
912
913 echo "post-processing traces..."
914 rm -f $TRACE/qtrace.dexlist
915 post_trace $TRACE
916 if [ $? -ne 0 ]; then
917 echo "***"
918 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
919 echo "***"
920 return
921 fi
922 echo "generating dexlist output..."
923 /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
924 echo "generating dmtrace data..."
925 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
926 echo "generating html file..."
927 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
928 echo "done, see $TRACE/dmtrace.html for details"
929 echo "or run:"
930 echo " traceview $TRACE/dmtrace"
931}
932
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800933# communicate with a running device or emulator, set up necessary state,
934# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700935function runhat()
936{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800937 # process standard adb options
938 local adbTarget=""
Chris Dearmanf0bcf422011-02-16 12:16:09 -0800939 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800940 adbTarget=$1
941 shift 1
Chris Dearmanf0bcf422011-02-16 12:16:09 -0800942 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800943 adbTarget="$1 $2"
944 shift 2
945 fi
946 local adbOptions=${adbTarget}
947 echo adbOptions = ${adbOptions}
948
949 # runhat options
950 local targetPid=$1
951 local outputFile=$2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700952
953 if [ "$targetPid" = "" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800954 echo "Usage: runhat [ -d | -e | -s serial ] target-pid [output-file]"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700955 return
956 fi
957
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800958 # confirm hat is available
959 if [ -z $(which hat) ]; then
960 echo "hat is not available in this configuration."
961 return
962 fi
963
964 adb ${adbOptions} shell >/dev/null mkdir /data/misc
965 adb ${adbOptions} shell chmod 777 /data/misc
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966
The Android Open Source Project88b60792009-03-03 19:28:42 -0800967 # send a SIGUSR1 to cause the hprof dump
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700968 echo "Poking $targetPid and waiting for data..."
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800969 adb ${adbOptions} shell kill -10 $targetPid
The Android Open Source Project88b60792009-03-03 19:28:42 -0800970 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700971 echo -n "> "
972 read
973
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800974 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 -0800975 local devFile=/data/misc/${availFiles[0]}
976 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700977
The Android Open Source Project88b60792009-03-03 19:28:42 -0800978 echo "Retrieving file $devFile..."
979 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700980
The Android Open Source Project88b60792009-03-03 19:28:42 -0800981 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700982
The Android Open Source Project88b60792009-03-03 19:28:42 -0800983 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700984 echo "View the output by pointing your browser at http://localhost:7000/"
985 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800986 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700987}
988
989function getbugreports()
990{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800991 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700992
993 if [ ! "$reports" ]; then
994 echo "Could not locate any bugreports."
995 return
996 fi
997
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800998 local report
999 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001000 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001001 echo "/sdcard/bugreports/${report}"
1002 adb pull /sdcard/bugreports/${report} ${report}
1003 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001004 done
1005}
1006
1007function startviewserver()
1008{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001009 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001010 if [ $# -gt 0 ]; then
1011 port=$1
1012 fi
1013 adb shell service call window 1 i32 $port
1014}
1015
1016function stopviewserver()
1017{
1018 adb shell service call window 2
1019}
1020
1021function isviewserverstarted()
1022{
1023 adb shell service call window 3
1024}
1025
1026function smoketest()
1027{
1028 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1029 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1030 return
1031 fi
1032 T=$(gettop)
1033 if [ ! "$T" ]; then
1034 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1035 return
1036 fi
1037
1038 (cd "$T" && mmm tests/SmokeTest) &&
1039 adb uninstall com.android.smoketest > /dev/null &&
1040 adb uninstall com.android.smoketest.tests > /dev/null &&
1041 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1042 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1043 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1044}
1045
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001046# simple shortcut to the runtest command
1047function runtest()
1048{
1049 T=$(gettop)
1050 if [ ! "$T" ]; then
1051 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1052 return
1053 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001054 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001055}
1056
The Android Open Source Project88b60792009-03-03 19:28:42 -08001057function godir () {
1058 if [[ -z "$1" ]]; then
1059 echo "Usage: godir <regex>"
1060 return
1061 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001062 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001063 if [[ ! -f $T/filelist ]]; then
1064 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001065 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001066 echo " Done"
1067 echo ""
1068 fi
1069 local lines
1070 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1071 if [[ ${#lines[@]} = 0 ]]; then
1072 echo "Not found"
1073 return
1074 fi
1075 local pathname
1076 local choice
1077 if [[ ${#lines[@]} > 1 ]]; then
1078 while [[ -z "$pathname" ]]; do
1079 local index=1
1080 local line
1081 for line in ${lines[@]}; do
1082 printf "%6s %s\n" "[$index]" $line
1083 index=$(($index + 1))
1084 done
1085 echo
1086 echo -n "Select one: "
1087 unset choice
1088 read choice
1089 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1090 echo "Invalid choice"
1091 continue
1092 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001093 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001094 done
1095 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001096 pathname=${lines[0]}
1097 fi
1098 cd $T/$pathname
1099}
1100
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001101# Force JAVA_HOME to point to java 1.6 if it isn't already set
1102function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001103 if [ ! "$JAVA_HOME" ]; then
1104 case `uname -s` in
1105 Darwin)
1106 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1107 ;;
1108 *)
1109 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1110 ;;
1111 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001112 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001113}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001114
Raphael Moll70a86b02011-06-20 16:03:14 -07001115if [ "x$SHELL" != "x/bin/bash" ]; then
1116 case `ps -o command -p $$` in
1117 *bash*)
1118 ;;
1119 *)
1120 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1121 ;;
1122 esac
1123fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001124
1125# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001126for 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 -08001127do
1128 echo "including $f"
1129 . $f
1130done
1131unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001132
1133addcompletions