Make TargetInfo.cfg private
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 2 Apr 2018 20:51:48 +0000 (23:51 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 2 Apr 2018 20:52:49 +0000 (23:52 +0300)
src/cargo/ops/cargo_rustc/context/mod.rs
src/cargo/ops/cargo_rustc/context/target_info.rs

index f54b8015f0c7f1d3585f2d7552bacba176850172..36857b1a708a8e59b4a6934755b6f95c8be24256 100644 (file)
@@ -315,7 +315,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             Kind::Host => (self.host_triple(), &self.host_info),
             Kind::Target => (self.target_triple(), &self.target_info),
         };
-        platform.matches(name, info.cfg.as_ref().map(|cfg| &cfg[..]))
+        platform.matches(name, info.cfg())
     }
 
     /// Gets a package for the given package id.
@@ -339,7 +339,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             Kind::Host => &self.host_info,
             Kind::Target => &self.target_info,
         };
-        info.cfg.as_ref().map(|s| &s[..]).unwrap_or(&[])
+        info.cfg().unwrap_or(&[])
     }
 
     /// Get the target configuration for a particular host or target
@@ -425,7 +425,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         env_args(
             self.config,
             &self.build_config,
-            self.info(&unit.kind),
+            self.info(&unit.kind).cfg(),
             unit.kind,
             "RUSTFLAGS",
         )
@@ -435,7 +435,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         env_args(
             self.config,
             &self.build_config,
-            self.info(&unit.kind),
+            self.info(&unit.kind).cfg(),
             unit.kind,
             "RUSTDOCFLAGS",
         )
@@ -473,7 +473,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
 fn env_args(
     config: &Config,
     build_config: &BuildConfig,
-    target_info: &TargetInfo,
+    target_cfg: Option<&[Cfg]>,
     kind: Kind,
     name: &str,
 ) -> CargoResult<Vec<String>> {
@@ -531,7 +531,7 @@ fn env_args(
         rustflags.extend(args);
     }
     // ...including target.'cfg(...)'.rustflags
-    if let Some(ref target_cfg) = target_info.cfg {
+    if let Some(target_cfg) = target_cfg {
         if let Some(table) = config.get_table("target")? {
             let cfgs = table.val.keys().filter_map(|t| {
                 if t.starts_with("cfg(") && t.ends_with(')') {
index 17f3ac7e67232d1c0f07e38e15687010ee57e9d0..1514ab28f0f49c752e8f679306a7f5c1a8aef3dc 100644 (file)
@@ -12,8 +12,8 @@ use ops::Kind;
 pub struct TargetInfo {
     crate_type_process: Option<ProcessBuilder>,
     crate_types: RefCell<HashMap<String, Option<(String, String)>>>,
-    pub(super) cfg: Option<Vec<Cfg>>,
-    pub(super) sysroot_libdir: Option<PathBuf>,
+    cfg: Option<Vec<Cfg>>,
+    pub sysroot_libdir: Option<PathBuf>,
 }
 
 /// Type of each file generated by a Unit.
@@ -36,13 +36,7 @@ pub struct FileType {
 
 impl TargetInfo {
     pub fn new(cx: &Context, kind: Kind) -> CargoResult<TargetInfo> {
-        let rustflags = env_args(
-            cx.config,
-            &cx.build_config,
-            cx.info(&kind),
-            kind,
-            "RUSTFLAGS",
-        )?;
+        let rustflags = env_args(cx.config, &cx.build_config, None, kind, "RUSTFLAGS")?;
         let mut process = cx.config.rustc()?.process();
         process
             .arg("-")
@@ -125,6 +119,10 @@ impl TargetInfo {
         })
     }
 
+    pub fn cfg(&self) -> Option<&[Cfg]> {
+        self.cfg.as_ref().map(|v| v.as_ref())
+    }
+
     pub fn file_types(
         &self,
         crate_type: &str,