diff options
| author | Jakub Beránek <berykubik@gmail.com> | 2025-03-25 12:37:52 +0100 |
|---|---|---|
| committer | Jakub Beránek <berykubik@gmail.com> | 2025-03-25 12:37:52 +0100 |
| commit | 6df2d589338945e663a3a798a60db17db5f805b8 (patch) | |
| tree | 1946b0a526f6d0ad5b815f0a6bea491900628b03 /src | |
| parent | 90f5eab952728ac6edcf529a171f7de5c25e5d49 (diff) | |
| download | rust-6df2d589338945e663a3a798a60db17db5f805b8.tar.gz rust-6df2d589338945e663a3a798a60db17db5f805b8.zip | |
Add function for linearizing `BuildStep` substeps
Diffstat (limited to 'src')
| -rw-r--r-- | src/build_helper/src/metrics.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/build_helper/src/metrics.rs b/src/build_helper/src/metrics.rs index b6daac32a44..4ab61245c16 100644 --- a/src/build_helper/src/metrics.rs +++ b/src/build_helper/src/metrics.rs @@ -156,25 +156,30 @@ 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; - let mut substeps: Vec<(u32, &BuildStep)> = Vec::new(); + /// 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)>) { - substeps.push((level, step)); - for child in &step.children { - visit(child, level + 1, substeps); + fn visit<'a>(step: &'a BuildStep, level: u32, substeps: &mut Vec<(u32, &'a BuildStep)>) { + substeps.push((level, step)); + for child in &step.children { + visit(child, level + 1, substeps); + } } + + visit(self, 0, &mut substeps); + substeps } +} - visit(root, 0, &mut 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), |
