Skip to content

Commit 797ea15

Browse files
committed
Auto merge of #7050 - schomatis:fix/fingerprint/dont-update-intermediate-artifacts-mtime, r=Eh2406
fix(fingerpring): do not touch intermediate artifacts Fixes #6972. The newly introduced [test](9aa7a4d) is [failing](https://travis-ci.com/rust-lang/cargo/jobs/209849725#L2569-L2580) as discussed in #6972 (comment) (replicating the issue). Removing the `touching of intermediate artifacts` as suggested fixes the issue, but makes the old test `simple_deps_cleaner_does_not_rebuild` fail. The `simple_deps_cleaner_does_not_rebuild` test is not needed anymore so it's removed. r? @Eh2406
2 parents 37cb9bb + 009876a commit 797ea15

File tree

2 files changed

+5
-59
lines changed

2 files changed

+5
-59
lines changed

src/cargo/core/compiler/fingerprint.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,7 @@ impl Fingerprint {
756756
/// dependencies up to this unit as well. This function assumes that the
757757
/// unit starts out as `FsStatus::Stale` and then it will optionally switch
758758
/// it to `UpToDate` if it can.
759-
fn check_filesystem(
760-
&mut self,
761-
pkg_root: &Path,
762-
target_root: &Path,
763-
mtime_on_use: bool,
764-
) -> CargoResult<()> {
759+
fn check_filesystem(&mut self, pkg_root: &Path, target_root: &Path) -> CargoResult<()> {
765760
assert!(!self.fs_status.up_to_date());
766761

767762
let mut mtimes = HashMap::new();
@@ -781,10 +776,6 @@ impl Fingerprint {
781776
return Ok(());
782777
}
783778
};
784-
if mtime_on_use {
785-
let t = FileTime::from_system_time(SystemTime::now());
786-
filetime::set_file_times(output, t, t)?;
787-
}
788779
assert!(mtimes.insert(output.clone(), mtime).is_none());
789780
}
790781

@@ -1024,8 +1015,7 @@ fn calculate<'a, 'cfg>(
10241015
// After we built the initial `Fingerprint` be sure to update the
10251016
// `fs_status` field of it.
10261017
let target_root = target_root(cx, unit);
1027-
let mtime_on_use = cx.bcx.config.cli_unstable().mtime_on_use;
1028-
fingerprint.check_filesystem(unit.pkg.root(), &target_root, mtime_on_use)?;
1018+
fingerprint.check_filesystem(unit.pkg.root(), &target_root)?;
10291019

10301020
let fingerprint = Arc::new(fingerprint);
10311021
cx.fingerprints.insert(*unit, Arc::clone(&fingerprint));

tests/testsuite/freshness.rs

+3-47
Original file line numberDiff line numberDiff line change
@@ -1170,31 +1170,8 @@ fn changing_rustflags_is_cached() {
11701170
.run();
11711171
}
11721172

1173-
fn simple_deps_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) {
1174-
// Cargo is experimenting with letting outside projects develop some
1175-
// limited forms of GC for target_dir. This is one of the forms.
1176-
// Specifically, Cargo is updating the mtime of files in
1177-
// target/profile/deps each time it uses the file.
1178-
// So a cleaner can remove files older then a time stamp without
1179-
// effecting any builds that happened since that time stamp.
1180-
let mut cleand = false;
1181-
dir.push("deps");
1182-
for dep in fs::read_dir(&dir).unwrap() {
1183-
let dep = dep.unwrap();
1184-
if filetime::FileTime::from_last_modification_time(&dep.metadata().unwrap()) <= timestamp {
1185-
fs::remove_file(dep.path()).unwrap();
1186-
println!("remove: {:?}", dep.path());
1187-
cleand = true;
1188-
}
1189-
}
1190-
assert!(
1191-
cleand,
1192-
"called simple_deps_cleaner, but there was nothing to remove"
1193-
);
1194-
}
1195-
11961173
#[cargo_test]
1197-
fn simple_deps_cleaner_does_not_rebuild() {
1174+
fn update_dependency_mtime_does_not_rebuild() {
11981175
let p = project()
11991176
.file(
12001177
"Cargo.toml",
@@ -1212,9 +1189,6 @@ fn simple_deps_cleaner_does_not_rebuild() {
12121189
.file("bar/src/lib.rs", "")
12131190
.build();
12141191

1215-
p.cargo("build -Z mtime-on-use")
1216-
.masquerade_as_nightly_cargo()
1217-
.run();
12181192
p.cargo("build -Z mtime-on-use")
12191193
.masquerade_as_nightly_cargo()
12201194
.env("RUSTFLAGS", "-C target-cpu=native")
@@ -1225,36 +1199,18 @@ fn simple_deps_cleaner_does_not_rebuild() {
12251199
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
12261200
)
12271201
.run();
1228-
if is_coarse_mtime() {
1229-
sleep_ms(1000);
1230-
}
1231-
let timestamp = filetime::FileTime::from_system_time(SystemTime::now());
1232-
if is_coarse_mtime() {
1233-
sleep_ms(1000);
1234-
}
1235-
// This does not make new files, but it does update the mtime.
1236-
p.cargo("build -Z mtime-on-use")
1202+
// This does not make new files, but it does update the mtime of the dependency.
1203+
p.cargo("build -p bar -Z mtime-on-use")
12371204
.masquerade_as_nightly_cargo()
12381205
.env("RUSTFLAGS", "-C target-cpu=native")
12391206
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
12401207
.run();
1241-
simple_deps_cleaner(p.target_debug_dir(), timestamp);
12421208
// This should not recompile!
12431209
p.cargo("build -Z mtime-on-use")
12441210
.masquerade_as_nightly_cargo()
12451211
.env("RUSTFLAGS", "-C target-cpu=native")
12461212
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
12471213
.run();
1248-
// But this should be cleaned and so need a rebuild
1249-
p.cargo("build -Z mtime-on-use")
1250-
.masquerade_as_nightly_cargo()
1251-
.with_stderr(
1252-
"\
1253-
[COMPILING] bar v0.0.1 ([..])
1254-
[COMPILING] foo v0.0.1 ([..])
1255-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
1256-
)
1257-
.run();
12581214
}
12591215

12601216
fn fingerprint_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) {

0 commit comments

Comments
 (0)