Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustbuild: use deterministic step ordering and respect path order on the command-line. #40152

Merged
merged 2 commits into from
Mar 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/bootstrap/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//! along with the actual implementation elsewhere. You can find more comments
//! about how to define rules themselves below.

use std::collections::{HashMap, HashSet};
use std::collections::{BTreeMap, HashSet};
use std::mem;

use check::{self, TestKind};
Expand Down Expand Up @@ -866,7 +866,7 @@ impl<'a, 'b> Drop for RuleBuilder<'a, 'b> {
pub struct Rules<'a> {
build: &'a Build,
sbuild: Step<'a>,
rules: HashMap<&'a str, Rule<'a>>,
rules: BTreeMap<&'a str, Rule<'a>>,
}

impl<'a> Rules<'a> {
Expand All @@ -879,7 +879,7 @@ impl<'a> Rules<'a> {
host: &build.config.build,
name: "",
},
rules: HashMap::new(),
rules: BTreeMap::new(),
}
}

Expand Down 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