From 3b7605043e74c0841c0a069e0b3af7d952f611b3 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Fri, 6 Sep 2024 13:33:49 -0700 Subject: [PATCH] Support emitting debug logs in rules_rust process wrapper. --- util/process_wrapper/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/util/process_wrapper/main.rs b/util/process_wrapper/main.rs index 85673dd8dd..7b75a61eca 100644 --- a/util/process_wrapper/main.rs +++ b/util/process_wrapper/main.rs @@ -61,10 +61,19 @@ impl fmt::Display for ProcessWrapperError { impl std::error::Error for ProcessWrapperError {} +macro_rules! log { + ($($arg:tt)*) => { + if std::env::var("RULES_RUST_PROCESS_WRAPPER_DEBUG").is_ok() { + eprintln!($($arg)*); + } + }; +} + fn main() -> Result<(), ProcessWrapperError> { let opts = options().map_err(|e| ProcessWrapperError(e.to_string()))?; - let mut child = Command::new(opts.executable) + let mut command = Command::new(opts.executable); + command .args(opts.child_arguments) .env_clear() .envs(opts.child_environment) @@ -79,7 +88,9 @@ fn main() -> Result<(), ProcessWrapperError> { } else { Stdio::inherit() }) - .stderr(Stdio::piped()) + .stderr(Stdio::piped()); + log!("Command: {:#?}", command); + let mut child = command .spawn() .map_err(|e| ProcessWrapperError(format!("failed to spawn child process: {}", e)))?;