Remove target_triple() method from Context
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Fri, 13 Apr 2018 17:54:05 +0000 (19:54 +0200)
committerDirkjan Ochtman <dirkjan@ochtman.nl>
Fri, 13 Apr 2018 18:03:20 +0000 (20:03 +0200)
Favor accessing cx.build_config directly.

src/cargo/core/compiler/context/compilation_files.rs
src/cargo/core/compiler/context/mod.rs
src/cargo/core/compiler/context/target_info.rs
src/cargo/core/compiler/custom_build.rs
src/cargo/core/compiler/mod.rs

index 95b5f638671f3b0b60a71e00ffcc9d339e355f38..da49868c3de3f8b011fb21c0c3aadeec4947414f 100644 (file)
@@ -265,7 +265,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
                         crate_type,
                         flavor,
                         unit.target.kind(),
-                        cx.target_triple(),
+                        cx.build_config.target_triple(),
                     )?;
 
                     match file_types {
@@ -321,14 +321,14 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
                      does not support these crate types",
                     unsupported.join(", "),
                     unit.pkg,
-                    cx.target_triple()
+                    cx.build_config.target_triple()
                 )
             }
             bail!(
                 "cannot compile `{}` as the target `{}` does not \
                  support any of the output crate types",
                 unit.pkg,
-                cx.target_triple()
+                cx.build_config.target_triple()
             );
         }
         info!("Target filenames: {:?}", ret);
@@ -380,7 +380,7 @@ fn compute_metadata<'a, 'cfg>(
     let __cargo_default_lib_metadata = env::var("__CARGO_DEFAULT_LIB_METADATA");
     if !(unit.profile.test || unit.profile.check)
         && (unit.target.is_dylib() || unit.target.is_cdylib()
-            || (unit.target.is_bin() && cx.target_triple().starts_with("wasm32-")))
+            || (unit.target.is_bin() && cx.build_config.target_triple().starts_with("wasm32-")))
         && unit.pkg.package_id().source_id().is_path()
         && __cargo_default_lib_metadata.is_err()
     {
index db78623a3ee47cf467c4ba6ffc52045febc2a7fe..33dbb01a1f8d8e43a53d753f523b8cadae4a3211 100644 (file)
@@ -283,7 +283,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                 self.compilation.native_dirs.insert(dir.clone());
             }
         }
-        self.compilation.target = self.target_triple().to_string();
+        self.compilation.target = self.build_config.target_triple().to_string();
         Ok(self.compilation)
     }
 
@@ -401,15 +401,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         self.files.as_mut().unwrap()
     }
 
-    /// Return the target triple which this context is targeting.
-    pub fn target_triple(&self) -> &str {
-        self.build_config
-            .requested_target
-            .as_ref()
-            .map(|s| &s[..])
-            .unwrap_or_else(|| &self.build_config.host_triple)
-    }
-
     /// Return the filenames that the given target for the given profile will
     /// generate as a list of 3-tuples (filename, link_dst, linkable)
     ///
@@ -452,7 +443,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         };
         let (name, info) = match kind {
             Kind::Host => (self.build_config.host_triple.as_ref(), &self.host_info),
-            Kind::Target => (self.target_triple(), &self.target_info),
+            Kind::Target => (self.build_config.target_triple(), &self.target_info),
         };
         platform.matches(name, info.cfg())
     }
index 82d759692fad5ce9200b412627b2605373cca595..c22ab42324472bf7bc14b492eff9df4837c52079 100644 (file)
@@ -63,7 +63,7 @@ impl TargetInfo {
             .env_remove("RUST_LOG");
 
         if kind == Kind::Target {
-            process.arg("--target").arg(&cx.target_triple());
+            process.arg("--target").arg(&cx.build_config.target_triple());
         }
 
         let crate_type_process = process.clone();
@@ -115,7 +115,7 @@ impl TargetInfo {
             } else {
                 rustlib.push("lib");
                 rustlib.push("rustlib");
-                rustlib.push(cx.target_triple());
+                rustlib.push(cx.build_config.target_triple());
                 rustlib.push("lib");
                 sysroot_libdir = Some(rustlib);
             }
index 35d9e79bc899cab6502f15e65271e6c45883d1dd..3c94e1e002853382ab013570a558194877b6334c 100644 (file)
@@ -128,7 +128,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
             "TARGET",
             &match unit.kind {
                 Kind::Host => &cx.build_config.host_triple,
-                Kind::Target => cx.target_triple(),
+                Kind::Target => cx.build_config.target_triple(),
             },
         )
         .env("DEBUG", &profile.debuginfo.is_some().to_string())
index ce4cdf2acfe00e581f75018c070ef2559fcfc5e2..cc2dc5f11b2aebb4756f64c5a5e1ccf59489058a 100644 (file)
@@ -89,6 +89,12 @@ impl BuildConfig {
             ..Default::default()
         })
     }
+
+    pub fn target_triple(&self) -> &str {
+        self.requested_target
+            .as_ref()
+            .unwrap_or_else(|| &self.host_triple)
+    }
 }
 
 /// Information required to build for a target