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