@@ -107,6 +107,58 @@ struct Args {
107
107
targets : Vec < OsString > ,
108
108
}
109
109
110
+ fn print_rules ( rules : & BTreeMap < String , BTreeSet < String > > ) {
111
+ print ! ( "{:?}" , rules) ;
112
+ }
113
+
114
+ /// Parse the makefile at the given path, or the first default makefile found.
115
+ /// If no makefile is found, print an error message and exit.
116
+ fn parse_makefile ( path : Option < impl AsRef < Path > > ) -> Result < Makefile , ErrorCode > {
117
+ let path = path. as_ref ( ) . map ( |p| p. as_ref ( ) ) ;
118
+
119
+ let path = match path {
120
+ Some ( path) => path,
121
+ None => {
122
+ let mut makefile = None ;
123
+ for m in MAKEFILE_PATH . iter ( ) {
124
+ let path = Path :: new ( m) ;
125
+ if path. exists ( ) {
126
+ makefile = Some ( path) ;
127
+ break ;
128
+ }
129
+ }
130
+ if let Some ( makefile) = makefile {
131
+ makefile
132
+ } else {
133
+ return Err ( NoMakefile ) ;
134
+ }
135
+ }
136
+ } ;
137
+
138
+ let contents = if path == Path :: new ( "-" ) {
139
+ read_stdin ( ) ?
140
+ } else {
141
+ match fs:: read_to_string ( path) {
142
+ Ok ( contents) => contents,
143
+ Err ( err) => {
144
+ return Err ( IoError ( err. kind ( ) ) ) ;
145
+ }
146
+ }
147
+ } ;
148
+
149
+ match Makefile :: from_str ( & contents) {
150
+ Ok ( makefile) => Ok ( makefile) ,
151
+ Err ( err) => Err ( ErrorCode :: ParserError { constraint : err } ) ,
152
+ }
153
+ }
154
+
155
+ /// Reads the makefile from `stdin` until EOF (Ctrl + D)
156
+ fn read_stdin ( ) -> Result < String , ErrorCode > {
157
+ let mut buffer = String :: new ( ) ;
158
+ io:: stdin ( ) . read_to_string ( & mut buffer) ?;
159
+ Ok ( buffer)
160
+ }
161
+
110
162
fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
111
163
setlocale ( LocaleCategory :: LcAll , "" ) ;
112
164
textdomain ( env ! ( "PROJECT_NAME" ) ) ?;
@@ -229,55 +281,3 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
229
281
}
230
282
process:: exit ( status_code) ;
231
283
}
232
-
233
- fn print_rules ( rules : & BTreeMap < String , BTreeSet < String > > ) {
234
- print ! ( "{:?}" , rules) ;
235
- }
236
-
237
- /// Parse the makefile at the given path, or the first default makefile found.
238
- /// If no makefile is found, print an error message and exit.
239
- fn parse_makefile ( path : Option < impl AsRef < Path > > ) -> Result < Makefile , ErrorCode > {
240
- let path = path. as_ref ( ) . map ( |p| p. as_ref ( ) ) ;
241
-
242
- let path = match path {
243
- Some ( path) => path,
244
- None => {
245
- let mut makefile = None ;
246
- for m in MAKEFILE_PATH . iter ( ) {
247
- let path = Path :: new ( m) ;
248
- if path. exists ( ) {
249
- makefile = Some ( path) ;
250
- break ;
251
- }
252
- }
253
- if let Some ( makefile) = makefile {
254
- makefile
255
- } else {
256
- return Err ( NoMakefile ) ;
257
- }
258
- }
259
- } ;
260
-
261
- let contents = if path == Path :: new ( "-" ) {
262
- read_stdin ( ) ?
263
- } else {
264
- match fs:: read_to_string ( path) {
265
- Ok ( contents) => contents,
266
- Err ( err) => {
267
- return Err ( IoError ( err. kind ( ) ) ) ;
268
- }
269
- }
270
- } ;
271
-
272
- match Makefile :: from_str ( & contents) {
273
- Ok ( makefile) => Ok ( makefile) ,
274
- Err ( err) => Err ( ErrorCode :: ParserError { constraint : err } ) ,
275
- }
276
- }
277
-
278
- /// Reads the makefile from `stdin` until EOF (Ctrl + D)
279
- fn read_stdin ( ) -> Result < String , ErrorCode > {
280
- let mut buffer = String :: new ( ) ;
281
- io:: stdin ( ) . read_to_string ( & mut buffer) ?;
282
- Ok ( buffer)
283
- }
0 commit comments