From 86c459d423924eb99ae97b4e5f739013f1bc7818 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Mon, 9 Apr 2018 23:09:11 +0300 Subject: [PATCH 01/58] Support for named Cargo profiles This allows creating custom profiles that inherit from other profiles. For example, one can have a release-lto profile that looks like this: [profile.release-lto] inherits = "release" lto = true The profile name will also carry itself into the output directory name so that the different build outputs can be cached independently from one another. So in effect, at the `target` directory, a name will be created for the new profile, in addition to the 'debug' and 'release' builds: ``` $ cargo build --profile release-lto $ ls -l target debug release release-lto ``` --- src/bin/cargo/commands/bench.rs | 3 +- src/bin/cargo/commands/build.rs | 1 + src/bin/cargo/commands/check.rs | 2 +- src/bin/cargo/commands/clean.rs | 3 +- src/bin/cargo/commands/clippy.rs | 1 + src/bin/cargo/commands/doc.rs | 1 + src/bin/cargo/commands/fix.rs | 2 +- src/bin/cargo/commands/install.rs | 2 +- src/bin/cargo/commands/run.rs | 1 + src/bin/cargo/commands/rustc.rs | 2 +- src/bin/cargo/commands/rustdoc.rs | 1 + src/bin/cargo/commands/test.rs | 1 + src/cargo/core/compiler/build_config.rs | 27 +- src/cargo/core/compiler/context/mod.rs | 11 +- .../compiler/context/unit_dependencies.rs | 2 +- src/cargo/core/compiler/custom_build.rs | 9 +- src/cargo/core/compiler/job_queue.rs | 9 +- src/cargo/core/compiler/mod.rs | 2 +- src/cargo/core/profiles.rs | 270 ++++++++++++------ src/cargo/ops/cargo_clean.rs | 16 +- src/cargo/ops/cargo_compile.rs | 4 +- .../ops/common_for_install_and_uninstall.rs | 14 +- src/cargo/util/command_prelude.rs | 39 ++- src/cargo/util/toml/mod.rs | 88 ++++-- 24 files changed, 347 insertions(+), 164 deletions(-) diff --git a/src/bin/cargo/commands/bench.rs b/src/bin/cargo/commands/bench.rs index e4d9959f075..04305cf15aa 100644 --- a/src/bin/cargo/commands/bench.rs +++ b/src/bin/cargo/commands/bench.rs @@ -75,7 +75,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let ws = args.workspace(config)?; let mut compile_opts = args.compile_options(config, CompileMode::Bench, Some(&ws))?; - compile_opts.build_config.release = true; + compile_opts.build_config.profile_kind = + args.get_profile_kind(ProfileKind::Custom("bench".to_owned()))?; let ops = TestOptions { no_run: args.is_present("no-run"), diff --git a/src/bin/cargo/commands/build.rs b/src/bin/cargo/commands/build.rs index ba83b7c1f02..cb615ae4169 100644 --- a/src/bin/cargo/commands/build.rs +++ b/src/bin/cargo/commands/build.rs @@ -27,6 +27,7 @@ pub fn cli() -> App { "Build all targets", ) .arg_release("Build artifacts in release mode, with optimizations") + .arg_profile("Build artifacts with the specified profile") .arg_features() .arg_target_triple("Build for the target triple") .arg_target_dir() diff --git a/src/bin/cargo/commands/check.rs b/src/bin/cargo/commands/check.rs index d0d5c6215bd..095b69a996e 100644 --- a/src/bin/cargo/commands/check.rs +++ b/src/bin/cargo/commands/check.rs @@ -27,7 +27,7 @@ pub fn cli() -> App { "Check all targets", ) .arg_release("Check artifacts in release mode, with optimizations") - .arg(opt("profile", "Profile to build the selected target for").value_name("PROFILE")) + .arg_profile("Check artifacts with the specified profile") .arg_features() .arg_target_triple("Check for the target triple") .arg_target_dir() diff --git a/src/bin/cargo/commands/clean.rs b/src/bin/cargo/commands/clean.rs index e336f73a031..1a180da7636 100644 --- a/src/bin/cargo/commands/clean.rs +++ b/src/bin/cargo/commands/clean.rs @@ -11,6 +11,7 @@ pub fn cli() -> App { .arg_target_triple("Target triple to clean output for") .arg_target_dir() .arg_release("Whether or not to clean release artifacts") + .arg_profile("Clean artifacts of the specified profile") .arg_doc("Whether or not to clean just the documentation directory") .after_help( "\ @@ -28,7 +29,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { config, spec: values(args, "package"), target: args.target(), - release: args.is_present("release"), + profile_kind: args.get_profile_kind(ProfileKind::Dev)?, doc: args.is_present("doc"), }; ops::clean(&ws, &opts)?; diff --git a/src/bin/cargo/commands/clippy.rs b/src/bin/cargo/commands/clippy.rs index 44054ae9c37..ba2cf599057 100644 --- a/src/bin/cargo/commands/clippy.rs +++ b/src/bin/cargo/commands/clippy.rs @@ -25,6 +25,7 @@ pub fn cli() -> App { "Check all targets", ) .arg_release("Check artifacts in release mode, with optimizations") + .arg_profile("Check artifacts with the specified profile") .arg_features() .arg_target_triple("Check for the target triple") .arg_target_dir() diff --git a/src/bin/cargo/commands/doc.rs b/src/bin/cargo/commands/doc.rs index 8405015dfbb..a3c92b8e566 100644 --- a/src/bin/cargo/commands/doc.rs +++ b/src/bin/cargo/commands/doc.rs @@ -24,6 +24,7 @@ pub fn cli() -> App { "Document all binaries", ) .arg_release("Build artifacts in release mode, with optimizations") + .arg_profile("Build artifacts with the specified profile") .arg_features() .arg_target_triple("Build for the target triple") .arg_target_dir() diff --git a/src/bin/cargo/commands/fix.rs b/src/bin/cargo/commands/fix.rs index 4ae59e580e3..9229be3fb5d 100644 --- a/src/bin/cargo/commands/fix.rs +++ b/src/bin/cargo/commands/fix.rs @@ -25,7 +25,7 @@ pub fn cli() -> App { "Fix all targets (default)", ) .arg_release("Fix artifacts in release mode, with optimizations") - .arg(opt("profile", "Profile to build the selected target for").value_name("PROFILE")) + .arg_profile("Build artifacts with the specified profile") .arg_features() .arg_target_triple("Fix for the target triple") .arg_target_dir() diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index ffe09b66f70..a2853bac47c 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -116,7 +116,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let workspace = args.workspace(config).ok(); let mut compile_opts = args.compile_options(config, CompileMode::Build, workspace.as_ref())?; - compile_opts.build_config.release = !args.is_present("debug"); + compile_opts.build_config.profile_kind = args.get_profile_kind(ProfileKind::Release)?; let krates = args .values_of("crate") diff --git a/src/bin/cargo/commands/run.rs b/src/bin/cargo/commands/run.rs index f30e8570d01..b2d75f50865 100644 --- a/src/bin/cargo/commands/run.rs +++ b/src/bin/cargo/commands/run.rs @@ -18,6 +18,7 @@ pub fn cli() -> App { .arg_package("Package with the target to run") .arg_jobs() .arg_release("Build artifacts in release mode, with optimizations") + .arg_profile("Build artifacts with the specified profile") .arg_features() .arg_target_triple("Build for the target triple") .arg_target_dir() diff --git a/src/bin/cargo/commands/rustc.rs b/src/bin/cargo/commands/rustc.rs index 5cb7f94e09b..519fe1b26c5 100644 --- a/src/bin/cargo/commands/rustc.rs +++ b/src/bin/cargo/commands/rustc.rs @@ -23,7 +23,7 @@ pub fn cli() -> App { "Build all targets", ) .arg_release("Build artifacts in release mode, with optimizations") - .arg(opt("profile", "Profile to build the selected target for").value_name("PROFILE")) + .arg_profile("Build artifacts with the specified profile") .arg_features() .arg_target_triple("Target triple which compiles will be for") .arg_target_dir() diff --git a/src/bin/cargo/commands/rustdoc.rs b/src/bin/cargo/commands/rustdoc.rs index 6616dc70e18..385c60f1470 100644 --- a/src/bin/cargo/commands/rustdoc.rs +++ b/src/bin/cargo/commands/rustdoc.rs @@ -27,6 +27,7 @@ pub fn cli() -> App { "Build all targets", ) .arg_release("Build artifacts in release mode, with optimizations") + .arg_profile("Build artifacts with the specified profile") .arg_features() .arg_target_triple("Build for the target triple") .arg_target_dir() diff --git a/src/bin/cargo/commands/test.rs b/src/bin/cargo/commands/test.rs index 06ef20d849c..26aa2db80d2 100644 --- a/src/bin/cargo/commands/test.rs +++ b/src/bin/cargo/commands/test.rs @@ -47,6 +47,7 @@ pub fn cli() -> App { ) .arg_jobs() .arg_release("Build artifacts in release mode, with optimizations") + .arg_profile("Build artifacts with the specified profile") .arg_features() .arg_target_triple("Build for the target triple") .arg_target_dir() diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index c2c3d76bd7c..ced5e30d3f8 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -6,6 +6,23 @@ use serde::ser; use crate::util::ProcessBuilder; use crate::util::{CargoResult, CargoResultExt, Config, RustfixDiagnosticServer}; +#[derive(Debug, Clone)] +pub enum ProfileKind { + Dev, + Release, + Custom(String), +} + +impl ProfileKind { + pub fn name(&self) -> &str { + match self { + ProfileKind::Dev => "dev", + ProfileKind::Release => "release", + ProfileKind::Custom(name) => &name, + } + } +} + /// Configuration information for a rustc build. #[derive(Debug)] pub struct BuildConfig { @@ -14,8 +31,8 @@ pub struct BuildConfig { pub requested_target: Option, /// Number of rustc jobs to run in parallel. pub jobs: u32, - /// `true` if we are building for release. - pub release: bool, + /// Build profile + pub profile_kind: ProfileKind, /// The mode we are compiling in. pub mode: CompileMode, /// `true` to print stdout in JSON format (for machine reading). @@ -93,7 +110,7 @@ impl BuildConfig { Ok(BuildConfig { requested_target: target, jobs, - release: false, + profile_kind: ProfileKind::Dev, mode, message_format: MessageFormat::Human, force_rebuild: false, @@ -115,6 +132,10 @@ impl BuildConfig { self.message_format == MessageFormat::Json } + pub fn profile_name(&self) -> &str { + self.profile_kind.name() + } + pub fn test(&self) -> bool { self.mode == CompileMode::Test || self.mode == CompileMode::Bench } diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index 76265f0d8fd..8a7d0080ad8 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -267,14 +267,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> { export_dir: Option, units: &[Unit<'a>], ) -> CargoResult<()> { - let dest = if self.bcx.build_config.release { - "release" - } else { - "debug" - }; - let host_layout = Layout::new(self.bcx.ws, None, dest)?; + let profile_kind = &self.bcx.build_config.profile_kind; + let dest = self.bcx.profiles.get_dir_name(profile_kind); + let host_layout = Layout::new(self.bcx.ws, None, &dest)?; let target_layout = match self.bcx.build_config.requested_target.as_ref() { - Some(target) => Some(Layout::new(self.bcx.ws, Some(target), dest)?), + Some(target) => Some(Layout::new(self.bcx.ws, Some(target), &dest)?), None => None, }; self.primary_packages diff --git a/src/cargo/core/compiler/context/unit_dependencies.rs b/src/cargo/core/compiler/context/unit_dependencies.rs index 3a85070937f..9f812a4b6cb 100644 --- a/src/cargo/core/compiler/context/unit_dependencies.rs +++ b/src/cargo/core/compiler/context/unit_dependencies.rs @@ -419,7 +419,7 @@ fn new_unit<'a>( bcx.ws.is_member(pkg), unit_for, mode, - bcx.build_config.release, + bcx.build_config.profile_kind.clone(), ); bcx.units.intern(pkg, target, profile, kind, mode) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 7978d1d480e..a7d4f49a72f 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -6,7 +6,7 @@ use std::str; use std::sync::{Arc, Mutex}; use crate::core::compiler::job_queue::JobState; -use crate::core::PackageId; +use crate::core::{profiles::ProfileRoot, PackageId}; use crate::util::errors::{CargoResult, CargoResultExt}; use crate::util::machine_message::{self, Message}; use crate::util::Cfg; @@ -160,10 +160,9 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes .env("OPT_LEVEL", &unit.profile.opt_level.to_string()) .env( "PROFILE", - if bcx.build_config.release { - "release" - } else { - "debug" + match unit.profile.root { + ProfileRoot::Release => "release", + ProfileRoot::Debug => "debug", }, ) .env("HOST", &bcx.host_triple()) diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index 3a4f7d7ef49..5b3ce0d7c66 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -16,6 +16,7 @@ use super::job::{ }; use super::{BuildContext, BuildPlan, CompileMode, Context, Unit}; use crate::core::{PackageId, TargetKind}; +use crate::core::compiler::{ProfileKind}; use crate::handle_error; use crate::util; use crate::util::diagnostic_server::{self, DiagnosticPrinter}; @@ -36,9 +37,9 @@ pub struct JobQueue<'a, 'cfg> { compiled: HashSet, documented: HashSet, counts: HashMap, - is_release: bool, progress: Progress<'cfg>, next_id: u32, + profile_kind: ProfileKind, } pub struct JobState<'a> { @@ -139,9 +140,9 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> { compiled: HashSet::new(), documented: HashSet::new(), counts: HashMap::new(), - is_release: bcx.build_config.release, progress, next_id: 0, + profile_kind: bcx.build_config.profile_kind.clone(), } } @@ -396,7 +397,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> { } self.progress.clear(); - let build_type = if self.is_release { "release" } else { "dev" }; + let build_type = self.profile_kind.name(); // NOTE: this may be a bit inaccurate, since this may not display the // profile for what was actually built. Profile overrides can change // these settings, and in some cases different targets are built with @@ -404,7 +405,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> { // list of Units built, and maybe display a list of the different // profiles used. However, to keep it simple and compatible with old // behavior, we just display what the base profile is. - let profile = cx.bcx.profiles.base_profile(self.is_release); + let profile = cx.bcx.profiles.base_profile(&self.profile_kind)?; let mut opt_type = String::from(if profile.opt_level.as_str() == "0" { "unoptimized" } else { diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index e8d14ec220b..2410129954a 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -24,7 +24,7 @@ use log::debug; use same_file::is_same_file; use serde::Serialize; -pub use self::build_config::{BuildConfig, CompileMode, MessageFormat}; +pub use self::build_config::{BuildConfig, CompileMode, MessageFormat, ProfileKind}; pub use self::build_context::{BuildContext, FileFlavor, TargetConfig, TargetInfo}; use self::build_plan::BuildPlan; pub use self::compilation::{Compilation, Doctest}; diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 80b4fa6a6f1..3187b781a5f 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -1,9 +1,10 @@ use std::collections::HashSet; +use std::collections::BTreeMap; use std::{cmp, env, fmt, hash}; use serde::Deserialize; -use crate::core::compiler::CompileMode; +use crate::core::compiler::{ProfileKind, CompileMode}; use crate::core::interning::InternedString; use crate::core::{Features, PackageId, PackageIdSpec, PackageSet, Shell}; use crate::util::errors::CargoResultExt; @@ -14,15 +15,12 @@ use crate::util::{CargoResult, Config}; /// Collection of all user profiles. #[derive(Clone, Debug)] pub struct Profiles { - dev: ProfileMaker, - release: ProfileMaker, - test: ProfileMaker, - bench: ProfileMaker, - doc: ProfileMaker, /// Incremental compilation can be overridden globally via: /// - `CARGO_INCREMENTAL` environment variable. /// - `build.incremental` config value. incremental: Option, + dir_names: BTreeMap, + by_name: BTreeMap, } impl Profiles { @@ -43,36 +41,142 @@ impl Profiles { None => config.get::>("build.incremental")?, }; - Ok(Profiles { - dev: ProfileMaker { - default: Profile::default_dev(), - toml: profiles.and_then(|p| p.dev.clone()), - config: config_profiles.dev.clone(), - }, - release: ProfileMaker { - default: Profile::default_release(), - toml: profiles.and_then(|p| p.release.clone()), - config: config_profiles.release.clone(), - }, - test: ProfileMaker { - default: Profile::default_test(), - toml: profiles.and_then(|p| p.test.clone()), - config: None, - }, - bench: ProfileMaker { - default: Profile::default_bench(), - toml: profiles.and_then(|p| p.bench.clone()), - config: None, - }, - doc: ProfileMaker { - default: Profile::default_doc(), - toml: profiles.and_then(|p| p.doc.clone()), - config: None, - }, + let mut profile_makers = Profiles { incremental, - }) + dir_names: Self::predefined_dir_names(), + by_name: BTreeMap::new(), + }; + + Self::add_root_profiles(&mut profile_makers, profiles, config_profiles); + + if let Some(profiles) = profiles { + let predefined_profiles = Self::predefined_profiles(); + profile_makers.process_customs(profiles.get_all(), &predefined_profiles)?; + } + + Ok(profile_makers) + } + + fn predefined_dir_names() -> BTreeMap { + let mut dir_names = BTreeMap::new(); + dir_names.insert("dev".to_owned(), "debug".to_owned()); + dir_names.insert("test".to_owned(), "debug".to_owned()); + dir_names.insert("bench".to_owned(), "release".to_owned()); + dir_names + } + + fn add_root_profiles(profile_makers: &mut Profiles, + profiles: Option<&TomlProfiles>, config_profiles: &ConfigProfiles) + { + let profile_name = "dev"; + profile_makers.by_name.insert(profile_name.to_owned(), ProfileMaker { + default: Profile::default_dev(), + toml: profiles.and_then(|p| p.get(profile_name).cloned()), + config: config_profiles.dev.clone(), + inherits: vec![], + }); + + let profile_name = "release"; + profile_makers.by_name.insert(profile_name.to_owned(), ProfileMaker { + default: Profile::default_release(), + toml: profiles.and_then(|p| p.get(profile_name).cloned()), + config: config_profiles.release.clone(), + inherits: vec![], + }); + } + + fn predefined_profiles() -> BTreeMap<&'static str, TomlProfile> { + let mut predefined_profiles = BTreeMap::new(); + predefined_profiles.insert("bench", TomlProfile { + inherits: Some(String::from("release")), + ..TomlProfile::default() + }); + predefined_profiles.insert("test", TomlProfile { + inherits: Some(String::from("dev")), + ..TomlProfile::default() + }); + predefined_profiles + } + + pub fn process_customs(&mut self, profiles: &BTreeMap, + predefined_profiles: &BTreeMap<&'static str, TomlProfile>) + -> CargoResult<()> + { + for (name, profile) in profiles { + let mut set = HashSet::new(); + let mut result = Vec::new(); + + set.insert(name.as_str().to_owned()); + match &profile.dir_name { + None => {}, + Some(dir_name) => { + self.dir_names.insert(name.clone(), dir_name.to_owned()); + } + } + + let mut maker = self.process_chain(name, + &profile, &mut set, + &mut result, profiles, + predefined_profiles)?; + result.reverse(); + maker.inherits = result; + + self.by_name.insert(name.as_str().to_owned(), maker); + } + + Ok(()) + } + + fn process_chain(&mut self, + name: &String, + profile: &TomlProfile, + set: &mut HashSet, + result: &mut Vec, + profiles: &BTreeMap, + predefined_profiles: &BTreeMap<&'static str, TomlProfile>) + -> CargoResult + { + let profile = match predefined_profiles.get(name.as_str()) { + None => profile.clone(), + Some(predef) => { + let mut overriden_profile = predef.clone(); + overriden_profile.merge(&profile); + overriden_profile + } + }; + + result.push(profile.clone()); + match profile.inherits.as_ref().map(|x| x.as_str()) { + Some(name@"dev") | Some(name@"release") => { + // These are the root profiles + return Ok(self.by_name.get(name).unwrap().clone()); + } + Some(name) => { + let name = name.to_owned(); + if set.get(&name).is_some() { + failure::bail!("Inheritance loop of profiles cycles with {}", name); + } + + set.insert(name.clone()); + match profiles.get(&name) { + None => { + failure::bail!("Profile {} not found in Cargo.toml", name); + } + Some(parent) => { + self.process_chain( + &name, parent, set, + result, profiles, predefined_profiles) + } + } + } + None => { + failure::bail!("An 'inherits' directive is needed for all profiles. \ + Here it is missing from {}", name); + } + } } + /// Retrieves the profile for a target. /// `is_member` is whether or not this package is a member of the /// workspace. @@ -82,31 +186,11 @@ impl Profiles { is_member: bool, unit_for: UnitFor, mode: CompileMode, - release: bool, + profile_kind: ProfileKind, ) -> Profile { - let maker = match mode { - CompileMode::Test | CompileMode::Bench => { - if release { - &self.bench - } else { - &self.test - } - } - CompileMode::Build - | CompileMode::Check { .. } - | CompileMode::Doctest - | CompileMode::RunCustomBuild => { - // Note: `RunCustomBuild` doesn't normally use this code path. - // `build_unit_profiles` normally ensures that it selects the - // ancestor's profile. However, `cargo clean -p` can hit this - // path. - if release { - &self.release - } else { - &self.dev - } - } - CompileMode::Doc { .. } => &self.doc, + let maker = match self.by_name.get(profile_kind.name()) { + None => panic!("Profile {} undefined", profile_kind.name()), + Some(r) => r, }; let mut profile = maker.get_profile(Some(pkg_id), is_member, unit_for); // `panic` should not be set for tests/benches, or any of their @@ -143,14 +227,23 @@ impl Profiles { result } - /// This returns a generic base profile. This is currently used for the + /// This returns the base profile. This is currently used for the /// `[Finished]` line. It is not entirely accurate, since it doesn't /// select for the package that was actually built. - pub fn base_profile(&self, release: bool) -> Profile { - if release { - self.release.get_profile(None, true, UnitFor::new_normal()) - } else { - self.dev.get_profile(None, true, UnitFor::new_normal()) + pub fn base_profile(&self, profile_kind: &ProfileKind) -> CargoResult { + match self.by_name.get(profile_kind.name()) { + None => failure::bail!("Profile {} undefined", profile_kind.name()), + Some(r) => { + Ok(r.get_profile(None, true, UnitFor::new_normal())) + } + } + } + + pub fn get_dir_name(&self, profile_kind: &ProfileKind) -> String { + let dest = profile_kind.name(); + match self.dir_names.get(dest) { + None => dest.to_owned(), + Some(s) => s.clone(), } } @@ -160,11 +253,9 @@ impl Profiles { shell: &mut Shell, packages: &PackageSet<'_>, ) -> CargoResult<()> { - self.dev.validate_packages(shell, packages)?; - self.release.validate_packages(shell, packages)?; - self.test.validate_packages(shell, packages)?; - self.bench.validate_packages(shell, packages)?; - self.doc.validate_packages(shell, packages)?; + for (_, profile) in &self.by_name { + profile.validate_packages(shell, packages)?; + } Ok(()) } } @@ -185,6 +276,11 @@ struct ProfileMaker { default: Profile, /// The profile from the `Cargo.toml` manifest. toml: Option, + + /// Profiles from which we inherit, in the order from which + /// we inherit. + inherits: Vec, + /// Profile loaded from `.cargo/config` files. config: Option, } @@ -200,6 +296,9 @@ impl ProfileMaker { if let Some(ref toml) = self.toml { merge_toml(pkg_id, is_member, unit_for, &mut profile, toml); } + for toml in &self.inherits { + merge_toml(pkg_id, is_member, unit_for, &mut profile, toml); + } if let Some(ref toml) = self.config { merge_toml(pkg_id, is_member, unit_for, &mut profile, toml); } @@ -406,12 +505,19 @@ fn merge_profile(profile: &mut Profile, toml: &TomlProfile) { } } +#[derive(Clone, Copy, Eq, PartialOrd, Ord, PartialEq, Debug)] +pub enum ProfileRoot { + Release, + Debug, +} + /// Profile settings used to determine which compiler flags to use for a /// target. #[derive(Clone, Copy, Eq, PartialOrd, Ord)] pub struct Profile { pub name: &'static str, pub opt_level: InternedString, + pub root: ProfileRoot, pub lto: Lto, // `None` means use rustc default. pub codegen_units: Option, @@ -428,6 +534,7 @@ impl Default for Profile { Profile { name: "", opt_level: InternedString::new("0"), + root: ProfileRoot::Debug, lto: Lto::Bool(false), codegen_units: None, debuginfo: None, @@ -446,15 +553,13 @@ compact_debug! { let (default, default_name) = match self.name { "dev" => (Profile::default_dev(), "default_dev()"), "release" => (Profile::default_release(), "default_release()"), - "test" => (Profile::default_test(), "default_test()"), - "bench" => (Profile::default_bench(), "default_bench()"), - "doc" => (Profile::default_doc(), "default_doc()"), _ => (Profile::default(), "default()"), }; [debug_the_fields( name opt_level lto + root codegen_units debuginfo debug_assertions @@ -492,6 +597,7 @@ impl Profile { fn default_dev() -> Profile { Profile { name: "dev", + root: ProfileRoot::Debug, debuginfo: Some(2), debug_assertions: true, overflow_checks: true, @@ -503,32 +609,12 @@ impl Profile { fn default_release() -> Profile { Profile { name: "release", + root: ProfileRoot::Release, opt_level: InternedString::new("3"), ..Profile::default() } } - fn default_test() -> Profile { - Profile { - name: "test", - ..Profile::default_dev() - } - } - - fn default_bench() -> Profile { - Profile { - name: "bench", - ..Profile::default_release() - } - } - - fn default_doc() -> Profile { - Profile { - name: "doc", - ..Profile::default_dev() - } - } - /// Compares all fields except `name`, which doesn't affect compilation. /// This is necessary for `Unit` deduplication for things like "test" and /// "dev" which are essentially the same. diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 1a8a15cf0ef..cdcf74b885a 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -3,7 +3,7 @@ use std::fs; use std::path::Path; use crate::core::compiler::UnitInterner; -use crate::core::compiler::{BuildConfig, BuildContext, CompileMode, Context, Kind}; +use crate::core::compiler::{BuildConfig, BuildContext, CompileMode, Context, Kind, ProfileKind}; use crate::core::profiles::UnitFor; use crate::core::Workspace; use crate::ops; @@ -18,7 +18,7 @@ pub struct CleanOptions<'a> { /// The target arch triple to clean, or None for the host arch pub target: Option, /// Whether to clean the release directory - pub release: bool, + pub profile_kind: ProfileKind, /// Whether to just clean the doc directory pub doc: bool, } @@ -34,11 +34,6 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { return rm_rf(&target_dir.into_path_unlocked(), config); } - // If the release option is set, we set target to release directory - if opts.release { - target_dir = target_dir.join("release"); - } - // If we have a spec, then we need to delete some packages, otherwise, just // remove the whole target directory and be done with it! // @@ -53,7 +48,8 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { let profiles = ws.profiles(); let interner = UnitInterner::new(); let mut build_config = BuildConfig::new(config, Some(1), &opts.target, CompileMode::Build)?; - build_config.release = opts.release; + let profile_kind = opts.profile_kind.clone(); + build_config.profile_kind = profile_kind.clone(); let bcx = BuildContext::new( ws, &resolve, @@ -82,7 +78,7 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { ws.is_member(pkg), *unit_for, CompileMode::Build, - opts.release, + profile_kind.clone(), )) } else { profiles.get_profile( @@ -90,7 +86,7 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { ws.is_member(pkg), *unit_for, *mode, - opts.release, + profile_kind.clone(), ) }; units.push(bcx.units.intern(pkg, target, profile, *kind, *mode)); diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index fceab742505..78f7cdaebec 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -584,6 +584,8 @@ fn generate_targets<'a>( resolve: &Resolve, bcx: &BuildContext<'a, '_>, ) -> CargoResult>> { + let _ = profiles.base_profile(&bcx.build_config.profile_kind)?; + // Helper for creating a `Unit` struct. let new_unit = |pkg: &'a Package, target: &'a Target, target_mode: CompileMode| { let unit_for = if bcx.build_config.mode.is_any_test() { @@ -651,7 +653,7 @@ fn generate_targets<'a>( ws.is_member(pkg), unit_for, target_mode, - bcx.build_config.release, + bcx.build_config.profile_kind.clone(), ); bcx.units.intern(pkg, target, profile, kind, target_mode) }; diff --git a/src/cargo/ops/common_for_install_and_uninstall.rs b/src/cargo/ops/common_for_install_and_uninstall.rs index 12e435864d0..801a934404c 100644 --- a/src/cargo/ops/common_for_install_and_uninstall.rs +++ b/src/cargo/ops/common_for_install_and_uninstall.rs @@ -455,7 +455,7 @@ impl CrateListingV2 { info.features = feature_set(&opts.features); info.all_features = opts.all_features; info.no_default_features = opts.no_default_features; - info.profile = profile_name(opts.build_config.release).to_string(); + info.profile = opts.build_config.profile_name().to_string(); info.target = Some(target); info.rustc = Some(rustc); } else { @@ -467,7 +467,7 @@ impl CrateListingV2 { features: feature_set(&opts.features), all_features: opts.all_features, no_default_features: opts.no_default_features, - profile: profile_name(opts.build_config.release).to_string(), + profile: opts.build_config.profile_name().to_string(), target: Some(target), rustc: Some(rustc), other: BTreeMap::new(), @@ -527,7 +527,7 @@ impl InstallInfo { self.features == feature_set(&opts.features) && self.all_features == opts.all_features && self.no_default_features == opts.no_default_features - && self.profile == profile_name(opts.build_config.release) + && self.profile == opts.build_config.profile_name().to_string() && (self.target.is_none() || self.target.as_ref().map(|t| t.as_ref()) == Some(target)) && &self.bins == exes } @@ -720,14 +720,6 @@ where } } -fn profile_name(release: bool) -> &'static str { - if release { - "release" - } else { - "dev" - } -} - /// Helper to convert features Vec to a BTreeSet. fn feature_set(features: &[String]) -> BTreeSet { features.iter().cloned().collect() diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 8d6963c6d9a..1a0ede68629 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -15,7 +15,7 @@ use crate::util::{ use crate::CargoResult; use clap::{self, SubCommand}; -pub use crate::core::compiler::CompileMode; +pub use crate::core::compiler::{ProfileKind, CompileMode}; pub use crate::{CliError, CliResult, Config}; pub use clap::{AppSettings, Arg, ArgMatches}; @@ -113,6 +113,10 @@ pub trait AppExt: Sized { self._arg(opt("release", release)) } + fn arg_profile(self, profile: &'static str) -> Self { + self._arg(opt("profile", profile).value_name("PROFILE-NAME")) + } + fn arg_doc(self, doc: &'static str) -> Self { self._arg(opt("doc", doc)) } @@ -288,6 +292,37 @@ pub trait ArgMatchesExt { self._value_of("target").map(|s| s.to_string()) } + fn get_profile_kind(&self, default: ProfileKind) -> CargoResult { + let specified_profile = match self._value_of("profile") { + None => None, + Some("dev") => Some(ProfileKind::Dev), + Some("release") => Some(ProfileKind::Release), + Some(name) => Some(ProfileKind::Custom(name.to_string())), + }; + + if self._is_present("release") { + match specified_profile { + None | Some(ProfileKind::Release) => { + Ok(ProfileKind::Release) + } + _ => { + failure::bail!("Conflicting usage of --profile and --release") + } + } + } else if self._is_present("debug") { + match specified_profile { + None | Some(ProfileKind::Dev) => { + Ok(ProfileKind::Dev) + } + _ => { + failure::bail!("Conflicting usage of --profile and --debug") + } + } + } else { + Ok(specified_profile.unwrap_or(default)) + } + } + fn compile_options<'a>( &self, config: &'a Config, @@ -317,7 +352,7 @@ 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"); + build_config.profile_kind = self.get_profile_kind(ProfileKind::Dev)?; build_config.build_plan = self._is_present("build-plan"); if build_config.build_plan { config diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 13ed058ace6..b47156ffbce 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -270,30 +270,20 @@ pub struct TomlManifest { } #[derive(Deserialize, Serialize, Clone, Debug, Default)] -pub struct TomlProfiles { - pub test: Option, - pub doc: Option, - pub bench: Option, - pub dev: Option, - pub release: Option, -} +pub struct TomlProfiles(BTreeMap); impl TomlProfiles { + pub fn get_all(&self) -> &BTreeMap { + &self.0 + } + + pub fn get(&self, name: &'static str) -> Option<&TomlProfile> { + self.0.get(&String::from(name)) + } + pub fn validate(&self, features: &Features, warnings: &mut Vec) -> CargoResult<()> { - if let Some(ref test) = self.test { - test.validate("test", features, warnings)?; - } - if let Some(ref doc) = self.doc { - doc.validate("doc", features, warnings)?; - } - if let Some(ref bench) = self.bench { - bench.validate("bench", features, warnings)?; - } - if let Some(ref dev) = self.dev { - dev.validate("dev", features, warnings)?; - } - if let Some(ref release) = self.release { - release.validate("release", features, warnings)?; + for (name, profile) in &self.0 { + profile.validate(&name, features, warnings)?; } Ok(()) } @@ -416,6 +406,8 @@ pub struct TomlProfile { pub incremental: Option, pub overrides: Option>, pub build_override: Option>, + pub dir_name: Option, + pub inherits: Option, } #[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)] @@ -522,6 +514,60 @@ impl TomlProfile { } Ok(()) } + + pub fn merge(&mut self, profile: &TomlProfile) { + if let Some(v) = &profile.opt_level { + self.opt_level = Some(v.clone()); + } + + if let Some(v) = &profile.lto { + self.lto = Some(v.clone()); + } + + if let Some(v) = profile.codegen_units { + self.codegen_units = Some(v.clone()); + } + + if let Some(v) = &profile.debug { + self.debug = Some(v.clone()); + } + + if let Some(v) = profile.debug_assertions { + self.debug_assertions = Some(v.clone()); + } + + if let Some(v) = profile.rpath { + self.rpath = Some(v.clone()); + } + + if let Some(v) = &profile.panic { + self.panic = Some(v.clone()); + } + + if let Some(v) = profile.overflow_checks { + self.overflow_checks = Some(v.clone()); + } + + if let Some(v) = profile.incremental { + self.incremental = Some(v.clone()); + } + + if let Some(v) = &profile.overrides { + self.overrides = Some(v.clone()); + } + + if let Some(v) = &profile.build_override { + self.build_override = Some(v.clone()); + } + + if let Some(v) = &profile.inherits { + self.inherits = Some(v.clone()); + } + + if let Some(v) = &profile.dir_name { + self.dir_name = Some(v.clone()); + } + } } #[derive(Clone, Debug, Serialize, Eq, PartialEq)] From 55f4b675551a072b79eb8157082be8484e8a4360 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 1 Jun 2019 13:43:58 +0300 Subject: [PATCH 02/58] tests: fix and extend config_load_toml_profile for RFC 2689 --- tests/testsuite/config.rs | 50 ++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index 22b6c357d92..39b59ddad6a 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -164,6 +164,11 @@ opt-level = 1 [profile.dev.overrides.bar] codegen-units = 9 + +[profile.no-lto] +inherits = 'dev' +dir-name = 'without-lto' +lto = false ", ); @@ -180,31 +185,14 @@ codegen-units = 9 let key = toml::ProfilePackageSpec::Spec(::cargo::core::PackageIdSpec::parse("bar").unwrap()); let o_profile = toml::TomlProfile { opt_level: Some(toml::TomlOptLevel("2".to_string())), - lto: None, codegen_units: Some(9), - debug: None, - debug_assertions: None, - rpath: None, - panic: None, - overflow_checks: None, - incremental: None, - overrides: None, - build_override: None, + ..Default::default() }; overrides.insert(key, o_profile); let key = toml::ProfilePackageSpec::Spec(::cargo::core::PackageIdSpec::parse("env").unwrap()); let o_profile = toml::TomlProfile { - opt_level: None, - lto: None, codegen_units: Some(13), - debug: None, - debug_assertions: None, - rpath: None, - panic: None, - overflow_checks: None, - incremental: None, - overrides: None, - build_override: None, + ..Default::default() }; overrides.insert(key, o_profile); @@ -223,17 +211,21 @@ codegen-units = 9 overrides: Some(overrides), build_override: Some(Box::new(toml::TomlProfile { opt_level: Some(toml::TomlOptLevel("1".to_string())), - lto: None, codegen_units: Some(11), - debug: None, - debug_assertions: None, - rpath: None, - panic: None, - overflow_checks: None, - incremental: None, - overrides: None, - build_override: None - })) + ..Default::default() + })), + ..Default::default() + } + ); + + let p: toml::TomlProfile = config.get("profile.lto").unwrap(); + assert_eq!( + p, + toml::TomlProfile { + lto: Some(toml::StringOrBool::Bool(false)), + dir_name: Some("without-lto".to_string()), + inherits: Some("dev".to_string()), + ..Default::default() } ); } From a72c405fe5f243229d442117e342e30f32e8f37d Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 1 Jun 2019 13:49:51 +0300 Subject: [PATCH 03/58] tests: we now allow a profile.debug --- tests/testsuite/bad_config.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 20f6d9de529..c8a510a63c1 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -699,19 +699,13 @@ warning: unused manifest key: target.foo.bar [profile.debug] debug = 1 + inherits = "dev" "#, ) .file("src/lib.rs", "") .build(); p.cargo("build") - .with_stderr( - "\ -warning: unused manifest key: profile.debug -warning: use `[profile.dev]` to configure debug builds -[..] -[..]", - ) .run(); let p = project() From 7c6a3d44eb2f0bec20a2561b7622c8e276d8887a Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 1 Jun 2019 14:01:18 +0300 Subject: [PATCH 04/58] tests: profile_doc_deprecated should have 'inherits' --- tests/testsuite/profiles.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testsuite/profiles.rs b/tests/testsuite/profiles.rs index 40454f93ead..c341222cc42 100644 --- a/tests/testsuite/profiles.rs +++ b/tests/testsuite/profiles.rs @@ -362,6 +362,7 @@ fn profile_doc_deprecated() { [profile.doc] opt-level = 0 + inherits = "dev" "#, ) .file("src/lib.rs", "") From b107d526f8fafa057a5883978e4cca4c0f33494e Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 1 Jun 2019 14:01:48 +0300 Subject: [PATCH 05/58] custom-named-profiles: Bug fix - no need for 'inherits' in root profiles When resolving profile parameters for custom named profiles, we can skip 'dev' and 'release' because they are the root profiles from which all others inherit. Otherwise, for example, we fail the tests where a simple `[profile.dev]` clause is specified. --- src/cargo/core/profiles.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 3187b781a5f..765a6028ac9 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -113,6 +113,12 @@ impl Profiles { self.dir_names.insert(name.clone(), dir_name.to_owned()); } } + match name.as_str() { + "dev" | "release" => { + continue; + } + _ => {} + }; let mut maker = self.process_chain(name, &profile, &mut set, @@ -170,8 +176,11 @@ impl Profiles { } } None => { - failure::bail!("An 'inherits' directive is needed for all profiles. \ - Here it is missing from {}", name); + failure::bail!( + "An 'inherits' directive is needed for all \ + profiles that are not 'dev' or 'release. Here \ + it is missing from {}", + name); } } } From b52cc1bc534f5deabd81d4e9a8705ffcf1c02ee2 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 1 Jun 2019 14:58:18 +0300 Subject: [PATCH 06/58] custom-named-profiles: fix merges of predefined profiles The predefined 'test' and 'bench' profiles should exist even if the user did not define anything in the Cargo.toml. This also rewrites how the merging is done. --- src/cargo/core/profiles.rs | 67 ++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 765a6028ac9..365293db92e 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -49,11 +49,28 @@ impl Profiles { Self::add_root_profiles(&mut profile_makers, profiles, config_profiles); - if let Some(profiles) = profiles { - let predefined_profiles = Self::predefined_profiles(); - profile_makers.process_customs(profiles.get_all(), &predefined_profiles)?; + let mut profiles = if let Some(profiles) = profiles { + profiles.get_all().clone() + } else { + BTreeMap::new() + }; + + // Merge with predefined profiles + use std::collections::btree_map::Entry; + for (predef_name, mut predef_prof) in Self::predefined_profiles().into_iter() { + match profiles.entry(predef_name.to_owned()) { + Entry::Vacant(vac) => { vac.insert(predef_prof); }, + Entry::Occupied(mut oc) => { + // Override predefined with the user-provided Toml. + let r = oc.get_mut(); + predef_prof.merge(r); + *r = predef_prof; + }, + } } + profile_makers.process_customs(&profiles)?; + Ok(profile_makers) } @@ -85,21 +102,20 @@ impl Profiles { }); } - fn predefined_profiles() -> BTreeMap<&'static str, TomlProfile> { - let mut predefined_profiles = BTreeMap::new(); - predefined_profiles.insert("bench", TomlProfile { - inherits: Some(String::from("release")), - ..TomlProfile::default() - }); - predefined_profiles.insert("test", TomlProfile { - inherits: Some(String::from("dev")), - ..TomlProfile::default() - }); - predefined_profiles + fn predefined_profiles() -> Vec<(&'static str, TomlProfile)> { + vec![ + ("bench", TomlProfile { + inherits: Some(String::from("release")), + ..TomlProfile::default() + }), + ("test", TomlProfile { + inherits: Some(String::from("dev")), + ..TomlProfile::default() + }), + ] } - pub fn process_customs(&mut self, profiles: &BTreeMap, - predefined_profiles: &BTreeMap<&'static str, TomlProfile>) + pub fn process_customs(&mut self, profiles: &BTreeMap) -> CargoResult<()> { for (name, profile) in profiles { @@ -122,8 +138,7 @@ impl Profiles { let mut maker = self.process_chain(name, &profile, &mut set, - &mut result, profiles, - predefined_profiles)?; + &mut result, profiles)?; result.reverse(); maker.inherits = result; @@ -138,19 +153,9 @@ impl Profiles { profile: &TomlProfile, set: &mut HashSet, result: &mut Vec, - profiles: &BTreeMap, - predefined_profiles: &BTreeMap<&'static str, TomlProfile>) + profiles: &BTreeMap) -> CargoResult { - let profile = match predefined_profiles.get(name.as_str()) { - None => profile.clone(), - Some(predef) => { - let mut overriden_profile = predef.clone(); - overriden_profile.merge(&profile); - overriden_profile - } - }; - result.push(profile.clone()); match profile.inherits.as_ref().map(|x| x.as_str()) { Some(name@"dev") | Some(name@"release") => { @@ -169,9 +174,7 @@ impl Profiles { failure::bail!("Profile {} not found in Cargo.toml", name); } Some(parent) => { - self.process_chain( - &name, parent, set, - result, profiles, predefined_profiles) + self.process_chain(&name, parent, set, result, profiles) } } } From bb86a5c3f49557db695507b2850cac7bc11fa496 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 1 Jun 2019 15:06:18 +0300 Subject: [PATCH 07/58] tests: config_load_toml_profile fixup --- tests/testsuite/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index 39b59ddad6a..000ff77a368 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -218,7 +218,7 @@ lto = false } ); - let p: toml::TomlProfile = config.get("profile.lto").unwrap(); + let p: toml::TomlProfile = config.get("profile.no-lto").unwrap(); assert_eq!( p, toml::TomlProfile { From 92339a5b53fc4e8e0864fb4e4ee70a48aeaaffa0 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 1 Jun 2019 15:18:54 +0300 Subject: [PATCH 08/58] custom-named-profiles: fix profile for custom build The profile returned for custom build should have the proper 'root' field value. This fixes test build_script::profile_and_opt_level_set_correctly. --- src/cargo/core/profiles.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 365293db92e..32ec8ef4d69 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -234,6 +234,7 @@ impl Profiles { /// times). pub fn get_profile_run_custom_build(&self, for_unit_profile: &Profile) -> Profile { let mut result = Profile::default(); + result.root = for_unit_profile.root; result.debuginfo = for_unit_profile.debuginfo; result.opt_level = for_unit_profile.opt_level; result From c27d8994891195c7f3f310885bca38aca6eef2c9 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 1 Jun 2019 15:25:04 +0300 Subject: [PATCH 09/58] custom-named-profiles: predefined check profile Since we also for 'cargo rustc' to received '--profile check', let it be consistent with the other commands and use a predefined 'check' profile for it that inherits from "dev". Fixes tests check::rustc_check and check::rustc_check_err. --- src/cargo/core/profiles.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 32ec8ef4d69..1eb64422bdf 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -77,6 +77,7 @@ impl Profiles { fn predefined_dir_names() -> BTreeMap { let mut dir_names = BTreeMap::new(); dir_names.insert("dev".to_owned(), "debug".to_owned()); + dir_names.insert("check".to_owned(), "debug".to_owned()); dir_names.insert("test".to_owned(), "debug".to_owned()); dir_names.insert("bench".to_owned(), "release".to_owned()); dir_names @@ -112,6 +113,10 @@ impl Profiles { inherits: Some(String::from("dev")), ..TomlProfile::default() }), + ("check", TomlProfile { + inherits: Some(String::from("dev")), + ..TomlProfile::default() + }), ] } From 04e80b5e7b3dc895e945d8e2979112337656b931 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Fri, 7 Jun 2019 19:36:26 +0300 Subject: [PATCH 10/58] custom-named-profiles: fix handling of 'clean' command Before the RFC, the 'clean' command would have cleaned entirety of target/ unless `--release` is specified - in that case it would have cleaned only `target/release`. Initial commit broke that. Now, passing `--profile=NAME` will clean the directory related to profile `NAME` via the dir-name setting. `--release` is supported for backward compatibility. --- src/bin/cargo/commands/clean.rs | 2 ++ src/cargo/ops/cargo_clean.rs | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/bin/cargo/commands/clean.rs b/src/bin/cargo/commands/clean.rs index 1a180da7636..bc4ba21c32e 100644 --- a/src/bin/cargo/commands/clean.rs +++ b/src/bin/cargo/commands/clean.rs @@ -30,6 +30,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { spec: values(args, "package"), target: args.target(), profile_kind: args.get_profile_kind(ProfileKind::Dev)?, + release: args.is_present("release"), + profile_specified: args.is_present("profile"), doc: args.is_present("doc"), }; ops::clean(&ws, &opts)?; diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index cdcf74b885a..a9d28cf4dd0 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -18,6 +18,10 @@ pub struct CleanOptions<'a> { /// The target arch triple to clean, or None for the host arch pub target: Option, /// Whether to clean the release directory + pub release: bool, + /// Whether a certain build profile was specified + pub profile_specified: bool, + /// Whether to clean the directory of a certain build profile pub profile_kind: ProfileKind, /// Whether to just clean the doc directory pub doc: bool, @@ -34,6 +38,20 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { return rm_rf(&target_dir.into_path_unlocked(), config); } + let (packages, resolve) = ops::resolve_ws(ws)?; + let profiles = ws.profiles(); + + // If the release option is set, we set target to release directory + if opts.release { + target_dir = target_dir.join(profiles.get_dir_name(&ProfileKind::Release)); + } else if opts.profile_specified { + // After parsing profiles we know the dir-name of the profile, if a profile + // was passed freom the command line. If so, delete only the directory of + // that profile. + let dir_name = profiles.get_dir_name(&opts.profile_kind); + target_dir = target_dir.join(dir_name); + } + // If we have a spec, then we need to delete some packages, otherwise, just // remove the whole target directory and be done with it! // @@ -43,9 +61,6 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { return rm_rf(&target_dir.into_path_unlocked(), config); } - let (packages, resolve) = ops::resolve_ws(ws)?; - - let profiles = ws.profiles(); let interner = UnitInterner::new(); let mut build_config = BuildConfig::new(config, Some(1), &opts.target, CompileMode::Build)?; let profile_kind = opts.profile_kind.clone(); From e37253c871f9f69ca2d273e69d0f78ef17f147e4 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Fri, 7 Jun 2019 20:26:03 +0300 Subject: [PATCH 11/58] custom-named-profiles: for 'cargo test' use "test" profile by default --- src/bin/cargo/commands/test.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bin/cargo/commands/test.rs b/src/bin/cargo/commands/test.rs index 26aa2db80d2..9a0579b491a 100644 --- a/src/bin/cargo/commands/test.rs +++ b/src/bin/cargo/commands/test.rs @@ -102,6 +102,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let mut compile_opts = args.compile_options(config, CompileMode::Test, Some(&ws))?; + compile_opts.build_config.profile_kind = + args.get_profile_kind(ProfileKind::Custom("test".to_owned()))?; + // `TESTNAME` is actually an argument of the test binary, but it's // important, so we explicitly mention it and reconfigure. let test_name: Option<&str> = args.value_of("TESTNAME"); From a0290b10c82822d00acc05d70856de76957f1c8f Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Fri, 7 Jun 2019 20:08:43 +0300 Subject: [PATCH 12/58] tests: adjust profiles::profile_panic_test_bench for sorted output New code relies on a BTreeMap, rather than handed coded calls. --- tests/testsuite/profiles.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testsuite/profiles.rs b/tests/testsuite/profiles.rs index c341222cc42..e8d04bcc2d7 100644 --- a/tests/testsuite/profiles.rs +++ b/tests/testsuite/profiles.rs @@ -343,8 +343,8 @@ fn profile_panic_test_bench() { p.cargo("build") .with_stderr_contains( "\ -[WARNING] `panic` setting is ignored for `test` profile [WARNING] `panic` setting is ignored for `bench` profile +[WARNING] `panic` setting is ignored for `test` profile ", ) .run(); From e25f6a425538a6828558f2b9cdba3457cd4a0a6b Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Fri, 7 Jun 2019 21:09:47 +0300 Subject: [PATCH 13/58] tests: fix finished line for 'cargo test' --- tests/testsuite/build_script.rs | 12 ++-- tests/testsuite/freshness.rs | 6 +- tests/testsuite/git.rs | 2 +- tests/testsuite/path.rs | 4 +- tests/testsuite/profile_targets.rs | 6 +- tests/testsuite/required_features.rs | 22 +++---- tests/testsuite/rustflags.rs | 8 +-- tests/testsuite/test.rs | 94 ++++++++++++++-------------- tests/testsuite/tool_paths.rs | 4 +- 9 files changed, 79 insertions(+), 79 deletions(-) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index e21a954c860..b3bbf60eec0 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -690,7 +690,7 @@ fn testing_and_such() { [RUNNING] `[..]/build-script-build` [RUNNING] `rustc --crate-name foo [..]` [RUNNING] `rustc --crate-name foo [..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] `[..]/foo-[..][EXE]` [DOCTEST] foo [RUNNING] `rustdoc --test [..]`", @@ -1787,7 +1787,7 @@ fn cfg_test() { [RUNNING] [..] --cfg foo[..] [RUNNING] [..] --cfg foo[..] [RUNNING] [..] --cfg foo[..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] `[..]/foo-[..][EXE]` [RUNNING] `[..]/test-[..][EXE]` [DOCTEST] foo @@ -1898,7 +1898,7 @@ fn cfg_override_test() { [RUNNING] `[..]` [RUNNING] `[..]` [RUNNING] `[..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] `[..]/foo-[..][EXE]` [RUNNING] `[..]/test-[..][EXE]` [DOCTEST] foo @@ -2034,7 +2034,7 @@ fn env_test() { [RUNNING] [..] --crate-name foo[..] [RUNNING] [..] --crate-name foo[..] [RUNNING] [..] --crate-name test[..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] `[..]/foo-[..][EXE]` [RUNNING] `[..]/test-[..][EXE]` [DOCTEST] foo @@ -2135,7 +2135,7 @@ fn flags_go_into_tests() { [COMPILING] foo v0.5.0 ([..] [RUNNING] `rustc [..] src/lib.rs [..] -L test[..]` [RUNNING] `rustc [..] tests/foo.rs [..] -L test[..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] `[..]/foo-[..][EXE]`", ) .with_stdout_contains("running 0 tests") @@ -2147,7 +2147,7 @@ fn flags_go_into_tests() { [FRESH] a v0.5.0 ([..] [COMPILING] b v0.5.0 ([..] [RUNNING] `rustc [..] b/src/lib.rs [..] -L test[..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] `[..]/b-[..][EXE]`", ) .with_stdout_contains("running 0 tests") diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index da7686befff..61678def1a7 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -231,7 +231,7 @@ fn changing_profiles_caches_targets() { .with_stderr( "\ [..]Compiling foo v0.0.1 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target[..]debug[..]deps[..]foo-[..][EXE] [DOCTEST] foo ", @@ -247,7 +247,7 @@ fn changing_profiles_caches_targets() { p.cargo("test foo") .with_stderr( "\ -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target[..]debug[..]deps[..]foo-[..][EXE] ", ) @@ -572,7 +572,7 @@ fn no_rebuild_transitive_target_deps() { [COMPILING] c v0.0.1 ([..]) [COMPILING] b v0.0.1 ([..]) [COMPILING] foo v0.0.1 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] ", ) .run(); diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index 62ed8cfbd0d..5b6e09b2b7d 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -1320,7 +1320,7 @@ fn dev_deps_with_testing() { "\ [COMPILING] [..] v0.5.0 ([..]) [COMPILING] [..] v0.5.0 ([..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE]", ) .with_stdout_contains("test tests::foo ... ok") diff --git a/tests/testsuite/path.rs b/tests/testsuite/path.rs index bf272d0cf3d..ab522e248a6 100644 --- a/tests/testsuite/path.rs +++ b/tests/testsuite/path.rs @@ -186,7 +186,7 @@ fn cargo_compile_with_root_dev_deps_with_testing() { "\ [COMPILING] [..] v0.5.0 ([..]) [COMPILING] [..] v0.5.0 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE]", ) .with_stdout_contains("running 0 tests") @@ -783,7 +783,7 @@ fn dev_deps_no_rebuild_lib() { "\ [COMPILING] [..] v0.5.0 ([CWD][..]) [COMPILING] [..] v0.5.0 ([CWD][..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE]", ) .with_stdout_contains("running 0 tests") diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index e1f5f8b510f..dbcf9a09fa3 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -314,7 +314,7 @@ fn profile_selection_test() { [FRESH] bar [..] [FRESH] bdep [..] [FRESH] foo [..] -[FINISHED] dev [unoptimized + debuginfo] [..] +[FINISHED] test [unoptimized + debuginfo] [..] [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` @@ -441,7 +441,7 @@ fn profile_selection_bench() { [FRESH] bar [..] [FRESH] bdep [..] [FRESH] foo [..] -[FINISHED] release [optimized] [..] +[FINISHED] bench [optimized] [..] [RUNNING] `[..]/deps/foo-[..] --bench` [RUNNING] `[..]/deps/foo-[..] --bench` [RUNNING] `[..]/deps/bench1-[..] --bench` @@ -609,7 +609,7 @@ fn profile_selection_check_all_targets_test() { [FRESH] bar [..] [FRESH] bdep [..] [FRESH] foo [..] -[FINISHED] dev [unoptimized + debuginfo] [..] +[FINISHED] test [unoptimized + debuginfo] [..] ", ) .run(); diff --git a/tests/testsuite/required_features.rs b/tests/testsuite/required_features.rs index d4afea0d4e9..3273cf387c9 100644 --- a/tests/testsuite/required_features.rs +++ b/tests/testsuite/required_features.rs @@ -288,21 +288,21 @@ fn test_default_features() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE]", ) .with_stdout_contains("test test ... ok") .run(); p.cargo("test --no-default-features") - .with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]") + .with_stderr("[FINISHED] test [unoptimized + debuginfo] target(s) in [..]") .with_stdout("") .run(); p.cargo("test --test=foo") .with_stderr( "\ -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE]", ) .with_stdout_contains("test test ... ok") @@ -345,7 +345,7 @@ fn test_arg_features() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE]", ) .with_stdout_contains("test test ... ok") @@ -386,7 +386,7 @@ fn test_multiple_required_features() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo_2-[..][EXE]", ) .with_stdout_contains("test test ... ok") @@ -396,7 +396,7 @@ fn test_multiple_required_features() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo_1-[..][EXE] [RUNNING] target/debug/deps/foo_2-[..][EXE]", ) @@ -404,7 +404,7 @@ fn test_multiple_required_features() { .run(); p.cargo("test --no-default-features") - .with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]") + .with_stderr("[FINISHED] test [unoptimized + debuginfo] target(s) in [..]") .with_stdout("") .run(); } @@ -847,7 +847,7 @@ fn dep_feature_in_toml() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE]", ) .with_stdout_contains("test test ... ok") @@ -964,7 +964,7 @@ Consider enabling them by passing, e.g., `--features=\"bar/a\"` // test p.cargo("test") - .with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]") + .with_stderr("[FINISHED] test [unoptimized + debuginfo] target(s) in [..]") .with_stdout("") .run(); @@ -972,7 +972,7 @@ Consider enabling them by passing, e.g., `--features=\"bar/a\"` .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE]", ) .with_stdout_contains("test test ... ok") @@ -1044,7 +1044,7 @@ fn test_skips_compiling_bin_with_missing_required_features() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE]", ) .with_stdout_contains("running 0 tests") diff --git a/tests/testsuite/rustflags.rs b/tests/testsuite/rustflags.rs index da5b5eb78c2..8993e16ae76 100644 --- a/tests/testsuite/rustflags.rs +++ b/tests/testsuite/rustflags.rs @@ -1094,7 +1094,7 @@ fn cfg_rustflags_normal_source() { [RUNNING] `rustc [..] --cfg bar[..]` [RUNNING] `rustc [..] --cfg bar[..]` [RUNNING] `rustc [..] --cfg bar[..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] ", ) .run(); @@ -1106,7 +1106,7 @@ fn cfg_rustflags_normal_source() { [RUNNING] `rustc [..] --cfg bar[..]` [RUNNING] `rustc [..] --cfg bar[..]` [RUNNING] `rustc [..] --cfg bar[..]` -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] ", ) .run(); @@ -1176,7 +1176,7 @@ fn cfg_rustflags_precedence() { [RUNNING] `rustc [..] --cfg bar[..]` [RUNNING] `rustc [..] --cfg bar[..]` [RUNNING] `rustc [..] --cfg bar[..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] ", ) .run(); @@ -1188,7 +1188,7 @@ fn cfg_rustflags_precedence() { [RUNNING] `rustc [..] --cfg bar[..]` [RUNNING] `rustc [..] --cfg bar[..]` [RUNNING] `rustc [..] --cfg bar[..]` -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] ", ) .run(); diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index e9eacee5dd8..7cb569b1456 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -39,7 +39,7 @@ fn cargo_test_simple() { .with_stderr( "\ [COMPILING] foo v0.5.0 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE]", ) .with_stdout_contains("test test_hello ... ok") @@ -231,7 +231,7 @@ fn cargo_test_verbose() { "\ [COMPILING] foo v0.5.0 ([CWD]) [RUNNING] `rustc [..] src/main.rs [..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] `[CWD]/target/debug/deps/foo-[..] hello` ", ) @@ -304,7 +304,7 @@ fn cargo_test_failing_test_in_bin() { .with_stderr( "\ [COMPILING] foo v0.5.0 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [ERROR] test failed, to rerun pass '--bin foo'", ) @@ -352,7 +352,7 @@ fn cargo_test_failing_test_in_test() { .with_stderr( "\ [COMPILING] foo v0.5.0 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [RUNNING] target/debug/deps/footest-[..][EXE] [ERROR] test failed, to rerun pass '--test footest'", @@ -391,7 +391,7 @@ fn cargo_test_failing_test_in_lib() { .with_stderr( "\ [COMPILING] foo v0.5.0 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [ERROR] test failed, to rerun pass '--lib'", ) @@ -465,7 +465,7 @@ fn test_with_lib_dep() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [RUNNING] target/debug/deps/baz-[..][EXE] [DOCTEST] foo", @@ -519,7 +519,7 @@ fn test_with_deep_lib_dep() { "\ [COMPILING] bar v0.0.1 ([..]) [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target[..] [DOCTEST] foo", ) @@ -568,7 +568,7 @@ fn external_test_explicit() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [RUNNING] target/debug/deps/test-[..][EXE] [DOCTEST] foo", @@ -628,7 +628,7 @@ fn external_test_implicit() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [RUNNING] target/debug/deps/external-[..][EXE] [DOCTEST] foo", @@ -669,7 +669,7 @@ fn pass_through_command_line() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] ", ) @@ -680,7 +680,7 @@ fn pass_through_command_line() { p.cargo("test foo") .with_stderr( "\ -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] ", ) @@ -745,7 +745,7 @@ fn lib_bin_same_name() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [RUNNING] target/debug/deps/foo-[..][EXE] [DOCTEST] foo", @@ -786,7 +786,7 @@ fn lib_with_standard_name() { .with_stderr( "\ [COMPILING] syntax v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/syntax-[..][EXE] [RUNNING] target/debug/deps/test-[..][EXE] [DOCTEST] syntax", @@ -832,7 +832,7 @@ fn lib_with_standard_name2() { .with_stderr( "\ [COMPILING] syntax v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/syntax-[..][EXE]", ) .with_stdout_contains("test test ... ok") @@ -873,7 +873,7 @@ fn lib_without_name() { .with_stderr( "\ [COMPILING] syntax v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/syntax-[..][EXE]", ) .with_stdout_contains("test test ... ok") @@ -1185,7 +1185,7 @@ fn test_dylib() { "\ [COMPILING] bar v0.0.1 ([CWD]/bar) [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [RUNNING] target/debug/deps/test-[..][EXE]", ) @@ -1196,7 +1196,7 @@ fn test_dylib() { p.cargo("test") .with_stderr( "\ -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [RUNNING] target/debug/deps/test-[..][EXE]", ) @@ -1225,7 +1225,7 @@ fn test_twice_with_build_cmd() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [DOCTEST] foo", ) @@ -1236,7 +1236,7 @@ fn test_twice_with_build_cmd() { p.cargo("test") .with_stderr( "\ -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [DOCTEST] foo", ) @@ -1253,7 +1253,7 @@ fn test_then_build() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [DOCTEST] foo", ) @@ -1274,7 +1274,7 @@ fn test_no_run() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] ", ) .run(); @@ -1308,7 +1308,7 @@ fn test_run_specific_bin_target() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/bin2-[..][EXE]", ) .with_stdout_contains("test test2 ... ok") @@ -1349,7 +1349,7 @@ fn test_run_implicit_bin_target() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/mybin-[..][EXE]", ) .with_stdout_contains("test test_in_bin ... ok") @@ -1369,7 +1369,7 @@ fn test_run_specific_test_target() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/b-[..][EXE]", ) .with_stdout_contains("test test_b ... ok") @@ -1409,7 +1409,7 @@ fn test_run_implicit_test_target() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/mybin-[..][EXE] [RUNNING] target/debug/deps/mytest-[..][EXE]", ) @@ -1450,7 +1450,7 @@ fn test_run_implicit_bench_target() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/mybin-[..][EXE] [RUNNING] target/debug/deps/mybench-[..][EXE]", ) @@ -1556,7 +1556,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out "\ [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc --crate-name foo src/lib.rs [..] --test [..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] `[CWD]/target/debug/deps/foo-[..] foo` ", ) @@ -1593,7 +1593,7 @@ fn test_no_harness() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/bar-[..][EXE] ", ) @@ -1665,7 +1665,7 @@ fn selective_testing() { .with_stderr( "\ [COMPILING] d1 v0.0.1 ([CWD]/d1) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/d1-[..][EXE] [RUNNING] target/debug/deps/d1-[..][EXE]", ) @@ -1677,7 +1677,7 @@ fn selective_testing() { .with_stderr( "\ [COMPILING] d2 v0.0.1 ([CWD]/d2) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/d2-[..][EXE] [RUNNING] target/debug/deps/d2-[..][EXE]", ) @@ -1689,7 +1689,7 @@ fn selective_testing() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE]", ) .with_stdout_contains("running 0 tests") @@ -1870,7 +1870,7 @@ fn selective_testing_with_docs() { .with_stderr( "\ [COMPILING] d1 v0.0.1 ([CWD]/d1) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/d1[..][EXE] [DOCTEST] d1", ) @@ -1891,7 +1891,7 @@ fn example_bin_same_name() { [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]` [RUNNING] `rustc [..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] ", ) .run(); @@ -1967,7 +1967,7 @@ fn example_with_dev_dep() { [..] [..] [RUNNING] `rustc --crate-name ex [..] --extern a=[..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] ", ) .run(); @@ -2033,7 +2033,7 @@ fn doctest_feature() { .with_stderr( "\ [COMPILING] foo [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo[..][EXE] [DOCTEST] foo", ) @@ -2110,7 +2110,7 @@ fn filter_no_doc_tests() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo[..][EXE]", ) .with_stdout_contains("running 0 tests") @@ -2149,7 +2149,7 @@ fn dylib_doctest() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [DOCTEST] foo", ) .with_stdout_contains("test [..] ... ok") @@ -2236,7 +2236,7 @@ fn cyclic_dev_dep_doc_test() { "\ [COMPILING] foo v0.0.1 ([..]) [COMPILING] bar v0.0.1 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo[..][EXE] [DOCTEST] foo", ) @@ -2332,7 +2332,7 @@ fn no_fail_fast() { .with_stderr_contains( "\ [COMPILING] foo v0.0.1 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [RUNNING] target/debug/deps/test_add_one-[..][EXE]", ) @@ -2429,7 +2429,7 @@ fn bin_does_not_rebuild_tests() { [COMPILING] foo v0.0.1 ([..]) [RUNNING] `rustc [..] src/main.rs [..]` [RUNNING] `rustc [..] src/main.rs [..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] ", ) .run(); @@ -2487,7 +2487,7 @@ fn selective_test_optional_dep() { [COMPILING] a v0.0.1 ([..]) [RUNNING] `rustc [..] a/src/lib.rs [..]` [RUNNING] `rustc [..] a/src/lib.rs [..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] ", ) .run(); @@ -2519,7 +2519,7 @@ fn only_test_docs() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [DOCTEST] foo", ) .with_stdout_contains("test [..] ... ok") @@ -2586,7 +2586,7 @@ fn cfg_test_even_with_no_harness() { "\ [COMPILING] foo v0.0.1 ([..]) [RUNNING] `rustc [..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] `[..]` ", ) @@ -3500,7 +3500,7 @@ fn doctest_skip_staticlib() { .with_stderr( "\ [COMPILING] foo [..] -[FINISHED] dev [..] +[FINISHED] test [..] [RUNNING] target/debug/deps/foo-[..]", ) .run(); @@ -3528,7 +3528,7 @@ pub fn foo() -> u8 { 1 } .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..] [DOCTEST] foo ", @@ -3552,7 +3552,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out p.cargo("test --lib") .with_stderr( "\ -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..]\n", ) .with_stdout( @@ -3618,7 +3618,7 @@ fn test_all_targets_lib() { .with_stderr( "\ [COMPILING] foo [..] -[FINISHED] dev [..] +[FINISHED] test [..] [RUNNING] [..]foo[..] ", ) diff --git a/tests/testsuite/tool_paths.rs b/tests/testsuite/tool_paths.rs index 9ba89670fe8..3616cc9692e 100644 --- a/tests/testsuite/tool_paths.rs +++ b/tests/testsuite/tool_paths.rs @@ -152,7 +152,7 @@ fn custom_runner() { "\ [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]` -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] `nonexistent-runner -r [..]/target/debug/deps/test-[..][EXE] --param` ", ) @@ -165,7 +165,7 @@ fn custom_runner() { [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]` [RUNNING] `rustc [..]` -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] `nonexistent-runner -r [..]/target/release/deps/bench-[..][EXE] --param --bench` ", ) From 913b69c15b360c531424298fbffb5c00e15d0ad4 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 1 Jun 2019 16:07:15 +0300 Subject: [PATCH 14/58] tests: adjust profile selection according to new code --- tests/testsuite/profile_targets.rs | 159 ++++++++++++++--------------- 1 file changed, 79 insertions(+), 80 deletions(-) diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index dbcf9a09fa3..49b8edf14bb 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -29,6 +29,8 @@ fn all_target_project() -> Project { codegen-units = 3 [profile.bench] codegen-units = 4 + [profile.check] + codegen-units = 5 "#, ) .file("src/lib.rs", "extern crate bar;") @@ -157,10 +159,10 @@ fn profile_selection_build_all_targets() { // ------ ------- ---- // lib dev+panic build (a normal lib target) // lib dev-panic build (used by tests/benches) - // lib test test - // test test test - // bench test test - // bin test test + // lib dev dev + // dev dev dev + // bench dev dev + // bin dev dev // bin dev build // example dev build p.cargo("build --all-targets -vv").with_stderr_unordered("\ @@ -174,11 +176,11 @@ fn profile_selection_build_all_targets() { [RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..]` -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C codegen-units=3 -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C codegen-units=1 -C debuginfo=2 --test [..]` [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..]` -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C codegen-units=3 -C debuginfo=2 --test [..]` -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C codegen-units=3 -C debuginfo=2 --test [..]` -[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C codegen-units=3 -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C codegen-units=1 -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C codegen-units=1 -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C codegen-units=1 -C debuginfo=2 --test [..]` [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..]` [RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..]` [FINISHED] dev [unoptimized + debuginfo] [..] @@ -222,10 +224,10 @@ fn profile_selection_build_all_targets_release() { // ------ ------- ---- // lib release+panic build (a normal lib target) // lib release-panic build (used by tests/benches) - // lib bench test (bench/test de-duped) - // test bench test - // bench bench test - // bin bench test (bench/test de-duped) + // lib release test (bench/test de-duped) + // test release test + // bench release test + // bin release test (bench/test de-duped) // bin release build // example release build p.cargo("build --all-targets --release -vv").with_stderr_unordered("\ @@ -239,11 +241,11 @@ fn profile_selection_build_all_targets_release() { [RUNNING] `[..]/target/release/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..]` -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..]` [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=2 [..]` -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..]` -[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..]` -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..]` +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..]` +[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..]` [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..]` [RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..]` [FINISHED] release [optimized] [..] @@ -268,40 +270,40 @@ fn profile_selection_test() { // - Dependency profiles: // Pkg Target Profile Reason // --- ------ ------- ------ - // bar lib dev For foo-bin - // bar lib dev-panic For tests/benches and bdep - // bdep lib dev-panic For foo build.rs - // foo custom dev-panic + // bar lib test For foo-bin + // bar lib test-panic For tests/benches and bdep + // bdep lib test-panic For foo build.rs + // foo custom test-panic // // - `foo` target list is: // Target Profile Mode // ------ ------- ---- - // lib dev-panic build (for tests) - // lib dev build (for bins) + // lib test-panic build (for tests) + // lib test build (for bins) // lib test test // test test test - // example dev-panic build + // example test-panic build // bin test test - // bin dev build + // bin test build // p.cargo("test -vv").with_stderr_unordered("\ [COMPILING] bar [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units=3 -C debuginfo=2 [..] [COMPILING] bdep [..] -[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] [COMPILING] foo [..] -[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] [RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C codegen-units=3 -C debuginfo=2 --test [..] [RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C codegen-units=3 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C codegen-units=3 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..] -[FINISHED] dev [unoptimized + debuginfo] [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C panic=abort -C codegen-units=3 -C debuginfo=2 [..] +[FINISHED] test [unoptimized + debuginfo] [..] [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` @@ -343,10 +345,10 @@ fn profile_selection_test_release() { // ------ ------- ---- // lib release-panic build (for tests) // lib release build (for bins) - // lib bench test - // test bench test + // lib release test + // test release test // example release-panic build - // bin bench test + // bin release test // bin release build // p.cargo("test --release -vv").with_stderr_unordered("\ @@ -361,9 +363,9 @@ fn profile_selection_test_release() { [foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..] -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..] +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..] [RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] [FINISHED] release [optimized] [..] @@ -399,38 +401,38 @@ fn profile_selection_bench() { // - Dependency profiles: // Pkg Target Profile Reason // --- ------ ------- ------ - // bar lib release For foo-bin - // bar lib release-panic For tests/benches and bdep - // bdep lib release-panic For foo build.rs - // foo custom release-panic + // bar lib bench For foo-bin + // bar lib bench-panic For tests/benches and bdep + // bdep lib bench-panic For foo build.rs + // foo custom bench-panic // // - `foo` target list is: // Target Profile Mode // ------ ------- ---- - // lib release-panic build (for benches) - // lib release build (for bins) + // lib bench-panic build (for benches) + // lib bench build (for bins) // lib bench test(bench) // bench bench test(bench) // bin bench test(bench) - // bin release build + // bin bench build // p.cargo("bench -vv").with_stderr_unordered("\ [COMPILING] bar [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=4 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=4 [..] [COMPILING] bdep [..] -[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] +[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=4 [..] [COMPILING] foo [..] -[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] +[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C codegen-units=4 [..] [RUNNING] `[..]target/release/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=4 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=4 [..] [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..] [RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..] [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] -[FINISHED] release [optimized] [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=4 [..] +[FINISHED] bench [optimized] [..] [RUNNING] `[..]/deps/foo-[..] --bench` [RUNNING] `[..]/deps/foo-[..] --bench` [RUNNING] `[..]/deps/bench1-[..] --bench` @@ -561,46 +563,43 @@ fn profile_selection_check_all_targets_release() { fn profile_selection_check_all_targets_test() { let p = all_target_project(); // `check --profile=test` - // NOTES: - // - This doesn't actually use the "test" profile. Everything uses "dev". - // It should probably use "test", although it probably doesn't really matter. // - Dependency profiles: // Pkg Target Profile Action Reason // --- ------ ------- ------ ------ - // bar lib dev* link For bdep - // bar lib dev-panic metadata For tests/benches - // bdep lib dev* link For foo build.rs - // foo custom dev* link For build.rs + // bar lib test* link For bdep + // bar lib test-panic metdata For tests/benches + // bdep lib test* link For foo build.rs + // foo custom test* link For build.rs // // `*` = wants panic, but it is cleared when args are built. // // - foo target list is: - // Target Profile Mode - // ------ ------- ---- - // lib dev-panic check-test (for tests/benches) - // lib dev-panic check-test (checking lib as a unittest) - // example dev-panic check-test - // test dev-panic check-test - // bench dev-panic check-test - // bin dev-panic check-test + // Target Profile Mode + // ------ ------- ---- + // lib test-panic check-test (for tests/benches) + // lib test-panic check-test (checking lib as a unittest) + // example test-panic check-test + // test test-panic check-test + // bench test-panic check-test + // bin test-panic check-test // p.cargo("check --all-targets --profile=test -vv").with_stderr_unordered("\ [COMPILING] bar [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]metadata -C codegen-units=1 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]metadata -C codegen-units=3 -C debuginfo=2 [..] [COMPILING] bdep[..] -[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] [COMPILING] foo [..] -[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] [RUNNING] `[..]target/debug/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]metadata -C codegen-units=1 -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]metadata -C codegen-units=1 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]metadata -C codegen-units=1 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]metadata -C codegen-units=1 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]metadata -C codegen-units=1 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--emit=[..]metadata -C codegen-units=1 -C debuginfo=2 --test [..] -[FINISHED] dev [unoptimized + debuginfo] [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]metadata -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]metadata -C codegen-units=3 -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]metadata -C codegen-units=3 -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]metadata -C codegen-units=3 -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]metadata -C codegen-units=3 -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--emit=[..]metadata -C codegen-units=3 -C debuginfo=2 --test [..] +[FINISHED] test [unoptimized + debuginfo] [..] ").run(); p.cargo("check --all-targets --profile=test -vv") From b0db19338a6a54ba16699a0bc1186b9df69947f7 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 8 Jun 2019 17:43:42 +0300 Subject: [PATCH 15/58] tests: fix finished line for 3 other tests --- tests/testsuite/cross_compile.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index e98d0b04456..eef809f6b92 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -535,7 +535,7 @@ fn cross_tests() { .with_stderr(&format!( "\ [COMPILING] foo v0.0.0 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/{triple}/debug/deps/foo-[..][EXE] [RUNNING] target/{triple}/debug/deps/bar-[..][EXE]", triple = target @@ -595,7 +595,7 @@ fn no_cross_doctests() { .with_stderr(&format!( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/{triple}/debug/deps/foo-[..][EXE] ", triple = target @@ -1224,7 +1224,7 @@ fn cross_test_dylib() { "\ [COMPILING] bar v0.0.1 ([CWD]/bar) [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/{arch}/debug/deps/foo-[..][EXE] [RUNNING] target/{arch}/debug/deps/test-[..][EXE]", arch = cross_compile::alternate() From ef59837c77a39e16ca5e23ca8ff6434c9156e9bf Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sun, 9 Jun 2019 09:11:02 +0300 Subject: [PATCH 16/58] tests: fix missing finished line changes in no_cross_doctests --- tests/testsuite/cross_compile.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index eef809f6b92..819bd860588 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -565,7 +565,7 @@ fn no_cross_doctests() { let host_output = "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/foo-[..][EXE] [DOCTEST] foo "; @@ -580,7 +580,7 @@ fn no_cross_doctests() { .with_stderr(&format!( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/{triple}/debug/deps/foo-[..][EXE] [DOCTEST] foo ", From 03b054392d98fed90fb3d3bc3736b28b413d240c Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sun, 9 Jun 2019 20:32:09 +0300 Subject: [PATCH 17/58] tests: fix nightly-only test with regard to the Finished line --- tests/testsuite/bench.rs | 46 ++++++++++++++-------------- tests/testsuite/required_features.rs | 22 ++++++------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/testsuite/bench.rs b/tests/testsuite/bench.rs index 93f2059a7e6..a8b38661fab 100644 --- a/tests/testsuite/bench.rs +++ b/tests/testsuite/bench.rs @@ -41,7 +41,7 @@ fn cargo_bench_simple() { .with_stderr( "\ [COMPILING] foo v0.5.0 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_stdout_contains("test bench_hello ... bench: [..]") @@ -84,7 +84,7 @@ fn bench_bench_implicit() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE] [RUNNING] target/release/deps/mybench-[..][EXE] ", @@ -129,7 +129,7 @@ fn bench_bin_implicit() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE] ", ) @@ -164,7 +164,7 @@ fn bench_tarname() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/bin2-[..][EXE] ", ) @@ -234,7 +234,7 @@ fn cargo_bench_verbose() { "\ [COMPILING] foo v0.5.0 ([CWD]) [RUNNING] `rustc [..] src/main.rs [..]` -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] `[..]target/release/deps/foo-[..][EXE] hello --bench`", ) .with_stdout_contains("test bench_hello ... bench: [..]") @@ -328,7 +328,7 @@ fn cargo_bench_failing_test() { .with_stderr_contains( "\ [COMPILING] foo v0.5.0 ([CWD])[..] -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_either_contains( @@ -400,7 +400,7 @@ fn bench_with_lib_dep() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE] [RUNNING] target/release/deps/baz-[..][EXE]", ) @@ -465,7 +465,7 @@ fn bench_with_deep_lib_dep() { "\ [COMPILING] foo v0.0.1 ([..]) [COMPILING] bar v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/bar-[..][EXE]", ) .with_stdout_contains("test bar_bench ... bench: [..]") @@ -522,7 +522,7 @@ fn external_bench_explicit() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE] [RUNNING] target/release/deps/bench-[..][EXE]", ) @@ -569,7 +569,7 @@ fn external_bench_implicit() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE] [RUNNING] target/release/deps/external-[..][EXE]", ) @@ -645,7 +645,7 @@ automatically infer them to be a target, such as in subfolders. For more information on this warning you can consult https://github.com/rust-lang/cargo/issues/5330 [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE] ", ) @@ -692,7 +692,7 @@ fn pass_through_command_line() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_stdout_contains("test bar ... bench: [..]") @@ -700,7 +700,7 @@ fn pass_through_command_line() { p.cargo("bench foo") .with_stderr( - "[FINISHED] release [optimized] target(s) in [..] + "[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_stdout_contains("test foo ... bench: [..]") @@ -785,7 +785,7 @@ fn lib_bin_same_name() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE] [RUNNING] target/release/deps/foo-[..][EXE]", ) @@ -834,7 +834,7 @@ fn lib_with_standard_name() { .with_stderr( "\ [COMPILING] syntax v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/syntax-[..][EXE] [RUNNING] target/release/deps/bench-[..][EXE]", ) @@ -886,7 +886,7 @@ fn lib_with_standard_name2() { .with_stderr( "\ [COMPILING] syntax v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/syntax-[..][EXE]", ) .with_stdout_contains("test bench ... bench: [..]") @@ -966,7 +966,7 @@ fn bench_dylib() { [RUNNING] [..] -C opt-level=3 [..] [RUNNING] [..] -C opt-level=3 [..] [RUNNING] [..] -C opt-level=3 [..] -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] `[..]target/release/deps/foo-[..][EXE] --bench` [RUNNING] `[..]target/release/deps/bench-[..][EXE] --bench`", ) @@ -979,7 +979,7 @@ fn bench_dylib() { "\ [FRESH] bar v0.0.1 ([CWD]/bar) [FRESH] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] `[..]target/release/deps/foo-[..][EXE] --bench` [RUNNING] `[..]target/release/deps/bench-[..][EXE] --bench`", ) @@ -1021,7 +1021,7 @@ fn bench_twice_with_build_cmd() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_stdout_contains("test foo ... bench: [..]") @@ -1029,7 +1029,7 @@ fn bench_twice_with_build_cmd() { p.cargo("bench") .with_stderr( - "[FINISHED] release [optimized] target(s) in [..] + "[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_stdout_contains("test foo ... bench: [..]") @@ -1114,7 +1114,7 @@ fn bench_with_examples() { [RUNNING] `rustc [..]` [RUNNING] `rustc [..]` [RUNNING] `rustc [..]` -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] `[CWD]/target/release/deps/foo-[..][EXE] --bench` [RUNNING] `[CWD]/target/release/deps/testb1-[..][EXE] --bench`", ) @@ -1156,7 +1156,7 @@ fn test_a_bench() { .with_stderr( "\ [COMPILING] foo v0.1.0 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] [RUNNING] target/debug/deps/b-[..][EXE]", ) .with_stdout_contains("test foo ... ok") @@ -1190,7 +1190,7 @@ fn test_bench_no_run() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([..]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] ", ) .run(); diff --git a/tests/testsuite/required_features.rs b/tests/testsuite/required_features.rs index 3273cf387c9..28c57efb666 100644 --- a/tests/testsuite/required_features.rs +++ b/tests/testsuite/required_features.rs @@ -449,21 +449,21 @@ fn bench_default_features() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_stdout_contains("test bench ... bench: [..]") .run(); p.cargo("bench --no-default-features") - .with_stderr("[FINISHED] release [optimized] target(s) in [..]".to_string()) + .with_stderr("[FINISHED] bench [optimized] target(s) in [..]".to_string()) .with_stdout("") .run(); p.cargo("bench --bench=foo") .with_stderr( "\ -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_stdout_contains("test bench ... bench: [..]") @@ -519,7 +519,7 @@ fn bench_arg_features() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_stdout_contains("test bench ... bench: [..]") @@ -582,7 +582,7 @@ fn bench_multiple_required_features() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo_2-[..][EXE]", ) .with_stdout_contains("test bench ... bench: [..]") @@ -592,7 +592,7 @@ fn bench_multiple_required_features() { .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo_1-[..][EXE] [RUNNING] target/release/deps/foo_2-[..][EXE]", ) @@ -600,7 +600,7 @@ fn bench_multiple_required_features() { .run(); p.cargo("bench --no-default-features") - .with_stderr("[FINISHED] release [optimized] target(s) in [..]") + .with_stderr("[FINISHED] bench [optimized] target(s) in [..]") .with_stdout("") .run(); } @@ -860,7 +860,7 @@ fn dep_feature_in_toml() { "\ [COMPILING] bar v0.0.1 ([CWD]/bar) [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_stdout_contains("test bench ... bench: [..]") @@ -981,7 +981,7 @@ Consider enabling them by passing, e.g., `--features=\"bar/a\"` // bench if is_nightly() { p.cargo("bench") - .with_stderr("[FINISHED] release [optimized] target(s) in [..]") + .with_stderr("[FINISHED] bench [optimized] target(s) in [..]") .with_stdout("") .run(); @@ -990,7 +990,7 @@ Consider enabling them by passing, e.g., `--features=\"bar/a\"` "\ [COMPILING] bar v0.0.1 ([CWD]/bar) [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_stdout_contains("test bench ... bench: [..]") @@ -1064,7 +1064,7 @@ error[E0463]: can't find crate for `bar`", .with_stderr( "\ [COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] release [optimized] target(s) in [..] +[FINISHED] bench [optimized] target(s) in [..] [RUNNING] target/release/deps/foo-[..][EXE]", ) .with_stdout_contains("running 0 tests") From 756ab7d5a036c90e10b9d3d6e6d73d52f68207df Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 20 Jun 2019 15:00:47 +0300 Subject: [PATCH 18/58] Add a named-profiles unstable feature gate This affects `--profile`, and the `dir-name` profile attribute. --- src/cargo/core/features.rs | 5 +++++ src/cargo/core/profiles.rs | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index ccb4808ee2e..828a69d67fe 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -202,6 +202,9 @@ features! { // Specifying the 'public' attribute on dependencies [unstable] public_dependency: bool, + + // Allow to specify profiles other than 'dev', 'release', 'test', etc. + [unstable] named_profiles: bool, } } @@ -332,6 +335,7 @@ pub struct CliUnstable { pub mtime_on_use: bool, pub install_upgrade: bool, pub cache_messages: bool, + pub named_profiles: bool, } impl CliUnstable { @@ -377,6 +381,7 @@ impl CliUnstable { "mtime-on-use" => self.mtime_on_use = true, "install-upgrade" => self.install_upgrade = true, "cache-messages" => self.cache_messages = true, + "named-profiles" => self.named_profiles = true, _ => failure::bail!("unknown `-Z` flag specified: {}", k), } diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 1eb64422bdf..85daabed563 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -6,7 +6,7 @@ use serde::Deserialize; use crate::core::compiler::{ProfileKind, CompileMode}; use crate::core::interning::InternedString; -use crate::core::{Features, PackageId, PackageIdSpec, PackageSet, Shell}; +use crate::core::{Features, Feature, PackageId, PackageIdSpec, PackageSet, Shell}; use crate::util::errors::CargoResultExt; use crate::util::lev_distance::lev_distance; use crate::util::toml::{ProfilePackageSpec, StringOrBool, TomlProfile, TomlProfiles, U32OrBool}; @@ -55,6 +55,22 @@ impl Profiles { BTreeMap::new() }; + // Feature gating + for (profile_name, profile) in &profiles { + match profile_name.as_str() { + "dev" | "release" | "bench" | "test" | "doc" => { + if profile.dir_name.is_some() { + features.require(Feature::named_profiles())?; + break; + } + }, + _ => { + features.require(Feature::named_profiles())?; + break; + } + } + } + // Merge with predefined profiles use std::collections::btree_map::Entry; for (predef_name, mut predef_prof) in Self::predefined_profiles().into_iter() { From bfe2e58feb8c5f6a4de2d3e5d168c7a3f050af9f Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 20 Jun 2019 15:56:20 +0300 Subject: [PATCH 19/58] Gate the usage of `--profile` on `unstable-options` --- src/bin/cargo/commands/bench.rs | 2 +- src/bin/cargo/commands/clean.rs | 2 +- src/bin/cargo/commands/install.rs | 2 +- src/bin/cargo/commands/test.rs | 2 +- src/cargo/util/command_prelude.rs | 10 ++++++++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/bin/cargo/commands/bench.rs b/src/bin/cargo/commands/bench.rs index 04305cf15aa..7aaf18eb2f9 100644 --- a/src/bin/cargo/commands/bench.rs +++ b/src/bin/cargo/commands/bench.rs @@ -76,7 +76,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let mut compile_opts = args.compile_options(config, CompileMode::Bench, Some(&ws))?; compile_opts.build_config.profile_kind = - args.get_profile_kind(ProfileKind::Custom("bench".to_owned()))?; + args.get_profile_kind(config, ProfileKind::Custom("bench".to_owned()))?; let ops = TestOptions { no_run: args.is_present("no-run"), diff --git a/src/bin/cargo/commands/clean.rs b/src/bin/cargo/commands/clean.rs index bc4ba21c32e..ff789e043e7 100644 --- a/src/bin/cargo/commands/clean.rs +++ b/src/bin/cargo/commands/clean.rs @@ -29,7 +29,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { config, spec: values(args, "package"), target: args.target(), - profile_kind: args.get_profile_kind(ProfileKind::Dev)?, + profile_kind: args.get_profile_kind(config, ProfileKind::Dev)?, release: args.is_present("release"), profile_specified: args.is_present("profile"), doc: args.is_present("doc"), diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index a2853bac47c..e69bb1e7d38 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -116,7 +116,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let workspace = args.workspace(config).ok(); let mut compile_opts = args.compile_options(config, CompileMode::Build, workspace.as_ref())?; - compile_opts.build_config.profile_kind = args.get_profile_kind(ProfileKind::Release)?; + compile_opts.build_config.profile_kind = args.get_profile_kind(config, ProfileKind::Release)?; let krates = args .values_of("crate") diff --git a/src/bin/cargo/commands/test.rs b/src/bin/cargo/commands/test.rs index 9a0579b491a..aa2b0863630 100644 --- a/src/bin/cargo/commands/test.rs +++ b/src/bin/cargo/commands/test.rs @@ -103,7 +103,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let mut compile_opts = args.compile_options(config, CompileMode::Test, Some(&ws))?; compile_opts.build_config.profile_kind = - args.get_profile_kind(ProfileKind::Custom("test".to_owned()))?; + args.get_profile_kind(config, ProfileKind::Custom("test".to_owned()))?; // `TESTNAME` is actually an argument of the test binary, but it's // important, so we explicitly mention it and reconfigure. diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 1a0ede68629..3ad6946cf35 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -292,7 +292,7 @@ pub trait ArgMatchesExt { self._value_of("target").map(|s| s.to_string()) } - fn get_profile_kind(&self, default: ProfileKind) -> CargoResult { + fn get_profile_kind(&self, config: &Config, default: ProfileKind) -> CargoResult { let specified_profile = match self._value_of("profile") { None => None, Some("dev") => Some(ProfileKind::Dev), @@ -300,6 +300,12 @@ pub trait ArgMatchesExt { Some(name) => Some(ProfileKind::Custom(name.to_string())), }; + if specified_profile.is_some() { + if !config.cli_unstable().unstable_options { + failure::bail!("Usage of `--profile` requires `-Z unstable-options`") + } + } + if self._is_present("release") { match specified_profile { None | Some(ProfileKind::Release) => { @@ -352,7 +358,7 @@ pub trait ArgMatchesExt { let mut build_config = BuildConfig::new(config, self.jobs()?, &self.target(), mode)?; build_config.message_format = message_format; - build_config.profile_kind = self.get_profile_kind(ProfileKind::Dev)?; + build_config.profile_kind = self.get_profile_kind(config, ProfileKind::Dev)?; build_config.build_plan = self._is_present("build-plan"); if build_config.build_plan { config From 99ced526d9707072d46d5de186957504264f3d2b Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 20 Jun 2019 15:57:19 +0300 Subject: [PATCH 20/58] named-profiles: add `--profile` to install Relates to #6992. --- src/bin/cargo/commands/install.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index e69bb1e7d38..5669f24a0ae 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -51,6 +51,7 @@ pub fn cli() -> App { "Do not save tracking information (unstable)", )) .arg_features() + .arg_profile("Install artifacts with from the specified profile") .arg(opt("debug", "Build in debug mode instead of release mode")) .arg_targets_bins_examples( "Install only the specified binary", From 14c3b3be3f8b4dc094a0c81cb39618bee449bb10 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 20 Jun 2019 16:02:04 +0300 Subject: [PATCH 21/58] profiles: fn process_customs() does not need 'pub' --- src/cargo/core/profiles.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 85daabed563..8448fe6a87d 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -136,7 +136,7 @@ impl Profiles { ] } - pub fn process_customs(&mut self, profiles: &BTreeMap) + fn process_customs(&mut self, profiles: &BTreeMap) -> CargoResult<()> { for (name, profile) in profiles { From 2f81adb115a826a45f5f989ea6a506b9458872d1 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 20 Jun 2019 18:32:28 +0300 Subject: [PATCH 22/58] named-profiles: feature gate exemptions To preserve old `profile` behavior, some cases of `--profile` should not trigger an error. Plus, the 'check' profile should be allowed for profile selection tests and `rustc --profile=check`. --- src/bin/cargo/commands/bench.rs | 6 ++++-- src/bin/cargo/commands/build.rs | 3 ++- src/bin/cargo/commands/check.rs | 2 +- src/bin/cargo/commands/clean.rs | 2 +- src/bin/cargo/commands/clippy.rs | 2 +- src/bin/cargo/commands/doc.rs | 2 +- src/bin/cargo/commands/fix.rs | 2 +- src/bin/cargo/commands/install.rs | 6 ++++-- src/bin/cargo/commands/run.rs | 3 ++- src/bin/cargo/commands/rustc.rs | 3 ++- src/bin/cargo/commands/rustdoc.rs | 1 + src/bin/cargo/commands/test.rs | 6 ++++-- src/cargo/core/profiles.rs | 2 +- src/cargo/util/command_prelude.rs | 27 +++++++++++++++++++++------ tests/testsuite/bad_config.rs | 5 ++++- 15 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/bin/cargo/commands/bench.rs b/src/bin/cargo/commands/bench.rs index 7aaf18eb2f9..5dc7ec254b7 100644 --- a/src/bin/cargo/commands/bench.rs +++ b/src/bin/cargo/commands/bench.rs @@ -73,10 +73,12 @@ 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, Some(&ws))?; + let mut compile_opts = args.compile_options(config, CompileMode::Bench, Some(&ws), + ProfileChecking::Checked)?; compile_opts.build_config.profile_kind = - args.get_profile_kind(config, ProfileKind::Custom("bench".to_owned()))?; + args.get_profile_kind(config, ProfileKind::Custom("bench".to_owned()), + ProfileChecking::Checked)?; let ops = TestOptions { no_run: args.is_present("no-run"), diff --git a/src/bin/cargo/commands/build.rs b/src/bin/cargo/commands/build.rs index cb615ae4169..7c774b5b472 100644 --- a/src/bin/cargo/commands/build.rs +++ b/src/bin/cargo/commands/build.rs @@ -56,7 +56,8 @@ the --release flag will use the `release` profile instead. pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let ws = args.workspace(config)?; - let mut compile_opts = args.compile_options(config, CompileMode::Build, Some(&ws))?; + let mut compile_opts = args.compile_options(config, CompileMode::Build, Some(&ws), + ProfileChecking::Checked)?; compile_opts.export_dir = args.value_of_path("out-dir", config); if compile_opts.export_dir.is_some() { diff --git a/src/bin/cargo/commands/check.rs b/src/bin/cargo/commands/check.rs index 095b69a996e..3d8feefe43e 100644 --- a/src/bin/cargo/commands/check.rs +++ b/src/bin/cargo/commands/check.rs @@ -69,7 +69,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { } }; let mode = CompileMode::Check { test }; - let compile_opts = args.compile_options(config, mode, Some(&ws))?; + let compile_opts = args.compile_options(config, mode, Some(&ws), ProfileChecking::Unchecked)?; ops::compile(&ws, &compile_opts)?; Ok(()) diff --git a/src/bin/cargo/commands/clean.rs b/src/bin/cargo/commands/clean.rs index ff789e043e7..dc57aab5a07 100644 --- a/src/bin/cargo/commands/clean.rs +++ b/src/bin/cargo/commands/clean.rs @@ -29,7 +29,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { config, spec: values(args, "package"), target: args.target(), - profile_kind: args.get_profile_kind(config, ProfileKind::Dev)?, + profile_kind: args.get_profile_kind(config, ProfileKind::Dev, ProfileChecking::Checked)?, release: args.is_present("release"), profile_specified: args.is_present("profile"), doc: args.is_present("doc"), diff --git a/src/bin/cargo/commands/clippy.rs b/src/bin/cargo/commands/clippy.rs index ba2cf599057..66101996822 100644 --- a/src/bin/cargo/commands/clippy.rs +++ b/src/bin/cargo/commands/clippy.rs @@ -61,7 +61,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let ws = args.workspace(config)?; let mode = CompileMode::Check { test: false }; - let mut compile_opts = args.compile_options(config, mode, Some(&ws))?; + let mut compile_opts = args.compile_options(config, mode, Some(&ws), ProfileChecking::Checked)?; if !config.cli_unstable().unstable_options { return Err(failure::format_err!( diff --git a/src/bin/cargo/commands/doc.rs b/src/bin/cargo/commands/doc.rs index a3c92b8e566..b15fae7555a 100644 --- a/src/bin/cargo/commands/doc.rs +++ b/src/bin/cargo/commands/doc.rs @@ -52,7 +52,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let mode = CompileMode::Doc { deps: !args.is_present("no-deps"), }; - let mut compile_opts = args.compile_options(config, mode, Some(&ws))?; + let mut compile_opts = args.compile_options(config, mode, Some(&ws), ProfileChecking::Checked)?; compile_opts.local_rustdoc_args = if args.is_present("document-private-items") { Some(vec!["--document-private-items".to_string()]) } else { diff --git a/src/bin/cargo/commands/fix.rs b/src/bin/cargo/commands/fix.rs index 9229be3fb5d..c2253c3da78 100644 --- a/src/bin/cargo/commands/fix.rs +++ b/src/bin/cargo/commands/fix.rs @@ -123,7 +123,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { // Unlike other commands default `cargo fix` to all targets to fix as much // code as we can. - let mut opts = args.compile_options(config, mode, Some(&ws))?; + let mut opts = args.compile_options(config, mode, Some(&ws), ProfileChecking::Unchecked)?; if let CompileFilter::Default { .. } = opts.filter { opts.filter = CompileFilter::Only { diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 05f12a64164..62f246f7afb 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -116,9 +116,11 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { } let workspace = args.workspace(config).ok(); - let mut compile_opts = args.compile_options(config, CompileMode::Build, workspace.as_ref())?; + let mut compile_opts = args.compile_options(config, CompileMode::Build, workspace.as_ref(), + ProfileChecking::Checked)?; - compile_opts.build_config.profile_kind = args.get_profile_kind(config, ProfileKind::Release)?; + compile_opts.build_config.profile_kind = args.get_profile_kind(config, ProfileKind::Release, + ProfileChecking::Checked)?; let krates = args .values_of("crate") diff --git a/src/bin/cargo/commands/run.rs b/src/bin/cargo/commands/run.rs index b2d75f50865..b0ecbc53f31 100644 --- a/src/bin/cargo/commands/run.rs +++ b/src/bin/cargo/commands/run.rs @@ -41,7 +41,8 @@ run. If you're passing arguments to both Cargo and the binary, the ones after pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let ws = args.workspace(config)?; - let mut compile_opts = args.compile_options(config, CompileMode::Build, Some(&ws))?; + let mut compile_opts = args.compile_options(config, CompileMode::Build, Some(&ws), + ProfileChecking::Checked)?; if !args.is_present("example") && !args.is_present("bin") { let default_runs: Vec<_> = compile_opts diff --git a/src/bin/cargo/commands/rustc.rs b/src/bin/cargo/commands/rustc.rs index 519fe1b26c5..75266bee05b 100644 --- a/src/bin/cargo/commands/rustc.rs +++ b/src/bin/cargo/commands/rustc.rs @@ -63,7 +63,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { return Err(CliError::new(err, 101)); } }; - let mut compile_opts = args.compile_options_for_single_package(config, mode, Some(&ws))?; + let mut compile_opts = args.compile_options_for_single_package( + config, mode, Some(&ws), ProfileChecking::Unchecked)?; let target_args = values(args, "args"); compile_opts.target_rustc_args = if target_args.is_empty() { None diff --git a/src/bin/cargo/commands/rustdoc.rs b/src/bin/cargo/commands/rustdoc.rs index 385c60f1470..f3c691658da 100644 --- a/src/bin/cargo/commands/rustdoc.rs +++ b/src/bin/cargo/commands/rustdoc.rs @@ -56,6 +56,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { config, CompileMode::Doc { deps: false }, Some(&ws), + ProfileChecking::Checked, )?; let target_args = values(args, "args"); compile_opts.target_rustdoc_args = if target_args.is_empty() { diff --git a/src/bin/cargo/commands/test.rs b/src/bin/cargo/commands/test.rs index aa2b0863630..a079a028237 100644 --- a/src/bin/cargo/commands/test.rs +++ b/src/bin/cargo/commands/test.rs @@ -100,10 +100,12 @@ To get the list of all options available for the test binaries use this: pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let ws = args.workspace(config)?; - let mut compile_opts = args.compile_options(config, CompileMode::Test, Some(&ws))?; + let mut compile_opts = args.compile_options(config, CompileMode::Test, Some(&ws), + ProfileChecking::Checked)?; compile_opts.build_config.profile_kind = - args.get_profile_kind(config, ProfileKind::Custom("test".to_owned()))?; + args.get_profile_kind(config, ProfileKind::Custom("test".to_owned()), + ProfileChecking::Checked)?; // `TESTNAME` is actually an argument of the test binary, but it's // important, so we explicitly mention it and reconfigure. diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 8448fe6a87d..4d72e634ee8 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -58,7 +58,7 @@ impl Profiles { // Feature gating for (profile_name, profile) in &profiles { match profile_name.as_str() { - "dev" | "release" | "bench" | "test" | "doc" => { + "dev" | "release" | "bench" | "test" | "doc" | "check" => { if profile.dir_name.is_some() { features.require(Feature::named_profiles())?; break; diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 3ad6946cf35..68ece69e1dc 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -240,6 +240,11 @@ pub fn subcommand(name: &'static str) -> App { ]) } +pub enum ProfileChecking { + Checked, + Unchecked, +} + pub trait ArgMatchesExt { fn value_of_u32(&self, name: &str) -> CargoResult> { let arg = match self._value_of(name) { @@ -292,7 +297,9 @@ pub trait ArgMatchesExt { self._value_of("target").map(|s| s.to_string()) } - fn get_profile_kind(&self, config: &Config, default: ProfileKind) -> CargoResult { + fn get_profile_kind(&self, config: &Config, default: ProfileKind, profile_checking: ProfileChecking) + -> CargoResult + { let specified_profile = match self._value_of("profile") { None => None, Some("dev") => Some(ProfileKind::Dev), @@ -300,9 +307,14 @@ pub trait ArgMatchesExt { Some(name) => Some(ProfileKind::Custom(name.to_string())), }; - if specified_profile.is_some() { - if !config.cli_unstable().unstable_options { - failure::bail!("Usage of `--profile` requires `-Z unstable-options`") + match profile_checking { + ProfileChecking::Unchecked => {}, + ProfileChecking::Checked => { + if specified_profile.is_some() { + if !config.cli_unstable().unstable_options { + failure::bail!("Usage of `--profile` requires `-Z unstable-options`") + } + } } } @@ -334,6 +346,7 @@ pub trait ArgMatchesExt { config: &'a Config, mode: CompileMode, workspace: Option<&Workspace<'a>>, + profile_checking: ProfileChecking, ) -> CargoResult> { let spec = Packages::from_flags( self._is_present("all"), @@ -358,7 +371,8 @@ pub trait ArgMatchesExt { let mut build_config = BuildConfig::new(config, self.jobs()?, &self.target(), mode)?; build_config.message_format = message_format; - build_config.profile_kind = self.get_profile_kind(config, ProfileKind::Dev)?; + build_config.profile_kind = self.get_profile_kind(config, ProfileKind::Dev, + profile_checking)?; build_config.build_plan = self._is_present("build-plan"); if build_config.build_plan { config @@ -403,8 +417,9 @@ pub trait ArgMatchesExt { config: &'a Config, mode: CompileMode, workspace: Option<&Workspace<'a>>, + profile_checking: ProfileChecking, ) -> CargoResult> { - let mut compile_opts = self.compile_options(config, mode, workspace)?; + let mut compile_opts = self.compile_options(config, mode, workspace, profile_checking)?; compile_opts.spec = Packages::Packages(self._values_of("package")); Ok(compile_opts) } diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 2c97d084ad5..2abb1297115 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -692,6 +692,8 @@ warning: unused manifest key: target.foo.bar .file( "Cargo.toml", r#" + cargo-features = ["named-profiles"] + [package] name = "foo" version = "0.1.0" @@ -705,7 +707,8 @@ warning: unused manifest key: target.foo.bar .file("src/lib.rs", "") .build(); - p.cargo("build") + p.cargo("build -Z named-profiles") + .masquerade_as_nightly_cargo() .run(); let p = project() From 29b7e90ba37f311baaf448894bbf04721bed5791 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 20 Jun 2019 19:43:33 +0300 Subject: [PATCH 23/58] named-profiles: formatting fixes from 'cargo fmt' --- src/bin/cargo/commands/bench.rs | 16 ++-- src/bin/cargo/commands/build.rs | 8 +- src/bin/cargo/commands/clippy.rs | 3 +- src/bin/cargo/commands/doc.rs | 3 +- src/bin/cargo/commands/install.rs | 14 +-- src/bin/cargo/commands/run.rs | 8 +- src/bin/cargo/commands/rustc.rs | 6 +- src/bin/cargo/commands/test.rs | 18 ++-- src/cargo/core/compiler/job_queue.rs | 2 +- src/cargo/core/profiles.rs | 129 +++++++++++++++------------ src/cargo/util/command_prelude.rs | 33 +++---- 11 files changed, 138 insertions(+), 102 deletions(-) diff --git a/src/bin/cargo/commands/bench.rs b/src/bin/cargo/commands/bench.rs index 5dc7ec254b7..512cf63e784 100644 --- a/src/bin/cargo/commands/bench.rs +++ b/src/bin/cargo/commands/bench.rs @@ -73,12 +73,18 @@ 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, Some(&ws), - ProfileChecking::Checked)?; + let mut compile_opts = args.compile_options( + config, + CompileMode::Bench, + Some(&ws), + ProfileChecking::Checked, + )?; - compile_opts.build_config.profile_kind = - args.get_profile_kind(config, ProfileKind::Custom("bench".to_owned()), - ProfileChecking::Checked)?; + compile_opts.build_config.profile_kind = args.get_profile_kind( + config, + ProfileKind::Custom("bench".to_owned()), + ProfileChecking::Checked, + )?; let ops = TestOptions { no_run: args.is_present("no-run"), diff --git a/src/bin/cargo/commands/build.rs b/src/bin/cargo/commands/build.rs index 7c774b5b472..ff22c33df5f 100644 --- a/src/bin/cargo/commands/build.rs +++ b/src/bin/cargo/commands/build.rs @@ -56,8 +56,12 @@ the --release flag will use the `release` profile instead. pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let ws = args.workspace(config)?; - let mut compile_opts = args.compile_options(config, CompileMode::Build, Some(&ws), - ProfileChecking::Checked)?; + let mut compile_opts = args.compile_options( + config, + CompileMode::Build, + Some(&ws), + ProfileChecking::Checked, + )?; compile_opts.export_dir = args.value_of_path("out-dir", config); if compile_opts.export_dir.is_some() { diff --git a/src/bin/cargo/commands/clippy.rs b/src/bin/cargo/commands/clippy.rs index 66101996822..7d31c39a5eb 100644 --- a/src/bin/cargo/commands/clippy.rs +++ b/src/bin/cargo/commands/clippy.rs @@ -61,7 +61,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let ws = args.workspace(config)?; let mode = CompileMode::Check { test: false }; - let mut compile_opts = args.compile_options(config, mode, Some(&ws), ProfileChecking::Checked)?; + let mut compile_opts = + args.compile_options(config, mode, Some(&ws), ProfileChecking::Checked)?; if !config.cli_unstable().unstable_options { return Err(failure::format_err!( diff --git a/src/bin/cargo/commands/doc.rs b/src/bin/cargo/commands/doc.rs index b15fae7555a..d445f4bdd29 100644 --- a/src/bin/cargo/commands/doc.rs +++ b/src/bin/cargo/commands/doc.rs @@ -52,7 +52,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let mode = CompileMode::Doc { deps: !args.is_present("no-deps"), }; - let mut compile_opts = args.compile_options(config, mode, Some(&ws), ProfileChecking::Checked)?; + let mut compile_opts = + args.compile_options(config, mode, Some(&ws), ProfileChecking::Checked)?; compile_opts.local_rustdoc_args = if args.is_present("document-private-items") { Some(vec!["--document-private-items".to_string()]) } else { diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 62f246f7afb..363cdb97198 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -116,11 +116,15 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { } let workspace = args.workspace(config).ok(); - let mut compile_opts = args.compile_options(config, CompileMode::Build, workspace.as_ref(), - ProfileChecking::Checked)?; - - compile_opts.build_config.profile_kind = args.get_profile_kind(config, ProfileKind::Release, - ProfileChecking::Checked)?; + let mut compile_opts = args.compile_options( + config, + CompileMode::Build, + workspace.as_ref(), + ProfileChecking::Checked, + )?; + + compile_opts.build_config.profile_kind = + args.get_profile_kind(config, ProfileKind::Release, ProfileChecking::Checked)?; let krates = args .values_of("crate") diff --git a/src/bin/cargo/commands/run.rs b/src/bin/cargo/commands/run.rs index b0ecbc53f31..29478d2a3af 100644 --- a/src/bin/cargo/commands/run.rs +++ b/src/bin/cargo/commands/run.rs @@ -41,8 +41,12 @@ run. If you're passing arguments to both Cargo and the binary, the ones after pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let ws = args.workspace(config)?; - let mut compile_opts = args.compile_options(config, CompileMode::Build, Some(&ws), - ProfileChecking::Checked)?; + let mut compile_opts = args.compile_options( + config, + CompileMode::Build, + Some(&ws), + ProfileChecking::Checked, + )?; if !args.is_present("example") && !args.is_present("bin") { let default_runs: Vec<_> = compile_opts diff --git a/src/bin/cargo/commands/rustc.rs b/src/bin/cargo/commands/rustc.rs index 75266bee05b..b2121caf869 100644 --- a/src/bin/cargo/commands/rustc.rs +++ b/src/bin/cargo/commands/rustc.rs @@ -64,7 +64,11 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { } }; let mut compile_opts = args.compile_options_for_single_package( - config, mode, Some(&ws), ProfileChecking::Unchecked)?; + config, + mode, + Some(&ws), + ProfileChecking::Unchecked, + )?; let target_args = values(args, "args"); compile_opts.target_rustc_args = if target_args.is_empty() { None diff --git a/src/bin/cargo/commands/test.rs b/src/bin/cargo/commands/test.rs index a079a028237..75174f0e342 100644 --- a/src/bin/cargo/commands/test.rs +++ b/src/bin/cargo/commands/test.rs @@ -100,12 +100,18 @@ To get the list of all options available for the test binaries use this: pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let ws = args.workspace(config)?; - let mut compile_opts = args.compile_options(config, CompileMode::Test, Some(&ws), - ProfileChecking::Checked)?; - - compile_opts.build_config.profile_kind = - args.get_profile_kind(config, ProfileKind::Custom("test".to_owned()), - ProfileChecking::Checked)?; + let mut compile_opts = args.compile_options( + config, + CompileMode::Test, + Some(&ws), + ProfileChecking::Checked, + )?; + + compile_opts.build_config.profile_kind = args.get_profile_kind( + config, + ProfileKind::Custom("test".to_owned()), + ProfileChecking::Checked, + )?; // `TESTNAME` is actually an argument of the test binary, but it's // important, so we explicitly mention it and reconfigure. diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index 31ecd0c3fda..1b379f8bfc8 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -15,8 +15,8 @@ use super::job::{ Job, }; use super::{BuildContext, BuildPlan, CompileMode, Context, Unit}; +use crate::core::compiler::ProfileKind; use crate::core::{PackageId, TargetKind}; -use crate::core::compiler::{ProfileKind}; use crate::handle_error; use crate::util; use crate::util::diagnostic_server::{self, DiagnosticPrinter}; diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 4d72e634ee8..301bd94e978 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -1,12 +1,12 @@ -use std::collections::HashSet; use std::collections::BTreeMap; +use std::collections::HashSet; use std::{cmp, env, fmt, hash}; use serde::Deserialize; -use crate::core::compiler::{ProfileKind, CompileMode}; +use crate::core::compiler::{CompileMode, ProfileKind}; use crate::core::interning::InternedString; -use crate::core::{Features, Feature, PackageId, PackageIdSpec, PackageSet, Shell}; +use crate::core::{Feature, Features, PackageId, PackageIdSpec, PackageSet, Shell}; use crate::util::errors::CargoResultExt; use crate::util::lev_distance::lev_distance; use crate::util::toml::{ProfilePackageSpec, StringOrBool, TomlProfile, TomlProfiles, U32OrBool}; @@ -63,7 +63,7 @@ impl Profiles { features.require(Feature::named_profiles())?; break; } - }, + } _ => { features.require(Feature::named_profiles())?; break; @@ -75,13 +75,15 @@ impl Profiles { use std::collections::btree_map::Entry; for (predef_name, mut predef_prof) in Self::predefined_profiles().into_iter() { match profiles.entry(predef_name.to_owned()) { - Entry::Vacant(vac) => { vac.insert(predef_prof); }, + Entry::Vacant(vac) => { + vac.insert(predef_prof); + } Entry::Occupied(mut oc) => { // Override predefined with the user-provided Toml. let r = oc.get_mut(); predef_prof.merge(r); *r = predef_prof; - }, + } } } @@ -99,53 +101,68 @@ impl Profiles { dir_names } - fn add_root_profiles(profile_makers: &mut Profiles, - profiles: Option<&TomlProfiles>, config_profiles: &ConfigProfiles) - { + fn add_root_profiles( + profile_makers: &mut Profiles, + profiles: Option<&TomlProfiles>, + config_profiles: &ConfigProfiles, + ) { let profile_name = "dev"; - profile_makers.by_name.insert(profile_name.to_owned(), ProfileMaker { - default: Profile::default_dev(), - toml: profiles.and_then(|p| p.get(profile_name).cloned()), - config: config_profiles.dev.clone(), - inherits: vec![], - }); + profile_makers.by_name.insert( + profile_name.to_owned(), + ProfileMaker { + default: Profile::default_dev(), + toml: profiles.and_then(|p| p.get(profile_name).cloned()), + config: config_profiles.dev.clone(), + inherits: vec![], + }, + ); let profile_name = "release"; - profile_makers.by_name.insert(profile_name.to_owned(), ProfileMaker { - default: Profile::default_release(), - toml: profiles.and_then(|p| p.get(profile_name).cloned()), - config: config_profiles.release.clone(), - inherits: vec![], - }); + profile_makers.by_name.insert( + profile_name.to_owned(), + ProfileMaker { + default: Profile::default_release(), + toml: profiles.and_then(|p| p.get(profile_name).cloned()), + config: config_profiles.release.clone(), + inherits: vec![], + }, + ); } fn predefined_profiles() -> Vec<(&'static str, TomlProfile)> { vec![ - ("bench", TomlProfile { - inherits: Some(String::from("release")), - ..TomlProfile::default() - }), - ("test", TomlProfile { - inherits: Some(String::from("dev")), - ..TomlProfile::default() - }), - ("check", TomlProfile { - inherits: Some(String::from("dev")), - ..TomlProfile::default() - }), + ( + "bench", + TomlProfile { + inherits: Some(String::from("release")), + ..TomlProfile::default() + }, + ), + ( + "test", + TomlProfile { + inherits: Some(String::from("dev")), + ..TomlProfile::default() + }, + ), + ( + "check", + TomlProfile { + inherits: Some(String::from("dev")), + ..TomlProfile::default() + }, + ), ] } - fn process_customs(&mut self, profiles: &BTreeMap) - -> CargoResult<()> - { + fn process_customs(&mut self, profiles: &BTreeMap) -> CargoResult<()> { for (name, profile) in profiles { let mut set = HashSet::new(); let mut result = Vec::new(); set.insert(name.as_str().to_owned()); match &profile.dir_name { - None => {}, + None => {} Some(dir_name) => { self.dir_names.insert(name.clone(), dir_name.to_owned()); } @@ -157,9 +174,7 @@ impl Profiles { _ => {} }; - let mut maker = self.process_chain(name, - &profile, &mut set, - &mut result, profiles)?; + let mut maker = self.process_chain(name, &profile, &mut set, &mut result, profiles)?; result.reverse(); maker.inherits = result; @@ -169,17 +184,17 @@ impl Profiles { Ok(()) } - fn process_chain(&mut self, - name: &String, - profile: &TomlProfile, - set: &mut HashSet, - result: &mut Vec, - profiles: &BTreeMap) - -> CargoResult - { + fn process_chain( + &mut self, + name: &String, + profile: &TomlProfile, + set: &mut HashSet, + result: &mut Vec, + profiles: &BTreeMap, + ) -> CargoResult { result.push(profile.clone()); match profile.inherits.as_ref().map(|x| x.as_str()) { - Some(name@"dev") | Some(name@"release") => { + Some(name @ "dev") | Some(name @ "release") => { // These are the root profiles return Ok(self.by_name.get(name).unwrap().clone()); } @@ -194,22 +209,20 @@ impl Profiles { None => { failure::bail!("Profile {} not found in Cargo.toml", name); } - Some(parent) => { - self.process_chain(&name, parent, set, result, profiles) - } + Some(parent) => self.process_chain(&name, parent, set, result, profiles), } } None => { failure::bail!( "An 'inherits' directive is needed for all \ - profiles that are not 'dev' or 'release. Here \ - it is missing from {}", - name); + profiles that are not 'dev' or 'release. Here \ + it is missing from {}", + name + ); } } } - /// Retrieves the profile for a target. /// `is_member` is whether or not this package is a member of the /// workspace. @@ -267,9 +280,7 @@ impl Profiles { pub fn base_profile(&self, profile_kind: &ProfileKind) -> CargoResult { match self.by_name.get(profile_kind.name()) { None => failure::bail!("Profile {} undefined", profile_kind.name()), - Some(r) => { - Ok(r.get_profile(None, true, UnitFor::new_normal())) - } + Some(r) => Ok(r.get_profile(None, true, UnitFor::new_normal())), } } diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 68ece69e1dc..4d36a59bbe5 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -15,7 +15,7 @@ use crate::util::{ use crate::CargoResult; use clap::{self, SubCommand}; -pub use crate::core::compiler::{ProfileKind, CompileMode}; +pub use crate::core::compiler::{CompileMode, ProfileKind}; pub use crate::{CliError, CliResult, Config}; pub use clap::{AppSettings, Arg, ArgMatches}; @@ -297,9 +297,12 @@ pub trait ArgMatchesExt { self._value_of("target").map(|s| s.to_string()) } - fn get_profile_kind(&self, config: &Config, default: ProfileKind, profile_checking: ProfileChecking) - -> CargoResult - { + fn get_profile_kind( + &self, + config: &Config, + default: ProfileKind, + profile_checking: ProfileChecking, + ) -> CargoResult { let specified_profile = match self._value_of("profile") { None => None, Some("dev") => Some(ProfileKind::Dev), @@ -308,7 +311,7 @@ pub trait ArgMatchesExt { }; match profile_checking { - ProfileChecking::Unchecked => {}, + ProfileChecking::Unchecked => {} ProfileChecking::Checked => { if specified_profile.is_some() { if !config.cli_unstable().unstable_options { @@ -320,21 +323,13 @@ pub trait ArgMatchesExt { if self._is_present("release") { match specified_profile { - None | Some(ProfileKind::Release) => { - Ok(ProfileKind::Release) - } - _ => { - failure::bail!("Conflicting usage of --profile and --release") - } + None | Some(ProfileKind::Release) => Ok(ProfileKind::Release), + _ => failure::bail!("Conflicting usage of --profile and --release"), } } else if self._is_present("debug") { match specified_profile { - None | Some(ProfileKind::Dev) => { - Ok(ProfileKind::Dev) - } - _ => { - failure::bail!("Conflicting usage of --profile and --debug") - } + None | Some(ProfileKind::Dev) => Ok(ProfileKind::Dev), + _ => failure::bail!("Conflicting usage of --profile and --debug"), } } else { Ok(specified_profile.unwrap_or(default)) @@ -371,8 +366,8 @@ pub trait ArgMatchesExt { let mut build_config = BuildConfig::new(config, self.jobs()?, &self.target(), mode)?; build_config.message_format = message_format; - build_config.profile_kind = self.get_profile_kind(config, ProfileKind::Dev, - profile_checking)?; + build_config.profile_kind = + self.get_profile_kind(config, ProfileKind::Dev, profile_checking)?; build_config.build_plan = self._is_present("build-plan"); if build_config.build_plan { config From 85e196a0c8982af6aa65963e2f58a24e6b16254f Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Fri, 5 Jul 2019 11:07:21 +0300 Subject: [PATCH 24/58] Revert "tests: profile_doc_deprecated should have 'inherits'" This reverts commit 07d084532346d45bb1404a53de6af294fff480fa. --- tests/testsuite/profiles.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testsuite/profiles.rs b/tests/testsuite/profiles.rs index c38258265fe..fab0f50534f 100644 --- a/tests/testsuite/profiles.rs +++ b/tests/testsuite/profiles.rs @@ -362,7 +362,6 @@ fn profile_doc_deprecated() { [profile.doc] opt-level = 0 - inherits = "dev" "#, ) .file("src/lib.rs", "") From 3aace50004b4c5a6cf360b6f076351011906c60c Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Fri, 5 Jul 2019 11:09:18 +0300 Subject: [PATCH 25/58] custom-profiles: for backward compatibility, allow 'doc' with a default 'inherits' Some packages still have old `Cargo.toml` with a `profile.doc` section and obviously without an 'inherits' keyword. We should not trip Cargo on processing their Cargo.toml files. --- src/cargo/core/profiles.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 301bd94e978..acaf353fa2c 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -152,6 +152,13 @@ impl Profiles { ..TomlProfile::default() }, ), + ( + "doc", + TomlProfile { + inherits: Some(String::from("dev")), + ..TomlProfile::default() + }, + ), ] } From 4d138d38bf01c407670e03c1c4d2672a9b3e0945 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 1 Aug 2019 11:27:06 +0300 Subject: [PATCH 26/58] profiles: evaluate overrides separately from profiles Before this change, settings from custom profiles had precedence over overrides from inherited profiles: [profile.dev.overrides.pkg] codegen-units = 5 [profile.dev-new] inherits = "dev" codegen-units = 2 Here with --profile=dev-new, `pkg` would have gotten codegen-units=2. The fix, this, when going over the list of TomlProfiles for the purpose of merging them, we should first merge the profiles themselves and only later apply settings from the profile overrides (and in the same order). --- src/cargo/core/profiles.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 9fa36d26791..358e6acaa56 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -344,15 +344,31 @@ impl ProfileMaker { unit_for: UnitFor, ) -> Profile { let mut profile = self.default; + + let mut tomls = vec![]; if let Some(ref toml) = self.toml { - merge_toml(pkg_id, is_member, unit_for, &mut profile, toml); + tomls.push(toml); } for toml in &self.inherits { - merge_toml(pkg_id, is_member, unit_for, &mut profile, toml); + tomls.push(toml); + } + + // First merge the profiles + for toml in &tomls { + merge_profile(&mut profile, toml); } + + // Then their overrides + for toml in &tomls { + merge_toml_overrides(pkg_id, is_member, unit_for, &mut profile, toml); + } + + // '.cargo/config' can still overrides everything we had so far. if let Some(ref toml) = self.config { - merge_toml(pkg_id, is_member, unit_for, &mut profile, toml); + merge_profile(&mut profile, toml); + merge_toml_overrides(pkg_id, is_member, unit_for, &mut profile, toml); } + profile } @@ -459,14 +475,13 @@ impl ProfileMaker { } } -fn merge_toml( +fn merge_toml_overrides( pkg_id: Option, is_member: bool, unit_for: UnitFor, profile: &mut Profile, toml: &TomlProfile, ) { - merge_profile(profile, toml); if unit_for.is_build() { if let Some(ref build_override) = toml.build_override { merge_profile(profile, build_override); From 84331fcf71a509677390b3497608cb051837f2ae Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 1 Aug 2019 11:45:43 +0300 Subject: [PATCH 27/58] profiles: allow to specify overrides other than for 'dev' and 'release' --- src/cargo/util/toml/mod.rs | 13 ---------- tests/testsuite/profile_overrides.rs | 36 ---------------------------- 2 files changed, 49 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 97629a9e68b..7ece621822f 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -461,19 +461,6 @@ impl TomlProfile { } } - match name { - "dev" | "release" => {} - _ => { - if self.overrides.is_some() || self.build_override.is_some() { - bail!( - "Profile overrides may only be specified for \ - `dev` or `release` profile, not `{}`.", - name - ); - } - } - } - match name { "doc" => { warnings.push("profile `doc` is deprecated and has no effect".to_string()); diff --git a/tests/testsuite/profile_overrides.rs b/tests/testsuite/profile_overrides.rs index 17b3c25c18b..a550e50d1b9 100644 --- a/tests/testsuite/profile_overrides.rs +++ b/tests/testsuite/profile_overrides.rs @@ -149,42 +149,6 @@ fn profile_override_warnings() { .run(); } -#[cargo_test] -fn profile_override_dev_release_only() { - let p = project() - .file( - "Cargo.toml", - r#" - cargo-features = ["profile-overrides"] - - [package] - name = "foo" - version = "0.0.1" - - [dependencies] - bar = {path = "bar"} - - [profile.test.overrides.bar] - opt-level = 3 - "#, - ) - .file("src/lib.rs", "") - .file("bar/Cargo.toml", &basic_lib_manifest("bar")) - .file("bar/src/lib.rs", "") - .build(); - - p.cargo("build") - .masquerade_as_nightly_cargo() - .with_status(101) - .with_stderr_contains( - "\ -Caused by: - Profile overrides may only be specified for `dev` or `release` profile, not `test`. -", - ) - .run(); -} - #[cargo_test] fn profile_override_bad_settings() { let bad_values = [ From 48640e3d615b909f06fab3dc19384560c7a43e78 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Tue, 10 Sep 2019 20:26:39 +0300 Subject: [PATCH 28/58] Validate profile names and dir-name --- src/cargo/core/profiles.rs | 26 ++++++++++++++++++++++++++ src/cargo/util/command_prelude.rs | 7 +++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 5da016299fd..d630eca4312 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -62,6 +62,13 @@ impl Profiles { features.require(Feature::named_profiles())?; break; } + + match &profile.dir_name { + None => {} + Some(dir_name) => { + validate_name(&dir_name, "dir-name")?; + } + } } _ => { features.require(Feature::named_profiles())?; @@ -311,6 +318,25 @@ impl Profiles { } } +/// Validate dir-names and profile names according to RFC 2678. +pub fn validate_name(name: &str, what: &str) -> CargoResult<()> { + if let Some(ch) = name + .chars() + .find(|ch| !ch.is_alphanumeric() && *ch != '_' && *ch != '-') + { + failure::bail!("Invalid character `{}` in {}: `{}`", ch, what, name); + } + + match name { + "package" | "build" | "debug" => { + failure::bail!("Invalid {}: `{}`", what, name); + } + _ => {}, + } + + Ok(()) +} + /// An object used for handling the profile override hierarchy. /// /// The precedence of profiles are (first one wins): diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 61c6a620acf..e59446b4c76 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -1,5 +1,5 @@ use crate::core::compiler::{BuildConfig, MessageFormat}; -use crate::core::Workspace; +use crate::core::{profiles, Workspace}; use crate::ops::{CompileFilter, CompileOptions, NewOptions, Packages, VersionControl}; use crate::sources::CRATES_IO_REGISTRY; use crate::util::important_paths::find_root_manifest_for_wd; @@ -303,7 +303,10 @@ pub trait ArgMatchesExt { None => None, Some("dev") => Some(ProfileKind::Dev), Some("release") => Some(ProfileKind::Release), - Some(name) => Some(ProfileKind::Custom(name.to_string())), + Some(name) => { + profiles::validate_name(name, "profile name")?; + Some(ProfileKind::Custom(name.to_string())) + }, }; match profile_checking { From fc4ee774483dc6b40f1edbd259879dc4cbcf20a5 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Tue, 10 Sep 2019 22:01:09 +0300 Subject: [PATCH 29/58] Rustfmt fixes --- src/cargo/core/profiles.rs | 2 +- src/cargo/util/command_prelude.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index d630eca4312..c308d97994b 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -331,7 +331,7 @@ pub fn validate_name(name: &str, what: &str) -> CargoResult<()> { "package" | "build" | "debug" => { failure::bail!("Invalid {}: `{}`", what, name); } - _ => {}, + _ => {} } Ok(()) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index e59446b4c76..dc06f48d775 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -306,7 +306,7 @@ pub trait ArgMatchesExt { Some(name) => { profiles::validate_name(name, "profile name")?; Some(ProfileKind::Custom(name.to_string())) - }, + } }; match profile_checking { From 80cc7c8170b92fab7a045ad05bf019642a94a636 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 12 Sep 2019 08:22:19 +0300 Subject: [PATCH 30/58] Reinstate warning regarding 'debug' profile The previous warning was detected at the decoding level, with the test removed in an earlier commit. Here it is brought back, in the custom profile processing level. Keeping this warning will serve to prevent confusion, when people expect to affect the 'debug' directory via the 'debug' profile to no effect, where in fact the 'dev' profile is the profile that they opted to change. --- src/cargo/util/toml/mod.rs | 6 +++++- tests/testsuite/bad_config.rs | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 7ece621822f..a824f51ae16 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -67,7 +67,7 @@ fn do_read_manifest( let add_unused = |warnings: &mut Warnings| { for key in unused { warnings.add_warning(format!("unused manifest key: {}", key)); - if key == "profile.debug" || key == "profiles.debug" { + if key == "profiles.debug" { warnings.add_warning("use `[profile.dev]` to configure debug builds".to_string()); } } @@ -282,6 +282,10 @@ impl TomlProfiles { pub fn validate(&self, features: &Features, warnings: &mut Vec) -> CargoResult<()> { for (name, profile) in &self.0 { + if name == "debug" { + warnings.push("use `[profile.dev]` to configure debug builds".to_string()); + } + profile.validate(&name, features, warnings)?; } Ok(()) diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 87fc42bab17..9c5fb17ff55 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -707,6 +707,16 @@ warning: unused manifest key: target.foo.bar .file("src/lib.rs", "") .build(); + p.cargo("build -Z named-profiles") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +warning: use `[profile.dev]` to configure debug builds +[..] +[..]", + ) + .run(); + p.cargo("build -Z named-profiles") .masquerade_as_nightly_cargo() .run(); From c86213f1412cf92ba69116981ee09222d364ee5a Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 12 Sep 2019 16:22:30 +0300 Subject: [PATCH 31/58] Typo fix --- src/cargo/ops/cargo_clean.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index c03600fe584..0ab33cd6674 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -47,7 +47,7 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { target_dir = target_dir.join(profiles.get_dir_name(&ProfileKind::Release)); } else if opts.profile_specified { // After parsing profiles we know the dir-name of the profile, if a profile - // was passed freom the command line. If so, delete only the directory of + // was passed from the command line. If so, delete only the directory of // that profile. let dir_name = profiles.get_dir_name(&opts.profile_kind); target_dir = target_dir.join(dir_name); From d71a172eaec5e13653bc2cf06c9c0e3c62e9601a Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 12 Sep 2019 17:03:48 +0300 Subject: [PATCH 32/58] profiles: improve formatting of some new error messages --- src/cargo/core/profiles.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index c308d97994b..1092df9f9b6 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -214,13 +214,13 @@ impl Profiles { Some(name) => { let name = name.to_owned(); if set.get(&name).is_some() { - failure::bail!("Inheritance loop of profiles cycles with {}", name); + failure::bail!("Inheritance loop of profiles cycles with profile '{}'", name); } set.insert(name.clone()); match profiles.get(&name) { None => { - failure::bail!("Profile {} not found in Cargo.toml", name); + failure::bail!("Profile '{}' not found in Cargo.toml", name); } Some(parent) => self.process_chain(&name, parent, set, result, profiles), } @@ -228,8 +228,8 @@ impl Profiles { None => { failure::bail!( "An 'inherits' directive is needed for all \ - profiles that are not 'dev' or 'release. Here \ - it is missing from {}", + profiles that are not 'dev' or 'release'. Here \ + it is missing from '{}'", name ); } From 593641dc933be46ea427a112bc976687ff0c2a76 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 12 Sep 2019 16:27:15 +0300 Subject: [PATCH 33/58] testsuite: introduce profile_custom This suite of tests verifies various cases around the 'inherits' keyword, and also verifies the relationship between profile overrides and custom profiles. --- tests/testsuite/main.rs | 1 + tests/testsuite/profile_custom.rs | 214 ++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 tests/testsuite/profile_custom.rs diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 60002361b49..e065266a490 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -71,6 +71,7 @@ mod path; mod plugins; mod proc_macro; mod profile_config; +mod profile_custom; mod profile_overrides; mod profile_targets; mod profiles; diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs new file mode 100644 index 00000000000..009df385100 --- /dev/null +++ b/tests/testsuite/profile_custom.rs @@ -0,0 +1,214 @@ +use crate::support::{project, basic_lib_manifest}; + +#[cargo_test] +fn missing_inherits() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["named-profiles"] + + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.release-lto] + codegen-units = 7 + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build") + .masquerade_as_nightly_cargo() + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at [..] + +Caused by: + An 'inherits' directive is needed for all profiles that are not 'dev' or 'release'. Here it is missing from 'release-lto'", + ) + .run(); +} + +#[cargo_test] +fn non_existent_inherits() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["named-profiles"] + + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.release-lto] + codegen-units = 7 + inherits = "non-existent" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build") + .masquerade_as_nightly_cargo() + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at [..] + +Caused by: + Profile 'non-existent' not found in Cargo.toml", + ) + .run(); +} + +#[cargo_test] +fn self_inherits() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["named-profiles"] + + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.release-lto] + codegen-units = 7 + inherits = "release-lto" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build") + .masquerade_as_nightly_cargo() + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at [..] + +Caused by: + Inheritance loop of profiles cycles with profile 'release-lto'", + ) + .run(); +} + +#[cargo_test] +fn inherits_loop() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["named-profiles"] + + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.release-lto] + codegen-units = 7 + inherits = "release-lto2" + + [profile.release-lto2] + codegen-units = 7 + inherits = "release-lto" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build") + .masquerade_as_nightly_cargo() + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at [..] + +Caused by: + Inheritance loop of profiles cycles with profile 'release-lto'", + ) + .run(); +} + +#[cargo_test] +fn overrides_with_custom() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["profile-overrides", "named-profiles"] + + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + xxx = {path = "xxx"} + yyy = {path = "yyy"} + + [profile.dev] + codegen-units = 7 + + [profile.dev.overrides.xxx] + codegen-units = 5 + [profile.dev.overrides.yyy] + codegen-units = 3 + + [profile.other] + inherits = "dev" + codegen-units = 2 + + [profile.other.overrides.yyy] + codegen-units = 6 + "#, + ) + .file("src/lib.rs", "") + .file("xxx/Cargo.toml", &basic_lib_manifest("xxx")) + .file("xxx/src/lib.rs", "") + .file("yyy/Cargo.toml", &basic_lib_manifest("yyy")) + .file("yyy/src/lib.rs", "") + .build(); + + // profile overrides are inherited between profiles using inherits and have a + // higher priority than profile options provided by custom profiles + p.cargo("build -v") + .masquerade_as_nightly_cargo() + .with_stderr_unordered("\ +[COMPILING] xxx [..] +[COMPILING] yyy [..] +[COMPILING] foo [..] +[RUNNING] `rustc --crate-name xxx [..] -C codegen-units=5 [..]` +[RUNNING] `rustc --crate-name yyy [..] -C codegen-units=3 [..]` +[RUNNING] `rustc --crate-name foo [..] -C codegen-units=7 [..]` +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); + + // This also verifies that the custom profile names appears in the finished line. + p.cargo("build --profile=other -Z unstable-options -v") + .masquerade_as_nightly_cargo() + .with_stderr_unordered("\ +[COMPILING] xxx [..] +[COMPILING] yyy [..] +[COMPILING] foo [..] +[RUNNING] `rustc --crate-name xxx [..] -C codegen-units=5 [..]` +[RUNNING] `rustc --crate-name yyy [..] -C codegen-units=6 [..]` +[RUNNING] `rustc --crate-name foo [..] -C codegen-units=2 [..]` +[FINISHED] other [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + + From ac2a4382ee5d927d917df026d2236ff5cd668717 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 12 Sep 2019 17:13:40 +0300 Subject: [PATCH 34/58] Rustfmt fixes --- src/cargo/core/profiles.rs | 5 ++++- tests/testsuite/profile_custom.rs | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 1092df9f9b6..f683d348127 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -214,7 +214,10 @@ impl Profiles { Some(name) => { let name = name.to_owned(); if set.get(&name).is_some() { - failure::bail!("Inheritance loop of profiles cycles with profile '{}'", name); + failure::bail!( + "Inheritance loop of profiles cycles with profile '{}'", + name + ); } set.insert(name.clone()); diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index 009df385100..1e23ff17489 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -1,4 +1,4 @@ -use crate::support::{project, basic_lib_manifest}; +use crate::support::{basic_lib_manifest, project}; #[cargo_test] fn missing_inherits() { @@ -183,7 +183,8 @@ fn overrides_with_custom() { // higher priority than profile options provided by custom profiles p.cargo("build -v") .masquerade_as_nightly_cargo() - .with_stderr_unordered("\ + .with_stderr_unordered( + "\ [COMPILING] xxx [..] [COMPILING] yyy [..] [COMPILING] foo [..] @@ -198,7 +199,8 @@ fn overrides_with_custom() { // This also verifies that the custom profile names appears in the finished line. p.cargo("build --profile=other -Z unstable-options -v") .masquerade_as_nightly_cargo() - .with_stderr_unordered("\ + .with_stderr_unordered( + "\ [COMPILING] xxx [..] [COMPILING] yyy [..] [COMPILING] foo [..] @@ -210,5 +212,3 @@ fn overrides_with_custom() { ) .run(); } - - From ea2b1b5c2c357ab70a6e21c7d831f490df1d32cd Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 12 Sep 2019 20:25:12 +0300 Subject: [PATCH 35/58] testsuite: profile_custom - add conflicting_usage --- tests/testsuite/profile_custom.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index 1e23ff17489..7eae4e2b50f 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -212,3 +212,31 @@ fn overrides_with_custom() { ) .run(); } + +#[cargo_test] +fn conflicting_usage() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build -Z unstable-options --profile=dev --release") + .masquerade_as_nightly_cargo() + .with_status(101) + .with_stderr_unordered("error: Conflicting usage of --profile and --release") + .run(); + + p.cargo("install -Z unstable-options --profile=release --debug") + .masquerade_as_nightly_cargo() + .with_status(101) + .with_stderr_unordered("error: Conflicting usage of --profile and --debug") + .run(); +} From ffc24e03d277407d9d701fac86ae3a9cfdb9575b Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Thu, 12 Sep 2019 20:40:03 +0300 Subject: [PATCH 36/58] testsuite: profile_custom - add clean_custom_dirname --- tests/testsuite/profile_custom.rs | 77 +++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index 7eae4e2b50f..a581fcca1ce 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -240,3 +240,80 @@ fn conflicting_usage() { .with_stderr_unordered("error: Conflicting usage of --profile and --debug") .run(); } + +#[cargo_test] +fn clean_custom_dirname() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["named-profiles"] + + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.other] + inherits = "release" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("build --release") + .masquerade_as_nightly_cargo() + .run(); + + p.cargo("clean -p foo").masquerade_as_nightly_cargo().run(); + + p.cargo("build --release") + .masquerade_as_nightly_cargo() + .with_stdout("") + .run(); + + p.cargo("clean -p foo --release") + .masquerade_as_nightly_cargo() + .run(); + + p.cargo("build --release") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([..]) +[FINISHED] release [optimized] target(s) in [..] +", + ) + .run(); + + p.cargo("build").masquerade_as_nightly_cargo().run(); + + p.cargo("build -Z unstable-options --profile=other") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([..]) +[FINISHED] other [optimized] target(s) in [..] +", + ) + .run(); + + p.cargo("clean") + .arg("--release") + .masquerade_as_nightly_cargo() + .run(); + + // Make sure that 'other' was not cleaned + assert!(p.build_dir().is_dir()); + assert!(p.build_dir().join("debug").is_dir()); + assert!(p.build_dir().join("other").is_dir()); + assert!(!p.build_dir().join("release").is_dir()); + + // This should clean 'other' + p.cargo("clean -Z unstable-options --profile=other") + .masquerade_as_nightly_cargo() + .with_stderr("") + .run(); + assert!(p.build_dir().join("debug").is_dir()); + assert!(!p.build_dir().join("other").is_dir()); +} From ced10bddf2f12607591b2e67cf69e9024c3a9eda Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Fri, 13 Sep 2019 12:31:36 +0300 Subject: [PATCH 37/58] custom-named-profiles: add documentation in unstable.md --- src/doc/src/reference/unstable.md | 61 ++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 5ec4e191614..b6826f9fb5e 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -92,7 +92,66 @@ opt-level = 2 opt-level = 3 ``` -Overrides can only be specified for dev and release profiles. +Overrides can be specified for any profile, including custom named profiles. + + +### Custom named profiles + +* Tracking Issue: [rust-lang/cargo#6988](https://github.com/rust-lang/cargo/issues/6988) +* RFC: [#2678](https://github.com/rust-lang/rfcs/pull/2678) + +With this feature you can define custom profiles having new names. With the +custom profile enabled, build artifacts can be emitted by default to +directories other than `release` or `debug`, based on the custom profile's +name. + +For example: + +```toml +cargo-features = ["named-profiles"] + +[profile.release-lto] +inherits = "release" +lto = true +```` + +An `inherits` key is used in order to receive attributes from other profiles, +so that a new custom profile can be based on the standard `dev` or `release` +profile presets. Cargo emits errors in case `inherits` loops are detected. When +considering inheritance hierarchy, all profiles directly or indirectly inherit +from either from `release` or from `dev`. + +Valid profile names are: must not be empty, use only alphanumeric characters or +`-` or `_`. + +Passing `--profile` with the profile's name to various Cargo commands, directs +operations to use the profile's attributes. Overrides that are specified in the +profiles from which the custom profile inherits are inherited too. + +For example, using `cargo build` with `--profile` and the manifest from above: + +``` +cargo +nightly build --profile release-lto -Z unstable-options +``` + +When a custom profile is used, build artifcats go to a different target by +default. In the example above, you can expect to see the outputs under +`target/release-lto`. + + +#### New `dir-name` attribute + +Some of the paths generated under `target/` have resulted in a de-facto "build +protocol", where `cargo` is invoked as a part of a larger project build. So, to +preserve the existing behavior, there is also a new attribute `dir-name`, which +when left unspecified, defaults to the name of the profile. For example: + +```toml +[profile.release-lto] +inherits = "release" +dir-name = "lto" # Emits to target/lto instead of target/release-lto +lto = true +``` ### Config Profiles From eeab934d5b36cf042010009ac6cca7c4cdcc0372 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 08:08:44 +0300 Subject: [PATCH 38/58] Update src/cargo/core/profiles.rs Co-Authored-By: Eric Huss --- src/cargo/core/profiles.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index f683d348127..a4f8b6215b4 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -295,7 +295,7 @@ impl Profiles { /// select for the package that was actually built. pub fn base_profile(&self, profile_kind: &ProfileKind) -> CargoResult { match self.by_name.get(profile_kind.name()) { - None => failure::bail!("Profile {} undefined", profile_kind.name()), + None => failure::bail!("Profile `{}` undefined", profile_kind.name()), Some(r) => Ok(r.get_profile(None, true, UnitFor::new_normal())), } } From f352af91f5f5590eb8227042e15ce74a2671b1c8 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 08:08:55 +0300 Subject: [PATCH 39/58] Update tests/testsuite/profile_targets.rs Co-Authored-By: Eric Huss --- tests/testsuite/profile_targets.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index 344596b8936..23dbc5c50df 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -160,7 +160,7 @@ fn profile_selection_build_all_targets() { // lib dev+panic build (a normal lib target) // lib dev-panic build (used by tests/benches) // lib dev dev - // dev dev dev + // test dev dev // bench dev dev // bin dev dev // bin dev build From 61beda64b9e648b881a9e10c4879742011193ad4 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 08:13:15 +0300 Subject: [PATCH 40/58] command_prelude: document ProfileChecking --- src/cargo/util/command_prelude.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index dc06f48d775..8082c4d6fec 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -236,6 +236,7 @@ pub fn subcommand(name: &'static str) -> App { ]) } +// Determines whether or not to gate `--profile` as unstable when resolving it. pub enum ProfileChecking { Checked, Unchecked, From 4c272daa81d8107627ba0f7e3870a50e7b8d0450 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 08:19:38 +0300 Subject: [PATCH 41/58] profiles: use HashMap for new maps instead of BTreeMap --- src/cargo/core/profiles.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index a4f8b6215b4..60378fbc379 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -1,4 +1,4 @@ -use std::collections::BTreeMap; +use std::collections::{BTreeMap, HashMap}; use std::collections::HashSet; use std::{cmp, env, fmt, hash}; @@ -18,8 +18,8 @@ pub struct Profiles { /// - `CARGO_INCREMENTAL` environment variable. /// - `build.incremental` config value. incremental: Option, - dir_names: BTreeMap, - by_name: BTreeMap, + dir_names: HashMap, + by_name: HashMap, } impl Profiles { @@ -43,7 +43,7 @@ impl Profiles { let mut profile_makers = Profiles { incremental, dir_names: Self::predefined_dir_names(), - by_name: BTreeMap::new(), + by_name: HashMap::new(), }; Self::add_root_profiles(&mut profile_makers, profiles, config_profiles); @@ -98,8 +98,8 @@ impl Profiles { Ok(profile_makers) } - fn predefined_dir_names() -> BTreeMap { - let mut dir_names = BTreeMap::new(); + fn predefined_dir_names() -> HashMap { + let mut dir_names = HashMap::new(); dir_names.insert("dev".to_owned(), "debug".to_owned()); dir_names.insert("check".to_owned(), "debug".to_owned()); dir_names.insert("test".to_owned(), "debug".to_owned()); From c2a8ca108e0c97cd57e14e658b2741e78d89f3df Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 09:01:21 +0300 Subject: [PATCH 42/58] cargo_clean: add profile name validation --- src/cargo/ops/cargo_clean.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 0ab33cd6674..a82e4f3ac66 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -42,6 +42,9 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { let (packages, resolve) = ops::resolve_ws(ws)?; let profiles = ws.profiles(); + // Check for whether the profile is defined. + let _ = profiles.base_profile(&opts.profile_kind)?; + // If the release option is set, we set target to release directory if opts.release { target_dir = target_dir.join(profiles.get_dir_name(&ProfileKind::Release)); From 47007d97ede2c9d0f7f0b859d4b5ab8a72195b93 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 09:01:41 +0300 Subject: [PATCH 43/58] cargo_compile: earlier profile name validation --- src/cargo/ops/cargo_compile.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index f540183035d..5cf1adaf9ad 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -302,6 +302,9 @@ pub fn compile_ws<'a>( let profiles = ws.profiles(); + // Early check for whether the profile is defined. + let _ = profiles.base_profile(&build_config.profile_kind)?; + let specs = spec.to_package_id_specs(ws)?; let dev_deps = ws.require_optional_deps() || filter.need_dev_deps(build_config.mode); let opts = ResolveOpts::new(dev_deps, features, all_features, !no_default_features); @@ -633,8 +636,6 @@ fn generate_targets<'a>( resolve: &'a Resolve, bcx: &BuildContext<'a, '_>, ) -> CargoResult>> { - let _ = profiles.base_profile(&bcx.build_config.profile_kind)?; - // Helper for creating a `Unit` struct. let new_unit = |pkg: &'a Package, target: &'a Target, target_mode: CompileMode| { let unit_for = if bcx.build_config.mode.is_any_test() { From 542161088f84902a2c468e091d8e7d0f1d38b4e1 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 09:10:11 +0300 Subject: [PATCH 44/58] cargo clean: remove 'release' field' --- src/bin/cargo/commands/clean.rs | 3 +-- src/cargo/ops/cargo_clean.rs | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/bin/cargo/commands/clean.rs b/src/bin/cargo/commands/clean.rs index dc57aab5a07..0cce5725767 100644 --- a/src/bin/cargo/commands/clean.rs +++ b/src/bin/cargo/commands/clean.rs @@ -30,8 +30,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { spec: values(args, "package"), target: args.target(), profile_kind: args.get_profile_kind(config, ProfileKind::Dev, ProfileChecking::Checked)?, - release: args.is_present("release"), - profile_specified: args.is_present("profile"), + profile_specified: args.is_present("profile") || args.is_present("release"), doc: args.is_present("doc"), }; ops::clean(&ws, &opts)?; diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index a82e4f3ac66..67ec25dc6bd 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -19,8 +19,6 @@ pub struct CleanOptions<'a> { /// The target arch triple to clean, or None for the host arch pub target: Option, /// Whether to clean the release directory - pub release: bool, - /// Whether a certain build profile was specified pub profile_specified: bool, /// Whether to clean the directory of a certain build profile pub profile_kind: ProfileKind, @@ -45,10 +43,7 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { // Check for whether the profile is defined. let _ = profiles.base_profile(&opts.profile_kind)?; - // If the release option is set, we set target to release directory - if opts.release { - target_dir = target_dir.join(profiles.get_dir_name(&ProfileKind::Release)); - } else if opts.profile_specified { + if opts.profile_specified { // After parsing profiles we know the dir-name of the profile, if a profile // was passed from the command line. If so, delete only the directory of // that profile. From 1e097c3bd7ae761f816a9913f30822f3067ab507 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 09:16:50 +0300 Subject: [PATCH 45/58] Update src/cargo/core/profiles.rs Co-Authored-By: Eric Huss --- src/cargo/core/profiles.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 60378fbc379..80bad3df6ea 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -314,7 +314,7 @@ impl Profiles { shell: &mut Shell, packages: &PackageSet<'_>, ) -> CargoResult<()> { - for (_, profile) in &self.by_name { + for profile in self.by_name.values() { profile.validate_packages(shell, packages)?; } Ok(()) From 01a0c24202e30e1e8feb2974e6c74bbc087bf5d8 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 09:17:47 +0300 Subject: [PATCH 46/58] profiles: add feature gating on 'inherits' and validate names --- src/cargo/core/profiles.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 80bad3df6ea..030bda2f49c 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -54,21 +54,25 @@ impl Profiles { BTreeMap::new() }; - // Feature gating + // Feature gating and name validation for (profile_name, profile) in &profiles { match profile_name.as_str() { "dev" | "release" | "bench" | "test" | "doc" | "check" => { - if profile.dir_name.is_some() { - features.require(Feature::named_profiles())?; - break; - } - match &profile.dir_name { None => {} Some(dir_name) => { + features.require(Feature::named_profiles())?; validate_name(&dir_name, "dir-name")?; } } + + match &profile.inherits { + None => {} + Some(inherits) => { + features.require(Feature::named_profiles())?; + validate_name(&inherits, "inherits")?; + } + } } _ => { features.require(Feature::named_profiles())?; From a2b719762dc9fd11f64d257c5b9bfffd588f16c9 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 09:26:45 +0300 Subject: [PATCH 47/58] profiles: catch invalid 'inherits' use on root profile --- src/cargo/core/profiles.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 030bda2f49c..feecce729d5 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -186,6 +186,15 @@ impl Profiles { } match name.as_str() { "dev" | "release" => { + match &profile.inherits { + None => {} + Some(_) => { + failure::bail!( + "An 'inherits' must not specified root profile '{}'", + name + ); + } + } continue; } _ => {} From 6cd8e87deaa9897db724894cac01f7d65c8dea9f Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 09:27:14 +0300 Subject: [PATCH 48/58] tests: profile_custom - test for invalid 'inherits' use on root profile --- tests/testsuite/profile_custom.rs | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index cb5f1dbacc8..738468fbf4d 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -1,5 +1,39 @@ use cargo_test_support::{basic_lib_manifest, project}; +#[cargo_test] +fn inherits_on_release() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["named-profiles"] + + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.release] + inherits = "dev" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build") + .masquerade_as_nightly_cargo() + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at [..] + +Caused by: + An 'inherits' must not specified root profile 'release' +" + ) + .run(); +} + #[cargo_test] fn missing_inherits() { let p = project() From bf5f0b7c3a3c7a7124e3529e1e1afe183d148077 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 09:32:07 +0300 Subject: [PATCH 49/58] tests: profile_custom - add missing stdout/stderr checks --- tests/testsuite/profile_custom.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index 738468fbf4d..070b725e1f8 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -297,6 +297,13 @@ fn clean_custom_dirname() { p.cargo("build --release") .masquerade_as_nightly_cargo() + .with_stdout("") + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([..]) +[FINISHED] release [optimized] target(s) in [..] +", + ) .run(); p.cargo("clean -p foo").masquerade_as_nightly_cargo().run(); @@ -304,6 +311,11 @@ fn clean_custom_dirname() { p.cargo("build --release") .masquerade_as_nightly_cargo() .with_stdout("") + .with_stderr( + "\ +[FINISHED] release [optimized] target(s) in [..] +", + ) .run(); p.cargo("clean -p foo --release") @@ -320,7 +332,16 @@ fn clean_custom_dirname() { ) .run(); - p.cargo("build").masquerade_as_nightly_cargo().run(); + p.cargo("build") + .masquerade_as_nightly_cargo() + .with_stdout("") + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([..]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); p.cargo("build -Z unstable-options --profile=other") .masquerade_as_nightly_cargo() From a50be59a70af64b83c07f40bc2faef80a73bc908 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 09:36:39 +0300 Subject: [PATCH 50/58] Rustfmt adjustments --- src/cargo/core/profiles.rs | 2 +- tests/testsuite/profile_custom.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index feecce729d5..38dcf51f3cb 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -1,5 +1,5 @@ -use std::collections::{BTreeMap, HashMap}; use std::collections::HashSet; +use std::collections::{BTreeMap, HashMap}; use std::{cmp, env, fmt, hash}; use serde::Deserialize; diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index 070b725e1f8..5eceb7d77c6 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -29,7 +29,7 @@ fn inherits_on_release() { Caused by: An 'inherits' must not specified root profile 'release' -" +", ) .run(); } From 5eef815e69b18b3e495f90a7527304270f1c0ee8 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 10:18:06 +0300 Subject: [PATCH 51/58] Move profile name and dir-name validation and gating to Toml level --- src/cargo/core/profiles.rs | 48 +--------------------------- src/cargo/util/command_prelude.rs | 6 ++-- src/cargo/util/toml/mod.rs | 52 +++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 50 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 38dcf51f3cb..e31d370e554 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -6,7 +6,7 @@ use serde::Deserialize; use crate::core::compiler::{CompileMode, ProfileKind}; use crate::core::interning::InternedString; -use crate::core::{Feature, Features, PackageId, PackageIdSpec, PackageSet, Shell}; +use crate::core::{Features, PackageId, PackageIdSpec, PackageSet, Shell}; use crate::util::errors::CargoResultExt; use crate::util::toml::{ProfilePackageSpec, StringOrBool, TomlProfile, TomlProfiles, U32OrBool}; use crate::util::{closest_msg, CargoResult, Config}; @@ -54,33 +54,6 @@ impl Profiles { BTreeMap::new() }; - // Feature gating and name validation - for (profile_name, profile) in &profiles { - match profile_name.as_str() { - "dev" | "release" | "bench" | "test" | "doc" | "check" => { - match &profile.dir_name { - None => {} - Some(dir_name) => { - features.require(Feature::named_profiles())?; - validate_name(&dir_name, "dir-name")?; - } - } - - match &profile.inherits { - None => {} - Some(inherits) => { - features.require(Feature::named_profiles())?; - validate_name(&inherits, "inherits")?; - } - } - } - _ => { - features.require(Feature::named_profiles())?; - break; - } - } - } - // Merge with predefined profiles use std::collections::btree_map::Entry; for (predef_name, mut predef_prof) in Self::predefined_profiles().into_iter() { @@ -334,25 +307,6 @@ impl Profiles { } } -/// Validate dir-names and profile names according to RFC 2678. -pub fn validate_name(name: &str, what: &str) -> CargoResult<()> { - if let Some(ch) = name - .chars() - .find(|ch| !ch.is_alphanumeric() && *ch != '_' && *ch != '-') - { - failure::bail!("Invalid character `{}` in {}: `{}`", ch, what, name); - } - - match name { - "package" | "build" | "debug" => { - failure::bail!("Invalid {}: `{}`", what, name); - } - _ => {} - } - - Ok(()) -} - /// An object used for handling the profile override hierarchy. /// /// The precedence of profiles are (first one wins): diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 8082c4d6fec..c3643718763 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -1,9 +1,9 @@ use crate::core::compiler::{BuildConfig, MessageFormat}; -use crate::core::{profiles, Workspace}; +use crate::core::Workspace; use crate::ops::{CompileFilter, CompileOptions, NewOptions, Packages, VersionControl}; use crate::sources::CRATES_IO_REGISTRY; use crate::util::important_paths::find_root_manifest_for_wd; -use crate::util::{paths, validate_package_name}; +use crate::util::{paths, toml::TomlProfile, validate_package_name}; use crate::util::{ print_available_benches, print_available_binaries, print_available_examples, print_available_tests, @@ -305,7 +305,7 @@ pub trait ArgMatchesExt { Some("dev") => Some(ProfileKind::Dev), Some("release") => Some(ProfileKind::Release), Some(name) => { - profiles::validate_name(name, "profile name")?; + TomlProfile::validate_name(name, "profile name")?; Some(ProfileKind::Custom(name.to_string())) } }; diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 8b395014bd5..92291b1b8bf 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -466,6 +466,39 @@ impl TomlProfile { } } + // Feature gate definition of named profiles + match name { + "dev" | "release" | "bench" | "test" | "doc" | "check" => {} + _ => { + features.require(Feature::named_profiles())?; + } + } + + // Feature gate on uses of keys related to named profiles + if self.inherits.is_some() { + features.require(Feature::named_profiles())?; + } + + if self.dir_name.is_some() { + features.require(Feature::named_profiles())?; + } + + // `dir-name` validation + match &self.dir_name { + None => {} + Some(dir_name) => { + Self::validate_name(&dir_name, "dir-name")?; + } + } + + // `inherits` validation + match &self.inherits { + None => {} + Some(inherits) => { + Self::validate_name(&inherits, "inherits")?; + } + } + match name { "doc" => { warnings.push("profile `doc` is deprecated and has no effect".to_string()); @@ -490,6 +523,25 @@ impl TomlProfile { Ok(()) } + /// Validate dir-names and profile names according to RFC 2678. + pub fn validate_name(name: &str, what: &str) -> CargoResult<()> { + if let Some(ch) = name + .chars() + .find(|ch| !ch.is_alphanumeric() && *ch != '_' && *ch != '-') + { + failure::bail!("Invalid character `{}` in {}: `{}`", ch, what, name); + } + + match name { + "package" | "build" | "debug" => { + failure::bail!("Invalid {}: `{}`", what, name); + } + _ => {} + } + + Ok(()) + } + fn validate_override(&self) -> CargoResult<()> { if self.overrides.is_some() || self.build_override.is_some() { bail!("Profile overrides cannot be nested."); From 97035e264f4ee7ada3b026af0415cfec7da54b36 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 10:18:11 +0300 Subject: [PATCH 52/58] TomlProfile::validate_name: disallow a 'doc' dir-name --- src/cargo/util/toml/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 92291b1b8bf..f59e7bb8ada 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -479,7 +479,7 @@ impl TomlProfile { features.require(Feature::named_profiles())?; } - if self.dir_name.is_some() { + if self.dir_name.is_some() { features.require(Feature::named_profiles())?; } @@ -536,6 +536,9 @@ impl TomlProfile { "package" | "build" | "debug" => { failure::bail!("Invalid {}: `{}`", what, name); } + "doc" if what == "dir-name" => { + failure::bail!("Invalid {}: `{}`", what, name); + } _ => {} } From cdd85ccc1f7ec0f3686ca45d1b27d6984bec4d2b Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 10:27:30 +0300 Subject: [PATCH 53/58] toml: add missing profile name validation --- src/cargo/util/toml/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index f59e7bb8ada..b5b65c9af49 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -474,6 +474,9 @@ impl TomlProfile { } } + // Profile name validation + Self::validate_name(name, "profile name")?; + // Feature gate on uses of keys related to named profiles if self.inherits.is_some() { features.require(Feature::named_profiles())?; From 330717632691348dde40877eb12e66aa3a0424cd Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 10:27:51 +0300 Subject: [PATCH 54/58] tests: profile_custom - add name validation tests --- tests/testsuite/profile_custom.rs | 103 ++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/tests/testsuite/profile_custom.rs b/tests/testsuite/profile_custom.rs index 5eceb7d77c6..9fcb43f831c 100644 --- a/tests/testsuite/profile_custom.rs +++ b/tests/testsuite/profile_custom.rs @@ -67,6 +67,109 @@ Caused by: .run(); } +#[cargo_test] +fn invalid_profile_name() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["named-profiles"] + + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.'.release-lto'] + inherits = "release" + codegen-units = 7 + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build") + .masquerade_as_nightly_cargo() + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at [..] + +Caused by: + Invalid character `.` in profile name: `.release-lto`", + ) + .run(); +} + +#[cargo_test] +fn invalid_dir_name() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["named-profiles"] + + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.'release-lto'] + inherits = "release" + dir-name = ".subdir" + codegen-units = 7 + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build") + .masquerade_as_nightly_cargo() + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at [..] + +Caused by: + Invalid character `.` in dir-name: `.subdir`", + ) + .run(); +} + +#[cargo_test] +fn invalid_inherits() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["named-profiles"] + + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.'release-lto'] + inherits = ".release" + codegen-units = 7 + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build") + .masquerade_as_nightly_cargo() + .with_status(101) + .with_stderr( + "\ +[ERROR] failed to parse manifest at [..] + +Caused by: + Invalid character `.` in inherits: `.release`", + ) + .run(); +} + #[cargo_test] fn non_existent_inherits() { let p = project() From a08a1a36eea33642e6f52e87e6ed32047c4f73cd Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 21 Sep 2019 11:02:41 +0300 Subject: [PATCH 55/58] toml: be less stringent on 'debug' profile, we already emit a warning on it --- src/cargo/util/toml/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index b5b65c9af49..4688fcc999e 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -536,9 +536,16 @@ impl TomlProfile { } match name { - "package" | "build" | "debug" => { + "package" | "build" => { failure::bail!("Invalid {}: `{}`", what, name); } + "debug" if what == "profile" => { + if what == "profile name" { + // Allowed, but will emit warnings + } else { + failure::bail!("Invalid {}: `{}`", what, name); + } + } "doc" if what == "dir-name" => { failure::bail!("Invalid {}: `{}`", what, name); } From b43778292942f6108e5dd3d8b70449e8eaa4f18e Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sun, 22 Sep 2019 09:06:30 +0300 Subject: [PATCH 56/58] profiles: remove 'check' from stable access --- src/cargo/util/toml/mod.rs | 2 +- tests/testsuite/profile_targets.rs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 4688fcc999e..39c5593a48a 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -468,7 +468,7 @@ impl TomlProfile { // Feature gate definition of named profiles match name { - "dev" | "release" | "bench" | "test" | "doc" | "check" => {} + "dev" | "release" | "bench" | "test" | "doc" => {} _ => { features.require(Feature::named_profiles())?; } diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index 23dbc5c50df..459348f076f 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -29,8 +29,6 @@ fn all_target_project() -> Project { codegen-units = 3 [profile.bench] codegen-units = 4 - [profile.check] - codegen-units = 5 "#, ) .file("src/lib.rs", "extern crate bar;") From e634ee549cbb2646500afc3a8615072e04044398 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Fri, 27 Sep 2019 22:28:44 +0300 Subject: [PATCH 57/58] named-profiles: add backward compatibility if feature is disabled The effects over the profile used by targets are made conditional in this commit, using the old scheme if the `named-profiles` feature is disabled. This also affects the `profile_targets` tests, which now have two modes - stable, and nightly with the feature enabled. --- src/cargo/core/profiles.rs | 146 ++++++++++++++++++++++++++++- tests/testsuite/profile_targets.rs | 143 ++++++++++++++++------------ 2 files changed, 228 insertions(+), 61 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index e31d370e554..69b1b3764d9 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -6,7 +6,7 @@ use serde::Deserialize; use crate::core::compiler::{CompileMode, ProfileKind}; use crate::core::interning::InternedString; -use crate::core::{Features, PackageId, PackageIdSpec, PackageSet, Shell}; +use crate::core::{Feature, Features, PackageId, PackageIdSpec, PackageSet, Shell}; use crate::util::errors::CargoResultExt; use crate::util::toml::{ProfilePackageSpec, StringOrBool, TomlProfile, TomlProfiles, U32OrBool}; use crate::util::{closest_msg, CargoResult, Config}; @@ -20,6 +20,7 @@ pub struct Profiles { incremental: Option, dir_names: HashMap, by_name: HashMap, + named_profiles_enabled: bool, } impl Profiles { @@ -40,8 +41,85 @@ impl Profiles { None => config.get::>("build.incremental")?, }; + if !features.is_enabled(Feature::named_profiles()) { + let mut profile_makers = Profiles { + incremental, + named_profiles_enabled: false, + dir_names: Self::predefined_dir_names(), + by_name: HashMap::new(), + }; + + profile_makers.by_name.insert( + "dev".to_owned(), + ProfileMaker { + toml: profiles.and_then(|p| p.get("dev").cloned()), + inherits: vec![], + config: config_profiles.dev.clone(), + default: Profile::default_dev(), + }, + ); + profile_makers + .dir_names + .insert("dev".to_owned(), "debug".to_owned()); + + profile_makers.by_name.insert( + "release".to_owned(), + ProfileMaker { + toml: profiles.and_then(|p| p.get("release").cloned()), + inherits: vec![], + config: config_profiles.release.clone(), + default: Profile::default_release(), + }, + ); + profile_makers + .dir_names + .insert("release".to_owned(), "release".to_owned()); + + profile_makers.by_name.insert( + "test".to_owned(), + ProfileMaker { + toml: profiles.and_then(|p| p.get("test").cloned()), + inherits: vec![], + config: None, + default: Profile::default_test(), + }, + ); + profile_makers + .dir_names + .insert("test".to_owned(), "debug".to_owned()); + + profile_makers.by_name.insert( + "bench".to_owned(), + ProfileMaker { + toml: profiles.and_then(|p| p.get("bench").cloned()), + inherits: vec![], + config: None, + default: Profile::default_bench(), + }, + ); + profile_makers + .dir_names + .insert("bench".to_owned(), "release".to_owned()); + + profile_makers.by_name.insert( + "doc".to_owned(), + ProfileMaker { + toml: profiles.and_then(|p| p.get("doc").cloned()), + inherits: vec![], + config: None, + default: Profile::default_doc(), + }, + ); + profile_makers + .dir_names + .insert("doc".to_owned(), "debug".to_owned()); + + return Ok(profile_makers); + } + let mut profile_makers = Profiles { incremental, + named_profiles_enabled: true, dir_names: Self::predefined_dir_names(), by_name: HashMap::new(), }; @@ -236,8 +314,47 @@ impl Profiles { mode: CompileMode, profile_kind: ProfileKind, ) -> Profile { - let maker = match self.by_name.get(profile_kind.name()) { - None => panic!("Profile {} undefined", profile_kind.name()), + let profile_name = if !self.named_profiles_enabled { + // With the feature disabled, we degrade `--profile` back to the + // `--release` and `--debug` predicates, and convert back from + // ProfileKind::Custom instantiation. + + let release = match profile_kind { + ProfileKind::Release => true, + ProfileKind::Custom(ref s) if s == "bench" => true, + ProfileKind::Custom(ref s) if s == "test" => false, + _ => false, + }; + + match mode { + CompileMode::Test | CompileMode::Bench => { + if release { + "bench" + } else { + "test" + } + } + CompileMode::Build + | CompileMode::Check { .. } + | CompileMode::Doctest + | CompileMode::RunCustomBuild => { + // Note: `RunCustomBuild` doesn't normally use this code path. + // `build_unit_profiles` normally ensures that it selects the + // ancestor's profile. However, `cargo clean -p` can hit this + // path. + if release { + "release" + } else { + "dev" + } + } + CompileMode::Doc { .. } => "doc", + } + } else { + profile_kind.name() + }; + let maker = match self.by_name.get(profile_name) { + None => panic!("Profile {} undefined", profile_name), Some(r) => r, }; let mut profile = maker.get_profile(Some(pkg_id), is_member, unit_for); @@ -666,6 +783,29 @@ impl Profile { } } + // NOTE: Remove the following three once `named_profiles` is default: + + fn default_test() -> Profile { + Profile { + name: "test", + ..Profile::default_dev() + } + } + + fn default_bench() -> Profile { + Profile { + name: "bench", + ..Profile::default_release() + } + } + + fn default_doc() -> Profile { + Profile { + name: "doc", + ..Profile::default_dev() + } + } + /// Compares all fields except `name`, which doesn't affect compilation. /// This is necessary for `Unit` deduplication for things like "test" and /// "dev" which are essentially the same. diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index 459348f076f..2fc76b66775 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -1,4 +1,4 @@ -use cargo_test_support::{basic_manifest, project, Project}; +use cargo_test_support::{basic_manifest, is_nightly, project, Project}; // These tests try to exercise exactly which profiles are selected for every target. @@ -8,16 +8,19 @@ fn all_target_project() -> Project { project() .file( "Cargo.toml", - r#" + &format!( + r#" + cargo-features = [{named_profiles}] + [package] name = "foo" version = "0.0.1" [dependencies] - bar = { path = "bar" } + bar = {{ path = "bar" }} [build-dependencies] - bdep = { path = "bdep" } + bdep = {{ path = "bdep" }} [profile.dev] codegen-units = 1 @@ -30,6 +33,12 @@ fn all_target_project() -> Project { [profile.bench] codegen-units = 4 "#, + named_profiles = if is_nightly() { + "\"named-profiles\", " + } else { + "" + } + ), ) .file("src/lib.rs", "extern crate bar;") .file("src/main.rs", "extern crate foo; fn main() {}") @@ -76,7 +85,7 @@ fn profile_selection_build() { // NOTES: // - bdep `panic` is not set because it thinks `build.rs` is a plugin. // - build_script_build is built without panic because it thinks `build.rs` is a plugin. - p.cargo("build -vv").with_stderr_unordered("\ + p.cargo("build -vv").masquerade_as_nightly_cargo().with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] @@ -91,6 +100,7 @@ fn profile_selection_build() { [FINISHED] dev [unoptimized + debuginfo] [..] ").run(); p.cargo("build -vv") + .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -107,7 +117,7 @@ fn profile_selection_build_release() { let p = all_target_project(); // `build --release` - p.cargo("build --release -vv").with_stderr_unordered("\ + p.cargo("build --release -vv").masquerade_as_nightly_cargo().with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] @@ -122,6 +132,7 @@ fn profile_selection_build_release() { [FINISHED] release [optimized] [..] ").run(); p.cargo("build --release -vv") + .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -136,6 +147,7 @@ fn profile_selection_build_release() { #[cargo_test] fn profile_selection_build_all_targets() { let p = all_target_project(); + let affected = if is_nightly() { 1 } else { 3 }; // `build` // NOTES: // - bdep `panic` is not set because it thinks `build.rs` is a plugin. @@ -158,12 +170,12 @@ fn profile_selection_build_all_targets() { // lib dev+panic build (a normal lib target) // lib dev-panic build (used by tests/benches) // lib dev dev - // test dev dev + // test dev dev // bench dev dev // bin dev dev // bin dev build // example dev build - p.cargo("build --all-targets -vv").with_stderr_unordered("\ + p.cargo("build --all-targets -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..] @@ -174,16 +186,17 @@ fn profile_selection_build_all_targets() { [RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..]` -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C codegen-units=1 -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C codegen-units={affected} -C debuginfo=2 --test [..]` [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..]` -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C codegen-units=1 -C debuginfo=2 --test [..]` -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C codegen-units=1 -C debuginfo=2 --test [..]` -[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C codegen-units=1 -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C codegen-units={affected} -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C codegen-units={affected} -C debuginfo=2 --test [..]` +[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C codegen-units={affected} -C debuginfo=2 --test [..]` [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..]` [RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C panic=abort -C codegen-units=1 -C debuginfo=2 [..]` [FINISHED] dev [unoptimized + debuginfo] [..] -").run(); +", affected=affected)).run(); p.cargo("build -vv") + .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -198,6 +211,7 @@ fn profile_selection_build_all_targets() { #[cargo_test] fn profile_selection_build_all_targets_release() { let p = all_target_project(); + let affected = if is_nightly() { 2 } else { 4 }; // `build --all-targets --release` // NOTES: // - bdep `panic` is not set because it thinks `build.rs` is a plugin. @@ -228,7 +242,7 @@ fn profile_selection_build_all_targets_release() { // bin release test (bench/test de-duped) // bin release build // example release build - p.cargo("build --all-targets --release -vv").with_stderr_unordered("\ + p.cargo("build --all-targets --release -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] @@ -239,16 +253,17 @@ fn profile_selection_build_all_targets_release() { [RUNNING] `[..]/target/release/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..]` -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units={affected} --test [..]` [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=2 [..]` -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..]` -[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..]` -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..]` +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units={affected} --test [..]` +[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units={affected} --test [..]` +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units={affected} --test [..]` [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..]` [RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..]` [FINISHED] release [optimized] [..] -").run(); +", affected=affected)).run(); p.cargo("build --all-targets --release -vv") + .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -263,6 +278,7 @@ fn profile_selection_build_all_targets_release() { #[cargo_test] fn profile_selection_test() { let p = all_target_project(); + let affected = if is_nightly() { 3 } else { 1 }; // `test` // NOTES: // - Dependency profiles: @@ -284,31 +300,32 @@ fn profile_selection_test() { // bin test test // bin test build // - p.cargo("test -vv").with_stderr_unordered("\ + p.cargo("test -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ [COMPILING] bar [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units={affected} -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units={affected} -C debuginfo=2 [..] [COMPILING] bdep [..] -[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units={affected} -C debuginfo=2 [..] [COMPILING] foo [..] -[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C codegen-units={affected} -C debuginfo=2 [..] [RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units=3 -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C codegen-units={affected} -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units={affected} -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C codegen-units=3 -C debuginfo=2 --test [..] [RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C codegen-units=3 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C codegen-units={affected} -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C codegen-units=3 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C panic=abort -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C panic=abort -C codegen-units={affected} -C debuginfo=2 [..] [FINISHED] test [unoptimized + debuginfo] [..] [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo [RUNNING] `rustdoc [..]--test [..] -").run(); +", affected=affected)).run(); p.cargo("test -vv") + .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -328,6 +345,8 @@ fn profile_selection_test() { #[cargo_test] fn profile_selection_test_release() { let p = all_target_project(); + let affected = if is_nightly() { 2 } else { 4 }; + // `test --release` // NOTES: // - Dependency profiles: @@ -349,7 +368,7 @@ fn profile_selection_test_release() { // bin release test // bin release build // - p.cargo("test --release -vv").with_stderr_unordered("\ + p.cargo("test --release -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] @@ -361,9 +380,9 @@ fn profile_selection_test_release() { [foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..] -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=2 --test [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units={affected} --test [..] +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units={affected} --test [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units={affected} --test [..] [RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=2 [..] [FINISHED] release [optimized] [..] @@ -372,8 +391,9 @@ fn profile_selection_test_release() { [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo [RUNNING] `rustdoc [..]--test [..]` -").run(); +", affected=affected)).run(); p.cargo("test --release -vv") + .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -393,6 +413,7 @@ fn profile_selection_test_release() { #[cargo_test] fn profile_selection_bench() { let p = all_target_project(); + let affected = if is_nightly() { 4 } else { 2 }; // `bench` // NOTES: @@ -414,28 +435,29 @@ fn profile_selection_bench() { // bin bench test(bench) // bin bench build // - p.cargo("bench -vv").with_stderr_unordered("\ + p.cargo("bench -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ [COMPILING] bar [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=4 [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=4 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units={affected} [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units={affected} [..] [COMPILING] bdep [..] -[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=4 [..] +[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units={affected} [..] [COMPILING] foo [..] -[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C codegen-units=4 [..] +[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C codegen-units={affected} [..] [RUNNING] `[..]target/release/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=4 [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=4 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units={affected} [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units={affected} [..] [RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..] [RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..] [RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]link -C opt-level=3 -C codegen-units=4 --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units=4 [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C opt-level=3 -C panic=abort -C codegen-units={affected} [..] [FINISHED] bench [optimized] [..] [RUNNING] `[..]/deps/foo-[..] --bench` [RUNNING] `[..]/deps/foo-[..] --bench` [RUNNING] `[..]/deps/bench1-[..] --bench` -").run(); +", affected=affected)).run(); p.cargo("bench -vv") + .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -478,7 +500,7 @@ fn profile_selection_check_all_targets() { // bin dev check // bin dev-panic check-test (checking bin as a unittest) // - p.cargo("check --all-targets -vv").with_stderr_unordered("\ + p.cargo("check --all-targets -vv").masquerade_as_nightly_cargo().with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]metadata -C codegen-units=1 -C debuginfo=2 [..] @@ -504,6 +526,7 @@ fn profile_selection_check_all_targets() { // rechecked. // See PR rust-lang/rust#49289 and issue rust-lang/cargo#3624. p.cargo("check --all-targets -vv") + .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -523,7 +546,7 @@ fn profile_selection_check_all_targets_release() { // This is a pretty straightforward variant of // `profile_selection_check_all_targets` that uses `release` instead of // `dev` for all targets. - p.cargo("check --all-targets --release -vv").with_stderr_unordered("\ + p.cargo("check --all-targets --release -vv").masquerade_as_nightly_cargo().with_stderr_unordered("\ [COMPILING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C opt-level=3 -C codegen-units=2 [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]metadata -C opt-level=3 -C codegen-units=2 [..] @@ -546,6 +569,7 @@ fn profile_selection_check_all_targets_release() { ").run(); p.cargo("check --all-targets --release -vv") + .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -560,6 +584,8 @@ fn profile_selection_check_all_targets_release() { #[cargo_test] fn profile_selection_check_all_targets_test() { let p = all_target_project(); + let affected = if is_nightly() { 3 } else { 1 }; + // `check --profile=test` // - Dependency profiles: // Pkg Target Profile Action Reason @@ -581,26 +607,27 @@ fn profile_selection_check_all_targets_test() { // bench test-panic check-test // bin test-panic check-test // - p.cargo("check --all-targets --profile=test -vv").with_stderr_unordered("\ + p.cargo("check --all-targets --profile=test -vv").masquerade_as_nightly_cargo().with_stderr_unordered(format!("\ [COMPILING] bar [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]metadata -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units={affected} -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]metadata -C codegen-units={affected} -C debuginfo=2 [..] [COMPILING] bdep[..] -[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units={affected} -C debuginfo=2 [..] [COMPILING] foo [..] -[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C codegen-units=3 -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link -C codegen-units={affected} -C debuginfo=2 [..] [RUNNING] `[..]target/debug/build/foo-[..]/build-script-build` [foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0 -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]metadata -C codegen-units=3 -C debuginfo=2 [..] -[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]metadata -C codegen-units=3 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]metadata -C codegen-units=3 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]metadata -C codegen-units=3 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]metadata -C codegen-units=3 -C debuginfo=2 --test [..] -[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--emit=[..]metadata -C codegen-units=3 -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]metadata -C codegen-units={affected} -C debuginfo=2 [..] +[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--emit=[..]metadata -C codegen-units={affected} -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name test1 tests/test1.rs [..]--emit=[..]metadata -C codegen-units={affected} -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--emit=[..]metadata -C codegen-units={affected} -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name bench1 benches/bench1.rs [..]--emit=[..]metadata -C codegen-units={affected} -C debuginfo=2 --test [..] +[RUNNING] `[..] rustc --crate-name ex1 examples/ex1.rs [..]--emit=[..]metadata -C codegen-units={affected} -C debuginfo=2 --test [..] [FINISHED] test [unoptimized + debuginfo] [..] -").run(); +", affected=affected)).run(); p.cargo("check --all-targets --profile=test -vv") + .masquerade_as_nightly_cargo() .with_stderr_unordered( "\ [FRESH] bar [..] @@ -626,7 +653,7 @@ fn profile_selection_doc() { // foo custom dev* link For build.rs // // `*` = wants panic, but it is cleared when args are built. - p.cargo("doc -vv").with_stderr_unordered("\ + p.cargo("doc -vv").masquerade_as_nightly_cargo().with_stderr_unordered("\ [COMPILING] bar [..] [DOCUMENTING] bar [..] [RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C codegen-units=1 -C debuginfo=2 [..] From fad192d0dda5e9c08d348e1db5b60b3bf3621030 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Sat, 28 Sep 2019 01:10:08 +0300 Subject: [PATCH 58/58] named-profiles: fix backward compatibility for `rustc` with `--profile=check` And a small cleanup in `base_profile` to make the logic parallel to the one in `get_profile`. --- src/cargo/core/profiles.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 69b1b3764d9..7ea1cd1cf6c 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -322,7 +322,6 @@ impl Profiles { let release = match profile_kind { ProfileKind::Release => true, ProfileKind::Custom(ref s) if s == "bench" => true, - ProfileKind::Custom(ref s) if s == "test" => false, _ => false, }; @@ -397,7 +396,17 @@ impl Profiles { /// `[Finished]` line. It is not entirely accurate, since it doesn't /// select for the package that was actually built. pub fn base_profile(&self, profile_kind: &ProfileKind) -> CargoResult { - match self.by_name.get(profile_kind.name()) { + let profile_name = if !self.named_profiles_enabled { + match profile_kind { + ProfileKind::Release => "release", + ProfileKind::Custom(ref s) if s == "bench" => "bench", + _ => "dev", + } + } else { + profile_kind.name() + }; + + match self.by_name.get(profile_name) { None => failure::bail!("Profile `{}` undefined", profile_kind.name()), Some(r) => Ok(r.get_profile(None, true, UnitFor::new_normal())), }