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