Skip to content

Commit a1515b9

Browse files
zaniebkonstin
authored andcommitted
Add an UnusableDependencies incompatibility kind (#4)
1 parent 21226b8 commit a1515b9

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

src/internal/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct State<DP: DependencyProvider> {
2525
root_package: DP::P,
2626
root_version: DP::V,
2727

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

src/internal/incompatibility.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ use crate::version_set::VersionSet;
3434
#[derive(Debug, Clone)]
3535
pub struct Incompatibility<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> {
3636
package_terms: SmallMap<P, Term<VS>>,
37-
/// The reason for the incompatibility.
37+
/// The reason why this version or combination of versions can't be selected.
3838
pub kind: Kind<P, VS, M>,
3939
}
4040

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

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

141+
/// Create an incompatibility to remember
142+
/// that a package version is not selectable
143+
/// because its dependencies are not usable.
144+
pub fn unusable_dependencies(package: P, version: VS::V, reason: M) -> Self {
145+
let set = VS::singleton(version);
146+
Self {
147+
package_terms: SmallMap::One([(package.clone(), Term::Positive(set.clone()))]),
148+
kind: Kind::Custom(package, set, reason),
149+
}
150+
}
151+
141152
/// Build an incompatibility from a given dependency.
142153
pub fn from_dependency(package: P, versions: VS, dep: (&P, &VS)) -> Self {
143154
let (p2, set2) = dep;
@@ -154,8 +165,7 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
154165
}
155166
}
156167

157-
/// Return the two packages where this incompatibility when the incompatibility was created
158-
/// through a dependency edge between the two.
168+
/// The two packages causing the incompatibility, if it was derived from dependencies.
159169
pub fn as_dependency(&self) -> Option<(&P, &P)> {
160170
match &self.kind {
161171
Kind::FromDependencyOf(p1, _, p2, _) => Some((p1, p2)),
@@ -296,11 +306,9 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> Incompatibilit
296306
dep_set.clone(),
297307
))
298308
}
299-
Kind::Custom(package, set, metadata) => DerivationTree::External(External::Custom(
300-
package.clone(),
301-
set.clone(),
302-
metadata.clone(),
303-
)),
309+
Kind::Custom(package, set, reason) => {
310+
DerivationTree::External(External::Custom(package, set, reason))
311+
}
304312
}
305313
}
306314
}

src/report.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree
121121
//
122122
// Cannot be merged because the reason may not match
123123
DerivationTree::External(External::NoVersions(_, _)) => None,
124+
DerivationTree::External(External::Custom(_, r, reason)) => Some(
125+
DerivationTree::External(External::Custom(package, set.union(&r), reason)),
126+
),
124127
DerivationTree::External(External::FromDependencyOf(p1, r1, p2, r2)) => {
125128
if p1 == package {
126129
Some(DerivationTree::External(External::FromDependencyOf(
@@ -138,8 +141,6 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree
138141
)))
139142
}
140143
}
141-
// Cannot be merged because the reason may not match
142-
DerivationTree::External(External::Custom(_, _, _)) => None,
143144
}
144145
}
145146
}
@@ -159,18 +160,14 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> fmt::Display
159160
write!(f, "there is no version of {} in {}", package, set)
160161
}
161162
}
162-
Self::Custom(package, set, metadata) => {
163+
Self::Custom(package, set, reason) => {
163164
if set == &VS::full() {
164-
write!(
165-
f,
166-
"dependencies of {} are unavailable {}",
167-
package, metadata
168-
)
165+
write!(f, "dependencies of {} are unusable: {reason}", package)
169166
} else {
170167
write!(
171168
f,
172-
"dependencies of {} at version {} are unavailable {}",
173-
package, set, metadata
169+
"dependencies of {} at version {} are unusable: {reason}",
170+
package, set
174171
)
175172
}
176173
}

0 commit comments

Comments
 (0)