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