Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix schema_version deserialization #197

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion svd-encoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version = "0.13.1"
readme = "README.md"

[dependencies]
svd-rs = { version = "0.13.0", path = "../svd-rs"}
svd-rs = { version = "0.13.1", path = "../svd-rs"}
thiserror = "1.0.30"

[dependencies.xmltree]
Expand Down
4 changes: 2 additions & 2 deletions svd-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ readme = "README.md"
derive-from = ["svd-rs/derive-from"]

[dependencies]
svd-rs = { version = "0.13.0", path = "../svd-rs"}
svd-rs = { version = "0.13.1", path = "../svd-rs"}
roxmltree = "0.14.1"
anyhow = "1.0.45"
thiserror = "1.0.30"

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

[[example]]
name = "svd2json"
7 changes: 6 additions & 1 deletion svd-rs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

## [v0.13.2] - 2022-04-12

- Fix `schema_version` deserialization

## [v0.13.1] - 2022-02-12

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

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

[Unreleased]: https://github.com/rust-embedded/svd/compare/svd-rs-v0.13.1...HEAD
[Unreleased]: https://github.com/rust-embedded/svd/compare/svd-rs-v0.13.2...HEAD
[v0.13.2]: https://github.com/rust-embedded/svd/compare/svd-rs-v0.13.1...svd-rs-v0.13.2
[v0.13.1]: https://github.com/rust-embedded/svd/compare/svd-parser-v0.13.1...svd-rs-v0.13.1
[v0.13.0]: https://github.com/rust-embedded/svd/compare/svd-rs-v0.12.1...v0.13.0
[v0.12.1]: https://github.com/rust-embedded/svd/compare/v0.12.0...svd-rs-v0.12.1
Expand Down
34 changes: 24 additions & 10 deletions svd-rs/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,34 @@ pub struct Device {
pub peripherals: Vec<Peripheral>,

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

/// Specify the file path and file name of the CMSIS-SVD Schema
#[cfg_attr(feature = "serde", serde(skip))]
#[cfg_attr(
feature = "serde",
serde(skip, default = "default_no_namespace_schema_location")
)]
pub no_namespace_schema_location: String,

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

fn default_xmlns_xs() -> String {
"http://www.w3.org/2001/XMLSchema-instance".into()
}
fn default_no_namespace_schema_location() -> String {
format!(
"CMSIS-SVD_Schema_{}.xsd",
default_schema_version().replace('.', "_")
)
}
fn default_schema_version() -> String {
"1.1".into()
}

/// Builder for [`Device`]
#[derive(Clone, Debug, Default)]
pub struct DeviceBuilder {
Expand Down Expand Up @@ -237,7 +253,7 @@ impl DeviceBuilder {
}
/// Validate and build a [`Device`].
pub fn build(self, lvl: ValidateLevel) -> Result<Device, SvdError> {
let schema_version = self.schema_version.unwrap_or_else(|| "1.1".into());
let schema_version = self.schema_version.unwrap_or_else(default_schema_version);
let mut device = Device {
vendor: self.vendor,
vendor_id: self.vendor_id,
Expand Down Expand Up @@ -281,12 +297,10 @@ impl DeviceBuilder {
peripherals: self
.peripherals
.ok_or_else(|| BuildError::Uninitialized("peripherals".to_string()))?,
xmlns_xs: self
.xmlns_xs
.unwrap_or_else(|| "http://www.w3.org/2001/XMLSchema-instance".into()),
no_namespace_schema_location: self.no_namespace_schema_location.unwrap_or_else(|| {
format!("CMSIS-SVD_Schema_{}.xsd", schema_version.replace(".", "_"))
}),
xmlns_xs: self.xmlns_xs.unwrap_or_else(default_xmlns_xs),
no_namespace_schema_location: self
.no_namespace_schema_location
.unwrap_or_else(default_no_namespace_schema_location),
schema_version,
};
if !lvl.is_disabled() {
Expand Down