nightly: use mail(1) instead of mailx(1)
[unleashed.git] / tools / nightly.sh
blobc34fcc0fb63526a7ae3be1b7d25234d899e2e703
1 #!/bin/ksh -p
2 # vim: noet sw=8 ts=8
4 # CDDL HEADER START
6 # The contents of this file are subject to the terms of the
7 # Common Development and Distribution License (the "License").
8 # You may not use this file except in compliance with the License.
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
21 # CDDL HEADER END
25 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
26 # Copyright 2008, 2010, Richard Lowe
27 # Copyright 2011 Nexenta Systems, Inc. All rights reserved.
28 # Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
29 # Copyright 2014 Garrett D'Amore <garrett@damore.org>
31 # Based on the nightly script from the integration folks,
32 # Mostly modified and owned by mike_s.
33 # Changes also by kjc, dmk.
35 # -i on the command line, means fast options, so when it's on the
36 # command line (only), check builds are skipped no matter what
37 # the setting of their individual flags are in NIGHTLY_OPTIONS.
39 # OPTHOME may be set in the environment to override /opt
43 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
44 # under certain circumstances, which can really screw things up; unset it.
46 unset CDPATH
48 # Get the absolute path of the nightly script that the user invoked. This
49 # may be a relative path, and we need to do this before changing directory.
50 nightly_path=`whence $0`
53 # Keep track of where we found nightly so we can invoke the matching
54 # which_scm script. If that doesn't work, don't go guessing, just rely
55 # on the $PATH settings, which will generally give us either /opt/onbld
56 # or the user's workspace.
58 WHICH_SCM=$(dirname $nightly_path)/which_scm
59 if [[ ! -x $WHICH_SCM ]]; then
60 WHICH_SCM=which_scm
63 function fatal_error
65 print -u2 "nightly: $*"
66 exit 1
70 # Function to do a DEBUG and non-DEBUG build. Needed because we might
71 # need to do another for the source build, and since we only deliver DEBUG or
72 # non-DEBUG packages.
74 # usage: normal_build
76 function normal_build {
78 typeset orig_p_FLAG="$p_FLAG"
80 if [ "$D_FLAG" = "n" ]; then
81 set_non_debug_build_flags
82 build "non-DEBUG"
83 else
84 set_debug_build_flags
85 build "DEBUG"
88 p_FLAG="$orig_p_FLAG"
92 # usage: run_hook HOOKNAME ARGS...
94 # If variable "$HOOKNAME" is defined, insert a section header into
95 # our logs and then run the command with ARGS
97 function run_hook {
98 HOOKNAME=$1
99 eval HOOKCMD=\$$HOOKNAME
100 shift
102 if [ -n "$HOOKCMD" ]; then
104 echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
105 ( $HOOKCMD "$@" 2>&1 )
106 if [ "$?" -ne 0 ]; then
107 # Let exit status propagate up
108 touch $TMPDIR/abort
112 if [ -f $TMPDIR/abort ]; then
113 build_ok=n
114 echo "\nAborting at request of $HOOKNAME"
115 exit 1
120 # Return library search directive as function of given root.
121 function myldlibs {
122 echo "-L$1/lib -L$1/usr/lib"
125 # Return header search directive as function of given root.
126 function myheaders {
127 echo "-I$1/usr/include"
131 # Function to do the build, including package generation.
132 # usage: build LABEL
133 # - LABEL is used to tag build output.
135 function build {
136 LABEL=$1
137 INSTALLOG=install-${MACH}
138 NOISE=noise-${MACH}
140 export ROOT
142 export ENVLDLIBS1=`myldlibs $ROOT`
143 export ENVCPPFLAGS1=`myheaders $ROOT`
145 this_build_ok=y
148 # Before we build anything via dmake, we need to install
149 # bmake-ified headers to the proto area
151 bmake_build_step_user_dir $CODEMGR_WS/include all
152 bmake_build_step_user_dir $CODEMGR_WS/include install
155 # Build the legacy part of the source
157 echo "\n==== Building legacy source at `date` ($LABEL) ====\n"
159 cd $SRC
160 echo "\n==== dmake install ====\n" >&2
161 if ! /bin/time $MAKE -e install; then
162 build_ok=n
163 this_build_ok=n
167 # Build the new part of the source
169 bmake_build_step_user build
171 echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n"
174 # Building Packages
176 if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
177 if [ -d $SRC/pkg ]; then
178 echo "\n==== Creating $LABEL packages at `date` ====\n"
179 echo "Clearing out $PKGARCHIVE ..."
180 rm -rf $PKGARCHIVE
181 mkdir -p $PKGARCHIVE
183 rm -f $SRC/pkg/${INSTALLOG}.out
184 cd $SRC/pkg
185 echo "\n==== package build errors ($LABEL) ====\n" >&2
186 if ! /bin/time $MAKE -e install; then
187 build_extras_ok=n
188 this_build_ok=n
190 else
192 # Handle it gracefully if -p was set but there so
193 # no pkg directory.
195 echo "\n==== No $LABEL packages to build ====\n"
197 else
198 echo "\n==== Not creating $LABEL packages ====\n"
203 # Build and install the onbld tools.
205 # usage: build_tools DESTROOT
207 # returns non-zero status if the build was successful.
209 function build_tools {
210 DESTROOT=$1
212 INSTALLOG=install-${MACH}
214 echo "\n==== Building tools at `date` ====\n" \
216 rm -f ${TOOLS}/${INSTALLOG}.out
217 cd ${TOOLS}
218 echo "\n==== Tools build errors ====\n" >&2
219 if ! /bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install; then
220 return 1
222 return 0
226 # Set up to use locally installed tools.
228 # usage: use_tools TOOLSROOT
230 function use_tools {
231 TOOLSROOT=$1
234 # If we're not building ON workspace, then the TOOLSROOT
235 # settings here are clearly ignored by the workspace
236 # makefiles, prepending nonexistent directories to PATH is
237 # harmless, and we clearly do not wish to override
238 # ONBLD_TOOLS.
240 # If we're building an ON workspace, then the prepended PATH
241 # elements should supercede the preexisting ONBLD_TOOLS paths,
242 # and we want to override ONBLD_TOOLS to catch the tools that
243 # don't have specific path env vars here.
245 # So the only conditional behavior is overriding ONBLD_TOOLS,
246 # and we check for "an ON workspace" by looking for
247 # ${TOOLSROOT}/opt/onbld.
250 STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
251 export STABS
252 CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
253 export CTFSTABS
254 GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
255 export GENOFFSETS
258 PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
259 PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
260 export PATH
262 if [ -d "${TOOLSROOT}/opt/onbld" ]; then
263 ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
264 export ONBLD_TOOLS
267 echo "\n==== New environment settings. ====\n"
268 echo "STABS=${STABS}"
269 echo "CTFSTABS=${CTFSTABS}"
270 echo "PATH=${PATH}"
271 echo "ONBLD_TOOLS=${ONBLD_TOOLS}"
275 # wrapper over wsdiff.
276 # usage: do_wsdiff LABEL OLDPROTO NEWPROTO
278 function do_wsdiff {
279 label=$1
280 oldproto=$2
281 newproto=$3
283 wsdiff="wsdiff -t"
285 echo "\n==== Getting object changes since last build at `date`" \
286 "($label) ====\n" >&2
287 $wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto >&2
288 echo "\n==== Object changes determined at `date` ($label) ====\n" >&2
292 # Functions for setting build flags (DEBUG/non-DEBUG). Keep them
293 # together.
296 function set_non_debug_build_flags {
297 export RELEASE_BUILD ; RELEASE_BUILD=
298 unset EXTRA_OPTIONS
299 unset EXTRA_CFLAGS
302 function set_debug_build_flags {
303 unset RELEASE_BUILD
304 unset EXTRA_OPTIONS
305 unset EXTRA_CFLAGS
309 MACH=`uname -p`
311 if [ "$OPTHOME" = "" ]; then
312 OPTHOME=/opt
313 export OPTHOME
316 USAGE='Usage: nightly [-in] [-V VERS ] <env_file>
318 Where:
319 -i Fast incremental options (no clobber, check)
320 -V VERS set the build version string to VERS
322 <env_file> file in Bourne shell syntax that sets and exports
323 variables that configure the operation of this script and many of
324 the scripts this one calls.
326 non-DEBUG is the default build type. Build options can be set in the
327 NIGHTLY_OPTIONS variable in the <env_file> as follows:
329 -A check for ABI differences in .so files
330 -C check for cstyle/hdrchk errors
331 -D do a build with DEBUG on
332 -G gate keeper default group of options (-au)
333 -I integration engineer default group of options (-ampu)
334 -M do not run pmodes (safe file permission checker)
335 -N do not run protocmp
336 -R default group of options for building a release (-mp)
337 -U update proto area in the parent
338 -V VERS set the build version string to VERS
339 -f find unreferenced files
340 -i do an incremental build (no "make clobber")
341 -m send mail to $MAILTO at end of build
342 -p create packages
343 -r check ELF runtime attributes in the proto area
344 -u update proto_list_$MACH and friends in the parent workspace;
345 when used with -f, also build an unrefmaster.out in the parent
346 -w report on differences between previous and current proto areas
349 # A log file will be generated under the name $LOGFILE
350 # for partially completed build and log.`date '+%F'`
351 # in the same directory for fully completed builds.
354 # default values for low-level FLAGS; G I R are group FLAGS
355 A_FLAG=n
356 C_FLAG=n
357 D_FLAG=n
358 f_FLAG=n
359 i_FLAG=n; i_CMD_LINE_FLAG=n
360 M_FLAG=n
361 m_FLAG=n
362 N_FLAG=n
363 p_FLAG=n
364 r_FLAG=n
365 V_FLAG=n
366 w_FLAG=n
367 W_FLAG=n
369 build_ok=y
370 build_extras_ok=y
373 # examine arguments
376 OPTIND=1
377 while getopts +iV:W FLAG
379 case $FLAG in
380 i ) i_FLAG=y; i_CMD_LINE_FLAG=y
382 V ) V_FLAG=y
383 V_ARG="$OPTARG"
385 W ) W_FLAG=y
387 \? ) echo "$USAGE"
388 exit 1
390 esac
391 done
393 # correct argument count after options
394 shift `expr $OPTIND - 1`
396 # test that the path to the environment-setting file was given
397 if [ $# -ne 1 ]; then
398 echo "$USAGE"
399 exit 1
403 # force locale to C
404 LANG=C; export LANG
405 LC_ALL=C; export LC_ALL
406 LC_COLLATE=C; export LC_COLLATE
407 LC_CTYPE=C; export LC_CTYPE
408 LC_MESSAGES=C; export LC_MESSAGES
409 LC_MONETARY=C; export LC_MONETARY
410 LC_NUMERIC=C; export LC_NUMERIC
411 LC_TIME=C; export LC_TIME
413 # clear environment variables we know to be bad for the build
414 unset LD_OPTIONS
415 unset LD_AUDIT LD_AUDIT_32 LD_AUDIT_64
416 unset LD_BIND_NOW LD_BIND_NOW_32 LD_BIND_NOW_64
417 unset LD_BREADTH LD_BREADTH_32 LD_BREADTH_64
418 unset LD_CONFIG LD_CONFIG_32 LD_CONFIG_64
419 unset LD_DEBUG LD_DEBUG_32 LD_DEBUG_64
420 unset LD_DEMANGLE LD_DEMANGLE_32 LD_DEMANGLE_64
421 unset LD_FLAGS LD_FLAGS_32 LD_FLAGS_64
422 unset LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64
423 unset LD_LOADFLTR LD_LOADFLTR_32 LD_LOADFLTR_64
424 unset LD_NOAUDIT LD_NOAUDIT_32 LD_NOAUDIT_64
425 unset LD_NOAUXFLTR LD_NOAUXFLTR_32 LD_NOAUXFLTR_64
426 unset LD_NOCONFIG LD_NOCONFIG_32 LD_NOCONFIG_64
427 unset LD_NODIRCONFIG LD_NODIRCONFIG_32 LD_NODIRCONFIG_64
428 unset LD_NODIRECT LD_NODIRECT_32 LD_NODIRECT_64
429 unset LD_NOLAZYLOAD LD_NOLAZYLOAD_32 LD_NOLAZYLOAD_64
430 unset LD_NOOBJALTER LD_NOOBJALTER_32 LD_NOOBJALTER_64
431 unset LD_NOVERSION LD_NOVERSION_32 LD_NOVERSION_64
432 unset LD_ORIGIN LD_ORIGIN_32 LD_ORIGIN_64
433 unset LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
434 unset LD_PROFILE LD_PROFILE_32 LD_PROFILE_64
436 unset CONFIG
437 unset GROUP
438 unset OWNER
439 unset REMOTE
440 unset ENV
441 unset ARCH
442 unset CLASSPATH
443 unset NAME
446 # To get ONBLD_TOOLS from the environment, it must come from the env file.
447 # If it comes interactively, it is generally TOOLS_PROTO, which will be
448 # clobbered before the compiler version checks, which will therefore fail.
450 unset ONBLD_TOOLS
453 # Setup environmental variables
455 if [ -f $1 ]; then
456 if [[ $1 = */* ]]; then
457 . $1
458 else
459 . ./$1
461 else
462 echo "Cannot find env file as either $1"
463 exit 1
466 # Check if we have sufficient data to continue...
467 [[ -v CODEMGR_WS ]] || \
468 fatal_error "Error: Variable CODEMGR_WS not set."
469 [[ -d "${CODEMGR_WS}" ]] || \
470 fatal_error "Error: ${CODEMGR_WS} is not a directory."
471 [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || \
472 fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
475 # place ourselves in a new task, respecting BUILD_PROJECT if set.
477 if [ -z "$BUILD_PROJECT" ]; then
478 /usr/bin/newtask -c $$
479 else
480 /usr/bin/newtask -c $$ -p $BUILD_PROJECT
483 ps -o taskid= -p $$ | read build_taskid
484 ps -o project= -p $$ | read build_project
487 # See if NIGHTLY_OPTIONS is set
489 if [ "$NIGHTLY_OPTIONS" = "" ]; then
490 NIGHTLY_OPTIONS="-aBm"
494 # Note: changes to the option letters here should also be applied to the
495 # bldenv script. `d' is listed for backward compatibility.
497 NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
498 OPTIND=1
499 while getopts +ABCDdfGIiMmNpRrwW FLAG $NIGHTLY_OPTIONS
501 case $FLAG in
502 A ) A_FLAG=y
504 B ) D_FLAG=y
505 ;; # old version of D
506 C ) C_FLAG=y
508 D ) D_FLAG=y
510 f ) f_FLAG=y
512 G ) ;;
513 I ) m_FLAG=y
514 p_FLAG=y
516 i ) i_FLAG=y
518 M ) M_FLAG=y
520 m ) m_FLAG=y
522 N ) N_FLAG=y
524 p ) p_FLAG=y
526 R ) m_FLAG=y
527 p_FLAG=y
529 r ) r_FLAG=y
531 w ) w_FLAG=y
533 W ) W_FLAG=y
535 \? ) echo "$USAGE"
536 exit 1
538 esac
539 done
541 if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
542 MAILTO=`/usr/xpg4/bin/id -un`
543 export MAILTO
546 PATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
547 PATH="$PATH:/usr/bin:/usr/sbin:/usr/ucb"
548 PATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:.:$OPTHOME/SUNWspro/bin"
549 export PATH
551 # roots of source trees, both relative to $SRC and absolute.
552 relsrcdirs="."
553 abssrcdirs="$SRC"
555 PROTOCMPTERSE="protocmp.terse -gu"
556 POUND_SIGN="#"
557 # have we set RELEASE_DATE in our env file?
558 if [ -z "$RELEASE_DATE" ]; then
559 RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
561 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
562 BASEWSDIR=$(basename $CODEMGR_WS)
563 DEV_CM="\"@(#)illumos Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
564 RELEASE_MICRO=$(( ($(date +%Y) * 12 + $(date +%m) - 1) - (2010 * 12 + 8 - 1) ))
566 # we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
567 # by avoiding repeated shell invocations to evaluate Makefile.master
568 # definitions.
569 export POUND_SIGN RELEASE_DATE DEV_CM RELEASE_MICRO
571 maketype="distributed"
572 if [[ -z "$MAKE" ]]; then
573 MAKE=dmake
574 elif [[ ! -x "$MAKE" ]]; then
575 echo "\$MAKE is set to garbage in the environment"
576 exit 1
578 export PATH
579 export MAKE
581 hostname=$(uname -n)
582 if [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
583 then
584 maxjobs=
585 if [[ -f $HOME/.make.machines ]]
586 then
587 # Note: there is a hard tab and space character in the []s
588 # below.
589 egrep -i "^[ ]*$hostname[ \.]" \
590 $HOME/.make.machines | read host jobs
591 maxjobs=${jobs##*=}
594 if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
595 then
596 # default
597 maxjobs=4
600 export DMAKE_MAX_JOBS=$maxjobs
603 DMAKE_MODE=parallel;
604 export DMAKE_MODE
606 if [ -z "${ROOT}" ]; then
607 echo "ROOT must be set."
608 exit 1
612 # if -V flag was given, reset VERSION to V_ARG
614 if [ "$V_FLAG" = "y" ]; then
615 VERSION=$V_ARG
618 TMPDIR="/tmp/nightly.tmpdir.$$"
619 export TMPDIR
620 rm -rf ${TMPDIR}
621 mkdir -p $TMPDIR || exit 1
623 # Tools should only be built non-DEBUG. Keep track of the tools proto
624 # area path relative to $TOOLS, because the latter changes in an
625 # export build.
627 # TOOLS_PROTO is included below for builds other than usr/src/tools
628 # that look for this location. For usr/src/tools, this will be
629 # overridden on the $MAKE command line in build_tools().
631 TOOLS=${SRC}/tools
632 TOOLS_PROTO_REL=proto/root_${MACH}-nd
633 TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
635 unset CFLAGS LD_LIBRARY_PATH LDFLAGS
637 # create directories that are automatically removed if the nightly script
638 # fails to start correctly
639 function newdir {
640 dir=$1
641 toadd=
642 while [ ! -d $dir ]; do
643 toadd="$dir $toadd"
644 dir=`dirname $dir`
645 done
646 torm=
647 newlist=
648 for dir in $toadd; do
649 if mkdir $dir; then
650 newlist="$dir $newlist"
651 torm="$dir $torm"
652 else
653 [ -z "$torm" ] || rmdir $torm
654 return 1
656 done
657 newdirlist="$newlist $newdirlist"
658 return 0
660 newdirlist=
662 [ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
664 # since this script assumes the build is from full source, it nullifies
665 # variables likely to have been set by a "ws" script; nullification
666 # confines the search space for headers and libraries to the proto area
667 # built from this immediate source.
668 ENVLDLIBS1=
669 ENVLDLIBS2=
670 ENVLDLIBS3=
671 ENVCPPFLAGS1=
672 ENVCPPFLAGS2=
673 ENVCPPFLAGS3=
674 ENVCPPFLAGS4=
676 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
677 ENVLDLIBS1 ENVLDLIBS2
680 # Juggle the logs and optionally send mail on completion.
683 function logshuffle {
684 LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
685 if [ -f $LLOG -o -d $LLOG ]; then
686 LLOG=$LLOG.$$
688 mkdir $LLOG
689 export LLOG
691 if [ "$build_ok" = "y" ]; then
692 mv $ATLOG/proto_list_${MACH} $LLOG
694 if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
695 mv $ATLOG/proto_list_tools_${MACH} $LLOG
698 if [ -f $TMPDIR/wsdiff.results ]; then
699 mv $TMPDIR/wsdiff.results $LLOG
702 if [ -f $TMPDIR/wsdiff-nd.results ]; then
703 mv $TMPDIR/wsdiff-nd.results $LLOG
707 kill $TEE
708 case "$build_ok" in
710 state=Completed
713 state=Interrupted
716 state=Failed
718 esac
720 if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
721 state=Failed
724 NIGHTLY_STATUS=$state
725 export NIGHTLY_STATUS
727 run_hook POST_NIGHTLY $state
728 run_hook SYS_POST_NIGHTLY $state
730 echo "Subject: Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
731 > ${LLOG}/mail_msg
732 cat $build_time_file $mail_msg_file \
733 >> ${LLOG}/mail_msg
734 if [ "$m_FLAG" = "y" ]; then
735 /usr/bin/mail ${MAILTO} < ${LLOG}/mail_msg
738 mv $LOGFILE $LLOG
742 # Remove the temporary files on any exit
744 function cleanup {
745 logshuffle
747 set -- $newdirlist
748 while [ $# -gt 0 ]; do
749 rmdir $1
750 shift; shift
751 done
752 rm -rf $TMPDIR
755 function cleanup_signal {
756 build_ok=i
757 # this will trigger cleanup(), above.
758 exit 1
761 trap cleanup 0
762 trap cleanup_signal 1 2 3 15
764 newdirlist=
767 # Create mail_msg_file
769 mail_msg_file="${TMPDIR}/mail_msg"
770 touch $mail_msg_file
771 build_time_file="${TMPDIR}/build_time"
773 mkdir -p "$ATLOG"
775 # Move old LOGFILE aside
777 if [ -f $LOGFILE ]; then
778 mv -f $LOGFILE ${LOGFILE}-
781 mkfifo ${TMPDIR}/err.fifo ${TMPDIR}/out.fifo
782 tee $mail_msg_file < ${TMPDIR}/err.fifo >> $LOGFILE &
783 TEE=$!
784 tee ${TMPDIR}/stdout.txt < ${TMPDIR}/out.fifo >> $LOGFILE &
785 TEE="$TEE $!"
786 exec > ${TMPDIR}/out.fifo
787 exec 2> ${TMPDIR}/err.fifo
790 # Build OsNet source
792 START_DATE=`date`
793 SECONDS=0
794 echo "\n==== Nightly $maketype build started: $START_DATE ====" | \
795 tee -a $build_time_file
797 echo "\nBuild project: $build_project\nBuild taskid: $build_taskid" >&2
799 run_hook SYS_PRE_NIGHTLY
800 run_hook PRE_NIGHTLY
802 echo "\n==== list of environment variables ====\n"
805 echo "\n==== Nightly argument issues ====\n" >&2
807 if [ "$N_FLAG" = "y" ]; then
808 if [ "$p_FLAG" = "y" ]; then
809 cat <<EOF >&2
810 WARNING: the p option (create packages) is set, but so is the N option (do
811 not run protocmp); this is dangerous; you should unset the N option
813 else
814 cat <<EOF >&2
815 Warning: the N option (do not run protocmp) is set; it probably shouldn't be
818 echo "" >&2
821 if [ "$f_FLAG" = "y" ]; then
822 if [ "$i_FLAG" = "y" ]; then
823 echo "WARNING: the -f flag cannot be used during incremental" \
824 "builds; ignoring -f\n" >&2
825 f_FLAG=n
827 if [ "${p_FLAG}" != "y" ]; then
828 echo "WARNING: the -f flag requires -p;" \
829 "ignoring -f\n" >&2
830 f_FLAG=n
834 if [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
835 echo "WARNING: -w specified, but $ROOT does not exist;" \
836 "ignoring -w\n" >&2
837 w_FLAG=n
840 echo "\n==== Build version ====\n" >&2
841 echo $VERSION >&2
843 # Save the current proto area if we're comparing against the last build
844 if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
845 if [ -d "$ROOT.prev" ]; then
846 rm -rf $ROOT.prev
848 mv $ROOT $ROOT.prev
851 # Echo the SCM types of $CODEMGR_WS
852 function child_wstype {
853 typeset scm_type junk
855 # Probe CODEMGR_WS to determine its type
856 if [[ -d $CODEMGR_WS ]]; then
857 $WHICH_SCM | read scm_type junk || exit 1
860 case "$scm_type" in
861 none|git|mercurial)
863 *) scm_type=none
865 esac
867 echo $scm_type
870 function run_bmake {
871 echo "\n==== bmake $@ ====\n" >&2
872 /bin/time env -i PATH=${GCC_ROOT}/bin:/usr/bin \
873 bmake -j $DMAKE_MAX_JOBS \
874 VERBOSE=yes \
875 "$@"
878 # usage: bmake_build_step_args <dir> <target> <args...>
879 function bmake_build_step_args {
880 D=$1
881 shift
883 echo "\n==== \`bmake -C $D $@\` at `date` ($LABEL) ====\n"
885 if ! run_bmake -C $D "$@"; then
886 build_ok=n
887 this_build_ok=n
888 return 1
891 return 0
894 # usage: bmake_build_step_user <target>
895 function bmake_build_step_user {
896 bmake_build_step_args $CODEMGR_WS $1 \
897 DESTDIR=$ROOT
900 # usage: bmake_build_step_user_dir <dir> <target>
901 function bmake_build_step_user_dir {
902 bmake_build_step_args $1 $2 \
903 DESTDIR=$ROOT
906 SCM_TYPE=$(child_wstype)
908 # Safeguards
909 [[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
910 [[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory."
911 [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
914 # Generate the cfgparam files
916 # We have to do this before running *any* make commands.
918 bmake_build_step_args $CODEMGR_WS gen-config || build_extras_ok=n
921 # Decide whether to clobber
923 if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
924 echo "\n==== Make clobber at `date` ====\n"
926 cd $SRC
927 # remove old clobber file
928 rm -f $SRC/clobber.out
929 rm -f $SRC/clobber-${MACH}.out
931 # Remove all .make.state* files, just in case we are restarting
932 # the build after having interrupted a previous 'make clobber'.
933 find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
934 -o -name 'interfaces.*' \) -prune \
935 -o -name '.make.*' -print | xargs rm -f
937 echo "\n==== Make clobber ERRORS ====\n" >&2
938 if ! $MAKE -ek clobber; then
939 build_extras_ok=n
942 echo "\n==== Make tools clobber at `date` ====\n"
943 cd ${TOOLS}
944 rm -f ${TOOLS}/clobber-${MACH}.out
946 echo "\n==== Make tools clobber ERRORS ====\n" >&2
947 if ! $MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber; then
948 build_extras_ok=n
950 rm -rf ${TOOLS_PROTO}
951 mkdir -p ${TOOLS_PROTO}
953 typeset roots=$ROOT
954 echo "\n\nClearing $roots"
955 rm -rf $roots
957 # Get back to a clean workspace as much as possible to catch
958 # problems that only occur on fresh workspaces.
959 # Remove all .make.state* files, libraries, and .o's that may
960 # have been omitted from clobber. A couple of libraries are
961 # under source code control, so leave them alone.
962 # We should probably blow away temporary directories too.
963 cd $SRC
964 find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
965 -o -name .git -o -name 'interfaces.*' \) -prune -o \
966 \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
967 -name '*.o' \) -print | \
968 grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
969 echo "\n==== bmake cleandir ====\n"
970 run_bmake -C $CODEMGR_WS cleandir
971 else
972 echo "\n==== No clobber at `date` ====\n"
975 echo "\n==== Build environment ====\n" >&2
977 # System
978 whence uname >&2
979 uname -a >&2
980 echo >&2
982 # make
983 whence $MAKE >&2
984 $MAKE -v >&2
985 echo "number of concurrent jobs = $DMAKE_MAX_JOBS" >&2
988 # Report the compiler versions.
991 if [[ ! -f $SRC/Makefile ]]; then
992 build_ok=n
993 echo "\nUnable to find \"Makefile\" in $SRC." >&2
994 exit 1
997 whence ld >&2
998 LDVER=`ld -V 2>&1`
999 echo $LDVER >&2
1001 # Build and use the workspace's tools if requested
1003 set_non_debug_build_flags
1005 build_tools ${TOOLS_PROTO}
1006 if (( $? != 0 )); then
1007 build_ok=n
1008 else
1009 use_tools $TOOLS_PROTO
1012 # timestamp the start of the normal build; the findunref tool uses it.
1013 touch $SRC/.build.tstamp
1015 normal_build
1017 ORIG_SRC=$SRC
1018 BINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
1020 if [ "$build_ok" = "y" ]; then
1021 echo "\n==== Creating protolist system file at `date` ====" \
1022 protolist $ROOT > $ATLOG/proto_list_${MACH}
1023 echo "==== protolist system file created at `date` ====\n" \
1025 if [ "$N_FLAG" != "y" ]; then
1029 for f in $f1; do
1030 if [ -f "$f" ]; then
1031 E1="$E1 -e $f"
1033 done
1037 if [ -d "$SRC/pkg" ]; then
1038 f2="$f2 exceptions/packaging"
1041 for f in $f2; do
1042 if [ -f "$f" ]; then
1043 E2="$E2 -e $f"
1045 done
1048 if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
1049 echo "\n==== Validating manifests against proto area ====\n" >&2
1050 if ! ( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$ROOT" ) >&2; then
1051 build_extras_ok=n
1057 # ELF verification: ABI (-A) and runtime (-r) checks
1059 if [[ ($build_ok = y) && (($A_FLAG = y) || ($r_FLAG = y)) ]]; then
1060 # Directory ELF-data.$MACH holds the files produced by these tests.
1061 elf_ddir=$SRC/ELF-data.$MACH
1063 # If there is a previous ELF-data backup directory, remove it. Then,
1064 # rotate current ELF-data directory into its place and create a new
1065 # empty directory
1066 rm -rf $elf_ddir.ref
1067 if [[ -d $elf_ddir ]]; then
1068 mv $elf_ddir $elf_ddir.ref
1070 mkdir -p $elf_ddir
1072 # Call find_elf to produce a list of the ELF objects in the proto area.
1073 # This list is passed to check_rtime and interface_check, preventing
1074 # them from separately calling find_elf to do the same work twice.
1075 find_elf -fr $ROOT > $elf_ddir/object_list
1077 if [[ $A_FLAG = y ]]; then
1078 echo "\n==== Check versioning and ABI information ====\n" >&2
1080 # Produce interface description for the proto. Report errors.
1081 interface_check -o -w $elf_ddir -f object_list \
1082 -i interface -E interface.err
1083 if [[ -s $elf_ddir/interface.err ]]; then
1084 cat $elf_ddir/interface.err >&2
1085 build_extras_ok=n
1088 # If ELF_DATA_BASELINE_DIR is defined, compare the new interface
1089 # description file to that from the baseline gate. Issue a
1090 # warning if the baseline is not present, and keep going.
1091 if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
1092 base_ifile="$ELF_DATA_BASELINE_DIR/interface"
1094 echo "\n==== Compare versioning and ABI information" \
1095 "to baseline ====\n" >&2
1096 echo "Baseline: $base_ifile\n"
1098 if [[ -f $base_ifile ]]; then
1099 interface_cmp -d -o $base_ifile \
1100 $elf_ddir/interface > $elf_ddir/interface.cmp
1101 if [[ -s $elf_ddir/interface.cmp ]]; then
1102 echo >&2
1103 cat $elf_ddir/interface.cmp >&2
1104 build_extras_ok=n
1106 else
1107 echo "baseline not available. comparison" \
1108 "skipped" >&2
1114 if [[ $r_FLAG = y ]]; then
1115 echo "\n==== Check ELF runtime attributes ====\n" >&2
1117 # If we're doing a DEBUG build the proto area will be left
1118 # with debuggable objects, thus don't assert -s.
1119 if [[ $D_FLAG = y ]]; then
1120 rtime_sflag=""
1121 else
1122 rtime_sflag="-s"
1124 check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
1125 -D object_list -f object_list -E runtime.err \
1126 -I runtime.attr.raw
1127 if (( $? != 0 )); then
1128 build_extras_ok=n
1131 # check_rtime -I output needs to be sorted in order to
1132 # compare it to that from previous builds.
1133 sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
1134 rm $elf_ddir/runtime.attr.raw
1136 # Report errors
1137 if [[ -s $elf_ddir/runtime.err ]]; then
1138 cat $elf_ddir/runtime.err >&2
1139 build_extras_ok=n
1142 # If there is an ELF-data directory from a previous build,
1143 # then diff the attr files. These files contain information
1144 # about dependencies, versioning, and runpaths. There is some
1145 # overlap with the ABI checking done above, but this also
1146 # flushes out non-ABI interface differences along with the
1147 # other information.
1148 echo "\n==== Diff ELF runtime attributes" \
1149 "(since last build) ====\n" >&2
1151 if [[ -f $elf_ddir.ref/runtime.attr ]]; then
1152 diff $elf_ddir.ref/runtime.attr \
1153 $elf_ddir/runtime.attr >&2
1158 # "make check" begins
1160 if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
1161 # remove old check.out
1162 rm -f $SRC/check.out
1164 rm -f $SRC/check-${MACH}.out
1165 cd $SRC
1166 echo "\n==== cstyle/hdrchk errors ====\n" >&2
1167 if ! $MAKE -ek check ROOT="$ROOT"; then
1168 build_extras_ok=n
1170 else
1171 echo "\n==== No '$MAKE check' ====\n"
1174 echo "\n==== Find core files ====\n" >&2
1176 find $abssrcdirs -name core -a -type f -exec file {} \; >&2
1178 if [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
1179 echo "\n==== Diff unreferenced files (since last build) ====\n" >&2
1180 rm -f $SRC/unref-${MACH}.ref
1181 if [ -f $SRC/unref-${MACH}.out ]; then
1182 mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
1185 findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
1186 ${TOOLS}/findunref/exception_list | \
1187 sort > $SRC/unref-${MACH}.out
1189 if [ ! -f $SRC/unref-${MACH}.ref ]; then
1190 cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
1193 diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >&2
1196 # Verify that the usual lists of files, such as exception lists,
1197 # contain only valid references to files. If the build has failed,
1198 # then don't check the proto area.
1199 CHECK_PATHS=${CHECK_PATHS:-y}
1200 if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
1201 echo "\n==== Check lists of files ====\n" >&2
1202 arg=-b
1203 [ "$build_ok" = y ] && arg=
1204 checkpaths $arg $ROOT > $SRC/check-paths.out 2>&1
1205 if [[ -s $SRC/check-paths.out ]]; then
1206 cat $SRC/check-paths.out >&2
1207 build_extras_ok=n
1211 if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
1212 echo "\n==== Impact on file permissions ====\n" >&2
1214 abspkg=
1215 for d in $abssrcdirs; do
1216 if [ -d "$d/pkg" ]; then
1217 abspkg="$abspkg $d"
1219 done
1221 if [ -n "$abspkg" ]; then
1222 for d in "$abspkg"; do
1223 ( cd $d/pkg ; $MAKE -e pmodes ) >&2
1224 done
1228 if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
1229 if [[ "$D_FLAG" = y ]]; then
1230 do_wsdiff DEBUG $ROOT.prev $ROOT
1231 else
1232 do_wsdiff non-DEBUG $ROOT.prev $ROOT
1236 END_DATE=`date`
1237 echo "==== Nightly $maketype build completed: $END_DATE ====" | \
1238 tee -a $build_time_file
1240 typeset -i10 hours
1241 typeset -Z2 minutes
1242 typeset -Z2 seconds
1244 elapsed_time=$SECONDS
1245 ((hours = elapsed_time / 3600 ))
1246 ((minutes = elapsed_time / 60 % 60))
1247 ((seconds = elapsed_time % 60))
1249 echo "\n==== Total build time ====" | \
1250 tee -a $build_time_file
1251 echo "\nreal ${hours}:${minutes}:${seconds}" | \
1252 tee -a $build_time_file
1255 # All done save for the sweeping up.
1256 # (whichever exit we hit here will trigger the "cleanup" trap which
1257 # optionally sends mail on completion).
1259 if [[ "$build_ok" == "y" ]]; then
1260 if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
1261 exit 0
1265 exit 1