Skip to content

Commit

Permalink
Merge pull request #785 from rust-embedded/regress-url
Browse files Browse the repository at this point in the history
svd2rust-regress: allow downloading arbitrary svd with `--url`
  • Loading branch information
Emilgardis authored Dec 10, 2023
2 parents 76cd523 + 1075da7 commit 2bc8c82
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
32 changes: 28 additions & 4 deletions ci/svd2rust-regress/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ pub struct Diffing {
#[clap(long, short = 'P')]
pub use_pager_directly: bool,

/// URL for SVD to download
#[clap(global = true, long)]
pub url: Option<String>,

#[clap(last = true)]
pub last_args: Option<String>,
}
Expand Down Expand Up @@ -176,12 +180,32 @@ impl Diffing {
}
})
.collect::<Vec<_>>();
let test = match (tests.len(), self.sub.as_ref()) {
(1, _) => tests[0],
(_, Some(DiffingMode::Pr { .. })) => tests

let test = match (tests.len(), self.sub.as_ref(), self.url.as_ref()) {
(1, _, None) => tests[0].clone(),
(_, Some(DiffingMode::Pr { .. }), None) => tests
.iter()
.find(|t| t.chip == "STM32F103")
.unwrap_or(&tests[0]),
.map(|t| (*t).clone())
.unwrap_or_else(|| tests[0].clone()),
(_, _, Some(url)) => crate::tests::TestCase {
arch: self
.arch
.clone()
.map(|s| svd2rust::Target::parse(&s))
.transpose()?
.unwrap_or_default(),
mfgr: crate::tests::Manufacturer::Unknown,
chip: url
.rsplit('/')
.next()
.and_then(|file| file.split('.').next())
.ok_or_else(|| anyhow::anyhow!("couldn't get chip name from url"))?
.to_owned(),
svd_url: Some(url.to_owned()),
should_pass: true,
run_when: crate::tests::RunWhen::Always,
},
_ => {
let error = anyhow::anyhow!("diff requires exactly one test case");
let len = tests.len();
Expand Down
9 changes: 5 additions & 4 deletions ci/svd2rust-regress/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum Manufacturer {
SiFive,
TexasInstruments,
Espressif,
Unknown,
}

impl Manufacturer {
Expand Down Expand Up @@ -54,7 +55,7 @@ impl std::fmt::Display for Manufacturer {
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Default)]
#[derive(Debug, serde::Serialize, serde::Deserialize, Default, Clone, Copy)]
#[serde(rename_all = "kebab-case")]
pub enum RunWhen {
#[default]
Expand All @@ -65,17 +66,17 @@ pub enum RunWhen {
Never,
}

#[derive(serde::Serialize, serde::Deserialize)]
#[derive(serde::Serialize, serde::Deserialize, Clone)]
pub struct TestCase {
pub arch: Target,
pub mfgr: Manufacturer,
pub chip: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
svd_url: Option<String>,
pub svd_url: Option<String>,
#[serde(default = "true_")]
pub should_pass: bool,
#[serde(default)]
run_when: RunWhen,
pub run_when: RunWhen,
}

fn true_() -> bool {
Expand Down

0 comments on commit 2bc8c82

Please sign in to comment.