4028 remove CLOSED_IS_PRESENT

   1 #!/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  25 # Copyright 2008, 2010, Richard Lowe
  26 # Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  27 # Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
  28 #
  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 # OPTHOME and TEAMWARE may be set in the environment to override /opt
  50 # and /opt/teamware defaults.
  51 #
  52 
  53 #
  54 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
  55 # under certain circumstances, which can really screw things up; unset it.
  56 #
  57 unset CDPATH
  58 
  59 # Get the absolute path of the nightly script that the user invoked.  This
  60 # may be a relative path, and we need to do this before changing directory.
  61 nightly_path=`whence $0`
  62 
  63 #
  64 # Keep track of where we found nightly so we can invoke the matching
  65 # which_scm script.  If that doesn't work, don't go guessing, just rely
  66 # on the $PATH settings, which will generally give us either /opt/onbld
  67 # or the user's workspace.
  68 #
  69 WHICH_SCM=$(dirname $nightly_path)/which_scm
  70 if [[ ! -x $WHICH_SCM ]]; then
  71         WHICH_SCM=which_scm
  72 fi
  73 
  74 function fatal_error
  75 {
  76         print -u2 "nightly: $*"
  77         exit 1
  78 }
  79 
  80 #
  81 # Function to do a DEBUG and non-DEBUG build. Needed because we might
  82 # need to do another for the source build, and since we only deliver DEBUG or
  83 # non-DEBUG packages.
  84 #
  85 # usage: normal_build
  86 #
  87 function normal_build {
  88 
  89         typeset orig_p_FLAG="$p_FLAG"
  90         typeset crypto_signer="$CODESIGN_USER"
  91 
  92         suffix=""
  93 
  94         # non-DEBUG build begins
  95 
  96         if [ "$F_FLAG" = "n" ]; then
  97                 set_non_debug_build_flags
  98                 CODESIGN_USER="$crypto_signer" \
  99                     build "non-DEBUG" "$suffix-nd" "-nd" "$MULTI_PROTO"
 100                 if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
 101                     "$p_FLAG" = "y" ]; then
 102                         copy_ihv_pkgs non-DEBUG -nd
 103                 fi
 104         else
 105                 echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
 106         fi
 107 
 108         # non-DEBUG build ends
 109 
 110         # DEBUG build begins
 111 
 112         if [ "$D_FLAG" = "y" ]; then
 113                 set_debug_build_flags
 114                 CODESIGN_USER="$crypto_signer" \
 115                     build "DEBUG" "$suffix" "" "$MULTI_PROTO"
 116                 if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
 117                     "$p_FLAG" = "y" ]; then
 118                         copy_ihv_pkgs DEBUG ""
 119                 fi
 120         else
 121                 echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
 122         fi
 123 
 124         # DEBUG build ends
 125 
 126         p_FLAG="$orig_p_FLAG"
 127 }
 128 
 129 #
 130 # usage: run_hook HOOKNAME ARGS...
 131 #
 132 # If variable "$HOOKNAME" is defined, insert a section header into 
 133 # our logs and then run the command with ARGS
 134 #
 135 function run_hook {
 136         HOOKNAME=$1
 137         eval HOOKCMD=\$$HOOKNAME
 138         shift
 139 
 140         if [ -n "$HOOKCMD" ]; then 
 141                 (
 142                         echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
 143                         ( $HOOKCMD "$@" 2>&1 )
 144                         if [ "$?" -ne 0 ]; then
 145                                 # Let exit status propagate up
 146                                 touch $TMPDIR/abort
 147                         fi
 148                 ) | tee -a $mail_msg_file >> $LOGFILE
 149 
 150                 if [ -f $TMPDIR/abort ]; then
 151                         build_ok=n
 152                         echo "\nAborting at request of $HOOKNAME" |
 153                                 tee -a $mail_msg_file >> $LOGFILE
 154                         exit 1
 155                 fi
 156         fi
 157 }
 158 
 159 #
 160 # usage: filelist DESTDIR PATTERN
 161 #
 162 function filelist {
 163         DEST=$1
 164         PATTERN=$2
 165         cd ${DEST}
 166 }
 167 
 168 # function to save off binaries after a full build for later
 169 # restoration
 170 function save_binaries {
 171         # save off list of binaries
 172         echo "\n==== Saving binaries from build at `date` ====\n" | \
 173             tee -a $mail_msg_file >> $LOGFILE
 174         rm -f ${BINARCHIVE}
 175         cd ${CODEMGR_WS}
 176         filelist ${CODEMGR_WS} '^preserve:' >> $LOGFILE
 177         filelist ${CODEMGR_WS} '^preserve:' | \
 178             cpio -ocB 2>/dev/null | compress \
 179             > ${BINARCHIVE}
 180 }
 181 
 182 # delete files
 183 # usage: hybridize_files DESTDIR MAKE_TARGET
 184 function hybridize_files {
 185         DEST=$1
 186         MAKETARG=$2
 187 
 188         echo "\n==== Hybridizing files at `date` ====\n" | \
 189             tee -a $mail_msg_file >> $LOGFILE
 190         for i in `filelist ${DEST} '^delete:'`
 191         do
 192                 echo "removing ${i}." | tee -a $mail_msg_file >> $LOGFILE
 193                 rm -rf "${i}"
 194         done
 195         for i in `filelist ${DEST} '^hybridize:' `
 196         do
 197                 echo "hybridizing ${i}." | tee -a $mail_msg_file >> $LOGFILE
 198                 rm -f ${i}+
 199                 sed -e "/^# HYBRID DELETE START/,/^# HYBRID DELETE END/d" \
 200                     < ${i} > ${i}+
 201                 mv ${i}+ ${i}
 202         done
 203 }
 204 
 205 # restore binaries into the proper source tree.
 206 # usage: restore_binaries DESTDIR MAKE_TARGET
 207 function restore_binaries {
 208         DEST=$1
 209         MAKETARG=$2
 210 
 211         echo "\n==== Restoring binaries to ${MAKETARG} at `date` ====\n" | \
 212             tee -a $mail_msg_file >> $LOGFILE
 213         cd ${DEST}
 214         zcat ${BINARCHIVE} | \
 215             cpio -idmucvB 2>/dev/null | tee -a $mail_msg_file >> ${LOGFILE}
 216 }
 217 
 218 # rename files we save binaries of
 219 # usage: rename_files DESTDIR MAKE_TARGET
 220 function rename_files {
 221         DEST=$1
 222         MAKETARG=$2
 223         echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
 224             tee -a $mail_msg_file >> $LOGFILE
 225         for i in `filelist ${DEST} '^rename:'`
 226         do
 227                 echo ${i} | tee -a $mail_msg_file >> ${LOGFILE}
 228                 rm -f ${i}.export
 229                 mv ${i} ${i}.export
 230         done
 231 }
 232 
 233 #
 234 # Copy some or all of the source tree.
 235 #
 236 # Returns 0 for success, non-zero for failure.
 237 #
 238 # usage: copy_source CODEMGR_WS DESTDIR LABEL SRCROOT
 239 #
 240 function copy_source {
 241         WS=$1
 242         DEST=$2
 243         label=$3
 244         srcroot=$4
 245 
 246         printf "\n==== Creating %s source from %s (%s) ====\n\n" \
 247             "$DEST" "$WS" "$label" | tee -a $mail_msg_file >> $LOGFILE
 248 
 249         printf "cleaning out %s\n" "$DEST." >> $LOGFILE
 250         rm -rf "$DEST" >> $LOGFILE 2>&1
 251 
 252         printf "creating %s\n" "$DEST." >> $LOGFILE
 253         mkdir -p "$DEST" 2>> $LOGFILE
 254 
 255         if (( $? != 0 )) ; then
 256                 printf "failed to create %s\n" "$DEST" |
 257                     tee -a $mail_msg_file >> $LOGFILE
 258                 build_ok=n
 259                 return 1
 260         fi
 261         cd "$WS"
 262 
 263         printf "populating %s\n" "$DEST." >> $LOGFILE
 264 
 265         case "$SCM_TYPE" in
 266         teamware)
 267                 find $srcroot -name 's\.*' -a -type f -print | \
 268                     sed -e 's,SCCS\/s.,,' | \
 269                     grep -v '/\.del-*' | \
 270                     cpio -pd $DEST >>$LOGFILE 2>&1
 271                 if (( $? != 0 )) ; then
 272                     printf "cpio failed for %s\n" "$DEST" |
 273                         tee -a $mail_msg_file >> $LOGFILE
 274                     build_ok=n
 275                     return 1
 276                 fi
 277                 ;;
 278         mercurial)
 279                 copy_source_mercurial $DEST $srcroot
 280                 if (( $? != 0 )) ; then
 281                     build_ok=n
 282                     return 1
 283                 fi
 284                 ;;
 285         *)
 286                 build_ok=n
 287                 echo "Tree copy is not supported for workspace type" \
 288                     "$SCM_TYPE" | tee -a $mail_msg_file >> $LOGFILE
 289                 return 1
 290                 ;;
 291         esac
 292 
 293         return 0
 294 }
 295 
 296 #
 297 # Mercurial-specific copy code for copy_source().  Handles the
 298 # combined open and closed trees.
 299 #
 300 # Returns 0 for success, non-zero for failure.
 301 #
 302 # usage: copy_source_mercurial destdir srcroot
 303 #
 304 function copy_source_mercurial {
 305         typeset dest=$1
 306         typeset srcroot=$2
 307         typeset open_top closed_top
 308 
 309         case $srcroot in
 310         usr)
 311                 open_top=usr
 312                 if [[ "$CLOSED_IS_PRESENT" = yes ]]; then
 313                         closed_top=usr/closed
 314                 fi
 315                 ;;
 316         usr/closed*)
 317                 if [[ "$CLOSED_IS_PRESENT" = no ]]; then
 318                         printf "can't copy %s: closed tree not present.\n" \
 319                             "$srcroot" | tee -a $mail_msg_file >> $LOGFILE
 320                         return 1
 321                 fi
 322                 closed_top="$srcroot"
 323                 ;;
 324         *)
 325                 open_top="$srcroot"
 326                 ;;
 327         esac            
 328 
 329         if [[ -n "$open_top" ]]; then
 330                 hg locate -I "$open_top" | cpio -pd "$dest" >>$LOGFILE 2>&1
 331                 if (( $? != 0 )) ; then
 332                     printf "cpio failed for %s\n" "$dest" |
 333                         tee -a $mail_msg_file >> $LOGFILE
 334                     return 1
 335                 fi
 336         fi
 337 
 338         if [[ -n "$closed_top" ]]; then
 339                 mkdir -p "$dest/usr/closed" || return 1
 340                 if [[ "$closed_top" = usr/closed ]]; then
 341                         (cd usr/closed; hg locate |
 342                             cpio -pd "$dest/usr/closed") >>$LOGFILE 2>&1
 343                         if (( $? != 0 )) ; then
 344                             printf "cpio failed for %s/usr/closed\n" \
 345                                 "$dest" | tee -a $mail_msg_file >> $LOGFILE
 346                             return 1
 347                         fi
 348                 else
 349                         # copy subtree of usr/closed
 350                         closed_top=${closed_top#usr/closed/}
 351                         (cd usr/closed; hg locate -I "$closed_top" |
 352                             cpio -pd "$dest/usr/closed") >>$LOGFILE 2>&1
 353                         if (( $? != 0 )) ; then
 354                             printf "cpio failed for %s/usr/closed/%s\n" \
 355                                 "$dest" "$closed_top" |
 356                                 tee -a $mail_msg_file >> $LOGFILE
 357                             return 1
 358                         fi
 359                 fi
 360         fi
 361 
 362         return 0
 363 }
 364 
 365 #
 366 # function to create (but not build) the export/crypt source tree.
 367 # usage: set_up_source_build CODEMGR_WS DESTDIR MAKE_TARGET
 368 # Sets SRC to the modified source tree, for use by the caller when it
 369 # builds the tree.
 370 #
 371 function set_up_source_build {
 372         WS=$1
 373         DEST=$2
 374         MAKETARG=$3
 375 
 376         copy_source $WS $DEST $MAKETARG usr
 377         if (( $? != 0 )); then
 378             echo "\nCould not copy source tree for source build." |
 379                 tee -a $mail_msg_file >> $LOGFILE
 380             build_ok=n
 381             return
 382         fi
 383 
 384         SRC=${DEST}/usr/src
 385 
 386         cd $SRC
 387         rm -f ${MAKETARG}.out
 388         echo "making ${MAKETARG} in ${SRC}." >> $LOGFILE
 389         /bin/time $MAKE -e ${MAKETARG} 2>&1 | \
 390             tee -a $SRC/${MAKETARG}.out >> $LOGFILE
 391         echo "\n==== ${MAKETARG} build errors ====\n" >> $mail_msg_file
 392         egrep ":" $SRC/${MAKETARG}.out | \
 393                 egrep -e "(^${MAKE}:|[  ]error[:        \n])" | \
 394                 egrep -v "Ignoring unknown host" | \
 395                 egrep -v "warning" >> $mail_msg_file
 396 
 397         echo "clearing state files." >> $LOGFILE
 398         find . -name '.make*' -exec rm -f {} \;
 399 }
 400 
 401 # Return library search directive as function of given root.
 402 function myldlibs {
 403         echo "-L$1/lib -L$1/usr/lib"
 404 }
 405 
 406 # Return header search directive as function of given root.
 407 function myheaders {
 408         echo "-I$1/usr/include"
 409 }
 410 
 411 #
 412 # Function to do the build, including package generation.
 413 # usage: build LABEL SUFFIX ND MULTIPROTO
 414 # - LABEL is used to tag build output.
 415 # - SUFFIX is used to distinguish files (e.g., DEBUG vs non-DEBUG,
 416 #   open-only vs full tree).
 417 # - ND is "-nd" (non-DEBUG builds) or "" (DEBUG builds).
 418 # - If MULTIPROTO is "yes", it means to name the proto area according to
 419 #   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
 420 #
 421 function build {
 422         LABEL=$1
 423         SUFFIX=$2
 424         ND=$3
 425         MULTIPROTO=$4
 426         INSTALLOG=install${SUFFIX}-${MACH}
 427         NOISE=noise${SUFFIX}-${MACH}
 428         PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
 429 
 430         ORIGROOT=$ROOT
 431         [ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
 432 
 433         if [[ "$O_FLAG" = y ]]; then
 434                 echo "\nSetting CLOSEDROOT= ${ROOT}-closed\n" >> $LOGFILE
 435                 export CLOSEDROOT=${ROOT}-closed
 436         fi
 437 
 438         export ENVLDLIBS1=`myldlibs $ROOT`
 439         export ENVCPPFLAGS1=`myheaders $ROOT`
 440 
 441         this_build_ok=y
 442         #
 443         #       Build OS-Networking source
 444         #
 445         echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
 446                 >> $LOGFILE
 447 
 448         rm -f $SRC/${INSTALLOG}.out
 449         cd $SRC
 450         /bin/time $MAKE -e install 2>&1 | \
 451             tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
 452 
 453         if [[ "$SCM_TYPE" = teamware ]]; then
 454                 echo "\n==== SCCS Noise ($LABEL) ====\n" >> $mail_msg_file
 455                 egrep 'sccs(check:| *get)' $SRC/${INSTALLOG}.out >> \
 456                         $mail_msg_file
 457         fi
 458 
 459         echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
 460         egrep ":" $SRC/${INSTALLOG}.out |
 461                 egrep -e "(^${MAKE}:|[  ]error[:        \n])" | \
 462                 egrep -v "Ignoring unknown host" | \
 463                 egrep -v "cc .* -o error " | \
 464                 egrep -v "warning" >> $mail_msg_file
 465         if [ "$?" = "0" ]; then
 466                 build_ok=n
 467                 this_build_ok=n
 468         fi
 469         grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
 470                 >> $mail_msg_file
 471         if [ "$?" = "0" ]; then
 472                 build_ok=n
 473                 this_build_ok=n
 474         fi
 475 
 476         if [ "$W_FLAG" = "n" ]; then
 477                 echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
 478                 egrep -i warning: $SRC/${INSTALLOG}.out \
 479                         | egrep -v '^tic:' \
 480                         | egrep -v "symbol (\`|')timezone' has differing types:" \
 481                         | egrep -v "parameter <PSTAMP> set to" \
 482                         | egrep -v "Ignoring unknown host" \
 483                         | egrep -v "redefining segment flags attribute for" \
 484                         >> $mail_msg_file
 485         fi
 486 
 487         echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
 488                 >> $LOGFILE
 489 
 490         echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
 491         tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
 492 
 493         if [ "$i_FLAG" = "n" -a "$W_FLAG" = "n" ]; then
 494                 rm -f $SRC/${NOISE}.ref
 495                 if [ -f $SRC/${NOISE}.out ]; then
 496                         mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
 497                 fi
 498                 grep : $SRC/${INSTALLOG}.out \
 499                         | egrep -v '^/' \
 500                         | egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
 501                         | egrep -v '^tic:' \
 502                         | egrep -v '^mcs' \
 503                         | egrep -v '^LD_LIBRARY_PATH=' \
 504                         | egrep -v 'ar: creating' \
 505                         | egrep -v 'ar: writing' \
 506                         | egrep -v 'conflicts:' \
 507                         | egrep -v ':saved created' \
 508                         | egrep -v '^stty.*c:' \
 509                         | egrep -v '^mfgname.c:' \
 510                         | egrep -v '^uname-i.c:' \
 511                         | egrep -v '^volumes.c:' \
 512                         | egrep -v '^lint library construction:' \
 513                         | egrep -v 'tsort: INFORM:' \
 514                         | egrep -v 'stripalign:' \
 515                         | egrep -v 'chars, width' \
 516                         | egrep -v "symbol (\`|')timezone' has differing types:" \
 517                         | egrep -v 'PSTAMP' \
 518                         | egrep -v '|%WHOANDWHERE%|' \
 519                         | egrep -v '^Manifying' \
 520                         | egrep -v 'Ignoring unknown host' \
 521                         | egrep -v 'Processing method:' \
 522                         | egrep -v '^Writing' \
 523                         | egrep -v 'spellin1:' \
 524                         | egrep -v '^adding:' \
 525                         | egrep -v "^echo 'msgid" \
 526                         | egrep -v '^echo ' \
 527                         | egrep -v '\.c:$' \
 528                         | egrep -v '^Adding file:' \
 529                         | egrep -v 'CLASSPATH=' \
 530                         | egrep -v '\/var\/mail\/:saved' \
 531                         | egrep -v -- '-DUTS_VERSION=' \
 532                         | egrep -v '^Running Mkbootstrap' \
 533                         | egrep -v '^Applet length read:' \
 534                         | egrep -v 'bytes written:' \
 535                         | egrep -v '^File:SolarisAuthApplet.bin' \
 536                         | egrep -v -i 'jibversion' \
 537                         | egrep -v '^Output size:' \
 538                         | egrep -v '^Solo size statistics:' \
 539                         | egrep -v '^Using ROM API Version' \
 540                         | egrep -v '^Zero Signature length:' \
 541                         | egrep -v '^Note \(probably harmless\):' \
 542                         | egrep -v '::' \
 543                         | egrep -v -- '-xcache' \
 544                         | egrep -v '^\+' \
 545                         | egrep -v '^cc1: note: -fwritable-strings' \
 546                         | egrep -v 'svccfg-native -s svc:/' \
 547                         | sort | uniq >$SRC/${NOISE}.out
 548                 if [ ! -f $SRC/${NOISE}.ref ]; then
 549                         cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
 550                 fi
 551                 echo "\n==== Build noise differences ($LABEL) ====\n" \
 552                         >>$mail_msg_file
 553                 diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
 554         fi
 555 
 556         #
 557         #       Re-sign selected binaries using signing server
 558         #       (gatekeeper builds only)
 559         #
 560         if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
 561                 echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
 562                 signing_file="${TMPDIR}/signing"
 563                 rm -f ${signing_file}
 564                 export CODESIGN_USER
 565                 signproto $SRC/tools/codesign/creds 2>&1 | \
 566                         tee -a ${signing_file} >> $LOGFILE
 567                 echo "\n==== Finished signing proto area at `date` ====\n" \
 568                     >> $LOGFILE
 569                 echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
 570                     >> $mail_msg_file
 571                 egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
 572                 if (( $? == 0 )) ; then
 573                         build_ok=n
 574                         this_build_ok=n
 575                 fi
 576         fi
 577 
 578         #
 579         #       Building Packages
 580         #
 581         if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
 582                 if [ -d $SRC/pkg -o -d $SRC/pkgdefs ]; then
 583                         echo "\n==== Creating $LABEL packages at `date` ====\n" \
 584                                 >> $LOGFILE
 585                         echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
 586                         rm -rf $PKGARCHIVE >> "$LOGFILE" 2>&1
 587                         mkdir -p $PKGARCHIVE >> "$LOGFILE" 2>&1
 588 
 589                         for d in pkg pkgdefs; do
 590                                 if [ ! -f "$SRC/$d/Makefile" ]; then
 591                                         continue
 592                                 fi
 593                                 rm -f $SRC/$d/${INSTALLOG}.out
 594                                 cd $SRC/$d
 595                                 /bin/time $MAKE -e install 2>&1 | \
 596                                         tee -a $SRC/$d/${INSTALLOG}.out >> $LOGFILE
 597                         done
 598 
 599                         echo "\n==== package build errors ($LABEL) ====\n" \
 600                                 >> $mail_msg_file
 601 
 602                         for d in pkg pkgdefs; do
 603                                 if [ ! -f "$SRC/$d/Makefile" ]; then
 604                                         continue
 605                                 fi
 606 
 607                                 egrep "${MAKE}|ERROR|WARNING" $SRC/$d/${INSTALLOG}.out | \
 608                                         grep ':' | \
 609                                         grep -v PSTAMP | \
 610                                         egrep -v "Ignoring unknown host" \
 611                                         >> $mail_msg_file
 612                         done
 613                 else
 614                         #
 615                         # Handle it gracefully if -p was set but there are
 616                         # neither pkg nor pkgdefs directories.
 617                         #
 618                         echo "\n==== No $LABEL packages to build ====\n" \
 619                                 >> $LOGFILE
 620                 fi
 621         else
 622                 echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
 623         fi
 624 
 625         ROOT=$ORIGROOT
 626 }
 627 
 628 # Usage: dolint /dir y|n
 629 # Arg. 2 is a flag to turn on/off the lint diff output
 630 function dolint {
 631         if [ ! -d "$1" ]; then
 632                 echo "dolint error: $1 is not a directory"
 633                 exit 1
 634         fi
 635 
 636         if [ "$2" != "y" -a "$2" != "n" ]; then
 637                 echo "dolint internal error: $2 should be 'y' or 'n'"
 638                 exit 1
 639         fi
 640 
 641         lintdir=$1
 642         dodiff=$2
 643         base=`basename $lintdir`
 644         LINTOUT=$lintdir/lint-${MACH}.out
 645         LINTNOISE=$lintdir/lint-noise-${MACH}
 646         export ENVLDLIBS1=`myldlibs $ROOT`
 647         export ENVCPPFLAGS1=`myheaders $ROOT`
 648 
 649         set_debug_build_flags
 650 
 651         #
 652         #       '$MAKE lint' in $lintdir
 653         #
 654         echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
 655 
 656         # remove old lint.out
 657         rm -f $lintdir/lint.out $lintdir/lint-noise.out
 658         if [ -f $lintdir/lint-noise.ref ]; then
 659                 mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
 660         fi
 661 
 662         rm -f $LINTOUT
 663         cd $lintdir
 664         #
 665         # Remove all .ln files to ensure a full reference file
 666         #
 667         rm -f Nothing_to_remove \
 668             `find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \) \
 669                 -prune -o -type f -name '*.ln' -print `
 670 
 671         /bin/time $MAKE -ek lint 2>&1 | \
 672             tee -a $LINTOUT >> $LOGFILE
 673         echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
 674         grep "$MAKE:" $LINTOUT |
 675                 egrep -v "Ignoring unknown host" \
 676                 >> $mail_msg_file
 677 
 678         echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
 679 
 680         echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
 681                 >>$mail_msg_file
 682         tail -3  $LINTOUT >>$mail_msg_file
 683 
 684         rm -f ${LINTNOISE}.ref
 685         if [ -f ${LINTNOISE}.out ]; then
 686                 mv ${LINTNOISE}.out ${LINTNOISE}.ref
 687         fi
 688         grep : $LINTOUT | \
 689                 egrep -v '^(real|user|sys)' |
 690                 egrep -v '(library construction)' | \
 691                 egrep -v ': global crosschecks' | \
 692                 egrep -v 'Ignoring unknown host' | \
 693                 egrep -v '\.c:$' | \
 694                 sort | uniq > ${LINTNOISE}.out
 695         if [ ! -f ${LINTNOISE}.ref ]; then
 696                 cp ${LINTNOISE}.out ${LINTNOISE}.ref
 697         fi
 698         if [ "$dodiff" != "n" ]; then
 699                 echo "\n==== lint warnings $base ====\n" \
 700                         >>$mail_msg_file
 701                 # should be none, though there are a few that were filtered out
 702                 # above
 703                 egrep -i '(warning|lint):' ${LINTNOISE}.out \
 704                         | sort | uniq >> $mail_msg_file
 705                 echo "\n==== lint noise differences $base ====\n" \
 706                         >> $mail_msg_file
 707                 diff ${LINTNOISE}.ref ${LINTNOISE}.out \
 708                         >> $mail_msg_file
 709         fi
 710 }
 711 
 712 # Install proto area from IHV build
 713 
 714 function copy_ihv_proto {
 715 
 716         echo "\n==== Installing IHV proto area ====\n" \
 717                 >> $LOGFILE
 718         if [ -d "$IA32_IHV_ROOT" ]; then
 719                 if [ ! -d "$ROOT" ]; then
 720                         echo "mkdir -p $ROOT" >> $LOGFILE
 721                         mkdir -p $ROOT
 722                 fi
 723                 echo "copying $IA32_IHV_ROOT to $ROOT\n" >> $LOGFILE
 724                 cd $IA32_IHV_ROOT
 725                 tar cf - . | (cd $ROOT; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
 726         else
 727                 echo "$IA32_IHV_ROOT: not found" >> $LOGFILE
 728         fi
 729 
 730         if [ "$MULTI_PROTO" = yes ]; then
 731                 if [ ! -d "$ROOT-nd" ]; then
 732                         echo "mkdir -p $ROOT-nd" >> $LOGFILE
 733                         mkdir -p $ROOT-nd
 734                 fi
 735                 # If there's a non-DEBUG version of the IHV proto area,
 736                 # copy it, but copy something if there's not.
 737                 if [ -d "$IA32_IHV_ROOT-nd" ]; then
 738                         echo "copying $IA32_IHV_ROOT-nd to $ROOT-nd\n" >> $LOGFILE
 739                         cd $IA32_IHV_ROOT-nd
 740                 elif [ -d "$IA32_IHV_ROOT" ]; then
 741                         echo "copying $IA32_IHV_ROOT to $ROOT-nd\n" >> $LOGFILE
 742                         cd $IA32_IHV_ROOT
 743                 else
 744                         echo "$IA32_IHV_ROOT{-nd,}: not found" >> $LOGFILE
 745                         return
 746                 fi
 747                 tar cf - . | (cd $ROOT-nd; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
 748         fi
 749 }
 750 
 751 # Install IHV packages in PKGARCHIVE
 752 # usage: copy_ihv_pkgs LABEL SUFFIX
 753 function copy_ihv_pkgs {
 754         LABEL=$1
 755         SUFFIX=$2
 756         # always use non-DEBUG IHV packages
 757         IA32_IHV_PKGS=${IA32_IHV_PKGS_ORIG}-nd
 758         PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
 759 
 760         echo "\n==== Installing IHV packages from $IA32_IHV_PKGS ($LABEL) ====\n" \
 761                 >> $LOGFILE
 762         if [ -d "$IA32_IHV_PKGS" ]; then
 763                 cd $IA32_IHV_PKGS
 764                 tar cf - * | \
 765                    (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
 766         else
 767                 echo "$IA32_IHV_PKGS: not found" >> $LOGFILE
 768         fi
 769 
 770         echo "\n==== Installing IHV packages from $IA32_IHV_BINARY_PKGS ($LABEL) ====\n" \
 771                 >> $LOGFILE
 772         if [ -d "$IA32_IHV_BINARY_PKGS" ]; then
 773                 cd $IA32_IHV_BINARY_PKGS
 774                 tar cf - * | \
 775                     (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
 776         else
 777                 echo "$IA32_IHV_BINARY_PKGS: not found" >> $LOGFILE
 778         fi
 779 }
 780 
 781 #
 782 # Build and install the onbld tools.
 783 #
 784 # usage: build_tools DESTROOT
 785 #
 786 # returns non-zero status if the build was successful.
 787 #
 788 function build_tools {
 789         DESTROOT=$1
 790 
 791         INSTALLOG=install-${MACH}
 792 
 793         echo "\n==== Building tools at `date` ====\n" \
 794                 >> $LOGFILE
 795 
 796         rm -f ${TOOLS}/${INSTALLOG}.out
 797         cd ${TOOLS}
 798         /bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install 2>&1 | \
 799             tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
 800 
 801         echo "\n==== Tools build errors ====\n" >> $mail_msg_file
 802 
 803         egrep ":" ${TOOLS}/${INSTALLOG}.out |
 804                 egrep -e "(${MAKE}:|[   ]error[:        \n])" | \
 805                 egrep -v "Ignoring unknown host" | \
 806                 egrep -v warning >> $mail_msg_file
 807         return $?
 808 }
 809 
 810 #
 811 # Set up to use locally installed tools.
 812 #
 813 # usage: use_tools TOOLSROOT
 814 #
 815 function use_tools {
 816         TOOLSROOT=$1
 817 
 818         #
 819         # If we're not building ON workspace, then the TOOLSROOT
 820         # settings here are clearly ignored by the workspace
 821         # makefiles, prepending nonexistent directories to PATH is
 822         # harmless, and we clearly do not wish to override
 823         # ONBLD_TOOLS.
 824         #
 825         # If we're building an ON workspace, then the prepended PATH
 826         # elements should supercede the preexisting ONBLD_TOOLS paths,
 827         # and we want to override ONBLD_TOOLS to catch the tools that
 828         # don't have specific path env vars here.
 829         #
 830         # So the only conditional behavior is overriding ONBLD_TOOLS,
 831         # and we check for "an ON workspace" by looking for
 832         # ${TOOLSROOT}/opt/onbld.
 833         #
 834 
 835         STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
 836         export STABS
 837         CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
 838         export CTFSTABS
 839         GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
 840         export GENOFFSETS
 841 
 842         CTFCONVERT=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfconvert
 843         export CTFCONVERT
 844         CTFMERGE=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfmerge
 845         export CTFMERGE
 846 
 847         CTFCVTPTBL=${TOOLSROOT}/opt/onbld/bin/ctfcvtptbl
 848         export CTFCVTPTBL
 849         CTFFINDMOD=${TOOLSROOT}/opt/onbld/bin/ctffindmod
 850         export CTFFINDMOD
 851 
 852         if [ "$VERIFY_ELFSIGN" = "y" ]; then
 853                 ELFSIGN=${TOOLSROOT}/opt/onbld/bin/elfsigncmp
 854         else
 855                 ELFSIGN=${TOOLSROOT}/opt/onbld/bin/${MACH}/elfsign
 856         fi
 857         export ELFSIGN
 858 
 859         PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
 860         PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
 861         export PATH
 862 
 863         if [ -d "${TOOLSROOT}/opt/onbld" ]; then
 864                 ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
 865                 export ONBLD_TOOLS
 866         fi
 867 
 868         echo "\n==== New environment settings. ====\n" >> $LOGFILE
 869         echo "STABS=${STABS}" >> $LOGFILE
 870         echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
 871         echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
 872         echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
 873         echo "CTFCVTPTBL=${CTFCVTPTBL}" >> $LOGFILE
 874         echo "CTFFINDMOD=${CTFFINDMOD}" >> $LOGFILE
 875         echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
 876         echo "PATH=${PATH}" >> $LOGFILE
 877         echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE
 878 }
 879 
 880 function staffer {
 881         if [ $ISUSER -ne 0 ]; then
 882                 "$@"
 883         else
 884                 arg="\"$1\""
 885                 shift
 886                 for i
 887                 do
 888                         arg="$arg \"$i\""
 889                 done
 890                 eval su $STAFFER -c \'$arg\'
 891         fi
 892 }
 893 
 894 #
 895 # Verify that the closed tree is present if it needs to be.
 896 #
 897 function check_closed_tree {
 898         if [[ ! -d "$ON_CLOSED_BINS" ]]; then
 899                 echo "If the closed sources are not present," \
 900                     "ON_CLOSED_BINS"
 901                 echo "must point to the closed binaries tree."
 902                 build_ok=n
 903                 exit 1
 904         fi
 905 }
 906 
 907 function obsolete_build {
 908         echo "WARNING: Obsolete $1 build requested; request will be ignored"
 909 }
 910 
 911 #
 912 # wrapper over wsdiff.
 913 # usage: do_wsdiff LABEL OLDPROTO NEWPROTO
 914 #
 915 function do_wsdiff {
 916         label=$1
 917         oldproto=$2
 918         newproto=$3
 919 
 920         wsdiff="wsdiff"
 921         [ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
 922 
 923         echo "\n==== Getting object changes since last build at `date`" \
 924             "($label) ====\n" | tee -a $LOGFILE >> $mail_msg_file
 925         $wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
 926                     tee -a $LOGFILE >> $mail_msg_file
 927         echo "\n==== Object changes determined at `date` ($label) ====\n" | \
 928             tee -a $LOGFILE >> $mail_msg_file
 929 }
 930 
 931 #
 932 # Functions for setting build flags (DEBUG/non-DEBUG).  Keep them
 933 # together.
 934 #
 935 
 936 function set_non_debug_build_flags {
 937         export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
 938         export RELEASE_BUILD ; RELEASE_BUILD=
 939         unset EXTRA_OPTIONS
 940         unset EXTRA_CFLAGS
 941 }
 942 
 943 function set_debug_build_flags {
 944         export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
 945         unset RELEASE_BUILD
 946         unset EXTRA_OPTIONS
 947         unset EXTRA_CFLAGS
 948 }
 949 
 950 
 951 MACH=`uname -p`
 952 
 953 if [ "$OPTHOME" = "" ]; then
 954         OPTHOME=/opt
 955         export OPTHOME
 956 fi
 957 if [ "$TEAMWARE" = "" ]; then
 958         TEAMWARE=$OPTHOME/teamware
 959         export TEAMWARE
 960 fi
 961 
 962 USAGE='Usage: nightly [-in] [+t] [-V VERS ] [ -S E|D|H|O ] <env_file>
 963 
 964 Where:
 965         -i      Fast incremental options (no clobber, lint, check)
 966         -n      Do not do a bringover
 967         +t      Use the build tools in $ONBLD_TOOLS/bin
 968         -V VERS set the build version string to VERS
 969         -S      Build a variant of the source product
 970                 E - build exportable source
 971                 D - build domestic source (exportable + crypt)
 972                 H - build hybrid source (binaries + deleted source)
 973                 O - build (only) open source
 974 
 975         <env_file>  file in Bourne shell syntax that sets and exports
 976         variables that configure the operation of this script and many of
 977         the scripts this one calls. If <env_file> does not exist,
 978         it will be looked for in $OPTHOME/onbld/env.
 979 
 980 non-DEBUG is the default build type. Build options can be set in the
 981 NIGHTLY_OPTIONS variable in the <env_file> as follows:
 982 
 983         -A      check for ABI differences in .so files
 984         -C      check for cstyle/hdrchk errors
 985         -D      do a build with DEBUG on
 986         -F      do _not_ do a non-DEBUG build
 987         -G      gate keeper default group of options (-au)
 988         -I      integration engineer default group of options (-ampu)
 989         -M      do not run pmodes (safe file permission checker)
 990         -N      do not run protocmp
 991         -O      generate OpenSolaris deliverables
 992         -R      default group of options for building a release (-mp)
 993         -U      update proto area in the parent
 994         -V VERS set the build version string to VERS
 995         -X      copy x86 IHV proto area
 996         -f      find unreferenced files
 997         -i      do an incremental build (no "make clobber")
 998         -l      do "make lint" in $LINTDIRS (default: $SRC y)
 999         -m      send mail to $MAILTO at end of build
1000         -n      do not do a bringover
1001         -o      build using root privileges to set OWNER/GROUP (old style)
1002         -p      create packages
1003         -r      check ELF runtime attributes in the proto area
1004         -t      build and use the tools in $SRC/tools (default setting)
1005         +t      Use the build tools in $ONBLD_TOOLS/bin
1006         -u      update proto_list_$MACH and friends in the parent workspace;
1007                 when used with -f, also build an unrefmaster.out in the parent
1008         -w      report on differences between previous and current proto areas
1009         -z      compress cpio archives with gzip
1010         -W      Do not report warnings (freeware gate ONLY)
1011         -S      Build a variant of the source product
1012                 E - build exportable source
1013                 D - build domestic source (exportable + crypt)
1014                 H - build hybrid source (binaries + deleted source)
1015                 O - build (only) open source
1016 '
1017 #
1018 #       A log file will be generated under the name $LOGFILE
1019 #       for partially completed build and log.`date '+%F'`
1020 #       in the same directory for fully completed builds.
1021 #
1022 
1023 # default values for low-level FLAGS; G I R are group FLAGS
1024 A_FLAG=n
1025 C_FLAG=n
1026 D_FLAG=n
1027 F_FLAG=n
1028 f_FLAG=n
1029 i_FLAG=n; i_CMD_LINE_FLAG=n
1030 l_FLAG=n
1031 M_FLAG=n
1032 m_FLAG=n
1033 N_FLAG=n
1034 n_FLAG=n
1035 O_FLAG=n
1036 o_FLAG=n
1037 P_FLAG=n
1038 p_FLAG=n
1039 r_FLAG=n
1040 T_FLAG=n
1041 t_FLAG=y
1042 U_FLAG=n
1043 u_FLAG=n
1044 V_FLAG=n
1045 W_FLAG=n
1046 w_FLAG=n
1047 X_FLAG=n
1048 SD_FLAG=n
1049 SE_FLAG=n
1050 SH_FLAG=n
1051 SO_FLAG=n
1052 #
1053 XMOD_OPT=
1054 #
1055 build_ok=y
1056 
1057 function is_source_build {
1058         [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \
1059             "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ]
1060         return $?
1061 }
1062 
1063 #
1064 # examine arguments
1065 #
1066 
1067 #
1068 # single function for setting -S flag and doing error checking.
1069 # usage: set_S_flag <type>
1070 # where <type> is the source build type ("E", "D", ...).
1071 #
1072 function set_S_flag {
1073         if is_source_build; then
1074                 echo "Can only build one source variant at a time."
1075                 exit 1
1076         fi
1077         if [ "$1" = "E" ]; then
1078                 SE_FLAG=y
1079         elif [ "$1" = "D" ]; then
1080                 SD_FLAG=y
1081         elif [ "$1" = "H" ]; then
1082                 SH_FLAG=y
1083         elif [ "$1" = "O" ]; then
1084                 SO_FLAG=y
1085         else
1086                 echo "$USAGE"
1087                 exit 1
1088         fi
1089 }
1090 
1091 OPTIND=1
1092 while getopts +inS:tV: FLAG
1093 do
1094         case $FLAG in
1095           i )   i_FLAG=y; i_CMD_LINE_FLAG=y
1096                 ;;
1097           n )   n_FLAG=y
1098                 ;;
1099           S )
1100                 set_S_flag $OPTARG
1101                 ;;
1102          +t )   t_FLAG=n
1103                 ;;
1104           V )   V_FLAG=y
1105                 V_ARG="$OPTARG"
1106                 ;;
1107          \? )   echo "$USAGE"
1108                 exit 1
1109                 ;;
1110         esac
1111 done
1112 
1113 # correct argument count after options
1114 shift `expr $OPTIND - 1`
1115 
1116 # test that the path to the environment-setting file was given
1117 if [ $# -ne 1 ]; then
1118         echo "$USAGE"
1119         exit 1
1120 fi
1121 
1122 # check if user is running nightly as root
1123 # ISUSER is set non-zero if an ordinary user runs nightly, or is zero
1124 # when root invokes nightly.
1125 /usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
1126 ISUSER=$?;      export ISUSER
1127 
1128 #
1129 # force locale to C
1130 LC_COLLATE=C;   export LC_COLLATE
1131 LC_CTYPE=C;     export LC_CTYPE
1132 LC_MESSAGES=C;  export LC_MESSAGES
1133 LC_MONETARY=C;  export LC_MONETARY
1134 LC_NUMERIC=C;   export LC_NUMERIC
1135 LC_TIME=C;      export LC_TIME
1136 
1137 # clear environment variables we know to be bad for the build
1138 unset LD_OPTIONS
1139 unset LD_AUDIT          LD_AUDIT_32             LD_AUDIT_64
1140 unset LD_BIND_NOW       LD_BIND_NOW_32          LD_BIND_NOW_64
1141 unset LD_BREADTH        LD_BREADTH_32           LD_BREADTH_64
1142 unset LD_CONFIG         LD_CONFIG_32            LD_CONFIG_64
1143 unset LD_DEBUG          LD_DEBUG_32             LD_DEBUG_64
1144 unset LD_DEMANGLE       LD_DEMANGLE_32          LD_DEMANGLE_64
1145 unset LD_FLAGS          LD_FLAGS_32             LD_FLAGS_64
1146 unset LD_LIBRARY_PATH   LD_LIBRARY_PATH_32      LD_LIBRARY_PATH_64
1147 unset LD_LOADFLTR       LD_LOADFLTR_32          LD_LOADFLTR_64
1148 unset LD_NOAUDIT        LD_NOAUDIT_32           LD_NOAUDIT_64
1149 unset LD_NOAUXFLTR      LD_NOAUXFLTR_32         LD_NOAUXFLTR_64
1150 unset LD_NOCONFIG       LD_NOCONFIG_32          LD_NOCONFIG_64
1151 unset LD_NODIRCONFIG    LD_NODIRCONFIG_32       LD_NODIRCONFIG_64
1152 unset LD_NODIRECT       LD_NODIRECT_32          LD_NODIRECT_64
1153 unset LD_NOLAZYLOAD     LD_NOLAZYLOAD_32        LD_NOLAZYLOAD_64
1154 unset LD_NOOBJALTER     LD_NOOBJALTER_32        LD_NOOBJALTER_64
1155 unset LD_NOVERSION      LD_NOVERSION_32         LD_NOVERSION_64
1156 unset LD_ORIGIN         LD_ORIGIN_32            LD_ORIGIN_64
1157 unset LD_PRELOAD        LD_PRELOAD_32           LD_PRELOAD_64
1158 unset LD_PROFILE        LD_PROFILE_32           LD_PROFILE_64
1159 
1160 unset CONFIG
1161 unset GROUP
1162 unset OWNER
1163 unset REMOTE
1164 unset ENV
1165 unset ARCH
1166 unset CLASSPATH
1167 unset NAME
1168 
1169 #
1170 # To get ONBLD_TOOLS from the environment, it must come from the env file.
1171 # If it comes interactively, it is generally TOOLS_PROTO, which will be
1172 # clobbered before the compiler version checks, which will therefore fail.
1173 #
1174 unset ONBLD_TOOLS
1175 
1176 #
1177 #       Setup environmental variables
1178 #
1179 if [ -f /etc/nightly.conf ]; then
1180         . /etc/nightly.conf
1181 fi    
1182 
1183 if [ -f $1 ]; then
1184         if [[ $1 = */* ]]; then
1185                 . $1
1186         else
1187                 . ./$1
1188         fi
1189 else
1190         if [ -f $OPTHOME/onbld/env/$1 ]; then
1191                 . $OPTHOME/onbld/env/$1
1192         else
1193                 echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
1194                 exit 1
1195         fi
1196 fi
1197 
1198 # contents of stdenv.sh inserted after next line:
1199 # STDENV_START
1200 # STDENV_END
1201 
1202 # Check if we have sufficient data to continue...
1203 [[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
1204 if  [[ "${NIGHTLY_OPTIONS}" == ~(F)n ]] ; then
1205         # Check if the gate data are valid if we don't do a "bringover" below
1206         [[ -d "${CODEMGR_WS}" ]] || \
1207                 fatal_error "Error: ${CODEMGR_WS} is not a directory."
1208         [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || \
1209                 fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
1210 fi
1211 
1212 #
1213 # place ourselves in a new task, respecting BUILD_PROJECT if set.
1214 #
1215 if [ -z "$BUILD_PROJECT" ]; then
1216         /usr/bin/newtask -c $$
1217 else
1218         /usr/bin/newtask -c $$ -p $BUILD_PROJECT
1219 fi
1220 
1221 ps -o taskid= -p $$ | read build_taskid
1222 ps -o project= -p $$ | read build_project
1223 
1224 #
1225 # See if NIGHTLY_OPTIONS is set
1226 #
1227 if [ "$NIGHTLY_OPTIONS" = "" ]; then
1228         NIGHTLY_OPTIONS="-aBm"
1229 fi
1230 
1231 #
1232 # If BRINGOVER_WS was not specified, let it default to CLONE_WS
1233 #
1234 if [ "$BRINGOVER_WS" = "" ]; then
1235         BRINGOVER_WS=$CLONE_WS
1236 fi
1237 
1238 #
1239 # If CLOSED_BRINGOVER_WS was not specified, let it default to CLOSED_CLONE_WS
1240 #
1241 if [ "$CLOSED_BRINGOVER_WS" = "" ]; then
1242         CLOSED_BRINGOVER_WS=$CLOSED_CLONE_WS
1243 fi
1244 
1245 #
1246 # If BRINGOVER_FILES was not specified, default to usr
1247 #
1248 if [ "$BRINGOVER_FILES" = "" ]; then
1249         BRINGOVER_FILES="usr"
1250 fi
1251 
1252 #
1253 # If the closed sources are not present, the closed binaries must be
1254 # present for the build to succeed.  If there's no pointer to the
1255 # closed binaries, flag that now, rather than forcing the user to wait
1256 # a couple hours (or more) to find out.
1257 #
1258 orig_closed_is_present="$CLOSED_IS_PRESENT"
1259 check_closed_tree
1260 
1261 #
1262 # Note: changes to the option letters here should also be applied to the
1263 #       bldenv script.  `d' is listed for backward compatibility.
1264 #
1265 NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
1266 OPTIND=1
1267 while getopts +ABCDdFfGIilMmNnOoPpRrS:TtUuWwXxz FLAG $NIGHTLY_OPTIONS
1268 do
1269         case $FLAG in
1270           A )   A_FLAG=y
1271                 #
1272                 # If ELF_DATA_BASELINE_DIR is not defined, and we are on SWAN
1273                 # (based on CLOSED_IS_PRESENT), then refuse to run. The value
1274                 # of ELF version checking is greatly enhanced by including
1275                 # the baseline gate comparison.
1276                 if [ "$CLOSED_IS_PRESENT" = 'yes' -a \
1277                      "$ELF_DATA_BASELINE_DIR" = '' ]; then
1278                         echo "ELF_DATA_BASELINE_DIR must be set if the A" \
1279                             "flag is present in\nNIGHTLY_OPTIONS and closed" \
1280                             "sources are present. Update environment file."
1281                         exit 1;
1282                 fi
1283                 ;;
1284           B )   D_FLAG=y
1285                 ;; # old version of D
1286           C )   C_FLAG=y
1287                 ;;
1288           D )   D_FLAG=y
1289                 ;;
1290           F )   F_FLAG=y
1291                 ;;
1292           f )   f_FLAG=y
1293                 ;;
1294           G )   u_FLAG=y
1295                 ;;
1296           I )   m_FLAG=y
1297                 p_FLAG=y
1298                 u_FLAG=y
1299                 ;;
1300           i )   i_FLAG=y
1301                 ;;
1302           l )   l_FLAG=y
1303                 ;;
1304           M )   M_FLAG=y
1305                 ;;
1306           m )   m_FLAG=y
1307                 ;;
1308           N )   N_FLAG=y
1309                 ;;
1310           n )   n_FLAG=y
1311                 ;;
1312           O )   O_FLAG=y
1313                 ;;
1314           o )   o_FLAG=y
1315                 ;;
1316           P )   P_FLAG=y
1317                 ;; # obsolete
1318           p )   p_FLAG=y
1319                 ;;
1320           R )   m_FLAG=y
1321                 p_FLAG=y
1322                 ;;
1323           r )   r_FLAG=y
1324                 ;;
1325           S )
1326                 set_S_flag $OPTARG
1327                 ;;
1328           T )   T_FLAG=y
1329                 ;; # obsolete
1330          +t )   t_FLAG=n
1331                 ;;
1332           U )   if [ -z "${PARENT_ROOT}" ]; then
1333                         echo "PARENT_ROOT must be set if the U flag is" \
1334                             "present in NIGHTLY_OPTIONS."
1335                         exit 1
1336                 fi
1337                 NIGHTLY_PARENT_ROOT=$PARENT_ROOT
1338                 if [ -n "${PARENT_TOOLS_ROOT}" ]; then
1339                         NIGHTLY_PARENT_TOOLS_ROOT=$PARENT_TOOLS_ROOT
1340                 fi
1341                 U_FLAG=y
1342                 ;;
1343           u )   u_FLAG=y
1344                 ;;
1345           W )   W_FLAG=y
1346                 ;;
1347 
1348           w )   w_FLAG=y
1349                 ;;
1350           X )   # now that we no longer need realmode builds, just
1351                 # copy IHV packages.  only meaningful on x86.
1352                 if [ "$MACH" = "i386" ]; then
1353                         X_FLAG=y
1354                 fi
1355                 ;;
1356           x )   XMOD_OPT="-x"
1357                 ;;
1358          \? )   echo "$USAGE"
1359                 exit 1
1360                 ;;
1361         esac
1362 done
1363 
1364 if [ $ISUSER -ne 0 ]; then
1365         if [ "$o_FLAG" = "y" ]; then
1366                 echo "Old-style build requires root permission."
1367                 exit 1
1368         fi
1369 
1370         # Set default value for STAFFER, if needed.
1371         if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
1372                 STAFFER=`/usr/xpg4/bin/id -un`
1373                 export STAFFER
1374         fi
1375 fi
1376 
1377 if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
1378         MAILTO=$STAFFER
1379         export MAILTO
1380 fi
1381 
1382 PATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
1383 PATH="$PATH:$OPTHOME/SUNWspro/bin:$TEAMWARE/bin:/usr/bin:/usr/sbin:/usr/ucb"
1384 PATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
1385 export PATH
1386 
1387 # roots of source trees, both relative to $SRC and absolute.
1388 relsrcdirs="."
1389 if [[ -d $CODEMGR_WS/usr/closed && "$CLOSED_IS_PRESENT" != no ]]; then
1390         relsrcdirs="$relsrcdirs ../closed"
1391 fi
1392 abssrcdirs=""
1393 for d in $relsrcdirs; do
1394         abssrcdirs="$abssrcdirs $SRC/$d"
1395 done
1396 
1397 unset CH
1398 if [ "$o_FLAG" = "y" ]; then
1399 # root invoked old-style build -- make sure it works as it always has
1400 # by exporting 'CH'.  The current Makefile.master doesn't use this, but
1401 # the old ones still do.
1402         PROTOCMPTERSE="protocmp.terse"
1403         CH=
1404         export CH
1405 else
1406         PROTOCMPTERSE="protocmp.terse -gu"
1407 fi
1408 POUND_SIGN="#"
1409 # have we set RELEASE_DATE in our env file?
1410 if [ -z "$RELEASE_DATE" ]; then
1411         RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
1412 fi
1413 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
1414 BASEWSDIR=$(basename $CODEMGR_WS)
1415 DEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
1416 
1417 # we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
1418 # by avoiding repeated shell invocations to evaluate Makefile.master definitions.
1419 # we export o_FLAG and X_FLAG for use by makebfu, and by usr/src/pkg/Makefile
1420 export o_FLAG X_FLAG POUND_SIGN RELEASE_DATE DEV_CM
1421 
1422 maketype="distributed"
1423 MAKE=dmake
1424 # get the dmake version string alone
1425 DMAKE_VERSION=$( $MAKE -v )
1426 DMAKE_VERSION=${DMAKE_VERSION#*: }
1427 # focus in on just the dotted version number alone
1428 DMAKE_MAJOR=$( echo $DMAKE_VERSION | \
1429         sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
1430 # extract the second (or final) integer
1431 DMAKE_MINOR=${DMAKE_MAJOR#*.}
1432 DMAKE_MINOR=${DMAKE_MINOR%%.*}
1433 # extract the first integer
1434 DMAKE_MAJOR=${DMAKE_MAJOR%%.*}
1435 CHECK_DMAKE=${CHECK_DMAKE:-y}
1436 # x86 was built on the 12th, sparc on the 13th.
1437 if [ "$CHECK_DMAKE" = "y" -a \
1438      "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
1439      "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
1440      "$DMAKE_MAJOR" -lt 7 -o \
1441      "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
1442         if [ -z "$DMAKE_VERSION" ]; then
1443                 echo "$MAKE is missing."
1444                 exit 1
1445         fi
1446         echo `whence $MAKE`" version is:"
1447         echo "  ${DMAKE_VERSION}"
1448         cat <<EOF
1449 
1450 This version may not be safe for use.  Either set TEAMWARE to a better
1451 path or (if you really want to use this version of dmake anyway), add
1452 the following to your environment to disable this check:
1453 
1454   CHECK_DMAKE=n
1455 EOF
1456         exit 1
1457 fi
1458 export PATH
1459 export MAKE
1460 
1461 if [[ "$O_FLAG" = y ]]; then
1462         export TONICBUILD=""
1463 else
1464         export TONICBUILD="#"
1465 fi
1466 
1467 if [ "${SUNWSPRO}" != "" ]; then
1468         PATH="${SUNWSPRO}/bin:$PATH"
1469         export PATH
1470 fi
1471 
1472 hostname=$(uname -n)
1473 if [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
1474 then
1475         maxjobs=
1476         if [[ -f $HOME/.make.machines ]]
1477         then
1478                 # Note: there is a hard tab and space character in the []s
1479                 # below.
1480                 egrep -i "^[    ]*$hostname[    \.]" \
1481                         $HOME/.make.machines | read host jobs
1482                 maxjobs=${jobs##*=}
1483         fi
1484 
1485         if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
1486         then
1487                 # default
1488                 maxjobs=4
1489         fi
1490 
1491         export DMAKE_MAX_JOBS=$maxjobs
1492 fi
1493 
1494 DMAKE_MODE=parallel;
1495 export DMAKE_MODE
1496 
1497 if [ -z "${ROOT}" ]; then
1498         echo "ROOT must be set."
1499         exit 1
1500 fi
1501 
1502 #
1503 # if -V flag was given, reset VERSION to V_ARG
1504 #
1505 if [ "$V_FLAG" = "y" ]; then
1506         VERSION=$V_ARG
1507 fi
1508 
1509 #
1510 # Check for IHV root for copying ihv proto area
1511 #
1512 if [ "$X_FLAG" = "y" ]; then
1513         if [ "$IA32_IHV_ROOT" = "" ]; then
1514                 echo "IA32_IHV_ROOT: must be set for copying ihv proto"
1515                 args_ok=n
1516         fi
1517         if [ ! -d "$IA32_IHV_ROOT" ]; then
1518                 echo "$IA32_IHV_ROOT: not found"
1519                 args_ok=n
1520         fi
1521         if [ "$IA32_IHV_WS" = "" ]; then
1522                 echo "IA32_IHV_WS: must be set for copying ihv proto"
1523                 args_ok=n
1524         fi
1525         if [ ! -d "$IA32_IHV_WS" ]; then
1526                 echo "$IA32_IHV_WS: not found"
1527                 args_ok=n
1528         fi
1529 fi
1530 
1531 # Append source version
1532 if [ "$SE_FLAG" = "y" ]; then
1533         VERSION="${VERSION}:EXPORT"
1534 fi
1535 
1536 if [ "$SD_FLAG" = "y" ]; then
1537         VERSION="${VERSION}:DOMESTIC"
1538 fi
1539 
1540 if [ "$SH_FLAG" = "y" ]; then
1541         VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
1542 fi
1543 
1544 if [ "$SO_FLAG" = "y" ]; then
1545         VERSION="${VERSION}:OPEN_ONLY"
1546 fi
1547 
1548 TMPDIR="/tmp/nightly.tmpdir.$$"
1549 export TMPDIR
1550 rm -rf ${TMPDIR}
1551 mkdir -p $TMPDIR || exit 1
1552 chmod 777 $TMPDIR
1553 
1554 #
1555 # Keep elfsign's use of pkcs11_softtoken from looking in the user home
1556 # directory, which doesn't always work.   Needed until all build machines
1557 # have the fix for 6271754
1558 #
1559 SOFTTOKEN_DIR=$TMPDIR
1560 export SOFTTOKEN_DIR
1561 
1562 #
1563 # Tools should only be built non-DEBUG.  Keep track of the tools proto
1564 # area path relative to $TOOLS, because the latter changes in an
1565 # export build.
1566 #
1567 # TOOLS_PROTO is included below for builds other than usr/src/tools
1568 # that look for this location.  For usr/src/tools, this will be
1569 # overridden on the $MAKE command line in build_tools().
1570 #
1571 TOOLS=${SRC}/tools
1572 TOOLS_PROTO_REL=proto/root_${MACH}-nd
1573 TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL};        export TOOLS_PROTO
1574 
1575 unset   CFLAGS LD_LIBRARY_PATH LDFLAGS
1576 
1577 # create directories that are automatically removed if the nightly script
1578 # fails to start correctly
1579 function newdir {
1580         dir=$1
1581         toadd=
1582         while [ ! -d $dir ]; do
1583                 toadd="$dir $toadd"
1584                 dir=`dirname $dir`
1585         done
1586         torm=
1587         newlist=
1588         for dir in $toadd; do
1589                 if staffer mkdir $dir; then
1590                         newlist="$ISUSER $dir $newlist"
1591                         torm="$dir $torm"
1592                 else
1593                         [ -z "$torm" ] || staffer rmdir $torm
1594                         return 1
1595                 fi
1596         done
1597         newdirlist="$newlist $newdirlist"
1598         return 0
1599 }
1600 newdirlist=
1601 
1602 [ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
1603 
1604 # since this script assumes the build is from full source, it nullifies
1605 # variables likely to have been set by a "ws" script; nullification
1606 # confines the search space for headers and libraries to the proto area
1607 # built from this immediate source.
1608 ENVLDLIBS1=
1609 ENVLDLIBS2=
1610 ENVLDLIBS3=
1611 ENVCPPFLAGS1=
1612 ENVCPPFLAGS2=
1613 ENVCPPFLAGS3=
1614 ENVCPPFLAGS4=
1615 PARENT_ROOT=
1616 
1617 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
1618         PARENT_ROOT
1619 
1620 PKGARCHIVE_ORIG=$PKGARCHIVE
1621 IA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
1622 
1623 #
1624 # Juggle the logs and optionally send mail on completion.
1625 #
1626 
1627 function logshuffle {
1628         LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
1629         if [ -f $LLOG -o -d $LLOG ]; then
1630                 LLOG=$LLOG.$$
1631         fi
1632         mkdir $LLOG
1633         export LLOG
1634 
1635         if [ "$build_ok" = "y" ]; then
1636                 mv $ATLOG/proto_list_${MACH} $LLOG
1637 
1638                 if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
1639                         mv $ATLOG/proto_list_tools_${MACH} $LLOG
1640                 fi
1641 
1642                 if [ -f $TMPDIR/wsdiff.results ]; then
1643                         mv $TMPDIR/wsdiff.results $LLOG
1644                 fi
1645 
1646                 if [ -f $TMPDIR/wsdiff-nd.results ]; then
1647                         mv $TMPDIR/wsdiff-nd.results $LLOG
1648                 fi
1649         fi
1650 
1651         #
1652         # Now that we're about to send mail, it's time to check the noise
1653         # file.  In the event that an error occurs beyond this point, it will
1654         # be recorded in the nightly.log file, but nowhere else.  This would
1655         # include only errors that cause the copying of the noise log to fail
1656         # or the mail itself not to be sent.
1657         #
1658 
1659         exec >>$LOGFILE 2>&1
1660         if [ -s $build_noise_file ]; then
1661                 echo "\n==== Nightly build noise ====\n" |
1662                     tee -a $LOGFILE >>$mail_msg_file
1663                 cat $build_noise_file >>$LOGFILE
1664                 cat $build_noise_file >>$mail_msg_file
1665                 echo | tee -a $LOGFILE >>$mail_msg_file
1666         fi
1667         rm -f $build_noise_file
1668 
1669         case "$build_ok" in
1670                 y)
1671                         state=Completed
1672                         ;;
1673                 i)
1674                         state=Interrupted
1675                         ;;
1676                 *)
1677                         state=Failed
1678                         ;;
1679         esac
1680         NIGHTLY_STATUS=$state
1681         export NIGHTLY_STATUS
1682 
1683         run_hook POST_NIGHTLY $state
1684         run_hook SYS_POST_NIGHTLY $state
1685 
1686         #
1687         # mailx(1) sets From: based on the -r flag
1688         # if it is given.
1689         #
1690         mailx_r=
1691         if [[ -n "${MAILFROM}" ]]; then
1692                 mailx_r="-r ${MAILFROM}"
1693         fi
1694 
1695         cat $build_time_file $build_environ_file $mail_msg_file \
1696             > ${LLOG}/mail_msg
1697         if [ "$m_FLAG" = "y" ]; then
1698                 cat ${LLOG}/mail_msg | /usr/bin/mailx ${mailx_r} -s \
1699         "Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
1700                         ${MAILTO}
1701         fi
1702 
1703         if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
1704                 staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
1705                 staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
1706         fi
1707 
1708         mv $LOGFILE $LLOG
1709 }
1710 
1711 #
1712 #       Remove the locks and temporary files on any exit
1713 #
1714 function cleanup {
1715         logshuffle
1716 
1717         [ -z "$lockfile" ] || staffer rm -f $lockfile
1718         [ -z "$atloglockfile" ] || rm -f $atloglockfile
1719         [ -z "$ulockfile" ] || staffer rm -f $ulockfile
1720         [ -z "$Ulockfile" ] || rm -f $Ulockfile
1721 
1722         set -- $newdirlist
1723         while [ $# -gt 0 ]; do
1724                 ISUSER=$1 staffer rmdir $2
1725                 shift; shift
1726         done
1727         rm -rf $TMPDIR
1728 }
1729 
1730 function cleanup_signal {
1731         build_ok=i
1732         # this will trigger cleanup(), above.
1733         exit 1
1734 }
1735 
1736 trap cleanup 0
1737 trap cleanup_signal 1 2 3 15
1738 
1739 #
1740 # Generic lock file processing -- make sure that the lock file doesn't
1741 # exist.  If it does, it should name the build host and PID.  If it
1742 # doesn't, then make sure we can create it.  Clean up locks that are
1743 # known to be stale (assumes host name is unique among build systems
1744 # for the workspace).
1745 #
1746 function create_lock {
1747         lockf=$1
1748         lockvar=$2
1749 
1750         ldir=`dirname $lockf`
1751         [ -d $ldir ] || newdir $ldir || exit 1
1752         eval $lockvar=$lockf
1753 
1754         while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
1755                 basews=`basename $CODEMGR_WS`
1756                 ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
1757                 if [ "$host" != "$hostname" ]; then
1758                         echo "$MACH build of $basews apparently" \
1759                             "already started by $user on $host as $pid."
1760                         exit 1
1761                 elif kill -s 0 $pid 2>/dev/null; then
1762                         echo "$MACH build of $basews already started" \
1763                             "by $user as $pid."
1764                         exit 1
1765                 else
1766                         # stale lock; clear it out and try again
1767                         rm -f $lockf
1768                 fi
1769         done
1770 }
1771 
1772 #
1773 # Return the list of interesting proto areas, depending on the current
1774 # options.
1775 #
1776 function allprotos {
1777         typeset roots="$ROOT"
1778 
1779         if [[ "$F_FLAG" = n && "$MULTI_PROTO" = yes ]]; then
1780                 roots="$roots $ROOT-nd"
1781         fi
1782 
1783         if [[ $O_FLAG = y ]]; then
1784                 roots="$roots $ROOT-closed"
1785                 [ $MULTI_PROTO = yes ] && roots="$roots $ROOT-nd-closed"
1786         fi
1787 
1788         echo $roots
1789 }
1790 
1791 # Ensure no other instance of this script is running on this host.
1792 # LOCKNAME can be set in <env_file>, and is by default, but is not
1793 # required due to the use of $ATLOG below.
1794 if [ -n "$LOCKNAME" ]; then
1795         create_lock /tmp/$LOCKNAME "lockfile"
1796 fi
1797 #
1798 # Create from one, two, or three other locks:
1799 #       $ATLOG/nightly.lock
1800 #               - protects against multiple builds in same workspace
1801 #       $PARENT_WS/usr/src/nightly.$MACH.lock
1802 #               - protects against multiple 'u' copy-backs
1803 #       $NIGHTLY_PARENT_ROOT/nightly.lock
1804 #               - protects against multiple 'U' copy-backs
1805 #
1806 # Overriding ISUSER to 1 causes the lock to be created as root if the
1807 # script is run as root.  The default is to create it as $STAFFER.
1808 ISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
1809 if [ "$u_FLAG" = "y" ]; then
1810         create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
1811 fi
1812 if [ "$U_FLAG" = "y" ]; then
1813         # NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
1814         ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
1815 fi
1816 
1817 # Locks have been taken, so we're doing a build and we're committed to
1818 # the directories we may have created so far.
1819 newdirlist=
1820 
1821 #
1822 # Create mail_msg_file
1823 #
1824 mail_msg_file="${TMPDIR}/mail_msg"
1825 touch $mail_msg_file
1826 build_time_file="${TMPDIR}/build_time"
1827 build_environ_file="${TMPDIR}/build_environ"
1828 touch $build_environ_file
1829 #
1830 #       Move old LOGFILE aside
1831 #       ATLOG directory already made by 'create_lock' above
1832 #
1833 if [ -f $LOGFILE ]; then
1834         mv -f $LOGFILE ${LOGFILE}-
1835 fi
1836 #
1837 #       Build OsNet source
1838 #
1839 START_DATE=`date`
1840 SECONDS=0
1841 echo "\n==== Nightly $maketype build started:   $START_DATE ====" \
1842     | tee -a $LOGFILE > $build_time_file
1843 
1844 echo "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
1845     tee -a $mail_msg_file >> $LOGFILE
1846 
1847 # make sure we log only to the nightly build file
1848 build_noise_file="${TMPDIR}/build_noise"
1849 exec </dev/null >$build_noise_file 2>&1
1850 
1851 run_hook SYS_PRE_NIGHTLY
1852 run_hook PRE_NIGHTLY
1853 
1854 echo "\n==== list of environment variables ====\n" >> $LOGFILE
1855 env >> $LOGFILE
1856 
1857 echo "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
1858 
1859 if [ "$P_FLAG" = "y" ]; then
1860         obsolete_build GPROF | tee -a $mail_msg_file >> $LOGFILE
1861 fi
1862 
1863 if [ "$T_FLAG" = "y" ]; then
1864         obsolete_build TRACE | tee -a $mail_msg_file >> $LOGFILE
1865 fi
1866 
1867 if is_source_build; then
1868         if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
1869                 echo "WARNING: the -S flags do not support incremental" \
1870                     "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
1871                 i_FLAG=n
1872                 i_CMD_LINE_FLAG=n
1873         fi
1874         if [ "$N_FLAG" = "n" ]; then
1875                 echo "WARNING: the -S flags do not support protocmp;" \
1876                     "protocmp disabled\n" | \
1877                     tee -a $mail_msg_file >> $LOGFILE
1878                 N_FLAG=y
1879         fi
1880         if [ "$l_FLAG" = "y" ]; then
1881                 echo "WARNING: the -S flags do not support lint;" \
1882                     "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
1883                 l_FLAG=n
1884         fi
1885         if [ "$C_FLAG" = "y" ]; then
1886                 echo "WARNING: the -S flags do not support cstyle;" \
1887                     "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
1888                 C_FLAG=n
1889         fi
1890 else
1891         if [ "$N_FLAG" = "y" ]; then
1892                 if [ "$p_FLAG" = "y" ]; then
1893                         cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1894 WARNING: the p option (create packages) is set, but so is the N option (do
1895          not run protocmp); this is dangerous; you should unset the N option
1896 EOF
1897                 else
1898                         cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1899 Warning: the N option (do not run protocmp) is set; it probably shouldn't be
1900 EOF
1901                 fi
1902                 echo "" | tee -a $mail_msg_file >> $LOGFILE
1903         fi
1904 fi
1905 
1906 if [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
1907         #
1908         # In the past we just complained but went ahead with the lint
1909         # pass, even though the proto area was built non-DEBUG.  It's
1910         # unlikely that non-DEBUG headers will make a difference, but
1911         # rather than assuming it's a safe combination, force the user
1912         # to specify a DEBUG build.
1913         #
1914         echo "WARNING: DEBUG build not requested; disabling lint.\n" \
1915             | tee -a $mail_msg_file >> $LOGFILE
1916         l_FLAG=n
1917 fi
1918 
1919 if [ "$f_FLAG" = "y" ]; then
1920         if [ "$i_FLAG" = "y" ]; then
1921                 echo "WARNING: the -f flag cannot be used during incremental" \
1922                     "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
1923                 f_FLAG=n
1924         fi
1925         if [ "${l_FLAG}${p_FLAG}" != "yy" ]; then
1926                 echo "WARNING: the -f flag requires -l, and -p;" \
1927                     "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
1928                 f_FLAG=n
1929         fi
1930 fi
1931 
1932 if [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
1933         echo "WARNING: -w specified, but $ROOT does not exist;" \
1934             "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
1935         w_FLAG=n
1936 fi
1937 
1938 if [ "$t_FLAG" = "n" ]; then
1939         #
1940         # We're not doing a tools build, so make sure elfsign(1) is
1941         # new enough to safely sign non-crypto binaries.  We test
1942         # debugging output from elfsign to detect the old version.
1943         #
1944         newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
1945             -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
1946             | egrep algorithmOID`
1947         if [ -z "$newelfsigntest" ]; then
1948                 echo "WARNING: /usr/bin/elfsign out of date;" \
1949                     "will only sign crypto modules\n" | \
1950                     tee -a $mail_msg_file >> $LOGFILE
1951                 export ELFSIGN_OBJECT=true
1952         elif [ "$VERIFY_ELFSIGN" = "y" ]; then
1953                 echo "WARNING: VERIFY_ELFSIGN=y requires" \
1954                     "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
1955                     tee -a $mail_msg_file >> $LOGFILE
1956         fi
1957 fi
1958 
1959 [ "$O_FLAG" = y ] && MULTI_PROTO=yes
1960 
1961 case $MULTI_PROTO in
1962 yes|no) ;;
1963 *)
1964         echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
1965             "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
1966         echo "Setting MULTI_PROTO to \"no\".\n" | \
1967             tee -a $mail_msg_file >> $LOGFILE
1968         export MULTI_PROTO=no
1969         ;;
1970 esac
1971 
1972 echo "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
1973 echo $VERSION | tee -a $mail_msg_file >> $LOGFILE
1974 
1975 # Save the current proto area if we're comparing against the last build
1976 if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
1977     if [ -d "$ROOT.prev" ]; then
1978         rm -rf $ROOT.prev
1979     fi
1980     mv $ROOT $ROOT.prev
1981 fi
1982 
1983 # Same for non-DEBUG proto area
1984 if [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
1985         if [ -d "$ROOT-nd.prev" ]; then
1986                 rm -rf $ROOT-nd.prev
1987         fi
1988         mv $ROOT-nd $ROOT-nd.prev
1989 fi
1990 
1991 #
1992 # Echo the SCM type of the parent workspace, this can't just be which_scm
1993 # as that does not know how to identify various network repositories.
1994 #
1995 function parent_wstype {
1996         typeset scm_type junk
1997 
1998         CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
1999             | read scm_type junk
2000         if [[ -z "$scm_type" || "$scm_type" == unknown ]]; then
2001                 # Probe BRINGOVER_WS to determine its type
2002                 if [[ $BRINGOVER_WS == svn*://* ]]; then
2003                         scm_type="subversion"
2004                 elif [[ $BRINGOVER_WS == file://* ]] &&
2005                     egrep -s "This is a Subversion repository" \
2006                     ${BRINGOVER_WS#file://}/README.txt 2> /dev/null; then
2007                         scm_type="subversion"
2008                 elif [[ $BRINGOVER_WS == ssh://* ]]; then
2009                         scm_type="mercurial"
2010                 elif [[ $BRINGOVER_WS == http://* ]] && \
2011                     wget -q -O- --save-headers "$BRINGOVER_WS/?cmd=heads" | \
2012                     egrep -s "application/mercurial" 2> /dev/null; then
2013                         scm_type="mercurial"
2014                 elif svn info $BRINGOVER_WS > /dev/null 2>&1; then
2015                         scm_type="subversion"
2016                 else
2017                         scm_type="none"
2018                 fi
2019         fi    
2020 
2021         # fold both unsupported and unrecognized results into "none"
2022         case "$scm_type" in
2023         none|subversion|teamware|mercurial)
2024                 ;;
2025         *)      scm_type=none
2026                 ;;
2027         esac
2028 
2029         echo $scm_type
2030 }
2031 
2032 # Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
2033 function child_wstype {
2034         typeset scm_type junk
2035 
2036         # Probe CODEMGR_WS to determine its type
2037         if [[ -d $CODEMGR_WS ]]; then
2038                 $WHICH_SCM | read scm_type junk || exit 1
2039         fi
2040 
2041         case "$scm_type" in
2042         none|subversion|git|teamware|mercurial)
2043                 ;;
2044         *)      scm_type=none
2045                 ;;
2046         esac
2047 
2048         echo $scm_type
2049 }
2050 
2051 SCM_TYPE=$(child_wstype)
2052 
2053 #
2054 #       Decide whether to clobber
2055 #
2056 if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
2057         echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
2058 
2059         cd $SRC
2060         # remove old clobber file
2061         rm -f $SRC/clobber.out
2062         rm -f $SRC/clobber-${MACH}.out
2063 
2064         # Remove all .make.state* files, just in case we are restarting
2065         # the build after having interrupted a previous 'make clobber'.
2066         find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
2067                 -o -name 'interfaces.*' \) -prune \
2068                 -o -name '.make.*' -print | xargs rm -f
2069 
2070         $MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
2071         echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
2072         grep "$MAKE:" $SRC/clobber-${MACH}.out |
2073                 egrep -v "Ignoring unknown host" \
2074                 >> $mail_msg_file
2075 
2076         if [[ "$t_FLAG" = "y" || "$O_FLAG" = "y" ]]; then
2077                 echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
2078                 cd ${TOOLS}
2079                 rm -f ${TOOLS}/clobber-${MACH}.out
2080                 $MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \
2081                         tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
2082                 echo "\n==== Make tools clobber ERRORS ====\n" \
2083                         >> $mail_msg_file
2084                 grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
2085                         >> $mail_msg_file
2086                 rm -rf ${TOOLS_PROTO}
2087                 mkdir -p ${TOOLS_PROTO}
2088         fi
2089 
2090         typeset roots=$(allprotos)
2091         echo "\n\nClearing $roots" >> "$LOGFILE"
2092         rm -rf $roots
2093 
2094         # Get back to a clean workspace as much as possible to catch
2095         # problems that only occur on fresh workspaces.
2096         # Remove all .make.state* files, libraries, and .o's that may
2097         # have been omitted from clobber.  A couple of libraries are
2098         # under source code control, so leave them alone.
2099         # We should probably blow away temporary directories too.
2100         cd $SRC
2101         find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
2102             -o -name .git -o -name 'interfaces.*' \) -prune -o \
2103             \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
2104                -name '*.o' \) -print | \
2105             grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
2106 else
2107         echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
2108 fi
2109 
2110 type bringover_teamware > /dev/null 2>&1 || function bringover_teamware {
2111         # sleep on the parent workspace's lock
2112         while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
2113         do
2114                 sleep 120
2115         done
2116 
2117         if [[ -z $BRINGOVER ]]; then
2118                 BRINGOVER=$TEAMWARE/bin/bringover
2119         fi
2120 
2121         staffer $BRINGOVER -c "nightly update" -p $BRINGOVER_WS \
2122             -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 ||
2123                 touch $TMPDIR/bringover_failed
2124 
2125         staffer bringovercheck $CODEMGR_WS >$TMPDIR/bringovercheck.out 2>&1
2126         if [ -s $TMPDIR/bringovercheck.out ]; then
2127                 echo "\n==== POST-BRINGOVER CLEANUP NOISE ====\n"
2128                 cat $TMPDIR/bringovercheck.out
2129         fi
2130 }
2131 
2132 type bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
2133         typeset -x PATH=$PATH
2134 
2135         # If the repository doesn't exist yet, then we want to populate it.
2136         if [[ ! -d $CODEMGR_WS/.hg ]]; then
2137                 staffer hg init $CODEMGR_WS
2138                 staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
2139                 staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
2140                 touch $TMPDIR/new_repository
2141         fi
2142 
2143         #
2144         # If the user set CLOSED_BRINGOVER_WS and didn't set CLOSED_IS_PRESENT
2145         # to "no," then we'll want to initialise the closed repository
2146         #
2147         # We use $orig_closed_is_present instead of $CLOSED_IS_PRESENT,
2148         # because for newly-created source trees, the latter will be "no"
2149         # until after the bringover completes.
2150         #
2151         if [[ "$orig_closed_is_present" != "no" && \
2152             -n "$CLOSED_BRINGOVER_WS" && \
2153             ! -d $CODEMGR_WS/usr/closed/.hg ]]; then
2154                 staffer mkdir -p $CODEMGR_WS/usr/closed
2155                 staffer hg init $CODEMGR_WS/usr/closed
2156                 staffer echo "[paths]" > $CODEMGR_WS/usr/closed/.hg/hgrc
2157                 staffer echo "default=$CLOSED_BRINGOVER_WS" >> $CODEMGR_WS/usr/closed/.hg/hgrc
2158                 touch $TMPDIR/new_closed
2159                 export CLOSED_IS_PRESENT=yes
2160         fi
2161 
2162         typeset -x HGMERGE="/bin/false"
2163 
2164         #
2165         # If the user has changes, regardless of whether those changes are
2166         # committed, and regardless of whether those changes conflict, then
2167         # we'll attempt to merge them either implicitly (uncommitted) or
2168         # explicitly (committed).
2169         #
2170         # These are the messages we'll use to help clarify mercurial output
2171         # in those cases.
2172         #
2173         typeset mergefailmsg="\
2174 ***\n\
2175 *** nightly was unable to automatically merge your changes.  You should\n\
2176 *** redo the full merge manually, following the steps outlined by mercurial\n\
2177 *** above, then restart nightly.\n\
2178 ***\n"
2179         typeset mergepassmsg="\
2180 ***\n\
2181 *** nightly successfully merged your changes.  This means that your working\n\
2182 *** directory has been updated, but those changes are not yet committed.\n\
2183 *** After nightly completes, you should validate the results of the merge,\n\
2184 *** then use hg commit manually.\n\
2185 ***\n"
2186 
2187         #
2188         # For each repository in turn:
2189         #
2190         # 1. Do the pull.  If this fails, dump the output and bail out.
2191         #
2192         # 2. If the pull resulted in an extra head, do an explicit merge.
2193         #    If this fails, dump the output and bail out.
2194         #
2195         # Because we can't rely on Mercurial to exit with a failure code
2196         # when a merge fails (Mercurial issue #186), we must grep the
2197         # output of pull/merge to check for attempted and/or failed merges.
2198         #
2199         # 3. If a merge failed, set the message and fail the bringover.
2200         #
2201         # 4. Otherwise, if a merge succeeded, set the message
2202         #
2203         # 5. Dump the output, and any message from step 3 or 4.
2204         #
2205 
2206         typeset HG_SOURCE=$BRINGOVER_WS
2207         if [ ! -f $TMPDIR/new_repository ]; then
2208                 HG_SOURCE=$TMPDIR/open_bundle.hg
2209                 staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
2210                     -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
2211 
2212                 #
2213                 # If there are no incoming changesets, then incoming will
2214                 # fail, and there will be no bundle file.  Reset the source,
2215                 # to allow the remaining logic to complete with no false
2216                 # negatives.  (Unlike incoming, pull will return success
2217                 # for the no-change case.)
2218                 #
2219                 if (( $? != 0 )); then
2220                         HG_SOURCE=$BRINGOVER_WS
2221                 fi
2222         fi
2223 
2224         staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
2225             > $TMPDIR/pull_open.out 2>&1
2226         if (( $? != 0 )); then
2227                 printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
2228                 cat $TMPDIR/pull_open.out
2229                 if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
2230                         printf "$mergefailmsg"
2231                 fi
2232                 touch $TMPDIR/bringover_failed
2233                 return
2234         fi
2235 
2236         if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
2237                 staffer hg --cwd $CODEMGR_WS merge \
2238                     >> $TMPDIR/pull_open.out 2>&1
2239                 if (( $? != 0 )); then
2240                         printf "%s: merge failed as follows:\n\n" \
2241                             "$CODEMGR_WS"
2242                         cat $TMPDIR/pull_open.out
2243                         if grep "^merging.*failed" $TMPDIR/pull_open.out \
2244                             > /dev/null 2>&1; then
2245                                 printf "$mergefailmsg"
2246                         fi
2247                         touch $TMPDIR/bringover_failed
2248                         return
2249                 fi
2250         fi
2251 
2252         printf "updated %s with the following results:\n" "$CODEMGR_WS"
2253         cat $TMPDIR/pull_open.out
2254         if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
2255                 printf "$mergepassmsg"
2256         fi
2257         printf "\n"
2258 
2259         #
2260         # We only want to update usr/closed if it exists, and we haven't been
2261         # told not to via $CLOSED_IS_PRESENT, and we actually know where to
2262         # pull from ($CLOSED_BRINGOVER_WS).
2263         #
2264         if [[ $CLOSED_IS_PRESENT = yes && \
2265             -d $CODEMGR_WS/usr/closed/.hg && \
2266             -n $CLOSED_BRINGOVER_WS ]]; then
2267 
2268                 HG_SOURCE=$CLOSED_BRINGOVER_WS
2269                 if [ ! -f $TMPDIR/new_closed ]; then
2270                         HG_SOURCE=$TMPDIR/closed_bundle.hg
2271                         staffer hg --cwd $CODEMGR_WS/usr/closed incoming \
2272                             --bundle $HG_SOURCE -v $CLOSED_BRINGOVER_WS \
2273                             > $TMPDIR/incoming_closed.out
2274 
2275                         #
2276                         # If there are no incoming changesets, then incoming will
2277                         # fail, and there will be no bundle file.  Reset the source,
2278                         # to allow the remaining logic to complete with no false
2279                         # negatives.  (Unlike incoming, pull will return success
2280                         # for the no-change case.)
2281                         #
2282                         if (( $? != 0 )); then
2283                                 HG_SOURCE=$CLOSED_BRINGOVER_WS
2284                         fi
2285                 fi
2286 
2287                 staffer hg --cwd $CODEMGR_WS/usr/closed pull -u \
2288                         $HG_SOURCE > $TMPDIR/pull_closed.out 2>&1
2289                 if (( $? != 0 )); then
2290                         printf "closed pull failed as follows:\n\n"
2291                         cat $TMPDIR/pull_closed.out
2292                         if grep "^merging.*failed" $TMPDIR/pull_closed.out \
2293                             > /dev/null 2>&1; then
2294                                 printf "$mergefailmsg"
2295                         fi
2296                         touch $TMPDIR/bringover_failed
2297                         return
2298                 fi
2299 
2300                 if grep "not updating" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
2301                         staffer hg --cwd $CODEMGR_WS/usr/closed merge \
2302                             >> $TMPDIR/pull_closed.out 2>&1
2303                         if (( $? != 0 )); then
2304                                 printf "closed merge failed as follows:\n\n"
2305                                 cat $TMPDIR/pull_closed.out
2306                                 if grep "^merging.*failed" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
2307                                         printf "$mergefailmsg"
2308                                 fi
2309                                 touch $TMPDIR/bringover_failed
2310                                 return
2311                         fi
2312                 fi
2313 
2314                 printf "updated %s with the following results:\n" \
2315                     "$CODEMGR_WS/usr/closed"
2316                 cat $TMPDIR/pull_closed.out
2317                 if grep "^merging" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
2318                         printf "$mergepassmsg"
2319                 fi
2320         fi
2321 
2322         #
2323         # Per-changeset output is neither useful nor manageable for a
2324         # newly-created repository.
2325         #
2326         if [ -f $TMPDIR/new_repository ]; then
2327                 return
2328         fi
2329 
2330         printf "\nadded the following changesets to open repository:\n"
2331         cat $TMPDIR/incoming_open.out
2332 
2333         #
2334         # The closed repository could have been newly created, even though
2335         # the open one previously existed...
2336         #
2337         if [ -f $TMPDIR/new_closed ]; then
2338                 return
2339         fi
2340 
2341         if [ -f $TMPDIR/incoming_closed.out ]; then
2342                 printf "\nadded the following changesets to closed repository:\n"
2343                 cat $TMPDIR/incoming_closed.out
2344         fi
2345 }
2346 
2347 type bringover_subversion > /dev/null 2>&1 || function bringover_subversion {
2348         typeset -x PATH=$PATH
2349 
2350         if [[ ! -d $CODEMGR_WS/.svn ]]; then
2351                 staffer svn checkout $BRINGOVER_WS $CODEMGR_WS ||
2352                         touch $TMPDIR/bringover_failed
2353         else
2354                 typeset root
2355                 root=$(staffer svn info $CODEMGR_WS |
2356                         nawk '/^Repository Root:/ {print $NF}')
2357                 if [[ $root != $BRINGOVER_WS ]]; then
2358                         # We fail here because there's no way to update
2359                         # from a named repo.
2360                         cat <<-EOF
2361                         \$BRINGOVER_WS doesn't match repository root:
2362                           \$BRINGOVER_WS:  $BRINGOVER_WS
2363                           Repository root: $root
2364                         EOF
2365                         touch $TMPDIR/bringover_failed
2366                 else
2367                         # If a conflict happens, svn still exits 0.
2368                         staffer svn update $CODEMGR_WS | tee $TMPDIR/pull.out ||
2369                                 touch $TMPDIR/bringover_failed
2370                         if grep "^C" $TMPDIR/pull.out > /dev/null 2>&1; then
2371                                 touch $TMPDIR/bringover_failed
2372                         fi
2373                 fi
2374         fi
2375 }
2376 
2377 type bringover_none > /dev/null 2>&1 || function bringover_none {
2378         echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
2379         touch $TMPDIR/bringover_failed
2380 }
2381 
2382 #
2383 #       Decide whether to bringover to the codemgr workspace
2384 #
2385 if [ "$n_FLAG" = "n" ]; then
2386         PARENT_SCM_TYPE=$(parent_wstype)
2387 
2388         if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
2389                 echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
2390                     "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
2391                 exit 1
2392         fi
2393 
2394         run_hook PRE_BRINGOVER
2395 
2396         echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
2397         echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
2398 
2399         eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
2400                 tee -a $mail_msg_file >> $LOGFILE
2401 
2402         if [ -f $TMPDIR/bringover_failed ]; then
2403                 rm -f $TMPDIR/bringover_failed
2404                 build_ok=n
2405                 echo "trouble with bringover, quitting at `date`." |
2406                         tee -a $mail_msg_file >> $LOGFILE
2407                 exit 1
2408         fi
2409 
2410         #
2411         # It's possible that we used the bringover above to create
2412         # $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
2413         # but should now be the same as $BRINGOVER_WS.
2414         #
2415         [[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
2416 
2417         run_hook POST_BRINGOVER
2418 
2419         #
2420         # Possible transition from pre-split workspace to split
2421         # workspace.  See if the bringover changed anything.
2422         #
2423         CLOSED_IS_PRESENT="$orig_closed_is_present"
2424         check_closed_tree
2425 
2426 else
2427         echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
2428 fi
2429 
2430 if [[ "$O_FLAG" = y && "$CLOSED_IS_PRESENT" != "yes" ]]; then
2431         build_ok=n
2432         echo "OpenSolaris binary deliverables need usr/closed." \
2433             | tee -a "$mail_msg_file" >> $LOGFILE
2434         exit 1
2435 fi
2436 
2437 # Safeguards
2438 [[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
2439 [[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory."
2440 [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
2441 
2442 echo "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
2443 
2444 # System
2445 whence uname | tee -a $build_environ_file >> $LOGFILE
2446 uname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
2447 echo | tee -a $build_environ_file >> $LOGFILE
2448 
2449 # make
2450 whence $MAKE | tee -a $build_environ_file >> $LOGFILE
2451 $MAKE -v | tee -a $build_environ_file >> $LOGFILE
2452 echo "number of concurrent jobs = $DMAKE_MAX_JOBS" |
2453     tee -a $build_environ_file >> $LOGFILE
2454 
2455 #
2456 # Report the compiler versions.
2457 #
2458 
2459 if [[ ! -f $SRC/Makefile ]]; then
2460         build_ok=n
2461         echo "\nUnable to find \"Makefile\" in $SRC." | \
2462             tee -a $build_environ_file >> $LOGFILE
2463         exit 1
2464 fi
2465 
2466 ( cd $SRC
2467   for target in cc-version cc64-version java-version; do
2468         echo
2469         #
2470         # Put statefile somewhere we know we can write to rather than trip
2471         # over a read-only $srcroot.
2472         #
2473         rm -f $TMPDIR/make-state
2474         export SRC
2475         if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
2476                 continue
2477         fi
2478         touch $TMPDIR/nocompiler
2479   done
2480   echo
2481 ) | tee -a $build_environ_file >> $LOGFILE
2482 
2483 if [ -f $TMPDIR/nocompiler ]; then
2484         rm -f $TMPDIR/nocompiler
2485         build_ok=n
2486         echo "Aborting due to missing compiler." |
2487                 tee -a $build_environ_file >> $LOGFILE
2488         exit 1
2489 fi
2490 
2491 # as
2492 whence as | tee -a $build_environ_file >> $LOGFILE
2493 as -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
2494 echo | tee -a $build_environ_file >> $LOGFILE
2495 
2496 # Check that we're running a capable link-editor
2497 whence ld | tee -a $build_environ_file >> $LOGFILE
2498 LDVER=`ld -V 2>&1`
2499 echo $LDVER | tee -a $build_environ_file >> $LOGFILE
2500 LDVER=`echo $LDVER | sed -e "s/.*-1\.\([0-9]*\).*/\1/"`
2501 if [ `expr $LDVER \< 422` -eq 1 ]; then
2502         echo "The link-editor needs to be at version 422 or higher to build" | \
2503             tee -a $build_environ_file >> $LOGFILE
2504         echo "the latest stuff.  Hope your build works." | \
2505             tee -a $build_environ_file >> $LOGFILE
2506 fi
2507 
2508 #
2509 # Build and use the workspace's tools if requested
2510 #
2511 if [[ "$t_FLAG" = "y" || "$O_FLAG" = y ]]; then
2512         set_non_debug_build_flags
2513 
2514         build_tools ${TOOLS_PROTO}
2515         if [[ $? != 0  && "$t_FLAG" = y ]]; then
2516                 use_tools $TOOLS_PROTO
2517         fi
2518 fi
2519 
2520 #
2521 # copy ihv proto area in addition to the build itself
2522 #
2523 if [ "$X_FLAG" = "y" ]; then
2524         copy_ihv_proto
2525 fi
2526 
2527 if [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
2528         echo "\n==== NOT Building base OS-Net source ====\n" | \
2529             tee -a $LOGFILE >> $mail_msg_file
2530 else
2531         # timestamp the start of the normal build; the findunref tool uses it.
2532         touch $SRC/.build.tstamp
2533 
2534         normal_build
2535 fi
2536 
2537 #
2538 # Generate the THIRDPARTYLICENSE files if needed.  This is done after
2539 # the build, so that dynamically-created license files are there.
2540 # It's done before findunref to help identify license files that need
2541 # to be added to tools/opensolaris/license-list.
2542 #
2543 if [ "$O_FLAG" = y -a "$build_ok" = y ]; then
2544         echo "\n==== Generating THIRDPARTYLICENSE files ====\n" |
2545             tee -a "$mail_msg_file" >> "$LOGFILE"
2546 
2547         if [ -d $ROOT/licenses/usr ]; then
2548                 ( cd $ROOT/licenses ; \
2549                     mktpl $SRC/pkg/license-list ) >> "$LOGFILE" 2>&1
2550                 if (( $? != 0 )) ; then
2551                         echo "Couldn't create THIRDPARTYLICENSE files" |
2552                             tee -a "$mail_msg_file" >> "$LOGFILE"
2553                 fi
2554         else
2555                 echo "No licenses found under $ROOT/licenses" |
2556                     tee -a "$mail_msg_file" >> "$LOGFILE"
2557         fi
2558 fi
2559 
2560 ORIG_SRC=$SRC
2561 BINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
2562 
2563 if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
2564         save_binaries
2565 fi
2566 
2567 
2568 # EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
2569 # $SRC pointing to the export_source usr/src.
2570 
2571 if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
2572         if [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
2573             set_up_source_build ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
2574         fi
2575 
2576         if [ $build_ok = y ]; then
2577             set_up_source_build ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
2578         fi
2579 fi
2580 
2581 if [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
2582         # drop the crypt files in place.
2583         cd ${EXPORT_SRC}
2584         echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
2585             >> ${LOGFILE}
2586         zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
2587             cpio -idmucvB 2>/dev/null >> ${LOGFILE}
2588         if [ "$?" = "0" ]; then
2589                 echo "\n==== DOMESTIC extraction succeeded ====\n" \
2590                     >> $mail_msg_file
2591         else
2592                 echo "\n==== DOMESTIC extraction failed ====\n" \
2593                     >> $mail_msg_file
2594         fi
2595 
2596 fi
2597 
2598 if [ "$SO_FLAG" = "y" -a "$build_ok" = y ]; then
2599         #
2600         # Copy the open sources into their own tree.
2601         # If copy_source fails, it will have already generated an
2602         # error message and set build_ok=n, so we don't need to worry
2603         # about that here.
2604         #
2605         copy_source $CODEMGR_WS $OPEN_SRCDIR OPEN_SOURCE usr/src
2606 fi
2607 
2608 if [ "$SO_FLAG" = "y" -a "$build_ok" = y ]; then
2609         SRC=$OPEN_SRCDIR/usr/src
2610         export CLOSED_IS_PRESENT=no
2611 fi
2612 
2613 if is_source_build && [ $build_ok = y ] ; then
2614         # remove proto area(s) here, since we don't clobber
2615         rm -rf `allprotos`
2616         if [ "$t_FLAG" = "y" ]; then
2617                 set_non_debug_build_flags
2618                 ORIG_TOOLS=$TOOLS
2619                 #
2620                 # SRC was set earlier to point to the source build
2621                 # source tree (e.g., $EXPORT_SRC).
2622                 #
2623                 TOOLS=${SRC}/tools
2624                 TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
2625                 build_tools ${TOOLS_PROTO}
2626                 if [[ $? != 0 ]]; then
2627                         use_tools ${TOOLS_PROTO}
2628                 fi
2629         fi
2630 
2631         normal_build
2632 fi
2633 
2634 #
2635 # There are several checks that need to look at the proto area, but
2636 # they only need to look at one, and they don't care whether it's
2637 # DEBUG or non-DEBUG.
2638 #
2639 if [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
2640         checkroot=$ROOT-nd
2641 else
2642         checkroot=$ROOT
2643 fi
2644 
2645 if [ "$build_ok" = "y" ]; then
2646         echo "\n==== Creating protolist system file at `date` ====" \
2647                 >> $LOGFILE
2648         protolist $checkroot > $ATLOG/proto_list_${MACH}
2649         echo "==== protolist system file created at `date` ====\n" \
2650                 >> $LOGFILE
2651 
2652         if [ "$N_FLAG" != "y" ]; then
2653 
2654                 E1=
2655                 f1=
2656                 if [ -d "$SRC/pkgdefs" ]; then
2657                         f1="$SRC/pkgdefs/etc/exception_list_$MACH"
2658                         if [ "$X_FLAG" = "y" ]; then
2659                                 f1="$f1 $IA32_IHV_WS/usr/src/pkgdefs/etc/exception_list_$MACH"
2660                         fi
2661                 fi
2662 
2663                 for f in $f1; do
2664                         if [ -f "$f" ]; then
2665                                 E1="$E1 -e $f"
2666                         fi
2667                 done
2668 
2669                 E2=
2670                 f2=
2671                 if [ -d "$SRC/pkg" ]; then
2672                         f2="$f2 exceptions/packaging"
2673                 fi
2674 
2675                 for f in $f2; do
2676                         if [ -f "$f" ]; then
2677                                 E2="$E2 -e $f"
2678                         fi
2679                 done
2680 
2681                 if [ -f "$REF_PROTO_LIST" ]; then
2682                         #
2683                         # For builds that copy the IHV proto area (-X), add the
2684                         # IHV proto list to the reference list if the reference
2685                         # was built without -X.
2686                         #
2687                         # For builds that don't copy the IHV proto area, add the
2688                         # IHV proto list to the build's proto list if the
2689                         # reference was built with -X.
2690                         #
2691                         # Use the presence of the first file entry of the cached
2692                         # IHV proto list in the reference list to determine
2693                         # whether it was built with -X or not.
2694                         #
2695                         IHV_REF_PROTO_LIST=$SRC/pkg/proto_list_ihv_$MACH
2696                         grepfor=$(nawk '$1 == "f" { print $2; exit }' \
2697                                 $IHV_REF_PROTO_LIST 2> /dev/null)
2698                         if [ $? = 0 -a -n "$grepfor" ]; then
2699                                 if [ "$X_FLAG" = "y" ]; then
2700                                         grep -w "$grepfor" \
2701                                                 $REF_PROTO_LIST > /dev/null
2702                                         if [ ! "$?" = "0" ]; then
2703                                                 REF_IHV_PROTO="-d $IHV_REF_PROTO_LIST"
2704                                         fi
2705                                 else
2706                                         grep -w "$grepfor" \
2707                                                 $REF_PROTO_LIST > /dev/null
2708                                         if [ "$?" = "0" ]; then
2709                                                 IHV_PROTO_LIST="$IHV_REF_PROTO_LIST"
2710                                         fi
2711                                 fi
2712                         fi
2713                 fi
2714         fi
2715 
2716         if [ "$N_FLAG" != "y" -a -f $SRC/pkgdefs/Makefile ]; then
2717                 echo "\n==== Impact on SVr4 packages ====\n" >> $mail_msg_file
2718                 #
2719                 # Compare the build's proto list with current package
2720                 # definitions to audit the quality of package
2721                 # definitions and makefile install targets. Use the
2722                 # current exception list.
2723                 #
2724                 PKGDEFS_LIST=""
2725                 for d in $abssrcdirs; do
2726                         if [ -d $d/pkgdefs ]; then
2727                                 PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
2728                         fi
2729                 done
2730                 if [ "$X_FLAG" = "y" -a \
2731                     -d $IA32_IHV_WS/usr/src/pkgdefs ]; then
2732                         PKGDEFS_LIST="$PKGDEFS_LIST -d $IA32_IHV_WS/usr/src/pkgdefs"
2733                 fi
2734                 $PROTOCMPTERSE \
2735                     "Files missing from the proto area:" \
2736                     "Files missing from packages:" \
2737                     "Inconsistencies between pkgdefs and proto area:" \
2738                     ${E1} \
2739                     ${PKGDEFS_LIST} \
2740                     $ATLOG/proto_list_${MACH} \
2741                     >> $mail_msg_file
2742         fi
2743 
2744         if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
2745                 echo "\n==== Validating manifests against proto area ====\n" \
2746                     >> $mail_msg_file
2747                 ( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) \
2748                     >> $mail_msg_file
2749 
2750         fi
2751 
2752         if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then
2753                 echo "\n==== Impact on proto area ====\n" >> $mail_msg_file
2754                 if [ -n "$E2" ]; then
2755                         ELIST=$E2
2756                 else
2757                         ELIST=$E1
2758                 fi
2759                 $PROTOCMPTERSE \
2760                         "Files in yesterday's proto area, but not today's:" \
2761                         "Files in today's proto area, but not yesterday's:" \
2762                         "Files that changed between yesterday and today:" \
2763                         ${ELIST} \
2764                         -d $REF_PROTO_LIST \
2765                         $REF_IHV_PROTO \
2766                         $ATLOG/proto_list_${MACH} \
2767                         $IHV_PROTO_LIST \
2768                         >> $mail_msg_file
2769         fi
2770 fi
2771 
2772 if [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
2773         staffer cp $ATLOG/proto_list_${MACH} \
2774                 $PARENT_WS/usr/src/proto_list_${MACH}
2775 fi
2776 
2777 # Update parent proto area if necessary. This is done now
2778 # so that the proto area has either DEBUG or non-DEBUG kernels.
2779 # Note that this clears out the lock file, so we can dispense with
2780 # the variable now.
2781 if [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
2782         echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
2783             tee -a $LOGFILE >> $mail_msg_file
2784         rm -rf $NIGHTLY_PARENT_ROOT/*
2785         unset Ulockfile
2786         mkdir -p $NIGHTLY_PARENT_ROOT
2787         if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2788                 ( cd $ROOT; tar cf - . |
2789                     ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
2790                     tee -a $mail_msg_file >> $LOGFILE
2791         fi
2792         if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
2793                 rm -rf $NIGHTLY_PARENT_ROOT-nd/*
2794                 mkdir -p $NIGHTLY_PARENT_ROOT-nd
2795                 cd $ROOT-nd
2796                 ( tar cf - . |
2797                     ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
2798                     tee -a $mail_msg_file >> $LOGFILE
2799         fi
2800         if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then
2801                 echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \
2802                     tee -a $LOGFILE >> $mail_msg_file
2803                 rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/*
2804                 mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT
2805                 if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2806                         ( cd $TOOLS_PROTO; tar cf - . |
2807                             ( cd $NIGHTLY_PARENT_TOOLS_ROOT; 
2808                             umask 0; tar xpf - ) ) 2>&1 |
2809                             tee -a $mail_msg_file >> $LOGFILE
2810                 fi
2811         fi
2812 fi
2813 
2814 #
2815 # ELF verification: ABI (-A) and runtime (-r) checks
2816 #
2817 if [[ ($build_ok = y) && ( ($A_FLAG = y) || ($r_FLAG = y) ) ]]; then
2818         # Directory ELF-data.$MACH holds the files produced by these tests.
2819         elf_ddir=$SRC/ELF-data.$MACH
2820 
2821         # If there is a previous ELF-data backup directory, remove it. Then,
2822         # rotate current ELF-data directory into its place and create a new
2823         # empty directory
2824         rm -rf $elf_ddir.ref
2825         if [[ -d $elf_ddir ]]; then
2826                 mv $elf_ddir $elf_ddir.ref
2827         fi
2828         mkdir -p $elf_ddir
2829 
2830         # Call find_elf to produce a list of the ELF objects in the proto area.
2831         # This list is passed to check_rtime and interface_check, preventing
2832         # them from separately calling find_elf to do the same work twice.
2833         find_elf -fr $checkroot > $elf_ddir/object_list
2834 
2835         if [[ $A_FLAG = y ]]; then
2836                 echo "\n==== Check versioning and ABI information ====\n"  | \
2837                     tee -a $LOGFILE >> $mail_msg_file
2838 
2839                 # Produce interface description for the proto. Report errors.
2840                 interface_check -o -w $elf_ddir -f object_list \
2841                         -i interface -E interface.err
2842                 if [[ -s $elf_ddir/interface.err ]]; then
2843                         tee -a $LOGFILE < $elf_ddir/interface.err \
2844                                 >> $mail_msg_file
2845                 fi
2846 
2847                 # If ELF_DATA_BASELINE_DIR is defined, compare the new interface
2848                 # description file to that from the baseline gate. Issue a
2849                 # warning if the baseline is not present, and keep going.
2850                 if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
2851                         base_ifile="$ELF_DATA_BASELINE_DIR/interface"
2852 
2853                         echo "\n==== Compare versioning and ABI information" \
2854                             "to baseline ====\n"  | \
2855                             tee -a $LOGFILE >> $mail_msg_file
2856                         echo "Baseline:  $base_ifile\n" >> $LOGFILE
2857 
2858                         if [[ -f $base_ifile ]]; then
2859                                 interface_cmp -d -o $base_ifile \
2860                                     $elf_ddir/interface > $elf_ddir/interface.cmp
2861                                 if [[ -s $elf_ddir/interface.cmp ]]; then
2862                                         echo | tee -a $LOGFILE >> $mail_msg_file
2863                                         tee -a $LOGFILE < \
2864                                             $elf_ddir/interface.cmp \
2865                                             >> $mail_msg_file
2866                                 fi
2867                         else
2868                                 echo "baseline not available. comparison" \
2869                                     "skipped" | \
2870                                     tee -a $LOGFILE >> $mail_msg_file
2871                         fi
2872 
2873                 fi
2874         fi
2875 
2876         if [[ $r_FLAG = y ]]; then
2877                 echo "\n==== Check ELF runtime attributes ====\n" | \
2878                     tee -a $LOGFILE >> $mail_msg_file
2879 
2880                 # If we're doing a DEBUG build the proto area will be left
2881                 # with debuggable objects, thus don't assert -s.
2882                 if [[ $D_FLAG = y ]]; then
2883                         rtime_sflag=""
2884                 else
2885                         rtime_sflag="-s"
2886                 fi
2887                 check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
2888                         -D object_list  -f object_list -E runtime.err \
2889                         -I runtime.attr.raw
2890 
2891                 # check_rtime -I output needs to be sorted in order to 
2892                 # compare it to that from previous builds.
2893                 sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
2894                 rm $elf_ddir/runtime.attr.raw
2895 
2896                 # Report errors
2897                 if [[ -s $elf_ddir/runtime.err ]]; then
2898                         tee -a $LOGFILE < $elf_ddir/runtime.err \
2899                                 >> $mail_msg_file
2900                 fi
2901 
2902                 # If there is an ELF-data directory from a previous build,
2903                 # then diff the attr files. These files contain information
2904                 # about dependencies, versioning, and runpaths. There is some
2905                 # overlap with the ABI checking done above, but this also
2906                 # flushes out non-ABI interface differences along with the
2907                 # other information.
2908                 echo "\n==== Diff ELF runtime attributes" \
2909                     "(since last build) ====\n" | \
2910                     tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
2911 
2912                 if [[ -f $elf_ddir.ref/runtime.attr ]]; then
2913                         diff $elf_ddir.ref/runtime.attr \
2914                                 $elf_ddir/runtime.attr \
2915                                 >> $mail_msg_file
2916                 fi
2917         fi
2918 
2919         # If -u set, copy contents of ELF-data.$MACH to the parent workspace.
2920         if [[ "$u_FLAG" = "y" ]]; then
2921                 p_elf_ddir=$PARENT_WS/usr/src/ELF-data.$MACH
2922 
2923                 # If parent lacks the ELF-data.$MACH directory, create it
2924                 if [[ ! -d $p_elf_ddir ]]; then
2925                         staffer mkdir -p $p_elf_ddir
2926                 fi
2927 
2928                 # These files are used asynchronously by other builds for ABI
2929                 # verification, as above for the -A option. As such, we require
2930                 # the file replacement to be atomic. Copy the data to a temp
2931                 # file in the same filesystem and then rename into place. 
2932                 (
2933                         cd $elf_ddir
2934                         for elf_dfile in *; do
2935                                 staffer cp $elf_dfile \
2936                                     ${p_elf_ddir}/${elf_dfile}.new
2937                                 staffer mv -f ${p_elf_ddir}/${elf_dfile}.new \
2938                                     ${p_elf_ddir}/${elf_dfile}
2939                         done
2940                 )
2941         fi
2942 fi
2943 
2944 # DEBUG lint of kernel begins
2945 
2946 if [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
2947         if [ "$LINTDIRS" = "" ]; then
2948                 # LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
2949                 LINTDIRS="$SRC y"
2950         fi
2951         set $LINTDIRS
2952         while [ $# -gt 0 ]; do
2953                 dolint $1 $2; shift; shift
2954         done
2955 else
2956         echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
2957 fi
2958 
2959 # "make check" begins
2960 
2961 if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
2962         # remove old check.out
2963         rm -f $SRC/check.out
2964 
2965         rm -f $SRC/check-${MACH}.out
2966         cd $SRC
2967         $MAKE -ek check ROOT="$checkroot" 2>&1 | tee -a $SRC/check-${MACH}.out \
2968             >> $LOGFILE
2969         echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
2970 
2971         grep ":" $SRC/check-${MACH}.out |
2972                 egrep -v "Ignoring unknown host" | \
2973                 sort | uniq >> $mail_msg_file
2974 else
2975         echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
2976 fi
2977 
2978 echo "\n==== Find core files ====\n" | \
2979     tee -a $LOGFILE >> $mail_msg_file
2980 
2981 find $abssrcdirs -name core -a -type f -exec file {} \; | \
2982         tee -a $LOGFILE >> $mail_msg_file
2983 
2984 if [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2985         echo "\n==== Diff unreferenced files (since last build) ====\n" \
2986             | tee -a $LOGFILE >>$mail_msg_file
2987         rm -f $SRC/unref-${MACH}.ref
2988         if [ -f $SRC/unref-${MACH}.out ]; then
2989                 mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2990         fi
2991 
2992         findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
2993             ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
2994             sort > $SRC/unref-${MACH}.out
2995 
2996         if [ ! -f $SRC/unref-${MACH}.ref ]; then
2997                 cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2998         fi
2999 
3000         diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
3001 fi
3002 
3003 #
3004 # Generate the OpenSolaris deliverables if requested.  Some of these
3005 # steps need to come after findunref and are commented below.
3006 #
3007 
3008 # If we are doing an OpenSolaris _source_ build (-S O) then we do
3009 # not have usr/closed available to us to generate closedbins from,
3010 # so skip this part.
3011 if [ "$SO_FLAG" = n -a "$O_FLAG" = y -a "$build_ok" = y ]; then
3012         echo "\n==== Generating OpenSolaris tarballs ====\n" | \
3013             tee -a $mail_msg_file >> $LOGFILE
3014 
3015         cd $CODEMGR_WS
3016 
3017         #
3018         # This step grovels through the package manifests, so it
3019         # must come after findunref.
3020         #
3021         # We assume no DEBUG vs non-DEBUG package content variation
3022         # here; if that changes, then the "make all" in $SRC/pkg will
3023         # need to be moved into the conditionals and repeated for each
3024         # different build.
3025         #
3026         echo "Generating closed binaries tarball(s)..." >> $LOGFILE
3027         closed_basename=on-closed-bins
3028         if [ "$D_FLAG" = y ]; then
3029                 bindrop "$closed_basename" >>"$LOGFILE" 2>&1
3030                 if (( $? != 0 )) ; then
3031                         echo "Couldn't create DEBUG closed binaries." |
3032                             tee -a $mail_msg_file >> $LOGFILE
3033                         build_ok=n
3034                 fi
3035         fi
3036         if [ "$F_FLAG" = n ]; then
3037                 bindrop -n "$closed_basename-nd" >>"$LOGFILE" 2>&1
3038                 if (( $? != 0 )) ; then
3039                         echo "Couldn't create non-DEBUG closed binaries." |
3040                             tee -a $mail_msg_file >> $LOGFILE
3041                         build_ok=n
3042                 fi
3043         fi
3044 
3045         echo "Generating README.opensolaris..." >> $LOGFILE
3046         cat $SRC/tools/opensolaris/README.opensolaris.tmpl | \
3047             mkreadme_osol $CODEMGR_WS/README.opensolaris >> $LOGFILE 2>&1
3048         if (( $? != 0 )) ; then
3049                 echo "Couldn't create README.opensolaris." |
3050                     tee -a $mail_msg_file >> $LOGFILE
3051                 build_ok=n
3052         fi
3053 fi
3054 
3055 # Verify that the usual lists of files, such as exception lists,
3056 # contain only valid references to files.  If the build has failed,
3057 # then don't check the proto area.
3058 CHECK_PATHS=${CHECK_PATHS:-y}
3059 if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
3060         echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
3061                 >>$mail_msg_file
3062         arg=-b
3063         [ "$build_ok" = y ] && arg=
3064         checkpaths $arg $checkroot 2>&1 | tee -a $LOGFILE >>$mail_msg_file
3065 fi
3066 
3067 if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
3068         echo "\n==== Impact on file permissions ====\n" \
3069                 >> $mail_msg_file
3070 
3071         abspkgdefs=
3072         abspkg=
3073         for d in $abssrcdirs; do
3074                 if [ -d "$d/pkgdefs" ]; then
3075                         abspkgdefs="$abspkgdefs $d"
3076                 fi
3077                 if [ -d "$d/pkg" ]; then
3078                         abspkg="$abspkg $d"
3079                 fi
3080         done
3081 
3082         if [ -n "$abspkgdefs" ]; then
3083                 pmodes -qvdP \
3084                     `find $abspkgdefs -name pkginfo.tmpl -print -o \
3085                     -name .del\* -prune | sed -e 's:/pkginfo.tmpl$::' | \
3086                     sort -u` >> $mail_msg_file
3087         fi
3088 
3089         if [ -n "$abspkg" ]; then
3090                 for d in "$abspkg"; do
3091                         ( cd $d/pkg ; $MAKE -e pmodes ) >> $mail_msg_file
3092                 done
3093         fi
3094 fi
3095 
3096 if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
3097         if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
3098                 do_wsdiff DEBUG $ROOT.prev $ROOT
3099         fi
3100 
3101         if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
3102                 do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
3103         fi
3104 fi
3105 
3106 END_DATE=`date`
3107 echo "==== Nightly $maketype build completed: $END_DATE ====" | \
3108     tee -a $LOGFILE >> $build_time_file
3109 
3110 typeset -i10 hours
3111 typeset -Z2 minutes
3112 typeset -Z2 seconds
3113 
3114 elapsed_time=$SECONDS
3115 ((hours = elapsed_time / 3600 ))
3116 ((minutes = elapsed_time / 60  % 60))
3117 ((seconds = elapsed_time % 60))
3118 
3119 echo "\n==== Total build time ====" | \
3120     tee -a $LOGFILE >> $build_time_file
3121 echo "\nreal    ${hours}:${minutes}:${seconds}" | \
3122     tee -a $LOGFILE >> $build_time_file
3123 
3124 if [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
3125         staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
3126 
3127         #
3128         # Produce a master list of unreferenced files -- ideally, we'd
3129         # generate the master just once after all of the nightlies
3130         # have finished, but there's no simple way to know when that
3131         # will be.  Instead, we assume that we're the last nightly to
3132         # finish and merge all of the unref-${MACH}.out files in
3133         # $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
3134         # finish, then this file will be the authoritative master
3135         # list.  Otherwise, another ${MACH}'s nightly will eventually
3136         # overwrite ours with its own master, but in the meantime our
3137         # temporary "master" will be no worse than any older master
3138         # which was already on the parent.
3139         #
3140 
3141         set -- $PARENT_WS/usr/src/unref-*.out
3142         cp "$1" ${TMPDIR}/unref.merge
3143         shift
3144 
3145         for unreffile; do
3146                 comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
3147                 mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
3148         done
3149 
3150         staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
3151 fi
3152 
3153 #
3154 # All done save for the sweeping up.
3155 # (whichever exit we hit here will trigger the "cleanup" trap which
3156 # optionally sends mail on completion).
3157 #
3158 if [ "$build_ok" = "y" ]; then
3159         exit 0
3160 fi
3161 exit 1
--- EOF ---