blob: a845a18f4d4e8571372c895f2dc4d172ebbe1e0f [file] [log] [blame]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001function help() {
2cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07004- croot: Changes directory to the top of the tree.
5- m: Makes from the top of the tree.
6- mm: Builds all of the modules in the current directory.
7- mmm: Builds all of the modules in the supplied directories.
8- cgrep: Greps on all local C/C++ files.
9- jgrep: Greps on all local Java files.
10- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080011- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070012
13Look at the source to view more functions. The complete list is:
14EOF
15 T=$(gettop)
16 local A
17 A=""
18 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
19 A="$A $i"
20 done
21 echo $A
22}
23
24# Get the value of a build variable as an absolute path.
25function get_abs_build_var()
26{
27 T=$(gettop)
28 if [ ! "$T" ]; then
29 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
30 return
31 fi
Brian Carlstrom177285a2010-04-06 13:22:02 -070032 (cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
33 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070034}
35
36# Get the exact value of a build variable.
37function get_build_var()
38{
39 T=$(gettop)
40 if [ ! "$T" ]; then
41 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
42 return
43 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080044 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
45 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1
46}
47
48# check to see if the supplied product is one we can build
49function check_product()
50{
51 T=$(gettop)
52 if [ ! "$T" ]; then
53 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
54 return
55 fi
56 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
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
Doug Zongker29034982011-04-22 08:16:56 -0700106 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
107 # strip trailing ':', if any
108 export PATH=${PATH/%:/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500109 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700110
111 # and in with the new
112 CODE_REVIEWS=
113 prebuiltdir=$(getprebuilt)
Raphael732936d2011-06-22 14:35:32 -0700114
Raphael Mollc639c782011-06-20 17:25:01 -0700115 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Raphael732936d2011-06-22 14:35:32 -0700116 export ANDROID_EABI_TOOLCHAIN=
117 toolchaindir=toolchain/arm-linux-androideabi-4.4.x/bin
Raphael Mollc639c782011-06-20 17:25:01 -0700118 if [ -d "$prebuiltdir/$toolchaindir" ]; then
119 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700120 fi
Raphael732936d2011-06-22 14:35:32 -0700121
122 export ARM_EABI_TOOLCHAIN=
123 toolchaindir=toolchain/arm-eabi-4.4.3/bin
124 if [ -d "$prebuiltdir/$toolchaindir" ]; then
125 export ARM_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
126 fi
127
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700128 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
129 export ANDROID_QTOOLS=$T/development/emulator/qtools
Jing Yu9d396e32010-07-29 15:07:31 -0700130 export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ARM_EABI_TOOLCHAIN$CODE_REVIEWS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700131 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800132
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500133 unset ANDROID_JAVA_TOOLCHAIN
134 if [ -n "$JAVA_HOME" ]; then
135 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
136 fi
137 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN
138 if [ -n "$ANDROID_PRE_BUILD_PATHS" ]; then
139 export PATH=$ANDROID_PRE_BUILD_PATHS:$PATH
140 fi
141
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800142 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700143 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
144 export OUT=$ANDROID_PRODUCT_OUT
145
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700146 unset ANDROID_HOST_OUT
147 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
148
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800149 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700150 # TODO: fix the path
151 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
152}
153
154function printconfig()
155{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800156 T=$(gettop)
157 if [ ! "$T" ]; then
158 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
159 return
160 fi
161 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700162}
163
164function set_stuff_for_environment()
165{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800166 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500167 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800168 setpaths
169 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700170
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800171 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700172}
173
174function set_sequence_number()
175{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700176 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700177}
178
179function settitle()
180{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800181 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700182 local product=$TARGET_PRODUCT
183 local variant=$TARGET_BUILD_VARIANT
184 local apps=$TARGET_BUILD_APPS
185 if [ -z "$apps" ]; then
186 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
187 else
188 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
189 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800190 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700191}
192
193case `uname -s` in
194 Linux)
195 function choosesim()
196 {
197 echo "Build for the simulator or the device?"
198 echo " 1. Device"
199 echo " 2. Simulator"
200 echo
201
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800202 export TARGET_SIMULATOR=
203 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700204 while [ -z $TARGET_SIMULATOR ]
205 do
206 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800207 if [ -z "$1" ] ; then
208 read ANSWER
209 else
210 echo $1
211 ANSWER=$1
212 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700213 case $ANSWER in
214 "")
215 export TARGET_SIMULATOR=false
216 ;;
217 1)
218 export TARGET_SIMULATOR=false
219 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800220 Device)
221 export TARGET_SIMULATOR=false
222 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700223 2)
224 export TARGET_SIMULATOR=true
225 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800226 Simulator)
227 export TARGET_SIMULATOR=true
228 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700229 *)
230 echo
231 echo "I didn't understand your response. Please try again."
232 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700233 ;;
234 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800235 if [ -n "$1" ] ; then
236 break
237 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700238 done
239
240 set_stuff_for_environment
241 }
242 ;;
243 *)
244 function choosesim()
245 {
246 echo "Only device builds are supported for" `uname -s`
247 echo " Forcing TARGET_SIMULATOR=false"
248 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800249 if [ -z "$1" ]
250 then
251 echo -n "Press enter: "
252 read
253 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700254
255 export TARGET_SIMULATOR=false
256 set_stuff_for_environment
257 }
258 ;;
259esac
260
261function choosetype()
262{
263 echo "Build type choices are:"
264 echo " 1. release"
265 echo " 2. debug"
266 echo
267
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800268 local DEFAULT_NUM DEFAULT_VALUE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700269 if [ $TARGET_SIMULATOR = "false" ] ; then
270 DEFAULT_NUM=1
271 DEFAULT_VALUE=release
272 else
273 DEFAULT_NUM=2
274 DEFAULT_VALUE=debug
275 fi
276
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800277 export TARGET_BUILD_TYPE=
278 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700279 while [ -z $TARGET_BUILD_TYPE ]
280 do
281 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800282 if [ -z "$1" ] ; then
283 read ANSWER
284 else
285 echo $1
286 ANSWER=$1
287 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700288 case $ANSWER in
289 "")
290 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
291 ;;
292 1)
293 export TARGET_BUILD_TYPE=release
294 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800295 release)
296 export TARGET_BUILD_TYPE=release
297 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700298 2)
299 export TARGET_BUILD_TYPE=debug
300 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800301 debug)
302 export TARGET_BUILD_TYPE=debug
303 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700304 *)
305 echo
306 echo "I didn't understand your response. Please try again."
307 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700308 ;;
309 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800310 if [ -n "$1" ] ; then
311 break
312 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700313 done
314
315 set_stuff_for_environment
316}
317
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800318#
319# This function isn't really right: It chooses a TARGET_PRODUCT
320# based on the list of boards. Usually, that gets you something
321# that kinda works with a generic product, but really, you should
322# pick a product by name.
323#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700324function chooseproduct()
325{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700326 if [ "x$TARGET_PRODUCT" != x ] ; then
327 default_value=$TARGET_PRODUCT
328 else
329 if [ "$TARGET_SIMULATOR" = true ] ; then
330 default_value=sim
331 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700332 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700333 fi
334 fi
335
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336 export TARGET_PRODUCT=
337 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338 while [ -z "$TARGET_PRODUCT" ]
339 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700340 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800341 if [ -z "$1" ] ; then
342 read ANSWER
343 else
344 echo $1
345 ANSWER=$1
346 fi
347
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700348 if [ -z "$ANSWER" ] ; then
349 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800350 else
351 if check_product $ANSWER
352 then
353 export TARGET_PRODUCT=$ANSWER
354 else
355 echo "** Not a valid product: $ANSWER"
356 fi
357 fi
358 if [ -n "$1" ] ; then
359 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700360 fi
361 done
362
363 set_stuff_for_environment
364}
365
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800366function choosevariant()
367{
368 echo "Variant choices are:"
369 local index=1
370 local v
371 for v in ${VARIANT_CHOICES[@]}
372 do
373 # The product name is the name of the directory containing
374 # the makefile we found, above.
375 echo " $index. $v"
376 index=$(($index+1))
377 done
378
379 local default_value=eng
380 local ANSWER
381
382 export TARGET_BUILD_VARIANT=
383 while [ -z "$TARGET_BUILD_VARIANT" ]
384 do
385 echo -n "Which would you like? [$default_value] "
386 if [ -z "$1" ] ; then
387 read ANSWER
388 else
389 echo $1
390 ANSWER=$1
391 fi
392
393 if [ -z "$ANSWER" ] ; then
394 export TARGET_BUILD_VARIANT=$default_value
395 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
396 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800397 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800398 fi
399 else
400 if check_variant $ANSWER
401 then
402 export TARGET_BUILD_VARIANT=$ANSWER
403 else
404 echo "** Not a valid variant: $ANSWER"
405 fi
406 fi
407 if [ -n "$1" ] ; then
408 break
409 fi
410 done
411}
412
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700413function choosecombo()
414{
415 choosesim $1
416
417 echo
418 echo
419 choosetype $2
420
421 echo
422 echo
423 chooseproduct $3
424
425 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800426 echo
427 choosevariant $4
428
429 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700430 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800431 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700432}
433
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800434# Clear this variable. It will be built up again when the vendorsetup.sh
435# files are included at the end of this file.
436unset LUNCH_MENU_CHOICES
437function add_lunch_combo()
438{
439 local new_combo=$1
440 local c
441 for c in ${LUNCH_MENU_CHOICES[@]} ; do
442 if [ "$new_combo" = "$c" ] ; then
443 return
444 fi
445 done
446 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
447}
448
449# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700450add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700451add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800452add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800453
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700454function print_lunch_menu()
455{
456 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700457 echo
458 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700459 echo
460 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800461
462 local i=1
463 local choice
464 for choice in ${LUNCH_MENU_CHOICES[@]}
465 do
466 echo " $i. $choice"
467 i=$(($i+1))
468 done
469
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470 echo
471}
472
473function lunch()
474{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800475 local answer
476
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700477 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800478 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700479 else
480 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700481 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483 fi
484
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800485 local selection=
486
487 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700488 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700489 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490 elif [ "$answer" = "simulator" ]
491 then
492 selection=simulator
493 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
494 then
495 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
496 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800497 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800498 fi
499 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
500 then
501 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700502 fi
503
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 if [ -z "$selection" ]
505 then
506 echo
507 echo "Invalid lunch combo: $answer"
508 return 1
509 fi
510
Joe Onoratoda12daf2010-06-09 18:18:31 -0700511 export TARGET_BUILD_APPS=
512
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800513 # special case the simulator
514 if [ "$selection" = "simulator" ]
515 then
516 export TARGET_PRODUCT=sim
517 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700518 export TARGET_SIMULATOR=true
519 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520 else
521 local product=$(echo -n $selection | sed -e "s/-.*$//")
522 check_product $product
523 if [ $? -ne 0 ]
524 then
525 echo
526 echo "** Don't have a product spec for: '$product'"
527 echo "** Do you have the right repo manifest?"
528 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700529 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530
531 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
532 check_variant $variant
533 if [ $? -ne 0 ]
534 then
535 echo
536 echo "** Invalid variant: '$variant'"
537 echo "** Must be one of ${VARIANT_CHOICES[@]}"
538 variant=
539 fi
540
541 if [ -z "$product" -o -z "$variant" ]
542 then
543 echo
544 return 1
545 fi
546
547 export TARGET_PRODUCT=$product
548 export TARGET_BUILD_VARIANT=$variant
549 export TARGET_SIMULATOR=false
550 export TARGET_BUILD_TYPE=release
551 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700552
553 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800554
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700555 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800556 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700557}
558
Jeff Davidson513d7a42010-08-02 10:00:44 -0700559# Tab completion for lunch.
560function _lunch()
561{
562 local cur prev opts
563 COMPREPLY=()
564 cur="${COMP_WORDS[COMP_CWORD]}"
565 prev="${COMP_WORDS[COMP_CWORD-1]}"
566
567 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
568 return 0
569}
570complete -F _lunch lunch
571
Joe Onoratoda12daf2010-06-09 18:18:31 -0700572# Configures the build to build unbundled apps.
573# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
574function tapas()
575{
576 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
577 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
578
579 if [ $(echo $variant | wc -w) -gt 1 ]; then
580 echo "tapas: Error: Multiple build variants supplied: $variant"
581 return
582 fi
583 if [ -z "$variant" ]; then
584 variant=eng
585 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700586 if [ -z "$apps" ]; then
587 apps=all
588 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700589
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700590 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700591 export TARGET_BUILD_VARIANT=$variant
592 export TARGET_SIMULATOR=false
593 export TARGET_BUILD_TYPE=release
594 export TARGET_BUILD_APPS=$apps
595
596 set_stuff_for_environment
597 printconfig
598}
599
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700600function gettop
601{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800602 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700603 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
604 echo $TOP
605 else
606 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800607 # The following circumlocution (repeated below as well) ensures
608 # that we record the true directory name and not one that is
609 # faked up with symlink names.
610 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700611 else
612 # We redirect cd to /dev/null in case it's aliased to
613 # a command that prints something as a side-effect
614 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800615 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700616 T=
617 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
618 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800619 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700620 done
621 cd $HERE > /dev/null
622 if [ -f "$T/$TOPFILE" ]; then
623 echo $T
624 fi
625 fi
626 fi
627}
628
629function m()
630{
631 T=$(gettop)
632 if [ "$T" ]; then
633 make -C $T $@
634 else
635 echo "Couldn't locate the top of the tree. Try setting TOP."
636 fi
637}
638
639function findmakefile()
640{
641 TOPFILE=build/core/envsetup.mk
642 # We redirect cd to /dev/null in case it's aliased to
643 # a command that prints something as a side-effect
644 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800645 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700646 T=
647 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
648 T=$PWD
649 if [ -f "$T/Android.mk" ]; then
650 echo $T/Android.mk
651 cd $HERE > /dev/null
652 return
653 fi
654 cd .. > /dev/null
655 done
656 cd $HERE > /dev/null
657}
658
659function mm()
660{
661 # If we're sitting in the root of the build tree, just do a
662 # normal make.
663 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
664 make $@
665 else
666 # Find the closest Android.mk file.
667 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800668 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700669 # Remove the path to top as the makefilepath needs to be relative
670 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700671 if [ ! "$T" ]; then
672 echo "Couldn't locate the top of the tree. Try setting TOP."
673 elif [ ! "$M" ]; then
674 echo "Couldn't locate a makefile from the current directory."
675 else
Ying Wang01884142010-07-20 16:18:16 -0700676 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700677 fi
678 fi
679}
680
681function mmm()
682{
683 T=$(gettop)
684 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800685 local MAKEFILE=
686 local ARGS=
687 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800688 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
689 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
690 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700691 DIR=`echo $DIR | sed -e 's:/$::'`
692 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700693 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700694 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800695 START=`PWD= /bin/pwd`
696 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700697 if [ "$MFILE" = "" ] ; then
698 MFILE=$DIR/Android.mk
699 else
700 MFILE=$MFILE/$DIR/Android.mk
701 fi
702 MAKEFILE="$MAKEFILE $MFILE"
703 else
704 if [ "$DIR" = snod ]; then
705 ARGS="$ARGS snod"
706 elif [ "$DIR" = showcommands ]; then
707 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700708 elif [ "$DIR" = dist ]; then
709 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800710 elif [ "$DIR" = incrementaljavac ]; then
711 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700712 else
713 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400714 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700715 fi
716 fi
717 done
Ying Wang01884142010-07-20 16:18:16 -0700718 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700719 else
720 echo "Couldn't locate the top of the tree. Try setting TOP."
721 fi
722}
723
724function croot()
725{
726 T=$(gettop)
727 if [ "$T" ]; then
728 cd $(gettop)
729 else
730 echo "Couldn't locate the top of the tree. Try setting TOP."
731 fi
732}
733
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700734function cproj()
735{
736 TOPFILE=build/core/envsetup.mk
737 # We redirect cd to /dev/null in case it's aliased to
738 # a command that prints something as a side-effect
739 # (like pushd)
740 local HERE=$PWD
741 T=
742 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
743 T=$PWD
744 if [ -f "$T/Android.mk" ]; then
745 cd $T
746 return
747 fi
748 cd .. > /dev/null
749 done
750 cd $HERE > /dev/null
751 echo "can't find Android.mk"
752}
753
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700754function pid()
755{
756 local EXE="$1"
757 if [ "$EXE" ] ; then
758 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
759 echo "$PID"
760 else
761 echo "usage: pid name"
762 fi
763}
764
Christopher Tate744ee802009-11-12 15:33:08 -0800765# systemstack - dump the current stack trace of all threads in the system process
766# to the usual ANR traces file
767function systemstack()
768{
769 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
770}
771
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700772function gdbclient()
773{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800774 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
775 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
776 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
777 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
778 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
780 local EXE="$1"
781 if [ "$EXE" ] ; then
782 EXE=$1
783 else
784 EXE="app_process"
785 fi
786
787 local PORT="$2"
788 if [ "$PORT" ] ; then
789 PORT=$2
790 else
791 PORT=":5039"
792 fi
793
794 local PID
795 local PROG="$3"
796 if [ "$PROG" ] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700797 if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
798 PID="$3"
799 else
800 PID=`pid $3`
801 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700802 adb forward "tcp$PORT" "tcp$PORT"
803 adb shell gdbserver $PORT --attach $PID &
804 sleep 2
805 else
806 echo ""
807 echo "If you haven't done so already, do this first on the device:"
808 echo " gdbserver $PORT /system/bin/$EXE"
809 echo " or"
810 echo " gdbserver $PORT --attach $PID"
811 echo ""
812 fi
813
814 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
815 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
816 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
817 echo >>"$OUT_ROOT/gdbclient.cmds" ""
818
Jing Yu9d396e32010-07-29 15:07:31 -0700819 arm-linux-androideabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700820 else
821 echo "Unable to determine build system output dir."
822 fi
823
824}
825
826case `uname -s` in
827 Darwin)
828 function sgrep()
829 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700830 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml|sh|mk)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700831 }
832
833 ;;
834 *)
835 function sgrep()
836 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700837 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cpp\|S\|java\|xml\|sh\|mk\)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700838 }
839 ;;
840esac
841
842function jgrep()
843{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700844 find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845}
846
847function cgrep()
848{
Mike Dodd0c26d342011-04-07 13:29:06 -0700849 find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850}
851
852function resgrep()
853{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700854 for dir in `find . -name .repo -prune -o -name .git -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855}
856
857case `uname -s` in
858 Darwin)
859 function mgrep()
860 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700861 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700862 }
863
864 function treegrep()
865 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700866 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700867 }
868
869 ;;
870 *)
871 function mgrep()
872 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700873 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700874 }
875
876 function treegrep()
877 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700878 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700879 }
880
881 ;;
882esac
883
884function getprebuilt
885{
886 get_abs_build_var ANDROID_PREBUILTS
887}
888
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700889function tracedmdump()
890{
891 T=$(gettop)
892 if [ ! "$T" ]; then
893 echo "Couldn't locate the top of the tree. Try setting TOP."
894 return
895 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800896 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700897 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700898
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800899 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700900 if [ ! "$TRACE" ] ; then
901 echo "usage: tracedmdump tracename"
902 return
903 fi
904
Jack Veenstra60116fc2009-04-09 18:12:34 -0700905 if [ ! -r "$KERNEL" ] ; then
906 echo "Error: cannot find kernel: '$KERNEL'"
907 return
908 fi
909
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800910 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700911 if [ "$BASETRACE" = "$TRACE" ] ; then
912 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
913 fi
914
915 echo "post-processing traces..."
916 rm -f $TRACE/qtrace.dexlist
917 post_trace $TRACE
918 if [ $? -ne 0 ]; then
919 echo "***"
920 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
921 echo "***"
922 return
923 fi
924 echo "generating dexlist output..."
925 /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
926 echo "generating dmtrace data..."
927 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
928 echo "generating html file..."
929 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
930 echo "done, see $TRACE/dmtrace.html for details"
931 echo "or run:"
932 echo " traceview $TRACE/dmtrace"
933}
934
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800935# communicate with a running device or emulator, set up necessary state,
936# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700937function runhat()
938{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800939 # process standard adb options
940 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700941 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800942 adbTarget=$1
943 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700944 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800945 adbTarget="$1 $2"
946 shift 2
947 fi
948 local adbOptions=${adbTarget}
949 echo adbOptions = ${adbOptions}
950
951 # runhat options
952 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700953
954 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700955 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700956 return
957 fi
958
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800959 # confirm hat is available
960 if [ -z $(which hat) ]; then
961 echo "hat is not available in this configuration."
962 return
963 fi
964
Andy McFaddenb6289852010-07-12 08:00:19 -0700965 # issue "am" command to cause the hprof dump
966 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700968 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800969 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700970 echo -n "> "
971 read
972
The Android Open Source Project88b60792009-03-03 19:28:42 -0800973 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
Romain Guyb84049a2010-10-04 16:56:11 -07001023function key_home()
1024{
1025 adb shell input keyevent 3
1026}
1027
1028function key_back()
1029{
1030 adb shell input keyevent 4
1031}
1032
1033function key_menu()
1034{
1035 adb shell input keyevent 82
1036}
1037
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001038function smoketest()
1039{
1040 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1041 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1042 return
1043 fi
1044 T=$(gettop)
1045 if [ ! "$T" ]; then
1046 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1047 return
1048 fi
1049
1050 (cd "$T" && mmm tests/SmokeTest) &&
1051 adb uninstall com.android.smoketest > /dev/null &&
1052 adb uninstall com.android.smoketest.tests > /dev/null &&
1053 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1054 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1055 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1056}
1057
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001058# simple shortcut to the runtest command
1059function runtest()
1060{
1061 T=$(gettop)
1062 if [ ! "$T" ]; then
1063 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1064 return
1065 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001066 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001067}
1068
The Android Open Source Project88b60792009-03-03 19:28:42 -08001069function godir () {
1070 if [[ -z "$1" ]]; then
1071 echo "Usage: godir <regex>"
1072 return
1073 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001074 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001075 if [[ ! -f $T/filelist ]]; then
1076 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001077 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001078 echo " Done"
1079 echo ""
1080 fi
1081 local lines
Doug Zongker29034982011-04-22 08:16:56 -07001082 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001083 if [[ ${#lines[@]} = 0 ]]; then
1084 echo "Not found"
1085 return
1086 fi
1087 local pathname
1088 local choice
1089 if [[ ${#lines[@]} > 1 ]]; then
1090 while [[ -z "$pathname" ]]; do
1091 local index=1
1092 local line
1093 for line in ${lines[@]}; do
1094 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001095 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001096 done
1097 echo
1098 echo -n "Select one: "
1099 unset choice
1100 read choice
1101 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1102 echo "Invalid choice"
1103 continue
1104 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001105 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001106 done
1107 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001108 pathname=${lines[0]}
1109 fi
1110 cd $T/$pathname
1111}
1112
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001113# Force JAVA_HOME to point to java 1.6 if it isn't already set
1114function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001115 if [ ! "$JAVA_HOME" ]; then
1116 case `uname -s` in
1117 Darwin)
1118 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1119 ;;
1120 *)
1121 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1122 ;;
1123 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001124 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001125}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001126
Raphael Moll70a86b02011-06-20 16:03:14 -07001127if [ "x$SHELL" != "x/bin/bash" ]; then
1128 case `ps -o command -p $$` in
1129 *bash*)
1130 ;;
1131 *)
1132 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1133 ;;
1134 esac
1135fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001136
1137# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001138for 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 -08001139do
1140 echo "including $f"
1141 . $f
1142done
1143unset f