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