Skip to content

Commit 15b4c1c

Browse files
committed
ref(daemon): switch to process-stream
1 parent 78ea10e commit 15b4c1c

File tree

8 files changed

+69
-141
lines changed

8 files changed

+69
-141
lines changed

Cargo.lock

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,27 @@ edition = "2021"
66
[features]
77
default = [ ]
88
xcodegen = [ "async", "dirs" ]
9-
daemon = [ "serial", "compilation", "logging", "async", "watcher", "proc", "xcodegen", "parity-tokio-ipc", "nvim-rs", "strum", "simctl" ]
10-
server = [ "serial", "logging", "dirs", "bsp-server", "url", "wax", "shell-words", "compilation", "strum" ]
11-
lua = [ "mlua", "serial", "strum", "simctl" ]
9+
daemon = [
10+
"serial",
11+
"compilation",
12+
"logging",
13+
"async",
14+
"watcher",
15+
"proc",
16+
"xcodegen",
17+
"parity-tokio-ipc",
18+
"nvim-rs",
19+
"simctl",
20+
"process-stream"
21+
]
22+
server = [ "serial", "logging", "dirs", "bsp-server", "url", "wax", "shell-words", "compilation" ]
23+
lua = [ "mlua", "serial", "simctl" ]
1224
serial = [ "serde", "serde_json", "serde_yaml" ]
1325
compilation = [ "serial", "lazy_static", "shell-words", "xcode" ]
1426
logging = [ "tracing", "tracing-appender", "tracing-subscriber" ]
15-
async = [ "tokio", "async-trait", "futures", "async-stream", "tokio-stream" ]
27+
async = [ "tokio", "async-trait", "async-stream" ]
1628
proc = [ "libproc" ]
1729
watcher = [ "dirs", "notify", "wax" ]
18-
jsonrpc = [ "serial" ]
1930
xcode = [ "xcodebuild" ]
2031

2132
[lib]
@@ -46,13 +57,13 @@ tap = "1.0.1"
4657
serde = { version = "1.0", features = ["derive"], optional = true }
4758
serde_json = { version = "1.0.79", optional = true }
4859
serde_yaml = { version = "0.8.23", optional = true }
60+
strum = { version = "0.24.0", features = ["derive"] }
4961
# Async Runtime Feature
5062
tokio = { version = "1.17.0", features = ["full"], optional = true }
5163
tokio-util = { version = "0.7.1", features = ["codec"], optional = true }
5264
async-trait = { version = "0.1.52", optional = true }
53-
tokio-stream = { version = "0.1.8", features = ["io-util"], optional = true }
5465
async-stream = { version = "0.3.3", optional = true }
55-
futures = { version = "0.3.21", optional = true }
66+
process-stream = { version = "0.1.3", optional = true }
5667
# Logging Feature
5768
tracing = { version = "0.1.32", optional = true }
5869
tracing-subscriber = { version = "0.3.9", features = ["env-filter"], optional = true}
@@ -73,7 +84,6 @@ libproc = { version = "0.12.0", optional = true }
7384
url = { version = "2.2.2", features = ["serde"], optional = true }
7485
nvim-rs = { version = "0.4.0", optional = true, features = ["use_tokio"] }
7586
parity-tokio-ipc = { version = "0.9.0", optional = true }
76-
strum = { version = "0.24.0", features = ["derive"], optional = true }
7787
simctl = { path = "../../../sources/simctl/", optional = true }
7888
thiserror = "1.0.31"
7989
libc = "0.2.126"

src/compile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,16 @@ use {
133133
xcode::fresh_build,
134134
xcodegen,
135135
},
136+
process_stream::StreamExt,
136137
std::path::PathBuf,
137138
tokio::{
138139
fs::{metadata, File},
139140
io::AsyncWriteExt,
140141
sync::OwnedMutexGuard,
141142
},
142-
tokio_stream::StreamExt,
143143
};
144144

145+
#[cfg(feature = "daemon")]
145146
pub async fn update_compilation_file(root: &path::PathBuf) -> Result<()> {
146147
// TODO(build): Ensure that build successed. check for Exit Code
147148
let steps = fresh_build(&root).await?.collect::<Vec<Step>>().await;

src/runner.rs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ use crate::{
77
nvim::BufferDirection,
88
state::State,
99
types::{Client, Platform},
10-
util::{
11-
fmt,
12-
process::{self, Output},
13-
},
10+
util::fmt,
1411
Error, Result,
1512
};
1613
use {
14+
process_stream::{Process, ProcessItem, StreamExt},
1715
tap::Pipe,
1816
tokio::{sync::OwnedMutexGuard, task::JoinHandle},
19-
tokio_stream::StreamExt,
20-
xcodebuild::{parser::BuildSettings, runner},
17+
xcodebuild::parser::BuildSettings,
2118
};
2219

2320
pub struct Runner {
@@ -51,11 +48,11 @@ impl Runner {
5148

5249
tokio::spawn(async move {
5350
let program = settings.path_to_output_binary()?;
54-
let mut stream = runner::run(&program).await?;
51+
let mut stream = Process::new(&program).stream()?;
5552

5653
tracing::debug!("Running binary {program:?}");
5754

58-
use xcodebuild::runner::ProcessUpdate::*;
55+
use ProcessItem::*;
5956
// NOTE: This is required so when neovim exist this should also exit
6057
while let Some(update) = stream.next().await {
6158
let state = DAEMON_STATE.clone();
@@ -65,20 +62,15 @@ impl Runner {
6562

6663
// NOTE: NSLog get directed to error by default which is odd
6764
match update {
68-
Stdout(msg) => {
69-
logger.log(msg).await?;
70-
}
71-
Error(msg) | Stderr(msg) => {
72-
logger.log(format!("[Error] {msg}")).await?;
73-
}
65+
Output(msg) => logger.log(msg).await?,
66+
Error(msg) => logger.log(format!("[Error] {msg}")).await?,
7467
Exit(ref code) => {
7568
let success = code == "0";
7669
let msg = fmt::as_section(if success {
7770
"".into()
7871
} else {
7972
format!("Panic {code}")
8073
});
81-
8274
logger.log(msg).await?;
8375
logger.set_status_end(success, true).await?;
8476
}
@@ -121,42 +113,37 @@ impl Runner {
121113
runner
122114
};
123115

124-
let child = runner.launch(logger).await?;
125-
let mut stream = process::stream(child)?;
116+
let mut launcher = runner.launch(logger).await?;
117+
let mut stream = launcher.stream()?;
126118
// TODO(daemon): ensure Simulator.app is running
127119

128120
logger.log(fmt::separator()).await?;
129121

130-
// TODO(nvim): Close ran simctl process on exit.
131122
tokio::spawn(async move {
132123
while let Some(output) = stream.next().await {
133124
let state = DAEMON_STATE.clone();
134125
let state = state.lock().await;
135126
let mut logger = match state.clients.get(&client.pid) {
136127
Ok(nvim) => nvim.new_unamed_logger(),
137-
Err(e) => {
138-
tracing::error!("SimDevice runner: {e}");
128+
Err(_) => {
129+
tracing::info!("Nvim Instance closed, closing runner ..");
130+
launcher.kill().await;
139131
break;
140132
}
141133
};
142134

135+
use ProcessItem::*;
143136
match output {
144-
Output::Out(msg) => {
137+
Output(msg) => {
145138
if !msg.contains("ignoring singular matrix") {
146139
logger.log(msg).await?;
147140
}
148141
}
149-
Output::Err(msg) => {
142+
Error(msg) => {
150143
logger.log(format!("[Error] {msg}")).await?;
151144
}
152-
Output::Exit(status) => {
153-
if let Ok(Some(code)) = status {
154-
logger.log(format!("[Exit] {code}")).await?;
155-
} else {
156-
logger
157-
.log(format!("[Error] Unable to get exit code"))
158-
.await?;
159-
}
145+
Exit(code) => {
146+
logger.log(format!("[Exit] {code}")).await?;
160147
break;
161148
}
162149
};

src/runner/simctl.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{nvim::Logger, types::SimDevice, Error, Result};
2-
use std::{path::PathBuf, process::Stdio};
2+
use process_stream::Process;
3+
use std::path::PathBuf;
34
use tap::Pipe;
4-
use tokio::process::{Child, Command};
55

66
/// SimDevice ruuner
77
pub struct SimDeviceRunner {
@@ -35,20 +35,19 @@ impl SimDeviceRunner {
3535
Ok(())
3636
}
3737

38-
pub async fn launch<'a>(&self, logger: &mut Logger<'a>) -> Result<Child> {
38+
pub async fn launch<'a>(&self, logger: &mut Logger<'a>) -> Result<Process> {
3939
logger.log(self.launching_msg()).await?;
40-
let process = Command::new("xcrun")
41-
.arg("simctl")
42-
.arg("launch")
43-
.arg("--terminate-running-process")
44-
.arg("--console")
45-
.arg(&self.device.udid)
46-
.arg(&self.app_id)
47-
.stdout(Stdio::piped())
48-
.stderr(Stdio::piped())
49-
.stdin(Stdio::null())
50-
.kill_on_drop(true)
51-
.spawn()?;
40+
let mut process = Process::new("xcrun");
41+
42+
process.args(&[
43+
"simctl",
44+
"launch",
45+
"--terminate-running-process",
46+
"--console",
47+
]);
48+
process.arg(&self.device.udid);
49+
process.arg(&self.app_id);
50+
process.kill_on_drop(true);
5251

5352
logger.log(self.connected_msg()).await?;
5453
Ok(process)

src/util/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,3 @@ pub mod serde;
1010
pub mod tracing;
1111

1212
pub mod fmt;
13-
14-
#[cfg(feature = "daemon")]
15-
pub mod process;

src/util/process.rs

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)