Skip to content

Commit 59cb00f

Browse files
committed
add caching fields inside Bootstrap command
1 parent e61dd43 commit 59cb00f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/bootstrap/src/utils/exec.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
//!
33
//! This module provides a structured way to execute and manage commands efficiently,
44
//! ensuring controlled failure handling and output management.
5+
#![allow(warnings)]
6+
7+
use std::collections::HashMap;
58
use std::ffi::OsStr;
69
use std::fmt::{Debug, Formatter};
10+
use std::hash::{Hash, Hasher};
711
use std::path::Path;
812
use std::process::{Command, CommandArgs, CommandEnvs, ExitStatus, Output, Stdio};
13+
use std::sync::Mutex;
914

1015
use build_helper::ci::CiEnv;
1116
use build_helper::drop_bomb::DropBomb;
1217

1318
use super::execution_context::{DeferredCommand, ExecutionContext};
19+
use crate::PathBuf;
1420

1521
/// What should be done when the command fails.
1622
#[derive(Debug, Copy, Clone)]
@@ -63,6 +69,11 @@ impl OutputMode {
6369
/// [allow_failure]: BootstrapCommand::allow_failure
6470
/// [delay_failure]: BootstrapCommand::delay_failure
6571
pub struct BootstrapCommand {
72+
program: String,
73+
args: Vec<String>,
74+
envs: Vec<(String, String)>,
75+
cwd: Option<PathBuf>,
76+
6677
command: Command,
6778
pub failure_behavior: BehaviorOnFailure,
6879
// Run the command even during dry run
@@ -79,6 +90,8 @@ impl<'a> BootstrapCommand {
7990
}
8091

8192
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
93+
let arg_str = arg.as_ref().to_string_lossy().into_owned();
94+
self.args.push(arg_str.clone());
8295
self.command.arg(arg.as_ref());
8396
self
8497
}
@@ -88,7 +101,9 @@ impl<'a> BootstrapCommand {
88101
I: IntoIterator<Item = S>,
89102
S: AsRef<OsStr>,
90103
{
91-
self.command.args(args);
104+
args.into_iter().for_each(|arg| {
105+
self.arg(arg);
106+
});
92107
self
93108
}
94109

@@ -97,6 +112,9 @@ impl<'a> BootstrapCommand {
97112
K: AsRef<OsStr>,
98113
V: AsRef<OsStr>,
99114
{
115+
let key_str = key.as_ref().to_string_lossy().into_owned();
116+
let val_str = val.as_ref().to_string_lossy().into_owned();
117+
self.envs.push((key_str.clone(), val_str.clone()));
100118
self.command.env(key, val);
101119
self
102120
}
@@ -115,6 +133,7 @@ impl<'a> BootstrapCommand {
115133
}
116134

117135
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self {
136+
self.cwd = Some(dir.as_ref().to_path_buf());
118137
self.command.current_dir(dir);
119138
self
120139
}
@@ -226,6 +245,10 @@ impl From<Command> for BootstrapCommand {
226245
let program = command.get_program().to_owned();
227246

228247
Self {
248+
program: program.clone().into_string().unwrap(),
249+
args: Vec::new(),
250+
envs: Vec::new(),
251+
cwd: None,
229252
command,
230253
failure_behavior: BehaviorOnFailure::Exit,
231254
run_in_dry_run: false,
@@ -235,6 +258,7 @@ impl From<Command> for BootstrapCommand {
235258
}
236259

237260
/// Represents the current status of `BootstrapCommand`.
261+
#[derive(Clone, PartialEq)]
238262
enum CommandStatus {
239263
/// The command has started and finished with some status.
240264
Finished(ExitStatus),
@@ -251,6 +275,7 @@ pub fn command<S: AsRef<OsStr>>(program: S) -> BootstrapCommand {
251275
}
252276

253277
/// Represents the output of an executed process.
278+
#[derive(Clone, PartialEq)]
254279
pub struct CommandOutput {
255280
status: CommandStatus,
256281
stdout: Option<Vec<u8>>,

0 commit comments

Comments
 (0)