diff options
| author | Jakub Beránek <berykubik@gmail.com> | 2023-10-09 23:04:11 +0200 |
|---|---|---|
| committer | Jakub Beránek <berykubik@gmail.com> | 2023-10-17 21:38:38 +0200 |
| commit | a69edc68aa224891a7e54d8ced094ffc28c4be3c (patch) | |
| tree | 73806e6b9435b62f838fa90f91a5fbbb9a852607 | |
| parent | bb74d1fa858852547bd8badaeeb0aed10e006c94 (diff) | |
| download | rust-a69edc68aa224891a7e54d8ced094ffc28c4be3c.tar.gz rust-a69edc68aa224891a7e54d8ced094ffc28c4be3c.zip | |
Add BootstrapCommand and `run_cmd`
| -rw-r--r-- | src/bootstrap/src/lib.rs | 34 | ||||
| -rw-r--r-- | src/bootstrap/src/utils/exec.rs | 21 | ||||
| -rw-r--r-- | src/bootstrap/src/utils/mod.rs | 1 |
3 files changed, 47 insertions, 9 deletions
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 97c743074af..b20c20a360b 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -39,6 +39,7 @@ use crate::core::config::flags; use crate::core::config::{DryRun, Target}; use crate::core::config::{LlvmLibunwind, TargetSelection}; use crate::utils::cache::{Interned, INTERNER}; +use crate::utils::exec::BootstrapCommand; use crate::utils::helpers::{ self, dir_is_empty, exe, libdir, mtime, output, run, run_suppressed, symlink_dir, try_run_suppressed, @@ -959,17 +960,32 @@ impl Build { /// Runs a command, printing out contextual info if it fails, and delaying errors until the build finishes. pub(crate) fn run_delaying_failure(&self, cmd: &mut Command) -> bool { - if !self.fail_fast { - #[allow(deprecated)] // can't use Build::try_run, that's us - if self.config.try_run(cmd).is_err() { - let mut failures = self.delayed_failures.borrow_mut(); - failures.push(format!("{cmd:?}")); - return false; + let cmd: BootstrapCommand<'_> = cmd.into(); + self.run_cmd(cmd.delay_failure()) + } + + /// A centralized function for running commands that do not return output. + pub(crate) fn run_cmd<'a, C: Into<BootstrapCommand<'a>>>(&self, cmd: C) -> bool { + let command = cmd.into(); + self.verbose(&format!("running: {command:?}")); + + #[allow(deprecated)] // can't use Build::try_run, that's us + let result = self.config.try_run(command.command); + + match result { + Ok(_) => true, + Err(_) => { + if command.delay_failure { + let mut failures = self.delayed_failures.borrow_mut(); + failures.push(format!("{command:?}")); + return false; + } + if self.fail_fast { + exit!(1); + } + false } - } else { - self.run(cmd); } - true } pub fn is_verbose_than(&self, level: usize) -> bool { diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs new file mode 100644 index 00000000000..a590171984e --- /dev/null +++ b/src/bootstrap/src/utils/exec.rs @@ -0,0 +1,21 @@ +use std::process::Command; + +/// Wrapper around `std::process::Command`. +#[derive(Debug)] +pub struct BootstrapCommand<'a> { + pub command: &'a mut Command, + /// Report failure later instead of immediately. + pub delay_failure: bool, +} + +impl<'a> BootstrapCommand<'a> { + pub fn delay_failure(self) -> Self { + Self { delay_failure: true, ..self } + } +} + +impl<'a> From<&'a mut Command> for BootstrapCommand<'a> { + fn from(command: &'a mut Command) -> Self { + Self { command, delay_failure: false } + } +} diff --git a/src/bootstrap/src/utils/mod.rs b/src/bootstrap/src/utils/mod.rs index 7dcb6a82862..8ca22d00865 100644 --- a/src/bootstrap/src/utils/mod.rs +++ b/src/bootstrap/src/utils/mod.rs @@ -6,6 +6,7 @@ pub(crate) mod cache; pub(crate) mod cc_detect; pub(crate) mod channel; pub(crate) mod dylib; +pub(crate) mod exec; pub(crate) mod helpers; pub(crate) mod job; #[cfg(feature = "build-metrics")] |
