Skip to content

Commit 4e25011

Browse files
committed
update CI to run clippy and docs
1 parent 93918f0 commit 4e25011

File tree

5 files changed

+125
-34
lines changed

5 files changed

+125
-34
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ jobs:
5757
fail-fast: false
5858
matrix:
5959
include:
60-
- { vendor: Atmel }
61-
- { vendor: Atmel, options: "-- --strict --atomics" }
62-
- { vendor: Freescale }
63-
- { vendor: Freescale, options: "-- --strict --atomics" }
60+
- { vendor: atmel }
61+
- { vendor: atmel, options: "-- --strict --atomics" }
62+
- { vendor: freescale }
63+
- { vendor: freescale, options: "-- --strict --atomics" }
6464
- { vendor: Fujitsu }
6565
- { vendor: Fujitsu, options: "-- --atomics" }
6666
- { vendor: Holtek }
@@ -123,9 +123,18 @@ jobs:
123123
# stable.
124124
run: cargo +stable regress tests --toolchain 1.76.0 -m Nordic -- --strict --atomics
125125

126-
ci-clippy:
126+
ci-docs-clippy:
127127
runs-on: ubuntu-latest
128128
needs: [check]
129+
strategy:
130+
fail-fast: false
131+
matrix:
132+
include:
133+
- { chip: STM32F030 }
134+
- { chip: STM32F410 }
135+
- { chip: esp32c3 }
136+
- { chip: MKW41Z4 }
137+
- { chip: nrf51 }
129138
steps:
130139
- uses: actions/checkout@v4
131140

@@ -140,12 +149,8 @@ jobs:
140149
run: |
141150
cargo install svd2rust --path .
142151
143-
- name: Run CI script
144-
env:
145-
VENDOR: RISC-V
146-
OPTIONS: ""
147-
COMMAND: clippy
148-
run: bash ci/script.sh
152+
- name: Check docs and clippy on generated PACs
153+
run: cargo regress test -c ${{ matrix.chip }} --docs --clippy ${{ matrix.options }}
149154

150155
ci-serde:
151156
runs-on: ubuntu-latest

