Skip to content

Commit 80541fe

Browse files
authored
Merge pull request #140 from stm32-rs/normpath
normpath
2 parents a8ac1df + 2ff7c42 commit 80541fe

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

CHANGELOG-rust.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This changelog tracks the Rust `svdtools` project. See
66
## [Unreleased]
77

88
* cluster add/modify
9+
* use `normpath` instead of std::fs::canonicalize
910

1011
## [v0.2.8] 2022-01-28
1112

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ globset = "0.4.8"
4141
commands = "0.0.5"
4242
env_logger = "0.9"
4343
log = { version = "~0.4", features = ["std"] }
44+
normpath = "1.1.0"
4445

4546
[dev-dependencies]
4647
tempfile = "3.3"

src/patch/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use svd_parser::SVDError::DimIndexParse;
1515
use svd_rs::{DimElement, DimElementBuilder, MaybeArray};
1616
use yaml_rust::{yaml::Hash, Yaml, YamlLoader};
1717

18-
use anyhow::{anyhow, Context, Ok, Result};
18+
use anyhow::{anyhow, Context, Result};
1919
pub type PatchResult = anyhow::Result<()>;
2020

2121
mod device;
@@ -72,7 +72,14 @@ pub fn process_file(yaml_file: &Path) -> Result<()> {
7272

7373
/// Gets the absolute path of relpath from the point of view of frompath.
7474
fn abspath(frompath: &Path, relpath: &Path) -> Result<PathBuf, std::io::Error> {
75-
std::fs::canonicalize(frompath.parent().unwrap().join(relpath))
75+
normpath::BasePath::new(frompath)
76+
.unwrap()
77+
.parent()
78+
.unwrap()
79+
.unwrap()
80+
.join(relpath)
81+
.canonicalize()
82+
.map(|b| b.as_path().into())
7683
}
7784

7885
/// Recursively loads any included YAML files.

src/test_utils.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,14 @@ pub fn get_patcher(test_subdir: &Path) -> Result<(Device, Hash)> {
3939

4040
/// Gets the absolute path of relpath from the point of view of frompath.
4141
fn abspath(frompath: &Path, relpath: &Path) -> PathBuf {
42-
std::fs::canonicalize(frompath.parent().unwrap().join(relpath)).unwrap()
42+
normpath::BasePath::new(frompath)
43+
.unwrap()
44+
.parent()
45+
.unwrap()
46+
.unwrap()
47+
.join(relpath)
48+
.canonicalize()
49+
.unwrap()
50+
.as_path()
51+
.into()
4352
}

svdtools/patch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ def add_cluster(self, cname: str, cadd: OrderedDict[str, Any]) -> None:
978978
)
979979
cnew = ET.SubElement(parent, "cluster")
980980
ET.SubElement(cnew, "name").text = cname
981-
for (key, value) in cadd.items():
981+
for key, value in cadd.items():
982982
# print(key, value)
983983
if key in {"addressOffset"}:
984984
ET.SubElement(cnew, key).text = str(value)
@@ -1299,7 +1299,7 @@ def add_register(self, rname: str, radd: OrderedDict[str, Any]) -> None:
12991299
)
13001300
rnew = ET.SubElement(parent, "register")
13011301
ET.SubElement(rnew, "name").text = rname
1302-
for (key, value) in radd.items():
1302+
for key, value in radd.items():
13031303
if key == "fields":
13041304
ET.SubElement(rnew, "fields")
13051305
for fname in value:
@@ -1312,7 +1312,7 @@ def modify_register(self, rspec: str, rmod: OrderedDict[str, Any]) -> None:
13121312
assert isinstance(rspec, str)
13131313
assert isinstance(rmod, OrderedDict)
13141314
for rtag in self.iter_registers(rspec):
1315-
for (key, value) in rmod.items():
1315+
for key, value in rmod.items():
13161316
tag = rtag.find(key)
13171317
if value == "" and tag is not None:
13181318
rtag.remove(tag)

0 commit comments

Comments
 (0)