]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/x86_64-gnu-tools/checktools.sh
Allow the linker to choose the LTO-plugin (which is useful when using LLD)
[rust.git] / src / ci / docker / x86_64-gnu-tools / checktools.sh
1 #!/bin/sh
2
3 # Copyright 2017 The Rust Project Developers. See the COPYRIGHT
4 # file at the top-level directory of this distribution and at
5 # http://rust-lang.org/COPYRIGHT.
6 #
7 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 # option. This file may not be copied, modified, or distributed
11 # except according to those terms.
12
13 set -eu
14
15 X_PY="$1"
16 TOOLSTATE_FILE="$(realpath $2)"
17 OS="$3"
18 COMMIT="$(git rev-parse HEAD)"
19 CHANGED_FILES="$(git diff --name-status HEAD HEAD^)"
20 SIX_WEEK_CYCLE="$(( ($(date +%s) / 604800 - 3) % 6 ))"
21 # ^ 1970 Jan 1st is a Thursday, and our release dates are also on Thursdays,
22 #   thus we could divide by 604800 (7 days in seconds) directly.
23
24 touch "$TOOLSTATE_FILE"
25
26 # Try to test all the tools and store the build/test success in the TOOLSTATE_FILE
27
28 set +e
29 python2.7 "$X_PY" test --no-fail-fast \
30     src/doc/book \
31     src/doc/nomicon \
32     src/doc/reference \
33     src/doc/rust-by-example \
34     src/tools/rls \
35     src/tools/rustfmt \
36     src/tools/miri \
37     src/tools/clippy
38 set -e
39
40 cat "$TOOLSTATE_FILE"
41 echo
42
43 # This function checks that if a tool's submodule changed, the tool's state must improve
44 verify_status() {
45     echo "Verifying status of $1..."
46     if echo "$CHANGED_FILES" | grep -q "^M[[:blank:]]$2$"; then
47         echo "This PR updated '$2', verifying if status is 'test-pass'..."
48         if grep -vq '"'"$1"'":"test-pass"' "$TOOLSTATE_FILE"; then
49             echo
50             echo "⚠️ We detected that this PR updated '$1', but its tests failed."
51             echo
52             echo "If you do intend to update '$1', please check the error messages above and"
53             echo "commit another update."
54             echo
55             echo "If you do NOT intend to update '$1', please ensure you did not accidentally"
56             echo "change the submodule at '$2'. You may ask your reviewer for the"
57             echo "proper steps."
58             exit 3
59         fi
60     fi
61 }
62
63 # deduplicates the submodule check and the assertion that on beta some tools MUST be passing
64 check_dispatch() {
65     if [ "$1" = submodule_changed ]; then
66         # ignore $2 (branch id)
67         verify_status $3 $4
68     elif [ "$2" = beta ]; then
69         echo "Requiring test passing for $3..."
70         if grep -q '"'"$3"'":"\(test\|build\)-fail"' "$TOOLSTATE_FILE"; then
71             exit 4
72         fi
73     fi
74 }
75
76 # list all tools here
77 status_check() {
78     check_dispatch $1 beta book src/doc/book
79     check_dispatch $1 beta nomicon src/doc/nomicon
80     check_dispatch $1 beta reference src/doc/reference
81     check_dispatch $1 beta rust-by-example src/doc/rust-by-example
82     check_dispatch $1 beta rls src/tool/rls
83     check_dispatch $1 beta rustfmt src/tool/rustfmt
84     # these tools are not required for beta to successfully branch
85     check_dispatch $1 nightly clippy-driver src/tool/clippy
86     check_dispatch $1 nightly miri src/tool/miri
87 }
88
89 # If this PR is intended to update one of these tools, do not let the build pass
90 # when they do not test-pass.
91
92 status_check "submodule_changed"
93
94 CHECK_NOT="$(readlink -f "$(dirname $0)/checkregression.py")"
95 change_toolstate() {
96     # only update the history
97     if python2.7 "$CHECK_NOT" "$OS" "$TOOLSTATE_FILE" "_data/latest.json" changed; then
98         echo 'Toolstate is not changed. Not updating.'
99     else
100         if [ $SIX_WEEK_CYCLE -eq 5 ]; then
101             python2.7 "$CHECK_NOT" "$OS" "$TOOLSTATE_FILE" "_data/latest.json" regressed
102         fi
103         sed -i "1 a\\
104 $COMMIT\t$(cat "$TOOLSTATE_FILE")
105 " "history/$OS.tsv"
106     fi
107 }
108
109 if [ "$RUST_RELEASE_CHANNEL" = nightly -a -n "${TOOLSTATE_REPO_ACCESS_TOKEN+is_set}" ]; then
110     . "$(dirname $0)/repo.sh"
111     MESSAGE_FILE=$(mktemp -t msg.XXXXXX)
112     echo "($OS CI update)" > "$MESSAGE_FILE"
113     commit_toolstate_change "$MESSAGE_FILE" change_toolstate
114     rm -f "$MESSAGE_FILE"
115     exit 0
116 fi
117
118 # abort compilation if an important tool doesn't build
119 # (this code is reachable if not on the nightly channel)
120 status_check "beta_required"