use super::{LocalizationKey, StageNumber, StatusReporter};
use crate::localization::{self, keys};
#[expect(
clippy::cast_possible_truncation,
reason = "PipelineStage::ALL length is a small compile-time constant"
)]
pub(crate) const PIPELINE_STAGE_TOTAL: StageNumber =
StageNumber::new_unchecked(PipelineStage::ALL.len() as u32);
const _: () = assert!(
PipelineStage::ALL.len() <= u32::MAX as usize,
"PipelineStage::ALL length must fit in u32"
);
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum PipelineStage {
ManifestIngestion = 1,
InitialYamlParsing = 2,
TemplateExpansion = 3,
FinalRendering = 4,
IrGenerationValidation = 5,
NinjaSynthesisAndExecution = 6,
GraphRendering,
}
impl PipelineStage {
pub const ALL: [Self; 6] = [
Self::ManifestIngestion,
Self::InitialYamlParsing,
Self::TemplateExpansion,
Self::FinalRendering,
Self::IrGenerationValidation,
Self::NinjaSynthesisAndExecution,
];
#[must_use]
pub const fn index(self) -> StageNumber {
let index = match self {
Self::ManifestIngestion => 1,
Self::InitialYamlParsing => 2,
Self::TemplateExpansion => 3,
Self::FinalRendering => 4,
Self::IrGenerationValidation => 5,
Self::NinjaSynthesisAndExecution | Self::GraphRendering => 6,
};
StageNumber::new_unchecked(index)
}
#[must_use]
pub fn description(self, tool_key: Option<LocalizationKey>) -> String {
match self {
Self::ManifestIngestion => {
localization::message(keys::STATUS_STAGE_MANIFEST_INGESTION).to_string()
}
Self::InitialYamlParsing => {
localization::message(keys::STATUS_STAGE_INITIAL_YAML_PARSING).to_string()
}
Self::TemplateExpansion => {
localization::message(keys::STATUS_STAGE_TEMPLATE_EXPANSION).to_string()
}
Self::FinalRendering => {
localization::message(keys::STATUS_STAGE_FINAL_RENDERING).to_string()
}
Self::IrGenerationValidation => {
localization::message(keys::STATUS_STAGE_IR_GENERATION_VALIDATION).to_string()
}
Self::NinjaSynthesisAndExecution => tool_key.map_or_else(
|| localization::message(keys::STATUS_STAGE_NINJA_SYNTHESIS).to_string(),
|tool_message_key| {
let tool = localization::message(tool_message_key.as_str()).to_string();
localization::message(keys::STATUS_STAGE_NINJA_SYNTHESIS_EXECUTE)
.with_arg("tool", tool)
.to_string()
},
),
Self::GraphRendering => tool_key.map_or_else(
|| localization::message(keys::STATUS_STAGE_GRAPH_RENDERING).to_string(),
|tool_message_key| {
let tool = localization::message(tool_message_key.as_str()).to_string();
localization::message(keys::STATUS_STAGE_GRAPH_RENDERING_WITH_TOOL)
.with_arg("tool", tool)
.to_string()
},
),
}
}
}
pub fn report_pipeline_stage(
reporter: &dyn StatusReporter,
stage: PipelineStage,
tool_key: Option<LocalizationKey>,
) {
let description = stage.description(tool_key);
reporter.report_stage(stage.index(), PIPELINE_STAGE_TOTAL, &description);
}