Skip to content

Commit

Permalink
Add a file to trivially disable tool building or testing
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Sep 17, 2017
1 parent f0b5402 commit ab018c7
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 43 deletions.
19 changes: 14 additions & 5 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::path::{PathBuf, Path};
use std::process::Command;
use std::io::Read;

use build_helper::{self, output};
use build_helper::{self, output, BuildExpectation};

use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
use cache::{INTERNER, Interned};
Expand All @@ -33,6 +33,7 @@ use native;
use tool::{self, Tool};
use util::{self, dylib_path, dylib_path_var};
use {Build, Mode};
use toolstate::ToolState;

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

Expand Down Expand Up @@ -64,17 +65,21 @@ impl fmt::Display for TestKind {
}
}

fn try_run(build: &Build, cmd: &mut Command) {
fn try_run_expecting(build: &Build, cmd: &mut Command, expect: BuildExpectation) {
if !build.fail_fast {
if !build.try_run(cmd) {
if !build.try_run(cmd, expect) {
let failures = build.delayed_failures.get();
build.delayed_failures.set(failures + 1);
}
} else {
build.run(cmd);
build.run_expecting(cmd, expect);
}
}

fn try_run(build: &Build, cmd: &mut Command) {
try_run_expecting(build, cmd, BuildExpectation::None)
}

fn try_run_quiet(build: &Build, cmd: &mut Command) {
if !build.fail_fast {
if !build.try_run_quiet(cmd) {
Expand Down Expand Up @@ -333,7 +338,11 @@ impl Step for Miri {

builder.add_rustc_lib_path(compiler, &mut cargo);

try_run(build, &mut cargo);
try_run_expecting(
build,
&mut cargo,
builder.build.config.toolstate.miri.passes(ToolState::Testing),
);
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use util::exe;
use cache::{INTERNER, Interned};
use flags::Flags;
pub use flags::Subcommand;
use toolstate::ToolStates;

/// Global configuration for the entire build and/or bootstrap.
///
Expand Down Expand Up @@ -131,6 +132,8 @@ pub struct Config {
// These are either the stage0 downloaded binaries or the locally installed ones.
pub initial_cargo: PathBuf,
pub initial_rustc: PathBuf,

pub toolstate: ToolStates,
}

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

let toolstate_toml_path = config.src.join("src/tools/toolstate.toml");
let parse_toolstate = || -> Result<_, Box<::std::error::Error>> {
let mut f = File::open(toolstate_toml_path)?;
let mut contents = String::new();
f.read_to_string(&mut contents)?;
Ok(toml::from_str(&contents)?)
};
config.toolstate = parse_toolstate().unwrap_or_else(|err| {
println!("failed to parse TOML configuration 'toolstate.toml': {}", err);
process::exit(2);
});

let build = toml.build.clone().unwrap_or(Build::default());
set(&mut config.build, build.build.clone().map(|x| INTERNER.intern_string(x)));
set(&mut config.build, flags.build);
Expand Down
29 changes: 19 additions & 10 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ use std::path::{PathBuf, Path};
use std::process::Command;
use std::slice;

use build_helper::{run_silent, run_suppressed, try_run_silent, try_run_suppressed, output, mtime};
use build_helper::{run_silent, run_suppressed, try_run_silent, try_run_suppressed, output, mtime,
BuildExpectation};

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

Expand All @@ -164,6 +165,7 @@ pub mod util;
mod builder;
mod cache;
mod tool;
mod toolstate;

#[cfg(windows)]
mod job;
Expand Down Expand Up @@ -542,32 +544,39 @@ impl Build {
.join(libdir(&self.config.build))
}

/// Runs a command, printing out nice contextual information if its build
/// status is not the expected one
fn run_expecting(&self, cmd: &mut Command, expect: BuildExpectation) {
self.verbose(&format!("running: {:?}", cmd));
run_silent(cmd, expect)
}

/// Runs a command, printing out nice contextual information if it fails.
fn run(&self, cmd: &mut Command) {
self.verbose(&format!("running: {:?}", cmd));
run_silent(cmd)
self.run_expecting(cmd, BuildExpectation::None)
}

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

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

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

pub fn is_verbose(&self) -> bool {
Expand Down
16 changes: 13 additions & 3 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use compile::{self, libtest_stamp, libstd_stamp, librustc_stamp};
use native;
use channel::GitInfo;
use cache::Interned;
use toolstate::ToolState;
use build_helper::BuildExpectation;

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct CleanTools {
Expand Down Expand Up @@ -64,6 +66,7 @@ struct ToolBuild {
tool: &'static str,
path: &'static str,
mode: Mode,
expectation: BuildExpectation,
}

impl Step for ToolBuild {
Expand All @@ -83,6 +86,7 @@ impl Step for ToolBuild {
let target = self.target;
let tool = self.tool;
let path = self.path;
let expectation = self.expectation;

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

let mut cargo = prepare_tool_cargo(builder, compiler, target, "build", path);
build.run(&mut cargo);
build.run_expecting(&mut cargo, expectation);
build.cargo_out(compiler, Mode::Tool, target).join(exe(tool, &compiler.host))
}
}
Expand Down Expand Up @@ -200,6 +204,7 @@ macro_rules! tool {
tool: $tool_name,
mode: $mode,
path: $path,
expectation: BuildExpectation::None,
})
}
}
Expand Down Expand Up @@ -247,6 +252,7 @@ impl Step for RemoteTestServer {
tool: "remote-test-server",
mode: Mode::Libstd,
path: "src/tools/remote-test-server",
expectation: BuildExpectation::None,
})
}
}
Expand Down Expand Up @@ -359,6 +365,7 @@ impl Step for Cargo {
tool: "cargo",
mode: Mode::Librustc,
path: "src/tools/cargo",
expectation: BuildExpectation::None,
})
}
}
Expand Down Expand Up @@ -398,6 +405,7 @@ impl Step for Clippy {
tool: "clippy",
mode: Mode::Librustc,
path: "src/tools/clippy",
expectation: BuildExpectation::None,
})
}
}
Expand Down Expand Up @@ -441,6 +449,7 @@ impl Step for Rls {
tool: "rls",
mode: Mode::Librustc,
path: "src/tools/rls",
expectation: BuildExpectation::None,
})
}
}
Expand Down Expand Up @@ -492,8 +501,8 @@ impl Step for Miri {
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
let builder = run.builder;
run.path("src/tools/miri").default_condition(builder.build.config.test_miri)
let build_miri = run.builder.build.config.test_miri;
run.path("src/tools/miri").default_condition(build_miri)
}

