From 20b73514395bb442fb16ce913b6c2b3965ff3156 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Fri, 4 Oct 2019 09:56:45 +0900 Subject: [PATCH 1/2] Workaround cargo bug on Windows --- clippy_dev/src/fmt.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/clippy_dev/src/fmt.rs b/clippy_dev/src/fmt.rs index 9f0b68baf9db..d5d56322f2a5 100644 --- a/clippy_dev/src/fmt.rs +++ b/clippy_dev/src/fmt.rs @@ -140,13 +140,13 @@ fn cargo_fmt(context: &FmtContext, path: &Path) -> Result { args.push("--"); args.push("--check"); } - let success = exec(context, "cargo", path, &args)?; + let success = exec(context, &bin_path("cargo"), path, &args)?; Ok(success) } fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> { - let program = "rustfmt"; + let program = bin_path("rustfmt"); let dir = std::env::current_dir()?; let args = &["+nightly", "--version"]; @@ -173,7 +173,7 @@ fn rustfmt(context: &FmtContext, path: &Path) -> Result { if context.check { args.push("--check".as_ref()); } - let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?; + let success = exec(context, &bin_path("rustfmt"), std::env::current_dir()?, &args)?; if !success { eprintln!("rustfmt failed on {}", path.display()); } @@ -198,3 +198,12 @@ fn project_root() -> Result { Err(CliError::ProjectRootNotFound) } + +// Workaround for https://github.com/rust-lang/cargo/issues/7475. +// FIXME: replace `&bin_path("command")` with `"command"` once the issue is fixed +fn bin_path(bin: &str) -> String { + let mut p = PathBuf::from(std::env::var_os("CARGO_HOME").unwrap()); + p.push("bin"); + p.push(bin); + p.display().to_string() +} From 248251b3b26c5f21e2c2f5bfa5d85cc17b13fc05 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Fri, 4 Oct 2019 11:05:44 +0900 Subject: [PATCH 2/2] Use home::cargo_home --- clippy_dev/Cargo.toml | 2 ++ clippy_dev/src/fmt.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clippy_dev/Cargo.toml b/clippy_dev/Cargo.toml index e2e946d06f27..de56e4b05c91 100644 --- a/clippy_dev/Cargo.toml +++ b/clippy_dev/Cargo.toml @@ -11,3 +11,5 @@ regex = "1" lazy_static = "1.0" shell-escape = "0.1" walkdir = "2" +# FIXME: remove this once cargo issue #7475 is fixed +home = "0.5" diff --git a/clippy_dev/src/fmt.rs b/clippy_dev/src/fmt.rs index d5d56322f2a5..1f4925db1bef 100644 --- a/clippy_dev/src/fmt.rs +++ b/clippy_dev/src/fmt.rs @@ -202,7 +202,7 @@ fn project_root() -> Result { // Workaround for https://github.com/rust-lang/cargo/issues/7475. // FIXME: replace `&bin_path("command")` with `"command"` once the issue is fixed fn bin_path(bin: &str) -> String { - let mut p = PathBuf::from(std::env::var_os("CARGO_HOME").unwrap()); + let mut p = home::cargo_home().unwrap(); p.push("bin"); p.push(bin); p.display().to_string()