From 1cc53ba631f1e149f9babe387ca4535b68242052 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 31 Mar 2026 20:02:34 -0400 Subject: [PATCH] Display progress. --- src/nix_util/activity.rs | 62 +++++++++++++++++++++++++++++++++++ src/nix_util/running_build.rs | 17 ++++++++-- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/nix_util/activity.rs b/src/nix_util/activity.rs index cea406f..775c260 100644 --- a/src/nix_util/activity.rs +++ b/src/nix_util/activity.rs @@ -202,6 +202,68 @@ impl Activity { } } + pub(crate) fn get_progress_text(&self) -> Option> { + match self { + Activity::Root(_activity_root) => { + // TODO + panic!("Attempted to get_progress_text of a root activity."); + } + Activity::Unknown(_activity_unknown) => None, + Activity::CopyPath(activity_copy_path) => Some(Cow::Owned(format!( + "[{}/{}]", + activity_copy_path.done, activity_copy_path.expected + ))), + Activity::FileTransfer(activity_file_transfer) => Some(Cow::Owned(format!( + "[{}/{}]", + activity_file_transfer.done, activity_file_transfer.expected + ))), + Activity::Realize(_activity_realize) => { + // TODO + panic!("Attempted to get_progress_text of a realize activity."); + } + Activity::CopyPaths(activity_copy_paths) => Some(Cow::Owned(format!( + "[{}/{}]", + activity_copy_paths.done, activity_copy_paths.expected + ))), + Activity::Builds(activity_builds) => Some(Cow::Owned(format!( + "[{}/{}]", + activity_builds.done, activity_builds.expected + ))), + Activity::Build(activity_build) => activity_build + .phase + .as_ref() + .map(|phase| Cow::Owned(format!("[{}]", phase))), + Activity::OptimizeStore(_activity_optimize_store) => { + // TODO + panic!("Attempted to get_progress_text of a optimize store activity."); + } + Activity::VerifyPaths(_activity_verify_paths) => { + // TODO + panic!("Attempted to get_progress_text of a verify paths activity."); + } + Activity::Substitute(_activity_substitute) => { + // TODO + panic!("Attempted to get_progress_text of a substitute activity."); + } + Activity::QueryPathInfo(_activity_query_path_info) => { + // TODO + panic!("Attempted to get_progress_text of a query path info activity."); + } + Activity::PostBuildHook(_activity_post_build_hook) => { + // TODO + panic!("Attempted to get_progress_text of a post build hook activity."); + } + Activity::BuildWaiting(_activity_build_waiting) => { + // TODO + panic!("Attempted to get_progress_text of a build waiting activity."); + } + Activity::FetchTree(_activity_fetch_tree) => { + // TODO + panic!("Attempted to get_progress_text of a fetch tree activity."); + } + } + } + pub(crate) fn set_phase(&mut self, phase: Option) -> () { match self { Activity::Root(_activity_root) => { diff --git a/src/nix_util/running_build.rs b/src/nix_util/running_build.rs index 58e4249..7de3198 100644 --- a/src/nix_util/running_build.rs +++ b/src/nix_util/running_build.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use sqlx::Row; use tokio::process::Child; use tracing::error; @@ -302,6 +304,8 @@ impl<'db> RunningBuild<'db> { activity .get_mut_activity() .set_phase(Some(activity_result_set_phase.phase)); + + self.print_current_status(); } ActivityResultMessage::Progress(activity_result_progress) => { let activity_id = self @@ -314,6 +318,8 @@ impl<'db> RunningBuild<'db> { activity_result_progress.running, activity_result_progress.failed, ); + + self.print_current_status(); } ActivityResultMessage::SetExpected(activity_result_set_expected) => { let activity_id = self @@ -323,6 +329,8 @@ impl<'db> RunningBuild<'db> { activity .get_mut_activity() .set_expected(activity_result_set_expected.expected); + + self.print_current_status(); } ActivityResultMessage::PostBuildLogLine( _activity_result_post_build_log_line, @@ -359,9 +367,12 @@ impl<'db> RunningBuild<'db> { .get_activity() .display_name() .expect("Currently we always return a display name."); - let activity_id = activity.get_activity_id(); - let parent_id = activity.get_parent_id(); - tree += &format!("{leading_bars}{branch}𜸟 {display_name} {parent_id} {activity_id}\n"); + let progress_text = activity.get_activity().get_progress_text(); + let (progress, progress_sep) = match progress_text { + Some(text) => (text, " "), + None => (Cow::Borrowed(""), ""), + }; + tree += &format!("{leading_bars}{branch}𜸟 {progress}{progress_sep}{display_name}\n"); } if tree.is_empty() { println!("No active activities.");