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

Add DerivationTree.packages() -> HashSet<&P> #11

Merged
merged 3 commits into from
Dec 8, 2023
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
7 changes: 7 additions & 0 deletions examples/unsat_root_message_no_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ impl ReportFormatter<Package, Range<SemanticVersion>> for CustomReportFormatter
format!("dependencies of {package} at version {set} are unavailable")
}
}
External::UnusableDependencies(package, set, ..) => {
if set == &Range::full() {
format!("dependencies of {package} are unusable")
} else {
format!("dependencies of {package} at version {set} are unusable")
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to understand this piece... Is this a bad diff? Why was this not necessary before to complete the match?

Copy link
Member Author

@zanieb zanieb Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI on main was broken from a previous rebase which added this upstream example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afab28f just fixes this problem

External::FromDependencyOf(package, package_set, dependency, dependency_set) => {
if package_set == &Range::full() && dependency_set == &Range::full() {
format!("{package} depends on {dependency}")
Expand Down
27 changes: 27 additions & 0 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use std::fmt;
use std::ops::{Deref, DerefMut};

use rustc_hash::FxHashSet;

use crate::package::Package;
use crate::term::Term;
use crate::type_aliases::Map;
Expand Down Expand Up @@ -72,6 +74,31 @@ pub struct Derived<P: Package, VS: VersionSet> {
}

impl<P: Package, VS: VersionSet> DerivationTree<P, VS> {
/// Get all [Package]s referred to in the deriviation tree.
pub fn packages(&self) -> FxHashSet<&P> {
let mut packages = FxHashSet::default();
match self {
Self::External(external) => match external {
External::FromDependencyOf(p, _, p2, _) => {
packages.insert(p);
packages.insert(p2);
}
External::NoVersions(p, _)
| External::NotRoot(p, _)
| External::UnavailableDependencies(p, _)
| External::UnusableDependencies(p, ..) => {
packages.insert(p);
}
},
Self::Derived(derived) => {
packages.extend(derived.terms.keys());
packages.extend(derived.cause1.packages().iter());
packages.extend(derived.cause2.packages().iter());
}
}
packages
}

/// Merge the [NoVersions](External::NoVersions) external incompatibilities
/// with the other one they are matched with
/// in a derived incompatibility.
Expand Down
Loading