From 5cb5c85152e2a8b7f3480a46f4619b572f162056 Mon Sep 17 00:00:00 2001 From: Tim Neumann Date: Mon, 31 Oct 2016 21:00:32 +0100 Subject: [PATCH] rustbuild+configure: improve bin/exe joining --- src/bootstrap/config.rs | 8 +++++--- src/bootstrap/util.rs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 0948a7c130e5f..9f6e91c85661c 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -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. /// @@ -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()) @@ -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"])); } _ => {} } diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs index 6c0a32a54d919..84ba03b2502e2 100644 --- a/src/bootstrap/util.rs +++ b/src/bootstrap/util.rs @@ -172,3 +172,21 @@ pub fn dylib_path() -> Vec { 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 +}