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 dirs="sdk/bash_completion vendor/cm/bash_completion"
361 if [ -d ${dir} ]; then
362 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
370 function choosetype()
372 echo "Build type choices are:"
377 local DEFAULT_NUM DEFAULT_VALUE
379 DEFAULT_VALUE=release
381 export TARGET_BUILD_TYPE=
383 while [ -z $TARGET_BUILD_TYPE ]
385 echo -n "Which would you like? ["$DEFAULT_NUM"] "
386 if [ -z "$1" ] ; then
394 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
397 export TARGET_BUILD_TYPE=release
400 export TARGET_BUILD_TYPE=release
403 export TARGET_BUILD_TYPE=debug
406 export TARGET_BUILD_TYPE=debug
410 echo "I didn't understand your response. Please try again."
414 if [ -n "$1" ] ; then
419 build_build_var_cache
420 set_stuff_for_environment
421 destroy_build_var_cache
425 # This function isn't really right: It chooses a TARGET_PRODUCT
426 # based on the list of boards. Usually, that gets you something
427 # that kinda works with a generic product, but really, you should
428 # pick a product by name.
430 function chooseproduct()
432 if [ "x$TARGET_PRODUCT" != x ] ; then
433 default_value=$TARGET_PRODUCT
435 default_value=aosp_arm
438 export TARGET_BUILD_APPS=
439 export TARGET_PRODUCT=
441 while [ -z "$TARGET_PRODUCT" ]
443 echo -n "Which product would you like? [$default_value] "
444 if [ -z "$1" ] ; then
451 if [ -z "$ANSWER" ] ; then
452 export TARGET_PRODUCT=$default_value
454 if check_product $ANSWER
456 export TARGET_PRODUCT=$ANSWER
458 echo "** Not a valid product: $ANSWER"
461 if [ -n "$1" ] ; then
466 build_build_var_cache
467 set_stuff_for_environment
468 destroy_build_var_cache
471 function choosevariant()
473 echo "Variant choices are:"
476 for v in ${VARIANT_CHOICES[@]}
478 # The product name is the name of the directory containing
479 # the makefile we found, above.
484 local default_value=eng
487 export TARGET_BUILD_VARIANT=
488 while [ -z "$TARGET_BUILD_VARIANT" ]
490 echo -n "Which would you like? [$default_value] "
491 if [ -z "$1" ] ; then
498 if [ -z "$ANSWER" ] ; then
499 export TARGET_BUILD_VARIANT=$default_value
500 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
501 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
502 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
505 if check_variant $ANSWER
507 export TARGET_BUILD_VARIANT=$ANSWER
509 echo "** Not a valid variant: $ANSWER"
512 if [ -n "$1" ] ; then
518 function choosecombo()
531 build_build_var_cache
532 set_stuff_for_environment
534 destroy_build_var_cache
537 # Clear this variable. It will be built up again when the vendorsetup.sh
538 # files are included at the end of this file.
539 unset LUNCH_MENU_CHOICES
540 function add_lunch_combo()
544 for c in ${LUNCH_MENU_CHOICES[@]} ; do
545 if [ "$new_combo" = "$c" ] ; then
549 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
552 # add the default one here
553 add_lunch_combo aosp_arm-eng
554 add_lunch_combo aosp_arm64-eng
555 add_lunch_combo aosp_mips-eng
556 add_lunch_combo aosp_mips64-eng
557 add_lunch_combo aosp_x86-eng
558 add_lunch_combo aosp_x86_64-eng
560 function print_lunch_menu()
564 echo "You're building on" $uname
565 if [ "$(uname)" = "Darwin" ] ; then
566 echo " (ohai, koush!)"
569 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
570 echo "Breakfast menu... pick a combo:"
572 echo "Lunch menu... pick a combo:"
577 for choice in ${LUNCH_MENU_CHOICES[@]}
583 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
584 echo "... and don't forget the bacon!"
593 if [ $? -eq 0 ]; then
596 echo "No such item in brunch menu. Try 'breakfast'"
605 CM_DEVICES_ONLY="true"
606 unset LUNCH_MENU_CHOICES
607 add_lunch_combo full-eng
608 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
615 if [ $# -eq 0 ]; then
616 # No arguments, so let's have the full menu
619 echo "z$target" | grep -q "-"
620 if [ $? -eq 0 ]; then
621 # A buildtype was specified, assume a full device name
624 # This is probably just the CM model name
625 lunch cm_$target-userdebug
641 echo -n "Which would you like? [aosp_arm-eng] "
649 selection=aosp_arm-eng
650 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
652 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
654 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
656 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
661 if [ -z "$selection" ]
664 echo "Invalid lunch combo: $answer"
668 export TARGET_BUILD_APPS=
670 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
671 check_variant $variant
675 echo "** Invalid variant: '$variant'"
676 echo "** Must be one of ${VARIANT_CHOICES[@]}"
680 local product=$(echo -n $selection | sed -e "s/-.*$//")
681 TARGET_PRODUCT=$product \
682 TARGET_BUILD_VARIANT=$variant \
683 build_build_var_cache
686 # if we can't find a product, try to grab it off the CM github
689 build/tools/roomservice.py $product
691 check_product $product
693 build/tools/roomservice.py $product true
698 echo "** Don't have a product spec for: '$product'"
699 echo "** Do you have the right repo manifest?"
703 if [ -z "$product" -o -z "$variant" ]
709 export TARGET_PRODUCT=$product
710 export TARGET_BUILD_VARIANT=$variant
711 export TARGET_BUILD_TYPE=release
715 set_stuff_for_environment
717 destroy_build_var_cache
720 # Tab completion for lunch.
725 cur="${COMP_WORDS[COMP_CWORD]}"
726 prev="${COMP_WORDS[COMP_CWORD-1]}"
728 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
731 complete -F _lunch lunch
733 # Configures the build to build unbundled apps.
734 # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
737 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
738 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
739 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
740 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)"
742 if [ $(echo $arch | wc -w) -gt 1 ]; then
743 echo "tapas: Error: Multiple build archs supplied: $arch"
746 if [ $(echo $variant | wc -w) -gt 1 ]; then
747 echo "tapas: Error: Multiple build variants supplied: $variant"
750 if [ $(echo $density | wc -w) -gt 1 ]; then
751 echo "tapas: Error: Multiple densities supplied: $density"
755 local product=aosp_arm
757 x86) product=aosp_x86;;
758 mips) product=aosp_mips;;
759 armv5) product=generic_armv5;;
760 arm64) product=aosp_arm64;;
761 x86_64) product=aosp_x86_64;;
762 mips64) product=aosp_mips64;;
764 if [ -z "$variant" ]; then
767 if [ -z "$apps" ]; then
770 if [ -z "$density" ]; then
774 export TARGET_PRODUCT=$product
775 export TARGET_BUILD_VARIANT=$variant
776 export TARGET_BUILD_DENSITY=$density
777 export TARGET_BUILD_TYPE=release
778 export TARGET_BUILD_APPS=$apps
780 build_build_var_cache
781 set_stuff_for_environment
783 destroy_build_var_cache
789 MODVERSION=`sed -n -e'/ro\.cm\.version/s/.*=//p' $OUT/system/build.prop`
790 ZIPFILE=cm-$MODVERSION.zip
791 ZIPPATH=$OUT/$ZIPFILE
792 if [ ! -f $ZIPPATH ] ; then
793 echo "Nothing to eat"
796 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
797 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
798 echo "No device is online. Waiting for one..."
799 echo "Please connect USB and/or enable USB debugging"
800 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
803 echo "Device Found.."
805 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
807 # if adbd isn't root we can't write to /cache/recovery/
811 SZ=`stat -c %s $ZIPPATH`
812 CACHESIZE=`adb shell busybox df -PB1 /cache | grep /cache | tr -s ' ' | cut -d ' ' -f 4`
813 if [ $CACHESIZE -gt $SZ ];
818 PUSHDIR=/storage/sdcard0/
819 # Optional path for sdcard0 in recovery
820 [ -z "$1" ] && DIR=sdcard/0 || DIR=$1
822 echo "Pushing $ZIPFILE to $PUSHDIR"
823 if adb push $ZIPPATH $PUSHDIR ; then
824 cat << EOF > /tmp/command
825 --update_package=/$DIR/$ZIPFILE
827 if adb push /tmp/command /cache/recovery/ ; then
828 echo "Rebooting into recovery for installation"
834 echo "Nothing to eat"
839 echo "The connected device does not appear to be $CM_BUILD, run away!"
851 local TOPFILE=build/core/envsetup.mk
852 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
853 # The following circumlocution ensures we remove symlinks from TOP.
854 (cd $TOP; PWD= /bin/pwd)
856 if [ -f $TOPFILE ] ; then
857 # The following circumlocution (repeated below as well) ensures
858 # that we record the true directory name and not one that is
859 # faked up with symlink names.
864 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
869 if [ -f "$T/$TOPFILE" ]; then
876 # Return driver for "make", if any (eg. static analyzer)
880 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
881 if [ -n "$WITH_STATIC_ANALYZER" ]; then
883 $T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
884 --use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
893 local DRV=$(getdriver $T)
895 $DRV make -C $T -f build/core/main.mk $@
897 echo "Couldn't locate the top of the tree. Try setting TOP."
902 function findmakefile()
904 TOPFILE=build/core/envsetup.mk
907 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
909 if [ -f "$T/Android.mk" ]; then
922 local DRV=$(getdriver $T)
923 # If we're sitting in the root of the build tree, just do a
925 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
928 # Find the closest Android.mk file.
929 local M=$(findmakefile)
931 local GET_INSTALL_PATH=
933 # Remove the path to top as the makefilepath needs to be relative
934 local M=`echo $M|sed 's:'$T'/::'`
936 echo "Couldn't locate the top of the tree. Try setting TOP."
938 elif [ ! "$M" ]; then
939 echo "Couldn't locate a makefile from the current directory."
944 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
947 if [ -n "$GET_INSTALL_PATH" ]; then
949 ARGS=GET-INSTALL-PATH
954 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
962 local DRV=$(getdriver $T)
968 local GET_INSTALL_PATH=
969 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
970 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
971 for DIR in $DIRS ; do
972 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
973 if [ "$MODULES" = "" ]; then
976 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
977 if [ -f $DIR/Android.mk ]; then
978 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
979 local TO_CHOP=`expr $TO_CHOP + 1`
980 local START=`PWD= /bin/pwd`
981 local MFILE=`echo $START | cut -c${TO_CHOP}-`
982 if [ "$MFILE" = "" ] ; then
983 MFILE=$DIR/Android.mk
985 MFILE=$MFILE/$DIR/Android.mk
987 MAKEFILE="$MAKEFILE $MFILE"
990 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
991 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
992 *) if [ -d $DIR ]; then
993 echo "No Android.mk in $DIR.";
995 echo "Couldn't locate the directory $DIR";
1001 if [ -n "$GET_INSTALL_PATH" ]; then
1002 ARGS=$GET_INSTALL_PATH
1005 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
1007 echo "Couldn't locate the top of the tree. Try setting TOP."
1015 local DRV=$(getdriver $T)
1016 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
1020 echo "Couldn't locate the top of the tree. Try setting TOP."
1023 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
1024 local MODULES_IN_PATHS=MODULES-IN-$MY_PWD
1025 # Convert "/" to "-".
1026 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
1027 $DRV make -C $T -f build/core/main.mk $@ $MODULES_IN_PATHS
1034 local DRV=$(getdriver $T)
1036 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
1037 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
1038 local MY_PWD=`PWD= /bin/pwd`
1039 if [ "$MY_PWD" = "$T" ]; then
1042 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
1045 local MODULES_IN_PATHS=
1047 for DIR in $DIRS ; do
1048 if [ -d $DIR ]; then
1049 # Remove the leading ./ and trailing / if any exists.
1052 if [ "$MY_PWD" != "" ]; then
1055 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
1058 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
1059 *) echo "Couldn't find directory $DIR"; return 1;;
1063 # Convert "/" to "-".
1064 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
1065 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS $MODULES_IN_PATHS
1067 echo "Couldn't locate the top of the tree. Try setting TOP."
1078 echo "Couldn't locate the top of the tree. Try setting TOP."
1084 TOPFILE=build/core/envsetup.mk
1087 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1089 if [ -f "$T/Android.mk" ]; then
1096 echo "can't find Android.mk"
1099 # simplified version of ps; output in the form
1104 if [ "$1" = "--exact" ]; then
1108 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1109 echo "usage: qpid [[--exact] <process name|pid>"
1114 if [ "$EXE" ] ; then
1115 qpid | \grep "$prepend$EXE$append"
1119 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1127 if [ "$1" = "--exact" ]; then
1133 if [ "$EXE" ] ; then
1134 local PID=`adb shell ps \
1136 | \grep "$prepend$EXE$append" \
1137 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1140 echo "usage: pid [--exact] <process name>"
1145 # coredump_setup - enable core dumps globally for any process
1146 # that has the core-file-size limit set correctly
1148 # NOTE: You must call also coredump_enable for a specific process
1149 # if its core-file-size limit is not set already.
1150 # NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1152 function coredump_setup()
1154 echo "Getting root...";
1156 adb wait-for-device;
1158 echo "Remounting root partition read-write...";
1159 adb shell mount -w -o remount -t rootfs rootfs;
1161 adb wait-for-device;
1162 adb shell mkdir -p /cores;
1163 adb shell mount -t tmpfs tmpfs /cores;
1164 adb shell chmod 0777 /cores;
1166 echo "Granting SELinux permission to dump in /cores...";
1167 adb shell restorecon -R /cores;
1169 echo "Set core pattern.";
1170 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1175 # coredump_enable - enable core dumps for the specified process
1176 # $1 = PID of process (e.g., $(pid mediaserver))
1178 # NOTE: coredump_setup must have been called as well for a core
1179 # dump to actually be generated.
1181 function coredump_enable()
1184 if [ -z "$PID" ]; then
1185 printf "Expecting a PID!\n";
1188 echo "Setting core limit for $PID to infinite...";
1189 adb shell prlimit $PID 4 -1 -1
1192 # core - send SIGV and pull the core for process
1193 # $1 = PID of process (e.g., $(pid mediaserver))
1195 # NOTE: coredump_setup must be called once per boot for core dumps to be
1202 if [ -z "$PID" ]; then
1203 printf "Expecting a PID!\n";
1207 local CORENAME=core.$PID;
1208 local COREPATH=/cores/$CORENAME;
1214 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1215 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1216 adb shell kill -$SIG $PID;
1220 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1221 echo "Done: core is under $COREPATH on device.";
1224 # systemstack - dump the current stack trace of all threads in the system process
1225 # to the usual ANR traces file
1226 function systemstack()
1228 stacks system_server
1233 if [[ $1 =~ ^[0-9]+$ ]] ; then
1235 elif [ "$1" ] ; then
1236 local PIDLIST="$(pid $1)"
1237 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1238 local PID="$PIDLIST"
1239 elif [ "$PIDLIST" ] ; then
1240 echo "more than one process: $1"
1242 echo "no such process: $1"
1245 echo "usage: stacks [pid|process name]"
1248 if [ "$PID" ] ; then
1249 # Determine whether the process is native
1250 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1251 # Dump stacks of Dalvik process
1252 local TRACES=/data/anr/traces.txt
1253 local ORIG=/data/anr/traces.orig
1254 local TMP=/data/anr/traces.tmp
1256 # Keep original traces to avoid clobbering
1257 adb shell mv $TRACES $ORIG
1259 # Make sure we have a usable file
1260 adb shell touch $TRACES
1261 adb shell chmod 666 $TRACES
1263 # Dump stacks and wait for dump to finish
1264 adb shell kill -3 $PID
1265 adb shell notify $TRACES >/dev/null
1267 # Restore original stacks, and show current output
1268 adb shell mv $TRACES $TMP
1269 adb shell mv $ORIG $TRACES
1272 # Dump stacks of native process
1273 local USE64BIT="$(is64bit $PID)"
1274 adb shell debuggerd$USE64BIT -b $PID
1279 # Read the ELF header from /proc/$PID/exe to determine if the process is
1284 if [ "$PID" ] ; then
1285 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
1299 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl|vts)' \
1300 -exec grep --color -n "$@" {} +
1307 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\)' \
1308 -exec grep --color -n "$@" {} +
1313 function gettargetarch
1315 get_build_var TARGET_ARCH
1320 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1321 -exec grep --color -n "$@" {} +
1326 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1327 -exec grep --color -n "$@" {} +
1332 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' \) \
1333 -exec grep --color -n "$@" {} +
1338 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1339 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1345 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1346 -exec grep --color -n "$@" {} +
1351 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1352 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
1357 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1358 -exec grep --color -n "$@" {} +
1365 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' \
1366 -exec grep --color -n "$@" {} +
1371 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' \
1372 -exec grep --color -n -i "$@" {} +
1379 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f \
1380 -exec grep --color -n "$@" {} +
1385 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f \
1386 -exec grep --color -n -i "$@" {} +
1392 function getprebuilt
1394 get_abs_build_var ANDROID_PREBUILTS
1397 function tracedmdump()
1401 echo "Couldn't locate the top of the tree. Try setting TOP."
1404 local prebuiltdir=$(getprebuilt)
1405 local arch=$(gettargetarch)
1406 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
1409 if [ ! "$TRACE" ] ; then
1410 echo "usage: tracedmdump tracename"
1414 if [ ! -r "$KERNEL" ] ; then
1415 echo "Error: cannot find kernel: '$KERNEL'"
1419 local BASETRACE=$(basename $TRACE)
1420 if [ "$BASETRACE" = "$TRACE" ] ; then
1421 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1424 echo "post-processing traces..."
1425 rm -f $TRACE/qtrace.dexlist
1427 if [ $? -ne 0 ]; then
1429 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1433 echo "generating dexlist output..."
1434 /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
1435 echo "generating dmtrace data..."
1436 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1437 echo "generating html file..."
1438 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1439 echo "done, see $TRACE/dmtrace.html for details"
1441 echo " traceview $TRACE/dmtrace"
1444 # communicate with a running device or emulator, set up necessary state,
1445 # and run the hat command.
1448 # process standard adb options
1450 if [ "$1" = "-d" -o "$1" = "-e" ]; then
1453 elif [ "$1" = "-s" ]; then
1457 local adbOptions=${adbTarget}
1458 #echo adbOptions = ${adbOptions}
1463 if [ "$targetPid" = "" ]; then
1464 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
1468 # confirm hat is available
1469 if [ -z $(which hat) ]; then
1470 echo "hat is not available in this configuration."
1474 # issue "am" command to cause the hprof dump
1475 local devFile=/data/local/tmp/hprof-$targetPid
1476 echo "Poking $targetPid and waiting for data..."
1477 echo "Storing data at $devFile"
1478 adb ${adbOptions} shell am dumpheap $targetPid $devFile
1479 echo "Press enter when logcat shows \"hprof: heap dump completed\""
1483 local localFile=/tmp/$$-hprof
1485 echo "Retrieving file $devFile..."
1486 adb ${adbOptions} pull $devFile $localFile
1488 adb ${adbOptions} shell rm $devFile
1490 echo "Running hat on $localFile"
1491 echo "View the output by pointing your browser at http://localhost:7000/"
1493 hat -JXmx512m $localFile
1496 function getbugreports()
1498 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
1500 if [ ! "$reports" ]; then
1501 echo "Could not locate any bugreports."
1506 for report in ${reports[@]}
1508 echo "/sdcard/bugreports/${report}"
1509 adb pull /sdcard/bugreports/${report} ${report}
1514 function getsdcardpath()
1516 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1519 function getscreenshotpath()
1521 echo "$(getsdcardpath)/Pictures/Screenshots"
1524 function getlastscreenshot()
1526 local screenshot_path=$(getscreenshotpath)
1527 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1528 if [ "$screenshot" = "" ]; then
1529 echo "No screenshots found."
1532 echo "${screenshot}"
1533 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1536 function startviewserver()
1539 if [ $# -gt 0 ]; then
1542 adb shell service call window 1 i32 $port
1545 function stopviewserver()
1547 adb shell service call window 2
1550 function isviewserverstarted()
1552 adb shell service call window 3
1557 adb shell input keyevent 3
1562 adb shell input keyevent 4
1567 adb shell input keyevent 82
1570 function smoketest()
1572 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1573 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1578 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1582 (\cd "$T" && mmm tests/SmokeTest) &&
1583 adb uninstall com.android.smoketest > /dev/null &&
1584 adb uninstall com.android.smoketest.tests > /dev/null &&
1585 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1586 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1587 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1590 # simple shortcut to the runtest command
1595 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1598 ("$T"/development/testrunner/runtest.py $@)
1602 if [[ -z "$1" ]]; then
1603 echo "Usage: godir <regex>"
1607 if [ ! "$OUT_DIR" = "" ]; then
1609 FILELIST=$OUT_DIR/filelist
1611 FILELIST=$T/filelist
1613 if [[ ! -f $FILELIST ]]; then
1614 echo -n "Creating index..."
1615 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
1620 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
1621 if [[ ${#lines[@]} = 0 ]]; then
1627 if [[ ${#lines[@]} > 1 ]]; then
1628 while [[ -z "$pathname" ]]; do
1631 for line in ${lines[@]}; do
1632 printf "%6s %s\n" "[$index]" $line
1633 index=$(($index + 1))
1636 echo -n "Select one: "
1639 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1640 echo "Invalid choice"
1643 pathname=${lines[$(($choice-1))]}
1646 pathname=${lines[0]}
1653 git remote rm cmremote 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 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1659 if [ -z "$GERRIT_REMOTE" ]
1661 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1662 if [ -z "$GERRIT_REMOTE" ]
1664 echo Unable to set up the git remote, are you in the root of the repo?
1668 CMUSER=`git config --get review.review.cyanogenmod.org.username`
1671 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
1673 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
1675 echo You can now push to "cmremote".
1679 function aospremote()
1681 git remote rm aosp 2> /dev/null
1684 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1686 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1687 if (echo $PROJECT | grep -qv "^device")
1691 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1692 echo "Remote 'aosp' created"
1694 export -f aospremote
1696 function installboot()
1698 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1700 echo "No recovery.fstab found. Build recovery first."
1703 if [ ! -e "$OUT/boot.img" ];
1705 echo "No boot.img found. Run make bootimage first."
1708 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1709 if [ -z "$PARTITION" ];
1711 echo "Unable to determine boot partition."
1720 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1722 adb push $OUT/boot.img /cache/
1723 for i in $OUT/system/lib/modules/*;
1725 adb push $i /system/lib/modules/
1727 adb shell dd if=/cache/boot.img of=$PARTITION
1728 adb shell chmod 644 /system/lib/modules/*
1729 echo "Installation complete."
1731 echo "The connected device does not appear to be $CM_BUILD, run away!"
1735 function installrecovery()
1737 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1739 echo "No recovery.fstab found. Build recovery first."
1742 if [ ! -e "$OUT/recovery.img" ];
1744 echo "No recovery.img found. Run make recoveryimage first."
1747 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1748 if [ -z "$PARTITION" ];
1750 echo "Unable to determine recovery partition."
1759 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1761 adb push $OUT/recovery.img /cache/
1762 adb shell dd if=/cache/recovery.img of=$PARTITION
1763 echo "Installation complete."
1765 echo "The connected device does not appear to be $CM_BUILD, run away!"
1769 function makerecipe() {
1772 echo "No branch name provided."
1776 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1777 git commit -a -m "$1"
1782 if [ "$REPO_REMOTE" == "github" ]
1786 git push cmremote HEAD:refs/heads/'$1'
1791 function cmgerrit() {
1792 if [ $# -eq 0 ]; then
1796 local user=`git config --get review.review.cyanogenmod.org.username`
1797 local review=`git config --get remote.github.review`
1798 local project=`git config --get remote.github.projectname`
1803 if [ $# -eq 0 ]; then
1806 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1809 fetch Just fetch the change as FETCH_HEAD
1810 help Show this help, or for a specific command
1811 pull Pull a change into current branch
1812 push Push HEAD or a local branch to Gerrit for a specific branch
1814 Any other Git commands that support refname would work as:
1815 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1817 See '$FUNCNAME help COMMAND' for more information on a specific command.
1820 $FUNCNAME checkout -b topic 1234/5
1822 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1823 && git checkout -b topic FETCH_HEAD
1824 will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1825 Patch-set 1 will be fetched if omitted.
1830 __cmg_*) echo "For internal use only." ;;
1832 if [ "$FUNCNAME" = "cmgerrit" ]; then
1833 echo "'$FUNCNAME $1' is deprecated."
1836 help) $FUNCNAME help ;;
1837 fetch|pull) cat <<EOF
1838 usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1841 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1842 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1846 will $1 patch-set 1 of change 1234
1850 usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1853 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1854 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1857 $FUNCNAME push fix6789:gingerbread
1858 will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1859 HEAD will be pushed from local if omitted.
1863 $FUNCNAME __cmg_err_not_supported $1 && return
1865 usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1868 git fetch http://DOMAIN/p/PROJECT \\
1869 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1870 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1876 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1877 local change_id patchset_id hash
1888 hash=$(($change_id % 100))
1890 [0-9]) hash="0$hash" ;;
1892 echo "refs/changes/$hash/$change_id/$patchset_id"
1895 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1896 $FUNCNAME __cmg_err_not_repo && return 1
1899 git $command $@ http://$review/p/$project \
1900 $($FUNCNAME __cmg_get_ref $change) || return 1
1903 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1904 $FUNCNAME __cmg_err_not_repo && return 1
1905 if [ -z "$user" ]; then
1906 echo >&2 "Gerrit username not found."
1909 local local_branch remote_branch
1912 local_branch=${1%:*}
1913 remote_branch=${1##*:}
1921 git push $@ ssh://$user@$review:29418/$project \
1922 $local_branch:refs/for/$remote_branch || return 1
1925 if [ "$FUNCNAME" = "cmgerrit" ]; then
1926 echo >&2 "'$FUNCNAME $command' is deprecated."
1930 if [ $# -lt 2 ]; then
1931 echo >&2 "'$FUNCNAME $command' missing argument."
1932 elif [ $2 -eq 0 ]; then
1933 if [ -n "$3" ]; then
1936 echo >&2 "'$FUNCNAME $1' missing argument."
1943 if [ -z "$review" -o -z "$project" ]; then
1944 echo >&2 "Not currently in any reviewable repository."
1949 __cmg_err_not_supported)
1950 $FUNCNAME __cmg_err_no_arg $command $# && return
1952 #TODO: filter more git commands that don't use refname
1953 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1954 echo >&2 "'$FUNCNAME $1' is not supported."
1959 #TODO: other special cases?
1961 $FUNCNAME __cmg_err_not_supported $command && return 1
1962 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1963 $FUNCNAME __cmg_err_not_repo && return 1
1965 local change pre_args refs_arg post_args
1968 pre_args=${args%%-- *}
1969 post_args="-- ${args#*-- }"
1971 *) pre_args="$args" ;;
1975 if [ ${#args[@]} -gt 0 ]; then
1976 change=${args[${#args[@]}-1]}
1978 if [ ${#args[@]} -gt 1 ]; then
1980 for ((i=1; i<${#args[@]}-1; i++)); do
1981 pre_args="$pre_args ${args[$i]}"
1987 $FUNCNAME help $command
1991 if [ -z "$refs_arg" ]; then
1992 refs_arg="@${change#*@}"
1993 change=${change%%@*}
1997 if [ -z "$refs_arg" ]; then
1998 refs_arg="~${change#*~}"
1999 change=${change%%~*}
2003 if [ -z "$refs_arg" ]; then
2004 refs_arg="^${change#*^}"
2005 change=${change%%^*}
2009 if [ -z "$refs_arg" ]; then
2010 refs_arg=":${change#*:}"
2011 change=${change%%:*}
2017 $FUNCNAME fetch $change \
2018 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2024 function cmrebase() {
2028 local dir="$(gettop)/$repo"
2030 if [ -z $repo ] || [ -z $refs ]; then
2031 echo "CyanogenMod Gerrit Rebase Usage: "
2032 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2033 echo " The patch IDs appear on the Gerrit commands that are offered."
2034 echo " They consist on a series of numbers and slashes, after the text"
2035 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2037 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2042 if [ ! -d $dir ]; then
2043 echo "Directory $dir doesn't exist in tree."
2047 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2048 echo "Starting branch..."
2049 repo start tmprebase .
2050 echo "Bringing it up to date..."
2052 echo "Fetching change..."
2053 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
2054 if [ "$?" != "0" ]; then
2055 echo "Error cherry-picking. Not uploading!"
2060 echo "Cleaning up..."
2061 repo abandon tmprebase .
2068 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2071 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
2076 function reposync() {
2082 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
2087 function repodiff() {
2088 if [ -z "$*" ]; then
2089 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2092 diffopts=$* repo forall -c \
2093 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2096 # Credit for color strip sed: http://goo.gl/BoIcm
2102 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2103 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2104 echo "No device is online. Waiting for one..."
2105 echo "Please connect USB and/or enable USB debugging"
2106 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2109 echo "Device Found."
2112 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2114 adb root &> /dev/null
2116 adb wait-for-device &> /dev/null
2118 adb remount &> /dev/null
2120 $func $* | tee $OUT/.log
2123 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)
2126 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)
2128 for FILE in $LOC; do
2129 # Get target file name (i.e. system/bin/adb)
2130 TARGET=$(echo $FILE | sed "s#$OUT/##")
2132 # Don't send files that are not in /system.
2133 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
2137 system/app/SystemUI.apk|system/framework/*)
2144 if $stop_n_start ; then adb shell stop ; fi
2145 echo "Pushing: $TARGET"
2146 adb push $FILE $TARGET
2147 if $stop_n_start ; then adb shell start ; fi
2153 echo "The connected device does not appear to be $CM_BUILD, run away!"
2157 alias mmp='dopush mm'
2158 alias mmmp='dopush mmm'
2159 alias mkap='dopush mka'
2160 alias cmkap='dopush cmka'
2162 # Force JAVA_HOME to point to java 1.7/1.8 if it isn't already set.
2163 function set_java_home() {
2164 # Clear the existing JAVA_HOME value if we set it ourselves, so that
2165 # we can reset it later, depending on the version of java the build
2168 # If we don't do this, the JAVA_HOME value set by the first call to
2169 # build/envsetup.sh will persist forever.
2170 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2174 if [ ! "$JAVA_HOME" ]; then
2175 if [ -n "$LEGACY_USE_JAVA7" ]; then
2176 echo Warning: Support for JDK 7 will be dropped. Switch to JDK 8.
2179 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2182 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2188 export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
2191 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
2196 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2197 # we can change it on the next envsetup.sh, if required.
2198 export ANDROID_SET_JAVA_HOME=true
2202 # Print colored exit condition
2206 if [ $retval -ne 0 ]
2208 echo $'\E'"[0;31mFAILURE\e[00m"
2210 echo $'\E'"[0;32mSUCCESS\e[00m"
2215 function get_make_command()
2222 local start_time=$(date +"%s")
2223 $(get_make_command) "$@"
2225 local end_time=$(date +"%s")
2226 local tdiff=$(($end_time-$start_time))
2227 local hours=$(($tdiff / 3600 ))
2228 local mins=$((($tdiff % 3600) / 60))
2229 local secs=$(($tdiff % 60))
2230 local ncolors=$(tput colors 2>/dev/null)
2231 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2232 color_failed=$'\E'"[0;31m"
2233 color_success=$'\E'"[0;32m"
2234 color_reset=$'\E'"[00m"
2241 if [ $ret -eq 0 ] ; then
2242 echo -n "${color_success}#### make completed successfully "
2244 echo -n "${color_failed}#### make failed to build some targets "
2246 if [ $hours -gt 0 ] ; then
2247 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2248 elif [ $mins -gt 0 ] ; then
2249 printf "(%02g:%02g (mm:ss))" $mins $secs
2250 elif [ $secs -gt 0 ] ; then
2251 printf "(%s seconds)" $secs
2253 echo " ####${color_reset}"
2258 function provision()
2260 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
2261 echo "Couldn't locate output files. Try running 'lunch' first." >&2
2264 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
2265 echo "There is no provisioning script for the device." >&2
2269 # Check if user really wants to do this.
2270 if [ "$1" = "--no-confirmation" ]; then
2273 echo "This action will reflash your device."
2275 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
2277 echo -n "Are you sure you want to do this (yes/no)? "
2279 if [[ "${REPLY}" != "yes" ]] ; then
2280 echo "Not taking any action. Exiting." >&2
2284 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
2287 if [ "x$SHELL" != "x/bin/bash" ]; then
2288 case `ps -o command -p $$` in
2292 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2297 # Execute the contents of any vendorsetup.sh files we can find.
2298 for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2299 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2300 `test -d product && find -L product -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`