Skip to content

Commit 07c4885

Browse files
committed
fix(fingerprint): relative path in rustdoc fingerprint
This makes build directory portable when moving the directory around
1 parent 5bd330a commit 07c4885

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed

src/cargo/core/compiler/compilation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ impl DocMergeInfo {
428428
let mut doc_parts: Vec<_> = self
429429
.doc_parts
430430
.iter()
431-
.chain(self.fingerprint.doc_parts())
432431
.cloned()
432+
.chain(self.fingerprint.doc_parts())
433433
.collect();
434434

435435
doc_parts.sort_unstable();

src/cargo/core/compiler/fingerprint/rustdoc.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ impl RustdocFingerprint {
145145

146146
/// Persists the current fingerprint with given doc parts paths.
147147
pub fn persist(&self, doc_parts: Vec<PathBuf>) -> CargoResult<()> {
148+
// Store relative paths to the fingerprint file.
149+
let base = self.path.parent().unwrap();
150+
let doc_parts = doc_parts
151+
.into_iter()
152+
.map(|p| pathdiff::diff_paths(&p, base).unwrap_or(p))
153+
.collect();
148154
let new_fingerprint = RustdocFingerprintJson {
149155
rustc_vv: self.fingerprint.rustc_vv.clone(),
150156
doc_parts,
@@ -153,10 +159,15 @@ impl RustdocFingerprint {
153159
}
154160

155161
/// Returns absolute paths to all valid cached doc parts files.
156-
pub fn doc_parts(&self) -> impl Iterator<Item = &PathBuf> {
157-
// Doc parts may be selectively cleaned via `cargo clean -p <doc>`.
158-
// We should stop caching those.
159-
self.fingerprint.doc_parts.iter().filter(|p| p.exists())
162+
pub fn doc_parts(&self) -> impl Iterator<Item = PathBuf> {
163+
let base = self.path.parent().unwrap();
164+
self.fingerprint
165+
.doc_parts
166+
.iter()
167+
.map(|doc_part| base.join(doc_part))
168+
// Doc parts may be selectively cleaned via `cargo clean -p <doc>`.
169+
// We should stop caching those.
170+
.filter(|p| p.exists())
160171
}
161172
}
162173

tests/testsuite/doc.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,8 +3272,8 @@ fn mergeable_info_with_deps() {
32723272
str![[r#"
32733273
{
32743274
"doc_parts": [
3275-
"[ROOT]/foo/target/debug/build/dep-[HASH]/deps/dep.json",
3276-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3275+
"debug/build/dep-[HASH]/deps/dep.json",
3276+
"debug/build/foo-[HASH]/deps/foo.json"
32773277
],
32783278
"rustc_vv": "{...}"
32793279
}
@@ -3330,7 +3330,7 @@ fn mergeable_info_no_deps() {
33303330
str![[r#"
33313331
{
33323332
"doc_parts": [
3333-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3333+
"debug/build/foo-[HASH]/deps/foo.json"
33343334
],
33353335
"rustc_vv": "{...}"
33363336
}
@@ -3404,9 +3404,9 @@ fn mergeable_info_workspace() {
34043404
str![[r#"
34053405
{
34063406
"doc_parts": [
3407-
"[ROOT]/foo/target/debug/build/bar-[HASH]/deps/bar.json",
3408-
"[ROOT]/foo/target/debug/build/dep-[HASH]/deps/dep.json",
3409-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3407+
"debug/build/bar-[HASH]/deps/bar.json",
3408+
"debug/build/dep-[HASH]/deps/dep.json",
3409+
"debug/build/foo-[HASH]/deps/foo.json"
34103410
],
34113411
"rustc_vv": "{...}"
34123412
}
@@ -3473,7 +3473,7 @@ fn mergeable_info_multi_targets() {
34733473
str![[r#"
34743474
{
34753475
"doc_parts": [
3476-
"[ROOT]/foo/target/[HOST_TARGET]/debug/build/foo-[HASH]/deps/foo.json"
3476+
"debug/build/foo-[HASH]/deps/foo.json"
34773477
],
34783478
"rustc_vv": "{...}"
34793479
}
@@ -3486,7 +3486,7 @@ fn mergeable_info_multi_targets() {
34863486
str![[r#"
34873487
{
34883488
"doc_parts": [
3489-
"[ROOT]/foo/target/[ALT_TARGET]/debug/build/foo-[HASH]/deps/foo.json"
3489+
"debug/build/foo-[HASH]/deps/foo.json"
34903490
],
34913491
"rustc_vv": "{...}"
34923492
}
@@ -3533,7 +3533,7 @@ fn mergeable_info_rebuild_detection() {
35333533
str![[r#"
35343534
{
35353535
"doc_parts": [
3536-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3536+
"debug/build/foo-[HASH]/deps/foo.json"
35373537
],
35383538
"rustc_vv": "{...}"
35393539
}
@@ -3560,7 +3560,7 @@ fn mergeable_info_rebuild_detection() {
35603560
str![[r#"
35613561
{
35623562
"doc_parts": [
3563-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3563+
"debug/build/foo-[HASH]/deps/foo.json"
35643564
],
35653565
"rustc_vv": "{...}"
35663566
}
@@ -3621,7 +3621,7 @@ fn mergeable_info_rebuild_detection() {
36213621
str![[r#"
36223622
{
36233623
"doc_parts": [
3624-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3624+
"debug/build/foo-[HASH]/deps/foo.json"
36253625
],
36263626
"rustc_vv": "{...}"
36273627
}
@@ -3671,7 +3671,7 @@ fn mergeable_info_rebuild_with_depinfo() {
36713671
str![[r#"
36723672
{
36733673
"doc_parts": [
3674-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3674+
"debug/build/foo-[HASH]/deps/foo.json"
36753675
],
36763676
"rustc_vv": "{...}"
36773677
}
@@ -3698,7 +3698,7 @@ fn mergeable_info_rebuild_with_depinfo() {
36983698
str![[r#"
36993699
{
37003700
"doc_parts": [
3701-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3701+
"debug/build/foo-[HASH]/deps/foo.json"
37023702
],
37033703
"rustc_vv": "{...}"
37043704
}
@@ -3759,7 +3759,7 @@ fn mergeable_info_rebuild_with_depinfo() {
37593759
str![[r#"
37603760
{
37613761
"doc_parts": [
3762-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3762+
"debug/build/foo-[HASH]/deps/foo.json"
37633763
],
37643764
"rustc_vv": "{...}"
37653765
}
@@ -3827,7 +3827,7 @@ fn mergeable_info_additive() {
38273827
str![[r#"
38283828
{
38293829
"doc_parts": [
3830-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3830+
"debug/build/foo-[HASH]/deps/foo.json"
38313831
],
38323832
"rustc_vv": "{...}"
38333833
}
@@ -3863,8 +3863,8 @@ fn mergeable_info_additive() {
38633863
str![[r#"
38643864
{
38653865
"doc_parts": [
3866-
"[ROOT]/foo/target/debug/build/dep-[HASH]/deps/dep.json",
3867-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3866+
"debug/build/dep-[HASH]/deps/dep.json",
3867+
"debug/build/foo-[HASH]/deps/foo.json"
38683868
],
38693869
"rustc_vv": "{...}"
38703870
}
@@ -3900,9 +3900,9 @@ fn mergeable_info_additive() {
39003900
str![[r#"
39013901
{
39023902
"doc_parts": [
3903-
"[ROOT]/foo/target/debug/build/bar-[HASH]/deps/bar.json",
3904-
"[ROOT]/foo/target/debug/build/dep-[HASH]/deps/dep.json",
3905-
"[ROOT]/foo/target/debug/build/foo-[HASH]/deps/foo.json"
3903+
"debug/build/bar-[HASH]/deps/bar.json",
3904+
"debug/build/dep-[HASH]/deps/dep.json",
3905+
"debug/build/foo-[HASH]/deps/foo.json"
39063906
],
39073907
"rustc_vv": "{...}"
39083908
}

0 commit comments

Comments
 (0)