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