Skip to content
Merged
14 changes: 8 additions & 6 deletions src/bootstrap/src/utils/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
//!
//! This module provides a structured way to execute and manage commands efficiently,
//! ensuring controlled failure handling and output management.
#![allow(warnings)]
use std::ffi::OsStr;
use std::fmt::{Debug, Formatter};
use std::path::Path;
use std::process::{Child, Command, CommandArgs, CommandEnvs, ExitStatus, Output, Stdio};
use std::process::{Command, CommandArgs, CommandEnvs, ExitStatus, Output, Stdio};

use build_helper::ci::CiEnv;
use build_helper::drop_bomb::DropBomb;
Expand Down Expand Up @@ -73,7 +72,7 @@ pub struct BootstrapCommand {
drop_bomb: DropBomb,
}

impl BootstrapCommand {
impl<'a> BootstrapCommand {
#[track_caller]
pub fn new<S: AsRef<OsStr>>(program: S) -> Self {
Command::new(program).into()
Expand Down Expand Up @@ -160,16 +159,19 @@ impl BootstrapCommand {

/// Spawn the command in background, while capturing and returning all its output.
#[track_caller]
pub fn start_capture(&mut self, exec_ctx: impl AsRef<ExecutionContext>) -> DeferredCommand {
pub fn start_capture(
&'a mut self,
exec_ctx: impl AsRef<ExecutionContext>,
) -> DeferredCommand<'a> {
exec_ctx.as_ref().start(self, OutputMode::Capture, OutputMode::Capture)
}

/// Spawn the command in background, while capturing and returning stdout, and printing stderr.
#[track_caller]
pub fn start_capture_stdout(
&mut self,
&'a mut self,
exec_ctx: impl AsRef<ExecutionContext>,
) -> DeferredCommand {
) -> DeferredCommand<'a> {
exec_ctx.as_ref().start(self, OutputMode::Capture, OutputMode::Print)
}

Expand Down
10 changes: 5 additions & 5 deletions src/bootstrap/src/utils/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl ExecutionContext {
let executed_at = std::panic::Location::caller();

if self.dry_run() && !command.run_always {
return DeferredCommand { process: None, stdout, stderr, command, created_at };
return DeferredCommand { process: None, stdout, stderr, command, executed_at };
}

#[cfg(feature = "tracing")]
Expand All @@ -110,7 +110,7 @@ impl ExecutionContext {

let child = cmd.spawn().unwrap();

DeferredCommand { process: Some(child), stdout, stderr, command, created_at }
DeferredCommand { process: Some(child), stdout, stderr, command, executed_at }
}

/// Execute a command and return its output.
Expand Down Expand Up @@ -161,7 +161,7 @@ pub struct DeferredCommand<'a> {
command: &'a mut BootstrapCommand,
stdout: OutputMode,
stderr: OutputMode,
created_at: Location<'a>,
executed_at: &'a Location<'a>,
}

impl<'a> DeferredCommand<'a> {
Expand All @@ -174,8 +174,8 @@ impl<'a> DeferredCommand<'a> {

let output = self.process.take().unwrap().wait_with_output();

let created_at = self.created_at;
let executed_at = std::panic::Location::caller();
let created_at = self.command.get_created_location();
let executed_at = self.executed_at;

use std::fmt::Write;

Expand Down
Loading