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