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