Skip to content

Commit 104e3f6

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 <work@onurozkan.dev>
1 parent e1f45a1 commit 104e3f6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/bootstrap/src/core/builder.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,40 @@ impl StepDescription {
473473
return;
474474
}
475475

476+
// List of `(usize, &StepDescription, Vec<PathSet>)` where `usize` is the closest index of a path
477+
// compared to the given CLI paths. So we can respect to the CLI order by using this value to sort
478+
// the steps.
479+
let mut steps_to_run = vec![];
480+
let orig_paths = paths.clone();
481+
let mut indexed_paths: Vec<&PathBuf> = vec![];
482+
476483
// Handle all PathSets.
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, value) in orig_paths.iter().enumerate() {
496+
if !indexed_paths.contains(&value) && !paths.contains(value) {
497+
closest_index = index;
498+
indexed_paths.push(value);
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+
for (_index, desc, pathsets) in steps_to_run {
479510
if !pathsets.is_empty() {
480511
desc.maybe_run(builder, pathsets);
481512
}

0 commit comments

Comments
 (0)