Skip to content

Commit

Permalink
rustbuild: sort rules by the order of matching CLI paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Feb 28, 2017
1 parent 146c462 commit 4c8b39d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/bootstrap/step.rs
Expand Up @@ -985,6 +985,8 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
// 2. Next, we determine which rules we're actually executing. If a
// number of path filters were specified on the command line we look
// for those, otherwise we look for anything tagged `default`.
// Here we also compute the priority of each rule based on how early
// in the command line the matching path filter showed up.
//
// 3. Finally, we generate some steps with host and target information.
//
Expand Down Expand Up @@ -1015,11 +1017,22 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
Subcommand::Clean => panic!(),
};

self.rules.values().filter(|rule| rule.kind == kind).filter(|rule| {
(paths.len() == 0 && rule.default) || paths.iter().any(|path| {
path.ends_with(rule.path)
})
}).flat_map(|rule| {
let mut rules: Vec<_> = self.rules.values().filter_map(|rule| {
if rule.kind != kind {
return None;
}

if paths.len() == 0 && rule.default {
Some((rule, 0))
} else {
paths.iter().position(|path| path.ends_with(rule.path))
.map(|priority| (rule, priority))
}
}).collect();

rules.sort_by_key(|&(_, priority)| priority);

rules.into_iter().flat_map(|(rule, _)| {
let hosts = if rule.only_host_build || rule.only_build {
&self.build.config.host[..1]
} else if self.build.flags.host.len() > 0 {
Expand Down

0 comments on commit 4c8b39d

Please sign in to comment.