Skip to content

Commit 9bfaf2e

Browse files
committed
Auto merge of #6493 - ehuss:fix-fingerprint-patch, r=alexcrichton
Fix fingerprint calculation for patched deps. If you have A→B→C where B and C are in a registry, and you `[patch]` C, the fingerprint calculation wasn't working correctly when C changes. The following sequence illustrates the problem: 1. Do a build from scratch. 2. Touch a file in C. 3. Build again. Everything rebuilds as expected. 4. Build again. You would expect this to be all fresh, but it rebuilds A. The problem is the hash-busting doesn't propagate up to parents from dependencies. Normal targets normally aren't a problem because they have a `LocalFingerprint::MtimeBased` style local value which always recomputes the hash. However, registry dependencies have a `Precalculated` style local value which never recomputes the hash. The solution here is to always recompute the hash. This shouldn't be too expensive, and is only done when writing the fingerprint, which should only happen when the target is dirty. I'm not entirely certain why the caching logic was added in #4125. Fixes rust-lang/rust#57142
2 parents 6e10374 + ed98cab commit 9bfaf2e

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

src/cargo/core/compiler/fingerprint.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ impl Fingerprint {
236236
}
237237

238238
fn update_local(&self, root: &Path) -> CargoResult<()> {
239-
let mut hash_busted = false;
240239
for local in self.local.iter() {
241240
match *local {
242241
LocalFingerprint::MtimeBased(ref slot, ref path) => {
@@ -246,12 +245,9 @@ impl Fingerprint {
246245
}
247246
LocalFingerprint::EnvBased(..) | LocalFingerprint::Precalculated(..) => continue,
248247
}
249-
hash_busted = true;
250248
}
251249

252-
if hash_busted {
253-
*self.memoized_hash.lock().unwrap() = None;
254-
}
250+
*self.memoized_hash.lock().unwrap() = None;
255251
Ok(())
256252
}
257253

tests/testsuite/freshness.rs

+58-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::io::prelude::*;
44
use crate::support::paths::CargoPathExt;
55
use crate::support::registry::Package;
66
use crate::support::sleep_ms;
7-
use crate::support::{basic_manifest, project};
7+
use crate::support::{basic_manifest, is_coarse_mtime, project};
88

99
#[test]
1010
fn modifying_and_moving() {
@@ -1252,3 +1252,60 @@ fn reuse_panic_pm() {
12521252
)
12531253
.run();
12541254
}
1255+
1256+
#[test]
1257+
fn bust_patched_dep() {
1258+
Package::new("registry1", "0.1.0").publish();
1259+
Package::new("registry2", "0.1.0")
1260+
.dep("registry1", "0.1.0")
1261+
.publish();
1262+
1263+
let p = project()
1264+
.file(
1265+
"Cargo.toml",
1266+
r#"
1267+
[package]
1268+
name = "foo"
1269+
version = "0.0.1"
1270+
1271+
[dependencies]
1272+
registry2 = "0.1.0"
1273+
1274+
[patch.crates-io]
1275+
registry1 = { path = "reg1new" }
1276+
"#,
1277+
)
1278+
.file("src/lib.rs", "")
1279+
.file("reg1new/Cargo.toml", &basic_manifest("registry1", "0.1.0"))
1280+
.file("reg1new/src/lib.rs", "")
1281+
.build();
1282+
1283+
p.cargo("build").run();
1284+
1285+
File::create(&p.root().join("reg1new/src/lib.rs")).unwrap();
1286+
if is_coarse_mtime() {
1287+
sleep_ms(1000);
1288+
}
1289+
1290+
p.cargo("build")
1291+
.with_stderr(
1292+
"\
1293+
[COMPILING] registry1 v0.1.0 ([..])
1294+
[COMPILING] registry2 v0.1.0
1295+
[COMPILING] foo v0.0.1 ([..])
1296+
[FINISHED] [..]
1297+
",
1298+
)
1299+
.run();
1300+
1301+
p.cargo("build -v")
1302+
.with_stderr(
1303+
"\
1304+
[FRESH] registry1 v0.1.0 ([..])
1305+
[FRESH] registry2 v0.1.0
1306+
[FRESH] foo v0.0.1 ([..])
1307+
[FINISHED] [..]
1308+
",
1309+
)
1310+
.run();
1311+
}

0 commit comments

Comments
 (0)