Skip to content

Commit

Permalink
Alternative to 162fe72
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed May 14, 2024
1 parent b22359f commit c222181
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
8 changes: 8 additions & 0 deletions dylint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,14 @@ fn check_or_fix(
])
.args(args);

// smoelius:: See: https://github.com/rust-lang/rustup/pull/3703 and
// https://github.com/rust-lang/rustup/issues/3825
#[cfg(windows)]
{
let new_path = dylint_internal::prepend_toolchain_path(toolchain)?;
command.envs(vec![(crate::env::PATH, new_path)]);
}

if let Some(stderr_path) = &opts.pipe_stderr {
let file = OpenOptions::new()
.append(true)
Expand Down
7 changes: 1 addition & 6 deletions internal/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,7 @@ impl Builder {
{
// 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();
let new_path = crate::prepend_path(Path::new(&cargo_home).join("bin")).unwrap();
command.envs(vec![(crate::env::PATH, new_path)]);
}
command.args([&self.subcommand]);
Expand Down
33 changes: 21 additions & 12 deletions internal/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{ensure, Context, Result};
use std::{
path::Path,
ffi::{OsStr, OsString},
path::{Path, PathBuf},
process::{Command, Output},
};

Expand Down Expand Up @@ -61,18 +62,26 @@ pub fn driver(toolchain: &str, driver: &Path) -> Result<Command> {
{
// 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)),
)?;
let new_path = prepend_toolchain_path(toolchain)?;
command.envs(vec![(crate::env::PATH, new_path)]);
}
Ok(command)
}

pub fn prepend_toolchain_path(toolchain: impl AsRef<Path>) -> Result<OsString> {
let rustup_home = crate::env::var(crate::env::RUSTUP_HOME)?;
prepend_path(
Path::new(&rustup_home)
.join("toolchains")
.join(toolchain)
.join("bin"),
)
}

pub fn prepend_path(path: impl AsRef<OsStr>) -> Result<OsString> {
let old_path = crate::env::var(crate::env::PATH)?;
let new_path = std::env::join_paths(
std::iter::once(PathBuf::from(path.as_ref())).chain(std::env::split_paths(&old_path)),
)?;
Ok(new_path)
}

0 comments on commit c222181

Please sign in to comment.