blob: a9417b8d52edb12054000b5e438b964a31febc3b [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
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900134 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500135 if [ -n "$JAVA_HOME" ]; then
136 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900137 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
138 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500139 fi
140
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800141 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700142 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
143 export OUT=$ANDROID_PRODUCT_OUT
144
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700145 unset ANDROID_HOST_OUT
146 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
147
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800148 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700149 # TODO: fix the path
150 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
151}
152
153function printconfig()
154{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800155 T=$(gettop)
156 if [ ! "$T" ]; then
157 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
158 return
159 fi
160 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700161}
162
163function set_stuff_for_environment()
164{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800165 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500166 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800167 setpaths
168 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700169
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800170 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700171}
172
173function set_sequence_number()
174{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700175 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700176}
177
178function settitle()
179{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800180 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700181 local product=$TARGET_PRODUCT
182 local variant=$TARGET_BUILD_VARIANT
183 local apps=$TARGET_BUILD_APPS
184 if [ -z "$apps" ]; then
185 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
186 else
187 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
188 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800189 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700190}
191
192case `uname -s` in
193 Linux)
194 function choosesim()
195 {
196 echo "Build for the simulator or the device?"
197 echo " 1. Device"
198 echo " 2. Simulator"
199 echo
200
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800201 export TARGET_SIMULATOR=
202 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700203 while [ -z $TARGET_SIMULATOR ]
204 do
205 echo -n "Which would you like? [1] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800206 if [ -z "$1" ] ; then
207 read ANSWER
208 else
209 echo $1
210 ANSWER=$1
211 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700212 case $ANSWER in
213 "")
214 export TARGET_SIMULATOR=false
215 ;;
216 1)
217 export TARGET_SIMULATOR=false
218 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800219 Device)
220 export TARGET_SIMULATOR=false
221 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700222 2)
223 export TARGET_SIMULATOR=true
224 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800225 Simulator)
226 export TARGET_SIMULATOR=true
227 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700228 *)
229 echo
230 echo "I didn't understand your response. Please try again."
231 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700232 ;;
233 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800234 if [ -n "$1" ] ; then
235 break
236 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700237 done
238
239 set_stuff_for_environment
240 }
241 ;;
242 *)
243 function choosesim()
244 {
245 echo "Only device builds are supported for" `uname -s`
246 echo " Forcing TARGET_SIMULATOR=false"
247 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800248 if [ -z "$1" ]
249 then
250 echo -n "Press enter: "
251 read
252 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700253
254 export TARGET_SIMULATOR=false
255 set_stuff_for_environment
256 }
257 ;;
258esac
259
260function choosetype()
261{
262 echo "Build type choices are:"
263 echo " 1. release"
264 echo " 2. debug"
265 echo
266
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800267 local DEFAULT_NUM DEFAULT_VALUE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700268 if [ $TARGET_SIMULATOR = "false" ] ; then
269 DEFAULT_NUM=1
270 DEFAULT_VALUE=release
271 else
272 DEFAULT_NUM=2
273 DEFAULT_VALUE=debug
274 fi
275
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800276 export TARGET_BUILD_TYPE=
277 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700278 while [ -z $TARGET_BUILD_TYPE ]
279 do
280 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800281 if [ -z "$1" ] ; then
282 read ANSWER
283 else
284 echo $1
285 ANSWER=$1
286 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700287 case $ANSWER in
288 "")
289 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
290 ;;
291 1)
292 export TARGET_BUILD_TYPE=release
293 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800294 release)
295 export TARGET_BUILD_TYPE=release
296 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297 2)
298 export TARGET_BUILD_TYPE=debug
299 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800300 debug)
301 export TARGET_BUILD_TYPE=debug
302 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700303 *)
304 echo
305 echo "I didn't understand your response. Please try again."
306 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700307 ;;
308 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800309 if [ -n "$1" ] ; then
310 break
311 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700312 done
313
314 set_stuff_for_environment
315}
316
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800317#
318# This function isn't really right: It chooses a TARGET_PRODUCT
319# based on the list of boards. Usually, that gets you something
320# that kinda works with a generic product, but really, you should
321# pick a product by name.
322#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700323function chooseproduct()
324{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325 if [ "x$TARGET_PRODUCT" != x ] ; then
326 default_value=$TARGET_PRODUCT
327 else
328 if [ "$TARGET_SIMULATOR" = true ] ; then
329 default_value=sim
330 else
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700331 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332 fi
333 fi
334
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335 export TARGET_PRODUCT=
336 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700337 while [ -z "$TARGET_PRODUCT" ]
338 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700339 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800340 if [ -z "$1" ] ; then
341 read ANSWER
342 else
343 echo $1
344 ANSWER=$1
345 fi
346
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 if [ -z "$ANSWER" ] ; then
348 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800349 else
350 if check_product $ANSWER
351 then
352 export TARGET_PRODUCT=$ANSWER
353 else
354 echo "** Not a valid product: $ANSWER"
355 fi
356 fi
357 if [ -n "$1" ] ; then
358 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700359 fi
360 done
361
362 set_stuff_for_environment
363}
364
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800365function choosevariant()
366{
367 echo "Variant choices are:"
368 local index=1
369 local v
370 for v in ${VARIANT_CHOICES[@]}
371 do
372 # The product name is the name of the directory containing
373 # the makefile we found, above.
374 echo " $index. $v"
375 index=$(($index+1))
376 done
377
378 local default_value=eng
379 local ANSWER
380
381 export TARGET_BUILD_VARIANT=
382 while [ -z "$TARGET_BUILD_VARIANT" ]
383 do
384 echo -n "Which would you like? [$default_value] "
385 if [ -z "$1" ] ; then
386 read ANSWER
387 else
388 echo $1
389 ANSWER=$1
390 fi
391
392 if [ -z "$ANSWER" ] ; then
393 export TARGET_BUILD_VARIANT=$default_value
394 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
395 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800396 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800397 fi
398 else
399 if check_variant $ANSWER
400 then
401 export TARGET_BUILD_VARIANT=$ANSWER
402 else
403 echo "** Not a valid variant: $ANSWER"
404 fi
405 fi
406 if [ -n "$1" ] ; then
407 break
408 fi
409 done
410}
411
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700412function choosecombo()
413{
414 choosesim $1
415
416 echo
417 echo
418 choosetype $2
419
420 echo
421 echo
422 chooseproduct $3
423
424 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800425 echo
426 choosevariant $4
427
428 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700429 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800430 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700431}
432
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800433# Clear this variable. It will be built up again when the vendorsetup.sh
434# files are included at the end of this file.
435unset LUNCH_MENU_CHOICES
436function add_lunch_combo()
437{
438 local new_combo=$1
439 local c
440 for c in ${LUNCH_MENU_CHOICES[@]} ; do
441 if [ "$new_combo" = "$c" ] ; then
442 return
443 fi
444 done
445 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
446}
447
448# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700449add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700450add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800451add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800452
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700453function print_lunch_menu()
454{
455 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700456 echo
457 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458 echo
459 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800460
461 local i=1
462 local choice
463 for choice in ${LUNCH_MENU_CHOICES[@]}
464 do
465 echo " $i. $choice"
466 i=$(($i+1))
467 done
468
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700469 echo
470}
471
472function lunch()
473{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800474 local answer
475
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700476 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478 else
479 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700480 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800481 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700482 fi
483
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800484 local selection=
485
486 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700487 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700488 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800489 elif [ "$answer" = "simulator" ]
490 then
491 selection=simulator
492 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
493 then
494 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
495 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800496 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800497 fi
498 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
499 then
500 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700501 fi
502
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800503 if [ -z "$selection" ]
504 then
505 echo
506 echo "Invalid lunch combo: $answer"
507 return 1
508 fi
509
Joe Onoratoda12daf2010-06-09 18:18:31 -0700510 export TARGET_BUILD_APPS=
511
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512 # special case the simulator
513 if [ "$selection" = "simulator" ]
514 then
515 export TARGET_PRODUCT=sim
516 export TARGET_BUILD_VARIANT=eng
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700517 export TARGET_SIMULATOR=true
518 export TARGET_BUILD_TYPE=debug
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800519 else
520 local product=$(echo -n $selection | sed -e "s/-.*$//")
521 check_product $product
522 if [ $? -ne 0 ]
523 then
524 echo
525 echo "** Don't have a product spec for: '$product'"
526 echo "** Do you have the right repo manifest?"
527 product=
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700528 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800529
530 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
531 check_variant $variant
532 if [ $? -ne 0 ]
533 then
534 echo
535 echo "** Invalid variant: '$variant'"
536 echo "** Must be one of ${VARIANT_CHOICES[@]}"
537 variant=
538 fi
539
540 if [ -z "$product" -o -z "$variant" ]
541 then
542 echo
543 return 1
544 fi
545
546 export TARGET_PRODUCT=$product
547 export TARGET_BUILD_VARIANT=$variant
548 export TARGET_SIMULATOR=false
549 export TARGET_BUILD_TYPE=release
550 fi # !simulator
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700551
552 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800553
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700554 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800555 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700556}
557
Jeff Davidson513d7a42010-08-02 10:00:44 -0700558# Tab completion for lunch.
559function _lunch()
560{
561 local cur prev opts
562 COMPREPLY=()
563 cur="${COMP_WORDS[COMP_CWORD]}"
564 prev="${COMP_WORDS[COMP_CWORD-1]}"
565
566 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
567 return 0
568}
569complete -F _lunch lunch
570
Joe Onoratoda12daf2010-06-09 18:18:31 -0700571# Configures the build to build unbundled apps.
572# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
573function tapas()
574{
575 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
576 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
577
578 if [ $(echo $variant | wc -w) -gt 1 ]; then
579 echo "tapas: Error: Multiple build variants supplied: $variant"
580 return
581 fi
582 if [ -z "$variant" ]; then
583 variant=eng
584 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700585 if [ -z "$apps" ]; then
586 apps=all
587 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700588
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700589 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700590 export TARGET_BUILD_VARIANT=$variant
591 export TARGET_SIMULATOR=false
592 export TARGET_BUILD_TYPE=release
593 export TARGET_BUILD_APPS=$apps
594
595 set_stuff_for_environment
596 printconfig
597}
598
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700599function gettop
600{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800601 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700602 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
603 echo $TOP
604 else
605 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800606 # The following circumlocution (repeated below as well) ensures
607 # that we record the true directory name and not one that is
608 # faked up with symlink names.
609 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700610 else
611 # We redirect cd to /dev/null in case it's aliased to
612 # a command that prints something as a side-effect
613 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800614 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700615 T=
616 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
617 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800618 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700619 done
620 cd $HERE > /dev/null
621 if [ -f "$T/$TOPFILE" ]; then
622 echo $T
623 fi
624 fi
625 fi
626}
627
628function m()
629{
630 T=$(gettop)
631 if [ "$T" ]; then
632 make -C $T $@
633 else
634 echo "Couldn't locate the top of the tree. Try setting TOP."
635 fi
636}
637
638function findmakefile()
639{
640 TOPFILE=build/core/envsetup.mk
641 # We redirect cd to /dev/null in case it's aliased to
642 # a command that prints something as a side-effect
643 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800644 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700645 T=
646 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
647 T=$PWD
648 if [ -f "$T/Android.mk" ]; then
649 echo $T/Android.mk
650 cd $HERE > /dev/null
651 return
652 fi
653 cd .. > /dev/null
654 done
655 cd $HERE > /dev/null
656}
657
658function mm()
659{
660 # If we're sitting in the root of the build tree, just do a
661 # normal make.
662 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
663 make $@
664 else
665 # Find the closest Android.mk file.
666 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800667 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700668 # Remove the path to top as the makefilepath needs to be relative
669 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700670 if [ ! "$T" ]; then
671 echo "Couldn't locate the top of the tree. Try setting TOP."
672 elif [ ! "$M" ]; then
673 echo "Couldn't locate a makefile from the current directory."
674 else
Ying Wang01884142010-07-20 16:18:16 -0700675 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700676 fi
677 fi
678}
679
680function mmm()
681{
682 T=$(gettop)
683 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800684 local MAKEFILE=
685 local ARGS=
686 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800687 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
688 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
689 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700690 DIR=`echo $DIR | sed -e 's:/$::'`
691 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700692 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700693 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800694 START=`PWD= /bin/pwd`
695 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700696 if [ "$MFILE" = "" ] ; then
697 MFILE=$DIR/Android.mk
698 else
699 MFILE=$MFILE/$DIR/Android.mk
700 fi
701 MAKEFILE="$MAKEFILE $MFILE"
702 else
703 if [ "$DIR" = snod ]; then
704 ARGS="$ARGS snod"
705 elif [ "$DIR" = showcommands ]; then
706 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700707 elif [ "$DIR" = dist ]; then
708 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800709 elif [ "$DIR" = incrementaljavac ]; then
710 ARGS="$ARGS incrementaljavac"
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
Grace Klobae9d04bf2011-04-30 11:04:05 -0700796 if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
797 PID="$3"
798 else
799 PID=`pid $3`
800 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 adb forward "tcp$PORT" "tcp$PORT"
802 adb shell gdbserver $PORT --attach $PID &
803 sleep 2
804 else
805 echo ""
806 echo "If you haven't done so already, do this first on the device:"
807 echo " gdbserver $PORT /system/bin/$EXE"
808 echo " or"
809 echo " gdbserver $PORT --attach $PID"
810 echo ""
811 fi
812
813 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
814 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
815 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
816 echo >>"$OUT_ROOT/gdbclient.cmds" ""
817
Jing Yu9d396e32010-07-29 15:07:31 -0700818 arm-linux-androideabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700819 else
820 echo "Unable to determine build system output dir."
821 fi
822
823}
824
825case `uname -s` in
826 Darwin)
827 function sgrep()
828 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700829 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 -0700830 }
831
832 ;;
833 *)
834 function sgrep()
835 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700836 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 -0700837 }
838 ;;
839esac
840
841function jgrep()
842{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700843 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 -0700844}
845
846function cgrep()
847{
Mike Dodd0c26d342011-04-07 13:29:06 -0700848 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 -0700849}
850
851function resgrep()
852{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700853 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 -0700854}
855
856case `uname -s` in
857 Darwin)
858 function mgrep()
859 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700860 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 -0700861 }
862
863 function treegrep()
864 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700865 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 -0700866 }
867
868 ;;
869 *)
870 function mgrep()
871 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700872 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 -0700873 }
874
875 function treegrep()
876 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700877 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 -0700878 }
879
880 ;;
881esac
882
883function getprebuilt
884{
885 get_abs_build_var ANDROID_PREBUILTS
886}
887
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700888function tracedmdump()
889{
890 T=$(gettop)
891 if [ ! "$T" ]; then
892 echo "Couldn't locate the top of the tree. Try setting TOP."
893 return
894 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800895 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700896 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700897
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800898 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700899 if [ ! "$TRACE" ] ; then
900 echo "usage: tracedmdump tracename"
901 return
902 fi
903
Jack Veenstra60116fc2009-04-09 18:12:34 -0700904 if [ ! -r "$KERNEL" ] ; then
905 echo "Error: cannot find kernel: '$KERNEL'"
906 return
907 fi
908
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800909 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700910 if [ "$BASETRACE" = "$TRACE" ] ; then
911 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
912 fi
913
914 echo "post-processing traces..."
915 rm -f $TRACE/qtrace.dexlist
916 post_trace $TRACE
917 if [ $? -ne 0 ]; then
918 echo "***"
919 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
920 echo "***"
921 return
922 fi
923 echo "generating dexlist output..."
924 /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
925 echo "generating dmtrace data..."
926 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
927 echo "generating html file..."
928 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
929 echo "done, see $TRACE/dmtrace.html for details"
930 echo "or run:"
931 echo " traceview $TRACE/dmtrace"
932}
933
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800934# communicate with a running device or emulator, set up necessary state,
935# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700936function runhat()
937{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800938 # process standard adb options
939 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700940 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800941 adbTarget=$1
942 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700943 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800944 adbTarget="$1 $2"
945 shift 2
946 fi
947 local adbOptions=${adbTarget}
948 echo adbOptions = ${adbOptions}
949
950 # runhat options
951 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700952
953 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700954 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
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
Andy McFaddenb6289852010-07-12 08:00:19 -0700964 # issue "am" command to cause the hprof dump
965 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700967 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800968 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700969 echo -n "> "
970 read
971
The Android Open Source Project88b60792009-03-03 19:28:42 -0800972 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700973
The Android Open Source Project88b60792009-03-03 19:28:42 -0800974 echo "Retrieving file $devFile..."
975 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700976
The Android Open Source Project88b60792009-03-03 19:28:42 -0800977 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700978
The Android Open Source Project88b60792009-03-03 19:28:42 -0800979 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700980 echo "View the output by pointing your browser at http://localhost:7000/"
981 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800982 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700983}
984
985function getbugreports()
986{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800987 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700988
989 if [ ! "$reports" ]; then
990 echo "Could not locate any bugreports."
991 return
992 fi
993
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800994 local report
995 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700996 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800997 echo "/sdcard/bugreports/${report}"
998 adb pull /sdcard/bugreports/${report} ${report}
999 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001000 done
1001}
1002
1003function startviewserver()
1004{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001005 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001006 if [ $# -gt 0 ]; then
1007 port=$1
1008 fi
1009 adb shell service call window 1 i32 $port
1010}
1011
1012function stopviewserver()
1013{
1014 adb shell service call window 2
1015}
1016
1017function isviewserverstarted()
1018{
1019 adb shell service call window 3
1020}
1021
Romain Guyb84049a2010-10-04 16:56:11 -07001022function key_home()
1023{
1024 adb shell input keyevent 3
1025}
1026
1027function key_back()
1028{
1029 adb shell input keyevent 4
1030}
1031
1032function key_menu()
1033{
1034 adb shell input keyevent 82
1035}
1036
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001037function smoketest()
1038{
1039 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1040 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1041 return
1042 fi
1043 T=$(gettop)
1044 if [ ! "$T" ]; then
1045 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1046 return
1047 fi
1048
1049 (cd "$T" && mmm tests/SmokeTest) &&
1050 adb uninstall com.android.smoketest > /dev/null &&
1051 adb uninstall com.android.smoketest.tests > /dev/null &&
1052 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1053 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1054 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1055}
1056
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001057# simple shortcut to the runtest command
1058function runtest()
1059{
1060 T=$(gettop)
1061 if [ ! "$T" ]; then
1062 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1063 return
1064 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001065 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001066}
1067
The Android Open Source Project88b60792009-03-03 19:28:42 -08001068function godir () {
1069 if [[ -z "$1" ]]; then
1070 echo "Usage: godir <regex>"
1071 return
1072 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001073 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001074 if [[ ! -f $T/filelist ]]; then
1075 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001076 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001077 echo " Done"
1078 echo ""
1079 fi
1080 local lines
Doug Zongker29034982011-04-22 08:16:56 -07001081 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001082 if [[ ${#lines[@]} = 0 ]]; then
1083 echo "Not found"
1084 return
1085 fi
1086 local pathname
1087 local choice
1088 if [[ ${#lines[@]} > 1 ]]; then
1089 while [[ -z "$pathname" ]]; do
1090 local index=1
1091 local line
1092 for line in ${lines[@]}; do
1093 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001094 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001095 done
1096 echo
1097 echo -n "Select one: "
1098 unset choice
1099 read choice
1100 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1101 echo "Invalid choice"
1102 continue
1103 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001104 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001105 done
1106 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001107 pathname=${lines[0]}
1108 fi
1109 cd $T/$pathname
1110}
1111
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001112# Force JAVA_HOME to point to java 1.6 if it isn't already set
1113function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001114 if [ ! "$JAVA_HOME" ]; then
1115 case `uname -s` in
1116 Darwin)
1117 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1118 ;;
1119 *)
1120 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1121 ;;
1122 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001123 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001124}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001125
Raphael Moll70a86b02011-06-20 16:03:14 -07001126if [ "x$SHELL" != "x/bin/bash" ]; then
1127 case `ps -o command -p $$` in
1128 *bash*)
1129 ;;
1130 *)
1131 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1132 ;;
1133 esac
1134fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001135
1136# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001137for 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 -08001138do
1139 echo "including $f"
1140 . $f
1141done
1142unset f