Skip to content

Commit 9b3138c

Browse files
committed
correct behavior when using force rebuild all
1 parent d60af7c commit 9b3138c

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

src/cargo/core/compiler/context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
146146
// function which will run everything in order with proper
147147
// parallelism.
148148
let force_rebuild = self.bcx.build_config.force_rebuild;
149-
super::compile(&mut self, &mut queue, &mut plan, unit, exec, force_rebuild)?;
149+
super::compile(&mut self, &mut queue, &mut plan, unit, units, exec, force_rebuild)?;
150150
}
151151

152152
// Now that we've figured out everything that we're going to do, do it!

src/cargo/core/compiler/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fn compile<'a, 'cfg: 'a>(
129129
jobs: &mut JobQueue<'a, 'cfg>,
130130
plan: &mut BuildPlan,
131131
unit: &Unit<'a>,
132+
units: &[Unit<'a>],
132133
exec: &Arc<dyn Executor>,
133134
force_rebuild: bool,
134135
) -> CargoResult<()> {
@@ -176,8 +177,12 @@ fn compile<'a, 'cfg: 'a>(
176177
drop(p);
177178

178179
// Be sure to compile all dependencies of this target as well.
179-
for unit in cx.dep_targets(unit).iter() {
180-
compile(cx, jobs, plan, unit, exec, false)?;
180+
// But skip any units which were already selected in order to ensure the correct value is set
181+
// for force_rebuild
182+
for unit in cx.dep_targets(unit).iter()
183+
.filter(|&u| !units.contains(u))
184+
{
185+
compile(cx, jobs, plan, unit, units, exec, false)?;
181186
}
182187
if build_plan {
183188
plan.add(cx, unit)?;

tests/testsuite/check.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,65 @@ fn force_rebuild_displays_error() {
221221
.run();
222222
}
223223

224+
// Confirm that force rebuild works correctly with dependencies which are also a target
225+
#[test]
226+
fn check_force_rebuild_with_workspace_dependencies() {
227+
let p = project()
228+
.file(
229+
"Cargo.toml",
230+
r#"
231+
[workspace]
232+
members = ["a", "b", "c", "d", "e", "f"]
233+
"#,
234+
)
235+
.file(
236+
"a/Cargo.toml",
237+
r#"
238+
[package]
239+
name = "a"
240+
version = "0.1.0"
241+
242+
[dependencies]
243+
b = { path = "../b" }
244+
c = { path = "../c" }
245+
d = { path = "../d" }
246+
e = { path = "../e" }
247+
f = { path = "../f" }
248+
"#,
249+
)
250+
.file("a/src/lib.rs", "")
251+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
252+
.file("b/src/lib.rs", "")
253+
.file("c/Cargo.toml", &basic_manifest("c", "0.0.1"))
254+
.file("c/src/lib.rs", "")
255+
.file("d/Cargo.toml", &basic_manifest("d", "0.0.1"))
256+
.file("d/src/lib.rs", "")
257+
.file("e/Cargo.toml", &basic_manifest("e", "0.0.1"))
258+
.file("e/src/lib.rs", "")
259+
.file("f/Cargo.toml", &basic_manifest("f", "0.0.1"))
260+
.file("f/src/lib.rs", "")
261+
.build();
262+
263+
p.cargo("check --all")
264+
.with_stderr_contains("[CHECKING] a [..]")
265+
.with_stderr_contains("[CHECKING] b [..]")
266+
.with_stderr_contains("[CHECKING] c [..]")
267+
.with_stderr_contains("[CHECKING] d [..]")
268+
.with_stderr_contains("[CHECKING] e [..]")
269+
.with_stderr_contains("[CHECKING] f [..]")
270+
.run();
271+
272+
p.cargo("check --all -Z unstable-options --force-rebuild")
273+
.masquerade_as_nightly_cargo()
274+
.with_stderr_contains("[CHECKING] a [..]")
275+
.with_stderr_contains("[CHECKING] b [..]")
276+
.with_stderr_contains("[CHECKING] c [..]")
277+
.with_stderr_contains("[CHECKING] d [..]")
278+
.with_stderr_contains("[CHECKING] e [..]")
279+
.with_stderr_contains("[CHECKING] f [..]")
280+
.run();
281+
}
282+
224283
// Checks that where a project has both a lib and a bin, the lib is only checked
225284
// not built.
226285
#[test]

0 commit comments

Comments
 (0)