@@ -61,13 +61,27 @@ impl InternalLog {
61
61
{
62
62
Some ( self )
63
63
}
64
+
64
65
InternalLog :: Msg { level, .. }
65
66
if * level > Verbosity :: Error && * level <= target_log_level =>
66
67
{
67
68
Some ( self )
68
69
}
69
70
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
+
70
83
InternalLog :: Start { level, .. } if * level <= target_log_level => Some ( self ) ,
84
+
71
85
InternalLog :: Result {
72
86
typ : ResultType :: BuildLogLine ,
73
87
..
@@ -76,13 +90,63 @@ impl InternalLog {
76
90
}
77
91
}
78
92
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
79
97
pub fn get_msg ( & self ) -> Option < Cow < ' _ , String > > {
80
98
use std:: fmt:: Write ;
81
99
82
100
match self {
83
101
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
+ } ) ,
84
149
85
- InternalLog :: Start { ref text, .. } => Some ( Cow :: Borrowed ( text) ) ,
86
150
InternalLog :: Result {
87
151
typ : ResultType :: BuildLogLine ,
88
152
fields,
@@ -200,6 +264,14 @@ impl Display for Field {
200
264
}
201
265
}
202
266
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
+
203
275
#[ cfg( test) ]
204
276
mod test {
205
277
use super :: * ;
0 commit comments