Skip to content

Commit 6a67a05

Browse files
Change make_run signature to taking a RunConfig struct for refactorability.
1 parent b05af49 commit 6a67a05

File tree

9 files changed

+203
-353
lines changed

9 files changed

+203
-353
lines changed

src/bootstrap/builder.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,7 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
7979
/// When path is `None`, we are executing in a context where no paths were
8080
/// passed. When `./x.py build` is run, for example, this rule could get
8181
/// called if it is in the correct list below with a path of `None`.
82-
fn make_run(
83-
_builder: &Builder,
84-
_path: Option<&Path>,
85-
_host: Interned<String>,
86-
_target: Interned<String>,
87-
) {
82+
fn make_run(_run: RunConfig) {
8883
// It is reasonable to not have an implementation of make_run for rules
8984
// who do not want to get called from the root context. This means that
9085
// they are likely dependencies (e.g., sysroot creation) or similar, and
@@ -93,13 +88,20 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
9388
}
9489
}
9590

91+
pub struct RunConfig<'a> {
92+
pub builder: &'a Builder<'a>,
93+
pub host: Interned<String>,
94+
pub target: Interned<String>,
95+
pub path: Option<&'a Path>,
96+
}
97+
9698
struct StepDescription {
9799
default: bool,
98100
only_hosts: bool,
99101
only_build_targets: bool,
100102
only_build: bool,
101103
should_run: fn(ShouldRun) -> ShouldRun,
102-
make_run: fn(&Builder, Option<&Path>, Interned<String>, Interned<String>),
104+
make_run: fn(RunConfig),
103105
}
104106

