forked from rust-lang/rustc_codegen_c
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfmt.rs
More file actions
43 lines (38 loc) · 1.2 KB
/
Copy pathfmt.rs
File metadata and controls
43 lines (38 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::process::Command;
use clap::Args;
use glob::glob;
use crate::Run;
/// Format code, examples and tests
#[derive(Args, Debug)]
pub struct FmtCommand {
#[arg(short, long)]
pub check: bool,
}
impl Run for FmtCommand {
fn run(&self, _manifest: &crate::manifest::Manifest) {
self.perform(
Command::new("cargo").arg("fmt").args(["--manifest-path", "bootstrap/Cargo.toml"]),
);
self.perform(
Command::new("cargo")
.arg("fmt")
.args(["--manifest-path", "crates/Cargo.toml"])
.arg("--all"),
);
for file in glob("examples/**/*.rs").unwrap() {
self.perform(Command::new("rustfmt").args(["--edition", "2021"]).arg(file.unwrap()));
}
for file in glob("tests/**/*.rs").unwrap() {
self.perform(Command::new("rustfmt").args(["--edition", "2021"]).arg(file.unwrap()));
}
}
}
impl FmtCommand {
pub fn perform(&self, command: &mut Command) {
if self.check {
command.arg("--check");
}
log::debug!("running {:?}", command);
assert!(command.status().unwrap().success(), "failed to run {:?}", command);
}
}