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