Skip to content

Commit 3946ef9

Browse files
committed
more, not current
1 parent 40686c1 commit 3946ef9

File tree

6 files changed

+323
-137
lines changed

6 files changed

+323
-137
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ jobs:
2121
runs-on: ubuntu-latest
2222
strategy:
2323
matrix:
24-
TARGET: [x86_64-unknown-linux-gnu, x86_64-apple-darwin, x86_64-pc-windows-msvc]
24+
TARGET:
25+
[
26+
x86_64-unknown-linux-gnu,
27+
x86_64-apple-darwin,
28+
x86_64-pc-windows-msvc,
29+
]
2530

2631
steps:
2732
- uses: actions/checkout@v3
@@ -75,7 +80,11 @@ jobs:
7580
- { rust: stable, vendor: Spansion, options: "--atomics" }
7681
- { rust: stable, vendor: STMicro, options: "" }
7782
- { rust: stable, vendor: STMicro, options: "--atomics" }
78-
- { rust: stable, vendor: STM32-patched, options: "--strict --const_generic --derive_more --pascal_enum_values --max_cluster_size --atomics" }
83+
- {
84+
rust: stable,
85+
vendor: STM32-patched,
86+
options: "--strict --const_generic --derive_more --pascal_enum_values --max_cluster_size --atomics",
87+
}
7988
- { rust: stable, vendor: Toshiba, options: all }
8089
- { rust: stable, vendor: Toshiba, options: "" }
8190
# Test MSRV
@@ -175,24 +184,34 @@ jobs:
175184
name: Build svd2rust artifact
176185
if: github.event_name == 'pull_request'
177186
needs: [check]
178-
runs-on: ubuntu-latest
187+
runs-on: ${{ matrix.runs-on }}
188+
strategy:
189+
matrix:
190+
include:
191+
- target: x86_64-unknown-linux-gnu
192+
runs-on: ubuntu-latest
193+
- target: aarch64-apple-darwin
194+
runs-on: macos-latest
195+
- target: x86_64-pc-windows-msvc
196+
runs-on: windows-latest
179197
steps:
180198
- uses: actions/checkout@v3
181199

182200
- uses: dtolnay/rust-toolchain@master
183201
with:
184202
toolchain: stable
203+
targets: ${{ matrix.target }}
185204

186205
- name: Cache Dependencies
187206
uses: Swatinem/rust-cache@v2
188207

189208
- name: Build svd2rust artifact
190-
run: cargo build --release
209+
run: cargo build --release --target ${{ matrix.target }}
191210

192-
- run: mv target/release/svd2rust svd2rust-x86_64-unknown-linux-gnu-$(git rev-parse --short HEAD)
211+
- run: mv target/${{ matrix.target }}/release/svd2rust svd2rust-${{ matrix.target }}-$(git rev-parse --short HEAD)
193212

194213
- name: Upload artifact
195214
uses: actions/upload-artifact@v3
196215
with:
197-
name: artifact-svd2rust-x86_64-unknown-linux-gnu
198-
path: svd2rust-x86_64-unknown-linux-gnu*
216+
name: artifact-svd2rust-${{ matrix.target }}
217+
path: svd2rust-${{ matrix.target }}*

ci/svd2rust-regress/src/command.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use std::process::Command;
2+
3+
use anyhow::Context;
4+
5+
pub trait CommandExt {
6+
#[track_caller]
7+
fn run(&mut self, hide: bool) -> Result<(), anyhow::Error>;
8+
9+
#[track_caller]
10+
fn get_output(&mut self) -> Result<std::process::Output, anyhow::Error>;
11+
12+
#[track_caller]
13+
fn get_output_string(&mut self) -> Result<String, anyhow::Error>;
14+
15+
fn display(&self) -> String;
16+
}
17+
18+
impl CommandExt for Command {
19+
#[track_caller]
20+
fn run(&mut self, hide: bool) -> Result<(), anyhow::Error> {
21+
if hide {
22+
self.stdout(std::process::Stdio::null())
23+
.stdin(std::process::Stdio::null());
24+
}
25+
let status = self
26+
.status()
27+
.with_context(|| format!("fail! {}", self.display()))?;
28+
if status.success() {
29+
Ok(())
30+
} else {
31+
anyhow::bail!("command `{}` failed", self.display())
32+
}
33+
}
34+
35+
#[track_caller]
36+
fn get_output(&mut self) -> Result<std::process::Output, anyhow::Error> {
37+
let output = self.output()?;
38+
if output.status.success() {
39+
Ok(output)
40+
} else {
41+
anyhow::bail!(
42+
"command `{}` failed: stdout: {}\nstderr: {}",
43+
self.display(),
44+
String::from_utf8_lossy(&output.stdout),
45+
String::from_utf8_lossy(&output.stderr),
46+
)
47+
}
48+
}
49+
50+
#[track_caller]
51+
fn get_output_string(&mut self) -> Result<String, anyhow::Error> {
52+
String::from_utf8(self.get_output()?.stdout).map_err(Into::into)
53+
}
54+
55+
fn display(&self) -> String {
56+
format!(
57+
"{} {}",
58+
self.get_program().to_string_lossy(),
59+
self.get_args()
60+
.map(|s| s.to_string_lossy())
61+
.collect::<Vec<_>>()
62+
.join(" ")
63+
)
64+
}
65+
}

