From 5c75348b91cc0aba728025f957a2af1324b824bf Mon Sep 17 00:00:00 2001 From: Sander Date: Wed, 4 Dec 2024 05:02:50 +0400 Subject: [PATCH] devenv: fix empty log lines being printed - Builds up activity messages from the log fields. This includes useful network info and fixes an issue where we'd print out empty log lines. - Adjusts the log level for activity messages. These also have broken log levels when streamed from the daemon. --- devenv-eval-cache/src/internal_log.rs | 74 ++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/devenv-eval-cache/src/internal_log.rs b/devenv-eval-cache/src/internal_log.rs index f45138826..ae7ff22a9 100644 --- a/devenv-eval-cache/src/internal_log.rs +++ b/devenv-eval-cache/src/internal_log.rs @@ -61,13 +61,27 @@ impl InternalLog { { Some(self) } + InternalLog::Msg { level, .. } if *level > Verbosity::Error && *level <= target_log_level => { Some(self) } + // The log levels are also broken for activity messages. + InternalLog::Start { + level: Verbosity::Error, + .. + } => { + if target_log_level >= Verbosity::Info { + Some(self) + } else { + None + } + } + InternalLog::Start { level, .. } if *level <= target_log_level => Some(self), + InternalLog::Result { typ: ResultType::BuildLogLine, .. @@ -76,13 +90,63 @@ impl InternalLog { } } + /// Extract or format a human-readable message from the log. + /// + /// Reference for activity messages: + /// https://github.com/NixOS/nix/blob/ff00eebb16fc4c0fd4cebf0cbfc63c471e3c4abd/src/libmain/progress-bar.cc#L177 pub fn get_msg(&self) -> Option> { use std::fmt::Write; match self { InternalLog::Msg { ref msg, .. } => Some(Cow::Borrowed(msg)), + InternalLog::Start { + typ: ActivityType::Substitute, + fields, + .. + } => fields.first().zip(fields.get(1)).and_then(|(path, sub)| { + if let (Field::String(path), Field::String(sub)) = (path, sub) { + let name = store_path_to_name(path); + let action = if sub.starts_with("local") { + "copying" + } else { + "fetching" + }; + Some(Cow::Owned(format!("{action} {name} from {sub}"))) + } else { + None + } + }), + + InternalLog::Start { + typ: ActivityType::Build, + fields, + .. + } => { + if let Some(Field::String(name)) = fields.first() { + let name = name.strip_suffix(".drv").unwrap_or(name); + let mut msg = format!("building {name}"); + if let Some(Field::String(machine_name)) = fields.get(1) { + write!(msg, " on {machine_name}").ok(); + } + Some(Cow::Owned(msg)) + } else { + None + } + } + + InternalLog::Start { + typ: ActivityType::QueryPathInfo, + fields, + .. + } => fields.first().zip(fields.get(1)).and_then(|(path, sub)| { + if let (Field::String(path), Field::String(sub)) = (path, sub) { + let name = store_path_to_name(path); + Some(Cow::Owned(format!("querying {name} on {sub}"))) + } else { + None + } + }), - InternalLog::Start { ref text, .. } => Some(Cow::Borrowed(text)), InternalLog::Result { typ: ResultType::BuildLogLine, fields, @@ -200,6 +264,14 @@ impl Display for Field { } } +fn store_path_to_name(path: &str) -> &str { + if let Some((_, name)) = path.split_once('-') { + name + } else { + path + } +} + #[cfg(test)] mod test { use super::*;