Skip to content

Commit 87d477b

Browse files
committed
use in-tree rustfmt if stage > 0 or precompiled one is unavailable
Signed-off-by: onur-ozkan <[email protected]>
1 parent 0eb0b8c commit 87d477b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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

Lines changed: 12 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,17 @@ 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 || !build.config.is_explicit_stage() {
243+
build.initial_rustfmt().unwrap_or_else(|| {
244+
let compiler = build.compiler(build.top_stage, build.config.build);
245+
build.ensure(tool::Rustfmt { compiler, target: build.config.build }).tool_path
246+
})
247+
} 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+
245252
let src = build.src.clone();
246253
let (tx, rx): (SyncSender<PathBuf>, _) = std::sync::mpsc::sync_channel(128);
247254
let walker = WalkBuilder::new(src.clone()).types(matcher).overrides(override_).build_parallel();

0 commit comments

Comments
 (0)