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