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