Skip to content

Commit f2b11f3

Browse files
committed
Auto merge of #46393 - kennytm:45861-step-2-3-make-tools-job-not-fail-fast, r=alexcrichton
[auto-toolstate][2+3/8] Move external tools tests into its own job with --no-fail-fast This PR performs these things: 1. The `aux` job now performs "cargotest" and "pretty" tests. The clippy/rustfmt/rls/miri tests are moved into its own job. 2. These tests are run with `--no-fail-fast`, so that we can get the maximum number of failures of all tools from a single CI run. 3. The test results are stored into a JSON file, ready to be uploaded in the future. This is step 2 and 3/8 of automatic management of broken tools #45861.
2 parents 0d11e51 + 1839645 commit f2b11f3

File tree

14 files changed

+124
-28
lines changed

14 files changed

+124
-28
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ matrix:
168168
if: branch = auto
169169
- env: IMAGE=x86_64-gnu-aux
170170
if: branch = auto
171-
- env: IMAGE=x86_64-gnu-cargotest
171+
- env: IMAGE=x86_64-gnu-tools
172172
if: branch = auto
173173
- env: IMAGE=x86_64-gnu-debug
174174
if: branch = auto

appveyor.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ environment:
2525
RUST_CHECK_TARGET: check-aux
2626
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc
2727

28-
# MSVC cargotest
28+
# MSVC tools tests
2929
- MSYS_BITS: 64
30-
SCRIPT: python x.py test src/tools/cargotest
31-
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc
30+
SCRIPT: src/ci/docker/x86_64-gnu-tools/checktools.sh x.py toolstates.json
31+
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --save-toolstates=toolstates.json
3232

3333
# 32/64-bit MinGW builds.
3434
#

config.toml.example

+4
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@
301301
# As a side-effect also generates MIR for all libraries.
302302
#test-miri = false
303303

304+
# After building or testing extended tools (e.g. clippy and rustfmt), append the
305+
# result (broken, compiling, testing) into this JSON file.
306+
#save-toolstates = "/path/to/toolstates.json"
307+
304308
# =============================================================================
305309
# Options for specific targets
306310
#

src/bootstrap/check.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,21 @@ impl fmt::Display for TestKind {
6565
}
6666
}
6767

68-
fn try_run_expecting(build: &Build, cmd: &mut Command, expect: BuildExpectation) {
68+
fn try_run_expecting(build: &Build, cmd: &mut Command, expect: BuildExpectation) -> bool {
6969
if !build.fail_fast {
7070
if !build.try_run(cmd, expect) {
7171
let mut failures = build.delayed_failures.borrow_mut();
7272
failures.push(format!("{:?}", cmd));
73+
return false;
7374
}
7475
} else {
7576
build.run_expecting(cmd, expect);
7677
}
78+
true
7779
}
7880

7981
fn try_run(build: &Build, cmd: &mut Command) {
80-
try_run_expecting(build, cmd, BuildExpectation::None)
82+
try_run_expecting(build, cmd, BuildExpectation::None);
8183
}
8284

8385
fn try_run_quiet(build: &Build, cmd: &mut Command) {
@@ -257,11 +259,13 @@ impl Step for Rls {
257259

258260
builder.add_rustc_lib_path(compiler, &mut cargo);
259261

260-
try_run_expecting(
262+
if try_run_expecting(
261263
build,
262264
&mut cargo,
263265
builder.build.config.toolstate.rls.passes(ToolState::Testing),
264-
);
266+
) {
267+
build.save_toolstate("rls", ToolState::Testing);
268+
}
265269
}
266270
}
267271

@@ -305,11 +309,13 @@ impl Step for Rustfmt {
305309

306310
builder.add_rustc_lib_path(compiler, &mut cargo);
307311

308-
try_run_expecting(
312+
if try_run_expecting(
309313
build,
310314
&mut cargo,
311315
builder.build.config.toolstate.rustfmt.passes(ToolState::Testing),
312-
);
316+
) {
317+
build.save_toolstate("rustfmt", ToolState::Testing);
318+
}
313319
}
314320
}
315321

