Trace execution of bootstrap commands
This commit is contained in:
parent
cfe9ffcd7c
commit
d7eca8ac15
5 changed files with 50 additions and 2 deletions
|
@ -30,7 +30,7 @@ use crate::utils::exec::command;
|
|||
use crate::utils::helpers::{
|
||||
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
|
||||
};
|
||||
use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode};
|
||||
use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode, trace_cmd};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Std {
|
||||
|
@ -2234,6 +2234,9 @@ pub fn stream_cargo(
|
|||
cb: &mut dyn FnMut(CargoMessage<'_>),
|
||||
) -> bool {
|
||||
let mut cmd = cargo.into_cmd();
|
||||
|
||||
let _run_span = trace_cmd!(cmd);
|
||||
|
||||
let cargo = cmd.as_command_mut();
|
||||
// Instruct Cargo to give us json messages on stdout, critically leaving
|
||||
// stderr as piped so we can get those pretty colors.
|
||||
|
|
|
@ -905,6 +905,8 @@ impl Build {
|
|||
return CommandOutput::default();
|
||||
}
|
||||
|
||||
let _run_span = trace_cmd!(command);
|
||||
|
||||
let created_at = command.get_created_location();
|
||||
let executed_at = std::panic::Location::caller();
|
||||
|
||||
|
|
|
@ -329,3 +329,25 @@ impl Default for CommandOutput {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper trait to format both Command and BootstrapCommand as a short execution line,
|
||||
/// without all the other details (e.g. environment variables).
|
||||
#[allow(unused)]
|
||||
pub trait FormatShortCmd {
|
||||
fn format_short_cmd(&self) -> String;
|
||||
}
|
||||
|
||||
impl FormatShortCmd for BootstrapCommand {
|
||||
fn format_short_cmd(&self) -> String {
|
||||
self.command.format_short_cmd()
|
||||
}
|
||||
}
|
||||
|
||||
impl FormatShortCmd for Command {
|
||||
fn format_short_cmd(&self) -> String {
|
||||
let program = Path::new(self.get_program());
|
||||
let mut line = vec![program.file_name().unwrap().to_str().unwrap()];
|
||||
line.extend(self.get_args().into_iter().map(|arg| arg.to_str().unwrap()));
|
||||
line.join(" ")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@ use std::{env, fs, io, str};
|
|||
use build_helper::util::fail;
|
||||
use object::read::archive::ArchiveFile;
|
||||
|
||||
use crate::LldMode;
|
||||
use crate::core::builder::Builder;
|
||||
use crate::core::config::{Config, TargetSelection};
|
||||
use crate::utils::exec::{BootstrapCommand, command};
|
||||
pub use crate::utils::shared_helpers::{dylib_path, dylib_path_var};
|
||||
use crate::{LldMode, trace_cmd};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
@ -265,6 +265,8 @@ pub fn make(host: &str) -> PathBuf {
|
|||
|
||||
#[track_caller]
|
||||
pub fn output(cmd: &mut Command) -> String {
|
||||
let _run_span = trace_cmd!(cmd);
|
||||
|
||||
let output = match cmd.stderr(Stdio::inherit()).output() {
|
||||
Ok(status) => status,
|
||||
Err(e) => fail(&format!("failed to execute command: {cmd:?}\nERROR: {e}")),
|
||||
|
|
|
@ -47,3 +47,22 @@ macro_rules! error {
|
|||
::tracing::error!($($tokens)*)
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! trace_cmd {
|
||||
($cmd:expr) => {
|
||||
{
|
||||
#[allow(unused)]
|
||||
use $crate::utils::exec::FormatShortCmd;
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
::tracing::span!(
|
||||
target: "COMMAND",
|
||||
::tracing::Level::TRACE,
|
||||
"executing command",
|
||||
cmd = $cmd.format_short_cmd(),
|
||||
full_cmd = ?$cmd
|
||||
).entered()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue