@@ -18,7 +18,13 @@ use crate::{
1818 parser:: { Rule as ParsedRule , VariableDefinition } ,
1919 signal_handler, DEFAULT_SHELL , DEFAULT_SHELL_VAR ,
2020} ;
21+ use config:: Config ;
22+ use gettextrs:: gettext;
23+ use prerequisite:: Prerequisite ;
24+ use recipe:: config:: Config as RecipeConfig ;
25+ use recipe:: Recipe ;
2126use std:: collections:: VecDeque ;
27+ use std:: io:: ErrorKind ;
2228use std:: path:: PathBuf ;
2329use std:: {
2430 collections:: HashMap ,
@@ -28,17 +34,12 @@ use std::{
2834 sync:: { Arc , LazyLock , Mutex } ,
2935 time:: SystemTime ,
3036} ;
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 ;
3737use target:: Target ;
3838
3939type LazyArcMutex < T > = LazyLock < Arc < Mutex < T > > > ;
4040
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 ) ) ) ;
4243
4344#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
4445pub struct Rule {
@@ -53,15 +54,15 @@ pub struct Rule {
5354}
5455
5556impl Rule {
56- pub fn targets ( & self ) -> impl Iterator < Item = & Target > {
57+ pub fn targets ( & self ) -> impl Iterator < Item = & Target > {
5758 self . targets . iter ( )
5859 }
5960
60- pub fn prerequisites ( & self ) -> impl Iterator < Item = & Prerequisite > {
61+ pub fn prerequisites ( & self ) -> impl Iterator < Item = & Prerequisite > {
6162 self . prerequisites . iter ( )
6263 }
6364
64- pub fn recipes ( & self ) -> impl Iterator < Item = & Recipe > {
65+ pub fn recipes ( & self ) -> impl Iterator < Item = & Recipe > {
6566 self . recipes . iter ( )
6667 }
6768
@@ -97,11 +98,14 @@ impl Rule {
9798 } = self . config ;
9899
99100 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 < _ > > ( ) ,
105109 _ => {
106110 vec ! [ ( PathBuf :: from( "" ) , PathBuf :: from( "" ) ) ]
107111 }
@@ -160,11 +164,15 @@ impl Rule {
160164 }
161165
162166 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 ) ,
164171 ) ;
165172
166173 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 ( ) ) ;
168176 command. args ( [ "-c" , recipe. as_ref ( ) ] ) ;
169177
170178 let status = match command. status ( ) {
@@ -217,7 +225,7 @@ impl Rule {
217225 target : & Target ,
218226 recipe : & Recipe ,
219227 files : & ( PathBuf , PathBuf ) ,
220- mut prereqs : impl Iterator < Item = & ' a Prerequisite > ,
228+ mut prereqs : impl Iterator < Item = & ' a Prerequisite > ,
221229 ) -> Recipe {
222230 let recipe = recipe. inner ( ) ;
223231 let mut stream = recipe. chars ( ) ;
@@ -230,18 +238,20 @@ impl Rule {
230238 }
231239
232240 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+ }
238246 Some ( '%' ) => {
239247 if let Some ( body) = target. as_ref ( ) . split ( '(' ) . nth ( 1 ) {
240248 result. push_str ( body. strip_suffix ( ')' ) . unwrap_or ( body) )
241249 }
242250 }
243251 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) ) ;
245255 }
246256 Some ( '$' ) => result. push ( '$' ) ,
247257 Some ( '<' ) => result. push_str ( files. 0 . to_str ( ) . unwrap ( ) ) ,
@@ -258,12 +268,15 @@ impl Rule {
258268
259269 /// A helper function to initialize env vars for shell commands.
260270 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 ( ) ;
267280
268281 if env_macros {
269282 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> {
298311 use std:: { env, fs} ;
299312
300313 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+ } ;
302317 let mut dirs_to_walk = VecDeque :: new ( ) ;
303318 dirs_to_walk. push_back ( current) ;
304319
0 commit comments