Skip to content

Commit

Permalink
Merge #17
Browse files Browse the repository at this point in the history
17: Repair criticalup run in Windows r=pietroalbini a=Hoverbear

`cargo run` does not invoke `rustc.exe`, it invokes `rustc`. 😅 

Co-authored-by: Ana Hobden <[email protected]>
  • Loading branch information
bors-ferrocene[bot] and Hoverbear committed May 24, 2024
2 parents 5887032 + 5d12de1 commit a49bf02
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
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

0 comments on commit a49bf02

Please sign in to comment.