Skip to content

Commit fb623fa

Browse files
committed
Auto merge of #48105 - Mark-Simulacrum:exclude-paths, r=alexcrichton
Implement excluding a build-step via --exclude First step to fixing #47911. This doesn't change any CI configuration, but implements what I believe necessary to make that feasible in rustbuild. In theory this should be sufficient to allow someone to open a PR against .travis.yml and appveyor.yml which splits the Windows 32-bit tests and maybe the OS X tests into multiple builders (depending on what our cost-concerns are) to reduce runtimes. r? @alexcrichton cc @kennytm
2 parents 4d2d3fc + a64575c commit fb623fa

File tree

10 files changed

+444
-327
lines changed

10 files changed

+444
-327
lines changed

src/bootstrap/builder.rs

+99-23
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct RunConfig<'a> {
9595
pub builder: &'a Builder<'a>,
9696
pub host: Interned<String>,
9797
pub target: Interned<String>,
98-
pub path: Option<&'a Path>,
98+
pub path: PathBuf,
9999
}
100100

101101
struct StepDescription {
@@ -105,6 +105,32 @@ struct StepDescription {
105105
only_build: bool,
106106
should_run: fn(ShouldRun) -> ShouldRun,
107107
make_run: fn(RunConfig),
108+
name: &'static str,
109+
}
110+
111+
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)]
112+
struct PathSet {
113+
set: BTreeSet<PathBuf>,
114+
}
115+
116+
impl PathSet {
117+
fn empty() -> PathSet {
118+
PathSet { set: BTreeSet::new() }
119+
}
120+
121+
fn one<P: Into<PathBuf>>(path: P) -> PathSet {
122+
let mut set = BTreeSet::new();
123+
set.insert(path.into());
124+
PathSet { set }
125+
}
126+
127+
fn has(&self, needle: &Path) -> bool {
128+
self.set.iter().any(|p| p.ends_with(needle))
129+
}
130+
131+
fn path(&self, builder: &Builder) -> PathBuf {
132+
self.set.iter().next().unwrap_or(&builder.build.src).to_path_buf()
133+
}
108134
}
109135

110136
impl StepDescription {
@@ -116,10 +142,18 @@ impl StepDescription {
116142
only_build: S::ONLY_BUILD,
117143
should_run: S::should_run,
118144
make_run: S::make_run,
145+
name: unsafe { ::std::intrinsics::type_name::<S>() },
119146
}
120147
}
121148

