3 Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
4 - lunch: lunch <product_name>-<build_variant>
5 - tapas: tapas [<App1> <App2> ...] [arm|x86|mips] [eng|userdebug|user]
6 - croot: Changes directory to the top of the tree.
7 - m: Makes from the top of the tree.
8 - mm: Builds all of the modules in the current directory.
9 - mmm: Builds all of the modules in the supplied directories.
10 - cgrep: Greps on all local C/C++ files.
11 - jgrep: Greps on all local Java files.
12 - resgrep: Greps on all local res/*.xml files.
13 - godir: Go to the directory containing a file.
15 Look at the source to view more functions. The complete list is:
20 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
26 # Get the value of a build variable as an absolute path.
27 function get_abs_build_var()
31 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
34 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
35 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1)
38 # Get the exact value of a build variable.
39 function get_build_var()
43 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
46 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
47 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1
50 # check to see if the supplied product is one we can build
51 function check_product()
55 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
58 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
60 TARGET_BUILD_VARIANT= \
63 get_build_var TARGET_DEVICE > /dev/null
64 # hide successful answers, but allow the errors to show
67 VARIANT_CHOICES=(user userdebug eng)
69 # check to see if the supplied variant is valid
70 function check_variant()
72 for v in ${VARIANT_CHOICES[@]}
86 echo "Couldn't locate the top of the tree. Try setting TOP."
90 ##################################################################
92 # Read me before you modify this code #
94 # This function sets ANDROID_BUILD_PATHS to what it is adding #
95 # to PATH, and the next time it is run, it removes that from #
96 # PATH. This is required so lunch can be run more than once #
97 # and still have working paths. #
99 ##################################################################
101 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
102 # due to "C:\Program Files" being in the path.
105 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
106 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
108 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
109 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
110 # strip leading ':', if any
111 export PATH=${PATH/:%/}
114 # and in with the new
116 prebuiltdir=$(getprebuilt)
117 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
119 # defined in core/config.mk
120 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
121 export TARGET_GCC_VERSION=$targetgccversion
123 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
124 export ANDROID_EABI_TOOLCHAIN=
125 local ARCH=$(get_build_var TARGET_ARCH)
127 x86) toolchaindir=x86/i686-linux-android-$targetgccversion/bin
129 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
131 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
134 echo "Can't find toolchain for unknown architecture: $ARCH"
135 toolchaindir=xxxxxxxxx
138 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
139 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
142 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
145 toolchaindir=arm/arm-eabi-$targetgccversion/bin
146 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
147 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
148 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
151 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
154 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
158 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
159 export ANDROID_QTOOLS=$T/development/emulator/qtools
160 export ANDROID_DEV_SCRIPTS=$T/development/scripts
161 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
162 export PATH=$ANDROID_BUILD_PATHS$PATH
164 unset ANDROID_JAVA_TOOLCHAIN
165 unset ANDROID_PRE_BUILD_PATHS
166 if [ -n "$JAVA_HOME" ]; then
167 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
168 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
169 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
172 unset ANDROID_PRODUCT_OUT
173 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
174 export OUT=$ANDROID_PRODUCT_OUT
176 unset ANDROID_HOST_OUT
177 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
179 # needed for processing samples collected by perf counters
180 unset OPROFILE_EVENTS_DIR
181 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
183 # needed for building linux on MacOS
185 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
188 function printconfig()
192 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
195 get_build_var report_config
198 function set_stuff_for_environment()
205 export ANDROID_BUILD_TOP=$(gettop)
208 function set_sequence_number()
210 export BUILD_ENV_SEQUENCE_NUMBER=10
215 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
216 local arch=$(gettargetarch)
217 local product=$TARGET_PRODUCT
218 local variant=$TARGET_BUILD_VARIANT
219 local apps=$TARGET_BUILD_APPS
220 if [ -z "$apps" ]; then
221 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
223 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
228 function addcompletions()
232 # Keep us from trying to run in something that isn't bash.
233 if [ -z "${BASH_VERSION}" ]; then
237 # Keep us from trying to run in bash that's too old.
238 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
242 dir="sdk/bash_completion"
243 if [ -d ${dir} ]; then
244 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
251 function choosetype()
253 echo "Build type choices are:"
258 local DEFAULT_NUM DEFAULT_VALUE
260 DEFAULT_VALUE=release
262 export TARGET_BUILD_TYPE=
264 while [ -z $TARGET_BUILD_TYPE ]
266 echo -n "Which would you like? ["$DEFAULT_NUM"] "
267 if [ -z "$1" ] ; then
275 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
278 export TARGET_BUILD_TYPE=release
281 export TARGET_BUILD_TYPE=release
284 export TARGET_BUILD_TYPE=debug
287 export TARGET_BUILD_TYPE=debug
291 echo "I didn't understand your response. Please try again."
295 if [ -n "$1" ] ; then
300 set_stuff_for_environment
304 # This function isn't really right: It chooses a TARGET_PRODUCT
305 # based on the list of boards. Usually, that gets you something
306 # that kinda works with a generic product, but really, you should
307 # pick a product by name.
309 function chooseproduct()
311 if [ "x$TARGET_PRODUCT" != x ] ; then
312 default_value=$TARGET_PRODUCT
317 export TARGET_PRODUCT=
319 while [ -z "$TARGET_PRODUCT" ]
321 echo -n "Which product would you like? [$default_value] "
322 if [ -z "$1" ] ; then
329 if [ -z "$ANSWER" ] ; then
330 export TARGET_PRODUCT=$default_value
332 if check_product $ANSWER
334 export TARGET_PRODUCT=$ANSWER
336 echo "** Not a valid product: $ANSWER"
339 if [ -n "$1" ] ; then
344 set_stuff_for_environment
347 function choosevariant()
349 echo "Variant choices are:"
352 for v in ${VARIANT_CHOICES[@]}
354 # The product name is the name of the directory containing
355 # the makefile we found, above.
360 local default_value=eng
363 export TARGET_BUILD_VARIANT=
364 while [ -z "$TARGET_BUILD_VARIANT" ]
366 echo -n "Which would you like? [$default_value] "
367 if [ -z "$1" ] ; then
374 if [ -z "$ANSWER" ] ; then
375 export TARGET_BUILD_VARIANT=$default_value
376 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
377 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
378 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
381 if check_variant $ANSWER
383 export TARGET_BUILD_VARIANT=$ANSWER
385 echo "** Not a valid variant: $ANSWER"
388 if [ -n "$1" ] ; then
394 function choosecombo()
407 set_stuff_for_environment
411 # Clear this variable. It will be built up again when the vendorsetup.sh
412 # files are included at the end of this file.
413 unset LUNCH_MENU_CHOICES
414 function add_lunch_combo()
418 for c in ${LUNCH_MENU_CHOICES[@]} ; do
419 if [ "$new_combo" = "$c" ] ; then
423 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
426 # add the default one here
427 add_lunch_combo full-eng
428 add_lunch_combo full_x86-eng
429 add_lunch_combo vbox_x86-eng
430 add_lunch_combo full_mips-eng
432 function print_lunch_menu()
436 echo "You're building on" $uname
438 echo "Lunch menu... pick a combo:"
442 for choice in ${LUNCH_MENU_CHOICES[@]}
459 echo -n "Which would you like? [full-eng] "
468 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
470 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
472 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
474 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
479 if [ -z "$selection" ]
482 echo "Invalid lunch combo: $answer"
486 export TARGET_BUILD_APPS=
488 local product=$(echo -n $selection | sed -e "s/-.*$//")
489 check_product $product
493 echo "** Don't have a product spec for: '$product'"
494 echo "** Do you have the right repo manifest?"
498 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
499 check_variant $variant
503 echo "** Invalid variant: '$variant'"
504 echo "** Must be one of ${VARIANT_CHOICES[@]}"
508 if [ -z "$product" -o -z "$variant" ]
514 export TARGET_PRODUCT=$product
515 export TARGET_BUILD_VARIANT=$variant
516 export TARGET_BUILD_TYPE=release
520 set_stuff_for_environment
524 # Tab completion for lunch.
529 cur="${COMP_WORDS[COMP_CWORD]}"
530 prev="${COMP_WORDS[COMP_CWORD-1]}"
532 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
535 complete -F _lunch lunch
537 # Configures the build to build unbundled apps.
538 # Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
541 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips)$'))
542 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
543 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips)$'))
545 if [ $(echo $arch | wc -w) -gt 1 ]; then
546 echo "tapas: Error: Multiple build archs supplied: $arch"
549 if [ $(echo $variant | wc -w) -gt 1 ]; then
550 echo "tapas: Error: Multiple build variants supplied: $variant"
556 x86) product=full_x86;;
557 mips) product=full_mips;;
559 if [ -z "$variant" ]; then
562 if [ -z "$apps" ]; then
566 export TARGET_PRODUCT=$product
567 export TARGET_BUILD_VARIANT=$variant
568 export TARGET_BUILD_TYPE=release
569 export TARGET_BUILD_APPS=$apps
571 set_stuff_for_environment
577 local TOPFILE=build/core/envsetup.mk
578 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
581 if [ -f $TOPFILE ] ; then
582 # The following circumlocution (repeated below as well) ensures
583 # that we record the true directory name and not one that is
584 # faked up with symlink names.
589 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
594 if [ -f "$T/$TOPFILE" ]; then
607 echo "Couldn't locate the top of the tree. Try setting TOP."
611 function findmakefile()
613 TOPFILE=build/core/envsetup.mk
616 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
618 if [ -f "$T/Android.mk" ]; then
630 # If we're sitting in the root of the build tree, just do a
632 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
635 # Find the closest Android.mk file.
637 local M=$(findmakefile)
638 # Remove the path to top as the makefilepath needs to be relative
639 local M=`echo $M|sed 's:'$T'/::'`
641 echo "Couldn't locate the top of the tree. Try setting TOP."
642 elif [ ! "$M" ]; then
643 echo "Couldn't locate a makefile from the current directory."
645 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
658 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
659 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
660 for DIR in $DIRS ; do
661 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
662 if [ "$MODULES" = "" ]; then
665 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
666 if [ -f $DIR/Android.mk ]; then
667 TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
668 TO_CHOP=`expr $TO_CHOP + 1`
669 START=`PWD= /bin/pwd`
670 MFILE=`echo $START | cut -c${TO_CHOP}-`
671 if [ "$MFILE" = "" ] ; then
672 MFILE=$DIR/Android.mk
674 MFILE=$MFILE/$DIR/Android.mk
676 MAKEFILE="$MAKEFILE $MFILE"
678 if [ "$DIR" = snod ]; then
680 elif [ "$DIR" = showcommands ]; then
681 ARGS="$ARGS showcommands"
682 elif [ "$DIR" = dist ]; then
684 elif [ "$DIR" = incrementaljavac ]; then
685 ARGS="$ARGS incrementaljavac"
687 echo "No Android.mk in $DIR."
692 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS $MODULES $ARGS
694 echo "Couldn't locate the top of the tree. Try setting TOP."
704 echo "Couldn't locate the top of the tree. Try setting TOP."
710 TOPFILE=build/core/envsetup.mk
713 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
715 if [ -f "$T/Android.mk" ]; then
722 echo "can't find Android.mk"
729 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
732 echo "usage: pid name"
736 # systemstack - dump the current stack trace of all threads in the system process
737 # to the usual ANR traces file
738 function systemstack()
745 if [[ $1 =~ ^[0-9]+$ ]] ; then
750 echo "usage: stacks [pid|process name]"
754 local TRACES=/data/anr/traces.txt
755 local ORIG=/data/anr/traces.orig
756 local TMP=/data/anr/traces.tmp
758 # Keep original traces to avoid clobbering
759 adb shell mv $TRACES $ORIG
761 # Make sure we have a usable file
762 adb shell touch $TRACES
763 adb shell chmod 666 $TRACES
765 # Dump stacks and wait for dump to finish
766 adb shell kill -3 $PID
767 adb shell notify $TRACES
769 # Restore original stacks, and show current output
770 adb shell mv $TRACES $TMP
771 adb shell mv $ORIG $TRACES
772 adb shell cat $TMP | less -S
776 function gdbwrapper()
778 $ANDROID_TOOLCHAIN/$GDB -x "$@"
783 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
784 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
785 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
786 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
787 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
788 local ARCH=$(get_build_var TARGET_ARCH)
791 x86) GDB=i686-linux-android-gdb;;
792 arm) GDB=arm-linux-androideabi-gdb;;
793 mips) GDB=mipsel-linux-android-gdb;;
794 *) echo "Unknown arch $ARCH"; return 1;;
797 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
806 if [ "$PORT" ] ; then
814 if [ "$PROG" ] ; then
815 if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
820 adb forward "tcp$PORT" "tcp$PORT"
821 adb shell gdbserver $PORT --attach $PID &
825 echo "If you haven't done so already, do this first on the device:"
826 echo " gdbserver $PORT /system/bin/$EXE"
828 echo " gdbserver $PORT --attach $PID"
832 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
833 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx"
834 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
835 echo >>"$OUT_ROOT/gdbclient.cmds" ""
837 gdbwrapper "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
839 echo "Unable to determine build system output dir."
848 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 "$@"
855 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 "$@"
860 function gettargetarch
862 get_build_var TARGET_ARCH
867 find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
872 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 "$@"
877 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;
882 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
889 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
894 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 "$@"
901 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@"
906 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 "$@"
914 get_abs_build_var ANDROID_PREBUILTS
917 function tracedmdump()
921 echo "Couldn't locate the top of the tree. Try setting TOP."
924 local prebuiltdir=$(getprebuilt)
925 local arch=$(gettargetarch)
926 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
929 if [ ! "$TRACE" ] ; then
930 echo "usage: tracedmdump tracename"
934 if [ ! -r "$KERNEL" ] ; then
935 echo "Error: cannot find kernel: '$KERNEL'"
939 local BASETRACE=$(basename $TRACE)
940 if [ "$BASETRACE" = "$TRACE" ] ; then
941 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
944 echo "post-processing traces..."
945 rm -f $TRACE/qtrace.dexlist
947 if [ $? -ne 0 ]; then
949 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
953 echo "generating dexlist output..."
954 /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
955 echo "generating dmtrace data..."
956 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
957 echo "generating html file..."
958 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
959 echo "done, see $TRACE/dmtrace.html for details"
961 echo " traceview $TRACE/dmtrace"
964 # communicate with a running device or emulator, set up necessary state,
965 # and run the hat command.
968 # process standard adb options
970 if [ "$1" = "-d" -o "$1" = "-e" ]; then
973 elif [ "$1" = "-s" ]; then
977 local adbOptions=${adbTarget}
978 #echo adbOptions = ${adbOptions}
983 if [ "$targetPid" = "" ]; then
984 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
988 # confirm hat is available
989 if [ -z $(which hat) ]; then
990 echo "hat is not available in this configuration."
994 # issue "am" command to cause the hprof dump
995 local sdcard=$(adb shell echo -n '$EXTERNAL_STORAGE')
996 local devFile=$sdcard/hprof-$targetPid
997 #local devFile=/data/local/hprof-$targetPid
998 echo "Poking $targetPid and waiting for data..."
999 echo "Storing data at $devFile"
1000 adb ${adbOptions} shell am dumpheap $targetPid $devFile
1001 echo "Press enter when logcat shows \"hprof: heap dump completed\""
1005 local localFile=/tmp/$$-hprof
1007 echo "Retrieving file $devFile..."
1008 adb ${adbOptions} pull $devFile $localFile
1010 adb ${adbOptions} shell rm $devFile
1012 echo "Running hat on $localFile"
1013 echo "View the output by pointing your browser at http://localhost:7000/"
1015 hat -JXmx512m $localFile
1018 function getbugreports()
1020 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
1022 if [ ! "$reports" ]; then
1023 echo "Could not locate any bugreports."
1028 for report in ${reports[@]}
1030 echo "/sdcard/bugreports/${report}"
1031 adb pull /sdcard/bugreports/${report} ${report}
1036 function getsdcardpath()
1038 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1041 function getscreenshotpath()
1043 echo "$(getsdcardpath)/Pictures/Screenshots"
1046 function getlastscreenshot()
1048 local screenshot_path=$(getscreenshotpath)
1049 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1050 if [ "$screenshot" = "" ]; then
1051 echo "No screenshots found."
1054 echo "${screenshot}"
1055 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1058 function startviewserver()
1061 if [ $# -gt 0 ]; then
1064 adb shell service call window 1 i32 $port
1067 function stopviewserver()
1069 adb shell service call window 2
1072 function isviewserverstarted()
1074 adb shell service call window 3
1079 adb shell input keyevent 3
1084 adb shell input keyevent 4
1089 adb shell input keyevent 82
1092 function smoketest()
1094 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1095 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1100 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1104 (\cd "$T" && mmm tests/SmokeTest) &&
1105 adb uninstall com.android.smoketest > /dev/null &&
1106 adb uninstall com.android.smoketest.tests > /dev/null &&
1107 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1108 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1109 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1112 # simple shortcut to the runtest command
1117 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1120 ("$T"/development/testrunner/runtest.py $@)
1124 if [[ -z "$1" ]]; then
1125 echo "Usage: godir <regex>"
1129 if [[ ! -f $T/filelist ]]; then
1130 echo -n "Creating index..."
1131 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
1136 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1137 if [[ ${#lines[@]} = 0 ]]; then
1143 if [[ ${#lines[@]} > 1 ]]; then
1144 while [[ -z "$pathname" ]]; do
1147 for line in ${lines[@]}; do
1148 printf "%6s %s\n" "[$index]" $line
1149 index=$(($index + 1))
1152 echo -n "Select one: "
1155 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1156 echo "Invalid choice"
1159 pathname=${lines[$(($choice-1))]}
1162 pathname=${lines[0]}
1167 # Force JAVA_HOME to point to java 1.6 if it isn't already set
1168 function set_java_home() {
1169 if [ ! "$JAVA_HOME" ]; then
1172 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1175 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1181 if [ "x$SHELL" != "x/bin/bash" ]; then
1182 case `ps -o command -p $$` in
1186 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1191 # Execute the contents of any vendorsetup.sh files we can find.
1192 for f in `/bin/ls vendor/*/vendorsetup.sh vendor/*/*/vendorsetup.sh device/*/*/vendorsetup.sh 2> /dev/null`