ci/svd2rust-regress/src/command.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ pub trait CommandExt {
77
fn run(&mut self, hide: bool) -> Result<(), anyhow::Error>;
88

99
#[track_caller]
10-
fn get_output(&mut self, can_fail: bool) -> Result<std::process::Output, anyhow::Error>;
10+
fn run_and_get_output(&mut self, can_fail: bool)
11+
-> Result<std::process::Output, anyhow::Error>;
1112

1213
#[track_caller]
1314
fn get_output_string(&mut self) -> Result<String, anyhow::Error>;
@@ -33,7 +34,10 @@ impl CommandExt for Command {
3334
}
3435

3536
#[track_caller]
36-
fn get_output(&mut self, can_fail: bool) -> Result<std::process::Output, anyhow::Error> {
37+
fn run_and_get_output(
38+
&mut self,
39+
can_fail: bool,
40+
) -> Result<std::process::Output, anyhow::Error> {
3741
let output = self
3842
.output()
3943
.with_context(|| format!("command `{}` couldn't be run", self.display()))?;
@@ -51,7 +55,7 @@ impl CommandExt for Command {
5155

5256
#[track_caller]
5357
fn get_output_string(&mut self) -> Result<String, anyhow::Error> {
54-
String::from_utf8(self.get_output(true)?.stdout).map_err(Into::into)
58+
String::from_utf8(self.run_and_get_output(true)?.stdout).map_err(Into::into)
5559
}
5660

5761
fn display(&self) -> String {

ci/svd2rust-regress/src/github.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub fn get_release_binary_artifact(
148148
Command::new("gzip")
149149
.arg("-d")
150150
.arg(output_dir.join(artifact))
151-
.get_output(false)?;
151+
.run_and_get_output(false)?;
152152
}
153153
}
154154
_ => {

ci/svd2rust-regress/src/main.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ pub struct TestAll {
9090
/// Enable splitting `lib.rs` with `form`
9191
pub form_lib: bool,
9292

93+
/// Check generated crates with clippy.
94+
#[clap(long)]
95+
pub clippy: bool,
96+
97+
/// Check documentation build.
98+
#[clap(long)]
99+
pub docs: bool,
100+
93101
/// Print all available test using the specified filters
94102
#[clap(long)]
95103
pub list: bool,
@@ -143,6 +151,13 @@ pub struct Test {
143151
/// Chip to use, use `--url` or `--svd-file` for another way to specify svd
144152
pub chip: Option<String>,
145153

154+
/// Check generated crate with clippy.
155+
#[arg(long)]
156+
pub clippy: bool,
157+
/// Check documentation build.
158+
#[arg(long)]
159+
pub docs: bool,
160+
146161
/// Path to an `svd2rust` binary, relative or absolute.
147162
/// Defaults to `target/release/svd2rust[.exe]` of this repository
148163
/// (which must be already built)
@@ -191,7 +206,13 @@ impl Test {
191206
.ok_or_else(|| anyhow::anyhow!("no test found for chip"))?
192207
.to_owned()
193208
};
194-
test.test(opts, &self.current_bin_path, &self.passthrough_opts)?;
209+
test.test(
210+
opts,
211+
&self.current_bin_path,
212+
self.clippy,
213+
self.docs,
214+
&self.passthrough_opts,
215+
)?;
195216
Ok(())
196217
}
197218
}
@@ -247,7 +268,13 @@ impl TestAll {
247268
tests.par_iter().for_each(|t| {
248269
let start = Instant::now();
249270

250-
match t.test(opt, &self.current_bin_path, &self.passthrough_opts) {
271+
match t.test(
272+
opt,
273+
&self.current_bin_path,
274+
self.clippy,
275+
self.docs,
276+
&self.passthrough_opts,
277+
) {
251278
Ok(s) => {
252279
if let Some(stderrs) = s {
253280
let mut buf = String::new();

ci/svd2rust-regress/src/svd_test.rs

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,43 @@ impl std::fmt::Debug for ProcessFailed {
7171
}
7272

7373
trait CommandHelper {
74-
fn capture_outputs(
74+
fn run_and_capture_outputs(
7575
&mut self,
7676
cant_fail: bool,
7777
name: &str,
7878
stdout: Option<&PathBuf>,
7979
stderr: Option<&PathBuf>,
8080
previous_processes_stderr: &[PathBuf],
8181
) -> 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+
}
8298
}
8399

84100
impl CommandHelper for Command {
85101
#[tracing::instrument(skip_all, fields(stdout = tracing::field::Empty, stderr = tracing::field::Empty))]
86-
fn capture_outputs(
102+
fn run_and_capture_outputs(
87103
&mut self,
88104
cant_fail: bool,
89105
name: &str,
90106
stdout: Option<&PathBuf>,
91107
stderr: Option<&PathBuf>,
92108
previous_processes_stderr: &[PathBuf],
93109
) -> Result<(), TestError> {
94-
let output = self.get_output(true)?;
110+
let output = self.run_and_get_output(true)?;
95111
let out_payload = String::from_utf8_lossy(&output.stdout);
96112
if let Some(out) = stdout {
97113
file_helper(&out_payload, out)?;
@@ -142,41 +158,80 @@ impl TestCase {
142158
&self,
143159
opts: &Opts,
144160
bin_path: &Path,
145-
cli_opts: &Option<Vec<String>>,
161+
run_clippy: bool,
162+
run_docs: bool,
163+
cli_passthrough_opts: &Option<Vec<String>>,
146164
) -> Result<Option<Vec<PathBuf>>, TestError> {
147165
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)
149167
.with_context(|| anyhow!("when setting up case for {}", self.name()))?;
150168
// Run `cargo check`, capturing stderr to a log file
151169
if !self.skip_check {
152170
let cargo_check_err_file = path_helper_base(&chip_dir, &["cargo-check.err.log"]);
153171
Command::new("cargo")
154172
.arg("check")
155173
.current_dir(&chip_dir)
156-
.capture_outputs(
174+
.run_and_capture_stderr(
157175
true,
158176
"cargo check",
159-
None,
160-
Some(&cargo_check_err_file),
177+
&cargo_check_err_file,
161178
&process_stderr_paths,
162179
)
163-
.with_context(|| "failed to check")?;
180+
.with_context(|| "failed to check with cargo check")?;
164181
process_stderr_paths.push(cargo_check_err_file);
165182
}
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+
}
166221
Ok(if opts.verbose > 1 {
167222
Some(process_stderr_paths)
168223
} else {
169224
None
170225
})
171226
}
172227

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))]
174229

175230
pub fn setup_case(
176231
&self,
177232
output_dir: &Path,
178233
svd2rust_bin_path: &Path,
179-
command: &Option<Vec<String>>,
234+
passthrough_opts: &Option<Vec<String>>,
180235
) -> Result<(PathBuf, Vec<PathBuf>), TestError> {
181236
let user = match std::env::var("USER") {
182237
Ok(val) => val,
@@ -209,10 +264,10 @@ impl TestCase {
209264
.arg("none")
210265
.arg("--lib")
211266
.arg(&chip_dir)
212-
.capture_outputs(true, "cargo init", None, None, &[])
267+
.run_and_capture_outputs(true, "cargo init", None, None, &[])
213268
.with_context(|| "Failed to cargo init")?;
214269

215-
self.prepare_chip_test_toml(&chip_dir, command)?;
270+
self.prepare_chip_test_toml(&chip_dir, passthrough_opts)?;
216271
let chip_svd = self.prepare_svd_file(&chip_dir)?;
217272
self.prepare_rust_toolchain_file(&chip_dir)?;
218273

@@ -225,7 +280,7 @@ impl TestCase {
225280
&chip_dir,
226281
&lib_rs_file,
227282
&svd2rust_err_file,
228-
command,
283+
passthrough_opts,
229284
)?;
230285
process_stderr_paths.push(svd2rust_err_file);
231286
match self.arch {
@@ -261,7 +316,7 @@ impl TestCase {
261316
.arg(&new_lib_rs_file)
262317
.arg("--outdir")
263318
.arg(&src_dir)
264-
.capture_outputs(
319+
.run_and_capture_outputs(
265320
true,
266321
"form",
267322
None,
@@ -290,7 +345,7 @@ impl TestCase {
290345
Command::new(rustfmt_bin_path)
291346
.arg(entry)
292347
.args(["--edition", "2021"])
293-
.capture_outputs(
348+
.run_and_capture_outputs(
294349
false,
295350
"rustfmt",
296351
None,
@@ -416,7 +471,7 @@ impl TestCase {
416471
if let Some(opts) = self.opts.as_ref() {
417472
base_cmd.args(opts);
418473
}
419-
base_cmd.current_dir(chip_dir).capture_outputs(
474+
base_cmd.current_dir(chip_dir).run_and_capture_outputs(
420475
true,
421476
"svd2rust",
422477
Some(lib_rs_file).filter(|_| {

0 commit comments

Comments
 (0)