Skip to content

Commit 3bb226f

Browse files
committed
Simplify BehaviorOnFailure
1 parent 57689f7 commit 3bb226f

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/bootstrap/exec.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ pub enum OutputMode {
2525
#[derive(Debug)]
2626
pub struct BootstrapCommand<'a> {
2727
pub command: &'a mut Command,
28-
pub failure_behavior: Option<BehaviorOnFailure>,
28+
pub failure_behavior: BehaviorOnFailure,
2929
pub output_mode: OutputMode,
3030
}
3131

3232
impl<'a> BootstrapCommand<'a> {
3333
pub fn delay_failure(self) -> Self {
34-
Self { failure_behavior: Some(BehaviorOnFailure::DelayFail), ..self }
34+
Self { failure_behavior: BehaviorOnFailure::DelayFail, ..self }
3535
}
3636
pub fn fail_fast(self) -> Self {
37-
Self { failure_behavior: Some(BehaviorOnFailure::Exit), ..self }
37+
Self { failure_behavior: BehaviorOnFailure::Exit, ..self }
3838
}
3939
pub fn output_mode(self, output_mode: OutputMode) -> Self {
4040
Self { output_mode, ..self }
@@ -43,6 +43,10 @@ impl<'a> BootstrapCommand<'a> {
4343

4444
impl<'a> From<&'a mut Command> for BootstrapCommand<'a> {
4545
fn from(command: &'a mut Command) -> Self {
46-
Self { command, failure_behavior: None, output_mode: OutputMode::SuppressOnSuccess }
46+
Self {
47+
command,
48+
failure_behavior: BehaviorOnFailure::Exit,
49+
output_mode: OutputMode::SuppressOnSuccess,
50+
}
4751
}
4852
}

src/bootstrap/lib.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1044,19 +1044,18 @@ impl Build {
10441044
match result {
10451045
Ok(_) => true,
10461046
Err(_) => {
1047-
if let Some(failure_behavior) = command.failure_behavior {
1048-
match failure_behavior {
1049-
BehaviorOnFailure::DelayFail => {
1050-
let mut failures = self.delayed_failures.borrow_mut();
1051-
failures.push(format!("{command:?}"));
1052-
}
1053-
BehaviorOnFailure::Exit => {
1047+
match command.failure_behavior {
1048+
BehaviorOnFailure::DelayFail => {
1049+
if self.fail_fast {
10541050
exit!(1);
10551051
}
1052+
1053+
let mut failures = self.delayed_failures.borrow_mut();
1054+
failures.push(format!("{command:?}"));
1055+
}
1056+
BehaviorOnFailure::Exit => {
1057+
exit!(1);
10561058
}
1057-
}
1058-
if self.fail_fast {
1059-
exit!(1);
10601059
}
10611060
false
10621061
}

0 commit comments

Comments
 (0)