kernel: convert BREAD/BWRITE/BWRITE2/GETBLK/bdwrite to static inlines
[unleashed.git] / tools / nightly.sh
blob3642ee29a58a2baee5fe0e026576fbb48e1480c4
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`
52 function fatal_error
54 print -u2 "nightly: $*"
55 exit 1
59 # Function to do a DEBUG and non-DEBUG build. Needed because we might
60 # need to do another for the source build, and since we only deliver DEBUG or
61 # non-DEBUG packages.
63 # usage: normal_build
65 function normal_build {
67 typeset orig_p_FLAG="$p_FLAG"
69 if [ "$D_FLAG" = "n" ]; then
70 set_non_debug_build_flags
71 build "non-DEBUG"
72 else
73 set_debug_build_flags
74 build "DEBUG"
77 p_FLAG="$orig_p_FLAG"
81 # usage: run_hook HOOKNAME ARGS...
83 # If variable "$HOOKNAME" is defined, insert a section header into
84 # our logs and then run the command with ARGS
86 function run_hook {
87 HOOKNAME=$1
88 eval HOOKCMD=\$$HOOKNAME
89 shift
91 if [ -n "$HOOKCMD" ]; then
93 echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
94 ( $HOOKCMD "$@" 2>&1 )
95 if [ "$?" -ne 0 ]; then
96 # Let exit status propagate up
97 touch $TMPDIR/abort
101 if [ -f $TMPDIR/abort ]; then
102 build_ok=n
103 echo "\nAborting at request of $HOOKNAME"
104 exit 1
109 # Return library search directive as function of given root.
110 function myldlibs {
111 echo "-L$1/lib -L$1/usr/lib"
114 # Return header search directive as function of given root.
115 function myheaders {
116 echo "-I$1/usr/include"
120 # Function to do the build, including package generation.
121 # usage: build LABEL
122 # - LABEL is used to tag build output.
124 function build {
125 LABEL=$1
126 INSTALLOG=install-${MACH}
128 export ROOT
130 export ENVLDLIBS1=`myldlibs $ROOT`
131 export ENVCPPFLAGS1=`myheaders $ROOT`
133 this_build_ok=y
136 # Before we build anything via dmake, we need to install
137 # bmake-ified headers to the proto area
139 if ! make -C $SRCTOP/include all install DESTDIR=$ROOT; then
140 build_ok=n
141 this_build_ok=n
142 fatal_error "cannot install headers"
146 # Build the legacy part of the source
148 echo "\n==== Building legacy source at `date` ($LABEL) ====\n"
150 cd $SRC
151 echo "\n==== dmake install ====\n" >&2
152 if ! /bin/time $MAKE -e install; then
153 build_ok=n
154 this_build_ok=n
158 # Build the new part of the source
160 echo "\n==== bmake build ====\n" >&2
161 if ! /bin/time env -i PATH=${GCC_ROOT}/bin:/usr/bin \
162 SRCTOP=$SRCTOP \
163 make -C $SRCTOP -j $DMAKE_MAX_JOBS VERBOSE=yes build DESTDIR=$ROOT; then
164 build_ok=n
165 this_build_ok=n
168 echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n"
171 # Building Packages
173 if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
174 if [ -d $SRC/pkg ]; then
175 echo "\n==== Creating $LABEL packages at `date` ====\n"
176 echo "Clearing out $PKGARCHIVE ..."
177 rm -rf $PKGARCHIVE
178 mkdir -p $PKGARCHIVE
180 rm -f $SRC/pkg/${INSTALLOG}.out
181 cd $SRC/pkg
182 echo "\n==== dmake -C $SRC/pkg install ====\n" >&2
183 if ! /bin/time $MAKE -e install; then
184 build_extras_ok=n
185 this_build_ok=n
187 else
189 # Handle it gracefully if -p was set but there so
190 # no pkg directory.
192 echo "\n==== No $LABEL packages to build ====\n"
194 else
195 echo "\n==== Not creating $LABEL packages ====\n"
200 # Build and install the onbld tools.
202 # usage: build_tools DESTROOT
204 # returns non-zero status if the build was successful.
206 function build_tools {
207 DESTROOT=$1
209 INSTALLOG=install-${MACH}
211 echo "\n==== Building tools at `date` ====\n" \
213 rm -f ${TOOLS}/${INSTALLOG}.out
214 cd ${TOOLS}
215 if ! $MAKE TOOLS_PROTO=${DESTROOT} -e install; then
216 return 1
218 return 0
222 # Set up to use locally installed tools.
224 # usage: use_tools TOOLSROOT
226 function use_tools {
227 TOOLSROOT=$1
230 # If we're not building ON workspace, then the TOOLSROOT
231 # settings here are clearly ignored by the workspace
232 # makefiles, prepending nonexistent directories to PATH is
233 # harmless, and we clearly do not wish to override
234 # ONBLD_TOOLS.
236 # If we're building an ON workspace, then the prepended PATH
237 # elements should supercede the preexisting ONBLD_TOOLS paths,
238 # and we want to override ONBLD_TOOLS to catch the tools that
239 # don't have specific path env vars here.
241 # So the only conditional behavior is overriding ONBLD_TOOLS,
242 # and we check for "an ON workspace" by looking for
243 # ${TOOLSROOT}/opt/onbld.
246 STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
247 export STABS
248 CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
249 export CTFSTABS
250 GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
251 export GENOFFSETS
254 PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
255 PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
256 export PATH
258 if [ -d "${TOOLSROOT}/opt/onbld" ]; then
259 ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
260 export ONBLD_TOOLS
263 echo "\n==== New environment settings. ====\n"
264 echo "STABS=${STABS}"
265 echo "CTFSTABS=${CTFSTABS}"
266 echo "PATH=${PATH}"
267 echo "ONBLD_TOOLS=${ONBLD_TOOLS}"
271 # wrapper over wsdiff.
272 # usage: do_wsdiff LABEL OLDPROTO NEWPROTO
274 function do_wsdiff {
275 label=$1
276 oldproto=$2
277 newproto=$3
279 wsdiff="wsdiff -t"
281 echo "\n==== Getting object changes since last build at `date`" \
282 "($label) ====\n" >&2
283 $wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto >&2
284 echo "\n==== Object changes determined at `date` ($label) ====\n" >&2
288 # Functions for setting build flags (DEBUG/non-DEBUG). Keep them
289 # together.
292 function set_non_debug_build_flags {
293 export RELEASE_BUILD ; RELEASE_BUILD=
294 unset EXTRA_OPTIONS
295 unset EXTRA_CFLAGS
298 function set_debug_build_flags {
299 unset RELEASE_BUILD
300 unset EXTRA_OPTIONS
301 unset EXTRA_CFLAGS
305 MACH=`uname -p`
307 if [ "$OPTHOME" = "" ]; then
308 OPTHOME=/opt
309 export OPTHOME
312 USAGE='Usage: nightly [-in] [-V VERS ] [env_file]
314 Where:
315 -i Fast incremental options (no clobber, check)
316 -V VERS set the build version string to VERS
318 <env_file> file in Bourne shell syntax that sets and exports
319 variables that configure the operation of this script and many of
320 the scripts this one calls.
322 non-DEBUG is the default build type. Build options can be set in the
323 NIGHTLY_OPTIONS variable in the <env_file> as follows:
325 -A check for ABI differences in .so files
326 -C check for cstyle/hdrchk errors
327 -D do a build with DEBUG on
328 -G gate keeper default group of options (-au)
329 -I integration engineer default group of options (-ampu)
330 -M do not run pmodes (safe file permission checker)
331 -N do not run protocmp
332 -R default group of options for building a release (-mp)
333 -U update proto area in the parent
334 -V VERS set the build version string to VERS
335 -i do an incremental build (no "make clobber")
336 -m send mail to $MAILTO at end of build
337 -p create packages
338 -r check ELF runtime attributes in the proto area
339 -u update proto_list_$MACH and friends in the parent workspace
340 -w report on differences between previous and current proto areas
343 # A log file will be generated under the name $LOGFILE
344 # for partially completed build and log.`date '+%F'`
345 # in the same directory for fully completed builds.
348 # default values for low-level FLAGS; G I R are group FLAGS
349 A_FLAG=n
350 C_FLAG=n
351 D_FLAG=n
352 i_FLAG=n; i_CMD_LINE_FLAG=n
353 M_FLAG=n
354 m_FLAG=n
355 N_FLAG=n
356 p_FLAG=n
357 r_FLAG=n
358 V_FLAG=n
359 w_FLAG=n
360 W_FLAG=n
362 build_ok=y
363 build_extras_ok=y
366 # examine arguments
369 OPTIND=1
370 while getopts +iV:W FLAG
372 case $FLAG in
373 i ) i_FLAG=y; i_CMD_LINE_FLAG=y
375 V ) V_FLAG=y
376 V_ARG="$OPTARG"
378 W ) W_FLAG=y
380 \? ) echo "$USAGE"
381 exit 1
383 esac
384 done
386 # correct argument count after options
387 shift `expr $OPTIND - 1`
389 # test that the path to the environment-setting file was given
390 if [ $# -ne 1 ]; then
391 envfile=$(dirname $0)/env.sh
392 else
393 envfile=$1
397 # force locale to C
398 LANG=C; export LANG
399 LC_ALL=C; export LC_ALL
400 LC_COLLATE=C; export LC_COLLATE
401 LC_CTYPE=C; export LC_CTYPE
402 LC_MESSAGES=C; export LC_MESSAGES
403 LC_MONETARY=C; export LC_MONETARY
404 LC_NUMERIC=C; export LC_NUMERIC
405 LC_TIME=C; export LC_TIME
407 # clear environment variables we know to be bad for the build
408 unset LD_OPTIONS
409 unset LD_AUDIT LD_AUDIT_32 LD_AUDIT_64
410 unset LD_BIND_NOW LD_BIND_NOW_32 LD_BIND_NOW_64
411 unset LD_BREADTH LD_BREADTH_32 LD_BREADTH_64
412 unset LD_CONFIG LD_CONFIG_32 LD_CONFIG_64
413 unset LD_DEBUG LD_DEBUG_32 LD_DEBUG_64
414 unset LD_DEMANGLE LD_DEMANGLE_32 LD_DEMANGLE_64
415 unset LD_FLAGS LD_FLAGS_32 LD_FLAGS_64
416 unset LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64
417 unset LD_LOADFLTR LD_LOADFLTR_32 LD_LOADFLTR_64
418 unset LD_NOAUDIT LD_NOAUDIT_32 LD_NOAUDIT_64
419 unset LD_NOAUXFLTR LD_NOAUXFLTR_32 LD_NOAUXFLTR_64
420 unset LD_NOCONFIG LD_NOCONFIG_32 LD_NOCONFIG_64
421 unset LD_NODIRCONFIG LD_NODIRCONFIG_32 LD_NODIRCONFIG_64
422 unset LD_NODIRECT LD_NODIRECT_32 LD_NODIRECT_64
423 unset LD_NOLAZYLOAD LD_NOLAZYLOAD_32 LD_NOLAZYLOAD_64
424 unset LD_NOOBJALTER LD_NOOBJALTER_32 LD_NOOBJALTER_64
425 unset LD_NOVERSION LD_NOVERSION_32 LD_NOVERSION_64
426 unset LD_ORIGIN LD_ORIGIN_32 LD_ORIGIN_64
427 unset LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
428 unset LD_PROFILE LD_PROFILE_32 LD_PROFILE_64
430 unset CONFIG
431 unset GROUP
432 unset OWNER
433 unset REMOTE
434 unset ENV
435 unset ARCH
436 unset CLASSPATH
437 unset NAME
440 # To get ONBLD_TOOLS from the environment, it must come from the env file.
441 # If it comes interactively, it is generally TOOLS_PROTO, which will be
442 # clobbered before the compiler version checks, which will therefore fail.
444 unset ONBLD_TOOLS
447 # Setup environmental variables
449 if [ -f $envfile ]; then
450 . $envfile
451 else
452 echo "Cannot find env file $envfile"
453 exit 1
456 # Check if we have sufficient data to continue...
457 [[ -v SRCTOP ]] || \
458 fatal_error "Error: Variable SRCTOP not set."
459 [[ -d "${SRCTOP}" ]] || \
460 fatal_error "Error: ${SRCTOP} is not a directory."
461 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || \
462 fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
465 # place ourselves in a new task, respecting BUILD_PROJECT if set.
467 if [ -z "$BUILD_PROJECT" ]; then
468 /usr/bin/newtask -c $$
469 else
470 /usr/bin/newtask -c $$ -p $BUILD_PROJECT
473 ps -o taskid= -p $$ | read build_taskid
474 ps -o project= -p $$ | read build_project
477 # See if NIGHTLY_OPTIONS is set
479 if [ "$NIGHTLY_OPTIONS" = "" ]; then
480 NIGHTLY_OPTIONS="-aBm"
484 # Note: changes to the option letters here should also be applied to the
485 # bldenv script. `d' is listed for backward compatibility.
487 NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
488 OPTIND=1
489 while getopts +ABCDdfGIiMmNpRrwW FLAG $NIGHTLY_OPTIONS
491 case $FLAG in
492 A ) A_FLAG=y
494 B ) D_FLAG=y
495 ;; # old version of D
496 C ) C_FLAG=y
498 D ) D_FLAG=y
500 G ) ;;
501 I ) m_FLAG=y
502 p_FLAG=y
504 i ) i_FLAG=y
506 M ) M_FLAG=y
508 m ) m_FLAG=y
510 N ) N_FLAG=y
512 p ) p_FLAG=y
514 R ) m_FLAG=y
515 p_FLAG=y
517 r ) r_FLAG=y
519 w ) w_FLAG=y
521 W ) W_FLAG=y
523 \? ) echo "$USAGE"
524 exit 1
526 esac
527 done
529 if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
530 MAILTO=`/usr/bin/id -un`
531 export MAILTO
534 PATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/bin"
535 PATH="$PATH:/usr/bin:/usr/sbin:/usr/ucb"
536 PATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:.:$OPTHOME/SUNWspro/bin"
537 export PATH
539 # roots of source trees, both relative to $SRC and absolute.
540 relsrcdirs="."
541 abssrcdirs="$SRC"
543 PROTOCMPTERSE="protocmp.terse -gu"
544 POUND_SIGN="#"
545 # have we set RELEASE_DATE in our env file?
546 if [ -z "$RELEASE_DATE" ]; then
547 RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
549 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
550 BASEWSDIR=$(basename $SRCTOP)
551 DEV_CM="\"@(#)illumos Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
552 RELEASE_MICRO=$(( ($(date +%Y) * 12 + $(date +%m) - 1) - (2010 * 12 + 8 - 1) ))
554 # we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
555 # by avoiding repeated shell invocations to evaluate Makefile.master
556 # definitions.
557 export POUND_SIGN RELEASE_DATE DEV_CM RELEASE_MICRO
559 maketype="distributed"
560 if [[ -z "$MAKE" ]]; then
561 MAKE=dmake
562 elif [[ ! -x "$MAKE" ]]; then
563 echo "\$MAKE is set to garbage in the environment"
564 exit 1
566 export PATH
567 export MAKE
569 hostname=$(uname -n)
570 if [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
571 then
572 maxjobs=
573 if [[ -f $HOME/.make.machines ]]
574 then
575 # Note: there is a hard tab and space character in the []s
576 # below.
577 egrep -i "^[ ]*$hostname[ \.]" \
578 $HOME/.make.machines | read host jobs
579 maxjobs=${jobs##*=}
582 if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
583 then
584 # default
585 maxjobs=4
588 export DMAKE_MAX_JOBS=$maxjobs
591 DMAKE_MODE=parallel;
592 export DMAKE_MODE
593 DMAKE_OUTPUT_MODE=TXT2;
594 export DMAKE_OUTPUT_MODE
596 if [ -z "${ROOT}" ]; then
597 echo "ROOT must be set."
598 exit 1
602 # if -V flag was given, reset VERSION to V_ARG
604 if [ "$V_FLAG" = "y" ]; then
605 VERSION=$V_ARG
608 TMPDIR="/tmp/nightly.tmpdir.$$"
609 export TMPDIR
610 rm -rf ${TMPDIR}
611 mkdir -p $TMPDIR || exit 1
613 # Tools should only be built non-DEBUG. Keep track of the tools proto
614 # area path relative to $TOOLS, because the latter changes in an
615 # export build.
617 # TOOLS_PROTO is included below for builds other than usr/src/tools
618 # that look for this location. For usr/src/tools, this will be
619 # overridden on the $MAKE command line in build_tools().
621 TOOLS=${SRC}/tools
622 TOOLS_PROTO_REL=proto/root_${MACH}-nd
623 TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
625 unset CFLAGS LD_LIBRARY_PATH LDFLAGS
627 # create directories that are automatically removed if the nightly script
628 # fails to start correctly
629 function newdir {
630 dir=$1
631 toadd=
632 while [ ! -d $dir ]; do
633 toadd="$dir $toadd"
634 dir=`dirname $dir`
635 done
636 torm=
637 newlist=
638 for dir in $toadd; do
639 if mkdir $dir; then
640 newlist="$dir $newlist"
641 torm="$dir $torm"
642 else
643 [ -z "$torm" ] || rmdir $torm
644 return 1
646 done
647 newdirlist="$newlist $newdirlist"
648 return 0
650 newdirlist=
652 [ -d $SRCTOP ] || newdir $SRCTOP || exit 1
654 # since this script assumes the build is from full source, it nullifies
655 # variables likely to have been set by a "ws" script; nullification
656 # confines the search space for headers and libraries to the proto area
657 # built from this immediate source.
658 ENVLDLIBS1=
659 ENVLDLIBS2=
660 ENVLDLIBS3=
661 ENVCPPFLAGS1=
662 ENVCPPFLAGS2=
663 ENVCPPFLAGS3=
664 ENVCPPFLAGS4=
666 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
667 ENVLDLIBS1 ENVLDLIBS2
670 # Juggle the logs and optionally send mail on completion.
673 function logshuffle {
674 LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
675 if [ -f $LLOG -o -d $LLOG ]; then
676 LLOG=$LLOG.$$
678 mkdir $LLOG
679 export LLOG
681 if [ "$build_ok" = "y" ]; then
682 mv $ATLOG/proto_list_${MACH} $LLOG
684 if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
685 mv $ATLOG/proto_list_tools_${MACH} $LLOG
688 if [ -f $TMPDIR/wsdiff.results ]; then
689 mv $TMPDIR/wsdiff.results $LLOG
692 if [ -f $TMPDIR/wsdiff-nd.results ]; then
693 mv $TMPDIR/wsdiff-nd.results $LLOG
697 kill $TEE
698 case "$build_ok" in
700 state=Completed
703 state=Interrupted
706 state=Failed
708 esac
710 if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
711 state=Failed
714 NIGHTLY_STATUS=$state
715 export NIGHTLY_STATUS
717 run_hook POST_NIGHTLY $state
718 run_hook SYS_POST_NIGHTLY $state
720 echo "Subject: Nightly ${MACH} Build of `basename ${SRCTOP}` ${state}." \
721 > ${LLOG}/mail_msg
722 cat $build_time_file $mail_msg_file \
723 >> ${LLOG}/mail_msg
724 if [ "$m_FLAG" = "y" ]; then
725 /usr/bin/mail ${MAILTO} < ${LLOG}/mail_msg
728 mv $LOGFILE $LLOG
732 # Remove the temporary files on any exit
734 function cleanup {
735 logshuffle
737 set -- $newdirlist
738 while [ $# -gt 0 ]; do
739 rmdir $1
740 shift; shift
741 done
742 rm -rf $TMPDIR
745 function cleanup_signal {
746 build_ok=i
747 # this will trigger cleanup(), above.
748 exit 1
751 trap cleanup 0
752 trap cleanup_signal 1 2 3 15
754 newdirlist=
757 # Create mail_msg_file
759 mail_msg_file="${TMPDIR}/mail_msg"
760 touch $mail_msg_file
761 build_time_file="${TMPDIR}/build_time"
763 mkdir -p "$ATLOG"
765 # Move old LOGFILE aside
767 if [ -f $LOGFILE ]; then
768 mv -f $LOGFILE ${LOGFILE}-
771 mkfifo ${TMPDIR}/err.fifo ${TMPDIR}/out.fifo
772 tee $mail_msg_file < ${TMPDIR}/err.fifo >> $LOGFILE &
773 TEE=$!
774 tee ${TMPDIR}/stdout.txt < ${TMPDIR}/out.fifo >> $LOGFILE &
775 TEE="$TEE $!"
776 exec > ${TMPDIR}/out.fifo
777 exec 2> ${TMPDIR}/err.fifo
780 # Build OsNet source
782 START_DATE=`date`
783 SECONDS=0
784 echo "\n==== Nightly $maketype build started: $START_DATE ====" | \
785 tee -a $build_time_file
787 run_hook SYS_PRE_NIGHTLY
788 run_hook PRE_NIGHTLY
790 echo "\n==== list of environment variables ====\n"
793 echo "Building $VERSION
794 on $(uname -srv)" >&2
796 if [[ ! -f $SRC/Makefile ]]; then
797 build_ok=n
798 echo "\nUnable to find \"Makefile\" in $SRC." >&2
799 exit 1
802 # Save the current proto area if we're comparing against the last build
803 if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
804 if [ -d "$ROOT.prev" ]; then
805 rm -rf $ROOT.prev
807 mv $ROOT $ROOT.prev
810 # Safeguards
811 [[ -v SRCTOP ]] || fatal_error "Error: Variable SRCTOP not set."
812 [[ -d "${SRCTOP}" ]] || fatal_error "Error: ${SRCTOP} is not a directory."
813 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
816 # Generate the cfgparam files
818 # We have to do this before running *any* make commands.
820 make gen-config || fatal_error "gen-config failed"
823 # Decide whether to clobber
825 if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
826 echo "\n==== Make clobber at `date` ====\n"
827 echo "\n==== clobber / cleandir ===="
829 cd $SRC
830 # remove old clobber file
831 rm -f $SRC/clobber.out
832 rm -f $SRC/clobber-${MACH}.out
834 # Remove all .make.state* files, just in case we are restarting
835 # the build after having interrupted a previous 'make clobber'.
836 find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
837 -o -name 'interfaces.*' \) -prune \
838 -o -name '.make.*' -print | xargs rm -f
839 if ! $MAKE -ek clobber; then
840 build_extras_ok=n
843 echo "\n==== Make tools clobber at `date` ====\n"
844 cd ${TOOLS}
845 rm -f ${TOOLS}/clobber-${MACH}.out
847 if ! $MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber; then
848 build_extras_ok=n
850 rm -rf ${TOOLS_PROTO}
851 mkdir -p ${TOOLS_PROTO}
853 typeset roots=$ROOT
854 echo "\n\nClearing $roots"
855 rm -rf $roots
857 # Get back to a clean workspace as much as possible to catch
858 # problems that only occur on fresh workspaces.
859 # Remove all .make.state* files, libraries, and .o's that may
860 # have been omitted from clobber. A couple of libraries are
861 # under source code control, so leave them alone.
862 # We should probably blow away temporary directories too.
863 cd $SRC
864 find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
865 -o -name .git -o -name 'interfaces.*' \) -prune -o \
866 \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
867 -name '*.o' \) -print | \
868 grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
869 make -C $SRCTOP cleandir
870 else
871 echo "\n==== No clobber at `date` ====\n"
875 # Build and use the workspace's tools if requested
877 set_non_debug_build_flags
879 build_tools ${TOOLS_PROTO}
880 if (( $? != 0 )); then
881 build_ok=n
882 else
883 use_tools $TOOLS_PROTO
886 normal_build
888 ORIG_SRC=$SRC
889 BINARCHIVE=${SRCTOP}/bin-${MACH}.cpio.Z
891 if [ "$build_ok" = "y" ]; then
892 echo "\n==== Creating protolist system file at `date` ====" \
893 protolist $ROOT > $ATLOG/proto_list_${MACH}
894 echo "==== protolist system file created at `date` ====\n" \
896 if [ "$N_FLAG" != "y" ]; then
900 for f in $f1; do
901 if [ -f "$f" ]; then
902 E1="$E1 -e $f"
904 done
908 if [ -d "$SRC/pkg" ]; then
909 f2="$f2 exceptions/packaging"
912 for f in $f2; do
913 if [ -f "$f" ]; then
914 E2="$E2 -e $f"
916 done
919 if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
920 echo "\n==== Validating manifests against proto area (protocmp) ====\n" >&2
921 if ! ( cd $SRC/pkg ; /bin/time $MAKE -e protocmp ROOT="$ROOT" ) >&2; then
922 build_extras_ok=n
928 # ELF verification: ABI (-A) and runtime (-r) checks
930 if [[ ($build_ok = y) && (($A_FLAG = y) || ($r_FLAG = y)) ]]; then
931 # Directory ELF-data.$MACH holds the files produced by these tests.
932 elf_ddir=$TMPDIR/ELF-data.$MACH
933 mkdir -p $elf_ddir
935 # Call find_elf to produce a list of the ELF objects in the proto area.
936 # This list is passed to check_rtime and interface_check, preventing
937 # them from separately calling find_elf to do the same work twice.
938 find_elf -fr $ROOT > $elf_ddir/object_list
940 if [[ $A_FLAG = y ]]; then
941 echo "\n==== Check versioning and ABI information (interface_check) ====\n" >&2
943 # Produce interface description for the proto. Report errors.
944 /bin/time interface_check -o -w $elf_ddir -f object_list \
945 -i interface -E interface.err
946 if [[ -s $elf_ddir/interface.err ]]; then
947 cat $elf_ddir/interface.err >&2
948 build_extras_ok=n
953 if [[ $r_FLAG = y ]]; then
954 echo "\n==== Check ELF runtime attributes (check_rtime) ====\n" >&2
956 # If we're doing a DEBUG build the proto area will be left
957 # with debuggable objects, thus don't assert -s.
958 if [[ $D_FLAG = y ]]; then
959 rtime_sflag=""
960 else
961 rtime_sflag="-s"
963 /bin/time check_rtime -i -v $rtime_sflag -o -w $elf_ddir \
964 -D object_list -f object_list -E runtime.err \
965 -I runtime.attr.raw
966 if (( $? != 0 )); then
967 build_extras_ok=n
970 # Report errors
971 if [[ -s $elf_ddir/runtime.err ]]; then
972 cat $elf_ddir/runtime.err >&2
973 build_extras_ok=n
978 # "make check" begins
980 if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
981 # remove old check.out
982 rm -f $SRC/check.out
984 rm -f $SRC/check-${MACH}.out
985 cd $SRC
986 echo "\n==== dmake check ====\n" >&2
987 if ! /bin/time $MAKE -ek check ROOT="$ROOT"; then
988 build_extras_ok=n
990 else
991 echo "\n==== No '$MAKE check' ====\n"
994 echo "\n==== Find core files ====\n" >&2
996 find $abssrcdirs -name core -a -type f -exec file {} \; >&2
998 # Verify that the usual lists of files, such as exception lists,
999 # contain only valid references to files. If the build has failed,
1000 # then don't check the proto area.
1001 CHECK_PATHS=${CHECK_PATHS:-y}
1002 if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
1003 echo "\n==== Check lists of files ====\n" >&2
1004 arg=-b
1005 [ "$build_ok" = y ] && arg=
1006 checkpaths $arg $ROOT > $TMPDIR/check-paths.out 2>&1
1007 if [[ -s $TMPDIR/check-paths.out ]]; then
1008 cat $TMPDIR/check-paths.out >&2
1009 build_extras_ok=n
1013 if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
1014 echo "\n==== Impact on file permissions ====\n" >&2
1016 abspkg=
1017 for d in $abssrcdirs; do
1018 if [ -d "$d/pkg" ]; then
1019 abspkg="$abspkg $d"
1021 done
1023 if [ -n "$abspkg" ]; then
1024 for d in "$abspkg"; do
1025 ( cd $d/pkg ; $MAKE -e pmodes ) >&2
1026 done
1030 if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
1031 if [[ "$D_FLAG" = y ]]; then
1032 do_wsdiff DEBUG $ROOT.prev $ROOT
1033 else
1034 do_wsdiff non-DEBUG $ROOT.prev $ROOT
1038 END_DATE=`date`
1039 echo "==== Nightly $maketype build completed: $END_DATE ====" | \
1040 tee -a $build_time_file
1042 typeset -i10 hours
1043 typeset -Z2 minutes
1044 typeset -Z2 seconds
1046 elapsed_time=$SECONDS
1047 ((hours = elapsed_time / 3600 ))
1048 ((minutes = elapsed_time / 60 % 60))
1049 ((seconds = elapsed_time % 60))
1051 echo "Total build time ${hours}:${minutes}:${seconds}" |
1052 tee -a $build_time_file
1055 # All done save for the sweeping up.
1056 # (whichever exit we hit here will trigger the "cleanup" trap which
1057 # optionally sends mail on completion).
1059 if [[ "$build_ok" == "y" ]]; then
1060 if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
1061 exit 0
1065 exit 1