Skip to content

Commit

Permalink
fix(core): make windows runtime input hashing windowless
Browse files Browse the repository at this point in the history
  • Loading branch information
axelstudios committed Mar 7, 2024
1 parent 46592d7 commit 120bc56
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions packages/nx/src/native/tasks/hashers/hash_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ use std::process::Command;
use std::sync::Arc;
use tracing::trace;

#[cfg(target_os = "windows")]
use std::os::windows::process::CommandExt;

// Windows API constant to prevent creating a window
#[cfg(target_os = "windows")]
const CREATE_NO_WINDOW: u32 = 0x08000000;

pub fn hash_runtime(
workspace_root: &str,
command: &str,
Expand All @@ -17,20 +24,7 @@ pub fn hash_runtime(
return Ok(cache_results.clone());
}

let mut command_builder = if cfg!(target_os = "windows") {
let comspec = std::env::var("COMSPEC");
let shell = comspec
.as_ref()
.map(|v| v.as_str())
.unwrap_or_else(|_| "cmd.exe");
let mut command = Command::new(shell);
command.arg("/C");
command
} else {
let mut command = Command::new("sh");
command.arg("-c");
command
};
let mut command_builder = create_command_builder();

command_builder.arg(command);

Expand All @@ -53,6 +47,22 @@ pub fn hash_runtime(
Ok(hash_result)
}

#[cfg(target_os = "windows")]
fn create_command_builder() -> Command {
let comspec = std::env::var("COMSPEC").unwrap_or_else(|_| "cmd.exe".to_string());
let mut command = Command::new(comspec);
command.creation_flags(CREATE_NO_WINDOW);
command.arg("/C");
command
}

#[cfg(not(target_os = "windows"))]
fn create_command_builder() -> Command {
let mut command = Command::new("sh");
command.arg("-c");
command
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 120bc56

Please sign in to comment.