Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d7eca8a

Browse files
committed
Trace execution of bootstrap commands
1 parent cfe9ffc commit d7eca8a

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::utils::exec::command;
3030
use crate::utils::helpers::{
3131
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
3232
};
33-
use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode};
33+
use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode, trace_cmd};
3434

3535
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3636
pub struct Std {
@@ -2234,6 +2234,9 @@ pub fn stream_cargo(
22342234
cb: &mut dyn FnMut(CargoMessage<'_>),
22352235
) -> bool {
22362236
let mut cmd = cargo.into_cmd();
2237+
2238+
let _run_span = trace_cmd!(cmd);
2239+
22372240
let cargo = cmd.as_command_mut();
22382241
// Instruct Cargo to give us json messages on stdout, critically leaving
22392242
// stderr as piped so we can get those pretty colors.

src/bootstrap/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ impl Build {
905905
return CommandOutput::default();
906906
}
907907

908+
let _run_span = trace_cmd!(command);
909+
908910
let created_at = command.get_created_location();
909911
let executed_at = std::panic::Location::caller();
910912

src/bootstrap/src/utils/exec.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,25 @@ impl Default for CommandOutput {
329329
}
330330
}
331331
}
332+
333+
/// Helper trait to format both Command and BootstrapCommand as a short execution line,
334+
/// without all the other details (e.g. environment variables).
335+
#[allow(unused)]
336+
pub trait FormatShortCmd {
337+
fn format_short_cmd(&self) -> String;
338+
}
339+
340+
impl FormatShortCmd for BootstrapCommand {
341+
fn format_short_cmd(&self) -> String {
342+
self.command.format_short_cmd()
343+
}
344+
}
345+
346+
impl FormatShortCmd for Command {
347+
fn format_short_cmd(&self) -> String {
348+
let program = Path::new(self.get_program());
349+
let mut line = vec![program.file_name().unwrap().to_str().unwrap()];
350+
line.extend(self.get_args().into_iter().map(|arg| arg.to_str().unwrap()));
351+
line.join(" ")
352+
}
353+
}

src/bootstrap/src/utils/helpers.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use std::{env, fs, io, str};
1313
use build_helper::util::fail;
1414
use object::read::archive::ArchiveFile;
1515

16-
use crate::LldMode;
1716
use crate::core::builder::Builder;
1817
use crate::core::config::{Config, TargetSelection};
1918
use crate::utils::exec::{BootstrapCommand, command};
2019
pub use crate::utils::shared_helpers::{dylib_path, dylib_path_var};
20+
use crate::{LldMode, trace_cmd};
2121

2222
#[cfg(test)]
2323
mod tests;
@@ -265,6 +265,8 @@ pub fn make(host: &str) -> PathBuf {
265265

266266
#[track_caller]
267267
pub fn output(cmd: &mut Command) -> String {
268+
let _run_span = trace_cmd!(cmd);
269+
268270
let output = match cmd.stderr(Stdio::inherit()).output() {
269271
Ok(status) => status,
270272
Err(e) => fail(&format!("failed to execute command: {cmd:?}\nERROR: {e}")),

src/bootstrap/src/utils/tracing.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,22 @@ macro_rules! error {
4747
::tracing::error!($($tokens)*)
4848
}
4949
}
50+
51+
#[macro_export]
52+
macro_rules! trace_cmd {
53+
($cmd:expr) => {
54+
{
55+
#[allow(unused)]
56+
use $crate::utils::exec::FormatShortCmd;
57+
58+
#[cfg(feature = "tracing")]
59+
::tracing::span!(
60+
target: "COMMAND",
61+
::tracing::Level::TRACE,
62+
"executing command",
63+
cmd = $cmd.format_short_cmd(),
64+
full_cmd = ?$cmd
65+
).entered()
66+
}
67+
};
68+
}

0 commit comments

Comments
 (0)