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 - cout: Changes directory to out.
8 - m: Makes from the top of the tree.
9 - mm: Builds all of the modules in the current directory, but not their dependencies.
10 - mmm: Builds all of the modules in the supplied directories, but not their dependencies.
11 To limit the modules being built use the syntax: mmm dir/:target1,target2.
12 - mma: Builds all of the modules in the current directory, and their dependencies.
13 - mmma: Builds all of the modules in the supplied directories, and their dependencies.
14 - mmp: Builds all of the modules in the current directory and pushes them to the device.
15 - mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
16 - provision: Flash device with all required partitions. Options will be passed on to fastboot.
17 - cgrep: Greps on all local C/C++ files.
18 - ggrep: Greps on all local Gradle files.
19 - jgrep: Greps on all local Java files.
20 - resgrep: Greps on all local res/*.xml files.
21 - mangrep: Greps on all local AndroidManifest.xml files.
22 - mgrep: Greps on all local Makefiles files.
23 - sepgrep: Greps on all local sepolicy files.
24 - sgrep: Greps on all local source files.
25 - godir: Go to the directory containing a file.
26 - cmremote: Add git remote for CM Gerrit Review
27 - cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
28 - aospremote: Add git remote for matching AOSP repository
29 - cafremote: Add git remote for matching CodeAurora repository.
30 - cmrebase: Rebase a Gerrit change and push it again
31 - mka: Builds using SCHED_BATCH on all processors
32 - mkap: Builds the module(s) using mka and pushes them to the device.
33 - cmka: Cleans and builds using mka.
34 - repolastsync: Prints date and time of last repo sync.
35 - reposync: Parallel repo sync using ionice and SCHED_BATCH
36 - repopick: Utility to fetch changes from Gerrit.
37 - installboot: Installs a boot.img to the connected device.
38 - installrecovery: Installs a recovery.img to the connected device.
39 - repodiff: Diff 2 different branches or tags within the same repo
42 - SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
43 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
44 build is leak-check clean.
46 Look at the source to view more functions. The complete list is:
49 for i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
54 # Get all the build variables needed by this script in a single call to the build system.
55 function build_build_var_cache()
58 # Grep out the variable names from the script.
59 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' ' '`
60 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' ' '`
61 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
62 build_dicts_script=`\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
63 command make --no-print-directory -f build/core/config.mk \
65 DUMP_MANY_VARS="$cached_vars" \
66 DUMP_MANY_ABS_VARS="$cached_abs_vars" \
67 DUMP_VAR_PREFIX="var_cache_" \
68 DUMP_ABS_VAR_PREFIX="abs_var_cache_"`
72 unset build_dicts_script
75 # Excute the script to store the "<val>=<value>" pairs as shell variables.
76 eval "$build_dicts_script"
78 unset build_dicts_script
83 BUILD_VAR_CACHE_READY="true"
86 # Delete the build var cache, so that we can still call into the build system
87 # to get build variables not listed in this script.
88 function destroy_build_var_cache()
90 unset BUILD_VAR_CACHE_READY
91 for v in $cached_vars; do
95 for v in $cached_abs_vars; do
96 unset abs_var_cache_$v
101 # Get the value of a build variable as an absolute path.
102 function get_abs_build_var()
104 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
106 eval echo \"\${abs_var_cache_$1}\"
112 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
115 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
116 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
119 # Get the exact value of a build variable.
120 function get_build_var()
122 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
124 eval echo \"\${var_cache_$1}\"
130 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
133 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
134 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
137 # check to see if the supplied product is one we can build
138 function check_product()
142 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
146 if (echo -n $1 | grep -q -e "^cm_") ; then
147 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
148 export BUILD_NUMBER=$((date +%s%N ; echo $CM_BUILD; hostname) | openssl sha1 | sed -e 's/.*=//g; s/ //g' | cut -c1-10)
155 TARGET_BUILD_VARIANT= \
158 get_build_var TARGET_DEVICE > /dev/null
159 # hide successful answers, but allow the errors to show
162 VARIANT_CHOICES=(user userdebug eng)
164 # check to see if the supplied variant is valid
165 function check_variant()
167 for v in ${VARIANT_CHOICES[@]}
181 echo "Couldn't locate the top of the tree. Try setting TOP."
185 ##################################################################
187 # Read me before you modify this code #
189 # This function sets ANDROID_BUILD_PATHS to what it is adding #
190 # to PATH, and the next time it is run, it removes that from #
191 # PATH. This is required so lunch can be run more than once #
192 # and still have working paths. #
194 ##################################################################
196 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
197 # due to "C:\Program Files" being in the path.
200 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
201 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
203 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
204 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
205 # strip leading ':', if any
206 export PATH=${PATH/:%/}
209 # and in with the new
210 prebuiltdir=$(getprebuilt)
211 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
213 # defined in core/config.mk
214 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
215 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
216 export TARGET_GCC_VERSION=$targetgccversion
218 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
219 export ANDROID_TOOLCHAIN=
220 export ANDROID_TOOLCHAIN_2ND_ARCH=
221 local ARCH=$(get_build_var TARGET_ARCH)
223 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
225 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
227 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
229 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
230 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
232 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
235 echo "Can't find toolchain for unknown architecture: $ARCH"
236 toolchaindir=xxxxxxxxx
239 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
240 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
243 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
244 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
247 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
248 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_DEV_SCRIPTS:
250 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
251 # to ensure that the corresponding 'emulator' binaries are used.
254 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
257 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
260 ANDROID_EMULATOR_PREBUILTS=
263 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
264 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
265 export ANDROID_EMULATOR_PREBUILTS
268 export PATH=$ANDROID_BUILD_PATHS$PATH
269 export PYTHONPATH=$T/development/python-packages:$PYTHONPATH
271 unset ANDROID_JAVA_TOOLCHAIN
272 unset ANDROID_PRE_BUILD_PATHS
273 if [ -n "$JAVA_HOME" ]; then
274 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
275 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
276 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
279 unset ANDROID_PRODUCT_OUT
280 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
281 export OUT=$ANDROID_PRODUCT_OUT
283 unset ANDROID_HOST_OUT
284 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
286 # needed for building linux on MacOS
288 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
291 function printconfig()
295 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
298 get_build_var report_config
301 function set_stuff_for_environment()
308 # With this environment variable new GCC can apply colors to warnings/errors
309 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
310 export ASAN_OPTIONS=detect_leaks=0
313 function set_sequence_number()
315 export BUILD_ENV_SEQUENCE_NUMBER=10
320 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
321 local arch=$(gettargetarch)
322 local product=$TARGET_PRODUCT
323 local variant=$TARGET_BUILD_VARIANT
324 local apps=$TARGET_BUILD_APPS
325 if [ -z "$PROMPT_COMMAND" ]; then
327 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
328 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
329 # Prompts exist, but no hardstatus
330 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
332 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
333 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
336 if [ -z "$apps" ]; then
337 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
339 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
341 export ANDROID_PROMPT_PREFIX
343 # Inject build data into hardstatus
344 export PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/\\033]0;\(.*\)\\007/\\033]0;$ANDROID_PROMPT_PREFIX \1\\007/g')"
348 function check_bash_version()
350 # Keep us from trying to run in something that isn't bash.
351 if [ -z "${BASH_VERSION}" ]; then
355 # Keep us from trying to run in bash that's too old.
356 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
363 function choosetype()
365 echo "Build type choices are:"
370 local DEFAULT_NUM DEFAULT_VALUE
372 DEFAULT_VALUE=release
374 export TARGET_BUILD_TYPE=
376 while [ -z $TARGET_BUILD_TYPE ]
378 echo -n "Which would you like? ["$DEFAULT_NUM"] "
379 if [ -z "$1" ] ; then
387 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
390 export TARGET_BUILD_TYPE=release
393 export TARGET_BUILD_TYPE=release
396 export TARGET_BUILD_TYPE=debug
399 export TARGET_BUILD_TYPE=debug
403 echo "I didn't understand your response. Please try again."
407 if [ -n "$1" ] ; then
412 build_build_var_cache
413 set_stuff_for_environment
414 destroy_build_var_cache
418 # This function isn't really right: It chooses a TARGET_PRODUCT
419 # based on the list of boards. Usually, that gets you something
420 # that kinda works with a generic product, but really, you should
421 # pick a product by name.
423 function chooseproduct()
425 if [ "x$TARGET_PRODUCT" != x ] ; then
426 default_value=$TARGET_PRODUCT
428 default_value=aosp_arm
431 export TARGET_BUILD_APPS=
432 export TARGET_PRODUCT=
434 while [ -z "$TARGET_PRODUCT" ]
436 echo -n "Which product would you like? [$default_value] "
437 if [ -z "$1" ] ; then
444 if [ -z "$ANSWER" ] ; then
445 export TARGET_PRODUCT=$default_value
447 if check_product $ANSWER
449 export TARGET_PRODUCT=$ANSWER
451 echo "** Not a valid product: $ANSWER"
454 if [ -n "$1" ] ; then
459 build_build_var_cache
460 set_stuff_for_environment
461 destroy_build_var_cache
464 function choosevariant()
466 echo "Variant choices are:"
469 for v in ${VARIANT_CHOICES[@]}
471 # The product name is the name of the directory containing
472 # the makefile we found, above.
477 local default_value=eng
480 export TARGET_BUILD_VARIANT=
481 while [ -z "$TARGET_BUILD_VARIANT" ]
483 echo -n "Which would you like? [$default_value] "
484 if [ -z "$1" ] ; then
491 if [ -z "$ANSWER" ] ; then
492 export TARGET_BUILD_VARIANT=$default_value
493 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
494 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
495 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
498 if check_variant $ANSWER
500 export TARGET_BUILD_VARIANT=$ANSWER
502 echo "** Not a valid variant: $ANSWER"
505 if [ -n "$1" ] ; then
511 function choosecombo()
524 build_build_var_cache
525 set_stuff_for_environment
527 destroy_build_var_cache
530 # Clear this variable. It will be built up again when the vendorsetup.sh
531 # files are included at the end of this file.
532 unset LUNCH_MENU_CHOICES
533 function add_lunch_combo()
537 for c in ${LUNCH_MENU_CHOICES[@]} ; do
538 if [ "$new_combo" = "$c" ] ; then
542 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
545 # add the default one here
546 add_lunch_combo aosp_arm-eng
547 add_lunch_combo aosp_arm64-eng
548 add_lunch_combo aosp_mips-eng
549 add_lunch_combo aosp_mips64-eng
550 add_lunch_combo aosp_x86-eng
551 add_lunch_combo aosp_x86_64-eng
553 function print_lunch_menu()
557 echo "You're building on" $uname
558 if [ "$(uname)" = "Darwin" ] ; then
559 echo " (ohai, koush!)"
562 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
563 echo "Breakfast menu... pick a combo:"
565 echo "Lunch menu... pick a combo:"
570 for choice in ${LUNCH_MENU_CHOICES[@]}
576 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
577 echo "... and don't forget the bacon!"
586 if [ $? -eq 0 ]; then
589 echo "No such item in brunch menu. Try 'breakfast'"
599 CM_DEVICES_ONLY="true"
600 unset LUNCH_MENU_CHOICES
601 add_lunch_combo full-eng
602 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
609 if [ $# -eq 0 ]; then
610 # No arguments, so let's have the full menu
613 echo "z$target" | grep -q "-"
614 if [ $? -eq 0 ]; then
615 # A buildtype was specified, assume a full device name
618 # This is probably just the CM model name
619 if [ -z "$variant" ]; then
622 lunch cm_$target-$variant
633 LUNCH_MENU_CHOICES=($(for l in ${LUNCH_MENU_CHOICES[@]}; do echo "$l"; done | sort))
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
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 2>/dev/null
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=$(get_build_var CM_VERSION)
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 getprop ro.cm.device | grep -q "$CM_BUILD");
807 # if adbd isn't root we can't write to /cache/recovery/
811 cat << EOF > /tmp/command
814 if adb push /tmp/command /cache/recovery/ ; then
815 echo "Rebooting into recovery for sideload installation"
817 adb wait-for-sideload
818 adb sideload $ZIPPATH
822 echo "Nothing to eat"
827 echo "The connected device does not appear to be $CM_BUILD, run away!"
839 local TOPFILE=build/core/envsetup.mk
840 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
841 # The following circumlocution ensures we remove symlinks from TOP.
842 (cd $TOP; PWD= /bin/pwd)
844 if [ -f $TOPFILE ] ; then
845 # The following circumlocution (repeated below as well) ensures
846 # that we record the true directory name and not one that is
847 # faked up with symlink names.
852 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
857 if [ -f "$T/$TOPFILE" ]; then
864 # Return driver for "make", if any (eg. static analyzer)
868 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
869 if [ -n "$WITH_STATIC_ANALYZER" ]; then
871 $T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
872 --use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
881 local DRV=$(getdriver $T)
883 $DRV make -C $T -f build/core/main.mk $@
885 echo "Couldn't locate the top of the tree. Try setting TOP."
890 function findmakefile()
892 TOPFILE=build/core/envsetup.mk
895 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
897 if [ -f "$T/Android.mk" ]; then
910 local DRV=$(getdriver $T)
911 # If we're sitting in the root of the build tree, just do a
913 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
916 # Find the closest Android.mk file.
917 local M=$(findmakefile)
919 local GET_INSTALL_PATH=
921 # Remove the path to top as the makefilepath needs to be relative
922 local M=`echo $M|sed 's:'$T'/::'`
924 echo "Couldn't locate the top of the tree. Try setting TOP."
926 elif [ ! "$M" ]; then
927 echo "Couldn't locate a makefile from the current directory."
932 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
935 if [ -n "$GET_INSTALL_PATH" ]; then
937 ARGS=GET-INSTALL-PATH
942 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
950 local DRV=$(getdriver $T)
956 local GET_INSTALL_PATH=
957 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
958 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
959 for DIR in $DIRS ; do
960 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
961 if [ "$MODULES" = "" ]; then
964 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
965 if [ -f $DIR/Android.mk ]; then
966 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
967 local TO_CHOP=`expr $TO_CHOP + 1`
968 local START=`PWD= /bin/pwd`
969 local MFILE=`echo $START | cut -c${TO_CHOP}-`
970 if [ "$MFILE" = "" ] ; then
971 MFILE=$DIR/Android.mk
973 MFILE=$MFILE/$DIR/Android.mk
975 MAKEFILE="$MAKEFILE $MFILE"
978 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
979 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
980 *) if [ -d $DIR ]; then
981 echo "No Android.mk in $DIR.";
983 echo "Couldn't locate the directory $DIR";
989 if [ -n "$GET_INSTALL_PATH" ]; then
990 ARGS=$GET_INSTALL_PATH
993 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
995 echo "Couldn't locate the top of the tree. Try setting TOP."
1003 local DRV=$(getdriver $T)
1004 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
1008 echo "Couldn't locate the top of the tree. Try setting TOP."
1011 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
1012 local MODULES_IN_PATHS=MODULES-IN-$MY_PWD
1013 # Convert "/" to "-".
1014 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
1015 $DRV make -C $T -f build/core/main.mk $@ $MODULES_IN_PATHS
1022 local DRV=$(getdriver $T)
1024 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
1025 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
1026 local MY_PWD=`PWD= /bin/pwd`
1027 if [ "$MY_PWD" = "$T" ]; then
1030 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
1033 local MODULES_IN_PATHS=
1035 for DIR in $DIRS ; do
1036 if [ -d $DIR ]; then
1037 # Remove the leading ./ and trailing / if any exists.
1040 if [ "$MY_PWD" != "" ]; then
1043 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
1046 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
1047 *) echo "Couldn't find directory $DIR"; return 1;;
1051 # Convert "/" to "-".
1052 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
1053 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS $MODULES_IN_PATHS
1055 echo "Couldn't locate the top of the tree. Try setting TOP."
1066 echo "Couldn't locate the top of the tree. Try setting TOP."
1075 echo "Couldn't locate out directory. Try setting OUT."
1081 TOPFILE=build/core/envsetup.mk
1084 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1086 if [ -f "$T/Android.mk" ]; then
1093 echo "can't find Android.mk"
1096 # simplified version of ps; output in the form
1101 if [ "$1" = "--exact" ]; then
1105 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1106 echo "usage: qpid [[--exact] <process name|pid>"
1111 if [ "$EXE" ] ; then
1112 qpid | \grep "$prepend$EXE$append"
1116 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1124 if [ "$1" = "--exact" ]; then
1130 if [ "$EXE" ] ; then
1131 local PID=`adb shell ps \
1133 | \grep "$prepend$EXE$append" \
1134 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1137 echo "usage: pid [--exact] <process name>"
1142 # coredump_setup - enable core dumps globally for any process
1143 # that has the core-file-size limit set correctly
1145 # NOTE: You must call also coredump_enable for a specific process
1146 # if its core-file-size limit is not set already.
1147 # NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1149 function coredump_setup()
1151 echo "Getting root...";
1153 adb wait-for-device;
1155 echo "Remounting root partition read-write...";
1156 adb shell mount -w -o remount -t rootfs rootfs;
1158 adb wait-for-device;
1159 adb shell mkdir -p /cores;
1160 adb shell mount -t tmpfs tmpfs /cores;
1161 adb shell chmod 0777 /cores;
1163 echo "Granting SELinux permission to dump in /cores...";
1164 adb shell restorecon -R /cores;
1166 echo "Set core pattern.";
1167 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1172 # coredump_enable - enable core dumps for the specified process
1173 # $1 = PID of process (e.g., $(pid mediaserver))
1175 # NOTE: coredump_setup must have been called as well for a core
1176 # dump to actually be generated.
1178 function coredump_enable()
1181 if [ -z "$PID" ]; then
1182 printf "Expecting a PID!\n";
1185 echo "Setting core limit for $PID to infinite...";
1186 adb shell prlimit $PID 4 -1 -1
1189 # core - send SIGV and pull the core for process
1190 # $1 = PID of process (e.g., $(pid mediaserver))
1192 # NOTE: coredump_setup must be called once per boot for core dumps to be
1199 if [ -z "$PID" ]; then
1200 printf "Expecting a PID!\n";
1204 local CORENAME=core.$PID;
1205 local COREPATH=/cores/$CORENAME;
1211 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1212 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1213 adb shell kill -$SIG $PID;
1217 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1218 echo "Done: core is under $COREPATH on device.";
1221 # systemstack - dump the current stack trace of all threads in the system process
1222 # to the usual ANR traces file
1223 function systemstack()
1225 stacks system_server
1230 if [[ $1 =~ ^[0-9]+$ ]] ; then
1232 elif [ "$1" ] ; then
1233 local PIDLIST="$(pid $1)"
1234 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1235 local PID="$PIDLIST"
1236 elif [ "$PIDLIST" ] ; then
1237 echo "more than one process: $1"
1239 echo "no such process: $1"
1242 echo "usage: stacks [pid|process name]"
1245 if [ "$PID" ] ; then
1246 # Determine whether the process is native
1247 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1248 # Dump stacks of Dalvik process
1249 local TRACES=/data/anr/traces.txt
1250 local ORIG=/data/anr/traces.orig
1251 local TMP=/data/anr/traces.tmp
1253 # Keep original traces to avoid clobbering
1254 adb shell mv $TRACES $ORIG
1256 # Make sure we have a usable file
1257 adb shell touch $TRACES
1258 adb shell chmod 666 $TRACES
1260 # Dump stacks and wait for dump to finish
1261 adb shell kill -3 $PID
1262 adb shell notify $TRACES >/dev/null
1264 # Restore original stacks, and show current output
1265 adb shell mv $TRACES $TMP
1266 adb shell mv $ORIG $TRACES
1269 # Dump stacks of native process
1270 local USE64BIT="$(is64bit $PID)"
1271 adb shell debuggerd$USE64BIT -b $PID
1276 # Read the ELF header from /proc/$PID/exe to determine if the process is
1281 if [ "$PID" ] ; then
1282 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
1292 function dddclient()
1294 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1295 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1296 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1297 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1298 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1299 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1300 local ARCH=$(get_build_var TARGET_ARCH)
1303 arm) GDB=arm-linux-androideabi-gdb;;
1304 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1305 mips|mips64) GDB=mips64el-linux-android-gdb;;
1306 x86) GDB=x86_64-linux-android-gdb;;
1307 x86_64) GDB=x86_64-linux-android-gdb;;
1308 *) echo "Unknown arch $ARCH"; return 1;;
1311 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1313 if [ "$EXE" ] ; then
1315 if [[ $EXE =~ ^[^/].* ]] ; then
1316 EXE="system/bin/"$EXE
1323 if [ "$PORT" ] ; then
1330 if [ "$PID" ] ; then
1331 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1333 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1334 # that likely didn't work because of returning multiple processes
1335 # try again, filtering by root processes (don't contain colon)
1336 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1337 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1339 echo "Couldn't resolve '$3' to single PID"
1343 echo "WARNING: multiple processes matching '$3' observed, using root process"
1348 adb forward "tcp$PORT" "tcp$PORT"
1349 local USE64BIT="$(is64bit $PID)"
1350 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1354 echo "If you haven't done so already, do this first on the device:"
1355 echo " gdbserver $PORT /system/bin/$EXE"
1357 echo " gdbserver $PORT --attach <PID>"
1361 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1362 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1364 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1365 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl"
1366 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1367 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1368 # Enable special debugging for ART processes.
1369 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1370 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1372 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1376 if [ "$USE64BIT" != "" ] ; then
1377 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1378 # 32-bit exe / 32-bit platform
1379 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1380 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1381 # 32-bit exe / 64-bit platform
1383 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1386 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1388 echo "Unable to determine build system output dir."
1396 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl|vts)' \
1397 -exec grep --color -n "$@" {} +
1404 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\)' \
1405 -exec grep --color -n "$@" {} +
1410 function gettargetarch
1412 get_build_var TARGET_ARCH
1417 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1418 -exec grep --color -n "$@" {} +
1423 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1424 -exec grep --color -n "$@" {} +
1429 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' \) \
1430 -exec grep --color -n "$@" {} +
1435 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1436 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1442 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1443 -exec grep --color -n "$@" {} +
1448 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1449 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
1454 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1455 -exec grep --color -n "$@" {} +
1462 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' \
1463 -exec grep --color -n "$@" {} +
1468 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' \
1469 -exec grep --color -n -i "$@" {} +
1476 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f \
1477 -exec grep --color -n "$@" {} +
1482 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f \
1483 -exec grep --color -n -i "$@" {} +
1489 function getprebuilt
1491 get_abs_build_var ANDROID_PREBUILTS
1494 function tracedmdump()
1498 echo "Couldn't locate the top of the tree. Try setting TOP."
1501 local prebuiltdir=$(getprebuilt)
1502 local arch=$(gettargetarch)
1503 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
1506 if [ ! "$TRACE" ] ; then
1507 echo "usage: tracedmdump tracename"
1511 if [ ! -r "$KERNEL" ] ; then
1512 echo "Error: cannot find kernel: '$KERNEL'"
1516 local BASETRACE=$(basename $TRACE)
1517 if [ "$BASETRACE" = "$TRACE" ] ; then
1518 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1521 echo "post-processing traces..."
1522 rm -f $TRACE/qtrace.dexlist
1524 if [ $? -ne 0 ]; then
1526 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1530 echo "generating dexlist output..."
1531 /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
1532 echo "generating dmtrace data..."
1533 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1534 echo "generating html file..."
1535 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1536 echo "done, see $TRACE/dmtrace.html for details"
1538 echo " traceview $TRACE/dmtrace"
1541 # communicate with a running device or emulator, set up necessary state,
1542 # and run the hat command.
1545 # process standard adb options
1547 if [ "$1" = "-d" -o "$1" = "-e" ]; then
1550 elif [ "$1" = "-s" ]; then
1554 local adbOptions=${adbTarget}
1555 #echo adbOptions = ${adbOptions}
1560 if [ "$targetPid" = "" ]; then
1561 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
1565 # confirm hat is available
1566 if [ -z $(which hat) ]; then
1567 echo "hat is not available in this configuration."
1571 # issue "am" command to cause the hprof dump
1572 local devFile=/data/local/tmp/hprof-$targetPid
1573 echo "Poking $targetPid and waiting for data..."
1574 echo "Storing data at $devFile"
1575 adb ${adbOptions} shell am dumpheap $targetPid $devFile
1576 echo "Press enter when logcat shows \"hprof: heap dump completed\""
1580 local localFile=/tmp/$$-hprof
1582 echo "Retrieving file $devFile..."
1583 adb ${adbOptions} pull $devFile $localFile
1585 adb ${adbOptions} shell rm $devFile
1587 echo "Running hat on $localFile"
1588 echo "View the output by pointing your browser at http://localhost:7000/"
1590 hat -JXmx512m $localFile
1593 function getbugreports()
1595 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
1597 if [ ! "$reports" ]; then
1598 echo "Could not locate any bugreports."
1603 for report in ${reports[@]}
1605 echo "/sdcard/bugreports/${report}"
1606 adb pull /sdcard/bugreports/${report} ${report}
1611 function getsdcardpath()
1613 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1616 function getscreenshotpath()
1618 echo "$(getsdcardpath)/Pictures/Screenshots"
1621 function getlastscreenshot()
1623 local screenshot_path=$(getscreenshotpath)
1624 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1625 if [ "$screenshot" = "" ]; then
1626 echo "No screenshots found."
1629 echo "${screenshot}"
1630 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1633 function startviewserver()
1636 if [ $# -gt 0 ]; then
1639 adb shell service call window 1 i32 $port
1642 function stopviewserver()
1644 adb shell service call window 2
1647 function isviewserverstarted()
1649 adb shell service call window 3
1654 adb shell input keyevent 3
1659 adb shell input keyevent 4
1664 adb shell input keyevent 82
1667 function smoketest()
1669 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1670 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1675 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1679 (\cd "$T" && mmm tests/SmokeTest) &&
1680 adb uninstall com.android.smoketest > /dev/null &&
1681 adb uninstall com.android.smoketest.tests > /dev/null &&
1682 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1683 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1684 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1687 # simple shortcut to the runtest command
1692 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1695 ("$T"/development/testrunner/runtest.py $@)
1699 if [[ -z "$1" ]]; then
1700 echo "Usage: godir <regex>"
1704 if [ ! "$OUT_DIR" = "" ]; then
1706 FILELIST=$OUT_DIR/filelist
1708 FILELIST=$T/filelist
1710 if [[ ! -f $FILELIST ]]; then
1711 echo -n "Creating index..."
1712 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
1717 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
1718 if [[ ${#lines[@]} = 0 ]]; then
1724 if [[ ${#lines[@]} > 1 ]]; then
1725 while [[ -z "$pathname" ]]; do
1728 for line in ${lines[@]}; do
1729 printf "%6s %s\n" "[$index]" $line
1730 index=$(($index + 1))
1733 echo -n "Select one: "
1736 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1737 echo "Invalid choice"
1740 pathname=${lines[$(($choice-1))]}
1743 pathname=${lines[0]}
1750 git remote rm cmremote 2> /dev/null
1751 GERRIT_REMOTE=$(git config --get remote.github.projectname)
1752 if [ -z "$GERRIT_REMOTE" ]
1754 echo Unable to set up the git remote, are you under a git repo?
1757 CMUSER=$(git config --get review.review.cyanogenmod.org.username)
1760 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
1762 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
1764 echo You can now push to "cmremote".
1767 function aospremote()
1769 git remote rm aosp 2> /dev/null
1772 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1774 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
1775 if (echo $PROJECT | grep -qv "^device")
1779 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1780 echo "Remote 'aosp' created"
1783 function cafremote()
1785 git remote rm caf 2> /dev/null
1788 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1790 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
1791 if (echo $PROJECT | grep -qv "^device")
1795 git remote add caf git://codeaurora.org/$PFX$PROJECT
1796 echo "Remote 'caf' created"
1799 function installboot()
1801 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1803 echo "No recovery.fstab found. Build recovery first."
1806 if [ ! -e "$OUT/boot.img" ];
1808 echo "No boot.img found. Run make bootimage first."
1811 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1812 if [ -z "$PARTITION" ];
1814 # Try for RECOVERY_FSTAB_VERSION = 2
1815 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1816 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1817 if [ -z "$PARTITION" ];
1819 echo "Unable to determine boot partition."
1827 adb wait-for-online shell mount /system 2>&1 > /dev/null
1828 adb wait-for-online remount
1829 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
1831 adb push $OUT/boot.img /cache/
1832 for i in $OUT/system/lib/modules/*;
1834 adb push $i /system/lib/modules/
1836 adb shell dd if=/cache/boot.img of=$PARTITION
1837 adb shell chmod 644 /system/lib/modules/*
1838 echo "Installation complete."
1840 echo "The connected device does not appear to be $CM_BUILD, run away!"
1844 function installrecovery()
1846 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1848 echo "No recovery.fstab found. Build recovery first."
1851 if [ ! -e "$OUT/recovery.img" ];
1853 echo "No recovery.img found. Run make recoveryimage first."
1856 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1857 if [ -z "$PARTITION" ];
1859 # Try for RECOVERY_FSTAB_VERSION = 2
1860 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1861 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1862 if [ -z "$PARTITION" ];
1864 echo "Unable to determine recovery partition."
1872 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1873 adb wait-for-online remount
1874 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
1876 adb push $OUT/recovery.img /cache/
1877 adb shell dd if=/cache/recovery.img of=$PARTITION
1878 echo "Installation complete."
1880 echo "The connected device does not appear to be $CM_BUILD, run away!"
1884 function makerecipe() {
1887 echo "No branch name provided."
1891 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1892 git commit -a -m "$1"
1897 if [ "$REPO_REMOTE" == "github" ]
1901 git push cmremote HEAD:refs/heads/'$1'
1906 function cmgerrit() {
1907 if [ $# -eq 0 ]; then
1911 local user=`git config --get review.review.cyanogenmod.org.username`
1912 local review=`git config --get remote.github.review`
1913 local project=`git config --get remote.github.projectname`
1918 if [ $# -eq 0 ]; then
1921 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1924 fetch Just fetch the change as FETCH_HEAD
1925 help Show this help, or for a specific command
1926 pull Pull a change into current branch
1927 push Push HEAD or a local branch to Gerrit for a specific branch
1929 Any other Git commands that support refname would work as:
1930 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1932 See '$FUNCNAME help COMMAND' for more information on a specific command.
1935 $FUNCNAME checkout -b topic 1234/5
1937 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1938 && git checkout -b topic FETCH_HEAD
1939 will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1940 Patch-set 1 will be fetched if omitted.
1945 __cmg_*) echo "For internal use only." ;;
1947 if [ "$FUNCNAME" = "cmgerrit" ]; then
1948 echo "'$FUNCNAME $1' is deprecated."
1951 help) $FUNCNAME help ;;
1952 fetch|pull) cat <<EOF
1953 usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1956 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1957 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1961 will $1 patch-set 1 of change 1234
1965 usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1968 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1969 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1972 $FUNCNAME push fix6789:gingerbread
1973 will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1974 HEAD will be pushed from local if omitted.
1978 $FUNCNAME __cmg_err_not_supported $1 && return
1980 usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1983 git fetch http://DOMAIN/p/PROJECT \\
1984 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1985 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1991 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1992 local change_id patchset_id hash
2003 hash=$(($change_id % 100))
2005 [0-9]) hash="0$hash" ;;
2007 echo "refs/changes/$hash/$change_id/$patchset_id"
2010 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
2011 $FUNCNAME __cmg_err_not_repo && return 1
2014 git $command $@ http://$review/p/$project \
2015 $($FUNCNAME __cmg_get_ref $change) || return 1
2018 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
2019 $FUNCNAME __cmg_err_not_repo && return 1
2020 if [ -z "$user" ]; then
2021 echo >&2 "Gerrit username not found."
2024 local local_branch remote_branch
2027 local_branch=${1%:*}
2028 remote_branch=${1##*:}
2036 git push $@ ssh://$user@$review:29418/$project \
2037 $local_branch:refs/for/$remote_branch || return 1
2040 if [ "$FUNCNAME" = "cmgerrit" ]; then
2041 echo >&2 "'$FUNCNAME $command' is deprecated."
2045 if [ $# -lt 2 ]; then
2046 echo >&2 "'$FUNCNAME $command' missing argument."
2047 elif [ $2 -eq 0 ]; then
2048 if [ -n "$3" ]; then
2051 echo >&2 "'$FUNCNAME $1' missing argument."
2058 if [ -z "$review" -o -z "$project" ]; then
2059 echo >&2 "Not currently in any reviewable repository."
2064 __cmg_err_not_supported)
2065 $FUNCNAME __cmg_err_no_arg $command $# && return
2067 #TODO: filter more git commands that don't use refname
2068 init|add|rm|mv|status|clone|remote|bisect|config|stash)
2069 echo >&2 "'$FUNCNAME $1' is not supported."
2074 #TODO: other special cases?
2076 $FUNCNAME __cmg_err_not_supported $command && return 1
2077 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
2078 $FUNCNAME __cmg_err_not_repo && return 1
2080 local change pre_args refs_arg post_args
2083 pre_args=${args%%-- *}
2084 post_args="-- ${args#*-- }"
2086 *) pre_args="$args" ;;
2090 if [ ${#args[@]} -gt 0 ]; then
2091 change=${args[${#args[@]}-1]}
2093 if [ ${#args[@]} -gt 1 ]; then
2095 for ((i=1; i<${#args[@]}-1; i++)); do
2096 pre_args="$pre_args ${args[$i]}"
2102 $FUNCNAME help $command
2106 if [ -z "$refs_arg" ]; then
2107 refs_arg="@${change#*@}"
2108 change=${change%%@*}
2112 if [ -z "$refs_arg" ]; then
2113 refs_arg="~${change#*~}"
2114 change=${change%%~*}
2118 if [ -z "$refs_arg" ]; then
2119 refs_arg="^${change#*^}"
2120 change=${change%%^*}
2124 if [ -z "$refs_arg" ]; then
2125 refs_arg=":${change#*:}"
2126 change=${change%%:*}
2132 $FUNCNAME fetch $change \
2133 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2139 function cmrebase() {
2143 local dir="$(gettop)/$repo"
2145 if [ -z $repo ] || [ -z $refs ]; then
2146 echo "CyanogenMod Gerrit Rebase Usage: "
2147 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2148 echo " The patch IDs appear on the Gerrit commands that are offered."
2149 echo " They consist on a series of numbers and slashes, after the text"
2150 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2152 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2157 if [ ! -d $dir ]; then
2158 echo "Directory $dir doesn't exist in tree."
2162 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2163 echo "Starting branch..."
2164 repo start tmprebase .
2165 echo "Bringing it up to date..."
2167 echo "Fetching change..."
2168 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
2169 if [ "$?" != "0" ]; then
2170 echo "Error cherry-picking. Not uploading!"
2175 echo "Cleaning up..."
2176 repo abandon tmprebase .
2183 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2186 mk_timer schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
2192 if [ ! -z "$1" ]; then
2195 bacon|otapackage|systemimage)
2211 function repolastsync() {
2212 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
2213 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
2214 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
2215 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
2218 function reposync() {
2224 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
2229 function repodiff() {
2230 if [ -z "$*" ]; then
2231 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2234 diffopts=$* repo forall -c \
2235 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2238 # Credit for color strip sed: http://goo.gl/BoIcm
2244 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2245 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2246 echo "No device is online. Waiting for one..."
2247 echo "Please connect USB and/or enable USB debugging"
2248 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2251 echo "Device Found."
2254 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD") || [ "$FORCE_PUSH" == "true" ];
2256 # retrieve IP and PORT info if we're using a TCP connection
2257 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2258 | head -1 | awk '{print $1}')
2259 adb root &> /dev/null
2261 if [ -n "$TCPIPPORT" ]
2263 # adb root just killed our connection
2265 adb connect "$TCPIPPORT"
2267 adb wait-for-device &> /dev/null
2269 adb remount &> /dev/null
2272 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
2274 if [ $ret -ne 0 ]; then
2275 rm -f $OUT/.log;return $ret
2279 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)"
2282 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)"
2284 # If any files are going to /data, push an octal file permissions reader to device
2285 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
2286 CHKPERM="/data/local/tmp/chkfileperm.sh"
2291 if [ -e $FILE ]; then
2292 ls -l $FILE | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}' | cut -d ' ' -f1
2295 ) > $OUT/.chkfileperm.sh
2296 echo "Pushing file permissions checker to device"
2297 adb push $OUT/.chkfileperm.sh $CHKPERM
2298 adb shell chmod 755 $CHKPERM
2299 rm -f $OUT/.chkfileperm.sh
2303 for FILE in $LOC; do
2304 # Make sure file is in $OUT/system or $OUT/data
2306 $OUT/system/*|$OUT/data/*)
2307 # Get target file name (i.e. /system/bin/adb)
2308 TARGET=$(echo $FILE | sed "s#$OUT##")
2315 # fs_config only sets permissions and se labels for files pushed to /system
2316 if [ -n "$CHKPERM" ]; then
2317 OLDPERM=$(adb shell $CHKPERM $TARGET)
2318 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
2319 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
2320 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
2322 echo "Pushing: $TARGET"
2323 adb push $FILE $TARGET
2324 if [ -n "$OLDPERM" ]; then
2325 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
2326 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
2327 adb shell chmod "$OLDPERM" $TARGET
2329 echo "$TARGET did not exist previously, you should set file permissions manually"
2331 adb shell restorecon "$TARGET"
2333 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
2334 # Only need to stop services once
2335 if ! $stop_n_start; then
2339 echo "Pushing: $TARGET"
2340 adb push $FILE $TARGET
2343 echo "Pushing: $TARGET"
2344 adb push $FILE $TARGET
2348 if [ -n "$CHKPERM" ]; then
2349 adb shell rm $CHKPERM
2351 if $stop_n_start; then
2357 echo "The connected device does not appear to be $CM_BUILD, run away!"
2361 alias mmp='dopush mm'
2362 alias mmmp='dopush mmm'
2363 alias mkap='dopush mka'
2364 alias cmkap='dopush cmka'
2366 function repopick() {
2368 $T/build/tools/repopick.py $@
2371 function fixup_common_out_dir() {
2372 common_out_dir=$(get_build_var OUT_DIR)/target/common
2373 target_device=$(get_build_var TARGET_DEVICE)
2374 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2375 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2376 mv ${common_out_dir} ${common_out_dir}-${target_device}
2377 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2379 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2380 mkdir -p ${common_out_dir}-${target_device}
2381 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2384 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2385 mkdir -p ${common_out_dir}
2389 # Force JAVA_HOME to point to java 1.7/1.8 if it isn't already set.
2390 function set_java_home() {
2391 # Clear the existing JAVA_HOME value if we set it ourselves, so that
2392 # we can reset it later, depending on the version of java the build
2395 # If we don't do this, the JAVA_HOME value set by the first call to
2396 # build/envsetup.sh will persist forever.
2397 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2401 if [ ! "$JAVA_HOME" ]; then
2402 if [ -n "$LEGACY_USE_JAVA7" ]; then
2403 echo Warning: Support for JDK 7 will be dropped. Switch to JDK 8.
2406 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2409 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2415 export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
2418 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
2423 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2424 # we can change it on the next envsetup.sh, if required.
2425 export ANDROID_SET_JAVA_HOME=true
2429 # Print colored exit condition
2433 if [ $retval -ne 0 ]
2435 echo $'\E'"[0;31mFAILURE\e[00m"
2437 echo $'\E'"[0;32mSUCCESS\e[00m"
2442 function get_make_command()
2449 local start_time=$(date +"%s")
2452 local end_time=$(date +"%s")
2453 local tdiff=$(($end_time-$start_time))
2454 local hours=$(($tdiff / 3600 ))
2455 local mins=$((($tdiff % 3600) / 60))
2456 local secs=$(($tdiff % 60))
2457 local ncolors=$(tput colors 2>/dev/null)
2458 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2459 color_failed=$'\E'"[0;31m"
2460 color_success=$'\E'"[0;32m"
2461 color_reset=$'\E'"[00m"
2468 if [ $ret -eq 0 ] ; then
2469 echo -n "${color_success}#### make completed successfully "
2471 echo -n "${color_failed}#### make failed to build some targets "
2473 if [ $hours -gt 0 ] ; then
2474 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2475 elif [ $mins -gt 0 ] ; then
2476 printf "(%02g:%02g (mm:ss))" $mins $secs
2477 elif [ $secs -gt 0 ] ; then
2478 printf "(%s seconds)" $secs
2480 echo " ####${color_reset}"
2485 function provision()
2487 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
2488 echo "Couldn't locate output files. Try running 'lunch' first." >&2
2491 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
2492 echo "There is no provisioning script for the device." >&2
2496 # Check if user really wants to do this.
2497 if [ "$1" = "--no-confirmation" ]; then
2500 echo "This action will reflash your device."
2502 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
2504 echo -n "Are you sure you want to do this (yes/no)? "
2506 if [[ "${REPLY}" != "yes" ]] ; then
2507 echo "Not taking any action. Exiting." >&2
2511 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
2516 mk_timer $(get_make_command) "$@"
2519 if [ "x$SHELL" != "x/bin/bash" ]; then
2520 case `ps -o command -p $$` in
2526 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
2531 # Execute the contents of any vendorsetup.sh files we can find.
2532 for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2533 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2534 `test -d product && find -L product -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
2542 check_bash_version && {
2543 dirs="sdk/bash_completion vendor/cm/bash_completion"
2544 for dir in $dirs; do
2545 if [ -d ${dir} ]; then
2546 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2554 export ANDROID_BUILD_TOP=$(gettop)