Skip to content

Commit

Permalink
correct behavior when using force rebuild all
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshMcguigan committed Feb 20, 2019
1 parent d60af7c commit 9b3138c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
// function which will run everything in order with proper
// parallelism.
let force_rebuild = self.bcx.build_config.force_rebuild;
super::compile(&mut self, &mut queue, &mut plan, unit, exec, force_rebuild)?;
super::compile(&mut self, &mut queue, &mut plan, unit, units, exec, force_rebuild)?;
}

// Now that we've figured out everything that we're going to do, do it!
Expand Down
9 changes: 7 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ fn compile<'a, 'cfg: 'a>(
jobs: &mut JobQueue<'a, 'cfg>,
plan: &mut BuildPlan,
unit: &Unit<'a>,
units: &[Unit<'a>],
exec: &Arc<dyn Executor>,
force_rebuild: bool,
) -> CargoResult<()> {
Expand Down Expand Up @@ -176,8 +177,12 @@ fn compile<'a, 'cfg: 'a>(
drop(p);

// Be sure to compile all dependencies of this target as well.
for unit in cx.dep_targets(unit).iter() {
compile(cx, jobs, plan, unit, exec, false)?;
// But skip any units which were already selected in order to ensure the correct value is set
// for force_rebuild
for unit in cx.dep_targets(unit).iter()
.filter(|&u| !units.contains(u))
{
compile(cx, jobs, plan, unit, units, exec, false)?;
}
if build_plan {
plan.add(cx, unit)?;
Expand Down
59 changes: 59 additions & 0 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,65 @@ fn force_rebuild_displays_error() {
.run();
}

// Confirm that force rebuild works correctly with dependencies which are also a target
#[test]
fn check_force_rebuild_with_workspace_dependencies() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["a", "b", "c", "d", "e", "f"]
"#,
)
.file(
"a/Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"
[dependencies]
b = { path = "../b" }
c = { path = "../c" }
d = { path = "../d" }
e = { path = "../e" }
f = { path = "../f" }
"#,
)
.file("a/src/lib.rs", "")
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
.file("b/src/lib.rs", "")
.file("c/Cargo.toml", &basic_manifest("c", "0.0.1"))
.file("c/src/lib.rs", "")
.file("d/Cargo.toml", &basic_manifest("d", "0.0.1"))
.file("d/src/lib.rs", "")
.file("e/Cargo.toml", &basic_manifest("e", "0.0.1"))
.file("e/src/lib.rs", "")
.file("f/Cargo.toml", &basic_manifest("f", "0.0.1"))
.file("f/src/lib.rs", "")
.build();

p.cargo("check --all")
.with_stderr_contains("[CHECKING] a [..]")
.with_stderr_contains("[CHECKING] b [..]")
.with_stderr_contains("[CHECKING] c [..]")
.with_stderr_contains("[CHECKING] d [..]")
.with_stderr_contains("[CHECKING] e [..]")
.with_stderr_contains("[CHECKING] f [..]")
.run();

p.cargo("check --all -Z unstable-options --force-rebuild")
.masquerade_as_nightly_cargo()
.with_stderr_contains("[CHECKING] a [..]")
.with_stderr_contains("[CHECKING] b [..]")
.with_stderr_contains("[CHECKING] c [..]")
.with_stderr_contains("[CHECKING] d [..]")
.with_stderr_contains("[CHECKING] e [..]")
.with_stderr_contains("[CHECKING] f [..]")
.run();
}

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

0 comments on commit 9b3138c

Please sign in to comment.