Skip to content

Commit 3cb7ae3

Browse files
authored
Merge pull request #187 from rust-embedded/include
_include in root peripherals
2 parents 2cf9544 + 991c9f8 commit 3cb7ae3

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

CHANGELOG-python.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This changelog tracks the Python `svdtools` project. See
55

66
## [Unreleased]
77

8+
* Support `_include` in peripherals in `device.yaml`
89
* `-1` for default enum value
910
* Strip `alternateRegister` too
1011

CHANGELOG-rust.md

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

66
## [Unreleased]
77

8+
* Support `_include` in peripherals in `device.yaml`
89
* Add `--enum_derive` flag
910
* Strip `alternateRegister` too
1011
* Add `modifiedWriteValues` and `readAction` field patch (#156)

src/patch/mod.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,21 @@ pub fn yaml_includes(parent: &mut Hash) -> Result<Vec<PathBuf>> {
142142
let y_path = "_path".to_yaml();
143143
let mut included = vec![];
144144
let self_path = PathBuf::from(parent.get(&y_path).unwrap().str()?);
145+
146+
// Process any peripheral-level includes in child
147+
for (pspec, val) in parent.iter_mut() {
148+
if !pspec.str()?.starts_with('_') {
149+
match val {
150+
Yaml::Hash(val) if val.contains_key(&"_include".to_yaml()) => {
151+
let ypath = self_path.to_str().unwrap().to_yaml();
152+
val.insert(y_path.clone(), ypath.clone());
153+
included.extend(yaml_includes(val)?);
154+
}
155+
_ => {}
156+
}
157+
}
158+
}
159+
145160
let inc = parent.get_vec("_include")?.unwrap_or(&Vec::new()).clone();
146161
for relpath in inc {
147162
let relpath = relpath.as_str().unwrap();
@@ -162,19 +177,6 @@ pub fn yaml_includes(parent: &mut Hash) -> Result<Vec<PathBuf>> {
162177
child.insert(y_path.clone(), ypath.clone());
163178
included.push(path.clone());
164179

165-
// Process any peripheral-level includes in child
166-
for (pspec, val) in child.iter_mut() {
167-
if !pspec.str()?.starts_with('_') {
168-
match val {
169-
Yaml::Hash(val) if val.contains_key(&"_include".to_yaml()) => {
170-
val.insert(y_path.clone(), ypath.clone());
171-
included.extend(yaml_includes(val)?);
172-
}
173-
_ => {}
174-
}
175-
}
176-
}
177-
178180
// Process any top-level includes in child
179181
included.extend(yaml_includes(child)?);
180182
update_dict(parent, child)?;

svdtools/patch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ def update_dict(parent, child):
119119
def yaml_includes(parent):
120120
"""Recursively loads any included YAML files."""
121121
included = []
122+
# Process any peripheral-level includes in child
123+
for pspec in parent:
124+
if not pspec.startswith("_") and "_include" in parent[pspec]:
125+
parent[pspec]["_path"] = parent["_path"]
126+
included += yaml_includes(parent[pspec])
122127
for relpath in parent.get("_include", []):
123128
path = abspath(parent["_path"], relpath)
124129
if path in included:
@@ -127,11 +132,6 @@ def yaml_includes(parent):
127132
child = yaml.safe_load(f)
128133
child["_path"] = path
129134
included.append(path)
130-
# Process any peripheral-level includes in child
131-
for pspec in child:
132-
if not pspec.startswith("_") and "_include" in child[pspec]:
133-
child[pspec]["_path"] = path
134-
included += yaml_includes(child[pspec])
135135
# Process any top-level includes in child
136136
included += yaml_includes(child)
137137
update_dict(parent, child)

0 commit comments

Comments
 (0)