From 82165fbd16aa328464949ec8d336dfc6730c90fc Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Thu, 5 May 2016 21:46:19 -0500 Subject: [PATCH] Append .cargo/bin and toolchain/bin to PATH --- src/rustup/env_var.rs | 18 ++++++++++++++++-- src/rustup/toolchain.rs | 12 ++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/rustup/env_var.rs b/src/rustup/env_var.rs index 97bf39cf40..c6a5531bdb 100644 --- a/src/rustup/env_var.rs +++ b/src/rustup/env_var.rs @@ -1,9 +1,23 @@ use std::ffi::OsString; use std::env; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::Command; -pub fn set_path(name: &str, value: &Path, cmd: &mut Command) { +pub fn append_path(name: &str, value: Vec, cmd: &mut Command) { + let old_value = env::var_os(name); + let mut parts: Vec; + if let Some(ref v) = old_value { + parts = env::split_paths(v).collect(); + parts.extend(value); + } else { + parts = value; + } + if let Ok(new_value) = env::join_paths(parts) { + cmd.env(name, new_value); + } +} + +pub fn prepend_path(name: &str, value: &Path, cmd: &mut Command) { let old_value = env::var_os(name); let mut parts = vec![value.to_owned()]; if let Some(ref v) = old_value { diff --git a/src/rustup/toolchain.rs b/src/rustup/toolchain.rs index fe83df6db6..f0555ea4c3 100644 --- a/src/rustup/toolchain.rs +++ b/src/rustup/toolchain.rs @@ -307,8 +307,16 @@ impl<'a> Toolchain<'a> { pub fn set_ldpath(&self, cmd: &mut Command) { let new_path = self.path.join("lib"); - env_var::set_path("LD_LIBRARY_PATH", &new_path, cmd); - env_var::set_path("DYLD_LIBRARY_PATH", &new_path, cmd); + env_var::prepend_path("LD_LIBRARY_PATH", &new_path, cmd); + env_var::prepend_path("DYLD_LIBRARY_PATH", &new_path, cmd); + + // Append first cargo_home, then toolchain/bin to the PATH + let mut path_to_append = Vec::with_capacity(2); + if let Ok(cargo_home) = utils::cargo_home() { + path_to_append.push(cargo_home.join("bin")); + } + path_to_append.push(self.path.join("bin")); + env_var::append_path("PATH", path_to_append, cmd); } pub fn doc_path(&self, relative: &str) -> Result {