From: Dirkjan Ochtman Date: Thu, 12 Apr 2018 13:58:12 +0000 (+0200) Subject: Move creation of TargetConfig 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~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=035377a793be8075354ecc9d21dd3176ac14ea45;p=cargo.git Move creation of TargetConfig into new() method --- diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 47c1237a1..cc527bc3c 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -12,7 +12,7 @@ use serde_json; use core::{Feature, PackageId, Profile, Target}; use core::manifest::Lto; use core::shell::ColorChoice; -use util::{self, machine_message, ProcessBuilder}; +use util::{self, machine_message, Config, ProcessBuilder}; use util::{internal, join_paths, profile}; use util::paths; use util::errors::{CargoResult, CargoResultExt, Internal}; @@ -102,6 +102,86 @@ pub struct TargetConfig { pub overrides: HashMap, } +impl TargetConfig { + pub fn new(config: &Config, triple: &str) -> CargoResult { + let key = format!("target.{}", triple); + let mut ret = TargetConfig { + ar: config.get_path(&format!("{}.ar", key))?.map(|v| v.val), + linker: config.get_path(&format!("{}.linker", key))?.map(|v| v.val), + overrides: HashMap::new(), + }; + let table = match config.get_table(&key)? { + Some(table) => table.val, + None => return Ok(ret), + }; + for (lib_name, value) in table { + match lib_name.as_str() { + "ar" | "linker" | "runner" | "rustflags" => continue, + _ => {} + } + + let mut output = BuildOutput { + library_paths: Vec::new(), + library_links: Vec::new(), + cfgs: Vec::new(), + env: Vec::new(), + metadata: Vec::new(), + rerun_if_changed: Vec::new(), + rerun_if_env_changed: Vec::new(), + warnings: Vec::new(), + }; + // We require deterministic order of evaluation, so we must sort the pairs by key first. + let mut pairs = Vec::new(); + for (k, value) in value.table(&lib_name)?.0 { + pairs.push((k, value)); + } + pairs.sort_by_key(|p| p.0); + for (k, value) in pairs { + let key = format!("{}.{}", key, k); + match &k[..] { + "rustc-flags" => { + let (flags, definition) = value.string(k)?; + let whence = format!("in `{}` (in {})", key, definition.display()); + let (paths, links) = BuildOutput::parse_rustc_flags(flags, &whence)?; + output.library_paths.extend(paths); + output.library_links.extend(links); + } + "rustc-link-lib" => { + let list = value.list(k)?; + output + .library_links + .extend(list.iter().map(|v| v.0.clone())); + } + "rustc-link-search" => { + let list = value.list(k)?; + output + .library_paths + .extend(list.iter().map(|v| PathBuf::from(&v.0))); + } + "rustc-cfg" => { + let list = value.list(k)?; + output.cfgs.extend(list.iter().map(|v| v.0.clone())); + } + "rustc-env" => for (name, val) in value.table(k)?.0 { + let val = val.string(name)?.0; + output.env.push((name.clone(), val.to_string())); + }, + "warning" | "rerun-if-changed" | "rerun-if-env-changed" => { + bail!("`{}` is not supported in build script overrides", k); + } + _ => { + let val = value.string(k)?.0; + output.metadata.push((k.clone(), val.to_string())); + } + } + } + ret.overrides.insert(lib_name, output); + } + + Ok(ret) + } +} + /// A glorified callback for executing calls to rustc. Rather than calling rustc /// directly, we'll use an Executor, giving clients an opportunity to intercept /// the build calls. diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 8a2d75980..6745fa490 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -22,13 +22,13 @@ //! previously compiled dependency //! -use std::collections::{HashMap, HashSet}; +use std::collections::HashSet; use std::path::{Path, PathBuf}; use std::sync::Arc; use core::{Package, Source, Target}; use core::{PackageId, PackageIdSpec, Profile, Profiles, TargetKind, Workspace}; -use core::compiler::{BuildConfig, BuildOutput, Compilation, Context, DefaultExecutor, Executor}; +use core::compiler::{BuildConfig, Compilation, Context, DefaultExecutor, Executor}; use core::compiler::{Kind, TargetConfig, Unit}; use core::resolver::{Method, Resolve}; use ops; @@ -879,88 +879,10 @@ fn scrape_build_config( let target = target.or(cfg_target); let mut base = BuildConfig::new(&config.rustc()?.host, &target)?; base.jobs = jobs; - base.host = scrape_target_config(config, &base.host_triple)?; + base.host = TargetConfig::new(config, &base.host_triple)?; base.target = match target.as_ref() { - Some(triple) => scrape_target_config(config, triple)?, + Some(triple) => TargetConfig::new(config, triple)?, None => base.host.clone(), }; Ok(base) } - -fn scrape_target_config(config: &Config, triple: &str) -> CargoResult { - let key = format!("target.{}", triple); - let mut ret = TargetConfig { - ar: config.get_path(&format!("{}.ar", key))?.map(|v| v.val), - linker: config.get_path(&format!("{}.linker", key))?.map(|v| v.val), - overrides: HashMap::new(), - }; - let table = match config.get_table(&key)? { - Some(table) => table.val, - None => return Ok(ret), - }; - for (lib_name, value) in table { - match lib_name.as_str() { - "ar" | "linker" | "runner" | "rustflags" => continue, - _ => {} - } - - let mut output = BuildOutput { - library_paths: Vec::new(), - library_links: Vec::new(), - cfgs: Vec::new(), - env: Vec::new(), - metadata: Vec::new(), - rerun_if_changed: Vec::new(), - rerun_if_env_changed: Vec::new(), - warnings: Vec::new(), - }; - // We require deterministic order of evaluation, so we must sort the pairs by key first. - let mut pairs = Vec::new(); - for (k, value) in value.table(&lib_name)?.0 { - pairs.push((k, value)); - } - pairs.sort_by_key(|p| p.0); - for (k, value) in pairs { - let key = format!("{}.{}", key, k); - match &k[..] { - "rustc-flags" => { - let (flags, definition) = value.string(k)?; - let whence = format!("in `{}` (in {})", key, definition.display()); - let (paths, links) = BuildOutput::parse_rustc_flags(flags, &whence)?; - output.library_paths.extend(paths); - output.library_links.extend(links); - } - "rustc-link-lib" => { - let list = value.list(k)?; - output - .library_links - .extend(list.iter().map(|v| v.0.clone())); - } - "rustc-link-search" => { - let list = value.list(k)?; - output - .library_paths - .extend(list.iter().map(|v| PathBuf::from(&v.0))); - } - "rustc-cfg" => { - let list = value.list(k)?; - output.cfgs.extend(list.iter().map(|v| v.0.clone())); - } - "rustc-env" => for (name, val) in value.table(k)?.0 { - let val = val.string(name)?.0; - output.env.push((name.clone(), val.to_string())); - }, - "warning" | "rerun-if-changed" | "rerun-if-env-changed" => { - bail!("`{}` is not supported in build script overrides", k); - } - _ => { - let val = value.string(k)?.0; - output.metadata.push((k.clone(), val.to_string())); - } - } - } - ret.overrides.insert(lib_name, output); - } - - Ok(ret) -}