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 | |
Clark Scheff | 75b36a4 | 2014-12-23 13:30:51 -0800 | [diff] [blame] | 1221 | function dddclient() |
| 1222 | { |
| 1223 | local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT) |
| 1224 | local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED) |
| 1225 | local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED) |
| 1226 | local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED) |
| 1227 | local OUT_EXE_SYMBOLS=$(get_symbols_directory) |
| 1228 | local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS) |
| 1229 | local ARCH=$(get_build_var TARGET_ARCH) |
| 1230 | local GDB |
| 1231 | case "$ARCH" in |
| 1232 | arm) GDB=arm-linux-androideabi-gdb;; |
| 1233 | arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;; |
| 1234 | mips|mips64) GDB=mips64el-linux-android-gdb;; |
| 1235 | x86) GDB=x86_64-linux-android-gdb;; |
| 1236 | x86_64) GDB=x86_64-linux-android-gdb;; |
| 1237 | *) echo "Unknown arch $ARCH"; return 1;; |
| 1238 | esac |
| 1239 | |
| 1240 | if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then |
| 1241 | local EXE="$1" |
| 1242 | if [ "$EXE" ] ; then |
| 1243 | EXE=$1 |
| 1244 | if [[ $EXE =~ ^[^/].* ]] ; then |
| 1245 | EXE="system/bin/"$EXE |
| 1246 | fi |
| 1247 | else |
| 1248 | EXE="app_process" |
| 1249 | fi |
| 1250 | |
| 1251 | local PORT="$2" |
| 1252 | if [ "$PORT" ] ; then |
| 1253 | PORT=$2 |
| 1254 | else |
| 1255 | PORT=":5039" |
| 1256 | fi |
| 1257 | |
| 1258 | local PID="$3" |
| 1259 | if [ "$PID" ] ; then |
| 1260 | if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then |
| 1261 | PID=`pid $3` |
| 1262 | if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then |
| 1263 | # that likely didn't work because of returning multiple processes |
| 1264 | # try again, filtering by root processes (don't contain colon) |
| 1265 | PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'` |
| 1266 | if [[ ! "$PID" =~ ^[0-9]+$ ]] |
| 1267 | then |
| 1268 | echo "Couldn't resolve '$3' to single PID" |
| 1269 | return 1 |
| 1270 | else |
| 1271 | echo "" |
| 1272 | echo "WARNING: multiple processes matching '$3' observed, using root process" |
| 1273 | echo "" |
| 1274 | fi |
| 1275 | fi |
| 1276 | fi |
| 1277 | adb forward "tcp$PORT" "tcp$PORT" |
| 1278 | local USE64BIT="$(is64bit $PID)" |
| 1279 | adb shell gdbserver$USE64BIT $PORT --attach $PID & |
| 1280 | sleep 2 |
| 1281 | else |
| 1282 | echo "" |
| 1283 | echo "If you haven't done so already, do this first on the device:" |
| 1284 | echo " gdbserver $PORT /system/bin/$EXE" |
| 1285 | echo " or" |
| 1286 | echo " gdbserver $PORT --attach <PID>" |
| 1287 | echo "" |
| 1288 | fi |
| 1289 | |
| 1290 | OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT |
| 1291 | OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT |
| 1292 | |
| 1293 | echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS" |
| 1294 | echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl" |
| 1295 | echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb" |
| 1296 | echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT" |
| 1297 | # Enable special debugging for ART processes. |
| 1298 | if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then |
| 1299 | echo >> "$OUT_ROOT/gdbclient.cmds" "art-on" |
| 1300 | fi |
| 1301 | echo >>"$OUT_ROOT/gdbclient.cmds" "" |
| 1302 | |
| 1303 | local WHICH_GDB= |
| 1304 | # 64-bit exe found |
| 1305 | if [ "$USE64BIT" != "" ] ; then |
| 1306 | WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64 |
| 1307 | # 32-bit exe / 32-bit platform |
| 1308 | elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then |
| 1309 | WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB |
| 1310 | # 32-bit exe / 64-bit platform |
| 1311 | else |
| 1312 | WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB |
| 1313 | fi |
| 1314 | |
| 1315 | ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE" |
| 1316 | else |
| 1317 | echo "Unable to determine build system output dir." |
| 1318 | fi |
| 1319 | } |
| 1320 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1321 | case `uname -s` in |
| 1322 | Darwin) |
| 1323 | function sgrep() |
| 1324 | { |
Jeff Brown | 46cbd20 | 2014-07-26 15:15:41 -0700 | [diff] [blame] | 1325 | 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] | 1326 | } |
| 1327 | |
| 1328 | ;; |
| 1329 | *) |
| 1330 | function sgrep() |
| 1331 | { |
Jeff Brown | 46cbd20 | 2014-07-26 15:15:41 -0700 | [diff] [blame] | 1332 | 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] | 1333 | } |
| 1334 | ;; |
| 1335 | esac |
| 1336 | |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1337 | function gettargetarch |
| 1338 | { |
| 1339 | get_build_var TARGET_ARCH |
| 1340 | } |
| 1341 | |
Jon Boekenoogen | cbca56f | 2014-04-07 10:57:38 -0700 | [diff] [blame] | 1342 | function ggrep() |
| 1343 | { |
| 1344 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@" |
| 1345 | } |
| 1346 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1347 | function jgrep() |
| 1348 | { |
Anatolii Shuba | 91c72d2 | 2013-07-05 16:09:25 +0300 | [diff] [blame] | 1349 | 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] | 1350 | } |
| 1351 | |
| 1352 | function cgrep() |
| 1353 | { |
Dan Albert | 0196119 | 2014-11-22 10:16:01 -0800 | [diff] [blame] | 1354 | 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] | 1355 | } |
| 1356 | |
| 1357 | function resgrep() |
| 1358 | { |
Anatolii Shuba | 91c72d2 | 2013-07-05 16:09:25 +0300 | [diff] [blame] | 1359 | 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] | 1360 | } |
| 1361 | |
Jeff Sharkey | 50b61e9 | 2013-03-08 10:20:47 -0800 | [diff] [blame] | 1362 | function mangrep() |
| 1363 | { |
| 1364 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@" |
| 1365 | } |
| 1366 | |
Alex Klyubin | ba5fc8e | 2013-05-06 14:11:48 -0700 | [diff] [blame] | 1367 | function sepgrep() |
| 1368 | { |
| 1369 | 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 "$@" |
| 1370 | } |
| 1371 | |
Jeff Sharkey | ea0068a | 2015-02-26 14:13:46 -0800 | [diff] [blame] | 1372 | function rcgrep() |
| 1373 | { |
| 1374 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@" |
| 1375 | } |
| 1376 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1377 | case `uname -s` in |
| 1378 | Darwin) |
| 1379 | function mgrep() |
| 1380 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 1381 | 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] | 1382 | } |
| 1383 | |
| 1384 | function treegrep() |
| 1385 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 1386 | 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] | 1387 | } |
| 1388 | |
| 1389 | ;; |
| 1390 | *) |
| 1391 | function mgrep() |
| 1392 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 1393 | 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] | 1394 | } |
| 1395 | |
| 1396 | function treegrep() |
| 1397 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 1398 | 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] | 1399 | } |
| 1400 | |
| 1401 | ;; |
| 1402 | esac |
| 1403 | |
| 1404 | function getprebuilt |
| 1405 | { |
| 1406 | get_abs_build_var ANDROID_PREBUILTS |
| 1407 | } |
| 1408 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1409 | function tracedmdump() |
| 1410 | { |
| 1411 | T=$(gettop) |
| 1412 | if [ ! "$T" ]; then |
| 1413 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 1414 | return |
| 1415 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1416 | local prebuiltdir=$(getprebuilt) |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1417 | local arch=$(gettargetarch) |
| 1418 | local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1419 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1420 | local TRACE=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1421 | if [ ! "$TRACE" ] ; then |
| 1422 | echo "usage: tracedmdump tracename" |
| 1423 | return |
| 1424 | fi |
| 1425 | |
Jack Veenstra | 60116fc | 2009-04-09 18:12:34 -0700 | [diff] [blame] | 1426 | if [ ! -r "$KERNEL" ] ; then |
| 1427 | echo "Error: cannot find kernel: '$KERNEL'" |
| 1428 | return |
| 1429 | fi |
| 1430 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1431 | local BASETRACE=$(basename $TRACE) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1432 | if [ "$BASETRACE" = "$TRACE" ] ; then |
| 1433 | TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE |
| 1434 | fi |
| 1435 | |
| 1436 | echo "post-processing traces..." |
| 1437 | rm -f $TRACE/qtrace.dexlist |
| 1438 | post_trace $TRACE |
| 1439 | if [ $? -ne 0 ]; then |
| 1440 | echo "***" |
| 1441 | echo "*** Error: malformed trace. Did you remember to exit the emulator?" |
| 1442 | echo "***" |
| 1443 | return |
| 1444 | fi |
| 1445 | echo "generating dexlist output..." |
| 1446 | /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 |
| 1447 | echo "generating dmtrace data..." |
| 1448 | q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return |
| 1449 | echo "generating html file..." |
| 1450 | dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return |
| 1451 | echo "done, see $TRACE/dmtrace.html for details" |
| 1452 | echo "or run:" |
| 1453 | echo " traceview $TRACE/dmtrace" |
| 1454 | } |
| 1455 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1456 | # communicate with a running device or emulator, set up necessary state, |
| 1457 | # and run the hat command. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1458 | function runhat() |
| 1459 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1460 | # process standard adb options |
| 1461 | local adbTarget="" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1462 | if [ "$1" = "-d" -o "$1" = "-e" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1463 | adbTarget=$1 |
| 1464 | shift 1 |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1465 | elif [ "$1" = "-s" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1466 | adbTarget="$1 $2" |
| 1467 | shift 2 |
| 1468 | fi |
| 1469 | local adbOptions=${adbTarget} |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1470 | #echo adbOptions = ${adbOptions} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1471 | |
| 1472 | # runhat options |
| 1473 | local targetPid=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1474 | |
| 1475 | if [ "$targetPid" = "" ]; then |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1476 | echo "Usage: runhat [ -d | -e | -s serial ] target-pid" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1477 | return |
| 1478 | fi |
| 1479 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1480 | # confirm hat is available |
| 1481 | if [ -z $(which hat) ]; then |
| 1482 | echo "hat is not available in this configuration." |
| 1483 | return |
| 1484 | fi |
| 1485 | |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1486 | # issue "am" command to cause the hprof dump |
Nick Kralevich | 9948b1e | 2014-07-18 15:45:38 -0700 | [diff] [blame] | 1487 | local devFile=/data/local/tmp/hprof-$targetPid |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1488 | echo "Poking $targetPid and waiting for data..." |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1489 | echo "Storing data at $devFile" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1490 | adb ${adbOptions} shell am dumpheap $targetPid $devFile |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1491 | 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] | 1492 | echo -n "> " |
| 1493 | read |
| 1494 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1495 | local localFile=/tmp/$$-hprof |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1496 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1497 | echo "Retrieving file $devFile..." |
| 1498 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1499 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1500 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1501 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1502 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1503 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 1504 | echo "" |
Dianne Hackborn | 6e4e1bb | 2011-11-10 15:19:51 -0800 | [diff] [blame] | 1505 | hat -JXmx512m $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | function getbugreports() |
| 1509 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1510 | 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] | 1511 | |
| 1512 | if [ ! "$reports" ]; then |
| 1513 | echo "Could not locate any bugreports." |
| 1514 | return |
| 1515 | fi |
| 1516 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1517 | local report |
| 1518 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1519 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1520 | echo "/sdcard/bugreports/${report}" |
| 1521 | adb pull /sdcard/bugreports/${report} ${report} |
| 1522 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1523 | done |
| 1524 | } |
| 1525 | |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1526 | function getsdcardpath() |
| 1527 | { |
| 1528 | adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} |
| 1529 | } |
| 1530 | |
| 1531 | function getscreenshotpath() |
| 1532 | { |
| 1533 | echo "$(getsdcardpath)/Pictures/Screenshots" |
| 1534 | } |
| 1535 | |
| 1536 | function getlastscreenshot() |
| 1537 | { |
| 1538 | local screenshot_path=$(getscreenshotpath) |
| 1539 | local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1` |
| 1540 | if [ "$screenshot" = "" ]; then |
| 1541 | echo "No screenshots found." |
| 1542 | return |
| 1543 | fi |
| 1544 | echo "${screenshot}" |
| 1545 | adb ${adbOptions} pull ${screenshot_path}/${screenshot} |
| 1546 | } |
| 1547 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1548 | function startviewserver() |
| 1549 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1550 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1551 | if [ $# -gt 0 ]; then |
| 1552 | port=$1 |
| 1553 | fi |
| 1554 | adb shell service call window 1 i32 $port |
| 1555 | } |
| 1556 | |
| 1557 | function stopviewserver() |
| 1558 | { |
| 1559 | adb shell service call window 2 |
| 1560 | } |
| 1561 | |
| 1562 | function isviewserverstarted() |
| 1563 | { |
| 1564 | adb shell service call window 3 |
| 1565 | } |
| 1566 | |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1567 | function key_home() |
| 1568 | { |
| 1569 | adb shell input keyevent 3 |
| 1570 | } |
| 1571 | |
| 1572 | function key_back() |
| 1573 | { |
| 1574 | adb shell input keyevent 4 |
| 1575 | } |
| 1576 | |
| 1577 | function key_menu() |
| 1578 | { |
| 1579 | adb shell input keyevent 82 |
| 1580 | } |
| 1581 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1582 | function smoketest() |
| 1583 | { |
| 1584 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1585 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1586 | return |
| 1587 | fi |
| 1588 | T=$(gettop) |
| 1589 | if [ ! "$T" ]; then |
| 1590 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1591 | return |
| 1592 | fi |
| 1593 | |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1594 | (\cd "$T" && mmm tests/SmokeTest) && |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1595 | adb uninstall com.android.smoketest > /dev/null && |
| 1596 | adb uninstall com.android.smoketest.tests > /dev/null && |
| 1597 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && |
| 1598 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && |
| 1599 | adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner |
| 1600 | } |
| 1601 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1602 | # simple shortcut to the runtest command |
| 1603 | function runtest() |
| 1604 | { |
| 1605 | T=$(gettop) |
| 1606 | if [ ! "$T" ]; then |
| 1607 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1608 | return |
| 1609 | fi |
Brett Chabot | 3fb149d | 2009-10-21 20:05:26 -0700 | [diff] [blame] | 1610 | ("$T"/development/testrunner/runtest.py $@) |
Brett Chabot | 762748c | 2009-03-27 10:25:11 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1613 | function godir () { |
| 1614 | if [[ -z "$1" ]]; then |
| 1615 | echo "Usage: godir <regex>" |
| 1616 | return |
| 1617 | fi |
Brian Carlstrom | b9915a6 | 2010-01-29 16:39:32 -0800 | [diff] [blame] | 1618 | T=$(gettop) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1619 | if [[ ! -f $T/filelist ]]; then |
| 1620 | echo -n "Creating index..." |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1621 | (\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] | 1622 | echo " Done" |
| 1623 | echo "" |
| 1624 | fi |
| 1625 | local lines |
Jeff Hamilton | 293f939 | 2011-11-18 17:15:25 -0600 | [diff] [blame] | 1626 | 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] | 1627 | if [[ ${#lines[@]} = 0 ]]; then |
| 1628 | echo "Not found" |
| 1629 | return |
| 1630 | fi |
| 1631 | local pathname |
| 1632 | local choice |
| 1633 | if [[ ${#lines[@]} > 1 ]]; then |
| 1634 | while [[ -z "$pathname" ]]; do |
| 1635 | local index=1 |
| 1636 | local line |
| 1637 | for line in ${lines[@]}; do |
| 1638 | printf "%6s %s\n" "[$index]" $line |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 1639 | index=$(($index + 1)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1640 | done |
| 1641 | echo |
| 1642 | echo -n "Select one: " |
| 1643 | unset choice |
| 1644 | read choice |
| 1645 | if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then |
| 1646 | echo "Invalid choice" |
| 1647 | continue |
| 1648 | fi |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 1649 | pathname=${lines[$(($choice-1))]} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1650 | done |
| 1651 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1652 | pathname=${lines[0]} |
| 1653 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1654 | \cd $T/$pathname |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1655 | } |
| 1656 | |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1657 | function cmremote() |
| 1658 | { |
| 1659 | git remote rm cmremote 2> /dev/null |
Chirayu Desai | f2f15f1 | 2014-12-16 18:22:55 +0530 | [diff] [blame] | 1660 | GERRIT_REMOTE=$(git config --get remote.github.projectname) |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1661 | if [ -z "$GERRIT_REMOTE" ] |
| 1662 | then |
Chirayu Desai | f2f15f1 | 2014-12-16 18:22:55 +0530 | [diff] [blame] | 1663 | echo Unable to set up the git remote, are you under a git repo? |
| 1664 | return 0 |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1665 | fi |
Chirayu Desai | f2f15f1 | 2014-12-16 18:22:55 +0530 | [diff] [blame] | 1666 | CMUSER=$(git config --get review.review.cyanogenmod.org.username) |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1667 | if [ -z "$CMUSER" ] |
| 1668 | then |
Pawit Pornkitprasan | 7bef61f | 2012-12-11 16:41:07 +0700 | [diff] [blame] | 1669 | git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1670 | else |
Pawit Pornkitprasan | 7bef61f | 2012-12-11 16:41:07 +0700 | [diff] [blame] | 1671 | git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1672 | fi |
| 1673 | echo You can now push to "cmremote". |
| 1674 | } |
Koushik Dutta | b55f13a | 2012-05-14 16:14:36 -0700 | [diff] [blame] | 1675 | |
Steve Kondik | 873fa56 | 2012-09-17 11:33:18 -0700 | [diff] [blame] | 1676 | function aospremote() |
| 1677 | { |
| 1678 | git remote rm aosp 2> /dev/null |
| 1679 | if [ ! -d .git ] |
| 1680 | then |
| 1681 | echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up. |
| 1682 | fi |
Steve Kondik | e917827b | 2013-11-16 03:48:30 -0800 | [diff] [blame] | 1683 | PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g` |
Steve Kondik | 873fa56 | 2012-09-17 11:33:18 -0700 | [diff] [blame] | 1684 | if (echo $PROJECT | grep -qv "^device") |
| 1685 | then |
| 1686 | PFX="platform/" |
| 1687 | fi |
| 1688 | git remote add aosp https://android.googlesource.com/$PFX$PROJECT |
| 1689 | echo "Remote 'aosp' created" |
| 1690 | } |
Steve Kondik | 873fa56 | 2012-09-17 11:33:18 -0700 | [diff] [blame] | 1691 | |
Steve Kondik | 20c21d2 | 2013-10-27 13:34:36 -0700 | [diff] [blame] | 1692 | function cafremote() |
| 1693 | { |
| 1694 | git remote rm caf 2> /dev/null |
| 1695 | if [ ! -d .git ] |
| 1696 | then |
| 1697 | echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up. |
| 1698 | fi |
Steve Kondik | e917827b | 2013-11-16 03:48:30 -0800 | [diff] [blame] | 1699 | PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g` |
Steve Kondik | 20c21d2 | 2013-10-27 13:34:36 -0700 | [diff] [blame] | 1700 | if (echo $PROJECT | grep -qv "^device") |
| 1701 | then |
| 1702 | PFX="platform/" |
| 1703 | fi |
| 1704 | git remote add caf git://codeaurora.org/$PFX$PROJECT |
| 1705 | echo "Remote 'caf' created" |
| 1706 | } |
Steve Kondik | 20c21d2 | 2013-10-27 13:34:36 -0700 | [diff] [blame] | 1707 | |
Steve Kondik | f00e7d9 | 2012-09-23 23:46:55 -0700 | [diff] [blame] | 1708 | function installboot() |
| 1709 | { |
| 1710 | if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ]; |
| 1711 | then |
| 1712 | echo "No recovery.fstab found. Build recovery first." |
| 1713 | return 1 |
| 1714 | fi |
| 1715 | if [ ! -e "$OUT/boot.img" ]; |
| 1716 | then |
| 1717 | echo "No boot.img found. Run make bootimage first." |
| 1718 | return 1 |
| 1719 | fi |
| 1720 | PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 1721 | if [ -z "$PARTITION" ]; |
| 1722 | then |
Ricardo Cerqueira | 9e4c4a7 | 2013-07-27 13:51:56 +0100 | [diff] [blame] | 1723 | # Try for RECOVERY_FSTAB_VERSION = 2 |
| 1724 | PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}` |
| 1725 | PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 1726 | if [ -z "$PARTITION" ]; |
| 1727 | then |
| 1728 | echo "Unable to determine boot partition." |
| 1729 | return 1 |
| 1730 | fi |
Steve Kondik | f00e7d9 | 2012-09-23 23:46:55 -0700 | [diff] [blame] | 1731 | fi |
| 1732 | adb start-server |
Steve Kondik | 3bc5cfd | 2013-08-30 17:34:37 -0700 | [diff] [blame] | 1733 | adb wait-for-online |
Steve Kondik | f00e7d9 | 2012-09-23 23:46:55 -0700 | [diff] [blame] | 1734 | adb root |
| 1735 | sleep 1 |
Steve Kondik | 21e4f7f | 2013-04-13 13:23:35 -0700 | [diff] [blame] | 1736 | adb wait-for-online shell mount /system 2>&1 > /dev/null |
| 1737 | adb wait-for-online remount |
Steve Kondik | f00e7d9 | 2012-09-23 23:46:55 -0700 | [diff] [blame] | 1738 | if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD"); |
| 1739 | then |
| 1740 | adb push $OUT/boot.img /cache/ |
| 1741 | for i in $OUT/system/lib/modules/*; |
| 1742 | do |
| 1743 | adb push $i /system/lib/modules/ |
| 1744 | done |
| 1745 | adb shell dd if=/cache/boot.img of=$PARTITION |
| 1746 | adb shell chmod 644 /system/lib/modules/* |
| 1747 | echo "Installation complete." |
| 1748 | else |
| 1749 | echo "The connected device does not appear to be $CM_BUILD, run away!" |
| 1750 | fi |
| 1751 | } |
| 1752 | |
Steve Kondik | 83c03d5 | 2012-10-24 16:40:42 -0700 | [diff] [blame] | 1753 | function installrecovery() |
| 1754 | { |
| 1755 | if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ]; |
| 1756 | then |
| 1757 | echo "No recovery.fstab found. Build recovery first." |
| 1758 | return 1 |
| 1759 | fi |
| 1760 | if [ ! -e "$OUT/recovery.img" ]; |
| 1761 | then |
| 1762 | echo "No recovery.img found. Run make recoveryimage first." |
| 1763 | return 1 |
| 1764 | fi |
| 1765 | PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 1766 | if [ -z "$PARTITION" ]; |
| 1767 | then |
Steve Kondik | 75f1076 | 2013-08-09 21:03:42 -0700 | [diff] [blame] | 1768 | # Try for RECOVERY_FSTAB_VERSION = 2 |
Steve Kondik | d8b510a | 2013-08-10 21:02:09 -0700 | [diff] [blame] | 1769 | PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}` |
| 1770 | 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] | 1771 | if [ -z "$PARTITION" ]; |
| 1772 | then |
| 1773 | echo "Unable to determine recovery partition." |
| 1774 | return 1 |
| 1775 | fi |
Steve Kondik | 83c03d5 | 2012-10-24 16:40:42 -0700 | [diff] [blame] | 1776 | fi |
| 1777 | adb start-server |
Steve Kondik | 3bc5cfd | 2013-08-30 17:34:37 -0700 | [diff] [blame] | 1778 | adb wait-for-online |
Steve Kondik | 83c03d5 | 2012-10-24 16:40:42 -0700 | [diff] [blame] | 1779 | adb root |
| 1780 | sleep 1 |
Steve Kondik | 21e4f7f | 2013-04-13 13:23:35 -0700 | [diff] [blame] | 1781 | adb wait-for-online shell mount /system 2>&1 >> /dev/null |
| 1782 | adb wait-for-online remount |
Steve Kondik | 83c03d5 | 2012-10-24 16:40:42 -0700 | [diff] [blame] | 1783 | if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD"); |
| 1784 | then |
| 1785 | adb push $OUT/recovery.img /cache/ |
| 1786 | adb shell dd if=/cache/recovery.img of=$PARTITION |
| 1787 | echo "Installation complete." |
| 1788 | else |
| 1789 | echo "The connected device does not appear to be $CM_BUILD, run away!" |
| 1790 | fi |
| 1791 | } |
Steve Kondik | f00e7d9 | 2012-09-23 23:46:55 -0700 | [diff] [blame] | 1792 | |
Koushik Dutta | b55f13a | 2012-05-14 16:14:36 -0700 | [diff] [blame] | 1793 | function makerecipe() { |
| 1794 | if [ -z "$1" ] |
| 1795 | then |
| 1796 | echo "No branch name provided." |
| 1797 | return 1 |
| 1798 | fi |
| 1799 | cd android |
| 1800 | sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml |
| 1801 | git commit -a -m "$1" |
| 1802 | cd .. |
| 1803 | |
| 1804 | repo forall -c ' |
| 1805 | |
| 1806 | if [ "$REPO_REMOTE" == "github" ] |
| 1807 | then |
| 1808 | pwd |
| 1809 | cmremote |
| 1810 | git push cmremote HEAD:refs/heads/'$1' |
| 1811 | fi |
| 1812 | ' |
| 1813 | } |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1814 | |
| 1815 | function cmgerrit() { |
| 1816 | if [ $# -eq 0 ]; then |
| 1817 | $FUNCNAME help |
| 1818 | return 1 |
| 1819 | fi |
Pawit Pornkitprasan | 7bef61f | 2012-12-11 16:41:07 +0700 | [diff] [blame] | 1820 | local user=`git config --get review.review.cyanogenmod.org.username` |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 1821 | local review=`git config --get remote.github.review` |
| 1822 | local project=`git config --get remote.github.projectname` |
| 1823 | local command=$1 |
| 1824 | shift |
| 1825 | case $command in |
| 1826 | help) |
| 1827 | if [ $# -eq 0 ]; then |
| 1828 | cat <<EOF |
| 1829 | Usage: |
| 1830 | $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS] |
| 1831 | |
| 1832 | Commands: |
| 1833 | fetch Just fetch the change as FETCH_HEAD |
| 1834 | help Show this help, or for a specific command |
| 1835 | pull Pull a change into current branch |
| 1836 | push Push HEAD or a local branch to Gerrit for a specific branch |
| 1837 | |
| 1838 | Any other Git commands that support refname would work as: |
| 1839 | git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS |
| 1840 | |
| 1841 | See '$FUNCNAME help COMMAND' for more information on a specific command. |
| 1842 | |
| 1843 | Example: |
| 1844 | $FUNCNAME checkout -b topic 1234/5 |
| 1845 | works as: |
| 1846 | git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\ |
| 1847 | && git checkout -b topic FETCH_HEAD |
| 1848 | will checkout a new branch 'topic' base on patch-set 5 of change 1234. |
| 1849 | Patch-set 1 will be fetched if omitted. |
| 1850 | EOF |
| 1851 | return |
| 1852 | fi |
| 1853 | case $1 in |
| 1854 | __cmg_*) echo "For internal use only." ;; |
| 1855 | changes|for) |
| 1856 | if [ "$FUNCNAME" = "cmgerrit" ]; then |
| 1857 | echo "'$FUNCNAME $1' is deprecated." |
| 1858 | fi |
| 1859 | ;; |
| 1860 | help) $FUNCNAME help ;; |
| 1861 | fetch|pull) cat <<EOF |
| 1862 | usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET] |
| 1863 | |
| 1864 | works as: |
| 1865 | git $1 OPTIONS http://DOMAIN/p/PROJECT \\ |
| 1866 | refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} |
| 1867 | |
| 1868 | Example: |
| 1869 | $FUNCNAME $1 1234 |
| 1870 | will $1 patch-set 1 of change 1234 |
| 1871 | EOF |
| 1872 | ;; |
| 1873 | push) cat <<EOF |
| 1874 | usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH |
| 1875 | |
| 1876 | works as: |
| 1877 | git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\ |
| 1878 | {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH |
| 1879 | |
| 1880 | Example: |
| 1881 | $FUNCNAME push fix6789:gingerbread |
| 1882 | will push local branch 'fix6789' to Gerrit for branch 'gingerbread'. |
| 1883 | HEAD will be pushed from local if omitted. |
| 1884 | EOF |
| 1885 | ;; |
| 1886 | *) |
| 1887 | $FUNCNAME __cmg_err_not_supported $1 && return |
| 1888 | cat <<EOF |
| 1889 | usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS] |
| 1890 | |
| 1891 | works as: |
| 1892 | git fetch http://DOMAIN/p/PROJECT \\ |
| 1893 | refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\ |
| 1894 | && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS |
| 1895 | EOF |
| 1896 | ;; |
| 1897 | esac |
| 1898 | ;; |
| 1899 | __cmg_get_ref) |
| 1900 | $FUNCNAME __cmg_err_no_arg $command $# && return 1 |
| 1901 | local change_id patchset_id hash |
| 1902 | case $1 in |
| 1903 | */*) |
| 1904 | change_id=${1%%/*} |
| 1905 | patchset_id=${1#*/} |
| 1906 | ;; |
| 1907 | *) |
| 1908 | change_id=$1 |
| 1909 | patchset_id=1 |
| 1910 | ;; |
| 1911 | esac |
| 1912 | hash=$(($change_id % 100)) |
| 1913 | case $hash in |
| 1914 | [0-9]) hash="0$hash" ;; |
| 1915 | esac |
| 1916 | echo "refs/changes/$hash/$change_id/$patchset_id" |
| 1917 | ;; |
| 1918 | fetch|pull) |
| 1919 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 1920 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 1921 | local change=$1 |
| 1922 | shift |
| 1923 | git $command $@ http://$review/p/$project \ |
| 1924 | $($FUNCNAME __cmg_get_ref $change) || return 1 |
| 1925 | ;; |
| 1926 | push) |
| 1927 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 1928 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 1929 | if [ -z "$user" ]; then |
| 1930 | echo >&2 "Gerrit username not found." |
| 1931 | return 1 |
| 1932 | fi |
| 1933 | local local_branch remote_branch |
| 1934 | case $1 in |
| 1935 | *:*) |
| 1936 | local_branch=${1%:*} |
| 1937 | remote_branch=${1##*:} |
| 1938 | ;; |
| 1939 | *) |
| 1940 | local_branch=HEAD |
| 1941 | remote_branch=$1 |
| 1942 | ;; |
| 1943 | esac |
| 1944 | shift |
| 1945 | git push $@ ssh://$user@$review:29418/$project \ |
| 1946 | $local_branch:refs/for/$remote_branch || return 1 |
| 1947 | ;; |
| 1948 | changes|for) |
| 1949 | if [ "$FUNCNAME" = "cmgerrit" ]; then |
| 1950 | echo >&2 "'$FUNCNAME $command' is deprecated." |
| 1951 | fi |
| 1952 | ;; |
| 1953 | __cmg_err_no_arg) |
| 1954 | if [ $# -lt 2 ]; then |
| 1955 | echo >&2 "'$FUNCNAME $command' missing argument." |
| 1956 | elif [ $2 -eq 0 ]; then |
| 1957 | if [ -n "$3" ]; then |
| 1958 | $FUNCNAME help $1 |
| 1959 | else |
| 1960 | echo >&2 "'$FUNCNAME $1' missing argument." |
| 1961 | fi |
| 1962 | else |
| 1963 | return 1 |
| 1964 | fi |
| 1965 | ;; |
| 1966 | __cmg_err_not_repo) |
| 1967 | if [ -z "$review" -o -z "$project" ]; then |
| 1968 | echo >&2 "Not currently in any reviewable repository." |
| 1969 | else |
| 1970 | return 1 |
| 1971 | fi |
| 1972 | ;; |
| 1973 | __cmg_err_not_supported) |
| 1974 | $FUNCNAME __cmg_err_no_arg $command $# && return |
| 1975 | case $1 in |
| 1976 | #TODO: filter more git commands that don't use refname |
| 1977 | init|add|rm|mv|status|clone|remote|bisect|config|stash) |
| 1978 | echo >&2 "'$FUNCNAME $1' is not supported." |
| 1979 | ;; |
| 1980 | *) return 1 ;; |
| 1981 | esac |
| 1982 | ;; |
| 1983 | #TODO: other special cases? |
| 1984 | *) |
| 1985 | $FUNCNAME __cmg_err_not_supported $command && return 1 |
| 1986 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 1987 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 1988 | local args="$@" |
| 1989 | local change pre_args refs_arg post_args |
| 1990 | case "$args" in |
| 1991 | *--\ *) |
| 1992 | pre_args=${args%%-- *} |
| 1993 | post_args="-- ${args#*-- }" |
| 1994 | ;; |
| 1995 | *) pre_args="$args" ;; |
| 1996 | esac |
| 1997 | args=($pre_args) |
| 1998 | pre_args= |
| 1999 | if [ ${#args[@]} -gt 0 ]; then |
| 2000 | change=${args[${#args[@]}-1]} |
| 2001 | fi |
| 2002 | if [ ${#args[@]} -gt 1 ]; then |
| 2003 | pre_args=${args[0]} |
| 2004 | for ((i=1; i<${#args[@]}-1; i++)); do |
| 2005 | pre_args="$pre_args ${args[$i]}" |
| 2006 | done |
| 2007 | fi |
| 2008 | while ((1)); do |
| 2009 | case $change in |
| 2010 | ""|--) |
| 2011 | $FUNCNAME help $command |
| 2012 | return 1 |
| 2013 | ;; |
| 2014 | *@*) |
| 2015 | if [ -z "$refs_arg" ]; then |
| 2016 | refs_arg="@${change#*@}" |
| 2017 | change=${change%%@*} |
| 2018 | fi |
| 2019 | ;; |
| 2020 | *~*) |
| 2021 | if [ -z "$refs_arg" ]; then |
| 2022 | refs_arg="~${change#*~}" |
| 2023 | change=${change%%~*} |
| 2024 | fi |
| 2025 | ;; |
| 2026 | *^*) |
| 2027 | if [ -z "$refs_arg" ]; then |
| 2028 | refs_arg="^${change#*^}" |
| 2029 | change=${change%%^*} |
| 2030 | fi |
| 2031 | ;; |
| 2032 | *:*) |
| 2033 | if [ -z "$refs_arg" ]; then |
| 2034 | refs_arg=":${change#*:}" |
| 2035 | change=${change%%:*} |
| 2036 | fi |
| 2037 | ;; |
| 2038 | *) break ;; |
| 2039 | esac |
| 2040 | done |
| 2041 | $FUNCNAME fetch $change \ |
| 2042 | && git $command $pre_args FETCH_HEAD$refs_arg $post_args \ |
| 2043 | || return 1 |
| 2044 | ;; |
| 2045 | esac |
| 2046 | } |
| 2047 | |
| 2048 | function cmrebase() { |
| 2049 | local repo=$1 |
| 2050 | local refs=$2 |
| 2051 | local pwd="$(pwd)" |
| 2052 | local dir="$(gettop)/$repo" |
| 2053 | |
| 2054 | if [ -z $repo ] || [ -z $refs ]; then |
| 2055 | echo "CyanogenMod Gerrit Rebase Usage: " |
| 2056 | echo " cmrebase <path to project> <patch IDs on Gerrit>" |
| 2057 | echo " The patch IDs appear on the Gerrit commands that are offered." |
| 2058 | echo " They consist on a series of numbers and slashes, after the text" |
| 2059 | echo " refs/changes. For example, the ID in the following command is 26/8126/2" |
| 2060 | echo "" |
| 2061 | echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD" |
| 2062 | echo "" |
| 2063 | return |
| 2064 | fi |
| 2065 | |
| 2066 | if [ ! -d $dir ]; then |
| 2067 | echo "Directory $dir doesn't exist in tree." |
| 2068 | return |
| 2069 | fi |
| 2070 | cd $dir |
| 2071 | repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g) |
| 2072 | echo "Starting branch..." |
| 2073 | repo start tmprebase . |
| 2074 | echo "Bringing it up to date..." |
| 2075 | repo sync . |
| 2076 | echo "Fetching change..." |
Pawit Pornkitprasan | 7bef61f | 2012-12-11 16:41:07 +0700 | [diff] [blame] | 2077 | 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] | 2078 | if [ "$?" != "0" ]; then |
| 2079 | echo "Error cherry-picking. Not uploading!" |
| 2080 | return |
| 2081 | fi |
| 2082 | echo "Uploading..." |
| 2083 | repo upload . |
| 2084 | echo "Cleaning up..." |
| 2085 | repo abandon tmprebase . |
| 2086 | cd $pwd |
| 2087 | } |
| 2088 | |
| 2089 | function mka() { |
| 2090 | case `uname -s` in |
| 2091 | Darwin) |
| 2092 | make -j `sysctl hw.ncpu|cut -d" " -f2` "$@" |
| 2093 | ;; |
| 2094 | *) |
Arnav Gupta | 3b90994 | 2012-11-23 10:47:44 -0700 | [diff] [blame] | 2095 | 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] | 2096 | ;; |
| 2097 | esac |
| 2098 | } |
| 2099 | |
Chirayu Desai | cf2bdb6 | 2012-09-28 11:56:02 +0530 | [diff] [blame] | 2100 | function cmka() { |
| 2101 | if [ ! -z "$1" ]; then |
| 2102 | for i in "$@"; do |
| 2103 | case $i in |
| 2104 | bacon|otapackage|systemimage) |
| 2105 | mka installclean |
| 2106 | mka $i |
| 2107 | ;; |
| 2108 | *) |
| 2109 | mka clean-$i |
| 2110 | mka $i |
| 2111 | ;; |
| 2112 | esac |
| 2113 | done |
| 2114 | else |
| 2115 | mka clean |
| 2116 | mka |
| 2117 | fi |
| 2118 | } |
| 2119 | |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 2120 | function reposync() { |
| 2121 | case `uname -s` in |
| 2122 | Darwin) |
| 2123 | repo sync -j 4 "$@" |
| 2124 | ;; |
| 2125 | *) |
Alan Orth | ef363cd | 2012-09-07 11:44:27 +0300 | [diff] [blame] | 2126 | 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] | 2127 | ;; |
| 2128 | esac |
| 2129 | } |
Tanguy Pruvot | 2192fd2 | 2012-06-06 21:39:23 +0200 | [diff] [blame] | 2130 | |
| 2131 | function repodiff() { |
| 2132 | if [ -z "$*" ]; then |
| 2133 | echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]" |
| 2134 | return |
| 2135 | fi |
| 2136 | diffopts=$* repo forall -c \ |
| 2137 | 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;' |
| 2138 | } |
| 2139 | |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2140 | # Credit for color strip sed: http://goo.gl/BoIcm |
| 2141 | function dopush() |
| 2142 | { |
| 2143 | local func=$1 |
| 2144 | shift |
| 2145 | |
| 2146 | adb start-server # Prevent unexpected starting server message from adb get-state in the next line |
| 2147 | if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then |
| 2148 | echo "No device is online. Waiting for one..." |
| 2149 | echo "Please connect USB and/or enable USB debugging" |
| 2150 | until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do |
| 2151 | sleep 1 |
| 2152 | done |
| 2153 | echo "Device Found." |
| 2154 | fi |
| 2155 | |
Chirayu Desai | 6dadb57 | 2012-12-26 10:53:58 +0530 | [diff] [blame] | 2156 | if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD"); |
| 2157 | then |
Sam Mortimer | 9e0a3f7 | 2013-08-10 22:57:08 -0700 | [diff] [blame] | 2158 | # retrieve IP and PORT info if we're using a TCP connection |
| 2159 | TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \ |
| 2160 | | head -1 | awk '{print $1}') |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2161 | adb root &> /dev/null |
| 2162 | sleep 0.3 |
Sam Mortimer | 9e0a3f7 | 2013-08-10 22:57:08 -0700 | [diff] [blame] | 2163 | if [ -n "$TCPIPPORT" ] |
| 2164 | then |
| 2165 | # adb root just killed our connection |
| 2166 | # so reconnect... |
| 2167 | adb connect "$TCPIPPORT" |
| 2168 | fi |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2169 | adb wait-for-device &> /dev/null |
| 2170 | sleep 0.3 |
| 2171 | adb remount &> /dev/null |
| 2172 | |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2173 | mkdir -p $OUT |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2174 | $func $* | tee $OUT/.log |
| 2175 | |
| 2176 | # Install: <file> |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2177 | 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] | 2178 | |
| 2179 | # Copy: <file> |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2180 | 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] | 2181 | |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2182 | stop_n_start=false |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2183 | for FILE in $LOC; do |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2184 | # Make sure file is in $OUT/system |
| 2185 | case $FILE in |
| 2186 | $OUT/system/*) |
| 2187 | # Get target file name (i.e. /system/bin/adb) |
| 2188 | TARGET=$(echo $FILE | sed "s#$OUT##") |
| 2189 | ;; |
| 2190 | *) continue ;; |
| 2191 | esac |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2192 | |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2193 | case $TARGET in |
Pawit Pornkitprasan | 1822ad0 | 2014-12-22 20:11:47 +0700 | [diff] [blame] | 2194 | /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*) |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2195 | # Only need to stop services once |
| 2196 | if ! $stop_n_start; then |
| 2197 | adb shell stop |
| 2198 | stop_n_start=true |
| 2199 | fi |
| 2200 | echo "Pushing: $TARGET" |
| 2201 | adb push $FILE $TARGET |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2202 | ;; |
| 2203 | *) |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2204 | echo "Pushing: $TARGET" |
| 2205 | adb push $FILE $TARGET |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2206 | ;; |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2207 | esac |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2208 | done |
Matt Mower | 668ea26 | 2014-05-20 02:52:23 -0500 | [diff] [blame] | 2209 | if $stop_n_start; then |
| 2210 | adb shell start |
| 2211 | fi |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2212 | rm -f $OUT/.log |
| 2213 | return 0 |
Chirayu Desai | 6dadb57 | 2012-12-26 10:53:58 +0530 | [diff] [blame] | 2214 | else |
| 2215 | echo "The connected device does not appear to be $CM_BUILD, run away!" |
| 2216 | fi |
Chirayu Desai | ae7a4d0 | 2012-10-16 19:40:18 +0530 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | alias mmp='dopush mm' |
| 2220 | alias mmmp='dopush mmm' |
| 2221 | alias mkap='dopush mka' |
| 2222 | alias cmkap='dopush cmka' |
| 2223 | |
Chirayu Desai | 4a319b8 | 2013-06-05 20:14:33 +0530 | [diff] [blame] | 2224 | function repopick() { |
| 2225 | T=$(gettop) |
| 2226 | $T/build/tools/repopick.py $@ |
| 2227 | } |
| 2228 | |
Chirayu Desai | b89b324 | 2013-06-30 10:04:25 +0530 | [diff] [blame] | 2229 | function fixup_common_out_dir() { |
| 2230 | common_out_dir=$(get_build_var OUT_DIR)/target/common |
| 2231 | target_device=$(get_build_var TARGET_DEVICE) |
| 2232 | if [ ! -z $CM_FIXUP_COMMON_OUT ]; then |
| 2233 | if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then |
| 2234 | mv ${common_out_dir} ${common_out_dir}-${target_device} |
| 2235 | ln -s ${common_out_dir}-${target_device} ${common_out_dir} |
| 2236 | else |
| 2237 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 2238 | mkdir -p ${common_out_dir}-${target_device} |
| 2239 | ln -s ${common_out_dir}-${target_device} ${common_out_dir} |
| 2240 | fi |
| 2241 | else |
| 2242 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 2243 | mkdir -p ${common_out_dir} |
| 2244 | fi |
| 2245 | } |
| 2246 | |
Andrew Sutherland | d6bd065 | 2011-11-18 00:45:55 -0600 | [diff] [blame] | 2247 | # 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] | 2248 | # |
| 2249 | # Note that the MacOS path for java 1.7 includes a minor revision number (sigh). |
| 2250 | # For some reason, installing the JDK doesn't make it show up in the |
| 2251 | # JavaVM.framework/Versions/1.7/ folder. |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 2252 | function set_java_home() { |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 2253 | # 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] | 2254 | # we can reset it later, depending on the version of java the build |
| 2255 | # system needs. |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 2256 | # |
| 2257 | # If we don't do this, the JAVA_HOME value set by the first call to |
| 2258 | # build/envsetup.sh will persist forever. |
| 2259 | if [ -n "$ANDROID_SET_JAVA_HOME" ]; then |
| 2260 | export JAVA_HOME="" |
| 2261 | fi |
| 2262 | |
Andy McFadden | bd96094 | 2010-06-24 12:52:51 -0700 | [diff] [blame] | 2263 | if [ ! "$JAVA_HOME" ]; then |
Neil Fuller | 46e00ea | 2014-10-16 10:23:03 +0100 | [diff] [blame] | 2264 | case `uname -s` in |
| 2265 | Darwin) |
| 2266 | export JAVA_HOME=$(/usr/libexec/java_home -v 1.7) |
| 2267 | ;; |
| 2268 | *) |
| 2269 | export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 |
| 2270 | ;; |
| 2271 | esac |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 2272 | |
| 2273 | # Keep track of the fact that we set JAVA_HOME ourselves, so that |
| 2274 | # we can change it on the next envsetup.sh, if required. |
| 2275 | export ANDROID_SET_JAVA_HOME=true |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 2276 | fi |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 2277 | } |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 2278 | |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 2279 | # Print colored exit condition |
| 2280 | function pez { |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 2281 | "$@" |
| 2282 | local retval=$? |
| 2283 | if [ $retval -ne 0 ] |
| 2284 | then |
| 2285 | echo -e "\e[0;31mFAILURE\e[00m" |
| 2286 | else |
| 2287 | echo -e "\e[0;32mSUCCESS\e[00m" |
| 2288 | fi |
| 2289 | return $retval |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 2290 | } |
| 2291 | |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 2292 | function get_make_command() |
| 2293 | { |
| 2294 | echo command make |
| 2295 | } |
| 2296 | |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2297 | function make() |
| 2298 | { |
| 2299 | local start_time=$(date +"%s") |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 2300 | $(get_make_command) "$@" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2301 | local ret=$? |
| 2302 | local end_time=$(date +"%s") |
| 2303 | local tdiff=$(($end_time-$start_time)) |
| 2304 | local hours=$(($tdiff / 3600 )) |
| 2305 | local mins=$((($tdiff % 3600) / 60)) |
| 2306 | local secs=$(($tdiff % 60)) |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 2307 | local ncolors=$(tput colors 2>/dev/null) |
| 2308 | if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then |
| 2309 | color_failed="\e[0;31m" |
| 2310 | color_success="\e[0;32m" |
| 2311 | color_reset="\e[00m" |
| 2312 | else |
| 2313 | color_failed="" |
| 2314 | color_success="" |
| 2315 | color_reset="" |
| 2316 | fi |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2317 | echo |
| 2318 | if [ $ret -eq 0 ] ; then |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 2319 | echo -n -e "${color_success}#### make completed successfully " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2320 | else |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 2321 | echo -n -e "${color_failed}#### make failed to build some targets " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2322 | fi |
| 2323 | if [ $hours -gt 0 ] ; then |
| 2324 | printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs |
| 2325 | elif [ $mins -gt 0 ] ; then |
| 2326 | printf "(%02g:%02g (mm:ss))" $mins $secs |
| 2327 | elif [ $secs -gt 0 ] ; then |
| 2328 | printf "(%s seconds)" $secs |
| 2329 | fi |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 2330 | echo -e " ####${color_reset}" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 2331 | echo |
| 2332 | return $ret |
| 2333 | } |
| 2334 | |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 2335 | if [ "x$SHELL" != "x/bin/bash" ]; then |
| 2336 | case `ps -o command -p $$` in |
| 2337 | *bash*) |
| 2338 | ;; |
Emilio López | 7ff9caa | 2013-11-03 13:05:43 -0300 | [diff] [blame] | 2339 | *zsh*) |
| 2340 | ;; |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 2341 | *) |
Emilio López | 7ff9caa | 2013-11-03 13:05:43 -0300 | [diff] [blame] | 2342 | 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] | 2343 | ;; |
| 2344 | esac |
| 2345 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 2346 | |
| 2347 | # Execute the contents of any vendorsetup.sh files we can find. |
Oleksiy Avramchenko | 15760a8 | 2014-10-06 18:51:58 +0200 | [diff] [blame] | 2348 | for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \ |
| 2349 | `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] | 2350 | do |
| 2351 | echo "including $f" |
| 2352 | . $f |
| 2353 | done |
| 2354 | unset f |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 2355 | |
Kyle Ladd | 031a0b6 | 2013-09-11 20:43:42 -0400 | [diff] [blame] | 2356 | # Add completions |
| 2357 | check_bash_version && { |
| 2358 | dirs="sdk/bash_completion vendor/cm/bash_completion" |
| 2359 | for dir in $dirs; do |
| 2360 | if [ -d ${dir} ]; then |
| 2361 | for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do |
| 2362 | echo "including $f" |
| 2363 | . $f |
| 2364 | done |
| 2365 | fi |
| 2366 | done |
| 2367 | } |
Chirayu Desai | e1466d6 | 2013-03-19 17:50:37 +0530 | [diff] [blame] | 2368 | |
| 2369 | export ANDROID_BUILD_TOP=$(gettop) |