Skip to content

Commit 4ad753a

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 4ad753a

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/bootstrap/src/core/builder.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,41 @@ impl StepDescription {
473473
return;
474474
}
475475

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

0 commit comments

Comments
 (0)