Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rustbuild+configure: improve bin/exe joining
  • Loading branch information
TimNN committed Oct 31, 2016
1 parent dce4600 commit 5cb5c85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/bootstrap/config.rs
Expand Up @@ -23,6 +23,7 @@ use std::process;
use num_cpus;
use rustc_serialize::Decodable;
use toml::{Parser, Decoder, Value};
use util::push_exe_path;

/// Global configuration for the entire build and/or bootstrap.
///
Expand Down Expand Up @@ -417,7 +418,7 @@ impl Config {
let target = self.target_config.entry(self.build.clone())
.or_insert(Target::default());
let root = PathBuf::from(value);
target.llvm_config = Some(root.join("bin/llvm-config"));
target.llvm_config = Some(push_exe_path(root, &["bin", "llvm-config"]));
}
"CFG_JEMALLOC_ROOT" if value.len() > 0 => {
let target = self.target_config.entry(self.build.clone())
Expand Down Expand Up @@ -449,8 +450,9 @@ impl Config {
target.ndk = Some(PathBuf::from(value));
}
"CFG_LOCAL_RUST_ROOT" if value.len() > 0 => {
self.rustc = Some(PathBuf::from(value).join("bin/rustc"));
self.cargo = Some(PathBuf::from(value).join("bin/cargo"));
let path = PathBuf::from(value);
self.rustc = Some(push_exe_path(path.clone(), &["bin", "rustc"]));
self.cargo = Some(push_exe_path(path, &["bin", "cargo"]));
}
_ => {}
}
Expand Down
18 changes: 18 additions & 0 deletions src/bootstrap/util.rs
Expand Up @@ -172,3 +172,21 @@ pub fn dylib_path() -> Vec<PathBuf> {
env::split_paths(&env::var_os(dylib_path_var()).unwrap_or(OsString::new()))
.collect()
}

/// `push` all components to `buf`. On windows, append `.exe` to the last component.
pub fn push_exe_path(mut buf: PathBuf, components: &[&str]) -> PathBuf {
let (&file, components) = components.split_last().expect("at least one component required");
let mut file = file.to_owned();

if cfg!(windows) {
file.push_str(".exe");
}

for c in components {
buf.push(c);
}

buf.push(file);

buf
}

0 comments on commit 5cb5c85

Please sign in to comment.