blob: f8f20ab5cf103bae2b197273cf928cfcad880afd [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001function help() {
2cat <<EOF
3Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
4- 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.
11- godir: Go to the directory containing a file.
12
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
32 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
33 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1
34}
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
44 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= \
59 get_build_var TARGET_DEVICE > /dev/null
60 # hide successful answers, but allow the errors to show
61}
62
63VARIANT_CHOICES=(user userdebug eng)
64
65# check to see if the supplied variant is valid
66function check_variant()
67{
68 for v in ${VARIANT_CHOICES[@]}
69 do
70 if [ "$v" = "$1" ]
71 then
72 return 0
73 fi
74 done
75 return 1
76}
77
78function setpaths()
79{
80 T=$(gettop)
81 if [ ! "$T" ]; then
82 echo "Couldn't locate the top of the tree. Try setting TOP."
83 return
84 fi
85
86 ##################################################################
87 # #
88 # Read me before you modify this code #
89 # #
90 # This function sets ANDROID_BUILD_PATHS to what it is adding #
91 # to PATH, and the next time it is run, it removes that from #
92 # PATH. This is required so lunch can be run more than once #
93 # and still have working paths. #
94 # #
95 ##################################################################
96
97 # out with the old
98 if [ -n $ANDROID_BUILD_PATHS ] ; then
99 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
100 fi
101
102 # and in with the new
103 CODE_REVIEWS=
104 prebuiltdir=$(getprebuilt)
105 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/toolchain/arm-eabi-4.2.1/bin
106 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
107 export ANDROID_QTOOLS=$T/development/emulator/qtools
108 export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_EABI_TOOLCHAIN$CODE_REVIEWS
109 export PATH=$PATH$ANDROID_BUILD_PATHS
110
111 unset ANDROID_PRODUCT_OUT
112 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
113 export OUT=$ANDROID_PRODUCT_OUT
114
115 # needed for building linux on MacOS
116 # TODO: fix the path
117 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
118
119 # needed for OProfile to post-process collected samples
120 export OPROFILE_EVENTS_DIR=$prebuiltdir/oprofile
121}
122
123function printconfig()
124{
125 T=$(gettop)
126 if [ ! "$T" ]; then
127 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
128 return
129 fi
130 get_build_var report_config
131}
132
133function set_stuff_for_environment()
134{
135 settitle
136 setpaths
137 set_sequence_number
138
139 # Don't try to do preoptimization until it works better on OSX.
140 export DISABLE_DEXPREOPT=true
141
142 export ANDROID_BUILD_TOP=$(gettop)
143}
144
145function set_sequence_number()
146{
147 export BUILD_ENV_SEQUENCE_NUMBER=9
148}
149
150function settitle()
151{
152 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
153 local product=$(get_build_var TARGET_PRODUCT)
154 local variant=$(get_build_var TARGET_BUILD_VARIANT)
155 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
156 fi
157}
158
159case `uname -s` in
160 Linux)
161 function choosesim()
162 {
163 echo "Build for the simulator or the device?"
164 echo " 1. Device"
165 echo " 2. Simulator"
166 echo
167
168 export TARGET_SIMULATOR=
169 local ANSWER
170 while [ -z $TARGET_SIMULATOR ]
171 do
172 echo -n "Which would you like? [1] "
173 if [ -z "$1" ] ; then
174 read ANSWER
175 else
176 echo $1
177 ANSWER=$1
178 fi
179 case $ANSWER in
180 "")
181 export TARGET_SIMULATOR=false
182 ;;
183 1)
184 export TARGET_SIMULATOR=false
185 ;;
186 Device)
187 export TARGET_SIMULATOR=false
188 ;;
189 2)
190 export TARGET_SIMULATOR=true
191 ;;
192 Simulator)
193 export TARGET_SIMULATOR=true
194 ;;
195 *)
196 echo
197 echo "I didn't understand your response. Please try again."
198 echo
199 ;;
200 esac
201 if [ -n "$1" ] ; then
202 break
203 fi
204 done
205
206 set_stuff_for_environment
207 }
208 ;;
209 *)
210 function choosesim()
211 {
212 echo "Only device builds are supported for" `uname -s`
213 echo " Forcing TARGET_SIMULATOR=false"
214 echo
215 if [ -z "$1" ]
216 then
217 echo -n "Press enter: "
218 read
219 fi
220
221 export TARGET_SIMULATOR=false
222 set_stuff_for_environment
223 }
224 ;;
225esac
226
227function choosetype()
228{
229 echo "Build type choices are:"
230 echo " 1. release"
231 echo " 2. debug"
232 echo
233
234 local DEFAULT_NUM DEFAULT_VALUE
235 if [ $TARGET_SIMULATOR = "false" ] ; then
236 DEFAULT_NUM=1
237 DEFAULT_VALUE=release
238 else
239 DEFAULT_NUM=2
240 DEFAULT_VALUE=debug
241 fi
242
243 export TARGET_BUILD_TYPE=
244 local ANSWER
245 while [ -z $TARGET_BUILD_TYPE ]
246 do
247 echo -n "Which would you like? ["$DEFAULT_NUM"] "
248 if [ -z "$1" ] ; then
249 read ANSWER
250 else
251 echo $1
252 ANSWER=$1
253 fi
254 case $ANSWER in
255 "")
256 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
257 ;;
258 1)
259 export TARGET_BUILD_TYPE=release
260 ;;
261 release)
262 export TARGET_BUILD_TYPE=release
263 ;;
264 2)
265 export TARGET_BUILD_TYPE=debug
266 ;;
267 debug)
268 export TARGET_BUILD_TYPE=debug
269 ;;
270 *)
271 echo
272 echo "I didn't understand your response. Please try again."
273 echo
274 ;;
275 esac
276 if [ -n "$1" ] ; then
277 break
278 fi
279 done
280
281 set_stuff_for_environment
282}
283
284#
285# This function isn't really right: It chooses a TARGET_PRODUCT
286# based on the list of boards. Usually, that gets you something
287# that kinda works with a generic product, but really, you should
288# pick a product by name.
289#
290function chooseproduct()
291{
292 # Find the makefiles that must exist for a product.
293 # Send stderr to /dev/null in case partner isn't present.
294 local -a choices
295 choices=(`/bin/ls build/target/board/*/BoardConfig.mk vendor/*/*/BoardConfig.mk 2> /dev/null`)
296
297 local choice
298 local -a prodlist
299 for choice in ${choices[@]}
300 do
301 # The product name is the name of the directory containing
302 # the makefile we found, above.
303 prodlist=(${prodlist[@]} `dirname ${choice} | xargs basename`)
304 done
305
306 local index=1
307 local p
308 echo "Product choices are:"
309 for p in ${prodlist[@]}
310 do
311 echo " $index. $p"
312 let "index = $index + 1"
313 done
314
315
316 if [ "x$TARGET_PRODUCT" != x ] ; then
317 default_value=$TARGET_PRODUCT
318 else
319 if [ "$TARGET_SIMULATOR" = true ] ; then
320 default_value=sim
321 else
322 default_value=generic
323 fi
324 fi
325
326 export TARGET_PRODUCT=
327 local ANSWER
328 while [ -z "$TARGET_PRODUCT" ]
329 do
330 echo "You can also type the name of a product if you know it."
331 echo -n "Which would you like? [$default_value] "
332 if [ -z "$1" ] ; then
333 read ANSWER
334 else
335 echo $1
336 ANSWER=$1
337 fi
338
339 if [ -z "$ANSWER" ] ; then
340 export TARGET_PRODUCT=$default_value
341 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
342 local poo=`echo -n $ANSWER`
343 if [ $poo -le ${#prodlist[@]} ] ; then
344 export TARGET_PRODUCT=${prodlist[$(($ANSWER-$_arrayoffset))]}
345 else
346 echo "** Bad product selection: $ANSWER"
347 fi
348 else
349 if check_product $ANSWER
350 then
351 export TARGET_PRODUCT=$ANSWER
352 else
353 echo "** Not a valid product: $ANSWER"
354 fi
355 fi
356 if [ -n "$1" ] ; then
357 break
358 fi
359 done
360
361 set_stuff_for_environment
362}
363
364function choosevariant()
365{
366 echo "Variant choices are:"
367 local index=1
368 local v
369 for v in ${VARIANT_CHOICES[@]}
370 do
371 # The product name is the name of the directory containing
372 # the makefile we found, above.
373 echo " $index. $v"
374 index=$(($index+1))
375 done
376
377 local default_value=eng
378 local ANSWER
379
380 export TARGET_BUILD_VARIANT=
381 while [ -z "$TARGET_BUILD_VARIANT" ]
382 do
383 echo -n "Which would you like? [$default_value] "
384 if [ -z "$1" ] ; then
385 read ANSWER
386 else
387 echo $1
388 ANSWER=$1
389 fi
390
391 if [ -z "$ANSWER" ] ; then
392 export TARGET_BUILD_VARIANT=$default_value
393 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
394 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
395 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-$_arrayoffset))]}
396 fi
397 else
398 if check_variant $ANSWER
399 then
400 export TARGET_BUILD_VARIANT=$ANSWER
401 else
402 echo "** Not a valid variant: $ANSWER"
403 fi
404 fi
405 if [ -n "$1" ] ; then
406 break
407 fi
408 done
409}
410
411function tapas()
412{
413 choosecombo
414}
415
416function choosecombo()
417{
418 choosesim $1
419
420 echo
421 echo
422 choosetype $2
423
424 echo
425 echo
426 chooseproduct $3
427
428 echo
429 echo
430 choosevariant $4
431
432 echo
433 set_stuff_for_environment
434 printconfig
435}
436
437# Clear this variable. It will be built up again when the vendorsetup.sh
438# files are included at the end of this file.
439unset LUNCH_MENU_CHOICES
440function add_lunch_combo()
441{
442 local new_combo=$1
443 local c
444 for c in ${LUNCH_MENU_CHOICES[@]} ; do
445 if [ "$new_combo" = "$c" ] ; then
446 return
447 fi
448 done
449 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
450}
451
452# add the default one here
453add_lunch_combo generic-eng
454
455# if we're on linux, add the simulator. There is a special case
456# in lunch to deal with the simulator
457if [ "$(uname)" = "Linux" ] ; then
458 add_lunch_combo simulator
459fi
460
461function print_lunch_menu()
462{
463 local uname=$(uname)
464 echo
465 echo "You're building on" $uname
466 echo
467 echo ${LUNCH_MENU_CHOICES[@]}
468 echo "Lunch menu... pick a combo:"
469
470 local i=1
471 local choice
472 for choice in ${LUNCH_MENU_CHOICES[@]}
473 do
474 echo " $i. $choice"
475 i=$(($i+1))
476 done
477
478 echo
479}
480
481function lunch()
482{
483 local answer
484
485 if [ "$1" ] ; then
486 answer=$1
487 else
488 print_lunch_menu
489 echo -n "Which would you like? [generic-eng] "
490 read answer
491 fi
492
493 local selection=
494
495 if [ -z "$answer" ]
496 then
497 selection=generic-eng
498 elif [ "$answer" = "simulator" ]
499 then
500 selection=simulator
501 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
502 then
503 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
504 then
505 selection=${LUNCH_MENU_CHOICES[$(($answer-$_arrayoffset))]}
506 fi
507 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
508 then
509 selection=$answer
510 fi
511
512 if [ -z "$selection" ]
513 then
514 echo
515 echo "Invalid lunch combo: $answer"
516 return 1
517 fi
518
519 # special case the simulator
520 if [ "$selection" = "simulator" ]
521 then
522 export TARGET_PRODUCT=sim
523 export TARGET_BUILD_VARIANT=eng
524 export TARGET_SIMULATOR=true
525 export TARGET_BUILD_TYPE=debug
526 else
527 local product=$(echo -n $selection | sed -e "s/-.*$//")
528 check_product $product
529 if [ $? -ne 0 ]
530 then
531 echo
532 echo "** Don't have a product spec for: '$product'"
533 echo "** Do you have the right repo manifest?"
534 product=
535 fi
536
537 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
538 check_variant $variant
539 if [ $? -ne 0 ]
540 then
541 echo
542 echo "** Invalid variant: '$variant'"
543 echo "** Must be one of ${VARIANT_CHOICES[@]}"
544 variant=
545 fi
546
547 if [ -z "$product" -o -z "$variant" ]
548 then
549 echo
550 return 1
551 fi
552
553 export TARGET_PRODUCT=$product
554 export TARGET_BUILD_VARIANT=$variant
555 export TARGET_SIMULATOR=false
556 export TARGET_BUILD_TYPE=release
557 fi # !simulator
558
559 echo
560
561 set_stuff_for_environment
562 printconfig
563}
564
565function gettop
566{
567 local TOPFILE=build/core/envsetup.mk
568 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
569 echo $TOP
570 else
571 if [ -f $TOPFILE ] ; then
572 echo $PWD
573 else
574 # We redirect cd to /dev/null in case it's aliased to
575 # a command that prints something as a side-effect
576 # (like pushd)
577 local HERE=$PWD
578 T=
579 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
580 cd .. > /dev/null
581 T=$PWD
582 done
583 cd $HERE > /dev/null
584 if [ -f "$T/$TOPFILE" ]; then
585 echo $T
586 fi
587 fi
588 fi
589}
590
591function m()
592{
593 T=$(gettop)
594 if [ "$T" ]; then
595 make -C $T $@
596 else
597 echo "Couldn't locate the top of the tree. Try setting TOP."
598 fi
599}
600
601function findmakefile()
602{
603 TOPFILE=build/core/envsetup.mk
604 # We redirect cd to /dev/null in case it's aliased to
605 # a command that prints something as a side-effect
606 # (like pushd)
607 local HERE=$PWD
608 T=
609 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
610 T=$PWD
611 if [ -f "$T/Android.mk" ]; then
612 echo $T/Android.mk
613 cd $HERE > /dev/null
614 return
615 fi
616 cd .. > /dev/null
617 done
618 cd $HERE > /dev/null
619}
620
621function mm()
622{
623 # If we're sitting in the root of the build tree, just do a
624 # normal make.
625 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
626 make $@
627 else
628 # Find the closest Android.mk file.
629 T=$(gettop)
630 local M=$(findmakefile)
631 if [ ! "$T" ]; then
632 echo "Couldn't locate the top of the tree. Try setting TOP."
633 elif [ ! "$M" ]; then
634 echo "Couldn't locate a makefile from the current directory."
635 else
636 ONE_SHOT_MAKEFILE=$M make -C $T files $@
637 fi
638 fi
639}
640
641function mmm()
642{
643 T=$(gettop)
644 if [ "$T" ]; then
645 local MAKEFILE=
646 local ARGS=
647 local DIR TO_CHOP
648 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
649 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
650 for DIR in $DIRS ; do
651 DIR=`echo $DIR | sed -e 's:/$::'`
652 if [ -f $DIR/Android.mk ]; then
653 TO_CHOP=`echo $T | wc -c | tr -d ' '`
654 TO_CHOP=`expr $TO_CHOP + 1`
655 MFILE=`echo $PWD | cut -c${TO_CHOP}-`
656 if [ "$MFILE" = "" ] ; then
657 MFILE=$DIR/Android.mk
658 else
659 MFILE=$MFILE/$DIR/Android.mk
660 fi
661 MAKEFILE="$MAKEFILE $MFILE"
662 else
663 if [ "$DIR" = snod ]; then
664 ARGS="$ARGS snod"
665 elif [ "$DIR" = showcommands ]; then
666 ARGS="$ARGS showcommands"
667 else
668 echo "No Android.mk in $DIR."
669 fi
670 fi
671 done
672 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS files $ARGS
673 else
674 echo "Couldn't locate the top of the tree. Try setting TOP."
675 fi
676}
677
678function croot()
679{
680 T=$(gettop)
681 if [ "$T" ]; then
682 cd $(gettop)
683 else
684 echo "Couldn't locate the top of the tree. Try setting TOP."
685 fi
686}
687
688function pid()
689{
690 local EXE="$1"
691 if [ "$EXE" ] ; then
692 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
693 echo "$PID"
694 else
695 echo "usage: pid name"
696 fi
697}
698
699function gdbclient()
700{
701 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
702 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
703 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
704 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
705 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
706 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
707 local EXE="$1"
708 if [ "$EXE" ] ; then
709 EXE=$1
710 else
711 EXE="app_process"
712 fi
713
714 local PORT="$2"
715 if [ "$PORT" ] ; then
716 PORT=$2
717 else
718 PORT=":5039"
719 fi
720
721 local PID
722 local PROG="$3"
723 if [ "$PROG" ] ; then
724 PID=`pid $3`
725 adb forward "tcp$PORT" "tcp$PORT"
726 adb shell gdbserver $PORT --attach $PID &
727 sleep 2
728 else
729 echo ""
730 echo "If you haven't done so already, do this first on the device:"
731 echo " gdbserver $PORT /system/bin/$EXE"
732 echo " or"
733 echo " gdbserver $PORT --attach $PID"
734 echo ""
735 fi
736
737 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
738 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
739 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
740 echo >>"$OUT_ROOT/gdbclient.cmds" ""
741
742 arm-eabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
743 else
744 echo "Unable to determine build system output dir."
745 fi
746
747}
748
749case `uname -s` in
750 Darwin)
751 function sgrep()
752 {
753 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n "$@"
754 }
755
756 ;;
757 *)
758 function sgrep()
759 {
760 find . -type f -iregex '.*\.\(c\|h\|cpp\|S\|java\|xml\)' -print0 | xargs -0 grep --color -n "$@"
761 }
762 ;;
763esac
764
765function jgrep()
766{
767 find . -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
768}
769
770function cgrep()
771{
772 find . -type f -name "*\.c*" -print0 | xargs -0 grep --color -n "$@"
773}
774
775function resgrep()
776{
777 for dir in `find . -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
778}
779
780case `uname -s` in
781 Darwin)
782 function mgrep()
783 {
784 find -E . -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
785 }
786
787 function treegrep()
788 {
789 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
790 }
791
792 ;;
793 *)
794 function mgrep()
795 {
796 find . -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@"
797 }
798
799 function treegrep()
800 {
801 find . -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
802 }
803
804 ;;
805esac
806
807function getprebuilt
808{
809 get_abs_build_var ANDROID_PREBUILTS
810}
811
812function tracedmdump()
813{
814 T=$(gettop)
815 if [ ! "$T" ]; then
816 echo "Couldn't locate the top of the tree. Try setting TOP."
817 return
818 fi
819 local prebuiltdir=$(getprebuilt)
Jack Veenstra8f8b99c2009-04-10 10:30:51 -0700820 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Project88b60792009-03-03 19:28:42 -0800821
822 local TRACE=$1
823 if [ ! "$TRACE" ] ; then
824 echo "usage: tracedmdump tracename"
825 return
826 fi
827
Jack Veenstra8f8b99c2009-04-10 10:30:51 -0700828 if [ ! -r "$KERNEL" ] ; then
829 echo "Error: cannot find kernel: '$KERNEL'"
830 return
831 fi
832
The Android Open Source Project88b60792009-03-03 19:28:42 -0800833 local BASETRACE=$(basename $TRACE)
834 if [ "$BASETRACE" = "$TRACE" ] ; then
835 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
836 fi
837
838 echo "post-processing traces..."
839 rm -f $TRACE/qtrace.dexlist
840 post_trace $TRACE
841 if [ $? -ne 0 ]; then
842 echo "***"
843 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
844 echo "***"
845 return
846 fi
847 echo "generating dexlist output..."
848 /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
849 echo "generating dmtrace data..."
850 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
851 echo "generating html file..."
852 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
853 echo "done, see $TRACE/dmtrace.html for details"
854 echo "or run:"
855 echo " traceview $TRACE/dmtrace"
856}
857
858# communicate with a running device or emulator, set up necessary state,
859# and run the hat command.
860function runhat()
861{
862 # process standard adb options
863 local adbTarget=""
864 if [ $1 = "-d" -o $1 = "-e" ]; then
865 adbTarget=$1
866 shift 1
867 elif [ $1 = "-s" ]; then
868 adbTarget="$1 $2"
869 shift 2
870 fi
871 local adbOptions=${adbTarget}
872 echo adbOptions = ${adbOptions}
873
874 # runhat options
875 local targetPid=$1
876 local outputFile=$2
877
878 if [ "$targetPid" = "" ]; then
879 echo "Usage: runhat [ -d | -e | -s serial ] target-pid [output-file]"
880 return
881 fi
882
883 # confirm hat is available
884 if [ -z $(which hat) ]; then
885 echo "hat is not available in this configuration."
886 return
887 fi
888
889 adb ${adbOptions} shell >/dev/null mkdir /data/misc
890 adb ${adbOptions} shell chmod 777 /data/misc
891
892 # send a SIGUSR1 to cause the hprof dump
893 echo "Poking $targetPid and waiting for data..."
894 adb ${adbOptions} shell kill -10 $targetPid
895 echo "Press enter when logcat shows \"hprof: heap dump completed\""
896 echo -n "> "
897 read
898
899 local availFiles=( $(adb ${adbOptions} shell ls /data/misc | grep '^heap-dump' | sed -e 's/.*heap-dump-/heap-dump-/' | sort -r | tr '[:space:][:cntrl:]' ' ') )
900 local devFile=/data/misc/${availFiles[0]}
901 local localFile=/tmp/$$-hprof
902
903 echo "Retrieving file $devFile..."
904 adb ${adbOptions} pull $devFile $localFile
905
906 adb ${adbOptions} shell rm $devFile
907
908 echo "Running hat on $localFile"
909 echo "View the output by pointing your browser at http://localhost:7000/"
910 echo ""
911 hat $localFile
912}
913
914function getbugreports()
915{
916 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
917
918 if [ ! "$reports" ]; then
919 echo "Could not locate any bugreports."
920 return
921 fi
922
923 local report
924 for report in ${reports[@]}
925 do
926 echo "/sdcard/bugreports/${report}"
927 adb pull /sdcard/bugreports/${report} ${report}
928 gunzip ${report}
929 done
930}
931
932function startviewserver()
933{
934 local port=4939
935 if [ $# -gt 0 ]; then
936 port=$1
937 fi
938 adb shell service call window 1 i32 $port
939}
940
941function stopviewserver()
942{
943 adb shell service call window 2
944}
945
946function isviewserverstarted()
947{
948 adb shell service call window 3
949}
950
951function smoketest()
952{
953 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
954 echo "Couldn't locate output files. Try running 'lunch' first." >&2
955 return
956 fi
957 T=$(gettop)
958 if [ ! "$T" ]; then
959 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
960 return
961 fi
962
963 (cd "$T" && mmm tests/SmokeTest) &&
964 adb uninstall com.android.smoketest > /dev/null &&
965 adb uninstall com.android.smoketest.tests > /dev/null &&
966 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
967 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
968 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
969}
970
971# simple shortcut to the runtest command
972function runtest()
973{
974 T=$(gettop)
975 if [ ! "$T" ]; then
976 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
977 return
978 fi
979 (cd "$T" && development/tools/runtest $@)
980}
981
Brett Chabote253d822009-03-27 20:17:02 -0700982# simple shortcut to the runtest.py command
Brett Chabot03e1e282009-03-31 14:53:34 -0700983function runtest_py()
Brett Chabote253d822009-03-27 20:17:02 -0700984{
985 T=$(gettop)
986 if [ ! "$T" ]; then
987 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
988 return
989 fi
990 (cd "$T" && development/testrunner/runtest.py $@)
991}
992
The Android Open Source Project88b60792009-03-03 19:28:42 -0800993function godir () {
994 if [[ -z "$1" ]]; then
995 echo "Usage: godir <regex>"
996 return
997 fi
998 if [[ ! -f $T/filelist ]]; then
999 echo -n "Creating index..."
1000 (cd $T; find . -wholename ./out -prune -o -type f > filelist)
1001 echo " Done"
1002 echo ""
1003 fi
1004 local lines
1005 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1006 if [[ ${#lines[@]} = 0 ]]; then
1007 echo "Not found"
1008 return
1009 fi
1010 local pathname
1011 local choice
1012 if [[ ${#lines[@]} > 1 ]]; then
1013 while [[ -z "$pathname" ]]; do
1014 local index=1
1015 local line
1016 for line in ${lines[@]}; do
1017 printf "%6s %s\n" "[$index]" $line
1018 index=$(($index + 1))
1019 done
1020 echo
1021 echo -n "Select one: "
1022 unset choice
1023 read choice
1024 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1025 echo "Invalid choice"
1026 continue
1027 fi
1028 pathname=${lines[$(($choice-$_arrayoffset))]}
1029 done
1030 else
1031 # even though zsh arrays are 1-based, $foo[0] is an alias for $foo[1]
1032 pathname=${lines[0]}
1033 fi
1034 cd $T/$pathname
1035}
1036
1037# determine whether arrays are zero-based (bash) or one-based (zsh)
1038_xarray=(a b c)
1039if [ -z "${_xarray[${#_xarray[@]}]}" ]
1040then
1041 _arrayoffset=1
1042else
1043 _arrayoffset=0
1044fi
1045unset _xarray
1046
1047# Execute the contents of any vendorsetup.sh files we can find.
1048for f in `/bin/ls vendor/*/vendorsetup.sh 2> /dev/null`
1049do
1050 echo "including $f"
1051 . $f
1052done
1053unset f