treewide: move rom's parser logic to cognos
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I6a6a6964960ab80b5555a6cca7b20e11c8ac0ea2
This commit is contained in:
parent
c07b295f71
commit
5fea07c768
7 changed files with 57 additions and 119 deletions
|
|
@ -9,4 +9,13 @@ pub use aterm::{
|
|||
parse_drv_file,
|
||||
};
|
||||
pub use internal_json::{Actions, Activities, Id, Verbosity};
|
||||
pub use state::{BuildInfo, BuildStatus, Derivation, Host, State};
|
||||
pub use state::{BuildInfo, BuildStatus, Derivation, Host, OutputName, State, ProgressState};
|
||||
|
||||
/// Process a list of actions and return the resulting state
|
||||
pub fn process_actions(actions: Vec<Actions>) -> State {
|
||||
let mut state = State { progress: ProgressState::JustStarted };
|
||||
for action in actions {
|
||||
state.imbibe(action);
|
||||
}
|
||||
state
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ pub enum BuildStatus {
|
|||
Failed,
|
||||
}
|
||||
|
||||
pub enum Progress {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum ProgressState {
|
||||
JustStarted,
|
||||
InputReceived,
|
||||
Finished,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum OutputName {
|
||||
Out,
|
||||
Doc,
|
||||
|
|
@ -36,9 +38,37 @@ pub enum OutputName {
|
|||
Other(String),
|
||||
}
|
||||
|
||||
impl OutputName {
|
||||
#[must_use]
|
||||
pub fn parse(name: &str) -> Self {
|
||||
match name.to_lowercase().as_str() {
|
||||
"out" => Self::Out,
|
||||
"doc" => Self::Doc,
|
||||
"dev" => Self::Dev,
|
||||
"bin" => Self::Bin,
|
||||
"info" => Self::Info,
|
||||
"lib" => Self::Lib,
|
||||
"man" => Self::Man,
|
||||
"dist" => Self::Dist,
|
||||
_ => Self::Other(name.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Host {
|
||||
Local,
|
||||
Host(String),
|
||||
Localhost,
|
||||
Remote(String),
|
||||
}
|
||||
|
||||
impl Host {
|
||||
#[must_use]
|
||||
pub fn name(&self) -> &str {
|
||||
match self {
|
||||
Self::Localhost => "localhost",
|
||||
Self::Remote(name) => name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Derivation {
|
||||
|
|
@ -65,9 +95,9 @@ pub struct Dependencies {
|
|||
|
||||
// #[derive(Default)]
|
||||
pub struct State {
|
||||
progress: Progress,
|
||||
pub progress: ProgressState,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn imbibe(&mut self, update: Actions) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ use std::{
|
|||
};
|
||||
|
||||
use clap::Parser;
|
||||
use cognos::ProgressState;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(name = "rom", version, about = "ROM - A Nix build output monitor")]
|
||||
|
|
@ -582,7 +583,7 @@ fn run_monitored_command(
|
|||
|
||||
if !silent {
|
||||
if has_activity
|
||||
|| state.progress_state != crate::state::ProgressState::JustStarted
|
||||
|| state.progress_state != ProgressState::JustStarted
|
||||
{
|
||||
// Clear any previous timer display
|
||||
if last_timer_display.is_some() {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@ pub struct Display<W: Write> {
|
|||
writer: W,
|
||||
config: DisplayConfig,
|
||||
last_lines: usize,
|
||||
using_alt_screen: bool,
|
||||
}
|
||||
|
||||
struct TreeNode {
|
||||
|
|
@ -80,7 +79,6 @@ impl<W: Write> Display<W> {
|
|||
writer,
|
||||
config,
|
||||
last_lines: 0,
|
||||
using_alt_screen: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -860,27 +858,7 @@ impl<W: Write> Display<W> {
|
|||
lines
|
||||
}
|
||||
|
||||
fn is_active_or_has_active_descendants(
|
||||
&self,
|
||||
state: &State,
|
||||
drv_id: DerivationId,
|
||||
) -> bool {
|
||||
if let Some(info) = state.get_derivation_info(drv_id) {
|
||||
match info.build_status {
|
||||
BuildStatus::Building(_) => return true,
|
||||
BuildStatus::Failed { .. } => return true,
|
||||
_ => {},
|
||||
}
|
||||
|
||||
// Check children
|
||||
for input in &info.input_derivations {
|
||||
if self.is_active_or_has_active_descendants(state, input.derivation) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn build_active_forest(
|
||||
&self,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use crate::{
|
|||
types::{Config, InputMode},
|
||||
update,
|
||||
};
|
||||
use cognos::Host;
|
||||
|
||||
/// Main monitor that processes nix output and displays progress
|
||||
pub struct Monitor<W: Write> {
|
||||
|
|
@ -152,7 +153,7 @@ impl<W: Write> Monitor<W> {
|
|||
|
||||
let build_info = crate::state::BuildInfo {
|
||||
start: now,
|
||||
host: crate::state::Host::Localhost,
|
||||
host: Host::Localhost,
|
||||
estimate: None,
|
||||
activity_id: None,
|
||||
};
|
||||
|
|
@ -175,7 +176,7 @@ impl<W: Write> Monitor<W> {
|
|||
|
||||
let transfer = crate::state::TransferInfo {
|
||||
start: now,
|
||||
host: crate::state::Host::Localhost,
|
||||
host: Host::Localhost,
|
||||
activity_id: 0, // No activity ID in human mode
|
||||
bytes_transferred: 0,
|
||||
total_bytes: None,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use std::{
|
|||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
use cognos::Id;
|
||||
use cognos::{Host, Id, OutputName, ProgressState};
|
||||
use indexmap::IndexMap;
|
||||
|
||||
/// Unique identifier for store paths
|
||||
|
|
@ -18,35 +18,9 @@ pub type DerivationId = usize;
|
|||
/// Unique identifier for activities
|
||||
pub type ActivityId = Id;
|
||||
|
||||
/// Overall progress state
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ProgressState {
|
||||
JustStarted,
|
||||
InputReceived,
|
||||
Finished,
|
||||
}
|
||||
|
||||
/// Build host information
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Host {
|
||||
Localhost,
|
||||
Remote(String),
|
||||
}
|
||||
|
||||
impl Host {
|
||||
#[must_use]
|
||||
pub const fn is_local(&self) -> bool {
|
||||
matches!(self, Self::Localhost)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn name(&self) -> &str {
|
||||
match self {
|
||||
Self::Localhost => "localhost",
|
||||
Self::Remote(name) => name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Store path representation
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
|
@ -111,36 +85,8 @@ impl Derivation {
|
|||
}
|
||||
}
|
||||
|
||||
/// Output name for derivations
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum OutputName {
|
||||
Out,
|
||||
Doc,
|
||||
Dev,
|
||||
Bin,
|
||||
Info,
|
||||
Lib,
|
||||
Man,
|
||||
Dist,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
impl OutputName {
|
||||
#[must_use]
|
||||
pub fn parse(name: &str) -> Self {
|
||||
match name.to_lowercase().as_str() {
|
||||
"out" => Self::Out,
|
||||
"doc" => Self::Doc,
|
||||
"dev" => Self::Dev,
|
||||
"bin" => Self::Bin,
|
||||
"info" => Self::Info,
|
||||
"lib" => Self::Lib,
|
||||
"man" => Self::Man,
|
||||
"dist" => Self::Dist,
|
||||
_ => Self::Other(name.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Transfer information (download/upload)
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -603,7 +549,7 @@ impl State {
|
|||
// Create output set
|
||||
let mut output_set = HashSet::new();
|
||||
for output in outputs {
|
||||
output_set.insert(parse_output_name(&output));
|
||||
output_set.insert(OutputName::parse(&output));
|
||||
}
|
||||
|
||||
// Add to parent's input derivations
|
||||
|
|
@ -728,19 +674,7 @@ pub fn current_time() -> f64 {
|
|||
.as_secs_f64()
|
||||
}
|
||||
|
||||
fn parse_output_name(name: &str) -> OutputName {
|
||||
match name {
|
||||
"out" => OutputName::Out,
|
||||
"doc" => OutputName::Doc,
|
||||
"dev" => OutputName::Dev,
|
||||
"bin" => OutputName::Bin,
|
||||
"info" => OutputName::Info,
|
||||
"lib" => OutputName::Lib,
|
||||
"man" => OutputName::Man,
|
||||
"dist" => OutputName::Dist,
|
||||
_ => OutputName::Other(name.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! State update logic for processing nix messages
|
||||
|
||||
use cognos::{Actions, Activities, Id, Verbosity};
|
||||
use cognos::{Actions, Activities, Host, Id, ProgressState, Verbosity};
|
||||
use tracing::{debug, trace};
|
||||
|
||||
use crate::state::{
|
||||
|
|
@ -14,10 +14,7 @@ use crate::state::{
|
|||
DerivationId,
|
||||
FailType,
|
||||
FailedBuildInfo,
|
||||
Host,
|
||||
InputDerivation,
|
||||
OutputName,
|
||||
ProgressState,
|
||||
State,
|
||||
StorePath,
|
||||
StorePathId,
|
||||
|
|
@ -887,17 +884,5 @@ pub fn finish_state(state: &mut State) {
|
|||
}
|
||||
}
|
||||
|
||||
/// Parse output name string to `OutputName` enum
|
||||
fn parse_output_name(s: &str) -> Option<OutputName> {
|
||||
match s {
|
||||
"out" => Some(OutputName::Out),
|
||||
"doc" => Some(OutputName::Doc),
|
||||
"dev" => Some(OutputName::Dev),
|
||||
"bin" => Some(OutputName::Bin),
|
||||
"info" => Some(OutputName::Info),
|
||||
"lib" => Some(OutputName::Lib),
|
||||
"man" => Some(OutputName::Man),
|
||||
"dist" => Some(OutputName::Dist),
|
||||
other => Some(OutputName::Other(other.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue