Skip to content

Commit

Permalink
Normalize paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Jan 12, 2024
1 parent f70b6aa commit ccf7eca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ digraph {
4 [ label = "crate cc 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)" ]
5 [ label = "crate cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" ]
6 [ label = "crate cmake 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" ]
7 [ label = "crate feature-bug 0.1.0 (path+file:///home/jake/code/krates/tests/feature-bug)" ]
7 [ label = "crate feature-bug 0.1.0 (path+file:///krates/tests/feature-bug)" ]
8 [ label = "crate getrandom 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" ]
9 [ label = "crate katexit 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" ]
10 [ label = "crate lapack-sys 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" ]
Expand All @@ -31,7 +31,7 @@ digraph {
25 [ label = "crate rand_core 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" ]
26 [ label = "crate rawpointer 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" ]
27 [ label = "crate serde 1.0.195 (registry+https://github.com/rust-lang/crates.io-index)" ]
28 [ label = "crate sub-crate 0.1.0 (path+file:///home/jake/code/krates/tests/feature-bug/sub-crate)" ]
28 [ label = "crate sub-crate 0.1.0 (path+file:///krates/tests/feature-bug/sub-crate)" ]
29 [ label = "crate syn 1.0.109 (registry+https://github.com/rust-lang/crates.io-index)" ]
30 [ label = "crate syn 2.0.48 (registry+https://github.com/rust-lang/crates.io-index)" ]
31 [ label = "crate thiserror 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)" ]
Expand Down
28 changes: 27 additions & 1 deletion tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,33 @@ impl From<krates::cm::Package> for JustId {

impl fmt::Display for JustId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0.repr)
if let Some((prefix, path)) = self.0.repr.split_once("(path+file://") {
let path = &path[..path.len() - 1];
let path = std::path::Path::new(path);

fn push(f: &mut fmt::Formatter<'_>, path: &std::path::Path) {
let Some(file_name) = path.file_name().and_then(|s| s.to_str()) else {
return;
};
if file_name != "krates" {
let Some(parent) = path.parent() else {
return;
};
push(f, parent);
}

f.write_str("/").unwrap();
f.write_str(file_name).unwrap();
}

f.write_str(prefix)?;
f.write_str("(path+file://")?;
push(f, path);
f.write_str(")")?;
Ok(())
} else {
f.write_str(&self.0.repr)
}
}
}

Expand Down

0 comments on commit ccf7eca

Please sign in to comment.