Skip to content
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

Repair criticalup run in Windows #17

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 15 additions & 1 deletion crates/criticalup-cli/src/binary_proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ 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)]
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();

let config = Config::detect(whitelabel)?;
Expand All @@ -31,7 +45,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()
Expand Down
11 changes: 8 additions & 3 deletions crates/criticalup-cli/tests/cli/binary_proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"),
Expand All @@ -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),
},
},
},
Expand All @@ -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!"); }"#,
);

Expand Down
Loading