Skip to content

Commit

Permalink
Replace more process::Command and smol::Command calls
Browse files Browse the repository at this point in the history
  • Loading branch information
someone13574 committed Apr 25, 2024
1 parent bf2fabd commit af30e28
Show file tree
Hide file tree
Showing 20 changed files with 245 additions and 292 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

72 changes: 26 additions & 46 deletions crates/extension/src/extension_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,14 @@ impl ExtensionBuilder {
let cargo_toml: CargoToml = toml::from_str(&cargo_toml_content)?;

log::info!("compiling rust extension {}", extension_dir.display());
let mut process = process::Process::new("cargo");
process
let output = process::Process::new("cargo")
.args(["build", "--target", RUST_TARGET])
.args(options.release.then_some("--release"))
.arg("--target-dir")
.arg(extension_dir.join("target"))
.current_dir(&extension_dir);
let output = process
.current_dir(&extension_dir)
.output()
.standard()
.context("failed to run `cargo`")?;

if !output.status.success() {
bail!(
"failed to build extension {}",
Expand Down Expand Up @@ -210,17 +206,17 @@ impl ExtensionBuilder {
let scanner_path = src_path.join("scanner.c");

log::info!("compiling {grammar_name} parser");
let mut process = process::Process::new(&clang_path);
process
let clang_output = process::Process::new(&clang_path)
.args(["-fPIC", "-shared", "-Os"])
.arg(format!("-Wl,--export=tree_sitter_{grammar_name}"))
.arg("-o")
.arg(&grammar_wasm_path)
.arg("-I")
.arg(&src_path)
.arg(&parser_path)
.args(scanner_path.exists().then_some(scanner_path));
let clang_output = process.output().standard().context("failed to run clang")?;
.args(scanner_path.exists().then_some(scanner_path))
.output()
.context("failed to run clang")?;
if !clang_output.status.success() {
bail!(
"failed to compile {} parser with clang: {}",
Expand All @@ -236,13 +232,11 @@ impl ExtensionBuilder {
let git_dir = directory.join(".git");

if directory.exists() {
let mut process = process::Process::new("git");
process
let remotes_output = process::Process::new("git")
.arg("--git-dir")
.arg(&git_dir)
.args(["remote", "-v"]);
let remotes_output = process.output().standard()?;

.args(["remote", "-v"])
.output()?;
let has_remote = remotes_output.status.success()
&& String::from_utf8_lossy(&remotes_output.stdout)
.lines()
Expand All @@ -261,27 +255,23 @@ impl ExtensionBuilder {
fs::create_dir_all(&directory).with_context(|| {
format!("failed to create grammar directory {}", directory.display(),)
})?;
let mut process = process::Process::new("git");
process.arg("init").current_dir(&directory);
let init_output = process.output().standard()?;

let init_output = process::Process::new("git")
.arg("init")
.current_dir(&directory)
.output()?;
if !init_output.status.success() {
bail!(
"failed to run `git init` in directory '{}'",
directory.display()
);
}

let mut process = process::Process::new("git");
process
let remote_add_output = process::Process::new("git")
.arg("--git-dir")
.arg(&git_dir)
.args(["remote", "add", "origin", url]);
let remote_add_output = process
.args(["remote", "add", "origin", url])
.output()
.standard()
.context("failed to execute `git remote add`")?;

if !remote_add_output.status.success() {
bail!(
"failed to add remote {url} for git repository {}",
Expand All @@ -290,27 +280,20 @@ impl ExtensionBuilder {
}
}

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

let mut process = process::Process::new("git");
process
let checkout_output = process::Process::new("git")
.arg("--git-dir")
.arg(&git_dir)
.args(["checkout", &rev])
.current_dir(&directory);
let checkout_output = process
.current_dir(&directory)
.output()
.standard()
.context("failed to execute `git checkout`")?;

if !checkout_output.status.success() {
if !fetch_output.status.success() {
bail!(
Expand All @@ -331,10 +314,11 @@ impl ExtensionBuilder {
}

fn install_rust_wasm_target_if_needed(&self) -> Result<()> {
let mut process = process::Process::new("rustc");
process.arg("--print").arg("sysroot");
let rustc_output = process.output().standard().context("failed to run rustc")?;

let rustc_output = process::Process::new("rustc")
.arg("--print")
.arg("sysroot")
.output()
.context("failed to run rustc")?;
if !rustc_output.status.success() {
bail!(
"failed to retrieve rust sysroot: {}",
Expand All @@ -347,16 +331,12 @@ impl ExtensionBuilder {
return Ok(());
}

let mut process = process::Process::new("rustup");
process
let output = process::Process::new("rustup")
.args(["target", "add", RUST_TARGET])
.stderr(Stdio::inherit())
.stdout(Stdio::inherit());
let output = process
.stdout(Stdio::inherit())
.output()
.standard()
.context("failed to run `rustup target add`")?;

if !output.status.success() {
bail!("failed to install the `{RUST_TARGET}` target");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/extension/src/wasm_host/wit/since_v0_0_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl ExtensionImports for WasmState {
futures::pin_mut!(body);
self.host.fs.create_file_with(&zip_path, body).await?;

let unzip_status = std::process::Command::new("unzip")
let unzip_status = process::Process::new("unzip")
.current_dir(&extension_work_dir)
.arg("-d")
.arg(&destination_path)
Expand Down
6 changes: 1 addition & 5 deletions crates/git/src/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ use time::OffsetDateTime;
use time::UtcOffset;
use url::Url;

#[cfg(windows)]
use process::WindowsCommandExt;

pub use git2 as libgit;

#[derive(Debug, Clone, Default)]
Expand Down Expand Up @@ -92,11 +89,10 @@ fn run_git_blame(
.stderr(Stdio::piped());

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

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

let mut stdin = child
Expand Down
6 changes: 1 addition & 5 deletions crates/git/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use anyhow::{anyhow, Result};
use collections::HashMap;
use std::path::Path;

#[cfg(windows)]
use process::WindowsCommandExt;

pub fn get_messages(working_directory: &Path, shas: &[Oid]) -> Result<HashMap<Oid, String>> {
const MARKER: &'static str = "<MARKER>";

Expand All @@ -19,11 +16,10 @@ pub fn get_messages(working_directory: &Path, shas: &[Oid]) -> Result<HashMap<Oi
.args(shas.iter().map(ToString::to_string));

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

let output = command
.output()
.standard()
.map_err(|e| anyhow!("Failed to start git blame process: {}", e))?;

anyhow::ensure!(
Expand Down
1 change: 1 addition & 0 deletions crates/languages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ lazy_static.workspace = true
log.workspace = true
lsp.workspace = true
node_runtime.workspace = true
process.workspace = true
project.workspace = true
regex.workspace = true
rope.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/languages/src/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ 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 = process::Process::new("unzip")
.current_dir(&container_dir)
.arg(&zip_path)
.output()
.output_async(false)
.await?
.status;
if !unzip_status.success() {
Expand Down
4 changes: 2 additions & 2 deletions crates/languages/src/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ impl LspAdapter for DenoLspAdapter {
}
futures::io::copy(response.body_mut(), &mut file).await?;

let unzip_status = smol::process::Command::new("unzip")
let unzip_status = process::Process::new("unzip")
.current_dir(&container_dir)
.arg(&zip_path)
.arg("-d")
.arg(&version_dir)
.output()
.output_async(false)
.await?
.status;
if !unzip_status.success() {
Expand Down
8 changes: 4 additions & 4 deletions crates/languages/src/elixir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ impl LspAdapter for ElixirLspAdapter {

let delegate = delegate.clone();
Some(cx.spawn(|cx| async move {
let elixir_output = smol::process::Command::new("elixir")
let elixir_output = process::Process::new("elixir")
.args(["--version"])
.output()
.output_async(false)
.await;
if elixir_output.is_err() {
if DID_SHOW_NOTIFICATION
Expand Down Expand Up @@ -149,11 +149,11 @@ impl LspAdapter for ElixirLspAdapter {
fs::create_dir_all(&folder_path)
.await
.with_context(|| format!("failed to create directory {}", folder_path.display()))?;
let unzip_status = smol::process::Command::new("unzip")
let unzip_status = process::Process::new("unzip")
.arg(&zip_path)
.arg("-d")
.arg(&folder_path)
.output()
.output_async(false)
.await?
.status;
if !unzip_status.success() {
Expand Down
15 changes: 9 additions & 6 deletions crates/languages/src/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use project::project_settings::{BinarySettings, ProjectSettings};
use regex::Regex;
use serde_json::json;
use settings::Settings;
use smol::{fs, process};
use smol::fs;
use std::{
any::Any,
ffi::{OsStr, OsString},
Expand Down Expand Up @@ -109,7 +109,10 @@ impl super::LspAdapter for GoLspAdapter {

let delegate = delegate.clone();
Some(cx.spawn(|cx| async move {
let install_output = process::Command::new("go").args(["version"]).output().await;
let install_output = process::Process::new("go")
.args(["version"])
.output_async(false)
.await;
if install_output.is_err() {
if DID_SHOW_NOTIFICATION
.compare_exchange(false, true, SeqCst, SeqCst)
Expand Down Expand Up @@ -159,11 +162,11 @@ impl super::LspAdapter for GoLspAdapter {

let gobin_dir = container_dir.join("gobin");
fs::create_dir_all(&gobin_dir).await?;
let install_output = process::Command::new("go")
let install_output = process::Process::new("go")
.env("GO111MODULE", "on")
.env("GOBIN", &gobin_dir)
.args(["install", "golang.org/x/tools/gopls@latest"])
.output()
.output_async(false)
.await?;

if !install_output.status.success() {
Expand All @@ -177,9 +180,9 @@ impl super::LspAdapter for GoLspAdapter {
}

let installed_binary_path = gobin_dir.join("gopls");
let version_output = process::Command::new(&installed_binary_path)
let version_output = process::Process::new(&installed_binary_path)
.arg("version")
.output()
.output_async(false)
.await
.context("failed to run installed gopls binary")?;
let version_stdout = str::from_utf8(&version_output.stdout)
Expand Down
2 changes: 1 addition & 1 deletion crates/languages/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ fn human_readable_package_name(package_directory: &Path) -> Option<String> {
}

let pkgid = String::from_utf8(
std::process::Command::new("cargo")
process::Process::new("cargo")
.current_dir(package_directory)
.arg("pkgid")
.output()
Expand Down
1 change: 1 addition & 0 deletions crates/lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ gpui.workspace = true
log.workspace = true
lsp-types = { git = "https://github.com/zed-industries/lsp-types", branch = "updated-completion-list-item-defaults" }
parking_lot.workspace = true
process.workspace = true
postage.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
Loading

0 comments on commit af30e28

Please sign in to comment.