Skip to content

Commit b153a01

Browse files
committed
Simplify BehaviorOnFailure
1 parent 03d48dd commit b153a01

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/bootstrap/src/lib.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -997,19 +997,18 @@ impl Build {
997997
match result {
998998
Ok(_) => true,
999999
Err(_) => {
1000-
if let Some(failure_behavior) = command.failure_behavior {
1001-
match failure_behavior {
1002-
BehaviorOnFailure::DelayFail => {
1003-
let mut failures = self.delayed_failures.borrow_mut();
1004-
failures.push(format!("{command:?}"));
1005-
}
1006-
BehaviorOnFailure::Exit => {
1000+
match command.failure_behavior {
1001+
BehaviorOnFailure::DelayFail => {
1002+
if self.fail_fast {
10071003
exit!(1);
10081004
}
1005+
1006+
let mut failures = self.delayed_failures.borrow_mut();
1007+
failures.push(format!("{command:?}"));
1008+
}
1009+
BehaviorOnFailure::Exit => {
1010+
exit!(1);
10091011
}
1010-
}
1011-
if self.fail_fast {
1012-
exit!(1);
10131012
}
10141013
false
10151014
}

src/bootstrap/src/utils/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
}

0 commit comments

Comments
 (0)