From: Dirkjan Ochtman Date: Sat, 14 Apr 2018 09:06:51 +0000 (+0200) Subject: Store BuildConfig directly in CompileOptions X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~10^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=08025169479b6976489f4e5f9defb73459e4ccbd;p=cargo.git Store BuildConfig directly in CompileOptions --- diff --git a/src/bin/cargo/command_prelude.rs b/src/bin/cargo/command_prelude.rs index fb1b907a4..3ef518e57 100644 --- a/src/bin/cargo/command_prelude.rs +++ b/src/bin/cargo/command_prelude.rs @@ -4,7 +4,7 @@ use std::fs; use clap::{self, SubCommand}; use cargo::CargoResult; use cargo::core::Workspace; -use cargo::core::compiler::MessageFormat; +use cargo::core::compiler::{BuildConfig, MessageFormat}; use cargo::ops::{CompileFilter, CompileOptions, NewOptions, Packages, VersionControl}; use cargo::util::paths; use cargo::util::important_paths::find_root_manifest_for_wd; @@ -272,16 +272,17 @@ pub trait ArgMatchesExt { } }; + let mut build_config = BuildConfig::new(config, self.jobs()?, &self.target(), mode)?; + build_config.message_format = message_format; + build_config.release = self._is_present("release"); + let opts = CompileOptions { config, - jobs: self.jobs()?, - target: self.target(), + build_config, features: self._values_of("features"), all_features: self._is_present("all-features"), no_default_features: self._is_present("no-default-features"), spec, - mode, - release: self._is_present("release"), filter: CompileFilter::new( self._is_present("lib"), self._values_of("bin"), @@ -294,7 +295,6 @@ pub trait ArgMatchesExt { self._is_present("benches"), self._is_present("all-targets"), ), - message_format, target_rustdoc_args: None, target_rustc_args: None, export_dir: None, diff --git a/src/bin/cargo/commands/bench.rs b/src/bin/cargo/commands/bench.rs index 69a237629..ea12a4575 100644 --- a/src/bin/cargo/commands/bench.rs +++ b/src/bin/cargo/commands/bench.rs @@ -73,7 +73,7 @@ Compilation can be customized with the `bench` profile in the manifest. pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { let ws = args.workspace(config)?; let mut compile_opts = args.compile_options(config, CompileMode::Bench)?; - compile_opts.release = true; + compile_opts.build_config.release = true; let ops = TestOptions { no_run: args.is_present("no-run"), diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 4ddd6af12..f0c65515d 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -73,7 +73,7 @@ continuous integration systems.", pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { let mut compile_opts = args.compile_options(config, CompileMode::Build)?; - compile_opts.release = !args.is_present("debug"); + compile_opts.build_config.release = !args.is_present("debug"); let krates = args.values_of("crate") .unwrap_or_default() diff --git a/src/bin/cargo/commands/test.rs b/src/bin/cargo/commands/test.rs index 6d7e1289a..f0c352bca 100644 --- a/src/bin/cargo/commands/test.rs +++ b/src/bin/cargo/commands/test.rs @@ -94,7 +94,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { let mut compile_opts = args.compile_options(config, CompileMode::Test)?; let doc = args.is_present("doc"); if doc { - compile_opts.mode = CompileMode::Doctest; + compile_opts.build_config.mode = CompileMode::Doctest; compile_opts.filter = ops::CompileFilter::new( true, Vec::new(), diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index e336105f1..e4d1377b7 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -2,6 +2,7 @@ use std::path::Path; use util::{CargoResult, CargoResultExt, Config}; /// Configuration information for a rustc build. +#[derive(Debug)] pub struct BuildConfig { /// The target arch triple, defaults to host arch pub requested_target: Option, diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 3d78a3d75..04f76dc23 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -27,7 +27,7 @@ use std::path::PathBuf; use std::sync::Arc; use core::compiler::{BuildConfig, BuildContext, Compilation, Context, DefaultExecutor, Executor}; -use core::compiler::{CompileMode, Kind, MessageFormat, Unit}; +use core::compiler::{CompileMode, Kind, Unit}; use core::profiles::{ProfileFor, Profiles}; use core::resolver::{Method, Resolve}; use core::{Package, Source, Target}; @@ -40,10 +40,8 @@ use util::{lev_distance, profile, CargoResult}; #[derive(Debug)] pub struct CompileOptions<'a> { pub config: &'a Config, - /// Number of concurrent jobs to use. - pub jobs: Option, - /// The target platform to compile for (example: `i686-unknown-linux-gnu`). - pub target: Option, + /// Configuration information for a rustc build + pub build_config: BuildConfig, /// Extra features to build for the root package pub features: Vec, /// Flag whether all available features should be built for the root package @@ -55,12 +53,6 @@ pub struct CompileOptions<'a> { /// Filter to apply to the root package to select which targets will be /// built. pub filter: CompileFilter, - /// Whether this is a release build or not - pub release: bool, - /// Mode for this compile. - pub mode: CompileMode, - /// `--error_format` flag for the compiler. - pub message_format: MessageFormat, /// Extra arguments to be passed to rustdoc (for main crate and dependencies) pub target_rustdoc_args: Option>, /// The specified target will be compiled with all the available arguments, @@ -75,25 +67,21 @@ pub struct CompileOptions<'a> { } impl<'a> CompileOptions<'a> { - pub fn default(config: &'a Config, mode: CompileMode) -> CompileOptions<'a> { - CompileOptions { + pub fn default(config: &'a Config, mode: CompileMode) -> CargoResult> { + Ok(CompileOptions { config, - jobs: None, - target: None, + build_config: BuildConfig::new(config, None, &None, mode)?, features: Vec::new(), all_features: false, no_default_features: false, spec: ops::Packages::Packages(Vec::new()), - mode, - release: false, filter: CompileFilter::Default { required_features_filterable: false, }, - message_format: MessageFormat::Human, target_rustdoc_args: None, target_rustc_args: None, export_dir: None, - } + }) } } @@ -214,24 +202,17 @@ pub fn compile_ws<'a>( ) -> CargoResult> { let CompileOptions { config, - jobs, - ref target, + ref build_config, ref spec, ref features, all_features, no_default_features, - release, - mode, - message_format, ref filter, ref target_rustdoc_args, ref target_rustc_args, ref export_dir, } = *options; - let mut build_config = BuildConfig::new(config, jobs, &target, mode)?; - build_config.release = release; - build_config.message_format = message_format; let default_arch_kind = if build_config.requested_target.is_some() { Kind::Target } else { @@ -241,7 +222,7 @@ pub fn compile_ws<'a>( let specs = spec.into_package_id_specs(ws)?; let features = Method::split_features(features); let method = Method::Required { - dev_deps: ws.require_optional_deps() || filter.need_dev_deps(mode), + dev_deps: ws.require_optional_deps() || filter.need_dev_deps(build_config.mode), features: &features, all_features, uses_default_features: !no_default_features, @@ -288,7 +269,7 @@ pub fn compile_ws<'a>( filter, default_arch_kind, &resolve_with_overrides, - &build_config, + build_config, )?; if let Some(args) = extra_args { diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index ed71ddc2a..ab3aa62ce 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -91,7 +91,7 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> { // nothing we can do about it and otherwise if it's getting overwritten // then that's also ok! let mut target_dir = ws.target_dir(); - if let Some(ref triple) = options.compile_opts.target { + if let Some(ref triple) = options.compile_opts.build_config.requested_target { target_dir.push(Path::new(triple).file_stem().unwrap()); } let path = target_dir.join("doc").join(&name).join("index.html"); diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index cf898b30c..f9de82868 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -10,7 +10,7 @@ use git2; use tar::{Archive, Builder, EntryType, Header}; use core::{Package, Source, SourceId, Workspace}; -use core::compiler::{CompileMode, DefaultExecutor, MessageFormat}; +use core::compiler::{BuildConfig, CompileMode, DefaultExecutor}; use sources::PathSource; use util::{self, internal, Config, FileLock}; use util::paths; @@ -337,8 +337,7 @@ fn run_verify(ws: &Workspace, tar: &FileLock, opts: &PackageOpts) -> CargoResult None, &ops::CompileOptions { config, - jobs: opts.jobs, - target: opts.target.clone(), + build_config: BuildConfig::new(config, opts.jobs, &opts.target, CompileMode::Build)?, features: Vec::new(), no_default_features: false, all_features: false, @@ -346,9 +345,6 @@ fn run_verify(ws: &Workspace, tar: &FileLock, opts: &PackageOpts) -> CargoResult filter: ops::CompileFilter::Default { required_features_filterable: true, }, - release: false, - message_format: MessageFormat::Human, - mode: CompileMode::Build, target_rustdoc_args: None, target_rustc_args: None, export_dir: None,