Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cargo not doing anything when the input and output mtimes are equal #5919

Merged
merged 3 commits into from
Aug 22, 2018
Merged
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
19 changes: 18 additions & 1 deletion src/cargo/core/compiler/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,24 @@ where
return true;
}
};
if mtime2 > mtime {

// Note that equal mtimes are considered "stale". For filesystems with
// not much timestamp precision like 1s this is a conservative approximation
// to handle the case where a file is modified within the same second after
// a build finishes. We want to make sure that incremental rebuilds pick that up!
//
// For filesystems with nanosecond precision it's been seen in the wild that
// its "nanosecond precision" isn't really nanosecond-accurate. It turns out that
// kernels may cache the current time so files created at different times actually
// list the same nanosecond precision. Some digging on #5919 picked up that the
// kernel caches the current time between timer ticks, which could mean that if
// a file is updated at most 10ms after a build finishes then Cargo may not
// pick up the build changes.
//
// All in all, the equality check here is a conservative assumption that,
// if equal, files were changed just after a previous build finished.
// It's hoped this doesn't cause too many issues in practice!
if mtime2 >= mtime {
info!("stale: {} -- {} vs {}", path.display(), mtime2, mtime);
true
} else {
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,7 @@ fn rebuild_only_on_explicit_paths() {
sleep_ms(1000);
File::create(p.root().join("foo")).unwrap();
File::create(p.root().join("bar")).unwrap();
sleep_ms(1000); // make sure the to-be-created outfile has a timestamp distinct from the infiles

// now the exist, so run once, catch the mtime, then shouldn't run again
println!("run with");
Expand Down