diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index a71c641fa..0e44fed51 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -42,8 +42,14 @@ async fn main() -> MainResult { ..TracingOptions::default() }); + let mut args = env::args_os().collect::>(); + debug!( - args = ?env::args().collect::>(), + bin = ?args.remove(0), + args = ?args, + shim = env::var("PROTO_SHIM_NAME").ok(), + shim_bin = env::var("PROTO_SHIM_PATH").ok(), + pid = std::process::id(), "Running proto v{}", env!("CARGO_PKG_VERSION") ); diff --git a/crates/cli/src/main_shim.rs b/crates/cli/src/main_shim.rs index 8fa993565..eee9b5997 100644 --- a/crates/cli/src/main_shim.rs +++ b/crates/cli/src/main_shim.rs @@ -1,11 +1,9 @@ // NOTE: We want to keep the shim binary as lean as possible, -// so these imports use std as much as possible, and should -// not pull in large libraries (tracing is already enough)! +// so these imports primarily use std, and avoid fat crates. use anyhow::{anyhow, Result}; use proto_shim::{exec_command_and_replace, locate_proto_exe}; use rust_json::{json_parse, JsonElem as Json}; -use starbase::tracing::{self, trace, TracingOptions}; use std::collections::HashMap; use std::ffi::OsString; use std::path::PathBuf; @@ -71,17 +69,9 @@ fn create_command(args: Vec, shim_name: &str) -> Result { } } - // Find an applicable proto binary to run with - let proto_bin = locate_proto_exe("proto"); - - if let Some(bin) = proto_bin.as_deref() { - trace!(shim = shim_name, proto_bin = ?bin, "Using a located proto binary"); - } else { - trace!(shim = shim_name, "Assuming proto binary is on PATH"); - } - // Create the command and handle alternate logic - let mut command = Command::new(proto_bin.unwrap_or_else(|| "proto".into())); + let mut command = Command::new(locate_proto_exe("proto").unwrap_or_else(|| "proto".into())); + // command.args(["run", "node", "--"]); // command.arg("./docs/shim-test.mjs"); // command.arg("--version"); @@ -115,43 +105,27 @@ fn create_command(args: Vec, shim_name: &str) -> Result { pub fn main() -> Result<()> { sigpipe::reset(); - // Setup tracing and pass log level down - let log_level = env::var("PROTO_LOG").unwrap_or_else(|_| "info".into()); - - tracing::setup_tracing(TracingOptions { - filter_modules: vec!["proto".into()], - intercept_log: env::var("PROTO_WASM_LOG").is_err(), - log_env: "PROTO_LOG".into(), - ..TracingOptions::default() - }); - // Extract arguments to pass-through let args = env::args_os().collect::>(); let exe_path = env::current_exe().unwrap_or_else(|_| PathBuf::from(&args[0])); + // Extract the tool from the shim's file name let shim_name = exe_path .file_name() - .map(|file| String::from_utf8_lossy(file.as_encoded_bytes())) + .map(|file| file.to_string_lossy()) .unwrap_or_default() .replace(".exe", ""); - trace!(shim = &shim_name, shim_bin = ?exe_path, args = ?args, "Running {} shim", shim_name); - if shim_name.is_empty() || shim_name.contains("proto-shim") { return Err(anyhow!( "Invalid shim name detected. Unable to execute the appropriate proto tool.\nPlease refer to the documentation or ask for support on Discord." )); } - // Create and spawn the command + // Create and execute the command let mut command = create_command(args, &shim_name)?; - command.env("PROTO_LOG", log_level); - - trace!( - shim = &shim_name, - pid = std::process::id(), - "Spawning proto process" - ); + command.env("PROTO_SHIM_NAME", shim_name); + command.env("PROTO_SHIM_PATH", exe_path); // Must be the last line! Ok(exec_command_and_replace(command)?) diff --git a/crates/core/src/tool.rs b/crates/core/src/tool.rs index 1c0a6defe..ca4d1e674 100644 --- a/crates/core/src/tool.rs +++ b/crates/core/src/tool.rs @@ -1203,20 +1203,19 @@ impl Tool { let mut locations = vec![]; let mut add = |name: &str, config: ExecutableConfig, primary: bool| { - if !config.no_bin { - if config + if !config.no_bin + && config .exe_link_path .as_ref() .or(config.exe_path.as_ref()) .is_some() - { - locations.push(ExecutableLocation { - path: self.proto.bin_dir.join(get_exe_file_name(name)), - name: name.to_owned(), - config, - primary, - }); - } + { + locations.push(ExecutableLocation { + path: self.proto.bin_dir.join(get_exe_file_name(name)), + name: name.to_owned(), + config, + primary, + }); } };