Skip to content

Commit ab018c7

Browse files
committed
Add a file to trivially disable tool building or testing
1 parent f0b5402 commit ab018c7

File tree

9 files changed

+203
-43
lines changed

9 files changed

+203
-43
lines changed

src/bootstrap/check.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::path::{PathBuf, Path};
2323
use std::process::Command;
2424
use std::io::Read;
2525

26-
use build_helper::{self, output};
26+
use build_helper::{self, output, BuildExpectation};
2727

2828
use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
2929
use cache::{INTERNER, Interned};
@@ -33,6 +33,7 @@ use native;
3333
use tool::{self, Tool};
3434
use util::{self, dylib_path, dylib_path_var};
3535
use {Build, Mode};
36+
use toolstate::ToolState;
3637

3738
const ADB_TEST_DIR: &str = "/data/tmp/work";
3839

@@ -64,17 +65,21 @@ impl fmt::Display for TestKind {
6465
}
6566
}
6667

67-
fn try_run(build: &Build, cmd: &mut Command) {
68+
fn try_run_expecting(build: &Build, cmd: &mut Command, expect: BuildExpectation) {
6869
if !build.fail_fast {
69-
if !build.try_run(cmd) {
70+
if !build.try_run(cmd, expect) {
7071
let failures = build.delayed_failures.get();
7172
build.delayed_failures.set(failures + 1);
7273
}
7374
} else {
74-
build.run(cmd);
75+
build.run_expecting(cmd, expect);
7576
}
7677
}
7778

79+
fn try_run(build: &Build, cmd: &mut Command) {
80+
try_run_expecting(build, cmd, BuildExpectation::None)
81+
}
82+
7883
fn try_run_quiet(build: &Build, cmd: &mut Command) {
7984
if !build.fail_fast {
8085
if !build.try_run_quiet(cmd) {
@@ -333,7 +338,11 @@ impl Step for Miri {
333338

334339
builder.add_rustc_lib_path(compiler, &mut cargo);
335340

336-
try_run(build, &mut cargo);
341+
try_run_expecting(
342+
build,
343+
&mut cargo,
344+
builder.build.config.toolstate.miri.passes(ToolState::Testing),
345+
);
337346
}
338347
}
339348

src/bootstrap/config.rs

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use util::exe;
2727
use cache::{INTERNER, Interned};
2828
use flags::Flags;
2929
pub use flags::Subcommand;
30+
use toolstate::ToolStates;
3031

3132
/// Global configuration for the entire build and/or bootstrap.
3233
///
@@ -131,6 +132,8 @@ pub struct Config {
131132
// These are either the stage0 downloaded binaries or the locally installed ones.
132133
pub initial_cargo: PathBuf,
133134
pub initial_rustc: PathBuf,
135+
136+
pub toolstate: ToolStates,
134137
}
135138

136139
/// Per-target configuration stored in the global configuration structure.
@@ -333,6 +336,18 @@ impl Config {
333336
}
334337
}).unwrap_or_else(|| TomlConfig::default());
335338

339+
let toolstate_toml_path = config.src.join("src/tools/toolstate.toml");
340+
let parse_toolstate = || -> Result<_, Box<::std::error::Error>> {
341+
let mut f = File::open(toolstate_toml_path)?;
342+
let mut contents = String::new();
343+
f.read_to_string(&mut contents)?;
344+
Ok(toml::from_str(&contents)?)
345+
};
346+
config.toolstate = parse_toolstate().unwrap_or_else(|err| {
347+
println!("failed to parse TOML configuration 'toolstate.toml': {}", err);
348+
process::exit(2);
349+
});
350+
336351
let build = toml.build.clone().unwrap_or(Build::default());
337352
set(&mut config.build, build.build.clone().map(|x| INTERNER.intern_string(x)));
338353
set(&mut config.build, flags.build);

src/bootstrap/lib.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ use std::path::{PathBuf, Path};
143143
use std::process::Command;
144144
use std::slice;
145145

146-
use build_helper::{run_silent, run_suppressed, try_run_silent, try_run_suppressed, output, mtime};
146+
use build_helper::{run_silent, run_suppressed, try_run_silent, try_run_suppressed, output, mtime,
147+
BuildExpectation};
147148

148149
use util::{exe, libdir, OutputFolder, CiEnv};
149150

@@ -164,6 +165,7 @@ pub mod util;
164165
mod builder;
165166
mod cache;
166167
mod tool;
168+
mod toolstate;
167169

168170
#[cfg(windows)]
169171
mod job;
@@ -542,32 +544,39 @@ impl Build {
542544
.join(libdir(&self.config.build))
543545
}
544546

547+
/// Runs a command, printing out nice contextual information if its build
548+
/// status is not the expected one
549+
fn run_expecting(&self, cmd: &mut Command, expect: BuildExpectation) {
550+
self.verbose(&format!("running: {:?}", cmd));
551+
run_silent(cmd, expect)
552+
}
553+
545554
/// Runs a command, printing out nice contextual information if it fails.
546555
fn run(&self, cmd: &mut Command) {
547-
self.verbose(&format!("running: {:?}", cmd));
548-
run_silent(cmd)
556+
self.run_expecting(cmd, BuildExpectation::None)
549557
}
550558

551559
/// Runs a command, printing out nice contextual information if it fails.
552560
fn run_quiet(&self, cmd: &mut Command) {
553561
self.verbose(&format!("running: {:?}", cmd));
554-
run_suppressed(cmd)
562+
run_suppressed(cmd, BuildExpectation::None)
555563
}
556564

557-
/// Runs a command, printing out nice contextual information if it fails.
558-
/// Exits if the command failed to execute at all, otherwise returns its
559-
/// `status.success()`.
560-
fn try_run(&self, cmd: &mut Command) -> bool {
565+
/// Runs a command, printing out nice contextual information if its build
566+
/// status is not the expected one.
567+
/// Exits if the command failed to execute at all, otherwise returns whether
568+
/// the expectation was met
569+
fn try_run(&self, cmd: &mut Command, expect: BuildExpectation) -> bool {
561570
self.verbose(&format!("running: {:?}", cmd));
562-
try_run_silent(cmd)
571+
try_run_silent(cmd, expect)
563572
}
564573

565574
/// Runs a command, printing out nice contextual information if it fails.
566575
/// Exits if the command failed to execute at all, otherwise returns its
567576
/// `status.success()`.
568577
fn try_run_quiet(&self, cmd: &mut Command) -> bool {
569578
self.verbose(&format!("running: {:?}", cmd));
570-
try_run_suppressed(cmd)
579+
try_run_suppressed(cmd, BuildExpectation::None)
571580
}
572581

573582
pub fn is_verbose(&self) -> bool {

src/bootstrap/tool.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use compile::{self, libtest_stamp, libstd_stamp, librustc_stamp};
2121
use native;
2222
use channel::GitInfo;
2323
use cache::Interned;
24+
use toolstate::ToolState;
25+
use build_helper::BuildExpectation;
2426

2527
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2628
pub struct CleanTools {
@@ -64,6 +66,7 @@ struct ToolBuild {
6466
tool: &'static str,
6567
path: &'static str,
6668
mode: Mode,
69+
expectation: BuildExpectation,
6770
}
6871

6972
impl Step for ToolBuild {
@@ -83,6 +86,7 @@ impl Step for ToolBuild {
8386
let target = self.target;
8487
let tool = self.tool;
8588
let path = self.path;
89+
let expectation = self.expectation;
8690

8791
match self.mode {
8892
Mode::Libstd => builder.ensure(compile::Std { compiler, target }),
@@ -95,7 +99,7 @@ impl Step for ToolBuild {
9599
println!("Building stage{} tool {} ({})", compiler.stage, tool, target);
96100

97101
let mut cargo = prepare_tool_cargo(builder, compiler, target, "build", path);
98-
build.run(&mut cargo);
102+
build.run_expecting(&mut cargo, expectation);
99103
build.cargo_out(compiler, Mode::Tool, target).join(exe(tool, &compiler.host))
100104
}
101105
}
@@ -200,6 +204,7 @@ macro_rules! tool {
200204
tool: $tool_name,
201205
mode: $mode,
202206
path: $path,
207+
expectation: BuildExpectation::None,
203208
})
204209
}
205210
}
@@ -247,6 +252,7 @@ impl Step for RemoteTestServer {
247252
tool: "remote-test-server",
248253
mode: Mode::Libstd,
249254
path: "src/tools/remote-test-server",
255+
expectation: BuildExpectation::None,
250256
})
251257
}
252258
}
@@ -359,6 +365,7 @@ impl Step for Cargo {
359365
tool: "cargo",
360366
mode: Mode::Librustc,
361367
path: "src/tools/cargo",
368+
expectation: BuildExpectation::None,
362369
})
363370
}
364371
}
@@ -398,6 +405,7 @@ impl Step for Clippy {
398405
tool: "clippy",
399406
mode: Mode::Librustc,
400407
path: "src/tools/clippy",
408+
expectation: BuildExpectation::None,
401409
})
402410
}
403411
}
@@ -441,6 +449,7 @@ impl Step for Rls {
441449
tool: "rls",
442450
mode: Mode::Librustc,
443451
path: "src/tools/rls",
452+
expectation: BuildExpectation::None,
444453
})
445454
}
446455
}
@@ -492,8 +501,8 @@ impl Step for Miri {
492501
const ONLY_HOSTS: bool = true;
493502

494503
fn should_run(run: ShouldRun) -> ShouldRun {
495-
let builder = run.builder;
496-
run.path("src/tools/miri").default_condition(builder.build.config.test_miri)
504+
let build_miri = run.builder.build.config.test_miri;
505+
run.path("src/tools/miri").default_condition(build_miri)
497506
}
498507

499508
fn make_run(run: RunConfig) {
@@ -510,6 +519,7 @@ impl Step for Miri {
510519
tool: "miri",
511520
mode: Mode::Librustc,
512521
path: "src/tools/miri",
522+
expectation: builder.build.config.toolstate.miri.passes(ToolState::Compiling),
513523
})
514524
}
515525
}

