Skip to content

Commit 956e0ba

Browse files
jyn514calebcartwright
authored andcommitted
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
1 parent b2d45c0 commit 956e0ba

File tree

6 files changed

+13
-21
lines changed

6 files changed

+13
-21
lines changed

src/bootstrap/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ impl<'a> Builder<'a> {
379379
check::Clippy,
380380
check::Miri,
381381
check::Rls,
382+
check::Rustfmt,
382383
check::Bootstrap
383384
),
384385
Kind::Test => describe!(

src/bootstrap/check.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,14 @@ macro_rules! tool_check_step {
363363
}
364364

365365
tool_check_step!(Rustdoc, "src/tools/rustdoc", "src/librustdoc", SourceType::InTree);
366-
// Clippy is a hybrid. It is an external tool, but uses a git subtree instead
366+
// Clippy and Rustfmt are hybrids. They are external tools, but use a git subtree instead
367367
// of a submodule. Since the SourceType only drives the deny-warnings
368368
// behavior, treat it as in-tree so that any new warnings in clippy will be
369369
// rejected.
370370
tool_check_step!(Clippy, "src/tools/clippy", SourceType::InTree);
371371
tool_check_step!(Miri, "src/tools/miri", SourceType::Submodule);
372372
tool_check_step!(Rls, "src/tools/rls", SourceType::Submodule);
373+
tool_check_step!(Rustfmt, "src/tools/rustfmt", SourceType::InTree);
373374

374375
tool_check_step!(Bootstrap, "src/bootstrap", SourceType::InTree, false);
375376

src/bootstrap/test.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,9 @@ impl Step for Rustfmt {
319319
let host = self.host;
320320
let compiler = builder.compiler(stage, host);
321321

322-
let build_result = builder.ensure(tool::Rustfmt {
323-
compiler,
324-
target: self.host,
325-
extra_features: Vec::new(),
326-
});
327-
if build_result.is_none() {
328-
eprintln!("failed to test rustfmt: could not build");
329-
return;
330-
}
322+
builder
323+
.ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() })
324+
.expect("in-tree tool");
331325

332326
let mut cargo = tool::prepare_tool_cargo(
333327
builder,
@@ -346,9 +340,7 @@ impl Step for Rustfmt {
346340

347341
cargo.add_rustc_lib_path(builder, compiler);
348342

349-
if try_run(builder, &mut cargo.into()) {
350-
builder.save_toolstate("rustfmt", ToolState::TestPass);
351-
}
343+
builder.run(&mut cargo.into());
352344
}
353345
}
354346

src/bootstrap/tool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ macro_rules! tool_extended {
726726
// Note: tools need to be also added to `Builder::get_step_descriptions` in `builder.rs`
727727
// to make `./x.py build <tool>` work.
728728
tool_extended!((self, builder),
729-
Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", stable=true, {};
729+
Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", stable=true, in_tree=true, {};
730730
CargoClippy, clippy, "src/tools/clippy", "cargo-clippy", stable=true, in_tree=true, {};
731731
Clippy, clippy, "src/tools/clippy", "clippy-driver", stable=true, in_tree=true, {};
732732
Miri, miri, "src/tools/miri", "miri", stable=false, {};
@@ -740,7 +740,7 @@ tool_extended!((self, builder),
740740
self.extra_features.push("clippy".to_owned());
741741
};
742742
RustDemangler, rust_demangler, "src/tools/rust-demangler", "rust-demangler", stable=false, in_tree=true, {};
743-
Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, {};
743+
Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, in_tree=true, {};
744744
RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=false, {};
745745
);
746746

src/bootstrap/toolstate.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ static STABLE_TOOLS: &[(&str, &str)] = &[
7777
("rust-by-example", "src/doc/rust-by-example"),
7878
("edition-guide", "src/doc/edition-guide"),
7979
("rls", "src/tools/rls"),
80-
("rustfmt", "src/tools/rustfmt"),
8180
];
8281

8382
// These tools are permitted to not build on the beta/stable channels.
@@ -278,10 +277,9 @@ impl Builder<'_> {
278277
if self.config.dry_run {
279278
return;
280279
}
281-
// Toolstate isn't tracked for clippy, but since most tools do, we avoid
282-
// checking in all the places we could save toolstate and just do so
283-
// here.
284-
if tool == "clippy-driver" {
280+
// Toolstate isn't tracked for clippy or rustfmt, but since most tools do, we avoid checking
281+
// in all the places we could save toolstate and just do so here.
282+
if tool == "clippy-driver" || tool == "rustfmt" {
285283
return;
286284
}
287285
if let Some(ref path) = self.config.save_toolstates {

src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ python3 "$X_PY" test --stage 2 --no-fail-fast \
1515
src/doc/embedded-book \
1616
src/doc/edition-guide \
1717
src/tools/rls \
18-
src/tools/rustfmt \
1918
src/tools/miri \
2019

2120
set -e
@@ -24,3 +23,4 @@ set -e
2423
cat /tmp/toolstate/toolstates.json
2524
python3 "$X_PY" test --stage 2 check-tools
2625
python3 "$X_PY" test --stage 2 src/tools/clippy
26+
python3 "$X_PY" test --stage 2 src/tools/rustfmt

0 commit comments

Comments
 (0)