Skip to content

Commit 6d15f72

Browse files
zaniebkonstin
authored andcommitted
Add an UnusableDependencies incompatibility kind (#4)
1 parent b78bfdd commit 6d15f72

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
@@ -147,6 +147,9 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree
147147
//
148148
// Cannot be merged because the reason may not match
149149
DerivationTree::External(External::NoVersions(_, _)) => None,
150+
DerivationTree::External(External::Custom(_, r, reason)) => Some(
151+
DerivationTree::External(External::Custom(package, set.union(&r), reason)),
152+
),
150153
DerivationTree::External(External::FromDependencyOf(p1, r1, p2, r2)) => {
151154
if p1 == package {
152155
Some(DerivationTree::External(External::FromDependencyOf(
@@ -164,8 +167,6 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree
164167
)))
165168
}
166169
}
167-
// Cannot be merged because the reason may not match
168-
DerivationTree::External(External::Custom(_, _, _)) => None,
169170
}
170171
}
171172
}
@@ -185,18 +186,14 @@ impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> fmt::Display
185186
write!(f, "there is no version of {} in {}", package, set)
186187
}
187188
}
188-
Self::Custom(package, set, metadata) => {
189+
Self::Custom(package, set, reason) => {
189190
if set == &VS::full() {
190-
write!(
191-
f,
192-
"dependencies of {} are unavailable {}",
193-
package, metadata
194-
)
191+
write!(f, "dependencies of {} are unusable: {reason}", package)
195192
} else {
196193
write!(
197194
f,
198-
"dependencies of {} at version {} are unavailable {}",
199-
package, set, metadata
195+
"dependencies of {} at version {} are unusable: {reason}",
196+
package, set
200197
)
201198
}
202199
}

0 commit comments

Comments
 (0)