diff options
| author | Jakub Beránek <berykubik@gmail.com> | 2024-06-22 10:53:35 +0200 |
|---|---|---|
| committer | Jakub Beránek <berykubik@gmail.com> | 2024-06-28 12:42:52 +0200 |
| commit | 3722fb5d9f32ffaabf01b05b9af3500702edfb23 (patch) | |
| tree | b4a1568635c6ae4d6a25a700f8987e1353324b85 | |
| parent | 31911e5ccf0bc364c267cb1d99f1fe06efc04009 (diff) | |
| download | rust-3722fb5d9f32ffaabf01b05b9af3500702edfb23.tar.gz rust-3722fb5d9f32ffaabf01b05b9af3500702edfb23.zip | |
Store `Command` directly inside `BootstrapCommand`
This will make it easier to migrate existing commands to bootstrap command.
| -rw-r--r-- | src/bootstrap/src/lib.rs | 4 | ||||
| -rw-r--r-- | src/bootstrap/src/utils/exec.rs | 33 |
2 files changed, 31 insertions, 6 deletions
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index fdf5f48771a..cee6b344902 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -960,12 +960,12 @@ impl Build { /// Execute a command and return its output. /// This method should be used for all command executions in bootstrap. - fn run<'a, C: Into<BootstrapCommand<'a>>>(&self, command: C) -> CommandOutput { + fn run<C: Into<BootstrapCommand>>(&self, command: C) -> CommandOutput { if self.config.dry_run() { return CommandOutput::default(); } - let command = command.into(); + let mut command = command.into(); self.verbose(|| println!("running: {command:?}")); diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index 24659511614..024a80e6040 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -37,13 +37,13 @@ pub enum OutputMode { /// [allow_failure]: BootstrapCommand::allow_failure /// [delay_failure]: BootstrapCommand::delay_failure #[derive(Debug)] -pub struct BootstrapCommand<'a> { - pub command: &'a mut Command, +pub struct BootstrapCommand { + pub command: Command, pub failure_behavior: BehaviorOnFailure, pub output_mode: Option<OutputMode>, } -impl<'a> BootstrapCommand<'a> { +impl BootstrapCommand { pub fn delay_failure(self) -> Self { Self { failure_behavior: BehaviorOnFailure::DelayFail, ..self } } @@ -66,8 +66,33 @@ impl<'a> BootstrapCommand<'a> { } } -impl<'a> From<&'a mut Command> for BootstrapCommand<'a> { +/// This implementation is temporary, until all `Command` invocations are migrated to +/// `BootstrapCommand`. +impl<'a> From<&'a mut Command> for BootstrapCommand { fn from(command: &'a mut Command) -> Self { + // This is essentially a manual `Command::clone` + let mut cmd = Command::new(command.get_program()); + if let Some(dir) = command.get_current_dir() { + cmd.current_dir(dir); + } + cmd.args(command.get_args()); + for (key, value) in command.get_envs() { + match value { + Some(value) => { + cmd.env(key, value); + } + None => { + cmd.env_remove(key); + } + } + } + + cmd.into() + } +} + +impl From<Command> for BootstrapCommand { + fn from(command: Command) -> Self { Self { command, failure_behavior: BehaviorOnFailure::Exit, output_mode: None } } } |
