Skip to content

Commit

Permalink
Work around rustup #2978
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Jul 31, 2022
1 parent 6409a16 commit f5cb5b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
12 changes: 12 additions & 0 deletions internal/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ fn cargo(subcommand: &str, verb: &str, description: &str, quiet: bool) -> crate:
.expect("Could not write to stderr");
}
let mut command = crate::Command::new("cargo");
#[cfg(windows)]
{
// smoelius: Work around https://github.com/rust-lang/rustup/pull/2978
let cargo_home = cargo_home().unwrap();
let old_path = crate::env::var(crate::env::PATH).unwrap();
let new_path = std::env::join_paths(
std::iter::once(Path::new(&cargo_home).join("bin"))
.chain(std::env::split_paths(&old_path)),
)
.unwrap();
command.envs(vec![(env::PATH, new_path)]);
}
command.args(&[subcommand]);
if quiet {
command.stderr(Stdio::null());
Expand Down
46 changes: 20 additions & 26 deletions internal/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::env::{self, var};
use anyhow::{ensure, Context, Result};
use std::{
env::{join_paths, split_paths},
ffi::{OsStr, OsString},
ffi::OsStr,
path::Path,
process::{Command as StdCommand, Output, Stdio},
};
Expand Down Expand Up @@ -96,30 +94,26 @@ impl Command {
}
}

#[allow(unused_variables)]
pub fn driver(toolchain: &str, driver: &Path) -> Result<Command> {
let path = var(env::PATH)?;

let path = {
if cfg!(target_os = "windows") {
// MinerSebas: To succesfully determine the dylint driver Version on Windows,
// it is neccesary to add some Libraries to the Path.
let rustup_home = var(env::RUSTUP_HOME)?;

join_paths(
std::iter::once(
Path::new(&rustup_home)
.join("toolchains")
.join(toolchain)
.join("bin"),
)
.chain(split_paths(&path)),
)?
} else {
OsString::from(path)
}
};

#[allow(unused_mut)]
let mut command = Command::new(driver);
command.envs(vec![(env::PATH, path)]);
#[cfg(windows)]
{
// MinerSebas: To succesfully determine the dylint driver Version on Windows,
// it is neccesary to add some Libraries to the Path.
let rustup_home = crate::env::var(crate::env::RUSTUP_HOME)?;
let old_path = crate::env::var(crate::env::PATH)?;
let new_path = std::env::join_paths(
std::iter::once(
Path::new(&rustup_home)
.join("toolchains")
.join(toolchain)
.join("bin"),
)
.chain(std::env::split_paths(&old_path)),
)?;
command.envs(vec![(crate::env::PATH, new_path)]);
}
Ok(command)
}

0 comments on commit f5cb5b7

Please sign in to comment.