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