Skip to content

Commit

Permalink
Remove run_delaying_failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Jun 20, 2024
1 parent e933cfb commit 0de7b92
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
30 changes: 19 additions & 11 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ You can skip linkcheck with --skip src/tools/linkchecker"
let _guard =
builder.msg(Kind::Test, compiler.stage, "Linkcheck", bootstrap_host, bootstrap_host);
let _time = helpers::timeit(builder);
builder.run_delaying_failure(linkchecker.arg(builder.out.join(host.triple).join("doc")));
builder.run_tracked(
BootstrapCommand::from(linkchecker.arg(builder.out.join(host.triple).join("doc")))
.delay_failure(),
);
}

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand Down Expand Up @@ -213,8 +216,11 @@ impl Step for HtmlCheck {
builder,
));

builder.run_delaying_failure(
builder.tool_cmd(Tool::HtmlChecker).arg(builder.doc_out(self.target)),
builder.run_tracked(
BootstrapCommand::from(
builder.tool_cmd(Tool::HtmlChecker).arg(builder.doc_out(self.target)),
)
.delay_failure(),
);
}
}
Expand Down Expand Up @@ -261,7 +267,7 @@ impl Step for Cargotest {
.env("RUSTC", builder.rustc(compiler))
.env("RUSTDOC", builder.rustdoc(compiler));
add_rustdoc_cargo_linker_args(cmd, builder, compiler.host, LldThreads::No);
builder.run_delaying_failure(cmd);
builder.run_tracked(BootstrapCommand::from(cmd).delay_failure());
}
}

Expand Down Expand Up @@ -813,7 +819,7 @@ impl Step for RustdocTheme {
.env("RUSTC_BOOTSTRAP", "1");
cmd.args(linker_args(builder, self.compiler.host, LldThreads::No));

builder.run_delaying_failure(&mut cmd);
builder.run_tracked(BootstrapCommand::from(&mut cmd).delay_failure());
}
}

Expand Down Expand Up @@ -1093,7 +1099,7 @@ HELP: to skip test's attempt to check tidiness, pass `--skip src/tools/tidy` to
}

builder.info("tidy check");
builder.run_delaying_failure(&mut cmd);
builder.run_tracked(BootstrapCommand::from(&mut cmd).delay_failure());

builder.info("x.py completions check");
let [bash, zsh, fish, powershell] = ["x.py.sh", "x.py.zsh", "x.py.fish", "x.py.ps1"]
Expand Down Expand Up @@ -2179,7 +2185,8 @@ impl BookTest {
compiler.host,
);
let _time = helpers::timeit(builder);
let toolstate = if builder.run_delaying_failure(&mut rustbook_cmd) {
let cmd = BootstrapCommand::from(&mut rustbook_cmd).delay_failure();
let toolstate = if builder.run_tracked(cmd).is_success() {
ToolState::TestPass
} else {
ToolState::TestFail
Expand Down Expand Up @@ -2371,7 +2378,8 @@ impl Step for RustcGuide {

let src = builder.src.join(relative_path);
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
let toolstate = if builder.run_delaying_failure(rustbook_cmd.arg("linkcheck").arg(&src)) {
let cmd = BootstrapCommand::from(rustbook_cmd.arg("linkcheck").arg(&src)).delay_failure();
let toolstate = if builder.run_tracked(cmd).is_success() {
ToolState::TestPass
} else {
ToolState::TestFail
Expand Down Expand Up @@ -2985,7 +2993,7 @@ impl Step for Bootstrap {
.current_dir(builder.src.join("src/bootstrap/"));
// NOTE: we intentionally don't pass test_args here because the args for unittest and cargo test are mutually incompatible.
// Use `python -m unittest` manually if you want to pass arguments.
builder.run_delaying_failure(&mut check_bootstrap);
builder.run_tracked(BootstrapCommand::from(&mut check_bootstrap).delay_failure());

let mut cmd = Command::new(&builder.initial_cargo);
cmd.arg("test")
Expand Down Expand Up @@ -3062,7 +3070,7 @@ impl Step for TierCheck {
self.compiler.host,
self.compiler.host,
);
builder.run_delaying_failure(&mut cargo.into());
builder.run_tracked(BootstrapCommand::from(&mut cargo.into()).delay_failure());
}
}

Expand Down Expand Up @@ -3148,7 +3156,7 @@ impl Step for RustInstaller {
cmd.env("CARGO", &builder.initial_cargo);
cmd.env("RUSTC", &builder.initial_rustc);
cmd.env("TMP_DIR", &tmpdir);
builder.run_delaying_failure(&mut cmd);
builder.run_tracked(BootstrapCommand::from(&mut cmd).delay_failure());
}

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand Down
22 changes: 10 additions & 12 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,11 @@ impl Build {

self.verbose(|| println!("running: {command:?}"));

let (output, print_error): (io::Result<CommandOutput>, bool) = match command.output_mode {
let output_mode = command.output_mode.unwrap_or_else(|| match self.is_verbose() {
true => OutputMode::PrintAll,
false => OutputMode::PrintOutput,
});
let (output, print_error): (io::Result<CommandOutput>, bool) = match output_mode {
mode @ (OutputMode::PrintAll | OutputMode::PrintOutput) => (
command.command.status().map(|status| status.into()),
matches!(mode, OutputMode::PrintAll),
Expand Down Expand Up @@ -1028,16 +1032,6 @@ impl Build {
));
}

/// Runs a command, printing out contextual info if it fails, and delaying errors until the build finishes.
pub(crate) fn run_delaying_failure(&self, cmd: &mut Command) -> bool {
self.run_cmd(BootstrapCommand::from(cmd).delay_failure().output_mode(
match self.is_verbose() {
true => OutputMode::PrintAll,
false => OutputMode::PrintOutput,
},
))
}

/// A centralized function for running commands that do not return output.
pub(crate) fn run_cmd<'a, C: Into<BootstrapCommand<'a>>>(&self, cmd: C) -> bool {
if self.config.dry_run() {
Expand All @@ -1047,7 +1041,11 @@ impl Build {
let command = cmd.into();
self.verbose(|| println!("running: {command:?}"));

let (output, print_error) = match command.output_mode {
let output_mode = command.output_mode.unwrap_or_else(|| match self.is_verbose() {
true => OutputMode::PrintAll,
false => OutputMode::PrintOutput,
});
let (output, print_error) = match output_mode {
mode @ (OutputMode::PrintAll | OutputMode::PrintOutput) => (
command.command.status().map(|status| Output {
status,
Expand Down
10 changes: 3 additions & 7 deletions src/bootstrap/src/utils/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum OutputMode {
pub struct BootstrapCommand<'a> {
pub command: &'a mut Command,
pub failure_behavior: BehaviorOnFailure,
pub output_mode: OutputMode,
pub output_mode: Option<OutputMode>,
}

impl<'a> BootstrapCommand<'a> {
Expand All @@ -50,17 +50,13 @@ impl<'a> BootstrapCommand<'a> {
}

pub fn output_mode(self, output_mode: OutputMode) -> Self {
Self { output_mode, ..self }
Self { output_mode: Some(output_mode), ..self }
}
}

impl<'a> From<&'a mut Command> for BootstrapCommand<'a> {
fn from(command: &'a mut Command) -> Self {
Self {
command,
failure_behavior: BehaviorOnFailure::Exit,
output_mode: OutputMode::PrintAll,
}
Self { command, failure_behavior: BehaviorOnFailure::Exit, output_mode: None }
}
}

Expand Down

0 comments on commit 0de7b92

Please sign in to comment.