diff options
| -rw-r--r-- | src/bootstrap/src/utils/exec.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index a7b92441d74..28b8fc2734e 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -2,15 +2,21 @@ //! //! This module provides a structured way to execute and manage commands efficiently, //! ensuring controlled failure handling and output management. +#![allow(warnings)] + +use std::collections::HashMap; use std::ffi::OsStr; use std::fmt::{Debug, Formatter}; +use std::hash::{Hash, Hasher}; use std::path::Path; use std::process::{Command, CommandArgs, CommandEnvs, ExitStatus, Output, Stdio}; +use std::sync::Mutex; use build_helper::ci::CiEnv; use build_helper::drop_bomb::DropBomb; use super::execution_context::{DeferredCommand, ExecutionContext}; +use crate::PathBuf; /// What should be done when the command fails. #[derive(Debug, Copy, Clone)] @@ -63,6 +69,11 @@ impl OutputMode { /// [allow_failure]: BootstrapCommand::allow_failure /// [delay_failure]: BootstrapCommand::delay_failure pub struct BootstrapCommand { + program: String, + args: Vec<String>, + envs: Vec<(String, String)>, + cwd: Option<PathBuf>, + command: Command, pub failure_behavior: BehaviorOnFailure, // Run the command even during dry run @@ -79,6 +90,8 @@ impl<'a> BootstrapCommand { } pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self { + let arg_str = arg.as_ref().to_string_lossy().into_owned(); + self.args.push(arg_str.clone()); self.command.arg(arg.as_ref()); self } @@ -88,7 +101,9 @@ impl<'a> BootstrapCommand { I: IntoIterator<Item = S>, S: AsRef<OsStr>, { - self.command.args(args); + args.into_iter().for_each(|arg| { + self.arg(arg); + }); self } @@ -97,6 +112,9 @@ impl<'a> BootstrapCommand { K: AsRef<OsStr>, V: AsRef<OsStr>, { + let key_str = key.as_ref().to_string_lossy().into_owned(); + let val_str = val.as_ref().to_string_lossy().into_owned(); + self.envs.push((key_str.clone(), val_str.clone())); self.command.env(key, val); self } @@ -115,6 +133,7 @@ impl<'a> BootstrapCommand { } pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self { + self.cwd = Some(dir.as_ref().to_path_buf()); self.command.current_dir(dir); self } @@ -226,6 +245,10 @@ impl From<Command> for BootstrapCommand { let program = command.get_program().to_owned(); Self { + program: program.clone().into_string().unwrap(), + args: Vec::new(), + envs: Vec::new(), + cwd: None, command, failure_behavior: BehaviorOnFailure::Exit, run_in_dry_run: false, @@ -235,6 +258,7 @@ impl From<Command> for BootstrapCommand { } /// Represents the current status of `BootstrapCommand`. +#[derive(Clone, PartialEq)] enum CommandStatus { /// The command has started and finished with some status. Finished(ExitStatus), @@ -251,6 +275,7 @@ pub fn command<S: AsRef<OsStr>>(program: S) -> BootstrapCommand { } /// Represents the output of an executed process. +#[derive(Clone, PartialEq)] pub struct CommandOutput { status: CommandStatus, stdout: Option<Vec<u8>>, |
