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