Skip to content

Commit 774af29

Browse files
committed
maintain the given order on step execution
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 <[email protected]>
1 parent e1f45a1 commit 774af29

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/bootstrap/src/core/builder.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,42 @@ impl StepDescription {
473473
return;
474474
}
475475

476-
// Handle all PathSets.
476+
let orig_paths = paths.clone();
477+
478+
// List of `(usize, &StepDescription, Vec<PathSet>)` where `usize` is the closest index of a path
479+
// compared to the given CLI paths. So we can respect to the CLI order by using this value to sort
480+
// the steps.
481+
let mut steps_to_run = vec![];
482+
483+
let mut indexed_paths: Vec<&PathBuf> = vec![];
484+
477485
for (desc, should_run) in v.iter().zip(&should_runs) {
478486
let pathsets = should_run.pathset_for_paths_removing_matches(&mut paths, desc.kind);
487+
488+
// This value is used for sorting the step execution order.
489+
// By default, `usize::MAX` is used as the index for steps to assign them the lowest priority.
490+
//
491+
// If we resolve the step's path from the given CLI input, this value will be updated with
492+
// the step's actual index.
493+
let mut closest_index = usize::MAX;
494+
495+
// Find the closest index from the original list of paths given by the CLI input.
496+
for (index, value) in orig_paths.iter().enumerate() {
497+
if !indexed_paths.contains(&value) && !paths.contains(value) {
498+
closest_index = index;
499+
indexed_paths.push(value);
500+
break;
501+
}
502+
}
503+
504+
steps_to_run.push((closest_index, desc, pathsets));
505+
}
506+
507+
// Sort the steps before running them to respect the CLI order.
508+
steps_to_run.sort_by_key(|(index, _, _)| *index);
509+
510+
// Handle all PathSets.
511+
for (_index, desc, pathsets) in steps_to_run {
479512
if !pathsets.is_empty() {
480513
desc.maybe_run(builder, pathsets);
481514
}

0 commit comments

Comments
 (0)