Skip to content

Commit 4bee701

Browse files
committed
feat(fingerprint): impl Serialize for DirtyReason
To implement Serialize for DirtyReason, we need to also impl Serialize for underly types as well: * `FileTime`: serialize as f64 milliseconds Millisecond precision should be sufficient for mtime comparison, if not we can change to nanosecond * `Checksum`: serializing to Display format (e.g., "sha256=abc123...") * `StaleItem`: with internally tagged format, for example ``` {"stale-item":"missing-file","path":"src/lib.rs"} {"stale-item":"changed-file","reference_mtimer":"...", ...} ``` * `FsStatus`: with internally tagged format, for example ``` {"fs-status":"stale-item","type":"missing-file","path":"..."} ``` The `UpToDate` variant is skipped since it's not relevant for rebuild reason logging. _Part of `-Zbuild-analysis` rebuild reason logging feature_
1 parent 371b1c3 commit 4bee701

File tree

3 files changed

+551
-3
lines changed

3 files changed

+551
-3
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use anyhow::bail;
1818
use cargo_util::ProcessBuilder;
1919
use cargo_util::Sha256;
2020
use cargo_util::paths;
21+
use serde::Serialize;
2122

2223
use crate::CARGO_ENV;
2324
use crate::CargoResult;
@@ -660,6 +661,15 @@ impl fmt::Display for Checksum {
660661
}
661662
}
662663

664+
impl Serialize for Checksum {
665+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
666+
where
667+
S: serde::Serializer,
668+
{
669+
serializer.serialize_str(&self.to_string())
670+
}
671+
}
672+
663673
#[derive(Debug, thiserror::Error)]
664674
pub enum InvalidChecksum {
665675
#[error("algorithm portion incorrect, expected `sha256`, or `blake3`")]

0 commit comments

Comments
 (0)