-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
564 additions
and
518 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
mod bin; | ||
mod handler; | ||
mod meduim; | ||
mod simulator; | ||
|
||
use crate::{ | ||
client::Client, daemon::RunRequest, state::State, types::Device, xcode::build_with_logger, | ||
Error, Result, | ||
}; | ||
use tokio::sync::MutexGuard; | ||
use xcodebuild::runner::build_settings; | ||
use {handler::RunServiceHandler, meduim::RunMedium}; | ||
|
||
/// Run Service | ||
pub struct RunService { | ||
pub client: Client, | ||
pub handler: RunServiceHandler, | ||
pub medium: RunMedium, | ||
} | ||
|
||
impl RunService { | ||
pub async fn new(state: &mut MutexGuard<'_, State>, req: RunRequest) -> Result<Self> { | ||
let ref target = req.config.target; | ||
let ref root = req.client.root; | ||
let device = state.devices.from_lookup(req.device); | ||
let build_args = req.config.args(root, &device)?; | ||
let nvim = req.client.nvim(state)?; | ||
|
||
let ref mut logger = nvim.logger(); | ||
|
||
logger.set_title(format!("Run:{target}")); | ||
logger.open_win().await?; | ||
logger.set_direction(&req.direction); | ||
logger.set_running().await?; | ||
|
||
let build_settings = build_settings(root, &build_args).await?; | ||
let build_success = build_with_logger(logger, root, &build_args, false, false).await?; | ||
|
||
if !build_success { | ||
let msg = format!("Failed: {}", req.config); | ||
nvim.echo_err(&msg).await?; | ||
return Err(Error::Build(msg)); | ||
} | ||
|
||
let medium = RunMedium::from_device_or_settings(device, build_settings, req.config)?; | ||
let process = medium.run(logger).await?; | ||
let handler = RunServiceHandler::new(req.client.clone(), process)?; | ||
|
||
Ok(Self { | ||
client: req.client, | ||
handler, | ||
medium, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#![allow(dead_code)] | ||
use crate::types::BuildConfiguration; | ||
use crate::{Error, Result}; | ||
use process_stream::Process; | ||
use std::path::PathBuf; | ||
use xcodebuild::parser::BuildSettings; | ||
|
||
pub struct Bin { | ||
path: PathBuf, | ||
info: BuildSettings, | ||
config: BuildConfiguration, | ||
} | ||
|
||
impl Bin { | ||
pub fn new(info: BuildSettings, config: BuildConfiguration) -> Self { | ||
Self { | ||
path: info.path_to_output_binary().unwrap_or_default(), | ||
info, | ||
config, | ||
} | ||
} | ||
|
||
pub async fn launch(&self) -> Result<Process> { | ||
if !self.path.exists() { | ||
return Err(Error::Run(format!("{:?} doesn't exist!", self.path))); | ||
} | ||
|
||
Ok(Process::new(&self.path)) | ||
} | ||
|
||
/// Get a reference to the bin's info. | ||
#[must_use] | ||
pub fn info(&self) -> &BuildSettings { | ||
&self.info | ||
} | ||
|
||
/// Get a reference to the bin's config. | ||
#[must_use] | ||
pub fn config(&self) -> &BuildConfiguration { | ||
&self.config | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#![allow(dead_code)] | ||
use crate::{client::Client, constants::DAEMON_STATE, Error, Result}; | ||
use process_stream::{Process, StreamExt}; | ||
use tokio::task::JoinHandle; | ||
|
||
/// Run Service Task Handler | ||
pub enum RunServiceHandler { | ||
// Runner is running successfully | ||
Running((Process, JoinHandle<Result<()>>)), | ||
// Runner Errored | ||
Errored(Error), | ||
// Runner Stopped | ||
Stopped(i32), | ||
} | ||
|
||
impl RunServiceHandler { | ||
// Change the status of the process to running | ||
pub fn new(client: Client, mut process: Process) -> Result<Self> { | ||
let mut stream = process.spawn_and_stream()?; | ||
let kill_send = process.clone_kill_sender().unwrap(); | ||
|
||
let handler = tokio::spawn(async move { | ||
while let Some(output) = stream.next().await { | ||
let state = DAEMON_STATE.clone(); | ||
let ref state = state.lock().await; | ||
let ref mut logger = match client.nvim(state) { | ||
Ok(nvim) => nvim.logger(), | ||
Err(_) => { | ||
// TODO: Update state to set current handler as Errored | ||
tracing::info!("Nvim Instance closed, closing runner .."); | ||
kill_send.send(()).await.ok(); | ||
break; | ||
} | ||
}; | ||
|
||
use process_stream::ProcessItem::*; | ||
match output { | ||
Output(msg) => { | ||
if !msg.contains("ignoring singular matrix") { | ||
logger.log(msg).await?; | ||
} | ||
} | ||
Error(msg) => { | ||
logger.log(format!("[Error] {msg}")).await?; | ||
} | ||
// TODO: this should be skipped when user re-run the app | ||
Exit(code) => { | ||
let success = &code == "0"; | ||
logger.log(format!("[Exit] {code}")).await?; | ||
logger.set_status_end(success, !success).await?; | ||
break; | ||
} | ||
}; | ||
} | ||
|
||
drop(stream); | ||
|
||
// TODO: Update state to set current handler as stopped | ||
Ok(()) | ||
}); | ||
Ok(Self::Running((process, handler))) | ||
} | ||
} |
Oops, something went wrong.