Skip to content

Commit 9d87a7b

Browse files
bors[bot]James Munns
andcommitted
Merge #63
63: Make the schema field optional r=Emilgardis a=jamesmunns Some devices that have created fake SVDs, such as for the MSP430, may not have schemas listed. This fixes the error seen with https://travis-ci.org/rust-embedded/svd2rust/jobs/456451847, See also rust-embedded/svd2rust#256 (comment) Co-authored-by: James Munns <[email protected]>
2 parents 6aa4fdc + 10fca74 commit 9d87a7b

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/svd/device.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use svd::peripheral::Peripheral;
1818
#[derive(Clone, Debug)]
1919
pub struct Device {
2020
pub name: String,
21-
schema_version: String,
21+
schema_version: Option<String>,
2222
pub version: Option<String>,
2323
pub description: Option<String>,
2424
pub address_unit_bits: Option<u32>,
@@ -40,8 +40,7 @@ impl Parse for Device {
4040
name: tree.get_child_text("name")?,
4141
schema_version: tree.attributes
4242
.get("schemaVersion")
43-
.unwrap()
44-
.clone(),
43+
.map(|s| s.clone()),
4544
cpu: parse::optional::<Cpu>("cpu", tree)?,
4645
version: tree.get_child_text_opt("version")?,
4746
description: tree.get_child_text_opt("description")?,
@@ -77,14 +76,23 @@ impl Encode for Device {
7776
String::from("xmlns:xs"),
7877
String::from("http://www.w3.org/2001/XMLSchema-instance"),
7978
);
80-
elem.attributes.insert(
81-
String::from("schemaVersion"),
82-
format!("{}", self.schema_version),
83-
);
84-
elem.attributes.insert(
85-
String::from("xs:noNamespaceSchemaLocation"),
86-
format!("CMSIS-SVD_Schema_{}.xsd", self.schema_version),
87-
);
79+
match self.schema_version {
80+
Some(ref schema_version) => {
81+
elem.attributes.insert(
82+
String::from("schemaVersion"),
83+
format!("{}", schema_version));
84+
},
85+
None => (),
86+
}
87+
match self.schema_version {
88+
Some(ref schema_version) => {
89+
elem.attributes.insert(
90+
String::from("xs:noNamespaceSchemaLocation"),
91+
format!("CMSIS-SVD_Schema_{}.xsd", schema_version));
92+
},
93+
None => (),
94+
}
95+
8896

8997
match self.version {
9098
Some(ref v) => elem.children

0 commit comments

Comments
 (0)