Skip to content

Commit 0238706

Browse files
committed
use in-tree rustfmt if stage > 0 or precompiled one is unavailable
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 0eb0b8c commit 0238706

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/bootstrap/src/core/build_steps/format.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::sync::mpsc::SyncSender;
99
use build_helper::git::get_git_modified_files;
1010
use ignore::WalkBuilder;
1111

12+
use crate::core::build_steps::tool;
1213
use crate::core::builder::Builder;
1314
use crate::utils::build_stamp::BuildStamp;
1415
use crate::utils::exec::command;
@@ -237,11 +238,21 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
237238

238239
let override_ = override_builder.build().unwrap(); // `override` is a reserved keyword
239240

240-
let rustfmt_path = build.initial_rustfmt().unwrap_or_else(|| {
241-
eprintln!("fmt error: `x fmt` is not supported on this channel");
242-
crate::exit!(1);
243-
});
244-
assert!(rustfmt_path.exists(), "{}", rustfmt_path.display());
241+
// If stage is not explicitly set or is 0, try using the precompiled one first.
242+
let rustfmt_path = if build.top_stage == 0
243+
// This is useful for `x test tidy`, since `x test` defaults to stage 1,
244+
// but we don't actually want to use the in-tree stage 1 rustfmt for that command.
245+
|| !build.config.is_explicit_stage()
246+
{
247+
build.initial_rustfmt().unwrap_or_else(|| {
248+
let compiler = build.compiler(build.top_stage, build.config.build);
249+
build.ensure(tool::Rustfmt { compiler, target: build.config.build }).tool_path
250+
})
251+
} else {
252+
let compiler = build.compiler(build.top_stage, build.config.build);
253+
build.ensure(tool::Rustfmt { compiler, target: build.config.build }).tool_path
254+
};
255+
245256
let src = build.src.clone();
246257
let (tx, rx): (SyncSender<PathBuf>, _) = std::sync::mpsc::sync_channel(128);
247258
let walker = WalkBuilder::new(src.clone()).types(matcher).overrides(override_).build_parallel();

0 commit comments

Comments
 (0)