1 //! Runs rustfmt on the repository.
3 use crate::{util, Build};
4 use std::process::Command;
6 pub fn format(build: &Build, check: bool) {
7 let target = &build.build;
8 let rustfmt_path = build.config.initial_rustfmt.as_ref().unwrap_or_else(|| {
9 eprintln!("./x.py fmt is not supported on this channel");
10 std::process::exit(1);
12 let cargo_fmt_path = rustfmt_path.with_file_name(util::exe("cargo-fmt", &target));
13 assert!(cargo_fmt_path.is_file(), "{} not a file", cargo_fmt_path.display());
15 let mut cmd = Command::new(&cargo_fmt_path);
16 // cargo-fmt calls rustfmt as a bare command, so we need it to only find the correct one
17 cmd.env("PATH", cargo_fmt_path.parent().unwrap());
18 cmd.current_dir(&build.src);
26 let status = cmd.status().expect("executing cargo-fmt");
27 assert!(status.success(), "cargo-fmt errored with status {:?}", status);