Skip to content

Commit d59fee8

Browse files
authored
Merge pull request cachix#1624 from cachix/fixup-logging
devenv: fix empty log lines being printed
2 parents c1ca697 + 5c75348 commit d59fee8

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

devenv-eval-cache/src/internal_log.rs

+73-1
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,27 @@ impl InternalLog {
6161
{
6262
Some(self)
6363
}
64+
6465
InternalLog::Msg { level, .. }
6566
if *level > Verbosity::Error && *level <= target_log_level =>
6667
{
6768
Some(self)
6869
}
6970

71+
// The log levels are also broken for activity messages.
72+
InternalLog::Start {
73+
level: Verbosity::Error,
74+
..
75+
} => {
76+
if target_log_level >= Verbosity::Info {
77+
Some(self)
78+
} else {
79+
None
80+
}
81+
}
82+
7083
InternalLog::Start { level, .. } if *level <= target_log_level => Some(self),
84+
7185
InternalLog::Result {
7286
typ: ResultType::BuildLogLine,
7387
..
@@ -76,13 +90,63 @@ impl InternalLog {
7690
}
7791
}
7892

93+
/// Extract or format a human-readable message from the log.
94+
///
95+
/// Reference for activity messages:
96+
/// https://github.com/NixOS/nix/blob/ff00eebb16fc4c0fd4cebf0cbfc63c471e3c4abd/src/libmain/progress-bar.cc#L177
7997
pub fn get_msg(&self) -> Option<Cow<'_, String>> {
8098
use std::fmt::Write;
8199

82100
match self {
83101
InternalLog::Msg { ref msg, .. } => Some(Cow::Borrowed(msg)),
102+
InternalLog::Start {
103+
typ: ActivityType::Substitute,
104+
fields,
105+
..
106+
} => fields.first().zip(fields.get(1)).and_then(|(path, sub)| {
107+
if let (Field::String(path), Field::String(sub)) = (path, sub) {
108+
let name = store_path_to_name(path);
109+
let action = if sub.starts_with("local") {
110+
"copying"
111+
} else {
112+
"fetching"
113+
};
114+
Some(Cow::Owned(format!("{action} {name} from {sub}")))
115+
} else {
116+
None
117+
}
118+
}),
119+
120+
InternalLog::Start {
121+
typ: ActivityType::Build,
122+
fields,
123+
..
124+
} => {
125+
if let Some(Field::String(name)) = fields.first() {
126+
let name = name.strip_suffix(".drv").unwrap_or(name);
127+
let mut msg = format!("building {name}");
128+
if let Some(Field::String(machine_name)) = fields.get(1) {
129+
write!(msg, " on {machine_name}").ok();
130+
}
131+
Some(Cow::Owned(msg))
132+
} else {
133+
None
134+
}
135+
}
136+
137+
InternalLog::Start {
138+
typ: ActivityType::QueryPathInfo,
139+
fields,
140+
..
141+
} => fields.first().zip(fields.get(1)).and_then(|(path, sub)| {
142+
if let (Field::String(path), Field::String(sub)) = (path, sub) {
143+
let name = store_path_to_name(path);
144+
Some(Cow::Owned(format!("querying {name} on {sub}")))
145+
} else {
146+
None
147+
}
148+
}),
84149

85-
InternalLog::Start { ref text, .. } => Some(Cow::Borrowed(text)),
86150
InternalLog::Result {
87151
typ: ResultType::BuildLogLine,
88152
fields,
@@ -200,6 +264,14 @@ impl Display for Field {
200264
}
201265
}
202266

267+
fn store_path_to_name(path: &str) -> &str {
268+
if let Some((_, name)) = path.split_once('-') {
269+
name
270+
} else {
271+
path
272+
}
273+
}
274+
203275
#[cfg(test)]
204276
mod test {
205277
use super::*;

0 commit comments

Comments
 (0)