Hide BuildConfig.host_triple behind a getter
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 14 Apr 2018 08:54:33 +0000 (11:54 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 14 Apr 2018 08:54:33 +0000 (11:54 +0300)
src/cargo/core/compiler/context/mod.rs
src/cargo/core/compiler/custom_build.rs
src/cargo/core/compiler/mod.rs
src/cargo/util/paths.rs

index f5f279a2d94a44039bcd9fe39be95c255827d7ed..1620aad4a129824e5e15a342dd352fcb944827f4 100644 (file)
@@ -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();
index 578e2312cb4dba736c6fe04bddb89e582f837982..a219ddab5cd51f7f34459514f52d7f40aff2ae90 100644 (file)
@@ -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);
index f626637c74ec6938645dadae3a021c8ab66b7383..7f9c503b960b9b5cab443e84723f26d9c49b4112 100644 (file)
@@ -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())
     }
 }
 
index 07296880719ee1c556e4d94d247f92a119d6faf4..b08a589d4b521316570579a04155559cf54dbda3 100644 (file)
@@ -132,8 +132,8 @@ pub fn append(path: &Path, contents: &[u8]) -> CargoResult<()> {
 }
 
 pub fn mtime(path: &Path) -> CargoResult<FileTime> {
-    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))
 }