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 - mmap: Builds all of the modules in the current directory, and its dependencies, then pushes the package to the device.
15 - mmp: Builds all of the modules in the current directory and pushes them to the device.
16 - mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
17 - mms: Short circuit builder. Quickly re-build the kernel, rootfs, boot and system images
18 without deep dependencies. Requires the full build to have run before.
19 - provision: Flash device with all required partitions. Options will be passed on to fastboot.
20 - cgrep: Greps on all local C/C++ files.
21 - ggrep: Greps on all local Gradle files.
22 - jgrep: Greps on all local Java files.
23 - resgrep: Greps on all local res/*.xml files.
24 - mangrep: Greps on all local AndroidManifest.xml files.
25 - mgrep: Greps on all local Makefiles files.
26 - sepgrep: Greps on all local sepolicy files.
27 - sgrep: Greps on all local source files.
28 - godir: Go to the directory containing a file.
29 - cmremote: Add git remote for CM Gerrit Review
30 - cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
31 - aospremote: Add git remote for matching AOSP repository
32 - cafremote: Add git remote for matching CodeAurora repository.
33 - cmrebase: Rebase a Gerrit change and push it again
34 - mka: Builds using SCHED_BATCH on all processors
35 - mkap: Builds the module(s) using mka and pushes them to the device.
36 - cmka: Cleans and builds using mka.
37 - repolastsync: Prints date and time of last repo sync.
38 - reposync: Parallel repo sync using ionice and SCHED_BATCH
39 - repopick: Utility to fetch changes from Gerrit.
40 - installboot: Installs a boot.img to the connected device.
41 - installrecovery: Installs a recovery.img to the connected device.
42 - repodiff: Diff 2 different branches or tags within the same repo
45 - SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
46 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
47 build is leak-check clean.
49 Look at the source to view more functions. The complete list is:
52 for i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
57 # Get all the build variables needed by this script in a single call to the build system.
58 function build_build_var_cache()
61 # Grep out the variable names from the script.
62 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' ' '`
63 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' ' '`
64 # Call the build system to dump the "<val>=<value>" pairs as a shell script.
65 build_dicts_script=`\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
66 command make --no-print-directory -f build/core/config.mk \
68 DUMP_MANY_VARS="$cached_vars" \
69 DUMP_MANY_ABS_VARS="$cached_abs_vars" \
70 DUMP_VAR_PREFIX="var_cache_" \
71 DUMP_ABS_VAR_PREFIX="abs_var_cache_"`
75 unset build_dicts_script
78 # Excute the script to store the "<val>=<value>" pairs as shell variables.
79 eval "$build_dicts_script"
81 unset build_dicts_script
86 BUILD_VAR_CACHE_READY="true"
89 # Delete the build var cache, so that we can still call into the build system
90 # to get build variables not listed in this script.
91 function destroy_build_var_cache()
93 unset BUILD_VAR_CACHE_READY
94 for v in $cached_vars; do
98 for v in $cached_abs_vars; do
99 unset abs_var_cache_$v
101 unset cached_abs_vars
104 # Get the value of a build variable as an absolute path.
105 function get_abs_build_var()
107 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
109 eval echo \"\${abs_var_cache_$1}\"
115 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
118 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
119 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
122 # Get the exact value of a build variable.
123 function get_build_var()
125 if [ "$BUILD_VAR_CACHE_READY" = "true" ]
127 eval echo \"\${var_cache_$1}\"
133 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
136 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
137 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
140 # check to see if the supplied product is one we can build
141 function check_product()
145 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
149 if (echo -n $1 | grep -q -e "^cm_") ; then
150 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
151 export BUILD_NUMBER=$((date +%s%N ; echo $CM_BUILD; hostname) | openssl sha1 | sed -e 's/.*=//g; s/ //g' | cut -c1-10)
158 TARGET_BUILD_VARIANT= \
161 get_build_var TARGET_DEVICE > /dev/null
162 # hide successful answers, but allow the errors to show
165 VARIANT_CHOICES=(user userdebug eng)
167 # check to see if the supplied variant is valid
168 function check_variant()
170 for v in ${VARIANT_CHOICES[@]}
184 echo "Couldn't locate the top of the tree. Try setting TOP."
188 ##################################################################
190 # Read me before you modify this code #
192 # This function sets ANDROID_BUILD_PATHS to what it is adding #
193 # to PATH, and the next time it is run, it removes that from #
194 # PATH. This is required so lunch can be run more than once #
195 # and still have working paths. #
197 ##################################################################
199 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
200 # due to "C:\Program Files" being in the path.
203 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
204 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
206 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
207 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
208 # strip leading ':', if any
209 export PATH=${PATH/:%/}
212 # and in with the new
213 prebuiltdir=$(getprebuilt)
214 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
216 # defined in core/config.mk
217 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
218 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
219 export TARGET_GCC_VERSION=$targetgccversion
221 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
222 export ANDROID_TOOLCHAIN=
223 export ANDROID_TOOLCHAIN_2ND_ARCH=
224 local ARCH=$(get_build_var TARGET_ARCH)
226 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
228 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
230 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
232 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
233 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
235 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
238 echo "Can't find toolchain for unknown architecture: $ARCH"
239 toolchaindir=xxxxxxxxx
242 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
243 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
246 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
247 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
250 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
251 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_DEV_SCRIPTS:
253 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
254 # to ensure that the corresponding 'emulator' binaries are used.
257 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
260 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
263 ANDROID_EMULATOR_PREBUILTS=
266 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
267 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
268 export ANDROID_EMULATOR_PREBUILTS
271 export PATH=$ANDROID_BUILD_PATHS$PATH
272 export PYTHONPATH=$T/development/python-packages:$PYTHONPATH
274 unset ANDROID_JAVA_TOOLCHAIN
275 unset ANDROID_PRE_BUILD_PATHS
276 if [ -n "$JAVA_HOME" ]; then
277 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
278 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
279 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
282 unset ANDROID_PRODUCT_OUT
283 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
284 export OUT=$ANDROID_PRODUCT_OUT
286 unset ANDROID_HOST_OUT
287 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
289 if [ -n "$ANDROID_CCACHE_DIR" ]; then
290 export CCACHE_DIR=$ANDROID_CCACHE_DIR
293 # needed for building linux on MacOS
295 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
298 function printconfig()
302 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
305 get_build_var report_config
308 function set_stuff_for_environment()
315 # With this environment variable new GCC can apply colors to warnings/errors
316 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
317 export ASAN_OPTIONS=detect_leaks=0
320 function set_sequence_number()
322 export BUILD_ENV_SEQUENCE_NUMBER=10
327 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
328 local arch=$(gettargetarch)
329 local product=$TARGET_PRODUCT
330 local variant=$TARGET_BUILD_VARIANT
331 local apps=$TARGET_BUILD_APPS
332 if [ -z "$PROMPT_COMMAND" ]; then
334 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
335 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
336 # Prompts exist, but no hardstatus
337 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
339 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
340 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
343 if [ -z "$apps" ]; then
344 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
346 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
348 export ANDROID_PROMPT_PREFIX
350 # Inject build data into hardstatus
351 export PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/\\033]0;\(.*\)\\007/\\033]0;$ANDROID_PROMPT_PREFIX \1\\007/g')"
355 function check_bash_version()
357 # Keep us from trying to run in something that isn't bash.
358 if [ -z "${BASH_VERSION}" ]; then
362 # Keep us from trying to run in bash that's too old.
363 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
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'"
606 CM_DEVICES_ONLY="true"
607 unset LUNCH_MENU_CHOICES
608 add_lunch_combo full-eng
609 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
616 if [ $# -eq 0 ]; then
617 # No arguments, so let's have the full menu
620 echo "z$target" | grep -q "-"
621 if [ $? -eq 0 ]; then
622 # A buildtype was specified, assume a full device name
625 # This is probably just the CM model name
626 if [ -z "$variant" ]; then
629 lunch cm_$target-$variant
640 LUNCH_MENU_CHOICES=($(for l in ${LUNCH_MENU_CHOICES[@]}; do echo "$l"; done | sort))
646 echo -n "Which would you like? [aosp_arm-eng] "
654 selection=aosp_arm-eng
655 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
657 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
659 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
661 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
666 if [ -z "$selection" ]
669 echo "Invalid lunch combo: $answer"
673 export TARGET_BUILD_APPS=
675 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
676 check_variant $variant
680 echo "** Invalid variant: '$variant'"
681 echo "** Must be one of ${VARIANT_CHOICES[@]}"
685 local product=$(echo -n $selection | sed -e "s/-.*$//")
686 TARGET_PRODUCT=$product \
687 TARGET_BUILD_VARIANT=$variant \
688 build_build_var_cache
691 # if we can't find a product, try to grab it off the CM github
694 build/tools/roomservice.py $product
696 check_product $product
698 build/tools/roomservice.py $product true
703 echo "** Don't have a product spec for: '$product'"
704 echo "** Do you have the right repo manifest?"
708 if [ -z "$product" -o -z "$variant" ]
714 export TARGET_PRODUCT=$product
715 export TARGET_BUILD_VARIANT=$variant
716 export TARGET_BUILD_TYPE=release
722 set_stuff_for_environment
724 destroy_build_var_cache
727 # Tab completion for lunch.
732 cur="${COMP_WORDS[COMP_CWORD]}"
733 prev="${COMP_WORDS[COMP_CWORD-1]}"
735 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
738 complete -F _lunch lunch 2>/dev/null
740 # Configures the build to build unbundled apps.
741 # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
744 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
745 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
746 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
747 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)"
749 if [ $(echo $arch | wc -w) -gt 1 ]; then
750 echo "tapas: Error: Multiple build archs supplied: $arch"
753 if [ $(echo $variant | wc -w) -gt 1 ]; then
754 echo "tapas: Error: Multiple build variants supplied: $variant"
757 if [ $(echo $density | wc -w) -gt 1 ]; then
758 echo "tapas: Error: Multiple densities supplied: $density"
762 local product=aosp_arm
764 x86) product=aosp_x86;;
765 mips) product=aosp_mips;;
766 armv5) product=generic_armv5;;
767 arm64) product=aosp_arm64;;
768 x86_64) product=aosp_x86_64;;
769 mips64) product=aosp_mips64;;
771 if [ -z "$variant" ]; then
774 if [ -z "$apps" ]; then
777 if [ -z "$density" ]; then
781 export TARGET_PRODUCT=$product
782 export TARGET_BUILD_VARIANT=$variant
783 export TARGET_BUILD_DENSITY=$density
784 export TARGET_BUILD_TYPE=release
785 export TARGET_BUILD_APPS=$apps
787 build_build_var_cache
788 set_stuff_for_environment
790 destroy_build_var_cache
796 MODVERSION=$(get_build_var CM_VERSION)
797 ZIPFILE=cm-$MODVERSION.zip
798 ZIPPATH=$OUT/$ZIPFILE
799 if [ ! -f $ZIPPATH ] ; then
800 echo "Nothing to eat"
803 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
804 if [ $(adb get-state) != device -a $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
805 echo "No device is online. Waiting for one..."
806 echo "Please connect USB and/or enable USB debugging"
807 until [ $(adb get-state) = device -o $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
810 echo "Device Found.."
812 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
814 # if adbd isn't root we can't write to /cache/recovery/
818 cat << EOF > /tmp/command
819 --sideload_auto_reboot
821 if adb push /tmp/command /cache/recovery/ ; then
822 echo "Rebooting into recovery for sideload installation"
824 adb wait-for-sideload
825 adb sideload $ZIPPATH
829 echo "Nothing to eat"
834 echo "The connected device does not appear to be $CM_BUILD, run away!"
846 local TOPFILE=build/core/envsetup.mk
847 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
848 # The following circumlocution ensures we remove symlinks from TOP.
849 (cd $TOP; PWD= /bin/pwd)
851 if [ -f $TOPFILE ] ; then
852 # The following circumlocution (repeated below as well) ensures
853 # that we record the true directory name and not one that is
854 # faked up with symlink names.
859 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
864 if [ -f "$T/$TOPFILE" ]; then
871 # Return driver for "make", if any (eg. static analyzer)
875 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
876 if [ -n "$WITH_STATIC_ANALYZER" ]; then
878 $T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
879 --use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
888 local DRV=$(getdriver $T)
890 $DRV make -C $T -f build/core/main.mk $@
892 echo "Couldn't locate the top of the tree. Try setting TOP."
897 function findmakefile()
899 TOPFILE=build/core/envsetup.mk
902 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
904 if [ -f "$T/Android.mk" ]; then
917 local DRV=$(getdriver $T)
918 # If we're sitting in the root of the build tree, just do a
920 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
923 # Find the closest Android.mk file.
924 local M=$(findmakefile)
926 local GET_INSTALL_PATH=
927 # Remove the path to top as the makefilepath needs to be relative
928 local M=`echo $M|sed 's:'$T'/::'`
930 echo "Couldn't locate the top of the tree. Try setting TOP."
932 elif [ ! "$M" ]; then
933 echo "Couldn't locate a makefile from the current directory."
938 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
941 if [ -n "$GET_INSTALL_PATH" ]; then
943 # set all args to 'GET-INSTALL-PATH'
944 set -- GET-INSTALL-PATH
948 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES "$@"
956 local DRV=$(getdriver $T)
962 local GET_INSTALL_PATH=
964 if [ "$(__detect_shell)" = "zsh" ]; then
965 set -lA DASH_ARGS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
966 set -lA DIRS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
968 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
969 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
972 for DIR in $DIRS ; do
973 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
974 if [ "$MODULES" = "" ]; then
977 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
978 if [ -f $DIR/Android.mk ]; then
979 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
980 local TO_CHOP=`expr $TO_CHOP + 1`
981 local START=`PWD= /bin/pwd`
982 local MFILE=`echo $START | cut -c${TO_CHOP}-`
983 if [ "$MFILE" = "" ] ; then
984 MFILE=$DIR/Android.mk
986 MFILE=$MFILE/$DIR/Android.mk
988 MAKEFILE="$MAKEFILE $MFILE"
991 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
992 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
993 *) if [ -d $DIR ]; then
994 echo "No Android.mk in $DIR.";
996 echo "Couldn't locate the directory $DIR";
1002 if [ -n "$GET_INSTALL_PATH" ]; then
1003 ARGS=$GET_INSTALL_PATH
1006 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
1008 echo "Couldn't locate the top of the tree. Try setting TOP."
1016 local DRV=$(getdriver $T)
1017 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
1021 echo "Couldn't locate the top of the tree. Try setting TOP."
1024 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
1025 local MODULES_IN_PATHS=MODULES-IN-$MY_PWD
1026 # Convert "/" to "-".
1027 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
1028 $DRV make -C $T -f build/core/main.mk $@ $MODULES_IN_PATHS
1035 local DRV=$(getdriver $T)
1037 if [ "$(__detect_shell)" = "zsh" ]; then
1038 set -lA DASH_ARGS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
1039 set -lA DIRS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
1041 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
1042 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
1044 local MY_PWD=`PWD= /bin/pwd`
1045 if [ "$MY_PWD" = "$T" ]; then
1048 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
1051 local MODULES_IN_PATHS=
1053 for DIR in $DIRS ; do
1054 if [ -d $DIR ]; then
1055 # Remove the leading ./ and trailing / if any exists.
1058 if [ "$MY_PWD" != "" ]; then
1061 MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR"
1064 showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";;
1065 *) echo "Couldn't find directory $DIR"; return 1;;
1069 # Convert "/" to "-".
1070 MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-}
1071 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS $MODULES_IN_PATHS
1073 echo "Couldn't locate the top of the tree. Try setting TOP."
1084 echo "Couldn't locate the top of the tree. Try setting TOP."
1093 echo "Couldn't locate out directory. Try setting OUT."
1099 TOPFILE=build/core/envsetup.mk
1102 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1104 if [ -f "$T/Android.mk" ]; then
1111 echo "can't find Android.mk"
1114 # simplified version of ps; output in the form
1119 if [ "$1" = "--exact" ]; then
1123 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1124 echo "usage: qpid [[--exact] <process name|pid>"
1129 if [ "$EXE" ] ; then
1130 qpid | \grep "$prepend$EXE$append"
1134 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1142 if [ "$1" = "--exact" ]; then
1148 if [ "$EXE" ] ; then
1149 local PID=`adb shell ps \
1151 | \grep "$prepend$EXE$append" \
1152 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1155 echo "usage: pid [--exact] <process name>"
1160 # coredump_setup - enable core dumps globally for any process
1161 # that has the core-file-size limit set correctly
1163 # NOTE: You must call also coredump_enable for a specific process
1164 # if its core-file-size limit is not set already.
1165 # NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1167 function coredump_setup()
1169 echo "Getting root...";
1171 adb wait-for-device;
1173 echo "Remounting root partition read-write...";
1174 adb shell mount -w -o remount -t rootfs rootfs;
1176 adb wait-for-device;
1177 adb shell mkdir -p /cores;
1178 adb shell mount -t tmpfs tmpfs /cores;
1179 adb shell chmod 0777 /cores;
1181 echo "Granting SELinux permission to dump in /cores...";
1182 adb shell restorecon -R /cores;
1184 echo "Set core pattern.";
1185 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1190 # coredump_enable - enable core dumps for the specified process
1191 # $1 = PID of process (e.g., $(pid mediaserver))
1193 # NOTE: coredump_setup must have been called as well for a core
1194 # dump to actually be generated.
1196 function coredump_enable()
1199 if [ -z "$PID" ]; then
1200 printf "Expecting a PID!\n";
1203 echo "Setting core limit for $PID to infinite...";
1204 adb shell prlimit $PID 4 -1 -1
1207 # core - send SIGV and pull the core for process
1208 # $1 = PID of process (e.g., $(pid mediaserver))
1210 # NOTE: coredump_setup must be called once per boot for core dumps to be
1217 if [ -z "$PID" ]; then
1218 printf "Expecting a PID!\n";
1222 local CORENAME=core.$PID;
1223 local COREPATH=/cores/$CORENAME;
1229 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1230 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1231 adb shell kill -$SIG $PID;
1235 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1236 echo "Done: core is under $COREPATH on device.";
1239 # systemstack - dump the current stack trace of all threads in the system process
1240 # to the usual ANR traces file
1241 function systemstack()
1243 stacks system_server
1248 if [[ $1 =~ ^[0-9]+$ ]] ; then
1250 elif [ "$1" ] ; then
1251 local PIDLIST="$(pid $1)"
1252 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1253 local PID="$PIDLIST"
1254 elif [ "$PIDLIST" ] ; then
1255 echo "more than one process: $1"
1257 echo "no such process: $1"
1260 echo "usage: stacks [pid|process name]"
1263 if [ "$PID" ] ; then
1264 # Determine whether the process is native
1265 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1266 # Dump stacks of Dalvik process
1267 local TRACES=/data/anr/traces.txt
1268 local ORIG=/data/anr/traces.orig
1269 local TMP=/data/anr/traces.tmp
1271 # Keep original traces to avoid clobbering
1272 adb shell mv $TRACES $ORIG
1274 # Make sure we have a usable file
1275 adb shell touch $TRACES
1276 adb shell chmod 666 $TRACES
1278 # Dump stacks and wait for dump to finish
1279 adb shell kill -3 $PID
1280 adb shell notify $TRACES >/dev/null
1282 # Restore original stacks, and show current output
1283 adb shell mv $TRACES $TMP
1284 adb shell mv $ORIG $TRACES
1287 # Dump stacks of native process
1288 local USE64BIT="$(is64bit $PID)"
1289 adb shell debuggerd$USE64BIT -b $PID
1294 # Read the ELF header from /proc/$PID/exe to determine if the process is
1299 if [ "$PID" ] ; then
1300 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
1310 function dddclient()
1312 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1313 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1314 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1315 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1316 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1317 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1318 local ARCH=$(get_build_var TARGET_ARCH)
1321 arm) GDB=arm-linux-androideabi-gdb;;
1322 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1323 mips|mips64) GDB=mips64el-linux-android-gdb;;
1324 x86) GDB=x86_64-linux-android-gdb;;
1325 x86_64) GDB=x86_64-linux-android-gdb;;
1326 *) echo "Unknown arch $ARCH"; return 1;;
1329 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1331 if [ "$EXE" ] ; then
1333 if [[ $EXE =~ ^[^/].* ]] ; then
1334 EXE="system/bin/"$EXE
1341 if [ "$PORT" ] ; then
1348 if [ "$PID" ] ; then
1349 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1351 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1352 # that likely didn't work because of returning multiple processes
1353 # try again, filtering by root processes (don't contain colon)
1354 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1355 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1357 echo "Couldn't resolve '$3' to single PID"
1361 echo "WARNING: multiple processes matching '$3' observed, using root process"
1366 adb forward "tcp$PORT" "tcp$PORT"
1367 local USE64BIT="$(is64bit $PID)"
1368 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1372 echo "If you haven't done so already, do this first on the device:"
1373 echo " gdbserver $PORT /system/bin/$EXE"
1375 echo " gdbserver $PORT --attach <PID>"
1379 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1380 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1382 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1383 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"
1384 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1385 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1386 # Enable special debugging for ART processes.
1387 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1388 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1390 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1394 if [ "$USE64BIT" != "" ] ; then
1395 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1396 # 32-bit exe / 32-bit platform
1397 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1398 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1399 # 32-bit exe / 64-bit platform
1401 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1404 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1406 echo "Unable to determine build system output dir."
1414 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl|vts)' \
1415 -exec grep --color -n "$@" {} +
1422 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\)' \
1423 -exec grep --color -n "$@" {} +
1428 function gettargetarch
1430 get_build_var TARGET_ARCH
1435 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
1436 -exec grep --color -n "$@" {} +
1441 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
1442 -exec grep --color -n "$@" {} +
1447 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' \) \
1448 -exec grep --color -n "$@" {} +
1453 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
1454 find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
1460 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
1461 -exec grep --color -n "$@" {} +
1466 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
1467 -exec grep --color -n -r --exclude-dir=\.git "$@" {} +
1472 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
1473 -exec grep --color -n "$@" {} +
1480 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' \
1481 -exec grep --color -n "$@" {} +
1486 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' \
1487 -exec grep --color -n -i "$@" {} +
1494 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f \
1495 -exec grep --color -n "$@" {} +
1500 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f \
1501 -exec grep --color -n -i "$@" {} +
1507 function getprebuilt
1509 get_abs_build_var ANDROID_PREBUILTS
1512 function tracedmdump()
1516 echo "Couldn't locate the top of the tree. Try setting TOP."
1519 local prebuiltdir=$(getprebuilt)
1520 local arch=$(gettargetarch)
1521 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
1524 if [ ! "$TRACE" ] ; then
1525 echo "usage: tracedmdump tracename"
1529 if [ ! -r "$KERNEL" ] ; then
1530 echo "Error: cannot find kernel: '$KERNEL'"
1534 local BASETRACE=$(basename $TRACE)
1535 if [ "$BASETRACE" = "$TRACE" ] ; then
1536 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1539 echo "post-processing traces..."
1540 rm -f $TRACE/qtrace.dexlist
1542 if [ $? -ne 0 ]; then
1544 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1548 echo "generating dexlist output..."
1549 /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
1550 echo "generating dmtrace data..."
1551 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1552 echo "generating html file..."
1553 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1554 echo "done, see $TRACE/dmtrace.html for details"
1556 echo " traceview $TRACE/dmtrace"
1559 # communicate with a running device or emulator, set up necessary state,
1560 # and run the hat command.
1563 # process standard adb options
1565 if [ "$1" = "-d" -o "$1" = "-e" ]; then
1568 elif [ "$1" = "-s" ]; then
1572 local adbOptions=${adbTarget}
1573 #echo adbOptions = ${adbOptions}
1578 if [ "$targetPid" = "" ]; then
1579 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
1583 # confirm hat is available
1584 if [ -z $(which hat) ]; then
1585 echo "hat is not available in this configuration."
1589 # issue "am" command to cause the hprof dump
1590 local devFile=/data/local/tmp/hprof-$targetPid
1591 echo "Poking $targetPid and waiting for data..."
1592 echo "Storing data at $devFile"
1593 adb ${adbOptions} shell am dumpheap $targetPid $devFile
1594 echo "Press enter when logcat shows \"hprof: heap dump completed\""
1598 local localFile=/tmp/$$-hprof
1600 echo "Retrieving file $devFile..."
1601 adb ${adbOptions} pull $devFile $localFile
1603 adb ${adbOptions} shell rm $devFile
1605 echo "Running hat on $localFile"
1606 echo "View the output by pointing your browser at http://localhost:7000/"
1608 hat -JXmx512m $localFile
1611 function getbugreports()
1613 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
1615 if [ ! "$reports" ]; then
1616 echo "Could not locate any bugreports."
1621 for report in ${reports[@]}
1623 echo "/sdcard/bugreports/${report}"
1624 adb pull /sdcard/bugreports/${report} ${report}
1629 function getsdcardpath()
1631 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1634 function getscreenshotpath()
1636 echo "$(getsdcardpath)/Pictures/Screenshots"
1639 function getlastscreenshot()
1641 local screenshot_path=$(getscreenshotpath)
1642 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1643 if [ "$screenshot" = "" ]; then
1644 echo "No screenshots found."
1647 echo "${screenshot}"
1648 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1651 function startviewserver()
1654 if [ $# -gt 0 ]; then
1657 adb shell service call window 1 i32 $port
1660 function stopviewserver()
1662 adb shell service call window 2
1665 function isviewserverstarted()
1667 adb shell service call window 3
1672 adb shell input keyevent 3
1677 adb shell input keyevent 4
1682 adb shell input keyevent 82
1685 function smoketest()
1687 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1688 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1693 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1697 (\cd "$T" && mmm tests/SmokeTest) &&
1698 adb uninstall com.android.smoketest > /dev/null &&
1699 adb uninstall com.android.smoketest.tests > /dev/null &&
1700 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1701 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1702 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1705 # simple shortcut to the runtest command
1710 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1713 ("$T"/development/testrunner/runtest.py $@)
1717 if [[ -z "$1" ]]; then
1718 echo "Usage: godir <regex>"
1722 if [ ! "$OUT_DIR" = "" ]; then
1724 FILELIST=$OUT_DIR/filelist
1726 FILELIST=$T/filelist
1728 if [[ ! -f $FILELIST ]]; then
1729 echo -n "Creating index..."
1730 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
1735 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
1736 if [[ ${#lines[@]} = 0 ]]; then
1742 if [[ ${#lines[@]} > 1 ]]; then
1743 while [[ -z "$pathname" ]]; do
1746 for line in ${lines[@]}; do
1747 printf "%6s %s\n" "[$index]" $line
1748 index=$(($index + 1))
1751 echo -n "Select one: "
1754 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1755 echo "Invalid choice"
1758 pathname=${lines[$(($choice-1))]}
1761 pathname=${lines[0]}
1768 git remote rm cmremote 2> /dev/null
1769 GERRIT_REMOTE=$(git config --get remote.github.projectname)
1770 if [ -z "$GERRIT_REMOTE" ]
1772 echo Unable to set up the git remote, are you under a git repo?
1775 CMUSER=$(git config --get review.review.cyanogenmod.org.username)
1778 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
1780 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
1782 echo You can now push to "cmremote".
1785 function aospremote()
1787 git remote rm aosp 2> /dev/null
1790 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1792 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
1793 if (echo $PROJECT | grep -qv "^device")
1797 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1798 echo "Remote 'aosp' created"
1801 function cafremote()
1803 git remote rm caf 2> /dev/null
1806 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1808 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
1809 if (echo $PROJECT | grep -qv "^device")
1813 git remote add caf git://codeaurora.org/$PFX$PROJECT
1814 echo "Remote 'caf' created"
1817 function installboot()
1819 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1821 echo "No recovery.fstab found. Build recovery first."
1824 if [ ! -e "$OUT/boot.img" ];
1826 echo "No boot.img found. Run make bootimage first."
1829 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1830 if [ -z "$PARTITION" ];
1832 # Try for RECOVERY_FSTAB_VERSION = 2
1833 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1834 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1835 if [ -z "$PARTITION" ];
1837 echo "Unable to determine boot partition."
1845 adb wait-for-online shell mount /system 2>&1 > /dev/null
1846 adb wait-for-online remount
1847 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
1849 adb push $OUT/boot.img /cache/
1850 for i in $OUT/system/lib/modules/*;
1852 adb push $i /system/lib/modules/
1854 adb shell dd if=/cache/boot.img of=$PARTITION
1855 adb shell chmod 644 /system/lib/modules/*
1856 echo "Installation complete."
1858 echo "The connected device does not appear to be $CM_BUILD, run away!"
1862 function installrecovery()
1864 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1866 echo "No recovery.fstab found. Build recovery first."
1869 if [ ! -e "$OUT/recovery.img" ];
1871 echo "No recovery.img found. Run make recoveryimage first."
1874 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1875 if [ -z "$PARTITION" ];
1877 # Try for RECOVERY_FSTAB_VERSION = 2
1878 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1879 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1880 if [ -z "$PARTITION" ];
1882 echo "Unable to determine recovery partition."
1890 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1891 adb wait-for-online remount
1892 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
1894 adb push $OUT/recovery.img /cache/
1895 adb shell dd if=/cache/recovery.img of=$PARTITION
1896 echo "Installation complete."
1898 echo "The connected device does not appear to be $CM_BUILD, run away!"
1902 function makerecipe() {
1905 echo "No branch name provided."
1909 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1910 git commit -a -m "$1"
1915 if [ "$REPO_REMOTE" = "github" ]
1919 git push cmremote HEAD:refs/heads/'$1'
1924 function cmgerrit() {
1926 if [ "$(__detect_shell)" = "zsh" ]; then
1927 # zsh does not define FUNCNAME, derive from funcstack
1928 local FUNCNAME=$funcstack[1]
1931 if [ $# -eq 0 ]; then
1935 local user=`git config --get review.review.cyanogenmod.org.username`
1936 local review=`git config --get remote.github.review`
1937 local project=`git config --get remote.github.projectname`
1942 if [ $# -eq 0 ]; then
1945 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1948 fetch Just fetch the change as FETCH_HEAD
1949 help Show this help, or for a specific command
1950 pull Pull a change into current branch
1951 push Push HEAD or a local branch to Gerrit for a specific branch
1953 Any other Git commands that support refname would work as:
1954 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1956 See '$FUNCNAME help COMMAND' for more information on a specific command.
1959 $FUNCNAME checkout -b topic 1234/5
1961 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1962 && git checkout -b topic FETCH_HEAD
1963 will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1964 Patch-set 1 will be fetched if omitted.
1969 __cmg_*) echo "For internal use only." ;;
1971 if [ "$FUNCNAME" = "cmgerrit" ]; then
1972 echo "'$FUNCNAME $1' is deprecated."
1975 help) $FUNCNAME help ;;
1976 fetch|pull) cat <<EOF
1977 usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1980 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1981 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1985 will $1 patch-set 1 of change 1234
1989 usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1992 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1993 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1996 $FUNCNAME push fix6789:gingerbread
1997 will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1998 HEAD will be pushed from local if omitted.
2002 $FUNCNAME __cmg_err_not_supported $1 && return
2004 usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
2007 git fetch http://DOMAIN/p/PROJECT \\
2008 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
2009 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
2015 $FUNCNAME __cmg_err_no_arg $command $# && return 1
2016 local change_id patchset_id hash
2027 hash=$(($change_id % 100))
2029 [0-9]) hash="0$hash" ;;
2031 echo "refs/changes/$hash/$change_id/$patchset_id"
2034 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
2035 $FUNCNAME __cmg_err_not_repo && return 1
2038 git $command $@ http://$review/p/$project \
2039 $($FUNCNAME __cmg_get_ref $change) || return 1
2042 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
2043 $FUNCNAME __cmg_err_not_repo && return 1
2044 if [ -z "$user" ]; then
2045 echo >&2 "Gerrit username not found."
2048 local local_branch remote_branch
2051 local_branch=${1%:*}
2052 remote_branch=${1##*:}
2060 git push $@ ssh://$user@$review:29418/$project \
2061 $local_branch:refs/for/$remote_branch || return 1
2064 if [ "$FUNCNAME" = "cmgerrit" ]; then
2065 echo >&2 "'$FUNCNAME $command' is deprecated."
2069 if [ $# -lt 2 ]; then
2070 echo >&2 "'$FUNCNAME $command' missing argument."
2071 elif [ $2 -eq 0 ]; then
2072 if [ -n "$3" ]; then
2075 echo >&2 "'$FUNCNAME $1' missing argument."
2082 if [ -z "$review" -o -z "$project" ]; then
2083 echo >&2 "Not currently in any reviewable repository."
2088 __cmg_err_not_supported)
2089 $FUNCNAME __cmg_err_no_arg $command $# && return
2091 #TODO: filter more git commands that don't use refname
2092 init|add|rm|mv|status|clone|remote|bisect|config|stash)
2093 echo >&2 "'$FUNCNAME $1' is not supported."
2098 #TODO: other special cases?
2100 $FUNCNAME __cmg_err_not_supported $command && return 1
2101 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
2102 $FUNCNAME __cmg_err_not_repo && return 1
2104 local change pre_args refs_arg post_args
2107 pre_args=${args%%-- *}
2108 post_args="-- ${args#*-- }"
2110 *) pre_args="$args" ;;
2114 if [ ${#args[@]} -gt 0 ]; then
2115 change=${args[${#args[@]}-1]}
2117 if [ ${#args[@]} -gt 1 ]; then
2119 for ((i=1; i<${#args[@]}-1; i++)); do
2120 pre_args="$pre_args ${args[$i]}"
2126 $FUNCNAME help $command
2130 if [ -z "$refs_arg" ]; then
2131 refs_arg="@${change#*@}"
2132 change=${change%%@*}
2136 if [ -z "$refs_arg" ]; then
2137 refs_arg="~${change#*~}"
2138 change=${change%%~*}
2142 if [ -z "$refs_arg" ]; then
2143 refs_arg="^${change#*^}"
2144 change=${change%%^*}
2148 if [ -z "$refs_arg" ]; then
2149 refs_arg=":${change#*:}"
2150 change=${change%%:*}
2156 $FUNCNAME fetch $change \
2157 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2163 function cmrebase() {
2167 local dir="$(gettop)/$repo"
2169 if [ -z $repo ] || [ -z $refs ]; then
2170 echo "CyanogenMod Gerrit Rebase Usage: "
2171 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2172 echo " The patch IDs appear on the Gerrit commands that are offered."
2173 echo " They consist on a series of numbers and slashes, after the text"
2174 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2176 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2181 if [ ! -d $dir ]; then
2182 echo "Directory $dir doesn't exist in tree."
2186 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2187 echo "Starting branch..."
2188 repo start tmprebase .
2189 echo "Bringing it up to date..."
2191 echo "Fetching change..."
2192 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
2193 if [ "$?" != "0" ]; then
2194 echo "Error cherry-picking. Not uploading!"
2199 echo "Cleaning up..."
2200 repo abandon tmprebase .
2209 make -C $T -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2212 mk_timer schedtool -B -n 1 -e ionice -n 1 make -C $T -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
2217 echo "Couldn't locate the top of the tree. Try setting TOP."
2222 if [ ! -z "$1" ]; then
2225 bacon|otapackage|systemimage)
2245 echo "Couldn't locate the top of the tree. Try setting TOP."
2251 local NUM_CPUS=$(sysctl hw.ncpu|cut -d" " -f2)
2252 ONE_SHOT_MAKEFILE="__none__" \
2253 make -C $T -j $NUM_CPUS "$@"
2256 local NUM_CPUS=$(cat /proc/cpuinfo | grep "^processor" | wc -l)
2257 ONE_SHOT_MAKEFILE="__none__" \
2258 mk_timer schedtool -B -n 1 -e ionice -n 1 \
2259 make -C $T -j $NUM_CPUS "$@"
2265 function repolastsync() {
2266 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
2267 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
2268 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
2269 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
2272 function reposync() {
2278 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
2283 function repodiff() {
2284 if [ -z "$*" ]; then
2285 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2288 diffopts=$* repo forall -c \
2289 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2292 # Return success if adb is up and not in recovery
2293 function _adb_connected {
2295 if [[ "$(adb get-state)" == device &&
2296 "$(adb shell test -e /sbin/recovery; echo $?)" == 0 ]]
2305 # Credit for color strip sed: http://goo.gl/BoIcm
2311 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2312 if ! _adb_connected; then
2313 echo "No device is online. Waiting for one..."
2314 echo "Please connect USB and/or enable USB debugging"
2315 until _adb_connected; do
2318 echo "Device Found."
2321 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD") || [ "$FORCE_PUSH" = "true" ];
2323 # retrieve IP and PORT info if we're using a TCP connection
2324 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2325 | head -1 | awk '{print $1}')
2326 adb root &> /dev/null
2328 if [ -n "$TCPIPPORT" ]
2330 # adb root just killed our connection
2332 adb connect "$TCPIPPORT"
2334 adb wait-for-device &> /dev/null
2336 adb remount &> /dev/null
2339 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
2341 if [ $ret -ne 0 ]; then
2342 rm -f $OUT/.log;return $ret
2346 if [ `uname` = "Linux" ]; then
2347 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)"
2349 LOC="$(cat $OUT/.log | sed -E "s/"$'\E'"\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g" | grep '^Install: ' | cut -d ':' -f 2)"
2353 if [ `uname` = "Linux" ]; then
2354 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)"
2356 LOC="$LOC $(cat $OUT/.log | sed -E "s/"$'\E'"\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g" | grep '^Copy: ' | cut -d ':' -f 2)"
2359 # If any files are going to /data, push an octal file permissions reader to device
2360 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
2361 CHKPERM="/data/local/tmp/chkfileperm.sh"
2366 if [ -e $FILE ]; then
2367 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
2370 ) > $OUT/.chkfileperm.sh
2371 echo "Pushing file permissions checker to device"
2372 adb push $OUT/.chkfileperm.sh $CHKPERM
2373 adb shell chmod 755 $CHKPERM
2374 rm -f $OUT/.chkfileperm.sh
2378 for FILE in $(echo $LOC | tr " " "\n"); do
2379 # Make sure file is in $OUT/system or $OUT/data
2381 $OUT/system/*|$OUT/data/*)
2382 # Get target file name (i.e. /system/bin/adb)
2383 TARGET=$(echo $FILE | sed "s#$OUT##")
2390 # fs_config only sets permissions and se labels for files pushed to /system
2391 if [ -n "$CHKPERM" ]; then
2392 OLDPERM=$(adb shell $CHKPERM $TARGET)
2393 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
2394 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
2395 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
2397 echo "Pushing: $TARGET"
2398 adb push $FILE $TARGET
2399 if [ -n "$OLDPERM" ]; then
2400 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
2401 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
2402 adb shell chmod "$OLDPERM" $TARGET
2404 echo "$TARGET did not exist previously, you should set file permissions manually"
2406 adb shell restorecon "$TARGET"
2408 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
2409 # Only need to stop services once
2410 if ! $stop_n_start; then
2414 echo "Pushing: $TARGET"
2415 adb push $FILE $TARGET
2418 echo "Pushing: $TARGET"
2419 adb push $FILE $TARGET
2423 if [ -n "$CHKPERM" ]; then
2424 adb shell rm $CHKPERM
2426 if $stop_n_start; then
2432 echo "The connected device does not appear to be $CM_BUILD, run away!"
2436 alias mmp='dopush mm'
2437 alias mmmp='dopush mmm'
2438 alias mmap='dopush mma'
2439 alias mkap='dopush mka'
2440 alias cmkap='dopush cmka'
2442 function repopick() {
2444 $T/build/tools/repopick.py $@
2447 function fixup_common_out_dir() {
2448 common_out_dir=$(get_build_var OUT_DIR)/target/common
2449 target_device=$(get_build_var TARGET_DEVICE)
2450 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2451 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2452 mv ${common_out_dir} ${common_out_dir}-${target_device}
2453 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2455 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2456 mkdir -p ${common_out_dir}-${target_device}
2457 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2460 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2461 mkdir -p ${common_out_dir}
2465 # Force JAVA_HOME to point to java 1.7/1.8 if it isn't already set.
2466 function set_java_home() {
2467 # Clear the existing JAVA_HOME value if we set it ourselves, so that
2468 # we can reset it later, depending on the version of java the build
2471 # If we don't do this, the JAVA_HOME value set by the first call to
2472 # build/envsetup.sh will persist forever.
2473 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2477 if [ ! "$JAVA_HOME" ]; then
2478 if [ -n "$LEGACY_USE_JAVA7" ]; then
2479 echo Warning: Support for JDK 7 will be dropped. Switch to JDK 8.
2482 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2485 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2491 export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
2494 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
2499 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2500 # we can change it on the next envsetup.sh, if required.
2501 export ANDROID_SET_JAVA_HOME=true
2505 # Print colored exit condition
2509 if [ $retval -ne 0 ]
2511 echo $'\E'"[0;31mFAILURE\e[00m"
2513 echo $'\E'"[0;32mSUCCESS\e[00m"
2518 function get_make_command()
2525 local start_time=$(date +"%s")
2528 local end_time=$(date +"%s")
2529 local tdiff=$(($end_time-$start_time))
2530 local hours=$(($tdiff / 3600 ))
2531 local mins=$((($tdiff % 3600) / 60))
2532 local secs=$(($tdiff % 60))
2533 local ncolors=$(tput colors 2>/dev/null)
2534 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2535 color_failed=$'\E'"[0;31m"
2536 color_success=$'\E'"[0;32m"
2537 color_reset=$'\E'"[00m"
2544 if [ $ret -eq 0 ] ; then
2545 echo -n "${color_success}#### make completed successfully "
2547 echo -n "${color_failed}#### make failed to build some targets "
2549 if [ $hours -gt 0 ] ; then
2550 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2551 elif [ $mins -gt 0 ] ; then
2552 printf "(%02g:%02g (mm:ss))" $mins $secs
2553 elif [ $secs -gt 0 ] ; then
2554 printf "(%s seconds)" $secs
2556 echo " ####${color_reset}"
2561 function provision()
2563 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
2564 echo "Couldn't locate output files. Try running 'lunch' first." >&2
2567 if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
2568 echo "There is no provisioning script for the device." >&2
2572 # Check if user really wants to do this.
2573 if [ "$1" = "--no-confirmation" ]; then
2576 echo "This action will reflash your device."
2578 echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
2580 echo -n "Are you sure you want to do this (yes/no)? "
2582 if [[ "${REPLY}" != "yes" ]] ; then
2583 echo "Not taking any action. Exiting." >&2
2587 "$ANDROID_PRODUCT_OUT/provision-device" "$@"
2592 mk_timer $(get_make_command) "$@"
2595 function __detect_shell() {
2596 case `ps -o command -p $$` in
2612 if ! __detect_shell > /dev/null; then
2613 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
2616 # Execute the contents of any vendorsetup.sh files we can find.
2617 for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2618 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2619 `test -d product && find -L product -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
2627 check_bash_version && {
2628 dirs="sdk/bash_completion vendor/cm/bash_completion"
2629 for dir in $dirs; do
2630 if [ -d ${dir} ]; then
2631 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2639 export ANDROID_BUILD_TOP=$(gettop)