Initialize BuildConfig in a single place
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Wed, 11 Apr 2018 21:55:01 +0000 (23:55 +0200)
committerDirkjan Ochtman <dirkjan@ochtman.nl>
Wed, 11 Apr 2018 22:06:48 +0000 (00:06 +0200)
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_rustc/mod.rs

index 48b61dd0904ddfd95c9e30a28c231973fcfa4959..035999de2f1931708af6e585c5a68679571ccffe 100644 (file)
@@ -1,4 +1,3 @@
-use std::default::Default;
 use std::fs;
 use std::path::Path;
 
@@ -84,18 +83,14 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
         }
     }
 
+    let mut build_config = BuildConfig::new(&opts.config.rustc()?.host, &opts.target);
+    build_config.release = opts.release;
     let mut cx = Context::new(
         ws,
         &resolve,
         &packages,
         opts.config,
-        BuildConfig {
-            host_triple: opts.config.rustc()?.host.clone(),
-            requested_target: opts.target.clone(),
-            release: opts.release,
-            jobs: 1,
-            ..BuildConfig::default()
-        },
+        build_config,
         profiles,
         None,
         &units,
index 63372b2792897b9bd342f5437ff90b71be6a1b9a..83a303b065a23b77547d368cf448c3c5ffda7c25 100644 (file)
@@ -23,7 +23,6 @@
 //!
 
 use std::collections::{HashMap, HashSet};
-use std::default::Default;
 use std::path::{Path, PathBuf};
 use std::sync::Arc;
 
@@ -858,12 +857,8 @@ fn scrape_build_config(
     let jobs = jobs.or(cfg_jobs).unwrap_or(::num_cpus::get() as u32);
     let cfg_target = config.get_string("build.target")?.map(|s| s.val);
     let target = target.or(cfg_target);
-    let mut base = ops::BuildConfig {
-        host_triple: config.rustc()?.host.clone(),
-        requested_target: target.clone(),
-        jobs,
-        ..Default::default()
-    };
+    let mut base = ops::BuildConfig::new(&config.rustc()?.host, &target);
+    base.jobs = jobs;
     base.host = scrape_target_config(config, &base.host_triple)?;
     base.target = match target.as_ref() {
         Some(triple) => scrape_target_config(config, triple)?,
index c742f04f98d7753a7dd461cc3266de408a54db47..6e47859821dea6da3379a284c9cdb0f00bbd70fc 100644 (file)
@@ -76,6 +76,17 @@ pub struct BuildConfig {
     pub json_messages: bool,
 }
 
+impl BuildConfig {
+    pub fn new(host_triple: &str, requested_target: &Option<String>) -> BuildConfig {
+        BuildConfig {
+            host_triple: host_triple.to_string(),
+            requested_target: (*requested_target).clone(),
+            jobs: 1,
+            ..Default::default()
+        }
+    }
+}
+
 /// Information required to build for a target
 #[derive(Clone, Default)]
 pub struct TargetConfig {