Skip to content

Commit 7e827e9

Browse files
authored
Rollup merge of #84783 - jyn514:fmt-one, r=Mark-Simulacrum
Allow formatting specific subdirectories Fixes #71094.
2 parents 5fc8987 + dadcb05 commit 7e827e9

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/bootstrap/flags.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub enum Subcommand {
9191
paths: Vec<PathBuf>,
9292
},
9393
Format {
94+
paths: Vec<PathBuf>,
9495
check: bool,
9596
},
9697
Doc {
@@ -581,7 +582,7 @@ Arguments:
581582

582583
Subcommand::Clean { all: matches.opt_present("all") }
583584
}
584-
"fmt" => Subcommand::Format { check: matches.opt_present("check") },
585+
"fmt" => Subcommand::Format { check: matches.opt_present("check"), paths },
585586
"dist" => Subcommand::Dist { paths },
586587
"install" => Subcommand::Install { paths },
587588
"run" | "r" => {

src/bootstrap/format.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct RustfmtConfig {
4242
ignore: Vec<String>,
4343
}
4444

45-
pub fn format(build: &Build, check: bool) {
45+
pub fn format(build: &Build, check: bool, paths: &[PathBuf]) {
4646
if build.config.dry_run {
4747
return;
4848
}
@@ -118,8 +118,19 @@ pub fn format(build: &Build, check: bool) {
118118
.to_path_buf();
119119
let src = build.src.clone();
120120
let (tx, rx): (SyncSender<PathBuf>, _) = std::sync::mpsc::sync_channel(128);
121-
let walker =
122-
WalkBuilder::new(src.clone()).types(matcher).overrides(ignore_fmt).build_parallel();
121+
let walker = match paths.get(0) {
122+
Some(first) => {
123+
let mut walker = WalkBuilder::new(first);
124+
for path in &paths[1..] {
125+
walker.add(path);
126+
}
127+
walker
128+
}
129+
None => WalkBuilder::new(src.clone()),
130+
}
131+
.types(matcher)
132+
.overrides(ignore_fmt)
133+
.build_parallel();
123134

124135
// there is a lot of blocking involved in spawning a child process and reading files to format.
125136
// spawn more processes than available concurrency to keep the CPU busy

src/bootstrap/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ impl Build {
478478
job::setup(self);
479479
}
480480

481-
if let Subcommand::Format { check } = self.config.cmd {
482-
return format::format(self, check);
481+
if let Subcommand::Format { check, paths } = &self.config.cmd {
482+
return format::format(self, *check, &paths);
483483
}
484484

485485
if let Subcommand::Clean { all } = self.config.cmd {

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
889889
);
890890
std::process::exit(1);
891891
}
892-
crate::format::format(&builder.build, !builder.config.cmd.bless());
892+
crate::format::format(&builder.build, !builder.config.cmd.bless(), &[]);
893893
}
894894
}
895895

0 commit comments

Comments
 (0)