Skip to content

Commit dadcb05

Browse files
committed
Allow formatting specific subdirectories
1 parent b52769b commit dadcb05

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 {
@@ -578,7 +579,7 @@ Arguments:
578579

579580
Subcommand::Clean { all: matches.opt_present("all") }
580581
}
581-
"fmt" => Subcommand::Format { check: matches.opt_present("check") },
582+
"fmt" => Subcommand::Format { check: matches.opt_present("check"), paths },
582583
"dist" => Subcommand::Dist { paths },
583584
"install" => Subcommand::Install { paths },
584585
"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
@@ -897,7 +897,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
897897
);
898898
std::process::exit(1);
899899
}
900-
crate::format::format(&builder.build, !builder.config.cmd.bless());
900+
crate::format::format(&builder.build, !builder.config.cmd.bless(), &[]);
901901
}
902902
}
903903

0 commit comments

Comments
 (0)