1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25 # Copyright 2008, 2010, Richard Lowe
26 # Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
27 # Copyright 2014 Nexenta Systems, Inc. All rights reserved.
28 # Copyright (c) 2017 by Delphix. All rights reserved.
29 #
30 # Based on the nightly script from the integration folks,
31 # Mostly modified and owned by mike_s.
32 # Changes also by kjc, dmk.
33 #
34 # BRINGOVER_WS may be specified in the env file.
35 # The default is the old behavior of CLONE_WS
36 #
37 # -i on the command line, means fast options, so when it's on the
38 # command line (only), lint and check builds are skipped no matter what
39 # the setting of their individual flags are in NIGHTLY_OPTIONS.
40 #
41 # LINTDIRS can be set in the env file, format is a list of:
42 #
43 # /dirname-to-run-lint-on flag
44 #
45 # Where flag is: y - enable lint noise diff output
46 # n - disable lint noise diff output
47 #
48 # For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
49 #
50 # OPTHOME may be set in the environment to override /opt
51 #
52
53 #
54 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
55 # under certain circumstances, which can really screw things up; unset it.
56 #
57 unset CDPATH
58
59 # Get the absolute path of the nightly script that the user invoked. This
60 # may be a relative path, and we need to do this before changing directory.
61 nightly_path=`whence $0`
62
63 #
64 # Keep track of where we found nightly so we can invoke the matching
65 # which_scm script. If that doesn't work, don't go guessing, just rely
66 # on the $PATH settings, which will generally give us either /opt/onbld
67 # or the user's workspace.
68 #
69 WHICH_SCM=$(dirname $nightly_path)/which_scm
70 if [[ ! -x $WHICH_SCM ]]; then
71 WHICH_SCM=which_scm
72 fi
73
74 function fatal_error
75 {
76 print -u2 "nightly: $*"
77 exit 1
78 }
79
80 #
81 # Function to do a DEBUG and non-DEBUG build. Needed because we might
82 # need to do another for the source build, and since we only deliver DEBUG or
83 # non-DEBUG packages.
84 #
85 # usage: normal_build
86 #
87 function normal_build {
88
89 typeset orig_p_FLAG="$p_FLAG"
90 typeset crypto_signer="$CODESIGN_USER"
91
92 suffix=""
93
94 # non-DEBUG build begins
95
96 if [ "$F_FLAG" = "n" ]; then
97 set_non_debug_build_flags
98 CODESIGN_USER="$crypto_signer" \
99 build "non-DEBUG" "$suffix-nd" "-nd" "$MULTI_PROTO"
100 else
101 echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
102 fi
103
104 # non-DEBUG build ends
105
106 # DEBUG build begins
107
108 if [ "$D_FLAG" = "y" ]; then
109 VERSION=$VERSION":debug"
110 set_debug_build_flags
111 CODESIGN_USER="$crypto_signer" \
112 build "DEBUG" "$suffix" "" "$MULTI_PROTO"
113 else
114 echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
115 fi
116
117 # DEBUG build ends
118
119 p_FLAG="$orig_p_FLAG"
120 }
121
122 #
123 # usage: run_hook HOOKNAME ARGS...
124 #
125 # If variable "$HOOKNAME" is defined, insert a section header into
126 # our logs and then run the command with ARGS
127 #
128 function run_hook {
129 HOOKNAME=$1
130 eval HOOKCMD=\$$HOOKNAME
131 shift
132
133 if [ -n "$HOOKCMD" ]; then
134 (
135 echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
136 ( $HOOKCMD "$@" 2>&1 )
137 if [ "$?" -ne 0 ]; then
138 # Let exit status propagate up
139 touch $TMPDIR/abort
140 fi
141 ) | tee -a $mail_msg_file >> $LOGFILE
142
143 if [ -f $TMPDIR/abort ]; then
144 build_ok=n
145 echo "\nAborting at request of $HOOKNAME" |
146 tee -a $mail_msg_file >> $LOGFILE
147 exit 1
148 fi
149 fi
150 }
151
152 # Return library search directive as function of given root.
153 function myldlibs {
154 echo "-L$1/lib -L$1/usr/lib"
155 }
156
157 # Return header search directive as function of given root.
158 function myheaders {
159 echo "-I$1/usr/include"
160 }
161
162 #
163 # Function to do the build, including package generation.
164 # usage: build LABEL SUFFIX ND MULTIPROTO
165 # - LABEL is used to tag build output.
166 # - SUFFIX is used to distinguish files (e.g., DEBUG vs non-DEBUG,
167 # open-only vs full tree).
168 # - ND is "-nd" (non-DEBUG builds) or "" (DEBUG builds).
169 # - If MULTIPROTO is "yes", it means to name the proto area according to
170 # SUFFIX. Otherwise ("no"), (re)use the standard proto area.
171 #
172 function build {
173 LABEL=$1
174 SUFFIX=$2
175 ND=$3
176 MULTIPROTO=$4
177 INSTALLOG=install${SUFFIX}-${MACH}
178 NOISE=noise${SUFFIX}-${MACH}
179 PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
180
181 ORIGROOT=$ROOT
182 [ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
183
184 export ENVLDLIBS1=`myldlibs $ROOT`
185 export ENVCPPFLAGS1=`myheaders $ROOT`
186
187 this_build_ok=y
188 #
189 # Build OS-Networking source
190 #
191 echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
192 >> $LOGFILE
193
194 rm -f $SRC/${INSTALLOG}.out
195 cd $SRC
196 /bin/time $MAKE -e install 2>&1 | \
197 tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
198
199 echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
200 egrep ":" $SRC/${INSTALLOG}.out |
201 egrep -e "(^${MAKE}:|[ ]error[: \n])" | \
202 egrep -v "Ignoring unknown host" | \
203 egrep -v "cc .* -o error " | \
204 egrep -v "warning" | tee $TMPDIR/build_errs${SUFFIX} \
205 >> $mail_msg_file
206 sed -n "/^Undefined[ ]*first referenced$/,/^ld: fatal:/p" \
207 < $SRC/${INSTALLOG}.out >> $mail_msg_file
208 if [[ -s $TMPDIR/build_errs${SUFFIX} ]]; then
209 build_ok=n
210 this_build_ok=n
211 fi
212 grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
213 >> $mail_msg_file
214 if [ "$?" = "0" ]; then
215 build_ok=n
216 this_build_ok=n
217 fi
218
219 echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
220 egrep -i warning: $SRC/${INSTALLOG}.out \
221 | egrep -v '^tic:' \
222 | egrep -v "symbol (\`|')timezone' has differing types:" \
223 | egrep -v "parameter <PSTAMP> set to" \
224 | egrep -v "Ignoring unknown host" \
225 | egrep -v "redefining segment flags attribute for" \
226 | tee $TMPDIR/build_warnings${SUFFIX} >> $mail_msg_file
227 if [[ -s $TMPDIR/build_warnings${SUFFIX} ]]; then
228 build_ok=n
229 this_build_ok=n
230 fi
231
232 echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
233 >> $LOGFILE
234
235 echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
236 tail -3 $SRC/${INSTALLOG}.out >>$mail_msg_file
237
238 if [ "$i_FLAG" = "n" ]; then
239 rm -f $SRC/${NOISE}.ref
240 if [ -f $SRC/${NOISE}.out ]; then
241 mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
242 fi
243 grep : $SRC/${INSTALLOG}.out \
244 | egrep -v '^/' \
245 | egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
246 | egrep -v '^tic:' \
247 | egrep -v '^mcs' \
248 | egrep -v '^LD_LIBRARY_PATH=' \
249 | egrep -v 'ar: creating' \
250 | egrep -v 'ar: writing' \
251 | egrep -v 'conflicts:' \
252 | egrep -v ':saved created' \
253 | egrep -v '^stty.*c:' \
254 | egrep -v '^mfgname.c:' \
255 | egrep -v '^uname-i.c:' \
256 | egrep -v '^volumes.c:' \
257 | egrep -v '^lint library construction:' \
258 | egrep -v 'tsort: INFORM:' \
259 | egrep -v 'stripalign:' \
260 | egrep -v 'chars, width' \
261 | egrep -v "symbol (\`|')timezone' has differing types:" \
262 | egrep -v 'PSTAMP' \
263 | egrep -v '^Manifying' \
264 | egrep -v 'Ignoring unknown host' \
265 | egrep -v 'Processing method:' \
266 | egrep -v '^Writing' \
267 | egrep -v 'spellin1:' \
268 | egrep -v '^adding:' \
269 | egrep -v "^echo 'msgid" \
270 | egrep -v '^echo ' \
271 | egrep -v '\.c:$' \
272 | egrep -v '^Adding file:' \
273 | egrep -v 'CLASSPATH=' \
274 | egrep -v '\/var\/mail\/:saved' \
275 | egrep -v -- '-DUTS_VERSION=' \
276 | egrep -v '^Running Mkbootstrap' \
277 | egrep -v '^Applet length read:' \
278 | egrep -v 'bytes written:' \
279 | egrep -v '^File:SolarisAuthApplet.bin' \
280 | egrep -v -i 'jibversion' \
281 | egrep -v '^Output size:' \
282 | egrep -v '^Solo size statistics:' \
283 | egrep -v '^Using ROM API Version' \
284 | egrep -v '^Zero Signature length:' \
285 | egrep -v '^Note \(probably harmless\):' \
286 | egrep -v '::' \
287 | egrep -v -- '-xcache' \
288 | egrep -v '^\+' \
289 | egrep -v '^cc1: note: -fwritable-strings' \
290 | egrep -v 'svccfg-native -s svc:/' \
291 | sort | uniq >$SRC/${NOISE}.out
292 if [ ! -f $SRC/${NOISE}.ref ]; then
293 cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
294 fi
295 echo "\n==== Build noise differences ($LABEL) ====\n" \
296 >>$mail_msg_file
297 diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
298 fi
299
300 #
301 # Re-sign selected binaries using signing server
302 # (gatekeeper builds only)
303 #
304 if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
305 echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
306 signing_file="${TMPDIR}/signing"
307 rm -f ${signing_file}
308 export CODESIGN_USER
309 signproto $SRC/tools/codesign/creds 2>&1 | \
310 tee -a ${signing_file} >> $LOGFILE
311 echo "\n==== Finished signing proto area at `date` ====\n" \
312 >> $LOGFILE
313 echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
314 >> $mail_msg_file
315 egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
316 if (( $? == 0 )) ; then
317 build_ok=n
318 this_build_ok=n
319 fi
320 fi
321
322 #
323 # Building Packages
324 #
325 if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
326 if [ -d $SRC/pkg ]; then
327 echo "\n==== Creating $LABEL packages at `date` ====\n" \
328 >> $LOGFILE
329 echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
330 rm -rf $PKGARCHIVE >> "$LOGFILE" 2>&1
331 mkdir -p $PKGARCHIVE >> "$LOGFILE" 2>&1
332
333 rm -f $SRC/pkg/${INSTALLOG}.out
334 cd $SRC/pkg
335 /bin/time $MAKE -e install 2>&1 | \
336 tee -a $SRC/pkg/${INSTALLOG}.out >> $LOGFILE
337
338 echo "\n==== package build errors ($LABEL) ====\n" \
339 >> $mail_msg_file
340
341 egrep "${MAKE}|ERROR|WARNING" $SRC/pkg/${INSTALLOG}.out | \
342 grep ':' | \
343 grep -v PSTAMP | \
344 egrep -v "Ignoring unknown host" | \
345 tee $TMPDIR/package >> $mail_msg_file
346 if [[ -s $TMPDIR/package ]]; then
347 build_extras_ok=n
348 this_build_ok=n
349 fi
350 else
351 #
352 # Handle it gracefully if -p was set but there so
353 # no pkg directory.
354 #
355 echo "\n==== No $LABEL packages to build ====\n" \
356 >> $LOGFILE
357 fi
358 else
359 echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
360 fi
361
362 ROOT=$ORIGROOT
363 }
364
365 # Usage: dolint /dir y|n
366 # Arg. 2 is a flag to turn on/off the lint diff output
367 function dolint {
368 if [ ! -d "$1" ]; then
369 echo "dolint error: $1 is not a directory"
370 exit 1
371 fi
372
373 if [ "$2" != "y" -a "$2" != "n" ]; then
374 echo "dolint internal error: $2 should be 'y' or 'n'"
375 exit 1
376 fi
377
378 lintdir=$1
379 dodiff=$2
380 base=`basename $lintdir`
381 LINTOUT=$lintdir/lint-${MACH}.out
382 LINTNOISE=$lintdir/lint-noise-${MACH}
383 export ENVLDLIBS1=`myldlibs $ROOT`
384 export ENVCPPFLAGS1=`myheaders $ROOT`
385
386 set_debug_build_flags
387
388 #
389 # '$MAKE lint' in $lintdir
390 #
391 echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
392
393 # remove old lint.out
394 rm -f $lintdir/lint.out $lintdir/lint-noise.out
395 if [ -f $lintdir/lint-noise.ref ]; then
396 mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
397 fi
398
399 rm -f $LINTOUT
400 cd $lintdir
401 #
402 # Remove all .ln files to ensure a full reference file
403 #
404 rm -f Nothing_to_remove \
405 `find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \) \
406 -prune -o -type f -name '*.ln' -print `
407
408 /bin/time $MAKE -ek lint 2>&1 | \
409 tee -a $LINTOUT >> $LOGFILE
410
411 echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
412
413 grep "$MAKE:" $LINTOUT |
414 egrep -v "Ignoring unknown host" | \
415 tee $TMPDIR/lint_errs >> $mail_msg_file
416 if [[ -s $TMPDIR/lint_errs ]]; then
417 build_extras_ok=n
418 fi
419
420 echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
421
422 echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
423 >>$mail_msg_file
424 tail -3 $LINTOUT >>$mail_msg_file
425
426 rm -f ${LINTNOISE}.ref
427 if [ -f ${LINTNOISE}.out ]; then
428 mv ${LINTNOISE}.out ${LINTNOISE}.ref
429 fi
430 grep : $LINTOUT | \
431 egrep -v '^(real|user|sys)' |
432 egrep -v '(library construction)' | \
433 egrep -v ': global crosschecks' | \
434 egrep -v 'Ignoring unknown host' | \
435 egrep -v '\.c:$' | \
436 sort | uniq > ${LINTNOISE}.out
437 if [ ! -f ${LINTNOISE}.ref ]; then
438 cp ${LINTNOISE}.out ${LINTNOISE}.ref
439 fi
440
441 if [ "$dodiff" != "n" ]; then
442 echo "\n==== lint warnings $base ====\n" \
443 >>$mail_msg_file
444 # should be none, though there are a few that were filtered out
445 # above
446 egrep -i '(warning|lint):' ${LINTNOISE}.out \
447 | sort | uniq | tee $TMPDIR/lint_warns >> $mail_msg_file
448 if [[ -s $TMPDIR/lint_warns ]]; then
449 build_extras_ok=n
450 fi
451 echo "\n==== lint noise differences $base ====\n" \
452 >> $mail_msg_file
453 diff ${LINTNOISE}.ref ${LINTNOISE}.out \
454 >> $mail_msg_file
455 fi
456 }
457
458 #
459 # Build and install the onbld tools.
460 #
461 # usage: build_tools DESTROOT
462 #
463 # returns non-zero status if the build was successful.
464 #
465 function build_tools {
466 DESTROOT=$1
467
468 INSTALLOG=install-${MACH}
469
470 echo "\n==== Building tools at `date` ====\n" \
471 >> $LOGFILE
472
473 rm -f ${TOOLS}/${INSTALLOG}.out
474 cd ${TOOLS}
475 /bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install 2>&1 | \
476 tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
477
478 echo "\n==== Tools build errors ====\n" >> $mail_msg_file
479
480 egrep ":" ${TOOLS}/${INSTALLOG}.out |
481 egrep -e "(${MAKE}:|[ ]error[: \n])" | \
482 egrep -v "Ignoring unknown host" | \
483 egrep -v warning | tee $TMPDIR/tools_errors >> $mail_msg_file
484
485 if [[ -s $TMPDIR/tools_errors ]]; then
486 return 1
487 fi
488 return 0
489 }
490
491 function staffer {
492 if [ $ISUSER -ne 0 ]; then
493 "$@"
494 else
495 arg="\"$1\""
496 shift
497 for i
498 do
499 arg="$arg \"$i\""
500 done
501 eval su $STAFFER -c \'$arg\'
502 fi
503 }
504
505 #
506 # Verify that the closed bins are present
507 #
508 function check_closed_bins {
509 if [[ -n "$ON_CLOSED_BINS" && ! -d "$ON_CLOSED_BINS" ]]; then
510 echo "ON_CLOSED_BINS must point to the closed binaries tree."
511 build_ok=n
512 exit 1
513 fi
514 }
515
516 #
517 # wrapper over wsdiff.
518 # usage: do_wsdiff LABEL OLDPROTO NEWPROTO
519 #
520 function do_wsdiff {
521 label=$1
522 oldproto=$2
523 newproto=$3
524
525 wsdiff="wsdiff"
526 [ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
527
528 echo "\n==== Getting object changes since last build at `date`" \
529 "($label) ====\n" | tee -a $LOGFILE >> $mail_msg_file
530 $wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
531 tee -a $LOGFILE >> $mail_msg_file
532 echo "\n==== Object changes determined at `date` ($label) ====\n" | \
533 tee -a $LOGFILE >> $mail_msg_file
534 }
535
536 #
537 # Functions for setting build flags (DEBUG/non-DEBUG). Keep them
538 # together.
539 #
540
541 function set_non_debug_build_flags {
542 export RELEASE_BUILD ; RELEASE_BUILD=
543 unset EXTRA_OPTIONS
544 unset EXTRA_CFLAGS
545 }
546
547 function set_debug_build_flags {
548 unset RELEASE_BUILD
549 unset EXTRA_OPTIONS
550 unset EXTRA_CFLAGS
551 }
552
553
554 MACH=`uname -p`
555
556 if [ "$OPTHOME" = "" ]; then
557 OPTHOME=/opt
558 export OPTHOME
559 fi
560
561 USAGE='Usage: nightly [-in] [+t] [-V VERS ] <env_file>
562
563 Where:
564 -i Fast incremental options (no clobber, lint, check)
565 -n Do not do a bringover
566 +t Use the build tools in $ONBLD_TOOLS/bin
567 -V VERS set the build version string to VERS
568
569 <env_file> file in Bourne shell syntax that sets and exports
570 variables that configure the operation of this script and many of
571 the scripts this one calls. If <env_file> does not exist,
572 it will be looked for in $OPTHOME/onbld/env.
573
574 non-DEBUG is the default build type. Build options can be set in the
575 NIGHTLY_OPTIONS variable in the <env_file> as follows:
576
577 -A check for ABI differences in .so files
578 -C check for cstyle/hdrchk errors
579 -D do a build with DEBUG on
580 -F do _not_ do a non-DEBUG build
581 -G gate keeper default group of options (-au)
582 -I integration engineer default group of options (-ampu)
583 -M do not run pmodes (safe file permission checker)
584 -N do not run protocmp
585 -R default group of options for building a release (-mp)
586 -U update proto area in the parent
587 -V VERS set the build version string to VERS
588 -f find unreferenced files
589 -i do an incremental build (no "make clobber")
590 -l do "make lint" in $LINTDIRS (default: $SRC y)
591 -m send mail to $MAILTO at end of build
592 -n do not do a bringover
593 -p create packages
594 -r check ELF runtime attributes in the proto area
595 -t build and use the tools in $SRC/tools (default setting)
596 +t Use the build tools in $ONBLD_TOOLS/bin
597 -u update proto_list_$MACH and friends in the parent workspace;
598 when used with -f, also build an unrefmaster.out in the parent
599 -w report on differences between previous and current proto areas
600 '
601 #
602 # A log file will be generated under the name $LOGFILE
603 # for partially completed build and log.`date '+%F'`
604 # in the same directory for fully completed builds.
605 #
606
607 # default values for low-level FLAGS; G I R are group FLAGS
608 A_FLAG=n
609 C_FLAG=n
610 D_FLAG=n
611 F_FLAG=n
612 f_FLAG=n
613 i_FLAG=n; i_CMD_LINE_FLAG=n
614 l_FLAG=n
615 M_FLAG=n
616 m_FLAG=n
617 N_FLAG=n
618 n_FLAG=n
619 p_FLAG=n
620 r_FLAG=n
621 t_FLAG=y
622 U_FLAG=n
623 u_FLAG=n
624 V_FLAG=n
625 w_FLAG=n
626 W_FLAG=n
627 #
628 build_ok=y
629 build_extras_ok=y
630
631 #
632 # examine arguments
633 #
634
635 OPTIND=1
636 while getopts +intV:W FLAG
637 do
638 case $FLAG in
639 i ) i_FLAG=y; i_CMD_LINE_FLAG=y
640 ;;
641 n ) n_FLAG=y
642 ;;
643 +t ) t_FLAG=n
644 ;;
645 V ) V_FLAG=y
646 V_ARG="$OPTARG"
647 ;;
648 W ) W_FLAG=y
649 ;;
650 \? ) echo "$USAGE"
651 exit 1
652 ;;
653 esac
654 done
655
656 # correct argument count after options
657 shift `expr $OPTIND - 1`
658
659 # test that the path to the environment-setting file was given
660 if [ $# -ne 1 ]; then
661 echo "$USAGE"
662 exit 1
663 fi
664
665 # check if user is running nightly as root
666 # ISUSER is set non-zero if an ordinary user runs nightly, or is zero
667 # when root invokes nightly.
668 /usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
669 ISUSER=$?; export ISUSER
670
671 #
672 # force locale to C
673 LANG=C; export LANG
674 LC_ALL=C; export LC_ALL
675 LC_COLLATE=C; export LC_COLLATE
676 LC_CTYPE=C; export LC_CTYPE
677 LC_MESSAGES=C; export LC_MESSAGES
678 LC_MONETARY=C; export LC_MONETARY
679 LC_NUMERIC=C; export LC_NUMERIC
680 LC_TIME=C; export LC_TIME
681
682 # clear environment variables we know to be bad for the build
683 unset LD_OPTIONS
684 unset LD_AUDIT LD_AUDIT_32 LD_AUDIT_64
685 unset LD_BIND_NOW LD_BIND_NOW_32 LD_BIND_NOW_64
686 unset LD_BREADTH LD_BREADTH_32 LD_BREADTH_64
687 unset LD_CONFIG LD_CONFIG_32 LD_CONFIG_64
688 unset LD_DEBUG LD_DEBUG_32 LD_DEBUG_64
689 unset LD_DEMANGLE LD_DEMANGLE_32 LD_DEMANGLE_64
690 unset LD_FLAGS LD_FLAGS_32 LD_FLAGS_64
691 unset LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64
692 unset LD_LOADFLTR LD_LOADFLTR_32 LD_LOADFLTR_64
693 unset LD_NOAUDIT LD_NOAUDIT_32 LD_NOAUDIT_64
694 unset LD_NOAUXFLTR LD_NOAUXFLTR_32 LD_NOAUXFLTR_64
695 unset LD_NOCONFIG LD_NOCONFIG_32 LD_NOCONFIG_64
696 unset LD_NODIRCONFIG LD_NODIRCONFIG_32 LD_NODIRCONFIG_64
697 unset LD_NODIRECT LD_NODIRECT_32 LD_NODIRECT_64
698 unset LD_NOLAZYLOAD LD_NOLAZYLOAD_32 LD_NOLAZYLOAD_64
699 unset LD_NOOBJALTER LD_NOOBJALTER_32 LD_NOOBJALTER_64
700 unset LD_NOVERSION LD_NOVERSION_32 LD_NOVERSION_64
701 unset LD_ORIGIN LD_ORIGIN_32 LD_ORIGIN_64
702 unset LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
703 unset LD_PROFILE LD_PROFILE_32 LD_PROFILE_64
704
705 unset CONFIG
706 unset GROUP
707 unset OWNER
708 unset REMOTE
709 unset ENV
710 unset ARCH
711 unset CLASSPATH
712 unset NAME
713
714 #
715 # To get ONBLD_TOOLS from the environment, it must come from the env file.
716 # If it comes interactively, it is generally TOOLS_PROTO, which will be
717 # clobbered before the compiler version checks, which will therefore fail.
718 #
719 unset ONBLD_TOOLS
720
721 #
722 # Setup environmental variables
723 #
724 if [ -f /etc/nightly.conf ]; then
725 . /etc/nightly.conf
726 fi
727
728 if [ -f $1 ]; then
729 if [[ $1 = */* ]]; then
730 . $1
731 else
732 . ./$1
733 fi
734 else
735 if [ -f $OPTHOME/onbld/env/$1 ]; then
736 . $OPTHOME/onbld/env/$1
737 else
738 echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
739 exit 1
740 fi
741 fi
742
743 # contents of stdenv.sh inserted after next line:
744 # STDENV_START
745 # STDENV_END
746
747 # Check if we have sufficient data to continue...
748 [[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
749 if [[ "${NIGHTLY_OPTIONS}" == ~(F)n ]] ; then
750 # Check if the gate data are valid if we don't do a "bringover" below
751 [[ -d "${CODEMGR_WS}" ]] || \
752 fatal_error "Error: ${CODEMGR_WS} is not a directory."
753 [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || \
754 fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
755 fi
756
757 #
758 # place ourselves in a new task, respecting BUILD_PROJECT if set.
759 #
760 if [ -z "$BUILD_PROJECT" ]; then
761 /usr/bin/newtask -c $$
762 else
763 /usr/bin/newtask -c $$ -p $BUILD_PROJECT
764 fi
765
766 ps -o taskid= -p $$ | read build_taskid
767 ps -o project= -p $$ | read build_project
768
769 #
770 # See if NIGHTLY_OPTIONS is set
771 #
772 if [ "$NIGHTLY_OPTIONS" = "" ]; then
773 NIGHTLY_OPTIONS="-aBm"
774 fi
775
776 #
777 # If BRINGOVER_WS was not specified, let it default to CLONE_WS
778 #
779 if [ "$BRINGOVER_WS" = "" ]; then
780 BRINGOVER_WS=$CLONE_WS
781 fi
782
783 #
784 # If BRINGOVER_FILES was not specified, default to usr
785 #
786 if [ "$BRINGOVER_FILES" = "" ]; then
787 BRINGOVER_FILES="usr"
788 fi
789
790 check_closed_bins
791
792 #
793 # Note: changes to the option letters here should also be applied to the
794 # bldenv script. `d' is listed for backward compatibility.
795 #
796 NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
797 OPTIND=1
798 while getopts +ABCDdFfGIilMmNnpRrtUuwW FLAG $NIGHTLY_OPTIONS
799 do
800 case $FLAG in
801 A ) A_FLAG=y
802 ;;
803 B ) D_FLAG=y
804 ;; # old version of D
805 C ) C_FLAG=y
806 ;;
807 D ) D_FLAG=y
808 ;;
809 F ) F_FLAG=y
810 ;;
811 f ) f_FLAG=y
812 ;;
813 G ) u_FLAG=y
814 ;;
815 I ) m_FLAG=y
816 p_FLAG=y
817 u_FLAG=y
818 ;;
819 i ) i_FLAG=y
820 ;;
821 l ) l_FLAG=y
822 ;;
823 M ) M_FLAG=y
824 ;;
825 m ) m_FLAG=y
826 ;;
827 N ) N_FLAG=y
828 ;;
829 n ) n_FLAG=y
830 ;;
831 p ) p_FLAG=y
832 ;;
833 R ) m_FLAG=y
834 p_FLAG=y
835 ;;
836 r ) r_FLAG=y
837 ;;
838 +t ) t_FLAG=n
839 ;;
840 U ) if [ -z "${PARENT_ROOT}" ]; then
841 echo "PARENT_ROOT must be set if the U flag is" \
842 "present in NIGHTLY_OPTIONS."
843 exit 1
844 fi
845 NIGHTLY_PARENT_ROOT=$PARENT_ROOT
846 if [ -n "${PARENT_TOOLS_ROOT}" ]; then
847 NIGHTLY_PARENT_TOOLS_ROOT=$PARENT_TOOLS_ROOT
848 fi
849 U_FLAG=y
850 ;;
851 u ) u_FLAG=y
852 ;;
853 w ) w_FLAG=y
854 ;;
855 W ) W_FLAG=y
856 ;;
857 \? ) echo "$USAGE"
858 exit 1
859 ;;
860 esac
861 done
862
863 if [ $ISUSER -ne 0 ]; then
864 # Set default value for STAFFER, if needed.
865 if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
866 STAFFER=`/usr/xpg4/bin/id -un`
867 export STAFFER
868 fi
869 fi
870
871 if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
872 MAILTO=$STAFFER
873 export MAILTO
874 fi
875
876 PATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
877 PATH="$PATH:$OPTHOME/SUNWspro/bin:/usr/bin:/usr/sbin:/usr/ucb"
878 PATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
879 export PATH
880
881 # roots of source trees, both relative to $SRC and absolute.
882 relsrcdirs="."
883 abssrcdirs="$SRC"
884
885 PROTOCMPTERSE="protocmp.terse -gu"
886 POUND_SIGN="#"
887 # have we set RELEASE_DATE in our env file?
888 if [ -z "$RELEASE_DATE" ]; then
889 RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
890 fi
891 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
892 BASEWSDIR=$(basename $CODEMGR_WS)
893 DEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
894
895 # we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
896 # by avoiding repeated shell invocations to evaluate Makefile.master
897 # definitions.
898 export POUND_SIGN RELEASE_DATE DEV_CM
899
900 maketype="distributed"
901 if [[ -z "$MAKE" ]]; then
902 MAKE=dmake
903 elif [[ ! -x "$MAKE" ]]; then
904 echo "\$MAKE is set to garbage in the environment"
905 exit 1
906 fi
907 export PATH
908 export MAKE
909
910 if [ "${SUNWSPRO}" != "" ]; then
911 PATH="${SUNWSPRO}/bin:$PATH"
912 export PATH
913 fi
914
915 hostname=$(uname -n)
916 if [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
917 then
918 maxjobs=
919 if [[ -f $HOME/.make.machines ]]
920 then
921 # Note: there is a hard tab and space character in the []s
922 # below.
923 egrep -i "^[ ]*$hostname[ \.]" \
924 $HOME/.make.machines | read host jobs
925 maxjobs=${jobs##*=}
926 fi
927
928 if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
929 then
930 # default
931 maxjobs=4
932 fi
933
934 export DMAKE_MAX_JOBS=$maxjobs
935 fi
936
937 DMAKE_MODE=parallel;
938 export DMAKE_MODE
939
940 if [ -z "${ROOT}" ]; then
941 echo "ROOT must be set."
942 exit 1
943 fi
944
945 #
946 # if -V flag was given, reset VERSION to V_ARG
947 #
948 if [ "$V_FLAG" = "y" ]; then
949 VERSION=$V_ARG
950 fi
951
952 TMPDIR="/tmp/nightly.tmpdir.$$"
953 export TMPDIR
954 rm -rf ${TMPDIR}
955 mkdir -p $TMPDIR || exit 1
956 chmod 777 $TMPDIR
957
958 #
959 # Tools should only be built non-DEBUG. Keep track of the tools proto
960 # area path relative to $TOOLS, because the latter changes in an
961 # export build.
962 #
963 # TOOLS_PROTO is included below for builds other than usr/src/tools
964 # that look for this location. For usr/src/tools, this will be
965 # overridden on the $MAKE command line in build_tools().
966 #
967 TOOLS=${SRC}/tools
968 TOOLS_PROTO_REL=proto/root_${MACH}-nd
969 TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
970
971 unset CFLAGS LD_LIBRARY_PATH LDFLAGS
972
973 # create directories that are automatically removed if the nightly script
974 # fails to start correctly
975 function newdir {
976 dir=$1
977 toadd=
978 while [ ! -d $dir ]; do
979 toadd="$dir $toadd"
980 dir=`dirname $dir`
981 done
982 torm=
983 newlist=
984 for dir in $toadd; do
985 if staffer mkdir $dir; then
986 newlist="$ISUSER $dir $newlist"
987 torm="$dir $torm"
988 else
989 [ -z "$torm" ] || staffer rmdir $torm
990 return 1
991 fi
992 done
993 newdirlist="$newlist $newdirlist"
994 return 0
995 }
996 newdirlist=
997
998 [ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
999
1000 # since this script assumes the build is from full source, it nullifies
1001 # variables likely to have been set by a "ws" script; nullification
1002 # confines the search space for headers and libraries to the proto area
1003 # built from this immediate source.
1004 ENVLDLIBS1=
1005 ENVLDLIBS2=
1006 ENVLDLIBS3=
1007 ENVCPPFLAGS1=
1008 ENVCPPFLAGS2=
1009 ENVCPPFLAGS3=
1010 ENVCPPFLAGS4=
1011 PARENT_ROOT=
1012
1013 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
1014 ENVLDLIBS1 ENVLDLIBS2 PARENT_ROOT
1015
1016 PKGARCHIVE_ORIG=$PKGARCHIVE
1017
1018 #
1019 # Juggle the logs and optionally send mail on completion.
1020 #
1021
1022 function logshuffle {
1023 LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
1024 if [ -f $LLOG -o -d $LLOG ]; then
1025 LLOG=$LLOG.$$
1026 fi
1027 mkdir $LLOG
1028 export LLOG
1029
1030 if [ "$build_ok" = "y" ]; then
1031 mv $ATLOG/proto_list_${MACH} $LLOG
1032
1033 if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
1034 mv $ATLOG/proto_list_tools_${MACH} $LLOG
1035 fi
1036
1037 if [ -f $TMPDIR/wsdiff.results ]; then
1038 mv $TMPDIR/wsdiff.results $LLOG
1039 fi
1040
1041 if [ -f $TMPDIR/wsdiff-nd.results ]; then
1042 mv $TMPDIR/wsdiff-nd.results $LLOG
1043 fi
1044 fi
1045
1046 #
1047 # Now that we're about to send mail, it's time to check the noise
1048 # file. In the event that an error occurs beyond this point, it will
1049 # be recorded in the nightly.log file, but nowhere else. This would
1050 # include only errors that cause the copying of the noise log to fail
1051 # or the mail itself not to be sent.
1052 #
1053
1054 exec >>$LOGFILE 2>&1
1055 if [ -s $build_noise_file ]; then
1056 echo "\n==== Nightly build noise ====\n" |
1057 tee -a $LOGFILE >>$mail_msg_file
1058 cat $build_noise_file >>$LOGFILE
1059 cat $build_noise_file >>$mail_msg_file
1060 echo | tee -a $LOGFILE >>$mail_msg_file
1061 fi
1062 rm -f $build_noise_file
1063
1064 case "$build_ok" in
1065 y)
1066 state=Completed
1067 ;;
1068 i)
1069 state=Interrupted
1070 ;;
1071 *)
1072 state=Failed
1073 ;;
1074 esac
1075
1076 if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
1077 state=Failed
1078 fi
1079
1080 NIGHTLY_STATUS=$state
1081 export NIGHTLY_STATUS
1082
1083 # Want ${LLOG}/mail_msg available to POST_NIGHTLY
1084 cat $build_time_file $build_environ_file $mail_msg_file \
1085 > ${LLOG}/mail_msg
1086
1087 run_hook POST_NIGHTLY $state
1088 run_hook SYS_POST_NIGHTLY $state
1089
1090 #
1091 # mailx(1) sets From: based on the -r flag
1092 # if it is given.
1093 #
1094 mailx_r=
1095 if [[ -n "${MAILFROM}" ]]; then
1096 mailx_r="-r ${MAILFROM}"
1097 fi
1098
1099 if [ "$m_FLAG" = "y" ]; then
1100 cat ${LLOG}/mail_msg | /usr/bin/mailx ${mailx_r} -s \
1101 "Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
1102 ${MAILTO}
1103 fi
1104
1105 if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
1106 staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
1107 staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
1108 fi
1109
1110 mv $LOGFILE $LLOG
1111 }
1112
1113 #
1114 # Remove the locks and temporary files on any exit
1115 #
1116 function cleanup {
1117 logshuffle
1118
1119 [ -z "$lockfile" ] || staffer rm -f $lockfile
1120 [ -z "$atloglockfile" ] || rm -f $atloglockfile
1121 [ -z "$ulockfile" ] || staffer rm -f $ulockfile
1122 [ -z "$Ulockfile" ] || rm -f $Ulockfile
1123
1124 set -- $newdirlist
1125 while [ $# -gt 0 ]; do
1126 ISUSER=$1 staffer rmdir $2
1127 shift; shift
1128 done
1129 rm -rf $TMPDIR
1130 }
1131
1132 function cleanup_signal {
1133 build_ok=i
1134 # this will trigger cleanup(), above.
1135 exit 1
1136 }
1137
1138 trap cleanup 0
1139 trap cleanup_signal 1 2 3 15
1140
1141 #
1142 # Generic lock file processing -- make sure that the lock file doesn't
1143 # exist. If it does, it should name the build host and PID. If it
1144 # doesn't, then make sure we can create it. Clean up locks that are
1145 # known to be stale (assumes host name is unique among build systems
1146 # for the workspace).
1147 #
1148 function create_lock {
1149 lockf=$1
1150 lockvar=$2
1151
1152 ldir=`dirname $lockf`
1153 [ -d $ldir ] || newdir $ldir || exit 1
1154 eval $lockvar=$lockf
1155
1156 while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
1157 basews=`basename $CODEMGR_WS`
1158 ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
1159 if [ "$host" != "$hostname" ]; then
1160 echo "$MACH build of $basews apparently" \
1161 "already started by $user on $host as $pid."
1162 exit 1
1163 elif kill -s 0 $pid 2>/dev/null; then
1164 echo "$MACH build of $basews already started" \
1165 "by $user as $pid."
1166 exit 1
1167 else
1168 # stale lock; clear it out and try again
1169 rm -f $lockf
1170 fi
1171 done
1172 }
1173
1174 #
1175 # Return the list of interesting proto areas, depending on the current
1176 # options.
1177 #
1178 function allprotos {
1179 typeset roots="$ROOT"
1180
1181 if [[ "$F_FLAG" = n && "$MULTI_PROTO" = yes ]]; then
1182 roots="$roots $ROOT-nd"
1183 fi
1184
1185 echo $roots
1186 }
1187
1188 # Ensure no other instance of this script is running on this host.
1189 # LOCKNAME can be set in <env_file>, and is by default, but is not
1190 # required due to the use of $ATLOG below.
1191 if [ -n "$LOCKNAME" ]; then
1192 create_lock /tmp/$LOCKNAME "lockfile"
1193 fi
1194 #
1195 # Create from one, two, or three other locks:
1196 # $ATLOG/nightly.lock
1197 # - protects against multiple builds in same workspace
1198 # $PARENT_WS/usr/src/nightly.$MACH.lock
1199 # - protects against multiple 'u' copy-backs
1200 # $NIGHTLY_PARENT_ROOT/nightly.lock
1201 # - protects against multiple 'U' copy-backs
1202 #
1203 # Overriding ISUSER to 1 causes the lock to be created as root if the
1204 # script is run as root. The default is to create it as $STAFFER.
1205 ISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
1206 if [ "$u_FLAG" = "y" ]; then
1207 create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
1208 fi
1209 if [ "$U_FLAG" = "y" ]; then
1210 # NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
1211 ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
1212 fi
1213
1214 # Locks have been taken, so we're doing a build and we're committed to
1215 # the directories we may have created so far.
1216 newdirlist=
1217
1218 #
1219 # Create mail_msg_file
1220 #
1221 mail_msg_file="${TMPDIR}/mail_msg"
1222 touch $mail_msg_file
1223 build_time_file="${TMPDIR}/build_time"
1224 build_environ_file="${TMPDIR}/build_environ"
1225 touch $build_environ_file
1226 #
1227 # Move old LOGFILE aside
1228 # ATLOG directory already made by 'create_lock' above
1229 #
1230 if [ -f $LOGFILE ]; then
1231 mv -f $LOGFILE ${LOGFILE}-
1232 fi
1233 #
1234 # Build OsNet source
1235 #
1236 START_DATE=`date`
1237 SECONDS=0
1238 echo "\n==== Nightly $maketype build started: $START_DATE ====" \
1239 | tee -a $LOGFILE > $build_time_file
1240
1241 echo "\nBuild project: $build_project\nBuild taskid: $build_taskid" | \
1242 tee -a $mail_msg_file >> $LOGFILE
1243
1244 # make sure we log only to the nightly build file
1245 build_noise_file="${TMPDIR}/build_noise"
1246 exec </dev/null >$build_noise_file 2>&1
1247
1248 run_hook SYS_PRE_NIGHTLY
1249 run_hook PRE_NIGHTLY
1250
1251 echo "\n==== list of environment variables ====\n" >> $LOGFILE
1252 env >> $LOGFILE
1253
1254 echo "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
1255
1256 if [ "$N_FLAG" = "y" ]; then
1257 if [ "$p_FLAG" = "y" ]; then
1258 cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1259 WARNING: the p option (create packages) is set, but so is the N option (do
1260 not run protocmp); this is dangerous; you should unset the N option
1261 EOF
1262 else
1263 cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1264 Warning: the N option (do not run protocmp) is set; it probably shouldn't be
1265 EOF
1266 fi
1267 echo "" | tee -a $mail_msg_file >> $LOGFILE
1268 fi
1269
1270 if [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
1271 #
1272 # In the past we just complained but went ahead with the lint
1273 # pass, even though the proto area was built non-DEBUG. It's
1274 # unlikely that non-DEBUG headers will make a difference, but
1275 # rather than assuming it's a safe combination, force the user
1276 # to specify a DEBUG build.
1277 #
1278 echo "WARNING: DEBUG build not requested; disabling lint.\n" \
1279 | tee -a $mail_msg_file >> $LOGFILE
1280 l_FLAG=n
1281 fi
1282
1283 if [ "$f_FLAG" = "y" ]; then
1284 if [ "$i_FLAG" = "y" ]; then
1285 echo "WARNING: the -f flag cannot be used during incremental" \
1286 "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
1287 f_FLAG=n
1288 fi
1289 if [ "${l_FLAG}${p_FLAG}" != "yy" ]; then
1290 echo "WARNING: the -f flag requires -l, and -p;" \
1291 "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
1292 f_FLAG=n
1293 fi
1294 fi
1295
1296 if [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
1297 echo "WARNING: -w specified, but $ROOT does not exist;" \
1298 "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
1299 w_FLAG=n
1300 fi
1301
1302 case $MULTI_PROTO in
1303 yes|no) ;;
1304 *)
1305 echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
1306 "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
1307 echo "Setting MULTI_PROTO to \"no\".\n" | \
1308 tee -a $mail_msg_file >> $LOGFILE
1309 export MULTI_PROTO=no
1310 ;;
1311 esac
1312
1313 echo "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
1314 echo $VERSION | tee -a $mail_msg_file >> $LOGFILE
1315
1316 # Save the current proto area if we're comparing against the last build
1317 if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
1318 if [ -d "$ROOT.prev" ]; then
1319 rm -rf $ROOT.prev
1320 fi
1321 mv $ROOT $ROOT.prev
1322 fi
1323
1324 # Same for non-DEBUG proto area
1325 if [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
1326 if [ -d "$ROOT-nd.prev" ]; then
1327 rm -rf $ROOT-nd.prev
1328 fi
1329 mv $ROOT-nd $ROOT-nd.prev
1330 fi
1331
1332 #
1333 # Echo the SCM type of the parent workspace, this can't just be which_scm
1334 # as that does not know how to identify various network repositories.
1335 #
1336 function parent_wstype {
1337 typeset scm_type junk
1338
1339 CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
1340 | read scm_type junk
1341 if [[ -z "$scm_type" || "$scm_type" == unknown ]]; then
1342 # Probe BRINGOVER_WS to determine its type
1343 if [[ $BRINGOVER_WS == ssh://* ]]; then
1344 scm_type="mercurial"
1345 elif [[ $BRINGOVER_WS == http://* ]] && \
1346 wget -q -O- --save-headers "$BRINGOVER_WS/?cmd=heads" | \
1347 egrep -s "application/mercurial" 2> /dev/null; then
1348 scm_type="mercurial"
1349 else
1350 scm_type="none"
1351 fi
1352 fi
1353
1354 # fold both unsupported and unrecognized results into "none"
1355 case "$scm_type" in
1356 mercurial)
1357 ;;
1358 *) scm_type=none
1359 ;;
1360 esac
1361
1362 echo $scm_type
1363 }
1364
1365 # Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
1366 function child_wstype {
1367 typeset scm_type junk
1368
1369 # Probe CODEMGR_WS to determine its type
1370 if [[ -d $CODEMGR_WS ]]; then
1371 $WHICH_SCM | read scm_type junk || exit 1
1372 fi
1373
1374 case "$scm_type" in
1375 none|git|mercurial)
1376 ;;
1377 *) scm_type=none
1378 ;;
1379 esac
1380
1381 echo $scm_type
1382 }
1383
1384 SCM_TYPE=$(child_wstype)
1385
1386 #
1387 # Decide whether to clobber
1388 #
1389 if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
1390 echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
1391
1392 cd $SRC
1393 # remove old clobber file
1394 rm -f $SRC/clobber.out
1395 rm -f $SRC/clobber-${MACH}.out
1396
1397 # Remove all .make.state* files, just in case we are restarting
1398 # the build after having interrupted a previous 'make clobber'.
1399 find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
1400 -o -name 'interfaces.*' \) -prune \
1401 -o -name '.make.*' -print | xargs rm -f
1402
1403 $MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
1404 echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
1405 grep "$MAKE:" $SRC/clobber-${MACH}.out |
1406 egrep -v "Ignoring unknown host" | \
1407 tee $TMPDIR/clobber_errs >> $mail_msg_file
1408
1409 if [[ -s $TMPDIR/clobber_errs ]]; then
1410 build_extras_ok=n
1411 fi
1412
1413 if [[ "$t_FLAG" = "y" ]]; then
1414 echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
1415 cd ${TOOLS}
1416 rm -f ${TOOLS}/clobber-${MACH}.out
1417 $MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \
1418 tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
1419 echo "\n==== Make tools clobber ERRORS ====\n" \
1420 >> $mail_msg_file
1421 grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
1422 >> $mail_msg_file
1423 if (( $? == 0 )); then
1424 build_extras_ok=n
1425 fi
1426 rm -rf ${TOOLS_PROTO}
1427 mkdir -p ${TOOLS_PROTO}
1428 fi
1429
1430 typeset roots=$(allprotos)
1431 echo "\n\nClearing $roots" >> "$LOGFILE"
1432 rm -rf $roots
1433
1434 # Get back to a clean workspace as much as possible to catch
1435 # problems that only occur on fresh workspaces.
1436 # Remove all .make.state* files, libraries, and .o's that may
1437 # have been omitted from clobber. A couple of libraries are
1438 # under source code control, so leave them alone.
1439 # We should probably blow away temporary directories too.
1440 cd $SRC
1441 find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
1442 -o -name .git -o -name 'interfaces.*' \) -prune -o \
1443 \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
1444 -name '*.o' \) -print | \
1445 grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
1446 else
1447 echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
1448 fi
1449
1450 type bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
1451 typeset -x PATH=$PATH
1452
1453 # If the repository doesn't exist yet, then we want to populate it.
1454 if [[ ! -d $CODEMGR_WS/.hg ]]; then
1455 staffer hg init $CODEMGR_WS
1456 staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
1457 staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
1458 touch $TMPDIR/new_repository
1459 fi
1460
1461 typeset -x HGMERGE="/bin/false"
1462
1463 #
1464 # If the user has changes, regardless of whether those changes are
1465 # committed, and regardless of whether those changes conflict, then
1466 # we'll attempt to merge them either implicitly (uncommitted) or
1467 # explicitly (committed).
1468 #
1469 # These are the messages we'll use to help clarify mercurial output
1470 # in those cases.
1471 #
1472 typeset mergefailmsg="\
1473 ***\n\
1474 *** nightly was unable to automatically merge your changes. You should\n\
1475 *** redo the full merge manually, following the steps outlined by mercurial\n\
1476 *** above, then restart nightly.\n\
1477 ***\n"
1478 typeset mergepassmsg="\
1479 ***\n\
1480 *** nightly successfully merged your changes. This means that your working\n\
1481 *** directory has been updated, but those changes are not yet committed.\n\
1482 *** After nightly completes, you should validate the results of the merge,\n\
1483 *** then use hg commit manually.\n\
1484 ***\n"
1485
1486 #
1487 # For each repository in turn:
1488 #
1489 # 1. Do the pull. If this fails, dump the output and bail out.
1490 #
1491 # 2. If the pull resulted in an extra head, do an explicit merge.
1492 # If this fails, dump the output and bail out.
1493 #
1494 # Because we can't rely on Mercurial to exit with a failure code
1495 # when a merge fails (Mercurial issue #186), we must grep the
1496 # output of pull/merge to check for attempted and/or failed merges.
1497 #
1498 # 3. If a merge failed, set the message and fail the bringover.
1499 #
1500 # 4. Otherwise, if a merge succeeded, set the message
1501 #
1502 # 5. Dump the output, and any message from step 3 or 4.
1503 #
1504
1505 typeset HG_SOURCE=$BRINGOVER_WS
1506 if [ ! -f $TMPDIR/new_repository ]; then
1507 HG_SOURCE=$TMPDIR/open_bundle.hg
1508 staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
1509 -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
1510
1511 #
1512 # If there are no incoming changesets, then incoming will
1513 # fail, and there will be no bundle file. Reset the source,
1514 # to allow the remaining logic to complete with no false
1515 # negatives. (Unlike incoming, pull will return success
1516 # for the no-change case.)
1517 #
1518 if (( $? != 0 )); then
1519 HG_SOURCE=$BRINGOVER_WS
1520 fi
1521 fi
1522
1523 staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
1524 > $TMPDIR/pull_open.out 2>&1
1525 if (( $? != 0 )); then
1526 printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
1527 cat $TMPDIR/pull_open.out
1528 if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
1529 printf "$mergefailmsg"
1530 fi
1531 touch $TMPDIR/bringover_failed
1532 return
1533 fi
1534
1535 if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
1536 staffer hg --cwd $CODEMGR_WS merge \
1537 >> $TMPDIR/pull_open.out 2>&1
1538 if (( $? != 0 )); then
1539 printf "%s: merge failed as follows:\n\n" \
1540 "$CODEMGR_WS"
1541 cat $TMPDIR/pull_open.out
1542 if grep "^merging.*failed" $TMPDIR/pull_open.out \
1543 > /dev/null 2>&1; then
1544 printf "$mergefailmsg"
1545 fi
1546 touch $TMPDIR/bringover_failed
1547 return
1548 fi
1549 fi
1550
1551 printf "updated %s with the following results:\n" "$CODEMGR_WS"
1552 cat $TMPDIR/pull_open.out
1553 if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
1554 printf "$mergepassmsg"
1555 fi
1556 printf "\n"
1557
1558 #
1559 # Per-changeset output is neither useful nor manageable for a
1560 # newly-created repository.
1561 #
1562 if [ -f $TMPDIR/new_repository ]; then
1563 return
1564 fi
1565
1566 printf "\nadded the following changesets to open repository:\n"
1567 cat $TMPDIR/incoming_open.out
1568 }
1569
1570 type bringover_none > /dev/null 2>&1 || function bringover_none {
1571 echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
1572 touch $TMPDIR/bringover_failed
1573 }
1574
1575 #
1576 # Decide whether to bringover to the codemgr workspace
1577 #
1578 if [ "$n_FLAG" = "n" ]; then
1579 PARENT_SCM_TYPE=$(parent_wstype)
1580
1581 if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
1582 echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
1583 "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
1584 exit 1
1585 fi
1586
1587 run_hook PRE_BRINGOVER
1588
1589 echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
1590 echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
1591
1592 eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
1593 tee -a $mail_msg_file >> $LOGFILE
1594
1595 if [ -f $TMPDIR/bringover_failed ]; then
1596 rm -f $TMPDIR/bringover_failed
1597 build_ok=n
1598 echo "trouble with bringover, quitting at `date`." |
1599 tee -a $mail_msg_file >> $LOGFILE
1600 exit 1
1601 fi
1602
1603 #
1604 # It's possible that we used the bringover above to create
1605 # $CODEMGR_WS. If so, then SCM_TYPE was previously "none,"
1606 # but should now be the same as $BRINGOVER_WS.
1607 #
1608 [[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
1609
1610 run_hook POST_BRINGOVER
1611
1612 check_closed_bins
1613
1614 else
1615 echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
1616 fi
1617
1618 # Safeguards
1619 [[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
1620 [[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory."
1621 [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
1622
1623 if [[ "$t_FLAG" = "y" ]]; then
1624 echo "\n==== Bootstrapping cw ====\n" >> $LOGFILE
1625 ( cd ${TOOLS}
1626 set_non_debug_build_flags
1627 rm -f $TMPDIR/make-state
1628 $MAKE -K $TMPDIR/make-state -e TARGET=install cw 2>&1 >> $LOGFILE
1629 [[ "$?" -ne 0 ]] && fatal_error "Error: could not bootstrap cw"
1630 )
1631
1632 # Switch ONBLD_TOOLS early if -t is specified so that
1633 # we could use bootstrapped cw for compiler checks.
1634 ONBLD_TOOLS=${TOOLS_PROTO}/opt/onbld
1635 export ONBLD_TOOLS
1636 fi
1637
1638 echo "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
1639
1640 # System
1641 whence uname | tee -a $build_environ_file >> $LOGFILE
1642 uname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
1643 echo | tee -a $build_environ_file >> $LOGFILE
1644
1645 # make
1646 whence $MAKE | tee -a $build_environ_file >> $LOGFILE
1647 $MAKE -v | tee -a $build_environ_file >> $LOGFILE
1648 echo "number of concurrent jobs = $DMAKE_MAX_JOBS" |
1649 tee -a $build_environ_file >> $LOGFILE
1650
1651 #
1652 # Report the compiler versions.
1653 #
1654
1655 if [[ ! -f $SRC/Makefile ]]; then
1656 build_ok=n
1657 echo "\nUnable to find \"Makefile\" in $SRC." | \
1658 tee -a $build_environ_file >> $LOGFILE
1659 exit 1
1660 fi
1661
1662 ( cd $SRC
1663 for target in cc-version cc64-version java-version; do
1664 echo
1665 #
1666 # Put statefile somewhere we know we can write to rather than trip
1667 # over a read-only $srcroot.
1668 #
1669 rm -f $TMPDIR/make-state
1670 export SRC
1671 if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
1672 continue
1673 fi
1674 touch $TMPDIR/nocompiler
1675 done
1676 echo
1677 ) | tee -a $build_environ_file >> $LOGFILE
1678
1679 if [ -f $TMPDIR/nocompiler ]; then
1680 rm -f $TMPDIR/nocompiler
1681 build_ok=n
1682 echo "Aborting due to missing compiler." |
1683 tee -a $build_environ_file >> $LOGFILE
1684 exit 1
1685 fi
1686
1687 # as
1688 whence as | tee -a $build_environ_file >> $LOGFILE
1689 as -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
1690 echo | tee -a $build_environ_file >> $LOGFILE
1691
1692 # Check that we're running a capable link-editor
1693 whence ld | tee -a $build_environ_file >> $LOGFILE
1694 LDVER=`ld -V 2>&1`
1695 echo $LDVER | tee -a $build_environ_file >> $LOGFILE
1696 LDVER=`echo $LDVER | sed -e "s/.*-1\.\([0-9]*\).*/\1/"`
1697 if [ `expr $LDVER \< 422` -eq 1 ]; then
1698 echo "The link-editor needs to be at version 422 or higher to build" | \
1699 tee -a $build_environ_file >> $LOGFILE
1700 echo "the latest stuff. Hope your build works." | \
1701 tee -a $build_environ_file >> $LOGFILE
1702 fi
1703
1704 #
1705 # Build and use the workspace's tools if requested
1706 #
1707 if [[ "$t_FLAG" = "y" ]]; then
1708 set_non_debug_build_flags
1709
1710 build_tools ${TOOLS_PROTO}
1711 if (( $? != 0 )); then
1712 build_ok=n
1713 else
1714 STABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs
1715 export STABS
1716 CTFSTABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs
1717 export CTFSTABS
1718 GENOFFSETS=${TOOLS_PROTO}/opt/onbld/bin/genoffsets
1719 export GENOFFSETS
1720
1721 CTFCONVERT=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert
1722 export CTFCONVERT
1723 CTFMERGE=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge
1724 export CTFMERGE
1725
1726 PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
1727 PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
1728 export PATH
1729
1730 echo "\n==== New environment settings. ====\n" >> $LOGFILE
1731 echo "STABS=${STABS}" >> $LOGFILE
1732 echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
1733 echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
1734 echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
1735 echo "PATH=${PATH}" >> $LOGFILE
1736 echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE
1737 fi
1738 fi
1739
1740 # timestamp the start of the normal build; the findunref tool uses it.
1741 touch $SRC/.build.tstamp
1742
1743 normal_build
1744
1745 ORIG_SRC=$SRC
1746 BINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
1747
1748
1749 #
1750 # There are several checks that need to look at the proto area, but
1751 # they only need to look at one, and they don't care whether it's
1752 # DEBUG or non-DEBUG.
1753 #
1754 if [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
1755 checkroot=$ROOT-nd
1756 else
1757 checkroot=$ROOT
1758 fi
1759
1760 if [ "$build_ok" = "y" ]; then
1761 echo "\n==== Creating protolist system file at `date` ====" \
1762 >> $LOGFILE
1763 protolist $checkroot > $ATLOG/proto_list_${MACH}
1764 echo "==== protolist system file created at `date` ====\n" \
1765 >> $LOGFILE
1766
1767 if [ "$N_FLAG" != "y" ]; then
1768
1769 E1=
1770 f1=
1771 for f in $f1; do
1772 if [ -f "$f" ]; then
1773 E1="$E1 -e $f"
1774 fi
1775 done
1776
1777 E2=
1778 f2=
1779 if [ -d "$SRC/pkg" ]; then
1780 f2="$f2 exceptions/packaging"
1781 fi
1782
1783 for f in $f2; do
1784 if [ -f "$f" ]; then
1785 E2="$E2 -e $f"
1786 fi
1787 done
1788 fi
1789
1790 if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
1791 echo "\n==== Validating manifests against proto area ====\n" \
1792 >> $mail_msg_file
1793 ( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) | \
1794 tee $TMPDIR/protocmp_noise >> $mail_msg_file
1795 if [[ -s $TMPDIR/protocmp_noise ]]; then
1796 build_extras_ok=n
1797 fi
1798 fi
1799
1800 if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then
1801 echo "\n==== Impact on proto area ====\n" >> $mail_msg_file
1802 if [ -n "$E2" ]; then
1803 ELIST=$E2
1804 else
1805 ELIST=$E1
1806 fi
1807 $PROTOCMPTERSE \
1808 "Files in yesterday's proto area, but not today's:" \
1809 "Files in today's proto area, but not yesterday's:" \
1810 "Files that changed between yesterday and today:" \
1811 ${ELIST} \
1812 -d $REF_PROTO_LIST \
1813 $ATLOG/proto_list_${MACH} \
1814 >> $mail_msg_file
1815 fi
1816 fi
1817
1818 if [[ "$u_FLAG" == "y" && "$build_ok" == "y" && \
1819 "$build_extras_ok" == "y" ]]; then
1820 staffer cp $ATLOG/proto_list_${MACH} \
1821 $PARENT_WS/usr/src/proto_list_${MACH}
1822 fi
1823
1824 # Update parent proto area if necessary. This is done now
1825 # so that the proto area has either DEBUG or non-DEBUG kernels.
1826 # Note that this clears out the lock file, so we can dispense with
1827 # the variable now.
1828 if [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
1829 echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
1830 tee -a $LOGFILE >> $mail_msg_file
1831 rm -rf $NIGHTLY_PARENT_ROOT/*
1832 unset Ulockfile
1833 mkdir -p $NIGHTLY_PARENT_ROOT
1834 if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
1835 ( cd $ROOT; tar cf - . |
1836 ( cd $NIGHTLY_PARENT_ROOT; umask 0; tar xpf - ) ) 2>&1 |
1837 tee -a $mail_msg_file >> $LOGFILE
1838 fi
1839 if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
1840 rm -rf $NIGHTLY_PARENT_ROOT-nd/*
1841 mkdir -p $NIGHTLY_PARENT_ROOT-nd
1842 cd $ROOT-nd
1843 ( tar cf - . |
1844 ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
1845 tee -a $mail_msg_file >> $LOGFILE
1846 fi
1847 if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then
1848 echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \
1849 tee -a $LOGFILE >> $mail_msg_file
1850 rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/*
1851 mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT
1852 if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
1853 ( cd $TOOLS_PROTO; tar cf - . |
1854 ( cd $NIGHTLY_PARENT_TOOLS_ROOT;
1855 umask 0; tar xpf - ) ) 2>&1 |
1856 tee -a $mail_msg_file >> $LOGFILE
1857 fi
1858 fi
1859 fi
1860
1861 #
1862 # ELF verification: ABI (-A) and runtime (-r) checks
1863 #
1864 if [[ ($build_ok = y) && (($A_FLAG = y) || ($r_FLAG = y)) ]]; then
1865 # Directory ELF-data.$MACH holds the files produced by these tests.
1866 elf_ddir=$SRC/ELF-data.$MACH
1867
1868 # If there is a previous ELF-data backup directory, remove it. Then,
1869 # rotate current ELF-data directory into its place and create a new
1870 # empty directory
1871 rm -rf $elf_ddir.ref
1872 if [[ -d $elf_ddir ]]; then
1873 mv $elf_ddir $elf_ddir.ref
1874 fi
1875 mkdir -p $elf_ddir
1876
1877 # Call find_elf to produce a list of the ELF objects in the proto area.
1878 # This list is passed to check_rtime and interface_check, preventing
1879 # them from separately calling find_elf to do the same work twice.
1880 find_elf -fr $checkroot > $elf_ddir/object_list
1881
1882 if [[ $A_FLAG = y ]]; then
1883 echo "\n==== Check versioning and ABI information ====\n" | \
1884 tee -a $LOGFILE >> $mail_msg_file
1885
1886 # Produce interface description for the proto. Report errors.
1887 interface_check -o -w $elf_ddir -f object_list \
1888 -i interface -E interface.err
1889 if [[ -s $elf_ddir/interface.err ]]; then
1890 tee -a $LOGFILE < $elf_ddir/interface.err \
1891 >> $mail_msg_file
1892 build_extras_ok=n
1893 fi
1894
1895 # If ELF_DATA_BASELINE_DIR is defined, compare the new interface
1896 # description file to that from the baseline gate. Issue a
1897 # warning if the baseline is not present, and keep going.
1898 if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
1899 base_ifile="$ELF_DATA_BASELINE_DIR/interface"
1900
1901 echo "\n==== Compare versioning and ABI information" \
1902 "to baseline ====\n" | \
1903 tee -a $LOGFILE >> $mail_msg_file
1904 echo "Baseline: $base_ifile\n" >> $LOGFILE
1905
1906 if [[ -f $base_ifile ]]; then
1907 interface_cmp -d -o $base_ifile \
1908 $elf_ddir/interface > $elf_ddir/interface.cmp
1909 if [[ -s $elf_ddir/interface.cmp ]]; then
1910 echo | tee -a $LOGFILE >> $mail_msg_file
1911 tee -a $LOGFILE < \
1912 $elf_ddir/interface.cmp \
1913 >> $mail_msg_file
1914 build_extras_ok=n
1915 fi
1916 else
1917 echo "baseline not available. comparison" \
1918 "skipped" | \
1919 tee -a $LOGFILE >> $mail_msg_file
1920 fi
1921
1922 fi
1923 fi
1924
1925 if [[ $r_FLAG = y ]]; then
1926 echo "\n==== Check ELF runtime attributes ====\n" | \
1927 tee -a $LOGFILE >> $mail_msg_file
1928
1929 # If we're doing a DEBUG build the proto area will be left
1930 # with debuggable objects, thus don't assert -s.
1931 if [[ $D_FLAG = y ]]; then
1932 rtime_sflag=""
1933 else
1934 rtime_sflag="-s"
1935 fi
1936 check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
1937 -D object_list -f object_list -E runtime.err \
1938 -I runtime.attr.raw
1939 if (( $? != 0 )); then
1940 build_extras_ok=n
1941 fi
1942
1943 # check_rtime -I output needs to be sorted in order to
1944 # compare it to that from previous builds.
1945 sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
1946 rm $elf_ddir/runtime.attr.raw
1947
1948 # Report errors
1949 if [[ -s $elf_ddir/runtime.err ]]; then
1950 tee -a $LOGFILE < $elf_ddir/runtime.err \
1951 >> $mail_msg_file
1952 build_extras_ok=n
1953 fi
1954
1955 # If there is an ELF-data directory from a previous build,
1956 # then diff the attr files. These files contain information
1957 # about dependencies, versioning, and runpaths. There is some
1958 # overlap with the ABI checking done above, but this also
1959 # flushes out non-ABI interface differences along with the
1960 # other information.
1961 echo "\n==== Diff ELF runtime attributes" \
1962 "(since last build) ====\n" | \
1963 tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
1964
1965 if [[ -f $elf_ddir.ref/runtime.attr ]]; then
1966 diff $elf_ddir.ref/runtime.attr \
1967 $elf_ddir/runtime.attr \
1968 >> $mail_msg_file
1969 fi
1970 fi
1971
1972 # If -u set, copy contents of ELF-data.$MACH to the parent workspace.
1973 if [[ "$u_FLAG" = "y" ]]; then
1974 p_elf_ddir=$PARENT_WS/usr/src/ELF-data.$MACH
1975
1976 # If parent lacks the ELF-data.$MACH directory, create it
1977 if [[ ! -d $p_elf_ddir ]]; then
1978 staffer mkdir -p $p_elf_ddir
1979 fi
1980
1981 # These files are used asynchronously by other builds for ABI
1982 # verification, as above for the -A option. As such, we require
1983 # the file replacement to be atomic. Copy the data to a temp
1984 # file in the same filesystem and then rename into place.
1985 (
1986 cd $elf_ddir
1987 for elf_dfile in *; do
1988 staffer cp $elf_dfile \
1989 ${p_elf_ddir}/${elf_dfile}.new
1990 staffer mv -f ${p_elf_ddir}/${elf_dfile}.new \
1991 ${p_elf_ddir}/${elf_dfile}
1992 done
1993 )
1994 fi
1995 fi
1996
1997 # DEBUG lint of kernel begins
1998
1999 if [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
2000 if [ "$LINTDIRS" = "" ]; then
2001 # LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
2002 LINTDIRS="$SRC y"
2003 fi
2004 set $LINTDIRS
2005 while [ $# -gt 0 ]; do
2006 dolint $1 $2; shift; shift
2007 done
2008 else
2009 echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
2010 fi
2011
2012 # "make check" begins
2013
2014 if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
2015 # remove old check.out
2016 rm -f $SRC/check.out
2017
2018 rm -f $SRC/check-${MACH}.out
2019 cd $SRC
2020 $MAKE -ek check ROOT="$checkroot" 2>&1 | tee -a $SRC/check-${MACH}.out \
2021 >> $LOGFILE
2022 echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
2023
2024 grep ":" $SRC/check-${MACH}.out |
2025 egrep -v "Ignoring unknown host" | \
2026 sort | uniq | tee $TMPDIR/check_errors >> $mail_msg_file
2027
2028 if [[ -s $TMPDIR/check_errors ]]; then
2029 build_extras_ok=n
2030 fi
2031 else
2032 echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
2033 fi
2034
2035 echo "\n==== Find core files ====\n" | \
2036 tee -a $LOGFILE >> $mail_msg_file
2037
2038 find $abssrcdirs -name core -a -type f -exec file {} \; | \
2039 tee -a $LOGFILE >> $mail_msg_file
2040
2041 if [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2042 echo "\n==== Diff unreferenced files (since last build) ====\n" \
2043 | tee -a $LOGFILE >>$mail_msg_file
2044 rm -f $SRC/unref-${MACH}.ref
2045 if [ -f $SRC/unref-${MACH}.out ]; then
2046 mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2047 fi
2048
2049 findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
2050 ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
2051 sort > $SRC/unref-${MACH}.out
2052
2053 if [ ! -f $SRC/unref-${MACH}.ref ]; then
2054 cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2055 fi
2056
2057 diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
2058 fi
2059
2060 # Verify that the usual lists of files, such as exception lists,
2061 # contain only valid references to files. If the build has failed,
2062 # then don't check the proto area.
2063 CHECK_PATHS=${CHECK_PATHS:-y}
2064 if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
2065 echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
2066 >>$mail_msg_file
2067 arg=-b
2068 [ "$build_ok" = y ] && arg=
2069 checkpaths $arg $checkroot > $SRC/check-paths.out 2>&1
2070 if [[ -s $SRC/check-paths.out ]]; then
2071 tee -a $LOGFILE < $SRC/check-paths.out >> $mail_msg_file
2072 build_extras_ok=n
2073 fi
2074 fi
2075
2076 if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
2077 echo "\n==== Impact on file permissions ====\n" \
2078 >> $mail_msg_file
2079
2080 abspkg=
2081 for d in $abssrcdirs; do
2082 if [ -d "$d/pkg" ]; then
2083 abspkg="$abspkg $d"
2084 fi
2085 done
2086
2087 if [ -n "$abspkg" ]; then
2088 for d in "$abspkg"; do
2089 ( cd $d/pkg ; $MAKE -e pmodes ) >> $mail_msg_file
2090 done
2091 fi
2092 fi
2093
2094 if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
2095 if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2096 do_wsdiff DEBUG $ROOT.prev $ROOT
2097 fi
2098
2099 if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
2100 do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
2101 fi
2102 fi
2103
2104 END_DATE=`date`
2105 echo "==== Nightly $maketype build completed: $END_DATE ====" | \
2106 tee -a $LOGFILE >> $build_time_file
2107
2108 typeset -i10 hours
2109 typeset -Z2 minutes
2110 typeset -Z2 seconds
2111
2112 elapsed_time=$SECONDS
2113 ((hours = elapsed_time / 3600 ))
2114 ((minutes = elapsed_time / 60 % 60))
2115 ((seconds = elapsed_time % 60))
2116
2117 echo "\n==== Total build time ====" | \
2118 tee -a $LOGFILE >> $build_time_file
2119 echo "\nreal ${hours}:${minutes}:${seconds}" | \
2120 tee -a $LOGFILE >> $build_time_file
2121
2122 if [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2123 staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
2124
2125 #
2126 # Produce a master list of unreferenced files -- ideally, we'd
2127 # generate the master just once after all of the nightlies
2128 # have finished, but there's no simple way to know when that
2129 # will be. Instead, we assume that we're the last nightly to
2130 # finish and merge all of the unref-${MACH}.out files in
2131 # $PARENT_WS/usr/src/. If we are in fact the final ${MACH} to
2132 # finish, then this file will be the authoritative master
2133 # list. Otherwise, another ${MACH}'s nightly will eventually
2134 # overwrite ours with its own master, but in the meantime our
2135 # temporary "master" will be no worse than any older master
2136 # which was already on the parent.
2137 #
2138
2139 set -- $PARENT_WS/usr/src/unref-*.out
2140 cp "$1" ${TMPDIR}/unref.merge
2141 shift
2142
2143 for unreffile; do
2144 comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
2145 mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
2146 done
2147
2148 staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
2149 fi
2150
2151 #
2152 # All done save for the sweeping up.
2153 # (whichever exit we hit here will trigger the "cleanup" trap which
2154 # optionally sends mail on completion).
2155 #
2156 if [[ "$build_ok" == "y" ]]; then
2157 if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
2158 exit 0
2159 fi
2160 fi
2161
2162 exit 1