The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | function help() { |
| 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 |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 32 | 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 \ |
| 57 | TARGET_PRODUCT=$1 TARGET_BUILD_VARIANT= \ |
| 58 | TARGET_SIMULATOR= TARGET_BUILD_TYPE= \ |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 59 | TARGET_BUILD_APPS= \ |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 60 | get_build_var TARGET_DEVICE > /dev/null |
| 61 | # hide successful answers, but allow the errors to show |
| 62 | } |
| 63 | |
| 64 | VARIANT_CHOICES=(user userdebug eng) |
| 65 | |
| 66 | # check to see if the supplied variant is valid |
| 67 | function check_variant() |
| 68 | { |
| 69 | for v in ${VARIANT_CHOICES[@]} |
| 70 | do |
| 71 | if [ "$v" = "$1" ] |
| 72 | then |
| 73 | return 0 |
| 74 | fi |
| 75 | done |
| 76 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | function setpaths() |
| 80 | { |
| 81 | T=$(gettop) |
| 82 | if [ ! "$T" ]; then |
| 83 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 84 | return |
| 85 | fi |
| 86 | |
| 87 | ################################################################## |
| 88 | # # |
| 89 | # Read me before you modify this code # |
| 90 | # # |
| 91 | # This function sets ANDROID_BUILD_PATHS to what it is adding # |
| 92 | # to PATH, and the next time it is run, it removes that from # |
| 93 | # PATH. This is required so lunch can be run more than once # |
| 94 | # and still have working paths. # |
| 95 | # # |
| 96 | ################################################################## |
| 97 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 98 | # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces |
| 99 | # due to "C:\Program Files" being in the path. |
| 100 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 101 | # out with the old |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 102 | if [ -n "$ANDROID_BUILD_PATHS" ] ; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 103 | export PATH=${PATH/$ANDROID_BUILD_PATHS/} |
| 104 | fi |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 105 | if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 106 | export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/} |
| 107 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 108 | |
| 109 | # and in with the new |
| 110 | CODE_REVIEWS= |
| 111 | prebuiltdir=$(getprebuilt) |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 112 | toolchaindir=toolchain/arm-eabi-4.4.3/bin |
| 113 | # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it. |
| 114 | if [ -d "$prebuiltdir/$toolchaindir" ]; then |
| 115 | export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir |
| 116 | else |
| 117 | export ANDROID_EABI_TOOLCHAIN= |
| 118 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 119 | export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN |
| 120 | export ANDROID_QTOOLS=$T/development/emulator/qtools |
| 121 | export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_EABI_TOOLCHAIN$CODE_REVIEWS |
| 122 | export PATH=$PATH$ANDROID_BUILD_PATHS |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 123 | |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 124 | unset ANDROID_JAVA_TOOLCHAIN |
| 125 | if [ -n "$JAVA_HOME" ]; then |
| 126 | export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin |
| 127 | fi |
| 128 | export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN |
| 129 | if [ -n "$ANDROID_PRE_BUILD_PATHS" ]; then |
| 130 | export PATH=$ANDROID_PRE_BUILD_PATHS:$PATH |
| 131 | fi |
| 132 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 133 | unset ANDROID_PRODUCT_OUT |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 134 | export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT) |
| 135 | export OUT=$ANDROID_PRODUCT_OUT |
| 136 | |
Ed Heyl | 4f2297d | 2011-06-07 12:02:51 -0700 | [diff] [blame] | 137 | unset ANDROID_HOST_OUT |
| 138 | export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT) |
| 139 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 140 | # needed for building linux on MacOS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 141 | # TODO: fix the path |
| 142 | #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 143 | |
| 144 | # needed for OProfile to post-process collected samples |
| 145 | export OPROFILE_EVENTS_DIR=$prebuiltdir/oprofile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | function printconfig() |
| 149 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 150 | T=$(gettop) |
| 151 | if [ ! "$T" ]; then |
| 152 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 153 | return |
| 154 | fi |
| 155 | get_build_var report_config |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | function set_stuff_for_environment() |
| 159 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 160 | settitle |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 161 | set_java_home |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 162 | setpaths |
| 163 | set_sequence_number |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 164 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 165 | export ANDROID_BUILD_TOP=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | function set_sequence_number() |
| 169 | { |
Joe Onorato | aee4daa | 2010-06-23 14:03:13 -0700 | [diff] [blame] | 170 | export BUILD_ENV_SEQUENCE_NUMBER=10 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | function settitle() |
| 174 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 175 | if [ "$STAY_OFF_MY_LAWN" = "" ]; then |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 176 | local product=$TARGET_PRODUCT |
| 177 | local variant=$TARGET_BUILD_VARIANT |
| 178 | local apps=$TARGET_BUILD_APPS |
| 179 | if [ -z "$apps" ]; then |
| 180 | export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\"" |
| 181 | else |
| 182 | export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\"" |
| 183 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 184 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | case `uname -s` in |
| 188 | Linux) |
| 189 | function choosesim() |
| 190 | { |
| 191 | echo "Build for the simulator or the device?" |
| 192 | echo " 1. Device" |
| 193 | echo " 2. Simulator" |
| 194 | echo |
| 195 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 196 | export TARGET_SIMULATOR= |
| 197 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 198 | while [ -z $TARGET_SIMULATOR ] |
| 199 | do |
| 200 | echo -n "Which would you like? [1] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 201 | if [ -z "$1" ] ; then |
| 202 | read ANSWER |
| 203 | else |
| 204 | echo $1 |
| 205 | ANSWER=$1 |
| 206 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 207 | case $ANSWER in |
| 208 | "") |
| 209 | export TARGET_SIMULATOR=false |
| 210 | ;; |
| 211 | 1) |
| 212 | export TARGET_SIMULATOR=false |
| 213 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 214 | Device) |
| 215 | export TARGET_SIMULATOR=false |
| 216 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 217 | 2) |
| 218 | export TARGET_SIMULATOR=true |
| 219 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 220 | Simulator) |
| 221 | export TARGET_SIMULATOR=true |
| 222 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 223 | *) |
| 224 | echo |
| 225 | echo "I didn't understand your response. Please try again." |
| 226 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 227 | ;; |
| 228 | esac |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 229 | if [ -n "$1" ] ; then |
| 230 | break |
| 231 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 232 | done |
| 233 | |
| 234 | set_stuff_for_environment |
| 235 | } |
| 236 | ;; |
| 237 | *) |
| 238 | function choosesim() |
| 239 | { |
| 240 | echo "Only device builds are supported for" `uname -s` |
| 241 | echo " Forcing TARGET_SIMULATOR=false" |
| 242 | echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 243 | if [ -z "$1" ] |
| 244 | then |
| 245 | echo -n "Press enter: " |
| 246 | read |
| 247 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 248 | |
| 249 | export TARGET_SIMULATOR=false |
| 250 | set_stuff_for_environment |
| 251 | } |
| 252 | ;; |
| 253 | esac |
| 254 | |
| 255 | function choosetype() |
| 256 | { |
| 257 | echo "Build type choices are:" |
| 258 | echo " 1. release" |
| 259 | echo " 2. debug" |
| 260 | echo |
| 261 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 262 | local DEFAULT_NUM DEFAULT_VALUE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 263 | if [ $TARGET_SIMULATOR = "false" ] ; then |
| 264 | DEFAULT_NUM=1 |
| 265 | DEFAULT_VALUE=release |
| 266 | else |
| 267 | DEFAULT_NUM=2 |
| 268 | DEFAULT_VALUE=debug |
| 269 | fi |
| 270 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 271 | export TARGET_BUILD_TYPE= |
| 272 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 273 | while [ -z $TARGET_BUILD_TYPE ] |
| 274 | do |
| 275 | echo -n "Which would you like? ["$DEFAULT_NUM"] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 276 | if [ -z "$1" ] ; then |
| 277 | read ANSWER |
| 278 | else |
| 279 | echo $1 |
| 280 | ANSWER=$1 |
| 281 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 282 | case $ANSWER in |
| 283 | "") |
| 284 | export TARGET_BUILD_TYPE=$DEFAULT_VALUE |
| 285 | ;; |
| 286 | 1) |
| 287 | export TARGET_BUILD_TYPE=release |
| 288 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 289 | release) |
| 290 | export TARGET_BUILD_TYPE=release |
| 291 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 292 | 2) |
| 293 | export TARGET_BUILD_TYPE=debug |
| 294 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 295 | debug) |
| 296 | export TARGET_BUILD_TYPE=debug |
| 297 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 298 | *) |
| 299 | echo |
| 300 | echo "I didn't understand your response. Please try again." |
| 301 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 302 | ;; |
| 303 | esac |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 304 | if [ -n "$1" ] ; then |
| 305 | break |
| 306 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 307 | done |
| 308 | |
| 309 | set_stuff_for_environment |
| 310 | } |
| 311 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 312 | # |
| 313 | # This function isn't really right: It chooses a TARGET_PRODUCT |
| 314 | # based on the list of boards. Usually, that gets you something |
| 315 | # that kinda works with a generic product, but really, you should |
| 316 | # pick a product by name. |
| 317 | # |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 318 | function chooseproduct() |
| 319 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 320 | if [ "x$TARGET_PRODUCT" != x ] ; then |
| 321 | default_value=$TARGET_PRODUCT |
| 322 | else |
| 323 | if [ "$TARGET_SIMULATOR" = true ] ; then |
| 324 | default_value=sim |
| 325 | else |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 326 | default_value=full |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 327 | fi |
| 328 | fi |
| 329 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 330 | export TARGET_PRODUCT= |
| 331 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 332 | while [ -z "$TARGET_PRODUCT" ] |
| 333 | do |
Joe Onorato | 8849aed | 2009-04-29 15:56:47 -0700 | [diff] [blame] | 334 | echo -n "Which product would you like? [$default_value] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 335 | if [ -z "$1" ] ; then |
| 336 | read ANSWER |
| 337 | else |
| 338 | echo $1 |
| 339 | ANSWER=$1 |
| 340 | fi |
| 341 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 342 | if [ -z "$ANSWER" ] ; then |
| 343 | export TARGET_PRODUCT=$default_value |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 344 | else |
| 345 | if check_product $ANSWER |
| 346 | then |
| 347 | export TARGET_PRODUCT=$ANSWER |
| 348 | else |
| 349 | echo "** Not a valid product: $ANSWER" |
| 350 | fi |
| 351 | fi |
| 352 | if [ -n "$1" ] ; then |
| 353 | break |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 354 | fi |
| 355 | done |
| 356 | |
| 357 | set_stuff_for_environment |
| 358 | } |
| 359 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 360 | function choosevariant() |
| 361 | { |
| 362 | echo "Variant choices are:" |
| 363 | local index=1 |
| 364 | local v |
| 365 | for v in ${VARIANT_CHOICES[@]} |
| 366 | do |
| 367 | # The product name is the name of the directory containing |
| 368 | # the makefile we found, above. |
| 369 | echo " $index. $v" |
| 370 | index=$(($index+1)) |
| 371 | done |
| 372 | |
| 373 | local default_value=eng |
| 374 | local ANSWER |
| 375 | |
| 376 | export TARGET_BUILD_VARIANT= |
| 377 | while [ -z "$TARGET_BUILD_VARIANT" ] |
| 378 | do |
| 379 | echo -n "Which would you like? [$default_value] " |
| 380 | if [ -z "$1" ] ; then |
| 381 | read ANSWER |
| 382 | else |
| 383 | echo $1 |
| 384 | ANSWER=$1 |
| 385 | fi |
| 386 | |
| 387 | if [ -z "$ANSWER" ] ; then |
| 388 | export TARGET_BUILD_VARIANT=$default_value |
| 389 | elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then |
| 390 | if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 391 | export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 392 | fi |
| 393 | else |
| 394 | if check_variant $ANSWER |
| 395 | then |
| 396 | export TARGET_BUILD_VARIANT=$ANSWER |
| 397 | else |
| 398 | echo "** Not a valid variant: $ANSWER" |
| 399 | fi |
| 400 | fi |
| 401 | if [ -n "$1" ] ; then |
| 402 | break |
| 403 | fi |
| 404 | done |
| 405 | } |
| 406 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 407 | function choosecombo() |
| 408 | { |
| 409 | choosesim $1 |
| 410 | |
| 411 | echo |
| 412 | echo |
| 413 | choosetype $2 |
| 414 | |
| 415 | echo |
| 416 | echo |
| 417 | chooseproduct $3 |
| 418 | |
| 419 | echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 420 | echo |
| 421 | choosevariant $4 |
| 422 | |
| 423 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 424 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 425 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 426 | } |
| 427 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 428 | # Clear this variable. It will be built up again when the vendorsetup.sh |
| 429 | # files are included at the end of this file. |
| 430 | unset LUNCH_MENU_CHOICES |
| 431 | function add_lunch_combo() |
| 432 | { |
| 433 | local new_combo=$1 |
| 434 | local c |
| 435 | for c in ${LUNCH_MENU_CHOICES[@]} ; do |
| 436 | if [ "$new_combo" = "$c" ] ; then |
| 437 | return |
| 438 | fi |
| 439 | done |
| 440 | LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) |
| 441 | } |
| 442 | |
| 443 | # add the default one here |
Jean-Baptiste Queru | 45038e0 | 2010-07-01 09:22:53 -0700 | [diff] [blame] | 444 | add_lunch_combo full-eng |
Jean-Baptiste Queru | 6c2df3e | 2010-07-15 14:04:39 -0700 | [diff] [blame] | 445 | add_lunch_combo full_x86-eng |
Bruce Beare | ba366c4 | 2011-02-15 16:46:08 -0800 | [diff] [blame] | 446 | add_lunch_combo vbox_x86-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 447 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 448 | function print_lunch_menu() |
| 449 | { |
| 450 | local uname=$(uname) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 451 | echo |
| 452 | echo "You're building on" $uname |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 453 | echo |
| 454 | echo "Lunch menu... pick a combo:" |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 455 | |
| 456 | local i=1 |
| 457 | local choice |
| 458 | for choice in ${LUNCH_MENU_CHOICES[@]} |
| 459 | do |
| 460 | echo " $i. $choice" |
| 461 | i=$(($i+1)) |
| 462 | done |
| 463 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 464 | echo |
| 465 | } |
| 466 | |
| 467 | function lunch() |
| 468 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 469 | local answer |
| 470 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 471 | if [ "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 472 | answer=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 473 | else |
| 474 | print_lunch_menu |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 475 | echo -n "Which would you like? [full-eng] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 476 | read answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 477 | fi |
| 478 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 479 | local selection= |
| 480 | |
| 481 | if [ -z "$answer" ] |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 482 | then |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 483 | selection=full-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 484 | elif [ "$answer" = "simulator" ] |
| 485 | then |
| 486 | selection=simulator |
| 487 | elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") |
| 488 | then |
| 489 | if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ] |
| 490 | then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 491 | selection=${LUNCH_MENU_CHOICES[$(($answer-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 492 | fi |
| 493 | elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$") |
| 494 | then |
| 495 | selection=$answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 496 | fi |
| 497 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 498 | if [ -z "$selection" ] |
| 499 | then |
| 500 | echo |
| 501 | echo "Invalid lunch combo: $answer" |
| 502 | return 1 |
| 503 | fi |
| 504 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 505 | export TARGET_BUILD_APPS= |
| 506 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 507 | # special case the simulator |
| 508 | if [ "$selection" = "simulator" ] |
| 509 | then |
| 510 | export TARGET_PRODUCT=sim |
| 511 | export TARGET_BUILD_VARIANT=eng |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 512 | export TARGET_SIMULATOR=true |
| 513 | export TARGET_BUILD_TYPE=debug |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 514 | else |
| 515 | local product=$(echo -n $selection | sed -e "s/-.*$//") |
| 516 | check_product $product |
| 517 | if [ $? -ne 0 ] |
| 518 | then |
| 519 | echo |
| 520 | echo "** Don't have a product spec for: '$product'" |
| 521 | echo "** Do you have the right repo manifest?" |
| 522 | product= |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 523 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 524 | |
| 525 | local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//") |
| 526 | check_variant $variant |
| 527 | if [ $? -ne 0 ] |
| 528 | then |
| 529 | echo |
| 530 | echo "** Invalid variant: '$variant'" |
| 531 | echo "** Must be one of ${VARIANT_CHOICES[@]}" |
| 532 | variant= |
| 533 | fi |
| 534 | |
| 535 | if [ -z "$product" -o -z "$variant" ] |
| 536 | then |
| 537 | echo |
| 538 | return 1 |
| 539 | fi |
| 540 | |
| 541 | export TARGET_PRODUCT=$product |
| 542 | export TARGET_BUILD_VARIANT=$variant |
| 543 | export TARGET_SIMULATOR=false |
| 544 | export TARGET_BUILD_TYPE=release |
| 545 | fi # !simulator |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 546 | |
| 547 | echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 548 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 549 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 550 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 553 | # Configures the build to build unbundled apps. |
| 554 | # Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME) |
| 555 | function tapas() |
| 556 | { |
| 557 | local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$')) |
| 558 | local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$')) |
| 559 | |
| 560 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 561 | echo "tapas: Error: Multiple build variants supplied: $variant" |
| 562 | return |
| 563 | fi |
| 564 | if [ -z "$variant" ]; then |
| 565 | variant=eng |
| 566 | fi |
Ying Wang | c048c9b | 2010-06-24 15:08:33 -0700 | [diff] [blame] | 567 | if [ -z "$apps" ]; then |
| 568 | apps=all |
| 569 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 570 | |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 571 | export TARGET_PRODUCT=full |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 572 | export TARGET_BUILD_VARIANT=$variant |
| 573 | export TARGET_SIMULATOR=false |
| 574 | export TARGET_BUILD_TYPE=release |
| 575 | export TARGET_BUILD_APPS=$apps |
| 576 | |
| 577 | set_stuff_for_environment |
| 578 | printconfig |
| 579 | } |
| 580 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 581 | function gettop |
| 582 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 583 | local TOPFILE=build/core/envsetup.mk |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 584 | if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then |
| 585 | echo $TOP |
| 586 | else |
| 587 | if [ -f $TOPFILE ] ; then |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 588 | # The following circumlocution (repeated below as well) ensures |
| 589 | # that we record the true directory name and not one that is |
| 590 | # faked up with symlink names. |
| 591 | PWD= /bin/pwd |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 592 | else |
| 593 | # We redirect cd to /dev/null in case it's aliased to |
| 594 | # a command that prints something as a side-effect |
| 595 | # (like pushd) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 596 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 597 | T= |
| 598 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 599 | cd .. > /dev/null |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 600 | T=`PWD= /bin/pwd` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 601 | done |
| 602 | cd $HERE > /dev/null |
| 603 | if [ -f "$T/$TOPFILE" ]; then |
| 604 | echo $T |
| 605 | fi |
| 606 | fi |
| 607 | fi |
| 608 | } |
| 609 | |
| 610 | function m() |
| 611 | { |
| 612 | T=$(gettop) |
| 613 | if [ "$T" ]; then |
| 614 | make -C $T $@ |
| 615 | else |
| 616 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 617 | fi |
| 618 | } |
| 619 | |
| 620 | function findmakefile() |
| 621 | { |
| 622 | TOPFILE=build/core/envsetup.mk |
| 623 | # We redirect cd to /dev/null in case it's aliased to |
| 624 | # a command that prints something as a side-effect |
| 625 | # (like pushd) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 626 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 627 | T= |
| 628 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 629 | T=$PWD |
| 630 | if [ -f "$T/Android.mk" ]; then |
| 631 | echo $T/Android.mk |
| 632 | cd $HERE > /dev/null |
| 633 | return |
| 634 | fi |
| 635 | cd .. > /dev/null |
| 636 | done |
| 637 | cd $HERE > /dev/null |
| 638 | } |
| 639 | |
| 640 | function mm() |
| 641 | { |
| 642 | # If we're sitting in the root of the build tree, just do a |
| 643 | # normal make. |
| 644 | if [ -f build/core/envsetup.mk -a -f Makefile ]; then |
| 645 | make $@ |
| 646 | else |
| 647 | # Find the closest Android.mk file. |
| 648 | T=$(gettop) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 649 | local M=$(findmakefile) |
Robert Greenwalt | 3c794d7 | 2009-07-15 15:07:44 -0700 | [diff] [blame] | 650 | # Remove the path to top as the makefilepath needs to be relative |
| 651 | local M=`echo $M|sed 's:'$T'/::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 652 | if [ ! "$T" ]; then |
| 653 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 654 | elif [ ! "$M" ]; then |
| 655 | echo "Couldn't locate a makefile from the current directory." |
| 656 | else |
Ying Wang | 0188414 | 2010-07-20 16:18:16 -0700 | [diff] [blame] | 657 | ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 658 | fi |
| 659 | fi |
| 660 | } |
| 661 | |
| 662 | function mmm() |
| 663 | { |
| 664 | T=$(gettop) |
| 665 | if [ "$T" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 666 | local MAKEFILE= |
| 667 | local ARGS= |
| 668 | local DIR TO_CHOP |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 669 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 670 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 671 | for DIR in $DIRS ; do |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 672 | DIR=`echo $DIR | sed -e 's:/$::'` |
| 673 | if [ -f $DIR/Android.mk ]; then |
Brian Carlstrom | c634d2c | 2010-09-17 12:25:50 -0700 | [diff] [blame] | 674 | 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] | 675 | TO_CHOP=`expr $TO_CHOP + 1` |
Gilles Debunne | 8a20f58 | 2010-02-17 15:56:45 -0800 | [diff] [blame] | 676 | START=`PWD= /bin/pwd` |
| 677 | MFILE=`echo $START | cut -c${TO_CHOP}-` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 678 | if [ "$MFILE" = "" ] ; then |
| 679 | MFILE=$DIR/Android.mk |
| 680 | else |
| 681 | MFILE=$MFILE/$DIR/Android.mk |
| 682 | fi |
| 683 | MAKEFILE="$MAKEFILE $MFILE" |
| 684 | else |
| 685 | if [ "$DIR" = snod ]; then |
| 686 | ARGS="$ARGS snod" |
| 687 | elif [ "$DIR" = showcommands ]; then |
| 688 | ARGS="$ARGS showcommands" |
Ying Wang | 0188414 | 2010-07-20 16:18:16 -0700 | [diff] [blame] | 689 | elif [ "$DIR" = dist ]; then |
| 690 | ARGS="$ARGS dist" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 691 | else |
| 692 | echo "No Android.mk in $DIR." |
Joe Onorato | 51e6182 | 2009-04-13 15:36:15 -0400 | [diff] [blame] | 693 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 694 | fi |
| 695 | fi |
| 696 | done |
Ying Wang | 0188414 | 2010-07-20 16:18:16 -0700 | [diff] [blame] | 697 | ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 698 | else |
| 699 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 700 | fi |
| 701 | } |
| 702 | |
| 703 | function croot() |
| 704 | { |
| 705 | T=$(gettop) |
| 706 | if [ "$T" ]; then |
| 707 | cd $(gettop) |
| 708 | else |
| 709 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 710 | fi |
| 711 | } |
| 712 | |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 713 | function cproj() |
| 714 | { |
| 715 | TOPFILE=build/core/envsetup.mk |
| 716 | # We redirect cd to /dev/null in case it's aliased to |
| 717 | # a command that prints something as a side-effect |
| 718 | # (like pushd) |
| 719 | local HERE=$PWD |
| 720 | T= |
| 721 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 722 | T=$PWD |
| 723 | if [ -f "$T/Android.mk" ]; then |
| 724 | cd $T |
| 725 | return |
| 726 | fi |
| 727 | cd .. > /dev/null |
| 728 | done |
| 729 | cd $HERE > /dev/null |
| 730 | echo "can't find Android.mk" |
| 731 | } |
| 732 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 733 | function pid() |
| 734 | { |
| 735 | local EXE="$1" |
| 736 | if [ "$EXE" ] ; then |
| 737 | local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'` |
| 738 | echo "$PID" |
| 739 | else |
| 740 | echo "usage: pid name" |
| 741 | fi |
| 742 | } |
| 743 | |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 744 | # systemstack - dump the current stack trace of all threads in the system process |
| 745 | # to the usual ANR traces file |
| 746 | function systemstack() |
| 747 | { |
| 748 | adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server) |
| 749 | } |
| 750 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 751 | function gdbclient() |
| 752 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 753 | local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT) |
| 754 | local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED) |
| 755 | local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED) |
| 756 | local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED) |
| 757 | local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 758 | if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then |
| 759 | local EXE="$1" |
| 760 | if [ "$EXE" ] ; then |
| 761 | EXE=$1 |
| 762 | else |
| 763 | EXE="app_process" |
| 764 | fi |
| 765 | |
| 766 | local PORT="$2" |
| 767 | if [ "$PORT" ] ; then |
| 768 | PORT=$2 |
| 769 | else |
| 770 | PORT=":5039" |
| 771 | fi |
| 772 | |
| 773 | local PID |
| 774 | local PROG="$3" |
| 775 | if [ "$PROG" ] ; then |
| 776 | PID=`pid $3` |
| 777 | adb forward "tcp$PORT" "tcp$PORT" |
| 778 | adb shell gdbserver $PORT --attach $PID & |
| 779 | sleep 2 |
| 780 | else |
| 781 | echo "" |
| 782 | echo "If you haven't done so already, do this first on the device:" |
| 783 | echo " gdbserver $PORT /system/bin/$EXE" |
| 784 | echo " or" |
| 785 | echo " gdbserver $PORT --attach $PID" |
| 786 | echo "" |
| 787 | fi |
| 788 | |
| 789 | echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS" |
| 790 | echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS" |
| 791 | echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT" |
| 792 | echo >>"$OUT_ROOT/gdbclient.cmds" "" |
| 793 | |
| 794 | arm-eabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE" |
| 795 | else |
| 796 | echo "Unable to determine build system output dir." |
| 797 | fi |
| 798 | |
| 799 | } |
| 800 | |
| 801 | case `uname -s` in |
| 802 | Darwin) |
| 803 | function sgrep() |
| 804 | { |
Benno Leslie | 5ef878a | 2009-02-27 21:04:08 +1100 | [diff] [blame] | 805 | find -E . -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] | 806 | } |
| 807 | |
| 808 | ;; |
| 809 | *) |
| 810 | function sgrep() |
| 811 | { |
Benno Leslie | 5ef878a | 2009-02-27 21:04:08 +1100 | [diff] [blame] | 812 | find . -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] | 813 | } |
| 814 | ;; |
| 815 | esac |
| 816 | |
| 817 | function jgrep() |
| 818 | { |
| 819 | find . -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@" |
| 820 | } |
| 821 | |
| 822 | function cgrep() |
| 823 | { |
Ficus Kirkpatrick | 8889bdf | 2010-03-01 16:51:47 -0800 | [diff] [blame] | 824 | find . -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] | 825 | } |
| 826 | |
| 827 | function resgrep() |
| 828 | { |
| 829 | for dir in `find . -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done; |
| 830 | } |
| 831 | |
| 832 | case `uname -s` in |
| 833 | Darwin) |
| 834 | function mgrep() |
| 835 | { |
| 836 | find -E . -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@" |
| 837 | } |
| 838 | |
| 839 | function treegrep() |
| 840 | { |
| 841 | find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@" |
| 842 | } |
| 843 | |
| 844 | ;; |
| 845 | *) |
| 846 | function mgrep() |
| 847 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 848 | find . -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] | 849 | } |
| 850 | |
| 851 | function treegrep() |
| 852 | { |
| 853 | find . -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@" |
| 854 | } |
| 855 | |
| 856 | ;; |
| 857 | esac |
| 858 | |
| 859 | function getprebuilt |
| 860 | { |
| 861 | get_abs_build_var ANDROID_PREBUILTS |
| 862 | } |
| 863 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 864 | function tracedmdump() |
| 865 | { |
| 866 | T=$(gettop) |
| 867 | if [ ! "$T" ]; then |
| 868 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 869 | return |
| 870 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 871 | local prebuiltdir=$(getprebuilt) |
Jack Veenstra | 60116fc | 2009-04-09 18:12:34 -0700 | [diff] [blame] | 872 | local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 873 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 874 | local TRACE=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 875 | if [ ! "$TRACE" ] ; then |
| 876 | echo "usage: tracedmdump tracename" |
| 877 | return |
| 878 | fi |
| 879 | |
Jack Veenstra | 60116fc | 2009-04-09 18:12:34 -0700 | [diff] [blame] | 880 | if [ ! -r "$KERNEL" ] ; then |
| 881 | echo "Error: cannot find kernel: '$KERNEL'" |
| 882 | return |
| 883 | fi |
| 884 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 885 | local BASETRACE=$(basename $TRACE) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 886 | if [ "$BASETRACE" = "$TRACE" ] ; then |
| 887 | TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE |
| 888 | fi |
| 889 | |
| 890 | echo "post-processing traces..." |
| 891 | rm -f $TRACE/qtrace.dexlist |
| 892 | post_trace $TRACE |
| 893 | if [ $? -ne 0 ]; then |
| 894 | echo "***" |
| 895 | echo "*** Error: malformed trace. Did you remember to exit the emulator?" |
| 896 | echo "***" |
| 897 | return |
| 898 | fi |
| 899 | echo "generating dexlist output..." |
| 900 | /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 |
| 901 | echo "generating dmtrace data..." |
| 902 | q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return |
| 903 | echo "generating html file..." |
| 904 | dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return |
| 905 | echo "done, see $TRACE/dmtrace.html for details" |
| 906 | echo "or run:" |
| 907 | echo " traceview $TRACE/dmtrace" |
| 908 | } |
| 909 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 910 | # communicate with a running device or emulator, set up necessary state, |
| 911 | # and run the hat command. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 912 | function runhat() |
| 913 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 914 | # process standard adb options |
| 915 | local adbTarget="" |
Chris Dearman | f0bcf42 | 2011-02-16 12:16:09 -0800 | [diff] [blame] | 916 | if [ "$1" = "-d" -o "$1" = "-e" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 917 | adbTarget=$1 |
| 918 | shift 1 |
Chris Dearman | f0bcf42 | 2011-02-16 12:16:09 -0800 | [diff] [blame] | 919 | elif [ "$1" = "-s" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 920 | adbTarget="$1 $2" |
| 921 | shift 2 |
| 922 | fi |
| 923 | local adbOptions=${adbTarget} |
| 924 | echo adbOptions = ${adbOptions} |
| 925 | |
| 926 | # runhat options |
| 927 | local targetPid=$1 |
| 928 | local outputFile=$2 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 929 | |
| 930 | if [ "$targetPid" = "" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 931 | echo "Usage: runhat [ -d | -e | -s serial ] target-pid [output-file]" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 932 | return |
| 933 | fi |
| 934 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 935 | # confirm hat is available |
| 936 | if [ -z $(which hat) ]; then |
| 937 | echo "hat is not available in this configuration." |
| 938 | return |
| 939 | fi |
| 940 | |
| 941 | adb ${adbOptions} shell >/dev/null mkdir /data/misc |
| 942 | adb ${adbOptions} shell chmod 777 /data/misc |
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 | # send a SIGUSR1 to cause the hprof dump |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 945 | echo "Poking $targetPid and waiting for data..." |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 946 | adb ${adbOptions} shell kill -10 $targetPid |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 947 | echo "Press enter when logcat shows \"hprof: heap dump completed\"" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 948 | echo -n "> " |
| 949 | read |
| 950 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 951 | local availFiles=( $(adb ${adbOptions} shell ls /data/misc | grep '^heap-dump' | sed -e 's/.*heap-dump-/heap-dump-/' | sort -r | tr '[:space:][:cntrl:]' ' ') ) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 952 | local devFile=/data/misc/${availFiles[0]} |
| 953 | local localFile=/tmp/$$-hprof |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 954 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 955 | echo "Retrieving file $devFile..." |
| 956 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 957 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 958 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 959 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 960 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 961 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 962 | echo "" |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 963 | hat $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | function getbugreports() |
| 967 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 968 | 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] | 969 | |
| 970 | if [ ! "$reports" ]; then |
| 971 | echo "Could not locate any bugreports." |
| 972 | return |
| 973 | fi |
| 974 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 975 | local report |
| 976 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 977 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 978 | echo "/sdcard/bugreports/${report}" |
| 979 | adb pull /sdcard/bugreports/${report} ${report} |
| 980 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 981 | done |
| 982 | } |
| 983 | |
| 984 | function startviewserver() |
| 985 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 986 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 987 | if [ $# -gt 0 ]; then |
| 988 | port=$1 |
| 989 | fi |
| 990 | adb shell service call window 1 i32 $port |
| 991 | } |
| 992 | |
| 993 | function stopviewserver() |
| 994 | { |
| 995 | adb shell service call window 2 |
| 996 | } |
| 997 | |
| 998 | function isviewserverstarted() |
| 999 | { |
| 1000 | adb shell service call window 3 |
| 1001 | } |
| 1002 | |
| 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 |
| 1047 | lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq)) |
| 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 |
| 1060 | index=$(($index + 1)) |
| 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 |