From: Dirkjan Ochtman Date: Thu, 12 Apr 2018 14:12:14 +0000 (+0200) Subject: Move BuildConfig initialization into new() method X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~73^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=185665bd20fafb1ace60b2eecc10966867ea5a12;p=cargo.git Move BuildConfig initialization into new() method --- diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index cc527bc3c..0c650083a 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -76,16 +76,68 @@ pub struct BuildConfig { } impl BuildConfig { - pub fn new(host_triple: &str, requested_target: &Option) -> CargoResult { - if let Some(ref s) = *requested_target { + /// Parse all config files to learn about build configuration. Currently + /// configured options are: + /// + /// * build.jobs + /// * build.target + /// * target.$target.ar + /// * target.$target.linker + /// * target.$target.libfoo.metadata + pub fn new( + config: &Config, + jobs: Option, + requested_target: &Option, + ) -> CargoResult { + if let &Some(ref s) = requested_target { if s.trim().is_empty() { bail!("target was empty") } } + let cfg_target = config.get_string("build.target")?.map(|s| s.val); + let target = requested_target.clone().or(cfg_target); + + if jobs.is_some() && config.jobserver_from_env().is_some() { + config.shell().warn( + "a `-j` argument was passed to Cargo but Cargo is \ + also configured with an external jobserver in \ + its environment, ignoring the `-j` parameter", + )?; + } + let cfg_jobs = match config.get_i64("build.jobs")? { + Some(v) => { + if v.val <= 0 { + bail!( + "build.jobs must be positive, but found {} in {}", + v.val, + v.definition + ) + } else if v.val >= i64::from(u32::max_value()) { + bail!( + "build.jobs is too large: found {} in {}", + v.val, + v.definition + ) + } else { + Some(v.val as u32) + } + } + None => None, + }; + let jobs = jobs.or(cfg_jobs).unwrap_or(::num_cpus::get() as u32); + + let host_triple = config.rustc()?.host.clone(); + let host_config = TargetConfig::new(config, &host_triple)?; + let target_config = match target.as_ref() { + Some(triple) => TargetConfig::new(config, triple)?, + None => host_config.clone(), + }; Ok(BuildConfig { - host_triple: host_triple.to_string(), - requested_target: (*requested_target).clone(), - jobs: 1, + host_triple, + requested_target: target, + jobs, + host: host_config, + target: target_config, ..Default::default() }) } diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 0cab1d972..43a89ea64 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -84,7 +84,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> { } } - let mut build_config = BuildConfig::new(&opts.config.rustc()?.host, &opts.target)?; + let mut build_config = BuildConfig::new(config, Some(1), &opts.target)?; build_config.release = opts.release; let mut cx = Context::new(ws, &resolve, &packages, opts.config, build_config, profiles)?; cx.prepare_units(None, &units)?; diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 6745fa490..e734c4cb8 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -29,7 +29,7 @@ use std::sync::Arc; use core::{Package, Source, Target}; use core::{PackageId, PackageIdSpec, Profile, Profiles, TargetKind, Workspace}; use core::compiler::{BuildConfig, Compilation, Context, DefaultExecutor, Executor}; -use core::compiler::{Kind, TargetConfig, Unit}; +use core::compiler::{Kind, Unit}; use core::resolver::{Method, Resolve}; use ops; use util::config::Config; @@ -260,7 +260,7 @@ pub fn compile_ws<'a>( bail!("jobs must be at least 1") } - let mut build_config = scrape_build_config(config, jobs, target)?; + let mut build_config = BuildConfig::new(config, jobs, &target)?; build_config.release = release; build_config.test = mode == CompileMode::Test || mode == CompileMode::Bench; build_config.json_messages = message_format == MessageFormat::Json; @@ -833,56 +833,3 @@ fn generate_targets<'a>( filter_compatible_targets(targets, features) } - -/// Parse all config files to learn about build configuration. Currently -/// configured options are: -/// -/// * build.jobs -/// * build.target -/// * target.$target.ar -/// * target.$target.linker -/// * target.$target.libfoo.metadata -fn scrape_build_config( - config: &Config, - jobs: Option, - target: Option, -) -> CargoResult { - if jobs.is_some() && config.jobserver_from_env().is_some() { - config.shell().warn( - "a `-j` argument was passed to Cargo but Cargo is \ - also configured with an external jobserver in \ - its environment, ignoring the `-j` parameter", - )?; - } - let cfg_jobs = match config.get_i64("build.jobs")? { - Some(v) => { - if v.val <= 0 { - bail!( - "build.jobs must be positive, but found {} in {}", - v.val, - v.definition - ) - } else if v.val >= i64::from(u32::max_value()) { - bail!( - "build.jobs is too large: found {} in {}", - v.val, - v.definition - ) - } else { - Some(v.val as u32) - } - } - None => None, - }; - 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 = BuildConfig::new(&config.rustc()?.host, &target)?; - base.jobs = jobs; - base.host = TargetConfig::new(config, &base.host_triple)?; - base.target = match target.as_ref() { - Some(triple) => TargetConfig::new(config, triple)?, - None => base.host.clone(), - }; - Ok(base) -}