envsetup.sh revision 3fb149d2cb8eaa48fe2602a85a329d6f3d56f510
1function help() { 2cat <<EOF 3Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment: 4- croot: Changes directory to the top of the tree. 5- m: Makes from the top of the tree. 6- mm: Builds all of the modules in the current directory. 7- mmm: Builds all of the modules in the supplied directories. 8- cgrep: Greps on all local C/C++ files. 9- jgrep: Greps on all local Java files. 10- resgrep: Greps on all local res/*.xml files. 11- godir: Go to the directory containing a file. 12 13Look at the source to view more functions. The complete list is: 14EOF 15 T=$(gettop) 16 local A 17 A="" 18 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do 19 A="$A $i" 20 done 21 echo $A 22} 23 24# Get the value of a build variable as an absolute path. 25function get_abs_build_var() 26{ 27 T=$(gettop) 28 if [ ! "$T" ]; then 29 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 30 return 31 fi 32 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ 33 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1 34} 35 36# Get the exact value of a build variable. 37function get_build_var() 38{ 39 T=$(gettop) 40 if [ ! "$T" ]; then 41 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 42 return 43 fi 44 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ 45 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1 46} 47 48# check to see if the supplied product is one we can build 49function check_product() 50{ 51 T=$(gettop) 52 if [ ! "$T" ]; then 53 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 54 return 55 fi 56 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ 57 TARGET_PRODUCT=$1 TARGET_BUILD_VARIANT= \ 58 TARGET_SIMULATOR= TARGET_BUILD_TYPE= \ 59 get_build_var TARGET_DEVICE > /dev/null 60 # hide successful answers, but allow the errors to show 61} 62 63VARIANT_CHOICES=(user userdebug eng) 64 65# check to see if the supplied variant is valid 66function check_variant() 67{ 68 for v in ${VARIANT_CHOICES[@]} 69 do 70 if [ "$v" = "$1" ] 71 then 72 return 0 73 fi 74 done 75 return 1 76} 77 78function setpaths() 79{ 80 T=$(gettop) 81 if [ ! "$T" ]; then 82 echo "Couldn't locate the top of the tree. Try setting TOP." 83 return 84 fi 85 86 ################################################################## 87 # # 88 # Read me before you modify this code # 89 # # 90 # This function sets ANDROID_BUILD_PATHS to what it is adding # 91 # to PATH, and the next time it is run, it removes that from # 92 # PATH. This is required so lunch can be run more than once # 93 # and still have working paths. # 94 # # 95 ################################################################## 96 97 # out with the old 98 if [ -n $ANDROID_BUILD_PATHS ] ; then 99 export PATH=${PATH/$ANDROID_BUILD_PATHS/} 100 fi 101 102 # and in with the new 103 CODE_REVIEWS= 104 prebuiltdir=$(getprebuilt) 105 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/toolchain/arm-eabi-4.4.0/bin 106 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN 107 export ANDROID_QTOOLS=$T/development/emulator/qtools 108 export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_EABI_TOOLCHAIN$CODE_REVIEWS 109 export PATH=$PATH$ANDROID_BUILD_PATHS 110 111 unset ANDROID_PRODUCT_OUT 112 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT) 113 export OUT=$ANDROID_PRODUCT_OUT 114 115 # needed for building linux on MacOS 116 # TODO: fix the path 117 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include 118 119 # needed for OProfile to post-process collected samples 120 export OPROFILE_EVENTS_DIR=$prebuiltdir/oprofile 121} 122 123function printconfig() 124{ 125 T=$(gettop) 126 if [ ! "$T" ]; then 127 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 128 return 129 fi 130 get_build_var report_config 131} 132 133function set_stuff_for_environment() 134{ 135 settitle 136 setpaths 137 set_sequence_number 138 139 # Don't try to do preoptimization until it works better on OSX. 140 export DISABLE_DEXPREOPT=true 141 142 export ANDROID_BUILD_TOP=$(gettop) 143} 144 145function set_sequence_number() 146{ 147 export BUILD_ENV_SEQUENCE_NUMBER=9 148} 149 150function settitle() 151{ 152 if [ "$STAY_OFF_MY_LAWN" = "" ]; then 153 local product=$(get_build_var TARGET_PRODUCT) 154 local variant=$(get_build_var TARGET_BUILD_VARIANT) 155 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\"" 156 fi 157} 158 159case `uname -s` in 160 Linux) 161 function choosesim() 162 { 163 echo "Build for the simulator or the device?" 164 echo " 1. Device" 165 echo " 2. Simulator" 166 echo 167 168 export TARGET_SIMULATOR= 169 local ANSWER 170 while [ -z $TARGET_SIMULATOR ] 171 do 172 echo -n "Which would you like? [1] " 173 if [ -z "$1" ] ; then 174 read ANSWER 175 else 176 echo $1 177 ANSWER=$1 178 fi 179 case $ANSWER in 180 "") 181 export TARGET_SIMULATOR=false 182 ;; 183 1) 184 export TARGET_SIMULATOR=false 185 ;; 186 Device) 187 export TARGET_SIMULATOR=false 188 ;; 189 2) 190 export TARGET_SIMULATOR=true 191 ;; 192 Simulator) 193 export TARGET_SIMULATOR=true 194 ;; 195 *) 196 echo 197 echo "I didn't understand your response. Please try again." 198 echo 199 ;; 200 esac 201 if [ -n "$1" ] ; then 202 break 203 fi 204 done 205 206 set_stuff_for_environment 207 } 208 ;; 209 *) 210 function choosesim() 211 { 212 echo "Only device builds are supported for" `uname -s` 213 echo " Forcing TARGET_SIMULATOR=false" 214 echo 215 if [ -z "$1" ] 216 then 217 echo -n "Press enter: " 218 read 219 fi 220 221 export TARGET_SIMULATOR=false 222 set_stuff_for_environment 223 } 224 ;; 225esac 226 227function choosetype() 228{ 229 echo "Build type choices are:" 230 echo " 1. release" 231 echo " 2. debug" 232 echo 233 234 local DEFAULT_NUM DEFAULT_VALUE 235 if [ $TARGET_SIMULATOR = "false" ] ; then 236 DEFAULT_NUM=1 237 DEFAULT_VALUE=release 238 else 239 DEFAULT_NUM=2 240 DEFAULT_VALUE=debug 241 fi 242 243 export TARGET_BUILD_TYPE= 244 local ANSWER 245 while [ -z $TARGET_BUILD_TYPE ] 246 do 247 echo -n "Which would you like? ["$DEFAULT_NUM"] " 248 if [ -z "$1" ] ; then 249 read ANSWER 250 else 251 echo $1 252 ANSWER=$1 253 fi 254 case $ANSWER in 255 "") 256 export TARGET_BUILD_TYPE=$DEFAULT_VALUE 257 ;; 258 1) 259 export TARGET_BUILD_TYPE=release 260 ;; 261 release) 262 export TARGET_BUILD_TYPE=release 263 ;; 264 2) 265 export TARGET_BUILD_TYPE=debug 266 ;; 267 debug) 268 export TARGET_BUILD_TYPE=debug 269 ;; 270 *) 271 echo 272 echo "I didn't understand your response. Please try again." 273 echo 274 ;; 275 esac 276 if [ -n "$1" ] ; then 277 break 278 fi 279 done 280 281 set_stuff_for_environment 282} 283 284# 285# This function isn't really right: It chooses a TARGET_PRODUCT 286# based on the list of boards. Usually, that gets you something 287# that kinda works with a generic product, but really, you should 288# pick a product by name. 289# 290function chooseproduct() 291{ 292 if [ "x$TARGET_PRODUCT" != x ] ; then 293 default_value=$TARGET_PRODUCT 294 else 295 if [ "$TARGET_SIMULATOR" = true ] ; then 296 default_value=sim 297 else 298 default_value=generic 299 fi 300 fi 301 302 export TARGET_PRODUCT= 303 local ANSWER 304 while [ -z "$TARGET_PRODUCT" ] 305 do 306 echo -n "Which product would you like? [$default_value] " 307 if [ -z "$1" ] ; then 308 read ANSWER 309 else 310 echo $1 311 ANSWER=$1 312 fi 313 314 if [ -z "$ANSWER" ] ; then 315 export TARGET_PRODUCT=$default_value 316 else 317 if check_product $ANSWER 318 then 319 export TARGET_PRODUCT=$ANSWER 320 else 321 echo "** Not a valid product: $ANSWER" 322 fi 323 fi 324 if [ -n "$1" ] ; then 325 break 326 fi 327 done 328 329 set_stuff_for_environment 330} 331 332function choosevariant() 333{ 334 echo "Variant choices are:" 335 local index=1 336 local v 337 for v in ${VARIANT_CHOICES[@]} 338 do 339 # The product name is the name of the directory containing 340 # the makefile we found, above. 341 echo " $index. $v" 342 index=$(($index+1)) 343 done 344 345 local default_value=eng 346 local ANSWER 347 348 export TARGET_BUILD_VARIANT= 349 while [ -z "$TARGET_BUILD_VARIANT" ] 350 do 351 echo -n "Which would you like? [$default_value] " 352 if [ -z "$1" ] ; then 353 read ANSWER 354 else 355 echo $1 356 ANSWER=$1 357 fi 358 359 if [ -z "$ANSWER" ] ; then 360 export TARGET_BUILD_VARIANT=$default_value 361 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then 362 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then 363 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-$_arrayoffset))]} 364 fi 365 else 366 if check_variant $ANSWER 367 then 368 export TARGET_BUILD_VARIANT=$ANSWER 369 else 370 echo "** Not a valid variant: $ANSWER" 371 fi 372 fi 373 if [ -n "$1" ] ; then 374 break 375 fi 376 done 377} 378 379function tapas() 380{ 381 choosecombo 382} 383 384function choosecombo() 385{ 386 choosesim $1 387 388 echo 389 echo 390 choosetype $2 391 392 echo 393 echo 394 chooseproduct $3 395 396 echo 397 echo 398 choosevariant $4 399 400 echo 401 set_stuff_for_environment 402 printconfig 403} 404 405# Clear this variable. It will be built up again when the vendorsetup.sh 406# files are included at the end of this file. 407unset LUNCH_MENU_CHOICES 408function add_lunch_combo() 409{ 410 local new_combo=$1 411 local c 412 for c in ${LUNCH_MENU_CHOICES[@]} ; do 413 if [ "$new_combo" = "$c" ] ; then 414 return 415 fi 416 done 417 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) 418} 419 420# add the default one here 421add_lunch_combo generic-eng 422 423# if we're on linux, add the simulator. There is a special case 424# in lunch to deal with the simulator 425if [ "$(uname)" = "Linux" ] ; then 426 add_lunch_combo simulator 427fi 428 429function print_lunch_menu() 430{ 431 local uname=$(uname) 432 echo 433 echo "You're building on" $uname 434 echo 435 echo ${LUNCH_MENU_CHOICES[@]} 436 echo "Lunch menu... pick a combo:" 437 438 local i=1 439 local choice 440 for choice in ${LUNCH_MENU_CHOICES[@]} 441 do 442 echo " $i. $choice" 443 i=$(($i+1)) 444 done 445 446 echo 447} 448 449function lunch() 450{ 451 local answer 452 453 if [ "$1" ] ; then 454 answer=$1 455 else 456 print_lunch_menu 457 echo -n "Which would you like? [generic-eng] " 458 read answer 459 fi 460 461 local selection= 462 463 if [ -z "$answer" ] 464 then 465 selection=generic-eng 466 elif [ "$answer" = "simulator" ] 467 then 468 selection=simulator 469 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") 470 then 471 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ] 472 then 473 selection=${LUNCH_MENU_CHOICES[$(($answer-$_arrayoffset))]} 474 fi 475 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$") 476 then 477 selection=$answer 478 fi 479 480 if [ -z "$selection" ] 481 then 482 echo 483 echo "Invalid lunch combo: $answer" 484 return 1 485 fi 486 487 # special case the simulator 488 if [ "$selection" = "simulator" ] 489 then 490 export TARGET_PRODUCT=sim 491 export TARGET_BUILD_VARIANT=eng 492 export TARGET_SIMULATOR=true 493 export TARGET_BUILD_TYPE=debug 494 else 495 local product=$(echo -n $selection | sed -e "s/-.*$//") 496 check_product $product 497 if [ $? -ne 0 ] 498 then 499 echo 500 echo "** Don't have a product spec for: '$product'" 501 echo "** Do you have the right repo manifest?" 502 product= 503 fi 504 505 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//") 506 check_variant $variant 507 if [ $? -ne 0 ] 508 then 509 echo 510 echo "** Invalid variant: '$variant'" 511 echo "** Must be one of ${VARIANT_CHOICES[@]}" 512 variant= 513 fi 514 515 if [ -z "$product" -o -z "$variant" ] 516 then 517 echo 518 return 1 519 fi 520 521 export TARGET_PRODUCT=$product 522 export TARGET_BUILD_VARIANT=$variant 523 export TARGET_SIMULATOR=false 524 export TARGET_BUILD_TYPE=release 525 fi # !simulator 526 527 echo 528 529 set_stuff_for_environment 530 printconfig 531} 532 533function gettop 534{ 535 local TOPFILE=build/core/envsetup.mk 536 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then 537 echo $TOP 538 else 539 if [ -f $TOPFILE ] ; then 540 echo $PWD 541 else 542 # We redirect cd to /dev/null in case it's aliased to 543 # a command that prints something as a side-effect 544 # (like pushd) 545 local HERE=$PWD 546 T= 547 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do 548 cd .. > /dev/null 549 T=$PWD 550 done 551 cd $HERE > /dev/null 552 if [ -f "$T/$TOPFILE" ]; then 553 echo $T 554 fi 555 fi 556 fi 557} 558 559function m() 560{ 561 T=$(gettop) 562 if [ "$T" ]; then 563 make -C $T $@ 564 else 565 echo "Couldn't locate the top of the tree. Try setting TOP." 566 fi 567} 568 569function findmakefile() 570{ 571 TOPFILE=build/core/envsetup.mk 572 # We redirect cd to /dev/null in case it's aliased to 573 # a command that prints something as a side-effect 574 # (like pushd) 575 local HERE=$PWD 576 T= 577 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do 578 T=$PWD 579 if [ -f "$T/Android.mk" ]; then 580 echo $T/Android.mk 581 cd $HERE > /dev/null 582 return 583 fi 584 cd .. > /dev/null 585 done 586 cd $HERE > /dev/null 587} 588 589function mm() 590{ 591 # If we're sitting in the root of the build tree, just do a 592 # normal make. 593 if [ -f build/core/envsetup.mk -a -f Makefile ]; then 594 make $@ 595 else 596 # Find the closest Android.mk file. 597 T=$(gettop) 598 local M=$(findmakefile) 599 # Remove the path to top as the makefilepath needs to be relative 600 local M=`echo $M|sed 's:'$T'/::'` 601 if [ ! "$T" ]; then 602 echo "Couldn't locate the top of the tree. Try setting TOP." 603 elif [ ! "$M" ]; then 604 echo "Couldn't locate a makefile from the current directory." 605 else 606 ONE_SHOT_MAKEFILE=$M make -C $T files $@ 607 fi 608 fi 609} 610 611function mmm() 612{ 613 T=$(gettop) 614 if [ "$T" ]; then 615 local MAKEFILE= 616 local ARGS= 617 local DIR TO_CHOP 618 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') 619 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') 620 for DIR in $DIRS ; do 621 DIR=`echo $DIR | sed -e 's:/$::'` 622 if [ -f $DIR/Android.mk ]; then 623 TO_CHOP=`echo $T | wc -c | tr -d ' '` 624 TO_CHOP=`expr $TO_CHOP + 1` 625 MFILE=`echo $PWD | cut -c${TO_CHOP}-` 626 if [ "$MFILE" = "" ] ; then 627 MFILE=$DIR/Android.mk 628 else 629 MFILE=$MFILE/$DIR/Android.mk 630 fi 631 MAKEFILE="$MAKEFILE $MFILE" 632 else 633 if [ "$DIR" = snod ]; then 634 ARGS="$ARGS snod" 635 elif [ "$DIR" = showcommands ]; then 636 ARGS="$ARGS showcommands" 637 else 638 echo "No Android.mk in $DIR." 639 return 1 640 fi 641 fi 642 done 643 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS files $ARGS 644 else 645 echo "Couldn't locate the top of the tree. Try setting TOP." 646 fi 647} 648 649function croot() 650{ 651 T=$(gettop) 652 if [ "$T" ]; then 653 cd $(gettop) 654 else 655 echo "Couldn't locate the top of the tree. Try setting TOP." 656 fi 657} 658 659function cproj() 660{ 661 TOPFILE=build/core/envsetup.mk 662 # We redirect cd to /dev/null in case it's aliased to 663 # a command that prints something as a side-effect 664 # (like pushd) 665 local HERE=$PWD 666 T= 667 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do 668 T=$PWD 669 if [ -f "$T/Android.mk" ]; then 670 cd $T 671 return 672 fi 673 cd .. > /dev/null 674 done 675 cd $HERE > /dev/null 676 echo "can't find Android.mk" 677} 678 679function pid() 680{ 681 local EXE="$1" 682 if [ "$EXE" ] ; then 683 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'` 684 echo "$PID" 685 else 686 echo "usage: pid name" 687 fi 688} 689 690function gdbclient() 691{ 692 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT) 693 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED) 694 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED) 695 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED) 696 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS) 697 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then 698 local EXE="$1" 699 if [ "$EXE" ] ; then 700 EXE=$1 701 else 702 EXE="app_process" 703 fi 704 705 local PORT="$2" 706 if [ "$PORT" ] ; then 707 PORT=$2 708 else 709 PORT=":5039" 710 fi 711 712 local PID 713 local PROG="$3" 714 if [ "$PROG" ] ; then 715 PID=`pid $3` 716 adb forward "tcp$PORT" "tcp$PORT" 717 adb shell gdbserver $PORT --attach $PID & 718 sleep 2 719 else 720 echo "" 721 echo "If you haven't done so already, do this first on the device:" 722 echo " gdbserver $PORT /system/bin/$EXE" 723 echo " or" 724 echo " gdbserver $PORT --attach $PID" 725 echo "" 726 fi 727 728 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS" 729 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS" 730 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT" 731 echo >>"$OUT_ROOT/gdbclient.cmds" "" 732 733 arm-eabi-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE" 734 else 735 echo "Unable to determine build system output dir." 736 fi 737 738} 739 740case `uname -s` in 741 Darwin) 742 function sgrep() 743 { 744 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml|sh|mk)' -print0 | xargs -0 grep --color -n "$@" 745 } 746 747 ;; 748 *) 749 function sgrep() 750 { 751 find . -type f -iregex '.*\.\(c\|h\|cpp\|S\|java\|xml\|sh\|mk\)' -print0 | xargs -0 grep --color -n "$@" 752 } 753 ;; 754esac 755 756function jgrep() 757{ 758 find . -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@" 759} 760 761function cgrep() 762{ 763 find . -type f -name "*\.c*" -print0 | xargs -0 grep --color -n "$@" 764} 765 766function resgrep() 767{ 768 for dir in `find . -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done; 769} 770 771case `uname -s` in 772 Darwin) 773 function mgrep() 774 { 775 find -E . -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@" 776 } 777 778 function treegrep() 779 { 780 find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@" 781 } 782 783 ;; 784 *) 785 function mgrep() 786 { 787 find . -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@" 788 } 789 790 function treegrep() 791 { 792 find . -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@" 793 } 794 795 ;; 796esac 797 798function getprebuilt 799{ 800 get_abs_build_var ANDROID_PREBUILTS 801} 802 803function tracedmdump() 804{ 805 T=$(gettop) 806 if [ ! "$T" ]; then 807 echo "Couldn't locate the top of the tree. Try setting TOP." 808 return 809 fi 810 local prebuiltdir=$(getprebuilt) 811 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu 812 813 local TRACE=$1 814 if [ ! "$TRACE" ] ; then 815 echo "usage: tracedmdump tracename" 816 return 817 fi 818 819 if [ ! -r "$KERNEL" ] ; then 820 echo "Error: cannot find kernel: '$KERNEL'" 821 return 822 fi 823 824 local BASETRACE=$(basename $TRACE) 825 if [ "$BASETRACE" = "$TRACE" ] ; then 826 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE 827 fi 828 829 echo "post-processing traces..." 830 rm -f $TRACE/qtrace.dexlist 831 post_trace $TRACE 832 if [ $? -ne 0 ]; then 833 echo "***" 834 echo "*** Error: malformed trace. Did you remember to exit the emulator?" 835 echo "***" 836 return 837 fi 838 echo "generating dexlist output..." 839 /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 840 echo "generating dmtrace data..." 841 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return 842 echo "generating html file..." 843 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return 844 echo "done, see $TRACE/dmtrace.html for details" 845 echo "or run:" 846 echo " traceview $TRACE/dmtrace" 847} 848 849# communicate with a running device or emulator, set up necessary state, 850# and run the hat command. 851function runhat() 852{ 853 # process standard adb options 854 local adbTarget="" 855 if [ $1 = "-d" -o $1 = "-e" ]; then 856 adbTarget=$1 857 shift 1 858 elif [ $1 = "-s" ]; then 859 adbTarget="$1 $2" 860 shift 2 861 fi 862 local adbOptions=${adbTarget} 863 echo adbOptions = ${adbOptions} 864 865 # runhat options 866 local targetPid=$1 867 local outputFile=$2 868 869 if [ "$targetPid" = "" ]; then 870 echo "Usage: runhat [ -d | -e | -s serial ] target-pid [output-file]" 871 return 872 fi 873 874 # confirm hat is available 875 if [ -z $(which hat) ]; then 876 echo "hat is not available in this configuration." 877 return 878 fi 879 880 adb ${adbOptions} shell >/dev/null mkdir /data/misc 881 adb ${adbOptions} shell chmod 777 /data/misc 882 883 # send a SIGUSR1 to cause the hprof dump 884 echo "Poking $targetPid and waiting for data..." 885 adb ${adbOptions} shell kill -10 $targetPid 886 echo "Press enter when logcat shows \"hprof: heap dump completed\"" 887 echo -n "> " 888 read 889 890 local availFiles=( $(adb ${adbOptions} shell ls /data/misc | grep '^heap-dump' | sed -e 's/.*heap-dump-/heap-dump-/' | sort -r | tr '[:space:][:cntrl:]' ' ') ) 891 local devFile=/data/misc/${availFiles[0]} 892 local localFile=/tmp/$$-hprof 893 894 echo "Retrieving file $devFile..." 895 adb ${adbOptions} pull $devFile $localFile 896 897 adb ${adbOptions} shell rm $devFile 898 899 echo "Running hat on $localFile" 900 echo "View the output by pointing your browser at http://localhost:7000/" 901 echo "" 902 hat $localFile 903} 904 905function getbugreports() 906{ 907 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`) 908 909 if [ ! "$reports" ]; then 910 echo "Could not locate any bugreports." 911 return 912 fi 913 914 local report 915 for report in ${reports[@]} 916 do 917 echo "/sdcard/bugreports/${report}" 918 adb pull /sdcard/bugreports/${report} ${report} 919 gunzip ${report} 920 done 921} 922 923function startviewserver() 924{ 925 local port=4939 926 if [ $# -gt 0 ]; then 927 port=$1 928 fi 929 adb shell service call window 1 i32 $port 930} 931 932function stopviewserver() 933{ 934 adb shell service call window 2 935} 936 937function isviewserverstarted() 938{ 939 adb shell service call window 3 940} 941 942function smoketest() 943{ 944 if [ ! "$ANDROID_PRODUCT_OUT" ]; then 945 echo "Couldn't locate output files. Try running 'lunch' first." >&2 946 return 947 fi 948 T=$(gettop) 949 if [ ! "$T" ]; then 950 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 951 return 952 fi 953 954 (cd "$T" && mmm tests/SmokeTest) && 955 adb uninstall com.android.smoketest > /dev/null && 956 adb uninstall com.android.smoketest.tests > /dev/null && 957 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && 958 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && 959 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner 960} 961 962# simple shortcut to the runtest command 963function runtest() 964{ 965 T=$(gettop) 966 if [ ! "$T" ]; then 967 echo "Couldn't locate the top of the tree. Try setting TOP." >&2 968 return 969 fi 970 ("$T"/development/testrunner/runtest.py $@) 971} 972 973function godir () { 974 if [[ -z "$1" ]]; then 975 echo "Usage: godir <regex>" 976 return 977 fi 978 if [[ ! -f $T/filelist ]]; then 979 echo -n "Creating index..." 980 (cd $T; find . -wholename ./out -prune -o -type f > filelist) 981 echo " Done" 982 echo "" 983 fi 984 local lines 985 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq)) 986 if [[ ${#lines[@]} = 0 ]]; then 987 echo "Not found" 988 return 989 fi 990 local pathname 991 local choice 992 if [[ ${#lines[@]} > 1 ]]; then 993 while [[ -z "$pathname" ]]; do 994 local index=1 995 local line 996 for line in ${lines[@]}; do 997 printf "%6s %s\n" "[$index]" $line 998 index=$(($index + 1)) 999 done 1000 echo 1001 echo -n "Select one: " 1002 unset choice 1003 read choice 1004 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then 1005 echo "Invalid choice" 1006 continue 1007 fi 1008 pathname=${lines[$(($choice-$_arrayoffset))]} 1009 done 1010 else 1011 # even though zsh arrays are 1-based, $foo[0] is an alias for $foo[1] 1012 pathname=${lines[0]} 1013 fi 1014 cd $T/$pathname 1015} 1016 1017# determine whether arrays are zero-based (bash) or one-based (zsh) 1018_xarray=(a b c) 1019if [ -z "${_xarray[${#_xarray[@]}]}" ] 1020then 1021 _arrayoffset=1 1022else 1023 _arrayoffset=0 1024fi 1025unset _xarray 1026 1027# Execute the contents of any vendorsetup.sh files we can find. 1028for f in `/bin/ls vendor/*/vendorsetup.sh vendor/*/build/vendorsetup.sh 2> /dev/null` 1029do 1030 echo "including $f" 1031 . $f 1032done 1033unset f 1034