10
10
*/
11
11
12
12
use aml:: { AmlContext , DebugVerbosity } ;
13
- use clap:: { Arg , ArgGroup , ArgAction } ;
13
+ use clap:: { Arg , ArgAction , ArgGroup } ;
14
14
use std:: {
15
+ collections:: HashSet ,
15
16
ffi:: OsStr ,
16
17
fs:: { self , File } ,
17
18
io:: { Read , Write } ,
18
19
path:: { Path , PathBuf } ,
19
20
process:: Command ,
20
- collections:: HashSet ,
21
21
} ;
22
22
23
23
enum CompilationOutcome {
@@ -48,17 +48,21 @@ fn main() -> std::io::Result<()> {
48
48
let files: Vec < String > = if matches. contains_id ( "path" ) {
49
49
let dir_path = Path :: new ( matches. get_one :: < String > ( "path" ) . unwrap ( ) ) ;
50
50
println ! ( "Running tests in directory: {:?}" , dir_path) ;
51
- fs:: read_dir ( dir_path) ?. filter_map ( | entry | if entry. is_ok ( ) {
52
- Some ( entry. unwrap ( ) . path ( ) . to_string_lossy ( ) . to_string ( ) )
53
- } else {
54
- None
55
- } ) . collect ( )
51
+ fs:: read_dir ( dir_path) ?
52
+ . filter_map ( |entry| {
53
+ if entry. is_ok ( ) {
54
+ Some ( entry. unwrap ( ) . path ( ) . to_string_lossy ( ) . to_string ( ) )
55
+ } else {
56
+ None
57
+ }
58
+ } )
59
+ . collect ( )
56
60
} else {
57
- matches. get_many :: < String > ( "files" ) . unwrap_or_default ( ) . map ( | name | name. to_string ( ) ) . collect ( )
61
+ matches. get_many :: < String > ( "files" ) . unwrap_or_default ( ) . map ( |name| name. to_string ( ) ) . collect ( )
58
62
} ;
59
63
60
64
// Make sure all files exist, propagate error if it occurs
61
- files. iter ( ) . fold ( Ok ( ( ) ) , | result : std:: io:: Result < ( ) > , file | {
65
+ files. iter ( ) . fold ( Ok ( ( ) ) , |result : std:: io:: Result < ( ) > , file| {
62
66
let path = Path :: new ( file) ;
63
67
if !path. is_file ( ) {
64
68
println ! ( "Not a regular file: {}" , file) ;
@@ -80,42 +84,52 @@ fn main() -> std::io::Result<()> {
80
84
Err ( _) => false ,
81
85
} ;
82
86
83
- let compiled_files: Vec < CompilationOutcome > = files. iter ( ) . map ( | name | resolve_and_compile ( name, can_compile) . unwrap ( ) ) . collect ( ) ;
87
+ let compiled_files: Vec < CompilationOutcome > =
88
+ files. iter ( ) . map ( |name| resolve_and_compile ( name, can_compile) . unwrap ( ) ) . collect ( ) ;
84
89
85
90
// Check if compilation should have happened but did not
86
- if user_wants_compile && compiled_files. iter ( ) . any ( | outcome | matches ! ( outcome, CompilationOutcome :: NotCompiled ( _) ) ) {
87
- panic ! ( "`iasl` is not installed, but we want to compile some ASL files! Pass --no-compile, or install `iasl`" ) ;
91
+ if user_wants_compile
92
+ && compiled_files. iter ( ) . any ( |outcome| matches ! ( outcome, CompilationOutcome :: NotCompiled ( _) ) )
93
+ {
94
+ panic ! (
95
+ "`iasl` is not installed, but we want to compile some ASL files! Pass --no-compile, or install `iasl`"
96
+ ) ;
88
97
}
89
98
// Report compilation results
90
99
if user_wants_compile {
91
- let ( passed, failed) = compiled_files. iter ( )
92
- . fold ( ( 0 , 0 ) , | ( passed, failed) , outcome | match outcome {
93
- CompilationOutcome :: Succeeded ( _) => ( passed + 1 , failed) ,
94
- CompilationOutcome :: Failed ( _) => ( passed, failed + 1 ) ,
95
- _ => ( passed, failed) ,
100
+ let ( passed, failed) = compiled_files. iter ( ) . fold ( ( 0 , 0 ) , |( passed, failed) , outcome| match outcome {
101
+ CompilationOutcome :: Succeeded ( _) => ( passed + 1 , failed) ,
102
+ CompilationOutcome :: Failed ( _) => ( passed, failed + 1 ) ,
103
+ _ => ( passed, failed) ,
96
104
} ) ;
97
105
if passed + failed > 0 {
98
106
println ! ( "Compiled {} ASL files: {} passed, {} failed." , passed + failed, passed, failed) ;
107
+ println ! ( ) ;
99
108
}
100
109
}
101
110
102
111
// Make a list of the files we have processed, and skip them if we see them again
103
112
let mut dedup_list: HashSet < PathBuf > = HashSet :: new ( ) ;
104
113
105
114
// Filter down to the final list of AML files
106
- let aml_files = compiled_files. iter ( )
107
- . filter_map ( | outcome | match outcome {
115
+ let aml_files = compiled_files
116
+ . iter ( )
117
+ . filter_map ( |outcome| match outcome {
108
118
CompilationOutcome :: IsAml ( path) => Some ( path. clone ( ) ) ,
109
119
CompilationOutcome :: Newer ( path) => Some ( path. clone ( ) ) ,
110
120
CompilationOutcome :: Succeeded ( path) => Some ( path. clone ( ) ) ,
111
- CompilationOutcome :: Ignored | CompilationOutcome :: Failed ( _) | CompilationOutcome :: NotCompiled ( _) => None ,
121
+ CompilationOutcome :: Ignored | CompilationOutcome :: Failed ( _) | CompilationOutcome :: NotCompiled ( _) => {
122
+ None
123
+ }
112
124
} )
113
- . filter ( | path | if dedup_list. contains ( path) {
114
- false
115
- } else {
116
- dedup_list. insert ( path. clone ( ) ) ;
117
- true
118
- } ) ;
125
+ . filter ( |path| {
126
+ if dedup_list. contains ( path) {
127
+ false
128
+ } else {
129
+ dedup_list. insert ( path. clone ( ) ) ;
130
+ true
131
+ }
132
+ } ) ;
119
133
120
134
let user_wants_reset = matches. get_flag ( "reset" ) ;
121
135
let mut context = AmlContext :: new ( Box :: new ( Handler ) , DebugVerbosity :: None ) ;
@@ -129,7 +143,7 @@ fn main() -> std::io::Result<()> {
129
143
file. read_to_end ( & mut contents) . unwrap ( ) ;
130
144
131
145
const AML_TABLE_HEADER_LENGTH : usize = 36 ;
132
-
146
+
133
147
if user_wants_reset {
134
148
context = AmlContext :: new ( Box :: new ( Handler ) , DebugVerbosity :: None ) ;
135
149
}
@@ -178,14 +192,14 @@ fn resolve_and_compile(name: &str, can_compile: bool) -> std::io::Result<Compila
178
192
// If the aml is more recent than the asl, use the existing aml
179
193
// Otherwise continue to compilation
180
194
if asl_last_modified <= aml_last_modified {
181
- return Ok ( CompilationOutcome :: Newer ( aml_path) )
195
+ return Ok ( CompilationOutcome :: Newer ( aml_path) ) ;
182
196
}
183
197
}
184
198
185
199
if !can_compile {
186
200
return Ok ( CompilationOutcome :: NotCompiled ( path) ) ;
187
201
}
188
-
202
+
189
203
// Compile the ASL file using `iasl`
190
204
println ! ( "Compiling file: {}" , name) ;
191
205
let output = Command :: new ( "iasl" ) . arg ( name) . output ( ) ?;
0 commit comments