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 | |
Jeff Vander Stoep | 5aa6832 | 2015-06-12 09:56:39 -0700 | [diff] [blame] | 178 | export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin |
Ying Wang | 2a859d5 | 2014-06-30 10:25:33 -0700 | [diff] [blame] | 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)" |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 581 | local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)" |
| 582 | local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)" |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 583 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 584 | if [ $(echo $arch | wc -w) -gt 1 ]; then |
| 585 | echo "tapas: Error: Multiple build archs supplied: $arch" |
| 586 | return |
| 587 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 588 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 589 | echo "tapas: Error: Multiple build variants supplied: $variant" |
| 590 | return |
| 591 | fi |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 592 | if [ $(echo $density | wc -w) -gt 1 ]; then |
| 593 | echo "tapas: Error: Multiple densities supplied: $density" |
| 594 | return |
| 595 | fi |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 596 | |
| 597 | local product=full |
| 598 | case $arch in |
Ying Wang | b541ab6 | 2014-05-29 17:57:40 -0700 | [diff] [blame] | 599 | x86) product=full_x86;; |
| 600 | mips) product=full_mips;; |
| 601 | armv5) product=generic_armv5;; |
| 602 | arm64) product=aosp_arm64;; |
| 603 | x86_64) product=aosp_x86_64;; |
| 604 | mips64) product=aosp_mips64;; |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 605 | esac |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 606 | if [ -z "$variant" ]; then |
| 607 | variant=eng |
| 608 | fi |
Ying Wang | c048c9b | 2010-06-24 15:08:33 -0700 | [diff] [blame] | 609 | if [ -z "$apps" ]; then |
| 610 | apps=all |
| 611 | fi |
Justin Morey | 29d225c | 2014-11-04 13:35:51 -0600 | [diff] [blame] | 612 | if [ -z "$density" ]; then |
| 613 | density=alldpi |
| 614 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 615 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 616 | export TARGET_PRODUCT=$product |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 617 | export TARGET_BUILD_VARIANT=$variant |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 618 | export TARGET_BUILD_DENSITY=$density |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 619 | export TARGET_BUILD_TYPE=release |
| 620 | export TARGET_BUILD_APPS=$apps |
| 621 | |
| 622 | set_stuff_for_environment |
| 623 | printconfig |
| 624 | } |
| 625 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 626 | function gettop |
| 627 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 628 | local TOPFILE=build/core/envsetup.mk |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 629 | if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then |
Brian Carlstrom | a5c4f17 | 2014-09-12 00:33:25 -0700 | [diff] [blame] | 630 | # The following circumlocution ensures we remove symlinks from TOP. |
| 631 | (cd $TOP; PWD= /bin/pwd) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 632 | else |
| 633 | if [ -f $TOPFILE ] ; then |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 634 | # The following circumlocution (repeated below as well) ensures |
| 635 | # that we record the true directory name and not one that is |
| 636 | # faked up with symlink names. |
| 637 | PWD= /bin/pwd |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 638 | else |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 639 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 640 | T= |
| 641 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 642 | \cd .. |
synergy | b112a40 | 2013-07-05 19:47:47 -0700 | [diff] [blame] | 643 | T=`PWD= /bin/pwd -P` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 644 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 645 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 646 | if [ -f "$T/$TOPFILE" ]; then |
| 647 | echo $T |
| 648 | fi |
| 649 | fi |
| 650 | fi |
| 651 | } |
| 652 | |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 653 | # Return driver for "make", if any (eg. static analyzer) |
| 654 | function getdriver() |
| 655 | { |
| 656 | local T="$1" |
| 657 | test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER |
| 658 | if [ -n "$WITH_STATIC_ANALYZER" ]; then |
| 659 | echo "\ |
Andrew Hsieh | c4f7fba | 2014-03-03 16:53:17 +0800 | [diff] [blame] | 660 | $T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \ |
| 661 | --use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \ |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 662 | --status-bugs \ |
| 663 | --top=$T" |
| 664 | fi |
| 665 | } |
| 666 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 667 | function m() |
| 668 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 669 | local T=$(gettop) |
| 670 | local DRV=$(getdriver $T) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 671 | if [ "$T" ]; then |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 672 | $DRV make -C $T -f build/core/main.mk $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 673 | else |
| 674 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 675 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 676 | fi |
| 677 | } |
| 678 | |
| 679 | function findmakefile() |
| 680 | { |
| 681 | TOPFILE=build/core/envsetup.mk |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 682 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 683 | T= |
| 684 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
Ying Wang | 11b15b1 | 2012-10-11 15:05:07 -0700 | [diff] [blame] | 685 | T=`PWD= /bin/pwd` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 686 | if [ -f "$T/Android.mk" ]; then |
| 687 | echo $T/Android.mk |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 688 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 689 | return |
| 690 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 691 | \cd .. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 692 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 693 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | function mm() |
| 697 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 698 | local T=$(gettop) |
| 699 | local DRV=$(getdriver $T) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 700 | # If we're sitting in the root of the build tree, just do a |
| 701 | # normal make. |
| 702 | if [ -f build/core/envsetup.mk -a -f Makefile ]; then |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 703 | $DRV make $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 704 | else |
| 705 | # Find the closest Android.mk file. |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 706 | local M=$(findmakefile) |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 707 | local MODULES= |
| 708 | local GET_INSTALL_PATH= |
| 709 | local ARGS= |
Robert Greenwalt | 3c794d7 | 2009-07-15 15:07:44 -0700 | [diff] [blame] | 710 | # Remove the path to top as the makefilepath needs to be relative |
| 711 | local M=`echo $M|sed 's:'$T'/::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 712 | if [ ! "$T" ]; then |
| 713 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 714 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 715 | elif [ ! "$M" ]; then |
| 716 | echo "Couldn't locate a makefile from the current directory." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 717 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 718 | else |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 719 | for ARG in $@; do |
| 720 | case $ARG in |
| 721 | GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;; |
| 722 | esac |
| 723 | done |
| 724 | if [ -n "$GET_INSTALL_PATH" ]; then |
| 725 | MODULES= |
| 726 | ARGS=GET-INSTALL-PATH |
| 727 | else |
| 728 | MODULES=all_modules |
| 729 | ARGS=$@ |
| 730 | fi |
Andrew Hsieh | 246daf7 | 2013-09-10 18:07:23 -0700 | [diff] [blame] | 731 | 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] | 732 | fi |
| 733 | fi |
| 734 | } |
| 735 | |
| 736 | function mmm() |
| 737 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 738 | local T=$(gettop) |
| 739 | local DRV=$(getdriver $T) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 740 | if [ "$T" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 741 | local MAKEFILE= |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 742 | local MODULES= |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 743 | local ARGS= |
| 744 | local DIR TO_CHOP |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 745 | local GET_INSTALL_PATH= |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 746 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 747 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 748 | for DIR in $DIRS ; do |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 749 | MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'` |
| 750 | if [ "$MODULES" = "" ]; then |
| 751 | MODULES=all_modules |
| 752 | fi |
| 753 | DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 754 | if [ -f $DIR/Android.mk ]; then |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 755 | local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '` |
| 756 | local TO_CHOP=`expr $TO_CHOP + 1` |
| 757 | local START=`PWD= /bin/pwd` |
| 758 | local MFILE=`echo $START | cut -c${TO_CHOP}-` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 759 | if [ "$MFILE" = "" ] ; then |
| 760 | MFILE=$DIR/Android.mk |
| 761 | else |
| 762 | MFILE=$MFILE/$DIR/Android.mk |
| 763 | fi |
| 764 | MAKEFILE="$MAKEFILE $MFILE" |
| 765 | else |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 766 | case $DIR in |
Adrian Roos | afa958f | 2015-03-05 19:52:55 +0100 | [diff] [blame] | 767 | showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";; |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 768 | GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;; |
| 769 | *) echo "No Android.mk in $DIR."; return 1;; |
| 770 | esac |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 771 | fi |
| 772 | done |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 773 | if [ -n "$GET_INSTALL_PATH" ]; then |
| 774 | ARGS=$GET_INSTALL_PATH |
| 775 | MODULES= |
| 776 | fi |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 777 | 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] | 778 | else |
| 779 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 780 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 781 | fi |
| 782 | } |
| 783 | |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 784 | function mma() |
| 785 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 786 | local T=$(gettop) |
| 787 | local DRV=$(getdriver $T) |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 788 | if [ -f build/core/envsetup.mk -a -f Makefile ]; then |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 789 | $DRV make $@ |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 790 | else |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 791 | if [ ! "$T" ]; then |
| 792 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 793 | return 1 |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 794 | fi |
| 795 | local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'` |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 796 | $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD" |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 797 | fi |
| 798 | } |
| 799 | |
| 800 | function mmma() |
| 801 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 802 | local T=$(gettop) |
| 803 | local DRV=$(getdriver $T) |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 804 | if [ "$T" ]; then |
| 805 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 806 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 807 | local MY_PWD=`PWD= /bin/pwd` |
| 808 | if [ "$MY_PWD" = "$T" ]; then |
| 809 | MY_PWD= |
| 810 | else |
| 811 | MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'` |
| 812 | fi |
| 813 | local DIR= |
| 814 | local MODULE_PATHS= |
| 815 | local ARGS= |
| 816 | for DIR in $DIRS ; do |
| 817 | if [ -d $DIR ]; then |
| 818 | if [ "$MY_PWD" = "" ]; then |
| 819 | MODULE_PATHS="$MODULE_PATHS $DIR" |
| 820 | else |
| 821 | MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR" |
| 822 | fi |
| 823 | else |
| 824 | case $DIR in |
Adrian Roos | afa958f | 2015-03-05 19:52:55 +0100 | [diff] [blame] | 825 | showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";; |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 826 | *) echo "Couldn't find directory $DIR"; return 1;; |
| 827 | esac |
| 828 | fi |
| 829 | done |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 830 | $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS" |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 831 | else |
| 832 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 833 | return 1 |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 834 | fi |
| 835 | } |
| 836 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 837 | function croot() |
| 838 | { |
| 839 | T=$(gettop) |
| 840 | if [ "$T" ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 841 | \cd $(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 842 | else |
| 843 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 844 | fi |
| 845 | } |
| 846 | |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 847 | function cproj() |
| 848 | { |
| 849 | TOPFILE=build/core/envsetup.mk |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 850 | local HERE=$PWD |
| 851 | T= |
| 852 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 853 | T=$PWD |
| 854 | if [ -f "$T/Android.mk" ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 855 | \cd $T |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 856 | return |
| 857 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 858 | \cd .. |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 859 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 860 | \cd $HERE |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 861 | echo "can't find Android.mk" |
| 862 | } |
| 863 | |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 864 | # simplified version of ps; output in the form |
| 865 | # <pid> <procname> |
| 866 | function qpid() { |
| 867 | local prepend='' |
| 868 | local append='' |
| 869 | if [ "$1" = "--exact" ]; then |
| 870 | prepend=' ' |
| 871 | append='$' |
| 872 | shift |
| 873 | elif [ "$1" = "--help" -o "$1" = "-h" ]; then |
| 874 | echo "usage: qpid [[--exact] <process name|pid>" |
| 875 | return 255 |
| 876 | fi |
| 877 | |
| 878 | local EXE="$1" |
| 879 | if [ "$EXE" ] ; then |
Mathias Agopian | 4458327 | 2013-08-27 14:15:50 -0700 | [diff] [blame] | 880 | qpid | \grep "$prepend$EXE$append" |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 881 | else |
| 882 | adb shell ps \ |
| 883 | | tr -d '\r' \ |
| 884 | | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/' |
| 885 | fi |
| 886 | } |
| 887 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 888 | function pid() |
| 889 | { |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 890 | local prepend='' |
| 891 | local append='' |
| 892 | if [ "$1" = "--exact" ]; then |
| 893 | prepend=' ' |
| 894 | append='$' |
| 895 | shift |
| 896 | fi |
| 897 | local EXE="$1" |
| 898 | if [ "$EXE" ] ; then |
| 899 | local PID=`adb shell ps \ |
| 900 | | tr -d '\r' \ |
Mathias Agopian | 4458327 | 2013-08-27 14:15:50 -0700 | [diff] [blame] | 901 | | \grep "$prepend$EXE$append" \ |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 902 | | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'` |
| 903 | echo "$PID" |
| 904 | else |
| 905 | echo "usage: pid [--exact] <process name>" |
| 906 | return 255 |
| 907 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Iliyan Malchev | e675cfb | 2014-11-03 17:04:47 -0800 | [diff] [blame] | 910 | # coredump_setup - enable core dumps globally for any process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 911 | # that has the core-file-size limit set correctly |
| 912 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 913 | # NOTE: You must call also coredump_enable for a specific process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 914 | # if its core-file-size limit is not set already. |
| 915 | # NOTE: Core dumps are written to ramdisk; they will not survive a reboot! |
| 916 | |
Iliyan Malchev | e675cfb | 2014-11-03 17:04:47 -0800 | [diff] [blame] | 917 | function coredump_setup() |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 918 | { |
| 919 | echo "Getting root..."; |
| 920 | adb root; |
| 921 | adb wait-for-device; |
| 922 | |
| 923 | echo "Remounting root parition read-write..."; |
| 924 | adb shell mount -w -o remount -t rootfs rootfs; |
| 925 | sleep 1; |
| 926 | adb wait-for-device; |
| 927 | adb shell mkdir -p /cores; |
Nick Kralevich | a94282c | 2014-11-04 11:17:20 -0800 | [diff] [blame] | 928 | adb shell mount -t tmpfs tmpfs /cores; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 929 | adb shell chmod 0777 /cores; |
| 930 | |
| 931 | echo "Granting SELinux permission to dump in /cores..."; |
| 932 | adb shell restorecon -R /cores; |
| 933 | |
| 934 | echo "Set core pattern."; |
| 935 | adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern'; |
| 936 | |
| 937 | echo "Done." |
| 938 | } |
| 939 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 940 | # coredump_enable - enable core dumps for the specified process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 941 | # $1 = PID of process (e.g., $(pid mediaserver)) |
| 942 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 943 | # NOTE: coredump_setup must have been called as well for a core |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 944 | # dump to actually be generated. |
| 945 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 946 | function coredump_enable() |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 947 | { |
| 948 | local PID=$1; |
| 949 | if [ -z "$PID" ]; then |
| 950 | printf "Expecting a PID!\n"; |
| 951 | return; |
| 952 | fi; |
| 953 | echo "Setting core limit for $PID to infinite..."; |
| 954 | adb shell prlimit $PID 4 -1 -1 |
| 955 | } |
| 956 | |
| 957 | # core - send SIGV and pull the core for process |
| 958 | # $1 = PID of process (e.g., $(pid mediaserver)) |
| 959 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 960 | # NOTE: coredump_setup must be called once per boot for core dumps to be |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 961 | # enabled globally. |
| 962 | |
| 963 | function core() |
| 964 | { |
| 965 | local PID=$1; |
| 966 | |
| 967 | if [ -z "$PID" ]; then |
| 968 | printf "Expecting a PID!\n"; |
| 969 | return; |
| 970 | fi; |
| 971 | |
| 972 | local CORENAME=core.$PID; |
| 973 | local COREPATH=/cores/$CORENAME; |
| 974 | local SIG=SEGV; |
| 975 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 976 | coredump_enable $1; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 977 | |
| 978 | local done=0; |
| 979 | while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do |
| 980 | printf "\tSending SIG%s to %d...\n" $SIG $PID; |
| 981 | adb shell kill -$SIG $PID; |
| 982 | sleep 1; |
| 983 | done; |
| 984 | |
| 985 | adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done" |
| 986 | echo "Done: core is under $COREPATH on device."; |
| 987 | } |
| 988 | |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 989 | # systemstack - dump the current stack trace of all threads in the system process |
| 990 | # to the usual ANR traces file |
| 991 | function systemstack() |
| 992 | { |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 993 | stacks system_server |
| 994 | } |
| 995 | |
| 996 | function stacks() |
| 997 | { |
| 998 | if [[ $1 =~ ^[0-9]+$ ]] ; then |
| 999 | local PID="$1" |
| 1000 | elif [ "$1" ] ; then |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1001 | local PIDLIST="$(pid $1)" |
| 1002 | if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then |
| 1003 | local PID="$PIDLIST" |
| 1004 | elif [ "$PIDLIST" ] ; then |
| 1005 | echo "more than one process: $1" |
| 1006 | else |
| 1007 | echo "no such process: $1" |
| 1008 | fi |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1009 | else |
| 1010 | echo "usage: stacks [pid|process name]" |
| 1011 | fi |
| 1012 | |
| 1013 | if [ "$PID" ] ; then |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1014 | # Determine whether the process is native |
| 1015 | if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then |
| 1016 | # Dump stacks of Dalvik process |
| 1017 | local TRACES=/data/anr/traces.txt |
| 1018 | local ORIG=/data/anr/traces.orig |
| 1019 | local TMP=/data/anr/traces.tmp |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1020 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1021 | # Keep original traces to avoid clobbering |
| 1022 | adb shell mv $TRACES $ORIG |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1023 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1024 | # Make sure we have a usable file |
| 1025 | adb shell touch $TRACES |
| 1026 | adb shell chmod 666 $TRACES |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1027 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1028 | # Dump stacks and wait for dump to finish |
| 1029 | adb shell kill -3 $PID |
| 1030 | adb shell notify $TRACES >/dev/null |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1031 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1032 | # Restore original stacks, and show current output |
| 1033 | adb shell mv $TRACES $TMP |
| 1034 | adb shell mv $ORIG $TRACES |
| 1035 | adb shell cat $TMP |
| 1036 | else |
| 1037 | # Dump stacks of native process |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 1038 | local USE64BIT="$(is64bit $PID)" |
| 1039 | adb shell debuggerd$USE64BIT -b $PID |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1040 | fi |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1041 | fi |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 1042 | } |
| 1043 | |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 1044 | # Read the ELF header from /proc/$PID/exe to determine if the process is |
| 1045 | # 64-bit. |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 1046 | function is64bit() |
| 1047 | { |
| 1048 | local PID="$1" |
| 1049 | if [ "$PID" ] ; then |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 1050 | 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] | 1051 | echo "64" |
| 1052 | else |
| 1053 | echo "" |
| 1054 | fi |
| 1055 | else |
| 1056 | echo "" |
| 1057 | fi |
| 1058 | } |
| 1059 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1060 | case `uname -s` in |
| 1061 | Darwin) |
| 1062 | function sgrep() |
| 1063 | { |
Jeff Brown | 46cbd20 | 2014-07-26 15:15:41 -0700 | [diff] [blame] | 1064 | 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] | 1065 | } |
| 1066 | |
| 1067 | ;; |
| 1068 | *) |
| 1069 | function sgrep() |
| 1070 | { |
Jeff Brown | 46cbd20 | 2014-07-26 15:15:41 -0700 | [diff] [blame] | 1071 | 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] | 1072 | } |
| 1073 | ;; |
| 1074 | esac |
| 1075 | |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1076 | function gettargetarch |
| 1077 | { |
| 1078 | get_build_var TARGET_ARCH |
| 1079 | } |
| 1080 | |
Jon Boekenoogen | cbca56f | 2014-04-07 10:57:38 -0700 | [diff] [blame] | 1081 | function ggrep() |
| 1082 | { |
| 1083 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@" |
| 1084 | } |
| 1085 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1086 | function jgrep() |
| 1087 | { |
Anatolii Shuba | 91c72d2 | 2013-07-05 16:09:25 +0300 | [diff] [blame] | 1088 | 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] | 1089 | } |
| 1090 | |
| 1091 | function cgrep() |
| 1092 | { |
Dan Albert | 0196119 | 2014-11-22 10:16:01 -0800 | [diff] [blame] | 1093 | 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] | 1094 | } |
| 1095 | |
| 1096 | function resgrep() |
| 1097 | { |
Anatolii Shuba | 91c72d2 | 2013-07-05 16:09:25 +0300 | [diff] [blame] | 1098 | 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] | 1099 | } |
| 1100 | |
Jeff Sharkey | 50b61e9 | 2013-03-08 10:20:47 -0800 | [diff] [blame] | 1101 | function mangrep() |
| 1102 | { |
| 1103 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@" |
| 1104 | } |
| 1105 | |
Alex Klyubin | ba5fc8e | 2013-05-06 14:11:48 -0700 | [diff] [blame] | 1106 | function sepgrep() |
| 1107 | { |
| 1108 | 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 "$@" |
| 1109 | } |
| 1110 | |
Jeff Sharkey | ea0068a | 2015-02-26 14:13:46 -0800 | [diff] [blame] | 1111 | function rcgrep() |
| 1112 | { |
| 1113 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@" |
| 1114 | } |
| 1115 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1116 | case `uname -s` in |
| 1117 | Darwin) |
| 1118 | function mgrep() |
| 1119 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 1120 | 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] | 1121 | } |
| 1122 | |
| 1123 | function treegrep() |
| 1124 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 1125 | 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] | 1126 | } |
| 1127 | |
| 1128 | ;; |
| 1129 | *) |
| 1130 | function mgrep() |
| 1131 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 1132 | 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] | 1133 | } |
| 1134 | |
| 1135 | function treegrep() |
| 1136 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 1137 | 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] | 1138 | } |
| 1139 | |
| 1140 | ;; |
| 1141 | esac |
| 1142 | |
| 1143 | function getprebuilt |
| 1144 | { |
| 1145 | get_abs_build_var ANDROID_PREBUILTS |
| 1146 | } |
| 1147 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1148 | function tracedmdump() |
| 1149 | { |
| 1150 | T=$(gettop) |
| 1151 | if [ ! "$T" ]; then |
| 1152 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 1153 | return |
| 1154 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1155 | local prebuiltdir=$(getprebuilt) |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1156 | local arch=$(gettargetarch) |
| 1157 | local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1158 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1159 | local TRACE=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1160 | if [ ! "$TRACE" ] ; then |
| 1161 | echo "usage: tracedmdump tracename" |
| 1162 | return |
| 1163 | fi |
| 1164 | |
Jack Veenstra | 60116fc | 2009-04-09 18:12:34 -0700 | [diff] [blame] | 1165 | if [ ! -r "$KERNEL" ] ; then |
| 1166 | echo "Error: cannot find kernel: '$KERNEL'" |
| 1167 | return |
| 1168 | fi |
| 1169 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1170 | local BASETRACE=$(basename $TRACE) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1171 | if [ "$BASETRACE" = "$TRACE" ] ; then |
| 1172 | TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE |
| 1173 | fi |
| 1174 | |
| 1175 | echo "post-processing traces..." |
| 1176 | rm -f $TRACE/qtrace.dexlist |
| 1177 | post_trace $TRACE |
| 1178 | if [ $? -ne 0 ]; then |
| 1179 | echo "***" |
| 1180 | echo "*** Error: malformed trace. Did you remember to exit the emulator?" |
| 1181 | echo "***" |
| 1182 | return |
| 1183 | fi |
| 1184 | echo "generating dexlist output..." |
| 1185 | /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 |
| 1186 | echo "generating dmtrace data..." |
| 1187 | q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return |
| 1188 | echo "generating html file..." |
| 1189 | dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return |
| 1190 | echo "done, see $TRACE/dmtrace.html for details" |
| 1191 | echo "or run:" |
| 1192 | echo " traceview $TRACE/dmtrace" |
| 1193 | } |
| 1194 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1195 | # communicate with a running device or emulator, set up necessary state, |
| 1196 | # and run the hat command. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1197 | function runhat() |
| 1198 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1199 | # process standard adb options |
| 1200 | local adbTarget="" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1201 | if [ "$1" = "-d" -o "$1" = "-e" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1202 | adbTarget=$1 |
| 1203 | shift 1 |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1204 | elif [ "$1" = "-s" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1205 | adbTarget="$1 $2" |
| 1206 | shift 2 |
| 1207 | fi |
| 1208 | local adbOptions=${adbTarget} |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1209 | #echo adbOptions = ${adbOptions} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1210 | |
| 1211 | # runhat options |
| 1212 | local targetPid=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1213 | |
| 1214 | if [ "$targetPid" = "" ]; then |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1215 | echo "Usage: runhat [ -d | -e | -s serial ] target-pid" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1216 | return |
| 1217 | fi |
| 1218 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1219 | # confirm hat is available |
| 1220 | if [ -z $(which hat) ]; then |
| 1221 | echo "hat is not available in this configuration." |
| 1222 | return |
| 1223 | fi |
| 1224 | |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1225 | # issue "am" command to cause the hprof dump |
Nick Kralevich | 9948b1e | 2014-07-18 15:45:38 -0700 | [diff] [blame] | 1226 | local devFile=/data/local/tmp/hprof-$targetPid |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1227 | echo "Poking $targetPid and waiting for data..." |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1228 | echo "Storing data at $devFile" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1229 | adb ${adbOptions} shell am dumpheap $targetPid $devFile |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1230 | 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] | 1231 | echo -n "> " |
| 1232 | read |
| 1233 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1234 | local localFile=/tmp/$$-hprof |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1235 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1236 | echo "Retrieving file $devFile..." |
| 1237 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1238 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1239 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1240 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1241 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1242 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 1243 | echo "" |
Dianne Hackborn | 6e4e1bb | 2011-11-10 15:19:51 -0800 | [diff] [blame] | 1244 | hat -JXmx512m $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | function getbugreports() |
| 1248 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1249 | 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] | 1250 | |
| 1251 | if [ ! "$reports" ]; then |
| 1252 | echo "Could not locate any bugreports." |
| 1253 | return |
| 1254 | fi |
| 1255 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1256 | local report |
| 1257 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1258 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1259 | echo "/sdcard/bugreports/${report}" |
| 1260 | adb pull /sdcard/bugreports/${report} ${report} |
| 1261 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1262 | done |
| 1263 | } |
| 1264 | |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1265 | function getsdcardpath() |
| 1266 | { |
| 1267 | adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} |
| 1268 | } |
| 1269 | |
| 1270 | function getscreenshotpath() |
| 1271 | { |
| 1272 | echo "$(getsdcardpath)/Pictures/Screenshots" |
| 1273 | } |
| 1274 | |
| 1275 | function getlastscreenshot() |
| 1276 | { |
| 1277 | local screenshot_path=$(getscreenshotpath) |
| 1278 | local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1` |
| 1279 | if [ "$screenshot" = "" ]; then |
| 1280 | echo "No screenshots found." |
| 1281 | return |
| 1282 | fi |
| 1283 | echo "${screenshot}" |
| 1284 | adb ${adbOptions} pull ${screenshot_path}/${screenshot} |
| 1285 | } |
| 1286 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1287 | function startviewserver() |
| 1288 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1289 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1290 | if [ $# -gt 0 ]; then |
| 1291 | port=$1 |
| 1292 | fi |
| 1293 | adb shell service call window 1 i32 $port |
| 1294 | } |
| 1295 | |
| 1296 | function stopviewserver() |
| 1297 | { |
| 1298 | adb shell service call window 2 |
| 1299 | } |
| 1300 | |
| 1301 | function isviewserverstarted() |
| 1302 | { |
| 1303 | adb shell service call window 3 |
| 1304 | } |
| 1305 | |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1306 | function key_home() |
| 1307 | { |
| 1308 | adb shell input keyevent 3 |
| 1309 | } |
| 1310 | |
| 1311 | function key_back() |
| 1312 | { |
| 1313 | adb shell input keyevent 4 |
| 1314 | } |
| 1315 | |
| 1316 | function key_menu() |
| 1317 | { |
| 1318 | adb shell input keyevent 82 |
| 1319 | } |
| 1320 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1321 | function smoketest() |
| 1322 | { |
| 1323 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1324 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1325 | return |
| 1326 | fi |
| 1327 | T=$(gettop) |
| 1328 | if [ ! "$T" ]; then |
| 1329 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1330 | return |
| 1331 | fi |
| 1332 | |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1333 | (\cd "$T" && mmm tests/SmokeTest) && |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1334 | adb uninstall com.android.smoketest > /dev/null && |
| 1335 | adb uninstall com.android.smoketest.tests > /dev/null && |
| 1336 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && |
| 1337 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && |
| 1338 | adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner |
| 1339 | } |
| 1340 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1341 | # simple shortcut to the runtest command |
| 1342 | function runtest() |
| 1343 | { |
| 1344 | T=$(gettop) |
| 1345 | if [ ! "$T" ]; then |
| 1346 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1347 | return |
| 1348 | fi |
Brett Chabot | 3fb149d | 2009-10-21 20:05:26 -0700 | [diff] [blame] | 1349 | ("$T"/development/testrunner/runtest.py $@) |
Brett Chabot | 762748c | 2009-03-27 10:25:11 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1352 | function godir () { |
| 1353 | if [[ -z "$1" ]]; then |
| 1354 | echo "Usage: godir <regex>" |
| 1355 | return |
| 1356 | fi |
Brian Carlstrom | b9915a6 | 2010-01-29 16:39:32 -0800 | [diff] [blame] | 1357 | T=$(gettop) |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame^] | 1358 | if [ ! "$OUT_DIR" = "" ]; then |
| 1359 | mkdir -p $OUT_DIR |
| 1360 | FILELIST=$OUT_DIR/filelist |
| 1361 | else |
| 1362 | FILELIST=$T/filelist |
| 1363 | fi |
| 1364 | if [[ ! -f $FILELIST ]]; then |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1365 | echo -n "Creating index..." |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame^] | 1366 | (\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] | 1367 | echo " Done" |
| 1368 | echo "" |
| 1369 | fi |
| 1370 | local lines |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame^] | 1371 | lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1372 | if [[ ${#lines[@]} = 0 ]]; then |
| 1373 | echo "Not found" |
| 1374 | return |
| 1375 | fi |
| 1376 | local pathname |
| 1377 | local choice |
| 1378 | if [[ ${#lines[@]} > 1 ]]; then |
| 1379 | while [[ -z "$pathname" ]]; do |
| 1380 | local index=1 |
| 1381 | local line |
| 1382 | for line in ${lines[@]}; do |
| 1383 | printf "%6s %s\n" "[$index]" $line |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 1384 | index=$(($index + 1)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1385 | done |
| 1386 | echo |
| 1387 | echo -n "Select one: " |
| 1388 | unset choice |
| 1389 | read choice |
| 1390 | if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then |
| 1391 | echo "Invalid choice" |
| 1392 | continue |
| 1393 | fi |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 1394 | pathname=${lines[$(($choice-1))]} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1395 | done |
| 1396 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1397 | pathname=${lines[0]} |
| 1398 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1399 | \cd $T/$pathname |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1400 | } |
| 1401 | |
Neil Fuller | 46e00ea | 2014-10-16 10:23:03 +0100 | [diff] [blame] | 1402 | # 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] | 1403 | # |
| 1404 | # Note that the MacOS path for java 1.7 includes a minor revision number (sigh). |
| 1405 | # For some reason, installing the JDK doesn't make it show up in the |
| 1406 | # JavaVM.framework/Versions/1.7/ folder. |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 1407 | function set_java_home() { |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 1408 | # 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] | 1409 | # we can reset it later, depending on the version of java the build |
| 1410 | # system needs. |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 1411 | # |
| 1412 | # If we don't do this, the JAVA_HOME value set by the first call to |
| 1413 | # build/envsetup.sh will persist forever. |
| 1414 | if [ -n "$ANDROID_SET_JAVA_HOME" ]; then |
| 1415 | export JAVA_HOME="" |
| 1416 | fi |
| 1417 | |
Andy McFadden | bd96094 | 2010-06-24 12:52:51 -0700 | [diff] [blame] | 1418 | if [ ! "$JAVA_HOME" ]; then |
Neil Fuller | 46e00ea | 2014-10-16 10:23:03 +0100 | [diff] [blame] | 1419 | case `uname -s` in |
| 1420 | Darwin) |
| 1421 | export JAVA_HOME=$(/usr/libexec/java_home -v 1.7) |
| 1422 | ;; |
| 1423 | *) |
| 1424 | export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 |
| 1425 | ;; |
| 1426 | esac |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 1427 | |
| 1428 | # Keep track of the fact that we set JAVA_HOME ourselves, so that |
| 1429 | # we can change it on the next envsetup.sh, if required. |
| 1430 | export ANDROID_SET_JAVA_HOME=true |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 1431 | fi |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 1432 | } |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 1433 | |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1434 | # Print colored exit condition |
| 1435 | function pez { |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1436 | "$@" |
| 1437 | local retval=$? |
| 1438 | if [ $retval -ne 0 ] |
| 1439 | then |
| 1440 | echo -e "\e[0;31mFAILURE\e[00m" |
| 1441 | else |
| 1442 | echo -e "\e[0;32mSUCCESS\e[00m" |
| 1443 | fi |
| 1444 | return $retval |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1445 | } |
| 1446 | |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 1447 | function get_make_command() |
| 1448 | { |
| 1449 | echo command make |
| 1450 | } |
| 1451 | |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1452 | function make() |
| 1453 | { |
| 1454 | local start_time=$(date +"%s") |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 1455 | $(get_make_command) "$@" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1456 | local ret=$? |
| 1457 | local end_time=$(date +"%s") |
| 1458 | local tdiff=$(($end_time-$start_time)) |
| 1459 | local hours=$(($tdiff / 3600 )) |
| 1460 | local mins=$((($tdiff % 3600) / 60)) |
| 1461 | local secs=$(($tdiff % 60)) |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 1462 | local ncolors=$(tput colors 2>/dev/null) |
| 1463 | if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then |
| 1464 | color_failed="\e[0;31m" |
| 1465 | color_success="\e[0;32m" |
| 1466 | color_reset="\e[00m" |
| 1467 | else |
| 1468 | color_failed="" |
| 1469 | color_success="" |
| 1470 | color_reset="" |
| 1471 | fi |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1472 | echo |
| 1473 | if [ $ret -eq 0 ] ; then |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 1474 | echo -n -e "${color_success}#### make completed successfully " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1475 | else |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 1476 | echo -n -e "${color_failed}#### make failed to build some targets " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1477 | fi |
| 1478 | if [ $hours -gt 0 ] ; then |
| 1479 | printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs |
| 1480 | elif [ $mins -gt 0 ] ; then |
| 1481 | printf "(%02g:%02g (mm:ss))" $mins $secs |
| 1482 | elif [ $secs -gt 0 ] ; then |
| 1483 | printf "(%s seconds)" $secs |
| 1484 | fi |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 1485 | echo -e " ####${color_reset}" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1486 | echo |
| 1487 | return $ret |
| 1488 | } |
| 1489 | |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1490 | if [ "x$SHELL" != "x/bin/bash" ]; then |
| 1491 | case `ps -o command -p $$` in |
| 1492 | *bash*) |
| 1493 | ;; |
| 1494 | *) |
| 1495 | echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results" |
| 1496 | ;; |
| 1497 | esac |
| 1498 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1499 | |
| 1500 | # Execute the contents of any vendorsetup.sh files we can find. |
Oleksiy Avramchenko | 15760a8 | 2014-10-06 18:51:58 +0200 | [diff] [blame] | 1501 | for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \ |
| 1502 | `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1503 | do |
| 1504 | echo "including $f" |
| 1505 | . $f |
| 1506 | done |
| 1507 | unset f |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 1508 | |
| 1509 | addcompletions |