From 956e0bae58eb04b6ea48fb2474990437e0757ef9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 16 Feb 2021 22:37:17 -0500 Subject: [PATCH] Update bootstrap for in-tree rustfmt - Add rustfmt to `x.py check` - Update Cargo.lock - Remove rustfmt from the toolstate list - Make rustfmt an in-tree tool - Give an error on `x.py test rustfmt` if rustfmt fails to build or if tests fail - Don't call `save_toolstate` when testing rustfmt --- src/bootstrap/builder.rs | 1 + src/bootstrap/check.rs | 3 ++- src/bootstrap/test.rs | 16 ++++------------ src/bootstrap/tool.rs | 4 ++-- src/bootstrap/toolstate.rs | 8 +++----- .../host-x86_64/x86_64-gnu-tools/checktools.sh | 2 +- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 789267aa880..f39e89a9d01 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -379,6 +379,7 @@ impl<'a> Builder<'a> { check::Clippy, check::Miri, check::Rls, + check::Rustfmt, check::Bootstrap ), Kind::Test => describe!( diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index 3e9d921d0f5..c6844c16315 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -363,13 +363,14 @@ macro_rules! tool_check_step { } tool_check_step!(Rustdoc, "src/tools/rustdoc", "src/librustdoc", SourceType::InTree); -// Clippy is a hybrid. It is an external tool, but uses a git subtree instead +// Clippy and Rustfmt are hybrids. They are external tools, but use a git subtree instead // of a submodule. Since the SourceType only drives the deny-warnings // behavior, treat it as in-tree so that any new warnings in clippy will be // rejected. tool_check_step!(Clippy, "src/tools/clippy", SourceType::InTree); tool_check_step!(Miri, "src/tools/miri", SourceType::Submodule); tool_check_step!(Rls, "src/tools/rls", SourceType::Submodule); +tool_check_step!(Rustfmt, "src/tools/rustfmt", SourceType::InTree); tool_check_step!(Bootstrap, "src/bootstrap", SourceType::InTree, false); diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 0e9c561c689..98f753b25f0 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -319,15 +319,9 @@ impl Step for Rustfmt { let host = self.host; let compiler = builder.compiler(stage, host); - let build_result = builder.ensure(tool::Rustfmt { - compiler, - target: self.host, - extra_features: Vec::new(), - }); - if build_result.is_none() { - eprintln!("failed to test rustfmt: could not build"); - return; - } + builder + .ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() }) + .expect("in-tree tool"); let mut cargo = tool::prepare_tool_cargo( builder, @@ -346,9 +340,7 @@ impl Step for Rustfmt { cargo.add_rustc_lib_path(builder, compiler); - if try_run(builder, &mut cargo.into()) { - builder.save_toolstate("rustfmt", ToolState::TestPass); - } + builder.run(&mut cargo.into()); } } diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 4f2426648fd..12571c1b97d 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -726,7 +726,7 @@ macro_rules! tool_extended { // Note: tools need to be also added to `Builder::get_step_descriptions` in `builder.rs` // to make `./x.py build ` work. tool_extended!((self, builder), - Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", stable=true, {}; + Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", stable=true, in_tree=true, {}; CargoClippy, clippy, "src/tools/clippy", "cargo-clippy", stable=true, in_tree=true, {}; Clippy, clippy, "src/tools/clippy", "clippy-driver", stable=true, in_tree=true, {}; Miri, miri, "src/tools/miri", "miri", stable=false, {}; @@ -740,7 +740,7 @@ tool_extended!((self, builder), self.extra_features.push("clippy".to_owned()); }; RustDemangler, rust_demangler, "src/tools/rust-demangler", "rust-demangler", stable=false, in_tree=true, {}; - Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, {}; + Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, in_tree=true, {}; RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=false, {}; ); diff --git a/src/bootstrap/toolstate.rs b/src/bootstrap/toolstate.rs index 205524ad84f..2394c5e020d 100644 --- a/src/bootstrap/toolstate.rs +++ b/src/bootstrap/toolstate.rs @@ -77,7 +77,6 @@ static STABLE_TOOLS: &[(&str, &str)] = &[ ("rust-by-example", "src/doc/rust-by-example"), ("edition-guide", "src/doc/edition-guide"), ("rls", "src/tools/rls"), - ("rustfmt", "src/tools/rustfmt"), ]; // These tools are permitted to not build on the beta/stable channels. @@ -278,10 +277,9 @@ impl Builder<'_> { if self.config.dry_run { return; } - // Toolstate isn't tracked for clippy, but since most tools do, we avoid - // checking in all the places we could save toolstate and just do so - // here. - if tool == "clippy-driver" { + // Toolstate isn't tracked for clippy or rustfmt, but since most tools do, we avoid checking + // in all the places we could save toolstate and just do so here. + if tool == "clippy-driver" || tool == "rustfmt" { return; } if let Some(ref path) = self.config.save_toolstates { diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh b/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh index 49a8e5e88a0..412efe5c448 100755 --- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh +++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh @@ -15,7 +15,6 @@ python3 "$X_PY" test --stage 2 --no-fail-fast \ src/doc/embedded-book \ src/doc/edition-guide \ src/tools/rls \ - src/tools/rustfmt \ src/tools/miri \ set -e @@ -24,3 +23,4 @@ set -e cat /tmp/toolstate/toolstates.json python3 "$X_PY" test --stage 2 check-tools python3 "$X_PY" test --stage 2 src/tools/clippy +python3 "$X_PY" test --stage 2 src/tools/rustfmt