libc: rename struct FTW quit to __quit
[unleashed/lotheac.git] / tools / nightly.sh
blob0ab51a30a56155b2dd0be58606ac63a7456912c8
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
136 echo "\n==== bmake -C include all install\n" >&2
138 # Before we build anything via dmake, we need to install
139 # bmake-ified headers and libs to the proto area
141 if ! make -j$DMAKE_MAX_JOBS -C $SRCTOP/include all DESTDIR=$ROOT; then
142 build_ok=n
143 this_build_ok=n
144 fatal_error "cannot install headers"
146 if ! make -j$DMAKE_MAX_JOBS -C $SRCTOP/include install DESTDIR=$ROOT; then
147 build_ok=n
148 this_build_ok=n
149 fatal_error "cannot install headers"
151 echo "\n==== bmake -C lib build\n" >&2
152 if ! make -j$DMAKE_MAX_JOBS -C $SRCTOP/lib build DESTDIR=$ROOT; then
153 build_ok=n
154 this_build_ok=n
155 fatal_error "cannot install libraries"
159 # Build the legacy part of the source
161 echo "\n==== Building legacy source at `date` ($LABEL) ====\n"
163 cd $SRC
164 echo "\n==== dmake install ====\n" >&2
165 if ! /bin/time $MAKE -e install; then
166 build_ok=n
167 this_build_ok=n
171 # Build the new part of the source
173 echo "\n==== bmake build ====\n" >&2
174 if ! /bin/time env -i PATH=${GNUC_ROOT}/bin:/usr/bin \
175 SRCTOP=$SRCTOP \
176 make -C $SRCTOP -j $DMAKE_MAX_JOBS VERBOSE=yes build DESTDIR=$ROOT; then
177 build_ok=n
178 this_build_ok=n
181 echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n"
184 # Building Packages
186 if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
187 if [ -d $SRC/pkg ]; then
188 echo "\n==== Creating $LABEL packages at `date` ====\n"
189 echo "Clearing out $PKGARCHIVE ..."
190 rm -rf $PKGARCHIVE
191 mkdir -p $PKGARCHIVE
193 rm -f $SRC/pkg/${INSTALLOG}.out
194 cd $SRC/pkg
195 echo "\n==== dmake -C $SRC/pkg install ====\n" >&2
196 if ! /bin/time $MAKE -e install; then
197 build_extras_ok=n
198 this_build_ok=n
200 else
202 # Handle it gracefully if -p was set but there so
203 # no pkg directory.
205 echo "\n==== No $LABEL packages to build ====\n"
207 else
208 echo "\n==== Not creating $LABEL packages ====\n"
213 # Build and install the onbld tools.
215 # usage: build_tools DESTROOT
217 # returns non-zero status if the build was successful.
219 function build_tools {
220 DESTROOT=$1
222 INSTALLOG=install-${MACH}
224 echo "\n==== Building tools at `date` ====\n" \
226 rm -f ${TOOLS}/${INSTALLOG}.out
227 cd ${TOOLS}
228 if ! $MAKE TOOLS_PROTO=${DESTROOT} -e install; then
229 return 1
231 return 0
235 # Set up to use locally installed tools.
237 # usage: use_tools TOOLSROOT
239 function use_tools {
240 TOOLSROOT=$1
243 # If we're not building ON workspace, then the TOOLSROOT
244 # settings here are clearly ignored by the workspace
245 # makefiles, prepending nonexistent directories to PATH is
246 # harmless, and we clearly do not wish to override
247 # ONBLD_TOOLS.
249 # If we're building an ON workspace, then the prepended PATH
250 # elements should supercede the preexisting ONBLD_TOOLS paths,
251 # and we want to override ONBLD_TOOLS to catch the tools that
252 # don't have specific path env vars here.
254 # So the only conditional behavior is overriding ONBLD_TOOLS,
255 # and we check for "an ON workspace" by looking for
256 # ${TOOLSROOT}/opt/onbld.
259 STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
260 export STABS
261 CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
262 export CTFSTABS
263 GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
264 export GENOFFSETS
267 PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
268 PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
269 export PATH
271 if [ -d "${TOOLSROOT}/opt/onbld" ]; then
272 ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
273 export ONBLD_TOOLS
276 echo "\n==== New environment settings. ====\n"
277 echo "STABS=${STABS}"
278 echo "CTFSTABS=${CTFSTABS}"
279 echo "PATH=${PATH}"
280 echo "ONBLD_TOOLS=${ONBLD_TOOLS}"
284 # wrapper over wsdiff.
285 # usage: do_wsdiff LABEL OLDPROTO NEWPROTO
287 function do_wsdiff {
288 label=$1
289 oldproto=$2
290 newproto=$3
292 wsdiff="wsdiff -t"
294 echo "\n==== Getting object changes since last build at `date`" \
295 "($label) ====\n" >&2
296 $wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto >&2
297 echo "\n==== Object changes determined at `date` ($label) ====\n" >&2
301 # Functions for setting build flags (DEBUG/non-DEBUG). Keep them
302 # together.
305 function set_non_debug_build_flags {
306 export RELEASE_BUILD ; RELEASE_BUILD=
307 unset EXTRA_OPTIONS
308 unset EXTRA_CFLAGS
311 function set_debug_build_flags {
312 unset RELEASE_BUILD
313 unset EXTRA_OPTIONS
314 unset EXTRA_CFLAGS
318 MACH=`uname -p`
320 if [ "$OPTHOME" = "" ]; then
321 OPTHOME=/opt
322 export OPTHOME
325 USAGE='Usage: nightly [-in] [-V VERS ] [env_file]
327 Where:
328 -i Fast incremental options (no clobber, check)
329 -V VERS set the build version string to VERS
331 <env_file> file in Bourne shell syntax that sets and exports
332 variables that configure the operation of this script and many of
333 the scripts this one calls.
335 non-DEBUG is the default build type. Build options can be set in the
336 NIGHTLY_OPTIONS variable in the <env_file> as follows:
338 -A check for ABI differences in .so files
339 -C check for cstyle/hdrchk errors
340 -D do a build with DEBUG on
341 -G gate keeper default group of options (-au)
342 -I integration engineer default group of options (-ampu)
343 -M do not run pmodes (safe file permission checker)
344 -N do not run protocmp
345 -R default group of options for building a release (-mp)
346 -U update proto area in the parent
347 -V VERS set the build version string to VERS
348 -i do an incremental build (no "make clobber")
349 -m send mail to $MAILTO at end of build
350 -p create packages
351 -r check ELF runtime attributes in the proto area
352 -u update proto_list_$MACH and friends in the parent workspace
353 -w report on differences between previous and current proto areas
356 # A log file will be generated under the name $LOGFILE
357 # for partially completed build and log.`date '+%F'`
358 # in the same directory for fully completed builds.
361 # default values for low-level FLAGS; G I R are group FLAGS
362 A_FLAG=n
363 C_FLAG=n
364 D_FLAG=n
365 i_FLAG=n; i_CMD_LINE_FLAG=n
366 M_FLAG=n
367 m_FLAG=n
368 N_FLAG=n
369 p_FLAG=n
370 r_FLAG=n
371 V_FLAG=n
372 w_FLAG=n
373 W_FLAG=n
375 build_ok=y
376 build_extras_ok=y
379 # examine arguments
382 OPTIND=1
383 while getopts +iV:W FLAG
385 case $FLAG in
386 i ) i_FLAG=y; i_CMD_LINE_FLAG=y
388 V ) V_FLAG=y
389 V_ARG="$OPTARG"
391 W ) W_FLAG=y
393 \? ) echo "$USAGE"
394 exit 1
396 esac
397 done
399 # correct argument count after options
400 shift `expr $OPTIND - 1`
402 # test that the path to the environment-setting file was given
403 if [ $# -ne 1 ]; then
404 envfile=$(dirname $0)/env.sh
405 else
406 envfile=$1
410 # force locale to C
411 LANG=C; export LANG
412 LC_ALL=C; export LC_ALL
413 LC_COLLATE=C; export LC_COLLATE
414 LC_CTYPE=C; export LC_CTYPE
415 LC_MESSAGES=C; export LC_MESSAGES
416 LC_MONETARY=C; export LC_MONETARY
417 LC_NUMERIC=C; export LC_NUMERIC
418 LC_TIME=C; export LC_TIME
420 # clear environment variables we know to be bad for the build
421 unset LD_OPTIONS
422 unset LD_AUDIT LD_AUDIT_32 LD_AUDIT_64
423 unset LD_BIND_NOW LD_BIND_NOW_32 LD_BIND_NOW_64
424 unset LD_BREADTH LD_BREADTH_32 LD_BREADTH_64
425 unset LD_CONFIG LD_CONFIG_32 LD_CONFIG_64
426 unset LD_DEBUG LD_DEBUG_32 LD_DEBUG_64
427 unset LD_DEMANGLE LD_DEMANGLE_32 LD_DEMANGLE_64
428 unset LD_FLAGS LD_FLAGS_32 LD_FLAGS_64
429 unset LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64
430 unset LD_LOADFLTR LD_LOADFLTR_32 LD_LOADFLTR_64
431 unset LD_NOAUDIT LD_NOAUDIT_32 LD_NOAUDIT_64
432 unset LD_NOAUXFLTR LD_NOAUXFLTR_32 LD_NOAUXFLTR_64
433 unset LD_NOCONFIG LD_NOCONFIG_32 LD_NOCONFIG_64
434 unset LD_NODIRCONFIG LD_NODIRCONFIG_32 LD_NODIRCONFIG_64
435 unset LD_NODIRECT LD_NODIRECT_32 LD_NODIRECT_64
436 unset LD_NOLAZYLOAD LD_NOLAZYLOAD_32 LD_NOLAZYLOAD_64
437 unset LD_NOOBJALTER LD_NOOBJALTER_32 LD_NOOBJALTER_64
438 unset LD_NOVERSION LD_NOVERSION_32 LD_NOVERSION_64
439 unset LD_ORIGIN LD_ORIGIN_32 LD_ORIGIN_64
440 unset LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
441 unset LD_PROFILE LD_PROFILE_32 LD_PROFILE_64
443 unset CONFIG
444 unset GROUP
445 unset OWNER
446 unset REMOTE
447 unset ENV
448 unset ARCH
449 unset CLASSPATH
450 unset NAME
453 # To get ONBLD_TOOLS from the environment, it must come from the env file.
454 # If it comes interactively, it is generally TOOLS_PROTO, which will be
455 # clobbered before the compiler version checks, which will therefore fail.
457 unset ONBLD_TOOLS
460 # Setup environmental variables
462 if [ -f $envfile ]; then
463 . $envfile
464 else
465 echo "Cannot find env file $envfile"
466 exit 1
469 # Check if we have sufficient data to continue...
470 [[ -n "$SRCTOP" ]] || \
471 fatal_error "Error: Variable SRCTOP not set."
472 [[ -d "${SRCTOP}" ]] || \
473 fatal_error "Error: ${SRCTOP} is not a directory."
474 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || \
475 fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
478 # place ourselves in a new task, respecting BUILD_PROJECT if set.
480 if [ -z "$BUILD_PROJECT" ]; then
481 /usr/bin/newtask -c $$
482 else
483 /usr/bin/newtask -c $$ -p $BUILD_PROJECT
486 ps -o taskid= -p $$ | read build_taskid
487 ps -o project= -p $$ | read build_project
490 # See if NIGHTLY_OPTIONS is set
492 if [ "$NIGHTLY_OPTIONS" = "" ]; then
493 NIGHTLY_OPTIONS="-aBm"
497 # Note: changes to the option letters here should also be applied to the
498 # bldenv script. `d' is listed for backward compatibility.
500 NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
501 OPTIND=1
502 while getopts +ABCDdfGIiMmNpRrwW FLAG $NIGHTLY_OPTIONS
504 case $FLAG in
505 A ) A_FLAG=y
507 B ) D_FLAG=y
508 ;; # old version of D
509 C ) C_FLAG=y
511 D ) D_FLAG=y
513 G ) ;;
514 I ) m_FLAG=y
515 p_FLAG=y
517 i ) i_FLAG=y
519 M ) M_FLAG=y
521 m ) m_FLAG=y
523 N ) N_FLAG=y
525 p ) p_FLAG=y
527 R ) m_FLAG=y
528 p_FLAG=y
530 r ) r_FLAG=y
532 w ) w_FLAG=y
534 W ) W_FLAG=y
536 \? ) echo "$USAGE"
537 exit 1
539 esac
540 done
542 if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
543 MAILTO=`/usr/bin/id -un`
544 export MAILTO
547 PATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/bin"
548 PATH="$PATH:/usr/bin:/usr/sbin:/usr/ucb"
549 PATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:.:$OPTHOME/SUNWspro/bin"
550 export PATH
552 # roots of source trees, both relative to $SRC and absolute.
553 relsrcdirs="."
554 abssrcdirs="$SRC"
556 PROTOCMPTERSE="protocmp.terse -gu"
557 POUND_SIGN="#"
558 # have we set RELEASE_DATE in our env file?
559 if [ -z "$RELEASE_DATE" ]; then
560 RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
562 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
563 BASEWSDIR=$(basename $SRCTOP)
565 # we export POUND_SIGN and RELEASE_DATE to speed up the build process
566 # by avoiding repeated shell invocations to evaluate Makefile.master
567 # definitions.
568 export POUND_SIGN RELEASE_DATE
570 maketype="distributed"
571 if [[ -z "$MAKE" ]]; then
572 MAKE=dmake
573 elif [[ ! -x "$MAKE" ]]; then
574 echo "\$MAKE is set to garbage in the environment"
575 exit 1
577 export PATH
578 export MAKE
580 hostname=$(uname -n)
581 if [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
582 then
583 maxjobs=
584 if [[ -f $HOME/.make.machines ]]
585 then
586 # Note: there is a hard tab and space character in the []s
587 # below.
588 egrep -i "^[ ]*$hostname[ \.]" \
589 $HOME/.make.machines | read host jobs
590 maxjobs=${jobs##*=}
593 if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
594 then
595 # default
596 maxjobs=4
599 export DMAKE_MAX_JOBS=$maxjobs
602 DMAKE_MODE=parallel;
603 export DMAKE_MODE
604 DMAKE_OUTPUT_MODE=TXT2;
605 export DMAKE_OUTPUT_MODE
607 if [ -z "${ROOT}" ]; then
608 echo "ROOT must be set."
609 exit 1
613 # if -V flag was given, reset VERSION to V_ARG
615 if [ "$V_FLAG" = "y" ]; then
616 VERSION=$V_ARG
619 TMPDIR="/tmp/nightly.tmpdir.$$"
620 export TMPDIR
621 rm -rf ${TMPDIR}
622 mkdir -p $TMPDIR || exit 1
624 # Tools should only be built non-DEBUG. Keep track of the tools proto
625 # area path relative to $TOOLS, because the latter changes in an
626 # export build.
628 # TOOLS_PROTO is included below for builds other than usr/src/tools
629 # that look for this location. For usr/src/tools, this will be
630 # overridden on the $MAKE command line in build_tools().
632 TOOLS=${SRC}/tools
633 TOOLS_PROTO_REL=proto/root_${MACH}-nd
634 TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
636 unset CFLAGS LD_LIBRARY_PATH LDFLAGS
638 # create directories that are automatically removed if the nightly script
639 # fails to start correctly
640 function newdir {
641 dir=$1
642 toadd=
643 while [ ! -d $dir ]; do
644 toadd="$dir $toadd"
645 dir=`dirname $dir`
646 done
647 torm=
648 newlist=
649 for dir in $toadd; do
650 if mkdir $dir; then
651 newlist="$dir $newlist"
652 torm="$dir $torm"
653 else
654 [ -z "$torm" ] || rmdir $torm
655 return 1
657 done
658 newdirlist="$newlist $newdirlist"
659 return 0
661 newdirlist=
663 [ -d $SRCTOP ] || newdir $SRCTOP || exit 1
665 # since this script assumes the build is from full source, it nullifies
666 # variables likely to have been set by a "ws" script; nullification
667 # confines the search space for headers and libraries to the proto area
668 # built from this immediate source.
669 ENVLDLIBS1=
670 ENVLDLIBS2=
671 ENVLDLIBS3=
672 ENVCPPFLAGS1=
673 ENVCPPFLAGS2=
674 ENVCPPFLAGS3=
675 ENVCPPFLAGS4=
677 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
678 ENVLDLIBS1 ENVLDLIBS2
681 # Juggle the logs and optionally send mail on completion.
684 function logshuffle {
685 LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
686 if [ -f $LLOG -o -d $LLOG ]; then
687 LLOG=$LLOG.$$
690 rm -f "$ATLOG/latest" 2>/dev/null
691 mkdir $LLOG
692 export LLOG
694 if [ "$build_ok" = "y" ]; then
695 mv $ATLOG/proto_list_${MACH} $LLOG
697 if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
698 mv $ATLOG/proto_list_tools_${MACH} $LLOG
701 if [ -f $TMPDIR/wsdiff.results ]; then
702 mv $TMPDIR/wsdiff.results $LLOG
705 if [ -f $TMPDIR/wsdiff-nd.results ]; then
706 mv $TMPDIR/wsdiff-nd.results $LLOG
710 kill $TEE
711 case "$build_ok" in
713 state=Completed
716 state=Interrupted
719 state=Failed
721 esac
723 if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
724 state=Failed
727 NIGHTLY_STATUS=$state
728 export NIGHTLY_STATUS
730 run_hook POST_NIGHTLY $state
731 run_hook SYS_POST_NIGHTLY $state
733 echo "Subject: Nightly ${MACH} Build of `basename ${SRCTOP}` ${state}." \
734 > ${LLOG}/mail_msg
735 cat $build_time_file $mail_msg_file \
736 >> ${LLOG}/mail_msg
737 if [ "$m_FLAG" = "y" ]; then
738 /usr/bin/mail ${MAILTO} < ${LLOG}/mail_msg
741 mv $LOGFILE $LLOG
743 ln -s "$LLOG" "$ATLOG/latest"
747 # Remove the temporary files on any exit
749 function cleanup {
750 logshuffle
752 set -- $newdirlist
753 while [ $# -gt 0 ]; do
754 rmdir $1
755 shift; shift
756 done
757 rm -rf $TMPDIR
760 function cleanup_signal {
761 build_ok=i
762 # this will trigger cleanup(), above.
763 exit 1
766 trap cleanup 0
767 trap cleanup_signal 1 2 3 15
769 newdirlist=
772 # Create mail_msg_file
774 mail_msg_file="${TMPDIR}/mail_msg"
775 touch $mail_msg_file
776 build_time_file="${TMPDIR}/build_time"
778 mkdir -p "$ATLOG"
780 # Move old LOGFILE aside
782 if [ -f $LOGFILE ]; then
783 mv -f $LOGFILE ${LOGFILE}-
786 mkfifo ${TMPDIR}/err.fifo ${TMPDIR}/out.fifo
787 tee $mail_msg_file < ${TMPDIR}/err.fifo >> $LOGFILE &
788 TEE=$!
789 tee ${TMPDIR}/stdout.txt < ${TMPDIR}/out.fifo >> $LOGFILE &
790 TEE="$TEE $!"
791 exec > ${TMPDIR}/out.fifo
792 exec 2> ${TMPDIR}/err.fifo
795 # Build OsNet source
797 START_DATE=`date`
798 SECONDS=0
799 echo "\n==== Nightly $maketype build started: $START_DATE ====" | \
800 tee -a $build_time_file
802 run_hook SYS_PRE_NIGHTLY
803 run_hook PRE_NIGHTLY
805 echo "\n==== list of environment variables ====\n"
808 echo "Building $VERSION
809 on $(uname -srv)" >&2
811 if [[ ! -f $SRC/Makefile ]]; then
812 build_ok=n
813 echo "\nUnable to find \"Makefile\" in $SRC." >&2
814 exit 1
817 # Save the current proto area if we're comparing against the last build
818 if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
819 if [ -d "$ROOT.prev" ]; then
820 rm -rf $ROOT.prev
822 mv $ROOT $ROOT.prev
825 # Safeguards
826 [[ -n "${SRCTOP}" ]] || fatal_error "Error: Variable SRCTOP not set."
827 [[ -d "${SRCTOP}" ]] || fatal_error "Error: ${SRCTOP} is not a directory."
828 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
831 # Generate the cfgparam files
833 # We have to do this before running *any* make commands.
835 make gen-config || fatal_error "gen-config failed"
838 # Decide whether to clobber
840 if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
841 echo "\n==== Make clobber at `date` ====\n"
842 echo "\n==== clobber / cleandir ===="
844 cd $SRC
845 # remove old clobber file
846 rm -f $SRC/clobber.out
847 rm -f $SRC/clobber-${MACH}.out
849 # Remove all .make.state* files, just in case we are restarting
850 # the build after having interrupted a previous 'make clobber'.
851 find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
852 -o -name 'interfaces.*' \) -prune \
853 -o -name '.make.*' -print | xargs rm -f
854 if ! $MAKE -ek clobber; then
855 build_extras_ok=n
858 echo "\n==== Make tools clobber at `date` ====\n"
859 cd ${TOOLS}
860 rm -f ${TOOLS}/clobber-${MACH}.out
862 if ! $MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber; then
863 build_extras_ok=n
865 rm -rf ${TOOLS_PROTO}
866 mkdir -p ${TOOLS_PROTO}
868 typeset roots=$ROOT
869 echo "\n\nClearing $roots"
870 rm -rf $roots
872 # Get back to a clean workspace as much as possible to catch
873 # problems that only occur on fresh workspaces.
874 # Remove all .make.state* files, libraries, and .o's that may
875 # have been omitted from clobber. A couple of libraries are
876 # under source code control, so leave them alone.
877 # We should probably blow away temporary directories too.
878 cd $SRC
879 find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
880 -o -name .git -o -name 'interfaces.*' \) -prune -o \
881 \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
882 -name '*.o' \) -print | \
883 grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
884 make -C $SRCTOP cleandir
885 else
886 echo "\n==== No clobber at `date` ====\n"
890 # Build and use the workspace's tools if requested
892 set_non_debug_build_flags
894 build_tools ${TOOLS_PROTO}
895 if (( $? != 0 )); then
896 build_ok=n
897 else
898 use_tools $TOOLS_PROTO
901 normal_build
903 ORIG_SRC=$SRC
905 if [ "$build_ok" = "y" ]; then
906 echo "\n==== Creating protolist system file at `date` ====" \
907 protolist $ROOT > $ATLOG/proto_list_${MACH}
908 echo "==== protolist system file created at `date` ====\n" \
910 if [ "$N_FLAG" != "y" ]; then
914 for f in $f1; do
915 if [ -f "$f" ]; then
916 E1="$E1 -e $f"
918 done
922 if [ -d "$SRC/pkg" ]; then
923 f2="$f2 exceptions/packaging"
926 for f in $f2; do
927 if [ -f "$f" ]; then
928 E2="$E2 -e $f"
930 done
933 if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
934 echo "\n==== Validating manifests against proto area (protocmp) ====\n" >&2
935 if ! ( cd $SRC/pkg ; /bin/time $MAKE -e protocmp ROOT="$ROOT" ) >&2; then
936 build_extras_ok=n
942 # ELF verification: ABI (-A) and runtime (-r) checks
944 if [ "$build_ok" = y -a '(' "$A_FLAG" = y -o "$r_FLAG" = y ')' ]; then
945 # Directory ELF-data.$MACH holds the files produced by these tests.
946 elf_ddir=$TMPDIR/ELF-data.$MACH
947 mkdir -p $elf_ddir
949 # Call find_elf to produce a list of the ELF objects in the proto area.
950 # This list is passed to check_rtime and interface_check, preventing
951 # them from separately calling find_elf to do the same work twice.
952 find_elf -fr $ROOT > $elf_ddir/object_list
954 if [[ $A_FLAG = y ]]; then
955 echo "\n==== Check versioning and ABI information (interface_check) ====\n" >&2
957 # Produce interface description for the proto. Report errors.
958 /bin/time interface_check -o -w $elf_ddir -f object_list \
959 -i interface -E interface.err
960 if [[ -s $elf_ddir/interface.err ]]; then
961 cat $elf_ddir/interface.err >&2
962 build_extras_ok=n
967 if [[ $r_FLAG = y ]]; then
968 echo "\n==== Check ELF runtime attributes (check_rtime) ====\n" >&2
970 # If we're doing a DEBUG build the proto area will be left
971 # with debuggable objects, thus don't assert -s.
972 if [[ $D_FLAG = y ]]; then
973 rtime_sflag=""
974 else
975 rtime_sflag="-s"
977 /bin/time check_rtime -i -v $rtime_sflag -o -w $elf_ddir \
978 -D object_list -f object_list -E runtime.err \
979 -I runtime.attr.raw
980 if (( $? != 0 )); then
981 build_extras_ok=n
984 # Report errors
985 if [[ -s $elf_ddir/runtime.err ]]; then
986 cat $elf_ddir/runtime.err >&2
987 build_extras_ok=n
992 # "make check" begins
994 if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
995 # remove old check.out
996 rm -f $SRC/check.out
998 rm -f $SRC/check-${MACH}.out
999 cd $SRC
1000 echo "\n==== dmake check ====\n" >&2
1001 if ! /bin/time $MAKE -ek check ROOT="$ROOT"; then
1002 build_extras_ok=n
1004 else
1005 echo "\n==== No '$MAKE check' ====\n"
1008 echo "\n==== Find core files ====\n" >&2
1010 find $abssrcdirs -name core -a -type f -exec file {} \; >&2
1012 # Verify that the usual lists of files, such as exception lists,
1013 # contain only valid references to files. If the build has failed,
1014 # then don't check the proto area.
1015 CHECK_PATHS=${CHECK_PATHS:-y}
1016 if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
1017 echo "\n==== Check lists of files ====\n" >&2
1018 arg=-b
1019 [ "$build_ok" = y ] && arg=
1020 checkpaths $arg $ROOT > $TMPDIR/check-paths.out 2>&1
1021 if [[ -s $TMPDIR/check-paths.out ]]; then
1022 cat $TMPDIR/check-paths.out >&2
1023 build_extras_ok=n
1027 if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
1028 echo "\n==== Impact on file permissions ====\n" >&2
1030 abspkg=
1031 for d in $abssrcdirs; do
1032 if [ -d "$d/pkg" ]; then
1033 abspkg="$abspkg $d"
1035 done
1037 if [ -n "$abspkg" ]; then
1038 for d in "$abspkg"; do
1039 ( cd $d/pkg ; $MAKE -e pmodes ) >&2
1040 done
1044 if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
1045 if [[ "$D_FLAG" = y ]]; then
1046 do_wsdiff DEBUG $ROOT.prev $ROOT
1047 else
1048 do_wsdiff non-DEBUG $ROOT.prev $ROOT
1052 END_DATE=`date`
1053 echo "==== Nightly $maketype build completed: $END_DATE ====" | \
1054 tee -a $build_time_file
1056 typeset -i10 hours
1057 typeset -Z2 minutes
1058 typeset -Z2 seconds
1060 elapsed_time=$SECONDS
1061 hours=$(( elapsed_time / 3600 ))
1062 minutes=$(( elapsed_time / 60 % 60 ))
1063 seconds=$((elapsed_time % 60 ))
1065 echo "Total build time ${hours}:${minutes}:${seconds}" |
1066 tee -a $build_time_file
1069 # All done save for the sweeping up.
1070 # (whichever exit we hit here will trigger the "cleanup" trap which
1071 # optionally sends mail on completion).
1073 if [[ "$build_ok" == "y" ]]; then
1074 if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
1075 exit 0
1079 exit 1