1
Fork 0

Add function for linearizing BuildStep substeps

This commit is contained in:
Jakub Beránek 2025-03-25 12:37:52 +01:00
parent 90f5eab952
commit 6df2d58933
No known key found for this signature in database
GPG key ID: 909CD0D26483516B

View file

@ -156,12 +156,10 @@ impl BuildStep {
child.find_by_type(r#type, result);
}
}
}
/// Writes build steps into a nice indented table.
pub fn format_build_steps(root: &BuildStep) -> String {
use std::fmt::Write;
/// Returns a Vec with all substeps, ordered by their hierarchical order.
/// The first element of the tuple is the depth of a given step.
fn linearize_steps(&self) -> Vec<(u32, &BuildStep)> {
let mut substeps: Vec<(u32, &BuildStep)> = Vec::new();
fn visit<'a>(step: &'a BuildStep, level: u32, substeps: &mut Vec<(u32, &'a BuildStep)>) {
@ -171,10 +169,17 @@ pub fn format_build_steps(root: &BuildStep) -> String {
}
}
visit(root, 0, &mut substeps);
visit(self, 0, &mut substeps);
substeps
}
}
/// Writes build steps into a nice indented table.
pub fn format_build_steps(root: &BuildStep) -> String {
use std::fmt::Write;
let mut output = String::new();
for (level, step) in substeps {
for (level, step) in root.linearize_steps() {
let label = format!(
"{}{}",
".".repeat(level as usize),