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