xref: /illumos-gate/usr/src/tools/scripts/nightly (revision fc8c3a5155c57af4d5afa0b93dc1542934bf487a)
15ca82e69SJohn Levon#!/bin/ksh -p
25ca82e69SJohn Levon#
35ca82e69SJohn Levon# CDDL HEADER START
45ca82e69SJohn Levon#
55ca82e69SJohn Levon# The contents of this file are subject to the terms of the
65ca82e69SJohn Levon# Common Development and Distribution License (the "License").
75ca82e69SJohn Levon# You may not use this file except in compliance with the License.
85ca82e69SJohn Levon#
95ca82e69SJohn Levon# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
105ca82e69SJohn Levon# or http://www.opensolaris.org/os/licensing.
115ca82e69SJohn Levon# See the License for the specific language governing permissions
125ca82e69SJohn Levon# and limitations under the License.
135ca82e69SJohn Levon#
145ca82e69SJohn Levon# When distributing Covered Code, include this CDDL HEADER in each
155ca82e69SJohn Levon# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
165ca82e69SJohn Levon# If applicable, add the following below this CDDL HEADER, with the
175ca82e69SJohn Levon# fields enclosed by brackets "[]" replaced with your own identifying
185ca82e69SJohn Levon# information: Portions Copyright [yyyy] [name of copyright owner]
195ca82e69SJohn Levon#
205ca82e69SJohn Levon# CDDL HEADER END
215ca82e69SJohn Levon#
225ca82e69SJohn Levon
235ca82e69SJohn Levon#
245ca82e69SJohn Levon# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
255ca82e69SJohn Levon# Copyright 2008, 2010, Richard Lowe
263c6ef809SYuri Pankov# Copyright 2022 Tintri by DDN, Inc. All rights reserved.
275ca82e69SJohn Levon# Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
285ca82e69SJohn Levon# Copyright (c) 2017 by Delphix. All rights reserved.
295ca82e69SJohn Levon# Copyright 2020 Joyent, Inc.
305ca82e69SJohn Levon# Copyright 2019 Peter Trible.
316112cec5SJoshua M. Clulow# Copyright 2020 Oxide Computer Company
32069e6b7eSAndy Fiddaman# Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
334125432bSBill Sommerfeld# Copyright 2024 Bill Sommerfeld <sommerfeld@hamachi.org>
345ca82e69SJohn Levon#
355ca82e69SJohn Levon# Based on the nightly script from the integration folks,
365ca82e69SJohn Levon# Mostly modified and owned by mike_s.
375ca82e69SJohn Levon# Changes also by kjc, dmk.
385ca82e69SJohn Levon#
395ca82e69SJohn Levon# BRINGOVER_WS may be specified in the env file.
405ca82e69SJohn Levon# The default is the old behavior of CLONE_WS
415ca82e69SJohn Levon#
425ca82e69SJohn Levon# -i on the command line, means fast options, so when it's on the
435ca82e69SJohn Levon# command line (only), check builds are skipped no matter what
445ca82e69SJohn Levon# the setting of their individual flags are in NIGHTLY_OPTIONS.
455ca82e69SJohn Levon#
465ca82e69SJohn Levon# OPTHOME  may be set in the environment to override /opt
475ca82e69SJohn Levon#
485ca82e69SJohn Levon
495ca82e69SJohn Levon#
505ca82e69SJohn Levon# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
515ca82e69SJohn Levon# under certain circumstances, which can really screw things up; unset it.
525ca82e69SJohn Levon#
535ca82e69SJohn Levonunset CDPATH
545ca82e69SJohn Levon
555ca82e69SJohn Levon# Get the absolute path of the nightly script that the user invoked.  This
565ca82e69SJohn Levon# may be a relative path, and we need to do this before changing directory.
575ca82e69SJohn Levonnightly_path=`whence $0`
585ca82e69SJohn Levon
595ca82e69SJohn Levon#
605ca82e69SJohn Levon# Keep track of where we found nightly so we can invoke the matching
615ca82e69SJohn Levon# which_scm script.  If that doesn't work, don't go guessing, just rely
625ca82e69SJohn Levon# on the $PATH settings, which will generally give us either /opt/onbld
635ca82e69SJohn Levon# or the user's workspace.
645ca82e69SJohn Levon#
655ca82e69SJohn LevonWHICH_SCM=$(dirname $nightly_path)/which_scm
665ca82e69SJohn Levonif [[ ! -x $WHICH_SCM ]]; then
675ca82e69SJohn Levon	WHICH_SCM=which_scm
685ca82e69SJohn Levonfi
695ca82e69SJohn Levon
705ca82e69SJohn Levonfunction fatal_error
715ca82e69SJohn Levon{
725ca82e69SJohn Levon	print -u2 "nightly: $*"
735ca82e69SJohn Levon	exit 1
745ca82e69SJohn Levon}
755ca82e69SJohn Levon
765ca82e69SJohn Levon#
775ca82e69SJohn Levon# Function to do a DEBUG and non-DEBUG build. Needed because we might
785ca82e69SJohn Levon# need to do another for the source build, and since we only deliver DEBUG or
795ca82e69SJohn Levon# non-DEBUG packages.
805ca82e69SJohn Levon#
815ca82e69SJohn Levon# usage: normal_build
825ca82e69SJohn Levon#
835ca82e69SJohn Levonfunction normal_build {
845ca82e69SJohn Levon
855ca82e69SJohn Levon	typeset orig_p_FLAG="$p_FLAG"
865ca82e69SJohn Levon	typeset crypto_signer="$CODESIGN_USER"
875ca82e69SJohn Levon
885ca82e69SJohn Levon	suffix=""
895ca82e69SJohn Levon
905ca82e69SJohn Levon	# non-DEBUG build begins
915ca82e69SJohn Levon
925ca82e69SJohn Levon	if [ "$F_FLAG" = "n" ]; then
935ca82e69SJohn Levon		set_non_debug_build_flags
945ca82e69SJohn Levon		CODESIGN_USER="$crypto_signer" \
955ca82e69SJohn Levon		    build "non-DEBUG" "$suffix-nd" "-nd" "$MULTI_PROTO"
965ca82e69SJohn Levon	else
975ca82e69SJohn Levon		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
985ca82e69SJohn Levon	fi
995ca82e69SJohn Levon
1005ca82e69SJohn Levon	# non-DEBUG build ends
1015ca82e69SJohn Levon
1025ca82e69SJohn Levon	# DEBUG build begins
1035ca82e69SJohn Levon
1045ca82e69SJohn Levon	if [ "$D_FLAG" = "y" ]; then
1055ca82e69SJohn Levon		set_debug_build_flags
1065ca82e69SJohn Levon		CODESIGN_USER="$crypto_signer" \
1075ca82e69SJohn Levon		    build "DEBUG" "$suffix" "" "$MULTI_PROTO"
1085ca82e69SJohn Levon	else
1095ca82e69SJohn Levon		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
1105ca82e69SJohn Levon	fi
1115ca82e69SJohn Levon
1125ca82e69SJohn Levon	# DEBUG build ends
1135ca82e69SJohn Levon
1145ca82e69SJohn Levon	p_FLAG="$orig_p_FLAG"
1155ca82e69SJohn Levon}
1165ca82e69SJohn Levon
1175ca82e69SJohn Levon#
1185ca82e69SJohn Levon# usage: run_hook HOOKNAME ARGS...
1195ca82e69SJohn Levon#
1205ca82e69SJohn Levon# If variable "$HOOKNAME" is defined, insert a section header into
1215ca82e69SJohn Levon# our logs and then run the command with ARGS
1225ca82e69SJohn Levon#
1235ca82e69SJohn Levonfunction run_hook {
1245ca82e69SJohn Levon	HOOKNAME=$1
1255ca82e69SJohn Levon	eval HOOKCMD=\$$HOOKNAME
1265ca82e69SJohn Levon	shift
1275ca82e69SJohn Levon
1285ca82e69SJohn Levon	if [ -n "$HOOKCMD" ]; then
1295ca82e69SJohn Levon		(
1305ca82e69SJohn Levon			echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
1315ca82e69SJohn Levon			( $HOOKCMD "$@" 2>&1 )
1325ca82e69SJohn Levon			if [ "$?" -ne 0 ]; then
1335ca82e69SJohn Levon				# Let exit status propagate up
1345ca82e69SJohn Levon				touch $TMPDIR/abort
1355ca82e69SJohn Levon			fi
1365ca82e69SJohn Levon		) | tee -a $mail_msg_file >> $LOGFILE
1375ca82e69SJohn Levon
1385ca82e69SJohn Levon		if [ -f $TMPDIR/abort ]; then
1395ca82e69SJohn Levon			build_ok=n
1405ca82e69SJohn Levon			echo "\nAborting at request of $HOOKNAME" |
1415ca82e69SJohn Levon				tee -a $mail_msg_file >> $LOGFILE
1425ca82e69SJohn Levon			exit 1
1435ca82e69SJohn Levon		fi
1445ca82e69SJohn Levon	fi
1455ca82e69SJohn Levon}
1465ca82e69SJohn Levon
1475ca82e69SJohn Levon# Return library search directive as function of given root.
1485ca82e69SJohn Levonfunction myldlibs {
1495ca82e69SJohn Levon	echo "-L$1/lib -L$1/usr/lib"
1505ca82e69SJohn Levon}
1515ca82e69SJohn Levon
1525ca82e69SJohn Levon# Return header search directive as function of given root.
1535ca82e69SJohn Levonfunction myheaders {
1545ca82e69SJohn Levon	echo "-I$1/usr/include"
1555ca82e69SJohn Levon}
1565ca82e69SJohn Levon
1575ca82e69SJohn Levon#
1585ca82e69SJohn Levon# Function to do the build, including package generation.
1595ca82e69SJohn Levon# usage: build LABEL SUFFIX ND MULTIPROTO
1605ca82e69SJohn Levon# - LABEL is used to tag build output.
1615ca82e69SJohn Levon# - SUFFIX is used to distinguish files (e.g., DEBUG vs non-DEBUG,
1625ca82e69SJohn Levon#   open-only vs full tree).
1635ca82e69SJohn Levon# - ND is "-nd" (non-DEBUG builds) or "" (DEBUG builds).
1645ca82e69SJohn Levon# - If MULTIPROTO is "yes", it means to name the proto area according to
1655ca82e69SJohn Levon#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
1665ca82e69SJohn Levon#
1675ca82e69SJohn Levonfunction build {
1685ca82e69SJohn Levon	LABEL=$1
1695ca82e69SJohn Levon	SUFFIX=$2
1705ca82e69SJohn Levon	ND=$3
1715ca82e69SJohn Levon	MULTIPROTO=$4
1725ca82e69SJohn Levon	INSTALLOG=install${SUFFIX}-${MACH}
1735ca82e69SJohn Levon	NOISE=noise${SUFFIX}-${MACH}
1745ca82e69SJohn Levon	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
1755ca82e69SJohn Levon
1765ca82e69SJohn Levon	ORIGROOT=$ROOT
1775ca82e69SJohn Levon	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
1785ca82e69SJohn Levon
1795ca82e69SJohn Levon	export ENVLDLIBS1=`myldlibs $ROOT`
1805ca82e69SJohn Levon	export ENVCPPFLAGS1=`myheaders $ROOT`
1815ca82e69SJohn Levon
1825ca82e69SJohn Levon	this_build_ok=y
1835ca82e69SJohn Levon	#
1845ca82e69SJohn Levon	#	Build OS-Networking source
1855ca82e69SJohn Levon	#
1865ca82e69SJohn Levon	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
1875ca82e69SJohn Levon		>> $LOGFILE
1885ca82e69SJohn Levon
1895ca82e69SJohn Levon	rm -f $SRC/${INSTALLOG}.out
1905ca82e69SJohn Levon	cd $SRC
1915ca82e69SJohn Levon	/bin/time $MAKE -e install 2>&1 | \
1925ca82e69SJohn Levon	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
1935ca82e69SJohn Levon
1945ca82e69SJohn Levon	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
1955ca82e69SJohn Levon	egrep ":" $SRC/${INSTALLOG}.out |
196244a25b4SBill Sommerfeld	    egrep -e "(^${MAKE}"$':|[\t ]error[:\t ]|ld: guidance:)' | \
197eefeb0ceSBill Sommerfeld	    egrep -v ": (Entering|Leaving) directory " | \
1985ca82e69SJohn Levon	    egrep -v "Ignoring unknown host" | \
1995ca82e69SJohn Levon	    egrep -v "cc .* -o error " | \
2005ca82e69SJohn Levon	    egrep -v "warning" | tee $TMPDIR/build_errs${SUFFIX} \
2015ca82e69SJohn Levon	    >> $mail_msg_file
202244a25b4SBill Sommerfeld	    sed -n $'/^Undefined[\t ]*first referenced$/,/^ld: fatal:/p' \
2035ca82e69SJohn Levon	    < $SRC/${INSTALLOG}.out >> $mail_msg_file
2045ca82e69SJohn Levon	if [[ -s $TMPDIR/build_errs${SUFFIX} ]]; then
2055ca82e69SJohn Levon		build_ok=n
2065ca82e69SJohn Levon		this_build_ok=n
2075ca82e69SJohn Levon	fi
2085ca82e69SJohn Levon	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
2095ca82e69SJohn Levon		>> $mail_msg_file
2105ca82e69SJohn Levon	if [ "$?" = "0" ]; then
2115ca82e69SJohn Levon		build_ok=n
2125ca82e69SJohn Levon		this_build_ok=n
2135ca82e69SJohn Levon	fi
2145ca82e69SJohn Levon
2155ca82e69SJohn Levon	echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
216a56362d6SBill Sommerfeld	egrep -i 'warn(ing)?:' $SRC/${INSTALLOG}.out \
2175ca82e69SJohn Levon		| egrep -v '^tic:' \
2185ca82e69SJohn Levon		| egrep -v "symbol (\`|')timezone' has differing types:" \
2195ca82e69SJohn Levon		| egrep -v "parameter <PSTAMP> set to" \
2205ca82e69SJohn Levon		| egrep -v "Ignoring unknown host" \
2215ca82e69SJohn Levon		| egrep -v "redefining segment flags attribute for" \
2225ca82e69SJohn Levon		| tee $TMPDIR/build_warnings${SUFFIX} >> $mail_msg_file
2235ca82e69SJohn Levon	if [[ -s $TMPDIR/build_warnings${SUFFIX} ]]; then
2245ca82e69SJohn Levon		build_ok=n
2255ca82e69SJohn Levon		this_build_ok=n
2265ca82e69SJohn Levon	fi
2275ca82e69SJohn Levon
2285ca82e69SJohn Levon	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
2295ca82e69SJohn Levon		>> $LOGFILE
2305ca82e69SJohn Levon
2315ca82e69SJohn Levon	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
2325ca82e69SJohn Levon	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
2335ca82e69SJohn Levon
2345ca82e69SJohn Levon	if [ "$i_FLAG" = "n" ]; then
2355ca82e69SJohn Levon		rm -f $SRC/${NOISE}.ref
2365ca82e69SJohn Levon		if [ -f $SRC/${NOISE}.out ]; then
2375ca82e69SJohn Levon			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
2385ca82e69SJohn Levon		fi
2395ca82e69SJohn Levon		grep : $SRC/${INSTALLOG}.out \
2405ca82e69SJohn Levon			| egrep -v '^/' \
2415ca82e69SJohn Levon			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
2425ca82e69SJohn Levon			| egrep -v '^tic:' \
2435ca82e69SJohn Levon			| egrep -v '^mcs' \
2445ca82e69SJohn Levon			| egrep -v '^LD_LIBRARY_PATH=' \
2455ca82e69SJohn Levon			| egrep -v 'ar: creating' \
2465ca82e69SJohn Levon			| egrep -v 'ar: writing' \
2475ca82e69SJohn Levon			| egrep -v 'conflicts:' \
2485ca82e69SJohn Levon			| egrep -v ':saved created' \
2495ca82e69SJohn Levon			| egrep -v '^stty.*c:' \
2505ca82e69SJohn Levon			| egrep -v '^mfgname.c:' \
2515ca82e69SJohn Levon			| egrep -v '^uname-i.c:' \
2525ca82e69SJohn Levon			| egrep -v '^volumes.c:' \
2535ca82e69SJohn Levon			| egrep -v '^lint library construction:' \
2545ca82e69SJohn Levon			| egrep -v 'tsort: INFORM:' \
2555ca82e69SJohn Levon			| egrep -v 'stripalign:' \
2565ca82e69SJohn Levon			| egrep -v 'chars, width' \
2575ca82e69SJohn Levon			| egrep -v "symbol (\`|')timezone' has differing types:" \
2585ca82e69SJohn Levon			| egrep -v 'PSTAMP' \
2595ca82e69SJohn Levon			| egrep -v '^Manifying' \
2605ca82e69SJohn Levon			| egrep -v 'Ignoring unknown host' \
2615ca82e69SJohn Levon			| egrep -v 'Processing method:' \
2625ca82e69SJohn Levon			| egrep -v '^Writing' \
2635ca82e69SJohn Levon			| egrep -v 'spellin1:' \
2645ca82e69SJohn Levon			| egrep -v '^adding:' \
2655ca82e69SJohn Levon			| egrep -v "^echo 'msgid" \
2665ca82e69SJohn Levon			| egrep -v '^echo ' \
2675ca82e69SJohn Levon			| egrep -v '\.c:$' \
2685ca82e69SJohn Levon			| egrep -v '^Adding file:' \
2695ca82e69SJohn Levon			| egrep -v 'CLASSPATH=' \
2705ca82e69SJohn Levon			| egrep -v '\/var\/mail\/:saved' \
2715ca82e69SJohn Levon			| egrep -v -- '-DUTS_VERSION=' \
2725ca82e69SJohn Levon			| egrep -v '^Running Mkbootstrap' \
2735ca82e69SJohn Levon			| egrep -v '^Applet length read:' \
2745ca82e69SJohn Levon			| egrep -v 'bytes written:' \
2755ca82e69SJohn Levon			| egrep -v '^File:SolarisAuthApplet.bin' \
2765ca82e69SJohn Levon			| egrep -v -i 'jibversion' \
2775ca82e69SJohn Levon			| egrep -v '^Output size:' \
2785ca82e69SJohn Levon			| egrep -v '^Solo size statistics:' \
2795ca82e69SJohn Levon			| egrep -v '^Using ROM API Version' \
2805ca82e69SJohn Levon			| egrep -v '^Zero Signature length:' \
2815ca82e69SJohn Levon			| egrep -v '^Note \(probably harmless\):' \
2825ca82e69SJohn Levon			| egrep -v '::' \
2835ca82e69SJohn Levon			| egrep -v '^\+' \
2845ca82e69SJohn Levon			| egrep -v 'svccfg-native -s svc:/' \
285eefeb0ceSBill Sommerfeld			| egrep -v ": (Entering|Leaving) directory " \
2865ca82e69SJohn Levon			| sort | uniq >$SRC/${NOISE}.out
2875ca82e69SJohn Levon		if [ ! -f $SRC/${NOISE}.ref ]; then
2885ca82e69SJohn Levon			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
2895ca82e69SJohn Levon		fi
2905ca82e69SJohn Levon		echo "\n==== Build noise differences ($LABEL) ====\n" \
2915ca82e69SJohn Levon			>>$mail_msg_file
2925ca82e69SJohn Levon		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
2935ca82e69SJohn Levon	fi
2945ca82e69SJohn Levon
2955ca82e69SJohn Levon	#
2965ca82e69SJohn Levon	#	Re-sign selected binaries using signing server
2975ca82e69SJohn Levon	#	(gatekeeper builds only)
2985ca82e69SJohn Levon	#
2995ca82e69SJohn Levon	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
3005ca82e69SJohn Levon		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
3015ca82e69SJohn Levon		signing_file="${TMPDIR}/signing"
3025ca82e69SJohn Levon		rm -f ${signing_file}
3035ca82e69SJohn Levon		export CODESIGN_USER
3045ca82e69SJohn Levon		signproto $SRC/tools/codesign/creds 2>&1 | \
3055ca82e69SJohn Levon			tee -a ${signing_file} >> $LOGFILE
3065ca82e69SJohn Levon		echo "\n==== Finished signing proto area at `date` ====\n" \
3075ca82e69SJohn Levon		    >> $LOGFILE
3085ca82e69SJohn Levon		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
3095ca82e69SJohn Levon		    >> $mail_msg_file
3105ca82e69SJohn Levon		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
3115ca82e69SJohn Levon		if (( $? == 0 )) ; then
3125ca82e69SJohn Levon			build_ok=n
3135ca82e69SJohn Levon			this_build_ok=n
3145ca82e69SJohn Levon		fi
3155ca82e69SJohn Levon	fi
3165ca82e69SJohn Levon
3175ca82e69SJohn Levon	#
3185ca82e69SJohn Levon	#	Building Packages
3195ca82e69SJohn Levon	#
3205ca82e69SJohn Levon	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
3215ca82e69SJohn Levon		if [ -d $SRC/pkg ]; then
3225ca82e69SJohn Levon			echo "\n==== Creating $LABEL packages at `date` ====\n" \
3235ca82e69SJohn Levon				>> $LOGFILE
3245ca82e69SJohn Levon			echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
3255ca82e69SJohn Levon			rm -rf $PKGARCHIVE >> "$LOGFILE" 2>&1
3265ca82e69SJohn Levon			mkdir -p $PKGARCHIVE >> "$LOGFILE" 2>&1
3275ca82e69SJohn Levon
3285ca82e69SJohn Levon			rm -f $SRC/pkg/${INSTALLOG}.out
3295ca82e69SJohn Levon			cd $SRC/pkg
3305ca82e69SJohn Levon			/bin/time $MAKE -e install 2>&1 | \
3315ca82e69SJohn Levon			    tee -a $SRC/pkg/${INSTALLOG}.out >> $LOGFILE
3325ca82e69SJohn Levon
3335ca82e69SJohn Levon			echo "\n==== package build errors ($LABEL) ====\n" \
3345ca82e69SJohn Levon				>> $mail_msg_file
3355ca82e69SJohn Levon
3365ca82e69SJohn Levon			egrep "${MAKE}|ERROR|WARNING" $SRC/pkg/${INSTALLOG}.out | \
3375ca82e69SJohn Levon				grep ':' | \
3385ca82e69SJohn Levon				grep -v PSTAMP | \
339eefeb0ceSBill Sommerfeld				egrep -v "${MAKE}: (Entering|Leaving) directory " | \
3405ca82e69SJohn Levon				egrep -v "Ignoring unknown host" | \
3415ca82e69SJohn Levon				tee $TMPDIR/package >> $mail_msg_file
3425ca82e69SJohn Levon			if [[ -s $TMPDIR/package ]]; then
3435ca82e69SJohn Levon				build_extras_ok=n
3445ca82e69SJohn Levon				this_build_ok=n
3455ca82e69SJohn Levon			fi
3465ca82e69SJohn Levon		else
3475ca82e69SJohn Levon			#
3485ca82e69SJohn Levon			# Handle it gracefully if -p was set but there so
3495ca82e69SJohn Levon			# no pkg directory.
3505ca82e69SJohn Levon			#
3515ca82e69SJohn Levon			echo "\n==== No $LABEL packages to build ====\n" \
3525ca82e69SJohn Levon				>> $LOGFILE
3535ca82e69SJohn Levon		fi
3545ca82e69SJohn Levon	else
3555ca82e69SJohn Levon		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
3565ca82e69SJohn Levon	fi
3575ca82e69SJohn Levon
3585ca82e69SJohn Levon	ROOT=$ORIGROOT
3595ca82e69SJohn Levon}
3605ca82e69SJohn Levon
3615ca82e69SJohn Levon#
3625ca82e69SJohn Levon# Bootstrap build tools which are pre-requisites for the rest of the build.
3635ca82e69SJohn Levon#
3645ca82e69SJohn Levonfunction bootstrap_tools {
3655ca82e69SJohn Levon	echo "\n==== Bootstrapping tools at `date` ====\n" >> $LOGFILE
3665ca82e69SJohn Levon
3675ca82e69SJohn Levon	typeset INSTALLOG=install-bootstrap-${MACH}
3685ca82e69SJohn Levon
3695ca82e69SJohn Levon	rm -f $TMPDIR/make-state ${TOOLS}/$INSTALLOG.out
3705ca82e69SJohn Levon	cd ${TOOLS}
3715ca82e69SJohn Levon	/bin/time $MAKE -K $TMPDIR/make-state -e TARGET=install bootstrap \
3725ca82e69SJohn Levon	    2>&1 | tee -a ${TOOLS}/$INSTALLOG.out >> $LOGFILE
3735ca82e69SJohn Levon
3745ca82e69SJohn Levon	echo "\n==== Bootstrap build errors ====\n" >> $mail_msg_file
3755ca82e69SJohn Levon
3765ca82e69SJohn Levon	egrep ":" ${TOOLS}/$INSTALLOG.out |
377244a25b4SBill Sommerfeld	    egrep -e "(${MAKE}"$':|[\t ]error[:\t ])' | \
378eefeb0ceSBill Sommerfeld	    egrep -v ": (Entering|Leaving) directory " | \
3795ca82e69SJohn Levon	    egrep -v warning | tee $TMPDIR/bootstrap_errors >> $mail_msg_file
3805ca82e69SJohn Levon
3815ca82e69SJohn Levon	[[ -s $TMPDIR/bootstrap_errors ]] && return 1
3825ca82e69SJohn Levon	return 0
3835ca82e69SJohn Levon}
3845ca82e69SJohn Levon
3855ca82e69SJohn Levon#
3866faa6645SYuri Pankov# Build and install the tools.
3875ca82e69SJohn Levon#
3885ca82e69SJohn Levon# usage: build_tools DESTROOT
3895ca82e69SJohn Levon#
3906faa6645SYuri Pankov# returns zero status if the build was successful.
3915ca82e69SJohn Levon#
3925ca82e69SJohn Levonfunction build_tools {
3935ca82e69SJohn Levon	DESTROOT=$1
3945ca82e69SJohn Levon
3955ca82e69SJohn Levon	INSTALLOG=install-${MACH}
3965ca82e69SJohn Levon
3975ca82e69SJohn Levon	echo "\n==== Building tools at `date` ====\n" \
3985ca82e69SJohn Levon		>> $LOGFILE
3995ca82e69SJohn Levon
4005ca82e69SJohn Levon	rm -f ${TOOLS}/${INSTALLOG}.out
4015ca82e69SJohn Levon	cd ${TOOLS}
4025ca82e69SJohn Levon	/bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install 2>&1 | \
4035ca82e69SJohn Levon	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
4045ca82e69SJohn Levon
4055ca82e69SJohn Levon	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
4065ca82e69SJohn Levon
4075ca82e69SJohn Levon	egrep ":" ${TOOLS}/${INSTALLOG}.out |
408244a25b4SBill Sommerfeld		egrep -e "(${MAKE}"$':|[\t ]error[:\t ])' | \
409eefeb0ceSBill Sommerfeld		egrep -v ": (Entering|Leaving) directory " | \
4105ca82e69SJohn Levon		egrep -v "Ignoring unknown host" | \
4115ca82e69SJohn Levon		egrep -v warning | tee $TMPDIR/tools_errors >> $mail_msg_file
4125ca82e69SJohn Levon
4135ca82e69SJohn Levon	if [[ -s $TMPDIR/tools_errors ]]; then
4145ca82e69SJohn Levon		return 1
4155ca82e69SJohn Levon	fi
4165ca82e69SJohn Levon	return 0
4175ca82e69SJohn Levon}
4185ca82e69SJohn Levon
4195ca82e69SJohn Levonfunction staffer {
4205ca82e69SJohn Levon	if [ $ISUSER -ne 0 ]; then
4215ca82e69SJohn Levon		"$@"
4225ca82e69SJohn Levon	else
4235ca82e69SJohn Levon		arg="\"$1\""
4245ca82e69SJohn Levon		shift
4255ca82e69SJohn Levon		for i
4265ca82e69SJohn Levon		do
4275ca82e69SJohn Levon			arg="$arg \"$i\""
4285ca82e69SJohn Levon		done
4295ca82e69SJohn Levon		eval su $STAFFER -c \'$arg\'
4305ca82e69SJohn Levon	fi
4315ca82e69SJohn Levon}
4325ca82e69SJohn Levon
4335ca82e69SJohn Levon#
4345ca82e69SJohn Levon# Verify that the closed bins are present
4355ca82e69SJohn Levon#
4365ca82e69SJohn Levonfunction check_closed_bins {
4375ca82e69SJohn Levon	if [[ -n "$ON_CLOSED_BINS" && ! -d "$ON_CLOSED_BINS" ]]; then
4385ca82e69SJohn Levon		echo "ON_CLOSED_BINS must point to the closed binaries tree."
4395ca82e69SJohn Levon		build_ok=n
4405ca82e69SJohn Levon		exit 1
4415ca82e69SJohn Levon	fi
4425ca82e69SJohn Levon}
4435ca82e69SJohn Levon
4445ca82e69SJohn Levon#
4455ca82e69SJohn Levon# wrapper over wsdiff.
4465ca82e69SJohn Levon# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
4475ca82e69SJohn Levon#
4485ca82e69SJohn Levonfunction do_wsdiff {
4495ca82e69SJohn Levon	label=$1
4505ca82e69SJohn Levon	oldproto=$2
4515ca82e69SJohn Levon	newproto=$3
4525ca82e69SJohn Levon
4535ca82e69SJohn Levon	wsdiff="wsdiff"
4545ca82e69SJohn Levon	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
4555ca82e69SJohn Levon
4565ca82e69SJohn Levon	echo "\n==== Getting object changes since last build at `date`" \
4575ca82e69SJohn Levon	    "($label) ====\n" | tee -a $LOGFILE >> $mail_msg_file
4585ca82e69SJohn Levon	$wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
4595ca82e69SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
4605ca82e69SJohn Levon	echo "\n==== Object changes determined at `date` ($label) ====\n" | \
4615ca82e69SJohn Levon	    tee -a $LOGFILE >> $mail_msg_file
4625ca82e69SJohn Levon}
4635ca82e69SJohn Levon
4645ca82e69SJohn Levon#
4655ca82e69SJohn Levon# Functions for setting build flags (DEBUG/non-DEBUG).  Keep them
4665ca82e69SJohn Levon# together.
4675ca82e69SJohn Levon#
4685ca82e69SJohn Levon
4695ca82e69SJohn Levonfunction set_non_debug_build_flags {
4705ca82e69SJohn Levon	export RELEASE_BUILD ; RELEASE_BUILD=
4715ca82e69SJohn Levon	unset EXTRA_OPTIONS
4725ca82e69SJohn Levon	unset EXTRA_CFLAGS
4735ca82e69SJohn Levon	if [ -n "$RELEASE_CONSOLE_COLOR" ]; then
4745ca82e69SJohn Levon		export DEFAULT_CONSOLE_COLOR="$RELEASE_CONSOLE_COLOR"
4755ca82e69SJohn Levon	fi
4765ca82e69SJohn Levon}
4775ca82e69SJohn Levon
4785ca82e69SJohn Levonfunction set_debug_build_flags {
4795ca82e69SJohn Levon	unset RELEASE_BUILD
4805ca82e69SJohn Levon	unset EXTRA_OPTIONS
4815ca82e69SJohn Levon	unset EXTRA_CFLAGS
4825ca82e69SJohn Levon
4835ca82e69SJohn Levon	if [ -n "$DEBUG_CONSOLE_COLOR" ]; then
4845ca82e69SJohn Levon		export DEFAULT_CONSOLE_COLOR="$DEBUG_CONSOLE_COLOR"
4855ca82e69SJohn Levon	fi
4865ca82e69SJohn Levon}
4875ca82e69SJohn Levon
4885ca82e69SJohn Levon
4895ca82e69SJohn LevonMACH=`uname -p`
4905ca82e69SJohn Levon
4915ca82e69SJohn Levonif [ "$OPTHOME" = "" ]; then
4925ca82e69SJohn Levon	OPTHOME=/opt
4935ca82e69SJohn Levon	export OPTHOME
4945ca82e69SJohn Levonfi
4955ca82e69SJohn Levon
4965ca82e69SJohn LevonUSAGE='Usage: nightly [-in] [+t] [-V VERS ] <env_file>
4975ca82e69SJohn Levon
4985ca82e69SJohn LevonWhere:
4995ca82e69SJohn Levon	-i	Fast incremental options (no clobber, check)
5005ca82e69SJohn Levon	-n      Do not do a bringover
5015ca82e69SJohn Levon	+t	Use the build tools in $ONBLD_TOOLS/bin
5025ca82e69SJohn Levon	-V VERS set the build version string to VERS
5035ca82e69SJohn Levon
5045ca82e69SJohn Levon	<env_file>  file in Bourne shell syntax that sets and exports
5055ca82e69SJohn Levon	variables that configure the operation of this script and many of
5065ca82e69SJohn Levon	the scripts this one calls. If <env_file> does not exist,
5075ca82e69SJohn Levon	it will be looked for in $OPTHOME/onbld/env.
5085ca82e69SJohn Levon
5095ca82e69SJohn Levonnon-DEBUG is the default build type. Build options can be set in the
5105ca82e69SJohn LevonNIGHTLY_OPTIONS variable in the <env_file> as follows:
5115ca82e69SJohn Levon
5125ca82e69SJohn Levon	-A	check for ABI differences in .so files
5135ca82e69SJohn Levon	-C	check for cstyle/hdrchk errors
5145ca82e69SJohn Levon	-D	do a build with DEBUG on
5155ca82e69SJohn Levon	-F	do _not_ do a non-DEBUG build
5165ca82e69SJohn Levon	-G	gate keeper default group of options (-au)
5175ca82e69SJohn Levon	-I	integration engineer default group of options (-ampu)
518069e6b7eSAndy Fiddaman	-L	do not run pkglint
5195ca82e69SJohn Levon	-M	do not run pmodes (safe file permission checker)
5205ca82e69SJohn Levon	-N	do not run protocmp
5215ca82e69SJohn Levon	-R	default group of options for building a release (-mp)
5225ca82e69SJohn Levon	-U	update proto area in the parent
5235ca82e69SJohn Levon	-V VERS set the build version string to VERS
5245ca82e69SJohn Levon	-f	find unreferenced files
5255ca82e69SJohn Levon	-i	do an incremental build (no "make clobber")
5265ca82e69SJohn Levon	-m	send mail to $MAILTO at end of build
5275ca82e69SJohn Levon	-n      do not do a bringover
5285ca82e69SJohn Levon	-p	create packages
5295ca82e69SJohn Levon	-r	check ELF runtime attributes in the proto area
5305ca82e69SJohn Levon	-t	build and use the tools in $SRC/tools (default setting)
5315ca82e69SJohn Levon	+t	Use the build tools in $ONBLD_TOOLS/bin
5325ca82e69SJohn Levon	-u	update proto_list_$MACH and friends in the parent workspace;
5335ca82e69SJohn Levon		when used with -f, also build an unrefmaster.out in the parent
5345ca82e69SJohn Levon	-w	report on differences between previous and current proto areas
5355ca82e69SJohn Levon'
5365ca82e69SJohn Levon#
5375ca82e69SJohn Levon#	A log file will be generated under the name $LOGFILE
5385ca82e69SJohn Levon#	for partially completed build and log.`date '+%F'`
5395ca82e69SJohn Levon#	in the same directory for fully completed builds.
5405ca82e69SJohn Levon#
5415ca82e69SJohn Levon
5425ca82e69SJohn Levon# default values for low-level FLAGS; G I R are group FLAGS
5435ca82e69SJohn LevonA_FLAG=n
5445ca82e69SJohn LevonC_FLAG=n
5455ca82e69SJohn LevonD_FLAG=n
5465ca82e69SJohn LevonF_FLAG=n
5475ca82e69SJohn Levonf_FLAG=n
5485ca82e69SJohn Levoni_FLAG=n; i_CMD_LINE_FLAG=n
549069e6b7eSAndy FiddamanL_FLAG=n
5505ca82e69SJohn LevonM_FLAG=n
5515ca82e69SJohn Levonm_FLAG=n
5525ca82e69SJohn LevonN_FLAG=n
5535ca82e69SJohn Levonn_FLAG=n
5545ca82e69SJohn Levonp_FLAG=n
5555ca82e69SJohn Levonr_FLAG=n
5565ca82e69SJohn Levont_FLAG=y
5575ca82e69SJohn LevonU_FLAG=n
5585ca82e69SJohn Levonu_FLAG=n
5595ca82e69SJohn LevonV_FLAG=n
5605ca82e69SJohn Levonw_FLAG=n
5615ca82e69SJohn LevonW_FLAG=n
5625ca82e69SJohn Levon#
5635ca82e69SJohn Levonbuild_ok=y
5645ca82e69SJohn Levonbuild_extras_ok=y
5655ca82e69SJohn Levon
5665ca82e69SJohn Levon#
5675ca82e69SJohn Levon# examine arguments
5685ca82e69SJohn Levon#
5695ca82e69SJohn Levon
5705ca82e69SJohn LevonOPTIND=1
5715ca82e69SJohn Levonwhile getopts +intV:W FLAG
5725ca82e69SJohn Levondo
5735ca82e69SJohn Levon	case $FLAG in
5745ca82e69SJohn Levon	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
5755ca82e69SJohn Levon		;;
5765ca82e69SJohn Levon	  n )	n_FLAG=y
5775ca82e69SJohn Levon		;;
5785ca82e69SJohn Levon	 +t )	t_FLAG=n
5795ca82e69SJohn Levon		;;
5805ca82e69SJohn Levon	  V )	V_FLAG=y
5815ca82e69SJohn Levon		V_ARG="$OPTARG"
5825ca82e69SJohn Levon		;;
5835ca82e69SJohn Levon	  W )   W_FLAG=y
5845ca82e69SJohn Levon		;;
5855ca82e69SJohn Levon	 \? )	echo "$USAGE"
5865ca82e69SJohn Levon		exit 1
5875ca82e69SJohn Levon		;;
5885ca82e69SJohn Levon	esac
5895ca82e69SJohn Levondone
5905ca82e69SJohn Levon
5915ca82e69SJohn Levon# correct argument count after options
5925ca82e69SJohn Levonshift `expr $OPTIND - 1`
5935ca82e69SJohn Levon
5945ca82e69SJohn Levon# test that the path to the environment-setting file was given
5955ca82e69SJohn Levonif [ $# -ne 1 ]; then
5965ca82e69SJohn Levon	echo "$USAGE"
5975ca82e69SJohn Levon	exit 1
5985ca82e69SJohn Levonfi
5995ca82e69SJohn Levon
6005ca82e69SJohn Levon# check if user is running nightly as root
6015ca82e69SJohn Levon# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
6025ca82e69SJohn Levon# when root invokes nightly.
6035ca82e69SJohn Levon/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
6045ca82e69SJohn LevonISUSER=$?;	export ISUSER
6055ca82e69SJohn Levon
6065ca82e69SJohn Levon#
6075ca82e69SJohn Levon# force locale to C
6085ca82e69SJohn LevonLANG=C;		export LANG
6095ca82e69SJohn LevonLC_ALL=C;	export LC_ALL
6105ca82e69SJohn LevonLC_COLLATE=C;	export LC_COLLATE
6115ca82e69SJohn LevonLC_CTYPE=C;	export LC_CTYPE
6125ca82e69SJohn LevonLC_MESSAGES=C;	export LC_MESSAGES
6135ca82e69SJohn LevonLC_MONETARY=C;	export LC_MONETARY
6145ca82e69SJohn LevonLC_NUMERIC=C;	export LC_NUMERIC
6155ca82e69SJohn LevonLC_TIME=C;	export LC_TIME
6165ca82e69SJohn Levon
6175ca82e69SJohn Levon# clear environment variables we know to be bad for the build
6185ca82e69SJohn Levonunset LD_OPTIONS
6195ca82e69SJohn Levonunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
6205ca82e69SJohn Levonunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
6215ca82e69SJohn Levonunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
6225ca82e69SJohn Levonunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
6235ca82e69SJohn Levonunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
6245ca82e69SJohn Levonunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
6255ca82e69SJohn Levonunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
6265ca82e69SJohn Levonunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
6275ca82e69SJohn Levonunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
6285ca82e69SJohn Levonunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
6295ca82e69SJohn Levonunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
6305ca82e69SJohn Levonunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
6315ca82e69SJohn Levonunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
6325ca82e69SJohn Levonunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
6335ca82e69SJohn Levonunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
6345ca82e69SJohn Levonunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
6355ca82e69SJohn Levonunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
6365ca82e69SJohn Levonunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
6375ca82e69SJohn Levonunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
6385ca82e69SJohn Levonunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
6395ca82e69SJohn Levon
6405ca82e69SJohn Levonunset CONFIG
6415ca82e69SJohn Levonunset GROUP
6425ca82e69SJohn Levonunset OWNER
6435ca82e69SJohn Levonunset REMOTE
6445ca82e69SJohn Levonunset ENV
6455ca82e69SJohn Levonunset ARCH
6465ca82e69SJohn Levonunset CLASSPATH
6475ca82e69SJohn Levonunset NAME
6485ca82e69SJohn Levon
6495ca82e69SJohn Levon#
6505ca82e69SJohn Levon# To get ONBLD_TOOLS from the environment, it must come from the env file.
6515ca82e69SJohn Levon# If it comes interactively, it is generally TOOLS_PROTO, which will be
6525ca82e69SJohn Levon# clobbered before the compiler version checks, which will therefore fail.
6535ca82e69SJohn Levon#
6545ca82e69SJohn Levonunset ONBLD_TOOLS
6555ca82e69SJohn Levon
6565ca82e69SJohn Levon#
6575ca82e69SJohn Levon#	Setup environmental variables
6585ca82e69SJohn Levon#
6595ca82e69SJohn Levonif [ -f /etc/nightly.conf ]; then
6605ca82e69SJohn Levon	. /etc/nightly.conf
6615ca82e69SJohn Levonfi
6625ca82e69SJohn Levon
6635ca82e69SJohn Levonif [ -f $1 ]; then
66426e7d9a8SRichard Lowe	if [[ $1 == */* ]]; then
6655ca82e69SJohn Levon		. $1
6665ca82e69SJohn Levon	else
6675ca82e69SJohn Levon		. ./$1
6685ca82e69SJohn Levon	fi
6695ca82e69SJohn Levonelse
6705ca82e69SJohn Levon	if [ -f $OPTHOME/onbld/env/$1 ]; then
6715ca82e69SJohn Levon		. $OPTHOME/onbld/env/$1
6725ca82e69SJohn Levon	else
6735ca82e69SJohn Levon		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
6745ca82e69SJohn Levon		exit 1
6755ca82e69SJohn Levon	fi
6765ca82e69SJohn Levonfi
6775ca82e69SJohn Levon
6785ca82e69SJohn Levon# Check if we have sufficient data to continue...
6795ca82e69SJohn Levon[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
6805ca82e69SJohn Levonif  [[ "${NIGHTLY_OPTIONS}" == ~(F)n ]] ; then
6815ca82e69SJohn Levon	# Check if the gate data are valid if we don't do a "bringover" below
6825ca82e69SJohn Levon	[[ -d "${CODEMGR_WS}" ]] || \
6835ca82e69SJohn Levon		fatal_error "Error: ${CODEMGR_WS} is not a directory."
6845ca82e69SJohn Levon	[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || \
6855ca82e69SJohn Levon		fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
6865ca82e69SJohn Levonfi
6875ca82e69SJohn Levon
6885ca82e69SJohn Levon#
6895ca82e69SJohn Levon# place ourselves in a new task, respecting BUILD_PROJECT if set.
6905ca82e69SJohn Levon#
6915ca82e69SJohn Levonif [ -z "$BUILD_PROJECT" ]; then
6925ca82e69SJohn Levon	/usr/bin/newtask -c $$
6935ca82e69SJohn Levonelse
6945ca82e69SJohn Levon	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
6955ca82e69SJohn Levonfi
6965ca82e69SJohn Levon
6975ca82e69SJohn Levonps -o taskid= -p $$ | read build_taskid
6985ca82e69SJohn Levonps -o project= -p $$ | read build_project
6995ca82e69SJohn Levon
7005ca82e69SJohn Levon#
7015ca82e69SJohn Levon# See if NIGHTLY_OPTIONS is set
7025ca82e69SJohn Levon#
7035ca82e69SJohn Levonif [ "$NIGHTLY_OPTIONS" = "" ]; then
7045ca82e69SJohn Levon	NIGHTLY_OPTIONS="-aBm"
7055ca82e69SJohn Levonfi
7065ca82e69SJohn Levon
7075ca82e69SJohn Levon#
7085ca82e69SJohn Levon# If BRINGOVER_WS was not specified, let it default to CLONE_WS
7095ca82e69SJohn Levon#
7105ca82e69SJohn Levonif [ "$BRINGOVER_WS" = "" ]; then
7115ca82e69SJohn Levon	BRINGOVER_WS=$CLONE_WS
7125ca82e69SJohn Levonfi
7135ca82e69SJohn Levon
714*fc8c3a51SBill Sommerfeldif [ "$BRINGOVER_REMOTE" = "" ]; then
715*fc8c3a51SBill Sommerfeld	BRINGOVER_REMOTE=nightly_bringover_ws
716*fc8c3a51SBill Sommerfeldfi
717*fc8c3a51SBill Sommerfeld
718*fc8c3a51SBill Sommerfeldif [ "$BRINGOVER_SCM" = "" ]; then
719*fc8c3a51SBill Sommerfeld	BRINGOVER_SCM=git
7205ca82e69SJohn Levonfi
7215ca82e69SJohn Levon
7225ca82e69SJohn Levoncheck_closed_bins
7235ca82e69SJohn Levon
7245ca82e69SJohn Levon#
7255ca82e69SJohn Levon# Note: changes to the option letters here should also be applied to the
7265ca82e69SJohn Levon#	bldenv script.  `d' is listed for backward compatibility.
7275ca82e69SJohn Levon#
7285ca82e69SJohn LevonNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
7295ca82e69SJohn LevonOPTIND=1
730069e6b7eSAndy Fiddamanwhile getopts +ABCDdFfGIiLMmNnpRrtUuwW FLAG $NIGHTLY_OPTIONS
7315ca82e69SJohn Levondo
7325ca82e69SJohn Levon	case $FLAG in
7335ca82e69SJohn Levon	  A )	A_FLAG=y
7345ca82e69SJohn Levon		;;
7355ca82e69SJohn Levon	  B )	D_FLAG=y
7365ca82e69SJohn Levon		;; # old version of D
7375ca82e69SJohn Levon	  C )	C_FLAG=y
7385ca82e69SJohn Levon		;;
7395ca82e69SJohn Levon	  D )	D_FLAG=y
7405ca82e69SJohn Levon		;;
7415ca82e69SJohn Levon	  F )	F_FLAG=y
7425ca82e69SJohn Levon		;;
7435ca82e69SJohn Levon	  f )	f_FLAG=y
7445ca82e69SJohn Levon		;;
7455ca82e69SJohn Levon	  G )   u_FLAG=y
7465ca82e69SJohn Levon		;;
7475ca82e69SJohn Levon	  I )	m_FLAG=y
7485ca82e69SJohn Levon		p_FLAG=y
7495ca82e69SJohn Levon		u_FLAG=y
7505ca82e69SJohn Levon		;;
7515ca82e69SJohn Levon	  i )	i_FLAG=y
7525ca82e69SJohn Levon		;;
753069e6b7eSAndy Fiddaman	  L )	L_FLAG=y
754069e6b7eSAndy Fiddaman		;;
7555ca82e69SJohn Levon	  M )	M_FLAG=y
7565ca82e69SJohn Levon		;;
7575ca82e69SJohn Levon	  m )	m_FLAG=y
7585ca82e69SJohn Levon		;;
7595ca82e69SJohn Levon	  N )	N_FLAG=y
7605ca82e69SJohn Levon		;;
7615ca82e69SJohn Levon	  n )	n_FLAG=y
7625ca82e69SJohn Levon		;;
7635ca82e69SJohn Levon	  p )	p_FLAG=y
7645ca82e69SJohn Levon		;;
7655ca82e69SJohn Levon	  R )	m_FLAG=y
7665ca82e69SJohn Levon		p_FLAG=y
7675ca82e69SJohn Levon		;;
7685ca82e69SJohn Levon	  r )	r_FLAG=y
7695ca82e69SJohn Levon		;;
7705ca82e69SJohn Levon	 +t )	t_FLAG=n
7715ca82e69SJohn Levon		;;
7725ca82e69SJohn Levon	  U )   if [ -z "${PARENT_ROOT}" ]; then
7735ca82e69SJohn Levon			echo "PARENT_ROOT must be set if the U flag is" \
7745ca82e69SJohn Levon			    "present in NIGHTLY_OPTIONS."
7755ca82e69SJohn Levon			exit 1
7765ca82e69SJohn Levon		fi
7775ca82e69SJohn Levon		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
7785ca82e69SJohn Levon		if [ -n "${PARENT_TOOLS_ROOT}" ]; then
7795ca82e69SJohn Levon			NIGHTLY_PARENT_TOOLS_ROOT=$PARENT_TOOLS_ROOT
7805ca82e69SJohn Levon		fi
7815ca82e69SJohn Levon		U_FLAG=y
7825ca82e69SJohn Levon		;;
7835ca82e69SJohn Levon	  u )	u_FLAG=y
7845ca82e69SJohn Levon		;;
7855ca82e69SJohn Levon	  w )	w_FLAG=y
7865ca82e69SJohn Levon		;;
7875ca82e69SJohn Levon	  W )   W_FLAG=y
7885ca82e69SJohn Levon		;;
7895ca82e69SJohn Levon	 \? )	echo "$USAGE"
7905ca82e69SJohn Levon		exit 1
7915ca82e69SJohn Levon		;;
7925ca82e69SJohn Levon	esac
7935ca82e69SJohn Levondone
7945ca82e69SJohn Levon
7959cc2e6acSMatt Fiddaman# Skip pkglint if packages aren't being built
7969cc2e6acSMatt Fiddaman[ $p_FLAG = n ] && L_FLAG=y
7979cc2e6acSMatt Fiddaman
7985ca82e69SJohn Levonif [ $ISUSER -ne 0 ]; then
7995ca82e69SJohn Levon	# Set default value for STAFFER, if needed.
8005ca82e69SJohn Levon	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
8015ca82e69SJohn Levon		STAFFER=`/usr/xpg4/bin/id -un`
8025ca82e69SJohn Levon		export STAFFER
8035ca82e69SJohn Levon	fi
8045ca82e69SJohn Levonfi
8055ca82e69SJohn Levon
8065ca82e69SJohn Levonif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
8075ca82e69SJohn Levon	MAILTO=$STAFFER
8085ca82e69SJohn Levon	export MAILTO
8095ca82e69SJohn Levonfi
8105ca82e69SJohn Levon
8115ca82e69SJohn LevonPATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
8125ca82e69SJohn LevonPATH="$PATH:$OPTHOME/SUNWspro/bin:/usr/bin:/usr/sbin:/usr/ucb"
8135ca82e69SJohn LevonPATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
8145ca82e69SJohn Levonexport PATH
8155ca82e69SJohn Levon
8165ca82e69SJohn Levon# roots of source trees, both relative to $SRC and absolute.
8175ca82e69SJohn Levonrelsrcdirs="."
8185ca82e69SJohn Levonabssrcdirs="$SRC"
8195ca82e69SJohn Levon
8205ca82e69SJohn LevonPROTOCMPTERSE="protocmp.terse -gu"
8215ca82e69SJohn LevonPOUND_SIGN="#"
8226112cec5SJoshua M. Clulowbasews="$(basename "$CODEMGR_WS")"
8235ca82e69SJohn Levon# have we set RELEASE_DATE in our env file?
8245ca82e69SJohn Levonif [ -z "$RELEASE_DATE" ]; then
8255ca82e69SJohn Levon	RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
8265ca82e69SJohn Levonfi
8276112cec5SJoshua M. Clulownow=$(LC_ALL=C date +%Y-%b-%d)
8286112cec5SJoshua M. ClulowDEV_CM_TAIL="development build: $LOGNAME $now [$basews]"
8295ca82e69SJohn Levon
8306112cec5SJoshua M. Clulow#
8316112cec5SJoshua M. Clulow# We export POUND_SIGN, RELEASE_DATE and DEV_CM_TAIL to speed up the build
8326112cec5SJoshua M. Clulow# process by avoiding repeated shell invocations to evaluate Makefile.master
8335ca82e69SJohn Levon# definitions.
8346112cec5SJoshua M. Clulow#
8356112cec5SJoshua M. Clulowexport POUND_SIGN RELEASE_DATE DEV_CM_TAIL
8365ca82e69SJohn Levon
8375ca82e69SJohn Levonmaketype="distributed"
8385ca82e69SJohn Levonif [[ -z "$MAKE" ]]; then
8395ca82e69SJohn Levon	MAKE=dmake
8405ca82e69SJohn Levonelif [[ ! -x "$MAKE" ]]; then
8415ca82e69SJohn Levon	echo "\$MAKE is set to garbage in the environment"
8425ca82e69SJohn Levon	exit 1
8435ca82e69SJohn Levonfi
8445ca82e69SJohn Levonexport PATH
8455ca82e69SJohn Levonexport MAKE
8465ca82e69SJohn Levon
8475ca82e69SJohn Levonif [ "${SUNWSPRO}" != "" ]; then
8485ca82e69SJohn Levon	PATH="${SUNWSPRO}/bin:$PATH"
8495ca82e69SJohn Levon	export PATH
8505ca82e69SJohn Levonfi
8515ca82e69SJohn Levon
8525ca82e69SJohn Levonhostname=$(uname -n)
85326e7d9a8SRichard Loweif [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS == 0 ]]
8545ca82e69SJohn Levonthen
8555ca82e69SJohn Levon	maxjobs=
8565ca82e69SJohn Levon	if [[ -f $HOME/.make.machines ]]
8575ca82e69SJohn Levon	then
858244a25b4SBill Sommerfeld		egrep -i $'^[\t ]*'"${hostname}"$'[\t .]' \
8595ca82e69SJohn Levon			$HOME/.make.machines | read host jobs
8605ca82e69SJohn Levon		maxjobs=${jobs##*=}
8615ca82e69SJohn Levon	fi
8625ca82e69SJohn Levon
86326e7d9a8SRichard Lowe	if [[ $maxjobs != +([0-9]) || $maxjobs == 0 ]]
8645ca82e69SJohn Levon	then
8655ca82e69SJohn Levon		# default
8665ca82e69SJohn Levon		maxjobs=4
8675ca82e69SJohn Levon	fi
8685ca82e69SJohn Levon
8695ca82e69SJohn Levon	export DMAKE_MAX_JOBS=$maxjobs
8705ca82e69SJohn Levonfi
8715ca82e69SJohn Levon
8725ca82e69SJohn LevonDMAKE_MODE=parallel;
8735ca82e69SJohn Levonexport DMAKE_MODE
8745ca82e69SJohn Levon
8755ca82e69SJohn Levonif [ -z "${ROOT}" ]; then
8765ca82e69SJohn Levon	echo "ROOT must be set."
8775ca82e69SJohn Levon	exit 1
8785ca82e69SJohn Levonfi
8795ca82e69SJohn Levon
8805ca82e69SJohn LevonTMPDIR="/tmp/nightly.tmpdir.$$"
8815ca82e69SJohn Levonexport TMPDIR
8825ca82e69SJohn Levonrm -rf ${TMPDIR}
8835ca82e69SJohn Levonmkdir -p $TMPDIR || exit 1
8845ca82e69SJohn Levonchmod 777 $TMPDIR
8855ca82e69SJohn Levon
8865ca82e69SJohn Levon#
8875ca82e69SJohn Levon# Work around folks who have historically used GCC_ROOT and convert it to
8885ca82e69SJohn Levon# GNUC_ROOT. We leave GCC_ROOT in the environment for now (though this could
8895ca82e69SJohn Levon# mess up the case where multiple different gcc versions are being used to
8905ca82e69SJohn Levon# shadow).
8915ca82e69SJohn Levon#
8925ca82e69SJohn Levonif [[ -n "${GCC_ROOT}" ]]; then
8935ca82e69SJohn Levon	export GNUC_ROOT=${GCC_ROOT}
8945ca82e69SJohn Levonfi
8955ca82e69SJohn Levon
8965ca82e69SJohn Levon#
8975ca82e69SJohn Levon# Tools should only be built non-DEBUG.  Keep track of the tools proto
8985ca82e69SJohn Levon# area path relative to $TOOLS, because the latter changes in an
8995ca82e69SJohn Levon# export build.
9005ca82e69SJohn Levon#
9015ca82e69SJohn Levon# TOOLS_PROTO is included below for builds other than usr/src/tools
9025ca82e69SJohn Levon# that look for this location.  For usr/src/tools, this will be
9035ca82e69SJohn Levon# overridden on the $MAKE command line in build_tools().
9045ca82e69SJohn Levon#
9055ca82e69SJohn LevonTOOLS=${SRC}/tools
9065ca82e69SJohn LevonTOOLS_PROTO_REL=proto/root_${MACH}-nd
9075ca82e69SJohn LevonTOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL};	export TOOLS_PROTO
9085ca82e69SJohn Levon
9095ca82e69SJohn Levonunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
9105ca82e69SJohn Levon
911*fc8c3a51SBill Sommerfeld#
912*fc8c3a51SBill Sommerfeld# Echo the SCM type of the parent workspace, this can't just be which_scm
913*fc8c3a51SBill Sommerfeld# as that does not know how to identify various network repositories.
914*fc8c3a51SBill Sommerfeld#
915*fc8c3a51SBill Sommerfeldfunction parent_wstype {
916*fc8c3a51SBill Sommerfeld	typeset scm_type junk
917*fc8c3a51SBill Sommerfeld
918*fc8c3a51SBill Sommerfeld	CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
919*fc8c3a51SBill Sommerfeld	    | read scm_type junk
920*fc8c3a51SBill Sommerfeld	if [[ -z "$scm_type" || "$scm_type" == unknown ]]; then
921*fc8c3a51SBill Sommerfeld		# Probe BRINGOVER_WS to determine its type
922*fc8c3a51SBill Sommerfeld		case "$BRINGOVER_WS" in
923*fc8c3a51SBill Sommerfeld		git://* | http://*.git | https://*.git)
924*fc8c3a51SBill Sommerfeld			scm_type="git"
925*fc8c3a51SBill Sommerfeld			;;
926*fc8c3a51SBill Sommerfeld		ssh://* | http://* | https://* )
927*fc8c3a51SBill Sommerfeld			scm_type="${BRINGOVER_SCM}"
928*fc8c3a51SBill Sommerfeld			;;
929*fc8c3a51SBill Sommerfeld		*)	scm_type="none"
930*fc8c3a51SBill Sommerfeld			;;
931*fc8c3a51SBill Sommerfeld		esac
932*fc8c3a51SBill Sommerfeld	fi
933*fc8c3a51SBill Sommerfeld
934*fc8c3a51SBill Sommerfeld	# fold both unsupported and unrecognized results into "none"
935*fc8c3a51SBill Sommerfeld	case "$scm_type" in
936*fc8c3a51SBill Sommerfeld	mercurial|git)
937*fc8c3a51SBill Sommerfeld		;;
938*fc8c3a51SBill Sommerfeld	*)	scm_type=none
939*fc8c3a51SBill Sommerfeld		;;
940*fc8c3a51SBill Sommerfeld	esac
941*fc8c3a51SBill Sommerfeld
942*fc8c3a51SBill Sommerfeld	echo $scm_type
943*fc8c3a51SBill Sommerfeld}
944*fc8c3a51SBill Sommerfeld
945*fc8c3a51SBill Sommerfeld# Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
946*fc8c3a51SBill Sommerfeldfunction child_wstype {
947*fc8c3a51SBill Sommerfeld	typeset scm_type junk
948*fc8c3a51SBill Sommerfeld
949*fc8c3a51SBill Sommerfeld	# Probe CODEMGR_WS to determine its type
950*fc8c3a51SBill Sommerfeld	if [[ -d $CODEMGR_WS ]]; then
951*fc8c3a51SBill Sommerfeld		$WHICH_SCM | read scm_type junk || exit 1
952*fc8c3a51SBill Sommerfeld	fi
953*fc8c3a51SBill Sommerfeld
954*fc8c3a51SBill Sommerfeld	case "$scm_type" in
955*fc8c3a51SBill Sommerfeld	none|git|mercurial)
956*fc8c3a51SBill Sommerfeld		;;
957*fc8c3a51SBill Sommerfeld	*)	scm_type=none
958*fc8c3a51SBill Sommerfeld		;;
959*fc8c3a51SBill Sommerfeld	esac
960*fc8c3a51SBill Sommerfeld
961*fc8c3a51SBill Sommerfeld	echo $scm_type
962*fc8c3a51SBill Sommerfeld}
963*fc8c3a51SBill Sommerfeld
9645ca82e69SJohn Levon# create directories that are automatically removed if the nightly script
9655ca82e69SJohn Levon# fails to start correctly
9665ca82e69SJohn Levonfunction newdir {
9675ca82e69SJohn Levon	dir=$1
9685ca82e69SJohn Levon	toadd=
9695ca82e69SJohn Levon	while [ ! -d $dir ]; do
9705ca82e69SJohn Levon		toadd="$dir $toadd"
9715ca82e69SJohn Levon		dir=`dirname $dir`
9725ca82e69SJohn Levon	done
9735ca82e69SJohn Levon	torm=
9745ca82e69SJohn Levon	newlist=
9755ca82e69SJohn Levon	for dir in $toadd; do
9765ca82e69SJohn Levon		if staffer mkdir $dir; then
9775ca82e69SJohn Levon			newlist="$ISUSER $dir $newlist"
9785ca82e69SJohn Levon			torm="$dir $torm"
9795ca82e69SJohn Levon		else
9805ca82e69SJohn Levon			[ -z "$torm" ] || staffer rmdir $torm
9815ca82e69SJohn Levon			return 1
9825ca82e69SJohn Levon		fi
9835ca82e69SJohn Levon	done
9845ca82e69SJohn Levon	newdirlist="$newlist $newdirlist"
9855ca82e69SJohn Levon	return 0
9865ca82e69SJohn Levon}
9875ca82e69SJohn Levonnewdirlist=
9885ca82e69SJohn Levon
989*fc8c3a51SBill Sommerfeld# Initialize the git repo before creating the log subdir; "git clone" insists
990*fc8c3a51SBill Sommerfeld# that a preexisting directory be empty.
991*fc8c3a51SBill Sommerfeld# Use --reference-if-able to share most of the parent's .git tree.
992*fc8c3a51SBill Sommerfeldtype init_git > /dev/null 2>&1 || function init_git {
993*fc8c3a51SBill Sommerfeld	if [ -d "${BRINGOVER_WS}" ]; then
994*fc8c3a51SBill Sommerfeld		REF_WS="--reference-if-able $(git -C ${BRINGOVER_WS} rev-parse --path-format=absolute --git-common-dir)"
995*fc8c3a51SBill Sommerfeld	fi
996*fc8c3a51SBill Sommerfeld	staffer git clone \
997*fc8c3a51SBill Sommerfeld		--no-checkout \
998*fc8c3a51SBill Sommerfeld		${CLONE_OPTIONS} \
999*fc8c3a51SBill Sommerfeld		--origin ${BRINGOVER_REMOTE} \
1000*fc8c3a51SBill Sommerfeld		${REF_WS} \
1001*fc8c3a51SBill Sommerfeld		${BRINGOVER_WS} ${CODEMGR_WS}
1002*fc8c3a51SBill Sommerfeld}
1003*fc8c3a51SBill Sommerfeld
1004*fc8c3a51SBill Sommerfeld# All mercurial initialization is done in bringover_mercurial
1005*fc8c3a51SBill Sommerfeldtype init_mercurial > /dev/null 2>&1 || function init_mercurial {
1006*fc8c3a51SBill Sommerfeld	newdir $CODEMGR_WS
1007*fc8c3a51SBill Sommerfeld}
1008*fc8c3a51SBill Sommerfeld
1009*fc8c3a51SBill Sommerfeldtype init_none > /dev/null 2>&1 || function init_none {
1010*fc8c3a51SBill Sommerfeld	newdir $CODEMGR_WS
1011*fc8c3a51SBill Sommerfeld}
1012*fc8c3a51SBill Sommerfeld
1013*fc8c3a51SBill Sommerfeldfunction create_build_ws {
1014*fc8c3a51SBill Sommerfeld	PARENT_SCM_TYPE=$(parent_wstype)
1015*fc8c3a51SBill Sommerfeld
1016*fc8c3a51SBill Sommerfeld	eval "init_${PARENT_SCM_TYPE}" 2>&1
1017*fc8c3a51SBill Sommerfeld}
1018*fc8c3a51SBill Sommerfeld
1019*fc8c3a51SBill Sommerfeld[ -d $CODEMGR_WS ] || create_build_ws || exit 1
10205ca82e69SJohn Levon
10215ca82e69SJohn Levon# since this script assumes the build is from full source, it nullifies
10225ca82e69SJohn Levon# variables likely to have been set by a "ws" script; nullification
10235ca82e69SJohn Levon# confines the search space for headers and libraries to the proto area
10245ca82e69SJohn Levon# built from this immediate source.
10255ca82e69SJohn LevonENVLDLIBS1=
10265ca82e69SJohn LevonENVLDLIBS2=
10275ca82e69SJohn LevonENVLDLIBS3=
10285ca82e69SJohn LevonENVCPPFLAGS1=
10295ca82e69SJohn LevonENVCPPFLAGS2=
10305ca82e69SJohn LevonENVCPPFLAGS3=
10315ca82e69SJohn LevonENVCPPFLAGS4=
10325ca82e69SJohn LevonPARENT_ROOT=
10335ca82e69SJohn Levon
10345ca82e69SJohn Levonexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
10355ca82e69SJohn Levon	ENVLDLIBS1 ENVLDLIBS2 PARENT_ROOT
10365ca82e69SJohn Levon
10375ca82e69SJohn LevonPKGARCHIVE_ORIG=$PKGARCHIVE
10385ca82e69SJohn Levon
10395ca82e69SJohn Levon#
10405ca82e69SJohn Levon# Juggle the logs and optionally send mail on completion.
10415ca82e69SJohn Levon#
10425ca82e69SJohn Levon
10435ca82e69SJohn Levonfunction logshuffle {
10445ca82e69SJohn Levon	LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
10455ca82e69SJohn Levon	if [ -f $LLOG -o -d $LLOG ]; then
10465ca82e69SJohn Levon		LLOG=$LLOG.$$
10475ca82e69SJohn Levon	fi
10485ca82e69SJohn Levon
10495ca82e69SJohn Levon	rm -f "$ATLOG/latest" 2>/dev/null
10505ca82e69SJohn Levon	mkdir -p $LLOG
10515ca82e69SJohn Levon	export LLOG
10525ca82e69SJohn Levon
10535ca82e69SJohn Levon	if [ "$build_ok" = "y" ]; then
10545ca82e69SJohn Levon		mv $ATLOG/proto_list_${MACH} $LLOG
10555ca82e69SJohn Levon
10565ca82e69SJohn Levon		if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
10575ca82e69SJohn Levon			mv $ATLOG/proto_list_tools_${MACH} $LLOG
10585ca82e69SJohn Levon	        fi
10595ca82e69SJohn Levon
10605ca82e69SJohn Levon		if [ -f $TMPDIR/wsdiff.results ]; then
10615ca82e69SJohn Levon			mv $TMPDIR/wsdiff.results $LLOG
10625ca82e69SJohn Levon		fi
10635ca82e69SJohn Levon
10645ca82e69SJohn Levon		if [ -f $TMPDIR/wsdiff-nd.results ]; then
10655ca82e69SJohn Levon			mv $TMPDIR/wsdiff-nd.results $LLOG
10665ca82e69SJohn Levon		fi
10675ca82e69SJohn Levon	fi
10685ca82e69SJohn Levon
10695ca82e69SJohn Levon	#
10705ca82e69SJohn Levon	# Now that we're about to send mail, it's time to check the noise
10715ca82e69SJohn Levon	# file.  In the event that an error occurs beyond this point, it will
10725ca82e69SJohn Levon	# be recorded in the nightly.log file, but nowhere else.  This would
10735ca82e69SJohn Levon	# include only errors that cause the copying of the noise log to fail
10745ca82e69SJohn Levon	# or the mail itself not to be sent.
10755ca82e69SJohn Levon	#
10765ca82e69SJohn Levon
10775ca82e69SJohn Levon	exec >>$LOGFILE 2>&1
10785ca82e69SJohn Levon	if [ -s $build_noise_file ]; then
10795ca82e69SJohn Levon		echo "\n==== Nightly build noise ====\n" |
10805ca82e69SJohn Levon		    tee -a $LOGFILE >>$mail_msg_file
10815ca82e69SJohn Levon		cat $build_noise_file >>$LOGFILE
10825ca82e69SJohn Levon		cat $build_noise_file >>$mail_msg_file
10835ca82e69SJohn Levon		echo | tee -a $LOGFILE >>$mail_msg_file
10845ca82e69SJohn Levon	fi
10855ca82e69SJohn Levon	rm -f $build_noise_file
10865ca82e69SJohn Levon
10875ca82e69SJohn Levon	case "$build_ok" in
10885ca82e69SJohn Levon		y)
10895ca82e69SJohn Levon			state=Completed
10905ca82e69SJohn Levon			;;
10915ca82e69SJohn Levon		i)
10925ca82e69SJohn Levon			state=Interrupted
10935ca82e69SJohn Levon			;;
10945ca82e69SJohn Levon		*)
10955ca82e69SJohn Levon			state=Failed
10965ca82e69SJohn Levon			;;
10975ca82e69SJohn Levon	esac
10985ca82e69SJohn Levon
10995ca82e69SJohn Levon	if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
11005ca82e69SJohn Levon		state=Failed
11015ca82e69SJohn Levon	fi
11025ca82e69SJohn Levon
11035ca82e69SJohn Levon	NIGHTLY_STATUS=$state
11045ca82e69SJohn Levon	export NIGHTLY_STATUS
11055ca82e69SJohn Levon
11065ca82e69SJohn Levon	run_hook POST_NIGHTLY $state
11075ca82e69SJohn Levon	run_hook SYS_POST_NIGHTLY $state
11085ca82e69SJohn Levon
11095ca82e69SJohn Levon	#
11105ca82e69SJohn Levon	# mailx(1) sets From: based on the -r flag
11115ca82e69SJohn Levon	# if it is given.
11125ca82e69SJohn Levon	#
11135ca82e69SJohn Levon	mailx_r=
11145ca82e69SJohn Levon	if [[ -n "${MAILFROM}" ]]; then
11155ca82e69SJohn Levon		mailx_r="-r ${MAILFROM}"
11165ca82e69SJohn Levon	fi
11175ca82e69SJohn Levon
11185ca82e69SJohn Levon	cat $build_time_file $build_environ_file $mail_msg_file \
11195ca82e69SJohn Levon	    > ${LLOG}/mail_msg
11205ca82e69SJohn Levon	if [ "$m_FLAG" = "y" ]; then
11216112cec5SJoshua M. Clulow		/usr/bin/mailx ${mailx_r} -s \
11226112cec5SJoshua M. Clulow		    "Nightly ${MACH} Build of ${basews} ${state}." \
11236112cec5SJoshua M. Clulow		    "${MAILTO}" < "${LLOG}/mail_msg"
11245ca82e69SJohn Levon	fi
11255ca82e69SJohn Levon
11265ca82e69SJohn Levon	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
11275ca82e69SJohn Levon		staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
11285ca82e69SJohn Levon		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
11295ca82e69SJohn Levon	fi
11305ca82e69SJohn Levon
11315ca82e69SJohn Levon	mv $LOGFILE $LLOG
11325ca82e69SJohn Levon
11335ca82e69SJohn Levon	ln -s "$LLOG" "$ATLOG/latest"
11345ca82e69SJohn Levon}
11355ca82e69SJohn Levon
11365ca82e69SJohn Levon#
11375ca82e69SJohn Levon#	Remove the locks and temporary files on any exit
11385ca82e69SJohn Levon#
11395ca82e69SJohn Levonfunction cleanup {
11405ca82e69SJohn Levon	logshuffle
11415ca82e69SJohn Levon
11425ca82e69SJohn Levon	[ -z "$lockfile" ] || staffer rm -f $lockfile
11435ca82e69SJohn Levon	[ -z "$atloglockfile" ] || rm -f $atloglockfile
11445ca82e69SJohn Levon	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
11455ca82e69SJohn Levon	[ -z "$Ulockfile" ] || rm -f $Ulockfile
11465ca82e69SJohn Levon
11475ca82e69SJohn Levon	set -- $newdirlist
11485ca82e69SJohn Levon	while [ $# -gt 0 ]; do
11495ca82e69SJohn Levon		ISUSER=$1 staffer rmdir $2
11505ca82e69SJohn Levon		shift; shift
11515ca82e69SJohn Levon	done
11525ca82e69SJohn Levon	rm -rf $TMPDIR
11535ca82e69SJohn Levon}
11545ca82e69SJohn Levon
11555ca82e69SJohn Levonfunction cleanup_signal {
11565ca82e69SJohn Levon	build_ok=i
11575ca82e69SJohn Levon	# this will trigger cleanup(), above.
11585ca82e69SJohn Levon	exit 1
11595ca82e69SJohn Levon}
11605ca82e69SJohn Levon
11615ca82e69SJohn Levontrap cleanup 0
11625ca82e69SJohn Levontrap cleanup_signal 1 2 3 15
11635ca82e69SJohn Levon
11645ca82e69SJohn Levon#
11655ca82e69SJohn Levon# Generic lock file processing -- make sure that the lock file doesn't
11665ca82e69SJohn Levon# exist.  If it does, it should name the build host and PID.  If it
11675ca82e69SJohn Levon# doesn't, then make sure we can create it.  Clean up locks that are
11685ca82e69SJohn Levon# known to be stale (assumes host name is unique among build systems
11695ca82e69SJohn Levon# for the workspace).
11705ca82e69SJohn Levon#
11715ca82e69SJohn Levonfunction create_lock {
11725ca82e69SJohn Levon	lockf=$1
11735ca82e69SJohn Levon	lockvar=$2
11745ca82e69SJohn Levon
11755ca82e69SJohn Levon	ldir=`dirname $lockf`
11765ca82e69SJohn Levon	[ -d $ldir ] || newdir $ldir || exit 1
11775ca82e69SJohn Levon	eval $lockvar=$lockf
11785ca82e69SJohn Levon
11795ca82e69SJohn Levon	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
11805ca82e69SJohn Levon		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
11815ca82e69SJohn Levon		if [ "$host" != "$hostname" ]; then
11825ca82e69SJohn Levon			echo "$MACH build of $basews apparently" \
11835ca82e69SJohn Levon			    "already started by $user on $host as $pid."
11845ca82e69SJohn Levon			exit 1
11855ca82e69SJohn Levon		elif kill -s 0 $pid 2>/dev/null; then
11865ca82e69SJohn Levon			echo "$MACH build of $basews already started" \
11875ca82e69SJohn Levon			    "by $user as $pid."
11885ca82e69SJohn Levon			exit 1
11895ca82e69SJohn Levon		else
11905ca82e69SJohn Levon			# stale lock; clear it out and try again
11915ca82e69SJohn Levon			rm -f $lockf
11925ca82e69SJohn Levon		fi
11935ca82e69SJohn Levon	done
11945ca82e69SJohn Levon}
11955ca82e69SJohn Levon
11965ca82e69SJohn Levon#
11975ca82e69SJohn Levon# Return the list of interesting proto areas, depending on the current
11985ca82e69SJohn Levon# options.
11995ca82e69SJohn Levon#
12005ca82e69SJohn Levonfunction allprotos {
12015ca82e69SJohn Levon	typeset roots="$ROOT"
12025ca82e69SJohn Levon
120326e7d9a8SRichard Lowe	if [[ "$F_FLAG" == n && "$MULTI_PROTO" == yes ]]; then
12045ca82e69SJohn Levon		roots="$roots $ROOT-nd"
12055ca82e69SJohn Levon	fi
12065ca82e69SJohn Levon
12075ca82e69SJohn Levon	echo $roots
12085ca82e69SJohn Levon}
12095ca82e69SJohn Levon
12105ca82e69SJohn Levon# Ensure no other instance of this script is running on this host.
12115ca82e69SJohn Levon# LOCKNAME can be set in <env_file>, and is by default, but is not
12125ca82e69SJohn Levon# required due to the use of $ATLOG below.
12135ca82e69SJohn Levonif [ -n "$LOCKNAME" ]; then
12145ca82e69SJohn Levon	create_lock /tmp/$LOCKNAME "lockfile"
12155ca82e69SJohn Levonfi
12165ca82e69SJohn Levon#
12175ca82e69SJohn Levon# Create from one, two, or three other locks:
12185ca82e69SJohn Levon#	$ATLOG/nightly.lock
12195ca82e69SJohn Levon#		- protects against multiple builds in same workspace
12205ca82e69SJohn Levon#	$PARENT_WS/usr/src/nightly.$MACH.lock
12215ca82e69SJohn Levon#		- protects against multiple 'u' copy-backs
12225ca82e69SJohn Levon#	$NIGHTLY_PARENT_ROOT/nightly.lock
12235ca82e69SJohn Levon#		- protects against multiple 'U' copy-backs
12245ca82e69SJohn Levon#
12255ca82e69SJohn Levon# Overriding ISUSER to 1 causes the lock to be created as root if the
12265ca82e69SJohn Levon# script is run as root.  The default is to create it as $STAFFER.
12275ca82e69SJohn LevonISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
12285ca82e69SJohn Levonif [ "$u_FLAG" = "y" ]; then
12295ca82e69SJohn Levon	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
12305ca82e69SJohn Levonfi
12315ca82e69SJohn Levonif [ "$U_FLAG" = "y" ]; then
12325ca82e69SJohn Levon	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
12335ca82e69SJohn Levon	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
12345ca82e69SJohn Levonfi
12355ca82e69SJohn Levon
12365ca82e69SJohn Levon# Locks have been taken, so we're doing a build and we're committed to
12375ca82e69SJohn Levon# the directories we may have created so far.
12385ca82e69SJohn Levonnewdirlist=
12395ca82e69SJohn Levon
12405ca82e69SJohn Levon#
12415ca82e69SJohn Levon# Create mail_msg_file
12425ca82e69SJohn Levon#
12435ca82e69SJohn Levonmail_msg_file="${TMPDIR}/mail_msg"
12445ca82e69SJohn Levontouch $mail_msg_file
12455ca82e69SJohn Levonbuild_time_file="${TMPDIR}/build_time"
12465ca82e69SJohn Levonbuild_environ_file="${TMPDIR}/build_environ"
12475ca82e69SJohn Levontouch $build_environ_file
12485ca82e69SJohn Levon#
12495ca82e69SJohn Levon#	Move old LOGFILE aside
12505ca82e69SJohn Levon#	ATLOG directory already made by 'create_lock' above
12515ca82e69SJohn Levon#
12525ca82e69SJohn Levonif [ -f $LOGFILE ]; then
12535ca82e69SJohn Levon	mv -f $LOGFILE ${LOGFILE}-
12545ca82e69SJohn Levonfi
12555ca82e69SJohn Levon#
12565ca82e69SJohn Levon#	Build OsNet source
12575ca82e69SJohn Levon#
12585ca82e69SJohn LevonSTART_DATE=`date`
12595ca82e69SJohn LevonSECONDS=0
12605ca82e69SJohn Levonecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
12615ca82e69SJohn Levon    | tee -a $LOGFILE > $build_time_file
12625ca82e69SJohn Levon
12635ca82e69SJohn Levonecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
12645ca82e69SJohn Levon    tee -a $mail_msg_file >> $LOGFILE
12655ca82e69SJohn Levon
12665ca82e69SJohn Levon# make sure we log only to the nightly build file
12675ca82e69SJohn Levonbuild_noise_file="${TMPDIR}/build_noise"
12685ca82e69SJohn Levonexec </dev/null >$build_noise_file 2>&1
12695ca82e69SJohn Levon
12705ca82e69SJohn Levonrun_hook SYS_PRE_NIGHTLY
12715ca82e69SJohn Levonrun_hook PRE_NIGHTLY
12725ca82e69SJohn Levon
12735ca82e69SJohn Levonecho "\n==== list of environment variables ====\n" >> $LOGFILE
12745ca82e69SJohn Levonenv >> $LOGFILE
12755ca82e69SJohn Levon
12765ca82e69SJohn Levonecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
12775ca82e69SJohn Levon
12785ca82e69SJohn Levonif [ "$N_FLAG" = "y" ]; then
12795ca82e69SJohn Levon	if [ "$p_FLAG" = "y" ]; then
12805ca82e69SJohn Levon		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
12815ca82e69SJohn LevonWARNING: the p option (create packages) is set, but so is the N option (do
12825ca82e69SJohn Levon         not run protocmp); this is dangerous; you should unset the N option
12835ca82e69SJohn LevonEOF
12845ca82e69SJohn Levon	else
12855ca82e69SJohn Levon		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
12865ca82e69SJohn LevonWarning: the N option (do not run protocmp) is set; it probably shouldn't be
12875ca82e69SJohn LevonEOF
12885ca82e69SJohn Levon	fi
12895ca82e69SJohn Levon	echo "" | tee -a $mail_msg_file >> $LOGFILE
12905ca82e69SJohn Levonfi
12915ca82e69SJohn Levon
12925ca82e69SJohn Levonif [ "$f_FLAG" = "y" ]; then
12935ca82e69SJohn Levon	if [ "$i_FLAG" = "y" ]; then
12945ca82e69SJohn Levon		echo "WARNING: the -f flag cannot be used during incremental" \
12955ca82e69SJohn Levon		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
12965ca82e69SJohn Levon		f_FLAG=n
12975ca82e69SJohn Levon	fi
12985ca82e69SJohn Levon	if [ "${p_FLAG}" != "y" ]; then
12995ca82e69SJohn Levon		echo "WARNING: the -f flag requires -p;" \
13005ca82e69SJohn Levon		    "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
13015ca82e69SJohn Levon		f_FLAG=n
13025ca82e69SJohn Levon	fi
13035ca82e69SJohn Levonfi
13045ca82e69SJohn Levon
13055ca82e69SJohn Levonif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
13065ca82e69SJohn Levon	echo "WARNING: -w specified, but $ROOT does not exist;" \
13075ca82e69SJohn Levon	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
13085ca82e69SJohn Levon	w_FLAG=n
13095ca82e69SJohn Levonfi
13105ca82e69SJohn Levon
13115ca82e69SJohn Levoncase $MULTI_PROTO in
13125ca82e69SJohn Levonyes|no)	;;
13135ca82e69SJohn Levon*)
13145ca82e69SJohn Levon	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
13155ca82e69SJohn Levon	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
13165ca82e69SJohn Levon	echo "Setting MULTI_PROTO to \"no\".\n" | \
13175ca82e69SJohn Levon	    tee -a $mail_msg_file >> $LOGFILE
13185ca82e69SJohn Levon	export MULTI_PROTO=no
13195ca82e69SJohn Levon	;;
13205ca82e69SJohn Levonesac
13215ca82e69SJohn Levon
13225ca82e69SJohn Levon# Save the current proto area if we're comparing against the last build
13235ca82e69SJohn Levonif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
13245ca82e69SJohn Levon    if [ -d "$ROOT.prev" ]; then
13255ca82e69SJohn Levon	rm -rf $ROOT.prev
13265ca82e69SJohn Levon    fi
13275ca82e69SJohn Levon    mv $ROOT $ROOT.prev
13285ca82e69SJohn Levonfi
13295ca82e69SJohn Levon
13305ca82e69SJohn Levon# Same for non-DEBUG proto area
13315ca82e69SJohn Levonif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
13325ca82e69SJohn Levon	if [ -d "$ROOT-nd.prev" ]; then
13335ca82e69SJohn Levon		rm -rf $ROOT-nd.prev
13345ca82e69SJohn Levon	fi
13355ca82e69SJohn Levon	mv $ROOT-nd $ROOT-nd.prev
13365ca82e69SJohn Levonfi
13375ca82e69SJohn Levon
13385ca82e69SJohn LevonSCM_TYPE=$(child_wstype)
13395ca82e69SJohn Levon
13405ca82e69SJohn Levon#
13415ca82e69SJohn Levon#	Decide whether to clobber
13425ca82e69SJohn Levon#
13435ca82e69SJohn Levonif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
13445ca82e69SJohn Levon	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
13455ca82e69SJohn Levon
13465ca82e69SJohn Levon	cd $SRC
13475ca82e69SJohn Levon	# remove old clobber file
13485ca82e69SJohn Levon	rm -f $SRC/clobber.out
13495ca82e69SJohn Levon	rm -f $SRC/clobber-${MACH}.out
13505ca82e69SJohn Levon
13515ca82e69SJohn Levon	# Remove all .make.state* files, just in case we are restarting
13525ca82e69SJohn Levon	# the build after having interrupted a previous 'make clobber'.
13535ca82e69SJohn Levon	find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
13545ca82e69SJohn Levon		-o -name 'interfaces.*' \) -prune \
13555ca82e69SJohn Levon		-o -name '.make.*' -print | xargs rm -f
13565ca82e69SJohn Levon
13575ca82e69SJohn Levon	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
13585ca82e69SJohn Levon	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
13595ca82e69SJohn Levon	grep "$MAKE:" $SRC/clobber-${MACH}.out |
1360eefeb0ceSBill Sommerfeld		egrep -v ": (Entering|Leaving) directory " | \
13615ca82e69SJohn Levon		egrep -v "Ignoring unknown host" | \
13625ca82e69SJohn Levon		tee $TMPDIR/clobber_errs >> $mail_msg_file
13635ca82e69SJohn Levon
13645ca82e69SJohn Levon	if [[ -s $TMPDIR/clobber_errs ]]; then
13655ca82e69SJohn Levon		build_extras_ok=n
13665ca82e69SJohn Levon	fi
13675ca82e69SJohn Levon
136826e7d9a8SRichard Lowe	if [[ "$t_FLAG" == "y" ]]; then
13695ca82e69SJohn Levon		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
13705ca82e69SJohn Levon		cd ${TOOLS}
13715ca82e69SJohn Levon		rm -f ${TOOLS}/clobber-${MACH}.out
13725ca82e69SJohn Levon		$MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \
13735ca82e69SJohn Levon			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
13745ca82e69SJohn Levon		echo "\n==== Make tools clobber ERRORS ====\n" \
13755ca82e69SJohn Levon			>> $mail_msg_file
13765ca82e69SJohn Levon		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
1377eefeb0ceSBill Sommerfeld			| egrep -v ": (Entering|Leaving) directory " \
13785ca82e69SJohn Levon			>> $mail_msg_file
13795ca82e69SJohn Levon		if (( $? == 0 )); then
13805ca82e69SJohn Levon			build_extras_ok=n
13815ca82e69SJohn Levon		fi
13825ca82e69SJohn Levon		rm -rf ${TOOLS_PROTO}
13835ca82e69SJohn Levon		mkdir -p ${TOOLS_PROTO}
13845ca82e69SJohn Levon	fi
13855ca82e69SJohn Levon
13865ca82e69SJohn Levon	typeset roots=$(allprotos)
13875ca82e69SJohn Levon	echo "\n\nClearing $roots" >> "$LOGFILE"
13885ca82e69SJohn Levon	rm -rf $roots
13895ca82e69SJohn Levon
13905ca82e69SJohn Levon	# Get back to a clean workspace as much as possible to catch
13915ca82e69SJohn Levon	# problems that only occur on fresh workspaces.
13925ca82e69SJohn Levon	# Remove all .make.state* files, libraries, and .o's that may
13935ca82e69SJohn Levon	# have been omitted from clobber.  A couple of libraries are
13945ca82e69SJohn Levon	# under source code control, so leave them alone.
13955ca82e69SJohn Levon	# We should probably blow away temporary directories too.
13965ca82e69SJohn Levon	cd $SRC
13975ca82e69SJohn Levon	find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
13985ca82e69SJohn Levon	    -o -name .git -o -name 'interfaces.*' \) -prune -o \
13995ca82e69SJohn Levon	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
14005ca82e69SJohn Levon	       -name '*.o' \) -print | \
14015ca82e69SJohn Levon	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
14025ca82e69SJohn Levonelse
14035ca82e69SJohn Levon	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
14045ca82e69SJohn Levonfi
14055ca82e69SJohn Levon
1406*fc8c3a51SBill Sommerfeldtype bringover_git > /dev/null 2>&1 || function bringover_git {
1407*fc8c3a51SBill Sommerfeld	typeset -x PATH=$PATH
1408*fc8c3a51SBill Sommerfeld
1409*fc8c3a51SBill Sommerfeld	if [ "$BRINGOVER_BRANCH" = "" ]; then
1410*fc8c3a51SBill Sommerfeld		if [ -d "$BRINGOVER_WS" ]; then
1411*fc8c3a51SBill Sommerfeld			BRINGOVER_BRANCH=$(cd "${BRINGOVER_WS}"; git rev-parse --abbrev-ref HEAD)
1412*fc8c3a51SBill Sommerfeld			if [ "$BRINGOVER_BRANCH" = "HEAD" ]; then
1413*fc8c3a51SBill Sommerfeld				printf "%s: can't determine BRINGOVER_BRANCH from repo in 'detached HEAD' state\n" "$BRINGOVER_WS"
1414*fc8c3a51SBill Sommerfeld				touch $TMPDIR/bringover_failed
1415*fc8c3a51SBill Sommerfeld				return
1416*fc8c3a51SBill Sommerfeld			fi
1417*fc8c3a51SBill Sommerfeld		else
1418*fc8c3a51SBill Sommerfeld			printf "%s: can't determine BRINGOVER_BRANCH\n" "$BRINGOVER_WS"
1419*fc8c3a51SBill Sommerfeld			touch $TMPDIR/bringover_failed
1420*fc8c3a51SBill Sommerfeld			return
1421*fc8c3a51SBill Sommerfeld		fi
1422*fc8c3a51SBill Sommerfeld	fi
1423*fc8c3a51SBill Sommerfeld	(cd ${CODEMGR_WS} &&
1424*fc8c3a51SBill Sommerfeld		staffer git remote set-url ${BRINGOVER_REMOTE} ${BRINGOVER_WS} &&
1425*fc8c3a51SBill Sommerfeld		staffer git fetch ${BRINGOVER_REMOTE} ${BRINGOVER_BRANCH} &&
1426*fc8c3a51SBill Sommerfeld		staffer git switch --force-create ${BRINGOVER_BRANCH} \
1427*fc8c3a51SBill Sommerfeld			${BRINGOVER_REMOTE}/${BRINGOVER_BRANCH}) \
1428*fc8c3a51SBill Sommerfeld		    >$TMPDIR/bringover.out 2>&1
1429*fc8c3a51SBill Sommerfeld	if (( $? != 0 )); then
1430*fc8c3a51SBill Sommerfeld		printf "%s: update failed as follows:\n\n" "$CODEMGR_WS"
1431*fc8c3a51SBill Sommerfeld		cat $TMPDIR/bringover.out
1432*fc8c3a51SBill Sommerfeld		touch $TMPDIR/bringover_failed
1433*fc8c3a51SBill Sommerfeld		return
1434*fc8c3a51SBill Sommerfeld	fi
1435*fc8c3a51SBill Sommerfeld
1436*fc8c3a51SBill Sommerfeld	printf "%s: local branch '%s' updated to commit %s\n"	\
1437*fc8c3a51SBill Sommerfeld		"$CODEMGR_WS" "$BRINGOVER_BRANCH"		\
1438*fc8c3a51SBill Sommerfeld		$(cd ${CODEMGR_WS}; git rev-parse HEAD)
1439*fc8c3a51SBill Sommerfeld
1440*fc8c3a51SBill Sommerfeld	staffer git status --no-short --branch --untracked-files=no
1441*fc8c3a51SBill Sommerfeld}
1442*fc8c3a51SBill Sommerfeld
14435ca82e69SJohn Levontype bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
14445ca82e69SJohn Levon	typeset -x PATH=$PATH
14455ca82e69SJohn Levon
14465ca82e69SJohn Levon	# If the repository doesn't exist yet, then we want to populate it.
14475ca82e69SJohn Levon	if [[ ! -d $CODEMGR_WS/.hg ]]; then
14485ca82e69SJohn Levon		staffer hg init $CODEMGR_WS
14495ca82e69SJohn Levon		staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
14505ca82e69SJohn Levon		staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
14515ca82e69SJohn Levon		touch $TMPDIR/new_repository
14525ca82e69SJohn Levon	fi
14535ca82e69SJohn Levon
14545ca82e69SJohn Levon	typeset -x HGMERGE="/bin/false"
14555ca82e69SJohn Levon
14565ca82e69SJohn Levon	#
14575ca82e69SJohn Levon	# If the user has changes, regardless of whether those changes are
14585ca82e69SJohn Levon	# committed, and regardless of whether those changes conflict, then
14595ca82e69SJohn Levon	# we'll attempt to merge them either implicitly (uncommitted) or
14605ca82e69SJohn Levon	# explicitly (committed).
14615ca82e69SJohn Levon	#
14625ca82e69SJohn Levon	# These are the messages we'll use to help clarify mercurial output
14635ca82e69SJohn Levon	# in those cases.
14645ca82e69SJohn Levon	#
14655ca82e69SJohn Levon	typeset mergefailmsg="\
14665ca82e69SJohn Levon***\n\
14675ca82e69SJohn Levon*** nightly was unable to automatically merge your changes.  You should\n\
14685ca82e69SJohn Levon*** redo the full merge manually, following the steps outlined by mercurial\n\
14695ca82e69SJohn Levon*** above, then restart nightly.\n\
14705ca82e69SJohn Levon***\n"
14715ca82e69SJohn Levon	typeset mergepassmsg="\
14725ca82e69SJohn Levon***\n\
14735ca82e69SJohn Levon*** nightly successfully merged your changes.  This means that your working\n\
14745ca82e69SJohn Levon*** directory has been updated, but those changes are not yet committed.\n\
14755ca82e69SJohn Levon*** After nightly completes, you should validate the results of the merge,\n\
14765ca82e69SJohn Levon*** then use hg commit manually.\n\
14775ca82e69SJohn Levon***\n"
14785ca82e69SJohn Levon
14795ca82e69SJohn Levon	#
14805ca82e69SJohn Levon	# For each repository in turn:
14815ca82e69SJohn Levon	#
14825ca82e69SJohn Levon	# 1. Do the pull.  If this fails, dump the output and bail out.
14835ca82e69SJohn Levon	#
14845ca82e69SJohn Levon	# 2. If the pull resulted in an extra head, do an explicit merge.
14855ca82e69SJohn Levon	#    If this fails, dump the output and bail out.
14865ca82e69SJohn Levon	#
14875ca82e69SJohn Levon	# Because we can't rely on Mercurial to exit with a failure code
14885ca82e69SJohn Levon	# when a merge fails (Mercurial issue #186), we must grep the
14895ca82e69SJohn Levon	# output of pull/merge to check for attempted and/or failed merges.
14905ca82e69SJohn Levon	#
14915ca82e69SJohn Levon	# 3. If a merge failed, set the message and fail the bringover.
14925ca82e69SJohn Levon	#
14935ca82e69SJohn Levon	# 4. Otherwise, if a merge succeeded, set the message
14945ca82e69SJohn Levon	#
14955ca82e69SJohn Levon	# 5. Dump the output, and any message from step 3 or 4.
14965ca82e69SJohn Levon	#
14975ca82e69SJohn Levon
14985ca82e69SJohn Levon	typeset HG_SOURCE=$BRINGOVER_WS
14995ca82e69SJohn Levon	if [ ! -f $TMPDIR/new_repository ]; then
15005ca82e69SJohn Levon		HG_SOURCE=$TMPDIR/open_bundle.hg
15015ca82e69SJohn Levon		staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
15025ca82e69SJohn Levon		    -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
15035ca82e69SJohn Levon
15045ca82e69SJohn Levon		#
15055ca82e69SJohn Levon		# If there are no incoming changesets, then incoming will
15065ca82e69SJohn Levon		# fail, and there will be no bundle file.  Reset the source,
15075ca82e69SJohn Levon		# to allow the remaining logic to complete with no false
15085ca82e69SJohn Levon		# negatives.  (Unlike incoming, pull will return success
15095ca82e69SJohn Levon		# for the no-change case.)
15105ca82e69SJohn Levon		#
15115ca82e69SJohn Levon		if (( $? != 0 )); then
15125ca82e69SJohn Levon			HG_SOURCE=$BRINGOVER_WS
15135ca82e69SJohn Levon		fi
15145ca82e69SJohn Levon	fi
15155ca82e69SJohn Levon
15165ca82e69SJohn Levon	staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
15175ca82e69SJohn Levon	    > $TMPDIR/pull_open.out 2>&1
15185ca82e69SJohn Levon	if (( $? != 0 )); then
15195ca82e69SJohn Levon		printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
15205ca82e69SJohn Levon		cat $TMPDIR/pull_open.out
15215ca82e69SJohn Levon		if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
15225ca82e69SJohn Levon			printf "$mergefailmsg"
15235ca82e69SJohn Levon		fi
15245ca82e69SJohn Levon		touch $TMPDIR/bringover_failed
15255ca82e69SJohn Levon		return
15265ca82e69SJohn Levon	fi
15275ca82e69SJohn Levon
15285ca82e69SJohn Levon	if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
15295ca82e69SJohn Levon		staffer hg --cwd $CODEMGR_WS merge \
15305ca82e69SJohn Levon		    >> $TMPDIR/pull_open.out 2>&1
15315ca82e69SJohn Levon		if (( $? != 0 )); then
15325ca82e69SJohn Levon			printf "%s: merge failed as follows:\n\n" \
15335ca82e69SJohn Levon			    "$CODEMGR_WS"
15345ca82e69SJohn Levon			cat $TMPDIR/pull_open.out
15355ca82e69SJohn Levon			if grep "^merging.*failed" $TMPDIR/pull_open.out \
15365ca82e69SJohn Levon			    > /dev/null 2>&1; then
15375ca82e69SJohn Levon				printf "$mergefailmsg"
15385ca82e69SJohn Levon			fi
15395ca82e69SJohn Levon			touch $TMPDIR/bringover_failed
15405ca82e69SJohn Levon			return
15415ca82e69SJohn Levon		fi
15425ca82e69SJohn Levon	fi
15435ca82e69SJohn Levon
15445ca82e69SJohn Levon	printf "updated %s with the following results:\n" "$CODEMGR_WS"
15455ca82e69SJohn Levon	cat $TMPDIR/pull_open.out
15465ca82e69SJohn Levon	if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
15475ca82e69SJohn Levon		printf "$mergepassmsg"
15485ca82e69SJohn Levon	fi
15495ca82e69SJohn Levon	printf "\n"
15505ca82e69SJohn Levon
15515ca82e69SJohn Levon	#
15525ca82e69SJohn Levon	# Per-changeset output is neither useful nor manageable for a
15535ca82e69SJohn Levon	# newly-created repository.
15545ca82e69SJohn Levon	#
15555ca82e69SJohn Levon	if [ -f $TMPDIR/new_repository ]; then
15565ca82e69SJohn Levon		return
15575ca82e69SJohn Levon	fi
15585ca82e69SJohn Levon
15595ca82e69SJohn Levon	printf "\nadded the following changesets to open repository:\n"
15605ca82e69SJohn Levon	cat $TMPDIR/incoming_open.out
15615ca82e69SJohn Levon}
15625ca82e69SJohn Levon
15635ca82e69SJohn Levontype bringover_none > /dev/null 2>&1 || function bringover_none {
15645ca82e69SJohn Levon	echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
15655ca82e69SJohn Levon	touch $TMPDIR/bringover_failed
15665ca82e69SJohn Levon}
15675ca82e69SJohn Levon
15685ca82e69SJohn Levon#
15695ca82e69SJohn Levon#	Decide whether to bringover to the codemgr workspace
15705ca82e69SJohn Levon#
15715ca82e69SJohn Levonif [ "$n_FLAG" = "n" ]; then
15725ca82e69SJohn Levon	PARENT_SCM_TYPE=$(parent_wstype)
15735ca82e69SJohn Levon
15745ca82e69SJohn Levon	if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
15755ca82e69SJohn Levon		echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
15765ca82e69SJohn Levon		    "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
15775ca82e69SJohn Levon		exit 1
15785ca82e69SJohn Levon	fi
15795ca82e69SJohn Levon
15805ca82e69SJohn Levon	run_hook PRE_BRINGOVER
15815ca82e69SJohn Levon
15825ca82e69SJohn Levon	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
15835ca82e69SJohn Levon	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
15845ca82e69SJohn Levon
15855ca82e69SJohn Levon	eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
15865ca82e69SJohn Levon		tee -a $mail_msg_file >> $LOGFILE
15875ca82e69SJohn Levon
15885ca82e69SJohn Levon	if [ -f $TMPDIR/bringover_failed ]; then
15895ca82e69SJohn Levon		rm -f $TMPDIR/bringover_failed
15905ca82e69SJohn Levon		build_ok=n
15915ca82e69SJohn Levon		echo "trouble with bringover, quitting at `date`." |
15925ca82e69SJohn Levon			tee -a $mail_msg_file >> $LOGFILE
15935ca82e69SJohn Levon		exit 1
15945ca82e69SJohn Levon	fi
15955ca82e69SJohn Levon
15965ca82e69SJohn Levon	#
15975ca82e69SJohn Levon	# It's possible that we used the bringover above to create
15985ca82e69SJohn Levon	# $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
15995ca82e69SJohn Levon	# but should now be the same as $BRINGOVER_WS.
16005ca82e69SJohn Levon	#
160126e7d9a8SRichard Lowe	[[ $SCM_TYPE == none ]] && SCM_TYPE=$PARENT_SCM_TYPE
16025ca82e69SJohn Levon
16035ca82e69SJohn Levon	run_hook POST_BRINGOVER
16045ca82e69SJohn Levon
16055ca82e69SJohn Levon	check_closed_bins
16065ca82e69SJohn Levon
16075ca82e69SJohn Levonelse
16085ca82e69SJohn Levon	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
16095ca82e69SJohn Levonfi
16105ca82e69SJohn Levon
16115ca82e69SJohn Levon# Safeguards
16125ca82e69SJohn Levon[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
16135ca82e69SJohn Levon[[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory."
16145ca82e69SJohn Levon[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
16155ca82e69SJohn Levon
16164125432bSBill Sommerfeld#
16174125432bSBill Sommerfeld# if -V flag was given, reset VERSION to V_ARG
16184125432bSBill Sommerfeld#
16194125432bSBill Sommerfeldif [[ "$V_FLAG" == "y" ]]; then
16204125432bSBill Sommerfeld	export VERSION=$V_ARG
16214125432bSBill Sommerfeldelif [[ -z "$VERSION" ]]; then
16224125432bSBill Sommerfeld	export VERSION=$(git -C "${CODEMGR_WS}" describe --long --all --dirty |
16234125432bSBill Sommerfeld		cut -d/ -f2-)
16244125432bSBill Sommerfeldfi
16254125432bSBill Sommerfeld
16264125432bSBill Sommerfeld[[ -n "$VERSION" ]] || fatal_error "Error: VERSION not set"
16274125432bSBill Sommerfeld
16284125432bSBill Sommerfeldecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
16294125432bSBill Sommerfeldecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
16304125432bSBill Sommerfeld
163126e7d9a8SRichard Loweif [[ "$t_FLAG" == "y" ]]; then
16325ca82e69SJohn Levon	set_non_debug_build_flags
16335ca82e69SJohn Levon	# Switch ONBLD_TOOLS early if -t is specified so that
16345ca82e69SJohn Levon	# we could use bootstrapped cw for compiler checks.
16355ca82e69SJohn Levon	ONBLD_TOOLS=${TOOLS_PROTO}/opt/onbld
16365ca82e69SJohn Levon	export ONBLD_TOOLS
16373c6ef809SYuri Pankov
16383c6ef809SYuri Pankov	bootstrap_tools || fatal_error "Error: could not bootstrap tools"
16395ca82e69SJohn Levonfi
16405ca82e69SJohn Levon
16415ca82e69SJohn Levonecho "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
16425ca82e69SJohn Levon
16435ca82e69SJohn Levon# System
16445ca82e69SJohn Levonwhence uname | tee -a $build_environ_file >> $LOGFILE
16455ca82e69SJohn Levonuname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
16465ca82e69SJohn Levonecho | tee -a $build_environ_file >> $LOGFILE
16475ca82e69SJohn Levon
16485ca82e69SJohn Levon# make
16495ca82e69SJohn Levonwhence $MAKE | tee -a $build_environ_file >> $LOGFILE
16505ca82e69SJohn Levon$MAKE -v | tee -a $build_environ_file >> $LOGFILE
16515ca82e69SJohn Levonecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
16525ca82e69SJohn Levon    tee -a $build_environ_file >> $LOGFILE
16535ca82e69SJohn Levon
16545ca82e69SJohn Levon#
16555ca82e69SJohn Levon# Report the compiler versions.
16565ca82e69SJohn Levon#
16575ca82e69SJohn Levon
16585ca82e69SJohn Levonif [[ ! -f $SRC/Makefile ]]; then
16595ca82e69SJohn Levon	build_ok=n
16605ca82e69SJohn Levon	echo "\nUnable to find \"Makefile\" in $SRC." | \
16615ca82e69SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
16625ca82e69SJohn Levon	exit 1
16635ca82e69SJohn Levonfi
16645ca82e69SJohn Levon
16655ca82e69SJohn Levon( cd $SRC
16665ca82e69SJohn Levon  for target in cc-version java-version openssl-version; do
16675ca82e69SJohn Levon	echo
16685ca82e69SJohn Levon	#
16695ca82e69SJohn Levon	# Put statefile somewhere we know we can write to rather than trip
16705ca82e69SJohn Levon	# over a read-only $srcroot.
16715ca82e69SJohn Levon	#
16725ca82e69SJohn Levon	rm -f $TMPDIR/make-state
16735ca82e69SJohn Levon	export SRC
16745ca82e69SJohn Levon	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
16755ca82e69SJohn Levon		continue
16765ca82e69SJohn Levon	fi
16775ca82e69SJohn Levon	touch $TMPDIR/nocompiler
16785ca82e69SJohn Levon  done
16795ca82e69SJohn Levon  echo
1680eefeb0ceSBill Sommerfeld) | egrep -v "${MAKE}: (Entering|Leaving) directory " \
1681eefeb0ceSBill Sommerfeld    | tee -a $build_environ_file >> $LOGFILE
16825ca82e69SJohn Levon
16835ca82e69SJohn Levonif [ -f $TMPDIR/nocompiler ]; then
16845ca82e69SJohn Levon	rm -f $TMPDIR/nocompiler
16855ca82e69SJohn Levon	build_ok=n
16865ca82e69SJohn Levon	echo "Aborting due to missing compiler." |
16875ca82e69SJohn Levon		tee -a $build_environ_file >> $LOGFILE
16885ca82e69SJohn Levon	exit 1
16895ca82e69SJohn Levonfi
16905ca82e69SJohn Levon
16915ca82e69SJohn Levon# Check that we're running a capable link-editor
16925ca82e69SJohn Levonwhence ld | tee -a $build_environ_file >> $LOGFILE
16935ca82e69SJohn LevonLDVER=`ld -V 2>&1`
16945ca82e69SJohn Levonecho $LDVER | tee -a $build_environ_file >> $LOGFILE
16955ca82e69SJohn LevonLDVER=`echo $LDVER | sed -e "s/.*-1\.\([0-9]*\).*/\1/"`
16965ca82e69SJohn Levonif [ `expr $LDVER \< 422` -eq 1 ]; then
16975ca82e69SJohn Levon	echo "The link-editor needs to be at version 422 or higher to build" | \
16985ca82e69SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
16995ca82e69SJohn Levon	echo "the latest stuff.  Hope your build works." | \
17005ca82e69SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
17015ca82e69SJohn Levonfi
17025ca82e69SJohn Levon
17035ca82e69SJohn Levon#
17045ca82e69SJohn Levon# Build and use the workspace's tools if requested
17055ca82e69SJohn Levon#
170626e7d9a8SRichard Loweif [[ "$t_FLAG" == "y" ]]; then
17075ca82e69SJohn Levon	set_non_debug_build_flags
17085ca82e69SJohn Levon
17095ca82e69SJohn Levon	build_tools ${TOOLS_PROTO}
17105ca82e69SJohn Levon	if (( $? != 0 )); then
17115ca82e69SJohn Levon		build_ok=n
17126faa6645SYuri Pankov		exit 1
17136faa6645SYuri Pankov	fi
17146faa6645SYuri Pankov
17155ca82e69SJohn Levon	STABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs
17165ca82e69SJohn Levon	export STABS
17175ca82e69SJohn Levon	CTFSTABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs
17185ca82e69SJohn Levon	export CTFSTABS
17195ca82e69SJohn Levon	GENOFFSETS=${TOOLS_PROTO}/opt/onbld/bin/genoffsets
17205ca82e69SJohn Levon	export GENOFFSETS
17215ca82e69SJohn Levon
17225ca82e69SJohn Levon	CTFCONVERT=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert
17235ca82e69SJohn Levon	export CTFCONVERT
17245ca82e69SJohn Levon	CTFMERGE=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge
17255ca82e69SJohn Levon	export CTFMERGE
17265ca82e69SJohn Levon
17275ca82e69SJohn Levon	PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
17285ca82e69SJohn Levon	PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
17295ca82e69SJohn Levon	export PATH
17305ca82e69SJohn Levon
17315ca82e69SJohn Levon	echo "\n==== New environment settings. ====\n" >> $LOGFILE
17325ca82e69SJohn Levon	echo "STABS=${STABS}" >> $LOGFILE
17335ca82e69SJohn Levon	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
17345ca82e69SJohn Levon	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
17355ca82e69SJohn Levon	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
17365ca82e69SJohn Levon	echo "PATH=${PATH}" >> $LOGFILE
17375ca82e69SJohn Levon	echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE
17385ca82e69SJohn Levonfi
17395ca82e69SJohn Levon
17405ca82e69SJohn Levon# timestamp the start of the normal build; the findunref tool uses it.
17415ca82e69SJohn Levontouch $SRC/.build.tstamp
17425ca82e69SJohn Levon
17435ca82e69SJohn Levonnormal_build
17445ca82e69SJohn Levon
17455ca82e69SJohn LevonORIG_SRC=$SRC
17465ca82e69SJohn LevonBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
17475ca82e69SJohn Levon
174826e7d9a8SRichard Loweabspkg=
174926e7d9a8SRichard Lowefor d in $abssrcdirs; do
175026e7d9a8SRichard Lowe	if [ -d "$d/pkg" ]; then
175126e7d9a8SRichard Lowe		abspkg="$abspkg $d"
175226e7d9a8SRichard Lowe	fi
175326e7d9a8SRichard Lowedone
175426e7d9a8SRichard Lowe
175526e7d9a8SRichard Loweif [ "$L_FLAG" != "y" -a "$build_ok" = y ]; then
175626e7d9a8SRichard Lowe	echo "\n==== Linting packages ====\n" | \
175726e7d9a8SRichard Lowe	    tee -a $LOGFILE >> $mail_msg_file
175826e7d9a8SRichard Lowe
175926e7d9a8SRichard Lowe	if [ -n "$abspkg" ]; then
176026e7d9a8SRichard Lowe		for d in "$abspkg"; do
176126e7d9a8SRichard Lowe			( cd $d/pkg ; $MAKE -e pkglint ) | \
176226e7d9a8SRichard Lowe			    tee -a $LOGFILE | \
1763eefeb0ceSBill Sommerfeld			    egrep -v ": (Entering|Leaving) directory " | \
176426e7d9a8SRichard Lowe			    egrep -v 'Lint engine setup|Starting lint run'
176526e7d9a8SRichard Lowe		done 2>&1 | tee $TMPDIR/pkglint_noise >> $mail_msg_file
176626e7d9a8SRichard Lowe		if [[ -s $TMPDIR/pkglint_noise ]]; then
176726e7d9a8SRichard Lowe			build_extras_ok=n
176826e7d9a8SRichard Lowe		fi
176926e7d9a8SRichard Lowe	fi
177026e7d9a8SRichard Lowefi
17715ca82e69SJohn Levon
17725ca82e69SJohn Levon#
17735ca82e69SJohn Levon# There are several checks that need to look at the proto area, but
17745ca82e69SJohn Levon# they only need to look at one, and they don't care whether it's
17755ca82e69SJohn Levon# DEBUG or non-DEBUG.
17765ca82e69SJohn Levon#
177726e7d9a8SRichard Loweif [[ "$MULTI_PROTO" == yes && "$D_FLAG" == n ]]; then
17785ca82e69SJohn Levon	checkroot=$ROOT-nd
17795ca82e69SJohn Levonelse
17805ca82e69SJohn Levon	checkroot=$ROOT
17815ca82e69SJohn Levonfi
17825ca82e69SJohn Levon
17835ca82e69SJohn Levonif [ "$build_ok" = "y" ]; then
17845ca82e69SJohn Levon	echo "\n==== Creating protolist system file at `date` ====" \
17855ca82e69SJohn Levon		>> $LOGFILE
17865ca82e69SJohn Levon	protolist $checkroot > $ATLOG/proto_list_${MACH}
17875ca82e69SJohn Levon	echo "==== protolist system file created at `date` ====\n" \
17885ca82e69SJohn Levon		>> $LOGFILE
17895ca82e69SJohn Levon
17905ca82e69SJohn Levon	if [ "$N_FLAG" != "y" ]; then
17915ca82e69SJohn Levon
17925ca82e69SJohn Levon		E1=
17935ca82e69SJohn Levon		f1=
17945ca82e69SJohn Levon		for f in $f1; do
17955ca82e69SJohn Levon			if [ -f "$f" ]; then
17965ca82e69SJohn Levon				E1="$E1 -e $f"
17975ca82e69SJohn Levon			fi
17985ca82e69SJohn Levon		done
17995ca82e69SJohn Levon
18005ca82e69SJohn Levon		E2=
18015ca82e69SJohn Levon		f2=
18025ca82e69SJohn Levon		if [ -d "$SRC/pkg" ]; then
18035ca82e69SJohn Levon			f2="$f2 exceptions/packaging"
18045ca82e69SJohn Levon		fi
18055ca82e69SJohn Levon
18065ca82e69SJohn Levon		for f in $f2; do
18075ca82e69SJohn Levon			if [ -f "$f" ]; then
18085ca82e69SJohn Levon				E2="$E2 -e $f"
18095ca82e69SJohn Levon			fi
18105ca82e69SJohn Levon		done
18115ca82e69SJohn Levon	fi
18125ca82e69SJohn Levon
18135ca82e69SJohn Levon	if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
18145ca82e69SJohn Levon		echo "\n==== Validating manifests against proto area ====\n" \
18155ca82e69SJohn Levon		    >> $mail_msg_file
18165ca82e69SJohn Levon		( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) | \
1817eefeb0ceSBill Sommerfeld		    egrep -v ": (Entering|Leaving) directory " | \
18185ca82e69SJohn Levon		    tee $TMPDIR/protocmp_noise >> $mail_msg_file
18195ca82e69SJohn Levon		if [[ -s $TMPDIR/protocmp_noise ]]; then
18205ca82e69SJohn Levon			build_extras_ok=n
18215ca82e69SJohn Levon		fi
18225ca82e69SJohn Levon	fi
18235ca82e69SJohn Levon
18245ca82e69SJohn Levon	if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then
18255ca82e69SJohn Levon		echo "\n==== Impact on proto area ====\n" >> $mail_msg_file
18265ca82e69SJohn Levon		if [ -n "$E2" ]; then
18275ca82e69SJohn Levon			ELIST=$E2
18285ca82e69SJohn Levon		else
18295ca82e69SJohn Levon			ELIST=$E1
18305ca82e69SJohn Levon		fi
18315ca82e69SJohn Levon		$PROTOCMPTERSE \
18325ca82e69SJohn Levon			"Files in yesterday's proto area, but not today's:" \
18335ca82e69SJohn Levon			"Files in today's proto area, but not yesterday's:" \
18345ca82e69SJohn Levon			"Files that changed between yesterday and today:" \
18355ca82e69SJohn Levon			${ELIST} \
18365ca82e69SJohn Levon			-d $REF_PROTO_LIST \
18375ca82e69SJohn Levon			$ATLOG/proto_list_${MACH} \
18385ca82e69SJohn Levon			>> $mail_msg_file
18395ca82e69SJohn Levon	fi
18405ca82e69SJohn Levonfi
18415ca82e69SJohn Levon
18425ca82e69SJohn Levonif [[ "$u_FLAG" == "y" && "$build_ok" == "y" && \
18435ca82e69SJohn Levon    "$build_extras_ok" == "y" ]]; then
18445ca82e69SJohn Levon	staffer cp $ATLOG/proto_list_${MACH} \
18455ca82e69SJohn Levon		$PARENT_WS/usr/src/proto_list_${MACH}
18465ca82e69SJohn Levonfi
18475ca82e69SJohn Levon
18485ca82e69SJohn Levon# Update parent proto area if necessary. This is done now
18495ca82e69SJohn Levon# so that the proto area has either DEBUG or non-DEBUG kernels.
18505ca82e69SJohn Levon# Note that this clears out the lock file, so we can dispense with
18515ca82e69SJohn Levon# the variable now.
18525ca82e69SJohn Levonif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
18535ca82e69SJohn Levon	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
18545ca82e69SJohn Levon	    tee -a $LOGFILE >> $mail_msg_file
18555ca82e69SJohn Levon	rm -rf $NIGHTLY_PARENT_ROOT/*
18565ca82e69SJohn Levon	unset Ulockfile
18575ca82e69SJohn Levon	mkdir -p $NIGHTLY_PARENT_ROOT
185826e7d9a8SRichard Lowe	if [[ "$MULTI_PROTO" == no || "$D_FLAG" == y ]]; then
18595ca82e69SJohn Levon		( cd $ROOT; tar cf - . |
18605ca82e69SJohn Levon		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
18615ca82e69SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
18625ca82e69SJohn Levon	fi
186326e7d9a8SRichard Lowe	if [[ "$MULTI_PROTO" == yes && "$F_FLAG" == n ]]; then
18645ca82e69SJohn Levon		rm -rf $NIGHTLY_PARENT_ROOT-nd/*
18655ca82e69SJohn Levon		mkdir -p $NIGHTLY_PARENT_ROOT-nd
18665ca82e69SJohn Levon		cd $ROOT-nd
18675ca82e69SJohn Levon		( tar cf - . |
18685ca82e69SJohn Levon		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
18695ca82e69SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
18705ca82e69SJohn Levon	fi
18715ca82e69SJohn Levon	if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then
18725ca82e69SJohn Levon		echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \
18735ca82e69SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
18745ca82e69SJohn Levon		rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/*
18755ca82e69SJohn Levon		mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT
187626e7d9a8SRichard Lowe		if [[ "$MULTI_PROTO" == no || "$D_FLAG" == y ]]; then
18775ca82e69SJohn Levon			( cd $TOOLS_PROTO; tar cf - . |
18785ca82e69SJohn Levon			    ( cd $NIGHTLY_PARENT_TOOLS_ROOT;
18795ca82e69SJohn Levon			    umask 0; tar xpf - ) ) 2>&1 |
18805ca82e69SJohn Levon			    tee -a $mail_msg_file >> $LOGFILE
18815ca82e69SJohn Levon		fi
18825ca82e69SJohn Levon	fi
18835ca82e69SJohn Levonfi
18845ca82e69SJohn Levon
18855ca82e69SJohn Levon#
18865ca82e69SJohn Levon# ELF verification: ABI (-A) and runtime (-r) checks
18875ca82e69SJohn Levon#
188826e7d9a8SRichard Loweif [[ ($build_ok == y) && (($A_FLAG == y) || ($r_FLAG == y)) ]]; then
18895ca82e69SJohn Levon	# Directory ELF-data.$MACH holds the files produced by these tests.
18905ca82e69SJohn Levon	elf_ddir=$SRC/ELF-data.$MACH
18915ca82e69SJohn Levon
18925ca82e69SJohn Levon	# If there is a previous ELF-data backup directory, remove it. Then,
18935ca82e69SJohn Levon	# rotate current ELF-data directory into its place and create a new
18945ca82e69SJohn Levon	# empty directory
18955ca82e69SJohn Levon	rm -rf $elf_ddir.ref
18965ca82e69SJohn Levon	if [[ -d $elf_ddir ]]; then
18975ca82e69SJohn Levon		mv $elf_ddir $elf_ddir.ref
18985ca82e69SJohn Levon	fi
18995ca82e69SJohn Levon	mkdir -p $elf_ddir
19005ca82e69SJohn Levon
19015ca82e69SJohn Levon	# Call find_elf to produce a list of the ELF objects in the proto area.
19025ca82e69SJohn Levon	# This list is passed to check_rtime and interface_check, preventing
19035ca82e69SJohn Levon	# them from separately calling find_elf to do the same work twice.
19045ca82e69SJohn Levon	find_elf -fr $checkroot > $elf_ddir/object_list
19055ca82e69SJohn Levon
190626e7d9a8SRichard Lowe	if [[ $A_FLAG == y ]]; then
19075ca82e69SJohn Levon		echo "\n==== Check versioning and ABI information ====\n"  | \
19085ca82e69SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
19095ca82e69SJohn Levon
19105ca82e69SJohn Levon		# Produce interface description for the proto. Report errors.
19115ca82e69SJohn Levon		interface_check -o -w $elf_ddir -f object_list \
19125ca82e69SJohn Levon			-i interface -E interface.err
19135ca82e69SJohn Levon		if [[ -s $elf_ddir/interface.err ]]; then
19145ca82e69SJohn Levon			tee -a $LOGFILE < $elf_ddir/interface.err \
19155ca82e69SJohn Levon			    >> $mail_msg_file
19165ca82e69SJohn Levon			build_extras_ok=n
19175ca82e69SJohn Levon		fi
19185ca82e69SJohn Levon
19195ca82e69SJohn Levon		# If ELF_DATA_BASELINE_DIR is defined, compare the new interface
19205ca82e69SJohn Levon		# description file to that from the baseline gate. Issue a
19215ca82e69SJohn Levon		# warning if the baseline is not present, and keep going.
19225ca82e69SJohn Levon		if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
19235ca82e69SJohn Levon			base_ifile="$ELF_DATA_BASELINE_DIR/interface"
19245ca82e69SJohn Levon
19255ca82e69SJohn Levon			echo "\n==== Compare versioning and ABI information" \
19265ca82e69SJohn Levon			    "to baseline ====\n"  | \
19275ca82e69SJohn Levon			    tee -a $LOGFILE >> $mail_msg_file
19285ca82e69SJohn Levon			echo "Baseline:	 $base_ifile\n" >> $LOGFILE
19295ca82e69SJohn Levon
19305ca82e69SJohn Levon			if [[ -f $base_ifile ]]; then
19315ca82e69SJohn Levon				interface_cmp -d -o $base_ifile \
19325ca82e69SJohn Levon				    $elf_ddir/interface > $elf_ddir/interface.cmp
19335ca82e69SJohn Levon				if [[ -s $elf_ddir/interface.cmp ]]; then
19345ca82e69SJohn Levon					echo | tee -a $LOGFILE >> $mail_msg_file
19355ca82e69SJohn Levon					tee -a $LOGFILE < \
19365ca82e69SJohn Levon					    $elf_ddir/interface.cmp \
19375ca82e69SJohn Levon					    >> $mail_msg_file
19385ca82e69SJohn Levon					build_extras_ok=n
19395ca82e69SJohn Levon				fi
19405ca82e69SJohn Levon			else
19415ca82e69SJohn Levon				echo "baseline not available. comparison" \
19425ca82e69SJohn Levon                                    "skipped" | \
19435ca82e69SJohn Levon				    tee -a $LOGFILE >> $mail_msg_file
19445ca82e69SJohn Levon			fi
19455ca82e69SJohn Levon
19465ca82e69SJohn Levon		fi
19475ca82e69SJohn Levon	fi
19485ca82e69SJohn Levon
194926e7d9a8SRichard Lowe	if [[ $r_FLAG == y ]]; then
19505ca82e69SJohn Levon		echo "\n==== Check ELF runtime attributes ====\n" | \
19515ca82e69SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
19525ca82e69SJohn Levon
19535ca82e69SJohn Levon		# If we're doing a DEBUG build the proto area will be left
19545ca82e69SJohn Levon		# with debuggable objects, thus don't assert -s.
195526e7d9a8SRichard Lowe		if [[ $D_FLAG == y ]]; then
19565ca82e69SJohn Levon			rtime_sflag=""
19575ca82e69SJohn Levon		else
19585ca82e69SJohn Levon			rtime_sflag="-s"
19595ca82e69SJohn Levon		fi
19605ca82e69SJohn Levon		check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
19615ca82e69SJohn Levon			-D object_list  -f object_list -E runtime.err \
19625ca82e69SJohn Levon			-I runtime.attr.raw
19635ca82e69SJohn Levon		if (( $? != 0 )); then
19645ca82e69SJohn Levon			build_extras_ok=n
19655ca82e69SJohn Levon		fi
19665ca82e69SJohn Levon
19675ca82e69SJohn Levon		# check_rtime -I output needs to be sorted in order to
19685ca82e69SJohn Levon		# compare it to that from previous builds.
19695ca82e69SJohn Levon		sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
19705ca82e69SJohn Levon		rm $elf_ddir/runtime.attr.raw
19715ca82e69SJohn Levon
19725ca82e69SJohn Levon		# Report errors
19735ca82e69SJohn Levon		if [[ -s $elf_ddir/runtime.err ]]; then
19745ca82e69SJohn Levon			tee -a $LOGFILE < $elf_ddir/runtime.err \
19755ca82e69SJohn Levon				>> $mail_msg_file
19765ca82e69SJohn Levon			build_extras_ok=n
19775ca82e69SJohn Levon		fi
19785ca82e69SJohn Levon
19795ca82e69SJohn Levon		# If there is an ELF-data directory from a previous build,
19805ca82e69SJohn Levon		# then diff the attr files. These files contain information
19815ca82e69SJohn Levon		# about dependencies, versioning, and runpaths. There is some
19825ca82e69SJohn Levon		# overlap with the ABI checking done above, but this also
19835ca82e69SJohn Levon		# flushes out non-ABI interface differences along with the
19845ca82e69SJohn Levon		# other information.
19855ca82e69SJohn Levon		echo "\n==== Diff ELF runtime attributes" \
19865ca82e69SJohn Levon		    "(since last build) ====\n" | \
19875ca82e69SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
19885ca82e69SJohn Levon
19895ca82e69SJohn Levon		if [[ -f $elf_ddir.ref/runtime.attr ]]; then
19905ca82e69SJohn Levon			diff $elf_ddir.ref/runtime.attr \
19915ca82e69SJohn Levon				$elf_ddir/runtime.attr \
19925ca82e69SJohn Levon				>> $mail_msg_file
19935ca82e69SJohn Levon		fi
19945ca82e69SJohn Levon	fi
19955ca82e69SJohn Levon
19965ca82e69SJohn Levon	# If -u set, copy contents of ELF-data.$MACH to the parent workspace.
199726e7d9a8SRichard Lowe	if [[ "$u_FLAG" == "y" ]]; then
19985ca82e69SJohn Levon		p_elf_ddir=$PARENT_WS/usr/src/ELF-data.$MACH
19995ca82e69SJohn Levon
20005ca82e69SJohn Levon		# If parent lacks the ELF-data.$MACH directory, create it
20015ca82e69SJohn Levon		if [[ ! -d $p_elf_ddir ]]; then
20025ca82e69SJohn Levon			staffer mkdir -p $p_elf_ddir
20035ca82e69SJohn Levon		fi
20045ca82e69SJohn Levon
20055ca82e69SJohn Levon		# These files are used asynchronously by other builds for ABI
20065ca82e69SJohn Levon		# verification, as above for the -A option. As such, we require
20075ca82e69SJohn Levon		# the file replacement to be atomic. Copy the data to a temp
20085ca82e69SJohn Levon		# file in the same filesystem and then rename into place.
20095ca82e69SJohn Levon		(
20105ca82e69SJohn Levon			cd $elf_ddir
20115ca82e69SJohn Levon			for elf_dfile in *; do
20125ca82e69SJohn Levon				staffer cp $elf_dfile \
20135ca82e69SJohn Levon				    ${p_elf_ddir}/${elf_dfile}.new
20145ca82e69SJohn Levon				staffer mv -f ${p_elf_ddir}/${elf_dfile}.new \
20155ca82e69SJohn Levon				    ${p_elf_ddir}/${elf_dfile}
20165ca82e69SJohn Levon			done
20175ca82e69SJohn Levon		)
20185ca82e69SJohn Levon	fi
20195ca82e69SJohn Levonfi
20205ca82e69SJohn Levon
20215ca82e69SJohn Levon# "make check" begins
20225ca82e69SJohn Levon
20235ca82e69SJohn Levonif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
20245ca82e69SJohn Levon	# remove old check.out
20255ca82e69SJohn Levon	rm -f $SRC/check.out
20265ca82e69SJohn Levon
20275ca82e69SJohn Levon	rm -f $SRC/check-${MACH}.out
20285ca82e69SJohn Levon	cd $SRC
20295ca82e69SJohn Levon	$MAKE -ek check ROOT="$checkroot" 2>&1 | tee -a $SRC/check-${MACH}.out \
20305ca82e69SJohn Levon	    >> $LOGFILE
20315ca82e69SJohn Levon	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
20325ca82e69SJohn Levon
20335ca82e69SJohn Levon	grep ":" $SRC/check-${MACH}.out |
2034eefeb0ceSBill Sommerfeld		egrep -v ": (Entering|Leaving) directory " | \
20355ca82e69SJohn Levon		egrep -v "Ignoring unknown host" | \
20365ca82e69SJohn Levon		sort | uniq | tee $TMPDIR/check_errors >> $mail_msg_file
20375ca82e69SJohn Levon
20385ca82e69SJohn Levon	if [[ -s $TMPDIR/check_errors ]]; then
20395ca82e69SJohn Levon		build_extras_ok=n
20405ca82e69SJohn Levon	fi
20415ca82e69SJohn Levonelse
20425ca82e69SJohn Levon	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
20435ca82e69SJohn Levonfi
20445ca82e69SJohn Levon
20455ca82e69SJohn Levonecho "\n==== Find core files ====\n" | \
20465ca82e69SJohn Levon    tee -a $LOGFILE >> $mail_msg_file
20475ca82e69SJohn Levon
20485ca82e69SJohn Levonfind $abssrcdirs -name core -a -type f -exec file {} \; | \
20495ca82e69SJohn Levon	tee -a $LOGFILE >> $mail_msg_file
20505ca82e69SJohn Levon
20515ca82e69SJohn Levonif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
20525ca82e69SJohn Levon	echo "\n==== Diff unreferenced files (since last build) ====\n" \
20535ca82e69SJohn Levon	    | tee -a $LOGFILE >>$mail_msg_file
20545ca82e69SJohn Levon	rm -f $SRC/unref-${MACH}.ref
20555ca82e69SJohn Levon	if [ -f $SRC/unref-${MACH}.out ]; then
20565ca82e69SJohn Levon		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
20575ca82e69SJohn Levon	fi
20585ca82e69SJohn Levon
20595ca82e69SJohn Levon	findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
20605ca82e69SJohn Levon	    ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
20615ca82e69SJohn Levon	    sort > $SRC/unref-${MACH}.out
20625ca82e69SJohn Levon
20635ca82e69SJohn Levon	if [ ! -f $SRC/unref-${MACH}.ref ]; then
20645ca82e69SJohn Levon		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
20655ca82e69SJohn Levon	fi
20665ca82e69SJohn Levon
20675ca82e69SJohn Levon	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
20685ca82e69SJohn Levonfi
20695ca82e69SJohn Levon
20705ca82e69SJohn Levon# Verify that the usual lists of files, such as exception lists,
20715ca82e69SJohn Levon# contain only valid references to files.  If the build has failed,
20725ca82e69SJohn Levon# then don't check the proto area.
20735ca82e69SJohn LevonCHECK_PATHS=${CHECK_PATHS:-y}
20745ca82e69SJohn Levonif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
20755ca82e69SJohn Levon	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
20765ca82e69SJohn Levon		>>$mail_msg_file
20775ca82e69SJohn Levon	arg=-b
20785ca82e69SJohn Levon	[ "$build_ok" = y ] && arg=
20795ca82e69SJohn Levon	checkpaths $arg $checkroot > $SRC/check-paths.out 2>&1
20805ca82e69SJohn Levon	if [[ -s $SRC/check-paths.out ]]; then
20815ca82e69SJohn Levon		tee -a $LOGFILE < $SRC/check-paths.out >> $mail_msg_file
20825ca82e69SJohn Levon		build_extras_ok=n
20835ca82e69SJohn Levon	fi
20845ca82e69SJohn Levonfi
20855ca82e69SJohn Levon
2086069e6b7eSAndy Fiddamanif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
2087069e6b7eSAndy Fiddaman	echo "\n==== Impact on file permissions ====\n" \
2088069e6b7eSAndy Fiddaman		>> $mail_msg_file
2089069e6b7eSAndy Fiddaman
20905ca82e69SJohn Levon	if [ -n "$abspkg" ]; then
20915ca82e69SJohn Levon		for d in "$abspkg"; do
2092eefeb0ceSBill Sommerfeld			( cd $d/pkg ; $MAKE -e pmodes ) | \
2093eefeb0ceSBill Sommerfeld			egrep -v ": (Entering|Leaving) directory " \
2094eefeb0ceSBill Sommerfeld			>> $mail_msg_file
20955ca82e69SJohn Levon		done
20965ca82e69SJohn Levon	fi
20975ca82e69SJohn Levonfi
20985ca82e69SJohn Levon
20995ca82e69SJohn Levonif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
210026e7d9a8SRichard Lowe	if [[ "$MULTI_PROTO" == no || "$D_FLAG" == y ]]; then
21015ca82e69SJohn Levon		do_wsdiff DEBUG $ROOT.prev $ROOT
21025ca82e69SJohn Levon	fi
21035ca82e69SJohn Levon
210426e7d9a8SRichard Lowe	if [[ "$MULTI_PROTO" == yes && "$F_FLAG" == n ]]; then
21055ca82e69SJohn Levon		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
21065ca82e69SJohn Levon	fi
21075ca82e69SJohn Levonfi
21085ca82e69SJohn Levon
21095ca82e69SJohn LevonEND_DATE=`date`
21105ca82e69SJohn Levonecho "==== Nightly $maketype build completed: $END_DATE ====" | \
21115ca82e69SJohn Levon    tee -a $LOGFILE >> $build_time_file
21125ca82e69SJohn Levon
21135ca82e69SJohn Levontypeset -i10 hours
21145ca82e69SJohn Levontypeset -Z2 minutes
21155ca82e69SJohn Levontypeset -Z2 seconds
21165ca82e69SJohn Levon
21175ca82e69SJohn Levonelapsed_time=$SECONDS
21185ca82e69SJohn Levon((hours = elapsed_time / 3600 ))
21195ca82e69SJohn Levon((minutes = elapsed_time / 60  % 60))
21205ca82e69SJohn Levon((seconds = elapsed_time % 60))
21215ca82e69SJohn Levon
21225ca82e69SJohn Levonecho "\n==== Total build time ====" | \
21235ca82e69SJohn Levon    tee -a $LOGFILE >> $build_time_file
21245ca82e69SJohn Levonecho "\nreal    ${hours}:${minutes}:${seconds}" | \
21255ca82e69SJohn Levon    tee -a $LOGFILE >> $build_time_file
21265ca82e69SJohn Levon
21275ca82e69SJohn Levonif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
21285ca82e69SJohn Levon	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
21295ca82e69SJohn Levon
21305ca82e69SJohn Levon	#
21315ca82e69SJohn Levon	# Produce a master list of unreferenced files -- ideally, we'd
21325ca82e69SJohn Levon	# generate the master just once after all of the nightlies
21335ca82e69SJohn Levon	# have finished, but there's no simple way to know when that
21345ca82e69SJohn Levon	# will be.  Instead, we assume that we're the last nightly to
21355ca82e69SJohn Levon	# finish and merge all of the unref-${MACH}.out files in
21365ca82e69SJohn Levon	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
21375ca82e69SJohn Levon	# finish, then this file will be the authoritative master
21385ca82e69SJohn Levon	# list.  Otherwise, another ${MACH}'s nightly will eventually
21395ca82e69SJohn Levon	# overwrite ours with its own master, but in the meantime our
21405ca82e69SJohn Levon	# temporary "master" will be no worse than any older master
21415ca82e69SJohn Levon	# which was already on the parent.
21425ca82e69SJohn Levon	#
21435ca82e69SJohn Levon
21445ca82e69SJohn Levon	set -- $PARENT_WS/usr/src/unref-*.out
21455ca82e69SJohn Levon	cp "$1" ${TMPDIR}/unref.merge
21465ca82e69SJohn Levon	shift
21475ca82e69SJohn Levon
21485ca82e69SJohn Levon	for unreffile; do
21495ca82e69SJohn Levon		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
21505ca82e69SJohn Levon		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
21515ca82e69SJohn Levon	done
21525ca82e69SJohn Levon
21535ca82e69SJohn Levon	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
21545ca82e69SJohn Levonfi
21555ca82e69SJohn Levon
21565ca82e69SJohn Levon#
21575ca82e69SJohn Levon# All done save for the sweeping up.
21585ca82e69SJohn Levon# (whichever exit we hit here will trigger the "cleanup" trap which
21595ca82e69SJohn Levon# optionally sends mail on completion).
21605ca82e69SJohn Levon#
21615ca82e69SJohn Levonif [[ "$build_ok" == "y" ]]; then
21625ca82e69SJohn Levon	if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
21635ca82e69SJohn Levon		exit 0
21645ca82e69SJohn Levon	fi
21655ca82e69SJohn Levonfi
21665ca82e69SJohn Levon
21675ca82e69SJohn Levonexit 1
2168