6730623 nightly should create usr/closed if explicitly asked
6731128 nightly + mercurial bringover messaging could be improved

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







2149             ! -d $CODEMGR_WS/usr/closed/.hg ]]; then
2150                 staffer mkdir -p $CODEMGR_WS/usr/closed
2151                 staffer hg init $CODEMGR_WS/usr/closed
2152                 CLOSED_IS_PRESENT="yes"
2153         fi
2154 
2155         typeset -x HGMERGE="/bin/false"
2156 

2157         # Do the bringover, along with an update.  If a merge is necessary,
2158         # this will not fail properly:
2159         #     http://www.selenic.com/mercurial/bts/issue186
2160         # so we grep through the output for signs of a merge.
2161         #
2162         # Note that pulling even non-conflicting changes on top of local
2163         # changes (committed or not) requires a merge.

2164         staffer hg --cwd $CODEMGR_WS pull -u $BRINGOVER_WS 2>&1 | \
2165             tee $TMPDIR/pull_open.out
2166         hgstatus=$?
2167         if [ $hgstatus -ne 0 ]; then
2168                 touch $TMPDIR/bringover_failed
2169                 return
2170         fi
2171 
2172         # We never want to clone usr/closed by default.  If the usr/closed
2173         # repository exists already and CLOSED_BRINGOVER_WS is set, then
2174         # we update (pull -u).
2175         if [[ -d $CODEMGR_WS/usr/closed/.hg && \



2176             -n $CLOSED_BRINGOVER_WS ]]; then
2177                 staffer hg --cwd $CODEMGR_WS/usr/closed pull -u \
2178                         $CLOSED_BRINGOVER_WS 2>&1 | 
2179                         tee -a $TMPDIR/pull_closed.out
2180                 hgstatus=$?
2181                 if [ $hgstatus -ne 0 ]; then
2182                         touch $TMPDIR/bringover_failed
2183                         return
2184                 fi
2185         fi
2186 

2187         # If there were uncommitted changes, the pull -u would have
2188         # attempted a merge.  In the likely event that it failed, fail the
2189         # bringover.

