Skip to content

Commit

Permalink
windows: Set CREATE_NO_WINDOW for commands (zed-industries#18447)
Browse files Browse the repository at this point in the history
- Closes: zed-industries#18371

Release Notes:

- N/A
  • Loading branch information
JunkuiZhang authored and Anthony-Eid committed Nov 22, 2024
1 parent 2a8ba4f commit 9fa37d5
Show file tree
Hide file tree
Showing 31 changed files with 122 additions and 174 deletions.
9 changes: 3 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/context_servers/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde_json::{value::RawValue, Value};
use smol::{
channel,
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
process::{self, Child},
process::Child,
};
use std::{
fmt,
Expand Down Expand Up @@ -152,7 +152,7 @@ impl Client {
&binary.args
);

let mut command = process::Command::new(&binary.executable);
let mut command = util::command::new_smol_command(&binary.executable);
command
.args(&binary.args)
.envs(binary.env.unwrap_or_default())
Expand Down
3 changes: 2 additions & 1 deletion crates/evals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ languages.workspace = true
node_runtime.workspace = true
open_ai.workspace = true
project.workspace = true
reqwest_client.workspace = true
semantic_index.workspace = true
serde.workspace = true
serde_json.workspace = true
settings.workspace = true
smol.workspace = true
reqwest_client.workspace = true
util.workspace = true
10 changes: 5 additions & 5 deletions crates/evals/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::time::Duration;
use std::{
fs,
path::Path,
process::{exit, Command, Stdio},
process::{exit, Stdio},
sync::{
atomic::{AtomicUsize, Ordering::SeqCst},
Arc,
Expand Down Expand Up @@ -667,7 +667,7 @@ async fn fetch_eval_repo(
return;
}
if !repo_dir.join(".git").exists() {
let init_output = Command::new("git")
let init_output = util::command::new_std_command("git")
.current_dir(&repo_dir)
.args(&["init"])
.output()
Expand All @@ -682,13 +682,13 @@ async fn fetch_eval_repo(
}
}
let url = format!("https://github.com/{}.git", repo);
Command::new("git")
util::command::new_std_command("git")
.current_dir(&repo_dir)
.args(&["remote", "add", "-f", "origin", &url])
.stdin(Stdio::null())
.output()
.unwrap();
let fetch_output = Command::new("git")
let fetch_output = util::command::new_std_command("git")
.current_dir(&repo_dir)
.args(&["fetch", "--depth", "1", "origin", &sha])
.stdin(Stdio::null())
Expand All @@ -703,7 +703,7 @@ async fn fetch_eval_repo(
);
return;
}
let checkout_output = Command::new("git")
let checkout_output = util::command::new_std_command("git")
.current_dir(&repo_dir)
.args(&["checkout", &sha])
.output()
Expand Down
1 change: 1 addition & 0 deletions crates/extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ semantic_version.workspace = true
serde.workspace = true
serde_json.workspace = true
toml.workspace = true
util.workspace = true
wasm-encoder.workspace = true
wasmparser.workspace = true
wit-component.workspace = true
20 changes: 10 additions & 10 deletions crates/extension/src/extension_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use serde::Deserialize;
use std::{
env, fs, mem,
path::{Path, PathBuf},
process::{Command, Stdio},
process::Stdio,
sync::Arc,
};
use wasm_encoder::{ComponentSectionId, Encode as _, RawSection, Section as _};
Expand Down Expand Up @@ -130,7 +130,7 @@ impl ExtensionBuilder {
"compiling Rust crate for extension {}",
extension_dir.display()
);
let output = Command::new("cargo")
let output = util::command::new_std_command("cargo")
.args(["build", "--target", RUST_TARGET])
.args(options.release.then_some("--release"))
.arg("--target-dir")
Expand Down Expand Up @@ -237,7 +237,7 @@ impl ExtensionBuilder {
let scanner_path = src_path.join("scanner.c");

log::info!("compiling {grammar_name} parser");
let clang_output = Command::new(&clang_path)
let clang_output = util::command::new_std_command(&clang_path)
.args(["-fPIC", "-shared", "-Os"])
.arg(format!("-Wl,--export=tree_sitter_{grammar_name}"))
.arg("-o")
Expand All @@ -264,7 +264,7 @@ impl ExtensionBuilder {
let git_dir = directory.join(".git");

if directory.exists() {
let remotes_output = Command::new("git")
let remotes_output = util::command::new_std_command("git")
.arg("--git-dir")
.arg(&git_dir)
.args(["remote", "-v"])
Expand All @@ -287,7 +287,7 @@ impl ExtensionBuilder {
fs::create_dir_all(directory).with_context(|| {
format!("failed to create grammar directory {}", directory.display(),)
})?;
let init_output = Command::new("git")
let init_output = util::command::new_std_command("git")
.arg("init")
.current_dir(directory)
.output()?;
Expand All @@ -298,7 +298,7 @@ impl ExtensionBuilder {
);
}

let remote_add_output = Command::new("git")
let remote_add_output = util::command::new_std_command("git")
.arg("--git-dir")
.arg(&git_dir)
.args(["remote", "add", "origin", url])
Expand All @@ -312,14 +312,14 @@ impl ExtensionBuilder {
}
}

let fetch_output = Command::new("git")
let fetch_output = util::command::new_std_command("git")
.arg("--git-dir")
.arg(&git_dir)
.args(["fetch", "--depth", "1", "origin", rev])
.output()
.context("failed to execute `git fetch`")?;

let checkout_output = Command::new("git")
let checkout_output = util::command::new_std_command("git")
.arg("--git-dir")
.arg(&git_dir)
.args(["checkout", rev])
Expand All @@ -346,7 +346,7 @@ impl ExtensionBuilder {
}

fn install_rust_wasm_target_if_needed(&self) -> Result<()> {
let rustc_output = Command::new("rustc")
let rustc_output = util::command::new_std_command("rustc")
.arg("--print")
.arg("sysroot")
.output()
Expand All @@ -363,7 +363,7 @@ impl ExtensionBuilder {
return Ok(());
}

let output = Command::new("rustup")
let output = util::command::new_std_command("rustup")
.args(["target", "add", RUST_TARGET])
.stderr(Stdio::piped())
.stdout(Stdio::inherit())
Expand Down
4 changes: 0 additions & 4 deletions crates/git/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ time.workspace = true
url.workspace = true
util.workspace = true

[target.'cfg(target_os = "windows")'.dependencies]
windows.workspace = true


[dev-dependencies]
unindent.workspace = true
serde_json.workspace = true
Expand Down
16 changes: 3 additions & 13 deletions crates/git/src/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{anyhow, Context, Result};
use collections::{HashMap, HashSet};
use serde::{Deserialize, Serialize};
use std::io::Write;
use std::process::{Command, Stdio};
use std::process::Stdio;
use std::sync::Arc;
use std::{ops::Range, path::Path};
use text::Rope;
Expand Down Expand Up @@ -80,9 +80,7 @@ fn run_git_blame(
path: &Path,
contents: &Rope,
) -> Result<String> {
let mut child = Command::new(git_binary);

child
let child = util::command::new_std_command(git_binary)
.current_dir(working_directory)
.arg("blame")
.arg("--incremental")
Expand All @@ -91,15 +89,7 @@ fn run_git_blame(
.arg(path.as_os_str())
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());

#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
child.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0);
}

let child = child
.stderr(Stdio::piped())
.spawn()
.map_err(|e| anyhow!("Failed to start git blame process: {}", e))?;

Expand Down
15 changes: 2 additions & 13 deletions crates/git/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ use crate::Oid;
use anyhow::{anyhow, Result};
use collections::HashMap;
use std::path::Path;
use std::process::Command;

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

pub fn get_messages(working_directory: &Path, shas: &[Oid]) -> Result<HashMap<Oid, String>> {
if shas.is_empty() {
Expand All @@ -14,19 +10,12 @@ pub fn get_messages(working_directory: &Path, shas: &[Oid]) -> Result<HashMap<Oi

const MARKER: &str = "<MARKER>";

let mut command = Command::new("git");

command
let output = util::command::new_std_command("git")
.current_dir(working_directory)
.arg("show")
.arg("-s")
.arg(format!("--format=%B{}", MARKER))
.args(shas.iter().map(ToString::to_string));

#[cfg(windows)]
command.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0);

let output = command
.args(shas.iter().map(ToString::to_string))
.output()
.map_err(|e| anyhow!("Failed to start git blame process: {}", e))?;

Expand Down
16 changes: 3 additions & 13 deletions crates/git/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::repository::{GitFileStatus, RepoPath};
use anyhow::{anyhow, Result};
use std::{
path::{Path, PathBuf},
process::{Command, Stdio},
process::Stdio,
sync::Arc,
};

Expand All @@ -17,9 +17,7 @@ impl GitStatus {
working_directory: &Path,
path_prefixes: &[PathBuf],
) -> Result<Self> {
let mut child = Command::new(git_binary);

child
let child = util::command::new_std_command(git_binary)
.current_dir(working_directory)
.args([
"--no-optional-locks",
Expand All @@ -37,15 +35,7 @@ impl GitStatus {
}))
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped());

#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
child.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0);
}

let child = child
.stderr(Stdio::piped())
.spawn()
.map_err(|e| anyhow!("Failed to start git status process: {}", e))?;

Expand Down
2 changes: 1 addition & 1 deletion crates/gpui/src/platform/windows/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl Platform for WindowsPlatform {
pid,
app_path.display(),
);
let restart_process = std::process::Command::new("powershell.exe")
let restart_process = util::command::new_std_command("powershell.exe")
.arg("-command")
.arg(script)
.spawn();
Expand Down
2 changes: 1 addition & 1 deletion crates/languages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ load-grammars = [
"tree-sitter-rust",
"tree-sitter-typescript",
"tree-sitter-yaml",
"tree-sitter"
"tree-sitter",
]

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/languages/src/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl super::LspAdapter for CLspAdapter {
}
futures::io::copy(response.body_mut(), &mut file).await?;

let unzip_status = smol::process::Command::new("unzip")
let unzip_status = util::command::new_smol_command("unzip")
.current_dir(&container_dir)
.arg(&zip_path)
.output()
Expand Down
Loading

0 comments on commit 9fa37d5

Please sign in to comment.