Update for some review comments.
authorEric Huss <eric@huss.org>
Thu, 19 Apr 2018 02:17:38 +0000 (19:17 -0700)
committerEric Huss <eric@huss.org>
Fri, 27 Apr 2018 20:42:29 +0000 (13:42 -0700)
src/cargo/core/compiler/context/mod.rs
src/cargo/core/compiler/fingerprint.rs
src/cargo/core/compiler/mod.rs
src/cargo/core/profiles.rs
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_compile.rs
src/cargo/util/toml/mod.rs
src/doc/src/reference/unstable.md
tests/testsuite/profiles.rs

index 284515814e49489730c33ac802193d979d83e43b..f231c13084a639b79dadcd1c546c595d69e2e104 100644 (file)
@@ -92,11 +92,12 @@ pub struct Context<'a, 'cfg: 'a> {
     pub used_in_plugin: HashSet<Unit<'a>>,
     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<Unit<'a>, Vec<String>>,
+    /// 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<String>)>,
 
     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<Unit<'a>, Vec<String>>,
+        extra_compiler_args: Option<(Unit<'a>, Vec<String>)>,
     ) -> CargoResult<Context<'a, 'cfg>> {
         let incremental_env = match env::var("CARGO_INCREMENTAL") {
             Ok(v) => Some(v == "1"),
index e00b1324c41250b5d9821df84c509bfb9da0afdf..35a7ca73169065c3e10857251c308add5c4c668e 100644 (file)
@@ -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) {
index f458864ddee29a9219120aa62541384031da2265..e4a6617091cb18677d6e5860c7c0845d3567dd74 100644 (file)
@@ -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,
index e7aa0c88349c808558d1aeca35701c1189ae696a..c76be468c276a9896363113d6c7831744e1760cd 100644 (file)
@@ -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<ProfileFor> {
-        vec![
+    pub fn all_values() -> &'static [ProfileFor] {
+        static ALL: [ProfileFor; 3] = [
             ProfileFor::Any,
             ProfileFor::CustomBuild,
             ProfileFor::TestDependency,
-        ]
+        ];
+        &ALL
     }
 }
index d3692d5cde422a9df9379eaa9deb10d065c4d21f..21e195212e82f425e8d8676002090e1fa93310c1 100644 (file)
@@ -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)?;
 
index 3c257aa51f8b3764ed6f815d11ab0d1971189477..6025b2932535a2e926cd809de950a80c1a4a3fb0 100644 (file)
@@ -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<CompileMode> {
-        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 = {
index c8ae4839dba1c11ba0ebf9a0a687d510783385c2..f101b952fc7a518e907a63d2c6a778e02eb84878 100644 (file)
@@ -381,7 +381,6 @@ pub struct TomlProfile {
     pub overflow_checks: Option<bool>,
     pub incremental: Option<bool>,
     pub overrides: Option<BTreeMap<String, TomlProfile>>,
-    #[serde(rename = "build_override")]
     pub build_override: Option<Box<TomlProfile>>,
 }
 
index bd8ccbdada5d4991df759d7ae4b22fb6ceb07959..483e5e2537ea7d72f1f6e6ae23644d4c50452811 100644 (file)
@@ -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
 ```
 
index 978efd79ce6794748d505a235ca9fc41922af4c1..528806856bd3daa33676339aeecfcb4c83e54b30 100644 (file)
@@ -353,7 +353,7 @@ fn profile_override_gated() {
             version = "0.0.1"
             authors = []
 
-            [profile.dev.build_override]
+            [profile.dev.build-override]
             opt-level = 3
         "#,
         )