Skip to content

Commit 783ab5c

Browse files
committed
refactor(rustdoc): separate fingerprint data schema and logic
1 parent 918720b commit 783ab5c

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ use crate::CargoResult;
1010
use crate::core::compiler::BuildRunner;
1111
use crate::core::compiler::CompileKind;
1212

13+
/// JSON Schema of the [`RustdocFingerprint`] file.
14+
#[derive(Debug, Serialize, Deserialize)]
15+
struct RustdocFingerprintJson {
16+
/// `rustc -vV` verbose version output.
17+
pub rustc_vv: String,
18+
}
19+
1320
/// Structure used to deal with Rustdoc fingerprinting
1421
///
1522
/// This is important because the `.js`/`.html` & `.css` files
@@ -21,11 +28,8 @@ use crate::core::compiler::CompileKind;
2128
/// We need to make sure that if there were any previous docs already compiled,
2229
/// they were compiled with the same Rustc version that we're currently using.
2330
/// Otherwise we must remove the `doc/` folder and compile again forcing a rebuild.
24-
#[derive(Debug, Serialize, Deserialize)]
25-
pub struct RustdocFingerprint {
26-
/// `rustc -vV` verbose version output.
27-
pub rustc_vv: String,
28-
}
31+
#[derive(Debug)]
32+
pub struct RustdocFingerprint {}
2933

3034
impl RustdocFingerprint {
3135
/// Checks whether the latest version of rustc used to compile this workspace's docs
@@ -52,7 +56,7 @@ impl RustdocFingerprint {
5256
{
5357
return Ok(());
5458
}
55-
let new_fingerprint = RustdocFingerprint {
59+
let new_fingerprint = RustdocFingerprintJson {
5660
rustc_vv: build_runner.bcx.rustc().verbose_version.clone(),
5761
};
5862

@@ -77,7 +81,7 @@ fn fingerprint_path(build_runner: &BuildRunner<'_, '_>, kind: CompileKind) -> Pa
7781
/// Checks rustdoc fingerprint file for a given [`CompileKind`].
7882
fn check_fingerprint(
7983
build_runner: &BuildRunner<'_, '_>,
80-
new_fingerprint: &RustdocFingerprint,
84+
new_fingerprint: &RustdocFingerprintJson,
8185
kind: CompileKind,
8286
) -> CargoResult<()> {
8387
let fingerprint_path = fingerprint_path(build_runner, kind);
@@ -94,7 +98,7 @@ fn check_fingerprint(
9498
return write_fingerprint();
9599
};
96100

97-
match serde_json::from_str::<RustdocFingerprint>(&rustdoc_data) {
101+
match serde_json::from_str::<RustdocFingerprintJson>(&rustdoc_data) {
98102
Ok(on_disk_fingerprint) => {
99103
if on_disk_fingerprint.rustc_vv == new_fingerprint.rustc_vv {
100104
return Ok(());

tests/testsuite/doc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ use std::str;
66
use crate::prelude::*;
77
use crate::utils::tools;
88

9-
use cargo::core::compiler::RustdocFingerprint;
109
use cargo_test_support::registry::Package;
1110
use cargo_test_support::str;
1211
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, project};
1312
use cargo_test_support::{rustc_host, symlink_supported};
1413

14+
#[derive(serde::Serialize, serde::Deserialize)]
15+
struct RustdocFingerprint {
16+
rustc_vv: String,
17+
}
18+
1519
#[cargo_test]
1620
fn simple() {
1721
let p = project()

0 commit comments

Comments
 (0)