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