Skip to content

Commit 0e090e7

Browse files
committed
Add behavior on failure to BootstrapCommand
1 parent a69edc6 commit 0e090e7

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

src/bootstrap/src/lib.rs

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ use crate::core::config::flags;
3939
use crate::core::config::{DryRun, Target};
4040
use crate::core::config::{LlvmLibunwind, TargetSelection};
4141
use crate::utils::cache::{Interned, INTERNER};
42-
use crate::utils::exec::BootstrapCommand;
43-
use crate::utils::helpers::{
44-
self, dir_is_empty, exe, libdir, mtime, output, run, run_suppressed, symlink_dir,
45-
try_run_suppressed,
46-
};
42+
use crate::utils::exec::{BehaviorOnFailure, BootstrapCommand};
43+
use crate::utils::helpers::{self, dir_is_empty, exe, libdir, mtime, output, symlink_dir};
4744

4845
mod core;
4946
mod utils;
@@ -922,44 +919,30 @@ impl Build {
922919

923920
/// Runs a command, printing out nice contextual information if it fails.
924921
fn run(&self, cmd: &mut Command) {
925-
if self.config.dry_run() {
926-
return;
927-
}
928-
self.verbose(&format!("running: {cmd:?}"));
929-
run(cmd, self.is_verbose())
922+
// FIXME: output mode -> status + err if self.is_verbose()
923+
let cmd: BootstrapCommand<'_> = cmd.into();
924+
self.run_cmd(cmd.fail_fast());
930925
}
931926

932927
/// Runs a command, printing out nice contextual information if it fails.
933928
fn run_quiet(&self, cmd: &mut Command) {
934-
if self.config.dry_run() {
935-
return;
936-
}
937-
self.verbose(&format!("running: {cmd:?}"));
938-
run_suppressed(cmd)
929+
// FIXME: output mode -> output + err
930+
let cmd: BootstrapCommand<'_> = cmd.into();
931+
self.run_cmd(cmd.fail_fast());
939932
}
940933

941934
/// Runs a command, printing out nice contextual information if it fails.
942935
/// Exits if the command failed to execute at all, otherwise returns its
943936
/// `status.success()`.
944937
fn run_quiet_delaying_failure(&self, cmd: &mut Command) -> bool {
945-
if self.config.dry_run() {
946-
return true;
947-
}
948-
if !self.fail_fast {
949-
self.verbose(&format!("running: {cmd:?}"));
950-
if !try_run_suppressed(cmd) {
951-
let mut failures = self.delayed_failures.borrow_mut();
952-
failures.push(format!("{cmd:?}"));
953-
return false;
954-
}
955-
} else {
956-
self.run_quiet(cmd);
957-
}
958-
true
938+
// FIXME: output mode -> output + err
939+
let cmd: BootstrapCommand<'_> = cmd.into();
940+
self.run_cmd(cmd.delay_failure())
959941
}
960942

961943
/// Runs a command, printing out contextual info if it fails, and delaying errors until the build finishes.
962944
pub(crate) fn run_delaying_failure(&self, cmd: &mut Command) -> bool {
945+
// FIXME: output mode -> status + err if self.is_verbose()
963946
let cmd: BootstrapCommand<'_> = cmd.into();
964947
self.run_cmd(cmd.delay_failure())
965948
}
@@ -975,10 +958,16 @@ impl Build {
975958
match result {
976959
Ok(_) => true,
977960
Err(_) => {
978-
if command.delay_failure {
979-
let mut failures = self.delayed_failures.borrow_mut();
980-
failures.push(format!("{command:?}"));
981-
return false;
961+
if let Some(failure_behavior) = command.failure_behavior {
962+
match failure_behavior {
963+
BehaviorOnFailure::DelayFail => {
964+
let mut failures = self.delayed_failures.borrow_mut();
965+
failures.push(format!("{command:?}"));
966+
}
967+
BehaviorOnFailure::Exit => {
968+
exit!(1);
969+
}
970+
}
982971
}
983972
if self.fail_fast {
984973
exit!(1);

src/bootstrap/src/utils/exec.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
use std::process::Command;
22

3+
/// What should be done when the command fails.
4+
#[derive(Debug, Copy, Clone)]
5+
pub enum BehaviorOnFailure {
6+
/// Immediately stop bootstrap.
7+
Exit,
8+
/// Delay failure until the end of bootstrap invocation.
9+
DelayFail,
10+
}
11+
312
/// Wrapper around `std::process::Command`.
413
#[derive(Debug)]
514
pub struct BootstrapCommand<'a> {
615
pub command: &'a mut Command,
7-
/// Report failure later instead of immediately.
8-
pub delay_failure: bool,
16+
pub failure_behavior: Option<BehaviorOnFailure>,
917
}
1018

1119
impl<'a> BootstrapCommand<'a> {
1220
pub fn delay_failure(self) -> Self {
13-
Self { delay_failure: true, ..self }
21+
Self { failure_behavior: Some(BehaviorOnFailure::DelayFail), ..self }
22+
}
23+
pub fn fail_fast(self) -> Self {
24+
Self { failure_behavior: Some(BehaviorOnFailure::Exit), ..self }
1425
}
1526
}
1627

1728
impl<'a> From<&'a mut Command> for BootstrapCommand<'a> {
1829
fn from(command: &'a mut Command) -> Self {
19-
Self { command, delay_failure: false }
30+
Self { command, failure_behavior: None }
2031
}
2132
}

0 commit comments

Comments
 (0)