nightly should create a log/latest/ symlink
[unleashed.git] / tools / nightly.sh
blobb846ee13674fafd55724552a22be6f51db91c6fd
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>
30 # Copyright 2018 Joyent, Inc.
32 # Based on the nightly script from the integration folks,
33 # Mostly modified and owned by mike_s.
34 # Changes also by kjc, dmk.
36 # -i on the command line, means fast options, so when it's on the
37 # command line (only), check builds are skipped no matter what
38 # the setting of their individual flags are in NIGHTLY_OPTIONS.
40 # OPTHOME may be set in the environment to override /opt
44 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
45 # under certain circumstances, which can really screw things up; unset it.
47 unset CDPATH
49 # Get the absolute path of the nightly script that the user invoked. This
50 # may be a relative path, and we need to do this before changing directory.
51 nightly_path=`whence $0`
53 function fatal_error
55 print -u2 "nightly: $*"
56 exit 1
60 # Function to do a DEBUG and non-DEBUG build. Needed because we might
61 # need to do another for the source build, and since we only deliver DEBUG or
62 # non-DEBUG packages.
64 # usage: normal_build
66 function normal_build {
68 typeset orig_p_FLAG="$p_FLAG"
70 if [ "$D_FLAG" = "n" ]; then
71 set_non_debug_build_flags
72 build "non-DEBUG"
73 else
74 set_debug_build_flags
75 build "DEBUG"
78 p_FLAG="$orig_p_FLAG"
82 # usage: run_hook HOOKNAME ARGS...
84 # If variable "$HOOKNAME" is defined, insert a section header into
85 # our logs and then run the command with ARGS
87 function run_hook {
88 HOOKNAME=$1
89 eval HOOKCMD=\$$HOOKNAME
90 shift
92 if [ -n "$HOOKCMD" ]; then
94 echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
95 ( $HOOKCMD "$@" 2>&1 )
96 if [ "$?" -ne 0 ]; then
97 # Let exit status propagate up
98 touch $TMPDIR/abort
102 if [ -f $TMPDIR/abort ]; then
103 build_ok=n
104 echo "\nAborting at request of $HOOKNAME"
105 exit 1
110 # Return library search directive as function of given root.
111 function myldlibs {
112 echo "-L$1/lib -L$1/usr/lib"
115 # Return header search directive as function of given root.
116 function myheaders {
117 echo "-I$1/usr/include"
121 # Function to do the build, including package generation.
122 # usage: build LABEL
123 # - LABEL is used to tag build output.
125 function build {
126 LABEL=$1
127 INSTALLOG=install-${MACH}
129 export ROOT
131 export ENVLDLIBS1=`myldlibs $ROOT`
132 export ENVCPPFLAGS1=`myheaders $ROOT`
134 this_build_ok=y
137 # Before we build anything via dmake, we need to install
138 # bmake-ified headers to the proto area
140 if ! make -C $SRCTOP/include all install DESTDIR=$ROOT; then
141 build_ok=n
142 this_build_ok=n
143 fatal_error "cannot install headers"
147 # Build the legacy part of the source
149 echo "\n==== Building legacy source at `date` ($LABEL) ====\n"
151 cd $SRC
152 echo "\n==== dmake install ====\n" >&2
153 if ! /bin/time $MAKE -e install; then
154 build_ok=n
155 this_build_ok=n
159 # Build the new part of the source
161 echo "\n==== bmake build ====\n" >&2
162 if ! /bin/time env -i PATH=${GCC_ROOT}/bin:/usr/bin \
163 SRCTOP=$SRCTOP \
164 make -C $SRCTOP -j $DMAKE_MAX_JOBS VERBOSE=yes build DESTDIR=$ROOT; then
165 build_ok=n
166 this_build_ok=n
169 echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n"
172 # Building Packages
174 if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
175 if [ -d $SRC/pkg ]; then
176 echo "\n==== Creating $LABEL packages at `date` ====\n"
177 echo "Clearing out $PKGARCHIVE ..."
178 rm -rf $PKGARCHIVE
179 mkdir -p $PKGARCHIVE
181 rm -f $SRC/pkg/${INSTALLOG}.out
182 cd $SRC/pkg
183 echo "\n==== dmake -C $SRC/pkg install ====\n" >&2
184 if ! /bin/time $MAKE -e install; then
185 build_extras_ok=n
186 this_build_ok=n
188 else
190 # Handle it gracefully if -p was set but there so
191 # no pkg directory.
193 echo "\n==== No $LABEL packages to build ====\n"
195 else
196 echo "\n==== Not creating $LABEL packages ====\n"
201 # Build and install the onbld tools.
203 # usage: build_tools DESTROOT
205 # returns non-zero status if the build was successful.
207 function build_tools {
208 DESTROOT=$1
210 INSTALLOG=install-${MACH}
212 echo "\n==== Building tools at `date` ====\n" \
214 rm -f ${TOOLS}/${INSTALLOG}.out
215 cd ${TOOLS}
216 if ! $MAKE TOOLS_PROTO=${DESTROOT} -e install; then
217 return 1
219 return 0
223 # Set up to use locally installed tools.
225 # usage: use_tools TOOLSROOT
227 function use_tools {
228 TOOLSROOT=$1
231 # If we're not building ON workspace, then the TOOLSROOT
232 # settings here are clearly ignored by the workspace
233 # makefiles, prepending nonexistent directories to PATH is
234 # harmless, and we clearly do not wish to override
235 # ONBLD_TOOLS.
237 # If we're building an ON workspace, then the prepended PATH
238 # elements should supercede the preexisting ONBLD_TOOLS paths,
239 # and we want to override ONBLD_TOOLS to catch the tools that
240 # don't have specific path env vars here.
242 # So the only conditional behavior is overriding ONBLD_TOOLS,
243 # and we check for "an ON workspace" by looking for
244 # ${TOOLSROOT}/opt/onbld.
247 STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
248 export STABS
249 CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
250 export CTFSTABS
251 GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
252 export GENOFFSETS
255 PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
256 PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
257 export PATH
259 if [ -d "${TOOLSROOT}/opt/onbld" ]; then
260 ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
261 export ONBLD_TOOLS
264 echo "\n==== New environment settings. ====\n"
265 echo "STABS=${STABS}"
266 echo "CTFSTABS=${CTFSTABS}"
267 echo "PATH=${PATH}"
268 echo "ONBLD_TOOLS=${ONBLD_TOOLS}"
272 # wrapper over wsdiff.
273 # usage: do_wsdiff LABEL OLDPROTO NEWPROTO
275 function do_wsdiff {
276 label=$1
277 oldproto=$2
278 newproto=$3
280 wsdiff="wsdiff -t"
282 echo "\n==== Getting object changes since last build at `date`" \
283 "($label) ====\n" >&2
284 $wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto >&2
285 echo "\n==== Object changes determined at `date` ($label) ====\n" >&2
289 # Functions for setting build flags (DEBUG/non-DEBUG). Keep them
290 # together.
293 function set_non_debug_build_flags {
294 export RELEASE_BUILD ; RELEASE_BUILD=
295 unset EXTRA_OPTIONS
296 unset EXTRA_CFLAGS
299 function set_debug_build_flags {
300 unset RELEASE_BUILD
301 unset EXTRA_OPTIONS
302 unset EXTRA_CFLAGS
306 MACH=`uname -p`
308 if [ "$OPTHOME" = "" ]; then
309 OPTHOME=/opt
310 export OPTHOME
313 USAGE='Usage: nightly [-in] [-V VERS ] [env_file]
315 Where:
316 -i Fast incremental options (no clobber, check)
317 -V VERS set the build version string to VERS
319 <env_file> file in Bourne shell syntax that sets and exports
320 variables that configure the operation of this script and many of
321 the scripts this one calls.
323 non-DEBUG is the default build type. Build options can be set in the
324 NIGHTLY_OPTIONS variable in the <env_file> as follows:
326 -A check for ABI differences in .so files
327 -C check for cstyle/hdrchk errors
328 -D do a build with DEBUG on
329 -G gate keeper default group of options (-au)
330 -I integration engineer default group of options (-ampu)
331 -M do not run pmodes (safe file permission checker)
332 -N do not run protocmp
333 -R default group of options for building a release (-mp)
334 -U update proto area in the parent
335 -V VERS set the build version string to VERS
336 -i do an incremental build (no "make clobber")
337 -m send mail to $MAILTO at end of build
338 -p create packages
339 -r check ELF runtime attributes in the proto area
340 -u update proto_list_$MACH and friends in the parent workspace
341 -w report on differences between previous and current proto areas
344 # A log file will be generated under the name $LOGFILE
345 # for partially completed build and log.`date '+%F'`
346 # in the same directory for fully completed builds.
349 # default values for low-level FLAGS; G I R are group FLAGS
350 A_FLAG=n
351 C_FLAG=n
352 D_FLAG=n
353 i_FLAG=n; i_CMD_LINE_FLAG=n
354 M_FLAG=n
355 m_FLAG=n
356 N_FLAG=n
357 p_FLAG=n
358 r_FLAG=n
359 V_FLAG=n
360 w_FLAG=n
361 W_FLAG=n
363 build_ok=y
364 build_extras_ok=y
367 # examine arguments
370 OPTIND=1
371 while getopts +iV:W FLAG
373 case $FLAG in
374 i ) i_FLAG=y; i_CMD_LINE_FLAG=y
376 V ) V_FLAG=y
377 V_ARG="$OPTARG"
379 W ) W_FLAG=y
381 \? ) echo "$USAGE"
382 exit 1
384 esac
385 done
387 # correct argument count after options
388 shift `expr $OPTIND - 1`
390 # test that the path to the environment-setting file was given
391 if [ $# -ne 1 ]; then
392 envfile=$(dirname $0)/env.sh
393 else
394 envfile=$1
398 # force locale to C
399 LANG=C; export LANG
400 LC_ALL=C; export LC_ALL
401 LC_COLLATE=C; export LC_COLLATE
402 LC_CTYPE=C; export LC_CTYPE
403 LC_MESSAGES=C; export LC_MESSAGES
404 LC_MONETARY=C; export LC_MONETARY
405 LC_NUMERIC=C; export LC_NUMERIC
406 LC_TIME=C; export LC_TIME
408 # clear environment variables we know to be bad for the build
409 unset LD_OPTIONS
410 unset LD_AUDIT LD_AUDIT_32 LD_AUDIT_64
411 unset LD_BIND_NOW LD_BIND_NOW_32 LD_BIND_NOW_64
412 unset LD_BREADTH LD_BREADTH_32 LD_BREADTH_64
413 unset LD_CONFIG LD_CONFIG_32 LD_CONFIG_64
414 unset LD_DEBUG LD_DEBUG_32 LD_DEBUG_64
415 unset LD_DEMANGLE LD_DEMANGLE_32 LD_DEMANGLE_64
416 unset LD_FLAGS LD_FLAGS_32 LD_FLAGS_64
417 unset LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64
418 unset LD_LOADFLTR LD_LOADFLTR_32 LD_LOADFLTR_64
419 unset LD_NOAUDIT LD_NOAUDIT_32 LD_NOAUDIT_64
420 unset LD_NOAUXFLTR LD_NOAUXFLTR_32 LD_NOAUXFLTR_64
421 unset LD_NOCONFIG LD_NOCONFIG_32 LD_NOCONFIG_64
422 unset LD_NODIRCONFIG LD_NODIRCONFIG_32 LD_NODIRCONFIG_64
423 unset LD_NODIRECT LD_NODIRECT_32 LD_NODIRECT_64
424 unset LD_NOLAZYLOAD LD_NOLAZYLOAD_32 LD_NOLAZYLOAD_64
425 unset LD_NOOBJALTER LD_NOOBJALTER_32 LD_NOOBJALTER_64
426 unset LD_NOVERSION LD_NOVERSION_32 LD_NOVERSION_64
427 unset LD_ORIGIN LD_ORIGIN_32 LD_ORIGIN_64
428 unset LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
429 unset LD_PROFILE LD_PROFILE_32 LD_PROFILE_64
431 unset CONFIG
432 unset GROUP
433 unset OWNER
434 unset REMOTE
435 unset ENV
436 unset ARCH
437 unset CLASSPATH
438 unset NAME
441 # To get ONBLD_TOOLS from the environment, it must come from the env file.
442 # If it comes interactively, it is generally TOOLS_PROTO, which will be
443 # clobbered before the compiler version checks, which will therefore fail.
445 unset ONBLD_TOOLS
448 # Setup environmental variables
450 if [ -f $envfile ]; then
451 . $envfile
452 else
453 echo "Cannot find env file $envfile"
454 exit 1
457 # Check if we have sufficient data to continue...
458 [[ -v SRCTOP ]] || \
459 fatal_error "Error: Variable SRCTOP not set."
460 [[ -d "${SRCTOP}" ]] || \
461 fatal_error "Error: ${SRCTOP} is not a directory."
462 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || \
463 fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
466 # place ourselves in a new task, respecting BUILD_PROJECT if set.
468 if [ -z "$BUILD_PROJECT" ]; then
469 /usr/bin/newtask -c $$
470 else
471 /usr/bin/newtask -c $$ -p $BUILD_PROJECT
474 ps -o taskid= -p $$ | read build_taskid
475 ps -o project= -p $$ | read build_project
478 # See if NIGHTLY_OPTIONS is set
480 if [ "$NIGHTLY_OPTIONS" = "" ]; then
481 NIGHTLY_OPTIONS="-aBm"
485 # Note: changes to the option letters here should also be applied to the
486 # bldenv script. `d' is listed for backward compatibility.
488 NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
489 OPTIND=1
490 while getopts +ABCDdfGIiMmNpRrwW FLAG $NIGHTLY_OPTIONS
492 case $FLAG in
493 A ) A_FLAG=y
495 B ) D_FLAG=y
496 ;; # old version of D
497 C ) C_FLAG=y
499 D ) D_FLAG=y
501 G ) ;;
502 I ) m_FLAG=y
503 p_FLAG=y
505 i ) i_FLAG=y
507 M ) M_FLAG=y
509 m ) m_FLAG=y
511 N ) N_FLAG=y
513 p ) p_FLAG=y
515 R ) m_FLAG=y
516 p_FLAG=y
518 r ) r_FLAG=y
520 w ) w_FLAG=y
522 W ) W_FLAG=y
524 \? ) echo "$USAGE"
525 exit 1
527 esac
528 done
530 if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
531 MAILTO=`/usr/bin/id -un`
532 export MAILTO
535 PATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/bin"
536 PATH="$PATH:/usr/bin:/usr/sbin:/usr/ucb"
537 PATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:.:$OPTHOME/SUNWspro/bin"
538 export PATH
540 # roots of source trees, both relative to $SRC and absolute.
541 relsrcdirs="."
542 abssrcdirs="$SRC"
544 PROTOCMPTERSE="protocmp.terse -gu"
545 POUND_SIGN="#"
546 # have we set RELEASE_DATE in our env file?
547 if [ -z "$RELEASE_DATE" ]; then
548 RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
550 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
551 BASEWSDIR=$(basename $SRCTOP)
552 DEV_CM="\"@(#)illumos Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
553 RELEASE_MICRO=$(( ($(date +%Y) * 12 + $(date +%m) - 1) - (2010 * 12 + 8 - 1) ))
555 # we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
556 # by avoiding repeated shell invocations to evaluate Makefile.master
557 # definitions.
558 export POUND_SIGN RELEASE_DATE DEV_CM RELEASE_MICRO
560 maketype="distributed"
561 if [[ -z "$MAKE" ]]; then
562 MAKE=dmake
563 elif [[ ! -x "$MAKE" ]]; then
564 echo "\$MAKE is set to garbage in the environment"
565 exit 1
567 export PATH
568 export MAKE
570 hostname=$(uname -n)
571 if [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
572 then
573 maxjobs=
574 if [[ -f $HOME/.make.machines ]]
575 then
576 # Note: there is a hard tab and space character in the []s
577 # below.
578 egrep -i "^[ ]*$hostname[ \.]" \
579 $HOME/.make.machines | read host jobs
580 maxjobs=${jobs##*=}
583 if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
584 then
585 # default
586 maxjobs=4
589 export DMAKE_MAX_JOBS=$maxjobs
592 DMAKE_MODE=parallel;
593 export DMAKE_MODE
594 DMAKE_OUTPUT_MODE=TXT2;
595 export DMAKE_OUTPUT_MODE
597 if [ -z "${ROOT}" ]; then
598 echo "ROOT must be set."
599 exit 1
603 # if -V flag was given, reset VERSION to V_ARG
605 if [ "$V_FLAG" = "y" ]; then
606 VERSION=$V_ARG
609 TMPDIR="/tmp/nightly.tmpdir.$$"
610 export TMPDIR
611 rm -rf ${TMPDIR}
612 mkdir -p $TMPDIR || exit 1
614 # Tools should only be built non-DEBUG. Keep track of the tools proto
615 # area path relative to $TOOLS, because the latter changes in an
616 # export build.
618 # TOOLS_PROTO is included below for builds other than usr/src/tools
619 # that look for this location. For usr/src/tools, this will be
620 # overridden on the $MAKE command line in build_tools().
622 TOOLS=${SRC}/tools
623 TOOLS_PROTO_REL=proto/root_${MACH}-nd
624 TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
626 unset CFLAGS LD_LIBRARY_PATH LDFLAGS
628 # create directories that are automatically removed if the nightly script
629 # fails to start correctly
630 function newdir {
631 dir=$1
632 toadd=
633 while [ ! -d $dir ]; do
634 toadd="$dir $toadd"
635 dir=`dirname $dir`
636 done
637 torm=
638 newlist=
639 for dir in $toadd; do
640 if mkdir $dir; then
641 newlist="$dir $newlist"
642 torm="$dir $torm"
643 else
644 [ -z "$torm" ] || rmdir $torm
645 return 1
647 done
648 newdirlist="$newlist $newdirlist"
649 return 0
651 newdirlist=
653 [ -d $SRCTOP ] || newdir $SRCTOP || exit 1
655 # since this script assumes the build is from full source, it nullifies
656 # variables likely to have been set by a "ws" script; nullification
657 # confines the search space for headers and libraries to the proto area
658 # built from this immediate source.
659 ENVLDLIBS1=
660 ENVLDLIBS2=
661 ENVLDLIBS3=
662 ENVCPPFLAGS1=
663 ENVCPPFLAGS2=
664 ENVCPPFLAGS3=
665 ENVCPPFLAGS4=
667 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
668 ENVLDLIBS1 ENVLDLIBS2
671 # Juggle the logs and optionally send mail on completion.
674 function logshuffle {
675 LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
676 if [ -f $LLOG -o -d $LLOG ]; then
677 LLOG=$LLOG.$$
680 rm -f "$ATLOG/latest" 2>/dev/null
681 mkdir $LLOG
682 export LLOG
684 if [ "$build_ok" = "y" ]; then
685 mv $ATLOG/proto_list_${MACH} $LLOG
687 if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
688 mv $ATLOG/proto_list_tools_${MACH} $LLOG
691 if [ -f $TMPDIR/wsdiff.results ]; then
692 mv $TMPDIR/wsdiff.results $LLOG
695 if [ -f $TMPDIR/wsdiff-nd.results ]; then
696 mv $TMPDIR/wsdiff-nd.results $LLOG
700 kill $TEE
701 case "$build_ok" in
703 state=Completed
706 state=Interrupted
709 state=Failed
711 esac
713 if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
714 state=Failed
717 NIGHTLY_STATUS=$state
718 export NIGHTLY_STATUS
720 run_hook POST_NIGHTLY $state
721 run_hook SYS_POST_NIGHTLY $state
723 echo "Subject: Nightly ${MACH} Build of `basename ${SRCTOP}` ${state}." \
724 > ${LLOG}/mail_msg
725 cat $build_time_file $mail_msg_file \
726 >> ${LLOG}/mail_msg
727 if [ "$m_FLAG" = "y" ]; then
728 /usr/bin/mail ${MAILTO} < ${LLOG}/mail_msg
731 mv $LOGFILE $LLOG
733 ln -s "$LLOG" "$ATLOG/latest"
737 # Remove the temporary files on any exit
739 function cleanup {
740 logshuffle
742 set -- $newdirlist
743 while [ $# -gt 0 ]; do
744 rmdir $1
745 shift; shift
746 done
747 rm -rf $TMPDIR
750 function cleanup_signal {
751 build_ok=i
752 # this will trigger cleanup(), above.
753 exit 1
756 trap cleanup 0
757 trap cleanup_signal 1 2 3 15
759 newdirlist=
762 # Create mail_msg_file
764 mail_msg_file="${TMPDIR}/mail_msg"
765 touch $mail_msg_file
766 build_time_file="${TMPDIR}/build_time"
768 mkdir -p "$ATLOG"
770 # Move old LOGFILE aside
772 if [ -f $LOGFILE ]; then
773 mv -f $LOGFILE ${LOGFILE}-
776 mkfifo ${TMPDIR}/err.fifo ${TMPDIR}/out.fifo
777 tee $mail_msg_file < ${TMPDIR}/err.fifo >> $LOGFILE &
778 TEE=$!
779 tee ${TMPDIR}/stdout.txt < ${TMPDIR}/out.fifo >> $LOGFILE &
780 TEE="$TEE $!"
781 exec > ${TMPDIR}/out.fifo
782 exec 2> ${TMPDIR}/err.fifo
785 # Build OsNet source
787 START_DATE=`date`
788 SECONDS=0
789 echo "\n==== Nightly $maketype build started: $START_DATE ====" | \
790 tee -a $build_time_file
792 run_hook SYS_PRE_NIGHTLY
793 run_hook PRE_NIGHTLY
795 echo "\n==== list of environment variables ====\n"
798 echo "Building $VERSION
799 on $(uname -srv)" >&2
801 if [[ ! -f $SRC/Makefile ]]; then
802 build_ok=n
803 echo "\nUnable to find \"Makefile\" in $SRC." >&2
804 exit 1
807 # Save the current proto area if we're comparing against the last build
808 if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
809 if [ -d "$ROOT.prev" ]; then
810 rm -rf $ROOT.prev
812 mv $ROOT $ROOT.prev
815 # Safeguards
816 [[ -v SRCTOP ]] || fatal_error "Error: Variable SRCTOP not set."
817 [[ -d "${SRCTOP}" ]] || fatal_error "Error: ${SRCTOP} is not a directory."
818 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
821 # Generate the cfgparam files
823 # We have to do this before running *any* make commands.
825 make gen-config || fatal_error "gen-config failed"
828 # Decide whether to clobber
830 if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
831 echo "\n==== Make clobber at `date` ====\n"
832 echo "\n==== clobber / cleandir ===="
834 cd $SRC
835 # remove old clobber file
836 rm -f $SRC/clobber.out
837 rm -f $SRC/clobber-${MACH}.out
839 # Remove all .make.state* files, just in case we are restarting
840 # the build after having interrupted a previous 'make clobber'.
841 find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
842 -o -name 'interfaces.*' \) -prune \
843 -o -name '.make.*' -print | xargs rm -f
844 if ! $MAKE -ek clobber; then
845 build_extras_ok=n
848 echo "\n==== Make tools clobber at `date` ====\n"
849 cd ${TOOLS}
850 rm -f ${TOOLS}/clobber-${MACH}.out
852 if ! $MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber; then
853 build_extras_ok=n
855 rm -rf ${TOOLS_PROTO}
856 mkdir -p ${TOOLS_PROTO}
858 typeset roots=$ROOT
859 echo "\n\nClearing $roots"
860 rm -rf $roots
862 # Get back to a clean workspace as much as possible to catch
863 # problems that only occur on fresh workspaces.
864 # Remove all .make.state* files, libraries, and .o's that may
865 # have been omitted from clobber. A couple of libraries are
866 # under source code control, so leave them alone.
867 # We should probably blow away temporary directories too.
868 cd $SRC
869 find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
870 -o -name .git -o -name 'interfaces.*' \) -prune -o \
871 \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
872 -name '*.o' \) -print | \
873 grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
874 make -C $SRCTOP cleandir
875 else
876 echo "\n==== No clobber at `date` ====\n"
880 # Build and use the workspace's tools if requested
882 set_non_debug_build_flags
884 build_tools ${TOOLS_PROTO}
885 if (( $? != 0 )); then
886 build_ok=n
887 else
888 use_tools $TOOLS_PROTO
891 normal_build
893 ORIG_SRC=$SRC
894 BINARCHIVE=${SRCTOP}/bin-${MACH}.cpio.Z
896 if [ "$build_ok" = "y" ]; then
897 echo "\n==== Creating protolist system file at `date` ====" \
898 protolist $ROOT > $ATLOG/proto_list_${MACH}
899 echo "==== protolist system file created at `date` ====\n" \
901 if [ "$N_FLAG" != "y" ]; then
905 for f in $f1; do
906 if [ -f "$f" ]; then
907 E1="$E1 -e $f"
909 done
913 if [ -d "$SRC/pkg" ]; then
914 f2="$f2 exceptions/packaging"
917 for f in $f2; do
918 if [ -f "$f" ]; then
919 E2="$E2 -e $f"
921 done
924 if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
925 echo "\n==== Validating manifests against proto area (protocmp) ====\n" >&2
926 if ! ( cd $SRC/pkg ; /bin/time $MAKE -e protocmp ROOT="$ROOT" ) >&2; then
927 build_extras_ok=n
933 # ELF verification: ABI (-A) and runtime (-r) checks
935 if [[ ($build_ok = y) && (($A_FLAG = y) || ($r_FLAG = y)) ]]; then
936 # Directory ELF-data.$MACH holds the files produced by these tests.
937 elf_ddir=$TMPDIR/ELF-data.$MACH
938 mkdir -p $elf_ddir
940 # Call find_elf to produce a list of the ELF objects in the proto area.
941 # This list is passed to check_rtime and interface_check, preventing
942 # them from separately calling find_elf to do the same work twice.
943 find_elf -fr $ROOT > $elf_ddir/object_list
945 if [[ $A_FLAG = y ]]; then
946 echo "\n==== Check versioning and ABI information (interface_check) ====\n" >&2
948 # Produce interface description for the proto. Report errors.
949 /bin/time interface_check -o -w $elf_ddir -f object_list \
950 -i interface -E interface.err
951 if [[ -s $elf_ddir/interface.err ]]; then
952 cat $elf_ddir/interface.err >&2
953 build_extras_ok=n
958 if [[ $r_FLAG = y ]]; then
959 echo "\n==== Check ELF runtime attributes (check_rtime) ====\n" >&2
961 # If we're doing a DEBUG build the proto area will be left
962 # with debuggable objects, thus don't assert -s.
963 if [[ $D_FLAG = y ]]; then
964 rtime_sflag=""
965 else
966 rtime_sflag="-s"
968 /bin/time check_rtime -i -v $rtime_sflag -o -w $elf_ddir \
969 -D object_list -f object_list -E runtime.err \
970 -I runtime.attr.raw
971 if (( $? != 0 )); then
972 build_extras_ok=n
975 # Report errors
976 if [[ -s $elf_ddir/runtime.err ]]; then
977 cat $elf_ddir/runtime.err >&2
978 build_extras_ok=n
983 # "make check" begins
985 if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
986 # remove old check.out
987 rm -f $SRC/check.out
989 rm -f $SRC/check-${MACH}.out
990 cd $SRC
991 echo "\n==== dmake check ====\n" >&2
992 if ! /bin/time $MAKE -ek check ROOT="$ROOT"; then
993 build_extras_ok=n
995 else
996 echo "\n==== No '$MAKE check' ====\n"
999 echo "\n==== Find core files ====\n" >&2
1001 find $abssrcdirs -name core -a -type f -exec file {} \; >&2
1003 # Verify that the usual lists of files, such as exception lists,
1004 # contain only valid references to files. If the build has failed,
1005 # then don't check the proto area.
1006 CHECK_PATHS=${CHECK_PATHS:-y}
1007 if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
1008 echo "\n==== Check lists of files ====\n" >&2
1009 arg=-b
1010 [ "$build_ok" = y ] && arg=
1011 checkpaths $arg $ROOT > $TMPDIR/check-paths.out 2>&1
1012 if [[ -s $TMPDIR/check-paths.out ]]; then
1013 cat $TMPDIR/check-paths.out >&2
1014 build_extras_ok=n
1018 if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
1019 echo "\n==== Impact on file permissions ====\n" >&2
1021 abspkg=
1022 for d in $abssrcdirs; do
1023 if [ -d "$d/pkg" ]; then
1024 abspkg="$abspkg $d"
1026 done
1028 if [ -n "$abspkg" ]; then
1029 for d in "$abspkg"; do
1030 ( cd $d/pkg ; $MAKE -e pmodes ) >&2
1031 done
1035 if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
1036 if [[ "$D_FLAG" = y ]]; then
1037 do_wsdiff DEBUG $ROOT.prev $ROOT
1038 else
1039 do_wsdiff non-DEBUG $ROOT.prev $ROOT
1043 END_DATE=`date`
1044 echo "==== Nightly $maketype build completed: $END_DATE ====" | \
1045 tee -a $build_time_file
1047 typeset -i10 hours
1048 typeset -Z2 minutes
1049 typeset -Z2 seconds
1051 elapsed_time=$SECONDS
1052 ((hours = elapsed_time / 3600 ))
1053 ((minutes = elapsed_time / 60 % 60))
1054 ((seconds = elapsed_time % 60))
1056 echo "Total build time ${hours}:${minutes}:${seconds}" |
1057 tee -a $build_time_file
1060 # All done save for the sweeping up.
1061 # (whichever exit we hit here will trigger the "cleanup" trap which
1062 # optionally sends mail on completion).
1064 if [[ "$build_ok" == "y" ]]; then
1065 if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
1066 exit 0
1070 exit 1