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