1 #!/bin/ksh -p 2 # 3 # CDDL HEADER START 4 # 5 # The contents of this file are subject to the terms of the 6 # Common Development and Distribution License (the "License"). 7 # You may not use this file except in compliance with the License. 8 # 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 # or http://www.opensolaris.org/os/licensing. 11 # See the License for the specific language governing permissions 12 # and limitations under the License. 13 # 14 # When distributing Covered Code, include this CDDL HEADER in each 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 # If applicable, add the following below this CDDL HEADER, with the 17 # fields enclosed by brackets "[]" replaced with your own identifying 18 # information: Portions Copyright [yyyy] [name of copyright owner] 19 # 20 # CDDL HEADER END 21 # 22 23 # 24 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 25 # Copyright 2008, 2010, Richard Lowe 26 # Copyright 2011 Nexenta Systems, Inc. All rights reserved. 27 # Copyright 2012 Joshua M. Clulow <josh@sysmgr.org> 28 # Copyright (c) 2017 by Delphix. All rights reserved. 29 # 30 # Based on the nightly script from the integration folks, 31 # Mostly modified and owned by mike_s. 32 # Changes also by kjc, dmk. 33 # 34 # BRINGOVER_WS may be specified in the env file. 35 # The default is the old behavior of CLONE_WS 36 # 37 # -i on the command line, means fast options, so when it's on the 38 # command line (only), lint and check builds are skipped no matter what 39 # the setting of their individual flags are in NIGHTLY_OPTIONS. 40 # 41 # LINTDIRS can be set in the env file, format is a list of: 42 # 43 # /dirname-to-run-lint-on flag 44 # 45 # Where flag is: y - enable lint noise diff output 46 # n - disable lint noise diff output 47 # 48 # For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y" 49 # 50 # OPTHOME may be set in the environment to override /opt 51 # 52 53 # 54 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout 55 # under certain circumstances, which can really screw things up; unset it. 56 # 57 unset CDPATH 58 59 # Get the absolute path of the nightly script that the user invoked. This 60 # may be a relative path, and we need to do this before changing directory. 61 nightly_path=`whence $0` 62 63 # 64 # Keep track of where we found nightly so we can invoke the matching 65 # which_scm script. If that doesn't work, don't go guessing, just rely 66 # on the $PATH settings, which will generally give us either /opt/onbld 67 # or the user's workspace. 68 # 69 WHICH_SCM=$(dirname $nightly_path)/which_scm 70 if [[ ! -x $WHICH_SCM ]]; then 71 WHICH_SCM=which_scm 72 fi 73 74 function fatal_error 75 { 76 print -u2 "nightly: $*" 77 exit 1 78 } 79 80 # 81 # Function to do a DEBUG and non-DEBUG build. Needed because we might 82 # need to do another for the source build, and since we only deliver DEBUG or 83 # non-DEBUG packages. 84 # 85 # usage: normal_build 86 # 87 function normal_build { 88 89 typeset orig_p_FLAG="$p_FLAG" 90 typeset crypto_signer="$CODESIGN_USER" 91 92 suffix="" 93 94 # non-DEBUG build begins 95 96 if [ "$F_FLAG" = "n" ]; then 97 set_non_debug_build_flags 98 CODESIGN_USER="$crypto_signer" \ 99 build "non-DEBUG" "$suffix-nd" "-nd" "$MULTI_PROTO" 100 else 101 echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE" 102 fi 103 104 # non-DEBUG build ends 105 106 # DEBUG build begins 107 108 if [ "$D_FLAG" = "y" ]; then 109 set_debug_build_flags 110 CODESIGN_USER="$crypto_signer" \ 111 build "DEBUG" "$suffix" "" "$MULTI_PROTO" 112 else 113 echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE" 114 fi 115 116 # DEBUG build ends 117 118 p_FLAG="$orig_p_FLAG" 119 } 120 121 # 122 # usage: run_hook HOOKNAME ARGS... 123 # 124 # If variable "$HOOKNAME" is defined, insert a section header into 125 # our logs and then run the command with ARGS 126 # 127 function run_hook { 128 HOOKNAME=$1 129 eval HOOKCMD=\$$HOOKNAME 130 shift 131 132 if [ -n "$HOOKCMD" ]; then 133 ( 134 echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n" 135 ( $HOOKCMD "$@" 2>&1 ) 136 if [ "$?" -ne 0 ]; then 137 # Let exit status propagate up 138 touch $TMPDIR/abort 139 fi 140 ) | tee -a $mail_msg_file >> $LOGFILE 141 142 if [ -f $TMPDIR/abort ]; then 143 build_ok=n 144 echo "\nAborting at request of $HOOKNAME" | 145 tee -a $mail_msg_file >> $LOGFILE 146 exit 1 147 fi 148 fi 149 } 150 151 # Return library search directive as function of given root. 152 function myldlibs { 153 echo "-L$1/lib -L$1/usr/lib" 154 } 155 156 # Return header search directive as function of given root. 157 function myheaders { 158 echo "-I$1/usr/include" 159 } 160 161 # 162 # Function to do the build, including package generation. 163 # usage: build LABEL SUFFIX ND MULTIPROTO 164 # - LABEL is used to tag build output. 165 # - SUFFIX is used to distinguish files (e.g., DEBUG vs non-DEBUG, 166 # open-only vs full tree). 167 # - ND is "-nd" (non-DEBUG builds) or "" (DEBUG builds). 168 # - If MULTIPROTO is "yes", it means to name the proto area according to 169 # SUFFIX. Otherwise ("no"), (re)use the standard proto area. 170 # 171 function build { 172 LABEL=$1 173 SUFFIX=$2 174 ND=$3 175 MULTIPROTO=$4 176 INSTALLOG=install${SUFFIX}-${MACH} 177 NOISE=noise${SUFFIX}-${MACH} 178 PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX} 179 180 ORIGROOT=$ROOT 181 [ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX 182 183 export ENVLDLIBS1=`myldlibs $ROOT` 184 export ENVCPPFLAGS1=`myheaders $ROOT` 185 186 this_build_ok=y 187 # 188 # Build OS-Networking source 189 # 190 echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \ 191 >> $LOGFILE 192 193 rm -f $SRC/${INSTALLOG}.out 194 cd $SRC 195 /bin/time $MAKE -e install 2>&1 | \ 196 tee -a $SRC/${INSTALLOG}.out >> $LOGFILE 197 198 echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file 199 egrep ":" $SRC/${INSTALLOG}.out | 200 egrep -e "(^${MAKE}:|[ ]error[: \n])" | \ 201 egrep -v "Ignoring unknown host" | \ 202 egrep -v "cc .* -o error " | \ 203 egrep -v "warning" | tee $TMPDIR/build_errs${SUFFIX} \ 204 >> $mail_msg_file 205 sed -n "/^Undefined[ ]*first referenced$/,/^ld: fatal:/p" \ 206 < $SRC/${INSTALLOG}.out >> $mail_msg_file 207 if [[ -s $TMPDIR/build_errs${SUFFIX} ]]; then 208 build_ok=n 209 this_build_ok=n 210 fi 211 grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \ 212 >> $mail_msg_file 213 if [ "$?" = "0" ]; then 214 build_ok=n 215 this_build_ok=n 216 fi 217 218 echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file 219 egrep -i warning: $SRC/${INSTALLOG}.out \ 220 | egrep -v '^tic:' \ 221 | egrep -v "symbol (\`|')timezone' has differing types:" \ 222 | egrep -v "parameter <PSTAMP> set to" \ 223 | egrep -v "Ignoring unknown host" \ 224 | egrep -v "redefining segment flags attribute for" \ 225 | tee $TMPDIR/build_warnings${SUFFIX} >> $mail_msg_file 226 if [[ -s $TMPDIR/build_warnings${SUFFIX} ]]; then 227 build_ok=n 228 this_build_ok=n 229 fi 230 231 echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \ 232 >> $LOGFILE 233 234 echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file 235 tail -3 $SRC/${INSTALLOG}.out >>$mail_msg_file 236 237 if [ "$i_FLAG" = "n" ]; then 238 rm -f $SRC/${NOISE}.ref 239 if [ -f $SRC/${NOISE}.out ]; then 240 mv $SRC/${NOISE}.out $SRC/${NOISE}.ref 241 fi 242 grep : $SRC/${INSTALLOG}.out \ 243 | egrep -v '^/' \ 244 | egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \ 245 | egrep -v '^tic:' \ 246 | egrep -v '^mcs' \ 247 | egrep -v '^LD_LIBRARY_PATH=' \ 248 | egrep -v 'ar: creating' \ 249 | egrep -v 'ar: writing' \ 250 | egrep -v 'conflicts:' \ 251 | egrep -v ':saved created' \ 252 | egrep -v '^stty.*c:' \ 253 | egrep -v '^mfgname.c:' \ 254 | egrep -v '^uname-i.c:' \ 255 | egrep -v '^volumes.c:' \ 256 | egrep -v '^lint library construction:' \ 257 | egrep -v 'tsort: INFORM:' \ 258 | egrep -v 'stripalign:' \ 259 | egrep -v 'chars, width' \ 260 | egrep -v "symbol (\`|')timezone' has differing types:" \ 261 | egrep -v 'PSTAMP' \ 262 | egrep -v '^Manifying' \ 263 | egrep -v 'Ignoring unknown host' \ 264 | egrep -v 'Processing method:' \ 265 | egrep -v '^Writing' \ 266 | egrep -v 'spellin1:' \ 267 | egrep -v '^adding:' \ 268 | egrep -v "^echo 'msgid" \ 269 | egrep -v '^echo ' \ 270 | egrep -v '\.c:$' \ 271 | egrep -v '^Adding file:' \ 272 | egrep -v 'CLASSPATH=' \ 273 | egrep -v '\/var\/mail\/:saved' \ 274 | egrep -v -- '-DUTS_VERSION=' \ 275 | egrep -v '^Running Mkbootstrap' \ 276 | egrep -v '^Applet length read:' \ 277 | egrep -v 'bytes written:' \ 278 | egrep -v '^File:SolarisAuthApplet.bin' \ 279 | egrep -v -i 'jibversion' \ 280 | egrep -v '^Output size:' \ 281 | egrep -v '^Solo size statistics:' \ 282 | egrep -v '^Using ROM API Version' \ 283 | egrep -v '^Zero Signature length:' \ 284 | egrep -v '^Note \(probably harmless\):' \ 285 | egrep -v '::' \ 286 | egrep -v -- '-xcache' \ 287 | egrep -v '^\+' \ 288 | egrep -v '^cc1: note: -fwritable-strings' \ 289 | egrep -v 'svccfg-native -s svc:/' \ 290 | sort | uniq >$SRC/${NOISE}.out 291 if [ ! -f $SRC/${NOISE}.ref ]; then 292 cp $SRC/${NOISE}.out $SRC/${NOISE}.ref 293 fi 294 echo "\n==== Build noise differences ($LABEL) ====\n" \ 295 >>$mail_msg_file 296 diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file 297 fi 298 299 # 300 # Re-sign selected binaries using signing server 301 # (gatekeeper builds only) 302 # 303 if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then 304 echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE 305 signing_file="${TMPDIR}/signing" 306 rm -f ${signing_file} 307 export CODESIGN_USER 308 signproto $SRC/tools/codesign/creds 2>&1 | \ 309 tee -a ${signing_file} >> $LOGFILE 310 echo "\n==== Finished signing proto area at `date` ====\n" \ 311 >> $LOGFILE 312 echo "\n==== Crypto module signing errors ($LABEL) ====\n" \ 313 >> $mail_msg_file 314 egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file 315 if (( $? == 0 )) ; then 316 build_ok=n 317 this_build_ok=n 318 fi 319 fi 320 321 # 322 # Building Packages 323 # 324 if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then 325 if [ -d $SRC/pkg ]; then 326 echo "\n==== Creating $LABEL packages at `date` ====\n" \ 327 >> $LOGFILE 328 echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE 329 rm -rf $PKGARCHIVE >> "$LOGFILE" 2>&1 330 mkdir -p $PKGARCHIVE >> "$LOGFILE" 2>&1 331 332 rm -f $SRC/pkg/${INSTALLOG}.out 333 cd $SRC/pkg 334 /bin/time $MAKE -e install 2>&1 | \ 335 tee -a $SRC/pkg/${INSTALLOG}.out >> $LOGFILE 336 337 echo "\n==== package build errors ($LABEL) ====\n" \ 338 >> $mail_msg_file 339 340 egrep "${MAKE}|ERROR|WARNING" $SRC/pkg/${INSTALLOG}.out | \ 341 grep ':' | \ 342 grep -v PSTAMP | \ 343 egrep -v "Ignoring unknown host" | \ 344 tee $TMPDIR/package >> $mail_msg_file 345 if [[ -s $TMPDIR/package ]]; then 346 build_extras_ok=n 347 this_build_ok=n 348 fi 349 else 350 # 351 # Handle it gracefully if -p was set but there so 352 # no pkg directory. 353 # 354 echo "\n==== No $LABEL packages to build ====\n" \ 355 >> $LOGFILE 356 fi 357 else 358 echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE 359 fi 360 361 ROOT=$ORIGROOT 362 } 363 364 # Usage: dolint /dir y|n 365 # Arg. 2 is a flag to turn on/off the lint diff output 366 function dolint { 367 if [ ! -d "$1" ]; then 368 echo "dolint error: $1 is not a directory" 369 exit 1 370 fi 371 372 if [ "$2" != "y" -a "$2" != "n" ]; then 373 echo "dolint internal error: $2 should be 'y' or 'n'" 374 exit 1 375 fi 376 377 lintdir=$1 378 dodiff=$2 379 base=`basename $lintdir` 380 LINTOUT=$lintdir/lint-${MACH}.out 381 LINTNOISE=$lintdir/lint-noise-${MACH} 382 export ENVLDLIBS1=`myldlibs $ROOT` 383 export ENVCPPFLAGS1=`myheaders $ROOT` 384 385 set_debug_build_flags 386 387 # 388 # '$MAKE lint' in $lintdir 389 # 390 echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE 391 392 # remove old lint.out 393 rm -f $lintdir/lint.out $lintdir/lint-noise.out 394 if [ -f $lintdir/lint-noise.ref ]; then 395 mv $lintdir/lint-noise.ref ${LINTNOISE}.ref 396 fi 397 398 rm -f $LINTOUT 399 cd $lintdir 400 # 401 # Remove all .ln files to ensure a full reference file 402 # 403 rm -f Nothing_to_remove \ 404 `find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \) \ 405 -prune -o -type f -name '*.ln' -print ` 406 407 /bin/time $MAKE -ek lint 2>&1 | \ 408 tee -a $LINTOUT >> $LOGFILE 409 410 echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file 411 412 grep "$MAKE:" $LINTOUT | 413 egrep -v "Ignoring unknown host" | \ 414 tee $TMPDIR/lint_errs >> $mail_msg_file 415 if [[ -s $TMPDIR/lint_errs ]]; then 416 build_extras_ok=n 417 fi 418 419 echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE 420 421 echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \ 422 >>$mail_msg_file 423 tail -3 $LINTOUT >>$mail_msg_file 424 425 rm -f ${LINTNOISE}.ref 426 if [ -f ${LINTNOISE}.out ]; then 427 mv ${LINTNOISE}.out ${LINTNOISE}.ref 428 fi 429 grep : $LINTOUT | \ 430 egrep -v '^(real|user|sys)' | 431 egrep -v '(library construction)' | \ 432 egrep -v ': global crosschecks' | \ 433 egrep -v 'Ignoring unknown host' | \ 434 egrep -v '\.c:$' | \ 435 sort | uniq > ${LINTNOISE}.out 436 if [ ! -f ${LINTNOISE}.ref ]; then 437 cp ${LINTNOISE}.out ${LINTNOISE}.ref 438 fi 439 440 if [ "$dodiff" != "n" ]; then 441 echo "\n==== lint warnings $base ====\n" \ 442 >>$mail_msg_file 443 # should be none, though there are a few that were filtered out 444 # above 445 egrep -i '(warning|lint):' ${LINTNOISE}.out \ 446 | sort | uniq | tee $TMPDIR/lint_warns >> $mail_msg_file 447 if [[ -s $TMPDIR/lint_warns ]]; then 448 build_extras_ok=n 449 fi 450 echo "\n==== lint noise differences $base ====\n" \ 451 >> $mail_msg_file 452 diff ${LINTNOISE}.ref ${LINTNOISE}.out \ 453 >> $mail_msg_file 454 fi 455 } 456 457 # 458 # Build and install the onbld tools. 459 # 460 # usage: build_tools DESTROOT 461 # 462 # returns non-zero status if the build was successful. 463 # 464 function build_tools { 465 DESTROOT=$1 466 467 INSTALLOG=install-${MACH} 468 469 echo "\n==== Building tools at `date` ====\n" \ 470 >> $LOGFILE 471 472 rm -f ${TOOLS}/${INSTALLOG}.out 473 cd ${TOOLS} 474 /bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install 2>&1 | \ 475 tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE 476 477 echo "\n==== Tools build errors ====\n" >> $mail_msg_file 478 479 egrep ":" ${TOOLS}/${INSTALLOG}.out | 480 egrep -e "(${MAKE}:|[ ]error[: \n])" | \ 481 egrep -v "Ignoring unknown host" | \ 482 egrep -v warning | tee $TMPDIR/tools_errors >> $mail_msg_file 483 484 if [[ -s $TMPDIR/tools_errors ]]; then 485 return 1 486 fi 487 return 0 488 } 489 490 function staffer { 491 if [ $ISUSER -ne 0 ]; then 492 "$@" 493 else 494 arg="\"$1\"" 495 shift 496 for i 497 do 498 arg="$arg \"$i\"" 499 done 500 eval su $STAFFER -c \'$arg\' 501 fi 502 } 503 504 # 505 # Verify that the closed bins are present 506 # 507 function check_closed_bins { 508 if [[ -n "$ON_CLOSED_BINS" && ! -d "$ON_CLOSED_BINS" ]]; then 509 echo "ON_CLOSED_BINS must point to the closed binaries tree." 510 build_ok=n 511 exit 1 512 fi 513 } 514 515 # 516 # wrapper over wsdiff. 517 # usage: do_wsdiff LABEL OLDPROTO NEWPROTO 518 # 519 function do_wsdiff { 520 label=$1 521 oldproto=$2 522 newproto=$3 523 524 wsdiff="wsdiff" 525 [ "$t_FLAG" = y ] && wsdiff="wsdiff -t" 526 527 echo "\n==== Getting object changes since last build at `date`" \ 528 "($label) ====\n" | tee -a $LOGFILE >> $mail_msg_file 529 $wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \ 530 tee -a $LOGFILE >> $mail_msg_file 531 echo "\n==== Object changes determined at `date` ($label) ====\n" | \ 532 tee -a $LOGFILE >> $mail_msg_file 533 } 534 535 # 536 # Functions for setting build flags (DEBUG/non-DEBUG). Keep them 537 # together. 538 # 539 540 function set_non_debug_build_flags { 541 export RELEASE_BUILD ; RELEASE_BUILD= 542 unset EXTRA_OPTIONS 543 unset EXTRA_CFLAGS 544 } 545 546 function set_debug_build_flags { 547 unset RELEASE_BUILD 548 unset EXTRA_OPTIONS 549 unset EXTRA_CFLAGS 550 } 551 552 553 MACH=`uname -p` 554 555 if [ "$OPTHOME" = "" ]; then 556 OPTHOME=/opt 557 export OPTHOME 558 fi 559 560 USAGE='Usage: nightly [-in] [+t] [-V VERS ] <env_file> 561 562 Where: 563 -i Fast incremental options (no clobber, lint, check) 564 -n Do not do a bringover 565 +t Use the build tools in $ONBLD_TOOLS/bin 566 -V VERS set the build version string to VERS 567 568 <env_file> file in Bourne shell syntax that sets and exports 569 variables that configure the operation of this script and many of 570 the scripts this one calls. If <env_file> does not exist, 571 it will be looked for in $OPTHOME/onbld/env. 572 573 non-DEBUG is the default build type. Build options can be set in the 574 NIGHTLY_OPTIONS variable in the <env_file> as follows: 575 576 -A check for ABI differences in .so files 577 -C check for cstyle/hdrchk errors 578 -D do a build with DEBUG on 579 -F do _not_ do a non-DEBUG build 580 -G gate keeper default group of options (-au) 581 -I integration engineer default group of options (-ampu) 582 -M do not run pmodes (safe file permission checker) 583 -N do not run protocmp 584 -R default group of options for building a release (-mp) 585 -U update proto area in the parent 586 -V VERS set the build version string to VERS 587 -f find unreferenced files 588 -i do an incremental build (no "make clobber") 589 -l do "make lint" in $LINTDIRS (default: $SRC y) 590 -m send mail to $MAILTO at end of build 591 -n do not do a bringover 592 -p create packages 593 -r check ELF runtime attributes in the proto area 594 -t build and use the tools in $SRC/tools (default setting) 595 +t Use the build tools in $ONBLD_TOOLS/bin 596 -u update proto_list_$MACH and friends in the parent workspace; 597 when used with -f, also build an unrefmaster.out in the parent 598 -w report on differences between previous and current proto areas 599 ' 600 # 601 # A log file will be generated under the name $LOGFILE 602 # for partially completed build and log.`date '+%F'` 603 # in the same directory for fully completed builds. 604 # 605 606 # default values for low-level FLAGS; G I R are group FLAGS 607 A_FLAG=n 608 C_FLAG=n 609 D_FLAG=n 610 F_FLAG=n 611 f_FLAG=n 612 i_FLAG=n; i_CMD_LINE_FLAG=n 613 l_FLAG=n 614 M_FLAG=n 615 m_FLAG=n 616 N_FLAG=n 617 n_FLAG=n 618 p_FLAG=n 619 r_FLAG=n 620 t_FLAG=y 621 U_FLAG=n 622 u_FLAG=n 623 V_FLAG=n 624 w_FLAG=n 625 W_FLAG=n 626 # 627 build_ok=y 628 build_extras_ok=y 629 630 # 631 # examine arguments 632 # 633 634 OPTIND=1 635 while getopts +intV:W FLAG 636 do 637 case $FLAG in 638 i ) i_FLAG=y; i_CMD_LINE_FLAG=y 639 ;; 640 n ) n_FLAG=y 641 ;; 642 +t ) t_FLAG=n 643 ;; 644 V ) V_FLAG=y 645 V_ARG="$OPTARG" 646 ;; 647 W ) W_FLAG=y 648 ;; 649 \? ) echo "$USAGE" 650 exit 1 651 ;; 652 esac 653 done 654 655 # correct argument count after options 656 shift `expr $OPTIND - 1` 657 658 # test that the path to the environment-setting file was given 659 if [ $# -ne 1 ]; then 660 echo "$USAGE" 661 exit 1 662 fi 663 664 # check if user is running nightly as root 665 # ISUSER is set non-zero if an ordinary user runs nightly, or is zero 666 # when root invokes nightly. 667 /usr/bin/id | grep '^uid=0(' >/dev/null 2>&1 668 ISUSER=$?; export ISUSER 669 670 # 671 # force locale to C 672 LANG=C; export LANG 673 LC_ALL=C; export LC_ALL 674 LC_COLLATE=C; export LC_COLLATE 675 LC_CTYPE=C; export LC_CTYPE 676 LC_MESSAGES=C; export LC_MESSAGES 677 LC_MONETARY=C; export LC_MONETARY 678 LC_NUMERIC=C; export LC_NUMERIC 679 LC_TIME=C; export LC_TIME 680 681 # clear environment variables we know to be bad for the build 682 unset LD_OPTIONS 683 unset LD_AUDIT LD_AUDIT_32 LD_AUDIT_64 684 unset LD_BIND_NOW LD_BIND_NOW_32 LD_BIND_NOW_64 685 unset LD_BREADTH LD_BREADTH_32 LD_BREADTH_64 686 unset LD_CONFIG LD_CONFIG_32 LD_CONFIG_64 687 unset LD_DEBUG LD_DEBUG_32 LD_DEBUG_64 688 unset LD_DEMANGLE LD_DEMANGLE_32 LD_DEMANGLE_64 689 unset LD_FLAGS LD_FLAGS_32 LD_FLAGS_64 690 unset LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 691 unset LD_LOADFLTR LD_LOADFLTR_32 LD_LOADFLTR_64 692 unset LD_NOAUDIT LD_NOAUDIT_32 LD_NOAUDIT_64 693 unset LD_NOAUXFLTR LD_NOAUXFLTR_32 LD_NOAUXFLTR_64 694 unset LD_NOCONFIG LD_NOCONFIG_32 LD_NOCONFIG_64 695 unset LD_NODIRCONFIG LD_NODIRCONFIG_32 LD_NODIRCONFIG_64 696 unset LD_NODIRECT LD_NODIRECT_32 LD_NODIRECT_64 697 unset LD_NOLAZYLOAD LD_NOLAZYLOAD_32 LD_NOLAZYLOAD_64 698 unset LD_NOOBJALTER LD_NOOBJALTER_32 LD_NOOBJALTER_64 699 unset LD_NOVERSION LD_NOVERSION_32 LD_NOVERSION_64 700 unset LD_ORIGIN LD_ORIGIN_32 LD_ORIGIN_64 701 unset LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64 702 unset LD_PROFILE LD_PROFILE_32 LD_PROFILE_64 703 704 unset CONFIG 705 unset GROUP 706 unset OWNER 707 unset REMOTE 708 unset ENV 709 unset ARCH 710 unset CLASSPATH 711 unset NAME 712 713 # 714 # To get ONBLD_TOOLS from the environment, it must come from the env file. 715 # If it comes interactively, it is generally TOOLS_PROTO, which will be 716 # clobbered before the compiler version checks, which will therefore fail. 717 # 718 unset ONBLD_TOOLS 719 720 # 721 # Setup environmental variables 722 # 723 if [ -f /etc/nightly.conf ]; then 724 . /etc/nightly.conf 725 fi 726 727 if [ -f $1 ]; then 728 if [[ $1 = */* ]]; then 729 . $1 730 else 731 . ./$1 732 fi 733 else 734 if [ -f $OPTHOME/onbld/env/$1 ]; then 735 . $OPTHOME/onbld/env/$1 736 else 737 echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1" 738 exit 1 739 fi 740 fi 741 742 # contents of stdenv.sh inserted after next line: 743 # STDENV_START 744 # STDENV_END 745 746 # Check if we have sufficient data to continue... 747 [[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set." 748 if [[ "${NIGHTLY_OPTIONS}" == ~(F)n ]] ; then 749 # Check if the gate data are valid if we don't do a "bringover" below 750 [[ -d "${CODEMGR_WS}" ]] || \ 751 fatal_error "Error: ${CODEMGR_WS} is not a directory." 752 [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || \ 753 fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found." 754 fi 755 756 # 757 # place ourselves in a new task, respecting BUILD_PROJECT if set. 758 # 759 if [ -z "$BUILD_PROJECT" ]; then 760 /usr/bin/newtask -c $$ 761 else 762 /usr/bin/newtask -c $$ -p $BUILD_PROJECT 763 fi 764 765 ps -o taskid= -p $$ | read build_taskid 766 ps -o project= -p $$ | read build_project 767 768 # 769 # See if NIGHTLY_OPTIONS is set 770 # 771 if [ "$NIGHTLY_OPTIONS" = "" ]; then 772 NIGHTLY_OPTIONS="-aBm" 773 fi 774 775 # 776 # If BRINGOVER_WS was not specified, let it default to CLONE_WS 777 # 778 if [ "$BRINGOVER_WS" = "" ]; then 779 BRINGOVER_WS=$CLONE_WS 780 fi 781 782 # 783 # If BRINGOVER_FILES was not specified, default to usr 784 # 785 if [ "$BRINGOVER_FILES" = "" ]; then 786 BRINGOVER_FILES="usr" 787 fi 788 789 check_closed_bins 790 791 # 792 # Note: changes to the option letters here should also be applied to the 793 # bldenv script. `d' is listed for backward compatibility. 794 # 795 NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-} 796 OPTIND=1 797 while getopts +ABCDdFfGIilMmNnpRrtUuwW FLAG $NIGHTLY_OPTIONS 798 do 799 case $FLAG in 800 A ) A_FLAG=y 801 ;; 802 B ) D_FLAG=y 803 ;; # old version of D 804 C ) C_FLAG=y 805 ;; 806 D ) D_FLAG=y 807 ;; 808 F ) F_FLAG=y 809 ;; 810 f ) f_FLAG=y 811 ;; 812 G ) u_FLAG=y 813 ;; 814 I ) m_FLAG=y 815 p_FLAG=y 816 u_FLAG=y 817 ;; 818 i ) i_FLAG=y 819 ;; 820 l ) l_FLAG=y 821 ;; 822 M ) M_FLAG=y 823 ;; 824 m ) m_FLAG=y 825 ;; 826 N ) N_FLAG=y 827 ;; 828 n ) n_FLAG=y 829 ;; 830 p ) p_FLAG=y 831 ;; 832 R ) m_FLAG=y 833 p_FLAG=y 834 ;; 835 r ) r_FLAG=y 836 ;; 837 +t ) t_FLAG=n 838 ;; 839 U ) if [ -z "${PARENT_ROOT}" ]; then 840 echo "PARENT_ROOT must be set if the U flag is" \ 841 "present in NIGHTLY_OPTIONS." 842 exit 1 843 fi 844 NIGHTLY_PARENT_ROOT=$PARENT_ROOT 845 if [ -n "${PARENT_TOOLS_ROOT}" ]; then 846 NIGHTLY_PARENT_TOOLS_ROOT=$PARENT_TOOLS_ROOT 847 fi 848 U_FLAG=y 849 ;; 850 u ) u_FLAG=y 851 ;; 852 w ) w_FLAG=y 853 ;; 854 W ) W_FLAG=y 855 ;; 856 \? ) echo "$USAGE" 857 exit 1 858 ;; 859 esac 860 done 861 862 if [ $ISUSER -ne 0 ]; then 863 # Set default value for STAFFER, if needed. 864 if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then 865 STAFFER=`/usr/xpg4/bin/id -un` 866 export STAFFER 867 fi 868 fi 869 870 if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then 871 MAILTO=$STAFFER 872 export MAILTO 873 fi 874 875 PATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin" 876 PATH="$PATH:$OPTHOME/SUNWspro/bin:/usr/bin:/usr/sbin:/usr/ucb" 877 PATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:." 878 export PATH 879 880 # roots of source trees, both relative to $SRC and absolute. 881 relsrcdirs="." 882 abssrcdirs="$SRC" 883 884 PROTOCMPTERSE="protocmp.terse -gu" 885 POUND_SIGN="#" 886 # have we set RELEASE_DATE in our env file? 887 if [ -z "$RELEASE_DATE" ]; then 888 RELEASE_DATE=$(LC_ALL=C date +"%B %Y") 889 fi 890 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d) 891 BASEWSDIR=$(basename $CODEMGR_WS) 892 DEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\"" 893 894 # we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process 895 # by avoiding repeated shell invocations to evaluate Makefile.master 896 # definitions. 897 export POUND_SIGN RELEASE_DATE DEV_CM 898 899 maketype="distributed" 900 if [[ -z "$MAKE" ]]; then 901 MAKE=dmake 902 elif [[ ! -x "$MAKE" ]]; then 903 echo "\$MAKE is set to garbage in the environment" 904 exit 1 905 fi 906 export PATH 907 export MAKE 908 909 if [ "${SUNWSPRO}" != "" ]; then 910 PATH="${SUNWSPRO}/bin:$PATH" 911 export PATH 912 fi 913 914 hostname=$(uname -n) 915 if [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]] 916 then 917 maxjobs= 918 if [[ -f $HOME/.make.machines ]] 919 then 920 # Note: there is a hard tab and space character in the []s 921 # below. 922 egrep -i "^[ ]*$hostname[ \.]" \ 923 $HOME/.make.machines | read host jobs 924 maxjobs=${jobs##*=} 925 fi 926 927 if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]] 928 then 929 # default 930 maxjobs=4 931 fi 932 933 export DMAKE_MAX_JOBS=$maxjobs 934 fi 935 936 DMAKE_MODE=parallel; 937 export DMAKE_MODE 938 939 if [ -z "${ROOT}" ]; then 940 echo "ROOT must be set." 941 exit 1 942 fi 943 944 # 945 # if -V flag was given, reset VERSION to V_ARG 946 # 947 if [ "$V_FLAG" = "y" ]; then 948 VERSION=$V_ARG 949 fi 950 951 TMPDIR="/tmp/nightly.tmpdir.$$" 952 export TMPDIR 953 rm -rf ${TMPDIR} 954 mkdir -p $TMPDIR || exit 1 955 chmod 777 $TMPDIR 956 957 # 958 # Tools should only be built non-DEBUG. Keep track of the tools proto 959 # area path relative to $TOOLS, because the latter changes in an 960 # export build. 961 # 962 # TOOLS_PROTO is included below for builds other than usr/src/tools 963 # that look for this location. For usr/src/tools, this will be 964 # overridden on the $MAKE command line in build_tools(). 965 # 966 TOOLS=${SRC}/tools 967 TOOLS_PROTO_REL=proto/root_${MACH}-nd 968 TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO 969 970 unset CFLAGS LD_LIBRARY_PATH LDFLAGS 971 972 # create directories that are automatically removed if the nightly script 973 # fails to start correctly 974 function newdir { 975 dir=$1 976 toadd= 977 while [ ! -d $dir ]; do 978 toadd="$dir $toadd" 979 dir=`dirname $dir` 980 done 981 torm= 982 newlist= 983 for dir in $toadd; do 984 if staffer mkdir $dir; then 985 newlist="$ISUSER $dir $newlist" 986 torm="$dir $torm" 987 else 988 [ -z "$torm" ] || staffer rmdir $torm 989 return 1 990 fi 991 done 992 newdirlist="$newlist $newdirlist" 993 return 0 994 } 995 newdirlist= 996 997 [ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1 998 999 # since this script assumes the build is from full source, it nullifies 1000 # variables likely to have been set by a "ws" script; nullification 1001 # confines the search space for headers and libraries to the proto area 1002 # built from this immediate source. 1003 ENVLDLIBS1= 1004 ENVLDLIBS2= 1005 ENVLDLIBS3= 1006 ENVCPPFLAGS1= 1007 ENVCPPFLAGS2= 1008 ENVCPPFLAGS3= 1009 ENVCPPFLAGS4= 1010 PARENT_ROOT= 1011 1012 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \ 1013 ENVLDLIBS1 ENVLDLIBS2 PARENT_ROOT 1014 1015 PKGARCHIVE_ORIG=$PKGARCHIVE 1016 1017 # 1018 # Juggle the logs and optionally send mail on completion. 1019 # 1020 1021 function logshuffle { 1022 LLOG="$ATLOG/log.`date '+%F.%H:%M'`" 1023 if [ -f $LLOG -o -d $LLOG ]; then 1024 LLOG=$LLOG.$$ 1025 fi 1026 1027 rm -f "$ATLOG/latest" 2>/dev/null 1028 mkdir -p $LLOG 1029 export LLOG 1030 1031 if [ "$build_ok" = "y" ]; then 1032 mv $ATLOG/proto_list_${MACH} $LLOG 1033 1034 if [ -f $ATLOG/proto_list_tools_${MACH} ]; then 1035 mv $ATLOG/proto_list_tools_${MACH} $LLOG 1036 fi 1037 1038 if [ -f $TMPDIR/wsdiff.results ]; then 1039 mv $TMPDIR/wsdiff.results $LLOG 1040 fi 1041 1042 if [ -f $TMPDIR/wsdiff-nd.results ]; then 1043 mv $TMPDIR/wsdiff-nd.results $LLOG 1044 fi 1045 fi 1046 1047 # 1048 # Now that we're about to send mail, it's time to check the noise 1049 # file. In the event that an error occurs beyond this point, it will 1050 # be recorded in the nightly.log file, but nowhere else. This would 1051 # include only errors that cause the copying of the noise log to fail 1052 # or the mail itself not to be sent. 1053 # 1054 1055 exec >>$LOGFILE 2>&1 1056 if [ -s $build_noise_file ]; then 1057 echo "\n==== Nightly build noise ====\n" | 1058 tee -a $LOGFILE >>$mail_msg_file 1059 cat $build_noise_file >>$LOGFILE 1060 cat $build_noise_file >>$mail_msg_file 1061 echo | tee -a $LOGFILE >>$mail_msg_file 1062 fi 1063 rm -f $build_noise_file 1064 1065 case "$build_ok" in 1066 y) 1067 state=Completed 1068 ;; 1069 i) 1070 state=Interrupted 1071 ;; 1072 *) 1073 state=Failed 1074 ;; 1075 esac 1076 1077 if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then 1078 state=Failed 1079 fi 1080 1081 NIGHTLY_STATUS=$state 1082 export NIGHTLY_STATUS 1083 1084 run_hook POST_NIGHTLY $state 1085 run_hook SYS_POST_NIGHTLY $state 1086 1087 # 1088 # mailx(1) sets From: based on the -r flag 1089 # if it is given. 1090 # 1091 mailx_r= 1092 if [[ -n "${MAILFROM}" ]]; then 1093 mailx_r="-r ${MAILFROM}" 1094 fi 1095 1096 cat $build_time_file $build_environ_file $mail_msg_file \ 1097 > ${LLOG}/mail_msg 1098 if [ "$m_FLAG" = "y" ]; then 1099 cat ${LLOG}/mail_msg | /usr/bin/mailx ${mailx_r} -s \ 1100 "Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \ 1101 ${MAILTO} 1102 fi 1103 1104 if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then 1105 staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH} 1106 staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log 1107 fi 1108 1109 mv $LOGFILE $LLOG 1110 1111 ln -s "$LLOG" "$ATLOG/latest" 1112 } 1113 1114 # 1115 # Remove the locks and temporary files on any exit 1116 # 1117 function cleanup { 1118 logshuffle 1119 1120 [ -z "$lockfile" ] || staffer rm -f $lockfile 1121 [ -z "$atloglockfile" ] || rm -f $atloglockfile 1122 [ -z "$ulockfile" ] || staffer rm -f $ulockfile 1123 [ -z "$Ulockfile" ] || rm -f $Ulockfile 1124 1125 set -- $newdirlist 1126 while [ $# -gt 0 ]; do 1127 ISUSER=$1 staffer rmdir $2 1128 shift; shift 1129 done 1130 rm -rf $TMPDIR 1131 } 1132 1133 function cleanup_signal { 1134 build_ok=i 1135 # this will trigger cleanup(), above. 1136 exit 1 1137 } 1138 1139 trap cleanup 0 1140 trap cleanup_signal 1 2 3 15 1141 1142 # 1143 # Generic lock file processing -- make sure that the lock file doesn't 1144 # exist. If it does, it should name the build host and PID. If it 1145 # doesn't, then make sure we can create it. Clean up locks that are 1146 # known to be stale (assumes host name is unique among build systems 1147 # for the workspace). 1148 # 1149 function create_lock { 1150 lockf=$1 1151 lockvar=$2 1152 1153 ldir=`dirname $lockf` 1154 [ -d $ldir ] || newdir $ldir || exit 1 1155 eval $lockvar=$lockf 1156 1157 while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do 1158 basews=`basename $CODEMGR_WS` 1159 ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid 1160 if [ "$host" != "$hostname" ]; then 1161 echo "$MACH build of $basews apparently" \ 1162 "already started by $user on $host as $pid." 1163 exit 1 1164 elif kill -s 0 $pid 2>/dev/null; then 1165 echo "$MACH build of $basews already started" \ 1166 "by $user as $pid." 1167 exit 1 1168 else 1169 # stale lock; clear it out and try again 1170 rm -f $lockf 1171 fi 1172 done 1173 } 1174 1175 # 1176 # Return the list of interesting proto areas, depending on the current 1177 # options. 1178 # 1179 function allprotos { 1180 typeset roots="$ROOT" 1181 1182 if [[ "$F_FLAG" = n && "$MULTI_PROTO" = yes ]]; then 1183 roots="$roots $ROOT-nd" 1184 fi 1185 1186 echo $roots 1187 } 1188 1189 # Ensure no other instance of this script is running on this host. 1190 # LOCKNAME can be set in <env_file>, and is by default, but is not 1191 # required due to the use of $ATLOG below. 1192 if [ -n "$LOCKNAME" ]; then 1193 create_lock /tmp/$LOCKNAME "lockfile" 1194 fi 1195 # 1196 # Create from one, two, or three other locks: 1197 # $ATLOG/nightly.lock 1198 # - protects against multiple builds in same workspace 1199 # $PARENT_WS/usr/src/nightly.$MACH.lock 1200 # - protects against multiple 'u' copy-backs 1201 # $NIGHTLY_PARENT_ROOT/nightly.lock 1202 # - protects against multiple 'U' copy-backs 1203 # 1204 # Overriding ISUSER to 1 causes the lock to be created as root if the 1205 # script is run as root. The default is to create it as $STAFFER. 1206 ISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile" 1207 if [ "$u_FLAG" = "y" ]; then 1208 create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile" 1209 fi 1210 if [ "$U_FLAG" = "y" ]; then 1211 # NIGHTLY_PARENT_ROOT is written as root if script invoked as root. 1212 ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile" 1213 fi 1214 1215 # Locks have been taken, so we're doing a build and we're committed to 1216 # the directories we may have created so far. 1217 newdirlist= 1218 1219 # 1220 # Create mail_msg_file 1221 # 1222 mail_msg_file="${TMPDIR}/mail_msg" 1223 touch $mail_msg_file 1224 build_time_file="${TMPDIR}/build_time" 1225 build_environ_file="${TMPDIR}/build_environ" 1226 touch $build_environ_file 1227 # 1228 # Move old LOGFILE aside 1229 # ATLOG directory already made by 'create_lock' above 1230 # 1231 if [ -f $LOGFILE ]; then 1232 mv -f $LOGFILE ${LOGFILE}- 1233 fi 1234 # 1235 # Build OsNet source 1236 # 1237 START_DATE=`date` 1238 SECONDS=0 1239 echo "\n==== Nightly $maketype build started: $START_DATE ====" \ 1240 | tee -a $LOGFILE > $build_time_file 1241 1242 echo "\nBuild project: $build_project\nBuild taskid: $build_taskid" | \ 1243 tee -a $mail_msg_file >> $LOGFILE 1244 1245 # make sure we log only to the nightly build file 1246 build_noise_file="${TMPDIR}/build_noise" 1247 exec </dev/null >$build_noise_file 2>&1 1248 1249 run_hook SYS_PRE_NIGHTLY 1250 run_hook PRE_NIGHTLY 1251 1252 echo "\n==== list of environment variables ====\n" >> $LOGFILE 1253 env >> $LOGFILE 1254 1255 echo "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE 1256 1257 if [ "$N_FLAG" = "y" ]; then 1258 if [ "$p_FLAG" = "y" ]; then 1259 cat <<EOF | tee -a $mail_msg_file >> $LOGFILE 1260 WARNING: the p option (create packages) is set, but so is the N option (do 1261 not run protocmp); this is dangerous; you should unset the N option 1262 EOF 1263 else 1264 cat <<EOF | tee -a $mail_msg_file >> $LOGFILE 1265 Warning: the N option (do not run protocmp) is set; it probably shouldn't be 1266 EOF 1267 fi 1268 echo "" | tee -a $mail_msg_file >> $LOGFILE 1269 fi 1270 1271 if [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then 1272 # 1273 # In the past we just complained but went ahead with the lint 1274 # pass, even though the proto area was built non-DEBUG. It's 1275 # unlikely that non-DEBUG headers will make a difference, but 1276 # rather than assuming it's a safe combination, force the user 1277 # to specify a DEBUG build. 1278 # 1279 echo "WARNING: DEBUG build not requested; disabling lint.\n" \ 1280 | tee -a $mail_msg_file >> $LOGFILE 1281 l_FLAG=n 1282 fi 1283 1284 if [ "$f_FLAG" = "y" ]; then 1285 if [ "$i_FLAG" = "y" ]; then 1286 echo "WARNING: the -f flag cannot be used during incremental" \ 1287 "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE 1288 f_FLAG=n 1289 fi 1290 if [ "${l_FLAG}${p_FLAG}" != "yy" ]; then 1291 echo "WARNING: the -f flag requires -l, and -p;" \ 1292 "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE 1293 f_FLAG=n 1294 fi 1295 fi 1296 1297 if [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then 1298 echo "WARNING: -w specified, but $ROOT does not exist;" \ 1299 "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE 1300 w_FLAG=n 1301 fi 1302 1303 case $MULTI_PROTO in 1304 yes|no) ;; 1305 *) 1306 echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \ 1307 "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE 1308 echo "Setting MULTI_PROTO to \"no\".\n" | \ 1309 tee -a $mail_msg_file >> $LOGFILE 1310 export MULTI_PROTO=no 1311 ;; 1312 esac 1313 1314 echo "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE 1315 echo $VERSION | tee -a $mail_msg_file >> $LOGFILE 1316 1317 # Save the current proto area if we're comparing against the last build 1318 if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then 1319 if [ -d "$ROOT.prev" ]; then 1320 rm -rf $ROOT.prev 1321 fi 1322 mv $ROOT $ROOT.prev 1323 fi 1324 1325 # Same for non-DEBUG proto area 1326 if [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then 1327 if [ -d "$ROOT-nd.prev" ]; then 1328 rm -rf $ROOT-nd.prev 1329 fi 1330 mv $ROOT-nd $ROOT-nd.prev 1331 fi 1332 1333 # 1334 # Echo the SCM type of the parent workspace, this can't just be which_scm 1335 # as that does not know how to identify various network repositories. 1336 # 1337 function parent_wstype { 1338 typeset scm_type junk 1339 1340 CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \ 1341 | read scm_type junk 1342 if [[ -z "$scm_type" || "$scm_type" == unknown ]]; then 1343 # Probe BRINGOVER_WS to determine its type 1344 if [[ $BRINGOVER_WS == ssh://* ]]; then 1345 scm_type="mercurial" 1346 elif [[ $BRINGOVER_WS == http://* ]] && \ 1347 wget -q -O- --save-headers "$BRINGOVER_WS/?cmd=heads" | \ 1348 egrep -s "application/mercurial" 2> /dev/null; then 1349 scm_type="mercurial" 1350 else 1351 scm_type="none" 1352 fi 1353 fi 1354 1355 # fold both unsupported and unrecognized results into "none" 1356 case "$scm_type" in 1357 mercurial) 1358 ;; 1359 *) scm_type=none 1360 ;; 1361 esac 1362 1363 echo $scm_type 1364 } 1365 1366 # Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS 1367 function child_wstype { 1368 typeset scm_type junk 1369 1370 # Probe CODEMGR_WS to determine its type 1371 if [[ -d $CODEMGR_WS ]]; then 1372 $WHICH_SCM | read scm_type junk || exit 1 1373 fi 1374 1375 case "$scm_type" in 1376 none|git|mercurial) 1377 ;; 1378 *) scm_type=none 1379 ;; 1380 esac 1381 1382 echo $scm_type 1383 } 1384 1385 SCM_TYPE=$(child_wstype) 1386 1387 # 1388 # Decide whether to clobber 1389 # 1390 if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then 1391 echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE 1392 1393 cd $SRC 1394 # remove old clobber file 1395 rm -f $SRC/clobber.out 1396 rm -f $SRC/clobber-${MACH}.out 1397 1398 # Remove all .make.state* files, just in case we are restarting 1399 # the build after having interrupted a previous 'make clobber'. 1400 find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \ 1401 -o -name 'interfaces.*' \) -prune \ 1402 -o -name '.make.*' -print | xargs rm -f 1403 1404 $MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE 1405 echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file 1406 grep "$MAKE:" $SRC/clobber-${MACH}.out | 1407 egrep -v "Ignoring unknown host" | \ 1408 tee $TMPDIR/clobber_errs >> $mail_msg_file 1409 1410 if [[ -s $TMPDIR/clobber_errs ]]; then 1411 build_extras_ok=n 1412 fi 1413 1414 if [[ "$t_FLAG" = "y" ]]; then 1415 echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE 1416 cd ${TOOLS} 1417 rm -f ${TOOLS}/clobber-${MACH}.out 1418 $MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \ 1419 tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE 1420 echo "\n==== Make tools clobber ERRORS ====\n" \ 1421 >> $mail_msg_file 1422 grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \ 1423 >> $mail_msg_file 1424 if (( $? == 0 )); then 1425 build_extras_ok=n 1426 fi 1427 rm -rf ${TOOLS_PROTO} 1428 mkdir -p ${TOOLS_PROTO} 1429 fi 1430 1431 typeset roots=$(allprotos) 1432 echo "\n\nClearing $roots" >> "$LOGFILE" 1433 rm -rf $roots 1434 1435 # Get back to a clean workspace as much as possible to catch 1436 # problems that only occur on fresh workspaces. 1437 # Remove all .make.state* files, libraries, and .o's that may 1438 # have been omitted from clobber. A couple of libraries are 1439 # under source code control, so leave them alone. 1440 # We should probably blow away temporary directories too. 1441 cd $SRC 1442 find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \ 1443 -o -name .git -o -name 'interfaces.*' \) -prune -o \ 1444 \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \ 1445 -name '*.o' \) -print | \ 1446 grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f 1447 else 1448 echo "\n==== No clobber at `date` ====\n" >> $LOGFILE 1449 fi 1450 1451 type bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial { 1452 typeset -x PATH=$PATH 1453 1454 # If the repository doesn't exist yet, then we want to populate it. 1455 if [[ ! -d $CODEMGR_WS/.hg ]]; then 1456 staffer hg init $CODEMGR_WS 1457 staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc 1458 staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc 1459 touch $TMPDIR/new_repository 1460 fi 1461 1462 typeset -x HGMERGE="/bin/false" 1463 1464 # 1465 # If the user has changes, regardless of whether those changes are 1466 # committed, and regardless of whether those changes conflict, then 1467 # we'll attempt to merge them either implicitly (uncommitted) or 1468 # explicitly (committed). 1469 # 1470 # These are the messages we'll use to help clarify mercurial output 1471 # in those cases. 1472 # 1473 typeset mergefailmsg="\ 1474 ***\n\ 1475 *** nightly was unable to automatically merge your changes. You should\n\ 1476 *** redo the full merge manually, following the steps outlined by mercurial\n\ 1477 *** above, then restart nightly.\n\ 1478 ***\n" 1479 typeset mergepassmsg="\ 1480 ***\n\ 1481 *** nightly successfully merged your changes. This means that your working\n\ 1482 *** directory has been updated, but those changes are not yet committed.\n\ 1483 *** After nightly completes, you should validate the results of the merge,\n\ 1484 *** then use hg commit manually.\n\ 1485 ***\n" 1486 1487 # 1488 # For each repository in turn: 1489 # 1490 # 1. Do the pull. If this fails, dump the output and bail out. 1491 # 1492 # 2. If the pull resulted in an extra head, do an explicit merge. 1493 # If this fails, dump the output and bail out. 1494 # 1495 # Because we can't rely on Mercurial to exit with a failure code 1496 # when a merge fails (Mercurial issue #186), we must grep the 1497 # output of pull/merge to check for attempted and/or failed merges. 1498 # 1499 # 3. If a merge failed, set the message and fail the bringover. 1500 # 1501 # 4. Otherwise, if a merge succeeded, set the message 1502 # 1503 # 5. Dump the output, and any message from step 3 or 4. 1504 # 1505 1506 typeset HG_SOURCE=$BRINGOVER_WS 1507 if [ ! -f $TMPDIR/new_repository ]; then 1508 HG_SOURCE=$TMPDIR/open_bundle.hg 1509 staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \ 1510 -v $BRINGOVER_WS > $TMPDIR/incoming_open.out 1511 1512 # 1513 # If there are no incoming changesets, then incoming will 1514 # fail, and there will be no bundle file. Reset the source, 1515 # to allow the remaining logic to complete with no false 1516 # negatives. (Unlike incoming, pull will return success 1517 # for the no-change case.) 1518 # 1519 if (( $? != 0 )); then 1520 HG_SOURCE=$BRINGOVER_WS 1521 fi 1522 fi 1523 1524 staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \ 1525 > $TMPDIR/pull_open.out 2>&1 1526 if (( $? != 0 )); then 1527 printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS" 1528 cat $TMPDIR/pull_open.out 1529 if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then 1530 printf "$mergefailmsg" 1531 fi 1532 touch $TMPDIR/bringover_failed 1533 return 1534 fi 1535 1536 if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then 1537 staffer hg --cwd $CODEMGR_WS merge \ 1538 >> $TMPDIR/pull_open.out 2>&1 1539 if (( $? != 0 )); then 1540 printf "%s: merge failed as follows:\n\n" \ 1541 "$CODEMGR_WS" 1542 cat $TMPDIR/pull_open.out 1543 if grep "^merging.*failed" $TMPDIR/pull_open.out \ 1544 > /dev/null 2>&1; then 1545 printf "$mergefailmsg" 1546 fi 1547 touch $TMPDIR/bringover_failed 1548 return 1549 fi 1550 fi 1551 1552 printf "updated %s with the following results:\n" "$CODEMGR_WS" 1553 cat $TMPDIR/pull_open.out 1554 if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then 1555 printf "$mergepassmsg" 1556 fi 1557 printf "\n" 1558 1559 # 1560 # Per-changeset output is neither useful nor manageable for a 1561 # newly-created repository. 1562 # 1563 if [ -f $TMPDIR/new_repository ]; then 1564 return 1565 fi 1566 1567 printf "\nadded the following changesets to open repository:\n" 1568 cat $TMPDIR/incoming_open.out 1569 } 1570 1571 type bringover_none > /dev/null 2>&1 || function bringover_none { 1572 echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS." 1573 touch $TMPDIR/bringover_failed 1574 } 1575 1576 # 1577 # Decide whether to bringover to the codemgr workspace 1578 # 1579 if [ "$n_FLAG" = "n" ]; then 1580 PARENT_SCM_TYPE=$(parent_wstype) 1581 1582 if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then 1583 echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \ 1584 "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE 1585 exit 1 1586 fi 1587 1588 run_hook PRE_BRINGOVER 1589 1590 echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE 1591 echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file 1592 1593 eval "bringover_${PARENT_SCM_TYPE}" 2>&1 | 1594 tee -a $mail_msg_file >> $LOGFILE 1595 1596 if [ -f $TMPDIR/bringover_failed ]; then 1597 rm -f $TMPDIR/bringover_failed 1598 build_ok=n 1599 echo "trouble with bringover, quitting at `date`." | 1600 tee -a $mail_msg_file >> $LOGFILE 1601 exit 1 1602 fi 1603 1604 # 1605 # It's possible that we used the bringover above to create 1606 # $CODEMGR_WS. If so, then SCM_TYPE was previously "none," 1607 # but should now be the same as $BRINGOVER_WS. 1608 # 1609 [[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE 1610 1611 run_hook POST_BRINGOVER 1612 1613 check_closed_bins 1614 1615 else 1616 echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE 1617 fi 1618 1619 # Safeguards 1620 [[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set." 1621 [[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory." 1622 [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found." 1623 1624 if [[ "$t_FLAG" = "y" ]]; then 1625 echo "\n==== Bootstrapping cw ====\n" >> $LOGFILE 1626 ( cd ${TOOLS} 1627 set_non_debug_build_flags 1628 rm -f $TMPDIR/make-state 1629 $MAKE -K $TMPDIR/make-state -e TARGET=install cw 2>&1 >> $LOGFILE 1630 [[ "$?" -ne 0 ]] && fatal_error "Error: could not bootstrap cw" 1631 ) 1632 1633 # Switch ONBLD_TOOLS early if -t is specified so that 1634 # we could use bootstrapped cw for compiler checks. 1635 ONBLD_TOOLS=${TOOLS_PROTO}/opt/onbld 1636 export ONBLD_TOOLS 1637 fi 1638 1639 echo "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE 1640 1641 # System 1642 whence uname | tee -a $build_environ_file >> $LOGFILE 1643 uname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE 1644 echo | tee -a $build_environ_file >> $LOGFILE 1645 1646 # make 1647 whence $MAKE | tee -a $build_environ_file >> $LOGFILE 1648 $MAKE -v | tee -a $build_environ_file >> $LOGFILE 1649 echo "number of concurrent jobs = $DMAKE_MAX_JOBS" | 1650 tee -a $build_environ_file >> $LOGFILE 1651 1652 # 1653 # Report the compiler versions. 1654 # 1655 1656 if [[ ! -f $SRC/Makefile ]]; then 1657 build_ok=n 1658 echo "\nUnable to find \"Makefile\" in $SRC." | \ 1659 tee -a $build_environ_file >> $LOGFILE 1660 exit 1 1661 fi 1662 1663 ( cd $SRC 1664 for target in cc-version cc64-version java-version; do 1665 echo 1666 # 1667 # Put statefile somewhere we know we can write to rather than trip 1668 # over a read-only $srcroot. 1669 # 1670 rm -f $TMPDIR/make-state 1671 export SRC 1672 if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then 1673 continue 1674 fi 1675 touch $TMPDIR/nocompiler 1676 done 1677 echo 1678 ) | tee -a $build_environ_file >> $LOGFILE 1679 1680 if [ -f $TMPDIR/nocompiler ]; then 1681 rm -f $TMPDIR/nocompiler 1682 build_ok=n 1683 echo "Aborting due to missing compiler." | 1684 tee -a $build_environ_file >> $LOGFILE 1685 exit 1 1686 fi 1687 1688 # as 1689 whence as | tee -a $build_environ_file >> $LOGFILE 1690 as -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE 1691 echo | tee -a $build_environ_file >> $LOGFILE 1692 1693 # Check that we're running a capable link-editor 1694 whence ld | tee -a $build_environ_file >> $LOGFILE 1695 LDVER=`ld -V 2>&1` 1696 echo $LDVER | tee -a $build_environ_file >> $LOGFILE 1697 LDVER=`echo $LDVER | sed -e "s/.*-1\.\([0-9]*\).*/\1/"` 1698 if [ `expr $LDVER \< 422` -eq 1 ]; then 1699 echo "The link-editor needs to be at version 422 or higher to build" | \ 1700 tee -a $build_environ_file >> $LOGFILE 1701 echo "the latest stuff. Hope your build works." | \ 1702 tee -a $build_environ_file >> $LOGFILE 1703 fi 1704 1705 # 1706 # Build and use the workspace's tools if requested 1707 # 1708 if [[ "$t_FLAG" = "y" ]]; then 1709 set_non_debug_build_flags 1710 1711 build_tools ${TOOLS_PROTO} 1712 if (( $? != 0 )); then 1713 build_ok=n 1714 else 1715 STABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs 1716 export STABS 1717 CTFSTABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs 1718 export CTFSTABS 1719 GENOFFSETS=${TOOLS_PROTO}/opt/onbld/bin/genoffsets 1720 export GENOFFSETS 1721 1722 CTFCONVERT=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert 1723 export CTFCONVERT 1724 CTFMERGE=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge 1725 export CTFMERGE 1726 1727 PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}" 1728 PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}" 1729 export PATH 1730 1731 echo "\n==== New environment settings. ====\n" >> $LOGFILE 1732 echo "STABS=${STABS}" >> $LOGFILE 1733 echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE 1734 echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE 1735 echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE 1736 echo "PATH=${PATH}" >> $LOGFILE 1737 echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE 1738 fi 1739 fi 1740 1741 # timestamp the start of the normal build; the findunref tool uses it. 1742 touch $SRC/.build.tstamp 1743 1744 normal_build 1745 1746 ORIG_SRC=$SRC 1747 BINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z 1748 1749 1750 # 1751 # There are several checks that need to look at the proto area, but 1752 # they only need to look at one, and they don't care whether it's 1753 # DEBUG or non-DEBUG. 1754 # 1755 if [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then 1756 checkroot=$ROOT-nd 1757 else 1758 checkroot=$ROOT 1759 fi 1760 1761 if [ "$build_ok" = "y" ]; then 1762 echo "\n==== Creating protolist system file at `date` ====" \ 1763 >> $LOGFILE 1764 protolist $checkroot > $ATLOG/proto_list_${MACH} 1765 echo "==== protolist system file created at `date` ====\n" \ 1766 >> $LOGFILE 1767 1768 if [ "$N_FLAG" != "y" ]; then 1769 1770 E1= 1771 f1= 1772 for f in $f1; do 1773 if [ -f "$f" ]; then 1774 E1="$E1 -e $f" 1775 fi 1776 done 1777 1778 E2= 1779 f2= 1780 if [ -d "$SRC/pkg" ]; then 1781 f2="$f2 exceptions/packaging" 1782 fi 1783 1784 for f in $f2; do 1785 if [ -f "$f" ]; then 1786 E2="$E2 -e $f" 1787 fi 1788 done 1789 fi 1790 1791 if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then 1792 echo "\n==== Validating manifests against proto area ====\n" \ 1793 >> $mail_msg_file 1794 ( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) | \ 1795 tee $TMPDIR/protocmp_noise >> $mail_msg_file 1796 if [[ -s $TMPDIR/protocmp_noise ]]; then 1797 build_extras_ok=n 1798 fi 1799 fi 1800 1801 if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then 1802 echo "\n==== Impact on proto area ====\n" >> $mail_msg_file 1803 if [ -n "$E2" ]; then 1804 ELIST=$E2 1805 else 1806 ELIST=$E1 1807 fi 1808 $PROTOCMPTERSE \ 1809 "Files in yesterday's proto area, but not today's:" \ 1810 "Files in today's proto area, but not yesterday's:" \ 1811 "Files that changed between yesterday and today:" \ 1812 ${ELIST} \ 1813 -d $REF_PROTO_LIST \ 1814 $ATLOG/proto_list_${MACH} \ 1815 >> $mail_msg_file 1816 fi 1817 fi 1818 1819 if [[ "$u_FLAG" == "y" && "$build_ok" == "y" && \ 1820 "$build_extras_ok" == "y" ]]; then 1821 staffer cp $ATLOG/proto_list_${MACH} \ 1822 $PARENT_WS/usr/src/proto_list_${MACH} 1823 fi 1824 1825 # Update parent proto area if necessary. This is done now 1826 # so that the proto area has either DEBUG or non-DEBUG kernels. 1827 # Note that this clears out the lock file, so we can dispense with 1828 # the variable now. 1829 if [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then 1830 echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \ 1831 tee -a $LOGFILE >> $mail_msg_file 1832 rm -rf $NIGHTLY_PARENT_ROOT/* 1833 unset Ulockfile 1834 mkdir -p $NIGHTLY_PARENT_ROOT 1835 if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then 1836 ( cd $ROOT; tar cf - . | 1837 ( cd $NIGHTLY_PARENT_ROOT; umask 0; tar xpf - ) ) 2>&1 | 1838 tee -a $mail_msg_file >> $LOGFILE 1839 fi 1840 if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then 1841 rm -rf $NIGHTLY_PARENT_ROOT-nd/* 1842 mkdir -p $NIGHTLY_PARENT_ROOT-nd 1843 cd $ROOT-nd 1844 ( tar cf - . | 1845 ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 | 1846 tee -a $mail_msg_file >> $LOGFILE 1847 fi 1848 if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then 1849 echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \ 1850 tee -a $LOGFILE >> $mail_msg_file 1851 rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/* 1852 mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT 1853 if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then 1854 ( cd $TOOLS_PROTO; tar cf - . | 1855 ( cd $NIGHTLY_PARENT_TOOLS_ROOT; 1856 umask 0; tar xpf - ) ) 2>&1 | 1857 tee -a $mail_msg_file >> $LOGFILE 1858 fi 1859 fi 1860 fi 1861 1862 # 1863 # ELF verification: ABI (-A) and runtime (-r) checks 1864 # 1865 if [[ ($build_ok = y) && (($A_FLAG = y) || ($r_FLAG = y)) ]]; then 1866 # Directory ELF-data.$MACH holds the files produced by these tests. 1867 elf_ddir=$SRC/ELF-data.$MACH 1868 1869 # If there is a previous ELF-data backup directory, remove it. Then, 1870 # rotate current ELF-data directory into its place and create a new 1871 # empty directory 1872 rm -rf $elf_ddir.ref 1873 if [[ -d $elf_ddir ]]; then 1874 mv $elf_ddir $elf_ddir.ref 1875 fi 1876 mkdir -p $elf_ddir 1877 1878 # Call find_elf to produce a list of the ELF objects in the proto area. 1879 # This list is passed to check_rtime and interface_check, preventing 1880 # them from separately calling find_elf to do the same work twice. 1881 find_elf -fr $checkroot > $elf_ddir/object_list 1882 1883 if [[ $A_FLAG = y ]]; then 1884 echo "\n==== Check versioning and ABI information ====\n" | \ 1885 tee -a $LOGFILE >> $mail_msg_file 1886 1887 # Produce interface description for the proto. Report errors. 1888 interface_check -o -w $elf_ddir -f object_list \ 1889 -i interface -E interface.err 1890 if [[ -s $elf_ddir/interface.err ]]; then 1891 tee -a $LOGFILE < $elf_ddir/interface.err \ 1892 >> $mail_msg_file 1893 build_extras_ok=n 1894 fi 1895 1896 # If ELF_DATA_BASELINE_DIR is defined, compare the new interface 1897 # description file to that from the baseline gate. Issue a 1898 # warning if the baseline is not present, and keep going. 1899 if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then 1900 base_ifile="$ELF_DATA_BASELINE_DIR/interface" 1901 1902 echo "\n==== Compare versioning and ABI information" \ 1903 "to baseline ====\n" | \ 1904 tee -a $LOGFILE >> $mail_msg_file 1905 echo "Baseline: $base_ifile\n" >> $LOGFILE 1906 1907 if [[ -f $base_ifile ]]; then 1908 interface_cmp -d -o $base_ifile \ 1909 $elf_ddir/interface > $elf_ddir/interface.cmp 1910 if [[ -s $elf_ddir/interface.cmp ]]; then 1911 echo | tee -a $LOGFILE >> $mail_msg_file 1912 tee -a $LOGFILE < \ 1913 $elf_ddir/interface.cmp \ 1914 >> $mail_msg_file 1915 build_extras_ok=n 1916 fi 1917 else 1918 echo "baseline not available. comparison" \ 1919 "skipped" | \ 1920 tee -a $LOGFILE >> $mail_msg_file 1921 fi 1922 1923 fi 1924 fi 1925 1926 if [[ $r_FLAG = y ]]; then 1927 echo "\n==== Check ELF runtime attributes ====\n" | \ 1928 tee -a $LOGFILE >> $mail_msg_file 1929 1930 # If we're doing a DEBUG build the proto area will be left 1931 # with debuggable objects, thus don't assert -s. 1932 if [[ $D_FLAG = y ]]; then 1933 rtime_sflag="" 1934 else 1935 rtime_sflag="-s" 1936 fi 1937 check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \ 1938 -D object_list -f object_list -E runtime.err \ 1939 -I runtime.attr.raw 1940 if (( $? != 0 )); then 1941 build_extras_ok=n 1942 fi 1943 1944 # check_rtime -I output needs to be sorted in order to 1945 # compare it to that from previous builds. 1946 sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr 1947 rm $elf_ddir/runtime.attr.raw 1948 1949 # Report errors 1950 if [[ -s $elf_ddir/runtime.err ]]; then 1951 tee -a $LOGFILE < $elf_ddir/runtime.err \ 1952 >> $mail_msg_file 1953 build_extras_ok=n 1954 fi 1955 1956 # If there is an ELF-data directory from a previous build, 1957 # then diff the attr files. These files contain information 1958 # about dependencies, versioning, and runpaths. There is some 1959 # overlap with the ABI checking done above, but this also 1960 # flushes out non-ABI interface differences along with the 1961 # other information. 1962 echo "\n==== Diff ELF runtime attributes" \ 1963 "(since last build) ====\n" | \ 1964 tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file 1965 1966 if [[ -f $elf_ddir.ref/runtime.attr ]]; then 1967 diff $elf_ddir.ref/runtime.attr \ 1968 $elf_ddir/runtime.attr \ 1969 >> $mail_msg_file 1970 fi 1971 fi 1972 1973 # If -u set, copy contents of ELF-data.$MACH to the parent workspace. 1974 if [[ "$u_FLAG" = "y" ]]; then 1975 p_elf_ddir=$PARENT_WS/usr/src/ELF-data.$MACH 1976 1977 # If parent lacks the ELF-data.$MACH directory, create it 1978 if [[ ! -d $p_elf_ddir ]]; then 1979 staffer mkdir -p $p_elf_ddir 1980 fi 1981 1982 # These files are used asynchronously by other builds for ABI 1983 # verification, as above for the -A option. As such, we require 1984 # the file replacement to be atomic. Copy the data to a temp 1985 # file in the same filesystem and then rename into place. 1986 ( 1987 cd $elf_ddir 1988 for elf_dfile in *; do 1989 staffer cp $elf_dfile \ 1990 ${p_elf_ddir}/${elf_dfile}.new 1991 staffer mv -f ${p_elf_ddir}/${elf_dfile}.new \ 1992 ${p_elf_ddir}/${elf_dfile} 1993 done 1994 ) 1995 fi 1996 fi 1997 1998 # DEBUG lint of kernel begins 1999 2000 if [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then 2001 if [ "$LINTDIRS" = "" ]; then 2002 # LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y" 2003 LINTDIRS="$SRC y" 2004 fi 2005 set $LINTDIRS 2006 while [ $# -gt 0 ]; do 2007 dolint $1 $2; shift; shift 2008 done 2009 else 2010 echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE 2011 fi 2012 2013 # "make check" begins 2014 2015 if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then 2016 # remove old check.out 2017 rm -f $SRC/check.out 2018 2019 rm -f $SRC/check-${MACH}.out 2020 cd $SRC 2021 $MAKE -ek check ROOT="$checkroot" 2>&1 | tee -a $SRC/check-${MACH}.out \ 2022 >> $LOGFILE 2023 echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file 2024 2025 grep ":" $SRC/check-${MACH}.out | 2026 egrep -v "Ignoring unknown host" | \ 2027 sort | uniq | tee $TMPDIR/check_errors >> $mail_msg_file 2028 2029 if [[ -s $TMPDIR/check_errors ]]; then 2030 build_extras_ok=n 2031 fi 2032 else 2033 echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE 2034 fi 2035 2036 echo "\n==== Find core files ====\n" | \ 2037 tee -a $LOGFILE >> $mail_msg_file 2038 2039 find $abssrcdirs -name core -a -type f -exec file {} \; | \ 2040 tee -a $LOGFILE >> $mail_msg_file 2041 2042 if [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then 2043 echo "\n==== Diff unreferenced files (since last build) ====\n" \ 2044 | tee -a $LOGFILE >>$mail_msg_file 2045 rm -f $SRC/unref-${MACH}.ref 2046 if [ -f $SRC/unref-${MACH}.out ]; then 2047 mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref 2048 fi 2049 2050 findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \ 2051 ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \ 2052 sort > $SRC/unref-${MACH}.out 2053 2054 if [ ! -f $SRC/unref-${MACH}.ref ]; then 2055 cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref 2056 fi 2057 2058 diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file 2059 fi 2060 2061 # Verify that the usual lists of files, such as exception lists, 2062 # contain only valid references to files. If the build has failed, 2063 # then don't check the proto area. 2064 CHECK_PATHS=${CHECK_PATHS:-y} 2065 if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then 2066 echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \ 2067 >>$mail_msg_file 2068 arg=-b 2069 [ "$build_ok" = y ] && arg= 2070 checkpaths $arg $checkroot > $SRC/check-paths.out 2>&1 2071 if [[ -s $SRC/check-paths.out ]]; then 2072 tee -a $LOGFILE < $SRC/check-paths.out >> $mail_msg_file 2073 build_extras_ok=n 2074 fi 2075 fi 2076 2077 if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then 2078 echo "\n==== Impact on file permissions ====\n" \ 2079 >> $mail_msg_file 2080 2081 abspkg= 2082 for d in $abssrcdirs; do 2083 if [ -d "$d/pkg" ]; then 2084 abspkg="$abspkg $d" 2085 fi 2086 done 2087 2088 if [ -n "$abspkg" ]; then 2089 for d in "$abspkg"; do 2090 ( cd $d/pkg ; $MAKE -e pmodes ) >> $mail_msg_file 2091 done 2092 fi 2093 fi 2094 2095 if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then 2096 if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then 2097 do_wsdiff DEBUG $ROOT.prev $ROOT 2098 fi 2099 2100 if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then 2101 do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd 2102 fi 2103 fi 2104 2105 END_DATE=`date` 2106 echo "==== Nightly $maketype build completed: $END_DATE ====" | \ 2107 tee -a $LOGFILE >> $build_time_file 2108 2109 typeset -i10 hours 2110 typeset -Z2 minutes 2111 typeset -Z2 seconds 2112 2113 elapsed_time=$SECONDS 2114 ((hours = elapsed_time / 3600 )) 2115 ((minutes = elapsed_time / 60 % 60)) 2116 ((seconds = elapsed_time % 60)) 2117 2118 echo "\n==== Total build time ====" | \ 2119 tee -a $LOGFILE >> $build_time_file 2120 echo "\nreal ${hours}:${minutes}:${seconds}" | \ 2121 tee -a $LOGFILE >> $build_time_file 2122 2123 if [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then 2124 staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/ 2125 2126 # 2127 # Produce a master list of unreferenced files -- ideally, we'd 2128 # generate the master just once after all of the nightlies 2129 # have finished, but there's no simple way to know when that 2130 # will be. Instead, we assume that we're the last nightly to 2131 # finish and merge all of the unref-${MACH}.out files in 2132 # $PARENT_WS/usr/src/. If we are in fact the final ${MACH} to 2133 # finish, then this file will be the authoritative master 2134 # list. Otherwise, another ${MACH}'s nightly will eventually 2135 # overwrite ours with its own master, but in the meantime our 2136 # temporary "master" will be no worse than any older master 2137 # which was already on the parent. 2138 # 2139 2140 set -- $PARENT_WS/usr/src/unref-*.out 2141 cp "$1" ${TMPDIR}/unref.merge 2142 shift 2143 2144 for unreffile; do 2145 comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$ 2146 mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge 2147 done 2148 2149 staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out 2150 fi 2151 2152 # 2153 # All done save for the sweeping up. 2154 # (whichever exit we hit here will trigger the "cleanup" trap which 2155 # optionally sends mail on completion). 2156 # 2157 if [[ "$build_ok" == "y" ]]; then 2158 if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then 2159 exit 0 2160 fi 2161 fi 2162 2163 exit 1