Skip to content

Commit 6c6e03f

Browse files
committed
fix schema_version
1 parent 1d7a42a commit 6c6e03f

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

svd-encoder/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ version = "0.13.1"
1313
readme = "README.md"
1414

1515
[dependencies]
16-
svd-rs = { version = "0.13.0", path = "../svd-rs"}
16+
svd-rs = { version = "0.13.1", path = "../svd-rs"}
1717
thiserror = "1.0.30"
1818

1919
[dependencies.xmltree]

svd-parser/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ readme = "README.md"
1717
derive-from = ["svd-rs/derive-from"]
1818

1919
[dependencies]
20-
svd-rs = { version = "0.13.0", path = "../svd-rs"}
20+
svd-rs = { version = "0.13.1", path = "../svd-rs"}
2121
roxmltree = "0.14.1"
2222
anyhow = "1.0.45"
2323
thiserror = "1.0.30"
2424

2525
[dev-dependencies]
2626
serde_json = { version = "1.0", features = ["preserve_order"] }
2727
serde_yaml = "0.8.23"
28-
svd-rs = { version = "0.13.0", path = "../svd-rs", features = ["serde"] }
28+
svd-rs = { version = "0.13.1", path = "../svd-rs", features = ["serde"] }
2929

3030
[[example]]
3131
name = "svd2json"

svd-rs/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## Unreleased
99

10+
## [v0.13.2] - 2022-04-12
11+
12+
- Fix `schema_version` deserialization
13+
1014
## [v0.13.1] - 2022-02-12
1115

1216
- add `indexes_as_range` for `DimElement`
@@ -64,7 +68,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6468

6569
Previous versions in common [changelog](../CHANGELOG.md).
6670

67-
[Unreleased]: https://github.com/rust-embedded/svd/compare/svd-rs-v0.13.1...HEAD
71+
[Unreleased]: https://github.com/rust-embedded/svd/compare/svd-rs-v0.13.2...HEAD
72+
[v0.13.2]: https://github.com/rust-embedded/svd/compare/svd-rs-v0.13.1...svd-rs-v0.13.2
6873
[v0.13.1]: https://github.com/rust-embedded/svd/compare/svd-parser-v0.13.1...svd-rs-v0.13.1
6974
[v0.13.0]: https://github.com/rust-embedded/svd/compare/svd-rs-v0.12.1...v0.13.0
7075
[v0.12.1]: https://github.com/rust-embedded/svd/compare/v0.12.0...svd-rs-v0.12.1

svd-rs/src/device.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,34 @@ pub struct Device {
9191
pub peripherals: Vec<Peripheral>,
9292

9393
/// Specify the underlying XML schema to which the CMSIS-SVD schema is compliant.
94-
#[cfg_attr(feature = "serde", serde(skip))]
94+
#[cfg_attr(feature = "serde", serde(skip, default = "default_xmlns_xs"))]
9595
pub xmlns_xs: String,
9696

9797
/// Specify the file path and file name of the CMSIS-SVD Schema
98-
#[cfg_attr(feature = "serde", serde(skip))]
98+
#[cfg_attr(
99+
feature = "serde",
100+
serde(skip, default = "default_no_namespace_schema_location")
101+
)]
99102
pub no_namespace_schema_location: String,
100103

101104
/// Specify the compliant CMSIS-SVD schema version
102-
#[cfg_attr(feature = "serde", serde(skip))]
105+
#[cfg_attr(feature = "serde", serde(skip, default = "default_schema_version"))]
103106
pub schema_version: String,
104107
}
105108

109+
fn default_xmlns_xs() -> String {
110+
"http://www.w3.org/2001/XMLSchema-instance".into()
111+
}
112+
fn default_no_namespace_schema_location() -> String {
113+
format!(
114+
"CMSIS-SVD_Schema_{}.xsd",
115+
default_schema_version().replace('.', "_")
116+
)
117+
}
118+
fn default_schema_version() -> String {
119+
"1.1".into()
120+
}
121+
106122
/// Builder for [`Device`]
107123
#[derive(Clone, Debug, Default)]
108124
pub struct DeviceBuilder {
@@ -237,7 +253,7 @@ impl DeviceBuilder {
237253
}
238254
/// Validate and build a [`Device`].
239255
pub fn build(self, lvl: ValidateLevel) -> Result<Device, SvdError> {
240-
let schema_version = self.schema_version.unwrap_or_else(|| "1.1".into());
256+
let schema_version = self.schema_version.unwrap_or_else(default_schema_version);
241257
let mut device = Device {
242258
vendor: self.vendor,
243259
vendor_id: self.vendor_id,
@@ -281,12 +297,10 @@ impl DeviceBuilder {
281297
peripherals: self
282298
.peripherals
283299
.ok_or_else(|| BuildError::Uninitialized("peripherals".to_string()))?,
284-
xmlns_xs: self
285-
.xmlns_xs
286-
.unwrap_or_else(|| "http://www.w3.org/2001/XMLSchema-instance".into()),
287-
no_namespace_schema_location: self.no_namespace_schema_location.unwrap_or_else(|| {
288-
format!("CMSIS-SVD_Schema_{}.xsd", schema_version.replace(".", "_"))
289-
}),
300+
xmlns_xs: self.xmlns_xs.unwrap_or_else(default_xmlns_xs),
301+
no_namespace_schema_location: self
302+
.no_namespace_schema_location
303+
.unwrap_or_else(default_no_namespace_schema_location),
290304
schema_version,
291305
};
292306
if !lvl.is_disabled() {

0 commit comments

Comments
 (0)