Skip to content

Commit 502f0ae

Browse files
committed
Auto merge of #5919 - RalfJung:mtime, r=alexcrichton
fix cargo not doing anything when the input and output mtimes are equal That's a problem as the input may have changed in that same second but after the output got generated! Fixes #5918
2 parents 1ee1ef0 + b1fbafd commit 502f0ae

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/cargo/core/compiler/fingerprint.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,24 @@ where
744744
return true;
745745
}
746746
};
747-
if mtime2 > mtime {
747+
748+
// Note that equal mtimes are considered "stale". For filesystems with
749+
// not much timestamp precision like 1s this is a conservative approximation
750+
// to handle the case where a file is modified within the same second after
751+
// a build finishes. We want to make sure that incremental rebuilds pick that up!
752+
//
753+
// For filesystems with nanosecond precision it's been seen in the wild that
754+
// its "nanosecond precision" isn't really nanosecond-accurate. It turns out that
755+
// kernels may cache the current time so files created at different times actually
756+
// list the same nanosecond precision. Some digging on #5919 picked up that the
757+
// kernel caches the current time between timer ticks, which could mean that if
758+
// a file is updated at most 10ms after a build finishes then Cargo may not
759+
// pick up the build changes.
760+
//
761+
// All in all, the equality check here is a conservative assumption that,
762+
// if equal, files were changed just after a previous build finished.
763+
// It's hoped this doesn't cause too many issues in practice!
764+
if mtime2 >= mtime {
748765
info!("stale: {} -- {} vs {}", path.display(), mtime2, mtime);
749766
true
750767
} else {

tests/testsuite/build_script.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,7 @@ fn rebuild_only_on_explicit_paths() {
25452545
sleep_ms(1000);
25462546
File::create(p.root().join("foo")).unwrap();
25472547
File::create(p.root().join("bar")).unwrap();
2548+
sleep_ms(1000); // make sure the to-be-created outfile has a timestamp distinct from the infiles
25482549

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

0 commit comments

Comments
 (0)