From dac037bc10962e286de9de11907074f6f91e9fe2 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Thu, 14 Feb 2019 05:12:59 -0700 Subject: [PATCH 1/7] check subcommand should force rebuild --- src/bin/cargo/commands/check.rs | 6 +++++- tests/testsuite/check.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/bin/cargo/commands/check.rs b/src/bin/cargo/commands/check.rs index b3dfeb15d81..bfb3e57ae6d 100644 --- a/src/bin/cargo/commands/check.rs +++ b/src/bin/cargo/commands/check.rs @@ -68,7 +68,11 @@ 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 mut compile_opts = args.compile_options(config, mode, Some(&ws))?; + + // force rebuild of this module + // in order to show warnings even if the project was previously checked / built + compile_opts.build_config.force_rebuild = true; ops::compile(&ws, &compile_opts)?; Ok(()) diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 390293d0f8e..3d01fa9e174 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -195,6 +195,34 @@ fn build_check() { foo.cargo("check").run(); } +// Checks that warnings are displayed even if the project has not changed since the last check/build +#[test] +fn build_check_displays_error() { + let foo = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#, + ) + .file( + "src/main.rs", + "use std::default::Default; fn main() {}", + ) + .build(); + + foo.cargo("check") + .with_stderr_contains("[..]warning: unused import[..]") + .run(); + + foo.cargo("check") + .with_stderr_contains("[..]warning: unused import[..]") + .run(); +} + // Checks that where a project has both a lib and a bin, the lib is only checked // not built. #[test] From 3d140e9043384131ff3e31529da9671c774439d1 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Thu, 14 Feb 2019 07:45:54 -0700 Subject: [PATCH 2/7] update profile targets tests for new cargo check behavior --- tests/testsuite/profile_targets.rs | 52 +++++++----------------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index 8994e7e8f94..9496dc2247c 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -1,4 +1,3 @@ -use crate::support::is_nightly; use crate::support::{basic_manifest, project, Project}; // These tests try to exercise exactly which profiles are selected for every @@ -454,11 +453,6 @@ fn profile_selection_bench() { #[test] fn profile_selection_check_all_targets() { - if !is_nightly() { - // This can be removed once 1.27 is stable, see below. - return; - } - let p = all_target_project(); // check // NOTES: @@ -512,24 +506,15 @@ fn profile_selection_check_all_targets() { // See https://github.com/rust-lang/rust/pull/49289 and // https://github.com/rust-lang/cargo/issues/3624 p.cargo("check --all-targets -vv") - .with_stderr_unordered( - "\ -[FRESH] bar [..] -[FRESH] bdep [..] -[FRESH] foo [..] -[FINISHED] dev [unoptimized + debuginfo] [..] -", - ) + .with_stderr_contains("[FRESH] bar [..]") + .with_stderr_contains("[FRESH] bdep [..]") + .with_stderr_contains("[CHECKING] foo [..]") + .with_stderr_contains("[FINISHED] dev [unoptimized + debuginfo] [..]") .run(); } #[test] fn profile_selection_check_all_targets_release() { - if !is_nightly() { - // See note in profile_selection_check_all_targets. - return; - } - let p = all_target_project(); // check --release // https://github.com/rust-lang/cargo/issues/5218 @@ -559,24 +544,15 @@ fn profile_selection_check_all_targets_release() { ").run(); p.cargo("check --all-targets --release -vv") - .with_stderr_unordered( - "\ -[FRESH] bar [..] -[FRESH] bdep [..] -[FRESH] foo [..] -[FINISHED] release [optimized] [..] -", - ) + .with_stderr_contains("[FRESH] bar [..]") + .with_stderr_contains("[FRESH] bdep [..]") + .with_stderr_contains("[CHECKING] foo [..]") + .with_stderr_contains("[FINISHED] release [optimized] [..]") .run(); } #[test] fn profile_selection_check_all_targets_test() { - if !is_nightly() { - // See note in profile_selection_check_all_targets. - return; - } - let p = all_target_project(); // check --profile=test // NOTES: @@ -622,14 +598,10 @@ fn profile_selection_check_all_targets_test() { ").run(); p.cargo("check --all-targets --profile=test -vv") - .with_stderr_unordered( - "\ -[FRESH] bar [..] -[FRESH] bdep [..] -[FRESH] foo [..] -[FINISHED] dev [unoptimized + debuginfo] [..] -", - ) + .with_stderr_contains("[FRESH] bar [..]") + .with_stderr_contains("[FRESH] bdep [..]") + .with_stderr_contains("[CHECKING] foo [..]") + .with_stderr_contains("[FINISHED] dev [unoptimized + debuginfo] [..]") .run(); } From ffdbeac66faab6c20cab6e6e9ff6de781071a885 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sat, 16 Feb 2019 08:59:01 -0700 Subject: [PATCH 3/7] add force-rebuild flag to check subcommand --- src/bin/cargo/commands/check.rs | 7 ++---- src/cargo/util/command_prelude.rs | 5 ++++ tests/testsuite/check.rs | 7 +++--- tests/testsuite/profile_targets.rs | 37 ++++++++++++++++++++---------- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/bin/cargo/commands/check.rs b/src/bin/cargo/commands/check.rs index bfb3e57ae6d..a6a32e781e6 100644 --- a/src/bin/cargo/commands/check.rs +++ b/src/bin/cargo/commands/check.rs @@ -26,6 +26,7 @@ pub fn cli() -> App { "Check all targets", ) .arg_release("Check artifacts in release mode, with optimizations") + .arg_force_rebuild("Force rebuild of this crate") .arg(opt("profile", "Profile to build the selected target for").value_name("PROFILE")) .arg_features() .arg_target_triple("Check for the target triple") @@ -68,11 +69,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { } }; let mode = CompileMode::Check { test }; - let mut compile_opts = args.compile_options(config, mode, Some(&ws))?; - - // force rebuild of this module - // in order to show warnings even if the project was previously checked / built - compile_opts.build_config.force_rebuild = true; + let compile_opts = args.compile_options(config, mode, Some(&ws))?; ops::compile(&ws, &compile_opts)?; Ok(()) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index a8ddfdb94dd..7dfc87bc6ab 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -185,6 +185,10 @@ pub trait AppExt: Sized { fn arg_dry_run(self, dry_run: &'static str) -> Self { self._arg(opt("dry-run", dry_run)) } + + fn arg_force_rebuild(self, force_rebuild: &'static str) -> Self { + self._arg(opt("force-rebuild", force_rebuild)) + } } impl AppExt for App { @@ -315,6 +319,7 @@ pub trait ArgMatchesExt { build_config.message_format = message_format; build_config.release = self._is_present("release"); build_config.build_plan = self._is_present("build-plan"); + build_config.force_rebuild = self._is_present("force-rebuild"); if build_config.build_plan && !config.cli_unstable().unstable_options { Err(failure::format_err!( "`--build-plan` flag is unstable, pass `-Z unstable-options` to enable it" diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 3d01fa9e174..4ac0c30fe17 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -195,9 +195,10 @@ fn build_check() { foo.cargo("check").run(); } -// Checks that warnings are displayed even if the project has not changed since the last check/build +// Checks that --force-rebuild displays warnings even if the project has not changed +// since the last check/build #[test] -fn build_check_displays_error() { +fn force_rebuild_displays_error() { let foo = project() .file( "Cargo.toml", @@ -218,7 +219,7 @@ fn build_check_displays_error() { .with_stderr_contains("[..]warning: unused import[..]") .run(); - foo.cargo("check") + foo.cargo("check --force-rebuild") .with_stderr_contains("[..]warning: unused import[..]") .run(); } diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index 9496dc2247c..a62f1c9248d 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -1,3 +1,4 @@ +use crate::support::is_nightly; use crate::support::{basic_manifest, project, Project}; // These tests try to exercise exactly which profiles are selected for every @@ -506,10 +507,14 @@ fn profile_selection_check_all_targets() { // See https://github.com/rust-lang/rust/pull/49289 and // https://github.com/rust-lang/cargo/issues/3624 p.cargo("check --all-targets -vv") - .with_stderr_contains("[FRESH] bar [..]") - .with_stderr_contains("[FRESH] bdep [..]") - .with_stderr_contains("[CHECKING] foo [..]") - .with_stderr_contains("[FINISHED] dev [unoptimized + debuginfo] [..]") + .with_stderr_unordered( + "\ +[FRESH] bar [..] +[FRESH] bdep [..] +[FRESH] foo [..] +[FINISHED] dev [unoptimized + debuginfo] [..] +", + ) .run(); } @@ -544,10 +549,14 @@ fn profile_selection_check_all_targets_release() { ").run(); p.cargo("check --all-targets --release -vv") - .with_stderr_contains("[FRESH] bar [..]") - .with_stderr_contains("[FRESH] bdep [..]") - .with_stderr_contains("[CHECKING] foo [..]") - .with_stderr_contains("[FINISHED] release [optimized] [..]") + .with_stderr_unordered( + "\ +[FRESH] bar [..] +[FRESH] bdep [..] +[FRESH] foo [..] +[FINISHED] release [optimized] [..] +", + ) .run(); } @@ -598,10 +607,14 @@ fn profile_selection_check_all_targets_test() { ").run(); p.cargo("check --all-targets --profile=test -vv") - .with_stderr_contains("[FRESH] bar [..]") - .with_stderr_contains("[FRESH] bdep [..]") - .with_stderr_contains("[CHECKING] foo [..]") - .with_stderr_contains("[FINISHED] dev [unoptimized + debuginfo] [..]") + .with_stderr_unordered( + "\ +[FRESH] bar [..] +[FRESH] bdep [..] +[FRESH] foo [..] +[FINISHED] dev [unoptimized + debuginfo] [..] +", + ) .run(); } From 7b0e8b8cf2c122adbab2097dd92949a38f717bc3 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sat, 16 Feb 2019 09:07:51 -0700 Subject: [PATCH 4/7] remove unused import --- tests/testsuite/profile_targets.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index a62f1c9248d..9d4be79b32b 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -1,4 +1,3 @@ -use crate::support::is_nightly; use crate::support::{basic_manifest, project, Project}; // These tests try to exercise exactly which profiles are selected for every From b06dd28f71e9f97de7321eef78941332296495c9 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sat, 16 Feb 2019 09:36:18 -0700 Subject: [PATCH 5/7] remove unneeded cargo.toml in check force rebuild test --- tests/testsuite/check.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 4ac0c30fe17..8f1ead20a2f 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -200,15 +200,6 @@ fn build_check() { #[test] fn force_rebuild_displays_error() { let foo = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - authors = [] - "#, - ) .file( "src/main.rs", "use std::default::Default; fn main() {}", From 115f3926d638f788b3e78b0d0d015184cffe40e9 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sat, 16 Feb 2019 15:32:32 -0700 Subject: [PATCH 6/7] update arg description for check force rebuild --- src/bin/cargo/commands/check.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/cargo/commands/check.rs b/src/bin/cargo/commands/check.rs index a6a32e781e6..9deee4b26e4 100644 --- a/src/bin/cargo/commands/check.rs +++ b/src/bin/cargo/commands/check.rs @@ -26,7 +26,7 @@ pub fn cli() -> App { "Check all targets", ) .arg_release("Check artifacts in release mode, with optimizations") - .arg_force_rebuild("Force rebuild of this crate") + .arg_force_rebuild("Force rebuild of the selected target(s)") .arg(opt("profile", "Profile to build the selected target for").value_name("PROFILE")) .arg_features() .arg_target_triple("Check for the target triple") From d60af7cd7c8469542ceb5ab9fcc15c30c1606e7f Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Tue, 19 Feb 2019 17:42:41 -0700 Subject: [PATCH 7/7] move --force-rebuild behind unstable flag --- src/cargo/util/command_prelude.rs | 7 ++++++- tests/testsuite/check.rs | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 7dfc87bc6ab..ae6d7923dde 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -318,8 +318,13 @@ 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.build_plan = self._is_present("build-plan"); build_config.force_rebuild = self._is_present("force-rebuild"); + if build_config.force_rebuild && !config.cli_unstable().unstable_options { + Err(failure::format_err!( + "`--force-rebuild` flag is unstable, pass `-Z unstable-options` to enable it" + ))?; + }; + build_config.build_plan = self._is_present("build-plan"); if build_config.build_plan && !config.cli_unstable().unstable_options { Err(failure::format_err!( "`--build-plan` flag is unstable, pass `-Z unstable-options` to enable it" diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 8f1ead20a2f..43afe38fe2f 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -210,7 +210,13 @@ fn force_rebuild_displays_error() { .with_stderr_contains("[..]warning: unused import[..]") .run(); - foo.cargo("check --force-rebuild") + // for now this requires the unstable feature flag, so expect an error here + let output = foo.cargo("check --force-rebuild") + .exec_with_output(); + assert!(output.is_err()); + + foo.cargo("check -Z unstable-options --force-rebuild") + .masquerade_as_nightly_cargo() // remove this when `-Z unstable-options` is no longer required .with_stderr_contains("[..]warning: unused import[..]") .run(); }