105107
impl StepDescription {
@@ -146,7 +148,13 @@ impl StepDescription {
146148

147149
for host in hosts {
148150
for target in targets {
149-
(self.make_run)(builder, path, *host, *target);
151+
let run = RunConfig {
152+
builder,
153+
path,
154+
host: *host,
155+
target: *target,
156+
};
157+
(self.make_run)(run);
150158
}
151159
}
152160
}

src/bootstrap/check.rs

Lines changed: 59 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use util::{self, dylib_path, dylib_path_var};
3131

3232
use compile;
3333
use native;
34-
use builder::{Kind, ShouldRun, Builder, Compiler, Step};
34+
use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
3535
use tool::{self, Tool};
3636
use cache::{INTERNER, Interned};
3737

@@ -119,13 +119,8 @@ impl Step for Linkcheck {
119119
run.path("src/tools/linkchecker").default_condition(builder.build.config.docs)
120120
}
121121

122-
fn make_run(
123-
builder: &Builder,
124-
path: Option<&Path>,
125-
host: Interned<String>,
126-
_target: Interned<String>,
127-
) {
128-
builder.ensure(Linkcheck { host });
122+
fn make_run(run: RunConfig) {
123+
run.builder.ensure(Linkcheck { host: run.host });
129124
}
130125
}
131126

@@ -143,15 +138,10 @@ impl Step for Cargotest {
143138
run.path("src/tools/cargotest")
144139
}
145140

146-
fn make_run(
147-
builder: &Builder,
148-
_path: Option<&Path>,
149-
host: Interned<String>,
150-
_target: Interned<String>,
151-
) {
152-
builder.ensure(Cargotest {
153-
stage: builder.top_stage,
154-
host: host,
141+
fn make_run(run: RunConfig) {
142+
run.builder.ensure(Cargotest {
143+
stage: run.builder.top_stage,
144+
host: run.host,
155145
});
156146
}
157147

@@ -193,15 +183,10 @@ impl Step for Cargo {
193183
run.path("src/tools/cargo")
194184
}
195185

196-
fn make_run(
197-
builder: &Builder,
198-
_path: Option<&Path>,
199-
_host: Interned<String>,
200-
target: Interned<String>,
201-
) {
202-
builder.ensure(Cargo {
203-
stage: builder.top_stage,
204-
host: target,
186+
fn make_run(run: RunConfig) {
187+
run.builder.ensure(Cargo {
188+
stage: run.builder.top_stage,
189+
host: run.target,
205190
});
206191
}
207192

@@ -242,15 +227,10 @@ impl Step for Rls {
242227
run.path("src/tools/rls")
243228
}
244229

245-
fn make_run(
246-
builder: &Builder,
247-
_path: Option<&Path>,
248-
_host: Interned<String>,
249-
target: Interned<String>,
250-
) {
251-
builder.ensure(Rls {
252-
stage: builder.top_stage,
253-
host: target,
230+
fn make_run(run: RunConfig) {
231+
run.builder.ensure(Rls {
232+
stage: run.builder.top_stage,
233+
host: run.target,
254234
});
255235
}
256236

@@ -320,14 +300,9 @@ impl Step for Tidy {
320300
run.path("src/tools/tidy")
321301
}
322302

323-
fn make_run(
324-
builder: &Builder,
325-
_path: Option<&Path>,
326-
_host: Interned<String>,
327-
_target: Interned<String>,
328-
) {
329-
builder.ensure(Tidy {
330-
host: builder.build.build,
303+
fn make_run(run: RunConfig) {
304+
run.builder.ensure(Tidy {
305+
host: run.builder.build.build,
331306
});
332307
}
333308
}
@@ -382,15 +357,10 @@ impl Step for DefaultCompiletest {
382357
run
383358
}
384359

385-
fn make_run(
386-
builder: &Builder,
387-
path: Option<&Path>,
388-
host: Interned<String>,
389-
target: Interned<String>,
390-
) {
391-
let compiler = builder.compiler(builder.top_stage, host);
360+
fn make_run(run: RunConfig) {
361+
let compiler = run.builder.compiler(run.builder.top_stage, run.host);
392362

393-
let test = path.map(|path| {
363+
let test = run.path.map(|path| {
394364
DEFAULT_COMPILETESTS.iter().find(|&&test| {
395365
path.ends_with(test.path)
396366
}).unwrap_or_else(|| {
@@ -399,17 +369,17 @@ impl Step for DefaultCompiletest {
399369
});
400370

401371
if let Some(test) = test {
402-
builder.ensure(DefaultCompiletest {
372+
run.builder.ensure(DefaultCompiletest {
403373
compiler,
404-
target,
374+
target: run.target,
405375
mode: test.mode,
406376
suite: test.suite,
407377
});
408378
} else {
409379
for test in DEFAULT_COMPILETESTS {
410-
builder.ensure(DefaultCompiletest {
380+
run.builder.ensure(DefaultCompiletest {
411381
compiler,
412-
target,
382+
target: run.target,
413383
mode: test.mode,
414384
suite: test.suite
415385
});
@@ -468,15 +438,10 @@ impl Step for HostCompiletest {
468438
run
469439
}
470440

471-
fn make_run(
472-
builder: &Builder,
473-
path: Option<&Path>,
474-
host: Interned<String>,
475-
target: Interned<String>,
476-
) {
477-
let compiler = builder.compiler(builder.top_stage, host);
441+
fn make_run(run: RunConfig) {
442+
let compiler = run.builder.compiler(run.builder.top_stage, run.host);
478443

479-
let test = path.map(|path| {
444+
let test = run.path.map(|path| {
480445
HOST_COMPILETESTS.iter().find(|&&test| {
481446
path.ends_with(test.path)
482447
}).unwrap_or_else(|| {
@@ -485,17 +450,17 @@ impl Step for HostCompiletest {
485450
});
486451

487452
if let Some(test) = test {
488-
builder.ensure(HostCompiletest {
453+
run.builder.ensure(HostCompiletest {
489454
compiler,
490-
target,
455+
target: run.target,
491456
mode: test.mode,
492457
suite: test.suite,
493458
});
494459
} else {
495460
for test in HOST_COMPILETESTS {
496-
builder.ensure(HostCompiletest {
461+
run.builder.ensure(HostCompiletest {
497462
compiler,
498-
target,
463+
target: run.target,
499464
mode: test.mode,
500465
suite: test.suite
501466
});
@@ -739,14 +704,9 @@ impl Step for Docs {
739704
run.path("src/doc")
740705
}
741706

742-
fn make_run(
743-
builder: &Builder,
744-
_path: Option<&Path>,
745-
host: Interned<String>,
746-
_target: Interned<String>,
747-
) {
748-
builder.ensure(Docs {
749-
compiler: builder.compiler(builder.top_stage, host),
707+
fn make_run(run: RunConfig) {
708+
run.builder.ensure(Docs {
709+
compiler: run.builder.compiler(run.builder.top_stage, run.host),
750710
});
751711
}
752712

@@ -802,14 +762,9 @@ impl Step for ErrorIndex {
802762
run.path("src/tools/error_index_generator")
803763
}
804764

805-
fn make_run(
806-
builder: &Builder,
807-
_path: Option<&Path>,
808-
host: Interned<String>,
809-
_target: Interned<String>,
810-
) {
811-
builder.ensure(ErrorIndex {
812-
compiler: builder.compiler(builder.top_stage, host),
765+
fn make_run(run: RunConfig) {
766+
run.builder.ensure(ErrorIndex {
767+
compiler: run.builder.compiler(run.builder.top_stage, run.host),
813768
});
814769
}
815770

@@ -886,15 +841,11 @@ impl Step for CrateLibrustc {
886841
run.krate("rustc-main")
887842
}
888843

889-
fn make_run(
890-
builder: &Builder,
891-
path: Option<&Path>,
892-
host: Interned<String>,
893-
target: Interned<String>,
894-
) {
895-
let compiler = builder.compiler(builder.top_stage, host);
844+
fn make_run(run: RunConfig) {
845+
let builder = run.builder;
846+
let compiler = builder.compiler(builder.top_stage, run.host);
896847

897-
let run = |name: Option<Interned<String>>| {
848+
let make = |name: Option<Interned<String>>| {
898849
let test_kind = if builder.kind == Kind::Test {
899850
TestKind::Test
900851
} else if builder.kind == Kind::Bench {
@@ -905,20 +856,20 @@ impl Step for CrateLibrustc {
905856

906857
builder.ensure(CrateLibrustc {
907858
compiler,
908-
target,
859+
target: run.target,
909860
test_kind: test_kind,
910861
krate: name,
911862
});
912863
};
913864

914-
if let Some(path) = path {
865+
if let Some(path) = run.path {
915866
for (name, krate_path) in builder.crates("rustc-main") {
916867
if path.ends_with(krate_path) {
917-
run(Some(name));
868+
make(Some(name));
918869
}
919870
}
920871
} else {
921-
run(None);
872+
make(None);
922873
}
923874
}
924875

@@ -952,15 +903,11 @@ impl Step for Crate {
952903
run.krate("std").krate("test")
953904
}
954905

955-
fn make_run(
956-
builder: &Builder,
957-
path: Option<&Path>,
958-
host: Interned<String>,
959-
target: Interned<String>,
960-
) {
961-
let compiler = builder.compiler(builder.top_stage, host);
906+
fn make_run(run: RunConfig) {
907+
let builder = run.builder;
908+
let compiler = builder.compiler(builder.top_stage, run.host);
962909

963-
let run = |mode: Mode, name: Option<Interned<String>>| {
910+
let make = |mode: Mode, name: Option<Interned<String>>| {
964911
let test_kind = if builder.kind == Kind::Test {
965912
TestKind::Test
966913
} else if builder.kind == Kind::Bench {
@@ -970,27 +917,28 @@ impl Step for Crate {
970917
};
971918

972919
builder.ensure(Crate {
973-
compiler, target,
920+
compiler,
921+
target: run.target,
974922
mode: mode,
975923
test_kind: test_kind,
976924
krate: name,
977925
});
978926
};
979927

980-
if let Some(path) = path {
928+
if let Some(path) = run.path {
981929
for (name, krate_path) in builder.crates("std") {
982930
if path.ends_with(krate_path) {
983-
run(Mode::Libstd, Some(name));
931+
make(Mode::Libstd, Some(name));
984932
}
985933
}
986934
for (name, krate_path) in builder.crates("test") {
987935
if path.ends_with(krate_path) {
988-
run(Mode::Libtest, Some(name));
936+
make(Mode::Libtest, Some(name));
989937
}
990938
}
991939
} else {
992-
run(Mode::Libstd, None);
993-
run(Mode::Libtest, None);
940+
make(Mode::Libstd, None);
941+
make(Mode::Libtest, None);
994942
}
995943
}
996944

@@ -1333,12 +1281,7 @@ impl Step for Bootstrap {
13331281
run.path("src/bootstrap")
13341282
}
13351283

1336-
fn make_run(
1337-
builder: &Builder,
1338-
_path: Option<&Path>,
1339-
_host: Interned<String>,
1340-
_target: Interned<String>,
1341-
) {
1342-
builder.ensure(Bootstrap);
1284+
fn make_run(run: RunConfig) {
1285+
run.builder.ensure(Bootstrap);
13431286
}
13441287
}

0 commit comments

Comments
 (0)