Skip to content

Commit

Permalink
Merge pull request #402 from SpaceManiac/windows-path
Browse files Browse the repository at this point in the history
Point PATH to toolchain/bin on Windows
  • Loading branch information
brson committed May 17, 2016
2 parents debf1b6 + 82165fb commit 1a335ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/rustup/env_var.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf>, cmd: &mut Command) {
let old_value = env::var_os(name);
let mut parts: Vec<PathBuf>;
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 {
Expand Down
12 changes: 10 additions & 2 deletions src/rustup/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
Expand Down

0 comments on commit 1a335ec

Please sign in to comment.