122-
fn maybe_run(&self, builder: &Builder, path: Option<&Path>) {
149+
fn maybe_run(&self, builder: &Builder, pathset: &PathSet) {
150+
if builder.config.exclude.iter().any(|e| pathset.has(e)) {
151+
eprintln!("Skipping {:?} because it is excluded", pathset);
152+
return;
153+
} else if !builder.config.exclude.is_empty() {
154+
eprintln!("{:?} not skipped for {:?} -- not in {:?}", pathset,
155+
self.name, builder.config.exclude);
156+
}
123157
let build = builder.build;
124158
let hosts = if self.only_build_targets || self.only_build {
125159
build.build_triple()
@@ -144,7 +178,7 @@ impl StepDescription {
144178
for target in targets {
145179
let run = RunConfig {
146180
builder,
147-
path,
181+
path: pathset.path(builder),
148182
host: *host,
149183
target: *target,
150184
};
@@ -157,19 +191,28 @@ impl StepDescription {
157191
let should_runs = v.iter().map(|desc| {
158192
(desc.should_run)(ShouldRun::new(builder))
159193
}).collect::<Vec<_>>();
194+
195+
// sanity checks on rules
196+
for (desc, should_run) in v.iter().zip(&should_runs) {
197+
assert!(!should_run.paths.is_empty(),
198+
"{:?} should have at least one pathset", desc.name);
199+
}
200+
160201
if paths.is_empty() {
161202
for (desc, should_run) in v.iter().zip(should_runs) {
162203
if desc.default && should_run.is_really_default {
163-
desc.maybe_run(builder, None);
204+
for pathset in &should_run.paths {
205+
desc.maybe_run(builder, pathset);
206+
}
164207
}
165208
}
166209
} else {
167210
for path in paths {
168211
let mut attempted_run = false;
169212
for (desc, should_run) in v.iter().zip(&should_runs) {
170-
if should_run.run(path) {
213+
if let Some(pathset) = should_run.pathset_for_path(path) {
171214
attempted_run = true;
172-
desc.maybe_run(builder, Some(path));
215+
desc.maybe_run(builder, pathset);
173216
}
174217
}
175218

@@ -185,7 +228,7 @@ impl StepDescription {
185228
pub struct ShouldRun<'a> {
186229
pub builder: &'a Builder<'a>,
187230
// use a BTreeSet to maintain sort order
188-
paths: BTreeSet<PathBuf>,
231+
paths: BTreeSet<PathSet>,
189232

190233
// If this is a default rule, this is an additional constraint placed on
191234
// it's run. Generally something like compiler docs being enabled.
@@ -206,25 +249,46 @@ impl<'a> ShouldRun<'a> {
206249
self
207250
}
208251

252+
// Unlike `krate` this will create just one pathset. As such, it probably shouldn't actually
253+
// ever be used, but as we transition to having all rules properly handle passing krate(...) by
254+
// actually doing something different for every crate passed.
255+
pub fn all_krates(mut self, name: &str) -> Self {
256+
let mut set = BTreeSet::new();
257+
for krate in self.builder.in_tree_crates(name) {
258+
set.insert(PathBuf::from(&krate.path));
259+
}
260+
self.paths.insert(PathSet { set });
261+
self
262+
}
263+
209264
pub fn krate(mut self, name: &str) -> Self {
210-
for (_, krate_path) in self.builder.crates(name) {
211-
self.paths.insert(PathBuf::from(krate_path));
265+
for krate in self.builder.in_tree_crates(name) {
266+
self.paths.insert(PathSet::one(&krate.path));
212267
}
213268
self
214269
}
215270

216-
pub fn path(mut self, path: &str) -> Self {
217-
self.paths.insert(PathBuf::from(path));
271+
// single, non-aliased path
272+
pub fn path(self, path: &str) -> Self {
273+
self.paths(&[path])
274+
}
275+
276+
// multiple aliases for the same job
277+
pub fn paths(mut self, paths: &[&str]) -> Self {
278+
self.paths.insert(PathSet {
279+
set: paths.iter().map(PathBuf::from).collect(),
280+
});
218281
self
219282
}
220283

221284
// allows being more explicit about why should_run in Step returns the value passed to it
222-
pub fn never(self) -> ShouldRun<'a> {
285+
pub fn never(mut self) -> ShouldRun<'a> {
286+
self.paths.insert(PathSet::empty());
223287
self
224288
}
225289

226-
fn run(&self, path: &Path) -> bool {
227-
self.paths.iter().any(|p| path.ends_with(p))
290+
fn pathset_for_path(&self, path: &Path) -> Option<&PathSet> {
291+
self.paths.iter().find(|pathset| pathset.has(path))
228292
}
229293
}
230294

@@ -254,19 +318,23 @@ impl<'a> Builder<'a> {
254318
tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc, tool::Clippy,
255319
native::Llvm, tool::Rustfmt, tool::Miri),
256320
Kind::Check => describe!(check::Std, check::Test, check::Rustc),
257-
Kind::Test => describe!(test::Tidy, test::Bootstrap, test::DefaultCompiletest,
258-
test::HostCompiletest, test::Crate, test::CrateLibrustc, test::Rustdoc,
259-
test::Linkcheck, test::Cargotest, test::Cargo, test::Rls, test::Docs,
260-
test::ErrorIndex, test::Distcheck, test::Rustfmt, test::Miri, test::Clippy,
261-
test::RustdocJS, test::RustdocTheme),
321+
Kind::Test => describe!(test::Tidy, test::Bootstrap, test::Ui, test::RunPass,
322+
test::CompileFail, test::ParseFail, test::RunFail, test::RunPassValgrind,
323+
test::MirOpt, test::Codegen, test::CodegenUnits, test::Incremental, test::Debuginfo,
324+
test::UiFullDeps, test::RunPassFullDeps, test::RunFailFullDeps,
325+
test::CompileFailFullDeps, test::IncrementalFullDeps, test::Rustdoc, test::Pretty,
326+
test::RunPassPretty, test::RunFailPretty, test::RunPassValgrindPretty,
327+
test::RunPassFullDepsPretty, test::RunFailFullDepsPretty, test::RunMake,
328+
test::Crate, test::CrateLibrustc, test::Rustdoc, test::Linkcheck, test::Cargotest,
329+
test::Cargo, test::Rls, test::Docs, test::ErrorIndex, test::Distcheck,
330+
test::Rustfmt, test::Miri, test::Clippy, test::RustdocJS, test::RustdocTheme),
262331
Kind::Bench => describe!(test::Crate, test::CrateLibrustc),
263332
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
264333
doc::Standalone, doc::Std, doc::Test, doc::Rustc, doc::ErrorIndex, doc::Nomicon,
265334
doc::Reference, doc::Rustdoc, doc::RustByExample, doc::CargoBook),
266335
Kind::Dist => describe!(dist::Docs, dist::Mingw, dist::Rustc, dist::DebuggerScripts,
267336
dist::Std, dist::Analysis, dist::Src, dist::PlainSourceTarball, dist::Cargo,
268-
dist::Rls, dist::Rustfmt, dist::Extended, dist::HashSign,
269-
dist::DontDistWithMiriEnabled),
337+
dist::Rls, dist::Rustfmt, dist::Extended, dist::HashSign),
270338
Kind::Install => describe!(install::Docs, install::Std, install::Cargo, install::Rls,
271339
install::Rustfmt, install::Analysis, install::Src, install::Rustc),
272340
}
@@ -297,8 +365,10 @@ impl<'a> Builder<'a> {
297365
should_run = (desc.should_run)(should_run);
298366
}
299367
let mut help = String::from("Available paths:\n");
300-
for path in should_run.paths {
301-
help.push_str(format!(" ./x.py {} {}\n", subcommand, path.display()).as_str());
368+
for pathset in should_run.paths {
369+
for path in pathset.set {
370+
help.push_str(format!(" ./x.py {} {}\n", subcommand, path.display()).as_str());
371+
}
302372
}
303373
Some(help)
304374
}
@@ -323,6 +393,12 @@ impl<'a> Builder<'a> {
323393
stack: RefCell::new(Vec::new()),
324394
};
325395

396+
if kind == Kind::Dist {
397+
assert!(!build.config.test_miri, "Do not distribute with miri enabled.\n\
398+
The distributed libraries would include all MIR (increasing binary size).
399+
The distributed MIR would include validation statements.");
400+
}
401+
326402
StepDescription::run(&Builder::get_step_descriptions(builder.kind), &builder, paths);
327403
}
328404

src/bootstrap/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Step for Std {
2626
const DEFAULT: bool = true;
2727

2828
fn should_run(run: ShouldRun) -> ShouldRun {
29-
run.path("src/libstd").krate("std")
29+
run.all_krates("std")
3030
}
3131

3232
fn make_run(run: RunConfig) {
@@ -67,7 +67,7 @@ impl Step for Rustc {
6767
const DEFAULT: bool = true;
6868

6969
fn should_run(run: ShouldRun) -> ShouldRun {
70-
run.path("src/librustc").krate("rustc-main")
70+
run.all_krates("rustc-main")
7171
}
7272

7373
fn make_run(run: RunConfig) {
@@ -114,7 +114,7 @@ impl Step for Test {
114114
const DEFAULT: bool = true;
115115

116116
fn should_run(run: ShouldRun) -> ShouldRun {
117-
run.path("src/libtest").krate("test")
117+
run.all_krates("test")
118118
}
119119

120120
fn make_run(run: RunConfig) {

src/bootstrap/compile.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Step for Std {
4848
const DEFAULT: bool = true;
4949

5050
fn should_run(run: ShouldRun) -> ShouldRun {
51-
run.path("src/libstd").krate("std")
51+
run.all_krates("std")
5252
}
5353

5454
fn make_run(run: RunConfig) {
@@ -320,7 +320,7 @@ impl Step for Test {
320320
const DEFAULT: bool = true;
321321

322322
fn should_run(run: ShouldRun) -> ShouldRun {
323-
run.path("src/libtest").krate("test")
323+
run.all_krates("test")
324324
}
325325

326326
fn make_run(run: RunConfig) {
@@ -436,7 +436,7 @@ impl Step for Rustc {
436436
const DEFAULT: bool = true;
437437

438438
fn should_run(run: ShouldRun) -> ShouldRun {
439-
run.path("src/librustc").krate("rustc-main")
439+
run.all_krates("rustc-main")
440440
}
441441

442442
fn make_run(run: RunConfig) {
@@ -593,7 +593,7 @@ impl Step for CodegenBackend {
593593
const DEFAULT: bool = true;
594594

595595
fn should_run(run: ShouldRun) -> ShouldRun {
596-
run.path("src/librustc_trans")
596+
run.all_krates("rustc_trans")
597597
}
598598

599599
fn make_run(run: RunConfig) {
@@ -828,7 +828,7 @@ impl Step for Assemble {
828828
type Output = Compiler;
829829

830830
fn should_run(run: ShouldRun) -> ShouldRun {
831-
run.path("src/rustc")
831+
run.all_krates("rustc-main")
832832
}
833833

834834
/// Prepare a new compiler from the artifacts in `stage`

src/bootstrap/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct Config {
5656
pub sanitizers: bool,
5757
pub profiler: bool,
5858
pub ignore_git: bool,
59+
pub exclude: Vec<PathBuf>,
5960

6061
pub run_host_only: bool,
6162

@@ -311,6 +312,7 @@ impl Config {
311312
let flags = Flags::parse(&args);
312313
let file = flags.config.clone();
313314
let mut config = Config::default();
315+
config.exclude = flags.exclude;
314316
config.llvm_enabled = true;
315317
config.llvm_optimize = true;
316318
config.llvm_version_check = true;

src/bootstrap/dist.rs

-25
Original file line numberDiff line numberDiff line change
@@ -1233,31 +1233,6 @@ impl Step for Rustfmt {
12331233
}
12341234
}
12351235

1236-
1237-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1238-
pub struct DontDistWithMiriEnabled;
1239-
1240-
impl Step for DontDistWithMiriEnabled {
1241-
type Output = PathBuf;
1242-
const DEFAULT: bool = true;
1243-
1244-
fn should_run(run: ShouldRun) -> ShouldRun {
1245-
let build_miri = run.builder.build.config.test_miri;
1246-
run.default_condition(build_miri)
1247-
}
1248-
1249-
fn make_run(run: RunConfig) {
1250-
run.builder.ensure(DontDistWithMiriEnabled);
1251-
}
1252-
1253-
fn run(self, _: &Builder) -> PathBuf {
1254-
panic!("Do not distribute with miri enabled.\n\
1255-
The distributed libraries would include all MIR (increasing binary size).
1256-
The distributed MIR would include validation statements.");
1257-
}
1258-
}
1259-
1260-
12611236
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
12621237
pub struct Extended {
12631238
stage: u32,

src/bootstrap/doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl Step for Std {
429429

430430
fn should_run(run: ShouldRun) -> ShouldRun {
431431
let builder = run.builder;
432-
run.krate("std").default_condition(builder.build.config.docs)
432+
run.all_krates("std").default_condition(builder.build.config.docs)
433433
}
434434

435435
fn make_run(run: RunConfig) {

0 commit comments

Comments
 (0)