Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bin/cargo/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn cli() -> App {
"Check all targets",
)
.arg_release("Check artifacts in release mode, with optimizations")
.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")
Expand Down
10 changes: 10 additions & 0 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -362,6 +366,12 @@ pub trait ArgMatchesExt {
let mut build_config = BuildConfig::new(config, self.jobs()?, &self.target(), mode)?;
build_config.message_format = message_format.unwrap_or(MessageFormat::Human);
build_config.release = self._is_present("release");
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
Expand Down
26 changes: 26 additions & 0 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,32 @@ fn build_check() {
foo.cargo("check -v").run();
}

// Checks that --force-rebuild displays warnings even if the project has not changed
// since the last check/build
#[test]
fn force_rebuild_displays_error() {
let foo = project()
.file(
"src/main.rs",
"use std::default::Default; fn main() {}",
)
.build();

foo.cargo("check")
.with_stderr_contains("[..]warning: unused import[..]")
.run();

// 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();
}

// Checks that where a project has both a lib and a bin, the lib is only checked
// not built.
#[cargo_test]
Expand Down