Merge branch 'master'
[unleashed.git] / tools / nightly.sh
blobcd1e2e6a0f922aab3f5f6ed8b323eaec028cbe53
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}
127 NOISE=noise-${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 bmake_build_step_user_dir $SRCTOP/include all
141 bmake_build_step_user_dir $SRCTOP/include install
144 # Build the legacy part of the source
146 echo "\n==== Building legacy source at `date` ($LABEL) ====\n"
148 cd $SRC
149 echo "\n==== dmake install ====\n" >&2
150 if ! /bin/time $MAKE -e install; then
151 build_ok=n
152 this_build_ok=n
156 # Build the new part of the source
158 bmake_build_step_user build
160 echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n"
163 # Building Packages
165 if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
166 if [ -d $SRC/pkg ]; then
167 echo "\n==== Creating $LABEL packages at `date` ====\n"
168 echo "Clearing out $PKGARCHIVE ..."
169 rm -rf $PKGARCHIVE
170 mkdir -p $PKGARCHIVE
172 rm -f $SRC/pkg/${INSTALLOG}.out
173 cd $SRC/pkg
174 echo "\n==== package build errors ($LABEL) ====\n" >&2
175 if ! /bin/time $MAKE -e install; then
176 build_extras_ok=n
177 this_build_ok=n
179 else
181 # Handle it gracefully if -p was set but there so
182 # no pkg directory.
184 echo "\n==== No $LABEL packages to build ====\n"
186 else
187 echo "\n==== Not creating $LABEL packages ====\n"
192 # Build and install the onbld tools.
194 # usage: build_tools DESTROOT
196 # returns non-zero status if the build was successful.
198 function build_tools {
199 DESTROOT=$1
201 INSTALLOG=install-${MACH}
203 echo "\n==== Building tools at `date` ====\n" \
205 rm -f ${TOOLS}/${INSTALLOG}.out
206 cd ${TOOLS}
207 echo "\n==== Tools build errors ====\n" >&2
208 if ! /bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install; then
209 return 1
211 return 0
215 # Set up to use locally installed tools.
217 # usage: use_tools TOOLSROOT
219 function use_tools {
220 TOOLSROOT=$1
223 # If we're not building ON workspace, then the TOOLSROOT
224 # settings here are clearly ignored by the workspace
225 # makefiles, prepending nonexistent directories to PATH is
226 # harmless, and we clearly do not wish to override
227 # ONBLD_TOOLS.
229 # If we're building an ON workspace, then the prepended PATH
230 # elements should supercede the preexisting ONBLD_TOOLS paths,
231 # and we want to override ONBLD_TOOLS to catch the tools that
232 # don't have specific path env vars here.
234 # So the only conditional behavior is overriding ONBLD_TOOLS,
235 # and we check for "an ON workspace" by looking for
236 # ${TOOLSROOT}/opt/onbld.
239 STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
240 export STABS
241 CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
242 export CTFSTABS
243 GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
244 export GENOFFSETS
247 PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
248 PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
249 export PATH
251 if [ -d "${TOOLSROOT}/opt/onbld" ]; then
252 ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
253 export ONBLD_TOOLS
256 echo "\n==== New environment settings. ====\n"
257 echo "STABS=${STABS}"
258 echo "CTFSTABS=${CTFSTABS}"
259 echo "PATH=${PATH}"
260 echo "ONBLD_TOOLS=${ONBLD_TOOLS}"
264 # wrapper over wsdiff.
265 # usage: do_wsdiff LABEL OLDPROTO NEWPROTO
267 function do_wsdiff {
268 label=$1
269 oldproto=$2
270 newproto=$3
272 wsdiff="wsdiff -t"
274 echo "\n==== Getting object changes since last build at `date`" \
275 "($label) ====\n" >&2
276 $wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto >&2
277 echo "\n==== Object changes determined at `date` ($label) ====\n" >&2
281 # Functions for setting build flags (DEBUG/non-DEBUG). Keep them
282 # together.
285 function set_non_debug_build_flags {
286 export RELEASE_BUILD ; RELEASE_BUILD=
287 unset EXTRA_OPTIONS
288 unset EXTRA_CFLAGS
291 function set_debug_build_flags {
292 unset RELEASE_BUILD
293 unset EXTRA_OPTIONS
294 unset EXTRA_CFLAGS
298 MACH=`uname -p`
300 if [ "$OPTHOME" = "" ]; then
301 OPTHOME=/opt
302 export OPTHOME
305 USAGE='Usage: nightly [-in] [-V VERS ] <env_file>
307 Where:
308 -i Fast incremental options (no clobber, check)
309 -V VERS set the build version string to VERS
311 <env_file> file in Bourne shell syntax that sets and exports
312 variables that configure the operation of this script and many of
313 the scripts this one calls.
315 non-DEBUG is the default build type. Build options can be set in the
316 NIGHTLY_OPTIONS variable in the <env_file> as follows:
318 -A check for ABI differences in .so files
319 -C check for cstyle/hdrchk errors
320 -D do a build with DEBUG on
321 -G gate keeper default group of options (-au)
322 -I integration engineer default group of options (-ampu)
323 -M do not run pmodes (safe file permission checker)
324 -N do not run protocmp
325 -R default group of options for building a release (-mp)
326 -U update proto area in the parent
327 -V VERS set the build version string to VERS
328 -i do an incremental build (no "make clobber")
329 -m send mail to $MAILTO at end of build
330 -p create packages
331 -r check ELF runtime attributes in the proto area
332 -u update proto_list_$MACH and friends in the parent workspace
333 -w report on differences between previous and current proto areas
336 # A log file will be generated under the name $LOGFILE
337 # for partially completed build and log.`date '+%F'`
338 # in the same directory for fully completed builds.
341 # default values for low-level FLAGS; G I R are group FLAGS
342 A_FLAG=n
343 C_FLAG=n
344 D_FLAG=n
345 i_FLAG=n; i_CMD_LINE_FLAG=n
346 M_FLAG=n
347 m_FLAG=n
348 N_FLAG=n
349 p_FLAG=n
350 r_FLAG=n
351 V_FLAG=n
352 w_FLAG=n
353 W_FLAG=n
355 build_ok=y
356 build_extras_ok=y
359 # examine arguments
362 OPTIND=1
363 while getopts +iV:W FLAG
365 case $FLAG in
366 i ) i_FLAG=y; i_CMD_LINE_FLAG=y
368 V ) V_FLAG=y
369 V_ARG="$OPTARG"
371 W ) W_FLAG=y
373 \? ) echo "$USAGE"
374 exit 1
376 esac
377 done
379 # correct argument count after options
380 shift `expr $OPTIND - 1`
382 # test that the path to the environment-setting file was given
383 if [ $# -ne 1 ]; then
384 echo "$USAGE"
385 exit 1
389 # force locale to C
390 LANG=C; export LANG
391 LC_ALL=C; export LC_ALL
392 LC_COLLATE=C; export LC_COLLATE
393 LC_CTYPE=C; export LC_CTYPE
394 LC_MESSAGES=C; export LC_MESSAGES
395 LC_MONETARY=C; export LC_MONETARY
396 LC_NUMERIC=C; export LC_NUMERIC
397 LC_TIME=C; export LC_TIME
399 # clear environment variables we know to be bad for the build
400 unset LD_OPTIONS
401 unset LD_AUDIT LD_AUDIT_32 LD_AUDIT_64
402 unset LD_BIND_NOW LD_BIND_NOW_32 LD_BIND_NOW_64
403 unset LD_BREADTH LD_BREADTH_32 LD_BREADTH_64
404 unset LD_CONFIG LD_CONFIG_32 LD_CONFIG_64
405 unset LD_DEBUG LD_DEBUG_32 LD_DEBUG_64
406 unset LD_DEMANGLE LD_DEMANGLE_32 LD_DEMANGLE_64
407 unset LD_FLAGS LD_FLAGS_32 LD_FLAGS_64
408 unset LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64
409 unset LD_LOADFLTR LD_LOADFLTR_32 LD_LOADFLTR_64
410 unset LD_NOAUDIT LD_NOAUDIT_32 LD_NOAUDIT_64
411 unset LD_NOAUXFLTR LD_NOAUXFLTR_32 LD_NOAUXFLTR_64
412 unset LD_NOCONFIG LD_NOCONFIG_32 LD_NOCONFIG_64
413 unset LD_NODIRCONFIG LD_NODIRCONFIG_32 LD_NODIRCONFIG_64
414 unset LD_NODIRECT LD_NODIRECT_32 LD_NODIRECT_64
415 unset LD_NOLAZYLOAD LD_NOLAZYLOAD_32 LD_NOLAZYLOAD_64
416 unset LD_NOOBJALTER LD_NOOBJALTER_32 LD_NOOBJALTER_64
417 unset LD_NOVERSION LD_NOVERSION_32 LD_NOVERSION_64
418 unset LD_ORIGIN LD_ORIGIN_32 LD_ORIGIN_64
419 unset LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
420 unset LD_PROFILE LD_PROFILE_32 LD_PROFILE_64
422 unset CONFIG
423 unset GROUP
424 unset OWNER
425 unset REMOTE
426 unset ENV
427 unset ARCH
428 unset CLASSPATH
429 unset NAME
432 # To get ONBLD_TOOLS from the environment, it must come from the env file.
433 # If it comes interactively, it is generally TOOLS_PROTO, which will be
434 # clobbered before the compiler version checks, which will therefore fail.
436 unset ONBLD_TOOLS
439 # Setup environmental variables
441 if [ -f $1 ]; then
442 if [[ $1 = */* ]]; then
443 . $1
444 else
445 . ./$1
447 else
448 echo "Cannot find env file as either $1"
449 exit 1
452 # Check if we have sufficient data to continue...
453 [[ -v SRCTOP ]] || \
454 fatal_error "Error: Variable SRCTOP not set."
455 [[ -d "${SRCTOP}" ]] || \
456 fatal_error "Error: ${SRCTOP} is not a directory."
457 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || \
458 fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
461 # place ourselves in a new task, respecting BUILD_PROJECT if set.
463 if [ -z "$BUILD_PROJECT" ]; then
464 /usr/bin/newtask -c $$
465 else
466 /usr/bin/newtask -c $$ -p $BUILD_PROJECT
469 ps -o taskid= -p $$ | read build_taskid
470 ps -o project= -p $$ | read build_project
473 # See if NIGHTLY_OPTIONS is set
475 if [ "$NIGHTLY_OPTIONS" = "" ]; then
476 NIGHTLY_OPTIONS="-aBm"
480 # Note: changes to the option letters here should also be applied to the
481 # bldenv script. `d' is listed for backward compatibility.
483 NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
484 OPTIND=1
485 while getopts +ABCDdfGIiMmNpRrwW FLAG $NIGHTLY_OPTIONS
487 case $FLAG in
488 A ) A_FLAG=y
490 B ) D_FLAG=y
491 ;; # old version of D
492 C ) C_FLAG=y
494 D ) D_FLAG=y
496 G ) ;;
497 I ) m_FLAG=y
498 p_FLAG=y
500 i ) i_FLAG=y
502 M ) M_FLAG=y
504 m ) m_FLAG=y
506 N ) N_FLAG=y
508 p ) p_FLAG=y
510 R ) m_FLAG=y
511 p_FLAG=y
513 r ) r_FLAG=y
515 w ) w_FLAG=y
517 W ) W_FLAG=y
519 \? ) echo "$USAGE"
520 exit 1
522 esac
523 done
525 if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
526 MAILTO=`/usr/bin/id -un`
527 export MAILTO
530 PATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
531 PATH="$PATH:/usr/bin:/usr/sbin:/usr/ucb"
532 PATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:.:$OPTHOME/SUNWspro/bin"
533 export PATH
535 # roots of source trees, both relative to $SRC and absolute.
536 relsrcdirs="."
537 abssrcdirs="$SRC"
539 PROTOCMPTERSE="protocmp.terse -gu"
540 POUND_SIGN="#"
541 # have we set RELEASE_DATE in our env file?
542 if [ -z "$RELEASE_DATE" ]; then
543 RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
545 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
546 BASEWSDIR=$(basename $SRCTOP)
547 DEV_CM="\"@(#)illumos Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
548 RELEASE_MICRO=$(( ($(date +%Y) * 12 + $(date +%m) - 1) - (2010 * 12 + 8 - 1) ))
550 # we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
551 # by avoiding repeated shell invocations to evaluate Makefile.master
552 # definitions.
553 export POUND_SIGN RELEASE_DATE DEV_CM RELEASE_MICRO
555 maketype="distributed"
556 if [[ -z "$MAKE" ]]; then
557 MAKE=dmake
558 elif [[ ! -x "$MAKE" ]]; then
559 echo "\$MAKE is set to garbage in the environment"
560 exit 1
562 export PATH
563 export MAKE
565 hostname=$(uname -n)
566 if [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
567 then
568 maxjobs=
569 if [[ -f $HOME/.make.machines ]]
570 then
571 # Note: there is a hard tab and space character in the []s
572 # below.
573 egrep -i "^[ ]*$hostname[ \.]" \
574 $HOME/.make.machines | read host jobs
575 maxjobs=${jobs##*=}
578 if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
579 then
580 # default
581 maxjobs=4
584 export DMAKE_MAX_JOBS=$maxjobs
587 DMAKE_MODE=parallel;
588 export DMAKE_MODE
590 if [ -z "${ROOT}" ]; then
591 echo "ROOT must be set."
592 exit 1
596 # if -V flag was given, reset VERSION to V_ARG
598 if [ "$V_FLAG" = "y" ]; then
599 VERSION=$V_ARG
602 TMPDIR="/tmp/nightly.tmpdir.$$"
603 export TMPDIR
604 rm -rf ${TMPDIR}
605 mkdir -p $TMPDIR || exit 1
607 # Tools should only be built non-DEBUG. Keep track of the tools proto
608 # area path relative to $TOOLS, because the latter changes in an
609 # export build.
611 # TOOLS_PROTO is included below for builds other than usr/src/tools
612 # that look for this location. For usr/src/tools, this will be
613 # overridden on the $MAKE command line in build_tools().
615 TOOLS=${SRC}/tools
616 TOOLS_PROTO_REL=proto/root_${MACH}-nd
617 TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
619 unset CFLAGS LD_LIBRARY_PATH LDFLAGS
621 # create directories that are automatically removed if the nightly script
622 # fails to start correctly
623 function newdir {
624 dir=$1
625 toadd=
626 while [ ! -d $dir ]; do
627 toadd="$dir $toadd"
628 dir=`dirname $dir`
629 done
630 torm=
631 newlist=
632 for dir in $toadd; do
633 if mkdir $dir; then
634 newlist="$dir $newlist"
635 torm="$dir $torm"
636 else
637 [ -z "$torm" ] || rmdir $torm
638 return 1
640 done
641 newdirlist="$newlist $newdirlist"
642 return 0
644 newdirlist=
646 [ -d $SRCTOP ] || newdir $SRCTOP || exit 1
648 # since this script assumes the build is from full source, it nullifies
649 # variables likely to have been set by a "ws" script; nullification
650 # confines the search space for headers and libraries to the proto area
651 # built from this immediate source.
652 ENVLDLIBS1=
653 ENVLDLIBS2=
654 ENVLDLIBS3=
655 ENVCPPFLAGS1=
656 ENVCPPFLAGS2=
657 ENVCPPFLAGS3=
658 ENVCPPFLAGS4=
660 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
661 ENVLDLIBS1 ENVLDLIBS2
664 # Juggle the logs and optionally send mail on completion.
667 function logshuffle {
668 LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
669 if [ -f $LLOG -o -d $LLOG ]; then
670 LLOG=$LLOG.$$
672 mkdir $LLOG
673 export LLOG
675 if [ "$build_ok" = "y" ]; then
676 mv $ATLOG/proto_list_${MACH} $LLOG
678 if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
679 mv $ATLOG/proto_list_tools_${MACH} $LLOG
682 if [ -f $TMPDIR/wsdiff.results ]; then
683 mv $TMPDIR/wsdiff.results $LLOG
686 if [ -f $TMPDIR/wsdiff-nd.results ]; then
687 mv $TMPDIR/wsdiff-nd.results $LLOG
691 kill $TEE
692 case "$build_ok" in
694 state=Completed
697 state=Interrupted
700 state=Failed
702 esac
704 if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
705 state=Failed
708 NIGHTLY_STATUS=$state
709 export NIGHTLY_STATUS
711 run_hook POST_NIGHTLY $state
712 run_hook SYS_POST_NIGHTLY $state
714 echo "Subject: Nightly ${MACH} Build of `basename ${SRCTOP}` ${state}." \
715 > ${LLOG}/mail_msg
716 cat $build_time_file $mail_msg_file \
717 >> ${LLOG}/mail_msg
718 if [ "$m_FLAG" = "y" ]; then
719 /usr/bin/mail ${MAILTO} < ${LLOG}/mail_msg
722 mv $LOGFILE $LLOG
726 # Remove the temporary files on any exit
728 function cleanup {
729 logshuffle
731 set -- $newdirlist
732 while [ $# -gt 0 ]; do
733 rmdir $1
734 shift; shift
735 done
736 rm -rf $TMPDIR
739 function cleanup_signal {
740 build_ok=i
741 # this will trigger cleanup(), above.
742 exit 1
745 trap cleanup 0
746 trap cleanup_signal 1 2 3 15
748 newdirlist=
751 # Create mail_msg_file
753 mail_msg_file="${TMPDIR}/mail_msg"
754 touch $mail_msg_file
755 build_time_file="${TMPDIR}/build_time"
757 mkdir -p "$ATLOG"
759 # Move old LOGFILE aside
761 if [ -f $LOGFILE ]; then
762 mv -f $LOGFILE ${LOGFILE}-
765 mkfifo ${TMPDIR}/err.fifo ${TMPDIR}/out.fifo
766 tee $mail_msg_file < ${TMPDIR}/err.fifo >> $LOGFILE &
767 TEE=$!
768 tee ${TMPDIR}/stdout.txt < ${TMPDIR}/out.fifo >> $LOGFILE &
769 TEE="$TEE $!"
770 exec > ${TMPDIR}/out.fifo
771 exec 2> ${TMPDIR}/err.fifo
774 # Build OsNet source
776 START_DATE=`date`
777 SECONDS=0
778 echo "\n==== Nightly $maketype build started: $START_DATE ====" | \
779 tee -a $build_time_file
781 echo "\nBuild project: $build_project\nBuild taskid: $build_taskid" >&2
783 run_hook SYS_PRE_NIGHTLY
784 run_hook PRE_NIGHTLY
786 echo "\n==== list of environment variables ====\n"
789 echo "\n==== Nightly argument issues ====\n" >&2
791 if [ "$N_FLAG" = "y" ]; then
792 if [ "$p_FLAG" = "y" ]; then
793 cat <<EOF >&2
794 WARNING: the p option (create packages) is set, but so is the N option (do
795 not run protocmp); this is dangerous; you should unset the N option
797 else
798 cat <<EOF >&2
799 Warning: the N option (do not run protocmp) is set; it probably shouldn't be
802 echo "" >&2
805 if [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
806 echo "WARNING: -w specified, but $ROOT does not exist;" \
807 "ignoring -w\n" >&2
808 w_FLAG=n
811 echo "\n==== Build version ====\n" >&2
812 echo $VERSION >&2
814 # Save the current proto area if we're comparing against the last build
815 if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
816 if [ -d "$ROOT.prev" ]; then
817 rm -rf $ROOT.prev
819 mv $ROOT $ROOT.prev
822 function run_bmake {
823 echo "\n==== bmake $@ ====\n" >&2
824 /bin/time env -i PATH=${GCC_ROOT}/bin:/usr/bin \
825 SRCTOP=$SRCTOP \
826 bmake -j $DMAKE_MAX_JOBS \
827 VERBOSE=yes \
828 "$@"
831 # usage: bmake_build_step_args <dir> <target> <args...>
832 function bmake_build_step_args {
833 D=$1
834 shift
836 echo "\n==== \`bmake -C $D $@\` at `date` ($LABEL) ====\n"
838 if ! run_bmake -C $D "$@"; then
839 build_ok=n
840 this_build_ok=n
841 return 1
844 return 0
847 # usage: bmake_build_step_user <target>
848 function bmake_build_step_user {
849 bmake_build_step_args $SRCTOP $1 \
850 DESTDIR=$ROOT
853 # usage: bmake_build_step_user_dir <dir> <target>
854 function bmake_build_step_user_dir {
855 bmake_build_step_args $1 $2 \
856 DESTDIR=$ROOT
859 # Safeguards
860 [[ -v SRCTOP ]] || fatal_error "Error: Variable SRCTOP not set."
861 [[ -d "${SRCTOP}" ]] || fatal_error "Error: ${SRCTOP} is not a directory."
862 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
865 # Generate the cfgparam files
867 # We have to do this before running *any* make commands.
869 bmake_build_step_args $SRCTOP gen-config || build_extras_ok=n
872 # Decide whether to clobber
874 if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
875 echo "\n==== Make clobber at `date` ====\n"
877 cd $SRC
878 # remove old clobber file
879 rm -f $SRC/clobber.out
880 rm -f $SRC/clobber-${MACH}.out
882 # Remove all .make.state* files, just in case we are restarting
883 # the build after having interrupted a previous 'make clobber'.
884 find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
885 -o -name 'interfaces.*' \) -prune \
886 -o -name '.make.*' -print | xargs rm -f
888 echo "\n==== Make clobber ERRORS ====\n" >&2
889 if ! $MAKE -ek clobber; then
890 build_extras_ok=n
893 echo "\n==== Make tools clobber at `date` ====\n"
894 cd ${TOOLS}
895 rm -f ${TOOLS}/clobber-${MACH}.out
897 echo "\n==== Make tools clobber ERRORS ====\n" >&2
898 if ! $MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber; then
899 build_extras_ok=n
901 rm -rf ${TOOLS_PROTO}
902 mkdir -p ${TOOLS_PROTO}
904 typeset roots=$ROOT
905 echo "\n\nClearing $roots"
906 rm -rf $roots
908 # Get back to a clean workspace as much as possible to catch
909 # problems that only occur on fresh workspaces.
910 # Remove all .make.state* files, libraries, and .o's that may
911 # have been omitted from clobber. A couple of libraries are
912 # under source code control, so leave them alone.
913 # We should probably blow away temporary directories too.
914 cd $SRC
915 find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
916 -o -name .git -o -name 'interfaces.*' \) -prune -o \
917 \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
918 -name '*.o' \) -print | \
919 grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
920 echo "\n==== bmake cleandir ====\n"
921 run_bmake -C $SRCTOP cleandir
922 else
923 echo "\n==== No clobber at `date` ====\n"
926 echo "\n==== Build environment ====\n" >&2
928 # System
929 whence uname >&2
930 uname -a >&2
931 echo >&2
933 # make
934 whence $MAKE >&2
935 $MAKE -v >&2
936 echo "number of concurrent jobs = $DMAKE_MAX_JOBS" >&2
939 # Report the compiler versions.
942 if [[ ! -f $SRC/Makefile ]]; then
943 build_ok=n
944 echo "\nUnable to find \"Makefile\" in $SRC." >&2
945 exit 1
948 whence ld >&2
949 LDVER=`ld -V 2>&1`
950 echo $LDVER >&2
952 # Build and use the workspace's tools if requested
954 set_non_debug_build_flags
956 build_tools ${TOOLS_PROTO}
957 if (( $? != 0 )); then
958 build_ok=n
959 else
960 use_tools $TOOLS_PROTO
963 normal_build
965 ORIG_SRC=$SRC
966 BINARCHIVE=${SRCTOP}/bin-${MACH}.cpio.Z
968 if [ "$build_ok" = "y" ]; then
969 echo "\n==== Creating protolist system file at `date` ====" \
970 protolist $ROOT > $ATLOG/proto_list_${MACH}
971 echo "==== protolist system file created at `date` ====\n" \
973 if [ "$N_FLAG" != "y" ]; then
977 for f in $f1; do
978 if [ -f "$f" ]; then
979 E1="$E1 -e $f"
981 done
985 if [ -d "$SRC/pkg" ]; then
986 f2="$f2 exceptions/packaging"
989 for f in $f2; do
990 if [ -f "$f" ]; then
991 E2="$E2 -e $f"
993 done
996 if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
997 echo "\n==== Validating manifests against proto area ====\n" >&2
998 if ! ( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$ROOT" ) >&2; then
999 build_extras_ok=n
1005 # ELF verification: ABI (-A) and runtime (-r) checks
1007 if [[ ($build_ok = y) && (($A_FLAG = y) || ($r_FLAG = y)) ]]; then
1008 # Directory ELF-data.$MACH holds the files produced by these tests.
1009 elf_ddir=$SRC/ELF-data.$MACH
1011 # If there is a previous ELF-data backup directory, remove it. Then,
1012 # rotate current ELF-data directory into its place and create a new
1013 # empty directory
1014 rm -rf $elf_ddir.ref
1015 if [[ -d $elf_ddir ]]; then
1016 mv $elf_ddir $elf_ddir.ref
1018 mkdir -p $elf_ddir
1020 # Call find_elf to produce a list of the ELF objects in the proto area.
1021 # This list is passed to check_rtime and interface_check, preventing
1022 # them from separately calling find_elf to do the same work twice.
1023 find_elf -fr $ROOT > $elf_ddir/object_list
1025 if [[ $A_FLAG = y ]]; then
1026 echo "\n==== Check versioning and ABI information ====\n" >&2
1028 # Produce interface description for the proto. Report errors.
1029 interface_check -o -w $elf_ddir -f object_list \
1030 -i interface -E interface.err
1031 if [[ -s $elf_ddir/interface.err ]]; then
1032 cat $elf_ddir/interface.err >&2
1033 build_extras_ok=n
1036 # If ELF_DATA_BASELINE_DIR is defined, compare the new interface
1037 # description file to that from the baseline gate. Issue a
1038 # warning if the baseline is not present, and keep going.
1039 if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
1040 base_ifile="$ELF_DATA_BASELINE_DIR/interface"
1042 echo "\n==== Compare versioning and ABI information" \
1043 "to baseline ====\n" >&2
1044 echo "Baseline: $base_ifile\n"
1046 if [[ -f $base_ifile ]]; then
1047 interface_cmp -d -o $base_ifile \
1048 $elf_ddir/interface > $elf_ddir/interface.cmp
1049 if [[ -s $elf_ddir/interface.cmp ]]; then
1050 echo >&2
1051 cat $elf_ddir/interface.cmp >&2
1052 build_extras_ok=n
1054 else
1055 echo "baseline not available. comparison" \
1056 "skipped" >&2
1062 if [[ $r_FLAG = y ]]; then
1063 echo "\n==== Check ELF runtime attributes ====\n" >&2
1065 # If we're doing a DEBUG build the proto area will be left
1066 # with debuggable objects, thus don't assert -s.
1067 if [[ $D_FLAG = y ]]; then
1068 rtime_sflag=""
1069 else
1070 rtime_sflag="-s"
1072 check_rtime -i -v $rtime_sflag -o -w $elf_ddir \
1073 -D object_list -f object_list -E runtime.err \
1074 -I runtime.attr.raw
1075 if (( $? != 0 )); then
1076 build_extras_ok=n
1079 # check_rtime -I output needs to be sorted in order to
1080 # compare it to that from previous builds.
1081 sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
1082 rm $elf_ddir/runtime.attr.raw
1084 # Report errors
1085 if [[ -s $elf_ddir/runtime.err ]]; then
1086 cat $elf_ddir/runtime.err >&2
1087 build_extras_ok=n
1090 # If there is an ELF-data directory from a previous build,
1091 # then diff the attr files. These files contain information
1092 # about dependencies, versioning, and runpaths. There is some
1093 # overlap with the ABI checking done above, but this also
1094 # flushes out non-ABI interface differences along with the
1095 # other information.
1096 echo "\n==== Diff ELF runtime attributes" \
1097 "(since last build) ====\n" >&2
1099 if [[ -f $elf_ddir.ref/runtime.attr ]]; then
1100 diff $elf_ddir.ref/runtime.attr \
1101 $elf_ddir/runtime.attr >&2
1106 # "make check" begins
1108 if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
1109 # remove old check.out
1110 rm -f $SRC/check.out
1112 rm -f $SRC/check-${MACH}.out
1113 cd $SRC
1114 echo "\n==== cstyle/hdrchk errors ====\n" >&2
1115 if ! $MAKE -ek check ROOT="$ROOT"; then
1116 build_extras_ok=n
1118 else
1119 echo "\n==== No '$MAKE check' ====\n"
1122 echo "\n==== Find core files ====\n" >&2
1124 find $abssrcdirs -name core -a -type f -exec file {} \; >&2
1126 # Verify that the usual lists of files, such as exception lists,
1127 # contain only valid references to files. If the build has failed,
1128 # then don't check the proto area.
1129 CHECK_PATHS=${CHECK_PATHS:-y}
1130 if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
1131 echo "\n==== Check lists of files ====\n" >&2
1132 arg=-b
1133 [ "$build_ok" = y ] && arg=
1134 checkpaths $arg $ROOT > $SRC/check-paths.out 2>&1
1135 if [[ -s $SRC/check-paths.out ]]; then
1136 cat $SRC/check-paths.out >&2
1137 build_extras_ok=n
1141 if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
1142 echo "\n==== Impact on file permissions ====\n" >&2
1144 abspkg=
1145 for d in $abssrcdirs; do
1146 if [ -d "$d/pkg" ]; then
1147 abspkg="$abspkg $d"
1149 done
1151 if [ -n "$abspkg" ]; then
1152 for d in "$abspkg"; do
1153 ( cd $d/pkg ; $MAKE -e pmodes ) >&2
1154 done
1158 if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
1159 if [[ "$D_FLAG" = y ]]; then
1160 do_wsdiff DEBUG $ROOT.prev $ROOT
1161 else
1162 do_wsdiff non-DEBUG $ROOT.prev $ROOT
1166 END_DATE=`date`
1167 echo "==== Nightly $maketype build completed: $END_DATE ====" | \
1168 tee -a $build_time_file
1170 typeset -i10 hours
1171 typeset -Z2 minutes
1172 typeset -Z2 seconds
1174 elapsed_time=$SECONDS
1175 ((hours = elapsed_time / 3600 ))
1176 ((minutes = elapsed_time / 60 % 60))
1177 ((seconds = elapsed_time % 60))
1179 echo "\n==== Total build time ====" | \
1180 tee -a $build_time_file
1181 echo "\nreal ${hours}:${minutes}:${seconds}" | \
1182 tee -a $build_time_file
1185 # All done save for the sweeping up.
1186 # (whichever exit we hit here will trigger the "cleanup" trap which
1187 # optionally sends mail on completion).
1189 if [[ "$build_ok" == "y" ]]; then
1190 if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
1191 exit 0
1195 exit 1