Debian Codegraph @

scripts/build-release

raw symbols SCIP
1 #!/bin/bash
2
3 ## Copyright (C) 2018 Robert Krawitz
4 ##
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 2, or (at your option)
8 ## any later version.
9 ##
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program. If not, see <https://www.gnu.org/licenses/>.
17 ##
18 ## Build release tarball
19
20 # Note that the shebang line is explicit here, not indirected through
21 # autoconf. This allows the script to be run in a non-initialized workspace.
22 # We also require this script to be run in the root of a workspace so that
23 # it can find the script directory to get the version without having to be
24 # autotool-processed.
25
26 function xtput() {
27 if [[ -z ${STP_TEST_RECURSIVE:-} && -n ${TERM:-} && ${TERM:-} != dumb ]] ; then
28 tput "$@"
29 fi
30 }
31
32 set -u
33
34 # shellcheck disable=SC2155
35 {
36 declare -r tbold="$(xtput bold)"
37 declare -r tred="$(xtput setaf 1)$tbold"
38 declare -r tyellow="$(xtput setaf 3)$tbold"
39 declare -r tgreen="$(xtput setaf 2)$tbold"
40 declare -r tpurple="$(xtput setaf 5)$tbold"
41 declare -r tblue=$(xtput setaf 4)
42 declare -r tcyan=$(xtput setaf 6)
43 declare -r treset=$(xtput sgr0)
44 }
45 declare -i exitstatus=1
46 declare -i stepstatus=-1
47 declare currentmodule=
48 declare -a failedmodules=()
49 declare top_log
50 function fatal() {
51 echo "${tred}FATAL: $*${treset}"
52 exit 1
53 }
54
55 # shellcheck disable=SC2155
56 declare GIT=$(type -p git)
57 [[ -n $GIT ]] || fatal "Can't find git"
58
59 "$GIT" rev-parse --show-toplevel >/dev/null 2>&1 || fatal "Current directory is not a git workspace"
60 declare rootdir
61 rootdir="$("$GIT" rev-parse --show-toplevel 2>/dev/null)"
62 [[ -n $rootdir ]] || fatal "Can't find workspace root"
63 cd "$rootdir" || fatal "Can't cd to workspace root ($rootdir)"
64 [[ -s ChangeLog.pre-5.2.11 ]] || fatal "$rootdir does not appear to be a Gutenprint tree"
65
66 # shellcheck disable=SC2155
67 declare MAKE=$(type -p make)
68 [[ -n $MAKE ]] || fatal "Can't find make"
69
70 # shellcheck disable=SC2155
71 declare -r ROOT=$(pwd)
72 declare tmpfile=/dev/null
73 export STP_PARALLEL=${STP_PARALLEL:-$("$ROOT/scripts/count-cpus")}
74 declare counter=1
75 declare git_dirty=
76 declare build_type=release
77 [[ -n ${STP_BUILD_SNAPSHOT:-} ]] && build_type=snapshot
78
79 # This can't simply be a constant because scripts/gversion might
80 # not exist (or may be incorrect) prior to autogen being run.
81 function pkg_version() {
82 "$ROOT/scripts/gversion" pkg
83 }
84
85 function version() {
86 "$ROOT/scripts/gversion" full-version
87 }
88
89 function pkg_tag() {
90 # shellcheck disable=SC2155
91 local version=$(pkg_version)
92 echo "${version//./_}"
93 }
94
95 # Clean up any trailing whitespace.
96
97 function preflight() {
98 # shellcheck disable=SC2155
99 local trailing_ws="$("$GIT" grep -Il '[ ]$' ':(exclude)po/*.po')"
100 if [[ -n $trailing_ws ]] ; then
101 console_log "*** ERROR: The following files have trailing whitespace:"
102 console_log "$trailing_ws"
103 return 2
104 fi
105 return 0
106 }
107
108 # Git pre-checks (not version-specific)
109
110 function check_git() {
111 "$GIT" fetch
112 local gstatus=0
113
114 # Check for uncommitted files.
115 if [[ -n $("$GIT" status -uno --porcelain) ]] ; then
116 console_log "*** ERROR: Uncommitted changes in repository:"
117 "$GIT" status -uno --porcelain | console_log
118 gstatus=2
119 fi
120
121 # Ensure that the workspace is up to date (git status -uno
122 # --porcelain -b |grep -v ahead is empty -- it's OK to be ahead,
123 # but not behind) and that we don't need to rebase (no merges.
124 # Also check that we haven't diverged.
125
126 # shellcheck disable=SC2155
127 local ahead=$("$GIT" rev-list '@{u}..@')
128 # shellcheck disable=SC2155
129 local behind=$("$GIT" rev-list '@..@{u}')
130 if [[ -n $ahead && -n $behind ]] ; then
131 # Oops! Both ahead *and* behind remote. Really bad news!
132 console_log "*** ERROR: HEAD and remote have diverged!"
133 console_log "*** Please merge and rebase all changes!"
134 return 2
135 elif [[ -n $behind ]] ; then
136 # We're behind. Not good.
137 console_log "*** ERROR: Behind remote by $(wc -w <<< "$behind") commits."
138 return 2
139 elif [[ -n $ahead ]] ; then
140 # We're ahead. That's OK as long as there are no merge commits.
141 local merges=0
142 for h in $ahead ; do
143 (( $("$GIT" rev-parse "$h^@" |wc -w) > 1 )) && merges=$((merges + 1))
144 done
145 console_log "*** Warning: Ahead of remote."
146 if (( merges > 0 )) ; then
147 (( merges != 1 )) && pl=s
148 console_log "*** ERROR: $merges merge${pl:-} between HEAD and remote"
149 return 2
150 fi
151 fi
152 return $gstatus
153 }
154
155 # Run autogen.sh to ensure that we're using default build settings
156 # Everything else depends on this.
157
158 function run_target() {
159 make "$1" && return 0
160 local lstatus=$?
161 console_log "*** ERROR: ${3:+$3 }make $1 failed"
162 (( lstatus >= 127 )) && return $lstatus
163 return "${2:-2}"
164 }
165
166 function run_maintainer_clean() {
167 if [[ -f Makefile ]] ; then
168 run_target maintainer-clean
169 else
170 return 0
171 fi
172 }
173
174 function run_autogen() {
175 # shellcheck disable=SC2086
176 ./autogen.sh ${STP_CONFIG_ARGS:-} && return 0
177 console_log "*** FATAL: autogen failed!"
178 return 1
179 }
180
181 function colorize() {
182 sed \
183 -e "s/\*\*\* \(FATAL\|ERROR\):\(.*\)/${tred}*** \1:\2${treset}/" \
184 -e "s/\*\*\* Warning:\(.*\)/${tyellow}*** Warning:\1${treset}/"
185 }
186
187 function run_clean() {
188 run_target clean
189 }
190
191 function run_build() {
192 run_target "${STP_PARALLEL:+-j$STP_PARALLEL}" 1
193 }
194
195 # Same as above, without make clean if we know we're in a clean
196 # environment (e. g. CI)
197 function run_build_fresh() {
198 # shellcheck disable=SC2086
199 ./autogen.sh ${STP_CONFIG_ARGS:-} && make "${STP_PARALLEL:+-j$STP_PARALLEL}" && return 0
200 console_log "*** FATAL preliminary build failed!"
201 return 1
202 }
203
204 # Git check tag. This can't be run until after the build, because we
205 # don't have the version available until autogen.
206
207 function check_git_tag() {
208 # Make sure that the tag that we're going to want to apply isn't
209 # already present.
210 [[ $build_type != release ]] && return 0
211 if [[ -n $("$GIT" show-ref "refs/tags/$(pkg_tag)") ]] ; then
212 console_log "*** ERROR: Tag named $(pkg_tag) is already present"
213 return 2
214 fi
215 }
216
217 function _cleanup_test_repo() {
218 if [[ -d $TESTREPO ]] ; then
219 rm -rf -- "$TESTREPO"
220 fi
221 }
222
223 # Check that we can build a clone of this workspace
224 function _check_git_builds() {
225 # shellcheck disable=SC2155
226 export TESTREPO=$(mktemp -d "/tmp/stpbuild.XXXXXXXX")
227 trap _cleanup_test_repo EXIT SIGHUP SIGINT SIGQUIT SIGTERM
228 # shellcheck disable=SC2155
229 local rev=$("$GIT" rev-parse @)
230 cwd=$(pwd -P)
231 [[ -n $cwd ]] || {
232 console_log "*** ERROR: Can't find directory!"
233 return 2
234 }
235 cd "$TESTREPO" || {
236 console_log "*** ERROR: Can't cd to test repo directory $cwd!"
237 (( $? >= 127 )) && return 127
238 return 2
239 }
240 "$GIT" clone "$cwd" . || {
241 console_log "*** ERROR: Unable to clone repo"
242 (( $? >= 127 )) && return 127
243 return 2
244 }
245 "$GIT" checkout "$rev" || {
246 console_log "*** ERROR: Unable to check out rev $rev"
247 (( $? >= 127 )) && return 127
248 return 2
249 }
250 STP_TEST_RECURSIVE=$((${STP_TEST_RECURSIVE?-0}+1)) STP_LOG_NO_SUBDIR=1 STP_LOG_DIR=$STP_TEST_LOG_PREFIX scripts/build-release preflight run_autogen run_build run_distcheck_minimal || {
251 console_log "*** ERROR: Repo build failed!"
252 (( $? >= 127 )) && return 127
253 return 2
254 }
255 }
256
257 function check_git_builds() {
258 (_check_git_builds)
259 }
260
261 # Run make valgrind-minimal.
262 #
263 # This does a *very* limited set of valgrind checks, running
264 # testpattern and rastertogutenprint on 9 (currently) selected
265 # printers. It takes about 30 seconds on my laptop. Smoketest and
266 # all.
267
268 function run_valgrind_minimal() {
269 run_target check-valgrind-minimal
270 }
271
272 function run_valgrind_fast() {
273 run_target check-valgrind-fast
274 }
275
276 function run_check_minimal() {
277 run_target check-minimal
278 }
279
280 function run_check_fast() {
281 run_target check-fast
282 }
283
284 # Run make distcheck-fast.
285 #
286 # This actually builds the tarball, unpacks the tarball, builds it
287 # out of tree, runs a short set of tests against it, does a local
288 # make install, followed by make uninstall, and makes sure no
289 # debris is left around. This runs configure with all default
290 # arguments, so it is testing dynamically linked executables.
291 #
292 # The particular tests it runs are:
293 #
294 # - Conformance tests all non-translated non-simplified PPD files
295 # and distinct global ones.
296 #
297 # - Runs test-rastertogutenprint on distinct printers, with fast
298 # options (minimum paper size, lowest resolution, very fast
299 # dithering).
300 #
301 # - Runs run-testpattern-2:
302 #
303 # + Distinct printers, fast options
304 #
305 # + Selected printers, with cross product of input mode (and bit
306 # depth), color correction, ink type, and use gloss.
307 #
308 # It also has the property of maybe updating the .po files. These
309 # will later need to be committed and included in the tag. So we
310 # have to do our check for uncommitted bits prior to this.
311 #
312 # It has not escaped me that this could be part of a CI testing
313 # process. I don't know if Sourceforge has the necessary gittage
314 # (as GitHub does) to allow a merge bot to run something like this
315 # and only merge to the main repository if this suite passes.
316 #
317 # The reason for the distcheck-fast is so that if something stupid
318 # goes wrong it gets caught quickly. It takes about 270 seconmds
319 # on my laptop. It would be Kind Of Annoying to spend hours
320 # testing only to find out that something's not handling destdir
321 # correctly or make clean isn't removing something.
322 #
323 # Note that this can't be combined with valgrind, since this builds
324 # dynamic executables which can't conveniently be valground since
325 # they're actually shell scripts.
326 #
327 # There's now an even faster check, distcheck-minimal, that only
328 # tests a handful of printers. It takes about 50 seconds to run.
329 # But that's really most useful for testing the distcheck
330 # apparatus.
331 #
332 # So far we're at just over 5 minutes on a Skylake Xeon E3-1505Mv5,
333 # which isn't too bad for a prerelease smoke test. The rest of this
334 # takes a lot longer.
335
336 function run_distcheck_fast() {
337 run_target distcheck-fast
338 }
339
340 # Run make check-valgrind
341 #
342 # This is slow. It tests only unique printers, and a lot of extra
343 # combinations with a few printers, all using fast options. It
344 # uses both CUPS and run-testpattern-2 testing. However, it's
345 # essentially embarrassingly parallel.
346 #
347 # I'd like not to go too long without running it, as it's easy for
348 # things to make their way in. For CI purposes, if we ever go
349 # there, like to find a happy medium.
350
351 function run_valgrind() {
352 run_target check-valgrind
353 }
354
355 # Run make check-full
356 #
357 # This one I'm not sure of; do we need this or is this well enough
358 # covered by the combination of distcheck-fast and check-valgrind?
359 # It does take a while, but I haven't benchmarked it lately.
360 #
361 # - Conformance test all PPD files
362 #
363 # - Run test-rastertogutenprint on all printers, with default options
364 #
365 # - Runs run-testpattern-2:
366 #
367 # + Distinct printers, default options
368 #
369 # + All printers, fast options
370 #
371 # + Distinct printers, fast options, with cross product of input
372 # mode (and bit depth), color correction, ink type, and use
373 # gloss.
374 #
375 # IIRC this takes 60-90 minutes on my laptop, but again, it
376 # parallelizes very well.
377
378 function run_full() {
379 run_target check-full
380 }
381
382 # Run make checksums-release to generate a new regression file.
383 #
384 # The problem here is what do we require for the release build. Do
385 # we require a clean regression run (other than added
386 # printers/modes)? There are legitimate reasons for changing, and
387 # having to rerun the procedure because the release engineer forgot a
388 # command line option is a bit harsh. Something better might be to
389 # simply record changes unless there's an outright failure here, and
390 # let those be reviewed.
391 #
392 # For CI purposes, the default might be to require no changes, with
393 # human intervention if there are.
394 #
395 # This takes about 30 minutes on my laptop. This is extremely
396 # scalable. Give us a really big machine instance to run it on, this
397 # will run really fast.
398
399 function run_checksums() {
400 make checksums
401 local lstatus=$?
402 if (( lstatus == 0 )) ; then
403 # shellcheck disable=SC2155
404 local csum_file="src/testpattern/Checksums/sums.$(pkg_version).zpaq"
405 if [[ ! -f $csum_file ]] ; then
406 console_log "*** ERROR: Can't find new checksums file $csum_file"
407 (( lstatus > 127 )) && return $lstatus
408 return 2
409 fi
410 cp -p "$csum_file" "$ARTIFACTDIR"
411 return 0
412 fi
413 console_log "*** ERROR: make checksums failed"
414 (( lstatus > 127 )) && return $lstatus
415 return 2
416 }
417
418 # Fetch the translations
419
420 function fetch_translations() {
421 rsync -Lrtzv rsync://translationproject.org/tp/latest/gutenprint/ po/
422 }
423
424 # Prep the release
425
426 function git_prep_release() {
427 # .po files might have changed; nothing else should have!
428 # Add any of those changed files.
429 if [[ $build_type == release ]] ; then
430 "$GIT" add -u || return 1
431 # Add the checksums file.
432 # TBD whether to do this for snapshots. The file's not very big,
433 # but it's completely incompressible!
434 "$GIT" add -f "src/testpattern/Checksums/sums.$(pkg_version).zpaq" || return 1
435 # Commit this change
436 "$GIT" commit -m"Gutenprint $(pkg_version) release" || return 1
437 else
438 # Don't update the .po files for every snapshot.
439 echo "Cleaning up .po files"
440 "$GIT" checkout -- po
441 fi
442 # Shouldn't have anything left after this.
443 if "$GIT" status -uno --porcelain |grep -q -E -v 'po/.*\.po' ; then
444 console_log "*** ERROR: Unexpected untracked files:"
445 "$GIT" status -uno --porcelain |grep -E -v 'po/.*\.po' | console_log
446 return 1
447 fi
448 # Apply the tag. Ideally we should sign the tag too.
449 # But don't tag snapshot builds.
450 [[ $build_type != release ]] && return 0
451 "$GIT" tag -a "$(pkg_tag)" -m "Gutenprint $(pkg_version) release" || return 1
452 }
453
454 function git_final_cleanup() {
455 if [[ $build_type != release ]] ; then
456 # Don't update the .po files for every snapshot.
457 echo "Cleaning up .po files"
458 "$GIT" checkout -- po
459 fi
460 # Shouldn't have anything left after this.
461 echo "Cleaning up .po files"
462 git checkout -- po
463 if "$GIT" status -uno --porcelain |grep -q -E -v 'po/.*\.po' ; then
464 console_log "*** ERROR: Unexpected untracked files:"
465 "$GIT" status -uno --porcelain |grep -E -v 'po/.*\.po' | console_log
466 return 1
467 fi
468 return 0
469 }
470
471 # make distcheck-minimal
472 #
473 # We have to rebuild the tarball in any event here, so that we pick up
474 # the tag (to get a correct change log) and updated .po files.
475 # A minimal distcheck only takes about a minute; we might as well
476 # do a final sanity check.
477
478 function run_distcheck_minimal() {
479 run_target distcheck-minimal 1 Final
480 }
481
482 function run_check_minimal() {
483 run_target check-minimal
484 }
485
486 # Save away build
487 function save_build_artifacts() {
488 # shellcheck disable=SC2155
489 local tarball="$(pkg_version).tar.xz"
490 if [[ -s $tarball ]] ; then
491 cp -p "$tarball" "$ARTIFACTDIR"
492 else
493 echo "Cannot find $tarball"
494 return 1
495 fi
496 }
497
498 # Final release prep
499
500 function finis() {
501 local extra_verbiage=
502 [[ $build_type == release ]] && {
503 local printer_list_data
504 printer_list_data=$(STP_DATA_PATH=src/xml test/gen-printer-list) || return 1
505 cat > "printer-list.$(version)" <<EOF
506 <?
507 require('functions.php');
508 ###############################################
509 ## Set title of this page here ##########
510 \$title = 'Gutenprint Supported Printers';
511 ###############################################
512 ###############################################
513 require('standard_html_header.php');
514
515
516 ### Content Below ###
517 # Please remember to use <P> </P> tags ! ?>
518
519 <p>Please note that many of these drivers are currently under
520 development, and we do not necessarily have full specifications on all
521 of them. We will fill in this list as we verify successful operation
522 of these printers. You can help by testing this with your own printer
523 and reporting the results!</p>
524
525 <table summary="Supported printers for Gutenprint $version">
526 <caption style="font-size:135%;margin-bottom:0.50em;"><b>Gutenprint $version</b></caption>
527 $printer_list_data
528 </table>
529
530
531 <?require('standard_html_footer.php');?>
532 EOF
533 extra_verbiage=$(cat <<EOF
534
535 * Update the web site
536
537 * Copy the updated printer list in ${tcyan}printer-list.$(version)${tpurple}
538 to p_Supported_Printers.php and upload that to the web site.
539 EOF
540 )
541 }
542 console_log <<EOF
543 ${tpurple}
544 ================================================================
545 Remainder to be done manually:
546
547 * git push
548
549 * git push --tags
550
551 * Upload the tarball (${tcyan}$(pkg_version).tar.xz${tpurple})
552 $extra_verbiage
553 ================================================================
554 $treset
555 EOF
556 return 0
557 }
558
559 ################################################################
560 #
561 # Runtime
562 #
563 ################################################################
564
565 # Note that if we change the format of this timestamp we have to
566 # change console_log if the width changes.
567 #
568 # Unfortunately the shell built-in printf can't specify UTC.
569 function stamp() {
570 printf '%(%Y-%m-%dT%H:%M:%S%z)T' -1
571 }
572
573 function date_sec() {
574 printf '%(%s)T' -1
575 }
576
577 function report_progress() {
578 local outst="RUNNING[$1]: "
579 shift
580 # shellcheck disable=SC2046
581 echo $([[ -z ${BUILD_VERBOSE:-} ]] && echo '' -n) ">>> $(stamp) $outst $*"
582 }
583
584 # This allows us to log to multiple outputs, including stdout and
585 # (where available) file descriptors. Ideally we'd be able to build a
586 # pipeline and eval it, but it's not clear that that's possible.
587 function log1() {
588 if [[ $# -eq 0 || ($# == 1 && $1 == -) ]] ; then
589 exec cat
590 else
591 local dest="$1"
592 shift
593 # stdout needs to come last, because we just want to send data
594 # to stdout rather than teeing off or explicitly going to a file.
595 if [[ $dest == - && $# -gt 0 ]] ; then
596 # Protect against someone inadvertently specifying '-' twice!
597 # shellcheck disable=SC2046
598 log1 "$@" $([[ $1 == - ]] || echo -)
599 elif [[ $dest == -* ]] ; then
600 dest=${dest:1}
601 destdir=${dest%/*}
602 [[ -n $destdir && ! -d $destdir ]] && mkdir -p "$destdir"
603 if (( $# == 0 )) ; then
604 exec cat > "$dest"
605 elif [[ $* == - ]] ; then
606 exec tee "$dest"
607 else
608 exec tee "$dest" | log1 "$@"
609 fi
610 else
611 destdir=${dest%/*}
612 [[ -n $destdir && ! -d $destdir ]] && mkdir -p "$destdir"
613 if (( $# == 0 )) ; then
614 exec cat >> "$dest"
615 elif [[ $* == - ]] ; then
616 exec tee -a "$dest"
617 else
618 exec tee -a "$dest" | log1 "$@"
619 fi
620 fi
621 fi
622 }
623
624 function log() {
625 (log1 "$@" ${BUILD_VERBOSE:+-})
626 }
627
628 function log_top1() {
629 log "$top_log" -
630 }
631
632 function red() {
633 sed -e "s/^/${tred}/" -e "s/$/${treset}/"
634 }
635
636 function green() {
637 sed -e "s/^/${tgreen}/" -e "s/$/${treset}/"
638 }
639
640 function log_top() {
641 if [[ -n "$*" ]] ; then
642 log_top1 <<< "$*"
643 else
644 log_top1
645 fi
646 }
647
648 # Log the output to the console as well as the master log file and the
649 # per-operation log file.
650 #
651 # fd#4 (/dev/fd/4 -- let's hope we're building the package on
652 # a system that supports /dev/fd, but linux does)
653 # in the operation gets tied to stderr
654 #
655 # Note that fd#3 is used by lower levels
656 #
657 # Then we timestamp the data and send it to the top-level log (which
658 # is not normally timestamped).
659 #
660 # Finally, we remove the existing timestamp (which relies upon the timestamp
661 # format, ugh) and send it to stdout where it gets picked up and timestamped
662 # again.
663 function console_log1() {
664 if [[ -n ${STP_TEST_RECURSIVE:-} ]] ; then
665 tee >(exec cat 1>&4) >(timestamp | log_top | cut -c26-)
666 else
667 timestamp | log_top - | cut -c26-
668 fi
669 }
670
671 function console_log_immediate1() {
672 case "${STP_TEST_RECURSIVE:-0}" in
673 2)
674 tee >(exec cat 1>&6) >(exec cat 1>&5) >(exec cat 1>&4) >(timestamp | log_top | cut -c26-)
675 ;;
676 1)
677 tee >(exec cat 1>&5) >(exec cat 1>&4) >(timestamp | log_top | cut -c26-)
678 ;;
679 *)
680 tee >(exec cat 1>&2) >(timestamp | log_top | cut -c26-)
681 ;;
682 esac
683 }
684
685 function console_log() {
686 if [[ -n "$*" ]] ; then
687 console_log1 <<< "$*"
688 else
689 console_log1
690 fi
691 }
692
693 function console_log_immediate() {
694 if [[ -n "$*" ]] ; then
695 console_log_immediate1 <<< "$*"
696 else
697 console_log_immediate1
698 fi
699 }
700
701 function time_delta() {
702 local -i i=$((${2:-0} - ${1:-0}))
703 printf "%d:%02d:%02d" $((i / 3600)) $(((i % 3600) / 60)) $((i % 60))
704 }
705
706 function report_step_status() {
707 (( stepstatus == -1 )) && return
708 [[ -z ${BUILD_VERBOSE:-} ]] && {
709 local ststatus=OK
710 local stcolor="${tgreen}"
711 if (( stepstatus)) ; then
712 ststatus=FAILED
713 stcolor="${tred}"
714 if (( stepstatus == 126 )) ; then
715 ststatus="NOT FOUND"
716 stcolor="${tpurple}"
717 elif (( stepstatus >= 127 )) ; then
718 ststatus=INTERRUPTED
719 fi
720 fi
721 printf "$stcolor%$((longest_op - ${#op} ))s $ststatus$treset\n"
722 }
723 [[ -n $currentmodule && $stepstatus -ne 0 ]] && failedmodules+=("$currentmodule")
724 currentmodule=
725 if [[ -f $tmpfile ]] ; then
726 [[ -s $tmpfile ]] && colorize < "$tmpfile"
727 rm -f -- "$tmpfile"
728 fi
729 stepstatus=-1
730 }
731
732 # shellcheck disable=SC2155
733 function finish() {
734 local status=$exitstatus
735 local etime=$(date_sec)
736 local estamp=$(stamp)
737 report_step_status
738 if [[ $status != 0 || -n ${failedmodules[*]:-} ]] ; then
739 log_top "The following modules failed:"
740 log_top "$(printf " %s\n" "${failedmodules[@]:-}")"
741 log_top "*** Gutenprint $build_type build FAILED at $estamp ($(time_delta "$stime" "$etime"))" |red
742 else
743 log_top "*** Gutenprint $build_type build completed at $estamp ($(time_delta "$stime" "$etime"))" |green
744 fi
745 log "$top_log" <<< "================================================================"
746 if [[ -n ${TRAVIS_MODE:-} ]] ; then
747 # We really don't want the termination message from the deadman
748 exec 3>&2 2>/dev/null
749 kill %travis_deadman
750 wait %travis_deadman
751 exec 2>&3 3>&-
752 fi
753 trap - EXIT
754 exit "$status"
755 }
756
757 # Travis times out if there's no output for 10 minutes, but some things
758 # go silent for quite a while
759 function travis_deadman() {
760 while : ; do sleep 60; echo -e "\n${tblue}Mark $(uptime)${treset}" | log -; done
761 }
762
763 function timestamp() {
764 while read -r ; do echo "$(stamp) $REPLY"; done
765 }
766
767 # Run one operation.
768 # shellcheck disable=SC2155
769 function runit() {
770 local cmdname=$1
771 local cmd="$*"
772 local fcounter=$(printf "%02d" "$counter")
773 local local_logdir="$logdir/$fcounter.${cmd// /_/}"
774 mkdir -p "$local_logdir"
775 local logfile="$local_logdir/Master"
776 [[ -n ${DONTRUN_OP:-} ]] && logfile=/dev/null
777 local sstime=$(date_sec)
778 local ssstamp=$(stamp)
779 local status=0
780 local msg=completed
781 log "-$logfile" "$top_log" <<< "----------------------------------------------------------------"
782 if [[ -z ${DONTRUN_OP:-} ]] ; then
783 echo "$cmdname started at $ssstamp" | log "$logfile" "$top_log"
784 echo "Command: $cmd" | log "$logfile" "$top_log"
785 echo "Log file: ${logfile#${logdir}/}" | log "$top_log"
786 else
787 echo "$cmdname SKIPPED" | log "$top_log"
788 fi
789 report_progress "$fcounter" "$cmdname"
790
791 if [[ -z ${DONTRUN_OP:-} ]] ; then
792 #
793 stepstatus=127
794 currentmodule="$cmdname"
795 # Run the command, capturing console output as well as logged output.
796 if [[ -z $(type -t "$cmdname") ]] ; then
797 msg="NOT FOUND"
798 # 126 is also used for "permission denied", which amounts
799 # to the same thing -- it's something the user should not
800 # have tried to run.
801 stepstatus=126
802 else
803 if [[ -n ${STP_TEST_RECURSIVE:-} ]] ; then
804 STP_TEST_RECURSIVE=2 STP_TEST_LOG_PREFIX="$local_logdir/" $cmd </dev/null 4>"$tmpfile" 6>&5 5>&2 3>&1 2>&1 | timestamp | log "$logfile"
805 else
806 STP_TEST_RECURSIVE=1 STP_TEST_LOG_PREFIX="$local_logdir/" $cmd </dev/null 4>"$tmpfile" 5>&2 3>&1 2>&1 | timestamp | log "$logfile"
807 fi
808 stepstatus=${PIPESTATUS[0]}
809 (( stepstatus > 0 )) && msg=FAILED
810 fi
811 local -a emptyfiles=()
812 for f in "$local_logdir"/* ; do
813 [[ -f $f && ! -s $f ]] && emptyfiles+=("$f")
814 done
815 [[ -n "${emptyfiles[*]:-}" ]] && rm -f -- "${emptyfiles[@]}"
816 else
817 msg='(SKIPPED)'
818 fi
819 local setime=$(date_sec)
820 local sestamp=$(stamp)
821 if [[ -z ${DONTRUN_OP:-} ]] ; then
822 echo "$cmd $msg at $sestamp ($(time_delta "$sstime" "$setime"))" | log "$logfile" "$top_log"
823 echo "----------------------------------------------------------------" | log "$logfile" "$top_log"
824 fi
825 counter=$((counter+1))
826 }
827
828 declare -a OPERATIONS=(preflight
829 check_git
830 check_git_tag
831 run_maintainer_clean
832 run_autogen
833 run_clean
834 run_build
835 check_git_builds
836 run_valgrind_minimal
837 run_distcheck_fast
838 run_valgrind
839 run_full
840 run_checksums
841 fetch_translations
842 run_distcheck_minimal
843 git_prep_release
844 run_distcheck_minimal
845 save_build_artifacts
846 finis
847 git_final_cleanup)
848
849 function get_longest_op() {
850 local longest_op=0
851 local op
852 for op in "${OPERATIONS[@]}" ; do
853 (( ${#op} > longest_op )) && longest_op=${#op}
854 done
855 echo $((longest_op + 2))
856 }
857
858 # shellcheck disable=SC2206
859 [[ -n ${STP_BUILD_OPERATIONS:-} ]] && OPERATIONS=($STP_BUILD_OPERATIONS)
860 [[ -n "$*" ]] && OPERATIONS=("$@")
861
862 trap finish EXIT SIGHUP SIGINT SIGQUIT SIGTERM
863
864 # shellcheck disable=SC2155
865 {
866 declare sstamp=$(stamp)
867 declare stime=$(date_sec)
868 }
869 declare toplogdir=${STP_LOG_DIR:-"$ROOT/BuildLogs"}
870 declare logdir="$toplogdir/Log.${sstamp// /_}"
871 [[ -n ${STP_LOG_NO_SUBDIR:-} ]] && logdir=$toplogdir
872 top_log="$logdir/00.Master"
873 mkdir -p "$logdir"
874 if [[ -z ${STP_LOG_NO_SUBDIR:-} ]] ; then
875 if [[ -L $toplogdir/Current ]] ; then
876 rm -f -- "$toplogdir/Previous"
877 mv "$toplogdir/Current" "$toplogdir/Previous"
878 fi
879 ln -s "${logdir##*/}" "$toplogdir/Current"
880 fi
881 export ARTIFACTDIR="$logdir/Artifacts"
882 mkdir -p "$ARTIFACTDIR"
883
884 [[ -n $("$GIT" status --porcelain -uno) ]] && git_dirty=' (dirty)'
885 log "-$top_log" <<< "================================================================"
886
887 log_top <<EOF
888 ${tbold}*** Gutenprint $build_type build started at $sstamp on $(uname -n)${treset}
889
890 Directory: $ROOT
891 Logs: ${logdir#${ROOT}/}
892 Kernel: $(uname -o) $(uname -rv)
893 Revision: $("$GIT" rev-parse @)$git_dirty
894 Parallel: $STP_PARALLEL
895 EOF
896
897 [[ -n ${STP_TEST_ROTOR_CIRCUMFERENCE:-} && -n ${STP_TEST_ROTOR:-} ]] &&
898 log_top "Rotor: $STP_TEST_ROTOR / $STP_TEST_ROTOR_CIRCUMFERENCE"
899
900 # Or we could just do "env" here, but having them sorted makes it
901 # easier to read. Variables containing '%%' are functions
902 log_top <<EOF
903
904 Environment:
905 $(while read -r var ; do
906 eval "echo ' '$var=\${$var@Q}"
907 done <<< "$(compgen -e)")
908
909 CPU information:
910 $(lscpu -e)
911 $(lscpu)
912
913 Memory information:
914 $(free)
915
916 Running operations:
917 EOF
918
919 if [[ -n ${TRAVIS_MODE:-} ]] ; then
920 export BUILD_VERBOSE=1
921 travis_deadman&
922 fi
923
924 declare -A SKIP_OPS
925 [[ -n ${STP_BUILD_SKIP:-} ]] &&
926 for o in ${STP_BUILD_SKIP//,/ } ; do SKIP_OPS[$o]=1; done
927 declare -i runstatus=0
928 # shellcheck disable=SC2155
929 declare -i longest_op=$(get_longest_op)
930 declare -i lstatus=0
931 for op in "${OPERATIONS[@]}" ; do
932 [[ -z ${BUILD_VERBOSE:-} ]] && tmpfile=$(mktemp "/tmp/stpconsole.XXXXXXXX")
933 DONTRUN_OP="${DONTRUN:-}${SKIP_OPS[$op]:-}" runit "$op"
934 lstatus=$stepstatus
935 report_step_status
936 if (( lstatus > 0 )) ; then
937 runstatus=1
938 (( lstatus != 2 )) && break
939 fi
940 done
941 exitstatus="$runstatus"