Skip to content

Commit e31003a

Browse files
committed
add a test for touching fingerprint
1 parent 80f7b90 commit e31003a

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

tests/testsuite/freshness.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,91 @@ fn simple_deps_cleaner_dose_not_rebuild() {
12571257
.run();
12581258
}
12591259

1260+
fn fingerprint_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) {
1261+
// Cargo is experimenting with letting outside projects develop some
1262+
// limited forms of GC for target_dir. This is one of the forms.
1263+
// Specifically, Cargo is updating the mtime of a file in
1264+
// target/profile/.fingerprint each time it uses the fingerprint.
1265+
// So a cleaner can remove files associated with a fingerprint
1266+
// if all the files in the fingerprint's folder are older then a time stamp without
1267+
// effecting any builds that happened since that time stamp.
1268+
let mut cleand = false;
1269+
dir.push(".fingerprint");
1270+
for fing in fs::read_dir(&dir).unwrap() {
1271+
let fing = fing.unwrap();
1272+
1273+
if fs::read_dir(fing.path()).unwrap().all(|f| {
1274+
filetime::FileTime::from_last_modification_time(&f.unwrap().metadata().unwrap())
1275+
<= timestamp
1276+
}) {
1277+
fs::remove_dir_all(fing.path()).unwrap();
1278+
// a real cleaner would remove the big files in deps and build as well
1279+
// but fingerprint is sufficient for our tests
1280+
cleand = true;
1281+
} else {
1282+
}
1283+
}
1284+
assert!(
1285+
cleand,
1286+
"called fingerprint_cleaner, but there was nothing to remove"
1287+
);
1288+
}
1289+
1290+
#[test]
1291+
fn fingerprint_cleaner_dose_not_rebuild() {
1292+
let p = project()
1293+
.file(
1294+
"Cargo.toml",
1295+
r#"
1296+
[package]
1297+
name = "foo"
1298+
version = "0.0.1"
1299+
1300+
[dependencies]
1301+
bar = { path = "bar" }
1302+
"#,
1303+
)
1304+
.file("src/lib.rs", "")
1305+
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
1306+
.file("bar/src/lib.rs", "")
1307+
.build();
1308+
1309+
p.cargo("build").run();
1310+
p.cargo("build")
1311+
.env("RUSTFLAGS", "-C target-cpu=native")
1312+
.with_stderr(
1313+
"\
1314+
[COMPILING] bar v0.0.1 ([..])
1315+
[COMPILING] foo v0.0.1 ([..])
1316+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
1317+
)
1318+
.run();
1319+
if is_coarse_mtime() {
1320+
sleep_ms(1000);
1321+
}
1322+
let timestamp = filetime::FileTime::from_system_time(SystemTime::now());
1323+
// This dose not make new files, but it dose update the mtime.
1324+
p.cargo("build")
1325+
.env("RUSTFLAGS", "-C target-cpu=native")
1326+
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
1327+
.run();
1328+
fingerprint_cleaner(p.target_debug_dir(), timestamp);
1329+
// This should not recompile!
1330+
p.cargo("build")
1331+
.env("RUSTFLAGS", "-C target-cpu=native")
1332+
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
1333+
.run();
1334+
// But this should be cleaned and so need a rebuild
1335+
p.cargo("build")
1336+
.with_stderr(
1337+
"\
1338+
[COMPILING] bar v0.0.1 ([..])
1339+
[COMPILING] foo v0.0.1 ([..])
1340+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
1341+
)
1342+
.run();
1343+
}
1344+
12601345
#[test]
12611346
fn reuse_panic_build_dep_test() {
12621347
let p = project()

0 commit comments

Comments
 (0)