From 7051b630c82994712db31d314287c39793351740 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 18 Apr 2018 19:17:38 -0700 Subject: [PATCH] Update for some review comments. --- src/cargo/core/compiler/context/mod.rs | 13 +++++++------ src/cargo/core/compiler/fingerprint.rs | 2 +- src/cargo/core/compiler/mod.rs | 12 ++++++++---- src/cargo/core/profiles.rs | 13 ++++++------- src/cargo/ops/cargo_clean.rs | 9 ++++----- src/cargo/ops/cargo_compile.rs | 13 +++++++------ src/cargo/util/toml/mod.rs | 1 - src/doc/src/reference/unstable.md | 6 +++--- tests/testsuite/profiles.rs | 2 +- 9 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index 284515814..f231c1308 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -92,11 +92,12 @@ pub struct Context<'a, 'cfg: 'a> { pub used_in_plugin: HashSet>, pub jobserver: Client, pub profiles: &'a Profiles, - /// This is a workaround to carry the extra compiler args given on the - /// command-line for `cargo rustc` and `cargo rustdoc`. These commands - /// only support one target, but we don't want the args passed to any - /// dependencies. - pub extra_compiler_args: HashMap, Vec>, + /// This is a workaround to carry the extra compiler args for either + /// `rustc` or `rustdoc` given on the command-line for the commands `cargo + /// rustc` and `cargo rustdoc`. These commands only support one target, + /// but we don't want the args passed to any dependencies, so we include + /// the `Unit` corresponding to the top-level target. + pub extra_compiler_args: Option<(Unit<'a>, Vec)>, target_info: TargetInfo, host_info: TargetInfo, @@ -114,7 +115,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { config: &'cfg Config, build_config: BuildConfig, profiles: &'a Profiles, - extra_compiler_args: HashMap, Vec>, + extra_compiler_args: Option<(Unit<'a>, Vec)>, ) -> CargoResult> { let incremental_env = match env::var("CARGO_INCREMENTAL") { Ok(v) => Some(v == "1"), diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index e00b1324c..35a7ca731 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -102,7 +102,7 @@ pub fn prepare_target<'a, 'cfg>( } } - let allow_failure = cx.extra_compiler_args.get(unit).is_some(); + let allow_failure = cx.extra_compiler_args.is_some(); let target_root = cx.files().target_root().to_path_buf(); let write_fingerprint = Work::new(move |_| { match fingerprint.update_local(&target_root) { diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index f458864dd..e4a661709 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -777,8 +777,10 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult rustdoc.arg(format!("--edition={}", &manifest.edition())); } - if let Some(args) = cx.extra_compiler_args.get(unit) { - rustdoc.args(args); + if let Some((ref args_unit, ref args)) = cx.extra_compiler_args { + if args_unit == unit { + rustdoc.args(args); + } } build_deps_args(&mut rustdoc, cx, unit)?; @@ -942,8 +944,10 @@ fn build_base_args<'a, 'cfg>( cmd.arg("-C").arg(format!("debuginfo={}", debuginfo)); } - if let Some(args) = cx.extra_compiler_args.get(unit) { - cmd.args(args); + if let Some((ref args_unit, ref args)) = cx.extra_compiler_args { + if args_unit == unit { + cmd.args(args); + } } // -C overflow-checks is implied by the setting of -C debug-assertions, diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index e7aa0c883..c76be468c 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -72,8 +72,6 @@ impl Profiles { // `build_unit_profiles` normally ensures that it selects the // ancestor's profile. However `cargo clean -p` can hit this // path. - // TODO: I think `cargo clean -p xxx` is not cleaning out - // the "OUT_DIR" directory. This is not a new bug. if release { &self.release } else { @@ -109,7 +107,7 @@ impl Profiles { /// The precedence of profiles are (first one wins): /// - [profile.dev.overrides.name] - A named package. /// - [profile.dev.overrides."*"] - This cannot apply to workspace members. -/// - [profile.dev.build_override] - This can only apply to `build.rs` scripts +/// - [profile.dev.build-override] - This can only apply to `build.rs` scripts /// and their dependencies. /// - [profile.dev] /// - Default (hard-coded) values. @@ -321,7 +319,7 @@ pub enum ProfileFor { /// A general-purpose target. Any, /// A target for `build.rs` or any of its dependencies. This enables - /// `build_override` profiles for these targets. + /// `build-override` profiles for these targets. CustomBuild, /// A target that is a dependency of a test or benchmark. Currently this /// enforces that the `panic` setting is not set. @@ -329,11 +327,12 @@ pub enum ProfileFor { } impl ProfileFor { - pub fn all_values() -> Vec { - vec![ + pub fn all_values() -> &'static [ProfileFor] { + static ALL: [ProfileFor; 3] = [ ProfileFor::Any, ProfileFor::CustomBuild, ProfileFor::TestDependency, - ] + ]; + &ALL } } diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index d3692d5cd..21e195212 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -1,6 +1,5 @@ use std::fs; use std::path::Path; -use std::collections::HashMap; use core::Workspace; use core::compiler::{BuildConfig, Context, Kind, Unit}; @@ -53,8 +52,8 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> { let profile = profiles.get_profile( &pkg.name(), ws.is_member(pkg), - profile_for, - mode, + *profile_for, + *mode, opts.release, ); units.push(Unit { @@ -62,7 +61,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> { target, profile, kind: *kind, - mode, + mode: *mode, }); } } @@ -79,7 +78,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> { opts.config, build_config, profiles, - HashMap::new(), + None, )?; cx.prepare_units(None, &units)?; diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 3c257aa51..6025b2932 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -22,7 +22,7 @@ //! previously compiled dependency //! -use std::collections::{HashMap, HashSet}; +use std::collections::HashSet; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -162,8 +162,8 @@ impl CompileMode { /// List of all modes (currently used by `cargo clean -p` for computing /// all possible outputs). - pub fn all_modes() -> Vec { - vec![ + pub fn all_modes() -> &'static [CompileMode] { + static ALL: [CompileMode; 9] = [ CompileMode::Test, CompileMode::Build, CompileMode::Check { test: true }, @@ -173,7 +173,8 @@ impl CompileMode { CompileMode::Doc { deps: false }, CompileMode::Doctest, CompileMode::RunCustomBuild, - ] + ]; + &ALL } } @@ -381,7 +382,7 @@ pub fn compile_ws<'a>( } let profiles = ws.profiles(); - let mut extra_compiler_args = HashMap::new(); + let mut extra_compiler_args = None; let units = generate_targets( ws, @@ -403,7 +404,7 @@ pub fn compile_ws<'a>( extra_args_name ); } - extra_compiler_args.insert(units[0], args); + extra_compiler_args = Some((units[0], args)); } let mut ret = { diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index c8ae4839d..f101b952f 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -381,7 +381,6 @@ pub struct TomlProfile { pub overflow_checks: Option, pub incremental: Option, pub overrides: Option>, - #[serde(rename = "build_override")] pub build_override: Option>, } diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index bd8ccbdad..483e5e253 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -215,14 +215,14 @@ debug = true [profile.dev.overrides.image] opt-level = 3 -# All dependencies (but not this crate itself) will be compiled -# with -Copt-level=2 . This includes build dependencies. +# All dependencies (but not this crate itself or any workspace member) +# will be compiled with -Copt-level=2 . This includes build dependencies. [profile.dev.overrides."*"] opt-level = 2 # Build scripts and their dependencies will be compiled with -Copt-level=3 # By default, build scripts use the same rules as the rest of the profile -[profile.dev.build_override] +[profile.dev.build-override] opt-level = 3 ``` diff --git a/tests/testsuite/profiles.rs b/tests/testsuite/profiles.rs index 978efd79c..528806856 100644 --- a/tests/testsuite/profiles.rs +++ b/tests/testsuite/profiles.rs @@ -353,7 +353,7 @@ fn profile_override_gated() { version = "0.0.1" authors = [] - [profile.dev.build_override] + [profile.dev.build-override] opt-level = 3 "#, ) -- 2.30.2