Skip to content

Commit 19d38e5

Browse files
committed
Auto merge of #7865 - ehuss:fix-rebuild_sub_package_then_while_package, r=alexcrichton
Fix rebuild_sub_package_then_while_package on HFS. This test was flaky on HFS ([azure failure](https://dev.azure.com/rust-lang/cargo/_build/results?buildId=20144&view=logs&j=a5e52b91-c83f-5429-4a68-c246fc63a4f7&t=d4864165-4be3-5e34-b483-a6b05303aa68&l=2018)), resulting in this error: ``` Compiling foo v0.0.1 (/Users/runner/runners/2.164.7/work/1/s/target/cit/t750/foo) error[E0460]: found possibly newer version of crate `b` which `a` depends on --> src/lib.rs:1:1 | 1 | extern crate a; extern crate b; pub fn toplevel() {} | ^^^^^^^^^^^^^^^ | = note: perhaps that crate needs to be recompiled? = note: the following crate versions were found: crate `b`: /Users/runner/runners/2.164.7/work/1/s/target/cit/t750/foo/target/debug/deps/libb-98160c67a5811c37.rlib crate `b`: /Users/runner/runners/2.164.7/work/1/s/target/cit/t750/foo/target/debug/deps/libb-98160c67a5811c37.rmeta crate `a`: /Users/runner/runners/2.164.7/work/1/s/target/cit/t750/foo/target/debug/deps/liba-7d2b9ccd932a36e9.rmeta ``` There are two race-condition bugs here. Race 1: The second cargo build command (`cargo build -pb`) would sometimes not build, because it thought `b` is fresh. This can happen when the first build finishes and changing `b/src/lib.rs` happen within the same second. (#5918) The test silently ignored this failure, this is not the cause of the CI failure, though. Race 2: The first and second build commands work as expected. The third build command fails because it thinks both `a` and `b` are "fresh". However, `b` was just rebuilt, and `a` depends on it, so `a` should have been rebuilt. It thinks `a` is fresh because `a`'s mtime is equal to `b` when `b` finishes compiling within the same second that the first build finished. The solution here is to make sure the second step happens well after the first. The underlying problem is #5918.
2 parents 06834dc + da8d174 commit 19d38e5

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

tests/testsuite/freshness.rs

+39-11
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,49 @@ fn rebuild_sub_package_then_while_package() {
136136
.file("b/src/lib.rs", "")
137137
.build();
138138

139-
p.cargo("build").run();
139+
p.cargo("build")
140+
.with_stderr(
141+
"\
142+
[COMPILING] b [..]
143+
[COMPILING] a [..]
144+
[COMPILING] foo [..]
145+
[FINISHED] dev [..]
146+
",
147+
)
148+
.run();
140149

141-
File::create(&p.root().join("b/src/lib.rs"))
142-
.unwrap()
143-
.write_all(br#"pub fn b() {}"#)
144-
.unwrap();
150+
if is_coarse_mtime() {
151+
sleep_ms(1000);
152+
}
153+
p.change_file("b/src/lib.rs", "pub fn b() {}");
145154

146-
p.cargo("build -pb").run();
155+
p.cargo("build -pb -v")
156+
.with_stderr(
157+
"\
158+
[COMPILING] b [..]
159+
[RUNNING] `rustc --crate-name b [..]
160+
[FINISHED] dev [..]
161+
",
162+
)
163+
.run();
147164

148-
File::create(&p.root().join("src/lib.rs"))
149-
.unwrap()
150-
.write_all(br#"extern crate a; extern crate b; pub fn toplevel() {}"#)
151-
.unwrap();
165+
p.change_file(
166+
"src/lib.rs",
167+
"extern crate a; extern crate b; pub fn toplevel() {}",
168+
);
152169

153-
p.cargo("build").run();
170+
p.cargo("build -v")
171+
.with_stderr(
172+
"\
173+
[FRESH] b [..]
174+
[COMPILING] a [..]
175+
[RUNNING] `rustc --crate-name a [..]
176+
[COMPILING] foo [..]
177+
[RUNNING] `rustc --crate-name foo [..]
178+
[FINISHED] dev [..]
179+
",
180+
)
181+
.run();
154182
}
155183

156184
#[cargo_test]

0 commit comments

Comments
 (0)