fn make_run(run: RunConfig) {
Expand All @@ -510,6 +519,7 @@ impl Step for Miri {
tool: "miri",
mode: Mode::Librustc,
path: "src/tools/miri",
expectation: builder.build.config.toolstate.miri.passes(ToolState::Compiling),
})
}
}
Expand Down
48 changes: 48 additions & 0 deletions src/bootstrap/toolstate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use build_helper::BuildExpectation;

#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Eq)]
/// Whether a tool can be compiled, tested or neither
pub enum ToolState {
/// The tool compiles successfully, but the test suite fails
Compiling = 1,
/// The tool compiles successfully and its test suite passes
Testing = 2,
/// The tool can't even be compiled
Broken = 0,
}

impl ToolState {
/// If a tool with the current toolstate should be working on
/// the given toolstate
pub fn passes(self, other: ToolState) -> BuildExpectation {
if self as usize >= other as usize {
BuildExpectation::Succeeding
} else {
BuildExpectation::Failing
}
}
}

impl Default for ToolState {
fn default() -> Self {
// err on the safe side
ToolState::Broken
}
}

#[derive(Copy, Clone, Debug, Deserialize, Default)]
/// Used to express which tools should (not) be compiled or tested.
/// This is created from `toolstate.toml`.
pub struct ToolStates {
pub miri: ToolState,
}
Loading

0 comments on commit ab018c7

Please sign in to comment.