diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index 85a19ebe3688..eb9802bf2e1b 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -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; @@ -73,7 +72,7 @@ pub struct BootstrapCommand { drop_bomb: DropBomb, } -impl BootstrapCommand { +impl<'a> BootstrapCommand { #[track_caller] pub fn new>(program: S) -> Self { Command::new(program).into() @@ -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) -> DeferredCommand { + pub fn start_capture( + &'a mut self, + exec_ctx: impl AsRef, + ) -> 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, - ) -> DeferredCommand { + ) -> DeferredCommand<'a> { exec_ctx.as_ref().start(self, OutputMode::Capture, OutputMode::Print) } diff --git a/src/bootstrap/src/utils/execution_context.rs b/src/bootstrap/src/utils/execution_context.rs index 5417307e54f8..a1b6ff94ca74 100644 --- a/src/bootstrap/src/utils/execution_context.rs +++ b/src/bootstrap/src/utils/execution_context.rs @@ -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")] @@ -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. @@ -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> { @@ -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;