Add an optional condition to constrain defaults.

Utilized primarily to not be a default rule unless some configuration is
given (e.g., compiler docs are enabled).
This commit is contained in:
Mark Simulacrum 2017-07-20 17:24:11 -06:00
parent d8aecc19d8
commit b05af49086
6 changed files with 61 additions and 121 deletions

View File

@ -152,17 +152,20 @@ impl StepDescription {
}
fn run(v: &[StepDescription], builder: &Builder, paths: &[PathBuf]) {
let should_runs = v.iter().map(|desc| {
(desc.should_run)(ShouldRun::new(builder))
}).collect::<Vec<_>>();
if paths.is_empty() {
for desc in v {
if desc.default {
for (desc, should_run) in v.iter().zip(should_runs) {
if desc.default && should_run.is_really_default {
desc.maybe_run(builder, None);
}
}
} else {
for path in paths {
let mut attempted_run = false;
for desc in v {
if (desc.should_run)(ShouldRun::new(builder)).run(path) {
for (desc, should_run) in v.iter().zip(&should_runs) {
if should_run.run(path) {
attempted_run = true;
desc.maybe_run(builder, Some(path));
}
@ -178,9 +181,13 @@ impl StepDescription {
#[derive(Clone)]
pub struct ShouldRun<'a> {
builder: &'a Builder<'a>,
pub builder: &'a Builder<'a>,
// use a BTreeSet to maintain sort order
paths: BTreeSet<PathBuf>,
// If this is a default rule, this is an additional constraint placed on
// it's run. Generally something like compiler docs being enabled.
is_really_default: bool,
}
impl<'a> ShouldRun<'a> {
@ -188,9 +195,15 @@ impl<'a> ShouldRun<'a> {
ShouldRun {
builder: builder,
paths: BTreeSet::new(),
is_really_default: true, // by default no additional conditions
}
}
pub fn default_condition(mut self, cond: bool) -> Self {
self.is_really_default = cond;
self
}
pub fn krate(mut self, name: &str) -> Self {
for (_, krate_path) in self.builder.crates(name) {
self.paths.insert(PathBuf::from(krate_path));

View File

@ -115,7 +115,8 @@ impl Step for Linkcheck {
}
fn should_run(run: ShouldRun) -> ShouldRun {
run.path("src/tools/linkchecker")
let builder = run.builder;
run.path("src/tools/linkchecker").default_condition(builder.build.config.docs)
}
fn make_run(
@ -124,13 +125,7 @@ impl Step for Linkcheck {
host: Interned<String>,
_target: Interned<String>,
) {
if path.is_some() {
builder.ensure(Linkcheck { host });
} else {
if builder.build.config.docs {
builder.ensure(Linkcheck { host });
}
}
builder.ensure(Linkcheck { host });
}
}

View File

@ -607,7 +607,8 @@ impl Step for Analysis {
const ONLY_BUILD_TARGETS: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.path("analysis")
let builder = run.builder;
run.path("analysis").default_condition(builder.build.config.extended)
}
fn make_run(
@ -616,9 +617,6 @@ impl Step for Analysis {
host: Interned<String>,
target: Interned<String>
) {
if path.is_none() && !builder.build.config.extended {
return;
}
builder.ensure(Analysis {
compiler: builder.compiler(builder.top_stage, host),
target: target,
@ -818,16 +816,13 @@ impl Step for PlainSourceTarball {
const ONLY_BUILD: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.path("src")
let builder = run.builder;
run.path("src").default_condition(builder.config.rust_dist_src)
}
fn make_run(
builder: &Builder, path: Option<&Path>, _host: Interned<String>, _target: Interned<String>
) {
if path.is_none() && !builder.build.config.rust_dist_src {
return;
}
builder.ensure(PlainSourceTarball);
}
@ -1138,15 +1133,13 @@ impl Step for Extended {
const ONLY_HOSTS: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.path("cargo")
let builder = run.builder;
run.path("cargo").default_condition(builder.config.extended)
}
fn make_run(
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
) {
if path.is_none() && !builder.build.config.extended {
return;
}
builder.ensure(Extended {
stage: builder.top_stage,
target: target,

View File

@ -45,7 +45,8 @@ macro_rules! book {
const DEFAULT: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.path($path)
let builder = run.builder;
run.path($path).default_condition(builder.build.config.docs)
}
fn make_run(
@ -119,17 +120,13 @@ impl Step for UnstableBook {
const DEFAULT: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.path("src/doc/unstable-book")
let builder = run.builder;
run.path("src/doc/unstable-book").default_condition(builder.build.config.docs)
}
fn make_run(
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
) {
if path.is_none() && !builder.build.config.docs {
// Not a default rule if docs are disabled.
return;
}
builder.ensure(UnstableBook {
target,
});
@ -201,17 +198,13 @@ impl Step for TheBook {
const DEFAULT: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.path("src/doc/book")
let builder = run.builder;
run.path("src/doc/book").default_condition(builder.build.config.docs)
}
fn make_run(
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
) {
if path.is_none() && !builder.build.config.docs {
// Not a default rule if docs are disabled.
return;
}
builder.ensure(TheBook {
target,
name: "book",
@ -417,31 +410,17 @@ impl Step for Std {
const DEFAULT: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.krate("std")
let builder = run.builder;
run.krate("std").default_condition(builder.build.config.docs)
}
fn make_run(
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
) {
let run = || {
builder.ensure(Std {
stage: builder.top_stage,
target
});
};
if let Some(path) = path {
for (_, krate_path) in builder.crates("std") {
if path.ends_with(krate_path) {
run();
}
}
} else {
if builder.build.config.docs {
run();
}
}
builder.ensure(Std {
stage: builder.top_stage,
target
});
}
/// Compile all standard library documentation.
@ -520,30 +499,17 @@ impl Step for Test {
const DEFAULT: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.krate("test")
let builder = run.builder;
run.krate("test").default_condition(builder.config.compiler_docs)
}
fn make_run(
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
) {
let run = || {
builder.ensure(Test {
stage: builder.top_stage,
target
});
};
if let Some(path) = path {
for (_, krate_path) in builder.crates("test") {
if path.ends_with(krate_path) {
run();
}
}
} else {
if builder.build.config.compiler_docs {
run();
}
}
builder.ensure(Test {
stage: builder.top_stage,
target
});
}
/// Compile all libtest documentation.
@ -597,30 +563,17 @@ impl Step for Rustc {
const ONLY_HOSTS: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.krate("rustc-main")
let builder = run.builder;
run.krate("rustc-main").default_condition(builder.build.config.docs)
}
fn make_run(
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
) {
let run = || {
builder.ensure(Rustc {
stage: builder.top_stage,
target
});
};
if let Some(path) = path {
for (_, krate_path) in builder.crates("rustc-main") {
if path.ends_with(krate_path) {
run();
}
}
} else {
if builder.build.config.docs {
run();
}
}
builder.ensure(Rustc {
stage: builder.top_stage,
target
});
}
/// Generate all compiler documentation.
@ -690,17 +643,13 @@ impl Step for ErrorIndex {
const ONLY_HOSTS: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.path("src/tools/error_index_generator")
let builder = run.builder;
run.path("src/tools/error_index_generator").default_condition(builder.build.config.docs)
}
fn make_run(
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
) {
if path.is_none() && !builder.build.config.docs {
// Not a default rule if docs are disabled.
return;
}
builder.ensure(ErrorIndex {
target,
});
@ -742,17 +691,13 @@ impl Step for UnstableBookGen {
const ONLY_HOSTS: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.path("src/tools/unstable-book-gen")
let builder = run.builder;
run.path("src/tools/unstable-book-gen").default_condition(builder.build.config.docs)
}
fn make_run(
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>,
) {
if path.is_none() && !builder.build.config.docs {
// Not a default rule if docs are disabled.
return;
}
builder.ensure(UnstableBookGen {
target,
});

View File

@ -150,7 +150,8 @@ macro_rules! install {
$(const $c: bool = true;)*
fn should_run(run: ShouldRun) -> ShouldRun {
run.path($path)
let $builder = run.builder;
run.path($path).default_condition($default_cond)
}
fn make_run(
@ -159,9 +160,6 @@ macro_rules! install {
host: Interned<String>,
target: Interned<String>,
) {
if path.is_none() && !($default_cond) {
return;
}
$builder.ensure($name {
stage: $builder.top_stage,
target,

View File

@ -248,15 +248,13 @@ impl Step for Cargo {
const ONLY_HOSTS: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.path("src/tools/cargo")
let builder = run.builder;
run.path("src/tools/cargo").default_condition(builder.build.config.extended)
}
fn make_run(
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
) {
if path.is_none() && !builder.build.config.extended {
return;
}
builder.ensure(Cargo {
stage: builder.top_stage,
target,
@ -294,15 +292,13 @@ impl Step for Rls {
const ONLY_HOSTS: bool = true;
fn should_run(run: ShouldRun) -> ShouldRun {
run.path("src/tools/rls")
let builder = run.builder;
run.path("src/tools/rls").default_condition(builder.build.config.extended)
}
fn make_run(
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
) {
if path.is_none() && !builder.build.config.extended {
return;
}
builder.ensure(Rls {
stage: builder.top_stage,
target,