2190         if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1 || \
2191                 grep "^merging.*failed" $TMPDIR/pull_closed.out >/dev/null 2>&1;
2192         then
2193                 touch $TMPDIR/bringover_failed
2194                 return
2195         fi
2196 
2197         # If heads were added, then a merge is required.  We attempt the
2198         # merge, in case the branches touch different files (something that
2199         # teamware wouldn't balk at).  If the merge fails, fail the
2200         # bringover, leaving the conflicts unresolved.
2201         #
2202         # Note that even if the merge succeeds, the result of the merge
2203         # will need to be committed, and not doing so will block any
2204         # further pulls.
2205 
2206         typeset mergefailfmt="\
2207 ***\n\
2208 *** In repository %s:\n\
2209 ***\n\
2210 *** nightly was unable to automatically merge your changes.\n\
2211 *** Run hg merge manually, then restart nightly with -n.\n\
2212 ***\n"
2213 
2214         typeset mergepassfmt="\
2215 ***\n\
2216 *** In repository %s:\n\
2217 ***\n\
2218 *** nightly successfully merged your changes.  This means that your working\n\
2219 *** directory has been updated, but those changes are not yet committed.\n\
2220 *** After nightly completes, you should validate the results of the merge,\n\
2221 *** then use hg commit manually.\n\
2222 ***\n"
2223 
2224         if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
2225                 hg --cwd $CODEMGR_WS merge 2>&1 | tee $TMPDIR/merge.out
2226                 if grep "^merging.*failed" $TMPDIR/merge.out >/dev/null 2>&1;
2227                 then
2228                         printf "$mergefailfmt" "${CODEMGR_WS}"
2229                         touch $TMPDIR/bringover_failed
2230                 else
2231                         printf "$mergepassfmt" "${CODEMGR_WS}"
2232                 fi
2233         fi
2234         if grep "not updating" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
2235                 hg --cwd $CODEMGR_WS/usr/closed merge 2>&1 | tee $TMPDIR/merge.out
2236                 if grep "^merging.*failed" $TMPDIR/merge.out >/dev/null 2>&1;
2237                 then
2238                         printf "$mergefailfmt" "${CODEMGR_WS}/usr/closed"
2239                         touch $TMPDIR/bringover_failed
2240                 else
2241                         printf "$mergepassfmt" "${CODEMGR_WS}/usr/closed"
2242                 fi
2243         fi
2244 }
2245 
2246 type bringover_subversion > /dev/null 2>&1 || bringover_subversion() {
2247         typeset -x PATH=$PATH
2248 
2249         if [[ ! -d $CODEMGR_WS/.svn ]]; then
2250                 staffer svn checkout $BRINGOVER_WS $CODEMGR_WS ||
2251                         touch $TMPDIR/bringover_failed
2252         else
2253                 typeset root
2254                 root=$(staffer svn info $CODEMGR_WS |
2255                         nawk '/^Repository Root:/ {print $NF}')
2256                 if [[ $root != $BRINGOVER_WS ]]; then
2257                         # We fail here because there's no way to update
2258                         # from a named repo.
2259                         cat <<-EOF
2260                         \$BRINGOVER_WS doesn't match repository root:
2261                           \$BRINGOVER_WS:  $BRINGOVER_WS
2262                           Repository root: $root
2263                         EOF
2264                         touch $TMPDIR/bringover_failed
2265                 else
2266                         # If a conflict happens, svn still exits 0.
2267                         staffer svn update $CODEMGR_WS | tee $TMPDIR/pull.out ||
2268                                 touch $TMPDIR/bringover_failed
2269                         if grep "^C" $TMPDIR/pull.out > /dev/null 2>&1; then
2270                                 touch $TMPDIR/bringover_failed
2271                         fi
2272                 fi
2273         fi
2274 }
2275 
2276 type bringover_none > /dev/null 2>&1 || bringover_none() {
2277         echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
2278         touch $TMPDIR/bringover_failed
2279 }
2280 
2281 # Parse the URL.
2282 # The other way to deal with empty components is to echo a string that can
2283 # be eval'ed by the caller to associate values (possibly empty) with
2284 # variables.  In that case, passing in a printf string would let the caller
2285 # choose the variable names.
2286 parse_url() {
2287         typeset url method host port path
2288 
2289         url=$1
2290         method=${url%%://*}
2291         host=${url#$method://}
2292         path=${host#*/}
2293         host=${host%%/*}
2294         if [[ $host == *:* ]]; then
2295                 port=${host#*:}
2296                 host=${host%:*}
2297         fi
2298 
2299         # method can never be empty.  host can only be empty if method is
2300         # file, and that implies it's localhost.  path can default to / if
2301         # it's otherwise empty, leaving port as the only component without
2302         # a default, so it has to go last.
2303         echo $method ${host:-localhost} ${path:-/} $port
2304 }
2305 
2306 http_get() {
2307         typeset url method host port path
2308 
2309         url=$1
2310 
2311         if [[ -n $http_proxy ]]; then
2312                 parse_url $http_proxy | read method host path port
2313                 echo "GET $url HTTP/1.0\r\n" |
2314                         mconnect -p ${port:-8080} $host
2315         else
2316                 parse_url $url | read method host path port
2317                 echo "GET $path HTTP/1.0\r\n" |
2318                         mconnect -p ${port:-80} $host
2319         fi
2320 }
2321 
2322 # Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
2323 function wstypes {
2324         typeset parent_type child_type
2325 
2326         env CODEMGR_WS=$BRINGOVER_WS $WHICH_SCM 2>/dev/null | read parent_type junk
2327         if [[ -z "$parent_type" || "$parent_type" == unknown ]]; then
2328                 # Probe BRINGOVER_WS to determine its type
2329                 if [[ $BRINGOVER_WS == svn*://* ]]; then
2330                         parent_type="subversion"
2331                 elif [[ $BRINGOVER_WS == file://* ]] &&
2332                     egrep -s "This is a Subversion repository" \
2333                     ${BRINGOVER_WS#file://}/README.txt 2> /dev/null; then
2334                         parent_type="subversion"
2335                 elif [[ $BRINGOVER_WS == ssh://* ]]; then
2336                         parent_type="mercurial"
2337                 elif svn info $BRINGOVER_WS > /dev/null 2>&1; then
2338                         parent_type="subversion"
2339                 elif [[ $BRINGOVER_WS == http://* ]] && \
2340                     http_get "$BRINGOVER_WS/?cmd=heads" | \
2341                     egrep -s "application/mercurial" 2> /dev/null; then
2342                         parent_type="mercurial"
2343                 else
2344                         parent_type="none"
2345                 fi
2346         fi
2347 
2348         # Probe CODEMGR_WS to determine its type
2349         if [[ -d $CODEMGR_WS ]]; then
2350                 $WHICH_SCM | read child_type junk || exit 1
2351         fi
2352 
2353         # fold both unsupported and unrecognized results into "none"
2354         case "$parent_type" in
2355         none|subversion|teamware|mercurial)
2356                 ;;
2357         *)      parent_type=none
2358                 ;;
2359         esac
2360         case "$child_type" in
2361         none|subversion|teamware|mercurial)
2362                 ;;
2363         *)      child_type=none
2364                 ;;
2365         esac
2366 
2367         echo $child_type $parent_type
2368 }
2369 
2370 wstypes | read SCM_TYPE PARENT_SCM_TYPE
2371 export SCM_TYPE PARENT_SCM_TYPE
2372 
2373 #
2374 #       Decide whether to bringover to the codemgr workspace
2375 #
2376 if [ "$n_FLAG" = "n" ]; then
2377 
2378         if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
2379                 echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
2380                     "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
2381                 exit 1
2382         fi
2383 
2384         run_hook PRE_BRINGOVER
2385 
2386         echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
2387         echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
2388 
2389         eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
2390                 tee -a $mail_msg_file >> $LOGFILE
2391 
2392         if [ -f $TMPDIR/bringover_failed ]; then
2393                 rm -f $TMPDIR/bringover_failed
2394                 build_ok=n
2395                 echo "trouble with bringover, quitting at `date`." |
2396                         tee -a $mail_msg_file >> $LOGFILE
2397                 exit 1
2398         fi
2399 
2400         #
2401         # It's possible that we used the bringover above to create
2402         # $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
2403         # but should now be the same as $BRINGOVER_WS.
2404         #
2405         [[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
2406 
2407         run_hook POST_BRINGOVER
2408 
2409         #
2410         # Possible transition from pre-split workspace to split
2411         # workspace.  See if the bringover changed anything.
2412         #
2413         CLOSED_IS_PRESENT="$orig_closed_is_present"
2414         check_closed_tree
2415 else
2416         echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
2417 fi
2418 
2419 echo "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
2420 
2421 # System
2422 whence uname | tee -a $build_environ_file >> $LOGFILE
2423 uname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
2424 echo | tee -a $build_environ_file >> $LOGFILE
2425 
2426 # nightly
2427 echo "$0 $@" | tee -a $build_environ_file >> $LOGFILE
2428 if [[ $nightly_path = "/opt/onbld/bin/nightly" ]] &&
2429     pkginfo SUNWonbld > /dev/null 2>&1 ; then
2430         pkginfo -l SUNWonbld | egrep "PKGINST:|VERSION:|PSTAMP:"
2431 else
2432         ls -l "$nightly_path"
2433 fi | tee -a $build_environ_file >> $LOGFILE
2434 echo | tee -a $build_environ_file >> $LOGFILE
2435 
2436 # make
2437 whence $MAKE | tee -a $build_environ_file >> $LOGFILE
2438 $MAKE -v | tee -a $build_environ_file >> $LOGFILE
2439 echo "number of concurrent jobs = $DMAKE_MAX_JOBS" |
2440     tee -a $build_environ_file >> $LOGFILE
2441 
2442 #
2443 # Report the compiler versions.
2444 #
2445 
2446 if [[ ! -f $SRC/Makefile ]]; then
2447         build_ok=n
2448         echo "\nUnable to find \"Makefile\" in $SRC." | \
2449             tee -a $build_environ_file >> $LOGFILE
2450         exit 1
2451 fi
2452 
2453 ( cd $SRC
2454   for target in cc-version cc64-version java-version; do
2455         echo
2456         #
2457         # Put statefile somewhere we know we can write to rather than trip
2458         # over a read-only $srcroot.
2459         #
2460         rm -f $TMPDIR/make-state
2461         export SRC
2462         if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
2463                 continue
2464         fi
2465         touch $TMPDIR/nocompiler
2466   done
2467   echo
2468 ) | tee -a $build_environ_file >> $LOGFILE
2469 
2470 if [ -f $TMPDIR/nocompiler ]; then
2471         rm -f $TMPDIR/nocompiler
2472         build_ok=n
2473         echo "Aborting due to missing compiler." |
2474                 tee -a $build_environ_file >> $LOGFILE
2475         exit 1
2476 fi
2477 
2478 # as
2479 whence as | tee -a $build_environ_file >> $LOGFILE
2480 as -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
2481 echo | tee -a $build_environ_file >> $LOGFILE
2482 
2483 # Check that we're running a capable link-editor
2484 whence ld | tee -a $build_environ_file >> $LOGFILE
2485 LDVER=`ld -V 2>&1`
2486 echo $LDVER | tee -a $build_environ_file >> $LOGFILE
2487 LDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
2488 if [ `expr $LDVER \< 422` -eq 1 ]; then
2489         echo "The link-editor needs to be at version 422 or higher to build" | \
2490             tee -a $build_environ_file >> $LOGFILE
2491         echo "the latest stuff.  Hope your build works." | \
2492             tee -a $build_environ_file >> $LOGFILE
2493 fi
2494 
2495 #
2496 # Build and use the workspace's tools if requested
2497 #
2498 if [[ "$t_FLAG" = "y" || "$O_FLAG" = y ]]; then
2499         set_non_debug_build_flags
2500 
2501         build_tools ${TOOLS_PROTO}
2502 
2503         if [[ $? -ne 0 && "$t_FLAG" = y ]]; then
2504                 use_tools $TOOLS_PROTO
2505                 export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
2506         fi
2507 fi
2508 
2509 #
2510 # copy ihv proto area in addition to the build itself
2511 #
2512 if [ "$X_FLAG" = "y" ]; then
2513         copy_ihv_proto
2514 fi
2515 
2516 if [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
2517         echo "\n==== NOT Building base OS-Net source ====\n" | \
2518             tee -a $LOGFILE >> $mail_msg_file
2519 else
2520         # timestamp the start of the normal build; the findunref tool uses it.
2521         touch $SRC/.build.tstamp
2522 
2523         normal_build
2524 fi
2525 
2526 #
2527 # Generate the THIRDPARTYLICENSE files if needed.  This is done before
2528 # findunref to help identify license files that need to be added to
2529 # the list.
2530 #
2531 if [ "$O_FLAG" = y -a "$build_ok" = y ]; then
2532         echo "\n==== Generating THIRDPARTYLICENSE files ====\n" | \
2533             tee -a $mail_msg_file >> $LOGFILE
2534 
2535         mktpl usr/src/tools/opensolaris/license-list >>$LOGFILE 2>&1
2536         if (( $? != 0 )) ; then
2537                 echo "Couldn't create THIRDPARTYLICENSE files" |
2538                     tee -a $mail_msg_file >> $LOGFILE
2539         fi
2540 fi
2541 
2542 #
2543 # If OpenSolaris deliverables were requested, do the open-only build
2544 # now, so that it happens at roughly the same point as the source
2545 # product builds.  This lets us take advantage of checks that come
2546 # later (e.g., the core file check).
2547 #
2548 if [ "$O_FLAG" = y -a "$build_ok" = y ]; then
2549         #
2550         # Generate skeleton (minimal) closed binaries for open-only
2551         # build.  There's no need to distinguish debug from non-debug
2552         # binaries, but it simplifies file management to have separate
2553         # trees.
2554         #
2555 
2556         echo "\n==== Generating skeleton closed binaries for" \
2557             "open-only build ====\n" | \
2558             tee -a $LOGFILE >> $mail_msg_file
2559 
2560         rm -rf $CODEMGR_WS/closed.skel
2561         if [ "$D_FLAG" = y ]; then
2562                 mkclosed $MACH $ROOT $CODEMGR_WS/closed.skel/root_$MACH \
2563                     >>$LOGFILE 2>&1
2564                 if (( $? != 0 )) ; then
2565                         echo "Couldn't create skeleton DEBUG closed binaries." |
2566                             tee -a $mail_msg_file >> $LOGFILE
2567                 fi
2568         fi
2569         if [ "$F_FLAG" = n ]; then
2570                 mkclosed $MACH $ROOT-nd $CODEMGR_WS/closed.skel/root_$MACH-nd \
2571                     >>$LOGFILE 2>&1
2572                 if (( $? != 0 )) ; then
2573                         echo "Couldn't create skeleton non-DEBUG closed binaries." |
2574                             tee -a $mail_msg_file >> $LOGFILE
2575                 fi
2576         fi
2577 
2578         ORIG_CLOSED_IS_PRESENT=$CLOSED_IS_PRESENT
2579         export CLOSED_IS_PRESENT=no
2580 
2581         ORIG_ON_CLOSED_BINS="$ON_CLOSED_BINS"
2582         export ON_CLOSED_BINS=$CODEMGR_WS/closed.skel
2583 
2584         normal_build -O
2585 
2586         ON_CLOSED_BINS=$ORIG_ON_CLOSED_BINS
2587         CLOSED_IS_PRESENT=$ORIG_CLOSED_IS_PRESENT
2588 fi
2589 
2590 ORIG_SRC=$SRC
2591 BINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
2592 
2593 if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
2594         save_binaries
2595 fi
2596 
2597 
2598 # EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
2599 # $SRC pointing to the export_source usr/src.
2600 
2601 if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
2602         if [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
2603             set_up_source_build ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
2604         fi
2605 
2606         if [ $build_ok = y ]; then
2607             set_up_source_build ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
2608         fi
2609 fi
2610 
2611 if [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
2612         # drop the crypt files in place.
2613         cd ${EXPORT_SRC}
2614         echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
2615             >> ${LOGFILE}
2616         zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
2617             cpio -idmucvB 2>/dev/null >> ${LOGFILE}
2618         if [ "$?" = "0" ]; then
2619                 echo "\n==== DOMESTIC extraction succeeded ====\n" \
2620                     >> $mail_msg_file
2621         else
2622                 echo "\n==== DOMESTIC extraction failed ====\n" \
2623                     >> $mail_msg_file
2624         fi
2625 
2626 fi
2627 
2628 if [ "$SO_FLAG" = "y" -a $build_ok = y ]; then
2629         #
2630         # Copy the open sources into their own tree, set up the closed
2631         # binaries, and set up the environment.  The build looks for
2632         # the closed binaries in a location that depends on whether
2633         # it's a DEBUG build, so we might need to make two copies.
2634         #
2635         # If copy_source fails, it will have already generated an
2636         # error message and set build_ok=n, so we don't need to worry
2637         # about that here.
2638         #
2639         copy_source $CODEMGR_WS $OPEN_SRCDIR OPEN_SOURCE usr/src
2640 fi
2641 
2642 if [ "$SO_FLAG" = "y" -a $build_ok = y ]; then
2643         SRC=$OPEN_SRCDIR/usr/src
2644 
2645         # Try not to clobber any user-provided closed binaries.
2646         export ON_CLOSED_BINS=$CODEMGR_WS/closed$$
2647 
2648         echo "\n==== Copying skeleton closed binaries to" \
2649             "$ON_CLOSED_BINS ====\n" | \
2650             tee -a $mail_msg_file >> $LOGFILE
2651 
2652         if [ "$D_FLAG" = y ]; then
2653                 mkclosed $MACH $ROOT $ON_CLOSED_BINS/root_$MACH >>$LOGFILE 2>&1
2654                 if (( $? != 0 )) ; then
2655                         build_ok=n
2656                         echo "Couldn't create DEBUG closed binaries." |
2657                             tee -a $mail_msg_file >> $LOGFILE
2658                 fi
2659         fi
2660         if [ "$F_FLAG" = n ]; then
2661                 root=$ROOT
2662                 [ "$MULTI_PROTO" = yes ] && root=$ROOT-nd
2663                 mkclosed $MACH $root $ON_CLOSED_BINS/root_$MACH-nd \
2664                     >>$LOGFILE 2>&1
2665                 if (( $? != 0 )) ; then
2666                         build_ok=n
2667                         echo "Couldn't create non-DEBUG closed binaries." |
2668                             tee -a $mail_msg_file >> $LOGFILE
2669                 fi
2670         fi
2671 
2672         export CLOSED_IS_PRESENT=no
2673 fi
2674 
2675 if is_source_build && [ $build_ok = y ] ; then
2676         # remove proto area(s) here, since we don't clobber
2677         rm -rf `allprotos`
2678         if [ "$t_FLAG" = "y" ]; then
2679                 set_non_debug_build_flags
2680                 ORIG_TOOLS=$TOOLS
2681                 #
2682                 # SRC was set earlier to point to the source build
2683                 # source tree (e.g., $EXPORT_SRC).
2684                 #
2685                 TOOLS=${SRC}/tools
2686                 build_tools ${SRC}/tools/proto
2687                 TOOLS=$ORIG_TOOLS
2688         fi
2689 
2690         export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
2691         normal_build
2692 fi
2693 
2694 if [[ "$SO_FLAG" = "y" && "$build_ok" = "y" ]]; then
2695         rm -rf $ON_CLOSED_BINS
2696 fi
2697 
2698 #
2699 # There are several checks that need to look at the proto area, but
2700 # they only need to look at one, and they don't care whether it's
2701 # DEBUG or non-DEBUG.
2702 #
2703 if [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
2704         checkroot=$ROOT-nd
2705 else
2706         checkroot=$ROOT
2707 fi
2708 
2709 if [ "$build_ok" = "y" ]; then
2710         echo "\n==== Creating protolist system file at `date` ====" \
2711                 >> $LOGFILE
2712         protolist $checkroot > $ATLOG/proto_list_${MACH}
2713         echo "==== protolist system file created at `date` ====\n" \
2714                 >> $LOGFILE
2715 
2716         if [ "$N_FLAG" != "y" ]; then
2717                 echo "\n==== Impact on packages ====\n" >> $mail_msg_file
2718 
2719                 # If there is a reference proto list, compare the build's proto
2720                 # list with the reference to see changes in proto areas.
2721                 # Use the current exception list.
2722                 exc=etc/exception_list_$MACH
2723                 if [ -f $SRC/pkgdefs/$exc ]; then
2724                         ELIST="-e $SRC/pkgdefs/$exc"
2725                 fi
2726                 if [ "$X_FLAG" = "y" -a -f $IA32_IHV_WS/usr/src/pkgdefs/$exc ]; then
2727                         ELIST="$ELIST -e $IA32_IHV_WS/usr/src/pkgdefs/$exc"
2728                 fi
2729 
2730                 if [ -f "$REF_PROTO_LIST" ]; then
2731                         # For builds that copy the IHV proto area (-X), add the
2732                         # IHV proto list to the reference list if the reference
2733                         # was built without -X.
2734                         #
2735                         # For builds that don't copy the IHV proto area, add the
2736                         # IHV proto list to the build's proto list if the
2737                         # reference was built with -X.
2738                         #
2739                         # Use the presence of the first file entry of the cached
2740                         # IHV proto list in the reference list to determine
2741                         # whether it was build with -X or not.
2742                         IHV_REF_PROTO_LIST=$SRC/pkgdefs/etc/proto_list_ihv_$MACH
2743                         grepfor=$(nawk '$1 == "f" { print $2; exit }' \
2744                                 $IHV_REF_PROTO_LIST 2> /dev/null)
2745                         if [ $? = 0 -a -n "$grepfor" ]; then
2746                                 if [ "$X_FLAG" = "y" ]; then
2747                                         grep -w "$grepfor" \
2748                                                 $REF_PROTO_LIST > /dev/null
2749                                         if [ ! "$?" = "0" ]; then
2750                                                 REF_IHV_PROTO="-d $IHV_REF_PROTO_LIST"
2751                                         fi
2752                                 else
2753                                         grep -w "$grepfor" \
2754                                                 $REF_PROTO_LIST > /dev/null
2755                                         if [ "$?" = "0" ]; then
2756                                                 IHV_PROTO_LIST="$IHV_REF_PROTO_LIST"
2757                                         fi
2758                                 fi
2759                         fi
2760 
2761                         $PROTOCMPTERSE \
2762                           "Files in yesterday's proto area, but not today's:" \
2763                           "Files in today's proto area, but not yesterday's:" \
2764                           "Files that changed between yesterday and today:" \
2765                           ${ELIST} \
2766                           -d $REF_PROTO_LIST \
2767                           $REF_IHV_PROTO \
2768                           $ATLOG/proto_list_${MACH} \
2769                           $IHV_PROTO_LIST \
2770                                 >> $mail_msg_file
2771                 fi
2772                 # Compare the build's proto list with current package
2773                 # definitions to audit the quality of package definitions
2774                 # and makefile install targets. Use the current exception list.
2775                 PKGDEFS_LIST=""
2776                 for d in $abssrcdirs; do
2777                         if [ -d $d/pkgdefs ]; then
2778                                 PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
2779                         fi
2780                 done
2781                 if [ "$X_FLAG" = "y" -a -d $IA32_IHV_WS/usr/src/pkgdefs ]; then
2782                         PKGDEFS_LIST="$PKGDEFS_LIST -d $IA32_IHV_WS/usr/src/pkgdefs"
2783                 fi
2784 
2785                 $PROTOCMPTERSE \
2786                     "Files missing from the proto area:" \
2787                     "Files missing from packages:" \
2788                     "Inconsistencies between pkgdefs and proto area:" \
2789                     ${ELIST} \
2790                     ${PKGDEFS_LIST} \
2791                     $ATLOG/proto_list_${MACH} \
2792                     >> $mail_msg_file
2793         fi
2794 fi
2795 
2796 if [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
2797         staffer cp $ATLOG/proto_list_${MACH} \
2798                 $PARENT_WS/usr/src/proto_list_${MACH}
2799 fi
2800 
2801 # Update parent proto area if necessary. This is done now
2802 # so that the proto area has either DEBUG or non-DEBUG kernels.
2803 # Note that this clears out the lock file, so we can dispense with
2804 # the variable now.
2805 if [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
2806         echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
2807             tee -a $LOGFILE >> $mail_msg_file
2808         # The rm -rf command below produces predictable errors if
2809         # nightly is invoked from the parent's $ROOT/opt/onbld/bin,
2810         # and that directory is accessed via NFS.  This is because
2811         # deleted-but-still-open files don't actually disappear as
2812         # expected, but rather turn into .nfsXXXX junk files, leaving
2813         # the directory non-empty.  Since this is a not-unusual usage
2814         # pattern, and we still want to catch other errors here, we
2815         # take the unusal step of moving aside 'nightly' from that
2816         # directory (if we're using it).
2817         mypath=${nightly_path##*/root_$MACH/}
2818         if [ "$mypath" = $nightly_path ]; then
2819                 mypath=opt/onbld/bin/${nightly_path##*/}
2820         fi
2821         if [ $nightly_path -ef $PARENT_WS/proto/root_$MACH/$mypath ]; then
2822                 mv -f $nightly_path $PARENT_WS/proto/root_$MACH
2823         fi
2824         rm -rf $PARENT_WS/proto/root_$MACH/*
2825         unset Ulockfile
2826         mkdir -p $NIGHTLY_PARENT_ROOT
2827         if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2828                 cd $ROOT
2829                 ( tar cf - . |
2830                     ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
2831                     tee -a $mail_msg_file >> $LOGFILE
2832         fi
2833         if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
2834                 mkdir -p $NIGHTLY_PARENT_ROOT-nd
2835                 cd $ROOT-nd
2836                 ( tar cf - . |
2837                     ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
2838                     tee -a $mail_msg_file >> $LOGFILE
2839         fi
2840 fi
2841 
2842 #
2843 # do shared library interface verification
2844 #
2845 
2846 if [ "$A_FLAG" = "y" -a "$build_ok" = "y" ]; then
2847         echo "\n==== Check versioning and ABI information ====\n"  | \
2848             tee -a $LOGFILE >> $mail_msg_file
2849 
2850         rm -rf $SRC/interfaces.ref
2851         if [ -d $SRC/interfaces.out ]; then
2852                 mv $SRC/interfaces.out $SRC/interfaces.ref
2853         fi
2854         rm -rf $SRC/interfaces.out
2855         mkdir -p $SRC/interfaces.out
2856 
2857         intf_check -V -m -o -b $SRC/tools/abi/etc \
2858                 -d $SRC/interfaces.out $checkroot 2>&1 | sort \
2859                 > $SRC/interfaces.out/log
2860 
2861         # report any ERROR found in log file
2862         fgrep 'ERROR' $SRC/interfaces.out/log | sed 's/^ERROR: //' | \
2863                 tee -a $LOGFILE >> $mail_msg_file
2864 
2865         if [ ! -d $SRC/interfaces.ref ] ; then
2866                 mkdir -p $SRC/interfaces.ref
2867                 if [ -d  $SRC/interfaces.out ]; then
2868                         cp -r $SRC/interfaces.out/* $SRC/interfaces.ref
2869                 fi
2870         fi
2871 
2872         echo "\n==== Diff versioning warnings (since last build) ====\n" | \
2873             tee -a $LOGFILE >> $mail_msg_file
2874 
2875         out_vers=`grep ^VERSION $SRC/interfaces.out/log`;
2876         ref_vers=`grep ^VERSION $SRC/interfaces.ref/log`;
2877 
2878         # Report any differences in WARNING messages between last
2879         # and current build.
2880         if [ "$out_vers" = "$ref_vers" ]; then
2881                 diff $SRC/interfaces.ref/log $SRC/interfaces.out/log | \
2882                     fgrep 'WARNING' | sed 's/WARNING: //' | \
2883                     tee -a $LOGFILE >> $mail_msg_file
2884         fi
2885 fi
2886 
2887 if [ "$r_FLAG" = "y" -a "$build_ok" = "y" ]; then
2888         echo "\n==== Check ELF runtime attributes ====\n" | \
2889             tee -a $LOGFILE >> $mail_msg_file
2890 
2891         LDDUSAGE="^ldd: does not support -e"
2892         LDDWRONG="wrong class"
2893         CRLERROR="^crle:"
2894         CRLECONF="^crle: configuration file:"
2895 
2896         RUNTIMEREF=$SRC/runtime-${MACH}.ref
2897         RUNTIMEOUT=$SRC/runtime-${MACH}.out
2898 
2899         rm -f $RUNTIMEREF
2900         if [ -f $RUNTIMEOUT ]; then
2901                 egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2902                         $RUNTIMEOUT > $RUNTIMEREF
2903         fi
2904 
2905         # If we're doing a debug build the proto area will be left with
2906         # debuggable objects, thus don't assert -s.
2907         if [ "$D_FLAG" = "y" ]; then
2908                 rtime_sflag=""
2909         else
2910                 rtime_sflag="-s"
2911         fi
2912         check_rtime -d $checkroot -i -m -o $rtime_sflag $checkroot 2>&1 | \
2913             egrep -v ": unreferenced object=$checkroot/.*/lib(w|intl|thread|pthread).so" | \
2914             egrep -v ": unused object=$checkroot/.*/lib(w|intl|thread|pthread).so" | \
2915             sort > $RUNTIMEOUT
2916 
2917         # Determine any processing errors that will affect the final output
2918         # and display these first.
2919         grep -l "$LDDUSAGE" $RUNTIMEOUT > /dev/null
2920         if (( $? == 0 )) ; then
2921             echo "WARNING: ldd(1) does not support -e.  The version of ldd(1)" | \
2922                 tee -a $LOGFILE >> $mail_msg_file
2923             echo "on your system is old - 4390308 (s81_30) is required.\n" | \
2924                 tee -a $LOGFILE >> $mail_msg_file
2925         fi
2926         grep -l "$LDDWRONG" $RUNTIMEOUT > /dev/null
2927         if (( $? == 0 )) ; then
2928             echo "WARNING: wrong class message detected.  ldd(1) was unable" | \
2929                 tee -a $LOGFILE >> $mail_msg_file
2930             echo "to execute an object, thus it could not be checked fully." | \
2931                 tee -a $LOGFILE >> $mail_msg_file
2932             echo "Perhaps a 64-bit object was encountered on a 32-bit system," | \
2933                 tee -a $LOGFILE >> $mail_msg_file
2934             echo "or an i386 object was encountered on a sparc system?\n" | \
2935                 tee -a $LOGFILE >> $mail_msg_file
2936         fi
2937         grep -l "$CRLECONF" $RUNTIMEOUT > /dev/null
2938         if (( $? == 0 )) ; then
2939             echo "WARNING: creation of an alternative dependency cache failed." | \
2940                 tee -a $LOGFILE >> $mail_msg_file
2941             echo "Dependencies will bind to the base system libraries.\n" | \
2942                 tee -a $LOGFILE >> $mail_msg_file
2943             grep "$CRLECONF" $RUNTIMEOUT | \
2944                 tee -a $LOGFILE >> $mail_msg_file
2945             grep "$CRLERROR" $RUNTIMEOUT | grep -v "$CRLECONF" | \
2946                 tee -a $LOGFILE >> $mail_msg_file
2947             echo "\n" | tee -a $LOGFILE >> $mail_msg_file
2948         fi
2949 
2950         egrep '<dependency no longer necessary>' $RUNTIMEOUT | \
2951             tee -a $LOGFILE >> $mail_msg_file
2952 
2953         # NEEDED= and RPATH= are informational; report anything else that we
2954         # haven't already.
2955         egrep -v "NEEDED=|RPATH=|$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2956             $RUNTIMEOUT | tee -a $LOGFILE >> $mail_msg_file
2957 
2958         # probably should compare against a 'known ok runpaths' list
2959         if [ ! -f $RUNTIMEREF ]; then
2960                 egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2961                         $RUNTIMEOUT >  $RUNTIMEREF
2962         fi
2963 
2964         echo "\n==== Diff ELF runtime attributes (since last build) ====\n" \
2965             >> $mail_msg_file
2966 
2967         egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" $RUNTIMEOUT | \
2968             diff $RUNTIMEREF - >> $mail_msg_file
2969 fi
2970 
2971 # DEBUG lint of kernel begins
2972 
2973 if [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
2974         if [ "$LINTDIRS" = "" ]; then
2975                 # LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
2976                 LINTDIRS="$SRC y"
2977         fi
2978         set $LINTDIRS
2979         while [ $# -gt 0 ]; do
2980                 dolint $1 $2; shift; shift
2981         done
2982 else
2983         echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
2984 fi
2985 
2986 # "make check" begins
2987 
2988 if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
2989         # remove old check.out
2990         rm -f $SRC/check.out
2991 
2992         rm -f $SRC/check-${MACH}.out
2993         cd $SRC
2994         $MAKE -ek check 2>&1 | tee -a $SRC/check-${MACH}.out >> $LOGFILE
2995         echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
2996 
2997         grep ":" $SRC/check-${MACH}.out |
2998                 egrep -v "Ignoring unknown host" | \
2999                 sort | uniq >> $mail_msg_file
3000 else
3001         echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
3002 fi
3003 
3004 echo "\n==== Find core files ====\n" | \
3005     tee -a $LOGFILE >> $mail_msg_file
3006 
3007 find $abssrcdirs -name core -a -type f -exec file {} \; | \
3008         tee -a $LOGFILE >> $mail_msg_file
3009 
3010 if [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
3011         echo "\n==== Diff unreferenced files (since last build) ====\n" \
3012             | tee -a $LOGFILE >>$mail_msg_file
3013         rm -f $SRC/unref-${MACH}.ref
3014         if [ -f $SRC/unref-${MACH}.out ]; then
3015                 mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
3016         fi
3017 
3018         #
3019         # For any SCM other than teamware, we want to disable the
3020         # managed-by-SCCS test in findunref
3021         #
3022         findunref_all=""
3023         if [ "$SCM_TYPE" != teamware ]; then
3024                 findunref_all="-a"
3025         fi
3026  
3027         findunref $findunref_all -t $SRC/.build.tstamp $SRC/.. \
3028             ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
3029             sort | sed -e s=^./src/=./= -e s=^./closed/=../closed/= \
3030             > $SRC/unref-${MACH}.out
3031 
3032         if [ ! -f $SRC/unref-${MACH}.ref ]; then
3033                 cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
3034         fi
3035 
3036         diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
3037 fi
3038 
3039 #
3040 # Generate the OpenSolaris deliverables if requested.  Some of these
3041 # steps need to come after findunref and are commented below.
3042 #
3043 if [ "$O_FLAG" = y -a "$build_ok" = y ]; then
3044         echo "\n==== Generating OpenSolaris tarballs ====\n" | \
3045             tee -a $mail_msg_file >> $LOGFILE
3046 
3047         cd $CODEMGR_WS
3048 
3049         #
3050         # This step grovels through the pkgdefs proto* files, so it
3051         # must come after findunref.
3052         #
3053         echo "Generating closed binaries tarball(s)..." >> $LOGFILE
3054         closed_basename=on-closed-bins
3055         if [ "$D_FLAG" = y ]; then
3056                 bindrop "$ROOT" "$ROOT-open" "$closed_basename" \
3057                     >>"$LOGFILE" 2>&1
3058                 if (( $? != 0 )) ; then
3059                         echo "Couldn't create DEBUG closed binaries." |
3060                             tee -a $mail_msg_file >> $LOGFILE
3061                 fi
3062         fi
3063         if [ "$F_FLAG" = n ]; then
3064                 bindrop -n "$ROOT-nd" "$ROOT-open-nd" "$closed_basename-nd" \
3065                     >>"$LOGFILE" 2>&1
3066                 if (( $? != 0 )) ; then
3067                         echo "Couldn't create non-DEBUG closed binaries." |
3068                             tee -a $mail_msg_file >> $LOGFILE
3069                 fi
3070         fi
3071 
3072         echo "Generating SUNWonbld tarball..." >> $LOGFILE
3073         PKGARCHIVE=$PKGARCHIVE_ORIG
3074         onblddrop >> $LOGFILE 2>&1
3075         if (( $? != 0 )) ; then
3076                 echo "Couldn't create SUNWonbld tarball." |
3077                     tee -a $mail_msg_file >> $LOGFILE
3078         fi
3079 
3080         echo "Generating README.opensolaris..." >> $LOGFILE
3081         cat $SRC/tools/opensolaris/README.opensolaris.tmpl | \
3082             mkreadme_osol $CODEMGR_WS/README.opensolaris >> $LOGFILE 2>&1
3083         if (( $? != 0 )) ; then
3084                 echo "Couldn't create README.opensolaris." |
3085                     tee -a $mail_msg_file >> $LOGFILE
3086         fi
3087 
3088         # This step walks the source tree, so it must come after
3089         # findunref.  It depends on README.opensolaris.
3090         echo "Generating source tarball..." >> $LOGFILE
3091         sdrop >>$LOGFILE 2>&1
3092         if (( $? != 0 )) ; then
3093                 echo "Couldn't create source tarball." |
3094                     tee -a "$mail_msg_file" >> "$LOGFILE"
3095         fi
3096 
3097         # This step depends on the closed binaries tarballs.
3098         echo "Generating BFU tarball(s)..." >> $LOGFILE
3099         if [ "$D_FLAG" = y ]; then
3100                 makebfu_filt bfudrop "$ROOT-open" \
3101                     "$closed_basename.$MACH.tar.bz2" nightly-osol
3102                 if (( $? != 0 )) ; then
3103                         echo "Couldn't create DEBUG archives tarball." |
3104                             tee -a $mail_msg_file >> $LOGFILE
3105                 fi
3106         fi
3107         if [ "$F_FLAG" = n ]; then
3108                 makebfu_filt bfudrop -n "$ROOT-open-nd" \
3109                     "$closed_basename-nd.$MACH.tar.bz2" nightly-osol-nd
3110                 if (( $? != 0 )) ; then
3111                         echo "Couldn't create non-DEBUG archives tarball." |
3112                             tee -a $mail_msg_file >> $LOGFILE
3113                 fi
3114         fi
3115 fi
3116 
3117 # Verify that the usual lists of files, such as exception lists,
3118 # contain only valid references to files.  If the build has failed,
3119 # then don't check the proto area.
3120 CHECK_PATHS=${CHECK_PATHS:-y}
3121 if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
3122         echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
3123                 >>$mail_msg_file
3124         arg=-b
3125         [ "$build_ok" = y ] && arg=
3126         checkpaths $arg $checkroot 2>&1 | tee -a $LOGFILE >>$mail_msg_file
3127 fi
3128 
3129 if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
3130         echo "\n==== Impact on file permissions ====\n" \
3131                 >> $mail_msg_file
3132         #
3133         # Get pkginfo files from usr/src/pkgdefs
3134         #
3135         pmodes -qvdP \
3136         `for d in $abssrcdirs; do
3137                 if [ -d "$d/pkgdefs" ]
3138                 then
3139                         find $d/pkgdefs -name pkginfo.tmpl -print -o -name .del\* -prune
3140                 fi
3141          done | sed -e 's:/pkginfo.tmpl$::' | sort -u ` >> $mail_msg_file
3142 fi
3143 
3144 if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
3145         if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
3146                 do_wsdiff DEBUG $ROOT.prev $ROOT
3147         fi
3148 
3149         if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
3150                 do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
3151         fi
3152 fi
3153 
3154 END_DATE=`date`
3155 echo "==== Nightly $maketype build completed: $END_DATE ====" | \
3156     tee -a $LOGFILE >> $build_time_file
3157 
3158 typeset -Z2 minutes
3159 typeset -Z2 seconds
3160 
3161 elapsed_time=$SECONDS
3162 ((hours = elapsed_time / 3600 ))
3163 ((minutes = elapsed_time / 60  % 60))
3164 ((seconds = elapsed_time % 60))
3165 
3166 echo "\n==== Total build time ====" | \
3167     tee -a $LOGFILE >> $build_time_file
3168 echo "\nreal    ${hours}:${minutes}:${seconds}" | \
3169     tee -a $LOGFILE >> $build_time_file
3170 
3171 if [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
3172         staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
3173 
3174         #
3175         # Produce a master list of unreferenced files -- ideally, we'd
3176         # generate the master just once after all of the nightlies
3177         # have finished, but there's no simple way to know when that
3178         # will be.  Instead, we assume that we're the last nightly to
3179         # finish and merge all of the unref-${MACH}.out files in
3180         # $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
3181         # finish, then this file will be the authoritative master
3182         # list.  Otherwise, another ${MACH}'s nightly will eventually
3183         # overwrite ours with its own master, but in the meantime our
3184         # temporary "master" will be no worse than any older master
3185         # which was already on the parent.
3186         #
3187 
3188         set -- $PARENT_WS/usr/src/unref-*.out
3189         cp "$1" ${TMPDIR}/unref.merge
3190         shift
3191 
3192         for unreffile; do
3193                 comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
3194                 mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
3195         done
3196 
3197         staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
3198 fi
3199 
3200 #
3201 # All done save for the sweeping up.
3202 # (whichever exit we hit here will trigger the "cleanup" trap which
3203 # optionally sends mail on completion).
3204 #
3205 if [ "$build_ok" = "y" ]; then
3206         exit 0
3207 fi
3208 exit 1
--- EOF ---