Skip to content

Remove format short command trait #143798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 4 additions & 25 deletions src/bootstrap/src/utils/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ pub struct CommandFingerprint {
cwd: Option<PathBuf>,
}

impl FormatShortCmd for CommandFingerprint {
fn format_short_cmd(&self) -> String {
impl CommandFingerprint {
/// Helper method to format both Command and BootstrapCommand as a short execution line,
/// without all the other details (e.g. environment variables).
pub fn format_short_cmd(&self) -> String {
let program = Path::new(&self.program);
let mut line = vec![program.file_name().unwrap().to_str().unwrap().to_owned()];
line.extend(self.args.iter().map(|arg| arg.to_string_lossy().into_owned()));
Expand Down Expand Up @@ -545,29 +547,6 @@ 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).
pub trait FormatShortCmd {
fn format_short_cmd(&self) -> String;
}

#[cfg(feature = "tracing")]
impl FormatShortCmd for BootstrapCommand {
fn format_short_cmd(&self) -> String {
self.command.format_short_cmd()
}
}

#[cfg(feature = "tracing")]
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().map(|arg| arg.to_str().unwrap()));
line.join(" ")
}
}

#[derive(Clone, Default)]
pub struct ExecutionContext {
dry_run: DryRun,
Expand Down
4 changes: 1 addition & 3 deletions src/bootstrap/src/utils/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ macro_rules! error {
macro_rules! trace_cmd {
($cmd:expr) => {
{
use $crate::utils::exec::FormatShortCmd;

::tracing::span!(
target: "COMMAND",
::tracing::Level::TRACE,
"executing command",
cmd = $cmd.format_short_cmd(),
cmd = $cmd.fingerprint().format_short_cmd(),
full_cmd = ?$cmd
).entered()
}
Expand Down
Loading