Skip to content

Commit

Permalink
add concept of Step::noop()
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Dec 19, 2016
1 parent e70415b commit ef8921a
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/bootstrap/step.rs
Expand Up @@ -86,7 +86,7 @@ pub fn build_rules(build: &Build) -> Rules {
//
// To handle this we do a bit of dynamic dispatch to see what the dependency
// is. If we're building a LLVM for the build triple, then we don't actually
// have any dependencies! To do that we return a dependency on the "dummy"
// have any dependencies! To do that we return a dependency on the `Step::noop()`
// target which does nothing.
//
// If we're build a cross-compiled LLVM, however, we need to assemble the
Expand All @@ -104,7 +104,7 @@ pub fn build_rules(build: &Build) -> Rules {
.host(true)
.dep(move |s| {
if s.target == build.config.build {
dummy(s, build)
Step::noop()
} else {
s.target(&build.config.build)
}
Expand All @@ -115,14 +115,11 @@ pub fn build_rules(build: &Build) -> Rules {
// going on here. You can check out the API docs below and also see a bunch
// more examples of rules directly below as well.

// dummy rule to do nothing, useful when a dep maps to no deps
rules.build("dummy", "path/to/nowhere");

// the compiler with no target libraries ready to go
rules.build("rustc", "src/rustc")
.dep(move |s| {
if s.stage == 0 {
dummy(s, build)
Step::noop()
} else {
s.name("librustc")
.host(&build.config.build)
Expand Down Expand Up @@ -165,7 +162,7 @@ pub fn build_rules(build: &Build) -> Rules {
.dep(move |s| s.name("rustc").host(&build.config.build).target(s.host))
.dep(move |s| {
if s.host == build.config.build {
dummy(s, build)
Step::noop()
} else {
s.host(&build.config.build)
}
Expand All @@ -183,7 +180,7 @@ pub fn build_rules(build: &Build) -> Rules {
.dep(|s| s.name("libstd"))
.dep(move |s| {
if s.host == build.config.build {
dummy(s, build)
Step::noop()
} else {
s.host(&build.config.build)
}
Expand All @@ -203,7 +200,7 @@ pub fn build_rules(build: &Build) -> Rules {
.dep(move |s| s.name("llvm").host(&build.config.build).stage(0))
.dep(move |s| {
if s.host == build.config.build {
dummy(s, build)
Step::noop()
} else {
s.host(&build.config.build)
}
Expand Down Expand Up @@ -233,7 +230,7 @@ pub fn build_rules(build: &Build) -> Rules {
if s.target.contains("android") {
s.name("android-copy-libs")
} else {
dummy(s, build)
Step::noop()
}
})
.default(true)
Expand Down Expand Up @@ -514,12 +511,6 @@ pub fn build_rules(build: &Build) -> Rules {

rules.verify();
return rules;

fn dummy<'a>(s: &Step<'a>, build: &'a Build) -> Step<'a> {
s.name("dummy").stage(0)
.target(&build.config.build)
.host(&build.config.build)
}
}

#[derive(PartialEq, Eq, Hash, Clone, Debug)]
Expand All @@ -543,6 +534,10 @@ struct Step<'a> {
}

impl<'a> Step<'a> {
fn noop() -> Step<'a> {
Step { name: "", stage: 0, host: "", target: "" }
}

/// Creates a new step which is the same as this, except has a new name.
fn name(&self, name: &'a str) -> Step<'a> {
Step { name: name, ..*self }
Expand Down Expand Up @@ -738,6 +733,9 @@ impl<'a> Rules<'a> {
if self.rules.contains_key(&dep.name) || dep.name.starts_with("default:") {
continue
}
if dep == Step::noop() {
continue
}
panic!("\
invalid rule dependency graph detected, was a rule added and maybe typo'd?
Expand Down Expand Up @@ -864,6 +862,7 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
// of what we need to do.
let mut order = Vec::new();
let mut added = HashSet::new();
added.insert(Step::noop());
for step in steps.iter().cloned() {
self.fill(step, &mut order, &mut added);
}
Expand Down

0 comments on commit ef8921a

Please sign in to comment.