ci/svd2rust-regress/src/diff.rs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
use std::path::{Path, PathBuf};
2+
3+
use anyhow::Context;
4+
5+
use crate::github;
6+
use crate::Opts;
7+
8+
#[derive(clap::Parser, Debug)]
9+
#[clap(name = "diff")]
10+
pub struct Diffing {
11+
#[clap(long)]
12+
pub base: Option<String>,
13+
14+
#[clap(long)]
15+
pub head: Option<String>,
16+
17+
/// Enable formatting with `rustfmt`
18+
#[clap(short = 'f', long)]
19+
pub format: bool,
20+
21+
#[clap(subcommand)]
22+
pub sub: Option<DiffingSub>,
23+
24+
#[clap(long)]
25+
pub chip: Vec<String>,
26+
}
27+
28+
#[derive(clap::Parser, Debug)]
29+
pub enum DiffingSub {
30+
Pr,
31+
}
32+
33+
impl Diffing {
34+
pub fn run(&self, opts: &Opts, rustfmt_bin_path: Option<&Path>) -> Result<(), anyhow::Error> {
35+
let (head, base) = self
36+
.svd2rust_setup(opts)
37+
.with_context(|| "couldn't setup svd2rust")?;
38+
let tests = crate::tests::tests(Some(opts)).with_context(|| "no tests found")?;
39+
40+
tests[0]
41+
.setup_case(
42+
&opts.output_dir.join("head"),
43+
&head,
44+
rustfmt_bin_path,
45+
false,
46+
)
47+
.with_context(|| "couldn't create head")?;
48+
tests[0]
49+
.setup_case(
50+
&opts.output_dir.join("base"),
51+
&base,
52+
rustfmt_bin_path,
53+
false,
54+
)
55+
.with_context(|| "couldn't create base")?;
56+
Ok(())
57+
}
58+
59+
pub fn svd2rust_setup(&self, opts: &Opts) -> Result<(PathBuf, PathBuf), anyhow::Error> {
60+
let base = match self
61+
.base
62+
.as_deref()
63+
.and_then(|s| s.strip_prefix('@'))
64+
.and_then(|s| s.split(' ').next())
65+
{
66+
reference @ None | reference @ Some("" | "master") => {
67+
github::get_release_binary_artifact(reference.unwrap_or("master"), &opts.output_dir)
68+
.with_context(|| "couldn't get svd2rust latest unreleased artifact")?
69+
}
70+
Some("pr") => {
71+
let (number, sha) =
72+
github::get_current_pr().with_context(|| "couldn't get current pr")?;
73+
github::get_pr_binary_artifact(number, &sha, &opts.output_dir)
74+
.with_context(|| "couldn't get pr artifact")?
75+
}
76+
Some(reference) => github::get_release_binary_artifact(reference, &opts.output_dir)
77+
.with_context(|| format!("could not get svd2rust for {reference}"))?,
78+
};
79+
80+
let head = match self
81+
.head
82+
.as_deref()
83+
.and_then(|s| s.strip_prefix('@'))
84+
.and_then(|s| s.split(' ').next())
85+
{
86+
None | Some("" | "pr") => {
87+
let (number, sha) =
88+
github::get_current_pr().with_context(|| "couldn't get current pr")?;
89+
github::get_pr_binary_artifact(number, &sha, &opts.output_dir)
90+
.with_context(|| "couldn't get pr artifact")?
91+
}
92+
Some(reference) => github::get_release_binary_artifact(reference, &opts.output_dir)
93+
.with_context(|| format!("could not get svd2rust for {reference}"))?,
94+
};
95+
96+
Ok((base, head))
97+
}
98+
}
99+
100+
#[cfg(test)]
101+
#[test]
102+
pub fn diffing_cli_works() {
103+
use clap::Parser;
104+
105+
Diffing::parse_from(["diff", "pr"]);
106+
Diffing::parse_from(["diff", "--base", "", "--head", "\"--atomics\""]);
107+
Diffing::parse_from(["diff", "--base", "\"@master\"", "--head", "\"@pr\""]);
108+
Diffing::parse_from([
109+
"diff",
110+
"--base",
111+
"\"@master\"",
112+
"--head",
113+
"\"@pr\"",
114+
"--chip",
115+
"STM32F401",
116+
]);
117+
Diffing::parse_from([
118+
"diff",
119+
"--base",
120+
"\"@master\"",
121+
"--head",
122+
"\"@pr --atomics\"",
123+
]);
124+
Diffing::parse_from(["diff", "--head", "\"--atomics\""]);
125+
}

0 commit comments

Comments
 (0)