From: Aleksey Kladov Date: Sat, 14 Apr 2018 08:54:33 +0000 (+0300) Subject: Hide BuildConfig.host_triple behind a getter X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~69^2~8 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=52c9f025328eca86f71539f6f4daf8b8d612aff3;p=cargo.git Hide BuildConfig.host_triple behind a getter --- diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index f5f279a2d..1620aad4a 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -130,7 +130,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { let _p = profile::start("Context::probe_target_info"); debug!("probe_target_info"); let host_target_same = match build_config.requested_target { - Some(ref s) if s != &build_config.host_triple => false, + Some(ref s) if s != &build_config.host_triple() => false, _ => true, }; @@ -302,7 +302,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { self.compilation.native_dirs.insert(dir.clone()); } } - self.compilation.host = self.build_config.host_triple.clone(); + self.compilation.host = self.build_config.host_triple().to_string(); self.compilation.target = self.build_config.target_triple().to_string(); Ok(self.compilation) } @@ -441,7 +441,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { None => return true, }; let (name, info) = match kind { - Kind::Host => (self.build_config.host_triple.as_ref(), &self.host_info), + Kind::Host => (self.build_config.host_triple(), &self.host_info), Kind::Target => (self.build_config.target_triple(), &self.target_info), }; platform.matches(name, info.cfg()) @@ -653,7 +653,8 @@ fn env_args( let target = build_config .requested_target .as_ref() - .unwrap_or(&build_config.host_triple); + .map(|s| s.as_str()) + .unwrap_or(build_config.host_triple()); let key = format!("target.{}.{}", target, name); if let Some(args) = config.get_list_or_split_string(&key)? { let args = args.val.into_iter(); diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 578e2312c..a219ddab5 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -127,7 +127,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes .env( "TARGET", &match unit.kind { - Kind::Host => &cx.build_config.host_triple, + Kind::Host => &cx.build_config.host_triple(), Kind::Target => cx.build_config.target_triple(), }, ) @@ -141,7 +141,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes "debug" }, ) - .env("HOST", &cx.build_config.host_triple) + .env("HOST", &cx.build_config.host_triple()) .env("RUSTC", &cx.build_config.rustc.path) .env("RUSTDOC", &*cx.config.rustdoc()?) .inherit_jobserver(&cx.jobserver); diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index f626637c7..7f9c503b9 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -12,7 +12,7 @@ use serde_json; use core::{Feature, PackageId, Profile, Target}; use core::manifest::Lto; use core::shell::ColorChoice; -use util::{self, machine_message, Config, ProcessBuilder, Rustc, Freshness}; +use util::{self, machine_message, Config, Freshness, ProcessBuilder, Rustc}; use util::{internal, join_paths, profile}; use util::paths; use util::errors::{CargoResult, CargoResultExt, Internal}; @@ -49,13 +49,6 @@ pub enum Kind { /// Configuration information for a rustc build. pub struct BuildConfig { pub rustc: Rustc, - /// The host arch triple - /// - /// e.g. x86_64-unknown-linux-gnu, would be - /// - machine: x86_64 - /// - hardware-platform: unknown - /// - operating system: linux-gnu - pub host_triple: String, /// Build information for the host arch pub host: TargetConfig, /// The target arch triple, defaults to host arch @@ -125,15 +118,13 @@ impl BuildConfig { }; let jobs = jobs.or(cfg_jobs).unwrap_or(::num_cpus::get() as u32); let rustc = config.new_rustc()?; - let host_triple = rustc.host.clone(); - let host_config = TargetConfig::new(config, &host_triple)?; + let host_config = TargetConfig::new(config, &rustc.host)?; let target_config = match target.as_ref() { Some(triple) => TargetConfig::new(config, triple)?, None => host_config.clone(), }; Ok(BuildConfig { rustc, - host_triple, requested_target: target, jobs, host: host_config, @@ -145,10 +136,21 @@ impl BuildConfig { }) } + /// The host arch triple + /// + /// e.g. x86_64-unknown-linux-gnu, would be + /// - machine: x86_64 + /// - hardware-platform: unknown + /// - operating system: linux-gnu + pub fn host_triple(&self) -> &str { + &self.rustc.host + } + pub fn target_triple(&self) -> &str { self.requested_target .as_ref() - .unwrap_or_else(|| &self.host_triple) + .map(|s| s.as_str()) + .unwrap_or(self.host_triple()) } } diff --git a/src/cargo/util/paths.rs b/src/cargo/util/paths.rs index 072968807..b08a589d4 100644 --- a/src/cargo/util/paths.rs +++ b/src/cargo/util/paths.rs @@ -132,8 +132,8 @@ pub fn append(path: &Path, contents: &[u8]) -> CargoResult<()> { } pub fn mtime(path: &Path) -> CargoResult { - let meta = fs::metadata(path) - .chain_err(|| internal(format!("failed to stat `{}`", path.display())))?; + let meta = + fs::metadata(path).chain_err(|| internal(format!("failed to stat `{}`", path.display())))?; Ok(FileTime::from_last_modification_time(&meta)) }