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