Skip to content

Commit

Permalink
Auto merge of #7865 - ehuss:fix-rebuild_sub_package_then_while_packag…
Browse files Browse the repository at this point in the history
…e, 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.
  • Loading branch information
bors committed Feb 5, 2020
2 parents 06834dc + da8d174 commit 19d38e5
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,49 @@ fn rebuild_sub_package_then_while_package() {
.file("b/src/lib.rs", "")
.build();

p.cargo("build").run();
p.cargo("build")
.with_stderr(
"\
[COMPILING] b [..]
[COMPILING] a [..]
[COMPILING] foo [..]
[FINISHED] dev [..]
",
)
.run();

File::create(&p.root().join("b/src/lib.rs"))
.unwrap()
.write_all(br#"pub fn b() {}"#)
.unwrap();
if is_coarse_mtime() {
sleep_ms(1000);
}
p.change_file("b/src/lib.rs", "pub fn b() {}");

p.cargo("build -pb").run();
p.cargo("build -pb -v")
.with_stderr(
"\
[COMPILING] b [..]
[RUNNING] `rustc --crate-name b [..]
[FINISHED] dev [..]
",
)
.run();

File::create(&p.root().join("src/lib.rs"))
.unwrap()
.write_all(br#"extern crate a; extern crate b; pub fn toplevel() {}"#)
.unwrap();
p.change_file(
"src/lib.rs",
"extern crate a; extern crate b; pub fn toplevel() {}",
);

p.cargo("build").run();
p.cargo("build -v")
.with_stderr(
"\
[FRESH] b [..]
[COMPILING] a [..]
[RUNNING] `rustc --crate-name a [..]
[COMPILING] foo [..]
[RUNNING] `rustc --crate-name foo [..]
[FINISHED] dev [..]
",
)
.run();
}

#[cargo_test]
Expand Down

0 comments on commit 19d38e5

Please sign in to comment.