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