Skip to content

Commit 074c31f

Browse files
bors[bot]burrbull
andauthored
Merge #128
128: version, release 0.2.7 r=adamgreig a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents 041c576 + 760a6d1 commit 074c31f

File tree

7 files changed

+54
-25
lines changed

7 files changed

+54
-25
lines changed

CHANGELOG-rust.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This changelog tracks the Rust `svdtools` project. See
55

66
## [Unreleased]
77

8+
## [v0.2.7] 2022-09-18
9+
10+
* Print svdtools version on error, update dependencies
11+
* Check `_delete`, `_strip`, etc. on array of strings
12+
813
## [v0.2.6] 2022-08-21
914

1015
**Breaking changes**:

Cargo.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "svdtools"
3-
version = "0.2.6"
3+
version = "0.2.7"
44
repository = "https://github.com/stm32-rs/svdtools"
55
description = "Tool for modifying bugs in CMSIS SVD"
66
authors = [
@@ -24,22 +24,23 @@ include = ["/res", "/src", "/tests", "CHANGELOG-rust.md", "README.md", "LICENSE-
2424
edition = "2021"
2525

2626
[dependencies]
27-
clap = { version = "3.2", features = ["derive"] }
27+
clap = { version = "3.2", features = ["derive", "cargo"] }
2828
serde = { version = "1.0", features = ["derive"] }
29-
quick-xml = { version = "0.18", features = ["serialize"] }
29+
quick-xml = { version = "0.25", features = ["serialize"] }
3030
svd-rs = { version = "0.14.0", features = ["serde", "derive-from"] }
3131
svd-parser = { version = "0.14.0", features = ["expand"] }
3232
svd-encoder = "0.14.1"
3333
yaml-rust = "0.4"
34-
serde_yaml = "0.8.23"
34+
# serde_yaml 0.9.x looks broken
35+
serde_yaml = "0.8.26"
3536
serde_json = { version = "1.0", features = ["preserve_order"] }
36-
anyhow = "1.0.43"
37-
thiserror = "1.0.30"
37+
anyhow = "1.0.65"
38+
thiserror = "1.0.35"
3839
linked-hash-map = "0.5"
3940
globset = "0.4.8"
4041
commands = "0.0.5"
4142
env_logger = "0.9"
4243
log = { version = "~0.4", features = ["std"] }
4344

4445
[dev-dependencies]
45-
tempfile = "3.1"
46+
tempfile = "3.3"

src/cli.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,16 @@ struct CliArgs {
127127
}
128128

129129
pub fn run() {
130+
use anyhow::Context;
131+
130132
env_logger::init();
131133

132134
let args = CliArgs::parse();
133-
if let Err(e) = args.command.run() {
135+
if let Err(e) = args
136+
.command
137+
.run()
138+
.with_context(|| format!("by svdtools ({})", clap::crate_version!()))
139+
{
134140
log::error!("{:?}", e);
135141

136142
std::process::exit(1);

src/patch/device.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl DeviceExt for Device {
6464

6565
fn process(&mut self, device: &Hash, update_fields: bool) -> PatchResult {
6666
// Handle any deletions
67-
for pspec in device.str_vec_iter("_delete") {
67+
for pspec in device.str_vec_iter("_delete")? {
6868
self.delete_peripheral(pspec)
6969
.with_context(|| format!("Deleting peripheral matched to `{pspec}`"))?;
7070
}
@@ -120,7 +120,7 @@ impl DeviceExt for Device {
120120
}
121121

122122
// Handle field clearing
123-
for pspec in device.str_vec_iter("_clear_fields") {
123+
for pspec in device.str_vec_iter("_clear_fields")? {
124124
self.clear_fields(pspec).with_context(|| {
125125
format!("Clearing contents of fields in peripherals matched to `{pspec}` ")
126126
})?;

src/patch/peripheral.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl PeripheralExt for Peripheral {
9898
// For derived peripherals, only process interrupts
9999
if self.derived_from.is_some() {
100100
if let Some(deletions) = pmod.get_hash("_delete").ok().flatten() {
101-
for ispec in deletions.str_vec_iter("_interrupts") {
101+
for ispec in deletions.str_vec_iter("_interrupts")? {
102102
self.delete_interrupt(ispec)
103103
.with_context(|| format!("Deleting interrupts matched to `{ispec}`"))?;
104104
}
@@ -146,16 +146,27 @@ impl PeripheralExt for Peripheral {
146146
}
147147
}
148148
Yaml::Hash(deletions) => {
149-
for rspec in deletions.str_vec_iter("_registers") {
149+
for rspec in deletions.str_vec_iter("_registers")? {
150150
self.delete_register(rspec)
151151
.with_context(|| format!("Deleting registers matched to `{rspec}`"))?;
152152
}
153-
for ispec in deletions.str_vec_iter("_interrupts") {
153+
for ispec in deletions.str_vec_iter("_interrupts")? {
154154
self.delete_interrupt(ispec)
155155
.with_context(|| format!("Deleting interrupts matched to `{ispec}`"))?;
156156
}
157+
for d in deletions.keys() {
158+
if !matches!(d, Yaml::String(s) if s == "_registers" || s =="_interrupts") {
159+
return Err(anyhow!(
160+
"`_delete` requires string value or array of strings"
161+
));
162+
}
163+
}
164+
}
165+
_ => {
166+
return Err(anyhow!(
167+
"`_delete` requires string value or array of strings"
168+
))
157169
}
158-
_ => {}
159170
}
160171
}
161172

@@ -168,11 +179,11 @@ impl PeripheralExt for Peripheral {
168179
}
169180

170181
// Handle strips
171-
for prefix in pmod.str_vec_iter("_strip") {
182+
for prefix in pmod.str_vec_iter("_strip")? {
172183
self.strip_start(prefix)
173184
.with_context(|| format!("Stripping prefix `{prefix}` from register names"))?;
174185
}
175-
for suffix in pmod.str_vec_iter("_strip_end") {
186+
for suffix in pmod.str_vec_iter("_strip_end")? {
176187
self.strip_end(suffix)
177188
.with_context(|| format!("Stripping suffix `{suffix}` from register names"))?;
178189
}
@@ -210,7 +221,7 @@ impl PeripheralExt for Peripheral {
210221
}
211222

212223
// Handle field clearing
213-
for rspec in pmod.str_vec_iter("_clear_fields") {
224+
for rspec in pmod.str_vec_iter("_clear_fields")? {
214225
self.clear_fields(rspec).with_context(|| {
215226
format!("Clearing contents of fields in registers matched to `{rspec}` ")
216227
})?;

src/patch/register.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,23 @@ impl RegisterExt for Register {
9494
return Ok(());
9595
}
9696
// Handle deletions
97-
for fspec in rmod.str_vec_iter("_delete") {
97+
for fspec in rmod.str_vec_iter("_delete")? {
9898
self.delete_field(fspec)
9999
.with_context(|| format!("Deleting fields matched to `{fspec}`"))?;
100100
}
101101

102102
// Handle strips
103-
for prefix in rmod.str_vec_iter("_strip") {
103+
for prefix in rmod.str_vec_iter("_strip")? {
104104
self.strip_start(prefix)
105105
.with_context(|| format!("Stripping prefix `{prefix}` from field names"))?;
106106
}
107-
for suffix in rmod.str_vec_iter("_strip_end") {
107+
for suffix in rmod.str_vec_iter("_strip_end")? {
108108
self.strip_end(suffix)
109109
.with_context(|| format!("Stripping suffix `{suffix}` from field names"))?;
110110
}
111111

112112
// Handle field clearing
113-
for fspec in rmod.str_vec_iter("_clear") {
113+
for fspec in rmod.str_vec_iter("_clear")? {
114114
self.clear_field(fspec)
115115
.with_context(|| format!("Clearing contents of fields matched to `{fspec}`"))?;
116116
}

src/patch/yaml_ext.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::iterators::OptIter;
2-
use anyhow::{Context, Result};
2+
use anyhow::{anyhow, Context, Result};
33
use yaml_rust::{yaml::Hash, Yaml};
44

55
/// Errors that can occur during building.
@@ -164,7 +164,7 @@ pub trait GetVal {
164164
fn get_hash(&self, k: &str) -> Result<Option<&Hash>>;
165165
fn hash_iter<'a>(&'a self, k: &str) -> HashIter<'a>;
166166
fn get_vec(&self, k: &str) -> Result<Option<&Vec<Yaml>>>;
167-
fn str_vec_iter<'a>(&'a self, k: &str) -> OptIter<OverStringIter<'a>>;
167+
fn str_vec_iter<'a>(&'a self, k: &str) -> Result<OptIter<OverStringIter<'a>>>;
168168
}
169169

170170
impl GetVal for Hash {
@@ -220,7 +220,13 @@ impl GetVal for Hash {
220220
.map(Some),
221221
}
222222
}
223-
fn str_vec_iter<'a>(&'a self, k: &str) -> OptIter<OverStringIter<'a>> {
224-
OptIter::new(self.get(&k.to_yaml()).map(|y| OverStringIter(y, None)))
223+
fn str_vec_iter<'a>(&'a self, k: &str) -> Result<OptIter<OverStringIter<'a>>> {
224+
Ok(OptIter::new(match self.get(&k.to_yaml()) {
225+
None => None,
226+
Some(y) if matches!(y, Yaml::String(_) | Yaml::Array(_)) => {
227+
Some(OverStringIter(y, None))
228+
}
229+
_ => return Err(anyhow!("`{k}` requires string value or array of strings")),
230+
}))
225231
}
226232
}

0 commit comments

Comments
 (0)