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