Skip to content

Commit

Permalink
Add an UnusableDependencies incompatibility kind (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb authored and konstin committed May 8, 2024
1 parent 144e6e5 commit 6042699
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/internal/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct State<DP: DependencyProvider> {
root_package: DP::P,
root_version: DP::V,

/// All incompatibilities indexed by package.
/// The set of incompatibilities for each package.
#[allow(clippy::type_complexity)]
incompatibilities: Map<DP::P, Vec<IncompDpId<DP>>>,

Expand Down
26 changes: 17 additions & 9 deletions src/internal/incompatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ use crate::version_set::VersionSet;
#[derive(Debug, Clone)]
pub struct Incompatibility<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
package_terms: SmallMap<P, Term<VS>>,
/// The reason for the incompatibility.
/// The reason why this version or combination of versions can't be selected.
pub kind: Kind<P, VS, M>,
}

/// Type alias of unique identifiers for incompatibilities.
pub type IncompId<P, VS, M> = Id<Incompatibility<P, VS, M>>;

/// The reason for the incompatibility.
/// The reason why a version or combination of versions can't be selected.
#[derive(Debug, Clone)]
pub enum Kind<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
/// Initial incompatibility aiming at picking the root package for the first decision.
Expand Down Expand Up @@ -138,6 +138,17 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
}
}

/// Create an incompatibility to remember
/// that a package version is not selectable
/// because its dependencies are not usable.
pub fn unusable_dependencies(package: P, version: VS::V, reason: M) -> Self {
let set = VS::singleton(version);
Self {
package_terms: SmallMap::One([(package.clone(), Term::Positive(set.clone()))]),
kind: Kind::Custom(package, set, reason),
}
}

/// Build an incompatibility from a given dependency.
pub fn from_dependency(package: P, versions: VS, dep: (&P, &VS)) -> Self {
let (p2, set2) = dep;
Expand All @@ -154,8 +165,7 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
}
}

/// Return the two packages where this incompatibility when the incompatibility was created
/// through a dependency edge between the two.
/// The two packages causing the incompatibility, if it was derived from dependencies.
pub fn as_dependency(&self) -> Option<(&P, &P)> {
match &self.kind {
Kind::FromDependencyOf(p1, _, p2, _) => Some((p1, p2)),
Expand Down Expand Up @@ -296,11 +306,9 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
dep_set.clone(),
))
}
Kind::Custom(package, set, metadata) => DerivationTree::External(External::Custom(
package.clone(),
set.clone(),
metadata.clone(),
)),
Kind::Custom(package, set, reason) => {
DerivationTree::External(External::Custom(package, set, reason))
}
}
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree
//
// Cannot be merged because the reason may not match
DerivationTree::External(External::NoVersions(_, _)) => None,
DerivationTree::External(External::Custom(_, r, reason)) => Some(
DerivationTree::External(External::Custom(package, set.union(&r), reason)),
),
DerivationTree::External(External::FromDependencyOf(p1, r1, p2, r2)) => {
if p1 == package {
Some(DerivationTree::External(External::FromDependencyOf(
Expand All @@ -138,8 +141,6 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree
)))
}
}
// Cannot be merged because the reason may not match
DerivationTree::External(External::Custom(_, _, _)) => None,
}
}
}
Expand All @@ -159,18 +160,14 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> fmt::Display
write!(f, "there is no version of {} in {}", package, set)
}
}
Self::Custom(package, set, metadata) => {
Self::Custom(package, set, reason) => {
if set == &VS::full() {
write!(
f,
"dependencies of {} are unavailable {}",
package, metadata
)
write!(f, "dependencies of {} are unusable: {reason}", package)
} else {
write!(
f,
"dependencies of {} at version {} are unavailable {}",
package, set, metadata
"dependencies of {} at version {} are unusable: {reason}",
package, set
)
}
}
Expand Down

0 comments on commit 6042699

Please sign in to comment.