Make it possible to attach opaque string metadata to StepMetadata

This commit is contained in:
Jakub Beránek 2025-07-07 23:06:18 +02:00
parent c720f49c46
commit 8a195efa1e
No known key found for this signature in database
GPG key ID: 909CD0D26483516B
2 changed files with 12 additions and 2 deletions

View file

@ -146,6 +146,8 @@ pub struct StepMetadata {
target: TargetSelection,
built_by: Option<Compiler>,
stage: Option<u32>,
/// Additional opaque string printed in the metadata
metadata: Option<String>,
}
impl StepMetadata {
@ -170,7 +172,7 @@ impl StepMetadata {
}
fn new(name: &'static str, target: TargetSelection, kind: Kind) -> Self {
Self { name, kind, target, built_by: None, stage: None }
Self { name, kind, target, built_by: None, stage: None, metadata: None }
}
pub fn built_by(mut self, compiler: Compiler) -> Self {
@ -183,6 +185,11 @@ impl StepMetadata {
self
}
pub fn with_metadata(mut self, metadata: String) -> Self {
self.metadata = Some(metadata);
self
}
pub fn get_stage(&self) -> Option<u32> {
self.stage.or(self
.built_by

View file

@ -1587,7 +1587,7 @@ impl ExecutedSteps {
}
fn fuzzy_metadata_eq(executed: &StepMetadata, to_match: &StepMetadata) -> bool {
let StepMetadata { name, kind, target, built_by: _, stage: _ } = executed;
let StepMetadata { name, kind, target, built_by: _, stage: _, metadata } = executed;
*name == to_match.name && *kind == to_match.kind && *target == to_match.target
}
@ -1648,6 +1648,9 @@ fn render_metadata(metadata: &StepMetadata) -> String {
}
let stage = metadata.get_stage().map(|stage| format!("{stage} ")).unwrap_or_default();
write!(record, "{} {stage}<{}>", metadata.name, normalize_target(metadata.target));
if let Some(metadata) = &metadata.metadata {
write!(record, " {metadata}");
}
record
}