1 use crate::cargo_clippy_path;
2 use std::process::{self, Command, ExitStatus};
5 fn exit_if_err(status: io::Result<ExitStatus>) {
6 match status.expect("failed to run command").code() {
8 Some(n) => process::exit(n),
10 eprintln!("Killed by signal");
16 pub fn run(path: &str) {
17 let is_file = match fs::metadata(path) {
18 Ok(metadata) => metadata.is_file(),
20 eprintln!("Failed to read {path}: {e:?}");
28 .args(["run", "--bin", "clippy-driver", "--"])
29 .args(["-L", "./target/debug"])
30 .args(["-Z", "no-codegen"])
31 .args(["--edition", "2021"])
36 exit_if_err(Command::new("cargo").arg("build").status());
38 // Run in a tempdir as changes to clippy do not retrigger linting
39 let target = tempfile::Builder::new()
42 .expect("failed to create tempdir");
44 let status = Command::new(cargo_clippy_path())
46 .env("CARGO_TARGET_DIR", target.as_ref())
49 target.close().expect("failed to remove tempdir");