Rollup merge of #84783 - jyn514:fmt-one, r=Mark-Simulacrum
Allow formatting specific subdirectories Fixes https://github.com/rust-lang/rust/issues/71094.
This commit is contained in:
commit
7e827e936b
@ -91,6 +91,7 @@ pub enum Subcommand {
|
|||||||
paths: Vec<PathBuf>,
|
paths: Vec<PathBuf>,
|
||||||
},
|
},
|
||||||
Format {
|
Format {
|
||||||
|
paths: Vec<PathBuf>,
|
||||||
check: bool,
|
check: bool,
|
||||||
},
|
},
|
||||||
Doc {
|
Doc {
|
||||||
@ -581,7 +582,7 @@ Arguments:
|
|||||||
|
|
||||||
Subcommand::Clean { all: matches.opt_present("all") }
|
Subcommand::Clean { all: matches.opt_present("all") }
|
||||||
}
|
}
|
||||||
"fmt" => Subcommand::Format { check: matches.opt_present("check") },
|
"fmt" => Subcommand::Format { check: matches.opt_present("check"), paths },
|
||||||
"dist" => Subcommand::Dist { paths },
|
"dist" => Subcommand::Dist { paths },
|
||||||
"install" => Subcommand::Install { paths },
|
"install" => Subcommand::Install { paths },
|
||||||
"run" | "r" => {
|
"run" | "r" => {
|
||||||
|
@ -42,7 +42,7 @@ struct RustfmtConfig {
|
|||||||
ignore: Vec<String>,
|
ignore: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format(build: &Build, check: bool) {
|
pub fn format(build: &Build, check: bool, paths: &[PathBuf]) {
|
||||||
if build.config.dry_run {
|
if build.config.dry_run {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -118,8 +118,19 @@ pub fn format(build: &Build, check: bool) {
|
|||||||
.to_path_buf();
|
.to_path_buf();
|
||||||
let src = build.src.clone();
|
let src = build.src.clone();
|
||||||
let (tx, rx): (SyncSender<PathBuf>, _) = std::sync::mpsc::sync_channel(128);
|
let (tx, rx): (SyncSender<PathBuf>, _) = std::sync::mpsc::sync_channel(128);
|
||||||
let walker =
|
let walker = match paths.get(0) {
|
||||||
WalkBuilder::new(src.clone()).types(matcher).overrides(ignore_fmt).build_parallel();
|
Some(first) => {
|
||||||
|
let mut walker = WalkBuilder::new(first);
|
||||||
|
for path in &paths[1..] {
|
||||||
|
walker.add(path);
|
||||||
|
}
|
||||||
|
walker
|
||||||
|
}
|
||||||
|
None => WalkBuilder::new(src.clone()),
|
||||||
|
}
|
||||||
|
.types(matcher)
|
||||||
|
.overrides(ignore_fmt)
|
||||||
|
.build_parallel();
|
||||||
|
|
||||||
// there is a lot of blocking involved in spawning a child process and reading files to format.
|
// there is a lot of blocking involved in spawning a child process and reading files to format.
|
||||||
// spawn more processes than available concurrency to keep the CPU busy
|
// spawn more processes than available concurrency to keep the CPU busy
|
||||||
|
@ -478,8 +478,8 @@ impl Build {
|
|||||||
job::setup(self);
|
job::setup(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Subcommand::Format { check } = self.config.cmd {
|
if let Subcommand::Format { check, paths } = &self.config.cmd {
|
||||||
return format::format(self, check);
|
return format::format(self, *check, &paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Subcommand::Clean { all } = self.config.cmd {
|
if let Subcommand::Clean { all } = self.config.cmd {
|
||||||
|
@ -889,7 +889,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
|
|||||||
);
|
);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
crate::format::format(&builder.build, !builder.config.cmd.bless());
|
crate::format::format(&builder.build, !builder.config.cmd.bless(), &[]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user