@@ -71,27 +71,43 @@ impl std::fmt::Debug for ProcessFailed {
71
71
}
72
72
73
73
trait CommandHelper {
74
- fn capture_outputs (
74
+ fn run_and_capture_outputs (
75
75
& mut self ,
76
76
cant_fail : bool ,
77
77
name : & str ,
78
78
stdout : Option < & PathBuf > ,
79
79
stderr : Option < & PathBuf > ,
80
80
previous_processes_stderr : & [ PathBuf ] ,
81
81
) -> Result < ( ) , TestError > ;
82
+
83
+ fn run_and_capture_stderr (
84
+ & mut self ,
85
+ cant_fail : bool ,
86
+ name : & str ,
87
+ stderr : & PathBuf ,
88
+ previous_processes_stderr : & [ PathBuf ] ,
89
+ ) -> Result < ( ) , TestError > {
90
+ self . run_and_capture_outputs (
91
+ cant_fail,
92
+ name,
93
+ None ,
94
+ Some ( stderr) ,
95
+ previous_processes_stderr,
96
+ )
97
+ }
82
98
}
83
99
84
100
impl CommandHelper for Command {
85
101
#[ tracing:: instrument( skip_all, fields( stdout = tracing:: field:: Empty , stderr = tracing:: field:: Empty ) ) ]
86
- fn capture_outputs (
102
+ fn run_and_capture_outputs (
87
103
& mut self ,
88
104
cant_fail : bool ,
89
105
name : & str ,
90
106
stdout : Option < & PathBuf > ,
91
107
stderr : Option < & PathBuf > ,
92
108
previous_processes_stderr : & [ PathBuf ] ,
93
109
) -> Result < ( ) , TestError > {
94
- let output = self . get_output ( true ) ?;
110
+ let output = self . run_and_get_output ( true ) ?;
95
111
let out_payload = String :: from_utf8_lossy ( & output. stdout ) ;
96
112
if let Some ( out) = stdout {
97
113
file_helper ( & out_payload, out) ?;
@@ -142,41 +158,80 @@ impl TestCase {
142
158
& self ,
143
159
opts : & Opts ,
144
160
bin_path : & Path ,
145
- cli_opts : & Option < Vec < String > > ,
161
+ run_clippy : bool ,
162
+ run_docs : bool ,
163
+ cli_passthrough_opts : & Option < Vec < String > > ,
146
164
) -> Result < Option < Vec < PathBuf > > , TestError > {
147
165
let ( chip_dir, mut process_stderr_paths) = self
148
- . setup_case ( & opts. output_dir , bin_path, cli_opts )
166
+ . setup_case ( & opts. output_dir , bin_path, cli_passthrough_opts )
149
167
. with_context ( || anyhow ! ( "when setting up case for {}" , self . name( ) ) ) ?;
150
168
// Run `cargo check`, capturing stderr to a log file
151
169
if !self . skip_check {
152
170
let cargo_check_err_file = path_helper_base ( & chip_dir, & [ "cargo-check.err.log" ] ) ;
153
171
Command :: new ( "cargo" )
154
172
. arg ( "check" )
155
173
. current_dir ( & chip_dir)
156
- . capture_outputs (
174
+ . run_and_capture_stderr (
157
175
true ,
158
176
"cargo check" ,
159
- None ,
160
- Some ( & cargo_check_err_file) ,
177
+ & cargo_check_err_file,
161
178
& process_stderr_paths,
162
179
)
163
- . with_context ( || "failed to check" ) ?;
180
+ . with_context ( || "failed to check with cargo check " ) ?;
164
181
process_stderr_paths. push ( cargo_check_err_file) ;
165
182
}
183
+ if run_docs {
184
+ tracing:: info!( "Checking docs build" ) ;
185
+ let cargo_docs_err_file = path_helper_base ( & chip_dir, & [ "cargo-docs.err.log" ] ) ;
186
+ // Docs are built like docs.rs would build them. Additionally, build with all features.
187
+
188
+ // Set the RUSTDOCFLAGS environment variable
189
+ let rustdocflags = "--cfg docsrs --generate-link-to-definition -Z unstable-options" ;
190
+ Command :: new ( "cargo" )
191
+ . arg ( "+nightly" )
192
+ . arg ( "doc" )
193
+ . arg ( "--all-features" )
194
+ . env ( "RUSTDOCFLAGS" , rustdocflags) // Set the environment variable
195
+ . current_dir ( & chip_dir)
196
+ . run_and_capture_stderr (
197
+ true ,
198
+ "cargo docs" ,
199
+ & cargo_docs_err_file,
200
+ & process_stderr_paths,
201
+ )
202
+ . with_context ( || "failed to generate docs with cargo docs" ) ?;
203
+ }
204
+ if run_clippy {
205
+ tracing:: info!( "Checking with clippy" ) ;
206
+ let cargo_clippy_err_file = path_helper_base ( & chip_dir, & [ "cargo-clippy.err.log" ] ) ;
207
+ Command :: new ( "cargo" )
208
+ . arg ( "clippy" )
209
+ . arg ( "--" )
210
+ . arg ( "-D" )
211
+ . arg ( "warnings" )
212
+ . current_dir ( & chip_dir)
213
+ . run_and_capture_stderr (
214
+ true ,
215
+ "cargo clippy" ,
216
+ & cargo_clippy_err_file,
217
+ & process_stderr_paths,
218
+ )
219
+ . with_context ( || "failed to check with cargo clippy" ) ?;
220
+ }
166
221
Ok ( if opts. verbose > 1 {
167
222
Some ( process_stderr_paths)
168
223
} else {
169
224
None
170
225
} )
171
226
}
172
227
173
- #[ tracing:: instrument( skip( self , output_dir, command ) , fields( name = %self . name( ) , chip_dir = tracing:: field:: Empty ) ) ]
228
+ #[ tracing:: instrument( skip( self , output_dir, passthrough_opts ) , fields( name = %self . name( ) , chip_dir = tracing:: field:: Empty ) ) ]
174
229
175
230
pub fn setup_case (
176
231
& self ,
177
232
output_dir : & Path ,
178
233
svd2rust_bin_path : & Path ,
179
- command : & Option < Vec < String > > ,
234
+ passthrough_opts : & Option < Vec < String > > ,
180
235
) -> Result < ( PathBuf , Vec < PathBuf > ) , TestError > {
181
236
let user = match std:: env:: var ( "USER" ) {
182
237
Ok ( val) => val,
@@ -209,10 +264,10 @@ impl TestCase {
209
264
. arg ( "none" )
210
265
. arg ( "--lib" )
211
266
. arg ( & chip_dir)
212
- . capture_outputs ( true , "cargo init" , None , None , & [ ] )
267
+ . run_and_capture_outputs ( true , "cargo init" , None , None , & [ ] )
213
268
. with_context ( || "Failed to cargo init" ) ?;
214
269
215
- self . prepare_chip_test_toml ( & chip_dir, command ) ?;
270
+ self . prepare_chip_test_toml ( & chip_dir, passthrough_opts ) ?;
216
271
let chip_svd = self . prepare_svd_file ( & chip_dir) ?;
217
272
self . prepare_rust_toolchain_file ( & chip_dir) ?;
218
273
@@ -225,7 +280,7 @@ impl TestCase {
225
280
& chip_dir,
226
281
& lib_rs_file,
227
282
& svd2rust_err_file,
228
- command ,
283
+ passthrough_opts ,
229
284
) ?;
230
285
process_stderr_paths. push ( svd2rust_err_file) ;
231
286
match self . arch {
@@ -261,7 +316,7 @@ impl TestCase {
261
316
. arg ( & new_lib_rs_file)
262
317
. arg ( "--outdir" )
263
318
. arg ( & src_dir)
264
- . capture_outputs (
319
+ . run_and_capture_outputs (
265
320
true ,
266
321
"form" ,
267
322
None ,
@@ -290,7 +345,7 @@ impl TestCase {
290
345
Command :: new ( rustfmt_bin_path)
291
346
. arg ( entry)
292
347
. args ( [ "--edition" , "2021" ] )
293
- . capture_outputs (
348
+ . run_and_capture_outputs (
294
349
false ,
295
350
"rustfmt" ,
296
351
None ,
@@ -416,7 +471,7 @@ impl TestCase {
416
471
if let Some ( opts) = self . opts . as_ref ( ) {
417
472
base_cmd. args ( opts) ;
418
473
}
419
- base_cmd. current_dir ( chip_dir) . capture_outputs (
474
+ base_cmd. current_dir ( chip_dir) . run_and_capture_outputs (
420
475
true ,
421
476
"svd2rust" ,
422
477
Some ( lib_rs_file) . filter ( |_| {
0 commit comments