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|arm64|x86_64|mips64] [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 To limit the modules being built use the syntax: mmm dir/:target1,target2.
11 - mma: Builds all of the modules in the current directory, and their dependencies.
12 - mmma: Builds all of the modules in the supplied directories, and their dependencies.
13 - cgrep: Greps on all local C/C++ files.
14 - ggrep: Greps on all local Gradle files.
15 - jgrep: Greps on all local Java files.
16 - resgrep: Greps on all local res/*.xml files.
17 - mangrep: Greps on all local AndroidManifest.xml files.
18 - sepgrep: Greps on all local sepolicy files.
19 - sgrep: Greps on all local source files.
20 - godir: Go to the directory containing a file.
23 - SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
24 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
25 build is leak-check clean.
27 Look at the source to view more functions. The complete list is:
32 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
38 # Get the value of a build variable as an absolute path.
39 function get_abs_build_var()
43 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
46 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
47 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
50 # Get the exact value of a build variable.
51 function get_build_var()
55 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
58 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
59 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
62 # check to see if the supplied product is one we can build
63 function check_product()
67 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
71 TARGET_BUILD_VARIANT= \
74 get_build_var TARGET_DEVICE > /dev/null
75 # hide successful answers, but allow the errors to show
78 VARIANT_CHOICES=(user userdebug eng)
80 # check to see if the supplied variant is valid
81 function check_variant()
83 for v in ${VARIANT_CHOICES[@]}
97 echo "Couldn't locate the top of the tree. Try setting TOP."
101 ##################################################################
103 # Read me before you modify this code #
105 # This function sets ANDROID_BUILD_PATHS to what it is adding #
106 # to PATH, and the next time it is run, it removes that from #
107 # PATH. This is required so lunch can be run more than once #
108 # and still have working paths. #
110 ##################################################################
112 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
113 # due to "C:\Program Files" being in the path.
116 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
117 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
119 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
120 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
121 # strip leading ':', if any
122 export PATH=${PATH/:%/}
125 # and in with the new
126 prebuiltdir=$(getprebuilt)
127 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
129 # defined in core/config.mk
130 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
131 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
132 export TARGET_GCC_VERSION=$targetgccversion
134 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
135 export ANDROID_TOOLCHAIN=
136 export ANDROID_TOOLCHAIN_2ND_ARCH=
137 local ARCH=$(get_build_var TARGET_ARCH)
139 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
141 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
143 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
145 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
146 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
148 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
151 echo "Can't find toolchain for unknown architecture: $ARCH"
152 toolchaindir=xxxxxxxxx
155 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
156 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
159 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
160 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
163 unset ANDROID_KERNEL_TOOLCHAIN_PATH
166 # Legacy toolchain configuration used for ARM kernel compilation
167 toolchaindir=arm/arm-eabi-$targetgccversion/bin
168 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
169 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
170 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
174 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
178 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
179 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
181 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
182 # to ensure that the corresponding 'emulator' binaries are used.
185 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
188 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
191 ANDROID_EMULATOR_PREBUILTS=
194 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
195 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
196 export ANDROID_EMULATOR_PREBUILTS
199 export PATH=$ANDROID_BUILD_PATHS$PATH
201 unset ANDROID_JAVA_TOOLCHAIN
202 unset ANDROID_PRE_BUILD_PATHS
203 if [ -n "$JAVA_HOME" ]; then
204 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
205 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
206 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
209 unset ANDROID_PRODUCT_OUT
210 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
211 export OUT=$ANDROID_PRODUCT_OUT
213 unset ANDROID_HOST_OUT
214 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
216 # needed for building linux on MacOS
218 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
221 function printconfig()
225 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
228 get_build_var report_config
231 function set_stuff_for_environment()
238 export ANDROID_BUILD_TOP=$(gettop)
239 # With this environment variable new GCC can apply colors to warnings/errors
240 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
241 export ASAN_OPTIONS=detect_leaks=0
244 function set_sequence_number()
246 export BUILD_ENV_SEQUENCE_NUMBER=10
251 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
252 local arch=$(gettargetarch)
253 local product=$TARGET_PRODUCT
254 local variant=$TARGET_BUILD_VARIANT
255 local apps=$TARGET_BUILD_APPS
256 if [ -z "$apps" ]; then
257 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
259 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
264 function addcompletions()
268 # Keep us from trying to run in something that isn't bash.
269 if [ -z "${BASH_VERSION}" ]; then
273 # Keep us from trying to run in bash that's too old.
274 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
278 dir="sdk/bash_completion"
279 if [ -d ${dir} ]; then
280 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
287 function choosetype()
289 echo "Build type choices are:"
294 local DEFAULT_NUM DEFAULT_VALUE
296 DEFAULT_VALUE=release
298 export TARGET_BUILD_TYPE=
300 while [ -z $TARGET_BUILD_TYPE ]
302 echo -n "Which would you like? ["$DEFAULT_NUM"] "
303 if [ -z "$1" ] ; then
311 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
314 export TARGET_BUILD_TYPE=release
317 export TARGET_BUILD_TYPE=release
320 export TARGET_BUILD_TYPE=debug
323 export TARGET_BUILD_TYPE=debug
327 echo "I didn't understand your response. Please try again."
331 if [ -n "$1" ] ; then
336 set_stuff_for_environment
340 # This function isn't really right: It chooses a TARGET_PRODUCT
341 # based on the list of boards. Usually, that gets you something
342 # that kinda works with a generic product, but really, you should
343 # pick a product by name.
345 function chooseproduct()
347 if [ "x$TARGET_PRODUCT" != x ] ; then
348 default_value=$TARGET_PRODUCT
353 export TARGET_PRODUCT=
355 while [ -z "$TARGET_PRODUCT" ]
357 echo -n "Which product would you like? [$default_value] "
358 if [ -z "$1" ] ; then
365 if [ -z "$ANSWER" ] ; then
366 export TARGET_PRODUCT=$default_value
368 if check_product $ANSWER
370 export TARGET_PRODUCT=$ANSWER
372 echo "** Not a valid product: $ANSWER"
375 if [ -n "$1" ] ; then
380 set_stuff_for_environment
383 function choosevariant()
385 echo "Variant choices are:"
388 for v in ${VARIANT_CHOICES[@]}
390 # The product name is the name of the directory containing
391 # the makefile we found, above.
396 local default_value=eng
399 export TARGET_BUILD_VARIANT=
400 while [ -z "$TARGET_BUILD_VARIANT" ]
402 echo -n "Which would you like? [$default_value] "
403 if [ -z "$1" ] ; then
410 if [ -z "$ANSWER" ] ; then
411 export TARGET_BUILD_VARIANT=$default_value
412 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
413 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
414 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
417 if check_variant $ANSWER
419 export TARGET_BUILD_VARIANT=$ANSWER
421 echo "** Not a valid variant: $ANSWER"
424 if [ -n "$1" ] ; then
430 function choosecombo()
443 set_stuff_for_environment
447 # Clear this variable. It will be built up again when the vendorsetup.sh
448 # files are included at the end of this file.
449 unset LUNCH_MENU_CHOICES
450 function add_lunch_combo()
454 for c in ${LUNCH_MENU_CHOICES[@]} ; do
455 if [ "$new_combo" = "$c" ] ; then
459 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
462 # add the default one here
463 add_lunch_combo aosp_arm-eng
464 add_lunch_combo aosp_arm64-eng
465 add_lunch_combo aosp_mips-eng
466 add_lunch_combo aosp_mips64-eng
467 add_lunch_combo aosp_x86-eng
468 add_lunch_combo aosp_x86_64-eng
470 function print_lunch_menu()
474 echo "You're building on" $uname
476 echo "Lunch menu... pick a combo:"
480 for choice in ${LUNCH_MENU_CHOICES[@]}
497 echo -n "Which would you like? [aosp_arm-eng] "
505 selection=aosp_arm-eng
506 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
508 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
510 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
512 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
517 if [ -z "$selection" ]
520 echo "Invalid lunch combo: $answer"
524 export TARGET_BUILD_APPS=
526 local product=$(echo -n $selection | sed -e "s/-.*$//")
527 check_product $product
531 echo "** Don't have a product spec for: '$product'"
532 echo "** Do you have the right repo manifest?"
536 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
537 check_variant $variant
541 echo "** Invalid variant: '$variant'"
542 echo "** Must be one of ${VARIANT_CHOICES[@]}"
546 if [ -z "$product" -o -z "$variant" ]
552 export TARGET_PRODUCT=$product
553 export TARGET_BUILD_VARIANT=$variant
554 export TARGET_BUILD_TYPE=release
558 set_stuff_for_environment
562 # Tab completion for lunch.
567 cur="${COMP_WORDS[COMP_CWORD]}"
568 prev="${COMP_WORDS[COMP_CWORD-1]}"
570 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
573 complete -F _lunch lunch
575 # Configures the build to build unbundled apps.
576 # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
579 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
580 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
581 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
582 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
584 if [ $(echo $arch | wc -w) -gt 1 ]; then
585 echo "tapas: Error: Multiple build archs supplied: $arch"
588 if [ $(echo $variant | wc -w) -gt 1 ]; then
589 echo "tapas: Error: Multiple build variants supplied: $variant"
592 if [ $(echo $density | wc -w) -gt 1 ]; then
593 echo "tapas: Error: Multiple densities supplied: $density"
599 x86) product=full_x86;;
600 mips) product=full_mips;;
601 armv5) product=generic_armv5;;
602 arm64) product=aosp_arm64;;
603 x86_64) product=aosp_x86_64;;
604 mips64) product=aosp_mips64;;
606 if [ -z "$variant" ]; then
609 if [ -z "$apps" ]; then
612 if [ -z "$density" ]; then
616 export TARGET_PRODUCT=$product
617 export TARGET_BUILD_VARIANT=$variant
618 export TARGET_BUILD_DENSITY=$density
619 export TARGET_BUILD_TYPE=release
620 export TARGET_BUILD_APPS=$apps
622 set_stuff_for_environment
628 local TOPFILE=build/core/envsetup.mk
629 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
630 # The following circumlocution ensures we remove symlinks from TOP.
631 (cd $TOP; PWD= /bin/pwd)
633 if [ -f $TOPFILE ] ; then
634 # The following circumlocution (repeated below as well) ensures
635 # that we record the true directory name and not one that is
636 # faked up with symlink names.
641 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
646 if [ -f "$T/$TOPFILE" ]; then
653 # Return driver for "make", if any (eg. static analyzer)
657 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
658 if [ -n "$WITH_STATIC_ANALYZER" ]; then
660 $T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
661 --use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
670 local DRV=$(getdriver $T)
672 $DRV make -C $T -f build/core/main.mk $@
674 echo "Couldn't locate the top of the tree. Try setting TOP."
679 function findmakefile()
681 TOPFILE=build/core/envsetup.mk
684 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
686 if [ -f "$T/Android.mk" ]; then
699 local DRV=$(getdriver $T)
700 # If we're sitting in the root of the build tree, just do a
702 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
705 # Find the closest Android.mk file.
706 local M=$(findmakefile)
708 local GET_INSTALL_PATH=
710 # Remove the path to top as the makefilepath needs to be relative
711 local M=`echo $M|sed 's:'$T'/::'`
713 echo "Couldn't locate the top of the tree. Try setting TOP."
715 elif [ ! "$M" ]; then
716 echo "Couldn't locate a makefile from the current directory."
721 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
724 if [ -n "$GET_INSTALL_PATH" ]; then
726 ARGS=GET-INSTALL-PATH
731 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
739 local DRV=$(getdriver $T)
745 local GET_INSTALL_PATH=
746 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
747 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
748 for DIR in $DIRS ; do
749 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
750 if [ "$MODULES" = "" ]; then
753 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
754 if [ -f $DIR/Android.mk ]; then
755 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
756 local TO_CHOP=`expr $TO_CHOP + 1`
757 local START=`PWD= /bin/pwd`
758 local MFILE=`echo $START | cut -c${TO_CHOP}-`
759 if [ "$MFILE" = "" ] ; then
760 MFILE=$DIR/Android.mk
762 MFILE=$MFILE/$DIR/Android.mk
764 MAKEFILE="$MAKEFILE $MFILE"
767 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
768 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
769 *) echo "No Android.mk in $DIR."; return 1;;
773 if [ -n "$GET_INSTALL_PATH" ]; then
774 ARGS=$GET_INSTALL_PATH
777 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
779 echo "Couldn't locate the top of the tree. Try setting TOP."
787 local DRV=$(getdriver $T)
788 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
792 echo "Couldn't locate the top of the tree. Try setting TOP."
795 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
796 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
803 local DRV=$(getdriver $T)
805 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
806 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
807 local MY_PWD=`PWD= /bin/pwd`
808 if [ "$MY_PWD" = "$T" ]; then
811 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
816 for DIR in $DIRS ; do
818 if [ "$MY_PWD" = "" ]; then
819 MODULE_PATHS="$MODULE_PATHS $DIR"
821 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
825 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
826 *) echo "Couldn't find directory $DIR"; return 1;;
830 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
832 echo "Couldn't locate the top of the tree. Try setting TOP."
843 echo "Couldn't locate the top of the tree. Try setting TOP."
849 TOPFILE=build/core/envsetup.mk
852 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
854 if [ -f "$T/Android.mk" ]; then
861 echo "can't find Android.mk"
864 # simplified version of ps; output in the form
869 if [ "$1" = "--exact" ]; then
873 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
874 echo "usage: qpid [[--exact] <process name|pid>"
880 qpid | \grep "$prepend$EXE$append"
884 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
892 if [ "$1" = "--exact" ]; then
899 local PID=`adb shell ps \
901 | \grep "$prepend$EXE$append" \
902 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
905 echo "usage: pid [--exact] <process name>"
910 # coredump_setup - enable core dumps globally for any process
911 # that has the core-file-size limit set correctly
913 # NOTE: You must call also coredump_enable for a specific process
914 # if its core-file-size limit is not set already.
915 # NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
917 function coredump_setup()
919 echo "Getting root...";
923 echo "Remounting root parition read-write...";
924 adb shell mount -w -o remount -t rootfs rootfs;
927 adb shell mkdir -p /cores;
928 adb shell mount -t tmpfs tmpfs /cores;
929 adb shell chmod 0777 /cores;
931 echo "Granting SELinux permission to dump in /cores...";
932 adb shell restorecon -R /cores;
934 echo "Set core pattern.";
935 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
940 # coredump_enable - enable core dumps for the specified process
941 # $1 = PID of process (e.g., $(pid mediaserver))
943 # NOTE: coredump_setup must have been called as well for a core
944 # dump to actually be generated.
946 function coredump_enable()
949 if [ -z "$PID" ]; then
950 printf "Expecting a PID!\n";
953 echo "Setting core limit for $PID to infinite...";
954 adb shell prlimit $PID 4 -1 -1
957 # core - send SIGV and pull the core for process
958 # $1 = PID of process (e.g., $(pid mediaserver))
960 # NOTE: coredump_setup must be called once per boot for core dumps to be
967 if [ -z "$PID" ]; then
968 printf "Expecting a PID!\n";
972 local CORENAME=core.$PID;
973 local COREPATH=/cores/$CORENAME;
979 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
980 printf "\tSending SIG%s to %d...\n" $SIG $PID;
981 adb shell kill -$SIG $PID;
985 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
986 echo "Done: core is under $COREPATH on device.";
989 # systemstack - dump the current stack trace of all threads in the system process
990 # to the usual ANR traces file
991 function systemstack()
998 if [[ $1 =~ ^[0-9]+$ ]] ; then
1000 elif [ "$1" ] ; then
1001 local PIDLIST="$(pid $1)"
1002 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1003 local PID="$PIDLIST"
1004 elif [ "$PIDLIST" ] ; then
1005 echo "more than one process: $1"
1007 echo "no such process: $1"
1010 echo "usage: stacks [pid|process name]"
1013 if [ "$PID" ] ; then
1014 # Determine whether the process is native
1015 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1016 # Dump stacks of Dalvik process
1017 local TRACES=/data/anr/traces.txt
1018 local ORIG=/data/anr/traces.orig
1019 local TMP=/data/anr/traces.tmp
1021 # Keep original traces to avoid clobbering
1022 adb shell mv $TRACES $ORIG
1024 # Make sure we have a usable file
1025 adb shell touch $TRACES
1026 adb shell chmod 666 $TRACES
1028 # Dump stacks and wait for dump to finish
1029 adb shell kill -3 $PID
1030 adb shell notify $TRACES >/dev/null
1032 # Restore original stacks, and show current output
1033 adb shell mv $TRACES $TMP
1034 adb shell mv $ORIG $TRACES
1037 # Dump stacks of native process
1038 local USE64BIT="$(is64bit $PID)"
1039 adb shell debuggerd$USE64BIT -b $PID
1044 # Read the ELF header from /proc/$PID/exe to determine if the process is
1049 if [ "$PID" ] ; then
1050 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
1064 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' -print0 | xargs -0 grep --color -n "$@"
1071 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\)' -print0 | xargs -0 grep --color -n "$@"
1076 function gettargetarch
1078 get_build_var TARGET_ARCH
1083 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1088 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
1093 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) -print0 | xargs -0 grep --color -n "$@"
1098 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
1103 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1108 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 "$@"
1113 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1120 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 "$@"
1125 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 "$@"
1132 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 "$@"
1137 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 "$@"
1143 function getprebuilt
1145 get_abs_build_var ANDROID_PREBUILTS
1148 function tracedmdump()
1152 echo "Couldn't locate the top of the tree. Try setting TOP."
1155 local prebuiltdir=$(getprebuilt)
1156 local arch=$(gettargetarch)
1157 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
1160 if [ ! "$TRACE" ] ; then
1161 echo "usage: tracedmdump tracename"
1165 if [ ! -r "$KERNEL" ] ; then
1166 echo "Error: cannot find kernel: '$KERNEL'"
1170 local BASETRACE=$(basename $TRACE)
1171 if [ "$BASETRACE" = "$TRACE" ] ; then
1172 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1175 echo "post-processing traces..."
1176 rm -f $TRACE/qtrace.dexlist
1178 if [ $? -ne 0 ]; then
1180 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1184 echo "generating dexlist output..."
1185 /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
1186 echo "generating dmtrace data..."
1187 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1188 echo "generating html file..."
1189 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1190 echo "done, see $TRACE/dmtrace.html for details"
1192 echo " traceview $TRACE/dmtrace"
1195 # communicate with a running device or emulator, set up necessary state,
1196 # and run the hat command.
1199 # process standard adb options
1201 if [ "$1" = "-d" -o "$1" = "-e" ]; then
1204 elif [ "$1" = "-s" ]; then
1208 local adbOptions=${adbTarget}
1209 #echo adbOptions = ${adbOptions}
1214 if [ "$targetPid" = "" ]; then
1215 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
1219 # confirm hat is available
1220 if [ -z $(which hat) ]; then
1221 echo "hat is not available in this configuration."
1225 # issue "am" command to cause the hprof dump
1226 local devFile=/data/local/tmp/hprof-$targetPid
1227 echo "Poking $targetPid and waiting for data..."
1228 echo "Storing data at $devFile"
1229 adb ${adbOptions} shell am dumpheap $targetPid $devFile
1230 echo "Press enter when logcat shows \"hprof: heap dump completed\""
1234 local localFile=/tmp/$$-hprof
1236 echo "Retrieving file $devFile..."
1237 adb ${adbOptions} pull $devFile $localFile
1239 adb ${adbOptions} shell rm $devFile
1241 echo "Running hat on $localFile"
1242 echo "View the output by pointing your browser at http://localhost:7000/"
1244 hat -JXmx512m $localFile
1247 function getbugreports()
1249 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
1251 if [ ! "$reports" ]; then
1252 echo "Could not locate any bugreports."
1257 for report in ${reports[@]}
1259 echo "/sdcard/bugreports/${report}"
1260 adb pull /sdcard/bugreports/${report} ${report}
1265 function getsdcardpath()
1267 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1270 function getscreenshotpath()
1272 echo "$(getsdcardpath)/Pictures/Screenshots"
1275 function getlastscreenshot()
1277 local screenshot_path=$(getscreenshotpath)
1278 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1279 if [ "$screenshot" = "" ]; then
1280 echo "No screenshots found."
1283 echo "${screenshot}"
1284 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1287 function startviewserver()
1290 if [ $# -gt 0 ]; then
1293 adb shell service call window 1 i32 $port
1296 function stopviewserver()
1298 adb shell service call window 2
1301 function isviewserverstarted()
1303 adb shell service call window 3
1308 adb shell input keyevent 3
1313 adb shell input keyevent 4
1318 adb shell input keyevent 82
1321 function smoketest()
1323 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1324 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1329 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1333 (\cd "$T" && mmm tests/SmokeTest) &&
1334 adb uninstall com.android.smoketest > /dev/null &&
1335 adb uninstall com.android.smoketest.tests > /dev/null &&
1336 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1337 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1338 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1341 # simple shortcut to the runtest command
1346 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1349 ("$T"/development/testrunner/runtest.py $@)
1353 if [[ -z "$1" ]]; then
1354 echo "Usage: godir <regex>"
1358 if [ ! "$OUT_DIR" = "" ]; then
1360 FILELIST=$OUT_DIR/filelist
1362 FILELIST=$T/filelist
1364 if [[ ! -f $FILELIST ]]; then
1365 echo -n "Creating index..."
1366 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
1371 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
1372 if [[ ${#lines[@]} = 0 ]]; then
1378 if [[ ${#lines[@]} > 1 ]]; then
1379 while [[ -z "$pathname" ]]; do
1382 for line in ${lines[@]}; do
1383 printf "%6s %s\n" "[$index]" $line
1384 index=$(($index + 1))
1387 echo -n "Select one: "
1390 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1391 echo "Invalid choice"
1394 pathname=${lines[$(($choice-1))]}
1397 pathname=${lines[0]}
1402 # Force JAVA_HOME to point to java 1.7 if it isn't already set.
1404 # Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1405 # For some reason, installing the JDK doesn't make it show up in the
1406 # JavaVM.framework/Versions/1.7/ folder.
1407 function set_java_home() {
1408 # Clear the existing JAVA_HOME value if we set it ourselves, so that
1409 # we can reset it later, depending on the version of java the build
1412 # If we don't do this, the JAVA_HOME value set by the first call to
1413 # build/envsetup.sh will persist forever.
1414 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1418 if [ ! "$JAVA_HOME" ]; then
1421 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1424 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1428 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1429 # we can change it on the next envsetup.sh, if required.
1430 export ANDROID_SET_JAVA_HOME=true
1434 # Print colored exit condition
1438 if [ $retval -ne 0 ]
1440 echo -e "\e[0;31mFAILURE\e[00m"
1442 echo -e "\e[0;32mSUCCESS\e[00m"
1447 function get_make_command()
1454 local start_time=$(date +"%s")
1455 $(get_make_command) "$@"
1457 local end_time=$(date +"%s")
1458 local tdiff=$(($end_time-$start_time))
1459 local hours=$(($tdiff / 3600 ))
1460 local mins=$((($tdiff % 3600) / 60))
1461 local secs=$(($tdiff % 60))
1462 local ncolors=$(tput colors 2>/dev/null)
1463 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
1464 color_failed="\e[0;31m"
1465 color_success="\e[0;32m"
1466 color_reset="\e[00m"
1473 if [ $ret -eq 0 ] ; then
1474 echo -n -e "${color_success}#### make completed successfully "
1476 echo -n -e "${color_failed}#### make failed to build some targets "
1478 if [ $hours -gt 0 ] ; then
1479 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1480 elif [ $mins -gt 0 ] ; then
1481 printf "(%02g:%02g (mm:ss))" $mins $secs
1482 elif [ $secs -gt 0 ] ; then
1483 printf "(%s seconds)" $secs
1485 echo -e " ####${color_reset}"
1490 if [ "x$SHELL" != "x/bin/bash" ]; then
1491 case `ps -o command -p $$` in
1495 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1500 # Execute the contents of any vendorsetup.sh files we can find.
1501 for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
1502 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`