Skip to content

Commit b05af49

Browse files
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).
1 parent d8aecc1 commit b05af49

File tree

6 files changed

+61
-121
lines changed

6 files changed

+61
-121
lines changed

src/bootstrap/builder.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,20 @@ impl StepDescription {
152152
}
153153

154154
fn run(v: &[StepDescription], builder: &Builder, paths: &[PathBuf]) {
155+
let should_runs = v.iter().map(|desc| {
156+
(desc.should_run)(ShouldRun::new(builder))
157+
}).collect::<Vec<_>>();
155158
if paths.is_empty() {
156-
for desc in v {
157-
if desc.default {
159+
for (desc, should_run) in v.iter().zip(should_runs) {
160+
if desc.default && should_run.is_really_default {
158161
desc.maybe_run(builder, None);
159162
}
160163
}
161164
} else {
162165
for path in paths {
163166
let mut attempted_run = false;
164-
for desc in v {
165-
if (desc.should_run)(ShouldRun::new(builder)).run(path) {
167+
for (desc, should_run) in v.iter().zip(&should_runs) {
168+
if should_run.run(path) {
166169
attempted_run = true;
167170
desc.maybe_run(builder, Some(path));
168171
}
@@ -178,19 +181,29 @@ impl StepDescription {
178181

179182
#[derive(Clone)]
180183
pub struct ShouldRun<'a> {
181-
builder: &'a Builder<'a>,
184+
pub builder: &'a Builder<'a>,
182185
// use a BTreeSet to maintain sort order
183186
paths: BTreeSet<PathBuf>,
187+
188+
// If this is a default rule, this is an additional constraint placed on
189+
// it's run. Generally something like compiler docs being enabled.
190+
is_really_default: bool,
184191
}
185192

186193
impl<'a> ShouldRun<'a> {
187194
fn new(builder: &'a Builder) -> ShouldRun<'a> {
188195
ShouldRun {
189196
builder: builder,
190197
paths: BTreeSet::new(),
198+
is_really_default: true, // by default no additional conditions
191199
}
192200
}
193201

202+
pub fn default_condition(mut self, cond: bool) -> Self {
203+
self.is_really_default = cond;
204+
self
205+
}
206+
194207
pub fn krate(mut self, name: &str) -> Self {
195208
for (_, krate_path) in self.builder.crates(name) {
196209
self.paths.insert(PathBuf::from(krate_path));

src/bootstrap/check.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ impl Step for Linkcheck {
115115
}
116116

117117
fn should_run(run: ShouldRun) -> ShouldRun {
118-
run.path("src/tools/linkchecker")
118+
let builder = run.builder;
119+
run.path("src/tools/linkchecker").default_condition(builder.build.config.docs)
119120
}
120121

121122
fn make_run(
@@ -124,13 +125,7 @@ impl Step for Linkcheck {
124125
host: Interned<String>,
125126
_target: Interned<String>,
126127
) {
127-
if path.is_some() {
128-
builder.ensure(Linkcheck { host });
129-
} else {
130-
if builder.build.config.docs {
131-
builder.ensure(Linkcheck { host });
132-
}
133-
}
128+
builder.ensure(Linkcheck { host });
134129
}
135130
}
136131

src/bootstrap/dist.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,8 @@ impl Step for Analysis {
607607
const ONLY_BUILD_TARGETS: bool = true;
608608

609609
fn should_run(run: ShouldRun) -> ShouldRun {
610-
run.path("analysis")
610+
let builder = run.builder;
611+
run.path("analysis").default_condition(builder.build.config.extended)
611612
}
612613

613614
fn make_run(
@@ -616,9 +617,6 @@ impl Step for Analysis {
616617
host: Interned<String>,
617618
target: Interned<String>
618619
) {
619-
if path.is_none() && !builder.build.config.extended {
620-
return;
621-
}
622620
builder.ensure(Analysis {
623621
compiler: builder.compiler(builder.top_stage, host),
624622
target: target,
@@ -818,16 +816,13 @@ impl Step for PlainSourceTarball {
818816
const ONLY_BUILD: bool = true;
819817

820818
fn should_run(run: ShouldRun) -> ShouldRun {
821-
run.path("src")
819+
let builder = run.builder;
820+
run.path("src").default_condition(builder.config.rust_dist_src)
822821
}
823822

824823
fn make_run(
825824
builder: &Builder, path: Option<&Path>, _host: Interned<String>, _target: Interned<String>
826825
) {
827-
if path.is_none() && !builder.build.config.rust_dist_src {
828-
return;
829-
}
830-
831826
builder.ensure(PlainSourceTarball);
832827
}
833828

@@ -1138,15 +1133,13 @@ impl Step for Extended {
11381133
const ONLY_HOSTS: bool = true;
11391134

11401135
fn should_run(run: ShouldRun) -> ShouldRun {
1141-
run.path("cargo")
1136+
let builder = run.builder;
1137+
run.path("cargo").default_condition(builder.config.extended)
11421138
}
11431139

11441140
fn make_run(
11451141
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
11461142
) {
1147-
if path.is_none() && !builder.build.config.extended {
1148-
return;
1149-
}
11501143
builder.ensure(Extended {
11511144
stage: builder.top_stage,
11521145
target: target,

src/bootstrap/doc.rs

Lines changed: 28 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ macro_rules! book {
4545
const DEFAULT: bool = true;
4646

4747
fn should_run(run: ShouldRun) -> ShouldRun {
48-
run.path($path)
48+
let builder = run.builder;
49+
run.path($path).default_condition(builder.build.config.docs)
4950
}
5051

5152
fn make_run(
@@ -119,17 +120,13 @@ impl Step for UnstableBook {
119120
const DEFAULT: bool = true;
120121

121122
fn should_run(run: ShouldRun) -> ShouldRun {
122-
run.path("src/doc/unstable-book")
123+
let builder = run.builder;
124+
run.path("src/doc/unstable-book").default_condition(builder.build.config.docs)
123125
}
124126

125127
fn make_run(
126128
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
127129
) {
128-
if path.is_none() && !builder.build.config.docs {
129-
// Not a default rule if docs are disabled.
130-
return;
131-
}
132-
133130
builder.ensure(UnstableBook {
134131
target,
135132
});
@@ -201,17 +198,13 @@ impl Step for TheBook {
201198
const DEFAULT: bool = true;
202199

203200
fn should_run(run: ShouldRun) -> ShouldRun {
204-
run.path("src/doc/book")
201+
let builder = run.builder;
202+
run.path("src/doc/book").default_condition(builder.build.config.docs)
205203
}
206204

207205
fn make_run(
208206
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
209207
) {
210-
if path.is_none() && !builder.build.config.docs {
211-
// Not a default rule if docs are disabled.
212-
return;
213-
}
214-
215208
builder.ensure(TheBook {
216209
target,
217210
name: "book",
@@ -417,31 +410,17 @@ impl Step for Std {
417410
const DEFAULT: bool = true;
418411

419412
fn should_run(run: ShouldRun) -> ShouldRun {
420-
run.krate("std")
413+
let builder = run.builder;
414+
run.krate("std").default_condition(builder.build.config.docs)
421415
}
422416

423-
424417
fn make_run(
425418
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
426419
) {
427-
let run = || {
428-
builder.ensure(Std {
429-
stage: builder.top_stage,
430-
target
431-
});
432-
};
433-
434-
if let Some(path) = path {
435-
for (_, krate_path) in builder.crates("std") {
436-
if path.ends_with(krate_path) {
437-
run();
438-
}
439-
}
440-
} else {
441-
if builder.build.config.docs {
442-
run();
443-
}
444-
}
420+
builder.ensure(Std {
421+
stage: builder.top_stage,
422+
target
423+
});
445424
}
446425

447426
/// Compile all standard library documentation.
@@ -520,30 +499,17 @@ impl Step for Test {
520499
const DEFAULT: bool = true;
521500

522501
fn should_run(run: ShouldRun) -> ShouldRun {
523-
run.krate("test")
502+
let builder = run.builder;
503+
run.krate("test").default_condition(builder.config.compiler_docs)
524504
}
525505

526506
fn make_run(
527507
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
528508
) {
529-
let run = || {
530-
builder.ensure(Test {
531-
stage: builder.top_stage,
532-
target
533-
});
534-
};
535-
536-
if let Some(path) = path {
537-
for (_, krate_path) in builder.crates("test") {
538-
if path.ends_with(krate_path) {
539-
run();
540-
}
541-
}
542-
} else {
543-
if builder.build.config.compiler_docs {
544-
run();
545-
}
546-
}
509+
builder.ensure(Test {
510+
stage: builder.top_stage,
511+
target
512+
});
547513
}
548514

549515
/// Compile all libtest documentation.
@@ -597,30 +563,17 @@ impl Step for Rustc {
597563
const ONLY_HOSTS: bool = true;
598564

599565
fn should_run(run: ShouldRun) -> ShouldRun {
600-
run.krate("rustc-main")
566+
let builder = run.builder;
567+
run.krate("rustc-main").default_condition(builder.build.config.docs)
601568
}
602569

603570
fn make_run(
604571
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
605572
) {
606-
let run = || {
607-
builder.ensure(Rustc {
608-
stage: builder.top_stage,
609-
target
610-
});
611-
};
612-
613-
if let Some(path) = path {
614-
for (_, krate_path) in builder.crates("rustc-main") {
615-
if path.ends_with(krate_path) {
616-
run();
617-
}
618-
}
619-
} else {
620-
if builder.build.config.docs {
621-
run();
622-
}
623-
}
573+
builder.ensure(Rustc {
574+
stage: builder.top_stage,
575+
target
576+
});
624577
}
625578

626579
/// Generate all compiler documentation.
@@ -690,17 +643,13 @@ impl Step for ErrorIndex {
690643
const ONLY_HOSTS: bool = true;
691644

692645
fn should_run(run: ShouldRun) -> ShouldRun {
693-
run.path("src/tools/error_index_generator")
646+
let builder = run.builder;
647+
run.path("src/tools/error_index_generator").default_condition(builder.build.config.docs)
694648
}
695649

696650
fn make_run(
697651
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
698652
) {
699-
if path.is_none() && !builder.build.config.docs {
700-
// Not a default rule if docs are disabled.
701-
return;
702-
}
703-
704653
builder.ensure(ErrorIndex {
705654
target,
706655
});
@@ -742,17 +691,13 @@ impl Step for UnstableBookGen {
742691
const ONLY_HOSTS: bool = true;
743692

744693
fn should_run(run: ShouldRun) -> ShouldRun {
745-
run.path("src/tools/unstable-book-gen")
694+
let builder = run.builder;
695+
run.path("src/tools/unstable-book-gen").default_condition(builder.build.config.docs)
746696
}
747697

748698
fn make_run(
749699
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>,
750700
) {
751-
if path.is_none() && !builder.build.config.docs {
752-
// Not a default rule if docs are disabled.
753-
return;
754-
}
755-
756701
builder.ensure(UnstableBookGen {
757702
target,
758703
});

src/bootstrap/install.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ macro_rules! install {
150150
$(const $c: bool = true;)*
151151

152152
fn should_run(run: ShouldRun) -> ShouldRun {
153-
run.path($path)
153+
let $builder = run.builder;
154+
run.path($path).default_condition($default_cond)
154155
}
155156

156157
fn make_run(
@@ -159,9 +160,6 @@ macro_rules! install {
159160
host: Interned<String>,
160161
target: Interned<String>,
161162
) {
162-
if path.is_none() && !($default_cond) {
163-
return;
164-
}
165163
$builder.ensure($name {
166164
stage: $builder.top_stage,
167165
target,

src/bootstrap/tool.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,13 @@ impl Step for Cargo {
248248
const ONLY_HOSTS: bool = true;
249249

250250
fn should_run(run: ShouldRun) -> ShouldRun {
251-
run.path("src/tools/cargo")
251+
let builder = run.builder;
252+
run.path("src/tools/cargo").default_condition(builder.build.config.extended)
252253
}
253254

254255
fn make_run(
255256
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
256257
) {
257-
if path.is_none() && !builder.build.config.extended {
258-
return;
259-
}
260258
builder.ensure(Cargo {
261259
stage: builder.top_stage,
262260
target,
@@ -294,15 +292,13 @@ impl Step for Rls {
294292
const ONLY_HOSTS: bool = true;
295293

296294
fn should_run(run: ShouldRun) -> ShouldRun {
297-
run.path("src/tools/rls")
295+
let builder = run.builder;
296+
run.path("src/tools/rls").default_condition(builder.build.config.extended)
298297
}
299298

300299
fn make_run(
301300
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
302301
) {
303-
if path.is_none() && !builder.build.config.extended {
304-
return;
305-
}
306302
builder.ensure(Rls {
307303
stage: builder.top_stage,
308304
target,

0 commit comments

Comments
 (0)