Skip to content

Commit

Permalink
Fix filtering for workspace crates comparing canonical with non-canon…
Browse files Browse the repository at this point in the history
…ical paths (#94)

* Fix filtering for workspace crates comparing canonical with non-canonical paths

* Add test

* Fix lints

---------

Co-authored-by: Jake Shadle <[email protected]>
  • Loading branch information
Tastaturtaste and Jake-Shadle authored Nov 11, 2024
1 parent f042cc3 commit 0925e0f
Show file tree
Hide file tree
Showing 4 changed files with 468 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,11 @@ impl Builder {
} else {
for wm in &workspace_members {
if let Ok(i) = packages.binary_search_by(|(id, _pkg)| id.cmp(wm)) {
if self
.workspace_filters
.iter()
.any(|wf| wf == &packages[i].1.manifest_path)
{
let mp = packages[i].1.manifest_path.as_std_path();
let manifest_path = mp.canonicalize();

let mp = manifest_path.as_deref().unwrap_or(mp);
if self.workspace_filters.iter().any(|wf| wf == mp) {
roots.insert(wm);
}
}
Expand Down
23 changes: 10 additions & 13 deletions src/cm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,16 @@ pub struct Metadata {
impl Metadata {
/// Get the workspace's root package of this metadata instance.
pub fn root_package(&self) -> Option<&Package> {
match &self.resolve {
Some(resolve) => {
// if dependencies are resolved, use Cargo's answer
let root = resolve.root.as_ref()?;
self.packages.iter().find(|pkg| &pkg.id == root)
}
None => {
// if dependencies aren't resolved, check for a root package manually
let root_manifest_path = self.workspace_root.join("Cargo.toml");
self.packages
.iter()
.find(|pkg| pkg.manifest_path == root_manifest_path)
}
if let Some(resolve) = &self.resolve {
// if dependencies are resolved, use Cargo's answer
let root = resolve.root.as_ref()?;
self.packages.iter().find(|pkg| &pkg.id == root)
} else {
// if dependencies aren't resolved, check for a root package manually
let root_manifest_path = self.workspace_root.join("Cargo.toml");
self.packages
.iter()
.find(|pkg| pkg.manifest_path == root_manifest_path)
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/exclude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ fn excludes_workspace_member() {
insta::assert_snapshot!(grafs.dotgraph());
}

#[test]
fn includes_by_path() {
let mut kb = krates::Builder::new();
kb.include_workspace_crates(["/home/jake/code/krates/tests/ws/c"]);

let grafs = build("all-features.json", kb).unwrap();

insta::assert_snapshot!(grafs.dotgraph());
}

#[test]
fn excludes_dependencies() {
let mut kb = krates::Builder::new();
Expand Down
Loading

0 comments on commit 0925e0f

Please sign in to comment.