@@ -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,98 @@ 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_stable : bool ,
163
+ run_docs_nightly : bool ,
164
+ cli_passthrough_opts : & Option < Vec < String > > ,
146
165
) -> Result < Option < Vec < PathBuf > > , TestError > {
147
166
let ( chip_dir, mut process_stderr_paths) = self
148
- . setup_case ( & opts. output_dir , bin_path, cli_opts )
167
+ . setup_case ( & opts. output_dir , bin_path, cli_passthrough_opts )
149
168
. with_context ( || anyhow ! ( "when setting up case for {}" , self . name( ) ) ) ?;
150
169
// Run `cargo check`, capturing stderr to a log file
151
170
if !self . skip_check {
152
171
let cargo_check_err_file = path_helper_base ( & chip_dir, & [ "cargo-check.err.log" ] ) ;
153
172
Command :: new ( "cargo" )
154
173
. arg ( "check" )
155
174
. current_dir ( & chip_dir)
156
- . capture_outputs (
175
+ . run_and_capture_stderr (
157
176
true ,
158
177
"cargo check" ,
159
- None ,
160
- Some ( & cargo_check_err_file) ,
178
+ & cargo_check_err_file,
161
179
& process_stderr_paths,
162
180
)
163
- . with_context ( || "failed to check" ) ?;
181
+ . with_context ( || "failed to check with cargo check " ) ?;
164
182
process_stderr_paths. push ( cargo_check_err_file) ;
165
183
}
184
+ if run_docs_nightly {
185
+ tracing:: info!( "Checking docs build with nightly" ) ;
186
+ let cargo_docs_err_file = path_helper_base ( & chip_dir, & [ "cargo-docs-nightly.err.log" ] ) ;
187
+ // Docs are built like docs.rs would build them. Additionally, build with all features.
188
+
189
+ // Set the RUSTDOCFLAGS environment variable
190
+ let rustdocflags = "--cfg docsrs --generate-link-to-definition -Z unstable-options" ;
191
+ Command :: new ( "cargo" )
192
+ . arg ( "+nightly" )
193
+ . arg ( "doc" )
194
+ . arg ( "--all-features" )
195
+ . env ( "RUSTDOCFLAGS" , rustdocflags) // Set the environment variable
196
+ . current_dir ( & chip_dir)
197
+ . run_and_capture_stderr (
198
+ true ,
199
+ "cargo docs nightly" ,
200
+ & cargo_docs_err_file,
201
+ & process_stderr_paths,
202
+ )
203
+ . with_context ( || "failed to generate docs with cargo docs" ) ?;
204
+ }
205
+ if run_docs_stable {
206
+ tracing:: info!( "Checking docs build with stable" ) ;
207
+ let cargo_docs_err_file = path_helper_base ( & chip_dir, & [ "cargo-docs-stable.err.log" ] ) ;
208
+ // Docs are built like docs.rs would build them. Additionally, build with all features.
209
+ Command :: new ( "cargo" )
210
+ . arg ( "+stable" )
211
+ . arg ( "doc" )
212
+ . arg ( "--all-features" )
213
+ . current_dir ( & chip_dir)
214
+ . run_and_capture_stderr (
215
+ true ,
216
+ "cargo docs stable" ,
217
+ & cargo_docs_err_file,
218
+ & process_stderr_paths,
219
+ )
220
+ . with_context ( || "failed to generate docs with cargo docs" ) ?;
221
+ }
222
+ if run_clippy {
223
+ tracing:: info!( "Checking with clippy" ) ;
224
+ let cargo_clippy_err_file = path_helper_base ( & chip_dir, & [ "cargo-clippy.err.log" ] ) ;
225
+ Command :: new ( "cargo" )
226
+ . arg ( "clippy" )
227
+ . arg ( "--" )
228
+ . arg ( "-D" )
229
+ . arg ( "warnings" )
230
+ . current_dir ( & chip_dir)
231
+ . run_and_capture_stderr (
232
+ true ,
233
+ "cargo clippy" ,
234
+ & cargo_clippy_err_file,
235
+ & process_stderr_paths,
236
+ )
237
+ . with_context ( || "failed to check with cargo clippy" ) ?;
238
+ }
166
239
Ok ( if opts. verbose > 1 {
167
240
Some ( process_stderr_paths)
168
241
} else {
169
242
None
170
243
} )
171
244
}
172
245
173
- #[ tracing:: instrument( skip( self , output_dir, command ) , fields( name = %self . name( ) , chip_dir = tracing:: field:: Empty ) ) ]
246
+ #[ tracing:: instrument( skip( self , output_dir, passthrough_opts ) , fields( name = %self . name( ) , chip_dir = tracing:: field:: Empty ) ) ]
174
247
175
248
pub fn setup_case (
176
249
& self ,
177
250
output_dir : & Path ,
178
251
svd2rust_bin_path : & Path ,
179
- command : & Option < Vec < String > > ,
252
+ passthrough_opts : & Option < Vec < String > > ,
180
253
) -> Result < ( PathBuf , Vec < PathBuf > ) , TestError > {
181
254
let user = match std:: env:: var ( "USER" ) {
182
255
Ok ( val) => val,
@@ -209,10 +282,10 @@ impl TestCase {
209
282
. arg ( "none" )
210
283
. arg ( "--lib" )
211
284
. arg ( & chip_dir)
212
- . capture_outputs ( true , "cargo init" , None , None , & [ ] )
285
+ . run_and_capture_outputs ( true , "cargo init" , None , None , & [ ] )
213
286
. with_context ( || "Failed to cargo init" ) ?;
214
287
215
- self . prepare_chip_test_toml ( & chip_dir, command ) ?;
288
+ self . prepare_chip_test_toml ( & chip_dir, passthrough_opts ) ?;
216
289
let chip_svd = self . prepare_svd_file ( & chip_dir) ?;
217
290
self . prepare_rust_toolchain_file ( & chip_dir) ?;
218
291
@@ -225,7 +298,7 @@ impl TestCase {
225
298
& chip_dir,
226
299
& lib_rs_file,
227
300
& svd2rust_err_file,
228
- command ,
301
+ passthrough_opts ,
229
302
) ?;
230
303
process_stderr_paths. push ( svd2rust_err_file) ;
231
304
match self . arch {
@@ -261,7 +334,7 @@ impl TestCase {
261
334
. arg ( & new_lib_rs_file)
262
335
. arg ( "--outdir" )
263
336
. arg ( & src_dir)
264
- . capture_outputs (
337
+ . run_and_capture_outputs (
265
338
true ,
266
339
"form" ,
267
340
None ,
@@ -290,7 +363,7 @@ impl TestCase {
290
363
Command :: new ( rustfmt_bin_path)
291
364
. arg ( entry)
292
365
. args ( [ "--edition" , "2021" ] )
293
- . capture_outputs (
366
+ . run_and_capture_outputs (
294
367
false ,
295
368
"rustfmt" ,
296
369
None ,
@@ -416,7 +489,7 @@ impl TestCase {
416
489
if let Some ( opts) = self . opts . as_ref ( ) {
417
490
base_cmd. args ( opts) ;
418
491
}
419
- base_cmd. current_dir ( chip_dir) . capture_outputs (
492
+ base_cmd. current_dir ( chip_dir) . run_and_capture_outputs (
420
493
true ,
421
494
"svd2rust" ,
422
495
Some ( lib_rs_file) . filter ( |_| {
0 commit comments