Initialize Compilation fields directly from BuildContext
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Thu, 3 May 2018 08:08:16 +0000 (10:08 +0200)
committerDirkjan Ochtman <dirkjan@ochtman.nl>
Thu, 3 May 2018 19:54:49 +0000 (21:54 +0200)
src/cargo/core/compiler/compilation.rs
src/cargo/core/compiler/context/mod.rs

index ece186c9dc13441d24333ec2d342ace60b85f1b4..6137b94eb32faa78678db4ad939c73f4ae3358a3 100644 (file)
@@ -7,6 +7,7 @@ use lazycell::LazyCell;
 
 use core::{Package, PackageId, Target, TargetKind};
 use util::{self, join_paths, process, CargoResult, Config, ProcessBuilder};
+use super::BuildContext;
 
 /// A structure returning the result of a compilation.
 pub struct Compilation<'cfg> {
@@ -67,25 +68,25 @@ pub struct Compilation<'cfg> {
 }
 
 impl<'cfg> Compilation<'cfg> {
-    pub fn new(config: &'cfg Config, rustc_process: ProcessBuilder) -> Compilation<'cfg> {
+    pub fn new<'a>(bcx: &BuildContext<'a, 'cfg>) -> Compilation<'cfg> {
         Compilation {
             libraries: HashMap::new(),
             native_dirs: BTreeSet::new(), // TODO: deprecated, remove
             root_output: PathBuf::from("/"),
             deps_output: PathBuf::from("/"),
             host_deps_output: PathBuf::from("/"),
-            host_dylib_path: None,
-            target_dylib_path: None,
+            host_dylib_path: bcx.host_info.sysroot_libdir.clone(),
+            target_dylib_path: bcx.target_info.sysroot_libdir.clone(),
             tests: Vec::new(),
             binaries: Vec::new(),
             extra_env: HashMap::new(),
             to_doc_test: Vec::new(),
             cfgs: HashMap::new(),
             rustdocflags: HashMap::new(),
-            config,
-            rustc_process,
-            host: String::new(),
-            target: String::new(),
+            config: bcx.config,
+            rustc_process: bcx.build_config.rustc.process(),
+            host: bcx.build_config.host_triple().to_string(),
+            target: bcx.build_config.target_triple().to_string(),
             target_runner: LazyCell::new(),
         }
     }
index c106a04685355dc6324f62ca02d760a389b16587..907ccdf06bce19794f50114dae8ff5bcbc22461c 100644 (file)
@@ -94,12 +94,9 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                 .chain_err(|| "failed to create jobserver")?,
         };
 
-        let mut compilation = Compilation::new(config, bcx.build_config.rustc.process());
-        compilation.host_dylib_path = bcx.host_info.sysroot_libdir.clone();
-        compilation.target_dylib_path = bcx.target_info.sysroot_libdir.clone();
         Ok(Self {
             bcx,
-            compilation,
+            compilation: Compilation::new(bcx),
             build_state: Arc::new(BuildState::new(
                 &bcx.build_config.host,
                 &bcx.build_config.target,
@@ -247,8 +244,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                 self.compilation.native_dirs.insert(dir.clone());
             }
         }
-        self.compilation.host = self.bcx.build_config.host_triple().to_string();
-        self.compilation.target = self.bcx.build_config.target_triple().to_string();
         Ok(self.compilation)
     }