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 - mmp: Builds all of the modules in the current directory and pushes them to the device.
14 - mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
15 - provision: Flash device with all required partitions. Options will be passed on to fastboot.
16 - cgrep: Greps on all local C/C++ files.
17 - ggrep: Greps on all local Gradle files.
18 - jgrep: Greps on all local Java files.
19 - resgrep: Greps on all local res/*.xml files.
20 - mangrep: Greps on all local AndroidManifest.xml files.
21 - mgrep: Greps on all local Makefiles files.
22 - sepgrep: Greps on all local sepolicy files.
23 - sgrep: Greps on all local source files.
24 - godir: Go to the directory containing a file.
25 - cmremote: Add git remote for CM Gerrit Review
26 - cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
27 - aospremote: Add git remote for matching AOSP repository
28 - cmrebase: Rebase a Gerrit change and push it again
29 - mka: Builds using SCHED_BATCH on all processors
30 - reposync: Parallel repo sync using ionice and SCHED_BATCH
31 - installboot: Installs a boot.img to the connected device.
32 - installrecovery: Installs a recovery.img to the connected device.
33 - repodiff: Diff 2 different branches or tags within the same repo
36 - SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
37 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
38 build is leak-check clean.
40 Look at the source to view more functions. The complete list is:
45 for i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
51 # Get all the build variables needed by this script in a single call to the build system.
52 function build_build_var_cache()
55 # Grep out the variable names from the script.
56 cached_vars=`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`
57 cached_abs_vars=`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`
58 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
59 build_dicts_script=`\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
60 command make --no-print-directory -f build/core/config.mk \
62 DUMP_MANY_VARS="$cached_vars" \
63 DUMP_MANY_ABS_VARS="$cached_abs_vars" \
64 DUMP_VAR_PREFIX="var_cache_" \
65 DUMP_ABS_VAR_PREFIX="abs_var_cache_"`
69 unset build_dicts_script
72 # Excute the script to store the "<val>=<value>" pairs as shell variables.
73 eval "$build_dicts_script"
75 unset build_dicts_script
80 BUILD_VAR_CACHE_READY="true"
83 # Delete the build var cache, so that we can still call into the build system
84 # to get build variables not listed in this script.
85 function destroy_build_var_cache()
87 unset BUILD_VAR_CACHE_READY
88 for v in $cached_vars; do
92 for v in $cached_abs_vars; do
93 unset abs_var_cache_$v
98 # Get the value of a build variable as an absolute path.
99 function get_abs_build_var()
101 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
103 eval echo \"\${abs_var_cache_$1}\"
109 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
112 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
113 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
116 # Get the exact value of a build variable.
117 function get_build_var()
119 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
121 eval echo \"\${var_cache_$1}\"
127 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
130 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
131 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
134 # check to see if the supplied product is one we can build
135 function check_product()
139 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
143 if (echo -n $1 | grep -q -e "^cm_") ; then
144 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
151 TARGET_BUILD_VARIANT= \
154 get_build_var TARGET_DEVICE > /dev/null
155 # hide successful answers, but allow the errors to show
158 VARIANT_CHOICES=(user userdebug eng)
160 # check to see if the supplied variant is valid
161 function check_variant()
163 for v in ${VARIANT_CHOICES[@]}
177 echo "Couldn't locate the top of the tree. Try setting TOP."
181 ##################################################################
183 # Read me before you modify this code #
185 # This function sets ANDROID_BUILD_PATHS to what it is adding #
186 # to PATH, and the next time it is run, it removes that from #
187 # PATH. This is required so lunch can be run more than once #
188 # and still have working paths. #
190 ##################################################################
192 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
193 # due to "C:\Program Files" being in the path.
196 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
197 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
199 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
200 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
201 # strip leading ':', if any
202 export PATH=${PATH/:%/}
205 # and in with the new
206 prebuiltdir=$(getprebuilt)
207 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
209 # defined in core/config.mk
210 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
211 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
212 export TARGET_GCC_VERSION=$targetgccversion
214 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
215 export ANDROID_TOOLCHAIN=
216 export ANDROID_TOOLCHAIN_2ND_ARCH=
217 local ARCH=$(get_build_var TARGET_ARCH)
219 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
221 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
223 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
225 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
226 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
228 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
231 echo "Can't find toolchain for unknown architecture: $ARCH"
232 toolchaindir=xxxxxxxxx
235 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
236 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
239 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
240 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
243 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
244 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_DEV_SCRIPTS:
246 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
247 # to ensure that the corresponding 'emulator' binaries are used.
250 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
253 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
256 ANDROID_EMULATOR_PREBUILTS=
259 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
260 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
261 export ANDROID_EMULATOR_PREBUILTS
264 export PATH=$ANDROID_BUILD_PATHS$PATH
265 export PYTHONPATH=$T/development/python-packages:$PYTHONPATH
267 unset ANDROID_JAVA_TOOLCHAIN
268 unset ANDROID_PRE_BUILD_PATHS
269 if [ -n "$JAVA_HOME" ]; then
270 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
271 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
272 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
275 unset ANDROID_PRODUCT_OUT
276 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
277 export OUT=$ANDROID_PRODUCT_OUT
279 unset ANDROID_HOST_OUT
280 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
282 # needed for building linux on MacOS
284 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
287 function printconfig()
291 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
294 get_build_var report_config
297 function set_stuff_for_environment()
304 export ANDROID_BUILD_TOP=$(gettop)
305 # With this environment variable new GCC can apply colors to warnings/errors
306 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
307 export ASAN_OPTIONS=detect_leaks=0
310 function set_sequence_number()
312 export BUILD_ENV_SEQUENCE_NUMBER=10
317 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
318 local arch=$(gettargetarch)
319 local product=$TARGET_PRODUCT
320 local variant=$TARGET_BUILD_VARIANT
321 local apps=$TARGET_BUILD_APPS
322 if [ -z "$apps" ]; then
323 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
325 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
330 function addcompletions()
334 # Keep us from trying to run in something that isn't bash.
335 if [ -z "${BASH_VERSION}" ]; then
339 # Keep us from trying to run in bash that's too old.
340 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
344 dir="sdk/bash_completion"
345 if [ -d ${dir} ]; then
346 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
353 function choosetype()
355 echo "Build type choices are:"
360 local DEFAULT_NUM DEFAULT_VALUE
362 DEFAULT_VALUE=release
364 export TARGET_BUILD_TYPE=
366 while [ -z $TARGET_BUILD_TYPE ]
368 echo -n "Which would you like? ["$DEFAULT_NUM"] "
369 if [ -z "$1" ] ; then
377 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
380 export TARGET_BUILD_TYPE=release
383 export TARGET_BUILD_TYPE=release
386 export TARGET_BUILD_TYPE=debug
389 export TARGET_BUILD_TYPE=debug
393 echo "I didn't understand your response. Please try again."
397 if [ -n "$1" ] ; then
402 build_build_var_cache
403 set_stuff_for_environment
404 destroy_build_var_cache
408 # This function isn't really right: It chooses a TARGET_PRODUCT
409 # based on the list of boards. Usually, that gets you something
410 # that kinda works with a generic product, but really, you should
411 # pick a product by name.
413 function chooseproduct()
415 if [ "x$TARGET_PRODUCT" != x ] ; then
416 default_value=$TARGET_PRODUCT
418 default_value=aosp_arm
421 export TARGET_BUILD_APPS=
422 export TARGET_PRODUCT=
424 while [ -z "$TARGET_PRODUCT" ]
426 echo -n "Which product would you like? [$default_value] "
427 if [ -z "$1" ] ; then
434 if [ -z "$ANSWER" ] ; then
435 export TARGET_PRODUCT=$default_value
437 if check_product $ANSWER
439 export TARGET_PRODUCT=$ANSWER
441 echo "** Not a valid product: $ANSWER"
444 if [ -n "$1" ] ; then
449 build_build_var_cache
450 set_stuff_for_environment
451 destroy_build_var_cache
454 function choosevariant()
456 echo "Variant choices are:"
459 for v in ${VARIANT_CHOICES[@]}
461 # The product name is the name of the directory containing
462 # the makefile we found, above.
467 local default_value=eng
470 export TARGET_BUILD_VARIANT=
471 while [ -z "$TARGET_BUILD_VARIANT" ]
473 echo -n "Which would you like? [$default_value] "
474 if [ -z "$1" ] ; then
481 if [ -z "$ANSWER" ] ; then
482 export TARGET_BUILD_VARIANT=$default_value
483 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
484 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
485 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
488 if check_variant $ANSWER
490 export TARGET_BUILD_VARIANT=$ANSWER
492 echo "** Not a valid variant: $ANSWER"
495 if [ -n "$1" ] ; then
501 function choosecombo()
514 build_build_var_cache
515 set_stuff_for_environment
517 destroy_build_var_cache
520 # Clear this variable. It will be built up again when the vendorsetup.sh
521 # files are included at the end of this file.
522 unset LUNCH_MENU_CHOICES
523 function add_lunch_combo()
527 for c in ${LUNCH_MENU_CHOICES[@]} ; do
528 if [ "$new_combo" = "$c" ] ; then
532 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
535 # add the default one here
536 add_lunch_combo aosp_arm-eng
537 add_lunch_combo aosp_arm64-eng
538 add_lunch_combo aosp_mips-eng
539 add_lunch_combo aosp_mips64-eng
540 add_lunch_combo aosp_x86-eng
541 add_lunch_combo aosp_x86_64-eng
543 function print_lunch_menu()
547 echo "You're building on" $uname
548 if [ "$(uname)" = "Darwin" ] ; then
549 echo " (ohai, koush!)"
552 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
553 echo "Breakfast menu... pick a combo:"
555 echo "Lunch menu... pick a combo:"
560 for choice in ${LUNCH_MENU_CHOICES[@]}
566 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
567 echo "... and don't forget the bacon!"
576 if [ $? -eq 0 ]; then
579 echo "No such item in brunch menu. Try 'breakfast'"
588 CM_DEVICES_ONLY="true"
589 unset LUNCH_MENU_CHOICES
590 add_lunch_combo full-eng
591 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
598 if [ $# -eq 0 ]; then
599 # No arguments, so let's have the full menu
602 echo "z$target" | grep -q "-"
603 if [ $? -eq 0 ]; then
604 # A buildtype was specified, assume a full device name
607 # This is probably just the CM model name
608 lunch cm_$target-userdebug
624 echo -n "Which would you like? [aosp_arm-eng] "
632 selection=aosp_arm-eng
633 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
635 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
637 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
639 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
644 if [ -z "$selection" ]
647 echo "Invalid lunch combo: $answer"
651 export TARGET_BUILD_APPS=
653 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
654 check_variant $variant
658 echo "** Invalid variant: '$variant'"
659 echo "** Must be one of ${VARIANT_CHOICES[@]}"
663 local product=$(echo -n $selection | sed -e "s/-.*$//")
664 TARGET_PRODUCT=$product \
665 TARGET_BUILD_VARIANT=$variant \
666 build_build_var_cache
669 # if we can't find a product, try to grab it off the CM github
672 build/tools/roomservice.py $product
674 check_product $product
676 build/tools/roomservice.py $product true
681 echo "** Don't have a product spec for: '$product'"
682 echo "** Do you have the right repo manifest?"
686 if [ -z "$product" -o -z "$variant" ]
692 export TARGET_PRODUCT=$product
693 export TARGET_BUILD_VARIANT=$variant
694 export TARGET_BUILD_TYPE=release
698 set_stuff_for_environment
700 destroy_build_var_cache
703 # Tab completion for lunch.
708 cur="${COMP_WORDS[COMP_CWORD]}"
709 prev="${COMP_WORDS[COMP_CWORD-1]}"
711 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
714 complete -F _lunch lunch
716 # Configures the build to build unbundled apps.
717 # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
720 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
721 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
722 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
723 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)"
725 if [ $(echo $arch | wc -w) -gt 1 ]; then
726 echo "tapas: Error: Multiple build archs supplied: $arch"
729 if [ $(echo $variant | wc -w) -gt 1 ]; then
730 echo "tapas: Error: Multiple build variants supplied: $variant"
733 if [ $(echo $density | wc -w) -gt 1 ]; then
734 echo "tapas: Error: Multiple densities supplied: $density"
738 local product=aosp_arm
740 x86) product=aosp_x86;;
741 mips) product=aosp_mips;;
742 armv5) product=generic_armv5;;
743 arm64) product=aosp_arm64;;
744 x86_64) product=aosp_x86_64;;
745 mips64) product=aosp_mips64;;
747 if [ -z "$variant" ]; then
750 if [ -z "$apps" ]; then
753 if [ -z "$density" ]; then
757 export TARGET_PRODUCT=$product
758 export TARGET_BUILD_VARIANT=$variant
759 export TARGET_BUILD_DENSITY=$density
760 export TARGET_BUILD_TYPE=release
761 export TARGET_BUILD_APPS=$apps
763 build_build_var_cache
764 set_stuff_for_environment
766 destroy_build_var_cache
772 MODVERSION=`sed -n -e'/ro\.cm\.version/s/.*=//p' $OUT/system/build.prop`
773 ZIPFILE=cm-$MODVERSION.zip
774 ZIPPATH=$OUT/$ZIPFILE
775 if [ ! -f $ZIPPATH ] ; then
776 echo "Nothing to eat"
779 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
780 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
781 echo "No device is online. Waiting for one..."
782 echo "Please connect USB and/or enable USB debugging"
783 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
786 echo "Device Found.."
788 # if adbd isn't root we can't write to /cache/recovery/
792 SZ=`stat -c %s $ZIPPATH`
793 CACHESIZE=`adb shell busybox df -PB1 /cache | grep /cache | tr -s ' ' | cut -d ' ' -f 4`
794 if [ $CACHESIZE -gt $SZ ];
799 PUSHDIR=/storage/sdcard0/
800 # Optional path for sdcard0 in recovery
801 [ -z "$1" ] && DIR=sdcard/0 || DIR=$1
803 echo "Pushing $ZIPFILE to $PUSHDIR"
804 if adb push $ZIPPATH $PUSHDIR ; then
805 cat << EOF > /tmp/command
806 --update_package=/$DIR/$ZIPFILE
808 if adb push /tmp/command /cache/recovery/ ; then
809 echo "Rebooting into recovery for installation"
815 echo "Nothing to eat"
823 local TOPFILE=build/core/envsetup.mk
824 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
825 # The following circumlocution ensures we remove symlinks from TOP.
826 (cd $TOP; PWD= /bin/pwd)
828 if [ -f $TOPFILE ] ; then
829 # The following circumlocution (repeated below as well) ensures
830 # that we record the true directory name and not one that is
831 # faked up with symlink names.
836 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
841 if [ -f "$T/$TOPFILE" ]; then
848 # Return driver for "make", if any (eg. static analyzer)
852 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
853 if [ -n "$WITH_STATIC_ANALYZER" ]; then
855 $T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
856 --use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
865 local DRV=$(getdriver $T)
867 $DRV make -C $T -f build/core/main.mk $@
869 echo "Couldn't locate the top of the tree. Try setting TOP."
874 function findmakefile()
876 TOPFILE=build/core/envsetup.mk
879 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
881 if [ -f "$T/Android.mk" ]; then
894 local DRV=$(getdriver $T)
895 # If we're sitting in the root of the build tree, just do a
897 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
900 # Find the closest Android.mk file.
901 local M=$(findmakefile)
903 local GET_INSTALL_PATH=
905 # Remove the path to top as the makefilepath needs to be relative
906 local M=`echo $M|sed 's:'$T'/::'`
908 echo "Couldn't locate the top of the tree. Try setting TOP."
910 elif [ ! "$M" ]; then
911 echo "Couldn't locate a makefile from the current directory."
916 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
919 if [ -n "$GET_INSTALL_PATH" ]; then
921 ARGS=GET-INSTALL-PATH
926 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
934 local DRV=$(getdriver $T)
940 local GET_INSTALL_PATH=
941 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
942 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
943 for DIR in $DIRS ; do
944 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
945 if [ "$MODULES" = "" ]; then
948 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
949 if [ -f $DIR/Android.mk ]; then
950 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
951 local TO_CHOP=`expr $TO_CHOP + 1`
952 local START=`PWD= /bin/pwd`
953 local MFILE=`echo $START | cut -c${TO_CHOP}-`
954 if [ "$MFILE" = "" ] ; then
955 MFILE=$DIR/Android.mk
957 MFILE=$MFILE/$DIR/Android.mk
959 MAKEFILE="$MAKEFILE $MFILE"
962 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
963 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
964 *) if [ -d $DIR ]; then
965 echo "No Android.mk in $DIR.";
967 echo "Couldn't locate the directory $DIR";
973 if [ -n "$GET_INSTALL_PATH" ]; then
974 ARGS=$GET_INSTALL_PATH
977 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
979 echo "Couldn't locate the top of the tree. Try setting TOP."
987 local DRV=$(getdriver $T)
988 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
992 echo "Couldn't locate the top of the tree. Try setting TOP."
995 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
996 local MODULES_IN_PATHS=MODULES-IN-$MY_PWD
997 # Convert "/" to "-".
998 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
999 $DRV make -C $T -f build/core/main.mk $@ $MODULES_IN_PATHS
1006 local DRV=$(getdriver $T)
1008 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
1009 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
1010 local MY_PWD=`PWD= /bin/pwd`
1011 if [ "$MY_PWD" = "$T" ]; then
1014 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
1017 local MODULES_IN_PATHS=
1019 for DIR in $DIRS ; do
1020 if [ -d $DIR ]; then
1021 # Remove the leading ./ and trailing / if any exists.
1024 if [ "$MY_PWD" != "" ]; then
1027 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
1030 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
1031 *) echo "Couldn't find directory $DIR"; return 1;;
1035 # Convert "/" to "-".
1036 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
1037 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS $MODULES_IN_PATHS
1039 echo "Couldn't locate the top of the tree. Try setting TOP."
1050 echo "Couldn't locate the top of the tree. Try setting TOP."
1056 TOPFILE=build/core/envsetup.mk
1059 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1061 if [ -f "$T/Android.mk" ]; then
1068 echo "can't find Android.mk"
1071 # simplified version of ps; output in the form
1076 if [ "$1" = "--exact" ]; then
1080 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1081 echo "usage: qpid [[--exact] <process name|pid>"
1086 if [ "$EXE" ] ; then
1087 qpid | \grep "$prepend$EXE$append"
1091 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1099 if [ "$1" = "--exact" ]; then
1105 if [ "$EXE" ] ; then
1106 local PID=`adb shell ps \
1108 | \grep "$prepend$EXE$append" \
1109 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1112 echo "usage: pid [--exact] <process name>"
1117 # coredump_setup - enable core dumps globally for any process
1118 # that has the core-file-size limit set correctly
1120 # NOTE: You must call also coredump_enable for a specific process
1121 # if its core-file-size limit is not set already.
1122 # NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1124 function coredump_setup()
1126 echo "Getting root...";
1128 adb wait-for-device;
1130 echo "Remounting root partition read-write...";
1131 adb shell mount -w -o remount -t rootfs rootfs;
1133 adb wait-for-device;
1134 adb shell mkdir -p /cores;
1135 adb shell mount -t tmpfs tmpfs /cores;
1136 adb shell chmod 0777 /cores;
1138 echo "Granting SELinux permission to dump in /cores...";
1139 adb shell restorecon -R /cores;
1141 echo "Set core pattern.";
1142 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1147 # coredump_enable - enable core dumps for the specified process
1148 # $1 = PID of process (e.g., $(pid mediaserver))
1150 # NOTE: coredump_setup must have been called as well for a core
1151 # dump to actually be generated.
1153 function coredump_enable()
1156 if [ -z "$PID" ]; then
1157 printf "Expecting a PID!\n";
1160 echo "Setting core limit for $PID to infinite...";
1161 adb shell prlimit $PID 4 -1 -1
1164 # core - send SIGV and pull the core for process
1165 # $1 = PID of process (e.g., $(pid mediaserver))
1167 # NOTE: coredump_setup must be called once per boot for core dumps to be
1174 if [ -z "$PID" ]; then
1175 printf "Expecting a PID!\n";
1179 local CORENAME=core.$PID;
1180 local COREPATH=/cores/$CORENAME;
1186 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1187 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1188 adb shell kill -$SIG $PID;
1192 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1193 echo "Done: core is under $COREPATH on device.";
1196 # systemstack - dump the current stack trace of all threads in the system process
1197 # to the usual ANR traces file
1198 function systemstack()
1200 stacks system_server
1205 if [[ $1 =~ ^[0-9]+$ ]] ; then
1207 elif [ "$1" ] ; then
1208 local PIDLIST="$(pid $1)"
1209 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1210 local PID="$PIDLIST"
1211 elif [ "$PIDLIST" ] ; then
1212 echo "more than one process: $1"
1214 echo "no such process: $1"
1217 echo "usage: stacks [pid|process name]"
1220 if [ "$PID" ] ; then
1221 # Determine whether the process is native
1222 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1223 # Dump stacks of Dalvik process
1224 local TRACES=/data/anr/traces.txt
1225 local ORIG=/data/anr/traces.orig
1226 local TMP=/data/anr/traces.tmp
1228 # Keep original traces to avoid clobbering
1229 adb shell mv $TRACES $ORIG
1231 # Make sure we have a usable file
1232 adb shell touch $TRACES
1233 adb shell chmod 666 $TRACES
1235 # Dump stacks and wait for dump to finish
1236 adb shell kill -3 $PID
1237 adb shell notify $TRACES >/dev/null
1239 # Restore original stacks, and show current output
1240 adb shell mv $TRACES $TMP
1241 adb shell mv $ORIG $TRACES
1244 # Dump stacks of native process
1245 local USE64BIT="$(is64bit $PID)"
1246 adb shell debuggerd$USE64BIT -b $PID
1251 # Read the ELF header from /proc/$PID/exe to determine if the process is
1256 if [ "$PID" ] ; then
1257 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
1271 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl|vts)' \
1272 -exec grep --color -n "$@" {} +
1279 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\)' \
1280 -exec grep --color -n "$@" {} +
1285 function gettargetarch
1287 get_build_var TARGET_ARCH
1292 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1293 -exec grep --color -n "$@" {} +
1298 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1299 -exec grep --color -n "$@" {} +
1304 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' \) \
1305 -exec grep --color -n "$@" {} +
1310 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1311 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1317 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1318 -exec grep --color -n "$@" {} +
1323 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1324 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
1329 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1330 -exec grep --color -n "$@" {} +
1337 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' \
1338 -exec grep --color -n "$@" {} +
1343 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' \
1344 -exec grep --color -n -i "$@" {} +
1351 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f \
1352 -exec grep --color -n "$@" {} +
1357 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f \
1358 -exec grep --color -n -i "$@" {} +
1364 function getprebuilt
1366 get_abs_build_var ANDROID_PREBUILTS
1369 function tracedmdump()
1373 echo "Couldn't locate the top of the tree. Try setting TOP."
1376 local prebuiltdir=$(getprebuilt)
1377 local arch=$(gettargetarch)
1378 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
1381 if [ ! "$TRACE" ] ; then
1382 echo "usage: tracedmdump tracename"
1386 if [ ! -r "$KERNEL" ] ; then
1387 echo "Error: cannot find kernel: '$KERNEL'"
1391 local BASETRACE=$(basename $TRACE)
1392 if [ "$BASETRACE" = "$TRACE" ] ; then
1393 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1396 echo "post-processing traces..."
1397 rm -f $TRACE/qtrace.dexlist
1399 if [ $? -ne 0 ]; then
1401 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1405 echo "generating dexlist output..."
1406 /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
1407 echo "generating dmtrace data..."
1408 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1409 echo "generating html file..."
1410 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1411 echo "done, see $TRACE/dmtrace.html for details"
1413 echo " traceview $TRACE/dmtrace"
1416 # communicate with a running device or emulator, set up necessary state,
1417 # and run the hat command.
1420 # process standard adb options
1422 if [ "$1" = "-d" -o "$1" = "-e" ]; then
1425 elif [ "$1" = "-s" ]; then
1429 local adbOptions=${adbTarget}
1430 #echo adbOptions = ${adbOptions}
1435 if [ "$targetPid" = "" ]; then
1436 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
1440 # confirm hat is available
1441 if [ -z $(which hat) ]; then
1442 echo "hat is not available in this configuration."
1446 # issue "am" command to cause the hprof dump
1447 local devFile=/data/local/tmp/hprof-$targetPid
1448 echo "Poking $targetPid and waiting for data..."
1449 echo "Storing data at $devFile"
1450 adb ${adbOptions} shell am dumpheap $targetPid $devFile
1451 echo "Press enter when logcat shows \"hprof: heap dump completed\""
1455 local localFile=/tmp/$$-hprof
1457 echo "Retrieving file $devFile..."
1458 adb ${adbOptions} pull $devFile $localFile
1460 adb ${adbOptions} shell rm $devFile
1462 echo "Running hat on $localFile"
1463 echo "View the output by pointing your browser at http://localhost:7000/"
1465 hat -JXmx512m $localFile
1468 function getbugreports()
1470 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
1472 if [ ! "$reports" ]; then
1473 echo "Could not locate any bugreports."
1478 for report in ${reports[@]}
1480 echo "/sdcard/bugreports/${report}"
1481 adb pull /sdcard/bugreports/${report} ${report}
1486 function getsdcardpath()
1488 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1491 function getscreenshotpath()
1493 echo "$(getsdcardpath)/Pictures/Screenshots"
1496 function getlastscreenshot()
1498 local screenshot_path=$(getscreenshotpath)
1499 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1500 if [ "$screenshot" = "" ]; then
1501 echo "No screenshots found."
1504 echo "${screenshot}"
1505 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1508 function startviewserver()
1511 if [ $# -gt 0 ]; then
1514 adb shell service call window 1 i32 $port
1517 function stopviewserver()
1519 adb shell service call window 2
1522 function isviewserverstarted()
1524 adb shell service call window 3
1529 adb shell input keyevent 3
1534 adb shell input keyevent 4
1539 adb shell input keyevent 82
1542 function smoketest()
1544 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1545 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1550 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1554 (\cd "$T" && mmm tests/SmokeTest) &&
1555 adb uninstall com.android.smoketest > /dev/null &&
1556 adb uninstall com.android.smoketest.tests > /dev/null &&
1557 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1558 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1559 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1562 # simple shortcut to the runtest command
1567 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1570 ("$T"/development/testrunner/runtest.py $@)
1574 if [[ -z "$1" ]]; then
1575 echo "Usage: godir <regex>"
1579 if [ ! "$OUT_DIR" = "" ]; then
1581 FILELIST=$OUT_DIR/filelist
1583 FILELIST=$T/filelist
1585 if [[ ! -f $FILELIST ]]; then
1586 echo -n "Creating index..."
1587 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
1592 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
1593 if [[ ${#lines[@]} = 0 ]]; then
1599 if [[ ${#lines[@]} > 1 ]]; then
1600 while [[ -z "$pathname" ]]; do
1603 for line in ${lines[@]}; do
1604 printf "%6s %s\n" "[$index]" $line
1605 index=$(($index + 1))
1608 echo -n "Select one: "
1611 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1612 echo "Invalid choice"
1615 pathname=${lines[$(($choice-1))]}
1618 pathname=${lines[0]}
1625 git remote rm cmremote 2> /dev/null
1628 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1630 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1631 if [ -z "$GERRIT_REMOTE" ]
1633 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1634 if [ -z "$GERRIT_REMOTE" ]
1636 echo Unable to set up the git remote, are you in the root of the repo?
1640 CMUSER=`git config --get review.review.cyanogenmod.com.username`
1643 git remote add cmremote ssh://review.cyanogenmod.com:29418/$GERRIT_REMOTE
1645 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.com:29418/$GERRIT_REMOTE
1647 echo You can now push to "cmremote".
1651 function aospremote()
1653 git remote rm aosp 2> /dev/null
1656 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1658 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1659 if (echo $PROJECT | grep -qv "^device")
1663 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1664 echo "Remote 'aosp' created"
1666 export -f aospremote
1668 function installboot()
1670 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1672 echo "No recovery.fstab found. Build recovery first."
1675 if [ ! -e "$OUT/boot.img" ];
1677 echo "No boot.img found. Run make bootimage first."
1680 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1681 if [ -z "$PARTITION" ];
1683 echo "Unable to determine boot partition."
1692 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1694 adb push $OUT/boot.img /cache/
1695 for i in $OUT/system/lib/modules/*;
1697 adb push $i /system/lib/modules/
1699 adb shell dd if=/cache/boot.img of=$PARTITION
1700 adb shell chmod 644 /system/lib/modules/*
1701 echo "Installation complete."
1703 echo "The connected device does not appear to be $CM_BUILD, run away!"
1707 function installrecovery()
1709 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1711 echo "No recovery.fstab found. Build recovery first."
1714 if [ ! -e "$OUT/recovery.img" ];
1716 echo "No recovery.img found. Run make recoveryimage first."
1719 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1720 if [ -z "$PARTITION" ];
1722 echo "Unable to determine recovery partition."
1731 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1733 adb push $OUT/recovery.img /cache/
1734 adb shell dd if=/cache/recovery.img of=$PARTITION
1735 echo "Installation complete."
1737 echo "The connected device does not appear to be $CM_BUILD, run away!"
1741 function makerecipe() {
1744 echo "No branch name provided."
1748 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1749 git commit -a -m "$1"
1754 if [ "$REPO_REMOTE" == "github" ]
1758 git push cmremote HEAD:refs/heads/'$1'
1763 function cmgerrit() {
1764 if [ $# -eq 0 ]; then
1768 local user=`git config --get review.review.cyanogenmod.com.username`
1769 local review=`git config --get remote.github.review`
1770 local project=`git config --get remote.github.projectname`
1775 if [ $# -eq 0 ]; then
1778 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1781 fetch Just fetch the change as FETCH_HEAD
1782 help Show this help, or for a specific command
1783 pull Pull a change into current branch
1784 push Push HEAD or a local branch to Gerrit for a specific branch
1786 Any other Git commands that support refname would work as:
1787 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1789 See '$FUNCNAME help COMMAND' for more information on a specific command.
1792 $FUNCNAME checkout -b topic 1234/5
1794 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1795 && git checkout -b topic FETCH_HEAD
1796 will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1797 Patch-set 1 will be fetched if omitted.
1802 __cmg_*) echo "For internal use only." ;;
1804 if [ "$FUNCNAME" = "cmgerrit" ]; then
1805 echo "'$FUNCNAME $1' is deprecated."
1808 help) $FUNCNAME help ;;
1809 fetch|pull) cat <<EOF
1810 usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1813 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1814 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1818 will $1 patch-set 1 of change 1234
1822 usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1825 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1826 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1829 $FUNCNAME push fix6789:gingerbread
1830 will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1831 HEAD will be pushed from local if omitted.
1835 $FUNCNAME __cmg_err_not_supported $1 && return
1837 usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1840 git fetch http://DOMAIN/p/PROJECT \\
1841 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1842 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1848 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1849 local change_id patchset_id hash
1860 hash=$(($change_id % 100))
1862 [0-9]) hash="0$hash" ;;
1864 echo "refs/changes/$hash/$change_id/$patchset_id"
1867 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1868 $FUNCNAME __cmg_err_not_repo && return 1
1871 git $command $@ http://$review/p/$project \
1872 $($FUNCNAME __cmg_get_ref $change) || return 1
1875 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1876 $FUNCNAME __cmg_err_not_repo && return 1
1877 if [ -z "$user" ]; then
1878 echo >&2 "Gerrit username not found."
1881 local local_branch remote_branch
1884 local_branch=${1%:*}
1885 remote_branch=${1##*:}
1893 git push $@ ssh://$user@$review:29418/$project \
1894 $local_branch:refs/for/$remote_branch || return 1
1897 if [ "$FUNCNAME" = "cmgerrit" ]; then
1898 echo >&2 "'$FUNCNAME $command' is deprecated."
1902 if [ $# -lt 2 ]; then
1903 echo >&2 "'$FUNCNAME $command' missing argument."
1904 elif [ $2 -eq 0 ]; then
1905 if [ -n "$3" ]; then
1908 echo >&2 "'$FUNCNAME $1' missing argument."
1915 if [ -z "$review" -o -z "$project" ]; then
1916 echo >&2 "Not currently in any reviewable repository."
1921 __cmg_err_not_supported)
1922 $FUNCNAME __cmg_err_no_arg $command $# && return
1924 #TODO: filter more git commands that don't use refname
1925 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1926 echo >&2 "'$FUNCNAME $1' is not supported."
1931 #TODO: other special cases?
1933 $FUNCNAME __cmg_err_not_supported $command && return 1
1934 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1935 $FUNCNAME __cmg_err_not_repo && return 1
1937 local change pre_args refs_arg post_args
1940 pre_args=${args%%-- *}
1941 post_args="-- ${args#*-- }"
1943 *) pre_args="$args" ;;
1947 if [ ${#args[@]} -gt 0 ]; then
1948 change=${args[${#args[@]}-1]}
1950 if [ ${#args[@]} -gt 1 ]; then
1952 for ((i=1; i<${#args[@]}-1; i++)); do
1953 pre_args="$pre_args ${args[$i]}"
1959 $FUNCNAME help $command
1963 if [ -z "$refs_arg" ]; then
1964 refs_arg="@${change#*@}"
1965 change=${change%%@*}
1969 if [ -z "$refs_arg" ]; then
1970 refs_arg="~${change#*~}"
1971 change=${change%%~*}
1975 if [ -z "$refs_arg" ]; then
1976 refs_arg="^${change#*^}"
1977 change=${change%%^*}
1981 if [ -z "$refs_arg" ]; then
1982 refs_arg=":${change#*:}"
1983 change=${change%%:*}
1989 $FUNCNAME fetch $change \
1990 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1996 function cmrebase() {
2000 local dir="$(gettop)/$repo"
2002 if [ -z $repo ] || [ -z $refs ]; then
2003 echo "CyanogenMod Gerrit Rebase Usage: "
2004 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2005 echo " The patch IDs appear on the Gerrit commands that are offered."
2006 echo " They consist on a series of numbers and slashes, after the text"
2007 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2009 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2014 if [ ! -d $dir ]; then
2015 echo "Directory $dir doesn't exist in tree."
2019 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2020 echo "Starting branch..."
2021 repo start tmprebase .
2022 echo "Bringing it up to date..."
2024 echo "Fetching change..."
2025 git fetch "http://review.cyanogenmod.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
2026 if [ "$?" != "0" ]; then
2027 echo "Error cherry-picking. Not uploading!"
2032 echo "Cleaning up..."
2033 repo abandon tmprebase .
2040 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2043 schedtool -B -n 1 -e ionice -n 1 make -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@"
2048 function reposync() {
2054 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
2059 function repodiff() {
2060 if [ -z "$*" ]; then
2061 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2064 diffopts=$* repo forall -c \
2065 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2068 # Credit for color strip sed: http://goo.gl/BoIcm
2074 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2075 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2076 echo "No device is online. Waiting for one..."
2077 echo "Please connect USB and/or enable USB debugging"
2078 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2081 echo "Device Found."
2084 adb root &> /dev/null
2086 adb wait-for-device &> /dev/null
2088 adb remount &> /dev/null
2090 $func $* | tee $OUT/.log
2093 LOC=$(cat $OUT/.log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep 'Install' | cut -d ':' -f 2)
2096 LOC=$LOC $(cat $OUT/.log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep 'Copy' | cut -d ':' -f 2)
2098 for FILE in $LOC; do
2099 # Get target file name (i.e. system/bin/adb)
2100 TARGET=$(echo $FILE | sed "s#$OUT/##")
2102 # Don't send files that are not in /system.
2103 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
2107 system/app/SystemUI.apk|system/framework/*)
2114 if $stop_n_start ; then adb shell stop ; fi
2115 echo "Pushing: $TARGET"
2116 adb push $FILE $TARGET
2117 if $stop_n_start ; then adb shell start ; fi
2124 alias mmp='dopush mm'
2125 alias mmmp='dopush mmm'
2126 alias mkap='dopush mka'
2127 alias cmkap='dopush cmka'
2129 # Force JAVA_HOME to point to java 1.7/1.8 if it isn't already set.
2130 function set_java_home() {
2131 # Clear the existing JAVA_HOME value if we set it ourselves, so that
2132 # we can reset it later, depending on the version of java the build
2135 # If we don't do this, the JAVA_HOME value set by the first call to
2136 # build/envsetup.sh will persist forever.
2137 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2141 if [ ! "$JAVA_HOME" ]; then
2142 if [ -n "$LEGACY_USE_JAVA7" ]; then
2143 echo Warning: Support for JDK 7 will be dropped. Switch to JDK 8.
2146 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2149 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2155 export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
2158 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
2163 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2164 # we can change it on the next envsetup.sh, if required.
2165 export ANDROID_SET_JAVA_HOME=true
2169 # Print colored exit condition
2173 if [ $retval -ne 0 ]
2175 echo $'\E'"[0;31mFAILURE\e[00m"
2177 echo $'\E'"[0;32mSUCCESS\e[00m"
2182 function get_make_command()
2189 local start_time=$(date +"%s")
2190 $(get_make_command) "$@"
2192 local end_time=$(date +"%s")
2193 local tdiff=$(($end_time-$start_time))
2194 local hours=$(($tdiff / 3600 ))
2195 local mins=$((($tdiff % 3600) / 60))
2196 local secs=$(($tdiff % 60))
2197 local ncolors=$(tput colors 2>/dev/null)
2198 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2199 color_failed=$'\E'"[0;31m"
2200 color_success=$'\E'"[0;32m"
2201 color_reset=$'\E'"[00m"
2208 if [ $ret -eq 0 ] ; then
2209 echo -n "${color_success}#### make completed successfully "
2211 echo -n "${color_failed}#### make failed to build some targets "
2213 if [ $hours -gt 0 ] ; then
2214 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2215 elif [ $mins -gt 0 ] ; then
2216 printf "(%02g:%02g (mm:ss))" $mins $secs
2217 elif [ $secs -gt 0 ] ; then
2218 printf "(%s seconds)" $secs
2220 echo " ####${color_reset}"
2225 function provision()
2227 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
2228 echo "Couldn't locate output files. Try running 'lunch' first." >&2
2231 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
2232 echo "There is no provisioning script for the device." >&2
2236 # Check if user really wants to do this.
2237 if [ "$1" = "--no-confirmation" ]; then
2240 echo "This action will reflash your device."
2242 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
2244 echo -n "Are you sure you want to do this (yes/no)? "
2246 if [[ "${REPLY}" != "yes" ]] ; then
2247 echo "Not taking any action. Exiting." >&2
2251 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
2254 if [ "x$SHELL" != "x/bin/bash" ]; then
2255 case `ps -o command -p $$` in
2259 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2264 # Execute the contents of any vendorsetup.sh files we can find.
2265 for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2266 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2267 `test -d product && find -L product -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`