diff --git a/crates/ide-build/src/process.rs b/crates/ide-build/src/process.rs index c1e1eb41..1e129fd3 100644 --- a/crates/ide-build/src/process.rs +++ b/crates/ide-build/src/process.rs @@ -52,12 +52,7 @@ pub(crate) fn run( use std::os::unix::process::CommandExt; command.process_group(0); } - #[cfg(windows)] - { - use std::os::windows::process::CommandExt; - const CREATE_NO_WINDOW: u32 = 0x0800_0000; - command.creation_flags(CREATE_NO_WINDOW); - } + ide_core::process::no_window(&mut command); let mut child = command.spawn().map_err(|e| IdeError::unavailable(format!("cannot start {program}: {e}")))?; let (tx, rx) = mpsc::channel::<(Stream, String)>(); let pump = |stream: Box, kind: Stream, tx: mpsc::Sender<(Stream, String)>| { diff --git a/crates/ide-core/src/process.rs b/crates/ide-core/src/process.rs index bcfbadb8..78182623 100644 --- a/crates/ide-core/src/process.rs +++ b/crates/ide-core/src/process.rs @@ -2,6 +2,10 @@ use std::process::Command; +/// Windows `CREATE_NO_WINDOW` creation flag, for call sites that combine it +/// with other flags. Prefer [`no_window`] otherwise. +pub const CREATE_NO_WINDOW: u32 = 0x0800_0000; + /// Keeps a console child (java, node, curl, a language server, ...) from /// opening its own console window on Windows. Release builds use the GUI /// subsystem, so without this every spawn flashes a `cmd` window. A no-op @@ -10,7 +14,6 @@ pub fn no_window(cmd: &mut Command) -> &mut Command { #[cfg(windows)] { use std::os::windows::process::CommandExt; - const CREATE_NO_WINDOW: u32 = 0x0800_0000; cmd.creation_flags(CREATE_NO_WINDOW); } cmd diff --git a/crates/ide-docker/src/process.rs b/crates/ide-docker/src/process.rs index 76870106..f0c47f04 100644 --- a/crates/ide-docker/src/process.rs +++ b/crates/ide-docker/src/process.rs @@ -25,11 +25,7 @@ fn prepare(cmd: &mut Command) { use std::os::unix::process::CommandExt; cmd.process_group(0); } - #[cfg(windows)] - { - use std::os::windows::process::CommandExt; - cmd.creation_flags(0x0800_0000); - } + ide_core::process::no_window(cmd); } fn spawn(cmd: &mut Command) -> IdeResult { diff --git a/crates/ide-github/src/process.rs b/crates/ide-github/src/process.rs index 63aae7e7..4a574fcb 100644 --- a/crates/ide-github/src/process.rs +++ b/crates/ide-github/src/process.rs @@ -25,11 +25,7 @@ fn prepare(cmd: &mut Command) { use std::os::unix::process::CommandExt; cmd.process_group(0); } - #[cfg(windows)] - { - use std::os::windows::process::CommandExt; - cmd.creation_flags(0x0800_0000); - } + ide_core::process::no_window(cmd); } fn spawn(cmd: &mut Command) -> IdeResult { diff --git a/crates/ide-run/src/process.rs b/crates/ide-run/src/process.rs index 4b25f99c..93c5b949 100644 --- a/crates/ide-run/src/process.rs +++ b/crates/ide-run/src/process.rs @@ -205,8 +205,7 @@ impl ProcessManager { { use std::os::windows::process::CommandExt; const CREATE_NEW_PROCESS_GROUP: u32 = 0x0000_0200; - const CREATE_NO_WINDOW: u32 = 0x0800_0000; - cmd.creation_flags(CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW); + cmd.creation_flags(CREATE_NEW_PROCESS_GROUP | ide_core::process::CREATE_NO_WINDOW); } let mut child = cmd.spawn().map_err(|e| match e.kind() { @@ -400,7 +399,7 @@ fn kill_tree(pid: u32, _force: bool) { // Console children have no reliable graceful signal from outside their console. let _ = Command::new("taskkill") .args(["/T", "/F", "/PID", &pid.to_string()]) - .creation_flags(0x0800_0000) + .creation_flags(ide_core::process::CREATE_NO_WINDOW) .stdout(Stdio::null()) .stderr(Stdio::null()) .status(); diff --git a/crates/ide-vcs/src/cli.rs b/crates/ide-vcs/src/cli.rs index b69ddd02..97f687c6 100644 --- a/crates/ide-vcs/src/cli.rs +++ b/crates/ide-vcs/src/cli.rs @@ -64,11 +64,7 @@ pub fn git_version(executable: Option<&Path>) -> IdeResult { }; let mut cmd = Command::new(&exe); cmd.arg("--version").stdin(Stdio::null()).env("LC_ALL", "C"); - #[cfg(windows)] - { - use std::os::windows::process::CommandExt; - cmd.creation_flags(0x0800_0000); - } + ide_core::process::no_window(&mut cmd); let out = cmd.output().map_err(|e| IdeError::unavailable(format!("cannot run {}: {e}", exe.display())))?; let text = String::from_utf8_lossy(&out.stdout).trim().to_string(); if !out.status.success() || !text.starts_with("git version") { @@ -99,12 +95,7 @@ pub(crate) fn command(root: &Path) -> IdeResult { .env_remove("GIT_DIR") .env_remove("GIT_WORK_TREE") .env_remove("GIT_INDEX_FILE"); - #[cfg(windows)] - { - use std::os::windows::process::CommandExt; - const CREATE_NO_WINDOW: u32 = 0x0800_0000; - cmd.creation_flags(CREATE_NO_WINDOW); - } + ide_core::process::no_window(&mut cmd); Ok(cmd) }