Skip to content

Commit e212f1a

Browse files
authored
Add method for incompatibilities between virtual and base packages (#45)
Add a new method to add a single custom incompatibility that requires the base package and the proxy package share the same version range. This intended for cases where proxy packages (also known as virtual packages) are used. Without this information, pubgrub does not know that these packages have to be at the same version. In cases where the base package is already to an incompatible version, this avoids going through all versions of the proxy package. In cases where there are two incompatible proxy packages, it avoids trying versions for both of them. Both improve performance (we don't need to check all versions when there is a conflict) and error messages (report a conflict of version ranges instead of enumerating the conflicting versions). There's several usage patterns for this method. The basic one is upon encountering a dependency on a proxy package with a range, using this method with its base package and that range.
1 parent 51c6bce commit e212f1a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/internal/core.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,38 @@ impl<DP: DependencyProvider> State<DP> {
9797
self.merge_incompatibility(id);
9898
}
9999

100+
/// Add a single custom incompatibility that requires the base package and the proxy package
101+
/// share the same version range.
102+
///
103+
/// This intended for cases where proxy packages (also known as virtual packages) are used.
104+
/// Without this information, pubgrub does not know that these packages have to be at the same
105+
/// version. In cases where the base package is already to an incompatible version, this avoids
106+
/// going through all versions of the proxy package. In cases where there are two incompatible
107+
/// proxy packages, it avoids trying versions for both of them. Both improve performance (we
108+
/// don't need to check all versions when there is a conflict) and error messages (report a
109+
/// conflict of version ranges instead of enumerating the conflicting versions).
110+
///
111+
/// Using this method requires that each version of the proxy package depends on the exact
112+
/// version of the base package.
113+
pub fn add_proxy_package(
114+
&mut self,
115+
proxy_package: Id<DP::P>,
116+
base_package: Id<DP::P>,
117+
versions: DP::VS,
118+
) {
119+
let incompat = Incompatibility::from_dependency(
120+
proxy_package,
121+
versions.clone(),
122+
(base_package, versions),
123+
);
124+
let id = self
125+
.incompatibility_store
126+
.alloc_iter([incompat].into_iter());
127+
for id in IncompDpId::<DP>::range_to_iter(id) {
128+
self.merge_incompatibility(id);
129+
}
130+
}
131+
100132
/// Add an incompatibility to the state.
101133
#[cold]
102134
pub(crate) fn add_incompatibility_from_dependencies(

0 commit comments

Comments
 (0)