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 - ggrep: Greps on all local Gradle files.
14 - jgrep: Greps on all local Java files.
15 - resgrep: Greps on all local res/*.xml files.
16 - godir: Go to the directory containing a file.
18 Look at the source to view more functions. The complete list is:
23 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
29 # Get the value of a build variable as an absolute path.
30 function get_abs_build_var()
34 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
37 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
38 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1)
41 # Get the exact value of a build variable.
42 function get_build_var()
46 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
49 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
50 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1
53 # check to see if the supplied product is one we can build
54 function check_product()
58 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
61 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
63 TARGET_BUILD_VARIANT= \
66 get_build_var TARGET_DEVICE > /dev/null
67 # hide successful answers, but allow the errors to show
70 VARIANT_CHOICES=(user userdebug eng)
72 # check to see if the supplied variant is valid
73 function check_variant()
75 for v in ${VARIANT_CHOICES[@]}
89 echo "Couldn't locate the top of the tree. Try setting TOP."
93 ##################################################################
95 # Read me before you modify this code #
97 # This function sets ANDROID_BUILD_PATHS to what it is adding #
98 # to PATH, and the next time it is run, it removes that from #
99 # PATH. This is required so lunch can be run more than once #
100 # and still have working paths. #
102 ##################################################################
104 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
105 # due to "C:\Program Files" being in the path.
108 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
109 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
111 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
112 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
113 # strip leading ':', if any
114 export PATH=${PATH/:%/}
117 # and in with the new
119 prebuiltdir=$(getprebuilt)
120 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
122 # defined in core/config.mk
123 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
124 export TARGET_GCC_VERSION=$targetgccversion
126 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
127 export ANDROID_EABI_TOOLCHAIN=
128 local ARCH=$(get_build_var TARGET_ARCH)
130 x86) toolchaindir=x86/i686-linux-android-$targetgccversion/bin
132 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
134 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
137 echo "Can't find toolchain for unknown architecture: $ARCH"
138 toolchaindir=xxxxxxxxx
141 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
142 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
145 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
148 toolchaindir=arm/arm-eabi-$targetgccversion/bin
149 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
150 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
151 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
154 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
157 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
161 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
162 export ANDROID_QTOOLS=$T/development/emulator/qtools
163 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
164 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
165 export PATH=$ANDROID_BUILD_PATHS$PATH
167 unset ANDROID_JAVA_TOOLCHAIN
168 unset ANDROID_PRE_BUILD_PATHS
169 if [ -n "$JAVA_HOME" ]; then
170 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
171 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
172 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
175 unset ANDROID_PRODUCT_OUT
176 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
177 export OUT=$ANDROID_PRODUCT_OUT
179 unset ANDROID_HOST_OUT
180 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
182 # needed for processing samples collected by perf counters
183 unset OPROFILE_EVENTS_DIR
184 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
186 # needed for building linux on MacOS
188 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
191 function printconfig()
195 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
198 get_build_var report_config
201 function set_stuff_for_environment()
208 export ANDROID_BUILD_TOP=$(gettop)
211 function set_sequence_number()
213 export BUILD_ENV_SEQUENCE_NUMBER=10
218 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
219 local arch=$(gettargetarch)
220 local product=$TARGET_PRODUCT
221 local variant=$TARGET_BUILD_VARIANT
222 local apps=$TARGET_BUILD_APPS
223 if [ -z "$apps" ]; then
224 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
226 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
231 function addcompletions()
235 # Keep us from trying to run in something that isn't bash.
236 if [ -z "${BASH_VERSION}" ]; then
240 # Keep us from trying to run in bash that's too old.
241 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
245 dir="sdk/bash_completion"
246 if [ -d ${dir} ]; then
247 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
254 function choosetype()
256 echo "Build type choices are:"
261 local DEFAULT_NUM DEFAULT_VALUE
263 DEFAULT_VALUE=release
265 export TARGET_BUILD_TYPE=
267 while [ -z $TARGET_BUILD_TYPE ]
269 echo -n "Which would you like? ["$DEFAULT_NUM"] "
270 if [ -z "$1" ] ; then
278 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
281 export TARGET_BUILD_TYPE=release
284 export TARGET_BUILD_TYPE=release
287 export TARGET_BUILD_TYPE=debug
290 export TARGET_BUILD_TYPE=debug
294 echo "I didn't understand your response. Please try again."
298 if [ -n "$1" ] ; then
303 set_stuff_for_environment
307 # This function isn't really right: It chooses a TARGET_PRODUCT
308 # based on the list of boards. Usually, that gets you something
309 # that kinda works with a generic product, but really, you should
310 # pick a product by name.
312 function chooseproduct()
314 if [ "x$TARGET_PRODUCT" != x ] ; then
315 default_value=$TARGET_PRODUCT
320 export TARGET_PRODUCT=
322 while [ -z "$TARGET_PRODUCT" ]
324 echo -n "Which product would you like? [$default_value] "
325 if [ -z "$1" ] ; then
332 if [ -z "$ANSWER" ] ; then
333 export TARGET_PRODUCT=$default_value
335 if check_product $ANSWER
337 export TARGET_PRODUCT=$ANSWER
339 echo "** Not a valid product: $ANSWER"
342 if [ -n "$1" ] ; then
347 set_stuff_for_environment
350 function choosevariant()
352 echo "Variant choices are:"
355 for v in ${VARIANT_CHOICES[@]}
357 # The product name is the name of the directory containing
358 # the makefile we found, above.
363 local default_value=eng
366 export TARGET_BUILD_VARIANT=
367 while [ -z "$TARGET_BUILD_VARIANT" ]
369 echo -n "Which would you like? [$default_value] "
370 if [ -z "$1" ] ; then
377 if [ -z "$ANSWER" ] ; then
378 export TARGET_BUILD_VARIANT=$default_value
379 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
380 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
381 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
384 if check_variant $ANSWER
386 export TARGET_BUILD_VARIANT=$ANSWER
388 echo "** Not a valid variant: $ANSWER"
391 if [ -n "$1" ] ; then
397 function choosecombo()
410 set_stuff_for_environment
414 # Clear this variable. It will be built up again when the vendorsetup.sh
415 # files are included at the end of this file.
416 unset LUNCH_MENU_CHOICES
417 function add_lunch_combo()
421 for c in ${LUNCH_MENU_CHOICES[@]} ; do
422 if [ "$new_combo" = "$c" ] ; then
426 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
429 # add the default one here
430 add_lunch_combo aosp_arm-eng
431 add_lunch_combo aosp_x86-eng
432 add_lunch_combo aosp_mips-eng
433 add_lunch_combo vbox_x86-eng
435 function print_lunch_menu()
439 echo "You're building on" $uname
441 echo "Lunch menu... pick a combo:"
445 for choice in ${LUNCH_MENU_CHOICES[@]}
462 echo -n "Which would you like? [aosp_arm-eng] "
470 selection=aosp_arm-eng
471 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
473 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
475 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
477 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
482 if [ -z "$selection" ]
485 echo "Invalid lunch combo: $answer"
489 export TARGET_BUILD_APPS=
491 local product=$(echo -n $selection | sed -e "s/-.*$//")
492 check_product $product
496 echo "** Don't have a product spec for: '$product'"
497 echo "** Do you have the right repo manifest?"
501 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
502 check_variant $variant
506 echo "** Invalid variant: '$variant'"
507 echo "** Must be one of ${VARIANT_CHOICES[@]}"
511 if [ -z "$product" -o -z "$variant" ]
517 export TARGET_PRODUCT=$product
518 export TARGET_BUILD_VARIANT=$variant
519 export TARGET_BUILD_TYPE=release
523 set_stuff_for_environment
527 # Tab completion for lunch.
532 cur="${COMP_WORDS[COMP_CWORD]}"
533 prev="${COMP_WORDS[COMP_CWORD-1]}"
535 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
538 complete -F _lunch lunch
540 # Configures the build to build unbundled apps.
541 # Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
544 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
545 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
546 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5)$'))
548 if [ $(echo $arch | wc -w) -gt 1 ]; then
549 echo "tapas: Error: Multiple build archs supplied: $arch"
552 if [ $(echo $variant | wc -w) -gt 1 ]; then
553 echo "tapas: Error: Multiple build variants supplied: $variant"
559 x86) product=full_x86;;
560 mips) product=full_mips;;
561 armv5) product=generic_armv5;;
563 if [ -z "$variant" ]; then
566 if [ -z "$apps" ]; then
570 export TARGET_PRODUCT=$product
571 export TARGET_BUILD_VARIANT=$variant
572 export TARGET_BUILD_TYPE=release
573 export TARGET_BUILD_APPS=$apps
575 set_stuff_for_environment
581 local TOPFILE=build/core/envsetup.mk
582 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
585 if [ -f $TOPFILE ] ; then
586 # The following circumlocution (repeated below as well) ensures
587 # that we record the true directory name and not one that is
588 # faked up with symlink names.
593 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
598 if [ -f "$T/$TOPFILE" ]; then
609 make -C $T -f build/core/main.mk $@
611 echo "Couldn't locate the top of the tree. Try setting TOP."
615 function findmakefile()
617 TOPFILE=build/core/envsetup.mk
620 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
622 if [ -f "$T/Android.mk" ]; then
634 # If we're sitting in the root of the build tree, just do a
636 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
639 # Find the closest Android.mk file.
641 local M=$(findmakefile)
643 local GET_INSTALL_PATH=
645 # Remove the path to top as the makefilepath needs to be relative
646 local M=`echo $M|sed 's:'$T'/::'`
648 echo "Couldn't locate the top of the tree. Try setting TOP."
649 elif [ ! "$M" ]; then
650 echo "Couldn't locate a makefile from the current directory."
654 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
657 if [ -n "$GET_INSTALL_PATH" ]; then
659 ARGS=GET-INSTALL-PATH
664 ONE_SHOT_MAKEFILE=$M make -C $T -f build/core/main.mk $MODULES $ARGS
677 local GET_INSTALL_PATH=
678 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
679 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
680 for DIR in $DIRS ; do
681 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
682 if [ "$MODULES" = "" ]; then
685 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
686 if [ -f $DIR/Android.mk ]; then
687 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
688 local TO_CHOP=`expr $TO_CHOP + 1`
689 local START=`PWD= /bin/pwd`
690 local MFILE=`echo $START | cut -c${TO_CHOP}-`
691 if [ "$MFILE" = "" ] ; then
692 MFILE=$DIR/Android.mk
694 MFILE=$MFILE/$DIR/Android.mk
696 MAKEFILE="$MAKEFILE $MFILE"
699 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
700 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
701 *) echo "No Android.mk in $DIR."; return 1;;
705 if [ -n "$GET_INSTALL_PATH" ]; then
706 ARGS=$GET_INSTALL_PATH
709 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
711 echo "Couldn't locate the top of the tree. Try setting TOP."
717 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
722 echo "Couldn't locate the top of the tree. Try setting TOP."
724 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
725 make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
733 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
734 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
735 local MY_PWD=`PWD= /bin/pwd`
736 if [ "$MY_PWD" = "$T" ]; then
739 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
744 for DIR in $DIRS ; do
746 if [ "$MY_PWD" = "" ]; then
747 MODULE_PATHS="$MODULE_PATHS $DIR"
749 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
753 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
754 *) echo "Couldn't find directory $DIR"; return 1;;
758 make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
760 echo "Couldn't locate the top of the tree. Try setting TOP."
770 echo "Couldn't locate the top of the tree. Try setting TOP."
776 TOPFILE=build/core/envsetup.mk
779 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
781 if [ -f "$T/Android.mk" ]; then
788 echo "can't find Android.mk"
791 # simplified version of ps; output in the form
796 if [ "$1" = "--exact" ]; then
800 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
801 echo "usage: qpid [[--exact] <process name|pid>"
807 qpid | \grep "$prepend$EXE$append"
811 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
819 if [ "$1" = "--exact" ]; then
826 local PID=`adb shell ps \
828 | \grep "$prepend$EXE$append" \
829 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
832 echo "usage: pid [--exact] <process name>"
837 # systemstack - dump the current stack trace of all threads in the system process
838 # to the usual ANR traces file
839 function systemstack()
846 if [[ $1 =~ ^[0-9]+$ ]] ; then
849 local PIDLIST="$(pid $1)"
850 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
852 elif [ "$PIDLIST" ] ; then
853 echo "more than one process: $1"
855 echo "no such process: $1"
858 echo "usage: stacks [pid|process name]"
862 # Determine whether the process is native
863 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
864 # Dump stacks of Dalvik process
865 local TRACES=/data/anr/traces.txt
866 local ORIG=/data/anr/traces.orig
867 local TMP=/data/anr/traces.tmp
869 # Keep original traces to avoid clobbering
870 adb shell mv $TRACES $ORIG
872 # Make sure we have a usable file
873 adb shell touch $TRACES
874 adb shell chmod 666 $TRACES
876 # Dump stacks and wait for dump to finish
877 adb shell kill -3 $PID
878 adb shell notify $TRACES >/dev/null
880 # Restore original stacks, and show current output
881 adb shell mv $TRACES $TMP
882 adb shell mv $ORIG $TRACES
885 # Dump stacks of native process
886 adb shell debuggerd -b $PID
891 function gdbwrapper()
893 $ANDROID_TOOLCHAIN/$GDB -x "$@"
898 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
899 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
900 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
901 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
902 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
903 local ARCH=$(get_build_var TARGET_ARCH)
906 x86) GDB=i686-linux-android-gdb;;
907 arm) GDB=arm-linux-androideabi-gdb;;
908 mips) GDB=mipsel-linux-android-gdb;;
909 *) echo "Unknown arch $ARCH"; return 1;;
912 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
921 if [ "$PORT" ] ; then
929 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
931 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
932 # that likely didn't work because of returning multiple processes
933 # try again, filtering by root processes (don't contain colon)
934 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
935 if [[ ! "$PID" =~ ^[0-9]+$ ]]
937 echo "Couldn't resolve '$3' to single PID"
941 echo "WARNING: multiple processes matching '$3' observed, using root process"
946 adb forward "tcp$PORT" "tcp$PORT"
947 adb shell gdbserver $PORT --attach $PID &
951 echo "If you haven't done so already, do this first on the device:"
952 echo " gdbserver $PORT /system/bin/$EXE"
954 echo " gdbserver $PORT --attach <PID>"
958 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
959 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"
960 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
961 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
962 echo >>"$OUT_ROOT/gdbclient.cmds" ""
964 gdbwrapper "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
966 echo "Unable to determine build system output dir."
975 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 "$@"
982 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 "$@"
987 function gettargetarch
989 get_build_var TARGET_ARCH
994 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
999 find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
1004 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 "$@"
1009 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;
1014 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1019 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 "$@"
1026 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 "$@"
1031 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 "$@"
1038 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 "$@"
1043 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 "$@"
1049 function getprebuilt
1051 get_abs_build_var ANDROID_PREBUILTS
1054 function tracedmdump()
1058 echo "Couldn't locate the top of the tree. Try setting TOP."
1061 local prebuiltdir=$(getprebuilt)
1062 local arch=$(gettargetarch)
1063 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
1066 if [ ! "$TRACE" ] ; then
1067 echo "usage: tracedmdump tracename"
1071 if [ ! -r "$KERNEL" ] ; then
1072 echo "Error: cannot find kernel: '$KERNEL'"
1076 local BASETRACE=$(basename $TRACE)
1077 if [ "$BASETRACE" = "$TRACE" ] ; then
1078 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1081 echo "post-processing traces..."
1082 rm -f $TRACE/qtrace.dexlist
1084 if [ $? -ne 0 ]; then
1086 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1090 echo "generating dexlist output..."
1091 /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
1092 echo "generating dmtrace data..."
1093 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1094 echo "generating html file..."
1095 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1096 echo "done, see $TRACE/dmtrace.html for details"
1098 echo " traceview $TRACE/dmtrace"
1101 # communicate with a running device or emulator, set up necessary state,
1102 # and run the hat command.
1105 # process standard adb options
1107 if [ "$1" = "-d" -o "$1" = "-e" ]; then
1110 elif [ "$1" = "-s" ]; then
1114 local adbOptions=${adbTarget}
1115 #echo adbOptions = ${adbOptions}
1120 if [ "$targetPid" = "" ]; then
1121 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
1125 # confirm hat is available
1126 if [ -z $(which hat) ]; then
1127 echo "hat is not available in this configuration."
1131 # issue "am" command to cause the hprof dump
1132 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE')
1133 local devFile=$sdcard/hprof-$targetPid
1134 #local devFile=/data/local/hprof-$targetPid
1135 echo "Poking $targetPid and waiting for data..."
1136 echo "Storing data at $devFile"
1137 adb ${adbOptions} shell am dumpheap $targetPid $devFile
1138 echo "Press enter when logcat shows \"hprof: heap dump completed\""
1142 local localFile=/tmp/$$-hprof
1144 echo "Retrieving file $devFile..."
1145 adb ${adbOptions} pull $devFile $localFile
1147 adb ${adbOptions} shell rm $devFile
1149 echo "Running hat on $localFile"
1150 echo "View the output by pointing your browser at http://localhost:7000/"
1152 hat -JXmx512m $localFile
1155 function getbugreports()
1157 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
1159 if [ ! "$reports" ]; then
1160 echo "Could not locate any bugreports."
1165 for report in ${reports[@]}
1167 echo "/sdcard/bugreports/${report}"
1168 adb pull /sdcard/bugreports/${report} ${report}
1173 function getsdcardpath()
1175 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1178 function getscreenshotpath()
1180 echo "$(getsdcardpath)/Pictures/Screenshots"
1183 function getlastscreenshot()
1185 local screenshot_path=$(getscreenshotpath)
1186 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1187 if [ "$screenshot" = "" ]; then
1188 echo "No screenshots found."
1191 echo "${screenshot}"
1192 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1195 function startviewserver()
1198 if [ $# -gt 0 ]; then
1201 adb shell service call window 1 i32 $port
1204 function stopviewserver()
1206 adb shell service call window 2
1209 function isviewserverstarted()
1211 adb shell service call window 3
1216 adb shell input keyevent 3
1221 adb shell input keyevent 4
1226 adb shell input keyevent 82
1229 function smoketest()
1231 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1232 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1237 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1241 (\cd "$T" && mmm tests/SmokeTest) &&
1242 adb uninstall com.android.smoketest > /dev/null &&
1243 adb uninstall com.android.smoketest.tests > /dev/null &&
1244 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1245 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1246 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1249 # simple shortcut to the runtest command
1254 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1257 ("$T"/development/testrunner/runtest.py $@)
1261 if [[ -z "$1" ]]; then
1262 echo "Usage: godir <regex>"
1266 if [[ ! -f $T/filelist ]]; then
1267 echo -n "Creating index..."
1268 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
1273 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
1274 if [[ ${#lines[@]} = 0 ]]; then
1280 if [[ ${#lines[@]} > 1 ]]; then
1281 while [[ -z "$pathname" ]]; do
1284 for line in ${lines[@]}; do
1285 printf "%6s %s\n" "[$index]" $line
1286 index=$(($index + 1))
1289 echo -n "Select one: "
1292 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1293 echo "Invalid choice"
1296 pathname=${lines[$(($choice-1))]}
1299 pathname=${lines[0]}
1304 # Force JAVA_HOME to point to java 1.6 if it isn't already set
1305 function set_java_home() {
1306 if [ ! "$JAVA_HOME" ]; then
1309 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1312 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1318 # Print colored exit condition
1322 if [ $retval -ne 0 ]
1324 echo -e "\e[0;31mFAILURE\e[00m"
1326 echo -e "\e[0;32mSUCCESS\e[00m"
1331 if [ "x$SHELL" != "x/bin/bash" ]; then
1332 case `ps -o command -p $$` in
1336 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1341 # Execute the contents of any vendorsetup.sh files we can find.
1342 for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1343 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`