Skip to content

Commit

Permalink
_include in root peripherals
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Dec 15, 2023
1 parent 4286af9 commit d1fae23
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This changelog tracks the Python `svdtools` project. See

## [Unreleased]

* Support `_include` in peripherals in `device.yaml`
* `-1` for default enum value

## [v0.1.26] 2023-03-28
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This changelog tracks the Rust `svdtools` project. See

## [Unreleased]

* Support `_include` in peripherals in `device.yaml`
* Add `--enum_derive` flag

## [v0.3.6] 2023-11-01
Expand Down
28 changes: 15 additions & 13 deletions src/patch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ pub fn yaml_includes(parent: &mut Hash) -> Result<Vec<PathBuf>> {
let y_path = "_path".to_yaml();
let mut included = vec![];
let self_path = PathBuf::from(parent.get(&y_path).unwrap().str()?);

// Process any peripheral-level includes in child
for (pspec, val) in parent.iter_mut() {
if !pspec.str()?.starts_with('_') {
match val {
Yaml::Hash(val) if val.contains_key(&"_include".to_yaml()) => {
let ypath = self_path.to_str().unwrap().to_yaml();
val.insert(y_path.clone(), ypath.clone());
included.extend(yaml_includes(val)?);
}
_ => {}
}
}
}

let inc = parent.get_vec("_include")?.unwrap_or(&Vec::new()).clone();
for relpath in inc {
let relpath = relpath.as_str().unwrap();
Expand All @@ -161,19 +176,6 @@ pub fn yaml_includes(parent: &mut Hash) -> Result<Vec<PathBuf>> {
child.insert(y_path.clone(), ypath.clone());
included.push(path.clone());

// Process any peripheral-level includes in child
for (pspec, val) in child.iter_mut() {
if !pspec.str()?.starts_with('_') {
match val {
Yaml::Hash(val) if val.contains_key(&"_include".to_yaml()) => {
val.insert(y_path.clone(), ypath.clone());
included.extend(yaml_includes(val)?);
}
_ => {}
}
}
}

// Process any top-level includes in child
included.extend(yaml_includes(child)?);
update_dict(parent, child)?;
Expand Down
10 changes: 5 additions & 5 deletions svdtools/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ def update_dict(parent, child):
def yaml_includes(parent):
"""Recursively loads any included YAML files."""
included = []
# Process any peripheral-level includes in child
for pspec in parent:
if not pspec.startswith("_") and "_include" in parent[pspec]:
parent[pspec]["_path"] = parent["_path"]
included += yaml_includes(parent[pspec])
for relpath in parent.get("_include", []):
path = abspath(parent["_path"], relpath)
if path in included:
Expand All @@ -127,11 +132,6 @@ def yaml_includes(parent):
child = yaml.safe_load(f)
child["_path"] = path
included.append(path)
# Process any peripheral-level includes in child
for pspec in child:
if not pspec.startswith("_") and "_include" in child[pspec]:
child[pspec]["_path"] = path
included += yaml_includes(child[pspec])
# Process any top-level includes in child
included += yaml_includes(child)
update_dict(parent, child)
Expand Down

0 comments on commit d1fae23

Please sign in to comment.