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 | |
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 | export ANDROID_BUILD_TOP=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | function set_sequence_number() |
| 157 | { |
Joe Onorato | aee4daa | 2010-06-23 14:03:13 -0700 | [diff] [blame] | 158 | export BUILD_ENV_SEQUENCE_NUMBER=10 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | function settitle() |
| 162 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 163 | if [ "$STAY_OFF_MY_LAWN" = "" ]; then |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 164 | local product=$TARGET_PRODUCT |
| 165 | local variant=$TARGET_BUILD_VARIANT |
| 166 | local apps=$TARGET_BUILD_APPS |
| 167 | if [ -z "$apps" ]; then |
| 168 | export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\"" |
| 169 | else |
| 170 | export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\"" |
| 171 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 172 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | case `uname -s` in |
| 176 | Linux) |
| 177 | function choosesim() |
| 178 | { |
| 179 | echo "Build for the simulator or the device?" |
| 180 | echo " 1. Device" |
| 181 | echo " 2. Simulator" |
| 182 | echo |
| 183 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 184 | export TARGET_SIMULATOR= |
| 185 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 186 | while [ -z $TARGET_SIMULATOR ] |
| 187 | do |
| 188 | echo -n "Which would you like? [1] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 189 | if [ -z "$1" ] ; then |
| 190 | read ANSWER |
| 191 | else |
| 192 | echo $1 |
| 193 | ANSWER=$1 |
| 194 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 195 | case $ANSWER in |
| 196 | "") |
| 197 | export TARGET_SIMULATOR=false |
| 198 | ;; |
| 199 | 1) |
| 200 | export TARGET_SIMULATOR=false |
| 201 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 202 | Device) |
| 203 | export TARGET_SIMULATOR=false |
| 204 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 205 | 2) |
| 206 | export TARGET_SIMULATOR=true |
| 207 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 208 | Simulator) |
| 209 | export TARGET_SIMULATOR=true |
| 210 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 211 | *) |
| 212 | echo |
| 213 | echo "I didn't understand your response. Please try again." |
| 214 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 215 | ;; |
| 216 | esac |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 217 | if [ -n "$1" ] ; then |
| 218 | break |
| 219 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 220 | done |
| 221 | |
| 222 | set_stuff_for_environment |
| 223 | } |
| 224 | ;; |
| 225 | *) |
| 226 | function choosesim() |
| 227 | { |
| 228 | echo "Only device builds are supported for" `uname -s` |
| 229 | echo " Forcing TARGET_SIMULATOR=false" |
| 230 | echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 231 | if [ -z "$1" ] |
| 232 | then |
| 233 | echo -n "Press enter: " |
| 234 | read |
| 235 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 236 | |
| 237 | export TARGET_SIMULATOR=false |
| 238 | set_stuff_for_environment |
| 239 | } |
| 240 | ;; |
| 241 | esac |
| 242 | |
| 243 | function choosetype() |
| 244 | { |
| 245 | echo "Build type choices are:" |
| 246 | echo " 1. release" |
| 247 | echo " 2. debug" |
| 248 | echo |
| 249 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 250 | local DEFAULT_NUM DEFAULT_VALUE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 251 | if [ $TARGET_SIMULATOR = "false" ] ; then |
| 252 | DEFAULT_NUM=1 |
| 253 | DEFAULT_VALUE=release |
| 254 | else |
| 255 | DEFAULT_NUM=2 |
| 256 | DEFAULT_VALUE=debug |
| 257 | fi |
| 258 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 259 | export TARGET_BUILD_TYPE= |
| 260 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 261 | while [ -z $TARGET_BUILD_TYPE ] |
| 262 | do |
| 263 | echo -n "Which would you like? ["$DEFAULT_NUM"] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 264 | if [ -z "$1" ] ; then |
| 265 | read ANSWER |
| 266 | else |
| 267 | echo $1 |
| 268 | ANSWER=$1 |
| 269 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 270 | case $ANSWER in |
| 271 | "") |
| 272 | export TARGET_BUILD_TYPE=$DEFAULT_VALUE |
| 273 | ;; |
| 274 | 1) |
| 275 | export TARGET_BUILD_TYPE=release |
| 276 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 277 | release) |
| 278 | export TARGET_BUILD_TYPE=release |
| 279 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 280 | 2) |
| 281 | export TARGET_BUILD_TYPE=debug |
| 282 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 283 | debug) |
| 284 | export TARGET_BUILD_TYPE=debug |
| 285 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 286 | *) |
| 287 | echo |
| 288 | echo "I didn't understand your response. Please try again." |
| 289 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 290 | ;; |
| 291 | esac |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 292 | if [ -n "$1" ] ; then |
| 293 | break |
| 294 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 295 | done |
| 296 | |
| 297 | set_stuff_for_environment |
| 298 | } |
| 299 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 300 | # |
| 301 | # This function isn't really right: It chooses a TARGET_PRODUCT |
| 302 | # based on the list of boards. Usually, that gets you something |
| 303 | # that kinda works with a generic product, but really, you should |
| 304 | # pick a product by name. |
| 305 | # |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 306 | function chooseproduct() |
| 307 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 308 | if [ "x$TARGET_PRODUCT" != x ] ; then |
| 309 | default_value=$TARGET_PRODUCT |
| 310 | else |
| 311 | if [ "$TARGET_SIMULATOR" = true ] ; then |
| 312 | default_value=sim |
| 313 | else |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 314 | default_value=full |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 315 | fi |
| 316 | fi |
| 317 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 318 | export TARGET_PRODUCT= |
| 319 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 320 | while [ -z "$TARGET_PRODUCT" ] |
| 321 | do |
Joe Onorato | 8849aed | 2009-04-29 15:56:47 -0700 | [diff] [blame] | 322 | echo -n "Which product would you like? [$default_value] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 323 | if [ -z "$1" ] ; then |
| 324 | read ANSWER |
| 325 | else |
| 326 | echo $1 |
| 327 | ANSWER=$1 |
| 328 | fi |
| 329 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 330 | if [ -z "$ANSWER" ] ; then |
| 331 | export TARGET_PRODUCT=$default_value |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 332 | else |
| 333 | if check_product $ANSWER |
| 334 | then |
| 335 | export TARGET_PRODUCT=$ANSWER |
| 336 | else |
| 337 | echo "** Not a valid product: $ANSWER" |
| 338 | fi |
| 339 | fi |
| 340 | if [ -n "$1" ] ; then |
| 341 | break |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 342 | fi |
| 343 | done |
| 344 | |
| 345 | set_stuff_for_environment |
| 346 | } |
| 347 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 348 | function choosevariant() |
| 349 | { |
| 350 | echo "Variant choices are:" |
| 351 | local index=1 |
| 352 | local v |
| 353 | for v in ${VARIANT_CHOICES[@]} |
| 354 | do |
| 355 | # The product name is the name of the directory containing |
| 356 | # the makefile we found, above. |
| 357 | echo " $index. $v" |
| 358 | index=$(($index+1)) |
| 359 | done |
| 360 | |
| 361 | local default_value=eng |
| 362 | local ANSWER |
| 363 | |
| 364 | export TARGET_BUILD_VARIANT= |
| 365 | while [ -z "$TARGET_BUILD_VARIANT" ] |
| 366 | do |
| 367 | echo -n "Which would you like? [$default_value] " |
| 368 | if [ -z "$1" ] ; then |
| 369 | read ANSWER |
| 370 | else |
| 371 | echo $1 |
| 372 | ANSWER=$1 |
| 373 | fi |
| 374 | |
| 375 | if [ -z "$ANSWER" ] ; then |
| 376 | export TARGET_BUILD_VARIANT=$default_value |
| 377 | elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then |
| 378 | if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 379 | export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 380 | fi |
| 381 | else |
| 382 | if check_variant $ANSWER |
| 383 | then |
| 384 | export TARGET_BUILD_VARIANT=$ANSWER |
| 385 | else |
| 386 | echo "** Not a valid variant: $ANSWER" |
| 387 | fi |
| 388 | fi |
| 389 | if [ -n "$1" ] ; then |
| 390 | break |
| 391 | fi |
| 392 | done |
| 393 | } |
| 394 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 395 | function choosecombo() |
| 396 | { |
| 397 | choosesim $1 |
| 398 | |
| 399 | echo |
| 400 | echo |
| 401 | choosetype $2 |
| 402 | |
| 403 | echo |
| 404 | echo |
| 405 | chooseproduct $3 |
| 406 | |
| 407 | echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 408 | echo |
| 409 | choosevariant $4 |
| 410 | |
| 411 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 412 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 413 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 414 | } |
| 415 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 416 | # Clear this variable. It will be built up again when the vendorsetup.sh |
| 417 | # files are included at the end of this file. |
| 418 | unset LUNCH_MENU_CHOICES |
| 419 | function add_lunch_combo() |
| 420 | { |
| 421 | local new_combo=$1 |
| 422 | local c |
| 423 | for c in ${LUNCH_MENU_CHOICES[@]} ; do |
| 424 | if [ "$new_combo" = "$c" ] ; then |
| 425 | return |
| 426 | fi |
| 427 | done |
| 428 | LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) |
| 429 | } |
| 430 | |
| 431 | # add the default one here |
Jean-Baptiste Queru | 45038e0 | 2010-07-01 09:22:53 -0700 | [diff] [blame] | 432 | add_lunch_combo full-eng |
Jean-Baptiste Queru | 6c2df3e | 2010-07-15 14:04:39 -0700 | [diff] [blame] | 433 | add_lunch_combo full_x86-eng |
Bruce Beare | ba366c4 | 2011-02-15 16:46:08 -0800 | [diff] [blame] | 434 | add_lunch_combo vbox_x86-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 435 | |
| 436 | # if we're on linux, add the simulator. There is a special case |
| 437 | # in lunch to deal with the simulator |
| 438 | if [ "$(uname)" = "Linux" ] ; then |
| 439 | add_lunch_combo simulator |
| 440 | fi |
| 441 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 442 | function print_lunch_menu() |
| 443 | { |
| 444 | local uname=$(uname) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 445 | echo |
| 446 | echo "You're building on" $uname |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 447 | echo |
| 448 | echo "Lunch menu... pick a combo:" |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 449 | |
| 450 | local i=1 |
| 451 | local choice |
| 452 | for choice in ${LUNCH_MENU_CHOICES[@]} |
| 453 | do |
| 454 | echo " $i. $choice" |
| 455 | i=$(($i+1)) |
| 456 | done |
| 457 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 458 | echo |
| 459 | } |
| 460 | |
| 461 | function lunch() |
| 462 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 463 | local answer |
| 464 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 465 | if [ "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 466 | answer=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 467 | else |
| 468 | print_lunch_menu |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 469 | echo -n "Which would you like? [full-eng] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 470 | read answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 471 | fi |
| 472 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 473 | local selection= |
| 474 | |
| 475 | if [ -z "$answer" ] |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 476 | then |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 477 | selection=full-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 478 | elif [ "$answer" = "simulator" ] |
| 479 | then |
| 480 | selection=simulator |
| 481 | elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") |
| 482 | then |
| 483 | if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ] |
| 484 | then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 485 | selection=${LUNCH_MENU_CHOICES[$(($answer-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 486 | fi |
| 487 | elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$") |
| 488 | then |
| 489 | selection=$answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 490 | fi |
| 491 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 492 | if [ -z "$selection" ] |
| 493 | then |
| 494 | echo |
| 495 | echo "Invalid lunch combo: $answer" |
| 496 | return 1 |
| 497 | fi |
| 498 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 499 | export TARGET_BUILD_APPS= |
| 500 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 501 | # special case the simulator |
| 502 | if [ "$selection" = "simulator" ] |
| 503 | then |
| 504 | export TARGET_PRODUCT=sim |
| 505 | export TARGET_BUILD_VARIANT=eng |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 506 | export TARGET_SIMULATOR=true |
| 507 | export TARGET_BUILD_TYPE=debug |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 508 | else |
| 509 | local product=$(echo -n $selection | sed -e "s/-.*$//") |
| 510 | check_product $product |
| 511 | if [ $? -ne 0 ] |
| 512 | then |
| 513 | echo |
| 514 | echo "** Don't have a product spec for: '$product'" |
| 515 | echo "** Do you have the right repo manifest?" |
| 516 | product= |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 517 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 518 | |
| 519 | local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//") |
| 520 | check_variant $variant |
| 521 | if [ $? -ne 0 ] |
| 522 | then |
| 523 | echo |
| 524 | echo "** Invalid variant: '$variant'" |
| 525 | echo "** Must be one of ${VARIANT_CHOICES[@]}" |
| 526 | variant= |
| 527 | fi |
| 528 | |
| 529 | if [ -z "$product" -o -z "$variant" ] |
| 530 | then |
| 531 | echo |
| 532 | return 1 |
| 533 | fi |
| 534 | |
| 535 | export TARGET_PRODUCT=$product |
| 536 | export TARGET_BUILD_VARIANT=$variant |
| 537 | export TARGET_SIMULATOR=false |
| 538 | export TARGET_BUILD_TYPE=release |
| 539 | fi # !simulator |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 540 | |
| 541 | echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 542 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 543 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 544 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 547 | # Configures the build to build unbundled apps. |
| 548 | # Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME) |
| 549 | function tapas() |
| 550 | { |
| 551 | local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$')) |
| 552 | local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$')) |
| 553 | |
| 554 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 555 | echo "tapas: Error: Multiple build variants supplied: $variant" |
| 556 | return |
| 557 | fi |
| 558 | if [ -z "$variant" ]; then |
| 559 | variant=eng |
| 560 | fi |
Ying Wang | c048c9b | 2010-06-24 15:08:33 -0700 | [diff] [blame] | 561 | if [ -z "$apps" ]; then |
| 562 | apps=all |
| 563 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 564 | |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 565 | export TARGET_PRODUCT=full |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 566 | export TARGET_BUILD_VARIANT=$variant |
| 567 | export TARGET_SIMULATOR=false |
| 568 | export TARGET_BUILD_TYPE=release |
| 569 | export TARGET_BUILD_APPS=$apps |
| 570 | |
| 571 | set_stuff_for_environment |
| 572 | printconfig |
| 573 | } |
| 574 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 575 | function gettop |
| 576 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 577 | local TOPFILE=build/core/envsetup.mk |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 578 | if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then |
| 579 | echo $TOP |
| 580 | else |
| 581 | if [ -f $TOPFILE ] ; then |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 582 | # The following circumlocution (repeated below as well) ensures |
| 583 | # that we record the true directory name and not one that is |
| 584 | # faked up with symlink names. |
| 585 | PWD= /bin/pwd |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 586 | else |
| 587 | # We redirect cd to /dev/null in case it's aliased to |
| 588 | # a command that prints something as a side-effect |
| 589 | # (like pushd) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 590 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 591 | T= |
| 592 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 593 | cd .. > /dev/null |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 594 | T=`PWD= /bin/pwd` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 595 | done |
| 596 | cd $HERE > /dev/null |
| 597 | if [ -f "$T/$TOPFILE" ]; then |
| 598 | echo $T |
| 599 | fi |
| 600 | fi |
| 601 | fi |
| 602 | } |
| 603 | |
| 604 | function m() |
| 605 | { |
| 606 | T=$(gettop) |
| 607 | if [ "$T" ]; then |
| 608 | make -C $T $@ |
| 609 | else |
| 610 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 611 | fi |
| 612 | } |
| 613 | |
| 614 | function findmakefile() |
| 615 | { |
| 616 | TOPFILE=build/core/envsetup.mk |
| 617 | # We redirect cd to /dev/null in case it's aliased to |
| 618 | # a command that prints something as a side-effect |
| 619 | # (like pushd) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 620 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 621 | T= |
| 622 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 623 | T=$PWD |
| 624 | if [ -f "$T/Android.mk" ]; then |
| 625 | echo $T/Android.mk |
| 626 | cd $HERE > /dev/null |
| 627 | return |
| 628 | fi |
| 629 | cd .. > /dev/null |
| 630 | done |
| 631 | cd $HERE > /dev/null |
| 632 | } |
| 633 | |
| 634 | function mm() |
| 635 | { |
| 636 | # If we're sitting in the root of the build tree, just do a |
| 637 | # normal make. |
| 638 | if [ -f build/core/envsetup.mk -a -f Makefile ]; then |
| 639 | make $@ |
| 640 | else |
| 641 | # Find the closest Android.mk file. |
| 642 | T=$(gettop) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 643 | local M=$(findmakefile) |
Robert Greenwalt | 3c794d7 | 2009-07-15 15:07:44 -0700 | [diff] [blame] | 644 | # Remove the path to top as the makefilepath needs to be relative |
| 645 | local M=`echo $M|sed 's:'$T'/::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 646 | if [ ! "$T" ]; then |
| 647 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 648 | elif [ ! "$M" ]; then |
| 649 | echo "Couldn't locate a makefile from the current directory." |
| 650 | else |
Ying Wang | 0188414 | 2010-07-20 16:18:16 -0700 | [diff] [blame] | 651 | ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 652 | fi |
| 653 | fi |
| 654 | } |
| 655 | |
| 656 | function mmm() |
| 657 | { |
| 658 | T=$(gettop) |
| 659 | if [ "$T" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 660 | local MAKEFILE= |
| 661 | local ARGS= |
| 662 | local DIR TO_CHOP |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 663 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 664 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 665 | for DIR in $DIRS ; do |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 666 | DIR=`echo $DIR | sed -e 's:/$::'` |
| 667 | if [ -f $DIR/Android.mk ]; then |
Brian Carlstrom | c634d2c | 2010-09-17 12:25:50 -0700 | [diff] [blame] | 668 | 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] | 669 | TO_CHOP=`expr $TO_CHOP + 1` |
Gilles Debunne | 8a20f58 | 2010-02-17 15:56:45 -0800 | [diff] [blame] | 670 | START=`PWD= /bin/pwd` |
| 671 | MFILE=`echo $START | cut -c${TO_CHOP}-` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 672 | if [ "$MFILE" = "" ] ; then |
| 673 | MFILE=$DIR/Android.mk |
| 674 | else |
| 675 | MFILE=$MFILE/$DIR/Android.mk |
| 676 | fi |
| 677 | MAKEFILE="$MAKEFILE $MFILE" |
| 678 | else |
| 679 | if [ "$DIR" = snod ]; then |
| 680 | ARGS="$ARGS snod" |
| 681 | elif [ "$DIR" = showcommands ]; then |
| 682 | ARGS="$ARGS showcommands" |
Ying Wang | 0188414 | 2010-07-20 16:18:16 -0700 | [diff] [blame] | 683 | elif [ "$DIR" = dist ]; then |
| 684 | ARGS="$ARGS dist" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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 |
Ying Wang | 0188414 | 2010-07-20 16:18:16 -0700 | [diff] [blame] | 691 | 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] | 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="" |
Chris Dearman | f0bcf42 | 2011-02-16 12:16:09 -0800 | [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 |
Chris Dearman | f0bcf42 | 2011-02-16 12:16:09 -0800 | [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 |
| 922 | local outputFile=$2 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 923 | |
| 924 | if [ "$targetPid" = "" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 925 | 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] | 926 | return |
| 927 | fi |
| 928 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 929 | # confirm hat is available |
| 930 | if [ -z $(which hat) ]; then |
| 931 | echo "hat is not available in this configuration." |
| 932 | return |
| 933 | fi |
| 934 | |
| 935 | adb ${adbOptions} shell >/dev/null mkdir /data/misc |
| 936 | adb ${adbOptions} shell chmod 777 /data/misc |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 937 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 938 | # send a SIGUSR1 to cause the hprof dump |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 939 | echo "Poking $targetPid and waiting for data..." |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 940 | adb ${adbOptions} shell kill -10 $targetPid |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 941 | 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] | 942 | echo -n "> " |
| 943 | read |
| 944 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 945 | 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] | 946 | local devFile=/data/misc/${availFiles[0]} |
| 947 | local localFile=/tmp/$$-hprof |
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 "Retrieving file $devFile..." |
| 950 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 951 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 952 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 953 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 954 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 955 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 956 | echo "" |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 957 | hat $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | function getbugreports() |
| 961 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 962 | 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] | 963 | |
| 964 | if [ ! "$reports" ]; then |
| 965 | echo "Could not locate any bugreports." |
| 966 | return |
| 967 | fi |
| 968 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 969 | local report |
| 970 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 971 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 972 | echo "/sdcard/bugreports/${report}" |
| 973 | adb pull /sdcard/bugreports/${report} ${report} |
| 974 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 975 | done |
| 976 | } |
| 977 | |
| 978 | function startviewserver() |
| 979 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 980 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 981 | if [ $# -gt 0 ]; then |
| 982 | port=$1 |
| 983 | fi |
| 984 | adb shell service call window 1 i32 $port |
| 985 | } |
| 986 | |
| 987 | function stopviewserver() |
| 988 | { |
| 989 | adb shell service call window 2 |
| 990 | } |
| 991 | |
| 992 | function isviewserverstarted() |
| 993 | { |
| 994 | adb shell service call window 3 |
| 995 | } |
| 996 | |
| 997 | function smoketest() |
| 998 | { |
| 999 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1000 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1001 | return |
| 1002 | fi |
| 1003 | T=$(gettop) |
| 1004 | if [ ! "$T" ]; then |
| 1005 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1006 | return |
| 1007 | fi |
| 1008 | |
| 1009 | (cd "$T" && mmm tests/SmokeTest) && |
| 1010 | adb uninstall com.android.smoketest > /dev/null && |
| 1011 | adb uninstall com.android.smoketest.tests > /dev/null && |
| 1012 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && |
| 1013 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && |
| 1014 | adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner |
| 1015 | } |
| 1016 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1017 | # simple shortcut to the runtest command |
| 1018 | function runtest() |
| 1019 | { |
| 1020 | T=$(gettop) |
| 1021 | if [ ! "$T" ]; then |
| 1022 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1023 | return |
| 1024 | fi |
Brett Chabot | 3fb149d | 2009-10-21 20:05:26 -0700 | [diff] [blame] | 1025 | ("$T"/development/testrunner/runtest.py $@) |
Brett Chabot | 762748c | 2009-03-27 10:25:11 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1028 | function godir () { |
| 1029 | if [[ -z "$1" ]]; then |
| 1030 | echo "Usage: godir <regex>" |
| 1031 | return |
| 1032 | fi |
Brian Carlstrom | b9915a6 | 2010-01-29 16:39:32 -0800 | [diff] [blame] | 1033 | T=$(gettop) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1034 | if [[ ! -f $T/filelist ]]; then |
| 1035 | echo -n "Creating index..." |
Brian Carlstrom | 259e5b7 | 2010-01-30 11:45:03 -0800 | [diff] [blame] | 1036 | (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] | 1037 | echo " Done" |
| 1038 | echo "" |
| 1039 | fi |
| 1040 | local lines |
| 1041 | lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq)) |
| 1042 | if [[ ${#lines[@]} = 0 ]]; then |
| 1043 | echo "Not found" |
| 1044 | return |
| 1045 | fi |
| 1046 | local pathname |
| 1047 | local choice |
| 1048 | if [[ ${#lines[@]} > 1 ]]; then |
| 1049 | while [[ -z "$pathname" ]]; do |
| 1050 | local index=1 |
| 1051 | local line |
| 1052 | for line in ${lines[@]}; do |
| 1053 | printf "%6s %s\n" "[$index]" $line |
| 1054 | index=$(($index + 1)) |
| 1055 | done |
| 1056 | echo |
| 1057 | echo -n "Select one: " |
| 1058 | unset choice |
| 1059 | read choice |
| 1060 | if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then |
| 1061 | echo "Invalid choice" |
| 1062 | continue |
| 1063 | fi |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 1064 | pathname=${lines[$(($choice-1))]} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1065 | done |
| 1066 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1067 | pathname=${lines[0]} |
| 1068 | fi |
| 1069 | cd $T/$pathname |
| 1070 | } |
| 1071 | |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 1072 | # Force JAVA_HOME to point to java 1.6 if it isn't already set |
| 1073 | function set_java_home() { |
Andy McFadden | bd96094 | 2010-06-24 12:52:51 -0700 | [diff] [blame] | 1074 | if [ ! "$JAVA_HOME" ]; then |
| 1075 | case `uname -s` in |
| 1076 | Darwin) |
| 1077 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home |
| 1078 | ;; |
| 1079 | *) |
| 1080 | export JAVA_HOME=/usr/lib/jvm/java-6-sun |
| 1081 | ;; |
| 1082 | esac |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 1083 | fi |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 1084 | } |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 1085 | |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 1086 | case `ps -o command -p $$` in |
| 1087 | *bash*) |
| 1088 | ;; |
| 1089 | *) |
| 1090 | echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results" |
| 1091 | ;; |
| 1092 | esac |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1093 | |
| 1094 | # Execute the contents of any vendorsetup.sh files we can find. |
Bruce Beare | 6f8410b | 2010-06-24 13:51:35 -0700 | [diff] [blame] | 1095 | 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] | 1096 | do |
| 1097 | echo "including $f" |
| 1098 | . $f |
| 1099 | done |
| 1100 | unset f |