change to executed at
This commit is contained in:
parent
55e2c2681e
commit
186f588772
2 changed files with 13 additions and 11 deletions
|
|
@ -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<S: AsRef<OsStr>>(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<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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue