Skip to content

Commit

Permalink
Workaround cargo bug on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkuu committed Oct 4, 2019
1 parent 737f0a6 commit 20b7351
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions clippy_dev/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
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"];

Expand All @@ -173,7 +173,7 @@ fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
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());
}
Expand All @@ -198,3 +198,12 @@ fn project_root() -> Result<PathBuf, CliError> {

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()
}

0 comments on commit 20b7351

Please sign in to comment.