Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filtering for workspace crates comparing canonical with non-canonical paths #94

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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