src/bootstrap/toolstate.rs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use build_helper::BuildExpectation;
12+
13+
#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Eq)]
14+
/// Whether a tool can be compiled, tested or neither
15+
pub enum ToolState {
16+
/// The tool compiles successfully, but the test suite fails
17+
Compiling = 1,
18+
/// The tool compiles successfully and its test suite passes
19+
Testing = 2,
20+
/// The tool can't even be compiled
21+
Broken = 0,
22+
}
23+
24+
impl ToolState {
25+
/// If a tool with the current toolstate should be working on
26+
/// the given toolstate
27+
pub fn passes(self, other: ToolState) -> BuildExpectation {
28+
if self as usize >= other as usize {
29+
BuildExpectation::Succeeding
30+
} else {
31+
BuildExpectation::Failing
32+
}
33+
}
34+
}
35+
36+
impl Default for ToolState {
37+
fn default() -> Self {
38+
// err on the safe side
39+
ToolState::Broken
40+
}
41+
}
42+
43+
#[derive(Copy, Clone, Debug, Deserialize, Default)]
44+
/// Used to express which tools should (not) be compiled or tested.
45+
/// This is created from `toolstate.toml`.
46+
pub struct ToolStates {
47+
pub miri: ToolState,
48+
}

0 commit comments

Comments
 (0)