Skip to content

Commit 2c6e0e4

Browse files
committed
Auto merge of #40152 - eddyb:order-in-rustbuild, r=alexcrichton
rustbuild: use deterministic step ordering and respect path order on the command-line. Restores similar behavior to `make` rules, where: * the step order was always the same, e.g. the testsuite order in `make check` * `make check-stage1-{cfail,rpass}` would *always* run `cfail` before `rpass` * `./x.py test--stage 1 src/test/{compile-fail,run-pass}` is now equivalent r? @alexcrichton
2 parents 06c63f6 + 4c8b39d commit 2c6e0e4

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/bootstrap/step.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! along with the actual implementation elsewhere. You can find more comments
2727
//! about how to define rules themselves below.
2828
29-
use std::collections::{HashMap, HashSet};
29+
use std::collections::{BTreeMap, HashSet};
3030
use std::mem;
3131

3232
use check::{self, TestKind};
@@ -866,7 +866,7 @@ impl<'a, 'b> Drop for RuleBuilder<'a, 'b> {
866866
pub struct Rules<'a> {
867867
build: &'a Build,
868868
sbuild: Step<'a>,
869-
rules: HashMap<&'a str, Rule<'a>>,
869+
rules: BTreeMap<&'a str, Rule<'a>>,
870870
}
871871

872872
impl<'a> Rules<'a> {
@@ -879,7 +879,7 @@ impl<'a> Rules<'a> {
879879
host: &build.config.build,
880880
name: "",
881881
},
882-
rules: HashMap::new(),
882+
rules: BTreeMap::new(),
883883
}
884884
}
885885

@@ -985,6 +985,8 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
985985
// 2. Next, we determine which rules we're actually executing. If a
986986
// number of path filters were specified on the command line we look
987987
// for those, otherwise we look for anything tagged `default`.
988+
// Here we also compute the priority of each rule based on how early
989+
// in the command line the matching path filter showed up.
988990
//
989991
// 3. Finally, we generate some steps with host and target information.
990992
//
@@ -1015,11 +1017,22 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
10151017
Subcommand::Clean => panic!(),
10161018
};
10171019

1018-
self.rules.values().filter(|rule| rule.kind == kind).filter(|rule| {
1019-
(paths.len() == 0 && rule.default) || paths.iter().any(|path| {
1020-
path.ends_with(rule.path)
1021-
})
1022-
}).flat_map(|rule| {
1020+
let mut rules: Vec<_> = self.rules.values().filter_map(|rule| {
1021+
if rule.kind != kind {
1022+
return None;
1023+
}
1024+
1025+
if paths.len() == 0 && rule.default {
1026+
Some((rule, 0))
1027+
} else {
1028+
paths.iter().position(|path| path.ends_with(rule.path))
1029+
.map(|priority| (rule, priority))
1030+
}
1031+
}).collect();
1032+
1033+
rules.sort_by_key(|&(_, priority)| priority);
1034+
1035+
rules.into_iter().flat_map(|(rule, _)| {
10231036
let hosts = if rule.only_host_build || rule.only_build {
10241037
&self.build.config.host[..1]
10251038
} else if self.build.flags.host.len() > 0 {

0 commit comments

Comments
 (0)