Skip to content

Commit

Permalink
Simplify BehaviorOnFailure
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Oct 11, 2023
1 parent 57689f7 commit 3bb226f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src/bootstrap/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ pub enum OutputMode {
#[derive(Debug)]
pub struct BootstrapCommand<'a> {
pub command: &'a mut Command,
pub failure_behavior: Option<BehaviorOnFailure>,
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 }
Expand All @@ -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,
}
}
}
19 changes: 9 additions & 10 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,19 +1044,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
}
Expand Down

0 comments on commit 3bb226f

Please sign in to comment.