Skip to content

Commit c382434

Browse files
committed
Store Command directly inside BootstrapCommand
This will make it easier to migrate existing commands to bootstrap command.
1 parent a5f91ad commit c382434

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/bootstrap/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,12 +958,12 @@ impl Build {
958958

959959
/// Execute a command and return its output.
960960
/// This method should be used for all command executions in bootstrap.
961-
fn run<'a, C: Into<BootstrapCommand<'a>>>(&self, command: C) -> CommandOutput {
961+
fn run<C: Into<BootstrapCommand>>(&self, command: C) -> CommandOutput {
962962
if self.config.dry_run() {
963963
return CommandOutput::default();
964964
}
965965

966-
let command = command.into();
966+
let mut command = command.into();
967967

968968
self.verbose(|| println!("running: {command:?}"));
969969

src/bootstrap/src/utils/exec.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ pub enum OutputMode {
3737
/// [allow_failure]: BootstrapCommand::allow_failure
3838
/// [delay_failure]: BootstrapCommand::delay_failure
3939
#[derive(Debug)]
40-
pub struct BootstrapCommand<'a> {
41-
pub command: &'a mut Command,
40+
pub struct BootstrapCommand {
41+
pub command: Command,
4242
pub failure_behavior: BehaviorOnFailure,
4343
pub output_mode: Option<OutputMode>,
4444
}
4545

46-
impl<'a> BootstrapCommand<'a> {
46+
impl BootstrapCommand {
4747
pub fn delay_failure(self) -> Self {
4848
Self { failure_behavior: BehaviorOnFailure::DelayFail, ..self }
4949
}
@@ -66,8 +66,33 @@ impl<'a> BootstrapCommand<'a> {
6666
}
6767
}
6868

69-
impl<'a> From<&'a mut Command> for BootstrapCommand<'a> {
69+
/// This implementation is temporary, until all `Command` invocations are migrated to
70+
/// `BootstrapCommand`.
71+
impl<'a> From<&'a mut Command> for BootstrapCommand {
7072
fn from(command: &'a mut Command) -> Self {
73+
// This is essentially a manual `Command::clone`
74+
let mut cmd = Command::new(command.get_program());
75+
if let Some(dir) = command.get_current_dir() {
76+
cmd.current_dir(dir);
77+
}
78+
cmd.args(command.get_args());
79+
for (key, value) in command.get_envs() {
80+
match value {
81+
Some(value) => {
82+
cmd.env(key, value);
83+
}
84+
None => {
85+
cmd.env_remove(key);
86+
}
87+
}
88+
}
89+
90+
cmd.into()
91+
}
92+
}
93+
94+
impl From<Command> for BootstrapCommand {
95+
fn from(command: Command) -> Self {
7196
Self { command, failure_behavior: BehaviorOnFailure::Exit, output_mode: None }
7297
}
7398
}

0 commit comments

Comments
 (0)