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