Skip to content

Commit 576f422

Browse files
committed
Remove delayed_failures from build and add respective utility methods in execution context for delayed_failures
1 parent 8b9bd93 commit 576f422

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

src/bootstrap/src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ pub struct Build {
196196
crates: HashMap<String, Crate>,
197197
crate_paths: HashMap<PathBuf, String>,
198198
is_sudo: bool,
199-
delayed_failures: RefCell<Vec<String>>,
200199
prerelease_version: Cell<Option<u32>>,
201200

202201
#[cfg(feature = "build-metrics")]
@@ -457,9 +456,7 @@ impl Build {
457456
crates: HashMap::new(),
458457
crate_paths: HashMap::new(),
459458
is_sudo,
460-
delayed_failures: RefCell::new(Vec::new()),
461459
prerelease_version: Cell::new(None),
462-
463460
#[cfg(feature = "build-metrics")]
464461
metrics: crate::utils::metrics::BuildMetrics::init(),
465462
};
@@ -698,14 +695,7 @@ impl Build {
698695
debug!("checking for postponed test failures from `test --no-fail-fast`");
699696

700697
// Check for postponed failures from `test --no-fail-fast`.
701-
let failures = self.delayed_failures.borrow();
702-
if !failures.is_empty() {
703-
eprintln!("\n{} command(s) did not execute successfully:\n", failures.len());
704-
for failure in failures.iter() {
705-
eprintln!(" - {failure}\n");
706-
}
707-
exit!(1);
708-
}
698+
self.config.exec_ctx().report_failures_and_exit();
709699

710700
#[cfg(feature = "build-metrics")]
711701
self.metrics.persist(self);

src/bootstrap/src/utils/execution_context.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct ExecutionContext {
1414
dry_run: DryRun,
1515
verbose: u8,
1616
pub fail_fast: bool,
17-
pub delayed_failures: Arc<Mutex<Vec<String>>>,
17+
delayed_failures: Arc<Mutex<Vec<String>>>,
1818
}
1919

2020
impl ExecutionContext {
@@ -55,6 +55,22 @@ impl ExecutionContext {
5555
self.fail_fast = value;
5656
}
5757

58+
pub fn add_to_delay_failure(&self, message: String) {
59+
self.delayed_failures.lock().unwrap().push(message);
60+
}
61+
62+
pub fn report_failures_and_exit(&self) {
63+
let failures = self.delayed_failures.lock().unwrap();
64+
if failures.is_empty() {
65+
return;
66+
}
67+
eprintln!("\n{} command(s) did not execute successfully:\n", failures.len());
68+
for failure in &*failures {
69+
eprintln!(" - {failure}");
70+
}
71+
exit!(1);
72+
}
73+
5874
/// Execute a command and return its output.
5975
/// Note: Ideally, you should use one of the BootstrapCommand::run* functions to
6076
/// execute commands. They internally call this method.
@@ -166,8 +182,7 @@ Executed at: {executed_at}"#,
166182
fail(&message, output);
167183
}
168184

169-
let mut failures = self.delayed_failures.lock().unwrap();
170-
failures.push(message);
185+
self.add_to_delay_failure(message);
171186
}
172187
BehaviorOnFailure::Exit => {
173188
fail(&message, output);

src/bootstrap/src/utils/render_tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ pub(crate) fn try_run_tests(
4343
if builder.fail_fast {
4444
crate::exit!(1);
4545
} else {
46-
let mut failures = builder.delayed_failures.borrow_mut();
47-
failures.push(format!("{cmd:?}"));
46+
builder.config.exec_ctx().add_to_delay_failure(format!("{cmd:?}"));
4847
false
4948
}
5049
} else {

0 commit comments

Comments
 (0)