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 "$PROMPT_COMMAND" ]; then
324 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
325 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
326 # Prompts exist, but no hardstatus
327 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
329 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
330 PROMPT_COMMAND=$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')
333 if [ -z "$apps" ]; then
334 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
336 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
338 export ANDROID_PROMPT_PREFIX
340 # Inject build data into hardstatus
341 export PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/\\033]0;\(.*\)\\007/\\033]0;$ANDROID_PROMPT_PREFIX \1\\007/g')"
345 function addcompletions()
349 # Keep us from trying to run in something that isn't bash.
350 if [ -z "${BASH_VERSION}" ]; then
354 # Keep us from trying to run in bash that's too old.
355 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
359 dir="sdk/bash_completion"
360 if [ -d ${dir} ]; then
361 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
368 function choosetype()
370 echo "Build type choices are:"
375 local DEFAULT_NUM DEFAULT_VALUE
377 DEFAULT_VALUE=release
379 export TARGET_BUILD_TYPE=
381 while [ -z $TARGET_BUILD_TYPE ]
383 echo -n "Which would you like? ["$DEFAULT_NUM"] "
384 if [ -z "$1" ] ; then
392 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
395 export TARGET_BUILD_TYPE=release
398 export TARGET_BUILD_TYPE=release
401 export TARGET_BUILD_TYPE=debug
404 export TARGET_BUILD_TYPE=debug
408 echo "I didn't understand your response. Please try again."
412 if [ -n "$1" ] ; then
417 build_build_var_cache
418 set_stuff_for_environment
419 destroy_build_var_cache
423 # This function isn't really right: It chooses a TARGET_PRODUCT
424 # based on the list of boards. Usually, that gets you something
425 # that kinda works with a generic product, but really, you should
426 # pick a product by name.
428 function chooseproduct()
430 if [ "x$TARGET_PRODUCT" != x ] ; then
431 default_value=$TARGET_PRODUCT
433 default_value=aosp_arm
436 export TARGET_BUILD_APPS=
437 export TARGET_PRODUCT=
439 while [ -z "$TARGET_PRODUCT" ]
441 echo -n "Which product would you like? [$default_value] "
442 if [ -z "$1" ] ; then
449 if [ -z "$ANSWER" ] ; then
450 export TARGET_PRODUCT=$default_value
452 if check_product $ANSWER
454 export TARGET_PRODUCT=$ANSWER
456 echo "** Not a valid product: $ANSWER"
459 if [ -n "$1" ] ; then
464 build_build_var_cache
465 set_stuff_for_environment
466 destroy_build_var_cache
469 function choosevariant()
471 echo "Variant choices are:"
474 for v in ${VARIANT_CHOICES[@]}
476 # The product name is the name of the directory containing
477 # the makefile we found, above.
482 local default_value=eng
485 export TARGET_BUILD_VARIANT=
486 while [ -z "$TARGET_BUILD_VARIANT" ]
488 echo -n "Which would you like? [$default_value] "
489 if [ -z "$1" ] ; then
496 if [ -z "$ANSWER" ] ; then
497 export TARGET_BUILD_VARIANT=$default_value
498 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
499 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
500 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
503 if check_variant $ANSWER
505 export TARGET_BUILD_VARIANT=$ANSWER
507 echo "** Not a valid variant: $ANSWER"
510 if [ -n "$1" ] ; then
516 function choosecombo()
529 build_build_var_cache
530 set_stuff_for_environment
532 destroy_build_var_cache
535 # Clear this variable. It will be built up again when the vendorsetup.sh
536 # files are included at the end of this file.
537 unset LUNCH_MENU_CHOICES
538 function add_lunch_combo()
542 for c in ${LUNCH_MENU_CHOICES[@]} ; do
543 if [ "$new_combo" = "$c" ] ; then
547 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
550 # add the default one here
551 add_lunch_combo aosp_arm-eng
552 add_lunch_combo aosp_arm64-eng
553 add_lunch_combo aosp_mips-eng
554 add_lunch_combo aosp_mips64-eng
555 add_lunch_combo aosp_x86-eng
556 add_lunch_combo aosp_x86_64-eng
558 function print_lunch_menu()
562 echo "You're building on" $uname
563 if [ "$(uname)" = "Darwin" ] ; then
564 echo " (ohai, koush!)"
567 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
568 echo "Breakfast menu... pick a combo:"
570 echo "Lunch menu... pick a combo:"
575 for choice in ${LUNCH_MENU_CHOICES[@]}
581 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
582 echo "... and don't forget the bacon!"
591 if [ $? -eq 0 ]; then
594 echo "No such item in brunch menu. Try 'breakfast'"
603 CM_DEVICES_ONLY="true"
604 unset LUNCH_MENU_CHOICES
605 add_lunch_combo full-eng
606 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
613 if [ $# -eq 0 ]; then
614 # No arguments, so let's have the full menu
617 echo "z$target" | grep -q "-"
618 if [ $? -eq 0 ]; then
619 # A buildtype was specified, assume a full device name
622 # This is probably just the CM model name
623 lunch cm_$target-userdebug
639 echo -n "Which would you like? [aosp_arm-eng] "
647 selection=aosp_arm-eng
648 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
650 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
652 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
654 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
659 if [ -z "$selection" ]
662 echo "Invalid lunch combo: $answer"
666 export TARGET_BUILD_APPS=
668 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
669 check_variant $variant
673 echo "** Invalid variant: '$variant'"
674 echo "** Must be one of ${VARIANT_CHOICES[@]}"
678 local product=$(echo -n $selection | sed -e "s/-.*$//")
679 TARGET_PRODUCT=$product \
680 TARGET_BUILD_VARIANT=$variant \
681 build_build_var_cache
684 # if we can't find a product, try to grab it off the CM github
687 build/tools/roomservice.py $product
689 check_product $product
691 build/tools/roomservice.py $product true
696 echo "** Don't have a product spec for: '$product'"
697 echo "** Do you have the right repo manifest?"
701 if [ -z "$product" -o -z "$variant" ]
707 export TARGET_PRODUCT=$product
708 export TARGET_BUILD_VARIANT=$variant
709 export TARGET_BUILD_TYPE=release
713 set_stuff_for_environment
715 destroy_build_var_cache
718 # Tab completion for lunch.
723 cur="${COMP_WORDS[COMP_CWORD]}"
724 prev="${COMP_WORDS[COMP_CWORD-1]}"
726 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
729 complete -F _lunch lunch
731 # Configures the build to build unbundled apps.
732 # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
735 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
736 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
737 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
738 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)"
740 if [ $(echo $arch | wc -w) -gt 1 ]; then
741 echo "tapas: Error: Multiple build archs supplied: $arch"
744 if [ $(echo $variant | wc -w) -gt 1 ]; then
745 echo "tapas: Error: Multiple build variants supplied: $variant"
748 if [ $(echo $density | wc -w) -gt 1 ]; then
749 echo "tapas: Error: Multiple densities supplied: $density"
753 local product=aosp_arm
755 x86) product=aosp_x86;;
756 mips) product=aosp_mips;;
757 armv5) product=generic_armv5;;
758 arm64) product=aosp_arm64;;
759 x86_64) product=aosp_x86_64;;
760 mips64) product=aosp_mips64;;
762 if [ -z "$variant" ]; then
765 if [ -z "$apps" ]; then
768 if [ -z "$density" ]; then
772 export TARGET_PRODUCT=$product
773 export TARGET_BUILD_VARIANT=$variant
774 export TARGET_BUILD_DENSITY=$density
775 export TARGET_BUILD_TYPE=release
776 export TARGET_BUILD_APPS=$apps
778 build_build_var_cache
779 set_stuff_for_environment
781 destroy_build_var_cache
787 MODVERSION=`sed -n -e'/ro\.cm\.version/s/.*=//p' $OUT/system/build.prop`
788 ZIPFILE=cm-$MODVERSION.zip
789 ZIPPATH=$OUT/$ZIPFILE
790 if [ ! -f $ZIPPATH ] ; then
791 echo "Nothing to eat"
794 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
795 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
796 echo "No device is online. Waiting for one..."
797 echo "Please connect USB and/or enable USB debugging"
798 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
801 echo "Device Found.."
803 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
805 # if adbd isn't root we can't write to /cache/recovery/
809 SZ=`stat -c %s $ZIPPATH`
810 CACHESIZE=`adb shell busybox df -PB1 /cache | grep /cache | tr -s ' ' | cut -d ' ' -f 4`
811 if [ $CACHESIZE -gt $SZ ];
816 PUSHDIR=/storage/sdcard0/
817 # Optional path for sdcard0 in recovery
818 [ -z "$1" ] && DIR=sdcard/0 || DIR=$1
820 echo "Pushing $ZIPFILE to $PUSHDIR"
821 if adb push $ZIPPATH $PUSHDIR ; then
822 cat << EOF > /tmp/command
823 --update_package=/$DIR/$ZIPFILE
825 if adb push /tmp/command /cache/recovery/ ; then
826 echo "Rebooting into recovery for installation"
832 echo "Nothing to eat"
837 echo "The connected device does not appear to be $CM_BUILD, run away!"
849 local TOPFILE=build/core/envsetup.mk
850 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
851 # The following circumlocution ensures we remove symlinks from TOP.
852 (cd $TOP; PWD= /bin/pwd)
854 if [ -f $TOPFILE ] ; then
855 # The following circumlocution (repeated below as well) ensures
856 # that we record the true directory name and not one that is
857 # faked up with symlink names.
862 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
867 if [ -f "$T/$TOPFILE" ]; then
874 # Return driver for "make", if any (eg. static analyzer)
878 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
879 if [ -n "$WITH_STATIC_ANALYZER" ]; then
881 $T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
882 --use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
891 local DRV=$(getdriver $T)
893 $DRV make -C $T -f build/core/main.mk $@
895 echo "Couldn't locate the top of the tree. Try setting TOP."
900 function findmakefile()
902 TOPFILE=build/core/envsetup.mk
905 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
907 if [ -f "$T/Android.mk" ]; then
920 local DRV=$(getdriver $T)
921 # If we're sitting in the root of the build tree, just do a
923 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
926 # Find the closest Android.mk file.
927 local M=$(findmakefile)
929 local GET_INSTALL_PATH=
931 # Remove the path to top as the makefilepath needs to be relative
932 local M=`echo $M|sed 's:'$T'/::'`
934 echo "Couldn't locate the top of the tree. Try setting TOP."
936 elif [ ! "$M" ]; then
937 echo "Couldn't locate a makefile from the current directory."
942 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
945 if [ -n "$GET_INSTALL_PATH" ]; then
947 ARGS=GET-INSTALL-PATH
952 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
960 local DRV=$(getdriver $T)
966 local GET_INSTALL_PATH=
967 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
968 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
969 for DIR in $DIRS ; do
970 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
971 if [ "$MODULES" = "" ]; then
974 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
975 if [ -f $DIR/Android.mk ]; then
976 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
977 local TO_CHOP=`expr $TO_CHOP + 1`
978 local START=`PWD= /bin/pwd`
979 local MFILE=`echo $START | cut -c${TO_CHOP}-`
980 if [ "$MFILE" = "" ] ; then
981 MFILE=$DIR/Android.mk
983 MFILE=$MFILE/$DIR/Android.mk
985 MAKEFILE="$MAKEFILE $MFILE"
988 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
989 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
990 *) if [ -d $DIR ]; then
991 echo "No Android.mk in $DIR.";
993 echo "Couldn't locate the directory $DIR";
999 if [ -n "$GET_INSTALL_PATH" ]; then
1000 ARGS=$GET_INSTALL_PATH
1003 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
1005 echo "Couldn't locate the top of the tree. Try setting TOP."
1013 local DRV=$(getdriver $T)
1014 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
1018 echo "Couldn't locate the top of the tree. Try setting TOP."
1021 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
1022 local MODULES_IN_PATHS=MODULES-IN-$MY_PWD
1023 # Convert "/" to "-".
1024 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
1025 $DRV make -C $T -f build/core/main.mk $@ $MODULES_IN_PATHS
1032 local DRV=$(getdriver $T)
1034 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
1035 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
1036 local MY_PWD=`PWD= /bin/pwd`
1037 if [ "$MY_PWD" = "$T" ]; then
1040 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
1043 local MODULES_IN_PATHS=
1045 for DIR in $DIRS ; do
1046 if [ -d $DIR ]; then
1047 # Remove the leading ./ and trailing / if any exists.
1050 if [ "$MY_PWD" != "" ]; then
1053 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
1056 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
1057 *) echo "Couldn't find directory $DIR"; return 1;;
1061 # Convert "/" to "-".
1062 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
1063 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS $MODULES_IN_PATHS
1065 echo "Couldn't locate the top of the tree. Try setting TOP."
1076 echo "Couldn't locate the top of the tree. Try setting TOP."
1082 TOPFILE=build/core/envsetup.mk
1085 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1087 if [ -f "$T/Android.mk" ]; then
1094 echo "can't find Android.mk"
1097 # simplified version of ps; output in the form
1102 if [ "$1" = "--exact" ]; then
1106 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1107 echo "usage: qpid [[--exact] <process name|pid>"
1112 if [ "$EXE" ] ; then
1113 qpid | \grep "$prepend$EXE$append"
1117 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1125 if [ "$1" = "--exact" ]; then
1131 if [ "$EXE" ] ; then
1132 local PID=`adb shell ps \
1134 | \grep "$prepend$EXE$append" \
1135 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1138 echo "usage: pid [--exact] <process name>"
1143 # coredump_setup - enable core dumps globally for any process
1144 # that has the core-file-size limit set correctly
1146 # NOTE: You must call also coredump_enable for a specific process
1147 # if its core-file-size limit is not set already.
1148 # NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1150 function coredump_setup()
1152 echo "Getting root...";
1154 adb wait-for-device;
1156 echo "Remounting root partition read-write...";
1157 adb shell mount -w -o remount -t rootfs rootfs;
1159 adb wait-for-device;
1160 adb shell mkdir -p /cores;
1161 adb shell mount -t tmpfs tmpfs /cores;
1162 adb shell chmod 0777 /cores;
1164 echo "Granting SELinux permission to dump in /cores...";
1165 adb shell restorecon -R /cores;
1167 echo "Set core pattern.";
1168 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1173 # coredump_enable - enable core dumps for the specified process
1174 # $1 = PID of process (e.g., $(pid mediaserver))
1176 # NOTE: coredump_setup must have been called as well for a core
1177 # dump to actually be generated.
1179 function coredump_enable()
1182 if [ -z "$PID" ]; then
1183 printf "Expecting a PID!\n";
1186 echo "Setting core limit for $PID to infinite...";
1187 adb shell prlimit $PID 4 -1 -1
1190 # core - send SIGV and pull the core for process
1191 # $1 = PID of process (e.g., $(pid mediaserver))
1193 # NOTE: coredump_setup must be called once per boot for core dumps to be
1200 if [ -z "$PID" ]; then
1201 printf "Expecting a PID!\n";
1205 local CORENAME=core.$PID;
1206 local COREPATH=/cores/$CORENAME;
1212 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1213 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1214 adb shell kill -$SIG $PID;
1218 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1219 echo "Done: core is under $COREPATH on device.";
1222 # systemstack - dump the current stack trace of all threads in the system process
1223 # to the usual ANR traces file
1224 function systemstack()
1226 stacks system_server
1231 if [[ $1 =~ ^[0-9]+$ ]] ; then
1233 elif [ "$1" ] ; then
1234 local PIDLIST="$(pid $1)"
1235 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1236 local PID="$PIDLIST"
1237 elif [ "$PIDLIST" ] ; then
1238 echo "more than one process: $1"
1240 echo "no such process: $1"
1243 echo "usage: stacks [pid|process name]"
1246 if [ "$PID" ] ; then
1247 # Determine whether the process is native
1248 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1249 # Dump stacks of Dalvik process
1250 local TRACES=/data/anr/traces.txt
1251 local ORIG=/data/anr/traces.orig
1252 local TMP=/data/anr/traces.tmp
1254 # Keep original traces to avoid clobbering
1255 adb shell mv $TRACES $ORIG
1257 # Make sure we have a usable file
1258 adb shell touch $TRACES
1259 adb shell chmod 666 $TRACES
1261 # Dump stacks and wait for dump to finish
1262 adb shell kill -3 $PID
1263 adb shell notify $TRACES >/dev/null
1265 # Restore original stacks, and show current output
1266 adb shell mv $TRACES $TMP
1267 adb shell mv $ORIG $TRACES
1270 # Dump stacks of native process
1271 local USE64BIT="$(is64bit $PID)"
1272 adb shell debuggerd$USE64BIT -b $PID
1277 # Read the ELF header from /proc/$PID/exe to determine if the process is
1282 if [ "$PID" ] ; then
1283 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
1297 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl|vts)' \
1298 -exec grep --color -n "$@" {} +
1305 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\)' \
1306 -exec grep --color -n "$@" {} +
1311 function gettargetarch
1313 get_build_var TARGET_ARCH
1318 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1319 -exec grep --color -n "$@" {} +
1324 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1325 -exec grep --color -n "$@" {} +
1330 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' \) \
1331 -exec grep --color -n "$@" {} +
1336 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1337 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1343 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1344 -exec grep --color -n "$@" {} +
1349 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1350 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
1355 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1356 -exec grep --color -n "$@" {} +
1363 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' \
1364 -exec grep --color -n "$@" {} +
1369 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' \
1370 -exec grep --color -n -i "$@" {} +
1377 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f \
1378 -exec grep --color -n "$@" {} +
1383 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f \
1384 -exec grep --color -n -i "$@" {} +
1390 function getprebuilt
1392 get_abs_build_var ANDROID_PREBUILTS
1395 function tracedmdump()
1399 echo "Couldn't locate the top of the tree. Try setting TOP."
1402 local prebuiltdir=$(getprebuilt)
1403 local arch=$(gettargetarch)
1404 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
1407 if [ ! "$TRACE" ] ; then
1408 echo "usage: tracedmdump tracename"
1412 if [ ! -r "$KERNEL" ] ; then
1413 echo "Error: cannot find kernel: '$KERNEL'"
1417 local BASETRACE=$(basename $TRACE)
1418 if [ "$BASETRACE" = "$TRACE" ] ; then
1419 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1422 echo "post-processing traces..."
1423 rm -f $TRACE/qtrace.dexlist
1425 if [ $? -ne 0 ]; then
1427 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1431 echo "generating dexlist output..."
1432 /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
1433 echo "generating dmtrace data..."
1434 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1435 echo "generating html file..."
1436 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1437 echo "done, see $TRACE/dmtrace.html for details"
1439 echo " traceview $TRACE/dmtrace"
1442 # communicate with a running device or emulator, set up necessary state,
1443 # and run the hat command.
1446 # process standard adb options
1448 if [ "$1" = "-d" -o "$1" = "-e" ]; then
1451 elif [ "$1" = "-s" ]; then
1455 local adbOptions=${adbTarget}
1456 #echo adbOptions = ${adbOptions}
1461 if [ "$targetPid" = "" ]; then
1462 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
1466 # confirm hat is available
1467 if [ -z $(which hat) ]; then
1468 echo "hat is not available in this configuration."
1472 # issue "am" command to cause the hprof dump
1473 local devFile=/data/local/tmp/hprof-$targetPid
1474 echo "Poking $targetPid and waiting for data..."
1475 echo "Storing data at $devFile"
1476 adb ${adbOptions} shell am dumpheap $targetPid $devFile
1477 echo "Press enter when logcat shows \"hprof: heap dump completed\""
1481 local localFile=/tmp/$$-hprof
1483 echo "Retrieving file $devFile..."
1484 adb ${adbOptions} pull $devFile $localFile
1486 adb ${adbOptions} shell rm $devFile
1488 echo "Running hat on $localFile"
1489 echo "View the output by pointing your browser at http://localhost:7000/"
1491 hat -JXmx512m $localFile
1494 function getbugreports()
1496 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
1498 if [ ! "$reports" ]; then
1499 echo "Could not locate any bugreports."
1504 for report in ${reports[@]}
1506 echo "/sdcard/bugreports/${report}"
1507 adb pull /sdcard/bugreports/${report} ${report}
1512 function getsdcardpath()
1514 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1517 function getscreenshotpath()
1519 echo "$(getsdcardpath)/Pictures/Screenshots"
1522 function getlastscreenshot()
1524 local screenshot_path=$(getscreenshotpath)
1525 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1526 if [ "$screenshot" = "" ]; then
1527 echo "No screenshots found."
1530 echo "${screenshot}"
1531 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1534 function startviewserver()
1537 if [ $# -gt 0 ]; then
1540 adb shell service call window 1 i32 $port
1543 function stopviewserver()
1545 adb shell service call window 2
1548 function isviewserverstarted()
1550 adb shell service call window 3
1555 adb shell input keyevent 3
1560 adb shell input keyevent 4
1565 adb shell input keyevent 82
1568 function smoketest()
1570 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1571 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1576 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1580 (\cd "$T" && mmm tests/SmokeTest) &&
1581 adb uninstall com.android.smoketest > /dev/null &&
1582 adb uninstall com.android.smoketest.tests > /dev/null &&
1583 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1584 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1585 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1588 # simple shortcut to the runtest command
1593 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1596 ("$T"/development/testrunner/runtest.py $@)
1600 if [[ -z "$1" ]]; then
1601 echo "Usage: godir <regex>"
1605 if [ ! "$OUT_DIR" = "" ]; then
1607 FILELIST=$OUT_DIR/filelist
1609 FILELIST=$T/filelist
1611 if [[ ! -f $FILELIST ]]; then
1612 echo -n "Creating index..."
1613 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
1618 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
1619 if [[ ${#lines[@]} = 0 ]]; then
1625 if [[ ${#lines[@]} > 1 ]]; then
1626 while [[ -z "$pathname" ]]; do
1629 for line in ${lines[@]}; do
1630 printf "%6s %s\n" "[$index]" $line
1631 index=$(($index + 1))
1634 echo -n "Select one: "
1637 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1638 echo "Invalid choice"
1641 pathname=${lines[$(($choice-1))]}
1644 pathname=${lines[0]}
1651 git remote rm cmremote 2> /dev/null
1654 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1656 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1657 if [ -z "$GERRIT_REMOTE" ]
1659 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1660 if [ -z "$GERRIT_REMOTE" ]
1662 echo Unable to set up the git remote, are you in the root of the repo?
1666 CMUSER=`git config --get review.review.cyanogenmod.org.username`
1669 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
1671 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
1673 echo You can now push to "cmremote".
1677 function aospremote()
1679 git remote rm aosp 2> /dev/null
1682 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1684 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1685 if (echo $PROJECT | grep -qv "^device")
1689 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1690 echo "Remote 'aosp' created"
1692 export -f aospremote
1694 function installboot()
1696 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1698 echo "No recovery.fstab found. Build recovery first."
1701 if [ ! -e "$OUT/boot.img" ];
1703 echo "No boot.img found. Run make bootimage first."
1706 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1707 if [ -z "$PARTITION" ];
1709 echo "Unable to determine boot partition."
1718 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1720 adb push $OUT/boot.img /cache/
1721 for i in $OUT/system/lib/modules/*;
1723 adb push $i /system/lib/modules/
1725 adb shell dd if=/cache/boot.img of=$PARTITION
1726 adb shell chmod 644 /system/lib/modules/*
1727 echo "Installation complete."
1729 echo "The connected device does not appear to be $CM_BUILD, run away!"
1733 function installrecovery()
1735 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1737 echo "No recovery.fstab found. Build recovery first."
1740 if [ ! -e "$OUT/recovery.img" ];
1742 echo "No recovery.img found. Run make recoveryimage first."
1745 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1746 if [ -z "$PARTITION" ];
1748 echo "Unable to determine recovery partition."
1757 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1759 adb push $OUT/recovery.img /cache/
1760 adb shell dd if=/cache/recovery.img of=$PARTITION
1761 echo "Installation complete."
1763 echo "The connected device does not appear to be $CM_BUILD, run away!"
1767 function makerecipe() {
1770 echo "No branch name provided."
1774 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1775 git commit -a -m "$1"
1780 if [ "$REPO_REMOTE" == "github" ]
1784 git push cmremote HEAD:refs/heads/'$1'
1789 function cmgerrit() {
1790 if [ $# -eq 0 ]; then
1794 local user=`git config --get review.review.cyanogenmod.org.username`
1795 local review=`git config --get remote.github.review`
1796 local project=`git config --get remote.github.projectname`
1801 if [ $# -eq 0 ]; then
1804 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1807 fetch Just fetch the change as FETCH_HEAD
1808 help Show this help, or for a specific command
1809 pull Pull a change into current branch
1810 push Push HEAD or a local branch to Gerrit for a specific branch
1812 Any other Git commands that support refname would work as:
1813 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1815 See '$FUNCNAME help COMMAND' for more information on a specific command.
1818 $FUNCNAME checkout -b topic 1234/5
1820 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1821 && git checkout -b topic FETCH_HEAD
1822 will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1823 Patch-set 1 will be fetched if omitted.
1828 __cmg_*) echo "For internal use only." ;;
1830 if [ "$FUNCNAME" = "cmgerrit" ]; then
1831 echo "'$FUNCNAME $1' is deprecated."
1834 help) $FUNCNAME help ;;
1835 fetch|pull) cat <<EOF
1836 usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1839 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1840 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1844 will $1 patch-set 1 of change 1234
1848 usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1851 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1852 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1855 $FUNCNAME push fix6789:gingerbread
1856 will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1857 HEAD will be pushed from local if omitted.
1861 $FUNCNAME __cmg_err_not_supported $1 && return
1863 usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1866 git fetch http://DOMAIN/p/PROJECT \\
1867 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1868 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1874 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1875 local change_id patchset_id hash
1886 hash=$(($change_id % 100))
1888 [0-9]) hash="0$hash" ;;
1890 echo "refs/changes/$hash/$change_id/$patchset_id"
1893 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1894 $FUNCNAME __cmg_err_not_repo && return 1
1897 git $command $@ http://$review/p/$project \
1898 $($FUNCNAME __cmg_get_ref $change) || return 1
1901 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1902 $FUNCNAME __cmg_err_not_repo && return 1
1903 if [ -z "$user" ]; then
1904 echo >&2 "Gerrit username not found."
1907 local local_branch remote_branch
1910 local_branch=${1%:*}
1911 remote_branch=${1##*:}
1919 git push $@ ssh://$user@$review:29418/$project \
1920 $local_branch:refs/for/$remote_branch || return 1
1923 if [ "$FUNCNAME" = "cmgerrit" ]; then
1924 echo >&2 "'$FUNCNAME $command' is deprecated."
1928 if [ $# -lt 2 ]; then
1929 echo >&2 "'$FUNCNAME $command' missing argument."
1930 elif [ $2 -eq 0 ]; then
1931 if [ -n "$3" ]; then
1934 echo >&2 "'$FUNCNAME $1' missing argument."
1941 if [ -z "$review" -o -z "$project" ]; then
1942 echo >&2 "Not currently in any reviewable repository."
1947 __cmg_err_not_supported)
1948 $FUNCNAME __cmg_err_no_arg $command $# && return
1950 #TODO: filter more git commands that don't use refname
1951 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1952 echo >&2 "'$FUNCNAME $1' is not supported."
1957 #TODO: other special cases?
1959 $FUNCNAME __cmg_err_not_supported $command && return 1
1960 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1961 $FUNCNAME __cmg_err_not_repo && return 1
1963 local change pre_args refs_arg post_args
1966 pre_args=${args%%-- *}
1967 post_args="-- ${args#*-- }"
1969 *) pre_args="$args" ;;
1973 if [ ${#args[@]} -gt 0 ]; then
1974 change=${args[${#args[@]}-1]}
1976 if [ ${#args[@]} -gt 1 ]; then
1978 for ((i=1; i<${#args[@]}-1; i++)); do
1979 pre_args="$pre_args ${args[$i]}"
1985 $FUNCNAME help $command
1989 if [ -z "$refs_arg" ]; then
1990 refs_arg="@${change#*@}"
1991 change=${change%%@*}
1995 if [ -z "$refs_arg" ]; then
1996 refs_arg="~${change#*~}"
1997 change=${change%%~*}
2001 if [ -z "$refs_arg" ]; then
2002 refs_arg="^${change#*^}"
2003 change=${change%%^*}
2007 if [ -z "$refs_arg" ]; then
2008 refs_arg=":${change#*:}"
2009 change=${change%%:*}
2015 $FUNCNAME fetch $change \
2016 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2022 function cmrebase() {
2026 local dir="$(gettop)/$repo"
2028 if [ -z $repo ] || [ -z $refs ]; then
2029 echo "CyanogenMod Gerrit Rebase Usage: "
2030 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2031 echo " The patch IDs appear on the Gerrit commands that are offered."
2032 echo " They consist on a series of numbers and slashes, after the text"
2033 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2035 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2040 if [ ! -d $dir ]; then
2041 echo "Directory $dir doesn't exist in tree."
2045 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2046 echo "Starting branch..."
2047 repo start tmprebase .
2048 echo "Bringing it up to date..."
2050 echo "Fetching change..."
2051 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
2052 if [ "$?" != "0" ]; then
2053 echo "Error cherry-picking. Not uploading!"
2058 echo "Cleaning up..."
2059 repo abandon tmprebase .
2066 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2069 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
2074 function reposync() {
2080 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
2085 function repodiff() {
2086 if [ -z "$*" ]; then
2087 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2090 diffopts=$* repo forall -c \
2091 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2094 # Credit for color strip sed: http://goo.gl/BoIcm
2100 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2101 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2102 echo "No device is online. Waiting for one..."
2103 echo "Please connect USB and/or enable USB debugging"
2104 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2107 echo "Device Found."
2110 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2112 adb root &> /dev/null
2114 adb wait-for-device &> /dev/null
2116 adb remount &> /dev/null
2118 $func $* | tee $OUT/.log
2121 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)
2124 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)
2126 for FILE in $LOC; do
2127 # Get target file name (i.e. system/bin/adb)
2128 TARGET=$(echo $FILE | sed "s#$OUT/##")
2130 # Don't send files that are not in /system.
2131 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
2135 system/app/SystemUI.apk|system/framework/*)
2142 if $stop_n_start ; then adb shell stop ; fi
2143 echo "Pushing: $TARGET"
2144 adb push $FILE $TARGET
2145 if $stop_n_start ; then adb shell start ; fi
2151 echo "The connected device does not appear to be $CM_BUILD, run away!"
2155 alias mmp='dopush mm'
2156 alias mmmp='dopush mmm'
2157 alias mkap='dopush mka'
2158 alias cmkap='dopush cmka'
2160 # Force JAVA_HOME to point to java 1.7/1.8 if it isn't already set.
2161 function set_java_home() {
2162 # Clear the existing JAVA_HOME value if we set it ourselves, so that
2163 # we can reset it later, depending on the version of java the build
2166 # If we don't do this, the JAVA_HOME value set by the first call to
2167 # build/envsetup.sh will persist forever.
2168 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2172 if [ ! "$JAVA_HOME" ]; then
2173 if [ -n "$LEGACY_USE_JAVA7" ]; then
2174 echo Warning: Support for JDK 7 will be dropped. Switch to JDK 8.
2177 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2180 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2186 export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
2189 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
2194 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2195 # we can change it on the next envsetup.sh, if required.
2196 export ANDROID_SET_JAVA_HOME=true
2200 # Print colored exit condition
2204 if [ $retval -ne 0 ]
2206 echo $'\E'"[0;31mFAILURE\e[00m"
2208 echo $'\E'"[0;32mSUCCESS\e[00m"
2213 function get_make_command()
2220 local start_time=$(date +"%s")
2221 $(get_make_command) "$@"
2223 local end_time=$(date +"%s")
2224 local tdiff=$(($end_time-$start_time))
2225 local hours=$(($tdiff / 3600 ))
2226 local mins=$((($tdiff % 3600) / 60))
2227 local secs=$(($tdiff % 60))
2228 local ncolors=$(tput colors 2>/dev/null)
2229 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2230 color_failed=$'\E'"[0;31m"
2231 color_success=$'\E'"[0;32m"
2232 color_reset=$'\E'"[00m"
2239 if [ $ret -eq 0 ] ; then
2240 echo -n "${color_success}#### make completed successfully "
2242 echo -n "${color_failed}#### make failed to build some targets "
2244 if [ $hours -gt 0 ] ; then
2245 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2246 elif [ $mins -gt 0 ] ; then
2247 printf "(%02g:%02g (mm:ss))" $mins $secs
2248 elif [ $secs -gt 0 ] ; then
2249 printf "(%s seconds)" $secs
2251 echo " ####${color_reset}"
2256 function provision()
2258 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
2259 echo "Couldn't locate output files. Try running 'lunch' first." >&2
2262 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
2263 echo "There is no provisioning script for the device." >&2
2267 # Check if user really wants to do this.
2268 if [ "$1" = "--no-confirmation" ]; then
2271 echo "This action will reflash your device."
2273 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
2275 echo -n "Are you sure you want to do this (yes/no)? "
2277 if [[ "${REPLY}" != "yes" ]] ; then
2278 echo "Not taking any action. Exiting." >&2
2282 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
2285 if [ "x$SHELL" != "x/bin/bash" ]; then
2286 case `ps -o command -p $$` in
2290 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2295 # Execute the contents of any vendorsetup.sh files we can find.
2296 for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2297 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2298 `test -d product && find -L product -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`