]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/x86_64-gnu-tools/checktools.sh
Rollup merge of #63055 - Mark-Simulacrum:save-analysis-clean-2, r=Xanewok
[rust.git] / src / ci / docker / x86_64-gnu-tools / checktools.sh
1 #!/bin/sh
2
3 set -eu
4
5 X_PY="$1"
6 TOOLSTATE_FILE="$(realpath $2)"
7 OS="$3"
8 COMMIT="$(git rev-parse HEAD)"
9 CHANGED_FILES="$(git diff --name-status HEAD HEAD^)"
10 SIX_WEEK_CYCLE="$(( ($(date +%s) / 86400 - 20) % 42 ))"
11 # ^ Number of days after the last promotion of beta.
12 #   Its value is 41 on the Tuesday where "Promote master to beta (T-2)" happens.
13 #   The Wednesday after this has value 0.
14 #   We track this value to prevent regressing tools in the last week of the 6-week cycle.
15
16 touch "$TOOLSTATE_FILE"
17
18 # Try to test all the tools and store the build/test success in the TOOLSTATE_FILE
19
20 set +e
21 python2.7 "$X_PY" test --no-fail-fast \
22     src/doc/book \
23     src/doc/nomicon \
24     src/doc/reference \
25     src/doc/rust-by-example \
26     src/doc/embedded-book \
27     src/doc/edition-guide \
28     src/doc/rustc-guide \
29     src/tools/clippy \
30     src/tools/rls \
31     src/tools/rustfmt \
32     src/tools/miri \
33
34 set -e
35
36 cat "$TOOLSTATE_FILE"
37 echo
38
39 # This function checks if a particular tool is *not* in status "test-pass".
40 check_tool_failed() {
41     grep -vq '"'"$1"'":"test-pass"' "$TOOLSTATE_FILE"
42 }
43
44 # This function checks that if a tool's submodule changed, the tool's state must improve
45 verify_submodule_changed() {
46     echo "Verifying status of $1..."
47     if echo "$CHANGED_FILES" | grep -q "^M[[:blank:]]$2$"; then
48         echo "This PR updated '$2', verifying if status is 'test-pass'..."
49         if check_tool_failed "$1"; then
50             echo
51             echo "⚠️ We detected that this PR updated '$1', but its tests failed."
52             echo
53             echo "If you do intend to update '$1', please check the error messages above and"
54             echo "commit another update."
55             echo
56             echo "If you do NOT intend to update '$1', please ensure you did not accidentally"
57             echo "change the submodule at '$2'. You may ask your reviewer for the"
58             echo "proper steps."
59             exit 3
60         fi
61     fi
62 }
63
64 # deduplicates the submodule check and the assertion that on beta some tools MUST be passing.
65 # $1 should be "submodule_changed" to only check tools that got changed by this PR,
66 # or "beta_required" to check all tools that have $2 set to "beta".
67 check_dispatch() {
68     if [ "$1" = submodule_changed ]; then
69         # ignore $2 (branch id)
70         verify_submodule_changed $3 $4
71     elif [ "$2" = beta ]; then
72         echo "Requiring test passing for $3..."
73         if check_tool_failed "$3"; then
74             exit 4
75         fi
76     fi
77 }
78
79 # List all tools here.
80 # This function gets called with "submodule_changed" for each PR that changed a submodule,
81 # and with "beta_required" for each PR that lands on beta/stable.
82 # The purpose of this function is to *reject* PRs if a tool is not "test-pass" and
83 # (a) the tool's submodule has been updated, or (b) we landed on beta/stable and the
84 # tool has to "test-pass" on that branch.
85 status_check() {
86     check_dispatch $1 beta book src/doc/book
87     check_dispatch $1 beta nomicon src/doc/nomicon
88     check_dispatch $1 beta reference src/doc/reference
89     check_dispatch $1 beta rust-by-example src/doc/rust-by-example
90     check_dispatch $1 beta edition-guide src/doc/edition-guide
91     check_dispatch $1 beta rls src/tools/rls
92     check_dispatch $1 beta rustfmt src/tools/rustfmt
93     check_dispatch $1 beta clippy-driver src/tools/clippy
94     # These tools are not required on the beta/stable branches, but they *do* cause
95     # PRs to fail if a submodule update does not fix them.
96     # They will still cause failure during the beta cutoff week, unless `checkregression.py`
97     # exempts them from that.
98     check_dispatch $1 nightly miri src/tools/miri
99     check_dispatch $1 nightly embedded-book src/doc/embedded-book
100     check_dispatch $1 nightly rustc-guide src/doc/rustc-guide
101 }
102
103 # If this PR is intended to update one of these tools, do not let the build pass
104 # when they do not test-pass.
105
106 status_check "submodule_changed"
107
108 CHECK_NOT="$(readlink -f "$(dirname $0)/checkregression.py")"
109 # This callback is called by `commit_toolstate_change`, see `repo.sh`.
110 change_toolstate() {
111     # only update the history
112     if python2.7 "$CHECK_NOT" "$OS" "$TOOLSTATE_FILE" "_data/latest.json" changed; then
113         echo 'Toolstate is not changed. Not updating.'
114     else
115         if [ $SIX_WEEK_CYCLE -ge 35 ]; then
116             # Reject any regressions during the week before beta cutoff.
117             python2.7 "$CHECK_NOT" "$OS" "$TOOLSTATE_FILE" "_data/latest.json" regressed
118         fi
119         sed -i "1 a\\
120 $COMMIT\t$(cat "$TOOLSTATE_FILE")
121 " "history/$OS.tsv"
122     fi
123 }
124
125 if [ "$RUST_RELEASE_CHANNEL" = nightly ]; then
126     if [ -n "${TOOLSTATE_PUBLISH+is_set}" ]; then
127         . "$(dirname $0)/repo.sh"
128         MESSAGE_FILE=$(mktemp -t msg.XXXXXX)
129         echo "($OS CI update)" > "$MESSAGE_FILE"
130         commit_toolstate_change "$MESSAGE_FILE" change_toolstate
131         rm -f "$MESSAGE_FILE"
132     fi
133     exit 0
134 fi
135
136 # abort compilation if an important tool doesn't build
137 # (this code is reachable if not on the nightly channel)
138 status_check "beta_required"