From 24bc5b597632021135a13b00ae09181c63bdeb6f Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 24 May 2024 06:56:09 -0700 Subject: [PATCH 1/4] Repair criticalup run in Windows --- crates/criticalup-cli/src/binary_proxies.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/criticalup-cli/src/binary_proxies.rs b/crates/criticalup-cli/src/binary_proxies.rs index 8cceba6..14992f6 100644 --- a/crates/criticalup-cli/src/binary_proxies.rs +++ b/crates/criticalup-cli/src/binary_proxies.rs @@ -12,6 +12,13 @@ use std::process::{Command, Stdio}; pub(crate) fn proxy(whitelabel: WhitelabelConfig) -> Result<(), Error> { let binary_name = arg0(&whitelabel)?; + let mut binary_path = PathBuf::from(&binary_name); + // On Windows, we assume executables will *always* have `.exe` + // `cargo.exe` does not invoke `rustc.exe` though, it invokes + // `rustc` + #[cfg(windows)] + binary_path.set_extension("exe"); + let args: Vec<_> = std::env::args_os().skip(1).collect(); let config = Config::detect(whitelabel)?; @@ -31,7 +38,7 @@ pub(crate) fn proxy(whitelabel: WhitelabelConfig) -> Result<(), Error> { .map(|p| p.installation_id()) .filter_map(|id| { state - .resolve_binary_proxy(&id, PathBuf::from(&binary_name)) + .resolve_binary_proxy(&id, &binary_path) .map(|p| (id, p)) }) .next() From 1549715b462064c3df2af36e9440f581f2813d47 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 24 May 2024 07:23:59 -0700 Subject: [PATCH 2/4] Fix a warning --- crates/criticalup-cli/src/binary_proxies.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/criticalup-cli/src/binary_proxies.rs b/crates/criticalup-cli/src/binary_proxies.rs index 14992f6..c48e0e6 100644 --- a/crates/criticalup-cli/src/binary_proxies.rs +++ b/crates/criticalup-cli/src/binary_proxies.rs @@ -12,12 +12,19 @@ use std::process::{Command, Stdio}; pub(crate) fn proxy(whitelabel: WhitelabelConfig) -> Result<(), Error> { let binary_name = arg0(&whitelabel)?; - let mut binary_path = PathBuf::from(&binary_name); - // On Windows, we assume executables will *always* have `.exe` - // `cargo.exe` does not invoke `rustc.exe` though, it invokes - // `rustc` + + #[cfg(not(windows))] + let binary_path = PathBuf::from(&binary_name); #[cfg(windows)] - binary_path.set_extension("exe"); + let binary_path = { + let mut binary_path = PathBuf::from(&binary_name); + // On Windows, we assume executables will *always* have `.exe` + // `cargo.exe` does not invoke `rustc.exe` though, it invokes + // `rustc` + #[cfg(windows)] + binary_path.set_extension("exe"); + binary_path + }; let args: Vec<_> = std::env::args_os().skip(1).collect(); From a68d4a010c06a1984bbad3964dc3002086422064 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 24 May 2024 07:30:22 -0700 Subject: [PATCH 3/4] Handle windows specific test issue --- crates/criticalup-cli/tests/cli/binary_proxies.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/criticalup-cli/tests/cli/binary_proxies.rs b/crates/criticalup-cli/tests/cli/binary_proxies.rs index 03a7fdc..262ed51 100644 --- a/crates/criticalup-cli/tests/cli/binary_proxies.rs +++ b/crates/criticalup-cli/tests/cli/binary_proxies.rs @@ -4,7 +4,7 @@ use crate::assert_output; use crate::utils::TestEnvironment; use std::io::Write; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use tempfile::tempdir; @@ -51,6 +51,11 @@ fn invoking_inside_of_installed_project() { ) .unwrap(); + #[cfg(not(windows))] + let executable_name = "sample"; + #[cfg(windows)] + let executable_name = "sample.exe"; + // Create a sample state file referencing the binary proxy. std::fs::write( test_env.root().join("state.json"), @@ -60,7 +65,7 @@ fn invoking_inside_of_installed_project() { INSTALLATION_ID: { "manifests": ["/path/to/manifest/a", "/path/to/manifest/b"], "binary_proxies": { - "sample": "bin/sample", + executable_name: PathBuf::from("bin").join(executable_name), }, }, }, @@ -77,7 +82,7 @@ fn invoking_inside_of_installed_project() { .join("toolchains") .join(INSTALLATION_ID) .join("bin") - .join("sample"), + .join(executable_name), r#"fn main() { println!("proxies work!"); }"#, ); From 5d12de12c5515e69c835503b33f6f1da6a26ad6c Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 24 May 2024 07:56:28 -0700 Subject: [PATCH 4/4] fmt --- crates/criticalup-cli/src/binary_proxies.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/criticalup-cli/src/binary_proxies.rs b/crates/criticalup-cli/src/binary_proxies.rs index c48e0e6..1fdc7ba 100644 --- a/crates/criticalup-cli/src/binary_proxies.rs +++ b/crates/criticalup-cli/src/binary_proxies.rs @@ -12,7 +12,7 @@ use std::process::{Command, Stdio}; pub(crate) fn proxy(whitelabel: WhitelabelConfig) -> Result<(), Error> { let binary_name = arg0(&whitelabel)?; - + #[cfg(not(windows))] let binary_path = PathBuf::from(&binary_name); #[cfg(windows)]