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|armv5] [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, but not their dependencies.
9 - mmm: Builds all of the modules in the supplied directories, but not their dependencies.
10 - mma: Builds all of the modules in the current directory, and their dependencies.
11 - mmma: Builds all of the modules in the supplied directories, and their dependencies.
12 - cgrep: Greps on all local C/C++ files.
13 - jgrep: Greps on all local Java files.
14 - resgrep: Greps on all local res/*.xml files.
15 - godir: Go to the directory containing a file.
17 Look at the source to view more functions. The complete list is:
22 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
28 # Get the value of a build variable as an absolute path.
29 function get_abs_build_var()
33 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
36 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
37 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1)
40 # Get the exact value of a build variable.
41 function get_build_var()
45 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
48 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
49 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1
52 # check to see if the supplied product is one we can build
53 function check_product()
57 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
60 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
62 TARGET_BUILD_VARIANT= \
65 get_build_var TARGET_DEVICE > /dev/null
66 # hide successful answers, but allow the errors to show
69 VARIANT_CHOICES=(user userdebug eng)
71 # check to see if the supplied variant is valid
72 function check_variant()
74 for v in ${VARIANT_CHOICES[@]}
88 echo "Couldn't locate the top of the tree. Try setting TOP."
92 ##################################################################
94 # Read me before you modify this code #
96 # This function sets ANDROID_BUILD_PATHS to what it is adding #
97 # to PATH, and the next time it is run, it removes that from #
98 # PATH. This is required so lunch can be run more than once #
99 # and still have working paths. #
101 ##################################################################
103 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
104 # due to "C:\Program Files" being in the path.
107 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
108 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
110 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
111 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
112 # strip leading ':', if any
113 export PATH=${PATH/:%/}
116 # and in with the new
118 prebuiltdir=$(getprebuilt)
119 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
121 # defined in core/config.mk
122 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
123 export TARGET_GCC_VERSION=$targetgccversion
125 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
126 export ANDROID_EABI_TOOLCHAIN=
127 local ARCH=$(get_build_var TARGET_ARCH)
129 x86) toolchaindir=x86/i686-linux-android-$targetgccversion/bin
131 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
133 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
136 echo "Can't find toolchain for unknown architecture: $ARCH"
137 toolchaindir=xxxxxxxxx
140 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
141 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
144 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
147 toolchaindir=arm/arm-eabi-$targetgccversion/bin
148 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
149 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
150 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
153 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
156 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
160 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
161 export ANDROID_QTOOLS=$T/development/emulator/qtools
162 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
163 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
164 export PATH=$ANDROID_BUILD_PATHS$PATH
166 unset ANDROID_JAVA_TOOLCHAIN
167 unset ANDROID_PRE_BUILD_PATHS
168 if [ -n "$JAVA_HOME" ]; then
169 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
170 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
171 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
174 unset ANDROID_PRODUCT_OUT
175 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
176 export OUT=$ANDROID_PRODUCT_OUT
178 unset ANDROID_HOST_OUT
179 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
181 # needed for processing samples collected by perf counters
182 unset OPROFILE_EVENTS_DIR
183 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
185 # needed for building linux on MacOS
187 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
190 function printconfig()
194 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
197 get_build_var report_config
200 function set_stuff_for_environment()
207 export ANDROID_BUILD_TOP=$(gettop)
210 function set_sequence_number()
212 export BUILD_ENV_SEQUENCE_NUMBER=10
217 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
218 local arch=$(gettargetarch)
219 local product=$TARGET_PRODUCT
220 local variant=$TARGET_BUILD_VARIANT
221 local apps=$TARGET_BUILD_APPS
222 if [ -z "$apps" ]; then
223 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
225 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
230 function addcompletions()
234 # Keep us from trying to run in something that isn't bash.
235 if [ -z "${BASH_VERSION}" ]; then
239 # Keep us from trying to run in bash that's too old.
240 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
244 dir="sdk/bash_completion"
245 if [ -d ${dir} ]; then
246 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
253 function choosetype()
255 echo "Build type choices are:"
260 local DEFAULT_NUM DEFAULT_VALUE
262 DEFAULT_VALUE=release
264 export TARGET_BUILD_TYPE=
266 while [ -z $TARGET_BUILD_TYPE ]
268 echo -n "Which would you like? ["$DEFAULT_NUM"] "
269 if [ -z "$1" ] ; then
277 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
280 export TARGET_BUILD_TYPE=release
283 export TARGET_BUILD_TYPE=release
286 export TARGET_BUILD_TYPE=debug
289 export TARGET_BUILD_TYPE=debug
293 echo "I didn't understand your response. Please try again."
297 if [ -n "$1" ] ; then
302 set_stuff_for_environment
306 # This function isn't really right: It chooses a TARGET_PRODUCT
307 # based on the list of boards. Usually, that gets you something
308 # that kinda works with a generic product, but really, you should
309 # pick a product by name.
311 function chooseproduct()
313 if [ "x$TARGET_PRODUCT" != x ] ; then
314 default_value=$TARGET_PRODUCT
319 export TARGET_PRODUCT=
321 while [ -z "$TARGET_PRODUCT" ]
323 echo -n "Which product would you like? [$default_value] "
324 if [ -z "$1" ] ; then
331 if [ -z "$ANSWER" ] ; then
332 export TARGET_PRODUCT=$default_value
334 if check_product $ANSWER
336 export TARGET_PRODUCT=$ANSWER
338 echo "** Not a valid product: $ANSWER"
341 if [ -n "$1" ] ; then
346 set_stuff_for_environment
349 function choosevariant()
351 echo "Variant choices are:"
354 for v in ${VARIANT_CHOICES[@]}
356 # The product name is the name of the directory containing
357 # the makefile we found, above.
362 local default_value=eng
365 export TARGET_BUILD_VARIANT=
366 while [ -z "$TARGET_BUILD_VARIANT" ]
368 echo -n "Which would you like? [$default_value] "
369 if [ -z "$1" ] ; then
376 if [ -z "$ANSWER" ] ; then
377 export TARGET_BUILD_VARIANT=$default_value
378 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
379 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
380 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
383 if check_variant $ANSWER
385 export TARGET_BUILD_VARIANT=$ANSWER
387 echo "** Not a valid variant: $ANSWER"
390 if [ -n "$1" ] ; then
396 function choosecombo()
409 set_stuff_for_environment
413 # Clear this variable. It will be built up again when the vendorsetup.sh
414 # files are included at the end of this file.
415 unset LUNCH_MENU_CHOICES
416 function add_lunch_combo()
420 for c in ${LUNCH_MENU_CHOICES[@]} ; do
421 if [ "$new_combo" = "$c" ] ; then
425 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
428 # add the default one here
429 add_lunch_combo aosp_arm-eng
430 add_lunch_combo aosp_x86-eng
431 add_lunch_combo aosp_mips-eng
432 add_lunch_combo vbox_x86-eng
434 function print_lunch_menu()
438 echo "You're building on" $uname
440 echo "Lunch menu... pick a combo:"
444 for choice in ${LUNCH_MENU_CHOICES[@]}
461 echo -n "Which would you like? [aosp_arm-eng] "
469 selection=aosp_arm-eng
470 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
472 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
474 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
476 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
481 if [ -z "$selection" ]
484 echo "Invalid lunch combo: $answer"
488 export TARGET_BUILD_APPS=
490 local product=$(echo -n $selection | sed -e "s/-.*$//")
491 check_product $product
495 echo "** Don't have a product spec for: '$product'"
496 echo "** Do you have the right repo manifest?"
500 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
501 check_variant $variant
505 echo "** Invalid variant: '$variant'"
506 echo "** Must be one of ${VARIANT_CHOICES[@]}"
510 if [ -z "$product" -o -z "$variant" ]
516 export TARGET_PRODUCT=$product
517 export TARGET_BUILD_VARIANT=$variant
518 export TARGET_BUILD_TYPE=release
522 set_stuff_for_environment
526 # Tab completion for lunch.
531 cur="${COMP_WORDS[COMP_CWORD]}"
532 prev="${COMP_WORDS[COMP_CWORD-1]}"
534 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
537 complete -F _lunch lunch
539 # Configures the build to build unbundled apps.
540 # Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
543 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
544 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
545 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5)$'))
547 if [ $(echo $arch | wc -w) -gt 1 ]; then
548 echo "tapas: Error: Multiple build archs supplied: $arch"
551 if [ $(echo $variant | wc -w) -gt 1 ]; then
552 echo "tapas: Error: Multiple build variants supplied: $variant"
558 x86) product=full_x86;;
559 mips) product=full_mips;;
560 armv5) product=generic_armv5;;
562 if [ -z "$variant" ]; then
565 if [ -z "$apps" ]; then
569 export TARGET_PRODUCT=$product
570 export TARGET_BUILD_VARIANT=$variant
571 export TARGET_BUILD_TYPE=release
572 export TARGET_BUILD_APPS=$apps
574 set_stuff_for_environment
580 local TOPFILE=build/core/envsetup.mk
581 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
584 if [ -f $TOPFILE ] ; then
585 # The following circumlocution (repeated below as well) ensures
586 # that we record the true directory name and not one that is
587 # faked up with symlink names.
592 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
597 if [ -f "$T/$TOPFILE" ]; then
608 make -C $T -f build/core/main.mk $@
610 echo "Couldn't locate the top of the tree. Try setting TOP."
614 function findmakefile()
616 TOPFILE=build/core/envsetup.mk
619 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
621 if [ -f "$T/Android.mk" ]; then
633 # If we're sitting in the root of the build tree, just do a
635 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
638 # Find the closest Android.mk file.
640 local M=$(findmakefile)
641 # Remove the path to top as the makefilepath needs to be relative
642 local M=`echo $M|sed 's:'$T'/::'`
644 echo "Couldn't locate the top of the tree. Try setting TOP."
645 elif [ ! "$M" ]; then
646 echo "Couldn't locate a makefile from the current directory."
648 ONE_SHOT_MAKEFILE=$M make -C $T -f build/core/main.mk all_modules $@
661 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
662 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
663 for DIR in $DIRS ; do
664 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
665 if [ "$MODULES" = "" ]; then
668 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
669 if [ -f $DIR/Android.mk ]; then
670 TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
671 TO_CHOP=`expr $TO_CHOP + 1`
672 START=`PWD= /bin/pwd`
673 MFILE=`echo $START | cut -c${TO_CHOP}-`
674 if [ "$MFILE" = "" ] ; then
675 MFILE=$DIR/Android.mk
677 MFILE=$MFILE/$DIR/Android.mk
679 MAKEFILE="$MAKEFILE $MFILE"
681 if [ "$DIR" = snod ]; then
683 elif [ "$DIR" = showcommands ]; then
684 ARGS="$ARGS showcommands"
685 elif [ "$DIR" = dist ]; then
687 elif [ "$DIR" = incrementaljavac ]; then
688 ARGS="$ARGS incrementaljavac"
690 echo "No Android.mk in $DIR."
695 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
697 echo "Couldn't locate the top of the tree. Try setting TOP."
703 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
708 echo "Couldn't locate the top of the tree. Try setting TOP."
710 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
711 make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
719 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
720 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
721 local MY_PWD=`PWD= /bin/pwd`
722 if [ "$MY_PWD" = "$T" ]; then
725 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
730 for DIR in $DIRS ; do
732 if [ "$MY_PWD" = "" ]; then
733 MODULE_PATHS="$MODULE_PATHS $DIR"
735 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
739 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
740 *) echo "Couldn't find directory $DIR"; return 1;;
744 make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
746 echo "Couldn't locate the top of the tree. Try setting TOP."
756 echo "Couldn't locate the top of the tree. Try setting TOP."
762 TOPFILE=build/core/envsetup.mk
765 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
767 if [ -f "$T/Android.mk" ]; then
774 echo "can't find Android.mk"
781 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
784 echo "usage: pid name"
788 # systemstack - dump the current stack trace of all threads in the system process
789 # to the usual ANR traces file
790 function systemstack()
797 if [[ $1 =~ ^[0-9]+$ ]] ; then
802 echo "usage: stacks [pid|process name]"
806 local TRACES=/data/anr/traces.txt
807 local ORIG=/data/anr/traces.orig
808 local TMP=/data/anr/traces.tmp
810 # Keep original traces to avoid clobbering
811 adb shell mv $TRACES $ORIG
813 # Make sure we have a usable file
814 adb shell touch $TRACES
815 adb shell chmod 666 $TRACES
817 # Dump stacks and wait for dump to finish
818 adb shell kill -3 $PID
819 adb shell notify $TRACES
821 # Restore original stacks, and show current output
822 adb shell mv $TRACES $TMP
823 adb shell mv $ORIG $TRACES
824 adb shell cat $TMP | less -S
828 function gdbwrapper()
830 $ANDROID_TOOLCHAIN/$GDB -x "$@"
835 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
836 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
837 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
838 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
839 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
840 local ARCH=$(get_build_var TARGET_ARCH)
843 x86) GDB=i686-linux-android-gdb;;
844 arm) GDB=arm-linux-androideabi-gdb;;
845 mips) GDB=mipsel-linux-android-gdb;;
846 *) echo "Unknown arch $ARCH"; return 1;;
849 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
858 if [ "$PORT" ] ; then
866 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
868 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
869 # that likely didn't work because of returning multiple processes
870 # try again, filtering by root processes (don't contain colon)
871 PID=`adb shell ps | grep $3 | grep -v ":" | awk '{print $2}'`
872 if [[ ! "$PID" =~ ^[0-9]+$ ]]
874 echo "Couldn't resolve '$3' to single PID"
878 echo "WARNING: multiple processes matching '$3' observed, using root process"
883 adb forward "tcp$PORT" "tcp$PORT"
884 adb shell gdbserver $PORT --attach $PID &
888 echo "If you haven't done so already, do this first on the device:"
889 echo " gdbserver $PORT /system/bin/$EXE"
891 echo " gdbserver $PORT --attach <PID>"
895 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
896 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"
897 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
898 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
899 echo >>"$OUT_ROOT/gdbclient.cmds" ""
901 gdbwrapper "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
903 echo "Unable to determine build system output dir."
912 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 "$@"
919 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 "$@"
924 function gettargetarch
926 get_build_var TARGET_ARCH
931 find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
936 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 "$@"
941 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;
946 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
951 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d -print0 | xargs -0 grep --color -n -r --exclude-dir=\.git "$@"
958 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 "$@"
963 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 "$@"
970 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 "$@"
975 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 "$@"
983 get_abs_build_var ANDROID_PREBUILTS
986 function tracedmdump()
990 echo "Couldn't locate the top of the tree. Try setting TOP."
993 local prebuiltdir=$(getprebuilt)
994 local arch=$(gettargetarch)
995 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
998 if [ ! "$TRACE" ] ; then
999 echo "usage: tracedmdump tracename"
1003 if [ ! -r "$KERNEL" ] ; then
1004 echo "Error: cannot find kernel: '$KERNEL'"
1008 local BASETRACE=$(basename $TRACE)
1009 if [ "$BASETRACE" = "$TRACE" ] ; then
1010 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1013 echo "post-processing traces..."
1014 rm -f $TRACE/qtrace.dexlist
1016 if [ $? -ne 0 ]; then
1018 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1022 echo "generating dexlist output..."
1023 /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
1024 echo "generating dmtrace data..."
1025 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1026 echo "generating html file..."
1027 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1028 echo "done, see $TRACE/dmtrace.html for details"
1030 echo " traceview $TRACE/dmtrace"
1033 # communicate with a running device or emulator, set up necessary state,
1034 # and run the hat command.
1037 # process standard adb options
1039 if [ "$1" = "-d" -o "$1" = "-e" ]; then
1042 elif [ "$1" = "-s" ]; then
1046 local adbOptions=${adbTarget}
1047 #echo adbOptions = ${adbOptions}
1052 if [ "$targetPid" = "" ]; then
1053 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
1057 # confirm hat is available
1058 if [ -z $(which hat) ]; then
1059 echo "hat is not available in this configuration."
1063 # issue "am" command to cause the hprof dump
1064 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
1065 local devFile=$sdcard/hprof-$targetPid
1066 #local devFile=/data/local/hprof-$targetPid
1067 echo "Poking $targetPid and waiting for data..."
1068 echo "Storing data at $devFile"
1069 adb ${adbOptions} shell am dumpheap $targetPid $devFile
1070 echo "Press enter when logcat shows \"hprof: heap dump completed\""
1074 local localFile=/tmp/$$-hprof
1076 echo "Retrieving file $devFile..."
1077 adb ${adbOptions} pull $devFile $localFile
1079 adb ${adbOptions} shell rm $devFile
1081 echo "Running hat on $localFile"
1082 echo "View the output by pointing your browser at http://localhost:7000/"
1084 hat -JXmx512m $localFile
1087 function getbugreports()
1089 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
1091 if [ ! "$reports" ]; then
1092 echo "Could not locate any bugreports."
1097 for report in ${reports[@]}
1099 echo "/sdcard/bugreports/${report}"
1100 adb pull /sdcard/bugreports/${report} ${report}
1105 function getsdcardpath()
1107 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1110 function getscreenshotpath()
1112 echo "$(getsdcardpath)/Pictures/Screenshots"
1115 function getlastscreenshot()
1117 local screenshot_path=$(getscreenshotpath)
1118 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1119 if [ "$screenshot" = "" ]; then
1120 echo "No screenshots found."
1123 echo "${screenshot}"
1124 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1127 function startviewserver()
1130 if [ $# -gt 0 ]; then
1133 adb shell service call window 1 i32 $port
1136 function stopviewserver()
1138 adb shell service call window 2
1141 function isviewserverstarted()
1143 adb shell service call window 3
1148 adb shell input keyevent 3
1153 adb shell input keyevent 4
1158 adb shell input keyevent 82
1161 function smoketest()
1163 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1164 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1169 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1173 (\cd "$T" && mmm tests/SmokeTest) &&
1174 adb uninstall com.android.smoketest > /dev/null &&
1175 adb uninstall com.android.smoketest.tests > /dev/null &&
1176 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1177 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1178 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1181 # simple shortcut to the runtest command
1186 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1189 ("$T"/development/testrunner/runtest.py $@)
1193 if [[ -z "$1" ]]; then
1194 echo "Usage: godir <regex>"
1198 if [[ ! -f $T/filelist ]]; then
1199 echo -n "Creating index..."
1200 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
1205 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1206 if [[ ${#lines[@]} = 0 ]]; then
1212 if [[ ${#lines[@]} > 1 ]]; then
1213 while [[ -z "$pathname" ]]; do
1216 for line in ${lines[@]}; do
1217 printf "%6s %s\n" "[$index]" $line
1218 index=$(($index + 1))
1221 echo -n "Select one: "
1224 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1225 echo "Invalid choice"
1228 pathname=${lines[$(($choice-1))]}
1231 pathname=${lines[0]}
1236 # Force JAVA_HOME to point to java 1.6 if it isn't already set
1237 function set_java_home() {
1238 if [ ! "$JAVA_HOME" ]; then
1241 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1244 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1250 # Print colored exit condition
1254 if [ $retval -ne 0 ]
1256 echo -e "\e[0;31mFAILURE\e[00m"
1258 echo -e "\e[0;32mSUCCESS\e[00m"
1263 if [ "x$SHELL" != "x/bin/bash" ]; then
1264 case `ps -o command -p $$` in
1268 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1273 # Execute the contents of any vendorsetup.sh files we can find.
1274 for f in `/bin/ls vendor/*/vendorsetup.sh vendor/*/*/vendorsetup.sh device/*/*/vendorsetup.sh 2> /dev/null`