Skip to content

Commit

Permalink
maintain the given order on step execution
Browse files Browse the repository at this point in the history
Previously step execution disregarded the CLI order and this change executes the given
steps in the order specified on CLI.

For example, running `x $kind a b c` will execute `$kind` step for `a`, then `b`, then `c` crates
in the specified order.

Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Jul 16, 2024
1 parent e1f45a1 commit 774af29
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,42 @@ impl StepDescription {
return;
}

// Handle all PathSets.
let orig_paths = paths.clone();

// List of `(usize, &StepDescription, Vec<PathSet>)` where `usize` is the closest index of a path
// compared to the given CLI paths. So we can respect to the CLI order by using this value to sort
// the steps.
let mut steps_to_run = vec![];

let mut indexed_paths: Vec<&PathBuf> = vec![];

for (desc, should_run) in v.iter().zip(&should_runs) {
let pathsets = should_run.pathset_for_paths_removing_matches(&mut paths, desc.kind);

// This value is used for sorting the step execution order.
// By default, `usize::MAX` is used as the index for steps to assign them the lowest priority.
//
// If we resolve the step's path from the given CLI input, this value will be updated with
// the step's actual index.
let mut closest_index = usize::MAX;

// Find the closest index from the original list of paths given by the CLI input.
for (index, value) in orig_paths.iter().enumerate() {
if !indexed_paths.contains(&value) && !paths.contains(value) {
closest_index = index;
indexed_paths.push(value);
break;
}
}

steps_to_run.push((closest_index, desc, pathsets));
}

// Sort the steps before running them to respect the CLI order.
steps_to_run.sort_by_key(|(index, _, _)| *index);

// Handle all PathSets.
for (_index, desc, pathsets) in steps_to_run {
if !pathsets.is_empty() {
desc.maybe_run(builder, pathsets);
}
Expand Down

0 comments on commit 774af29

Please sign in to comment.