Scott Anderson | 1a5fc95 | 2012-03-07 17:15:06 -0800 | [diff] [blame] | 1 | function hmm() { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 2 | cat <<EOF |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 3 | Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment: |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 4 | - lunch: lunch <product_name>-<build_variant> |
Ying Wang | b541ab6 | 2014-05-29 17:57:40 -0700 | [diff] [blame] | 5 | - tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user] |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 6 | - croot: Changes directory to the top of the tree. |
nebkat | fb67a1e | 2012-12-28 10:40:45 +0000 | [diff] [blame] | 7 | - cout: Changes directory to out. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 8 | - m: Makes from the top of the tree. |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 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. |
Primiano Tucci | 6a8069d | 2014-02-26 11:09:19 +0000 | [diff] [blame] | 11 | To limit the modules being built use the syntax: mmm dir/:target1,target2. |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 12 | - mma: Builds all of the modules in the current directory, and their dependencies. |
Daniel Bateman | 22185ba | 2012-08-04 03:48:09 -0500 | [diff] [blame] | 13 | - mmp: Builds all of the modules in the current directory and pushes them to the device. |
| 14 | - mmmp: Builds all of the modules in the supplied directories and pushes them to the device. |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 15 | - mmma: Builds all of the modules in the supplied directories, and their dependencies. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 16 | - cgrep: Greps on all local C/C++ files. |
Jon Boekenoogen | cbca56f | 2014-04-07 10:57:38 -0700 | [diff] [blame] | 17 | - ggrep: Greps on all local Gradle files. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 18 | - jgrep: Greps on all local Java files. |
| 19 | - resgrep: Greps on all local res/*.xml files. |
Trevor Drake | 9c88976 | 2015-01-30 04:42:21 +0000 | [diff] [blame] | 20 | - mangrep: Greps on all local AndroidManifest.xml files. |
| 21 | - sepgrep: Greps on all local sepolicy files. |
Jeff Brown | 46cbd20 | 2014-07-26 15:15:41 -0700 | [diff] [blame] | 22 | - sgrep: Greps on all local source files. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 23 | - godir: Go to the directory containing a file. |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 24 | - cmremote: Add git remote for CM Gerrit Review |
| 25 | - cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review |
| 26 | - cmrebase: Rebase a Gerrit change and push it again |
Steve Kondik | 873fa56 | 2012-09-17 11:33:18 -0700 | [diff] [blame] | 27 | - aospremote: Add git remote for matching AOSP repository |
Steve Kondik | 20c21d2 | 2013-10-27 13:34:36 -0700 | [diff] [blame] | 28 | - cafremote: Add git remote for matching CodeAurora repository. |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 29 | - mka: Builds using SCHED_BATCH on all processors |
| 30 | - reposync: Parallel repo sync using ionice and SCHED_BATCH |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 31 | - repopick: Utility to fetch changes from Gerrit. |
Steve Kondik | 83c03d5 | 2012-10-24 16:40:42 -0700 | [diff] [blame] | 32 | - installboot: Installs a boot.img to the connected device. |
| 33 | - installrecovery: Installs a recovery.img to the connected device. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 34 | |
Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 35 | Environemnt options: |
| 36 | - SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that |
| 37 | ASAN_OPTIONS=detect_leaks=0 will be set by default until the |
| 38 | build is leak-check clean. |
| 39 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 40 | Look at the source to view more functions. The complete list is: |
| 41 | EOF |
| 42 | T=$(gettop) |
| 43 | local A |
| 44 | A="" |
Jeff Brown | 46cbd20 | 2014-07-26 15:15:41 -0700 | [diff] [blame] | 45 | for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 46 | A="$A $i" |
| 47 | done |
| 48 | echo $A |
| 49 | } |
| 50 | |
| 51 | # Get the value of a build variable as an absolute path. |
| 52 | function get_abs_build_var() |
| 53 | { |
| 54 | T=$(gettop) |
| 55 | if [ ! "$T" ]; then |
| 56 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 57 | return |
| 58 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 59 | (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ |
Ed Heyl | c6d11f8 | 2014-06-27 13:32:39 -0700 | [diff] [blame] | 60 | command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | # Get the exact value of a build variable. |
| 64 | function get_build_var() |
| 65 | { |
| 66 | T=$(gettop) |
| 67 | if [ ! "$T" ]; then |
| 68 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 69 | return |
| 70 | fi |
Andrew Boie | 6905e21 | 2013-12-19 13:21:46 -0800 | [diff] [blame] | 71 | (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ |
Ed Heyl | c6d11f8 | 2014-06-27 13:32:39 -0700 | [diff] [blame] | 72 | command make --no-print-directory -f build/core/config.mk dumpvar-$1) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | # check to see if the supplied product is one we can build |
| 76 | function check_product() |
| 77 | { |
| 78 | T=$(gettop) |
| 79 | if [ ! "$T" ]; then |
| 80 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 81 | return |
| 82 | fi |
Ricardo Cerqueira | 119d3bb | 2011-11-25 15:30:36 +0000 | [diff] [blame] | 83 | |
| 84 | if (echo -n $1 | grep -q -e "^cm_") ; then |
| 85 | CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g') |
Ricardo Cerqueira | 34ae323 | 2013-09-26 00:10:20 +0100 | [diff] [blame] | 86 | export BUILD_NUMBER=$((date +%s%N ; echo $CM_BUILD; hostname) | openssl sha1 | sed -e 's/.*=//g; s/ //g' | cut -c1-10) |
Ricardo Cerqueira | 119d3bb | 2011-11-25 15:30:36 +0000 | [diff] [blame] | 87 | else |
| 88 | CM_BUILD= |
| 89 | fi |
| 90 | export CM_BUILD |
| 91 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 92 | TARGET_PRODUCT=$1 \ |
| 93 | TARGET_BUILD_VARIANT= \ |
| 94 | TARGET_BUILD_TYPE= \ |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 95 | TARGET_BUILD_APPS= \ |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 96 | get_build_var TARGET_DEVICE > /dev/null |
| 97 | # hide successful answers, but allow the errors to show |
| 98 | } |
| 99 | |
| 100 | VARIANT_CHOICES=(user userdebug eng) |
| 101 | |
| 102 | # check to see if the supplied variant is valid |
| 103 | function check_variant() |
| 104 | { |
| 105 | for v in ${VARIANT_CHOICES[@]} |
| 106 | do |
| 107 | if [ "$v" = "$1" ] |
| 108 | then |
| 109 | return 0 |
| 110 | fi |
| 111 | done |
| 112 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | function setpaths() |
| 116 | { |
| 117 | T=$(gettop) |
| 118 | if [ ! "$T" ]; then |
| 119 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 120 | return |
| 121 | fi |
| 122 | |
| 123 | ################################################################## |
| 124 | # # |
| 125 | # Read me before you modify this code # |
| 126 | # # |
| 127 | # This function sets ANDROID_BUILD_PATHS to what it is adding # |
| 128 | # to PATH, and the next time it is run, it removes that from # |
| 129 | # PATH. This is required so lunch can be run more than once # |
| 130 | # and still have working paths. # |
| 131 | # # |
| 132 | ################################################################## |
| 133 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 134 | # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces |
| 135 | # due to "C:\Program Files" being in the path. |
| 136 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 137 | # out with the old |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 138 | if [ -n "$ANDROID_BUILD_PATHS" ] ; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 139 | export PATH=${PATH/$ANDROID_BUILD_PATHS/} |
| 140 | fi |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 141 | if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 142 | export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/} |
Ying Wang | aa1c9b5 | 2012-11-26 20:51:59 -0800 | [diff] [blame] | 143 | # strip leading ':', if any |
| 144 | export PATH=${PATH/:%/} |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 145 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 146 | |
| 147 | # and in with the new |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 148 | prebuiltdir=$(getprebuilt) |
Jing Yu | f5172c7 | 2012-03-29 20:45:50 -0700 | [diff] [blame] | 149 | gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS) |
Raphael | 732936d | 2011-06-22 14:35:32 -0700 | [diff] [blame] | 150 | |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 151 | # defined in core/config.mk |
| 152 | targetgccversion=$(get_build_var TARGET_GCC_VERSION) |
Colin Cross | 03b424a | 2014-05-22 11:57:43 -0700 | [diff] [blame] | 153 | targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION) |
Ben Cheng | 1526670 | 2012-12-10 16:04:39 -0800 | [diff] [blame] | 154 | export TARGET_GCC_VERSION=$targetgccversion |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 155 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 156 | # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it. |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 157 | export ANDROID_TOOLCHAIN= |
| 158 | export ANDROID_TOOLCHAIN_2ND_ARCH= |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 159 | local ARCH=$(get_build_var TARGET_ARCH) |
| 160 | case $ARCH in |
Pavel Chupin | c1a5664 | 2013-08-23 16:49:21 +0400 | [diff] [blame] | 161 | x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin |
Mark D Horn | 7d0ede7 | 2012-03-14 14:20:30 -0700 | [diff] [blame] | 162 | ;; |
Pavel Chupin | fd82a49 | 2012-11-26 09:50:07 +0400 | [diff] [blame] | 163 | x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin |
| 164 | ;; |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 165 | arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 166 | ;; |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 167 | arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin; |
Colin Cross | 03b424a | 2014-05-22 11:57:43 -0700 | [diff] [blame] | 168 | toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin |
Ben Cheng | db4fc20 | 2013-10-04 16:02:59 -0700 | [diff] [blame] | 169 | ;; |
Duane Sand | 3c4fcd8 | 2014-07-22 14:34:00 -0700 | [diff] [blame] | 170 | mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin |
Serban Constantinescu | 9b68fb2 | 2014-01-14 10:33:53 +0000 | [diff] [blame] | 171 | ;; |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 172 | *) |
| 173 | echo "Can't find toolchain for unknown architecture: $ARCH" |
| 174 | toolchaindir=xxxxxxxxx |
Mark D Horn | 7d0ede7 | 2012-03-14 14:20:30 -0700 | [diff] [blame] | 175 | ;; |
| 176 | esac |
Jing Yu | f5172c7 | 2012-03-29 20:45:50 -0700 | [diff] [blame] | 177 | if [ -d "$gccprebuiltdir/$toolchaindir" ]; then |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 178 | export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 179 | fi |
Raphael | 732936d | 2011-06-22 14:35:32 -0700 | [diff] [blame] | 180 | |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 181 | if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then |
| 182 | export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2 |
| 183 | fi |
| 184 | |
| 185 | unset ANDROID_KERNEL_TOOLCHAIN_PATH |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 186 | case $ARCH in |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 187 | arm) |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 188 | # Legacy toolchain configuration used for ARM kernel compilation |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 189 | toolchaindir=arm/arm-eabi-$targetgccversion/bin |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 190 | if [ -d "$gccprebuiltdir/$toolchaindir" ]; then |
Torne (Richard Coles) | f24c356 | 2014-04-25 16:24:22 +0100 | [diff] [blame] | 191 | export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir" |
| 192 | ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN": |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 193 | fi |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 194 | ;; |
| 195 | *) |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 196 | # No need to set ARM_EABI_TOOLCHAIN for other ARCHs |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 197 | ;; |
| 198 | esac |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 199 | |
Jeff Vander Stoep | 5aa6832 | 2015-06-12 09:56:39 -0700 | [diff] [blame] | 200 | export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin |
Ying Wang | 2a859d5 | 2014-06-30 10:25:33 -0700 | [diff] [blame] | 201 | export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS: |
David 'Digit' Turner | 94d16e5 | 2014-05-05 16:13:50 +0200 | [diff] [blame] | 202 | |
| 203 | # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH |
| 204 | # to ensure that the corresponding 'emulator' binaries are used. |
| 205 | case $(uname -s) in |
| 206 | Darwin) |
| 207 | ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64 |
| 208 | ;; |
| 209 | Linux) |
| 210 | ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64 |
| 211 | ;; |
| 212 | *) |
| 213 | ANDROID_EMULATOR_PREBUILTS= |
| 214 | ;; |
| 215 | esac |
| 216 | if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then |
Christopher Ferris | 7110f24 | 2014-05-20 13:56:00 -0700 | [diff] [blame] | 217 | ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS: |
David 'Digit' Turner | 94d16e5 | 2014-05-05 16:13:50 +0200 | [diff] [blame] | 218 | export ANDROID_EMULATOR_PREBUILTS |
| 219 | fi |
| 220 | |
Ying Wang | aa1c9b5 | 2012-11-26 20:51:59 -0800 | [diff] [blame] | 221 | export PATH=$ANDROID_BUILD_PATHS$PATH |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 222 | |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 223 | unset ANDROID_JAVA_TOOLCHAIN |
Ji-Hwan Lee | 752ad06 | 2011-07-04 14:09:47 +0900 | [diff] [blame] | 224 | unset ANDROID_PRE_BUILD_PATHS |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 225 | if [ -n "$JAVA_HOME" ]; then |
| 226 | export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin |
Ji-Hwan Lee | 752ad06 | 2011-07-04 14:09:47 +0900 | [diff] [blame] | 227 | export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN: |
| 228 | export PATH=$ANDROID_PRE_BUILD_PATHS$PATH |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 229 | fi |
| 230 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 231 | unset ANDROID_PRODUCT_OUT |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 232 | export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT) |
| 233 | export OUT=$ANDROID_PRODUCT_OUT |
| 234 | |
Jeff Brown | 8fd5cce | 2011-03-24 17:03:06 -0700 | [diff] [blame] | 235 | unset ANDROID_HOST_OUT |
| 236 | export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT) |
| 237 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 238 | # needed for building linux on MacOS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 239 | # TODO: fix the path |
| 240 | #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include |
| 241 | } |
| 242 | |
| 243 | function printconfig() |
| 244 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 245 | T=$(gettop) |
| 246 | if [ ! "$T" ]; then |
| 247 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 248 | return |
| 249 | fi |
| 250 | get_build_var report_config |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | function set_stuff_for_environment() |
| 254 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 255 | settitle |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 256 | set_java_home |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 257 | setpaths |
| 258 | set_sequence_number |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 259 | |
Ben Cheng | aac3f81 | 2013-08-13 14:38:15 -0700 | [diff] [blame] | 260 | # With this environment variable new GCC can apply colors to warnings/errors |
| 261 | export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' |
Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 262 | export ASAN_OPTIONS=detect_leaks=0 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | function set_sequence_number() |
| 266 | { |
Joe Onorato | aee4daa | 2010-06-23 14:03:13 -0700 | [diff] [blame] | 267 | export BUILD_ENV_SEQUENCE_NUMBER=10 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | function settitle() |
| 271 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 272 | if [ "$STAY_OFF_MY_LAWN" = "" ]; then |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 273 | local arch=$(gettargetarch) |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 274 | local product=$TARGET_PRODUCT |
| 275 | local variant=$TARGET_BUILD_VARIANT |
| 276 | local apps=$TARGET_BUILD_APPS |
Steve Kondik | d6fba55 | 2012-12-27 15:28:34 -0800 | [diff] [blame] | 277 | if [ -z "$PROMPT_COMMAND" ]; then |
| 278 | # No prompts |
| 279 | PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\"" |
| 280 | elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then |
| 281 | # Prompts exist, but no hardstatus |
| 282 | PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}" |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 283 | fi |
Steve Kondik | d6fba55 | 2012-12-27 15:28:34 -0800 | [diff] [blame] | 284 | if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then |
Christopher Lais | fa8d935 | 2013-06-03 15:15:39 -0500 | [diff] [blame] | 285 | PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')" |
Steve Kondik | d6fba55 | 2012-12-27 15:28:34 -0800 | [diff] [blame] | 286 | fi |
| 287 | |
| 288 | if [ -z "$apps" ]; then |
| 289 | ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]" |
| 290 | else |
| 291 | ANDROID_PROMPT_PREFIX="[$arch $apps $variant]" |
| 292 | fi |
| 293 | export ANDROID_PROMPT_PREFIX |
| 294 | |
| 295 | # Inject build data into hardstatus |
| 296 | export PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/\\033]0;\(.*\)\\007/\\033]0;$ANDROID_PROMPT_PREFIX \1\\007/g')" |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 297 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Kyle Ladd | 031a0b6 | 2013-09-11 20:43:42 -0400 | [diff] [blame] | 300 | function check_bash_version() |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 301 | { |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 302 | # Keep us from trying to run in something that isn't bash. |
| 303 | if [ -z "${BASH_VERSION}" ]; then |
Kyle Ladd | 031a0b6 | 2013-09-11 20:43:42 -0400 | [diff] [blame] | 304 | return 1 |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 305 | fi |
| 306 | |
| 307 | # Keep us from trying to run in bash that's too old. |
James Roberts-Thomson | 24dd07d | 2013-04-16 15:53:39 +1200 | [diff] [blame] | 308 | if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then |
Kyle Ladd | 031a0b6 | 2013-09-11 20:43:42 -0400 | [diff] [blame] | 309 | return 2 |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 310 | fi |
| 311 | |
Kyle Ladd | 031a0b6 | 2013-09-11 20:43:42 -0400 | [diff] [blame] | 312 | return 0 |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 313 | } |
| 314 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 315 | function choosetype() |
| 316 | { |
| 317 | echo "Build type choices are:" |
| 318 | echo " 1. release" |
| 319 | echo " 2. debug" |
| 320 | echo |
| 321 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 322 | local DEFAULT_NUM DEFAULT_VALUE |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 323 | DEFAULT_NUM=1 |
| 324 | DEFAULT_VALUE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 325 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 326 | export TARGET_BUILD_TYPE= |
| 327 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 328 | while [ -z $TARGET_BUILD_TYPE ] |
| 329 | do |
| 330 | echo -n "Which would you like? ["$DEFAULT_NUM"] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 331 | if [ -z "$1" ] ; then |
| 332 | read ANSWER |
| 333 | else |
| 334 | echo $1 |
| 335 | ANSWER=$1 |
| 336 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 337 | case $ANSWER in |
| 338 | "") |
| 339 | export TARGET_BUILD_TYPE=$DEFAULT_VALUE |
| 340 | ;; |
| 341 | 1) |
| 342 | export TARGET_BUILD_TYPE=release |
| 343 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 344 | release) |
| 345 | export TARGET_BUILD_TYPE=release |
| 346 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 347 | 2) |
| 348 | export TARGET_BUILD_TYPE=debug |
| 349 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 350 | debug) |
| 351 | export TARGET_BUILD_TYPE=debug |
| 352 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 353 | *) |
| 354 | echo |
| 355 | echo "I didn't understand your response. Please try again." |
| 356 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 357 | ;; |
| 358 | esac |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 359 | if [ -n "$1" ] ; then |
| 360 | break |
| 361 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 362 | done |
| 363 | |
| 364 | set_stuff_for_environment |
| 365 | } |
| 366 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 367 | # |
| 368 | # This function isn't really right: It chooses a TARGET_PRODUCT |
| 369 | # based on the list of boards. Usually, that gets you something |
| 370 | # that kinda works with a generic product, but really, you should |
| 371 | # pick a product by name. |
| 372 | # |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 373 | function chooseproduct() |
| 374 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 375 | if [ "x$TARGET_PRODUCT" != x ] ; then |
| 376 | default_value=$TARGET_PRODUCT |
| 377 | else |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 378 | default_value=full |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 379 | fi |
| 380 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 381 | export TARGET_PRODUCT= |
| 382 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 383 | while [ -z "$TARGET_PRODUCT" ] |
| 384 | do |
Joe Onorato | 8849aed | 2009-04-29 15:56:47 -0700 | [diff] [blame] | 385 | echo -n "Which product would you like? [$default_value] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 386 | if [ -z "$1" ] ; then |
| 387 | read ANSWER |
| 388 | else |
| 389 | echo $1 |
| 390 | ANSWER=$1 |
| 391 | fi |
| 392 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 393 | if [ -z "$ANSWER" ] ; then |
| 394 | export TARGET_PRODUCT=$default_value |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 395 | else |
| 396 | if check_product $ANSWER |
| 397 | then |
| 398 | export TARGET_PRODUCT=$ANSWER |
| 399 | else |
| 400 | echo "** Not a valid product: $ANSWER" |
| 401 | fi |
| 402 | fi |
| 403 | if [ -n "$1" ] ; then |
| 404 | break |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 405 | fi |
| 406 | done |
| 407 | |
| 408 | set_stuff_for_environment |
| 409 | } |
| 410 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 411 | function choosevariant() |
| 412 | { |
| 413 | echo "Variant choices are:" |
| 414 | local index=1 |
| 415 | local v |
| 416 | for v in ${VARIANT_CHOICES[@]} |
| 417 | do |
| 418 | # The product name is the name of the directory containing |
| 419 | # the makefile we found, above. |
| 420 | echo " $index. $v" |
| 421 | index=$(($index+1)) |
| 422 | done |
| 423 | |
| 424 | local default_value=eng |
| 425 | local ANSWER |
| 426 | |
| 427 | export TARGET_BUILD_VARIANT= |
| 428 | while [ -z "$TARGET_BUILD_VARIANT" ] |
| 429 | do |
| 430 | echo -n "Which would you like? [$default_value] " |
| 431 | if [ -z "$1" ] ; then |
| 432 | read ANSWER |
| 433 | else |
| 434 | echo $1 |
| 435 | ANSWER=$1 |
| 436 | fi |
| 437 | |
| 438 | if [ -z "$ANSWER" ] ; then |
| 439 | export TARGET_BUILD_VARIANT=$default_value |
| 440 | elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then |
| 441 | if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 442 | export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 443 | fi |
| 444 | else |
| 445 | if check_variant $ANSWER |
| 446 | then |
| 447 | export TARGET_BUILD_VARIANT=$ANSWER |
| 448 | else |
| 449 | echo "** Not a valid variant: $ANSWER" |
| 450 | fi |
| 451 | fi |
| 452 | if [ -n "$1" ] ; then |
| 453 | break |
| 454 | fi |
| 455 | done |
| 456 | } |
| 457 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 458 | function choosecombo() |
| 459 | { |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 460 | choosetype $1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 461 | |
| 462 | echo |
| 463 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 464 | chooseproduct $2 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 465 | |
| 466 | echo |
| 467 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 468 | choosevariant $3 |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 469 | |
| 470 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 471 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 472 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 473 | } |
| 474 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 475 | # Clear this variable. It will be built up again when the vendorsetup.sh |
| 476 | # files are included at the end of this file. |
| 477 | unset LUNCH_MENU_CHOICES |
| 478 | function add_lunch_combo() |
| 479 | { |
| 480 | local new_combo=$1 |
| 481 | local c |
| 482 | for c in ${LUNCH_MENU_CHOICES[@]} ; do |
| 483 | if [ "$new_combo" = "$c" ] ; then |
| 484 | return |
| 485 | fi |
| 486 | done |
| 487 | LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) |
| 488 | } |
| 489 | |
| 490 | # add the default one here |
Jean-Baptiste Queru | 324c123 | 2013-03-22 15:53:54 -0700 | [diff] [blame] | 491 | add_lunch_combo aosp_arm-eng |
Colin Cross | 4f0eb7d | 2014-01-21 19:35:38 -0800 | [diff] [blame] | 492 | add_lunch_combo aosp_arm64-eng |
Serban Constantinescu | 9b68fb2 | 2014-01-14 10:33:53 +0000 | [diff] [blame] | 493 | add_lunch_combo aosp_mips-eng |
Chris Dearman | 1efd9e4 | 2014-02-03 15:01:24 -0800 | [diff] [blame] | 494 | add_lunch_combo aosp_mips64-eng |
Serban Constantinescu | 9b68fb2 | 2014-01-14 10:33:53 +0000 | [diff] [blame] | 495 | add_lunch_combo aosp_x86-eng |
| 496 | add_lunch_combo aosp_x86_64-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 497 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 498 | function print_lunch_menu() |
| 499 | { |
| 500 | local uname=$(uname) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 501 | echo |
| 502 | echo "You're building on" $uname |
Ricardo Cerqueira | 8b2014d | 2011-01-31 00:49:49 +0000 | [diff] [blame] | 503 | if [ "$(uname)" = "Darwin" ] ; then |
| 504 | echo " (ohai, koush!)" |
| 505 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 506 | echo |
Ricardo Cerqueira | 8b2014d | 2011-01-31 00:49:49 +0000 | [diff] [blame] | 507 | if [ "z${CM_DEVICES_ONLY}" != "z" ]; then |
| 508 | echo "Breakfast menu... pick a combo:" |
| 509 | else |
| 510 | echo "Lunch menu... pick a combo:" |
| 511 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 512 | |
| 513 | local i=1 |
| 514 | local choice |
| 515 | for choice in ${LUNCH_MENU_CHOICES[@]} |
| 516 | do |
cybojenix | a5dd6ce | 2013-06-28 20:30:00 +0100 | [diff] [blame] | 517 | echo " $i. $choice " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 518 | i=$(($i+1)) |
cybojenix | a5dd6ce | 2013-06-28 20:30:00 +0100 | [diff] [blame] | 519 | done | column |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 520 | |
Ricardo Cerqueira | 8b2014d | 2011-01-31 00:49:49 +0000 | [diff] [blame] | 521 | if [ "z${CM_DEVICES_ONLY}" != "z" ]; then |
| 522 | echo "... and don't forget the bacon!" |
| 523 | fi |
| 524 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 525 | echo |
| 526 | } |
| 527 | |
Ricardo Cerqueira | 8b2014d | 2011-01-31 00:49:49 +0000 | [diff] [blame] | 528 | function brunch() |
| 529 | { |
| 530 | breakfast $* |
| 531 | if [ $? -eq 0 ]; then |
| 532 | mka bacon |
| 533 | else |
| 534 | echo "No such item in brunch menu. Try 'breakfast'" |
| 535 | return 1 |
| 536 | fi |
| 537 | return $? |
| 538 | } |
| 539 | |
| 540 | function breakfast() |
| 541 | { |
| 542 | target=$1 |
JustArchi | f70c7e6 | 2014-06-22 14:37:30 +0200 | [diff] [blame] | 543 | local variant=$2 |
Ricardo Cerqueira | 8b2014d | 2011-01-31 00:49:49 +0000 | [diff] [blame] | 544 | CM_DEVICES_ONLY="true" |
| 545 | unset LUNCH_MENU_CHOICES |
| 546 | add_lunch_combo full-eng |
| 547 | for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null` |
| 548 | do |
| 549 | echo "including $f" |
| 550 | . $f |
| 551 | done |
| 552 | unset f |
| 553 | |
| 554 | if [ $# -eq 0 ]; then |
| 555 | # No arguments, so let's have the full menu |
| 556 | lunch |
| 557 | else |
| 558 | echo "z$target" | grep -q "-" |
| 559 | if [ $? -eq 0 ]; then |
| 560 | # A buildtype was specified, assume a full device name |
| 561 | lunch $target |
| 562 | else |
| 563 | # This is probably just the CM model name |
JustArchi | f70c7e6 | 2014-06-22 14:37:30 +0200 | [diff] [blame] | 564 | if [ -z "$variant" ]; then |
| 565 | variant="userdebug" |
| 566 | fi |
| 567 | lunch cm_$target-$variant |
Ricardo Cerqueira | 8b2014d | 2011-01-31 00:49:49 +0000 | [diff] [blame] | 568 | fi |
| 569 | fi |
| 570 | return $? |
| 571 | } |
| 572 | |
| 573 | alias bib=breakfast |
| 574 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 575 | function lunch() |
| 576 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 577 | local answer |
| 578 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 579 | if [ "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 580 | answer=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 581 | else |
| 582 | print_lunch_menu |
Jean-Baptiste Queru | 324c123 | 2013-03-22 15:53:54 -0700 | [diff] [blame] | 583 | echo -n "Which would you like? [aosp_arm-eng] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 584 | read answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 585 | fi |
| 586 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 587 | local selection= |
| 588 | |
| 589 | if [ -z "$answer" ] |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 590 | then |
Jean-Baptiste Queru | 324c123 | 2013-03-22 15:53:54 -0700 | [diff] [blame] | 591 | selection=aosp_arm-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 592 | elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") |
| 593 | then |
| 594 | if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ] |
| 595 | then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 596 | selection=${LUNCH_MENU_CHOICES[$(($answer-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 597 | fi |
| 598 | elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$") |
| 599 | then |
| 600 | selection=$answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 601 | fi |
| 602 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 603 | if [ -z "$selection" ] |
| 604 | then |
| 605 | echo |
| 606 | echo "Invalid lunch combo: $answer" |
| 607 | return 1 |
| 608 | fi |
| 609 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 610 | export TARGET_BUILD_APPS= |
| 611 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 612 | local product=$(echo -n $selection | sed -e "s/-.*$//") |
| 613 | check_product $product |
| 614 | if [ $? -ne 0 ] |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 615 | then |
Koushik Dutta | 780fb5f | 2011-11-26 18:51:42 -0800 | [diff] [blame] | 616 | # if we can't find a product, try to grab it off the CM github |
| 617 | T=$(gettop) |
| 618 | pushd $T > /dev/null |
| 619 | build/tools/roomservice.py $product |
| 620 | popd > /dev/null |
| 621 | check_product $product |
Diogo Ferreira | 0d10917 | 2012-03-18 21:18:29 +0000 | [diff] [blame] | 622 | else |
| 623 | build/tools/roomservice.py $product true |
Koushik Dutta | 780fb5f | 2011-11-26 18:51:42 -0800 | [diff] [blame] | 624 | fi |
| 625 | if [ $? -ne 0 ] |
| 626 | then |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 627 | echo |
| 628 | echo "** Don't have a product spec for: '$product'" |
| 629 | echo "** Do you have the right repo manifest?" |
| 630 | product= |
| 631 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 632 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 633 | local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//") |
| 634 | check_variant $variant |
| 635 | if [ $? -ne 0 ] |
| 636 | then |
| 637 | echo |
| 638 | echo "** Invalid variant: '$variant'" |
| 639 | echo "** Must be one of ${VARIANT_CHOICES[@]}" |
| 640 | variant= |
| 641 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 642 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 643 | if [ -z "$product" -o -z "$variant" ] |
| 644 | then |
| 645 | echo |
| 646 | return 1 |
| 647 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 648 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 649 | export TARGET_PRODUCT=$product |
| 650 | export TARGET_BUILD_VARIANT=$variant |
| 651 | export TARGET_BUILD_TYPE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 652 | |
| 653 | echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 654 | |
Chirayu Desai | b89b324 | 2013-06-30 10:04:25 +0530 | [diff] [blame] | 655 | fixup_common_out_dir |
| 656 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 657 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 658 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 661 | # Tab completion for lunch. |
| 662 | function _lunch() |
| 663 | { |
| 664 | local cur prev opts |
| 665 | COMPREPLY=() |
| 666 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 667 | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 668 | |
| 669 | COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) ) |
| 670 | return 0 |
| 671 | } |
Emilio López | 9ad6eea | 2013-11-03 13:02:13 -0300 | [diff] [blame] | 672 | complete -F _lunch lunch 2>/dev/null |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 673 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 674 | # Configures the build to build unbundled apps. |
Doug Zongker | 0d8179e | 2014-04-16 11:34:34 -0700 | [diff] [blame] | 675 | # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME) |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 676 | function tapas() |
| 677 | { |
Ying Wang | b541ab6 | 2014-05-29 17:57:40 -0700 | [diff] [blame] | 678 | local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)" |
Doug Zongker | 0d8179e | 2014-04-16 11:34:34 -0700 | [diff] [blame] | 679 | local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)" |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 680 | local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)" |
| 681 | 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)" |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 682 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 683 | if [ $(echo $arch | wc -w) -gt 1 ]; then |
| 684 | echo "tapas: Error: Multiple build archs supplied: $arch" |
| 685 | return |
| 686 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 687 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 688 | echo "tapas: Error: Multiple build variants supplied: $variant" |
| 689 | return |
| 690 | fi |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 691 | if [ $(echo $density | wc -w) -gt 1 ]; then |
| 692 | echo "tapas: Error: Multiple densities supplied: $density" |
| 693 | return |
| 694 | fi |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 695 | |
| 696 | local product=full |
| 697 | case $arch in |
Ying Wang | b541ab6 | 2014-05-29 17:57:40 -0700 | [diff] [blame] | 698 | x86) product=full_x86;; |
| 699 | mips) product=full_mips;; |
| 700 | armv5) product=generic_armv5;; |
| 701 | arm64) product=aosp_arm64;; |
| 702 | x86_64) product=aosp_x86_64;; |
| 703 | mips64) product=aosp_mips64;; |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 704 | esac |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 705 | if [ -z "$variant" ]; then |
| 706 | variant=eng |
| 707 | fi |
Ying Wang | c048c9b | 2010-06-24 15:08:33 -0700 | [diff] [blame] | 708 | if [ -z "$apps" ]; then |
| 709 | apps=all |
| 710 | fi |
Justin Morey | 29d225c | 2014-11-04 13:35:51 -0600 | [diff] [blame] | 711 | if [ -z "$density" ]; then |
| 712 | density=alldpi |
| 713 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 714 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 715 | export TARGET_PRODUCT=$product |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 716 | export TARGET_BUILD_VARIANT=$variant |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 717 | export TARGET_BUILD_DENSITY=$density |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 718 | export TARGET_BUILD_TYPE=release |
| 719 | export TARGET_BUILD_APPS=$apps |
| 720 | |
| 721 | set_stuff_for_environment |
| 722 | printconfig |
| 723 | } |
| 724 | |
Ricardo Cerqueira | dbc3c4e | 2011-08-19 20:37:12 +0100 | [diff] [blame] | 725 | function eat() |
| 726 | { |
| 727 | if [ "$OUT" ] ; then |
Chirayu Desai | 80a277d | 2013-05-04 17:59:18 +0530 | [diff] [blame] | 728 | MODVERSION=$(get_build_var CM_VERSION) |
Ricardo Cerqueira | dbc3c4e | 2011-08-19 20:37:12 +0100 | [diff] [blame] | 729 | ZIPFILE=cm-$MODVERSION.zip |
| 730 | ZIPPATH=$OUT/$ZIPFILE |
| 731 | if [ ! -f $ZIPPATH ] ; then |
| 732 | echo "Nothing to eat" |
| 733 | return 1 |
| 734 | fi |
| 735 | adb start-server # Prevent unexpected starting server message from adb get-state in the next line |
| 736 | if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then |
| 737 | echo "No device is online. Waiting for one..." |
| 738 | echo "Please connect USB and/or enable USB debugging" |
| 739 | until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do |
| 740 | sleep 1 |
| 741 | done |
| 742 | echo "Device Found.." |
| 743 | fi |
Chirayu Desai | 6dadb57 | 2012-12-26 10:53:58 +0530 | [diff] [blame] | 744 | if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD"); |
| 745 | then |
Ricardo Cerqueira | dbc3c4e | 2011-08-19 20:37:12 +0100 | [diff] [blame] | 746 | # if adbd isn't root we can't write to /cache/recovery/ |
| 747 | adb root |
| 748 | sleep 1 |
| 749 | adb wait-for-device |
Steve Kondik | 464574f | 2013-04-13 07:19:52 -0700 | [diff] [blame] | 750 | cat << EOF > /tmp/command |
| 751 | --sideload |
Ricardo Cerqueira | dbc3c4e | 2011-08-19 20:37:12 +0100 | [diff] [blame] | 752 | EOF |
Steve Kondik | 464574f | 2013-04-13 07:19:52 -0700 | [diff] [blame] | 753 | if adb push /tmp/command /cache/recovery/ ; then |
| 754 | echo "Rebooting into recovery for sideload installation" |
| 755 | adb reboot recovery |
| 756 | adb wait-for-sideload |
| 757 | adb sideload $ZIPPATH |
Ricardo Cerqueira | dbc3c4e | 2011-08-19 20:37:12 +0100 | [diff] [blame] | 758 | fi |
Steve Kondik | 464574f | 2013-04-13 07:19:52 -0700 | [diff] [blame] | 759 | rm /tmp/command |
Ricardo Cerqueira | dbc3c4e | 2011-08-19 20:37:12 +0100 | [diff] [blame] | 760 | else |
| 761 | echo "Nothing to eat" |
| 762 | return 1 |
| 763 | fi |
| 764 | return $? |
Chirayu Desai | 6dadb57 | 2012-12-26 10:53:58 +0530 | [diff] [blame] | 765 | else |
| 766 | echo "The connected device does not appear to be $CM_BUILD, run away!" |
| 767 | fi |
Ricardo Cerqueira | dbc3c4e | 2011-08-19 20:37:12 +0100 | [diff] [blame] | 768 | } |
| 769 | |
Nebojsa Cvetkovic | d5c0c87 | 2012-11-09 23:02:54 +0000 | [diff] [blame] | 770 | function omnom |
| 771 | { |
| 772 | brunch $* |
| 773 | eat |
| 774 | } |
| 775 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 776 | function gettop |
| 777 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 778 | local TOPFILE=build/core/envsetup.mk |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 779 | if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then |
Brian Carlstrom | a5c4f17 | 2014-09-12 00:33:25 -0700 | [diff] [blame] | 780 | # The following circumlocution ensures we remove symlinks from TOP. |
| 781 | (cd $TOP; PWD= /bin/pwd) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 782 | else |
| 783 | if [ -f $TOPFILE ] ; then |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 784 | # The following circumlocution (repeated below as well) ensures |
| 785 | # that we record the true directory name and not one that is |
| 786 | # faked up with symlink names. |
| 787 | PWD= /bin/pwd |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 788 | else |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 789 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 790 | T= |
| 791 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 792 | \cd .. |
synergy | b112a40 | 2013-07-05 19:47:47 -0700 | [diff] [blame] | 793 | T=`PWD= /bin/pwd -P` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 794 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 795 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 796 | if [ -f "$T/$TOPFILE" ]; then |
| 797 | echo $T |
| 798 | fi |
| 799 | fi |
| 800 | fi |
| 801 | } |
| 802 | |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 803 | # Return driver for "make", if any (eg. static analyzer) |
| 804 | function getdriver() |
| 805 | { |
| 806 | local T="$1" |
| 807 | test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER |
| 808 | if [ -n "$WITH_STATIC_ANALYZER" ]; then |
| 809 | echo "\ |
Andrew Hsieh | c4f7fba | 2014-03-03 16:53:17 +0800 | [diff] [blame] | 810 | $T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \ |
| 811 | --use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \ |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 812 | --status-bugs \ |
| 813 | --top=$T" |
| 814 | fi |
| 815 | } |
| 816 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 817 | function m() |
| 818 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 819 | local T=$(gettop) |
| 820 | local DRV=$(getdriver $T) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 821 | if [ "$T" ]; then |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 822 | $DRV make -C $T -f build/core/main.mk $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 823 | else |
| 824 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 825 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 826 | fi |
| 827 | } |
| 828 | |
| 829 | function findmakefile() |
| 830 | { |
| 831 | TOPFILE=build/core/envsetup.mk |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 832 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 833 | T= |
| 834 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
Ying Wang | 11b15b1 | 2012-10-11 15:05:07 -0700 | [diff] [blame] | 835 | T=`PWD= /bin/pwd` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 836 | if [ -f "$T/Android.mk" ]; then |
| 837 | echo $T/Android.mk |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 838 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 839 | return |
| 840 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 841 | \cd .. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 842 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 843 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | function mm() |
| 847 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 848 | local T=$(gettop) |
| 849 | local DRV=$(getdriver $T) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 850 | # If we're sitting in the root of the build tree, just do a |
| 851 | # normal make. |
| 852 | if [ -f build/core/envsetup.mk -a -f Makefile ]; then |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 853 | $DRV make $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 854 | else |
| 855 | # Find the closest Android.mk file. |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 856 | local M=$(findmakefile) |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 857 | local MODULES= |
| 858 | local GET_INSTALL_PATH= |
| 859 | local ARGS= |
Robert Greenwalt | 3c794d7 | 2009-07-15 15:07:44 -0700 | [diff] [blame] | 860 | # Remove the path to top as the makefilepath needs to be relative |
| 861 | local M=`echo $M|sed 's:'$T'/::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 862 | if [ ! "$T" ]; then |
| 863 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 864 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 865 | elif [ ! "$M" ]; then |
| 866 | echo "Couldn't locate a makefile from the current directory." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 867 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 868 | else |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 869 | for ARG in $@; do |
| 870 | case $ARG in |
| 871 | GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;; |
| 872 | esac |
| 873 | done |
| 874 | if [ -n "$GET_INSTALL_PATH" ]; then |
| 875 | MODULES= |
| 876 | ARGS=GET-INSTALL-PATH |
| 877 | else |
| 878 | MODULES=all_modules |
| 879 | ARGS=$@ |
| 880 | fi |
Andrew Hsieh | 246daf7 | 2013-09-10 18:07:23 -0700 | [diff] [blame] | 881 | ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 882 | fi |
| 883 | fi |
| 884 | } |
| 885 | |
| 886 | function mmm() |
| 887 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 888 | local T=$(gettop) |
| 889 | local DRV=$(getdriver $T) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 890 | if [ "$T" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 891 | local MAKEFILE= |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 892 | local MODULES= |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 893 | local ARGS= |
| 894 | local DIR TO_CHOP |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 895 | local GET_INSTALL_PATH= |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 896 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 897 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 898 | for DIR in $DIRS ; do |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 899 | MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'` |
| 900 | if [ "$MODULES" = "" ]; then |
| 901 | MODULES=all_modules |
| 902 | fi |
| 903 | DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 904 | if [ -f $DIR/Android.mk ]; then |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 905 | local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '` |
| 906 | local TO_CHOP=`expr $TO_CHOP + 1` |
| 907 | local START=`PWD= /bin/pwd` |
| 908 | local MFILE=`echo $START | cut -c${TO_CHOP}-` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 909 | if [ "$MFILE" = "" ] ; then |
| 910 | MFILE=$DIR/Android.mk |
| 911 | else |
| 912 | MFILE=$MFILE/$DIR/Android.mk |
| 913 | fi |
| 914 | MAKEFILE="$MAKEFILE $MFILE" |
| 915 | else |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 916 | case $DIR in |
Adrian Roos | afa958f | 2015-03-05 19:52:55 +0100 | [diff] [blame] | 917 | showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";; |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 918 | GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;; |
| 919 | *) echo "No Android.mk in $DIR."; return 1;; |
| 920 | esac |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 921 | fi |
| 922 | done |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 923 | if [ -n "$GET_INSTALL_PATH" ]; then |
| 924 | ARGS=$GET_INSTALL_PATH |
| 925 | MODULES= |
| 926 | fi |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 927 | ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 928 | else |
| 929 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 930 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 931 | fi |
| 932 | } |
| 933 | |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 934 | function mma() |
| 935 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 936 | local T=$(gettop) |
| 937 | local DRV=$(getdriver $T) |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 938 | if [ -f build/core/envsetup.mk -a -f Makefile ]; then |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 939 | $DRV make $@ |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 940 | else |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 941 | if [ ! "$T" ]; then |
| 942 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 943 | return 1 |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 944 | fi |
| 945 | local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'` |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 946 | $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD" |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 947 | fi |
| 948 | } |
| 949 | |
| 950 | function mmma() |
| 951 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 952 | local T=$(gettop) |
| 953 | local DRV=$(getdriver $T) |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 954 | if [ "$T" ]; then |
| 955 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 956 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 957 | local MY_PWD=`PWD= /bin/pwd` |
| 958 | if [ "$MY_PWD" = "$T" ]; then |
| 959 | MY_PWD= |
| 960 | else |
| 961 | MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'` |
| 962 | fi |
| 963 | local DIR= |
| 964 | local MODULE_PATHS= |
| 965 | local ARGS= |
| 966 | for DIR in $DIRS ; do |
| 967 | if [ -d $DIR ]; then |
| 968 | if [ "$MY_PWD" = "" ]; then |
| 969 | MODULE_PATHS="$MODULE_PATHS $DIR" |
| 970 | else |
| 971 | MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR" |
| 972 | fi |
| 973 | else |
| 974 | case $DIR in |
Adrian Roos | afa958f | 2015-03-05 19:52:55 +0100 | [diff] [blame] | 975 | showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";; |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 976 | *) echo "Couldn't find directory $DIR"; return 1;; |
| 977 | esac |
| 978 | fi |
| 979 | done |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 980 | $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS" |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 981 | else |
| 982 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 983 | return 1 |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 984 | fi |
| 985 | } |
| 986 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 987 | function croot() |
| 988 | { |
| 989 | T=$(gettop) |
| 990 | if [ "$T" ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 991 | \cd $(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 992 | else |
| 993 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 994 | fi |
| 995 | } |
| 996 | |
nebkat | fb67a1e | 2012-12-28 10:40:45 +0000 | [diff] [blame] | 997 | function cout() |
| 998 | { |
| 999 | if [ "$OUT" ]; then |
| 1000 | cd $OUT |
| 1001 | else |
| 1002 | echo "Couldn't locate out directory. Try setting OUT." |
| 1003 | fi |
| 1004 | } |
| 1005 | |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 1006 | function cproj() |
| 1007 | { |
| 1008 | TOPFILE=build/core/envsetup.mk |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 1009 | local HERE=$PWD |
| 1010 | T= |
| 1011 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 1012 | T=$PWD |
| 1013 | if [ -f "$T/Android.mk" ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1014 | \cd $T |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 1015 | return |
| 1016 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1017 | \cd .. |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 1018 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1019 | \cd $HERE |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 1020 | echo "can't find Android.mk" |
| 1021 | } |
| 1022 | |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 1023 | # simplified version of ps; output in the form |
| 1024 | # <pid> <procname> |
| 1025 | function qpid() { |
| 1026 | local prepend='' |
| 1027 | local append='' |
| 1028 | if [ "$1" = "--exact" ]; then |
| 1029 | prepend=' ' |
| 1030 | append='$' |
| 1031 | shift |
| 1032 | elif [ "$1" = "--help" -o "$1" = "-h" ]; then |
| 1033 | echo "usage: qpid [[--exact] <process name|pid>" |
| 1034 | return 255 |
| 1035 | fi |
| 1036 | |
| 1037 | local EXE="$1" |
| 1038 | if [ "$EXE" ] ; then |
Mathias Agopian | 4458327 | 2013-08-27 14:15:50 -0700 | [diff] [blame] | 1039 | qpid | \grep "$prepend$EXE$append" |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 1040 | else |
| 1041 | adb shell ps \ |
| 1042 | | tr -d '\r' \ |
| 1043 | | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/' |
| 1044 | fi |
| 1045 | } |
| 1046 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1047 | function pid() |
| 1048 | { |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 1049 | local prepend='' |
| 1050 | local append='' |
| 1051 | if [ "$1" = "--exact" ]; then |
| 1052 | prepend=' ' |
| 1053 | append='$' |
| 1054 | shift |
| 1055 | fi |
| 1056 | local EXE="$1" |
| 1057 | if [ "$EXE" ] ; then |
| 1058 | local PID=`adb shell ps \ |
| 1059 | | tr -d '\r' \ |
Mathias Agopian | 4458327 | 2013-08-27 14:15:50 -0700 | [diff] [blame] | 1060 | | \grep "$prepend$EXE$append" \ |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 1061 | | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'` |
| 1062 | echo "$PID" |
| 1063 | else |
| 1064 | echo "usage: pid [--exact] <process name>" |
| 1065 | return 255 |
| 1066 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Iliyan Malchev | e675cfb | 2014-11-03 17:04:47 -0800 | [diff] [blame] | 1069 | # coredump_setup - enable core dumps globally for any process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1070 | # that has the core-file-size limit set correctly |
| 1071 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1072 | # NOTE: You must call also coredump_enable for a specific process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1073 | # if its core-file-size limit is not set already. |
| 1074 | # NOTE: Core dumps are written to ramdisk; they will not survive a reboot! |
| 1075 | |
Iliyan Malchev | e675cfb | 2014-11-03 17:04:47 -0800 | [diff] [blame] | 1076 | function coredump_setup() |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1077 | { |
| 1078 | echo "Getting root..."; |
| 1079 | adb root; |
| 1080 | adb wait-for-device; |
| 1081 | |
| 1082 | echo "Remounting root parition read-write..."; |
| 1083 | adb shell mount -w -o remount -t rootfs rootfs; |
| 1084 | sleep 1; |
| 1085 | adb wait-for-device; |
| 1086 | adb shell mkdir -p /cores; |
Nick Kralevich | a94282c | 2014-11-04 11:17:20 -0800 | [diff] [blame] | 1087 | adb shell mount -t tmpfs tmpfs /cores; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1088 | adb shell chmod 0777 /cores; |
| 1089 | |
| 1090 | echo "Granting SELinux permission to dump in /cores..."; |
| 1091 | adb shell restorecon -R /cores; |
| 1092 | |
| 1093 | echo "Set core pattern."; |
| 1094 | adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern'; |
| 1095 | |
| 1096 | echo "Done." |
| 1097 | } |
| 1098 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1099 | # coredump_enable - enable core dumps for the specified process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1100 | # $1 = PID of process (e.g., $(pid mediaserver)) |
| 1101 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1102 | # NOTE: coredump_setup must have been called as well for a core |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1103 | # dump to actually be generated. |
| 1104 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1105 | function coredump_enable() |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1106 | { |
| 1107 | local PID=$1; |
| 1108 | if [ -z "$PID" ]; then |
| 1109 | printf "Expecting a PID!\n"; |
| 1110 | return; |
| 1111 | fi; |
| 1112 | echo "Setting core limit for $PID to infinite..."; |
| 1113 | adb shell prlimit $PID 4 -1 -1 |
| 1114 | } |
| 1115 | |
| 1116 | # core - send SIGV and pull the core for process |
| 1117 | # $1 = PID of process (e.g., $(pid mediaserver)) |
| 1118 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1119 | # NOTE: coredump_setup must be called once per boot for core dumps to be |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1120 | # enabled globally. |
| 1121 | |
| 1122 | function core() |
| 1123 | { |
| 1124 | local PID=$1; |
| 1125 | |
| 1126 | if [ -z "$PID" ]; then |
| 1127 | printf "Expecting a PID!\n"; |
| 1128 | return; |
| 1129 | fi; |
| 1130 | |
| 1131 | local CORENAME=core.$PID; |
| 1132 | local COREPATH=/cores/$CORENAME; |
| 1133 | local SIG=SEGV; |
| 1134 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1135 | coredump_enable $1; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1136 | |
| 1137 | local done=0; |
| 1138 | while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do |
| 1139 | printf "\tSending SIG%s to %d...\n" $SIG $PID; |
| 1140 | adb shell kill -$SIG $PID; |
| 1141 | sleep 1; |
| 1142 | done; |
| 1143 | |
| 1144 | adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done" |
| 1145 | echo "Done: core is under $COREPATH on device."; |
| 1146 | } |
| 1147 | |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 1148 | # systemstack - dump the current stack trace of all threads in the system process |
| 1149 | # to the usual ANR traces file |
| 1150 | function systemstack() |
| 1151 | { |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1152 | stacks system_server |
| 1153 | } |
| 1154 | |
| 1155 | function stacks() |
| 1156 | { |
| 1157 | if [[ $1 =~ ^[0-9]+$ ]] ; then |
| 1158 | local PID="$1" |
| 1159 | elif [ "$1" ] ; then |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1160 | local PIDLIST="$(pid $1)" |
| 1161 | if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then |
| 1162 | local PID="$PIDLIST" |
| 1163 | elif [ "$PIDLIST" ] ; then |
| 1164 | echo "more than one process: $1" |
| 1165 | else |
| 1166 | echo "no such process: $1" |
| 1167 | fi |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1168 | else |
| 1169 | echo "usage: stacks [pid|process name]" |
| 1170 | fi |
| 1171 | |
| 1172 | if [ "$PID" ] ; then |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1173 | # Determine whether the process is native |
| 1174 | if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then |
| 1175 | # Dump stacks of Dalvik process |
| 1176 | local TRACES=/data/anr/traces.txt |
| 1177 | local ORIG=/data/anr/traces.orig |
| 1178 | local TMP=/data/anr/traces.tmp |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1179 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1180 | # Keep original traces to avoid clobbering |
| 1181 | adb shell mv $TRACES $ORIG |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1182 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1183 | # Make sure we have a usable file |
| 1184 | adb shell touch $TRACES |
| 1185 | adb shell chmod 666 $TRACES |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1186 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1187 | # Dump stacks and wait for dump to finish |
| 1188 | adb shell kill -3 $PID |
| 1189 | adb shell notify $TRACES >/dev/null |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1190 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1191 | # Restore original stacks, and show current output |
| 1192 | adb shell mv $TRACES $TMP |
| 1193 | adb shell mv $ORIG $TRACES |
| 1194 | adb shell cat $TMP |
| 1195 | else |
| 1196 | # Dump stacks of native process |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 1197 | local USE64BIT="$(is64bit $PID)" |
| 1198 | adb shell debuggerd$USE64BIT -b $PID |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1199 | fi |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1200 | fi |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 1201 | } |
| 1202 | |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 1203 | # Read the ELF header from /proc/$PID/exe to determine if the process is |
| 1204 | # 64-bit. |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 1205 | function is64bit() |
| 1206 | { |
| 1207 | local PID="$1" |
| 1208 | if [ "$PID" ] ; then |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 1209 | if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 1210 | echo "64" |
| 1211 | else |
| 1212 | echo "" |
| 1213 | fi |
| 1214 | else |
| 1215 | echo "" |
| 1216 | fi |
| 1217 | } |
| 1218 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1219 | case `uname -s` in |
| 1220 | Darwin) |
| 1221 | function sgrep() |
| 1222 | { |
Jeff Brown | 46cbd20 | 2014-07-26 15:15:41 -0700 | [diff] [blame] | 1223 | find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | ;; |
| 1227 | *) |
| 1228 | function sgrep() |
| 1229 | { |
Jeff Brown | 46cbd20 | 2014-07-26 15:15:41 -0700 | [diff] [blame] | 1230 | find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\)' -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1231 | } |
| 1232 | ;; |
| 1233 | esac |
| 1234 | |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1235 | function gettargetarch |
| 1236 | { |
| 1237 | get_build_var TARGET_ARCH |
| 1238 | } |
| 1239 | |
Jon Boekenoogen | cbca56f | 2014-04-07 10:57:38 -0700 | [diff] [blame] | 1240 | function ggrep() |
| 1241 | { |
| 1242 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@" |
| 1243 | } |
| 1244 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1245 | function jgrep() |
| 1246 | { |
Anatolii Shuba | 91c72d2 | 2013-07-05 16:09:25 +0300 | [diff] [blame] | 1247 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | function cgrep() |
| 1251 | { |
Dan Albert | 0196119 | 2014-11-22 10:16:01 -0800 | [diff] [blame] | 1252 | 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' \) -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | function resgrep() |
| 1256 | { |
Anatolii Shuba | 91c72d2 | 2013-07-05 16:09:25 +0300 | [diff] [blame] | 1257 | for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
Jeff Sharkey | 50b61e9 | 2013-03-08 10:20:47 -0800 | [diff] [blame] | 1260 | function mangrep() |
| 1261 | { |
| 1262 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@" |
| 1263 | } |
| 1264 | |
Alex Klyubin | ba5fc8e | 2013-05-06 14:11:48 -0700 | [diff] [blame] | 1265 | function sepgrep() |
| 1266 | { |
| 1267 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d -print0 | xargs -0 grep --color -n -r --exclude-dir=\.git "$@" |
| 1268 | } |
| 1269 | |
Jeff Sharkey | ea0068a | 2015-02-26 14:13:46 -0800 | [diff] [blame] | 1270 | function rcgrep() |
| 1271 | { |
| 1272 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@" |
| 1273 | } |
| 1274 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1275 | case `uname -s` in |
| 1276 | Darwin) |
| 1277 | function mgrep() |
| 1278 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 1279 | find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | function treegrep() |
| 1283 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 1284 | find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | ;; |
| 1288 | *) |
| 1289 | function mgrep() |
| 1290 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 1291 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | function treegrep() |
| 1295 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 1296 | find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | ;; |
| 1300 | esac |
| 1301 | |
| 1302 | function getprebuilt |
| 1303 | { |
| 1304 | get_abs_build_var ANDROID_PREBUILTS |
| 1305 | } |
| 1306 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1307 | function tracedmdump() |
| 1308 | { |
| 1309 | T=$(gettop) |
| 1310 | if [ ! "$T" ]; then |
| 1311 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 1312 | return |
| 1313 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1314 | local prebuiltdir=$(getprebuilt) |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1315 | local arch=$(gettargetarch) |
| 1316 | local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1317 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1318 | local TRACE=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1319 | if [ ! "$TRACE" ] ; then |
| 1320 | echo "usage: tracedmdump tracename" |
| 1321 | return |
| 1322 | fi |
| 1323 | |
Jack Veenstra | 60116fc | 2009-04-09 18:12:34 -0700 | [diff] [blame] | 1324 | if [ ! -r "$KERNEL" ] ; then |
| 1325 | echo "Error: cannot find kernel: '$KERNEL'" |
| 1326 | return |
| 1327 | fi |
| 1328 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1329 | local BASETRACE=$(basename $TRACE) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1330 | if [ "$BASETRACE" = "$TRACE" ] ; then |
| 1331 | TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE |
| 1332 | fi |
| 1333 | |
| 1334 | echo "post-processing traces..." |
| 1335 | rm -f $TRACE/qtrace.dexlist |
| 1336 | post_trace $TRACE |
| 1337 | if [ $? -ne 0 ]; then |
| 1338 | echo "***" |
| 1339 | echo "*** Error: malformed trace. Did you remember to exit the emulator?" |
| 1340 | echo "***" |
| 1341 | return |
| 1342 | fi |
| 1343 | echo "generating dexlist output..." |
| 1344 | /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 |
| 1345 | echo "generating dmtrace data..." |
| 1346 | q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return |
| 1347 | echo "generating html file..." |
| 1348 | dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return |
| 1349 | echo "done, see $TRACE/dmtrace.html for details" |
| 1350 | echo "or run:" |
| 1351 | echo " traceview $TRACE/dmtrace" |
| 1352 | } |
| 1353 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1354 | # communicate with a running device or emulator, set up necessary state, |
| 1355 | # and run the hat command. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1356 | function runhat() |
| 1357 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1358 | # process standard adb options |
| 1359 | local adbTarget="" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1360 | if [ "$1" = "-d" -o "$1" = "-e" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1361 | adbTarget=$1 |
| 1362 | shift 1 |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1363 | elif [ "$1" = "-s" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1364 | adbTarget="$1 $2" |
| 1365 | shift 2 |
| 1366 | fi |
| 1367 | local adbOptions=${adbTarget} |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1368 | #echo adbOptions = ${adbOptions} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1369 | |
| 1370 | # runhat options |
| 1371 | local targetPid=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1372 | |
| 1373 | if [ "$targetPid" = "" ]; then |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1374 | echo "Usage: runhat [ -d | -e | -s serial ] target-pid" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1375 | return |
| 1376 | fi |
| 1377 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1378 | # confirm hat is available |
| 1379 | if [ -z $(which hat) ]; then |
| 1380 | echo "hat is not available in this configuration." |
| 1381 | return |
| 1382 | fi |
| 1383 | |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1384 | # issue "am" command to cause the hprof dump |
Nick Kralevich | 9948b1e | 2014-07-18 15:45:38 -0700 | [diff] [blame] | 1385 | local devFile=/data/local/tmp/hprof-$targetPid |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1386 | echo "Poking $targetPid and waiting for data..." |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1387 | echo "Storing data at $devFile" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1388 | adb ${adbOptions} shell am dumpheap $targetPid $devFile |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1389 | echo "Press enter when logcat shows \"hprof: heap dump completed\"" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1390 | echo -n "> " |
| 1391 | read |
| 1392 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1393 | local localFile=/tmp/$$-hprof |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1394 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1395 | echo "Retrieving file $devFile..." |
| 1396 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1397 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1398 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1399 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1400 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1401 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 1402 | echo "" |
Dianne Hackborn | 6e4e1bb | 2011-11-10 15:19:51 -0800 | [diff] [blame] | 1403 | hat -JXmx512m $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | function getbugreports() |
| 1407 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1408 | local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1409 | |
| 1410 | if [ ! "$reports" ]; then |
| 1411 | echo "Could not locate any bugreports." |
| 1412 | return |
| 1413 | fi |
| 1414 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1415 | local report |
| 1416 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1417 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1418 | echo "/sdcard/bugreports/${report}" |
| 1419 | adb pull /sdcard/bugreports/${report} ${report} |
| 1420 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1421 | done |
| 1422 | } |
| 1423 | |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1424 | function getsdcardpath() |
| 1425 | { |
| 1426 | adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} |
| 1427 | } |
| 1428 | |
| 1429 | function getscreenshotpath() |
| 1430 | { |
| 1431 | echo "$(getsdcardpath)/Pictures/Screenshots" |
| 1432 | } |
| 1433 | |
| 1434 | function getlastscreenshot() |
| 1435 | { |
| 1436 | local screenshot_path=$(getscreenshotpath) |
| 1437 | local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1` |
| 1438 | if [ "$screenshot" = "" ]; then |
| 1439 | echo "No screenshots found." |
| 1440 | return |
| 1441 | fi |
| 1442 | echo "${screenshot}" |
| 1443 | adb ${adbOptions} pull ${screenshot_path}/${screenshot} |
| 1444 | } |
| 1445 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1446 | function startviewserver() |
| 1447 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1448 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1449 | if [ $# -gt 0 ]; then |
| 1450 | port=$1 |
| 1451 | fi |
| 1452 | adb shell service call window 1 i32 $port |
| 1453 | } |
| 1454 | |
| 1455 | function stopviewserver() |
| 1456 | { |
| 1457 | adb shell service call window 2 |
| 1458 | } |
| 1459 | |
| 1460 | function isviewserverstarted() |
| 1461 | { |
| 1462 | adb shell service call window 3 |
| 1463 | } |
| 1464 | |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1465 | function key_home() |
| 1466 | { |
| 1467 | adb shell input keyevent 3 |
| 1468 | } |
| 1469 | |
| 1470 | function key_back() |
| 1471 | { |
| 1472 | adb shell input keyevent 4 |
| 1473 | } |
| 1474 | |
| 1475 | function key_menu() |
| 1476 | { |
| 1477 | adb shell input keyevent 82 |
| 1478 | } |
| 1479 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1480 | function smoketest() |
| 1481 | { |
| 1482 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1483 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1484 | return |
| 1485 | fi |
| 1486 | T=$(gettop) |
| 1487 | if [ ! "$T" ]; then |
| 1488 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1489 | return |
| 1490 | fi |
| 1491 | |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1492 | (\cd "$T" && mmm tests/SmokeTest) && |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1493 | adb uninstall com.android.smoketest > /dev/null && |
| 1494 | adb uninstall com.android.smoketest.tests > /dev/null && |
| 1495 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && |
| 1496 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && |
| 1497 | adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner |
| 1498 | } |
| 1499 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1500 | # simple shortcut to the runtest command |
| 1501 | function runtest() |
| 1502 | { |
| 1503 | T=$(gettop) |
| 1504 | if [ ! "$T" ]; then |
| 1505 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1506 | return |
| 1507 | fi |
Brett Chabot | 3fb149d | 2009-10-21 20:05:26 -0700 | [diff] [blame] | 1508 | ("$T"/development/testrunner/runtest.py $@) |
Brett Chabot | 762748c | 2009-03-27 10:25:11 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1511 | function godir () { |
| 1512 | if [[ -z "$1" ]]; then |
| 1513 | echo "Usage: godir <regex>" |
| 1514 | return |
| 1515 | fi |
Brian Carlstrom | b9915a6 | 2010-01-29 16:39:32 -0800 | [diff] [blame] | 1516 | T=$(gettop) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1517 | if [[ ! -f $T/filelist ]]; then |
| 1518 | echo -n "Creating index..." |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1519 | (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1520 | echo " Done" |
| 1521 | echo "" |
| 1522 | fi |
| 1523 | local lines |
Jeff Hamilton | 293f939 | 2011-11-18 17:15:25 -0600 | [diff] [blame] | 1524 | lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1525 | if [[ ${#lines[@]} = 0 ]]; then |
| 1526 | echo "Not found" |
| 1527 | return |
| 1528 | fi |
| 1529 | local pathname |
| 1530 | local choice |
| 1531 | if [[ ${#lines[@]} > 1 ]]; then |
| 1532 | while [[ -z "$pathname" ]]; do |
| 1533 | local index=1 |
| 1534 | local line |
| 1535 | for line in ${lines[@]}; do |
| 1536 | printf "%6s %s\n" "[$index]" $line |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 1537 | index=$(($index + 1)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1538 | done |
| 1539 | echo |
| 1540 | echo -n "Select one: " |
| 1541 | unset choice |
| 1542 | read choice |
| 1543 | if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then |
| 1544 | echo "Invalid choice" |
| 1545 | continue |
| 1546 | fi |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 1547 | pathname=${lines[$(($choice-1))]} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1548 | done |
| 1549 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1550 | pathname=${lines[0]} |
| 1551 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1552 | \cd $T/$pathname |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1553 | } |
| 1554 | |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1555 | function cmremote() |
| 1556 | { |
| 1557 | git remote rm cmremote 2> /dev/null |
Chirayu Desai | f2f15f1 | 2014-12-16 18:22:55 +0530 | [diff] [blame] | 1558 | GERRIT_REMOTE=$(git config --get remote.github.projectname) |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1559 | if [ -z "$GERRIT_REMOTE" ] |
| 1560 | then |
Chirayu Desai | f2f15f1 | 2014-12-16 18:22:55 +0530 | [diff] [blame] | 1561 | echo Unable to set up the git remote, are you under a git repo? |
| 1562 | return 0 |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1563 | fi |
Chirayu Desai | f2f15f1 | 2014-12-16 18:22:55 +0530 | [diff] [blame] | 1564 | CMUSER=$(git config --get review.review.cyanogenmod.org.username) |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1565 | if [ -z "$CMUSER" ] |
| 1566 | then |
Pawit Pornkitprasan | 7bef61f | 2012-12-11 16:41:07 +0700 | [diff] [blame] | 1567 | git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1568 | else |
Pawit Pornkitprasan | 7bef61f | 2012-12-11 16:41:07 +0700 | [diff] [blame] | 1569 | git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1570 | fi |
| 1571 | echo You can now push to "cmremote". |
| 1572 | } |
Koushik Dutta | b55f13a | 2012-05-14 16:14:36 -0700 | [diff] [blame] | 1573 | |
Steve Kondik | 873fa56 | 2012-09-17 11:33:18 -0700 | [diff] [blame] | 1574 | function aospremote() |
| 1575 | { |
| 1576 | git remote rm aosp 2> /dev/null |
| 1577 | if [ ! -d .git ] |
| 1578 | then |
| 1579 | echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up. |
| 1580 | fi |
Steve Kondik | e917827b | 2013-11-16 03:48:30 -0800 | [diff] [blame] | 1581 | PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g` |
Steve Kondik | 873fa56 | 2012-09-17 11:33:18 -0700 | [diff] [blame] | 1582 | if (echo $PROJECT | grep -qv "^device") |
| 1583 | then |
| 1584 | PFX="platform/" |
| 1585 | fi |
| 1586 | git remote add aosp https://android.googlesource.com/$PFX$PROJECT |
| 1587 | echo "Remote 'aosp' created" |
| 1588 | } |
Steve Kondik | 873fa56 | 2012-09-17 11:33:18 -0700 | [diff] [blame] | 1589 | |
Steve Kondik | 20c21d2 | 2013-10-27 13:34:36 -0700 | [diff] [blame] | 1590 | function cafremote() |
| 1591 | { |
| 1592 | git remote rm caf 2> /dev/null |
| 1593 | if [ ! -d .git ] |
| 1594 | then |
| 1595 | echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up. |
| 1596 | fi |
Steve Kondik | e917827b | 2013-11-16 03:48:30 -0800 | [diff] [blame] | 1597 | PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g` |
Steve Kondik | 20c21d2 | 2013-10-27 13:34:36 -0700 | [diff] [blame] | 1598 | if (echo $PROJECT | grep -qv "^device") |
| 1599 | then |
| 1600 | PFX="platform/" |
| 1601 | fi |
| 1602 | git remote add caf git://codeaurora.org/$PFX$PROJECT |
| 1603 | echo "Remote 'caf' created" |
| 1604 | } |
Steve Kondik | 20c21d2 | 2013-10-27 13:34:36 -0700 | [diff] [blame] | 1605 | |
Steve Kondik | f00e7d9 | 2012-09-23 23:46:55 -0700 | [diff] [blame] | 1606 | function installboot() |
| 1607 | { |
| 1608 | if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ]; |
| 1609 | then |
| 1610 | echo "No recovery.fstab found. Build recovery first." |
| 1611 | return 1 |
| 1612 | fi |
| 1613 | if [ ! -e "$OUT/boot.img" ]; |
| 1614 | then |
| 1615 | echo "No boot.img found. Run make bootimage first." |
| 1616 | return 1 |
| 1617 | fi |
| 1618 | PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 1619 | if [ -z "$PARTITION" ]; |
| 1620 | then |
Ricardo Cerqueira | 9e4c4a7 | 2013-07-27 13:51:56 +0100 | [diff] [blame] | 1621 | # Try for RECOVERY_FSTAB_VERSION = 2 |
| 1622 | PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}` |
| 1623 | PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 1624 | if [ -z "$PARTITION" ]; |
| 1625 | then |
| 1626 | echo "Unable to determine boot partition." |
| 1627 | return 1 |
| 1628 | fi |
Steve Kondik | f00e7d9 | 2012-09-23 23:46:55 -0700 | [diff] [blame] | 1629 | fi |
| 1630 | adb start-server |
Steve Kondik | 3bc5cfd | 2013-08-30 17:34:37 -0700 | [diff] [blame] | 1631 | adb wait-for-online |
Steve Kondik | f00e7d9 | 2012-09-23 23:46:55 -0700 | [diff] [blame] | 1632 | adb root |
| 1633 | sleep 1 |
Steve Kondik | 21e4f7f | 2013-04-13 13:23:35 -0700 | [diff] [blame] | 1634 | adb wait-for-online shell mount /system 2>&1 > /dev/null |
| 1635 | adb wait-for-online remount |
Steve Kondik | f00e7d9 | 2012-09-23 23:46:55 -0700 | [diff] [blame] | 1636 | if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD"); |
| 1637 | then |
| 1638 | adb push $OUT/boot.img /cache/ |
| 1639 | for i in $OUT/system/lib/modules/*; |
| 1640 | do |
| 1641 | adb push $i /system/lib/modules/ |
| 1642 | done |
| 1643 | adb shell dd if=/cache/boot.img of=$PARTITION |
| 1644 | adb shell chmod 644 /system/lib/modules/* |
| 1645 | echo "Installation complete." |
| 1646 | else |
| 1647 | echo "The connected device does not appear to be $CM_BUILD, run away!" |
| 1648 | fi |
| 1649 | } |
| 1650 | |
Steve Kondik | 83c03d5 | 2012-10-24 16:40:42 -0700 | [diff] [blame] | 1651 | function installrecovery() |
| 1652 | { |
| 1653 | if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ]; |
| 1654 | then |
| 1655 | echo "No recovery.fstab found. Build recovery first." |
| 1656 | return 1 |
| 1657 | fi |
| 1658 | if [ ! -e "$OUT/recovery.img" ]; |
| 1659 | then |
| 1660 | echo "No recovery.img found. Run make recoveryimage first." |
| 1661 | return 1 |
| 1662 | fi |
| 1663 | PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 1664 | if [ -z "$PARTITION" ]; |
| 1665 | then |
Steve Kondik | 75f1076 | 2013-08-09 21:03:42 -0700 | [diff] [blame] | 1666 | # Try for RECOVERY_FSTAB_VERSION = 2 |
Steve Kondik | d8b510a | 2013-08-10 21:02:09 -0700 | [diff] [blame] | 1667 | PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}` |
| 1668 | PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
Steve Kondik | 75f1076 | 2013-08-09 21:03:42 -0700 | [diff] [blame] | 1669 | if [ -z "$PARTITION" ]; |
| 1670 | then |
| 1671 | echo "Unable to determine recovery partition." |
| 1672 | return 1 |
| 1673 | fi |
Steve Kondik | 83c03d5 | 2012-10-24 16:40:42 -0700 | [diff] [blame] | 1674 | fi |
| 1675 | adb start-server |
Steve Kondik | 3bc5cfd | 2013-08-30 17:34:37 -0700 | [diff] [blame] | 1676 | adb wait-for-online |
Steve Kondik | 83c03d5 | 2012-10-24 16:40:42 -0700 | [diff] [blame] | 1677 | adb root |
| 1678 | sleep 1 |
Steve Kondik | 21e4f7f | 2013-04-13 13:23:35 -0700 | [diff] [blame] | 1679 | adb wait-for-online shell mount /system 2>&1 >> /dev/null |
| 1680 | adb wait-for-online remount |
Steve Kondik | 83c03d5 | 2012-10-24 16:40:42 -0700 | [diff] [blame] | 1681 | if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD"); |
| 1682 | then |
| 1683 | adb push $OUT/recovery.img /cache/ |
| 1684 | adb shell dd if=/cache/recovery.img of=$PARTITION |
| 1685 | echo "Installation complete." |
| 1686 | else |
| 1687 | echo "The connected device does not appear to be $CM_BUILD, run away!" |
| 1688 | fi |
| 1689 | } |
Steve Kondik | f00e7d9 | 2012-09-23 23:46:55 -0700 | [diff] [blame] | 1690 | |
Koushik Dutta | b55f13a | 2012-05-14 16:14:36 -0700 | [diff] [blame] | 1691 | function makerecipe() { |
| 1692 | if [ -z "$1" ] |
| 1693 | then |
| 1694 | echo "No branch name provided." |
| 1695 | return 1 |
| 1696 | fi |
| 1697 | cd android |
| 1698 | sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml |
| 1699 | git commit -a -m "$1" |
| 1700 | cd .. |
| 1701 | |
| 1702 | repo forall -c ' |
| 1703 | |
| 1704 | if [ "$REPO_REMOTE" == "github" ] |
| 1705 | then |
| 1706 | pwd |
| 1707 | cmremote |
| 1708 | git push cmremote HEAD:refs/heads/'$1' |
| 1709 | fi |
| 1710 | ' |
| 1711 | } |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1712 | |
| 1713 | function cmgerrit() { |
| 1714 | if [ $# -eq 0 ]; then |
| 1715 | $FUNCNAME help |
| 1716 | return 1 |
| 1717 | fi |
Pawit Pornkitprasan | 7bef61f | 2012-12-11 16:41:07 +0700 | [diff] [blame] | 1718 | local user=`git config --get review.review.cyanogenmod.org.username` |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1719 | local review=`git config --get remote.github.review` |
| 1720 | local project=`git config --get remote.github.projectname` |
| 1721 | local command=$1 |
| 1722 | shift |
| 1723 | case $command in |
| 1724 | help) |
| 1725 | if [ $# -eq 0 ]; then |
| 1726 | cat <<EOF |
| 1727 | Usage: |
| 1728 | $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS] |
| 1729 | |
| 1730 | Commands: |
| 1731 | fetch Just fetch the change as FETCH_HEAD |
| 1732 | help Show this help, or for a specific command |
| 1733 | pull Pull a change into current branch |
| 1734 | push Push HEAD or a local branch to Gerrit for a specific branch |
| 1735 | |
| 1736 | Any other Git commands that support refname would work as: |
| 1737 | git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS |
| 1738 | |
| 1739 | See '$FUNCNAME help COMMAND' for more information on a specific command. |
| 1740 | |
| 1741 | Example: |
| 1742 | $FUNCNAME checkout -b topic 1234/5 |
| 1743 | works as: |
| 1744 | git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\ |
| 1745 | && git checkout -b topic FETCH_HEAD |
| 1746 | will checkout a new branch 'topic' base on patch-set 5 of change 1234. |
| 1747 | Patch-set 1 will be fetched if omitted. |
| 1748 | EOF |
| 1749 | return |
| 1750 | fi |
| 1751 | case $1 in |
| 1752 | __cmg_*) echo "For internal use only." ;; |
| 1753 | changes|for) |
| 1754 | if [ "$FUNCNAME" = "cmgerrit" ]; then |
| 1755 | echo "'$FUNCNAME $1' is deprecated." |
| 1756 | fi |
| 1757 | ;; |
| 1758 | help) $FUNCNAME help ;; |
| 1759 | fetch|pull) cat <<EOF |
| 1760 | usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET] |
| 1761 | |
| 1762 | works as: |
| 1763 | git $1 OPTIONS http://DOMAIN/p/PROJECT \\ |
| 1764 | refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} |
| 1765 | |
| 1766 | Example: |
| 1767 | $FUNCNAME $1 1234 |
| 1768 | will $1 patch-set 1 of change 1234 |
| 1769 | EOF |
| 1770 | ;; |
| 1771 | push) cat <<EOF |
| 1772 | usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH |
| 1773 | |
| 1774 | works as: |
| 1775 | git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\ |
| 1776 | {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH |
| 1777 | |
| 1778 | Example: |
| 1779 | $FUNCNAME push fix6789:gingerbread |
| 1780 | will push local branch 'fix6789' to Gerrit for branch 'gingerbread'. |
| 1781 | HEAD will be pushed from local if omitted. |
| 1782 | EOF |
| 1783 | ;; |
| 1784 | *) |
| 1785 | $FUNCNAME __cmg_err_not_supported $1 && return |
| 1786 | cat <<EOF |
| 1787 | usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS] |
| 1788 | |
| 1789 | works as: |
| 1790 | git fetch http://DOMAIN/p/PROJECT \\ |
| 1791 | refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\ |
| 1792 | && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS |
| 1793 | EOF |
| 1794 | ;; |
| 1795 | esac |
| 1796 | ;; |
| 1797 | __cmg_get_ref) |
| 1798 | $FUNCNAME __cmg_err_no_arg $command $# && return 1 |
| 1799 | local change_id patchset_id hash |
| 1800 | case $1 in |
| 1801 | */*) |
| 1802 | change_id=${1%%/*} |
| 1803 | patchset_id=${1#*/} |
| 1804 | ;; |
| 1805 | *) |
| 1806 | change_id=$1 |
| 1807 | patchset_id=1 |
| 1808 | ;; |
| 1809 | esac |
| 1810 | hash=$(($change_id % 100)) |
| 1811 | case $hash in |
| 1812 | [0-9]) hash="0$hash" ;; |
| 1813 | esac |
| 1814 | echo "refs/changes/$hash/$change_id/$patchset_id" |
| 1815 | ;; |
| 1816 | fetch|pull) |
| 1817 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 1818 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 1819 | local change=$1 |
| 1820 | shift |
| 1821 | git $command $@ http://$review/p/$project \ |
| 1822 | $($FUNCNAME __cmg_get_ref $change) || return 1 |
| 1823 | ;; |
| 1824 | push) |
| 1825 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 1826 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 1827 | if [ -z "$user" ]; then |
| 1828 | echo >&2 "Gerrit username not found." |
| 1829 | return 1 |
| 1830 | fi |
| 1831 | local local_branch remote_branch |
| 1832 | case $1 in |
| 1833 | *:*) |
| 1834 | local_branch=${1%:*} |
| 1835 | remote_branch=${1##*:} |
| 1836 | ;; |
| 1837 | *) |
| 1838 | local_branch=HEAD |
| 1839 | remote_branch=$1 |
| 1840 | ;; |
| 1841 | esac |
| 1842 | shift |
| 1843 | git push $@ ssh://$user@$review:29418/$project \ |
| 1844 | $local_branch:refs/for/$remote_branch || return 1 |
| 1845 | ;; |
| 1846 | changes|for) |
| 1847 | if [ "$FUNCNAME" = "cmgerrit" ]; then |
| 1848 | echo >&2 "'$FUNCNAME $command' is deprecated." |
| 1849 | fi |
| 1850 | ;; |
| 1851 | __cmg_err_no_arg) |
| 1852 | if [ $# -lt 2 ]; then |
| 1853 | echo >&2 "'$FUNCNAME $command' missing argument." |
| 1854 | elif [ $2 -eq 0 ]; then |
| 1855 | if [ -n "$3" ]; then |
| 1856 | $FUNCNAME help $1 |
| 1857 | else |
| 1858 | echo >&2 "'$FUNCNAME $1' missing argument." |
| 1859 | fi |
| 1860 | else |
| 1861 | return 1 |
| 1862 | fi |
| 1863 | ;; |
| 1864 | __cmg_err_not_repo) |
| 1865 | if [ -z "$review" -o -z "$project" ]; then |
| 1866 | echo >&2 "Not currently in any reviewable repository." |
| 1867 | else |
| 1868 | return 1 |
| 1869 | fi |
| 1870 | ;; |
| 1871 | __cmg_err_not_supported) |
| 1872 | $FUNCNAME __cmg_err_no_arg $command $# && return |
| 1873 | case $1 in |
| 1874 | #TODO: filter more git commands that don't use refname |
| 1875 | init|add|rm|mv|status|clone|remote|bisect|config|stash) |
| 1876 | echo >&2 "'$FUNCNAME $1' is not supported." |
| 1877 | ;; |
| 1878 | *) return 1 ;; |
| 1879 | esac |
| 1880 | ;; |
| 1881 | #TODO: other special cases? |
| 1882 | *) |
| 1883 | $FUNCNAME __cmg_err_not_supported $command && return 1 |
| 1884 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 1885 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 1886 | local args="$@" |
| 1887 | local change pre_args refs_arg post_args |
| 1888 | case "$args" in |
| 1889 | *--\ *) |
| 1890 | pre_args=${args%%-- *} |
| 1891 | post_args="-- ${args#*-- }" |
| 1892 | ;; |
| 1893 | *) pre_args="$args" ;; |
| 1894 | esac |
| 1895 | args=($pre_args) |
| 1896 | pre_args= |
| 1897 | if [ ${#args[@]} -gt 0 ]; then |
| 1898 | change=${args[${#args[@]}-1]} |
| 1899 | fi |
| 1900 | if [ ${#args[@]} -gt 1 ]; then |
| 1901 | pre_args=${args[0]} |
| 1902 | for ((i=1; i<${#args[@]}-1; i++)); do |
| 1903 | pre_args="$pre_args ${args[$i]}" |
| 1904 | done |
| 1905 | fi |
| 1906 | while ((1)); do |
| 1907 | case $change in |
| 1908 | ""|--) |
| 1909 | $FUNCNAME help $command |
| 1910 | return 1 |
| 1911 | ;; |
| 1912 | *@*) |
| 1913 | if [ -z "$refs_arg" ]; then |
| 1914 | refs_arg="@${change#*@}" |
| 1915 | change=${change%%@*} |
| 1916 | fi |
| 1917 | ;; |
| 1918 | *~*) |
| 1919 | if [ -z "$refs_arg" ]; then |
| 1920 | refs_arg="~${change#*~}" |
| 1921 | change=${change%%~*} |
| 1922 | fi |
| 1923 | ;; |
| 1924 | *^*) |
| 1925 | if [ -z "$refs_arg" ]; then |
| 1926 | refs_arg="^${change#*^}" |
| 1927 | change=${change%%^*} |
| 1928 | fi |
| 1929 | ;; |
| 1930 | *:*) |
| 1931 | if [ -z "$refs_arg" ]; then |
| 1932 | refs_arg=":${change#*:}" |
| 1933 | change=${change%%:*} |
| 1934 | fi |
| 1935 | ;; |
| 1936 | *) break ;; |
| 1937 | esac |
| 1938 | done |
| 1939 | $FUNCNAME fetch $change \ |
| 1940 | && git $command $pre_args FETCH_HEAD$refs_arg $post_args \ |
| 1941 | || return 1 |
| 1942 | ;; |
| 1943 | esac |
| 1944 | } |
| 1945 | |
| 1946 | function cmrebase() { |
| 1947 | local repo=$1 |
| 1948 | local refs=$2 |
| 1949 | local pwd="$(pwd)" |
| 1950 | local dir="$(gettop)/$repo" |
| 1951 | |
| 1952 | if [ -z $repo ] || [ -z $refs ]; then |
| 1953 | echo "CyanogenMod Gerrit Rebase Usage: " |
| 1954 | echo " cmrebase <path to project> <patch IDs on Gerrit>" |
| 1955 | echo " The patch IDs appear on the Gerrit commands that are offered." |
| 1956 | echo " They consist on a series of numbers and slashes, after the text" |
| 1957 | echo " refs/changes. For example, the ID in the following command is 26/8126/2" |
| 1958 | echo "" |
| 1959 | echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD" |
| 1960 | echo "" |
| 1961 | return |
| 1962 | fi |
| 1963 | |
| 1964 | if [ ! -d $dir ]; then |
| 1965 | echo "Directory $dir doesn't exist in tree." |
| 1966 | return |
| 1967 | fi |
| 1968 | cd $dir |
| 1969 | repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g) |
| 1970 | echo "Starting branch..." |
| 1971 | repo start tmprebase . |
| 1972 | echo "Bringing it up to date..." |
| 1973 | repo sync . |
| 1974 | echo "Fetching change..." |
Pawit Pornkitprasan | 7bef61f | 2012-12-11 16:41:07 +0700 | [diff] [blame] | 1975 | git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1976 | if [ "$?" != "0" ]; then |
| 1977 | echo "Error cherry-picking. Not uploading!" |
| 1978 | return |
| 1979 | fi |
| 1980 | echo "Uploading..." |
| 1981 | repo upload . |
| 1982 | echo "Cleaning up..." |
| 1983 | repo abandon tmprebase . |
| 1984 | cd $pwd |
| 1985 | } |
| 1986 | |
| 1987 | function mka() { |
| 1988 | case `uname -s` in |
| 1989 | Darwin) |
| 1990 | make -j `sysctl hw.ncpu|cut -d" " -f2` "$@" |
| 1991 | ;; |
| 1992 | *) |
Arnav Gupta | 3b90994 | 2012-11-23 10:47:44 -0700 | [diff] [blame] | 1993 | schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@" |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1994 | ;; |
| 1995 | esac |
| 1996 | } |
| 1997 | |
| 1998 | function reposync() { |
| 1999 | case `uname -s` in |
| 2000 | Darwin) |
| 2001 | repo sync -j 4 "$@" |
| 2002 | ;; |
| 2003 | *) |
Alan Orth | ef363cd | 2012-09-07 11:44:27 +0300 | [diff] [blame] | 2004 | schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@" |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 2005 | ;; |
| 2006 | esac |
| 2007 | } |
Tanguy Pruvot | 2192fd2 | 2012-06-06 21:39:23 +0200 | [diff] [blame] | 2008 | |
| 2009 | function repodiff() { |
| 2010 | if [ -z "$*" ]; then |
| 2011 | echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]" |
| 2012 | return |
| 2013 | fi |
| 2014 | diffopts=$* repo forall -c \ |
| 2015 | 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;' |
| 2016 | } |
| 2017 | |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2018 | # Credit for color strip sed: http://goo.gl/BoIcm |
| 2019 | function dopush() |
| 2020 | { |
| 2021 | local func=$1 |
| 2022 | shift |
| 2023 | |
| 2024 | adb start-server # Prevent unexpected starting server message from adb get-state in the next line |
| 2025 | if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then |
| 2026 | echo "No device is online. Waiting for one..." |
| 2027 | echo "Please connect USB and/or enable USB debugging" |
| 2028 | until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do |
| 2029 | sleep 1 |
| 2030 | done |
| 2031 | echo "Device Found." |
| 2032 | fi |
| 2033 | |
Chirayu Desai | 6dadb57 | 2012-12-26 10:53:58 +0530 | [diff] [blame] | 2034 | if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD"); |
| 2035 | then |
Sam Mortimer | 9e0a3f7 | 2013-08-10 22:57:08 -0700 | [diff] [blame] | 2036 | # retrieve IP and PORT info if we're using a TCP connection |
| 2037 | TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \ |
| 2038 | | head -1 | awk '{print $1}') |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2039 | adb root &> /dev/null |
| 2040 | sleep 0.3 |
Sam Mortimer | 9e0a3f7 | 2013-08-10 22:57:08 -0700 | [diff] [blame] | 2041 | if [ -n "$TCPIPPORT" ] |
| 2042 | then |
| 2043 | # adb root just killed our connection |
| 2044 | # so reconnect... |
| 2045 | adb connect "$TCPIPPORT" |
| 2046 | fi |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2047 | adb wait-for-device &> /dev/null |
| 2048 | sleep 0.3 |
| 2049 | adb remount &> /dev/null |
| 2050 | |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2051 | mkdir -p $OUT |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2052 | $func $* | tee $OUT/.log |
| 2053 | |
| 2054 | # Install: <file> |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2055 | 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)" |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2056 | |
| 2057 | # Copy: <file> |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2058 | 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)" |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2059 | |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2060 | stop_n_start=false |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2061 | for FILE in $LOC; do |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2062 | # Make sure file is in $OUT/system |
| 2063 | case $FILE in |
| 2064 | $OUT/system/*) |
| 2065 | # Get target file name (i.e. /system/bin/adb) |
| 2066 | TARGET=$(echo $FILE | sed "s#$OUT##") |
| 2067 | ;; |
| 2068 | *) continue ;; |
| 2069 | esac |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2070 | |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2071 | case $TARGET in |
Pawit Pornkitprasan | 1822ad0 | 2014-12-22 20:11:47 +0700 | [diff] [blame^] | 2072 | /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*) |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2073 | # Only need to stop services once |
| 2074 | if ! $stop_n_start; then |
| 2075 | adb shell stop |
| 2076 | stop_n_start=true |
| 2077 | fi |
| 2078 | echo "Pushing: $TARGET" |
| 2079 | adb push $FILE $TARGET |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2080 | ;; |
| 2081 | *) |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2082 | echo "Pushing: $TARGET" |
| 2083 | adb push $FILE $TARGET |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2084 | ;; |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2085 | esac |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2086 | done |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2087 | if $stop_n_start; then |
| 2088 | adb shell start |
| 2089 | fi |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2090 | rm -f $OUT/.log |
| 2091 | return 0 |
Chirayu Desai | 6dadb57 | 2012-12-26 10:53:58 +0530 | [diff] [blame] | 2092 | else |
| 2093 | echo "The connected device does not appear to be $CM_BUILD, run away!" |
| 2094 | fi |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | alias mmp='dopush mm' |
| 2098 | alias mmmp='dopush mmm' |
| 2099 | alias mkap='dopush mka' |
| 2100 | alias cmkap='dopush cmka' |
| 2101 | |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 2102 | function repopick() { |
| 2103 | T=$(gettop) |
| 2104 | $T/build/tools/repopick.py $@ |
| 2105 | } |
| 2106 | |
Chirayu Desai | b89b324 | 2013-06-30 10:04:25 +0530 | [diff] [blame] | 2107 | function fixup_common_out_dir() { |
| 2108 | common_out_dir=$(get_build_var OUT_DIR)/target/common |
| 2109 | target_device=$(get_build_var TARGET_DEVICE) |
| 2110 | if [ ! -z $CM_FIXUP_COMMON_OUT ]; then |
| 2111 | if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then |
| 2112 | mv ${common_out_dir} ${common_out_dir}-${target_device} |
| 2113 | ln -s ${common_out_dir}-${target_device} ${common_out_dir} |
| 2114 | else |
| 2115 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 2116 | mkdir -p ${common_out_dir}-${target_device} |
| 2117 | ln -s ${common_out_dir}-${target_device} ${common_out_dir} |
| 2118 | fi |
| 2119 | else |
| 2120 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 2121 | mkdir -p ${common_out_dir} |
| 2122 | fi |
| 2123 | } |
| 2124 | |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 2125 | # Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set. |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 2126 | # |
| 2127 | # Note that the MacOS path for java 1.7 includes a minor revision number (sigh). |
| 2128 | # For some reason, installing the JDK doesn't make it show up in the |
| 2129 | # JavaVM.framework/Versions/1.7/ folder. |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 2130 | function set_java_home() { |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 2131 | # Clear the existing JAVA_HOME value if we set it ourselves, so that |
Narayan Kamath | c84889b | 2014-04-01 14:16:26 +0100 | [diff] [blame] | 2132 | # we can reset it later, depending on the version of java the build |
| 2133 | # system needs. |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 2134 | # |
| 2135 | # If we don't do this, the JAVA_HOME value set by the first call to |
| 2136 | # build/envsetup.sh will persist forever. |
| 2137 | if [ -n "$ANDROID_SET_JAVA_HOME" ]; then |
| 2138 | export JAVA_HOME="" |
| 2139 | fi |
| 2140 | |
Andy McFadden | bd96094 | 2010-06-24 12:52:51 -0700 | [diff] [blame] | 2141 | if [ ! "$JAVA_HOME" ]; then |
Neil Fuller | 46e00ea | 2014-10-16 10:23:03 +0100 | [diff] [blame] | 2142 | case `uname -s` in |
| 2143 | Darwin) |
| 2144 | export JAVA_HOME=$(/usr/libexec/java_home -v 1.7) |
| 2145 | ;; |
| 2146 | *) |
| 2147 | export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 |
| 2148 | ;; |
| 2149 | esac |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 2150 | |
| 2151 | # Keep track of the fact that we set JAVA_HOME ourselves, so that |
| 2152 | # we can change it on the next envsetup.sh, if required. |
| 2153 | export ANDROID_SET_JAVA_HOME=true |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 2154 | fi |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 2155 | } |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 2156 | |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 2157 | # Print colored exit condition |
| 2158 | function pez { |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 2159 | "$@" |
| 2160 | local retval=$? |
| 2161 | if [ $retval -ne 0 ] |
| 2162 | then |
| 2163 | echo -e "\e[0;31mFAILURE\e[00m" |
| 2164 | else |
| 2165 | echo -e "\e[0;32mSUCCESS\e[00m" |
| 2166 | fi |
| 2167 | return $retval |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 2168 | } |
| 2169 | |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 2170 | function get_make_command() |
| 2171 | { |
| 2172 | echo command make |
| 2173 | } |
| 2174 | |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2175 | function make() |
| 2176 | { |
| 2177 | local start_time=$(date +"%s") |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 2178 | $(get_make_command) "$@" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2179 | local ret=$? |
| 2180 | local end_time=$(date +"%s") |
| 2181 | local tdiff=$(($end_time-$start_time)) |
| 2182 | local hours=$(($tdiff / 3600 )) |
| 2183 | local mins=$((($tdiff % 3600) / 60)) |
| 2184 | local secs=$(($tdiff % 60)) |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 2185 | local ncolors=$(tput colors 2>/dev/null) |
| 2186 | if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then |
| 2187 | color_failed="\e[0;31m" |
| 2188 | color_success="\e[0;32m" |
| 2189 | color_reset="\e[00m" |
| 2190 | else |
| 2191 | color_failed="" |
| 2192 | color_success="" |
| 2193 | color_reset="" |
| 2194 | fi |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2195 | echo |
| 2196 | if [ $ret -eq 0 ] ; then |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 2197 | echo -n -e "${color_success}#### make completed successfully " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2198 | else |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 2199 | echo -n -e "${color_failed}#### make failed to build some targets " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2200 | fi |
| 2201 | if [ $hours -gt 0 ] ; then |
| 2202 | printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs |
| 2203 | elif [ $mins -gt 0 ] ; then |
| 2204 | printf "(%02g:%02g (mm:ss))" $mins $secs |
| 2205 | elif [ $secs -gt 0 ] ; then |
| 2206 | printf "(%s seconds)" $secs |
| 2207 | fi |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 2208 | echo -e " ####${color_reset}" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2209 | echo |
| 2210 | return $ret |
| 2211 | } |
| 2212 | |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 2213 | if [ "x$SHELL" != "x/bin/bash" ]; then |
| 2214 | case `ps -o command -p $$` in |
| 2215 | *bash*) |
| 2216 | ;; |
Emilio López | 7ff9caa | 2013-11-03 13:05:43 -0300 | [diff] [blame] | 2217 | *zsh*) |
| 2218 | ;; |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 2219 | *) |
Emilio López | 7ff9caa | 2013-11-03 13:05:43 -0300 | [diff] [blame] | 2220 | echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results" |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 2221 | ;; |
| 2222 | esac |
| 2223 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 2224 | |
| 2225 | # Execute the contents of any vendorsetup.sh files we can find. |
Oleksiy Avramchenko | 15760a8 | 2014-10-06 18:51:58 +0200 | [diff] [blame] | 2226 | for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \ |
| 2227 | `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 2228 | do |
| 2229 | echo "including $f" |
| 2230 | . $f |
| 2231 | done |
| 2232 | unset f |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 2233 | |
Kyle Ladd | 031a0b6 | 2013-09-11 20:43:42 -0400 | [diff] [blame] | 2234 | # Add completions |
| 2235 | check_bash_version && { |
| 2236 | dirs="sdk/bash_completion vendor/cm/bash_completion" |
| 2237 | for dir in $dirs; do |
| 2238 | if [ -d ${dir} ]; then |
| 2239 | for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do |
| 2240 | echo "including $f" |
| 2241 | . $f |
| 2242 | done |
| 2243 | fi |
| 2244 | done |
| 2245 | } |
Chirayu Desai | e1466d6 | 2013-03-19 17:50:37 +0530 | [diff] [blame] | 2246 | |
| 2247 | export ANDROID_BUILD_TOP=$(gettop) |