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