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]
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.
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`
55 print
-u2 "nightly: $*"
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
66 function normal_build
{
68 typeset orig_p_FLAG
="$p_FLAG"
70 if [ "$D_FLAG" = "n" ]; then
71 set_non_debug_build_flags
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
89 eval HOOKCMD
=\$
$HOOKNAME
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
102 if [ -f $TMPDIR/abort
]; then
104 echo "\nAborting at request of $HOOKNAME"
110 # Return library search directive as function of given root.
112 echo "-L$1/lib -L$1/usr/lib"
115 # Return header search directive as function of given root.
117 echo "-I$1/usr/include"
121 # Function to do the build, including package generation.
123 # - LABEL is used to tag build output.
127 INSTALLOG
=install-
${MACH}
131 export ENVLDLIBS1
=`myldlibs $ROOT`
132 export ENVCPPFLAGS1
=`myheaders $ROOT`
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
144 fatal_error
"cannot install headers"
146 if ! make -j$DMAKE_MAX_JOBS -C $SRCTOP/include
install DESTDIR
=$ROOT; then
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
155 fatal_error
"cannot install libraries"
159 # Build the legacy part of the source
161 echo "\n==== Building legacy source at `date` ($LABEL) ====\n"
164 echo "\n==== dmake install ====\n" >&2
165 if ! /bin
/time $MAKE -e install; then
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 \
176 make -C $SRCTOP -j $DMAKE_MAX_JOBS VERBOSE
=yes build DESTDIR
=$ROOT; then
181 echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n"
183 if [ "$this_build_ok" = "y" ]; then
184 make -C ${SRCTOP}/tools
/postbuild clean obj
185 if ! make -j$DMAKE_MAX_JOBS -C ${SRCTOP}/tools
/postbuild
; then
193 # Build and install the onbld tools.
195 # usage: build_tools DESTROOT
197 # returns non-zero status if the build was successful.
199 function build_tools
{
202 INSTALLOG
=install-
${MACH}
204 echo "\n==== Building tools at `date` ====\n" \
206 rm -f ${TOOLS}/${INSTALLOG}.out
208 if ! $MAKE TOOLS_PROTO
=${DESTROOT} -e install; then
215 # Set up to use locally installed tools.
217 # usage: use_tools TOOLSROOT
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
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
241 CTFSTABS
=${TOOLSROOT}/opt
/onbld
/bin
/${MACH}/ctfstabs
243 GENOFFSETS
=${TOOLSROOT}/opt
/onbld
/bin
/genoffsets
247 PATH
="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
248 PATH
="${TOOLSROOT}/opt/onbld/bin:${PATH}"
251 if [ -d "${TOOLSROOT}/opt/onbld" ]; then
252 ONBLD_TOOLS
=${TOOLSROOT}/opt
/onbld
256 echo "\n==== New environment settings. ====\n"
257 echo "STABS=${STABS}"
258 echo "CTFSTABS=${CTFSTABS}"
260 echo "ONBLD_TOOLS=${ONBLD_TOOLS}"
264 # wrapper over wsdiff.
265 # usage: do_wsdiff LABEL OLDPROTO NEWPROTO
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
285 function set_non_debug_build_flags
{
286 export RELEASE_BUILD
; RELEASE_BUILD
=
291 function set_debug_build_flags
{
300 if [ "$OPTHOME" = "" ]; then
305 USAGE
='Usage: nightly [-in] [-V VERS ]
308 -i Fast incremental options (no clobber, check)
309 -V VERS set the build version string to VERS
311 non-DEBUG is the default build type. Build options can be set in the
312 NIGHTLY_OPTIONS variable in env.sh as follows:
314 -A check for ABI differences in .so files
315 -C check for cstyle/hdrchk errors
316 -D do a build with DEBUG on
317 -G gate keeper default group of options (-au)
318 -I integration engineer default group of options (-ampu)
319 -M do not run pmodes (safe file permission checker)
320 -N do not run protocmp
321 -R default group of options for building a release (-mp)
322 -U update proto area in the parent
323 -V VERS set the build version string to VERS
324 -i do an incremental build (no "make clobber")
325 -m send mail to $MAILTO at end of build
327 -r check ELF runtime attributes in the proto area
328 -u update proto_list_$MACH and friends in the parent workspace
329 -w report on differences between previous and current proto areas
332 # A log file will be generated under the name $LOGFILE
333 # for partially completed build and log.`date '+%F'`
334 # in the same directory for fully completed builds.
337 # default values for low-level FLAGS; G I R are group FLAGS
341 i_FLAG
=n
; i_CMD_LINE_FLAG
=n
359 while getopts +iV
:W FLAG
362 i
) i_FLAG
=y
; i_CMD_LINE_FLAG
=y
375 # correct argument count after options
376 shift `expr $OPTIND - 1`
378 envfile
=$
(dirname $0)/env.sh
383 LC_ALL
=C
; export LC_ALL
384 LC_COLLATE
=C
; export LC_COLLATE
385 LC_CTYPE
=C
; export LC_CTYPE
386 LC_MESSAGES
=C
; export LC_MESSAGES
387 LC_MONETARY
=C
; export LC_MONETARY
388 LC_NUMERIC
=C
; export LC_NUMERIC
389 LC_TIME
=C
; export LC_TIME
391 # clear environment variables we know to be bad for the build
393 unset LD_AUDIT LD_AUDIT_32 LD_AUDIT_64
394 unset LD_BIND_NOW LD_BIND_NOW_32 LD_BIND_NOW_64
395 unset LD_BREADTH LD_BREADTH_32 LD_BREADTH_64
396 unset LD_CONFIG LD_CONFIG_32 LD_CONFIG_64
397 unset LD_DEBUG LD_DEBUG_32 LD_DEBUG_64
398 unset LD_DEMANGLE LD_DEMANGLE_32 LD_DEMANGLE_64
399 unset LD_FLAGS LD_FLAGS_32 LD_FLAGS_64
400 unset LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64
401 unset LD_LOADFLTR LD_LOADFLTR_32 LD_LOADFLTR_64
402 unset LD_NOAUDIT LD_NOAUDIT_32 LD_NOAUDIT_64
403 unset LD_NOAUXFLTR LD_NOAUXFLTR_32 LD_NOAUXFLTR_64
404 unset LD_NOCONFIG LD_NOCONFIG_32 LD_NOCONFIG_64
405 unset LD_NODIRCONFIG LD_NODIRCONFIG_32 LD_NODIRCONFIG_64
406 unset LD_NODIRECT LD_NODIRECT_32 LD_NODIRECT_64
407 unset LD_NOLAZYLOAD LD_NOLAZYLOAD_32 LD_NOLAZYLOAD_64
408 unset LD_NOOBJALTER LD_NOOBJALTER_32 LD_NOOBJALTER_64
409 unset LD_NOVERSION LD_NOVERSION_32 LD_NOVERSION_64
410 unset LD_ORIGIN LD_ORIGIN_32 LD_ORIGIN_64
411 unset LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
412 unset LD_PROFILE LD_PROFILE_32 LD_PROFILE_64
424 # To get ONBLD_TOOLS from the environment, it must come from the env file.
425 # If it comes interactively, it is generally TOOLS_PROTO, which will be
426 # clobbered before the compiler version checks, which will therefore fail.
431 # Setup environmental variables
433 if [ -f $envfile ]; then
436 echo "Cannot find env file $envfile"
440 # Check if we have sufficient data to continue...
441 [[ -n "$SRCTOP" ]] || \
442 fatal_error
"Error: Variable SRCTOP not set."
443 [[ -d "${SRCTOP}" ]] || \
444 fatal_error
"Error: ${SRCTOP} is not a directory."
445 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || \
446 fatal_error
"Error: ${SRCTOP}/usr/src/Makefile not found."
449 # place ourselves in a new task, respecting BUILD_PROJECT if set.
451 if [ -z "$BUILD_PROJECT" ]; then
452 /usr
/bin
/newtask
-c $$
454 /usr
/bin
/newtask
-c $$
-p $BUILD_PROJECT
457 ps
-o taskid
= -p $$ |
read build_taskid
458 ps
-o project
= -p $$ |
read build_project
461 # See if NIGHTLY_OPTIONS is set
463 if [ "$NIGHTLY_OPTIONS" = "" ]; then
464 NIGHTLY_OPTIONS
="-aBm"
468 # Note: changes to the option letters here should also be applied to the
469 # bldenv script. `d' is listed for backward compatibility.
471 NIGHTLY_OPTIONS
=-${NIGHTLY_OPTIONS#-}
473 while getopts +ABCDdfGIiMmNpRrwW FLAG
$NIGHTLY_OPTIONS
479 ;; # old version of D
513 if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
514 MAILTO
=`/usr/bin/id -un`
518 PATH
="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/bin"
519 PATH
="$PATH:/usr/bin:/usr/sbin:/usr/ucb"
520 PATH
="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:.:$OPTHOME/SUNWspro/bin"
523 # roots of source trees, both relative to $SRC and absolute.
527 PROTOCMPTERSE
="protocmp.terse -gu"
529 # have we set RELEASE_DATE in our env file?
530 if [ -z "$RELEASE_DATE" ]; then
531 RELEASE_DATE
=$
(LC_ALL
=C
date +"%B %Y")
533 BUILD_DATE
=$
(LC_ALL
=C
date +%Y-
%b-
%d
)
534 BASEWSDIR
=$
(basename $SRCTOP)
536 # we export POUND_SIGN and RELEASE_DATE to speed up the build process
537 # by avoiding repeated shell invocations to evaluate Makefile.master
539 export POUND_SIGN RELEASE_DATE
541 maketype
="distributed"
542 if [[ -z "$MAKE" ]]; then
544 elif [[ ! -x "$MAKE" ]]; then
545 echo "\$MAKE is set to garbage in the environment"
552 if [[ $DMAKE_MAX_JOBS != +([0-9]) ||
$DMAKE_MAX_JOBS -eq 0 ]]
555 if [[ -f $HOME/.
make.machines
]]
557 # Note: there is a hard tab and space character in the []s
559 egrep -i "^[ ]*$hostname[ \.]" \
560 $HOME/.
make.machines |
read host jobs
564 if [[ $maxjobs != +([0-9]) ||
$maxjobs -eq 0 ]]
570 export DMAKE_MAX_JOBS
=$maxjobs
575 DMAKE_OUTPUT_MODE
=TXT2
;
576 export DMAKE_OUTPUT_MODE
578 if [ -z "${ROOT}" ]; then
579 echo "ROOT must be set."
584 # if -V flag was given, reset VERSION to V_ARG
586 if [ "$V_FLAG" = "y" ]; then
590 TMPDIR
="/tmp/nightly.tmpdir.$$"
593 mkdir
-p $TMPDIR ||
exit 1
595 # Tools should only be built non-DEBUG. Keep track of the tools proto
596 # area path relative to $TOOLS, because the latter changes in an
599 # TOOLS_PROTO is included below for builds other than usr/src/tools
600 # that look for this location. For usr/src/tools, this will be
601 # overridden on the $MAKE command line in build_tools().
604 TOOLS_PROTO_REL
=proto
/root_
${MACH}-nd
605 TOOLS_PROTO
=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
607 unset CFLAGS LD_LIBRARY_PATH LDFLAGS
609 # create directories that are automatically removed if the nightly script
610 # fails to start correctly
614 while [ ! -d $dir ]; do
620 for dir
in $toadd; do
622 newlist
="$dir $newlist"
625 [ -z "$torm" ] ||
rmdir $torm
629 newdirlist
="$newlist $newdirlist"
634 [ -d $SRCTOP ] || newdir
$SRCTOP ||
exit 1
636 # since this script assumes the build is from full source, it nullifies
637 # variables likely to have been set by a "ws" script; nullification
638 # confines the search space for headers and libraries to the proto area
639 # built from this immediate source.
648 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
649 ENVLDLIBS1 ENVLDLIBS2
652 # Juggle the logs and optionally send mail on completion.
655 function logshuffle
{
656 LLOG
="$ATLOG/log.`date '+%F.%H:%M'`"
657 if [ -f $LLOG -o -d $LLOG ]; then
661 rm -f "$ATLOG/latest" 2>/dev
/null
665 if [ "$build_ok" = "y" ]; then
666 mv $ATLOG/proto_list_
${MACH} $LLOG
668 if [ -f $ATLOG/proto_list_tools_
${MACH} ]; then
669 mv $ATLOG/proto_list_tools_
${MACH} $LLOG
672 if [ -f $TMPDIR/wsdiff.results
]; then
673 mv $TMPDIR/wsdiff.results
$LLOG
676 if [ -f $TMPDIR/wsdiff-nd.results
]; then
677 mv $TMPDIR/wsdiff-nd.results
$LLOG
694 if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
698 NIGHTLY_STATUS
=$state
699 export NIGHTLY_STATUS
701 run_hook POST_NIGHTLY
$state
702 run_hook SYS_POST_NIGHTLY
$state
704 echo "Subject: Nightly ${MACH} Build of `basename ${SRCTOP}` ${state}." \
706 cat $build_time_file $mail_msg_file \
708 if [ "$m_FLAG" = "y" ]; then
709 /usr
/bin
/mail ${MAILTO} < ${LLOG}/mail_msg
714 ln -s "$LLOG" "$ATLOG/latest"
718 # Remove the temporary files on any exit
724 while [ $# -gt 0 ]; do
731 function cleanup_signal
{
733 # this will trigger cleanup(), above.
738 trap cleanup_signal
1 2 3 15
743 # Create mail_msg_file
745 mail_msg_file
="${TMPDIR}/mail_msg"
747 build_time_file
="${TMPDIR}/build_time"
751 # Move old LOGFILE aside
753 if [ -f $LOGFILE ]; then
754 mv -f $LOGFILE ${LOGFILE}-
757 mkfifo ${TMPDIR}/err.fifo
${TMPDIR}/out.fifo
758 tee $mail_msg_file < ${TMPDIR}/err.fifo
>> $LOGFILE &
760 tee ${TMPDIR}/stdout.txt
< ${TMPDIR}/out.fifo
>> $LOGFILE &
762 exec > ${TMPDIR}/out.fifo
763 exec 2> ${TMPDIR}/err.fifo
770 echo "\n==== Nightly $maketype build started: $START_DATE ====" | \
771 tee -a $build_time_file
773 run_hook SYS_PRE_NIGHTLY
776 echo "\n==== list of environment variables ====\n"
779 echo "Building $VERSION
780 on $(uname -srv)" >&2
782 if [[ ! -f $SRC/Makefile
]]; then
784 echo "\nUnable to find \"Makefile\" in $SRC." >&2
788 # Save the current proto area if we're comparing against the last build
789 if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
790 if [ -d "$ROOT.prev" ]; then
797 [[ -n "${SRCTOP}" ]] || fatal_error
"Error: Variable SRCTOP not set."
798 [[ -d "${SRCTOP}" ]] || fatal_error
"Error: ${SRCTOP} is not a directory."
799 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || fatal_error
"Error: ${SRCTOP}/usr/src/Makefile not found."
802 # Generate the cfgparam files
804 # We have to do this before running *any* make commands.
806 make gen-config || fatal_error
"gen-config failed"
809 # Decide whether to clobber
811 if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
812 echo "\n==== Make clobber at `date` ====\n"
813 echo "\n==== clobber / cleandir ===="
816 # remove old clobber file
817 rm -f $SRC/clobber.out
818 rm -f $SRC/clobber-
${MACH}.out
820 # Remove all .make.state* files, just in case we are restarting
821 # the build after having interrupted a previous 'make clobber'.
822 find . \
( -name SCCS
-o -name .hg
-o -name .svn
-o -name .git \
823 -o -name 'interfaces.*' \
) -prune \
824 -o -name '.make.*' -print |
xargs rm -f
825 if ! $MAKE -ek clobber
; then
829 echo "\n==== Make tools clobber at `date` ====\n"
831 rm -f ${TOOLS}/clobber-
${MACH}.out
833 if ! $MAKE TOOLS_PROTO
=$TOOLS_PROTO -ek clobber
; then
836 rm -rf ${TOOLS_PROTO}
837 mkdir
-p ${TOOLS_PROTO}
840 echo "\n\nClearing $roots"
843 # Get back to a clean workspace as much as possible to catch
844 # problems that only occur on fresh workspaces.
845 # Remove all .make.state* files, libraries, and .o's that may
846 # have been omitted from clobber. A couple of libraries are
847 # under source code control, so leave them alone.
848 # We should probably blow away temporary directories too.
850 find $relsrcdirs \
( -name SCCS
-o -name .hg
-o -name .svn \
851 -o -name .git
-o -name 'interfaces.*' \
) -prune -o \
852 \
( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
853 -name '*.o' \
) -print | \
854 grep -v 'tools/ctf/dwarf/.*/libdwarf' |
xargs rm -f
855 make -C $SRCTOP cleandir
857 echo "\n==== No clobber at `date` ====\n"
861 # Build and use the workspace's tools if requested
863 set_non_debug_build_flags
865 build_tools
${TOOLS_PROTO}
866 if (( $?
!= 0 )); then
869 use_tools
$TOOLS_PROTO
876 if [ "$build_ok" = "y" ]; then
877 echo "\n==== Creating protolist system file at `date` ====" \
878 protolist
$ROOT > $ATLOG/proto_list_
${MACH}
879 echo "==== protolist system file created at `date` ====\n" \
881 if [ "$N_FLAG" != "y" ]; then
893 if [ -d "$SRC/pkg" ]; then
894 f2
="$f2 exceptions/packaging"
905 echo "\n==== Find core files ====\n" >&2
907 find $abssrcdirs -name core
-a -type f
-exec file {} \
; >&2
909 # Verify that the usual lists of files, such as exception lists,
910 # contain only valid references to files. If the build has failed,
911 # then don't check the proto area.
912 CHECK_PATHS
=${CHECK_PATHS:-y}
913 if [ "$CHECK_PATHS" = y
-a "$N_FLAG" != y
]; then
914 echo "\n==== Check lists of files ====\n" >&2
916 [ "$build_ok" = y
] && arg
=
917 checkpaths
$arg $ROOT > $TMPDIR/check-paths.out
2>&1
918 if [[ -s $TMPDIR/check-paths.out
]]; then
919 cat $TMPDIR/check-paths.out
>&2
924 if [ "$M_FLAG" != "y" -a "$build_ok" = y
]; then
925 echo "\n==== Impact on file permissions ====\n" >&2
928 for d
in $abssrcdirs; do
929 if [ -d "$d/pkg" ]; then
934 if [ -n "$abspkg" ]; then
935 for d
in "$abspkg"; do
936 ( cd $d/pkg
; $MAKE -e pmodes
) >&2
941 if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
942 if [[ "$D_FLAG" = y
]]; then
943 do_wsdiff DEBUG
$ROOT.prev
$ROOT
945 do_wsdiff non-DEBUG
$ROOT.prev
$ROOT
950 echo "==== Nightly $maketype build completed: $END_DATE ====" | \
951 tee -a $build_time_file
957 elapsed_time
=$SECONDS
958 hours
=$
(( elapsed_time
/ 3600 ))
959 minutes
=$
(( elapsed_time
/ 60 % 60 ))
960 seconds
=$
((elapsed_time
% 60 ))
962 echo "Total build time ${hours}:${minutes}:${seconds}" |
963 tee -a $build_time_file
966 # All done save for the sweeping up.
967 # (whichever exit we hit here will trigger the "cleanup" trap which
968 # optionally sends mail on completion).
970 if [[ "$build_ok" == "y" ]]; then
971 if [[ "$W_FLAG" == "y" ||
"$build_extras_ok" == "y" ]]; then