Skip to content

Commit eb0c405

Browse files
committed
fix last arg parsing and wrong lookup for chips
1 parent 848ca10 commit eb0c405

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

ci/svd2rust-regress/src/diff.rs

+43-15
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct Diffing {
3030
#[clap(subcommand)]
3131
pub sub: Option<DiffingMode>,
3232

33-
#[clap(long, short = 'c')]
33+
#[clap(global = true, long, short = 'c')]
3434
pub chip: Vec<String>,
3535

3636
/// Filter by manufacturer, case sensitive, may be combined with other filters
@@ -65,14 +65,23 @@ pub struct Diffing {
6565
pub use_pager_directly: bool,
6666

6767
#[clap(last = true)]
68-
pub args: Option<String>,
68+
pub last_args: Option<String>,
6969
}
7070

71-
#[derive(clap::Parser, Debug, Clone, Copy)]
71+
#[derive(clap::Parser, Debug, Clone)]
7272
pub enum DiffingMode {
73-
Semver,
74-
Diff,
75-
Pr,
73+
Semver {
74+
#[clap(last = true)]
75+
last_args: Option<String>,
76+
},
77+
Diff {
78+
#[clap(last = true)]
79+
last_args: Option<String>,
80+
},
81+
Pr {
82+
#[clap(last = true)]
83+
last_args: Option<String>,
84+
},
7685
}
7786

7887
impl DiffingMode {
@@ -81,7 +90,7 @@ impl DiffingMode {
8190
/// [`Pr`]: DiffingMode::Pr
8291
#[must_use]
8392
pub fn is_pr(&self) -> bool {
84-
matches!(self, Self::Pr)
93+
matches!(self, Self::Pr { .. })
8594
}
8695
}
8796

@@ -93,8 +102,8 @@ impl Diffing {
93102
let [baseline, current] = self
94103
.make_case(opts)
95104
.with_context(|| "couldn't setup test case")?;
96-
match self.sub.unwrap_or(DiffingMode::Diff) {
97-
DiffingMode::Diff | DiffingMode::Pr => {
105+
match self.sub.as_ref() {
106+
None | Some(DiffingMode::Diff { .. } | DiffingMode::Pr { .. }) => {
98107
let mut command;
99108
if let Some(pager) = &self.pager {
100109
if self.use_pager_directly {
@@ -118,7 +127,7 @@ impl Diffing {
118127
.with_context(|| "couldn't run diff")
119128
.map(|_| ())
120129
}
121-
DiffingMode::Semver => std::process::Command::new("cargo")
130+
Some(DiffingMode::Semver { .. }) => std::process::Command::new("cargo")
122131
.args(["semver-checks", "check-release"])
123132
.arg("--baseline-root")
124133
.arg(baseline.0)
@@ -158,7 +167,7 @@ impl Diffing {
158167
})
159168
.filter(|t| {
160169
if self.chip.is_empty() {
161-
false
170+
true
162171
} else {
163172
self.chip.iter().any(|c| {
164173
wildmatch::WildMatch::new(&c.to_ascii_lowercase())
@@ -167,9 +176,9 @@ impl Diffing {
167176
}
168177
})
169178
.collect::<Vec<_>>();
170-
let test = match (tests.len(), self.sub) {
179+
let test = match (tests.len(), self.sub.as_ref()) {
171180
(1, _) => tests[0],
172-
(1.., Some(DiffingMode::Pr)) => tests
181+
(_, Some(DiffingMode::Pr { .. })) => tests
173182
.iter()
174183
.find(|t| t.chip == "STM32F103")
175184
.unwrap_or(&tests[0]),
@@ -187,15 +196,34 @@ impl Diffing {
187196
}
188197
};
189198

199+
let last_args = self.last_args.as_deref().or(match &self.sub {
200+
Some(
201+
DiffingMode::Diff { last_args }
202+
| DiffingMode::Pr { last_args }
203+
| DiffingMode::Semver { last_args },
204+
) => last_args.as_deref(),
205+
None => None,
206+
});
207+
let join = |opt1: Option<&str>, opt2: Option<&str>| -> Option<String> {
208+
match (opt1, opt2) {
209+
(Some(str1), Some(str2)) => Some(format!("{} {}", str1, str2)),
210+
(Some(str), None) | (None, Some(str)) => Some(str.to_owned()),
211+
(None, None) => None,
212+
}
213+
};
190214
let baseline = test
191215
.setup_case(
192216
&opts.output_dir.join("baseline"),
193217
&baseline_bin,
194-
baseline_cmd,
218+
join(baseline_cmd, last_args).as_deref(),
195219
)
196220
.with_context(|| "couldn't create head")?;
197221
let current = test
198-
.setup_case(&opts.output_dir.join("current"), &current_bin, current_cmd)
222+
.setup_case(
223+
&opts.output_dir.join("current"),
224+
&current_bin,
225+
join(current_cmd, last_args).as_deref(),
226+
)
199227
.with_context(|| "couldn't create base")?;
200228

201229
Ok([baseline, current])

ci/svd2rust-regress/src/svd_test.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ impl TestCase {
261261
tracing::info!("Running svd2rust");
262262
let mut svd2rust_bin = Command::new(svd2rust_bin_path);
263263
if let Some(command) = command {
264-
svd2rust_bin.arg(command);
264+
if !command.is_empty() {
265+
svd2rust_bin.arg(command);
266+
}
265267
}
266268
svd2rust_bin
267269
.args(["-i", &chip_svd])

0 commit comments

Comments
 (0)