xref: /illumos-gate/usr/src/tools/scripts/nightly (revision a56362d6)
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.
335ca82e69SJohn Levon#
345ca82e69SJohn Levon# Based on the nightly script from the integration folks,
355ca82e69SJohn Levon# Mostly modified and owned by mike_s.
365ca82e69SJohn Levon# Changes also by kjc, dmk.
375ca82e69SJohn Levon#
385ca82e69SJohn Levon# BRINGOVER_WS may be specified in the env file.
395ca82e69SJohn Levon# The default is the old behavior of CLONE_WS
405ca82e69SJohn Levon#
415ca82e69SJohn Levon# -i on the command line, means fast options, so when it's on the
425ca82e69SJohn Levon# command line (only), check builds are skipped no matter what
435ca82e69SJohn Levon# the setting of their individual flags are in NIGHTLY_OPTIONS.
445ca82e69SJohn Levon#
455ca82e69SJohn Levon# OPTHOME  may be set in the environment to override /opt
465ca82e69SJohn Levon#
475ca82e69SJohn Levon
485ca82e69SJohn Levon#
495ca82e69SJohn Levon# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
505ca82e69SJohn Levon# under certain circumstances, which can really screw things up; unset it.
515ca82e69SJohn Levon#
525ca82e69SJohn Levonunset CDPATH
535ca82e69SJohn Levon
545ca82e69SJohn Levon# Get the absolute path of the nightly script that the user invoked.  This
555ca82e69SJohn Levon# may be a relative path, and we need to do this before changing directory.
565ca82e69SJohn Levonnightly_path=`whence $0`
575ca82e69SJohn Levon
585ca82e69SJohn Levon#
595ca82e69SJohn Levon# Keep track of where we found nightly so we can invoke the matching
605ca82e69SJohn Levon# which_scm script.  If that doesn't work, don't go guessing, just rely
615ca82e69SJohn Levon# on the $PATH settings, which will generally give us either /opt/onbld
625ca82e69SJohn Levon# or the user's workspace.
635ca82e69SJohn Levon#
645ca82e69SJohn LevonWHICH_SCM=$(dirname $nightly_path)/which_scm
655ca82e69SJohn Levonif [[ ! -x $WHICH_SCM ]]; then
665ca82e69SJohn Levon	WHICH_SCM=which_scm
675ca82e69SJohn Levonfi
685ca82e69SJohn Levon
695ca82e69SJohn Levonfunction fatal_error
705ca82e69SJohn Levon{
715ca82e69SJohn Levon	print -u2 "nightly: $*"
725ca82e69SJohn Levon	exit 1
735ca82e69SJohn Levon}
745ca82e69SJohn Levon
755ca82e69SJohn Levon#
765ca82e69SJohn Levon# Function to do a DEBUG and non-DEBUG build. Needed because we might
775ca82e69SJohn Levon# need to do another for the source build, and since we only deliver DEBUG or
785ca82e69SJohn Levon# non-DEBUG packages.
795ca82e69SJohn Levon#
805ca82e69SJohn Levon# usage: normal_build
815ca82e69SJohn Levon#
825ca82e69SJohn Levonfunction normal_build {
835ca82e69SJohn Levon
845ca82e69SJohn Levon	typeset orig_p_FLAG="$p_FLAG"
855ca82e69SJohn Levon	typeset crypto_signer="$CODESIGN_USER"
865ca82e69SJohn Levon
875ca82e69SJohn Levon	suffix=""
885ca82e69SJohn Levon
895ca82e69SJohn Levon	# non-DEBUG build begins
905ca82e69SJohn Levon
915ca82e69SJohn Levon	if [ "$F_FLAG" = "n" ]; then
925ca82e69SJohn Levon		set_non_debug_build_flags
935ca82e69SJohn Levon		CODESIGN_USER="$crypto_signer" \
945ca82e69SJohn Levon		    build "non-DEBUG" "$suffix-nd" "-nd" "$MULTI_PROTO"
955ca82e69SJohn Levon	else
965ca82e69SJohn Levon		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
975ca82e69SJohn Levon	fi
985ca82e69SJohn Levon
995ca82e69SJohn Levon	# non-DEBUG build ends
1005ca82e69SJohn Levon
1015ca82e69SJohn Levon	# DEBUG build begins
1025ca82e69SJohn Levon
1035ca82e69SJohn Levon	if [ "$D_FLAG" = "y" ]; then
1045ca82e69SJohn Levon		set_debug_build_flags
1055ca82e69SJohn Levon		CODESIGN_USER="$crypto_signer" \
1065ca82e69SJohn Levon		    build "DEBUG" "$suffix" "" "$MULTI_PROTO"
1075ca82e69SJohn Levon	else
1085ca82e69SJohn Levon		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
1095ca82e69SJohn Levon	fi
1105ca82e69SJohn Levon
1115ca82e69SJohn Levon	# DEBUG build ends
1125ca82e69SJohn Levon
1135ca82e69SJohn Levon	p_FLAG="$orig_p_FLAG"
1145ca82e69SJohn Levon}
1155ca82e69SJohn Levon
1165ca82e69SJohn Levon#
1175ca82e69SJohn Levon# usage: run_hook HOOKNAME ARGS...
1185ca82e69SJohn Levon#
1195ca82e69SJohn Levon# If variable "$HOOKNAME" is defined, insert a section header into
1205ca82e69SJohn Levon# our logs and then run the command with ARGS
1215ca82e69SJohn Levon#
1225ca82e69SJohn Levonfunction run_hook {
1235ca82e69SJohn Levon	HOOKNAME=$1
1245ca82e69SJohn Levon	eval HOOKCMD=\$$HOOKNAME
1255ca82e69SJohn Levon	shift
1265ca82e69SJohn Levon
1275ca82e69SJohn Levon	if [ -n "$HOOKCMD" ]; then
1285ca82e69SJohn Levon		(
1295ca82e69SJohn Levon			echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
1305ca82e69SJohn Levon			( $HOOKCMD "$@" 2>&1 )
1315ca82e69SJohn Levon			if [ "$?" -ne 0 ]; then
1325ca82e69SJohn Levon				# Let exit status propagate up
1335ca82e69SJohn Levon				touch $TMPDIR/abort
1345ca82e69SJohn Levon			fi
1355ca82e69SJohn Levon		) | tee -a $mail_msg_file >> $LOGFILE
1365ca82e69SJohn Levon
1375ca82e69SJohn Levon		if [ -f $TMPDIR/abort ]; then
1385ca82e69SJohn Levon			build_ok=n
1395ca82e69SJohn Levon			echo "\nAborting at request of $HOOKNAME" |
1405ca82e69SJohn Levon				tee -a $mail_msg_file >> $LOGFILE
1415ca82e69SJohn Levon			exit 1
1425ca82e69SJohn Levon		fi
1435ca82e69SJohn Levon	fi
1445ca82e69SJohn Levon}
1455ca82e69SJohn Levon
1465ca82e69SJohn Levon# Return library search directive as function of given root.
1475ca82e69SJohn Levonfunction myldlibs {
1485ca82e69SJohn Levon	echo "-L$1/lib -L$1/usr/lib"
1495ca82e69SJohn Levon}
1505ca82e69SJohn Levon
1515ca82e69SJohn Levon# Return header search directive as function of given root.
1525ca82e69SJohn Levonfunction myheaders {
1535ca82e69SJohn Levon	echo "-I$1/usr/include"
1545ca82e69SJohn Levon}
1555ca82e69SJohn Levon
1565ca82e69SJohn Levon#
1575ca82e69SJohn Levon# Function to do the build, including package generation.
1585ca82e69SJohn Levon# usage: build LABEL SUFFIX ND MULTIPROTO
1595ca82e69SJohn Levon# - LABEL is used to tag build output.
1605ca82e69SJohn Levon# - SUFFIX is used to distinguish files (e.g., DEBUG vs non-DEBUG,
1615ca82e69SJohn Levon#   open-only vs full tree).
1625ca82e69SJohn Levon# - ND is "-nd" (non-DEBUG builds) or "" (DEBUG builds).
1635ca82e69SJohn Levon# - If MULTIPROTO is "yes", it means to name the proto area according to
1645ca82e69SJohn Levon#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
1655ca82e69SJohn Levon#
1665ca82e69SJohn Levonfunction build {
1675ca82e69SJohn Levon	LABEL=$1
1685ca82e69SJohn Levon	SUFFIX=$2
1695ca82e69SJohn Levon	ND=$3
1705ca82e69SJohn Levon	MULTIPROTO=$4
1715ca82e69SJohn Levon	INSTALLOG=install${SUFFIX}-${MACH}
1725ca82e69SJohn Levon	NOISE=noise${SUFFIX}-${MACH}
1735ca82e69SJohn Levon	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
1745ca82e69SJohn Levon
1755ca82e69SJohn Levon	ORIGROOT=$ROOT
1765ca82e69SJohn Levon	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
1775ca82e69SJohn Levon
1785ca82e69SJohn Levon	export ENVLDLIBS1=`myldlibs $ROOT`
1795ca82e69SJohn Levon	export ENVCPPFLAGS1=`myheaders $ROOT`
1805ca82e69SJohn Levon
1815ca82e69SJohn Levon	this_build_ok=y
1825ca82e69SJohn Levon	#
1835ca82e69SJohn Levon	#	Build OS-Networking source
1845ca82e69SJohn Levon	#
1855ca82e69SJohn Levon	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
1865ca82e69SJohn Levon		>> $LOGFILE
1875ca82e69SJohn Levon
1885ca82e69SJohn Levon	rm -f $SRC/${INSTALLOG}.out
1895ca82e69SJohn Levon	cd $SRC
1905ca82e69SJohn Levon	/bin/time $MAKE -e install 2>&1 | \
1915ca82e69SJohn Levon	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
1925ca82e69SJohn Levon
1935ca82e69SJohn Levon	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
1945ca82e69SJohn Levon	egrep ":" $SRC/${INSTALLOG}.out |
19520de283bSJohn Levon	    egrep -e "(^${MAKE}:|[ 	]error[: 	\n]|ld: guidance:)" | \
196eefeb0ceSBill Sommerfeld	    egrep -v ": (Entering|Leaving) directory " | \
1975ca82e69SJohn Levon	    egrep -v "Ignoring unknown host" | \
1985ca82e69SJohn Levon	    egrep -v "cc .* -o error " | \
1995ca82e69SJohn Levon	    egrep -v "warning" | tee $TMPDIR/build_errs${SUFFIX} \
2005ca82e69SJohn Levon	    >> $mail_msg_file
2015ca82e69SJohn Levon	    sed -n "/^Undefined[ 	]*first referenced$/,/^ld: fatal:/p" \
2025ca82e69SJohn Levon	    < $SRC/${INSTALLOG}.out >> $mail_msg_file
2035ca82e69SJohn Levon	if [[ -s $TMPDIR/build_errs${SUFFIX} ]]; then
2045ca82e69SJohn Levon		build_ok=n
2055ca82e69SJohn Levon		this_build_ok=n
2065ca82e69SJohn Levon	fi
2075ca82e69SJohn Levon	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
2085ca82e69SJohn Levon		>> $mail_msg_file
2095ca82e69SJohn Levon	if [ "$?" = "0" ]; then
2105ca82e69SJohn Levon		build_ok=n
2115ca82e69SJohn Levon		this_build_ok=n
2125ca82e69SJohn Levon	fi
2135ca82e69SJohn Levon
2145ca82e69SJohn Levon	echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
215*a56362d6SBill Sommerfeld	egrep -i 'warn(ing)?:' $SRC/${INSTALLOG}.out \
2165ca82e69SJohn Levon		| egrep -v '^tic:' \
2175ca82e69SJohn Levon		| egrep -v "symbol (\`|')timezone' has differing types:" \
2185ca82e69SJohn Levon		| egrep -v "parameter <PSTAMP> set to" \
2195ca82e69SJohn Levon		| egrep -v "Ignoring unknown host" \
2205ca82e69SJohn Levon		| egrep -v "redefining segment flags attribute for" \
2215ca82e69SJohn Levon		| tee $TMPDIR/build_warnings${SUFFIX} >> $mail_msg_file
2225ca82e69SJohn Levon	if [[ -s $TMPDIR/build_warnings${SUFFIX} ]]; then
2235ca82e69SJohn Levon		build_ok=n
2245ca82e69SJohn Levon		this_build_ok=n
2255ca82e69SJohn Levon	fi
2265ca82e69SJohn Levon
2275ca82e69SJohn Levon	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
2285ca82e69SJohn Levon		>> $LOGFILE
2295ca82e69SJohn Levon
2305ca82e69SJohn Levon	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
2315ca82e69SJohn Levon	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
2325ca82e69SJohn Levon
2335ca82e69SJohn Levon	if [ "$i_FLAG" = "n" ]; then
2345ca82e69SJohn Levon		rm -f $SRC/${NOISE}.ref
2355ca82e69SJohn Levon		if [ -f $SRC/${NOISE}.out ]; then
2365ca82e69SJohn Levon			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
2375ca82e69SJohn Levon		fi
2385ca82e69SJohn Levon		grep : $SRC/${INSTALLOG}.out \
2395ca82e69SJohn Levon			| egrep -v '^/' \
2405ca82e69SJohn Levon			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
2415ca82e69SJohn Levon			| egrep -v '^tic:' \
2425ca82e69SJohn Levon			| egrep -v '^mcs' \
2435ca82e69SJohn Levon			| egrep -v '^LD_LIBRARY_PATH=' \
2445ca82e69SJohn Levon			| egrep -v 'ar: creating' \
2455ca82e69SJohn Levon			| egrep -v 'ar: writing' \
2465ca82e69SJohn Levon			| egrep -v 'conflicts:' \
2475ca82e69SJohn Levon			| egrep -v ':saved created' \
2485ca82e69SJohn Levon			| egrep -v '^stty.*c:' \
2495ca82e69SJohn Levon			| egrep -v '^mfgname.c:' \
2505ca82e69SJohn Levon			| egrep -v '^uname-i.c:' \
2515ca82e69SJohn Levon			| egrep -v '^volumes.c:' \
2525ca82e69SJohn Levon			| egrep -v '^lint library construction:' \
2535ca82e69SJohn Levon			| egrep -v 'tsort: INFORM:' \
2545ca82e69SJohn Levon			| egrep -v 'stripalign:' \
2555ca82e69SJohn Levon			| egrep -v 'chars, width' \
2565ca82e69SJohn Levon			| egrep -v "symbol (\`|')timezone' has differing types:" \
2575ca82e69SJohn Levon			| egrep -v 'PSTAMP' \
2585ca82e69SJohn Levon			| egrep -v '^Manifying' \
2595ca82e69SJohn Levon			| egrep -v 'Ignoring unknown host' \
2605ca82e69SJohn Levon			| egrep -v 'Processing method:' \
2615ca82e69SJohn Levon			| egrep -v '^Writing' \
2625ca82e69SJohn Levon			| egrep -v 'spellin1:' \
2635ca82e69SJohn Levon			| egrep -v '^adding:' \
2645ca82e69SJohn Levon			| egrep -v "^echo 'msgid" \
2655ca82e69SJohn Levon			| egrep -v '^echo ' \
2665ca82e69SJohn Levon			| egrep -v '\.c:$' \
2675ca82e69SJohn Levon			| egrep -v '^Adding file:' \
2685ca82e69SJohn Levon			| egrep -v 'CLASSPATH=' \
2695ca82e69SJohn Levon			| egrep -v '\/var\/mail\/:saved' \
2705ca82e69SJohn Levon			| egrep -v -- '-DUTS_VERSION=' \
2715ca82e69SJohn Levon			| egrep -v '^Running Mkbootstrap' \
2725ca82e69SJohn Levon			| egrep -v '^Applet length read:' \
2735ca82e69SJohn Levon			| egrep -v 'bytes written:' \
2745ca82e69SJohn Levon			| egrep -v '^File:SolarisAuthApplet.bin' \
2755ca82e69SJohn Levon			| egrep -v -i 'jibversion' \
2765ca82e69SJohn Levon			| egrep -v '^Output size:' \
2775ca82e69SJohn Levon			| egrep -v '^Solo size statistics:' \
2785ca82e69SJohn Levon			| egrep -v '^Using ROM API Version' \
2795ca82e69SJohn Levon			| egrep -v '^Zero Signature length:' \
2805ca82e69SJohn Levon			| egrep -v '^Note \(probably harmless\):' \
2815ca82e69SJohn Levon			| egrep -v '::' \
2825ca82e69SJohn Levon			| egrep -v '^\+' \
2835ca82e69SJohn Levon			| egrep -v 'svccfg-native -s svc:/' \
284eefeb0ceSBill Sommerfeld			| egrep -v ": (Entering|Leaving) directory " \
2855ca82e69SJohn Levon			| sort | uniq >$SRC/${NOISE}.out
2865ca82e69SJohn Levon		if [ ! -f $SRC/${NOISE}.ref ]; then
2875ca82e69SJohn Levon			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
2885ca82e69SJohn Levon		fi
2895ca82e69SJohn Levon		echo "\n==== Build noise differences ($LABEL) ====\n" \
2905ca82e69SJohn Levon			>>$mail_msg_file
2915ca82e69SJohn Levon		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
2925ca82e69SJohn Levon	fi
2935ca82e69SJohn Levon
2945ca82e69SJohn Levon	#
2955ca82e69SJohn Levon	#	Re-sign selected binaries using signing server
2965ca82e69SJohn Levon	#	(gatekeeper builds only)
2975ca82e69SJohn Levon	#
2985ca82e69SJohn Levon	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
2995ca82e69SJohn Levon		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
3005ca82e69SJohn Levon		signing_file="${TMPDIR}/signing"
3015ca82e69SJohn Levon		rm -f ${signing_file}
3025ca82e69SJohn Levon		export CODESIGN_USER
3035ca82e69SJohn Levon		signproto $SRC/tools/codesign/creds 2>&1 | \
3045ca82e69SJohn Levon			tee -a ${signing_file} >> $LOGFILE
3055ca82e69SJohn Levon		echo "\n==== Finished signing proto area at `date` ====\n" \
3065ca82e69SJohn Levon		    >> $LOGFILE
3075ca82e69SJohn Levon		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
3085ca82e69SJohn Levon		    >> $mail_msg_file
3095ca82e69SJohn Levon		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
3105ca82e69SJohn Levon		if (( $? == 0 )) ; then
3115ca82e69SJohn Levon			build_ok=n
3125ca82e69SJohn Levon			this_build_ok=n
3135ca82e69SJohn Levon		fi
3145ca82e69SJohn Levon	fi
3155ca82e69SJohn Levon
3165ca82e69SJohn Levon	#
3175ca82e69SJohn Levon	#	Building Packages
3185ca82e69SJohn Levon	#
3195ca82e69SJohn Levon	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
3205ca82e69SJohn Levon		if [ -d $SRC/pkg ]; then
3215ca82e69SJohn Levon			echo "\n==== Creating $LABEL packages at `date` ====\n" \
3225ca82e69SJohn Levon				>> $LOGFILE
3235ca82e69SJohn Levon			echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
3245ca82e69SJohn Levon			rm -rf $PKGARCHIVE >> "$LOGFILE" 2>&1
3255ca82e69SJohn Levon			mkdir -p $PKGARCHIVE >> "$LOGFILE" 2>&1
3265ca82e69SJohn Levon
3275ca82e69SJohn Levon			rm -f $SRC/pkg/${INSTALLOG}.out
3285ca82e69SJohn Levon			cd $SRC/pkg
3295ca82e69SJohn Levon			/bin/time $MAKE -e install 2>&1 | \
3305ca82e69SJohn Levon			    tee -a $SRC/pkg/${INSTALLOG}.out >> $LOGFILE
3315ca82e69SJohn Levon
3325ca82e69SJohn Levon			echo "\n==== package build errors ($LABEL) ====\n" \
3335ca82e69SJohn Levon				>> $mail_msg_file
3345ca82e69SJohn Levon
3355ca82e69SJohn Levon			egrep "${MAKE}|ERROR|WARNING" $SRC/pkg/${INSTALLOG}.out | \
3365ca82e69SJohn Levon				grep ':' | \
3375ca82e69SJohn Levon				grep -v PSTAMP | \
338eefeb0ceSBill Sommerfeld				egrep -v "${MAKE}: (Entering|Leaving) directory " | \
3395ca82e69SJohn Levon				egrep -v "Ignoring unknown host" | \
3405ca82e69SJohn Levon				tee $TMPDIR/package >> $mail_msg_file
3415ca82e69SJohn Levon			if [[ -s $TMPDIR/package ]]; then
3425ca82e69SJohn Levon				build_extras_ok=n
3435ca82e69SJohn Levon				this_build_ok=n
3445ca82e69SJohn Levon			fi
3455ca82e69SJohn Levon		else
3465ca82e69SJohn Levon			#
3475ca82e69SJohn Levon			# Handle it gracefully if -p was set but there so
3485ca82e69SJohn Levon			# no pkg directory.
3495ca82e69SJohn Levon			#
3505ca82e69SJohn Levon			echo "\n==== No $LABEL packages to build ====\n" \
3515ca82e69SJohn Levon				>> $LOGFILE
3525ca82e69SJohn Levon		fi
3535ca82e69SJohn Levon	else
3545ca82e69SJohn Levon		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
3555ca82e69SJohn Levon	fi
3565ca82e69SJohn Levon
3575ca82e69SJohn Levon	ROOT=$ORIGROOT
3585ca82e69SJohn Levon}
3595ca82e69SJohn Levon
3605ca82e69SJohn Levon#
3615ca82e69SJohn Levon# Bootstrap build tools which are pre-requisites for the rest of the build.
3625ca82e69SJohn Levon#
3635ca82e69SJohn Levonfunction bootstrap_tools {
3645ca82e69SJohn Levon	echo "\n==== Bootstrapping tools at `date` ====\n" >> $LOGFILE
3655ca82e69SJohn Levon
3665ca82e69SJohn Levon	typeset INSTALLOG=install-bootstrap-${MACH}
3675ca82e69SJohn Levon
3685ca82e69SJohn Levon	rm -f $TMPDIR/make-state ${TOOLS}/$INSTALLOG.out
3695ca82e69SJohn Levon	cd ${TOOLS}
3705ca82e69SJohn Levon	/bin/time $MAKE -K $TMPDIR/make-state -e TARGET=install bootstrap \
3715ca82e69SJohn Levon	    2>&1 | tee -a ${TOOLS}/$INSTALLOG.out >> $LOGFILE
3725ca82e69SJohn Levon
3735ca82e69SJohn Levon	echo "\n==== Bootstrap build errors ====\n" >> $mail_msg_file
3745ca82e69SJohn Levon
3755ca82e69SJohn Levon	egrep ":" ${TOOLS}/$INSTALLOG.out |
3765ca82e69SJohn Levon	    egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
377eefeb0ceSBill Sommerfeld	    egrep -v ": (Entering|Leaving) directory " | \
3785ca82e69SJohn Levon	    egrep -v warning | tee $TMPDIR/bootstrap_errors >> $mail_msg_file
3795ca82e69SJohn Levon
3805ca82e69SJohn Levon	[[ -s $TMPDIR/bootstrap_errors ]] && return 1
3815ca82e69SJohn Levon	return 0
3825ca82e69SJohn Levon}
3835ca82e69SJohn Levon
3845ca82e69SJohn Levon#
3856faa6645SYuri Pankov# Build and install the tools.
3865ca82e69SJohn Levon#
3875ca82e69SJohn Levon# usage: build_tools DESTROOT
3885ca82e69SJohn Levon#
3896faa6645SYuri Pankov# returns zero status if the build was successful.
3905ca82e69SJohn Levon#
3915ca82e69SJohn Levonfunction build_tools {
3925ca82e69SJohn Levon	DESTROOT=$1
3935ca82e69SJohn Levon
3945ca82e69SJohn Levon	INSTALLOG=install-${MACH}
3955ca82e69SJohn Levon
3965ca82e69SJohn Levon	echo "\n==== Building tools at `date` ====\n" \
3975ca82e69SJohn Levon		>> $LOGFILE
3985ca82e69SJohn Levon
3995ca82e69SJohn Levon	rm -f ${TOOLS}/${INSTALLOG}.out
4005ca82e69SJohn Levon	cd ${TOOLS}
4015ca82e69SJohn Levon	/bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install 2>&1 | \
4025ca82e69SJohn Levon	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
4035ca82e69SJohn Levon
4045ca82e69SJohn Levon	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
4055ca82e69SJohn Levon
4065ca82e69SJohn Levon	egrep ":" ${TOOLS}/${INSTALLOG}.out |
4075ca82e69SJohn Levon		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
408eefeb0ceSBill Sommerfeld		egrep -v ": (Entering|Leaving) directory " | \
4095ca82e69SJohn Levon		egrep -v "Ignoring unknown host" | \
4105ca82e69SJohn Levon		egrep -v warning | tee $TMPDIR/tools_errors >> $mail_msg_file
4115ca82e69SJohn Levon
4125ca82e69SJohn Levon	if [[ -s $TMPDIR/tools_errors ]]; then
4135ca82e69SJohn Levon		return 1
4145ca82e69SJohn Levon	fi
4155ca82e69SJohn Levon	return 0
4165ca82e69SJohn Levon}
4175ca82e69SJohn Levon
4185ca82e69SJohn Levonfunction staffer {
4195ca82e69SJohn Levon	if [ $ISUSER -ne 0 ]; then
4205ca82e69SJohn Levon		"$@"
4215ca82e69SJohn Levon	else
4225ca82e69SJohn Levon		arg="\"$1\""
4235ca82e69SJohn Levon		shift
4245ca82e69SJohn Levon		for i
4255ca82e69SJohn Levon		do
4265ca82e69SJohn Levon			arg="$arg \"$i\""
4275ca82e69SJohn Levon		done
4285ca82e69SJohn Levon		eval su $STAFFER -c \'$arg\'
4295ca82e69SJohn Levon	fi
4305ca82e69SJohn Levon}
4315ca82e69SJohn Levon
4325ca82e69SJohn Levon#
4335ca82e69SJohn Levon# Verify that the closed bins are present
4345ca82e69SJohn Levon#
4355ca82e69SJohn Levonfunction check_closed_bins {
4365ca82e69SJohn Levon	if [[ -n "$ON_CLOSED_BINS" && ! -d "$ON_CLOSED_BINS" ]]; then
4375ca82e69SJohn Levon		echo "ON_CLOSED_BINS must point to the closed binaries tree."
4385ca82e69SJohn Levon		build_ok=n
4395ca82e69SJohn Levon		exit 1
4405ca82e69SJohn Levon	fi
4415ca82e69SJohn Levon}
4425ca82e69SJohn Levon
4435ca82e69SJohn Levon#
4445ca82e69SJohn Levon# wrapper over wsdiff.
4455ca82e69SJohn Levon# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
4465ca82e69SJohn Levon#
4475ca82e69SJohn Levonfunction do_wsdiff {
4485ca82e69SJohn Levon	label=$1
4495ca82e69SJohn Levon	oldproto=$2
4505ca82e69SJohn Levon	newproto=$3
4515ca82e69SJohn Levon
4525ca82e69SJohn Levon	wsdiff="wsdiff"
4535ca82e69SJohn Levon	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
4545ca82e69SJohn Levon
4555ca82e69SJohn Levon	echo "\n==== Getting object changes since last build at `date`" \
4565ca82e69SJohn Levon	    "($label) ====\n" | tee -a $LOGFILE >> $mail_msg_file
4575ca82e69SJohn Levon	$wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
4585ca82e69SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
4595ca82e69SJohn Levon	echo "\n==== Object changes determined at `date` ($label) ====\n" | \
4605ca82e69SJohn Levon	    tee -a $LOGFILE >> $mail_msg_file
4615ca82e69SJohn Levon}
4625ca82e69SJohn Levon
4635ca82e69SJohn Levon#
4645ca82e69SJohn Levon# Functions for setting build flags (DEBUG/non-DEBUG).  Keep them
4655ca82e69SJohn Levon# together.
4665ca82e69SJohn Levon#
4675ca82e69SJohn Levon
4685ca82e69SJohn Levonfunction set_non_debug_build_flags {
4695ca82e69SJohn Levon	export RELEASE_BUILD ; RELEASE_BUILD=
4705ca82e69SJohn Levon	unset EXTRA_OPTIONS
4715ca82e69SJohn Levon	unset EXTRA_CFLAGS
4725ca82e69SJohn Levon	if [ -n "$RELEASE_CONSOLE_COLOR" ]; then
4735ca82e69SJohn Levon		export DEFAULT_CONSOLE_COLOR="$RELEASE_CONSOLE_COLOR"
4745ca82e69SJohn Levon	fi
4755ca82e69SJohn Levon}
4765ca82e69SJohn Levon
4775ca82e69SJohn Levonfunction set_debug_build_flags {
4785ca82e69SJohn Levon	unset RELEASE_BUILD
4795ca82e69SJohn Levon	unset EXTRA_OPTIONS
4805ca82e69SJohn Levon	unset EXTRA_CFLAGS
4815ca82e69SJohn Levon
4825ca82e69SJohn Levon	if [ -n "$DEBUG_CONSOLE_COLOR" ]; then
4835ca82e69SJohn Levon		export DEFAULT_CONSOLE_COLOR="$DEBUG_CONSOLE_COLOR"
4845ca82e69SJohn Levon	fi
4855ca82e69SJohn Levon}
4865ca82e69SJohn Levon
4875ca82e69SJohn Levon
4885ca82e69SJohn LevonMACH=`uname -p`
4895ca82e69SJohn Levon
4905ca82e69SJohn Levonif [ "$OPTHOME" = "" ]; then
4915ca82e69SJohn Levon	OPTHOME=/opt
4925ca82e69SJohn Levon	export OPTHOME
4935ca82e69SJohn Levonfi
4945ca82e69SJohn Levon
4955ca82e69SJohn LevonUSAGE='Usage: nightly [-in] [+t] [-V VERS ] <env_file>
4965ca82e69SJohn Levon
4975ca82e69SJohn LevonWhere:
4985ca82e69SJohn Levon	-i	Fast incremental options (no clobber, check)
4995ca82e69SJohn Levon	-n      Do not do a bringover
5005ca82e69SJohn Levon	+t	Use the build tools in $ONBLD_TOOLS/bin
5015ca82e69SJohn Levon	-V VERS set the build version string to VERS
5025ca82e69SJohn Levon
5035ca82e69SJohn Levon	<env_file>  file in Bourne shell syntax that sets and exports
5045ca82e69SJohn Levon	variables that configure the operation of this script and many of
5055ca82e69SJohn Levon	the scripts this one calls. If <env_file> does not exist,
5065ca82e69SJohn Levon	it will be looked for in $OPTHOME/onbld/env.
5075ca82e69SJohn Levon
5085ca82e69SJohn Levonnon-DEBUG is the default build type. Build options can be set in the
5095ca82e69SJohn LevonNIGHTLY_OPTIONS variable in the <env_file> as follows:
5105ca82e69SJohn Levon
5115ca82e69SJohn Levon	-A	check for ABI differences in .so files
5125ca82e69SJohn Levon	-C	check for cstyle/hdrchk errors
5135ca82e69SJohn Levon	-D	do a build with DEBUG on
5145ca82e69SJohn Levon	-F	do _not_ do a non-DEBUG build
5155ca82e69SJohn Levon	-G	gate keeper default group of options (-au)
5165ca82e69SJohn Levon	-I	integration engineer default group of options (-ampu)
517069e6b7eSAndy Fiddaman	-L	do not run pkglint
5185ca82e69SJohn Levon	-M	do not run pmodes (safe file permission checker)
5195ca82e69SJohn Levon	-N	do not run protocmp
5205ca82e69SJohn Levon	-R	default group of options for building a release (-mp)
5215ca82e69SJohn Levon	-U	update proto area in the parent
5225ca82e69SJohn Levon	-V VERS set the build version string to VERS
5235ca82e69SJohn Levon	-f	find unreferenced files
5245ca82e69SJohn Levon	-i	do an incremental build (no "make clobber")
5255ca82e69SJohn Levon	-m	send mail to $MAILTO at end of build
5265ca82e69SJohn Levon	-n      do not do a bringover
5275ca82e69SJohn Levon	-p	create packages
5285ca82e69SJohn Levon	-r	check ELF runtime attributes in the proto area
5295ca82e69SJohn Levon	-t	build and use the tools in $SRC/tools (default setting)
5305ca82e69SJohn Levon	+t	Use the build tools in $ONBLD_TOOLS/bin
5315ca82e69SJohn Levon	-u	update proto_list_$MACH and friends in the parent workspace;
5325ca82e69SJohn Levon		when used with -f, also build an unrefmaster.out in the parent
5335ca82e69SJohn Levon	-w	report on differences between previous and current proto areas
5345ca82e69SJohn Levon'
5355ca82e69SJohn Levon#
5365ca82e69SJohn Levon#	A log file will be generated under the name $LOGFILE
5375ca82e69SJohn Levon#	for partially completed build and log.`date '+%F'`
5385ca82e69SJohn Levon#	in the same directory for fully completed builds.
5395ca82e69SJohn Levon#
5405ca82e69SJohn Levon
5415ca82e69SJohn Levon# default values for low-level FLAGS; G I R are group FLAGS
5425ca82e69SJohn LevonA_FLAG=n
5435ca82e69SJohn LevonC_FLAG=n
5445ca82e69SJohn LevonD_FLAG=n
5455ca82e69SJohn LevonF_FLAG=n
5465ca82e69SJohn Levonf_FLAG=n
5475ca82e69SJohn Levoni_FLAG=n; i_CMD_LINE_FLAG=n
548069e6b7eSAndy FiddamanL_FLAG=n
5495ca82e69SJohn LevonM_FLAG=n
5505ca82e69SJohn Levonm_FLAG=n
5515ca82e69SJohn LevonN_FLAG=n
5525ca82e69SJohn Levonn_FLAG=n
5535ca82e69SJohn Levonp_FLAG=n
5545ca82e69SJohn Levonr_FLAG=n
5555ca82e69SJohn Levont_FLAG=y
5565ca82e69SJohn LevonU_FLAG=n
5575ca82e69SJohn Levonu_FLAG=n
5585ca82e69SJohn LevonV_FLAG=n
5595ca82e69SJohn Levonw_FLAG=n
5605ca82e69SJohn LevonW_FLAG=n
5615ca82e69SJohn Levon#
5625ca82e69SJohn Levonbuild_ok=y
5635ca82e69SJohn Levonbuild_extras_ok=y
5645ca82e69SJohn Levon
5655ca82e69SJohn Levon#
5665ca82e69SJohn Levon# examine arguments
5675ca82e69SJohn Levon#
5685ca82e69SJohn Levon
5695ca82e69SJohn LevonOPTIND=1
5705ca82e69SJohn Levonwhile getopts +intV:W FLAG
5715ca82e69SJohn Levondo
5725ca82e69SJohn Levon	case $FLAG in
5735ca82e69SJohn Levon	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
5745ca82e69SJohn Levon		;;
5755ca82e69SJohn Levon	  n )	n_FLAG=y
5765ca82e69SJohn Levon		;;
5775ca82e69SJohn Levon	 +t )	t_FLAG=n
5785ca82e69SJohn Levon		;;
5795ca82e69SJohn Levon	  V )	V_FLAG=y
5805ca82e69SJohn Levon		V_ARG="$OPTARG"
5815ca82e69SJohn Levon		;;
5825ca82e69SJohn Levon	  W )   W_FLAG=y
5835ca82e69SJohn Levon		;;
5845ca82e69SJohn Levon	 \? )	echo "$USAGE"
5855ca82e69SJohn Levon		exit 1
5865ca82e69SJohn Levon		;;
5875ca82e69SJohn Levon	esac
5885ca82e69SJohn Levondone
5895ca82e69SJohn Levon
5905ca82e69SJohn Levon# correct argument count after options
5915ca82e69SJohn Levonshift `expr $OPTIND - 1`
5925ca82e69SJohn Levon
5935ca82e69SJohn Levon# test that the path to the environment-setting file was given
5945ca82e69SJohn Levonif [ $# -ne 1 ]; then
5955ca82e69SJohn Levon	echo "$USAGE"
5965ca82e69SJohn Levon	exit 1
5975ca82e69SJohn Levonfi
5985ca82e69SJohn Levon
5995ca82e69SJohn Levon# check if user is running nightly as root
6005ca82e69SJohn Levon# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
6015ca82e69SJohn Levon# when root invokes nightly.
6025ca82e69SJohn Levon/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
6035ca82e69SJohn LevonISUSER=$?;	export ISUSER
6045ca82e69SJohn Levon
6055ca82e69SJohn Levon#
6065ca82e69SJohn Levon# force locale to C
6075ca82e69SJohn LevonLANG=C;		export LANG
6085ca82e69SJohn LevonLC_ALL=C;	export LC_ALL
6095ca82e69SJohn LevonLC_COLLATE=C;	export LC_COLLATE
6105ca82e69SJohn LevonLC_CTYPE=C;	export LC_CTYPE
6115ca82e69SJohn LevonLC_MESSAGES=C;	export LC_MESSAGES
6125ca82e69SJohn LevonLC_MONETARY=C;	export LC_MONETARY
6135ca82e69SJohn LevonLC_NUMERIC=C;	export LC_NUMERIC
6145ca82e69SJohn LevonLC_TIME=C;	export LC_TIME
6155ca82e69SJohn Levon
6165ca82e69SJohn Levon# clear environment variables we know to be bad for the build
6175ca82e69SJohn Levonunset LD_OPTIONS
6185ca82e69SJohn Levonunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
6195ca82e69SJohn Levonunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
6205ca82e69SJohn Levonunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
6215ca82e69SJohn Levonunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
6225ca82e69SJohn Levonunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
6235ca82e69SJohn Levonunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
6245ca82e69SJohn Levonunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
6255ca82e69SJohn Levonunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
6265ca82e69SJohn Levonunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
6275ca82e69SJohn Levonunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
6285ca82e69SJohn Levonunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
6295ca82e69SJohn Levonunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
6305ca82e69SJohn Levonunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
6315ca82e69SJohn Levonunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
6325ca82e69SJohn Levonunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
6335ca82e69SJohn Levonunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
6345ca82e69SJohn Levonunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
6355ca82e69SJohn Levonunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
6365ca82e69SJohn Levonunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
6375ca82e69SJohn Levonunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
6385ca82e69SJohn Levon
6395ca82e69SJohn Levonunset CONFIG
6405ca82e69SJohn Levonunset GROUP
6415ca82e69SJohn Levonunset OWNER
6425ca82e69SJohn Levonunset REMOTE
6435ca82e69SJohn Levonunset ENV
6445ca82e69SJohn Levonunset ARCH
6455ca82e69SJohn Levonunset CLASSPATH
6465ca82e69SJohn Levonunset NAME
6475ca82e69SJohn Levon
6485ca82e69SJohn Levon#
6495ca82e69SJohn Levon# To get ONBLD_TOOLS from the environment, it must come from the env file.
6505ca82e69SJohn Levon# If it comes interactively, it is generally TOOLS_PROTO, which will be
6515ca82e69SJohn Levon# clobbered before the compiler version checks, which will therefore fail.
6525ca82e69SJohn Levon#
6535ca82e69SJohn Levonunset ONBLD_TOOLS
6545ca82e69SJohn Levon
6555ca82e69SJohn Levon#
6565ca82e69SJohn Levon#	Setup environmental variables
6575ca82e69SJohn Levon#
6585ca82e69SJohn Levonif [ -f /etc/nightly.conf ]; then
6595ca82e69SJohn Levon	. /etc/nightly.conf
6605ca82e69SJohn Levonfi
6615ca82e69SJohn Levon
6625ca82e69SJohn Levonif [ -f $1 ]; then
66326e7d9a8SRichard Lowe	if [[ $1 == */* ]]; then
6645ca82e69SJohn Levon		. $1
6655ca82e69SJohn Levon	else
6665ca82e69SJohn Levon		. ./$1
6675ca82e69SJohn Levon	fi
6685ca82e69SJohn Levonelse
6695ca82e69SJohn Levon	if [ -f $OPTHOME/onbld/env/$1 ]; then
6705ca82e69SJohn Levon		. $OPTHOME/onbld/env/$1
6715ca82e69SJohn Levon	else
6725ca82e69SJohn Levon		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
6735ca82e69SJohn Levon		exit 1
6745ca82e69SJohn Levon	fi
6755ca82e69SJohn Levonfi
6765ca82e69SJohn Levon
6775ca82e69SJohn Levon# Check if we have sufficient data to continue...
6785ca82e69SJohn Levon[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
6795ca82e69SJohn Levonif  [[ "${NIGHTLY_OPTIONS}" == ~(F)n ]] ; then
6805ca82e69SJohn Levon	# Check if the gate data are valid if we don't do a "bringover" below
6815ca82e69SJohn Levon	[[ -d "${CODEMGR_WS}" ]] || \
6825ca82e69SJohn Levon		fatal_error "Error: ${CODEMGR_WS} is not a directory."
6835ca82e69SJohn Levon	[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || \
6845ca82e69SJohn Levon		fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
6855ca82e69SJohn Levonfi
6865ca82e69SJohn Levon
6875ca82e69SJohn Levon#
6885ca82e69SJohn Levon# place ourselves in a new task, respecting BUILD_PROJECT if set.
6895ca82e69SJohn Levon#
6905ca82e69SJohn Levonif [ -z "$BUILD_PROJECT" ]; then
6915ca82e69SJohn Levon	/usr/bin/newtask -c $$
6925ca82e69SJohn Levonelse
6935ca82e69SJohn Levon	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
6945ca82e69SJohn Levonfi
6955ca82e69SJohn Levon
6965ca82e69SJohn Levonps -o taskid= -p $$ | read build_taskid
6975ca82e69SJohn Levonps -o project= -p $$ | read build_project
6985ca82e69SJohn Levon
6995ca82e69SJohn Levon#
7005ca82e69SJohn Levon# See if NIGHTLY_OPTIONS is set
7015ca82e69SJohn Levon#
7025ca82e69SJohn Levonif [ "$NIGHTLY_OPTIONS" = "" ]; then
7035ca82e69SJohn Levon	NIGHTLY_OPTIONS="-aBm"
7045ca82e69SJohn Levonfi
7055ca82e69SJohn Levon
7065ca82e69SJohn Levon#
7075ca82e69SJohn Levon# If BRINGOVER_WS was not specified, let it default to CLONE_WS
7085ca82e69SJohn Levon#
7095ca82e69SJohn Levonif [ "$BRINGOVER_WS" = "" ]; then
7105ca82e69SJohn Levon	BRINGOVER_WS=$CLONE_WS
7115ca82e69SJohn Levonfi
7125ca82e69SJohn Levon
7135ca82e69SJohn Levon#
7145ca82e69SJohn Levon# If BRINGOVER_FILES was not specified, default to usr
7155ca82e69SJohn Levon#
7165ca82e69SJohn Levonif [ "$BRINGOVER_FILES" = "" ]; then
7175ca82e69SJohn Levon	BRINGOVER_FILES="usr"
7185ca82e69SJohn Levonfi
7195ca82e69SJohn Levon
7205ca82e69SJohn Levoncheck_closed_bins
7215ca82e69SJohn Levon
7225ca82e69SJohn Levon#
7235ca82e69SJohn Levon# Note: changes to the option letters here should also be applied to the
7245ca82e69SJohn Levon#	bldenv script.  `d' is listed for backward compatibility.
7255ca82e69SJohn Levon#
7265ca82e69SJohn LevonNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
7275ca82e69SJohn LevonOPTIND=1
728069e6b7eSAndy Fiddamanwhile getopts +ABCDdFfGIiLMmNnpRrtUuwW FLAG $NIGHTLY_OPTIONS
7295ca82e69SJohn Levondo
7305ca82e69SJohn Levon	case $FLAG in
7315ca82e69SJohn Levon	  A )	A_FLAG=y
7325ca82e69SJohn Levon		;;
7335ca82e69SJohn Levon	  B )	D_FLAG=y
7345ca82e69SJohn Levon		;; # old version of D
7355ca82e69SJohn Levon	  C )	C_FLAG=y
7365ca82e69SJohn Levon		;;
7375ca82e69SJohn Levon	  D )	D_FLAG=y
7385ca82e69SJohn Levon		;;
7395ca82e69SJohn Levon	  F )	F_FLAG=y
7405ca82e69SJohn Levon		;;
7415ca82e69SJohn Levon	  f )	f_FLAG=y
7425ca82e69SJohn Levon		;;
7435ca82e69SJohn Levon	  G )   u_FLAG=y
7445ca82e69SJohn Levon		;;
7455ca82e69SJohn Levon	  I )	m_FLAG=y
7465ca82e69SJohn Levon		p_FLAG=y
7475ca82e69SJohn Levon		u_FLAG=y
7485ca82e69SJohn Levon		;;
7495ca82e69SJohn Levon	  i )	i_FLAG=y
7505ca82e69SJohn Levon		;;
751069e6b7eSAndy Fiddaman	  L )	L_FLAG=y
752069e6b7eSAndy Fiddaman		;;
7535ca82e69SJohn Levon	  M )	M_FLAG=y
7545ca82e69SJohn Levon		;;
7555ca82e69SJohn Levon	  m )	m_FLAG=y
7565ca82e69SJohn Levon		;;
7575ca82e69SJohn Levon	  N )	N_FLAG=y
7585ca82e69SJohn Levon		;;
7595ca82e69SJohn Levon	  n )	n_FLAG=y
7605ca82e69SJohn Levon		;;
7615ca82e69SJohn Levon	  p )	p_FLAG=y
7625ca82e69SJohn Levon		;;
7635ca82e69SJohn Levon	  R )	m_FLAG=y
7645ca82e69SJohn Levon		p_FLAG=y
7655ca82e69SJohn Levon		;;
7665ca82e69SJohn Levon	  r )	r_FLAG=y
7675ca82e69SJohn Levon		;;
7685ca82e69SJohn Levon	 +t )	t_FLAG=n
7695ca82e69SJohn Levon		;;
7705ca82e69SJohn Levon	  U )   if [ -z "${PARENT_ROOT}" ]; then
7715ca82e69SJohn Levon			echo "PARENT_ROOT must be set if the U flag is" \
7725ca82e69SJohn Levon			    "present in NIGHTLY_OPTIONS."
7735ca82e69SJohn Levon			exit 1
7745ca82e69SJohn Levon		fi
7755ca82e69SJohn Levon		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
7765ca82e69SJohn Levon		if [ -n "${PARENT_TOOLS_ROOT}" ]; then
7775ca82e69SJohn Levon			NIGHTLY_PARENT_TOOLS_ROOT=$PARENT_TOOLS_ROOT
7785ca82e69SJohn Levon		fi
7795ca82e69SJohn Levon		U_FLAG=y
7805ca82e69SJohn Levon		;;
7815ca82e69SJohn Levon	  u )	u_FLAG=y
7825ca82e69SJohn Levon		;;
7835ca82e69SJohn Levon	  w )	w_FLAG=y
7845ca82e69SJohn Levon		;;
7855ca82e69SJohn Levon	  W )   W_FLAG=y
7865ca82e69SJohn Levon		;;
7875ca82e69SJohn Levon	 \? )	echo "$USAGE"
7885ca82e69SJohn Levon		exit 1
7895ca82e69SJohn Levon		;;
7905ca82e69SJohn Levon	esac
7915ca82e69SJohn Levondone
7925ca82e69SJohn Levon
7939cc2e6acSMatt Fiddaman# Skip pkglint if packages aren't being built
7949cc2e6acSMatt Fiddaman[ $p_FLAG = n ] && L_FLAG=y
7959cc2e6acSMatt Fiddaman
7965ca82e69SJohn Levonif [ $ISUSER -ne 0 ]; then
7975ca82e69SJohn Levon	# Set default value for STAFFER, if needed.
7985ca82e69SJohn Levon	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
7995ca82e69SJohn Levon		STAFFER=`/usr/xpg4/bin/id -un`
8005ca82e69SJohn Levon		export STAFFER
8015ca82e69SJohn Levon	fi
8025ca82e69SJohn Levonfi
8035ca82e69SJohn Levon
8045ca82e69SJohn Levonif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
8055ca82e69SJohn Levon	MAILTO=$STAFFER
8065ca82e69SJohn Levon	export MAILTO
8075ca82e69SJohn Levonfi
8085ca82e69SJohn Levon
8095ca82e69SJohn LevonPATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
8105ca82e69SJohn LevonPATH="$PATH:$OPTHOME/SUNWspro/bin:/usr/bin:/usr/sbin:/usr/ucb"
8115ca82e69SJohn LevonPATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
8125ca82e69SJohn Levonexport PATH
8135ca82e69SJohn Levon
8145ca82e69SJohn Levon# roots of source trees, both relative to $SRC and absolute.
8155ca82e69SJohn Levonrelsrcdirs="."
8165ca82e69SJohn Levonabssrcdirs="$SRC"
8175ca82e69SJohn Levon
8185ca82e69SJohn LevonPROTOCMPTERSE="protocmp.terse -gu"
8195ca82e69SJohn LevonPOUND_SIGN="#"
8206112cec5SJoshua M. Clulowbasews="$(basename "$CODEMGR_WS")"
8215ca82e69SJohn Levon# have we set RELEASE_DATE in our env file?
8225ca82e69SJohn Levonif [ -z "$RELEASE_DATE" ]; then
8235ca82e69SJohn Levon	RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
8245ca82e69SJohn Levonfi
8256112cec5SJoshua M. Clulownow=$(LC_ALL=C date +%Y-%b-%d)
8266112cec5SJoshua M. ClulowDEV_CM_TAIL="development build: $LOGNAME $now [$basews]"
8275ca82e69SJohn Levon
8286112cec5SJoshua M. Clulow#
8296112cec5SJoshua M. Clulow# We export POUND_SIGN, RELEASE_DATE and DEV_CM_TAIL to speed up the build
8306112cec5SJoshua M. Clulow# process by avoiding repeated shell invocations to evaluate Makefile.master
8315ca82e69SJohn Levon# definitions.
8326112cec5SJoshua M. Clulow#
8336112cec5SJoshua M. Clulowexport POUND_SIGN RELEASE_DATE DEV_CM_TAIL
8345ca82e69SJohn Levon
8355ca82e69SJohn Levonmaketype="distributed"
8365ca82e69SJohn Levonif [[ -z "$MAKE" ]]; then
8375ca82e69SJohn Levon	MAKE=dmake
8385ca82e69SJohn Levonelif [[ ! -x "$MAKE" ]]; then
8395ca82e69SJohn Levon	echo "\$MAKE is set to garbage in the environment"
8405ca82e69SJohn Levon	exit 1
8415ca82e69SJohn Levonfi
8425ca82e69SJohn Levonexport PATH
8435ca82e69SJohn Levonexport MAKE
8445ca82e69SJohn Levon
8455ca82e69SJohn Levonif [ "${SUNWSPRO}" != "" ]; then
8465ca82e69SJohn Levon	PATH="${SUNWSPRO}/bin:$PATH"
8475ca82e69SJohn Levon	export PATH
8485ca82e69SJohn Levonfi
8495ca82e69SJohn Levon
8505ca82e69SJohn Levonhostname=$(uname -n)
85126e7d9a8SRichard Loweif [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS == 0 ]]
8525ca82e69SJohn Levonthen
8535ca82e69SJohn Levon	maxjobs=
8545ca82e69SJohn Levon	if [[ -f $HOME/.make.machines ]]
8555ca82e69SJohn Levon	then
8565ca82e69SJohn Levon		# Note: there is a hard tab and space character in the []s
8575ca82e69SJohn Levon		# below.
85826e7d9a8SRichard Lowe		egrep -i "^[ 	]*${hostname}[ 	\.]" \
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 Levon#
8815ca82e69SJohn Levon# if -V flag was given, reset VERSION to V_ARG
8825ca82e69SJohn Levon#
8835ca82e69SJohn Levonif [ "$V_FLAG" = "y" ]; then
8845ca82e69SJohn Levon	VERSION=$V_ARG
8855ca82e69SJohn Levonfi
8865ca82e69SJohn Levon
8875ca82e69SJohn LevonTMPDIR="/tmp/nightly.tmpdir.$$"
8885ca82e69SJohn Levonexport TMPDIR
8895ca82e69SJohn Levonrm -rf ${TMPDIR}
8905ca82e69SJohn Levonmkdir -p $TMPDIR || exit 1
8915ca82e69SJohn Levonchmod 777 $TMPDIR
8925ca82e69SJohn Levon
8935ca82e69SJohn Levon#
8945ca82e69SJohn Levon# Work around folks who have historically used GCC_ROOT and convert it to
8955ca82e69SJohn Levon# GNUC_ROOT. We leave GCC_ROOT in the environment for now (though this could
8965ca82e69SJohn Levon# mess up the case where multiple different gcc versions are being used to
8975ca82e69SJohn Levon# shadow).
8985ca82e69SJohn Levon#
8995ca82e69SJohn Levonif [[ -n "${GCC_ROOT}" ]]; then
9005ca82e69SJohn Levon	export GNUC_ROOT=${GCC_ROOT}
9015ca82e69SJohn Levonfi
9025ca82e69SJohn Levon
9035ca82e69SJohn Levon#
9045ca82e69SJohn Levon# Tools should only be built non-DEBUG.  Keep track of the tools proto
9055ca82e69SJohn Levon# area path relative to $TOOLS, because the latter changes in an
9065ca82e69SJohn Levon# export build.
9075ca82e69SJohn Levon#
9085ca82e69SJohn Levon# TOOLS_PROTO is included below for builds other than usr/src/tools
9095ca82e69SJohn Levon# that look for this location.  For usr/src/tools, this will be
9105ca82e69SJohn Levon# overridden on the $MAKE command line in build_tools().
9115ca82e69SJohn Levon#
9125ca82e69SJohn LevonTOOLS=${SRC}/tools
9135ca82e69SJohn LevonTOOLS_PROTO_REL=proto/root_${MACH}-nd
9145ca82e69SJohn LevonTOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL};	export TOOLS_PROTO
9155ca82e69SJohn Levon
9165ca82e69SJohn Levonunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
9175ca82e69SJohn Levon
9185ca82e69SJohn Levon# create directories that are automatically removed if the nightly script
9195ca82e69SJohn Levon# fails to start correctly
9205ca82e69SJohn Levonfunction newdir {
9215ca82e69SJohn Levon	dir=$1
9225ca82e69SJohn Levon	toadd=
9235ca82e69SJohn Levon	while [ ! -d $dir ]; do
9245ca82e69SJohn Levon		toadd="$dir $toadd"
9255ca82e69SJohn Levon		dir=`dirname $dir`
9265ca82e69SJohn Levon	done
9275ca82e69SJohn Levon	torm=
9285ca82e69SJohn Levon	newlist=
9295ca82e69SJohn Levon	for dir in $toadd; do
9305ca82e69SJohn Levon		if staffer mkdir $dir; then
9315ca82e69SJohn Levon			newlist="$ISUSER $dir $newlist"
9325ca82e69SJohn Levon			torm="$dir $torm"
9335ca82e69SJohn Levon		else
9345ca82e69SJohn Levon			[ -z "$torm" ] || staffer rmdir $torm
9355ca82e69SJohn Levon			return 1
9365ca82e69SJohn Levon		fi
9375ca82e69SJohn Levon	done
9385ca82e69SJohn Levon	newdirlist="$newlist $newdirlist"
9395ca82e69SJohn Levon	return 0
9405ca82e69SJohn Levon}
9415ca82e69SJohn Levonnewdirlist=
9425ca82e69SJohn Levon
9435ca82e69SJohn Levon[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
9445ca82e69SJohn Levon
9455ca82e69SJohn Levon# since this script assumes the build is from full source, it nullifies
9465ca82e69SJohn Levon# variables likely to have been set by a "ws" script; nullification
9475ca82e69SJohn Levon# confines the search space for headers and libraries to the proto area
9485ca82e69SJohn Levon# built from this immediate source.
9495ca82e69SJohn LevonENVLDLIBS1=
9505ca82e69SJohn LevonENVLDLIBS2=
9515ca82e69SJohn LevonENVLDLIBS3=
9525ca82e69SJohn LevonENVCPPFLAGS1=
9535ca82e69SJohn LevonENVCPPFLAGS2=
9545ca82e69SJohn LevonENVCPPFLAGS3=
9555ca82e69SJohn LevonENVCPPFLAGS4=
9565ca82e69SJohn LevonPARENT_ROOT=
9575ca82e69SJohn Levon
9585ca82e69SJohn Levonexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
9595ca82e69SJohn Levon	ENVLDLIBS1 ENVLDLIBS2 PARENT_ROOT
9605ca82e69SJohn Levon
9615ca82e69SJohn LevonPKGARCHIVE_ORIG=$PKGARCHIVE
9625ca82e69SJohn Levon
9635ca82e69SJohn Levon#
9645ca82e69SJohn Levon# Juggle the logs and optionally send mail on completion.
9655ca82e69SJohn Levon#
9665ca82e69SJohn Levon
9675ca82e69SJohn Levonfunction logshuffle {
9685ca82e69SJohn Levon	LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
9695ca82e69SJohn Levon	if [ -f $LLOG -o -d $LLOG ]; then
9705ca82e69SJohn Levon		LLOG=$LLOG.$$
9715ca82e69SJohn Levon	fi
9725ca82e69SJohn Levon
9735ca82e69SJohn Levon	rm -f "$ATLOG/latest" 2>/dev/null
9745ca82e69SJohn Levon	mkdir -p $LLOG
9755ca82e69SJohn Levon	export LLOG
9765ca82e69SJohn Levon
9775ca82e69SJohn Levon	if [ "$build_ok" = "y" ]; then
9785ca82e69SJohn Levon		mv $ATLOG/proto_list_${MACH} $LLOG
9795ca82e69SJohn Levon
9805ca82e69SJohn Levon		if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
9815ca82e69SJohn Levon			mv $ATLOG/proto_list_tools_${MACH} $LLOG
9825ca82e69SJohn Levon	        fi
9835ca82e69SJohn Levon
9845ca82e69SJohn Levon		if [ -f $TMPDIR/wsdiff.results ]; then
9855ca82e69SJohn Levon			mv $TMPDIR/wsdiff.results $LLOG
9865ca82e69SJohn Levon		fi
9875ca82e69SJohn Levon
9885ca82e69SJohn Levon		if [ -f $TMPDIR/wsdiff-nd.results ]; then
9895ca82e69SJohn Levon			mv $TMPDIR/wsdiff-nd.results $LLOG
9905ca82e69SJohn Levon		fi
9915ca82e69SJohn Levon	fi
9925ca82e69SJohn Levon
9935ca82e69SJohn Levon	#
9945ca82e69SJohn Levon	# Now that we're about to send mail, it's time to check the noise
9955ca82e69SJohn Levon	# file.  In the event that an error occurs beyond this point, it will
9965ca82e69SJohn Levon	# be recorded in the nightly.log file, but nowhere else.  This would
9975ca82e69SJohn Levon	# include only errors that cause the copying of the noise log to fail
9985ca82e69SJohn Levon	# or the mail itself not to be sent.
9995ca82e69SJohn Levon	#
10005ca82e69SJohn Levon
10015ca82e69SJohn Levon	exec >>$LOGFILE 2>&1
10025ca82e69SJohn Levon	if [ -s $build_noise_file ]; then
10035ca82e69SJohn Levon		echo "\n==== Nightly build noise ====\n" |
10045ca82e69SJohn Levon		    tee -a $LOGFILE >>$mail_msg_file
10055ca82e69SJohn Levon		cat $build_noise_file >>$LOGFILE
10065ca82e69SJohn Levon		cat $build_noise_file >>$mail_msg_file
10075ca82e69SJohn Levon		echo | tee -a $LOGFILE >>$mail_msg_file
10085ca82e69SJohn Levon	fi
10095ca82e69SJohn Levon	rm -f $build_noise_file
10105ca82e69SJohn Levon
10115ca82e69SJohn Levon	case "$build_ok" in
10125ca82e69SJohn Levon		y)
10135ca82e69SJohn Levon			state=Completed
10145ca82e69SJohn Levon			;;
10155ca82e69SJohn Levon		i)
10165ca82e69SJohn Levon			state=Interrupted
10175ca82e69SJohn Levon			;;
10185ca82e69SJohn Levon		*)
10195ca82e69SJohn Levon			state=Failed
10205ca82e69SJohn Levon			;;
10215ca82e69SJohn Levon	esac
10225ca82e69SJohn Levon
10235ca82e69SJohn Levon	if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
10245ca82e69SJohn Levon		state=Failed
10255ca82e69SJohn Levon	fi
10265ca82e69SJohn Levon
10275ca82e69SJohn Levon	NIGHTLY_STATUS=$state
10285ca82e69SJohn Levon	export NIGHTLY_STATUS
10295ca82e69SJohn Levon
10305ca82e69SJohn Levon	run_hook POST_NIGHTLY $state
10315ca82e69SJohn Levon	run_hook SYS_POST_NIGHTLY $state
10325ca82e69SJohn Levon
10335ca82e69SJohn Levon	#
10345ca82e69SJohn Levon	# mailx(1) sets From: based on the -r flag
10355ca82e69SJohn Levon	# if it is given.
10365ca82e69SJohn Levon	#
10375ca82e69SJohn Levon	mailx_r=
10385ca82e69SJohn Levon	if [[ -n "${MAILFROM}" ]]; then
10395ca82e69SJohn Levon		mailx_r="-r ${MAILFROM}"
10405ca82e69SJohn Levon	fi
10415ca82e69SJohn Levon
10425ca82e69SJohn Levon	cat $build_time_file $build_environ_file $mail_msg_file \
10435ca82e69SJohn Levon	    > ${LLOG}/mail_msg
10445ca82e69SJohn Levon	if [ "$m_FLAG" = "y" ]; then
10456112cec5SJoshua M. Clulow		/usr/bin/mailx ${mailx_r} -s \
10466112cec5SJoshua M. Clulow		    "Nightly ${MACH} Build of ${basews} ${state}." \
10476112cec5SJoshua M. Clulow		    "${MAILTO}" < "${LLOG}/mail_msg"
10485ca82e69SJohn Levon	fi
10495ca82e69SJohn Levon
10505ca82e69SJohn Levon	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
10515ca82e69SJohn Levon		staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
10525ca82e69SJohn Levon		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
10535ca82e69SJohn Levon	fi
10545ca82e69SJohn Levon
10555ca82e69SJohn Levon	mv $LOGFILE $LLOG
10565ca82e69SJohn Levon
10575ca82e69SJohn Levon	ln -s "$LLOG" "$ATLOG/latest"
10585ca82e69SJohn Levon}
10595ca82e69SJohn Levon
10605ca82e69SJohn Levon#
10615ca82e69SJohn Levon#	Remove the locks and temporary files on any exit
10625ca82e69SJohn Levon#
10635ca82e69SJohn Levonfunction cleanup {
10645ca82e69SJohn Levon	logshuffle
10655ca82e69SJohn Levon
10665ca82e69SJohn Levon	[ -z "$lockfile" ] || staffer rm -f $lockfile
10675ca82e69SJohn Levon	[ -z "$atloglockfile" ] || rm -f $atloglockfile
10685ca82e69SJohn Levon	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
10695ca82e69SJohn Levon	[ -z "$Ulockfile" ] || rm -f $Ulockfile
10705ca82e69SJohn Levon
10715ca82e69SJohn Levon	set -- $newdirlist
10725ca82e69SJohn Levon	while [ $# -gt 0 ]; do
10735ca82e69SJohn Levon		ISUSER=$1 staffer rmdir $2
10745ca82e69SJohn Levon		shift; shift
10755ca82e69SJohn Levon	done
10765ca82e69SJohn Levon	rm -rf $TMPDIR
10775ca82e69SJohn Levon}
10785ca82e69SJohn Levon
10795ca82e69SJohn Levonfunction cleanup_signal {
10805ca82e69SJohn Levon	build_ok=i
10815ca82e69SJohn Levon	# this will trigger cleanup(), above.
10825ca82e69SJohn Levon	exit 1
10835ca82e69SJohn Levon}
10845ca82e69SJohn Levon
10855ca82e69SJohn Levontrap cleanup 0
10865ca82e69SJohn Levontrap cleanup_signal 1 2 3 15
10875ca82e69SJohn Levon
10885ca82e69SJohn Levon#
10895ca82e69SJohn Levon# Generic lock file processing -- make sure that the lock file doesn't
10905ca82e69SJohn Levon# exist.  If it does, it should name the build host and PID.  If it
10915ca82e69SJohn Levon# doesn't, then make sure we can create it.  Clean up locks that are
10925ca82e69SJohn Levon# known to be stale (assumes host name is unique among build systems
10935ca82e69SJohn Levon# for the workspace).
10945ca82e69SJohn Levon#
10955ca82e69SJohn Levonfunction create_lock {
10965ca82e69SJohn Levon	lockf=$1
10975ca82e69SJohn Levon	lockvar=$2
10985ca82e69SJohn Levon
10995ca82e69SJohn Levon	ldir=`dirname $lockf`
11005ca82e69SJohn Levon	[ -d $ldir ] || newdir $ldir || exit 1
11015ca82e69SJohn Levon	eval $lockvar=$lockf
11025ca82e69SJohn Levon
11035ca82e69SJohn Levon	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
11045ca82e69SJohn Levon		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
11055ca82e69SJohn Levon		if [ "$host" != "$hostname" ]; then
11065ca82e69SJohn Levon			echo "$MACH build of $basews apparently" \
11075ca82e69SJohn Levon			    "already started by $user on $host as $pid."
11085ca82e69SJohn Levon			exit 1
11095ca82e69SJohn Levon		elif kill -s 0 $pid 2>/dev/null; then
11105ca82e69SJohn Levon			echo "$MACH build of $basews already started" \
11115ca82e69SJohn Levon			    "by $user as $pid."
11125ca82e69SJohn Levon			exit 1
11135ca82e69SJohn Levon		else
11145ca82e69SJohn Levon			# stale lock; clear it out and try again
11155ca82e69SJohn Levon			rm -f $lockf
11165ca82e69SJohn Levon		fi
11175ca82e69SJohn Levon	done
11185ca82e69SJohn Levon}
11195ca82e69SJohn Levon
11205ca82e69SJohn Levon#
11215ca82e69SJohn Levon# Return the list of interesting proto areas, depending on the current
11225ca82e69SJohn Levon# options.
11235ca82e69SJohn Levon#
11245ca82e69SJohn Levonfunction allprotos {
11255ca82e69SJohn Levon	typeset roots="$ROOT"
11265ca82e69SJohn Levon
112726e7d9a8SRichard Lowe	if [[ "$F_FLAG" == n && "$MULTI_PROTO" == yes ]]; then
11285ca82e69SJohn Levon		roots="$roots $ROOT-nd"
11295ca82e69SJohn Levon	fi
11305ca82e69SJohn Levon
11315ca82e69SJohn Levon	echo $roots
11325ca82e69SJohn Levon}
11335ca82e69SJohn Levon
11345ca82e69SJohn Levon# Ensure no other instance of this script is running on this host.
11355ca82e69SJohn Levon# LOCKNAME can be set in <env_file>, and is by default, but is not
11365ca82e69SJohn Levon# required due to the use of $ATLOG below.
11375ca82e69SJohn Levonif [ -n "$LOCKNAME" ]; then
11385ca82e69SJohn Levon	create_lock /tmp/$LOCKNAME "lockfile"
11395ca82e69SJohn Levonfi
11405ca82e69SJohn Levon#
11415ca82e69SJohn Levon# Create from one, two, or three other locks:
11425ca82e69SJohn Levon#	$ATLOG/nightly.lock
11435ca82e69SJohn Levon#		- protects against multiple builds in same workspace
11445ca82e69SJohn Levon#	$PARENT_WS/usr/src/nightly.$MACH.lock
11455ca82e69SJohn Levon#		- protects against multiple 'u' copy-backs
11465ca82e69SJohn Levon#	$NIGHTLY_PARENT_ROOT/nightly.lock
11475ca82e69SJohn Levon#		- protects against multiple 'U' copy-backs
11485ca82e69SJohn Levon#
11495ca82e69SJohn Levon# Overriding ISUSER to 1 causes the lock to be created as root if the
11505ca82e69SJohn Levon# script is run as root.  The default is to create it as $STAFFER.
11515ca82e69SJohn LevonISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
11525ca82e69SJohn Levonif [ "$u_FLAG" = "y" ]; then
11535ca82e69SJohn Levon	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
11545ca82e69SJohn Levonfi
11555ca82e69SJohn Levonif [ "$U_FLAG" = "y" ]; then
11565ca82e69SJohn Levon	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
11575ca82e69SJohn Levon	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
11585ca82e69SJohn Levonfi
11595ca82e69SJohn Levon
11605ca82e69SJohn Levon# Locks have been taken, so we're doing a build and we're committed to
11615ca82e69SJohn Levon# the directories we may have created so far.
11625ca82e69SJohn Levonnewdirlist=
11635ca82e69SJohn Levon
11645ca82e69SJohn Levon#
11655ca82e69SJohn Levon# Create mail_msg_file
11665ca82e69SJohn Levon#
11675ca82e69SJohn Levonmail_msg_file="${TMPDIR}/mail_msg"
11685ca82e69SJohn Levontouch $mail_msg_file
11695ca82e69SJohn Levonbuild_time_file="${TMPDIR}/build_time"
11705ca82e69SJohn Levonbuild_environ_file="${TMPDIR}/build_environ"
11715ca82e69SJohn Levontouch $build_environ_file
11725ca82e69SJohn Levon#
11735ca82e69SJohn Levon#	Move old LOGFILE aside
11745ca82e69SJohn Levon#	ATLOG directory already made by 'create_lock' above
11755ca82e69SJohn Levon#
11765ca82e69SJohn Levonif [ -f $LOGFILE ]; then
11775ca82e69SJohn Levon	mv -f $LOGFILE ${LOGFILE}-
11785ca82e69SJohn Levonfi
11795ca82e69SJohn Levon#
11805ca82e69SJohn Levon#	Build OsNet source
11815ca82e69SJohn Levon#
11825ca82e69SJohn LevonSTART_DATE=`date`
11835ca82e69SJohn LevonSECONDS=0
11845ca82e69SJohn Levonecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
11855ca82e69SJohn Levon    | tee -a $LOGFILE > $build_time_file
11865ca82e69SJohn Levon
11875ca82e69SJohn Levonecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
11885ca82e69SJohn Levon    tee -a $mail_msg_file >> $LOGFILE
11895ca82e69SJohn Levon
11905ca82e69SJohn Levon# make sure we log only to the nightly build file
11915ca82e69SJohn Levonbuild_noise_file="${TMPDIR}/build_noise"
11925ca82e69SJohn Levonexec </dev/null >$build_noise_file 2>&1
11935ca82e69SJohn Levon
11945ca82e69SJohn Levonrun_hook SYS_PRE_NIGHTLY
11955ca82e69SJohn Levonrun_hook PRE_NIGHTLY
11965ca82e69SJohn Levon
11975ca82e69SJohn Levonecho "\n==== list of environment variables ====\n" >> $LOGFILE
11985ca82e69SJohn Levonenv >> $LOGFILE
11995ca82e69SJohn Levon
12005ca82e69SJohn Levonecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
12015ca82e69SJohn Levon
12025ca82e69SJohn Levonif [ "$N_FLAG" = "y" ]; then
12035ca82e69SJohn Levon	if [ "$p_FLAG" = "y" ]; then
12045ca82e69SJohn Levon		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
12055ca82e69SJohn LevonWARNING: the p option (create packages) is set, but so is the N option (do
12065ca82e69SJohn Levon         not run protocmp); this is dangerous; you should unset the N option
12075ca82e69SJohn LevonEOF
12085ca82e69SJohn Levon	else
12095ca82e69SJohn Levon		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
12105ca82e69SJohn LevonWarning: the N option (do not run protocmp) is set; it probably shouldn't be
12115ca82e69SJohn LevonEOF
12125ca82e69SJohn Levon	fi
12135ca82e69SJohn Levon	echo "" | tee -a $mail_msg_file >> $LOGFILE
12145ca82e69SJohn Levonfi
12155ca82e69SJohn Levon
12165ca82e69SJohn Levonif [ "$f_FLAG" = "y" ]; then
12175ca82e69SJohn Levon	if [ "$i_FLAG" = "y" ]; then
12185ca82e69SJohn Levon		echo "WARNING: the -f flag cannot be used during incremental" \
12195ca82e69SJohn Levon		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
12205ca82e69SJohn Levon		f_FLAG=n
12215ca82e69SJohn Levon	fi
12225ca82e69SJohn Levon	if [ "${p_FLAG}" != "y" ]; then
12235ca82e69SJohn Levon		echo "WARNING: the -f flag requires -p;" \
12245ca82e69SJohn Levon		    "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
12255ca82e69SJohn Levon		f_FLAG=n
12265ca82e69SJohn Levon	fi
12275ca82e69SJohn Levonfi
12285ca82e69SJohn Levon
12295ca82e69SJohn Levonif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
12305ca82e69SJohn Levon	echo "WARNING: -w specified, but $ROOT does not exist;" \
12315ca82e69SJohn Levon	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
12325ca82e69SJohn Levon	w_FLAG=n
12335ca82e69SJohn Levonfi
12345ca82e69SJohn Levon
12355ca82e69SJohn Levoncase $MULTI_PROTO in
12365ca82e69SJohn Levonyes|no)	;;
12375ca82e69SJohn Levon*)
12385ca82e69SJohn Levon	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
12395ca82e69SJohn Levon	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
12405ca82e69SJohn Levon	echo "Setting MULTI_PROTO to \"no\".\n" | \
12415ca82e69SJohn Levon	    tee -a $mail_msg_file >> $LOGFILE
12425ca82e69SJohn Levon	export MULTI_PROTO=no
12435ca82e69SJohn Levon	;;
12445ca82e69SJohn Levonesac
12455ca82e69SJohn Levon
12465ca82e69SJohn Levonecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
12475ca82e69SJohn Levonecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
12485ca82e69SJohn Levon
12495ca82e69SJohn Levon# Save the current proto area if we're comparing against the last build
12505ca82e69SJohn Levonif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
12515ca82e69SJohn Levon    if [ -d "$ROOT.prev" ]; then
12525ca82e69SJohn Levon	rm -rf $ROOT.prev
12535ca82e69SJohn Levon    fi
12545ca82e69SJohn Levon    mv $ROOT $ROOT.prev
12555ca82e69SJohn Levonfi
12565ca82e69SJohn Levon
12575ca82e69SJohn Levon# Same for non-DEBUG proto area
12585ca82e69SJohn Levonif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
12595ca82e69SJohn Levon	if [ -d "$ROOT-nd.prev" ]; then
12605ca82e69SJohn Levon		rm -rf $ROOT-nd.prev
12615ca82e69SJohn Levon	fi
12625ca82e69SJohn Levon	mv $ROOT-nd $ROOT-nd.prev
12635ca82e69SJohn Levonfi
12645ca82e69SJohn Levon
12655ca82e69SJohn Levon#
12665ca82e69SJohn Levon# Echo the SCM type of the parent workspace, this can't just be which_scm
12675ca82e69SJohn Levon# as that does not know how to identify various network repositories.
12685ca82e69SJohn Levon#
12695ca82e69SJohn Levonfunction parent_wstype {
12705ca82e69SJohn Levon	typeset scm_type junk
12715ca82e69SJohn Levon
12725ca82e69SJohn Levon	CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
12735ca82e69SJohn Levon	    | read scm_type junk
12745ca82e69SJohn Levon	if [[ -z "$scm_type" || "$scm_type" == unknown ]]; then
12755ca82e69SJohn Levon		# Probe BRINGOVER_WS to determine its type
12765ca82e69SJohn Levon		if [[ $BRINGOVER_WS == ssh://* ]]; then
12775ca82e69SJohn Levon			scm_type="mercurial"
12785ca82e69SJohn Levon		elif [[ $BRINGOVER_WS == http://* ]] && \
12795ca82e69SJohn Levon		    wget -q -O- --save-headers "$BRINGOVER_WS/?cmd=heads" | \
12805ca82e69SJohn Levon		    egrep -s "application/mercurial" 2> /dev/null; then
12815ca82e69SJohn Levon			scm_type="mercurial"
12825ca82e69SJohn Levon		else
12835ca82e69SJohn Levon			scm_type="none"
12845ca82e69SJohn Levon		fi
12855ca82e69SJohn Levon	fi
12865ca82e69SJohn Levon
12875ca82e69SJohn Levon	# fold both unsupported and unrecognized results into "none"
12885ca82e69SJohn Levon	case "$scm_type" in
12895ca82e69SJohn Levon	mercurial)
12905ca82e69SJohn Levon		;;
12915ca82e69SJohn Levon	*)	scm_type=none
12925ca82e69SJohn Levon		;;
12935ca82e69SJohn Levon	esac
12945ca82e69SJohn Levon
12955ca82e69SJohn Levon	echo $scm_type
12965ca82e69SJohn Levon}
12975ca82e69SJohn Levon
12985ca82e69SJohn Levon# Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
12995ca82e69SJohn Levonfunction child_wstype {
13005ca82e69SJohn Levon	typeset scm_type junk
13015ca82e69SJohn Levon
13025ca82e69SJohn Levon	# Probe CODEMGR_WS to determine its type
13035ca82e69SJohn Levon	if [[ -d $CODEMGR_WS ]]; then
13045ca82e69SJohn Levon		$WHICH_SCM | read scm_type junk || exit 1
13055ca82e69SJohn Levon	fi
13065ca82e69SJohn Levon
13075ca82e69SJohn Levon	case "$scm_type" in
13085ca82e69SJohn Levon	none|git|mercurial)
13095ca82e69SJohn Levon		;;
13105ca82e69SJohn Levon	*)	scm_type=none
13115ca82e69SJohn Levon		;;
13125ca82e69SJohn Levon	esac
13135ca82e69SJohn Levon
13145ca82e69SJohn Levon	echo $scm_type
13155ca82e69SJohn Levon}
13165ca82e69SJohn Levon
13175ca82e69SJohn LevonSCM_TYPE=$(child_wstype)
13185ca82e69SJohn Levon
13195ca82e69SJohn Levon#
13205ca82e69SJohn Levon#	Decide whether to clobber
13215ca82e69SJohn Levon#
13225ca82e69SJohn Levonif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
13235ca82e69SJohn Levon	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
13245ca82e69SJohn Levon
13255ca82e69SJohn Levon	cd $SRC
13265ca82e69SJohn Levon	# remove old clobber file
13275ca82e69SJohn Levon	rm -f $SRC/clobber.out
13285ca82e69SJohn Levon	rm -f $SRC/clobber-${MACH}.out
13295ca82e69SJohn Levon
13305ca82e69SJohn Levon	# Remove all .make.state* files, just in case we are restarting
13315ca82e69SJohn Levon	# the build after having interrupted a previous 'make clobber'.
13325ca82e69SJohn Levon	find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
13335ca82e69SJohn Levon		-o -name 'interfaces.*' \) -prune \
13345ca82e69SJohn Levon		-o -name '.make.*' -print | xargs rm -f
13355ca82e69SJohn Levon
13365ca82e69SJohn Levon	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
13375ca82e69SJohn Levon	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
13385ca82e69SJohn Levon	grep "$MAKE:" $SRC/clobber-${MACH}.out |
1339eefeb0ceSBill Sommerfeld		egrep -v ": (Entering|Leaving) directory " | \
13405ca82e69SJohn Levon		egrep -v "Ignoring unknown host" | \
13415ca82e69SJohn Levon		tee $TMPDIR/clobber_errs >> $mail_msg_file
13425ca82e69SJohn Levon
13435ca82e69SJohn Levon	if [[ -s $TMPDIR/clobber_errs ]]; then
13445ca82e69SJohn Levon		build_extras_ok=n
13455ca82e69SJohn Levon	fi
13465ca82e69SJohn Levon
134726e7d9a8SRichard Lowe	if [[ "$t_FLAG" == "y" ]]; then
13485ca82e69SJohn Levon		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
13495ca82e69SJohn Levon		cd ${TOOLS}
13505ca82e69SJohn Levon		rm -f ${TOOLS}/clobber-${MACH}.out
13515ca82e69SJohn Levon		$MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \
13525ca82e69SJohn Levon			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
13535ca82e69SJohn Levon		echo "\n==== Make tools clobber ERRORS ====\n" \
13545ca82e69SJohn Levon			>> $mail_msg_file
13555ca82e69SJohn Levon		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
1356eefeb0ceSBill Sommerfeld			| egrep -v ": (Entering|Leaving) directory " \
13575ca82e69SJohn Levon			>> $mail_msg_file
13585ca82e69SJohn Levon		if (( $? == 0 )); then
13595ca82e69SJohn Levon			build_extras_ok=n
13605ca82e69SJohn Levon		fi
13615ca82e69SJohn Levon		rm -rf ${TOOLS_PROTO}
13625ca82e69SJohn Levon		mkdir -p ${TOOLS_PROTO}
13635ca82e69SJohn Levon	fi
13645ca82e69SJohn Levon
13655ca82e69SJohn Levon	typeset roots=$(allprotos)
13665ca82e69SJohn Levon	echo "\n\nClearing $roots" >> "$LOGFILE"
13675ca82e69SJohn Levon	rm -rf $roots
13685ca82e69SJohn Levon
13695ca82e69SJohn Levon	# Get back to a clean workspace as much as possible to catch
13705ca82e69SJohn Levon	# problems that only occur on fresh workspaces.
13715ca82e69SJohn Levon	# Remove all .make.state* files, libraries, and .o's that may
13725ca82e69SJohn Levon	# have been omitted from clobber.  A couple of libraries are
13735ca82e69SJohn Levon	# under source code control, so leave them alone.
13745ca82e69SJohn Levon	# We should probably blow away temporary directories too.
13755ca82e69SJohn Levon	cd $SRC
13765ca82e69SJohn Levon	find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
13775ca82e69SJohn Levon	    -o -name .git -o -name 'interfaces.*' \) -prune -o \
13785ca82e69SJohn Levon	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
13795ca82e69SJohn Levon	       -name '*.o' \) -print | \
13805ca82e69SJohn Levon	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
13815ca82e69SJohn Levonelse
13825ca82e69SJohn Levon	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
13835ca82e69SJohn Levonfi
13845ca82e69SJohn Levon
13855ca82e69SJohn Levontype bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
13865ca82e69SJohn Levon	typeset -x PATH=$PATH
13875ca82e69SJohn Levon
13885ca82e69SJohn Levon	# If the repository doesn't exist yet, then we want to populate it.
13895ca82e69SJohn Levon	if [[ ! -d $CODEMGR_WS/.hg ]]; then
13905ca82e69SJohn Levon		staffer hg init $CODEMGR_WS
13915ca82e69SJohn Levon		staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
13925ca82e69SJohn Levon		staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
13935ca82e69SJohn Levon		touch $TMPDIR/new_repository
13945ca82e69SJohn Levon	fi
13955ca82e69SJohn Levon
13965ca82e69SJohn Levon	typeset -x HGMERGE="/bin/false"
13975ca82e69SJohn Levon
13985ca82e69SJohn Levon	#
13995ca82e69SJohn Levon	# If the user has changes, regardless of whether those changes are
14005ca82e69SJohn Levon	# committed, and regardless of whether those changes conflict, then
14015ca82e69SJohn Levon	# we'll attempt to merge them either implicitly (uncommitted) or
14025ca82e69SJohn Levon	# explicitly (committed).
14035ca82e69SJohn Levon	#
14045ca82e69SJohn Levon	# These are the messages we'll use to help clarify mercurial output
14055ca82e69SJohn Levon	# in those cases.
14065ca82e69SJohn Levon	#
14075ca82e69SJohn Levon	typeset mergefailmsg="\
14085ca82e69SJohn Levon***\n\
14095ca82e69SJohn Levon*** nightly was unable to automatically merge your changes.  You should\n\
14105ca82e69SJohn Levon*** redo the full merge manually, following the steps outlined by mercurial\n\
14115ca82e69SJohn Levon*** above, then restart nightly.\n\
14125ca82e69SJohn Levon***\n"
14135ca82e69SJohn Levon	typeset mergepassmsg="\
14145ca82e69SJohn Levon***\n\
14155ca82e69SJohn Levon*** nightly successfully merged your changes.  This means that your working\n\
14165ca82e69SJohn Levon*** directory has been updated, but those changes are not yet committed.\n\
14175ca82e69SJohn Levon*** After nightly completes, you should validate the results of the merge,\n\
14185ca82e69SJohn Levon*** then use hg commit manually.\n\
14195ca82e69SJohn Levon***\n"
14205ca82e69SJohn Levon
14215ca82e69SJohn Levon	#
14225ca82e69SJohn Levon	# For each repository in turn:
14235ca82e69SJohn Levon	#
14245ca82e69SJohn Levon	# 1. Do the pull.  If this fails, dump the output and bail out.
14255ca82e69SJohn Levon	#
14265ca82e69SJohn Levon	# 2. If the pull resulted in an extra head, do an explicit merge.
14275ca82e69SJohn Levon	#    If this fails, dump the output and bail out.
14285ca82e69SJohn Levon	#
14295ca82e69SJohn Levon	# Because we can't rely on Mercurial to exit with a failure code
14305ca82e69SJohn Levon	# when a merge fails (Mercurial issue #186), we must grep the
14315ca82e69SJohn Levon	# output of pull/merge to check for attempted and/or failed merges.
14325ca82e69SJohn Levon	#
14335ca82e69SJohn Levon	# 3. If a merge failed, set the message and fail the bringover.
14345ca82e69SJohn Levon	#
14355ca82e69SJohn Levon	# 4. Otherwise, if a merge succeeded, set the message
14365ca82e69SJohn Levon	#
14375ca82e69SJohn Levon	# 5. Dump the output, and any message from step 3 or 4.
14385ca82e69SJohn Levon	#
14395ca82e69SJohn Levon
14405ca82e69SJohn Levon	typeset HG_SOURCE=$BRINGOVER_WS
14415ca82e69SJohn Levon	if [ ! -f $TMPDIR/new_repository ]; then
14425ca82e69SJohn Levon		HG_SOURCE=$TMPDIR/open_bundle.hg
14435ca82e69SJohn Levon		staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
14445ca82e69SJohn Levon		    -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
14455ca82e69SJohn Levon
14465ca82e69SJohn Levon		#
14475ca82e69SJohn Levon		# If there are no incoming changesets, then incoming will
14485ca82e69SJohn Levon		# fail, and there will be no bundle file.  Reset the source,
14495ca82e69SJohn Levon		# to allow the remaining logic to complete with no false
14505ca82e69SJohn Levon		# negatives.  (Unlike incoming, pull will return success
14515ca82e69SJohn Levon		# for the no-change case.)
14525ca82e69SJohn Levon		#
14535ca82e69SJohn Levon		if (( $? != 0 )); then
14545ca82e69SJohn Levon			HG_SOURCE=$BRINGOVER_WS
14555ca82e69SJohn Levon		fi
14565ca82e69SJohn Levon	fi
14575ca82e69SJohn Levon
14585ca82e69SJohn Levon	staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
14595ca82e69SJohn Levon	    > $TMPDIR/pull_open.out 2>&1
14605ca82e69SJohn Levon	if (( $? != 0 )); then
14615ca82e69SJohn Levon		printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
14625ca82e69SJohn Levon		cat $TMPDIR/pull_open.out
14635ca82e69SJohn Levon		if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
14645ca82e69SJohn Levon			printf "$mergefailmsg"
14655ca82e69SJohn Levon		fi
14665ca82e69SJohn Levon		touch $TMPDIR/bringover_failed
14675ca82e69SJohn Levon		return
14685ca82e69SJohn Levon	fi
14695ca82e69SJohn Levon
14705ca82e69SJohn Levon	if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
14715ca82e69SJohn Levon		staffer hg --cwd $CODEMGR_WS merge \
14725ca82e69SJohn Levon		    >> $TMPDIR/pull_open.out 2>&1
14735ca82e69SJohn Levon		if (( $? != 0 )); then
14745ca82e69SJohn Levon			printf "%s: merge failed as follows:\n\n" \
14755ca82e69SJohn Levon			    "$CODEMGR_WS"
14765ca82e69SJohn Levon			cat $TMPDIR/pull_open.out
14775ca82e69SJohn Levon			if grep "^merging.*failed" $TMPDIR/pull_open.out \
14785ca82e69SJohn Levon			    > /dev/null 2>&1; then
14795ca82e69SJohn Levon				printf "$mergefailmsg"
14805ca82e69SJohn Levon			fi
14815ca82e69SJohn Levon			touch $TMPDIR/bringover_failed
14825ca82e69SJohn Levon			return
14835ca82e69SJohn Levon		fi
14845ca82e69SJohn Levon	fi
14855ca82e69SJohn Levon
14865ca82e69SJohn Levon	printf "updated %s with the following results:\n" "$CODEMGR_WS"
14875ca82e69SJohn Levon	cat $TMPDIR/pull_open.out
14885ca82e69SJohn Levon	if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
14895ca82e69SJohn Levon		printf "$mergepassmsg"
14905ca82e69SJohn Levon	fi
14915ca82e69SJohn Levon	printf "\n"
14925ca82e69SJohn Levon
14935ca82e69SJohn Levon	#
14945ca82e69SJohn Levon	# Per-changeset output is neither useful nor manageable for a
14955ca82e69SJohn Levon	# newly-created repository.
14965ca82e69SJohn Levon	#
14975ca82e69SJohn Levon	if [ -f $TMPDIR/new_repository ]; then
14985ca82e69SJohn Levon		return
14995ca82e69SJohn Levon	fi
15005ca82e69SJohn Levon
15015ca82e69SJohn Levon	printf "\nadded the following changesets to open repository:\n"
15025ca82e69SJohn Levon	cat $TMPDIR/incoming_open.out
15035ca82e69SJohn Levon}
15045ca82e69SJohn Levon
15055ca82e69SJohn Levontype bringover_none > /dev/null 2>&1 || function bringover_none {
15065ca82e69SJohn Levon	echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
15075ca82e69SJohn Levon	touch $TMPDIR/bringover_failed
15085ca82e69SJohn Levon}
15095ca82e69SJohn Levon
15105ca82e69SJohn Levon#
15115ca82e69SJohn Levon#	Decide whether to bringover to the codemgr workspace
15125ca82e69SJohn Levon#
15135ca82e69SJohn Levonif [ "$n_FLAG" = "n" ]; then
15145ca82e69SJohn Levon	PARENT_SCM_TYPE=$(parent_wstype)
15155ca82e69SJohn Levon
15165ca82e69SJohn Levon	if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
15175ca82e69SJohn Levon		echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
15185ca82e69SJohn Levon		    "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
15195ca82e69SJohn Levon		exit 1
15205ca82e69SJohn Levon	fi
15215ca82e69SJohn Levon
15225ca82e69SJohn Levon	run_hook PRE_BRINGOVER
15235ca82e69SJohn Levon
15245ca82e69SJohn Levon	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
15255ca82e69SJohn Levon	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
15265ca82e69SJohn Levon
15275ca82e69SJohn Levon	eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
15285ca82e69SJohn Levon		tee -a $mail_msg_file >> $LOGFILE
15295ca82e69SJohn Levon
15305ca82e69SJohn Levon	if [ -f $TMPDIR/bringover_failed ]; then
15315ca82e69SJohn Levon		rm -f $TMPDIR/bringover_failed
15325ca82e69SJohn Levon		build_ok=n
15335ca82e69SJohn Levon		echo "trouble with bringover, quitting at `date`." |
15345ca82e69SJohn Levon			tee -a $mail_msg_file >> $LOGFILE
15355ca82e69SJohn Levon		exit 1
15365ca82e69SJohn Levon	fi
15375ca82e69SJohn Levon
15385ca82e69SJohn Levon	#
15395ca82e69SJohn Levon	# It's possible that we used the bringover above to create
15405ca82e69SJohn Levon	# $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
15415ca82e69SJohn Levon	# but should now be the same as $BRINGOVER_WS.
15425ca82e69SJohn Levon	#
154326e7d9a8SRichard Lowe	[[ $SCM_TYPE == none ]] && SCM_TYPE=$PARENT_SCM_TYPE
15445ca82e69SJohn Levon
15455ca82e69SJohn Levon	run_hook POST_BRINGOVER
15465ca82e69SJohn Levon
15475ca82e69SJohn Levon	check_closed_bins
15485ca82e69SJohn Levon
15495ca82e69SJohn Levonelse
15505ca82e69SJohn Levon	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
15515ca82e69SJohn Levonfi
15525ca82e69SJohn Levon
15535ca82e69SJohn Levon# Safeguards
15545ca82e69SJohn Levon[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
15555ca82e69SJohn Levon[[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory."
15565ca82e69SJohn Levon[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
15575ca82e69SJohn Levon
155826e7d9a8SRichard Loweif [[ "$t_FLAG" == "y" ]]; then
15595ca82e69SJohn Levon	set_non_debug_build_flags
15605ca82e69SJohn Levon	# Switch ONBLD_TOOLS early if -t is specified so that
15615ca82e69SJohn Levon	# we could use bootstrapped cw for compiler checks.
15625ca82e69SJohn Levon	ONBLD_TOOLS=${TOOLS_PROTO}/opt/onbld
15635ca82e69SJohn Levon	export ONBLD_TOOLS
15643c6ef809SYuri Pankov
15653c6ef809SYuri Pankov	bootstrap_tools || fatal_error "Error: could not bootstrap tools"
15665ca82e69SJohn Levonfi
15675ca82e69SJohn Levon
15685ca82e69SJohn Levonecho "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
15695ca82e69SJohn Levon
15705ca82e69SJohn Levon# System
15715ca82e69SJohn Levonwhence uname | tee -a $build_environ_file >> $LOGFILE
15725ca82e69SJohn Levonuname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
15735ca82e69SJohn Levonecho | tee -a $build_environ_file >> $LOGFILE
15745ca82e69SJohn Levon
15755ca82e69SJohn Levon# make
15765ca82e69SJohn Levonwhence $MAKE | tee -a $build_environ_file >> $LOGFILE
15775ca82e69SJohn Levon$MAKE -v | tee -a $build_environ_file >> $LOGFILE
15785ca82e69SJohn Levonecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
15795ca82e69SJohn Levon    tee -a $build_environ_file >> $LOGFILE
15805ca82e69SJohn Levon
15815ca82e69SJohn Levon#
15825ca82e69SJohn Levon# Report the compiler versions.
15835ca82e69SJohn Levon#
15845ca82e69SJohn Levon
15855ca82e69SJohn Levonif [[ ! -f $SRC/Makefile ]]; then
15865ca82e69SJohn Levon	build_ok=n
15875ca82e69SJohn Levon	echo "\nUnable to find \"Makefile\" in $SRC." | \
15885ca82e69SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
15895ca82e69SJohn Levon	exit 1
15905ca82e69SJohn Levonfi
15915ca82e69SJohn Levon
15925ca82e69SJohn Levon( cd $SRC
15935ca82e69SJohn Levon  for target in cc-version java-version openssl-version; do
15945ca82e69SJohn Levon	echo
15955ca82e69SJohn Levon	#
15965ca82e69SJohn Levon	# Put statefile somewhere we know we can write to rather than trip
15975ca82e69SJohn Levon	# over a read-only $srcroot.
15985ca82e69SJohn Levon	#
15995ca82e69SJohn Levon	rm -f $TMPDIR/make-state
16005ca82e69SJohn Levon	export SRC
16015ca82e69SJohn Levon	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
16025ca82e69SJohn Levon		continue
16035ca82e69SJohn Levon	fi
16045ca82e69SJohn Levon	touch $TMPDIR/nocompiler
16055ca82e69SJohn Levon  done
16065ca82e69SJohn Levon  echo
1607eefeb0ceSBill Sommerfeld) | egrep -v "${MAKE}: (Entering|Leaving) directory " \
1608eefeb0ceSBill Sommerfeld    | tee -a $build_environ_file >> $LOGFILE
16095ca82e69SJohn Levon
16105ca82e69SJohn Levonif [ -f $TMPDIR/nocompiler ]; then
16115ca82e69SJohn Levon	rm -f $TMPDIR/nocompiler
16125ca82e69SJohn Levon	build_ok=n
16135ca82e69SJohn Levon	echo "Aborting due to missing compiler." |
16145ca82e69SJohn Levon		tee -a $build_environ_file >> $LOGFILE
16155ca82e69SJohn Levon	exit 1
16165ca82e69SJohn Levonfi
16175ca82e69SJohn Levon
16185ca82e69SJohn Levon# Check that we're running a capable link-editor
16195ca82e69SJohn Levonwhence ld | tee -a $build_environ_file >> $LOGFILE
16205ca82e69SJohn LevonLDVER=`ld -V 2>&1`
16215ca82e69SJohn Levonecho $LDVER | tee -a $build_environ_file >> $LOGFILE
16225ca82e69SJohn LevonLDVER=`echo $LDVER | sed -e "s/.*-1\.\([0-9]*\).*/\1/"`
16235ca82e69SJohn Levonif [ `expr $LDVER \< 422` -eq 1 ]; then
16245ca82e69SJohn Levon	echo "The link-editor needs to be at version 422 or higher to build" | \
16255ca82e69SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
16265ca82e69SJohn Levon	echo "the latest stuff.  Hope your build works." | \
16275ca82e69SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
16285ca82e69SJohn Levonfi
16295ca82e69SJohn Levon
16305ca82e69SJohn Levon#
16315ca82e69SJohn Levon# Build and use the workspace's tools if requested
16325ca82e69SJohn Levon#
163326e7d9a8SRichard Loweif [[ "$t_FLAG" == "y" ]]; then
16345ca82e69SJohn Levon	set_non_debug_build_flags
16355ca82e69SJohn Levon
16365ca82e69SJohn Levon	build_tools ${TOOLS_PROTO}
16375ca82e69SJohn Levon	if (( $? != 0 )); then
16385ca82e69SJohn Levon		build_ok=n
16396faa6645SYuri Pankov		exit 1
16406faa6645SYuri Pankov	fi
16416faa6645SYuri Pankov
16425ca82e69SJohn Levon	STABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs
16435ca82e69SJohn Levon	export STABS
16445ca82e69SJohn Levon	CTFSTABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs
16455ca82e69SJohn Levon	export CTFSTABS
16465ca82e69SJohn Levon	GENOFFSETS=${TOOLS_PROTO}/opt/onbld/bin/genoffsets
16475ca82e69SJohn Levon	export GENOFFSETS
16485ca82e69SJohn Levon
16495ca82e69SJohn Levon	CTFCONVERT=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert
16505ca82e69SJohn Levon	export CTFCONVERT
16515ca82e69SJohn Levon	CTFMERGE=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge
16525ca82e69SJohn Levon	export CTFMERGE
16535ca82e69SJohn Levon
16545ca82e69SJohn Levon	PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
16555ca82e69SJohn Levon	PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
16565ca82e69SJohn Levon	export PATH
16575ca82e69SJohn Levon
16585ca82e69SJohn Levon	echo "\n==== New environment settings. ====\n" >> $LOGFILE
16595ca82e69SJohn Levon	echo "STABS=${STABS}" >> $LOGFILE
16605ca82e69SJohn Levon	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
16615ca82e69SJohn Levon	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
16625ca82e69SJohn Levon	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
16635ca82e69SJohn Levon	echo "PATH=${PATH}" >> $LOGFILE
16645ca82e69SJohn Levon	echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE
16655ca82e69SJohn Levonfi
16665ca82e69SJohn Levon
16675ca82e69SJohn Levon# timestamp the start of the normal build; the findunref tool uses it.
16685ca82e69SJohn Levontouch $SRC/.build.tstamp
16695ca82e69SJohn Levon
16705ca82e69SJohn Levonnormal_build
16715ca82e69SJohn Levon
16725ca82e69SJohn LevonORIG_SRC=$SRC
16735ca82e69SJohn LevonBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
16745ca82e69SJohn Levon
167526e7d9a8SRichard Loweabspkg=
167626e7d9a8SRichard Lowefor d in $abssrcdirs; do
167726e7d9a8SRichard Lowe	if [ -d "$d/pkg" ]; then
167826e7d9a8SRichard Lowe		abspkg="$abspkg $d"
167926e7d9a8SRichard Lowe	fi
168026e7d9a8SRichard Lowedone
168126e7d9a8SRichard Lowe
168226e7d9a8SRichard Loweif [ "$L_FLAG" != "y" -a "$build_ok" = y ]; then
168326e7d9a8SRichard Lowe	echo "\n==== Linting packages ====\n" | \
168426e7d9a8SRichard Lowe	    tee -a $LOGFILE >> $mail_msg_file
168526e7d9a8SRichard Lowe
168626e7d9a8SRichard Lowe	if [ -n "$abspkg" ]; then
168726e7d9a8SRichard Lowe		for d in "$abspkg"; do
168826e7d9a8SRichard Lowe			( cd $d/pkg ; $MAKE -e pkglint ) | \
168926e7d9a8SRichard Lowe			    tee -a $LOGFILE | \
1690eefeb0ceSBill Sommerfeld			    egrep -v ": (Entering|Leaving) directory " | \
169126e7d9a8SRichard Lowe			    egrep -v 'Lint engine setup|Starting lint run'
169226e7d9a8SRichard Lowe		done 2>&1 | tee $TMPDIR/pkglint_noise >> $mail_msg_file
169326e7d9a8SRichard Lowe		if [[ -s $TMPDIR/pkglint_noise ]]; then
169426e7d9a8SRichard Lowe			build_extras_ok=n
169526e7d9a8SRichard Lowe		fi
169626e7d9a8SRichard Lowe	fi
169726e7d9a8SRichard Lowefi
16985ca82e69SJohn Levon
16995ca82e69SJohn Levon#
17005ca82e69SJohn Levon# There are several checks that need to look at the proto area, but
17015ca82e69SJohn Levon# they only need to look at one, and they don't care whether it's
17025ca82e69SJohn Levon# DEBUG or non-DEBUG.
17035ca82e69SJohn Levon#
170426e7d9a8SRichard Loweif [[ "$MULTI_PROTO" == yes && "$D_FLAG" == n ]]; then
17055ca82e69SJohn Levon	checkroot=$ROOT-nd
17065ca82e69SJohn Levonelse
17075ca82e69SJohn Levon	checkroot=$ROOT
17085ca82e69SJohn Levonfi
17095ca82e69SJohn Levon
17105ca82e69SJohn Levonif [ "$build_ok" = "y" ]; then
17115ca82e69SJohn Levon	echo "\n==== Creating protolist system file at `date` ====" \
17125ca82e69SJohn Levon		>> $LOGFILE
17135ca82e69SJohn Levon	protolist $checkroot > $ATLOG/proto_list_${MACH}
17145ca82e69SJohn Levon	echo "==== protolist system file created at `date` ====\n" \
17155ca82e69SJohn Levon		>> $LOGFILE
17165ca82e69SJohn Levon
17175ca82e69SJohn Levon	if [ "$N_FLAG" != "y" ]; then
17185ca82e69SJohn Levon
17195ca82e69SJohn Levon		E1=
17205ca82e69SJohn Levon		f1=
17215ca82e69SJohn Levon		for f in $f1; do
17225ca82e69SJohn Levon			if [ -f "$f" ]; then
17235ca82e69SJohn Levon				E1="$E1 -e $f"
17245ca82e69SJohn Levon			fi
17255ca82e69SJohn Levon		done
17265ca82e69SJohn Levon
17275ca82e69SJohn Levon		E2=
17285ca82e69SJohn Levon		f2=
17295ca82e69SJohn Levon		if [ -d "$SRC/pkg" ]; then
17305ca82e69SJohn Levon			f2="$f2 exceptions/packaging"
17315ca82e69SJohn Levon		fi
17325ca82e69SJohn Levon
17335ca82e69SJohn Levon		for f in $f2; do
17345ca82e69SJohn Levon			if [ -f "$f" ]; then
17355ca82e69SJohn Levon				E2="$E2 -e $f"
17365ca82e69SJohn Levon			fi
17375ca82e69SJohn Levon		done
17385ca82e69SJohn Levon	fi
17395ca82e69SJohn Levon
17405ca82e69SJohn Levon	if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
17415ca82e69SJohn Levon		echo "\n==== Validating manifests against proto area ====\n" \
17425ca82e69SJohn Levon		    >> $mail_msg_file
17435ca82e69SJohn Levon		( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) | \
1744eefeb0ceSBill Sommerfeld		    egrep -v ": (Entering|Leaving) directory " | \
17455ca82e69SJohn Levon		    tee $TMPDIR/protocmp_noise >> $mail_msg_file
17465ca82e69SJohn Levon		if [[ -s $TMPDIR/protocmp_noise ]]; then
17475ca82e69SJohn Levon			build_extras_ok=n
17485ca82e69SJohn Levon		fi
17495ca82e69SJohn Levon	fi
17505ca82e69SJohn Levon
17515ca82e69SJohn Levon	if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then
17525ca82e69SJohn Levon		echo "\n==== Impact on proto area ====\n" >> $mail_msg_file
17535ca82e69SJohn Levon		if [ -n "$E2" ]; then
17545ca82e69SJohn Levon			ELIST=$E2
17555ca82e69SJohn Levon		else
17565ca82e69SJohn Levon			ELIST=$E1
17575ca82e69SJohn Levon		fi
17585ca82e69SJohn Levon		$PROTOCMPTERSE \
17595ca82e69SJohn Levon			"Files in yesterday's proto area, but not today's:" \
17605ca82e69SJohn Levon			"Files in today's proto area, but not yesterday's:" \
17615ca82e69SJohn Levon			"Files that changed between yesterday and today:" \
17625ca82e69SJohn Levon			${ELIST} \
17635ca82e69SJohn Levon			-d $REF_PROTO_LIST \
17645ca82e69SJohn Levon			$ATLOG/proto_list_${MACH} \
17655ca82e69SJohn Levon			>> $mail_msg_file
17665ca82e69SJohn Levon	fi
17675ca82e69SJohn Levonfi
17685ca82e69SJohn Levon
17695ca82e69SJohn Levonif [[ "$u_FLAG" == "y" && "$build_ok" == "y" && \
17705ca82e69SJohn Levon    "$build_extras_ok" == "y" ]]; then
17715ca82e69SJohn Levon	staffer cp $ATLOG/proto_list_${MACH} \
17725ca82e69SJohn Levon		$PARENT_WS/usr/src/proto_list_${MACH}
17735ca82e69SJohn Levonfi
17745ca82e69SJohn Levon
17755ca82e69SJohn Levon# Update parent proto area if necessary. This is done now
17765ca82e69SJohn Levon# so that the proto area has either DEBUG or non-DEBUG kernels.
17775ca82e69SJohn Levon# Note that this clears out the lock file, so we can dispense with
17785ca82e69SJohn Levon# the variable now.
17795ca82e69SJohn Levonif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
17805ca82e69SJohn Levon	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
17815ca82e69SJohn Levon	    tee -a $LOGFILE >> $mail_msg_file
17825ca82e69SJohn Levon	rm -rf $NIGHTLY_PARENT_ROOT/*
17835ca82e69SJohn Levon	unset Ulockfile
17845ca82e69SJohn Levon	mkdir -p $NIGHTLY_PARENT_ROOT
178526e7d9a8SRichard Lowe	if [[ "$MULTI_PROTO" == no || "$D_FLAG" == y ]]; then
17865ca82e69SJohn Levon		( cd $ROOT; tar cf - . |
17875ca82e69SJohn Levon		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
17885ca82e69SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
17895ca82e69SJohn Levon	fi
179026e7d9a8SRichard Lowe	if [[ "$MULTI_PROTO" == yes && "$F_FLAG" == n ]]; then
17915ca82e69SJohn Levon		rm -rf $NIGHTLY_PARENT_ROOT-nd/*
17925ca82e69SJohn Levon		mkdir -p $NIGHTLY_PARENT_ROOT-nd
17935ca82e69SJohn Levon		cd $ROOT-nd
17945ca82e69SJohn Levon		( tar cf - . |
17955ca82e69SJohn Levon		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
17965ca82e69SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
17975ca82e69SJohn Levon	fi
17985ca82e69SJohn Levon	if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then
17995ca82e69SJohn Levon		echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \
18005ca82e69SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
18015ca82e69SJohn Levon		rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/*
18025ca82e69SJohn Levon		mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT
180326e7d9a8SRichard Lowe		if [[ "$MULTI_PROTO" == no || "$D_FLAG" == y ]]; then
18045ca82e69SJohn Levon			( cd $TOOLS_PROTO; tar cf - . |
18055ca82e69SJohn Levon			    ( cd $NIGHTLY_PARENT_TOOLS_ROOT;
18065ca82e69SJohn Levon			    umask 0; tar xpf - ) ) 2>&1 |
18075ca82e69SJohn Levon			    tee -a $mail_msg_file >> $LOGFILE
18085ca82e69SJohn Levon		fi
18095ca82e69SJohn Levon	fi
18105ca82e69SJohn Levonfi
18115ca82e69SJohn Levon
18125ca82e69SJohn Levon#
18135ca82e69SJohn Levon# ELF verification: ABI (-A) and runtime (-r) checks
18145ca82e69SJohn Levon#
181526e7d9a8SRichard Loweif [[ ($build_ok == y) && (($A_FLAG == y) || ($r_FLAG == y)) ]]; then
18165ca82e69SJohn Levon	# Directory ELF-data.$MACH holds the files produced by these tests.
18175ca82e69SJohn Levon	elf_ddir=$SRC/ELF-data.$MACH
18185ca82e69SJohn Levon
18195ca82e69SJohn Levon	# If there is a previous ELF-data backup directory, remove it. Then,
18205ca82e69SJohn Levon	# rotate current ELF-data directory into its place and create a new
18215ca82e69SJohn Levon	# empty directory
18225ca82e69SJohn Levon	rm -rf $elf_ddir.ref
18235ca82e69SJohn Levon	if [[ -d $elf_ddir ]]; then
18245ca82e69SJohn Levon		mv $elf_ddir $elf_ddir.ref
18255ca82e69SJohn Levon	fi
18265ca82e69SJohn Levon	mkdir -p $elf_ddir
18275ca82e69SJohn Levon
18285ca82e69SJohn Levon	# Call find_elf to produce a list of the ELF objects in the proto area.
18295ca82e69SJohn Levon	# This list is passed to check_rtime and interface_check, preventing
18305ca82e69SJohn Levon	# them from separately calling find_elf to do the same work twice.
18315ca82e69SJohn Levon	find_elf -fr $checkroot > $elf_ddir/object_list
18325ca82e69SJohn Levon
183326e7d9a8SRichard Lowe	if [[ $A_FLAG == y ]]; then
18345ca82e69SJohn Levon		echo "\n==== Check versioning and ABI information ====\n"  | \
18355ca82e69SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
18365ca82e69SJohn Levon
18375ca82e69SJohn Levon		# Produce interface description for the proto. Report errors.
18385ca82e69SJohn Levon		interface_check -o -w $elf_ddir -f object_list \
18395ca82e69SJohn Levon			-i interface -E interface.err
18405ca82e69SJohn Levon		if [[ -s $elf_ddir/interface.err ]]; then
18415ca82e69SJohn Levon			tee -a $LOGFILE < $elf_ddir/interface.err \
18425ca82e69SJohn Levon			    >> $mail_msg_file
18435ca82e69SJohn Levon			build_extras_ok=n
18445ca82e69SJohn Levon		fi
18455ca82e69SJohn Levon
18465ca82e69SJohn Levon		# If ELF_DATA_BASELINE_DIR is defined, compare the new interface
18475ca82e69SJohn Levon		# description file to that from the baseline gate. Issue a
18485ca82e69SJohn Levon		# warning if the baseline is not present, and keep going.
18495ca82e69SJohn Levon		if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
18505ca82e69SJohn Levon			base_ifile="$ELF_DATA_BASELINE_DIR/interface"
18515ca82e69SJohn Levon
18525ca82e69SJohn Levon			echo "\n==== Compare versioning and ABI information" \
18535ca82e69SJohn Levon			    "to baseline ====\n"  | \
18545ca82e69SJohn Levon			    tee -a $LOGFILE >> $mail_msg_file
18555ca82e69SJohn Levon			echo "Baseline:	 $base_ifile\n" >> $LOGFILE
18565ca82e69SJohn Levon
18575ca82e69SJohn Levon			if [[ -f $base_ifile ]]; then
18585ca82e69SJohn Levon				interface_cmp -d -o $base_ifile \
18595ca82e69SJohn Levon				    $elf_ddir/interface > $elf_ddir/interface.cmp
18605ca82e69SJohn Levon				if [[ -s $elf_ddir/interface.cmp ]]; then
18615ca82e69SJohn Levon					echo | tee -a $LOGFILE >> $mail_msg_file
18625ca82e69SJohn Levon					tee -a $LOGFILE < \
18635ca82e69SJohn Levon					    $elf_ddir/interface.cmp \
18645ca82e69SJohn Levon					    >> $mail_msg_file
18655ca82e69SJohn Levon					build_extras_ok=n
18665ca82e69SJohn Levon				fi
18675ca82e69SJohn Levon			else
18685ca82e69SJohn Levon				echo "baseline not available. comparison" \
18695ca82e69SJohn Levon                                    "skipped" | \
18705ca82e69SJohn Levon				    tee -a $LOGFILE >> $mail_msg_file
18715ca82e69SJohn Levon			fi
18725ca82e69SJohn Levon
18735ca82e69SJohn Levon		fi
18745ca82e69SJohn Levon	fi
18755ca82e69SJohn Levon
187626e7d9a8SRichard Lowe	if [[ $r_FLAG == y ]]; then
18775ca82e69SJohn Levon		echo "\n==== Check ELF runtime attributes ====\n" | \
18785ca82e69SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
18795ca82e69SJohn Levon
18805ca82e69SJohn Levon		# If we're doing a DEBUG build the proto area will be left
18815ca82e69SJohn Levon		# with debuggable objects, thus don't assert -s.
188226e7d9a8SRichard Lowe		if [[ $D_FLAG == y ]]; then
18835ca82e69SJohn Levon			rtime_sflag=""
18845ca82e69SJohn Levon		else
18855ca82e69SJohn Levon			rtime_sflag="-s"
18865ca82e69SJohn Levon		fi
18875ca82e69SJohn Levon		check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
18885ca82e69SJohn Levon			-D object_list  -f object_list -E runtime.err \
18895ca82e69SJohn Levon			-I runtime.attr.raw
18905ca82e69SJohn Levon		if (( $? != 0 )); then
18915ca82e69SJohn Levon			build_extras_ok=n
18925ca82e69SJohn Levon		fi
18935ca82e69SJohn Levon
18945ca82e69SJohn Levon		# check_rtime -I output needs to be sorted in order to
18955ca82e69SJohn Levon		# compare it to that from previous builds.
18965ca82e69SJohn Levon		sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
18975ca82e69SJohn Levon		rm $elf_ddir/runtime.attr.raw
18985ca82e69SJohn Levon
18995ca82e69SJohn Levon		# Report errors
19005ca82e69SJohn Levon		if [[ -s $elf_ddir/runtime.err ]]; then
19015ca82e69SJohn Levon			tee -a $LOGFILE < $elf_ddir/runtime.err \
19025ca82e69SJohn Levon				>> $mail_msg_file
19035ca82e69SJohn Levon			build_extras_ok=n
19045ca82e69SJohn Levon		fi
19055ca82e69SJohn Levon
19065ca82e69SJohn Levon		# If there is an ELF-data directory from a previous build,
19075ca82e69SJohn Levon		# then diff the attr files. These files contain information
19085ca82e69SJohn Levon		# about dependencies, versioning, and runpaths. There is some
19095ca82e69SJohn Levon		# overlap with the ABI checking done above, but this also
19105ca82e69SJohn Levon		# flushes out non-ABI interface differences along with the
19115ca82e69SJohn Levon		# other information.
19125ca82e69SJohn Levon		echo "\n==== Diff ELF runtime attributes" \
19135ca82e69SJohn Levon		    "(since last build) ====\n" | \
19145ca82e69SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
19155ca82e69SJohn Levon
19165ca82e69SJohn Levon		if [[ -f $elf_ddir.ref/runtime.attr ]]; then
19175ca82e69SJohn Levon			diff $elf_ddir.ref/runtime.attr \
19185ca82e69SJohn Levon				$elf_ddir/runtime.attr \
19195ca82e69SJohn Levon				>> $mail_msg_file
19205ca82e69SJohn Levon		fi
19215ca82e69SJohn Levon	fi
19225ca82e69SJohn Levon
19235ca82e69SJohn Levon	# If -u set, copy contents of ELF-data.$MACH to the parent workspace.
192426e7d9a8SRichard Lowe	if [[ "$u_FLAG" == "y" ]]; then
19255ca82e69SJohn Levon		p_elf_ddir=$PARENT_WS/usr/src/ELF-data.$MACH
19265ca82e69SJohn Levon
19275ca82e69SJohn Levon		# If parent lacks the ELF-data.$MACH directory, create it
19285ca82e69SJohn Levon		if [[ ! -d $p_elf_ddir ]]; then
19295ca82e69SJohn Levon			staffer mkdir -p $p_elf_ddir
19305ca82e69SJohn Levon		fi
19315ca82e69SJohn Levon
19325ca82e69SJohn Levon		# These files are used asynchronously by other builds for ABI
19335ca82e69SJohn Levon		# verification, as above for the -A option. As such, we require
19345ca82e69SJohn Levon		# the file replacement to be atomic. Copy the data to a temp
19355ca82e69SJohn Levon		# file in the same filesystem and then rename into place.
19365ca82e69SJohn Levon		(
19375ca82e69SJohn Levon			cd $elf_ddir
19385ca82e69SJohn Levon			for elf_dfile in *; do
19395ca82e69SJohn Levon				staffer cp $elf_dfile \
19405ca82e69SJohn Levon				    ${p_elf_ddir}/${elf_dfile}.new
19415ca82e69SJohn Levon				staffer mv -f ${p_elf_ddir}/${elf_dfile}.new \
19425ca82e69SJohn Levon				    ${p_elf_ddir}/${elf_dfile}
19435ca82e69SJohn Levon			done
19445ca82e69SJohn Levon		)
19455ca82e69SJohn Levon	fi
19465ca82e69SJohn Levonfi
19475ca82e69SJohn Levon
19485ca82e69SJohn Levon# "make check" begins
19495ca82e69SJohn Levon
19505ca82e69SJohn Levonif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
19515ca82e69SJohn Levon	# remove old check.out
19525ca82e69SJohn Levon	rm -f $SRC/check.out
19535ca82e69SJohn Levon
19545ca82e69SJohn Levon	rm -f $SRC/check-${MACH}.out
19555ca82e69SJohn Levon	cd $SRC
19565ca82e69SJohn Levon	$MAKE -ek check ROOT="$checkroot" 2>&1 | tee -a $SRC/check-${MACH}.out \
19575ca82e69SJohn Levon	    >> $LOGFILE
19585ca82e69SJohn Levon	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
19595ca82e69SJohn Levon
19605ca82e69SJohn Levon	grep ":" $SRC/check-${MACH}.out |
1961eefeb0ceSBill Sommerfeld		egrep -v ": (Entering|Leaving) directory " | \
19625ca82e69SJohn Levon		egrep -v "Ignoring unknown host" | \
19635ca82e69SJohn Levon		sort | uniq | tee $TMPDIR/check_errors >> $mail_msg_file
19645ca82e69SJohn Levon
19655ca82e69SJohn Levon	if [[ -s $TMPDIR/check_errors ]]; then
19665ca82e69SJohn Levon		build_extras_ok=n
19675ca82e69SJohn Levon	fi
19685ca82e69SJohn Levonelse
19695ca82e69SJohn Levon	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
19705ca82e69SJohn Levonfi
19715ca82e69SJohn Levon
19725ca82e69SJohn Levonecho "\n==== Find core files ====\n" | \
19735ca82e69SJohn Levon    tee -a $LOGFILE >> $mail_msg_file
19745ca82e69SJohn Levon
19755ca82e69SJohn Levonfind $abssrcdirs -name core -a -type f -exec file {} \; | \
19765ca82e69SJohn Levon	tee -a $LOGFILE >> $mail_msg_file
19775ca82e69SJohn Levon
19785ca82e69SJohn Levonif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
19795ca82e69SJohn Levon	echo "\n==== Diff unreferenced files (since last build) ====\n" \
19805ca82e69SJohn Levon	    | tee -a $LOGFILE >>$mail_msg_file
19815ca82e69SJohn Levon	rm -f $SRC/unref-${MACH}.ref
19825ca82e69SJohn Levon	if [ -f $SRC/unref-${MACH}.out ]; then
19835ca82e69SJohn Levon		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
19845ca82e69SJohn Levon	fi
19855ca82e69SJohn Levon
19865ca82e69SJohn Levon	findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
19875ca82e69SJohn Levon	    ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
19885ca82e69SJohn Levon	    sort > $SRC/unref-${MACH}.out
19895ca82e69SJohn Levon
19905ca82e69SJohn Levon	if [ ! -f $SRC/unref-${MACH}.ref ]; then
19915ca82e69SJohn Levon		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
19925ca82e69SJohn Levon	fi
19935ca82e69SJohn Levon
19945ca82e69SJohn Levon	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
19955ca82e69SJohn Levonfi
19965ca82e69SJohn Levon
19975ca82e69SJohn Levon# Verify that the usual lists of files, such as exception lists,
19985ca82e69SJohn Levon# contain only valid references to files.  If the build has failed,
19995ca82e69SJohn Levon# then don't check the proto area.
20005ca82e69SJohn LevonCHECK_PATHS=${CHECK_PATHS:-y}
20015ca82e69SJohn Levonif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
20025ca82e69SJohn Levon	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
20035ca82e69SJohn Levon		>>$mail_msg_file
20045ca82e69SJohn Levon	arg=-b
20055ca82e69SJohn Levon	[ "$build_ok" = y ] && arg=
20065ca82e69SJohn Levon	checkpaths $arg $checkroot > $SRC/check-paths.out 2>&1
20075ca82e69SJohn Levon	if [[ -s $SRC/check-paths.out ]]; then
20085ca82e69SJohn Levon		tee -a $LOGFILE < $SRC/check-paths.out >> $mail_msg_file
20095ca82e69SJohn Levon		build_extras_ok=n
20105ca82e69SJohn Levon	fi
20115ca82e69SJohn Levonfi
20125ca82e69SJohn Levon
2013069e6b7eSAndy Fiddamanif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
2014069e6b7eSAndy Fiddaman	echo "\n==== Impact on file permissions ====\n" \
2015069e6b7eSAndy Fiddaman		>> $mail_msg_file
2016069e6b7eSAndy Fiddaman
20175ca82e69SJohn Levon	if [ -n "$abspkg" ]; then
20185ca82e69SJohn Levon		for d in "$abspkg"; do
2019eefeb0ceSBill Sommerfeld			( cd $d/pkg ; $MAKE -e pmodes ) | \
2020eefeb0ceSBill Sommerfeld			egrep -v ": (Entering|Leaving) directory " \
2021eefeb0ceSBill Sommerfeld			>> $mail_msg_file
20225ca82e69SJohn Levon		done
20235ca82e69SJohn Levon	fi
20245ca82e69SJohn Levonfi
20255ca82e69SJohn Levon
20265ca82e69SJohn Levonif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
202726e7d9a8SRichard Lowe	if [[ "$MULTI_PROTO" == no || "$D_FLAG" == y ]]; then
20285ca82e69SJohn Levon		do_wsdiff DEBUG $ROOT.prev $ROOT
20295ca82e69SJohn Levon	fi
20305ca82e69SJohn Levon
203126e7d9a8SRichard Lowe	if [[ "$MULTI_PROTO" == yes && "$F_FLAG" == n ]]; then
20325ca82e69SJohn Levon		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
20335ca82e69SJohn Levon	fi
20345ca82e69SJohn Levonfi
20355ca82e69SJohn Levon
20365ca82e69SJohn LevonEND_DATE=`date`
20375ca82e69SJohn Levonecho "==== Nightly $maketype build completed: $END_DATE ====" | \
20385ca82e69SJohn Levon    tee -a $LOGFILE >> $build_time_file
20395ca82e69SJohn Levon
20405ca82e69SJohn Levontypeset -i10 hours
20415ca82e69SJohn Levontypeset -Z2 minutes
20425ca82e69SJohn Levontypeset -Z2 seconds
20435ca82e69SJohn Levon
20445ca82e69SJohn Levonelapsed_time=$SECONDS
20455ca82e69SJohn Levon((hours = elapsed_time / 3600 ))
20465ca82e69SJohn Levon((minutes = elapsed_time / 60  % 60))
20475ca82e69SJohn Levon((seconds = elapsed_time % 60))
20485ca82e69SJohn Levon
20495ca82e69SJohn Levonecho "\n==== Total build time ====" | \
20505ca82e69SJohn Levon    tee -a $LOGFILE >> $build_time_file
20515ca82e69SJohn Levonecho "\nreal    ${hours}:${minutes}:${seconds}" | \
20525ca82e69SJohn Levon    tee -a $LOGFILE >> $build_time_file
20535ca82e69SJohn Levon
20545ca82e69SJohn Levonif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
20555ca82e69SJohn Levon	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
20565ca82e69SJohn Levon
20575ca82e69SJohn Levon	#
20585ca82e69SJohn Levon	# Produce a master list of unreferenced files -- ideally, we'd
20595ca82e69SJohn Levon	# generate the master just once after all of the nightlies
20605ca82e69SJohn Levon	# have finished, but there's no simple way to know when that
20615ca82e69SJohn Levon	# will be.  Instead, we assume that we're the last nightly to
20625ca82e69SJohn Levon	# finish and merge all of the unref-${MACH}.out files in
20635ca82e69SJohn Levon	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
20645ca82e69SJohn Levon	# finish, then this file will be the authoritative master
20655ca82e69SJohn Levon	# list.  Otherwise, another ${MACH}'s nightly will eventually
20665ca82e69SJohn Levon	# overwrite ours with its own master, but in the meantime our
20675ca82e69SJohn Levon	# temporary "master" will be no worse than any older master
20685ca82e69SJohn Levon	# which was already on the parent.
20695ca82e69SJohn Levon	#
20705ca82e69SJohn Levon
20715ca82e69SJohn Levon	set -- $PARENT_WS/usr/src/unref-*.out
20725ca82e69SJohn Levon	cp "$1" ${TMPDIR}/unref.merge
20735ca82e69SJohn Levon	shift
20745ca82e69SJohn Levon
20755ca82e69SJohn Levon	for unreffile; do
20765ca82e69SJohn Levon		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
20775ca82e69SJohn Levon		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
20785ca82e69SJohn Levon	done
20795ca82e69SJohn Levon
20805ca82e69SJohn Levon	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
20815ca82e69SJohn Levonfi
20825ca82e69SJohn Levon
20835ca82e69SJohn Levon#
20845ca82e69SJohn Levon# All done save for the sweeping up.
20855ca82e69SJohn Levon# (whichever exit we hit here will trigger the "cleanup" trap which
20865ca82e69SJohn Levon# optionally sends mail on completion).
20875ca82e69SJohn Levon#
20885ca82e69SJohn Levonif [[ "$build_ok" == "y" ]]; then
20895ca82e69SJohn Levon	if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
20905ca82e69SJohn Levon		exit 0
20915ca82e69SJohn Levon	fi
20925ca82e69SJohn Levonfi
20935ca82e69SJohn Levon
20945ca82e69SJohn Levonexit 1
2095