@@ -18,7 +18,13 @@ use crate::{
18
18
parser:: { Rule as ParsedRule , VariableDefinition } ,
19
19
signal_handler, DEFAULT_SHELL , DEFAULT_SHELL_VAR ,
20
20
} ;
21
+ use config:: Config ;
22
+ use gettextrs:: gettext;
23
+ use prerequisite:: Prerequisite ;
24
+ use recipe:: config:: Config as RecipeConfig ;
25
+ use recipe:: Recipe ;
21
26
use std:: collections:: VecDeque ;
27
+ use std:: io:: ErrorKind ;
22
28
use std:: path:: PathBuf ;
23
29
use std:: {
24
30
collections:: HashMap ,
@@ -28,17 +34,12 @@ use std::{
28
34
sync:: { Arc , LazyLock , Mutex } ,
29
35
time:: SystemTime ,
30
36
} ;
31
- use std:: io:: ErrorKind ;
32
- use config:: Config ;
33
- use gettextrs:: gettext;
34
- use prerequisite:: Prerequisite ;
35
- use recipe:: config:: Config as RecipeConfig ;
36
- use recipe:: Recipe ;
37
37
use target:: Target ;
38
38
39
39
type LazyArcMutex < T > = LazyLock < Arc < Mutex < T > > > ;
40
40
41
- pub static INTERRUPT_FLAG : LazyArcMutex < Option < ( String , bool ) > > = LazyLock :: new ( || Arc :: new ( Mutex :: new ( None ) ) ) ;
41
+ pub static INTERRUPT_FLAG : LazyArcMutex < Option < ( String , bool ) > > =
42
+ LazyLock :: new ( || Arc :: new ( Mutex :: new ( None ) ) ) ;
42
43
43
44
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
44
45
pub struct Rule {
@@ -53,15 +54,15 @@ pub struct Rule {
53
54
}
54
55
55
56
impl Rule {
56
- pub fn targets ( & self ) -> impl Iterator < Item = & Target > {
57
+ pub fn targets ( & self ) -> impl Iterator < Item = & Target > {
57
58
self . targets . iter ( )
58
59
}
59
60
60
- pub fn prerequisites ( & self ) -> impl Iterator < Item = & Prerequisite > {
61
+ pub fn prerequisites ( & self ) -> impl Iterator < Item = & Prerequisite > {
61
62
self . prerequisites . iter ( )
62
63
}
63
64
64
- pub fn recipes ( & self ) -> impl Iterator < Item = & Recipe > {
65
+ pub fn recipes ( & self ) -> impl Iterator < Item = & Recipe > {
65
66
self . recipes . iter ( )
66
67
}
67
68
@@ -97,11 +98,14 @@ impl Rule {
97
98
} = self . config ;
98
99
99
100
let files = match target {
100
- Target :: Inference { name, from, to } => find_files_with_extension ( from) ?. into_iter ( ) . map ( |input| {
101
- let mut output = input. clone ( ) ;
102
- output. set_extension ( to) ;
103
- ( input, output)
104
- } ) . collect :: < Vec < _ > > ( ) ,
101
+ Target :: Inference { from, to, .. } => find_files_with_extension ( from) ?
102
+ . into_iter ( )
103
+ . map ( |input| {
104
+ let mut output = input. clone ( ) ;
105
+ output. set_extension ( to) ;
106
+ ( input, output)
107
+ } )
108
+ . collect :: < Vec < _ > > ( ) ,
105
109
_ => {
106
110
vec ! [ ( PathBuf :: from( "" ) , PathBuf :: from( "" ) ) ]
107
111
}
@@ -160,11 +164,15 @@ impl Rule {
160
164
}
161
165
162
166
let mut command = Command :: new (
163
- env:: var ( DEFAULT_SHELL_VAR ) . as_ref ( ) . map ( |s| s. as_str ( ) ) . unwrap_or ( DEFAULT_SHELL ) ,
167
+ env:: var ( DEFAULT_SHELL_VAR )
168
+ . as_ref ( )
169
+ . map ( |s| s. as_str ( ) )
170
+ . unwrap_or ( DEFAULT_SHELL ) ,
164
171
) ;
165
172
166
173
self . init_env ( env_macros, & mut command, macros) ;
167
- let recipe = self . substitute_internal_macros ( target, recipe, & inout, self . prerequisites ( ) ) ;
174
+ let recipe =
175
+ self . substitute_internal_macros ( target, recipe, & inout, self . prerequisites ( ) ) ;
168
176
command. args ( [ "-c" , recipe. as_ref ( ) ] ) ;
169
177
170
178
let status = match command. status ( ) {
@@ -217,7 +225,7 @@ impl Rule {
217
225
target : & Target ,
218
226
recipe : & Recipe ,
219
227
files : & ( PathBuf , PathBuf ) ,
220
- mut prereqs : impl Iterator < Item = & ' a Prerequisite > ,
228
+ mut prereqs : impl Iterator < Item = & ' a Prerequisite > ,
221
229
) -> Recipe {
222
230
let recipe = recipe. inner ( ) ;
223
231
let mut stream = recipe. chars ( ) ;
@@ -230,18 +238,20 @@ impl Rule {
230
238
}
231
239
232
240
match stream. next ( ) {
233
- Some ( '@' ) => if let Some ( s ) = target . as_ref ( ) . split ( '(' ) . next ( ) {
234
- result . push_str (
235
- s
236
- )
237
- } ,
241
+ Some ( '@' ) => {
242
+ if let Some ( s ) = target . as_ref ( ) . split ( '(' ) . next ( ) {
243
+ result . push_str ( s )
244
+ }
245
+ }
238
246
Some ( '%' ) => {
239
247
if let Some ( body) = target. as_ref ( ) . split ( '(' ) . nth ( 1 ) {
240
248
result. push_str ( body. strip_suffix ( ')' ) . unwrap_or ( body) )
241
249
}
242
250
}
243
251
Some ( '?' ) => {
244
- ( & mut prereqs) . map ( |x| x. as_ref ( ) ) . for_each ( |x| result. push_str ( x) ) ;
252
+ ( & mut prereqs)
253
+ . map ( |x| x. as_ref ( ) )
254
+ . for_each ( |x| result. push_str ( x) ) ;
245
255
}
246
256
Some ( '$' ) => result. push ( '$' ) ,
247
257
Some ( '<' ) => result. push_str ( files. 0 . to_str ( ) . unwrap ( ) ) ,
@@ -258,12 +268,15 @@ impl Rule {
258
268
259
269
/// A helper function to initialize env vars for shell commands.
260
270
fn init_env ( & self , env_macros : bool , command : & mut Command , variables : & [ VariableDefinition ] ) {
261
- let mut macros: HashMap < String , String > = variables. iter ( ) . map ( |v| {
262
- (
263
- v. name ( ) . unwrap_or_default ( ) ,
264
- v. raw_value ( ) . unwrap_or_default ( ) ,
265
- )
266
- } ) . collect ( ) ;
271
+ let mut macros: HashMap < String , String > = variables
272
+ . iter ( )
273
+ . map ( |v| {
274
+ (
275
+ v. name ( ) . unwrap_or_default ( ) ,
276
+ v. raw_value ( ) . unwrap_or_default ( ) ,
277
+ )
278
+ } )
279
+ . collect ( ) ;
267
280
268
281
if env_macros {
269
282
let env_vars: HashMap < String , String > = std:: env:: vars ( ) . collect ( ) ;
@@ -298,7 +311,9 @@ fn find_files_with_extension(ext: &str) -> Result<Vec<PathBuf>, ErrorCode> {
298
311
use std:: { env, fs} ;
299
312
300
313
let mut result = vec ! [ ] ;
301
- let Ok ( current) = env:: current_dir ( ) else { Err ( IoError ( ErrorKind :: PermissionDenied ) ) ? } ;
314
+ let Ok ( current) = env:: current_dir ( ) else {
315
+ Err ( IoError ( ErrorKind :: PermissionDenied ) ) ?
316
+ } ;
302
317
let mut dirs_to_walk = VecDeque :: new ( ) ;
303
318
dirs_to_walk. push_back ( current) ;
304
319
0 commit comments