Debian Codegraph @

dev/ci/ci-wrapper.sh

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/env bash
2
3 # Use this script to preserve the exit code of $CI_SCRIPT when piping
4 # it to `tee $log_file`. We have a separate script, because
5 # this only works in bash, which we don't require project-wide.
6
7 set -o pipefail
8 set -x
9
10 CI_NAME="$1"
11 CI_SCRIPT="scripts/ci-${CI_NAME}.sh"
12 log_file="_build_ci/${CI_NAME}.log"
13
14 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
15 # assume this script is in dev/ci/, cd to the root Rocq directory
16 cd "${DIR}/../.." || exit 1
17
18 mkdir -p _build_ci # needs to exist so we can write the log_file
19
20 export TIMED=1
21
22 # if COQ_CI_COLOR is set (from the environment) keep it intact (even when it's the empty string)'
23 if ! [ "${COQ_CI_COLOR+1}" ]; then
24 # NB: in CI TERM is unset in the environment
25 # when TERM is unset, bash sets it to "dumb" as a bash variable (not exported?)
26 if { [ -t 1 ] && ! [ "$TERM" = dumb ]; } || [ "$CI" ]
27 then COQ_CI_COLOR=1
28 else COQ_CI_COLOR=
29 fi
30 fi
31
32 # we don't want to block commands on user interaction
33 export GIT_PAGER=
34 if [ "$COQ_CI_COLOR" = 1 ] && command -v script > /dev/null; then
35 # prevent piping from disabling auto colors / enable auto colors in CI
36 if [ "$CI" ]; then
37 export TERM=xterm-color
38 fi
39 # on some macos systems OSTYPE is just "darwin", on others it's followed by version info
40 if [[ "$OSTYPE" =~ ^darwin ]]; then
41 script -q /dev/null bash "${DIR}/${CI_SCRIPT}" 2>&1 | tee "$log_file"
42 else
43 script --quiet --flush --return -c "bash '${DIR}/${CI_SCRIPT}'" /dev/null 2>&1 | tee "$log_file"
44 fi
45 else
46 if [ "$COQ_CI_COLOR" = 1 ]; then
47 >&2 echo 'script command not available, colors will be hidden'
48 fi
49 bash "${DIR}/${CI_SCRIPT}" 2>&1 | tee "$log_file"
50 fi
51 code=$?
52
53 printf "\n%s exit code: %s\n" "$CI_NAME" "$code" >> "$log_file"
54
55 # the test suite already prints a timing table
56 if [ "$CI_NAME" != stdlib_test ]; then
57 echo 'Aggregating timing log...'
58 echo
59 tools/make-one-time-file.py --real "$log_file"
60 fi
61
62 # don't print error summary for coq_tools as it gets spammy, and hides jason_msg
63 # see eg https://gitlab.inria.fr/coq/coq/-/jobs/6292796
64 if [ "$CI" ] && ! [ $code = 0 ] && [ "$CI_NAME" != coq_tools ]; then
65 set +x
66
67 escape_re=$(printf '\033%s' '\[[0-9;]+m')
68
69 # File ".*
70 file_re="($escape_re)?"'File ".*\n'
71
72 # OCaml: error message may contain some code extracts starting with the line number,
73 # followed by a line containing "^^^" to point at the columns (possibly colored)
74 codeline_re='([0-9].*\n)*'
75 carets_re="((($escape_re)|[ ^])*\n)?"
76
77 # Error messages may be multiline, but it's hard to find the end
78 # heuristic: if the line ends with ":" or ",", also print the next
79 # (typically if the start of the message got moved to the next line,
80 # the first line is just "Error:",
81 # also note that OCaml colors just "Error" but Rocq colors the whole "Error:")
82 error_re="($escape_re)?Error(.*[:,]($escape_re)?\n)*.*\n"
83
84 # for some reason when testing with colors on
85 # I also got carriage returns in my output which confused grep, so remove them
86
87 # -P: perl-like
88 # -z: multiline using \0 chars (which is why we have to tr to cleanup the output)
89 # -o: print only matched (otherwise it prints the whole file due to -z)
90
91 # || true: if no error is matched by this pattern, we still want to use the error code from the build
92 < "$log_file" tr -d "$(printf '\r')" \
93 | grep -Pzo "$file_re$codeline_re$carets_re$error_re" \
94 | tr -d '\0' > errors \
95 || true
96
97 if [ -s errors ]; then {
98 echo
99 echo "Error list (may be incomplete):"
100 echo
101 cat errors
102 } >&2
103 fi
104 rm errors
105
106 fi
107 exit $code