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