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

fix(core): make windows runtime input hashing windowless #22197

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 28 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,26 @@ pub fn hash_runtime(
Ok(hash_result)
}

#[cfg(target_os = "windows")]
fn create_command_builder() -> Command {
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.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