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