@@ -354,11 +360,13 @@ impl Step for Miri {
354360

355361
builder.add_rustc_lib_path(compiler, &mut cargo);
356362

357-
try_run_expecting(
363+
if try_run_expecting(
358364
build,
359365
&mut cargo,
360366
builder.build.config.toolstate.miri.passes(ToolState::Testing),
361-
);
367+
) {
368+
build.save_toolstate("miri", ToolState::Testing);
369+
}
362370
} else {
363371
eprintln!("failed to test miri: could not build");
364372
}
@@ -411,11 +419,13 @@ impl Step for Clippy {
411419

412420
builder.add_rustc_lib_path(compiler, &mut cargo);
413421

414-
try_run_expecting(
422+
if try_run_expecting(
415423
build,
416424
&mut cargo,
417425
builder.build.config.toolstate.clippy.passes(ToolState::Testing),
418-
);
426+
) {
427+
build.save_toolstate("clippy-driver", ToolState::Testing);
428+
}
419429
} else {
420430
eprintln!("failed to test clippy: could not build");
421431
}

src/bootstrap/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ pub struct Config {
112112
pub channel: String,
113113
pub quiet_tests: bool,
114114
pub test_miri: bool,
115+
pub save_toolstates: Option<PathBuf>,
116+
115117
// Fallback musl-root for all targets
116118
pub musl_root: Option<PathBuf>,
117119
pub prefix: Option<PathBuf>,
@@ -279,6 +281,7 @@ struct Rust {
279281
dist_src: Option<bool>,
280282
quiet_tests: Option<bool>,
281283
test_miri: Option<bool>,
284+
save_toolstates: Option<String>,
282285
}
283286

284287
/// TOML representation of how each build target is configured.
@@ -473,6 +476,7 @@ impl Config {
473476
set(&mut config.test_miri, rust.test_miri);
474477
config.rustc_default_linker = rust.default_linker.clone();
475478
config.musl_root = rust.musl_root.clone().map(PathBuf::from);
479+
config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
476480

477481
match rust.codegen_units {
478482
Some(0) => config.rust_codegen_units = Some(num_cpus::get() as u32),

src/bootstrap/configure.py

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def v(*args):
7777
o("debuginfo-lines", "rust.debuginfo-lines", "build with line number debugger metadata")
7878
o("debuginfo-only-std", "rust.debuginfo-only-std", "build only libstd with debugging information")
7979
o("debug-jemalloc", "rust.debug-jemalloc", "build jemalloc with --enable-debug --enable-fill")
80+
v("save-toolstates", "rust.save-toolstates", "save build and test status of external tools into this file")
8081

8182
v("prefix", "install.prefix", "set installation prefix")
8283
v("localstatedir", "install.localstatedir", "local state directory")

src/bootstrap/lib.rs

+25
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ mod job {
190190
pub use config::Config;
191191
use flags::Subcommand;
192192
use cache::{Interned, INTERNER};
193+
use toolstate::ToolState;
193194

194195
/// A structure representing a Rust compiler.
195196
///
@@ -874,6 +875,30 @@ impl Build {
874875
}
875876
}
876877

878+
/// Updates the actual toolstate of a tool.
879+
///
880+
/// The toolstates are saved to the file specified by the key
881+
/// `rust.save-toolstates` in `config.toml`. If unspecified, nothing will be
882+
/// done. The file is updated immediately after this function completes.
883+
pub fn save_toolstate(&self, tool: &str, state: ToolState) {
884+
use std::io::{Seek, SeekFrom};
885+
886+
if let Some(ref path) = self.config.save_toolstates {
887+
let mut file = t!(fs::OpenOptions::new()
888+
.create(true)
889+
.read(true)
890+
.write(true)
891+
.open(path));
892+
893+
let mut current_toolstates: HashMap<Box<str>, ToolState> =
894+
serde_json::from_reader(&mut file).unwrap_or_default();
895+
current_toolstates.insert(tool.into(), state);
896+
t!(file.seek(SeekFrom::Start(0)));
897+
t!(file.set_len(0));
898+
t!(serde_json::to_writer(file, &current_toolstates));
899+
}
900+
}
901+
877902
/// Get a list of crates from a root crate.
878903
///
879904
/// Returns Vec<(crate, path to crate, is_root_crate)>

src/bootstrap/mk/Makefile.in

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ check:
5353
check-aux:
5454
$(Q)$(BOOTSTRAP) test \
5555
src/tools/cargo \
56-
src/tools/rls \
57-
src/tools/rustfmt \
58-
src/tools/miri \
56+
src/tools/cargotest \
5957
src/test/pretty \
6058
src/test/run-pass/pretty \
6159
src/test/run-fail/pretty \

src/bootstrap/tool.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,19 @@ impl Step for ToolBuild {
115115
println!("Building stage{} tool {} ({})", compiler.stage, tool, target);
116116

117117
let mut cargo = prepare_tool_cargo(builder, compiler, target, "build", path);
118-
if !build.try_run(&mut cargo, expectation) {
118+
let is_expected = build.try_run(&mut cargo, expectation);
119+
// If the expectation is "Failing", `try_run` returning true actually
120+
// means a build-failure is successfully observed, i.e. the tool is
121+
// broken. Thus the XOR here.
122+
// Sorry for the complicated logic, but we can remove this expectation
123+
// logic after #45861 is fully fixed.
124+
build.save_toolstate(tool, if is_expected ^ (expectation == BuildExpectation::Failing) {
125+
ToolState::Compiling
126+
} else {
127+
ToolState::Broken
128+
});
129+
130+
if !is_expected {
119131
if expectation == BuildExpectation::None {
120132
exit(1);
121133
} else {

src/bootstrap/toolstate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use build_helper::BuildExpectation;
1212

13-
#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Eq)]
13+
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
1414
/// Whether a tool can be compiled, tested or neither
1515
pub enum ToolState {
1616
/// The tool compiles successfully, but the test suite fails

src/ci/docker/x86_64-gnu-aux/Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1212
libssl-dev \
1313
sudo \
1414
xz-utils \
15-
pkg-config
15+
pkg-config \
16+
libgl1-mesa-dev \
17+
llvm-dev \
18+
libfreetype6-dev \
19+
libexpat1-dev
1620

1721
COPY scripts/sccache.sh /scripts/
1822
RUN sh /scripts/sccache.sh

src/ci/docker/x86_64-gnu-cargotest/Dockerfile renamed to src/ci/docker/x86_64-gnu-tools/Dockerfile

+5-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1212
libssl-dev \
1313
sudo \
1414
xz-utils \
15-
pkg-config \
16-
libgl1-mesa-dev \
17-
llvm-dev \
18-
libfreetype6-dev \
19-
libexpat1-dev
15+
pkg-config
2016

2117
COPY scripts/sccache.sh /scripts/
2218
RUN sh /scripts/sccache.sh
2319

24-
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu
25-
ENV SCRIPT python2.7 ../x.py test src/tools/cargotest
20+
COPY x86_64-gnu-tools/checktools.sh /tmp/
21+
22+
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu --save-toolstates=/tmp/toolstates.json
23+
ENV SCRIPT /tmp/checktools.sh ../x.py /tmp/toolstates.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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="$2"
17+
18+
touch "$TOOLSTATE_FILE"
19+
20+
set +e
21+
python2.7 "$X_PY" test --no-fail-fast \
22+
src/tools/rls \
23+
src/tools/rustfmt \
24+
src/tools/miri \
25+
src/tools/clippy
26+
TEST_RESULT=$?
27+
set -e
28+
29+
# FIXME: Upload this file to the repository.
30+
cat "$TOOLSTATE_FILE"
31+
32+
# FIXME: After we can properly inform dev-tool maintainers about failure,
33+
# comment out the `exit 0` below.
34+
if [ "$RUST_RELEASE_CHANNEL" = nightly ]; then
35+
# exit 0
36+
true
37+
fi
38+
39+
exit $TEST_RESULT

src/ci/run.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ fi
4242
#
4343
# FIXME: need a scheme for changing this `nightly` value to `beta` and `stable`
4444
# either automatically or manually.
45+
export RUST_RELEASE_CHANNEL=nightly
4546
if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then
46-
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=nightly"
47+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
4748
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp"
4849

4950
if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then

0 commit comments

Comments
 (0)