diff --git a/src/rustup/env_var.rs b/src/rustup/env_var.rs index a787f11999..ff00ef7dea 100644 --- a/src/rustup/env_var.rs +++ b/src/rustup/env_var.rs @@ -1,6 +1,5 @@ -use std::ffi::OsString; use std::env; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::process::Command; pub const RUST_RECURSION_COUNT_MAX: u32 = 5; @@ -20,15 +19,19 @@ pub fn append_path(name: &str, value: Vec, cmd: &mut Command) { } } -pub fn prepend_path(name: &str, value: &Path, cmd: &mut Command) { +pub fn prepend_path(name: &str, value: Vec, cmd: &mut Command) { let old_value = env::var_os(name); - let mut parts = vec![value.to_owned()]; + let mut parts: Vec; if let Some(ref v) = old_value { - parts.extend(env::split_paths(v)); + parts = value; + parts.extend(env::split_paths(v).collect::>()); + } else { + parts = value; } - let new_value = env::join_paths(parts).unwrap_or_else(|_| OsString::from(value)); - cmd.env(name, new_value); + if let Ok(new_value) = env::join_paths(parts) { + cmd.env(name, new_value); + } } pub fn inc(name: &str, cmd: &mut Command) { diff --git a/src/rustup/toolchain.rs b/src/rustup/toolchain.rs index a37e711d31..49ba3712c2 100644 --- a/src/rustup/toolchain.rs +++ b/src/rustup/toolchain.rs @@ -407,15 +407,22 @@ impl<'a> Toolchain<'a> { mod sysenv { pub const LOADER_PATH: &'static str = "DYLD_LIBRARY_PATH"; } - env_var::prepend_path(sysenv::LOADER_PATH, &new_path, cmd); + env_var::prepend_path(sysenv::LOADER_PATH, vec![new_path.clone()], cmd); // Prepend CARGO_HOME/bin to the PATH variable so that we're sure to run // cargo/rustc via the proxy bins. There is no fallback case for if the // proxy bins don't exist. We'll just be running whatever happens to // be on the PATH. + let mut path_entries = vec![]; if let Ok(cargo_home) = utils::cargo_home() { - env_var::prepend_path("PATH", &cargo_home.join("bin"), cmd); + path_entries.push(cargo_home.join("bin").to_path_buf()); } + + if cfg!(target_os = "windows") { + path_entries.push(self.path.join("bin")); + } + + env_var::prepend_path("PATH", path_entries, cmd); } pub fn doc_path(&self, relative: &str) -> Result {