Skip to content

Commit 4c8b39d

Browse files
committed
rustbuild: sort rules by the order of matching CLI paths.
1 parent 146c462 commit 4c8b39d

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/bootstrap/step.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -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)