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> |
| 5 | - tapas: tapas [<App1> <App2> ...] [arm|x86|mips] [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. |
| 8 | - mm: Builds all of the modules in the current directory. |
| 9 | - mmm: Builds all of the modules in the supplied directories. |
| 10 | - cgrep: Greps on all local C/C++ files. |
| 11 | - jgrep: Greps on all local Java files. |
| 12 | - resgrep: Greps on all local res/*.xml files. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 13 | - godir: Go to the directory containing a file. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 14 | |
| 15 | Look at the source to view more functions. The complete list is: |
| 16 | EOF |
| 17 | T=$(gettop) |
| 18 | local A |
| 19 | A="" |
| 20 | for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do |
| 21 | A="$A $i" |
| 22 | done |
| 23 | echo $A |
| 24 | } |
| 25 | |
| 26 | # Get the value of a build variable as an absolute path. |
| 27 | function get_abs_build_var() |
| 28 | { |
| 29 | T=$(gettop) |
| 30 | if [ ! "$T" ]; then |
| 31 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 32 | return |
| 33 | fi |
Brian Carlstrom | 177285a | 2010-04-06 13:22:02 -0700 | [diff] [blame] | 34 | (cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ |
| 35 | make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | # Get the exact value of a build variable. |
| 39 | function get_build_var() |
| 40 | { |
| 41 | T=$(gettop) |
| 42 | if [ ! "$T" ]; then |
| 43 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 44 | return |
| 45 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 46 | CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ |
| 47 | make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1 |
| 48 | } |
| 49 | |
| 50 | # check to see if the supplied product is one we can build |
| 51 | function check_product() |
| 52 | { |
| 53 | T=$(gettop) |
| 54 | if [ ! "$T" ]; then |
| 55 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 56 | return |
| 57 | fi |
| 58 | CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 59 | TARGET_PRODUCT=$1 \ |
| 60 | TARGET_BUILD_VARIANT= \ |
| 61 | TARGET_BUILD_TYPE= \ |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 62 | TARGET_BUILD_APPS= \ |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 63 | get_build_var TARGET_DEVICE > /dev/null |
| 64 | # hide successful answers, but allow the errors to show |
| 65 | } |
| 66 | |
| 67 | VARIANT_CHOICES=(user userdebug eng) |
| 68 | |
| 69 | # check to see if the supplied variant is valid |
| 70 | function check_variant() |
| 71 | { |
| 72 | for v in ${VARIANT_CHOICES[@]} |
| 73 | do |
| 74 | if [ "$v" = "$1" ] |
| 75 | then |
| 76 | return 0 |
| 77 | fi |
| 78 | done |
| 79 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | function setpaths() |
| 83 | { |
| 84 | T=$(gettop) |
| 85 | if [ ! "$T" ]; then |
| 86 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 87 | return |
| 88 | fi |
| 89 | |
| 90 | ################################################################## |
| 91 | # # |
| 92 | # Read me before you modify this code # |
| 93 | # # |
| 94 | # This function sets ANDROID_BUILD_PATHS to what it is adding # |
| 95 | # to PATH, and the next time it is run, it removes that from # |
| 96 | # PATH. This is required so lunch can be run more than once # |
| 97 | # and still have working paths. # |
| 98 | # # |
| 99 | ################################################################## |
| 100 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 101 | # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces |
| 102 | # due to "C:\Program Files" being in the path. |
| 103 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 104 | # out with the old |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 105 | if [ -n "$ANDROID_BUILD_PATHS" ] ; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 106 | export PATH=${PATH/$ANDROID_BUILD_PATHS/} |
| 107 | fi |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 108 | if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 109 | export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/} |
| 110 | # strip trailing ':', if any |
| 111 | export PATH=${PATH/%:/} |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 112 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 113 | |
| 114 | # and in with the new |
| 115 | CODE_REVIEWS= |
| 116 | prebuiltdir=$(getprebuilt) |
Jing Yu | f5172c7 | 2012-03-29 20:45:50 -0700 | [diff] [blame] | 117 | gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS) |
Raphael | 732936d | 2011-06-22 14:35:32 -0700 | [diff] [blame] | 118 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 119 | # 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] | 120 | export ANDROID_EABI_TOOLCHAIN= |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 121 | local ARCH=$(get_build_var TARGET_ARCH) |
| 122 | case $ARCH in |
H.J. Lu | 402d7f3 | 2012-04-29 07:34:54 -0700 | [diff] [blame] | 123 | x86) toolchaindir=x86/i686-linux-android-4.6/bin |
Mark D Horn | 7d0ede7 | 2012-03-14 14:20:30 -0700 | [diff] [blame] | 124 | ;; |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 125 | arm) toolchaindir=arm/arm-linux-androideabi-4.6/bin |
| 126 | ;; |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 127 | mips) toolchaindir=mips/mipsel-linux-android-4.6/bin |
| 128 | ;; |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 129 | *) |
| 130 | echo "Can't find toolchain for unknown architecture: $ARCH" |
| 131 | toolchaindir=xxxxxxxxx |
Mark D Horn | 7d0ede7 | 2012-03-14 14:20:30 -0700 | [diff] [blame] | 132 | ;; |
| 133 | esac |
Jing Yu | f5172c7 | 2012-03-29 20:45:50 -0700 | [diff] [blame] | 134 | if [ -d "$gccprebuiltdir/$toolchaindir" ]; then |
| 135 | export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 136 | fi |
Raphael | 732936d | 2011-06-22 14:35:32 -0700 | [diff] [blame] | 137 | |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 138 | unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 139 | case $ARCH in |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 140 | arm) |
| 141 | toolchaindir=arm/arm-eabi-4.6/bin |
| 142 | if [ -d "$gccprebuiltdir/$toolchaindir" ]; then |
| 143 | export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir" |
| 144 | ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir" |
| 145 | fi |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 146 | ;; |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 147 | mips) toolchaindir=mips/mips-eabi-4.4.3/bin |
| 148 | ;; |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 149 | *) |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 150 | # No need to set ARM_EABI_TOOLCHAIN for other ARCHs |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 151 | ;; |
| 152 | esac |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 153 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 154 | export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN |
| 155 | export ANDROID_QTOOLS=$T/development/emulator/qtools |
Robert Greenwalt | 0987f03 | 2012-04-27 10:02:37 -0700 | [diff] [blame] | 156 | export ANDROID_DEV_SCRIPTS=$T/development/scripts |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 157 | export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 158 | export PATH=$PATH$ANDROID_BUILD_PATHS |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 159 | |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 160 | unset ANDROID_JAVA_TOOLCHAIN |
Ji-Hwan Lee | 752ad06 | 2011-07-04 14:09:47 +0900 | [diff] [blame] | 161 | unset ANDROID_PRE_BUILD_PATHS |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 162 | if [ -n "$JAVA_HOME" ]; then |
| 163 | export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin |
Ji-Hwan Lee | 752ad06 | 2011-07-04 14:09:47 +0900 | [diff] [blame] | 164 | export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN: |
| 165 | export PATH=$ANDROID_PRE_BUILD_PATHS$PATH |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 166 | fi |
| 167 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 168 | unset ANDROID_PRODUCT_OUT |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 169 | export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT) |
| 170 | export OUT=$ANDROID_PRODUCT_OUT |
| 171 | |
Jeff Brown | 8fd5cce | 2011-03-24 17:03:06 -0700 | [diff] [blame] | 172 | unset ANDROID_HOST_OUT |
| 173 | export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT) |
| 174 | |
Ben Cheng | 057fde1 | 2011-11-28 13:55:14 -0800 | [diff] [blame] | 175 | # needed for processing samples collected by perf counters |
| 176 | unset OPROFILE_EVENTS_DIR |
| 177 | export OPROFILE_EVENTS_DIR=$T/external/oprofile/events |
| 178 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 179 | # needed for building linux on MacOS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 180 | # TODO: fix the path |
| 181 | #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include |
| 182 | } |
| 183 | |
| 184 | function printconfig() |
| 185 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 186 | T=$(gettop) |
| 187 | if [ ! "$T" ]; then |
| 188 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 189 | return |
| 190 | fi |
| 191 | get_build_var report_config |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | function set_stuff_for_environment() |
| 195 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 196 | settitle |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 197 | set_java_home |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 198 | setpaths |
| 199 | set_sequence_number |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 200 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 201 | export ANDROID_BUILD_TOP=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | function set_sequence_number() |
| 205 | { |
Joe Onorato | aee4daa | 2010-06-23 14:03:13 -0700 | [diff] [blame] | 206 | export BUILD_ENV_SEQUENCE_NUMBER=10 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | function settitle() |
| 210 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 211 | if [ "$STAY_OFF_MY_LAWN" = "" ]; then |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 212 | local arch=$(gettargetarch) |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 213 | local product=$TARGET_PRODUCT |
| 214 | local variant=$TARGET_BUILD_VARIANT |
| 215 | local apps=$TARGET_BUILD_APPS |
| 216 | if [ -z "$apps" ]; then |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 217 | 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] | 218 | else |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 219 | 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] | 220 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 221 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 224 | function addcompletions() |
| 225 | { |
| 226 | local T dir f |
| 227 | |
| 228 | # Keep us from trying to run in something that isn't bash. |
| 229 | if [ -z "${BASH_VERSION}" ]; then |
| 230 | return |
| 231 | fi |
| 232 | |
| 233 | # Keep us from trying to run in bash that's too old. |
| 234 | if [ ${BASH_VERSINFO[0]} -lt 3 ]; then |
| 235 | return |
| 236 | fi |
| 237 | |
| 238 | dir="sdk/bash_completion" |
| 239 | if [ -d ${dir} ]; then |
Kenny Root | 7546d61 | 2011-07-18 13:11:34 -0700 | [diff] [blame] | 240 | 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] | 241 | echo "including $f" |
| 242 | . $f |
| 243 | done |
| 244 | fi |
| 245 | } |
| 246 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 247 | function choosetype() |
| 248 | { |
| 249 | echo "Build type choices are:" |
| 250 | echo " 1. release" |
| 251 | echo " 2. debug" |
| 252 | echo |
| 253 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 254 | local DEFAULT_NUM DEFAULT_VALUE |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 255 | DEFAULT_NUM=1 |
| 256 | DEFAULT_VALUE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 257 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 258 | export TARGET_BUILD_TYPE= |
| 259 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 260 | while [ -z $TARGET_BUILD_TYPE ] |
| 261 | do |
| 262 | echo -n "Which would you like? ["$DEFAULT_NUM"] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 263 | if [ -z "$1" ] ; then |
| 264 | read ANSWER |
| 265 | else |
| 266 | echo $1 |
| 267 | ANSWER=$1 |
| 268 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 269 | case $ANSWER in |
| 270 | "") |
| 271 | export TARGET_BUILD_TYPE=$DEFAULT_VALUE |
| 272 | ;; |
| 273 | 1) |
| 274 | export TARGET_BUILD_TYPE=release |
| 275 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 276 | release) |
| 277 | export TARGET_BUILD_TYPE=release |
| 278 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 279 | 2) |
| 280 | export TARGET_BUILD_TYPE=debug |
| 281 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 282 | debug) |
| 283 | export TARGET_BUILD_TYPE=debug |
| 284 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 285 | *) |
| 286 | echo |
| 287 | echo "I didn't understand your response. Please try again." |
| 288 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 289 | ;; |
| 290 | esac |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 291 | if [ -n "$1" ] ; then |
| 292 | break |
| 293 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 294 | done |
| 295 | |
| 296 | set_stuff_for_environment |
| 297 | } |
| 298 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 299 | # |
| 300 | # This function isn't really right: It chooses a TARGET_PRODUCT |
| 301 | # based on the list of boards. Usually, that gets you something |
| 302 | # that kinda works with a generic product, but really, you should |
| 303 | # pick a product by name. |
| 304 | # |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 305 | function chooseproduct() |
| 306 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 307 | if [ "x$TARGET_PRODUCT" != x ] ; then |
| 308 | default_value=$TARGET_PRODUCT |
| 309 | else |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 310 | default_value=full |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 311 | fi |
| 312 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 313 | export TARGET_PRODUCT= |
| 314 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 315 | while [ -z "$TARGET_PRODUCT" ] |
| 316 | do |
Joe Onorato | 8849aed | 2009-04-29 15:56:47 -0700 | [diff] [blame] | 317 | echo -n "Which product would you like? [$default_value] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 318 | if [ -z "$1" ] ; then |
| 319 | read ANSWER |
| 320 | else |
| 321 | echo $1 |
| 322 | ANSWER=$1 |
| 323 | fi |
| 324 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 325 | if [ -z "$ANSWER" ] ; then |
| 326 | export TARGET_PRODUCT=$default_value |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 327 | else |
| 328 | if check_product $ANSWER |
| 329 | then |
| 330 | export TARGET_PRODUCT=$ANSWER |
| 331 | else |
| 332 | echo "** Not a valid product: $ANSWER" |
| 333 | fi |
| 334 | fi |
| 335 | if [ -n "$1" ] ; then |
| 336 | break |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 337 | fi |
| 338 | done |
| 339 | |
| 340 | set_stuff_for_environment |
| 341 | } |
| 342 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 343 | function choosevariant() |
| 344 | { |
| 345 | echo "Variant choices are:" |
| 346 | local index=1 |
| 347 | local v |
| 348 | for v in ${VARIANT_CHOICES[@]} |
| 349 | do |
| 350 | # The product name is the name of the directory containing |
| 351 | # the makefile we found, above. |
| 352 | echo " $index. $v" |
| 353 | index=$(($index+1)) |
| 354 | done |
| 355 | |
| 356 | local default_value=eng |
| 357 | local ANSWER |
| 358 | |
| 359 | export TARGET_BUILD_VARIANT= |
| 360 | while [ -z "$TARGET_BUILD_VARIANT" ] |
| 361 | do |
| 362 | echo -n "Which would you like? [$default_value] " |
| 363 | if [ -z "$1" ] ; then |
| 364 | read ANSWER |
| 365 | else |
| 366 | echo $1 |
| 367 | ANSWER=$1 |
| 368 | fi |
| 369 | |
| 370 | if [ -z "$ANSWER" ] ; then |
| 371 | export TARGET_BUILD_VARIANT=$default_value |
| 372 | elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then |
| 373 | if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 374 | export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 375 | fi |
| 376 | else |
| 377 | if check_variant $ANSWER |
| 378 | then |
| 379 | export TARGET_BUILD_VARIANT=$ANSWER |
| 380 | else |
| 381 | echo "** Not a valid variant: $ANSWER" |
| 382 | fi |
| 383 | fi |
| 384 | if [ -n "$1" ] ; then |
| 385 | break |
| 386 | fi |
| 387 | done |
| 388 | } |
| 389 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 390 | function choosecombo() |
| 391 | { |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 392 | choosetype $1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 393 | |
| 394 | echo |
| 395 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 396 | chooseproduct $2 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 397 | |
| 398 | echo |
| 399 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 400 | choosevariant $3 |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 401 | |
| 402 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 403 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 404 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 405 | } |
| 406 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 407 | # Clear this variable. It will be built up again when the vendorsetup.sh |
| 408 | # files are included at the end of this file. |
| 409 | unset LUNCH_MENU_CHOICES |
| 410 | function add_lunch_combo() |
| 411 | { |
| 412 | local new_combo=$1 |
| 413 | local c |
| 414 | for c in ${LUNCH_MENU_CHOICES[@]} ; do |
| 415 | if [ "$new_combo" = "$c" ] ; then |
| 416 | return |
| 417 | fi |
| 418 | done |
| 419 | LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) |
| 420 | } |
| 421 | |
| 422 | # add the default one here |
Jean-Baptiste Queru | 45038e0 | 2010-07-01 09:22:53 -0700 | [diff] [blame] | 423 | add_lunch_combo full-eng |
Jean-Baptiste Queru | 6c2df3e | 2010-07-15 14:04:39 -0700 | [diff] [blame] | 424 | add_lunch_combo full_x86-eng |
Bruce Beare | ba366c4 | 2011-02-15 16:46:08 -0800 | [diff] [blame] | 425 | add_lunch_combo vbox_x86-eng |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 426 | add_lunch_combo full_mips-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 427 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 428 | function print_lunch_menu() |
| 429 | { |
| 430 | local uname=$(uname) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 431 | echo |
| 432 | echo "You're building on" $uname |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 433 | echo |
| 434 | echo "Lunch menu... pick a combo:" |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 435 | |
| 436 | local i=1 |
| 437 | local choice |
| 438 | for choice in ${LUNCH_MENU_CHOICES[@]} |
| 439 | do |
| 440 | echo " $i. $choice" |
| 441 | i=$(($i+1)) |
| 442 | done |
| 443 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 444 | echo |
| 445 | } |
| 446 | |
| 447 | function lunch() |
| 448 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 449 | local answer |
| 450 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 451 | if [ "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 452 | answer=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 453 | else |
| 454 | print_lunch_menu |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 455 | echo -n "Which would you like? [full-eng] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 456 | read answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 457 | fi |
| 458 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 459 | local selection= |
| 460 | |
| 461 | if [ -z "$answer" ] |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 462 | then |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 463 | selection=full-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 464 | elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") |
| 465 | then |
| 466 | if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ] |
| 467 | then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 468 | selection=${LUNCH_MENU_CHOICES[$(($answer-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 469 | fi |
| 470 | elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$") |
| 471 | then |
| 472 | selection=$answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 473 | fi |
| 474 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 475 | if [ -z "$selection" ] |
| 476 | then |
| 477 | echo |
| 478 | echo "Invalid lunch combo: $answer" |
| 479 | return 1 |
| 480 | fi |
| 481 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 482 | export TARGET_BUILD_APPS= |
| 483 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 484 | local product=$(echo -n $selection | sed -e "s/-.*$//") |
| 485 | check_product $product |
| 486 | if [ $? -ne 0 ] |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 487 | then |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 488 | echo |
| 489 | echo "** Don't have a product spec for: '$product'" |
| 490 | echo "** Do you have the right repo manifest?" |
| 491 | product= |
| 492 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 493 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 494 | local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//") |
| 495 | check_variant $variant |
| 496 | if [ $? -ne 0 ] |
| 497 | then |
| 498 | echo |
| 499 | echo "** Invalid variant: '$variant'" |
| 500 | echo "** Must be one of ${VARIANT_CHOICES[@]}" |
| 501 | variant= |
| 502 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 503 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 504 | if [ -z "$product" -o -z "$variant" ] |
| 505 | then |
| 506 | echo |
| 507 | return 1 |
| 508 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 509 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 510 | export TARGET_PRODUCT=$product |
| 511 | export TARGET_BUILD_VARIANT=$variant |
| 512 | export TARGET_BUILD_TYPE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 513 | |
| 514 | echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 515 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 516 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 517 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 520 | # Tab completion for lunch. |
| 521 | function _lunch() |
| 522 | { |
| 523 | local cur prev opts |
| 524 | COMPREPLY=() |
| 525 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 526 | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 527 | |
| 528 | COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) ) |
| 529 | return 0 |
| 530 | } |
| 531 | complete -F _lunch lunch |
| 532 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 533 | # Configures the build to build unbundled apps. |
| 534 | # Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME) |
| 535 | function tapas() |
| 536 | { |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 537 | local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips)$')) |
Jeff Hamilton | 293f939 | 2011-11-18 17:15:25 -0600 | [diff] [blame] | 538 | local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$')) |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 539 | local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips)$')) |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 540 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 541 | if [ $(echo $arch | wc -w) -gt 1 ]; then |
| 542 | echo "tapas: Error: Multiple build archs supplied: $arch" |
| 543 | return |
| 544 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 545 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 546 | echo "tapas: Error: Multiple build variants supplied: $variant" |
| 547 | return |
| 548 | fi |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 549 | |
| 550 | local product=full |
| 551 | case $arch in |
| 552 | x86) product=full_x86;; |
| 553 | mips) product=full_mips;; |
| 554 | esac |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 555 | if [ -z "$variant" ]; then |
| 556 | variant=eng |
| 557 | fi |
Ying Wang | c048c9b | 2010-06-24 15:08:33 -0700 | [diff] [blame] | 558 | if [ -z "$apps" ]; then |
| 559 | apps=all |
| 560 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 561 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 562 | export TARGET_PRODUCT=$product |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 563 | export TARGET_BUILD_VARIANT=$variant |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 564 | export TARGET_BUILD_TYPE=release |
| 565 | export TARGET_BUILD_APPS=$apps |
| 566 | |
| 567 | set_stuff_for_environment |
| 568 | printconfig |
| 569 | } |
| 570 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 571 | function gettop |
| 572 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 573 | local TOPFILE=build/core/envsetup.mk |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 574 | if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then |
| 575 | echo $TOP |
| 576 | else |
| 577 | if [ -f $TOPFILE ] ; then |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 578 | # The following circumlocution (repeated below as well) ensures |
| 579 | # that we record the true directory name and not one that is |
| 580 | # faked up with symlink names. |
| 581 | PWD= /bin/pwd |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 582 | else |
| 583 | # We redirect cd to /dev/null in case it's aliased to |
| 584 | # a command that prints something as a side-effect |
| 585 | # (like pushd) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 586 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 587 | T= |
| 588 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 589 | cd .. > /dev/null |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 590 | T=`PWD= /bin/pwd` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 591 | done |
| 592 | cd $HERE > /dev/null |
| 593 | if [ -f "$T/$TOPFILE" ]; then |
| 594 | echo $T |
| 595 | fi |
| 596 | fi |
| 597 | fi |
| 598 | } |
| 599 | |
| 600 | function m() |
| 601 | { |
| 602 | T=$(gettop) |
| 603 | if [ "$T" ]; then |
| 604 | make -C $T $@ |
| 605 | else |
| 606 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 607 | fi |
| 608 | } |
| 609 | |
| 610 | function findmakefile() |
| 611 | { |
| 612 | TOPFILE=build/core/envsetup.mk |
| 613 | # We redirect cd to /dev/null in case it's aliased to |
| 614 | # a command that prints something as a side-effect |
| 615 | # (like pushd) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 616 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 617 | T= |
| 618 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
Ying Wang | 11b15b1 | 2012-10-11 15:05:07 -0700 | [diff] [blame^] | 619 | T=`PWD= /bin/pwd` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 620 | if [ -f "$T/Android.mk" ]; then |
| 621 | echo $T/Android.mk |
| 622 | cd $HERE > /dev/null |
| 623 | return |
| 624 | fi |
| 625 | cd .. > /dev/null |
| 626 | done |
| 627 | cd $HERE > /dev/null |
| 628 | } |
| 629 | |
| 630 | function mm() |
| 631 | { |
| 632 | # If we're sitting in the root of the build tree, just do a |
| 633 | # normal make. |
| 634 | if [ -f build/core/envsetup.mk -a -f Makefile ]; then |
| 635 | make $@ |
| 636 | else |
| 637 | # Find the closest Android.mk file. |
| 638 | T=$(gettop) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 639 | local M=$(findmakefile) |
Robert Greenwalt | 3c794d7 | 2009-07-15 15:07:44 -0700 | [diff] [blame] | 640 | # Remove the path to top as the makefilepath needs to be relative |
| 641 | local M=`echo $M|sed 's:'$T'/::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 642 | if [ ! "$T" ]; then |
| 643 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 644 | elif [ ! "$M" ]; then |
| 645 | echo "Couldn't locate a makefile from the current directory." |
| 646 | else |
Ying Wang | 0188414 | 2010-07-20 16:18:16 -0700 | [diff] [blame] | 647 | ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 648 | fi |
| 649 | fi |
| 650 | } |
| 651 | |
| 652 | function mmm() |
| 653 | { |
| 654 | T=$(gettop) |
| 655 | if [ "$T" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 656 | local MAKEFILE= |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 657 | local MODULES= |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 658 | local ARGS= |
| 659 | local DIR TO_CHOP |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 660 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 661 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 662 | for DIR in $DIRS ; do |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 663 | MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'` |
| 664 | if [ "$MODULES" = "" ]; then |
| 665 | MODULES=all_modules |
| 666 | fi |
| 667 | DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 668 | if [ -f $DIR/Android.mk ]; then |
Brian Carlstrom | c634d2c | 2010-09-17 12:25:50 -0700 | [diff] [blame] | 669 | TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 670 | TO_CHOP=`expr $TO_CHOP + 1` |
Gilles Debunne | 8a20f58 | 2010-02-17 15:56:45 -0800 | [diff] [blame] | 671 | START=`PWD= /bin/pwd` |
| 672 | MFILE=`echo $START | cut -c${TO_CHOP}-` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 673 | if [ "$MFILE" = "" ] ; then |
| 674 | MFILE=$DIR/Android.mk |
| 675 | else |
| 676 | MFILE=$MFILE/$DIR/Android.mk |
| 677 | fi |
| 678 | MAKEFILE="$MAKEFILE $MFILE" |
| 679 | else |
| 680 | if [ "$DIR" = snod ]; then |
| 681 | ARGS="$ARGS snod" |
| 682 | elif [ "$DIR" = showcommands ]; then |
| 683 | ARGS="$ARGS showcommands" |
Ying Wang | 0188414 | 2010-07-20 16:18:16 -0700 | [diff] [blame] | 684 | elif [ "$DIR" = dist ]; then |
| 685 | ARGS="$ARGS dist" |
Ying Wang | 015edd2 | 2011-01-20 15:01:56 -0800 | [diff] [blame] | 686 | elif [ "$DIR" = incrementaljavac ]; then |
| 687 | ARGS="$ARGS incrementaljavac" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 688 | else |
| 689 | echo "No Android.mk in $DIR." |
Joe Onorato | 51e6182 | 2009-04-13 15:36:15 -0400 | [diff] [blame] | 690 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 691 | fi |
| 692 | fi |
| 693 | done |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 694 | ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS $MODULES $ARGS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 695 | else |
| 696 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 697 | fi |
| 698 | } |
| 699 | |
| 700 | function croot() |
| 701 | { |
| 702 | T=$(gettop) |
| 703 | if [ "$T" ]; then |
| 704 | cd $(gettop) |
| 705 | else |
| 706 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 707 | fi |
| 708 | } |
| 709 | |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 710 | function cproj() |
| 711 | { |
| 712 | TOPFILE=build/core/envsetup.mk |
| 713 | # We redirect cd to /dev/null in case it's aliased to |
| 714 | # a command that prints something as a side-effect |
| 715 | # (like pushd) |
| 716 | local HERE=$PWD |
| 717 | T= |
| 718 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 719 | T=$PWD |
| 720 | if [ -f "$T/Android.mk" ]; then |
| 721 | cd $T |
| 722 | return |
| 723 | fi |
| 724 | cd .. > /dev/null |
| 725 | done |
| 726 | cd $HERE > /dev/null |
| 727 | echo "can't find Android.mk" |
| 728 | } |
| 729 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 730 | function pid() |
| 731 | { |
| 732 | local EXE="$1" |
| 733 | if [ "$EXE" ] ; then |
| 734 | local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'` |
| 735 | echo "$PID" |
| 736 | else |
| 737 | echo "usage: pid name" |
| 738 | fi |
| 739 | } |
| 740 | |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 741 | # systemstack - dump the current stack trace of all threads in the system process |
| 742 | # to the usual ANR traces file |
| 743 | function systemstack() |
| 744 | { |
| 745 | adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server) |
| 746 | } |
| 747 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 748 | function gdbclient() |
| 749 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 750 | local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT) |
| 751 | local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED) |
| 752 | local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED) |
| 753 | local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED) |
| 754 | local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS) |
Nick Kralevich | 0ab21d3 | 2011-11-11 09:02:01 -0800 | [diff] [blame] | 755 | local ARCH=$(get_build_var TARGET_ARCH) |
| 756 | local GDB |
| 757 | case "$ARCH" in |
Jean-Baptiste Queru | feec98b | 2012-05-16 13:18:39 -0700 | [diff] [blame] | 758 | x86) GDB=i686-linux-android-gdb;; |
Nick Kralevich | 0ab21d3 | 2011-11-11 09:02:01 -0800 | [diff] [blame] | 759 | arm) GDB=arm-linux-androideabi-gdb;; |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 760 | mips) GDB=mipsel-linux-android-gdb;; |
Nick Kralevich | 0ab21d3 | 2011-11-11 09:02:01 -0800 | [diff] [blame] | 761 | *) echo "Unknown arch $ARCH"; return 1;; |
| 762 | esac |
| 763 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 764 | if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then |
| 765 | local EXE="$1" |
| 766 | if [ "$EXE" ] ; then |
| 767 | EXE=$1 |
| 768 | else |
| 769 | EXE="app_process" |
| 770 | fi |
| 771 | |
| 772 | local PORT="$2" |
| 773 | if [ "$PORT" ] ; then |
| 774 | PORT=$2 |
| 775 | else |
| 776 | PORT=":5039" |
| 777 | fi |
| 778 | |
| 779 | local PID |
| 780 | local PROG="$3" |
| 781 | if [ "$PROG" ] ; then |
Grace Kloba | e9d04bf | 2011-04-30 11:04:05 -0700 | [diff] [blame] | 782 | if [[ "$PROG" =~ ^[0-9]+$ ]] ; then |
| 783 | PID="$3" |
| 784 | else |
| 785 | PID=`pid $3` |
| 786 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 787 | adb forward "tcp$PORT" "tcp$PORT" |
| 788 | adb shell gdbserver $PORT --attach $PID & |
| 789 | sleep 2 |
| 790 | else |
| 791 | echo "" |
| 792 | echo "If you haven't done so already, do this first on the device:" |
| 793 | echo " gdbserver $PORT /system/bin/$EXE" |
| 794 | echo " or" |
| 795 | echo " gdbserver $PORT --attach $PID" |
| 796 | echo "" |
| 797 | fi |
| 798 | |
| 799 | echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS" |
Chris Dearman | 6858d51 | 2012-02-02 14:16:52 -0800 | [diff] [blame] | 800 | 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" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 801 | echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT" |
| 802 | echo >>"$OUT_ROOT/gdbclient.cmds" "" |
| 803 | |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 804 | $ANDROID_TOOLCHAIN/$GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 805 | else |
| 806 | echo "Unable to determine build system output dir." |
| 807 | fi |
| 808 | |
| 809 | } |
| 810 | |
| 811 | case `uname -s` in |
| 812 | Darwin) |
| 813 | function sgrep() |
| 814 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 815 | 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] | 816 | } |
| 817 | |
| 818 | ;; |
| 819 | *) |
| 820 | function sgrep() |
| 821 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 822 | 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] | 823 | } |
| 824 | ;; |
| 825 | esac |
| 826 | |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 827 | function gettargetarch |
| 828 | { |
| 829 | get_build_var TARGET_ARCH |
| 830 | } |
| 831 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 832 | function jgrep() |
| 833 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 834 | find . -name .repo -prune -o -name .git -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] | 835 | } |
| 836 | |
| 837 | function cgrep() |
| 838 | { |
Mike Dodd | 0c26d34 | 2011-04-07 13:29:06 -0700 | [diff] [blame] | 839 | find . -name .repo -prune -o -name .git -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] | 840 | } |
| 841 | |
| 842 | function resgrep() |
| 843 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 844 | for dir in `find . -name .repo -prune -o -name .git -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] | 845 | } |
| 846 | |
| 847 | case `uname -s` in |
| 848 | Darwin) |
| 849 | function mgrep() |
| 850 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 851 | 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] | 852 | } |
| 853 | |
| 854 | function treegrep() |
| 855 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 856 | 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] | 857 | } |
| 858 | |
| 859 | ;; |
| 860 | *) |
| 861 | function mgrep() |
| 862 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 863 | 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] | 864 | } |
| 865 | |
| 866 | function treegrep() |
| 867 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 868 | 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] | 869 | } |
| 870 | |
| 871 | ;; |
| 872 | esac |
| 873 | |
| 874 | function getprebuilt |
| 875 | { |
| 876 | get_abs_build_var ANDROID_PREBUILTS |
| 877 | } |
| 878 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 879 | function tracedmdump() |
| 880 | { |
| 881 | T=$(gettop) |
| 882 | if [ ! "$T" ]; then |
| 883 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 884 | return |
| 885 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 886 | local prebuiltdir=$(getprebuilt) |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 887 | local arch=$(gettargetarch) |
| 888 | local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 889 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 890 | local TRACE=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 891 | if [ ! "$TRACE" ] ; then |
| 892 | echo "usage: tracedmdump tracename" |
| 893 | return |
| 894 | fi |
| 895 | |
Jack Veenstra | 60116fc | 2009-04-09 18:12:34 -0700 | [diff] [blame] | 896 | if [ ! -r "$KERNEL" ] ; then |
| 897 | echo "Error: cannot find kernel: '$KERNEL'" |
| 898 | return |
| 899 | fi |
| 900 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 901 | local BASETRACE=$(basename $TRACE) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 902 | if [ "$BASETRACE" = "$TRACE" ] ; then |
| 903 | TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE |
| 904 | fi |
| 905 | |
| 906 | echo "post-processing traces..." |
| 907 | rm -f $TRACE/qtrace.dexlist |
| 908 | post_trace $TRACE |
| 909 | if [ $? -ne 0 ]; then |
| 910 | echo "***" |
| 911 | echo "*** Error: malformed trace. Did you remember to exit the emulator?" |
| 912 | echo "***" |
| 913 | return |
| 914 | fi |
| 915 | echo "generating dexlist output..." |
| 916 | /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 |
| 917 | echo "generating dmtrace data..." |
| 918 | q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return |
| 919 | echo "generating html file..." |
| 920 | dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return |
| 921 | echo "done, see $TRACE/dmtrace.html for details" |
| 922 | echo "or run:" |
| 923 | echo " traceview $TRACE/dmtrace" |
| 924 | } |
| 925 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 926 | # communicate with a running device or emulator, set up necessary state, |
| 927 | # and run the hat command. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 928 | function runhat() |
| 929 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 930 | # process standard adb options |
| 931 | local adbTarget="" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 932 | if [ "$1" = "-d" -o "$1" = "-e" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 933 | adbTarget=$1 |
| 934 | shift 1 |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 935 | elif [ "$1" = "-s" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 936 | adbTarget="$1 $2" |
| 937 | shift 2 |
| 938 | fi |
| 939 | local adbOptions=${adbTarget} |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 940 | #echo adbOptions = ${adbOptions} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 941 | |
| 942 | # runhat options |
| 943 | local targetPid=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 944 | |
| 945 | if [ "$targetPid" = "" ]; then |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 946 | echo "Usage: runhat [ -d | -e | -s serial ] target-pid" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 947 | return |
| 948 | fi |
| 949 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 950 | # confirm hat is available |
| 951 | if [ -z $(which hat) ]; then |
| 952 | echo "hat is not available in this configuration." |
| 953 | return |
| 954 | fi |
| 955 | |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 956 | # issue "am" command to cause the hprof dump |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 957 | local sdcard=$(adb shell echo -n '$EXTERNAL_STORAGE') |
| 958 | local devFile=$sdcard/hprof-$targetPid |
| 959 | #local devFile=/data/local/hprof-$targetPid |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 960 | echo "Poking $targetPid and waiting for data..." |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 961 | echo "Storing data at $devFile" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 962 | adb ${adbOptions} shell am dumpheap $targetPid $devFile |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 963 | 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] | 964 | echo -n "> " |
| 965 | read |
| 966 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 967 | local localFile=/tmp/$$-hprof |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 968 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 969 | echo "Retrieving file $devFile..." |
| 970 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 971 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 972 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 973 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 974 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 975 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 976 | echo "" |
Dianne Hackborn | 6e4e1bb | 2011-11-10 15:19:51 -0800 | [diff] [blame] | 977 | hat -JXmx512m $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | function getbugreports() |
| 981 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 982 | 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] | 983 | |
| 984 | if [ ! "$reports" ]; then |
| 985 | echo "Could not locate any bugreports." |
| 986 | return |
| 987 | fi |
| 988 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 989 | local report |
| 990 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 991 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 992 | echo "/sdcard/bugreports/${report}" |
| 993 | adb pull /sdcard/bugreports/${report} ${report} |
| 994 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 995 | done |
| 996 | } |
| 997 | |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 998 | function getsdcardpath() |
| 999 | { |
| 1000 | adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} |
| 1001 | } |
| 1002 | |
| 1003 | function getscreenshotpath() |
| 1004 | { |
| 1005 | echo "$(getsdcardpath)/Pictures/Screenshots" |
| 1006 | } |
| 1007 | |
| 1008 | function getlastscreenshot() |
| 1009 | { |
| 1010 | local screenshot_path=$(getscreenshotpath) |
| 1011 | local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1` |
| 1012 | if [ "$screenshot" = "" ]; then |
| 1013 | echo "No screenshots found." |
| 1014 | return |
| 1015 | fi |
| 1016 | echo "${screenshot}" |
| 1017 | adb ${adbOptions} pull ${screenshot_path}/${screenshot} |
| 1018 | } |
| 1019 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1020 | function startviewserver() |
| 1021 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1022 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1023 | if [ $# -gt 0 ]; then |
| 1024 | port=$1 |
| 1025 | fi |
| 1026 | adb shell service call window 1 i32 $port |
| 1027 | } |
| 1028 | |
| 1029 | function stopviewserver() |
| 1030 | { |
| 1031 | adb shell service call window 2 |
| 1032 | } |
| 1033 | |
| 1034 | function isviewserverstarted() |
| 1035 | { |
| 1036 | adb shell service call window 3 |
| 1037 | } |
| 1038 | |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1039 | function key_home() |
| 1040 | { |
| 1041 | adb shell input keyevent 3 |
| 1042 | } |
| 1043 | |
| 1044 | function key_back() |
| 1045 | { |
| 1046 | adb shell input keyevent 4 |
| 1047 | } |
| 1048 | |
| 1049 | function key_menu() |
| 1050 | { |
| 1051 | adb shell input keyevent 82 |
| 1052 | } |
| 1053 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1054 | function smoketest() |
| 1055 | { |
| 1056 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1057 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1058 | return |
| 1059 | fi |
| 1060 | T=$(gettop) |
| 1061 | if [ ! "$T" ]; then |
| 1062 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1063 | return |
| 1064 | fi |
| 1065 | |
| 1066 | (cd "$T" && mmm tests/SmokeTest) && |
| 1067 | adb uninstall com.android.smoketest > /dev/null && |
| 1068 | adb uninstall com.android.smoketest.tests > /dev/null && |
| 1069 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && |
| 1070 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && |
| 1071 | adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner |
| 1072 | } |
| 1073 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1074 | # simple shortcut to the runtest command |
| 1075 | function runtest() |
| 1076 | { |
| 1077 | T=$(gettop) |
| 1078 | if [ ! "$T" ]; then |
| 1079 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1080 | return |
| 1081 | fi |
Brett Chabot | 3fb149d | 2009-10-21 20:05:26 -0700 | [diff] [blame] | 1082 | ("$T"/development/testrunner/runtest.py $@) |
Brett Chabot | 762748c | 2009-03-27 10:25:11 -0700 | [diff] [blame] | 1083 | } |
| 1084 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1085 | function godir () { |
| 1086 | if [[ -z "$1" ]]; then |
| 1087 | echo "Usage: godir <regex>" |
| 1088 | return |
| 1089 | fi |
Brian Carlstrom | b9915a6 | 2010-01-29 16:39:32 -0800 | [diff] [blame] | 1090 | T=$(gettop) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1091 | if [[ ! -f $T/filelist ]]; then |
| 1092 | echo -n "Creating index..." |
Brian Carlstrom | 259e5b7 | 2010-01-30 11:45:03 -0800 | [diff] [blame] | 1093 | (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] | 1094 | echo " Done" |
| 1095 | echo "" |
| 1096 | fi |
| 1097 | local lines |
Jeff Hamilton | 293f939 | 2011-11-18 17:15:25 -0600 | [diff] [blame] | 1098 | 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] | 1099 | if [[ ${#lines[@]} = 0 ]]; then |
| 1100 | echo "Not found" |
| 1101 | return |
| 1102 | fi |
| 1103 | local pathname |
| 1104 | local choice |
| 1105 | if [[ ${#lines[@]} > 1 ]]; then |
| 1106 | while [[ -z "$pathname" ]]; do |
| 1107 | local index=1 |
| 1108 | local line |
| 1109 | for line in ${lines[@]}; do |
| 1110 | printf "%6s %s\n" "[$index]" $line |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 1111 | index=$(($index + 1)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1112 | done |
| 1113 | echo |
| 1114 | echo -n "Select one: " |
| 1115 | unset choice |
| 1116 | read choice |
| 1117 | if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then |
| 1118 | echo "Invalid choice" |
| 1119 | continue |
| 1120 | fi |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 1121 | pathname=${lines[$(($choice-1))]} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1122 | done |
| 1123 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1124 | pathname=${lines[0]} |
| 1125 | fi |
| 1126 | cd $T/$pathname |
| 1127 | } |
| 1128 | |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 1129 | # Force JAVA_HOME to point to java 1.6 if it isn't already set |
| 1130 | function set_java_home() { |
Andy McFadden | bd96094 | 2010-06-24 12:52:51 -0700 | [diff] [blame] | 1131 | if [ ! "$JAVA_HOME" ]; then |
| 1132 | case `uname -s` in |
| 1133 | Darwin) |
| 1134 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home |
| 1135 | ;; |
| 1136 | *) |
| 1137 | export JAVA_HOME=/usr/lib/jvm/java-6-sun |
| 1138 | ;; |
| 1139 | esac |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 1140 | fi |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 1141 | } |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 1142 | |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1143 | if [ "x$SHELL" != "x/bin/bash" ]; then |
| 1144 | case `ps -o command -p $$` in |
| 1145 | *bash*) |
| 1146 | ;; |
| 1147 | *) |
| 1148 | echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results" |
| 1149 | ;; |
| 1150 | esac |
| 1151 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1152 | |
| 1153 | # Execute the contents of any vendorsetup.sh files we can find. |
Bruce Beare | 6f8410b | 2010-06-24 13:51:35 -0700 | [diff] [blame] | 1154 | for f in `/bin/ls vendor/*/vendorsetup.sh vendor/*/*/vendorsetup.sh device/*/*/vendorsetup.sh 2> /dev/null` |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1155 | do |
| 1156 | echo "including $f" |
| 1157 | . $f |
| 1158 | done |
| 1159 | unset f |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 1160 | |
| 1161 | addcompletions |