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