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