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