about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-07 10:19:32 +0000
committerbors <bors@rust-lang.org>2022-11-07 10:19:32 +0000
commit774207741933465722a79b212afabd76829c3f07 (patch)
tree90cc1ae482577ff24ede170677b0f70be116ddd0
parentd03c1c87d4ca2d524646316387d47b12524ac451 (diff)
parent1dcc25a70afdc484081c0fc5cda1f8911d6660b8 (diff)
downloadrust-774207741933465722a79b212afabd76829c3f07.tar.gz
rust-774207741933465722a79b212afabd76829c3f07.zip
Auto merge of #13552 - Veykril:flycheck-process-group, r=Veykril
internal: Use a process group for flycheck

Should fix https://github.com/rust-lang/rust-analyzer/issues/13348
-rw-r--r--Cargo.lock24
-rw-r--r--crates/flycheck/Cargo.toml1
-rw-r--r--crates/flycheck/src/lib.rs19
3 files changed, 36 insertions, 8 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 8931c17bbdc..c04906c4538 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -222,6 +222,16 @@ dependencies = [
 ]
 
 [[package]]
+name = "command-group"
+version = "1.0.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7a8a86f409b4a59df3a3e4bee2de0b83f1755fdd2a25e3a9684c396fc4bed2c"
+dependencies = [
+ "nix",
+ "winapi",
+]
+
+[[package]]
 name = "countme"
 version = "3.0.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -390,6 +400,7 @@ name = "flycheck"
 version = "0.0.0"
 dependencies = [
  "cargo_metadata",
+ "command-group",
  "crossbeam-channel",
  "jod-thread",
  "paths",
@@ -971,6 +982,19 @@ dependencies = [
 ]
 
 [[package]]
+name = "nix"
+version = "0.22.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf"
+dependencies = [
+ "bitflags",
+ "cc",
+ "cfg-if",
+ "libc",
+ "memoffset",
+]
+
+[[package]]
 name = "notify"
 version = "5.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/crates/flycheck/Cargo.toml b/crates/flycheck/Cargo.toml
index 2ad32d24837..6871f90015f 100644
--- a/crates/flycheck/Cargo.toml
+++ b/crates/flycheck/Cargo.toml
@@ -17,6 +17,7 @@ rustc-hash = "1.1.0"
 serde = { version = "1.0.137", features = ["derive"] }
 serde_json = "1.0.86"
 jod-thread = "0.1.2"
+command-group = "1.0.8"
 
 toolchain = { path = "../toolchain", version = "0.0.0" }
 stdx = { path = "../stdx", version = "0.0.0" }
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs
index 8a91d606661..1758c9c27a2 100644
--- a/crates/flycheck/src/lib.rs
+++ b/crates/flycheck/src/lib.rs
@@ -10,11 +10,12 @@ use std::{
     time::Duration,
 };
 
+use command_group::{CommandGroup, GroupChild};
 use crossbeam_channel::{never, select, unbounded, Receiver, Sender};
 use paths::AbsPathBuf;
 use rustc_hash::FxHashMap;
 use serde::Deserialize;
-use stdx::{process::streaming_output, JodChild};
+use stdx::process::streaming_output;
 
 pub use cargo_metadata::diagnostic::{
     Applicability, Diagnostic, DiagnosticCode, DiagnosticLevel, DiagnosticSpan,
@@ -359,6 +360,8 @@ impl FlycheckActor {
     }
 }
 
+struct JodChild(GroupChild);
+
 /// A handle to a cargo process used for fly-checking.
 struct CargoHandle {
     /// The handle to the actual cargo process. As we cannot cancel directly from with
@@ -371,10 +374,10 @@ struct CargoHandle {
 impl CargoHandle {
     fn spawn(mut command: Command) -> std::io::Result<CargoHandle> {
         command.stdout(Stdio::piped()).stderr(Stdio::piped()).stdin(Stdio::null());
-        let mut child = JodChild::spawn(command)?;
+        let mut child = command.group_spawn().map(JodChild)?;
 
-        let stdout = child.stdout.take().unwrap();
-        let stderr = child.stderr.take().unwrap();
+        let stdout = child.0.inner().stdout.take().unwrap();
+        let stderr = child.0.inner().stderr.take().unwrap();
 
         let (sender, receiver) = unbounded();
         let actor = CargoActor::new(sender, stdout, stderr);
@@ -386,13 +389,13 @@ impl CargoHandle {
     }
 
     fn cancel(mut self) {
-        let _ = self.child.kill();
-        let _ = self.child.wait();
+        let _ = self.child.0.kill();
+        let _ = self.child.0.wait();
     }
 
     fn join(mut self) -> io::Result<()> {
-        let _ = self.child.kill();
-        let exit_status = self.child.wait()?;
+        let _ = self.child.0.kill();
+        let exit_status = self.child.0.wait()?;
         let (read_at_least_one_message, error) = self.thread.join()?;
         if read_at_least_one_message || exit_status.success() {
             Ok(())