envsetup.sh revision 6808c2608f0eff3275110154d7267f934700c167
1function hmm() { 2cat <<EOF 3Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment: 4- lunch: lunch <product_name>-<build_variant> 5- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [eng|userdebug|user] 6- croot: Changes directory to the top of the tree. 7- m: Makes from the top of the tree. 8- mm: Builds all of the modules in the current directory, but not their dependencies. 9- mmm: Builds all of the modules in the supplied directories, but not their dependencies. 10 To limit the modules being built use the syntax: mmm dir/:target1,target2. 11- mma: Builds all of the modules in the current directory, and their dependencies. 12- mmma: Builds all of the modules in the supplied directories, and their dependencies. 13- cgrep: Greps on all local C/C++ files. 14- jgrep: Greps on all local Java files. 15- resgrep: Greps on all local res/*.xml files. 16- godir: Go to the directory containing a file. 17 18Look at the source to view more functions. The complete list is: 19EOF 20 T=$(gettop) 21 local A 22 A="" 23 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do 24 A="$A $i" 25 done 26 echo $A 27} 28 29# Get the value of a build variable as an absolute path. 30function get_abs_build_var() 31{ 32 T=$(gettop) 33 if [ ! "$T" ]; then 34 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 35 return 36 fi 37 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ 38 make --no-print-directory -f build/core/config.mk dumpvar-abs-$1) 39} 40 41# Get the exact value of a build variable. 42function get_build_var() 43{ 44 T=$(gettop) 45 if [ ! "$T" ]; then 46 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 47 return 48 fi 49 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ 50 make --no-print-directory -f build/core/config.mk dumpvar-$1) 51} 52 53# check to see if the supplied product is one we can build 54function check_product() 55{ 56 T=$(gettop) 57 if [ ! "$T" ]; then 58 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 59 return 60 fi 61 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ 62 TARGET_PRODUCT=$1 \ 63 TARGET_BUILD_VARIANT= \ 64 TARGET_BUILD_TYPE= \ 65 TARGET_BUILD_APPS= \ 66 get_build_var TARGET_DEVICE > /dev/null 67 # hide successful answers, but allow the errors to show 68} 69 70VARIANT_CHOICES=(user userdebug eng) 71 72# check to see if the supplied variant is valid 73function check_variant() 74{ 75 for v in ${VARIANT_CHOICES[@]} 76 do 77 if [ "$v" = "$1" ] 78 then 79 return 0 80 fi 81 done 82 return 1 83} 84 85function setpaths() 86{ 87 T=$(gettop) 88 if [ ! "$T" ]; then 89 echo "Couldn't locate the top of the tree. Try setting TOP." 90 return 91 fi 92 93 ################################################################## 94 # # 95 # Read me before you modify this code # 96 # # 97 # This function sets ANDROID_BUILD_PATHS to what it is adding # 98 # to PATH, and the next time it is run, it removes that from # 99 # PATH. This is required so lunch can be run more than once # 100 # and still have working paths. # 101 # # 102 ################################################################## 103 104 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces 105 # due to "C:\Program Files" being in the path. 106 107 # out with the old 108 if [ -n "$ANDROID_BUILD_PATHS" ] ; then 109 export PATH=${PATH/$ANDROID_BUILD_PATHS/} 110 fi 111 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then 112 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/} 113 # strip leading ':', if any 114 export PATH=${PATH/:%/} 115 fi 116 117 # and in with the new 118 CODE_REVIEWS= 119 prebuiltdir=$(getprebuilt) 120 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS) 121 122 # defined in core/config.mk 123 targetgccversion=$(get_build_var TARGET_GCC_VERSION) 124 export TARGET_GCC_VERSION=$targetgccversion 125 126 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it. 127 export ANDROID_TOOLCHAIN= 128 export ANDROID_TOOLCHAIN_2ND_ARCH= 129 local ARCH=$(get_build_var TARGET_ARCH) 130 case $ARCH in 131 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin 132 ;; 133 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin 134 ;; 135 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin 136 ;; 137 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin; 138 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion/bin 139 ;; 140 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin 141 ;; 142 mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin 143 ;; 144 *) 145 echo "Can't find toolchain for unknown architecture: $ARCH" 146 toolchaindir=xxxxxxxxx 147 ;; 148 esac 149 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then 150 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir 151 fi 152 153 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then 154 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2 155 fi 156 157 unset ANDROID_KERNEL_TOOLCHAIN_PATH 158 case $ARCH in 159 arm) 160 # Legacy toolchain configuration used for ARM kernel compilation 161 toolchaindir=arm/arm-eabi-$targetgccversion/bin 162 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then 163 ANDROID_KERNEL_TOOLCHAIN_PATH="$gccprebuiltdir/$toolchaindir" 164 export ARM_EABI_TOOLCHAIN=$ANDROID_KERNEL_TOOLCHAIN_PATH 165 fi 166 ;; 167 mips) toolchaindir=mips/mips-eabi-4.4.3/bin 168 ;; 169 *) 170 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs 171 ;; 172 esac 173 174 export ANDROID_QTOOLS=$T/development/emulator/qtools 175 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools 176 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_KERNEL_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS: 177 export PATH=$ANDROID_BUILD_PATHS$PATH 178 179 unset ANDROID_JAVA_TOOLCHAIN 180 unset ANDROID_PRE_BUILD_PATHS 181 if [ -n "$JAVA_HOME" ]; then 182 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin 183 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN: 184 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH 185 fi 186 187 unset ANDROID_PRODUCT_OUT 188 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT) 189 export OUT=$ANDROID_PRODUCT_OUT 190 191 unset ANDROID_HOST_OUT 192 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT) 193 194 # needed for processing samples collected by perf counters 195 unset OPROFILE_EVENTS_DIR 196 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events 197 198 # needed for building linux on MacOS 199 # TODO: fix the path 200 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include 201} 202 203function printconfig() 204{ 205 T=$(gettop) 206 if [ ! "$T" ]; then 207 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 208 return 209 fi 210 get_build_var report_config 211} 212 213function set_stuff_for_environment() 214{ 215 settitle 216 set_java_home 217 setpaths 218 set_sequence_number 219 220 export ANDROID_BUILD_TOP=$(gettop) 221 # With this environment variable new GCC can apply colors to warnings/errors 222 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' 223} 224 225function set_sequence_number() 226{ 227 export BUILD_ENV_SEQUENCE_NUMBER=10 228} 229 230function settitle() 231{ 232 if [ "$STAY_OFF_MY_LAWN" = "" ]; then 233 local arch=$(gettargetarch) 234 local product=$TARGET_PRODUCT 235 local variant=$TARGET_BUILD_VARIANT 236 local apps=$TARGET_BUILD_APPS 237 if [ -z "$apps" ]; then 238 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\"" 239 else 240 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\"" 241 fi 242 fi 243} 244 245function addcompletions() 246{ 247 local T dir f 248 249 # Keep us from trying to run in something that isn't bash. 250 if [ -z "${BASH_VERSION}" ]; then 251 return 252 fi 253 254 # Keep us from trying to run in bash that's too old. 255 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then 256 return 257 fi 258 259 dir="sdk/bash_completion" 260 if [ -d ${dir} ]; then 261 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do 262 echo "including $f" 263 . $f 264 done 265 fi 266} 267 268function choosetype() 269{ 270 echo "Build type choices are:" 271 echo " 1. release" 272 echo " 2. debug" 273 echo 274 275 local DEFAULT_NUM DEFAULT_VALUE 276 DEFAULT_NUM=1 277 DEFAULT_VALUE=release 278 279 export TARGET_BUILD_TYPE= 280 local ANSWER 281 while [ -z $TARGET_BUILD_TYPE ] 282 do 283 echo -n "Which would you like? ["$DEFAULT_NUM"] " 284 if [ -z "$1" ] ; then 285 read ANSWER 286 else 287 echo $1 288 ANSWER=$1 289 fi 290 case $ANSWER in 291 "") 292 export TARGET_BUILD_TYPE=$DEFAULT_VALUE 293 ;; 294 1) 295 export TARGET_BUILD_TYPE=release 296 ;; 297 release) 298 export TARGET_BUILD_TYPE=release 299 ;; 300 2) 301 export TARGET_BUILD_TYPE=debug 302 ;; 303 debug) 304 export TARGET_BUILD_TYPE=debug 305 ;; 306 *) 307 echo 308 echo "I didn't understand your response. Please try again." 309 echo 310 ;; 311 esac 312 if [ -n "$1" ] ; then 313 break 314 fi 315 done 316 317 set_stuff_for_environment 318} 319 320# 321# This function isn't really right: It chooses a TARGET_PRODUCT 322# based on the list of boards. Usually, that gets you something 323# that kinda works with a generic product, but really, you should 324# pick a product by name. 325# 326function chooseproduct() 327{ 328 if [ "x$TARGET_PRODUCT" != x ] ; then 329 default_value=$TARGET_PRODUCT 330 else 331 default_value=full 332 fi 333 334 export TARGET_PRODUCT= 335 local ANSWER 336 while [ -z "$TARGET_PRODUCT" ] 337 do 338 echo -n "Which product would you like? [$default_value] " 339 if [ -z "$1" ] ; then 340 read ANSWER 341 else 342 echo $1 343 ANSWER=$1 344 fi 345 346 if [ -z "$ANSWER" ] ; then 347 export TARGET_PRODUCT=$default_value 348 else 349 if check_product $ANSWER 350 then 351 export TARGET_PRODUCT=$ANSWER 352 else 353 echo "** Not a valid product: $ANSWER" 354 fi 355 fi 356 if [ -n "$1" ] ; then 357 break 358 fi 359 done 360 361 set_stuff_for_environment 362} 363 364function choosevariant() 365{ 366 echo "Variant choices are:" 367 local index=1 368 local v 369 for v in ${VARIANT_CHOICES[@]} 370 do 371 # The product name is the name of the directory containing 372 # the makefile we found, above. 373 echo " $index. $v" 374 index=$(($index+1)) 375 done 376 377 local default_value=eng 378 local ANSWER 379 380 export TARGET_BUILD_VARIANT= 381 while [ -z "$TARGET_BUILD_VARIANT" ] 382 do 383 echo -n "Which would you like? [$default_value] " 384 if [ -z "$1" ] ; then 385 read ANSWER 386 else 387 echo $1 388 ANSWER=$1 389 fi 390 391 if [ -z "$ANSWER" ] ; then 392 export TARGET_BUILD_VARIANT=$default_value 393 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then 394 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then 395 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]} 396 fi 397 else 398 if check_variant $ANSWER 399 then 400 export TARGET_BUILD_VARIANT=$ANSWER 401 else 402 echo "** Not a valid variant: $ANSWER" 403 fi 404 fi 405 if [ -n "$1" ] ; then 406 break 407 fi 408 done 409} 410 411function choosecombo() 412{ 413 choosetype $1 414 415 echo 416 echo 417 chooseproduct $2 418 419 echo 420 echo 421 choosevariant $3 422 423 echo 424 set_stuff_for_environment 425 printconfig 426} 427 428# Clear this variable. It will be built up again when the vendorsetup.sh 429# files are included at the end of this file. 430unset LUNCH_MENU_CHOICES 431function add_lunch_combo() 432{ 433 local new_combo=$1 434 local c 435 for c in ${LUNCH_MENU_CHOICES[@]} ; do 436 if [ "$new_combo" = "$c" ] ; then 437 return 438 fi 439 done 440 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) 441} 442 443# add the default one here 444add_lunch_combo aosp_arm-eng 445add_lunch_combo aosp_arm64-eng 446add_lunch_combo aosp_mips-eng 447add_lunch_combo aosp_mips64-eng 448add_lunch_combo aosp_x86-eng 449add_lunch_combo aosp_x86_64-eng 450add_lunch_combo vbox_x86-eng 451 452function print_lunch_menu() 453{ 454 local uname=$(uname) 455 echo 456 echo "You're building on" $uname 457 echo 458 echo "Lunch menu... pick a combo:" 459 460 local i=1 461 local choice 462 for choice in ${LUNCH_MENU_CHOICES[@]} 463 do 464 echo " $i. $choice" 465 i=$(($i+1)) 466 done 467 468 echo 469} 470 471function lunch() 472{ 473 local answer 474 475 if [ "$1" ] ; then 476 answer=$1 477 else 478 print_lunch_menu 479 echo -n "Which would you like? [aosp_arm-eng] " 480 read answer 481 fi 482 483 local selection= 484 485 if [ -z "$answer" ] 486 then 487 selection=aosp_arm-eng 488 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") 489 then 490 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ] 491 then 492 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]} 493 fi 494 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$") 495 then 496 selection=$answer 497 fi 498 499 if [ -z "$selection" ] 500 then 501 echo 502 echo "Invalid lunch combo: $answer" 503 return 1 504 fi 505 506 export TARGET_BUILD_APPS= 507 508 local product=$(echo -n $selection | sed -e "s/-.*$//") 509 check_product $product 510 if [ $? -ne 0 ] 511 then 512 echo 513 echo "** Don't have a product spec for: '$product'" 514 echo "** Do you have the right repo manifest?" 515 product= 516 fi 517 518 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//") 519 check_variant $variant 520 if [ $? -ne 0 ] 521 then 522 echo 523 echo "** Invalid variant: '$variant'" 524 echo "** Must be one of ${VARIANT_CHOICES[@]}" 525 variant= 526 fi 527 528 if [ -z "$product" -o -z "$variant" ] 529 then 530 echo 531 return 1 532 fi 533 534 export TARGET_PRODUCT=$product 535 export TARGET_BUILD_VARIANT=$variant 536 export TARGET_BUILD_TYPE=release 537 538 echo 539 540 set_stuff_for_environment 541 printconfig 542} 543 544# Tab completion for lunch. 545function _lunch() 546{ 547 local cur prev opts 548 COMPREPLY=() 549 cur="${COMP_WORDS[COMP_CWORD]}" 550 prev="${COMP_WORDS[COMP_CWORD-1]}" 551 552 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) ) 553 return 0 554} 555complete -F _lunch lunch 556 557# Configures the build to build unbundled apps. 558# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME) 559function tapas() 560{ 561 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$')) 562 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$')) 563 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5)$')) 564 565 if [ $(echo $arch | wc -w) -gt 1 ]; then 566 echo "tapas: Error: Multiple build archs supplied: $arch" 567 return 568 fi 569 if [ $(echo $variant | wc -w) -gt 1 ]; then 570 echo "tapas: Error: Multiple build variants supplied: $variant" 571 return 572 fi 573 574 local product=full 575 case $arch in 576 x86) product=full_x86;; 577 mips) product=full_mips;; 578 armv5) product=generic_armv5;; 579 esac 580 if [ -z "$variant" ]; then 581 variant=eng 582 fi 583 if [ -z "$apps" ]; then 584 apps=all 585 fi 586 587 export TARGET_PRODUCT=$product 588 export TARGET_BUILD_VARIANT=$variant 589 export TARGET_BUILD_TYPE=release 590 export TARGET_BUILD_APPS=$apps 591 592 set_stuff_for_environment 593 printconfig 594} 595 596function gettop 597{ 598 local TOPFILE=build/core/envsetup.mk 599 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then 600 echo $TOP 601 else 602 if [ -f $TOPFILE ] ; then 603 # The following circumlocution (repeated below as well) ensures 604 # that we record the true directory name and not one that is 605 # faked up with symlink names. 606 PWD= /bin/pwd 607 else 608 local HERE=$PWD 609 T= 610 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do 611 \cd .. 612 T=`PWD= /bin/pwd -P` 613 done 614 \cd $HERE 615 if [ -f "$T/$TOPFILE" ]; then 616 echo $T 617 fi 618 fi 619 fi 620} 621 622# Return driver for "make", if any (eg. static analyzer) 623function getdriver() 624{ 625 local T="$1" 626 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER 627 if [ -n "$WITH_STATIC_ANALYZER" ]; then 628 echo "\ 629$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \ 630--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \ 631--status-bugs \ 632--top=$T" 633 fi 634} 635 636function m() 637{ 638 local T=$(gettop) 639 local DRV=$(getdriver $T) 640 if [ "$T" ]; then 641 $DRV make -C $T -f build/core/main.mk $@ 642 else 643 echo "Couldn't locate the top of the tree. Try setting TOP." 644 fi 645} 646 647function findmakefile() 648{ 649 TOPFILE=build/core/envsetup.mk 650 local HERE=$PWD 651 T= 652 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do 653 T=`PWD= /bin/pwd` 654 if [ -f "$T/Android.mk" ]; then 655 echo $T/Android.mk 656 \cd $HERE 657 return 658 fi 659 \cd .. 660 done 661 \cd $HERE 662} 663 664function mm() 665{ 666 local T=$(gettop) 667 local DRV=$(getdriver $T) 668 # If we're sitting in the root of the build tree, just do a 669 # normal make. 670 if [ -f build/core/envsetup.mk -a -f Makefile ]; then 671 $DRV make $@ 672 else 673 # Find the closest Android.mk file. 674 local M=$(findmakefile) 675 local MODULES= 676 local GET_INSTALL_PATH= 677 local ARGS= 678 # Remove the path to top as the makefilepath needs to be relative 679 local M=`echo $M|sed 's:'$T'/::'` 680 if [ ! "$T" ]; then 681 echo "Couldn't locate the top of the tree. Try setting TOP." 682 elif [ ! "$M" ]; then 683 echo "Couldn't locate a makefile from the current directory." 684 else 685 for ARG in $@; do 686 case $ARG in 687 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;; 688 esac 689 done 690 if [ -n "$GET_INSTALL_PATH" ]; then 691 MODULES= 692 ARGS=GET-INSTALL-PATH 693 else 694 MODULES=all_modules 695 ARGS=$@ 696 fi 697 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS 698 fi 699 fi 700} 701 702function mmm() 703{ 704 local T=$(gettop) 705 local DRV=$(getdriver $T) 706 if [ "$T" ]; then 707 local MAKEFILE= 708 local MODULES= 709 local ARGS= 710 local DIR TO_CHOP 711 local GET_INSTALL_PATH= 712 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') 713 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') 714 for DIR in $DIRS ; do 715 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'` 716 if [ "$MODULES" = "" ]; then 717 MODULES=all_modules 718 fi 719 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'` 720 if [ -f $DIR/Android.mk ]; then 721 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '` 722 local TO_CHOP=`expr $TO_CHOP + 1` 723 local START=`PWD= /bin/pwd` 724 local MFILE=`echo $START | cut -c${TO_CHOP}-` 725 if [ "$MFILE" = "" ] ; then 726 MFILE=$DIR/Android.mk 727 else 728 MFILE=$MFILE/$DIR/Android.mk 729 fi 730 MAKEFILE="$MAKEFILE $MFILE" 731 else 732 case $DIR in 733 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";; 734 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;; 735 *) echo "No Android.mk in $DIR."; return 1;; 736 esac 737 fi 738 done 739 if [ -n "$GET_INSTALL_PATH" ]; then 740 ARGS=$GET_INSTALL_PATH 741 MODULES= 742 fi 743 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS 744 else 745 echo "Couldn't locate the top of the tree. Try setting TOP." 746 fi 747} 748 749function mma() 750{ 751 local T=$(gettop) 752 local DRV=$(getdriver $T) 753 if [ -f build/core/envsetup.mk -a -f Makefile ]; then 754 $DRV make $@ 755 else 756 if [ ! "$T" ]; then 757 echo "Couldn't locate the top of the tree. Try setting TOP." 758 fi 759 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'` 760 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD" 761 fi 762} 763 764function mmma() 765{ 766 local T=$(gettop) 767 local DRV=$(getdriver $T) 768 if [ "$T" ]; then 769 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') 770 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') 771 local MY_PWD=`PWD= /bin/pwd` 772 if [ "$MY_PWD" = "$T" ]; then 773 MY_PWD= 774 else 775 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'` 776 fi 777 local DIR= 778 local MODULE_PATHS= 779 local ARGS= 780 for DIR in $DIRS ; do 781 if [ -d $DIR ]; then 782 if [ "$MY_PWD" = "" ]; then 783 MODULE_PATHS="$MODULE_PATHS $DIR" 784 else 785 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR" 786 fi 787 else 788 case $DIR in 789 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";; 790 *) echo "Couldn't find directory $DIR"; return 1;; 791 esac 792 fi 793 done 794 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS" 795 else 796 echo "Couldn't locate the top of the tree. Try setting TOP." 797 fi 798} 799 800function croot() 801{ 802 T=$(gettop) 803 if [ "$T" ]; then 804 \cd $(gettop) 805 else 806 echo "Couldn't locate the top of the tree. Try setting TOP." 807 fi 808} 809 810function cproj() 811{ 812 TOPFILE=build/core/envsetup.mk 813 local HERE=$PWD 814 T= 815 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do 816 T=$PWD 817 if [ -f "$T/Android.mk" ]; then 818 \cd $T 819 return 820 fi 821 \cd .. 822 done 823 \cd $HERE 824 echo "can't find Android.mk" 825} 826 827# simplified version of ps; output in the form 828# <pid> <procname> 829function qpid() { 830 local prepend='' 831 local append='' 832 if [ "$1" = "--exact" ]; then 833 prepend=' ' 834 append='$' 835 shift 836 elif [ "$1" = "--help" -o "$1" = "-h" ]; then 837 echo "usage: qpid [[--exact] <process name|pid>" 838 return 255 839 fi 840 841 local EXE="$1" 842 if [ "$EXE" ] ; then 843 qpid | \grep "$prepend$EXE$append" 844 else 845 adb shell ps \ 846 | tr -d '\r' \ 847 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/' 848 fi 849} 850 851function pid() 852{ 853 local prepend='' 854 local append='' 855 if [ "$1" = "--exact" ]; then 856 prepend=' ' 857 append='$' 858 shift 859 fi 860 local EXE="$1" 861 if [ "$EXE" ] ; then 862 local PID=`adb shell ps \ 863 | tr -d '\r' \ 864 | \grep "$prepend$EXE$append" \ 865 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'` 866 echo "$PID" 867 else 868 echo "usage: pid [--exact] <process name>" 869 return 255 870 fi 871} 872 873# systemstack - dump the current stack trace of all threads in the system process 874# to the usual ANR traces file 875function systemstack() 876{ 877 stacks system_server 878} 879 880function stacks() 881{ 882 if [[ $1 =~ ^[0-9]+$ ]] ; then 883 local PID="$1" 884 elif [ "$1" ] ; then 885 local PIDLIST="$(pid $1)" 886 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then 887 local PID="$PIDLIST" 888 elif [ "$PIDLIST" ] ; then 889 echo "more than one process: $1" 890 else 891 echo "no such process: $1" 892 fi 893 else 894 echo "usage: stacks [pid|process name]" 895 fi 896 897 if [ "$PID" ] ; then 898 # Determine whether the process is native 899 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then 900 # Dump stacks of Dalvik process 901 local TRACES=/data/anr/traces.txt 902 local ORIG=/data/anr/traces.orig 903 local TMP=/data/anr/traces.tmp 904 905 # Keep original traces to avoid clobbering 906 adb shell mv $TRACES $ORIG 907 908 # Make sure we have a usable file 909 adb shell touch $TRACES 910 adb shell chmod 666 $TRACES 911 912 # Dump stacks and wait for dump to finish 913 adb shell kill -3 $PID 914 adb shell notify $TRACES >/dev/null 915 916 # Restore original stacks, and show current output 917 adb shell mv $TRACES $TMP 918 adb shell mv $ORIG $TRACES 919 adb shell cat $TMP 920 else 921 # Dump stacks of native process 922 adb shell debuggerd -b $PID 923 fi 924 fi 925} 926 927function gdbwrapper() 928{ 929 local GDB_CMD="$1" 930 shift 1 931 $GDB_CMD -x "$@" 932} 933 934# process the symbolic link of /proc/$PID/exe and use the host file tool to 935# determine whether it is a 32-bit or 64-bit executable. It returns "" or "64" 936# which can be conveniently used as suffix. 937function is64bit() 938{ 939 local PID="$1" 940 if [ "$PID" ] ; then 941 local EXE=`adb shell ls -l /proc/$PID/exe \ 942 | tr -d '\r' \ 943 | cut -d'>' -f2 \ 944 | tr -d ' ' \ 945 | cut -d'/' -f4` 946 947 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED) 948 local IS64BIT=`file $OUT_EXE_SYMBOLS/$EXE | grep "64-bit"` 949 if [ "$IS64BIT" != "" ]; then 950 echo "64" 951 else 952 echo "" 953 fi 954 else 955 echo "" 956 fi 957} 958 959# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit 960# executable, set up the approriate gdbserver, then invokes the proper host 961# gdb. 962function gdbclient() 963{ 964 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT) 965 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED) 966 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED) 967 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED) 968 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS) 969 local ARCH=$(get_build_var TARGET_ARCH) 970 local GDB 971 case "$ARCH" in 972 arm) GDB=arm-linux-androideabi-gdb;; 973 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;; 974 mips) GDB=mipsel-linux-android-gdb;; 975 mips64) GDB=mipsel-linux-android-gdb;; 976 x86) GDB=x86_64-linux-android-gdb;; 977 x86_64) GDB=x86_64-linux-android-gdb;; 978 *) echo "Unknown arch $ARCH"; return 1;; 979 esac 980 981 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then 982 local EXE="$1" 983 if [ "$EXE" ] ; then 984 EXE=$1 985 else 986 EXE="app_process" 987 fi 988 989 local PORT="$2" 990 if [ "$PORT" ] ; then 991 PORT=$2 992 else 993 PORT=":5039" 994 fi 995 996 local PID="$3" 997 if [ "$PID" ] ; then 998 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then 999 PID=`pid $3` 1000 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then 1001 # that likely didn't work because of returning multiple processes 1002 # try again, filtering by root processes (don't contain colon) 1003 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'` 1004 if [[ ! "$PID" =~ ^[0-9]+$ ]] 1005 then 1006 echo "Couldn't resolve '$3' to single PID" 1007 return 1 1008 else 1009 echo "" 1010 echo "WARNING: multiple processes matching '$3' observed, using root process" 1011 echo "" 1012 fi 1013 fi 1014 fi 1015 adb forward "tcp$PORT" "tcp$PORT" 1016 local USE64BIT="$(is64bit $PID)" 1017 adb shell gdbserver$USE64BIT $PORT --attach $PID & 1018 sleep 2 1019 else 1020 echo "" 1021 echo "If you haven't done so already, do this first on the device:" 1022 echo " gdbserver $PORT /system/bin/$EXE" 1023 echo " or" 1024 echo " gdbserver $PORT --attach <PID>" 1025 echo "" 1026 fi 1027 1028 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS" 1029 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS$USE64BIT:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx" 1030 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb" 1031 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT" 1032 echo >>"$OUT_ROOT/gdbclient.cmds" "" 1033 1034 local WHICH_GDB= 1035 # 64-bit exe found 1036 if [ "$USE64BIT" != "" ] ; then 1037 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64 1038 # 32-bit exe / 32-bit platform 1039 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then 1040 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB 1041 # 32-bit exe / 64-bit platform 1042 else 1043 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB 1044 fi 1045 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE" 1046 else 1047 echo "Unable to determine build system output dir." 1048 fi 1049 1050} 1051 1052case `uname -s` in 1053 Darwin) 1054 function sgrep() 1055 { 1056 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml|sh|mk)' -print0 | xargs -0 grep --color -n "$@" 1057 } 1058 1059 ;; 1060 *) 1061 function sgrep() 1062 { 1063 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cpp\|S\|java\|xml\|sh\|mk\)' -print0 | xargs -0 grep --color -n "$@" 1064 } 1065 ;; 1066esac 1067 1068function gettargetarch 1069{ 1070 get_build_var TARGET_ARCH 1071} 1072 1073function jgrep() 1074{ 1075 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@" 1076} 1077 1078function cgrep() 1079{ 1080 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 grep --color -n "$@" 1081} 1082 1083function resgrep() 1084{ 1085 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done; 1086} 1087 1088function mangrep() 1089{ 1090 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@" 1091} 1092 1093function sepgrep() 1094{ 1095 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d -print0 | xargs -0 grep --color -n -r --exclude-dir=\.git "$@" 1096} 1097 1098case `uname -s` in 1099 Darwin) 1100 function mgrep() 1101 { 1102 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@" 1103 } 1104 1105 function treegrep() 1106 { 1107 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@" 1108 } 1109 1110 ;; 1111 *) 1112 function mgrep() 1113 { 1114 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@" 1115 } 1116 1117 function treegrep() 1118 { 1119 find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@" 1120 } 1121 1122 ;; 1123esac 1124 1125function getprebuilt 1126{ 1127 get_abs_build_var ANDROID_PREBUILTS 1128} 1129 1130function tracedmdump() 1131{ 1132 T=$(gettop) 1133 if [ ! "$T" ]; then 1134 echo "Couldn't locate the top of the tree. Try setting TOP." 1135 return 1136 fi 1137 local prebuiltdir=$(getprebuilt) 1138 local arch=$(gettargetarch) 1139 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu 1140 1141 local TRACE=$1 1142 if [ ! "$TRACE" ] ; then 1143 echo "usage: tracedmdump tracename" 1144 return 1145 fi 1146 1147 if [ ! -r "$KERNEL" ] ; then 1148 echo "Error: cannot find kernel: '$KERNEL'" 1149 return 1150 fi 1151 1152 local BASETRACE=$(basename $TRACE) 1153 if [ "$BASETRACE" = "$TRACE" ] ; then 1154 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE 1155 fi 1156 1157 echo "post-processing traces..." 1158 rm -f $TRACE/qtrace.dexlist 1159 post_trace $TRACE 1160 if [ $? -ne 0 ]; then 1161 echo "***" 1162 echo "*** Error: malformed trace. Did you remember to exit the emulator?" 1163 echo "***" 1164 return 1165 fi 1166 echo "generating dexlist output..." 1167 /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 1168 echo "generating dmtrace data..." 1169 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return 1170 echo "generating html file..." 1171 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return 1172 echo "done, see $TRACE/dmtrace.html for details" 1173 echo "or run:" 1174 echo " traceview $TRACE/dmtrace" 1175} 1176 1177# communicate with a running device or emulator, set up necessary state, 1178# and run the hat command. 1179function runhat() 1180{ 1181 # process standard adb options 1182 local adbTarget="" 1183 if [ "$1" = "-d" -o "$1" = "-e" ]; then 1184 adbTarget=$1 1185 shift 1 1186 elif [ "$1" = "-s" ]; then 1187 adbTarget="$1 $2" 1188 shift 2 1189 fi 1190 local adbOptions=${adbTarget} 1191 #echo adbOptions = ${adbOptions} 1192 1193 # runhat options 1194 local targetPid=$1 1195 1196 if [ "$targetPid" = "" ]; then 1197 echo "Usage: runhat [ -d | -e | -s serial ] target-pid" 1198 return 1199 fi 1200 1201 # confirm hat is available 1202 if [ -z $(which hat) ]; then 1203 echo "hat is not available in this configuration." 1204 return 1205 fi 1206 1207 # issue "am" command to cause the hprof dump 1208 local sdcard=$(adb ${adbOptions} shell echo -n '$EXTERNAL_STORAGE') 1209 local devFile=$sdcard/hprof-$targetPid 1210 #local devFile=/data/local/hprof-$targetPid 1211 echo "Poking $targetPid and waiting for data..." 1212 echo "Storing data at $devFile" 1213 adb ${adbOptions} shell am dumpheap $targetPid $devFile 1214 echo "Press enter when logcat shows \"hprof: heap dump completed\"" 1215 echo -n "> " 1216 read 1217 1218 local localFile=/tmp/$$-hprof 1219 1220 echo "Retrieving file $devFile..." 1221 adb ${adbOptions} pull $devFile $localFile 1222 1223 adb ${adbOptions} shell rm $devFile 1224 1225 echo "Running hat on $localFile" 1226 echo "View the output by pointing your browser at http://localhost:7000/" 1227 echo "" 1228 hat -JXmx512m $localFile 1229} 1230 1231function getbugreports() 1232{ 1233 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`) 1234 1235 if [ ! "$reports" ]; then 1236 echo "Could not locate any bugreports." 1237 return 1238 fi 1239 1240 local report 1241 for report in ${reports[@]} 1242 do 1243 echo "/sdcard/bugreports/${report}" 1244 adb pull /sdcard/bugreports/${report} ${report} 1245 gunzip ${report} 1246 done 1247} 1248 1249function getsdcardpath() 1250{ 1251 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} 1252} 1253 1254function getscreenshotpath() 1255{ 1256 echo "$(getsdcardpath)/Pictures/Screenshots" 1257} 1258 1259function getlastscreenshot() 1260{ 1261 local screenshot_path=$(getscreenshotpath) 1262 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1` 1263 if [ "$screenshot" = "" ]; then 1264 echo "No screenshots found." 1265 return 1266 fi 1267 echo "${screenshot}" 1268 adb ${adbOptions} pull ${screenshot_path}/${screenshot} 1269} 1270 1271function startviewserver() 1272{ 1273 local port=4939 1274 if [ $# -gt 0 ]; then 1275 port=$1 1276 fi 1277 adb shell service call window 1 i32 $port 1278} 1279 1280function stopviewserver() 1281{ 1282 adb shell service call window 2 1283} 1284 1285function isviewserverstarted() 1286{ 1287 adb shell service call window 3 1288} 1289 1290function key_home() 1291{ 1292 adb shell input keyevent 3 1293} 1294 1295function key_back() 1296{ 1297 adb shell input keyevent 4 1298} 1299 1300function key_menu() 1301{ 1302 adb shell input keyevent 82 1303} 1304 1305function smoketest() 1306{ 1307 if [ ! "$ANDROID_PRODUCT_OUT" ]; then 1308 echo "Couldn't locate output files. Try running 'lunch' first." >&2 1309 return 1310 fi 1311 T=$(gettop) 1312 if [ ! "$T" ]; then 1313 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 1314 return 1315 fi 1316 1317 (\cd "$T" && mmm tests/SmokeTest) && 1318 adb uninstall com.android.smoketest > /dev/null && 1319 adb uninstall com.android.smoketest.tests > /dev/null && 1320 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && 1321 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && 1322 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner 1323} 1324 1325# simple shortcut to the runtest command 1326function runtest() 1327{ 1328 T=$(gettop) 1329 if [ ! "$T" ]; then 1330 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 1331 return 1332 fi 1333 ("$T"/development/testrunner/runtest.py $@) 1334} 1335 1336function godir () { 1337 if [[ -z "$1" ]]; then 1338 echo "Usage: godir <regex>" 1339 return 1340 fi 1341 T=$(gettop) 1342 if [[ ! -f $T/filelist ]]; then 1343 echo -n "Creating index..." 1344 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist) 1345 echo " Done" 1346 echo "" 1347 fi 1348 local lines 1349 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq)) 1350 if [[ ${#lines[@]} = 0 ]]; then 1351 echo "Not found" 1352 return 1353 fi 1354 local pathname 1355 local choice 1356 if [[ ${#lines[@]} > 1 ]]; then 1357 while [[ -z "$pathname" ]]; do 1358 local index=1 1359 local line 1360 for line in ${lines[@]}; do 1361 printf "%6s %s\n" "[$index]" $line 1362 index=$(($index + 1)) 1363 done 1364 echo 1365 echo -n "Select one: " 1366 unset choice 1367 read choice 1368 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then 1369 echo "Invalid choice" 1370 continue 1371 fi 1372 pathname=${lines[$(($choice-1))]} 1373 done 1374 else 1375 pathname=${lines[0]} 1376 fi 1377 \cd $T/$pathname 1378} 1379 1380# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set. 1381# 1382# Note that the MacOS path for java 1.7 includes a minor revision number (sigh). 1383# For some reason, installing the JDK doesn't make it show up in the 1384# JavaVM.framework/Versions/1.7/ folder. 1385function set_java_home() { 1386 # Clear the existing JAVA_HOME value if we set it ourselves, so that 1387 # we can reset it later, depending on the value of EXPERIMENTAL_USE_JAVA7. 1388 # 1389 # If we don't do this, the JAVA_HOME value set by the first call to 1390 # build/envsetup.sh will persist forever. 1391 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then 1392 export JAVA_HOME="" 1393 fi 1394 1395 if [ ! "$JAVA_HOME" ]; then 1396 if [ ! "$EXPERIMENTAL_USE_JAVA7" ]; then 1397 case `uname -s` in 1398 Darwin) 1399 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home 1400 ;; 1401 *) 1402 export JAVA_HOME=/usr/lib/jvm/java-6-sun 1403 ;; 1404 esac 1405 else 1406 case `uname -s` in 1407 Darwin) 1408 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home 1409 ;; 1410 *) 1411 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 1412 ;; 1413 esac 1414 fi 1415 1416 # Keep track of the fact that we set JAVA_HOME ourselves, so that 1417 # we can change it on the next envsetup.sh, if required. 1418 export ANDROID_SET_JAVA_HOME=true 1419 fi 1420} 1421 1422# Print colored exit condition 1423function pez { 1424 "$@" 1425 local retval=$? 1426 if [ $retval -ne 0 ] 1427 then 1428 echo -e "\e[0;31mFAILURE\e[00m" 1429 else 1430 echo -e "\e[0;32mSUCCESS\e[00m" 1431 fi 1432 return $retval 1433} 1434 1435if [ "x$SHELL" != "x/bin/bash" ]; then 1436 case `ps -o command -p $$` in 1437 *bash*) 1438 ;; 1439 *) 1440 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results" 1441 ;; 1442 esac 1443fi 1444 1445# Execute the contents of any vendorsetup.sh files we can find. 1446for f in `test -d device && find device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \ 1447 `test -d vendor && find vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` 1448do 1449 echo "including $f" 1450 . $f 1451done 1452unset f 1453 1454addcompletions 1455