Skip to content

Commit 8d3e73f

Browse files
authored
feat(build-analysis): emit rebuild reason log entry (#16203)
### What does this PR try to resolve? This implements a basic emission for rebuild reasons. It reuses the `DirtyReason` enum in the log messages. Hence the serialization change. Part of #15844 ### How to test and review this PR? The schema is not final, subject to change, but at least this PR unblocks us the exploration of `cargo report` commands. See tests in dirty_reason.rs for the shape of the JSON message. #### Schema decisions We may need to review this before stabilization: * `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_mtime":"...", ...} ``` * `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.
2 parents 1369549 + 4d35dcf commit 8d3e73f

File tree

5 files changed

+784
-71
lines changed

5 files changed

+784
-71
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)