From b153a0182875b420bdecb19c81be0731e2e2f6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 11 Oct 2023 19:02:00 +0200 Subject: [PATCH] Simplify BehaviorOnFailure --- src/bootstrap/src/lib.rs | 19 +++++++++---------- src/bootstrap/src/utils/exec.rs | 12 ++++++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 6f9a9beb3316..701c8df11a72 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -997,19 +997,18 @@ impl Build { match result { Ok(_) => true, Err(_) => { - if let Some(failure_behavior) = command.failure_behavior { - match failure_behavior { - BehaviorOnFailure::DelayFail => { - let mut failures = self.delayed_failures.borrow_mut(); - failures.push(format!("{command:?}")); - } - BehaviorOnFailure::Exit => { + match command.failure_behavior { + BehaviorOnFailure::DelayFail => { + if self.fail_fast { exit!(1); } + + let mut failures = self.delayed_failures.borrow_mut(); + failures.push(format!("{command:?}")); + } + BehaviorOnFailure::Exit => { + exit!(1); } - } - if self.fail_fast { - exit!(1); } false } diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index f244f5152beb..1b9e5cb174a0 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -25,16 +25,16 @@ pub enum OutputMode { #[derive(Debug)] pub struct BootstrapCommand<'a> { pub command: &'a mut Command, - pub failure_behavior: Option, + pub failure_behavior: BehaviorOnFailure, pub output_mode: OutputMode, } impl<'a> BootstrapCommand<'a> { pub fn delay_failure(self) -> Self { - Self { failure_behavior: Some(BehaviorOnFailure::DelayFail), ..self } + Self { failure_behavior: BehaviorOnFailure::DelayFail, ..self } } pub fn fail_fast(self) -> Self { - Self { failure_behavior: Some(BehaviorOnFailure::Exit), ..self } + Self { failure_behavior: BehaviorOnFailure::Exit, ..self } } pub fn output_mode(self, output_mode: OutputMode) -> Self { Self { output_mode, ..self } @@ -43,6 +43,10 @@ impl<'a> BootstrapCommand<'a> { impl<'a> From<&'a mut Command> for BootstrapCommand<'a> { fn from(command: &'a mut Command) -> Self { - Self { command, failure_behavior: None, output_mode: OutputMode::SuppressOnSuccess } + Self { + command, + failure_behavior: BehaviorOnFailure::Exit, + output_mode: OutputMode::SuppressOnSuccess, + } } }