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