Skip to content
Open
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
10 changes: 10 additions & 0 deletions apt/private/apt_dep_resolver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load(":version_constraint.bzl", "version_constraint")
def _resolve_package(state, name, version, arch):
# First check if the constraint is satisfied by a virtual package
virtual_packages = state.repository.virtual_packages(name = name, arch = arch)
virtual_packages.extend(state.repository.virtual_packages(name = name, arch = "all"))

candidates = [
package
Expand Down Expand Up @@ -34,6 +35,15 @@ def _resolve_package(state, name, version, arch):
if "Priority" in package and package["Priority"] == "required":
return package

# Sometimes they are provided by multiple versions of the same library
if len({c["Package"]: None for c in candidates}.keys()) == 1:
versions = [c["Version"] for c in candidates]
selected_version = 0
for i in range(1, len(versions)):
if version_constraint.relop(versions[i], versions[selected_version], ">>"):
selected_version = i
return candidates[selected_version]

# Otherwise, we can't disambiguate the virtual package providers so
# choose none and warn.
# buildifier: disable=print
Expand Down
2 changes: 1 addition & 1 deletion apt/private/version_constraint.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _is_satisfied_by(va, vb):
if vb[0] != "=":
fail("Per https://www.debian.org/doc/debian-policy/ch-relationships.html only = is allowed for Provides field.")

return _version_relop(va[1], vb[1], va[0])
return _version_relop(vb[1], va[1], va[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_version_relop(va, vb, op) will return the result of va {op} vb

In the context of is_satisfied_by, va is a constraint (e.g. >= 3.8.1) and vb is a version to be tested (e.g. = 3.8.3-1.1ubuntu4) so before this change we end up testing {constraint_version} {constraint_op} {test_version} (e.g. 3.8.1 >= 3.8.3-1.1ubuntu4) which rejects viable candidates (and could accept wrong candidates).

With this change we do the correct operation.

Note that there is some tests here but they all pass because for these specific test cases the inversion doesn't matter. In particular if you change the last one to (">> 1.1", "= 1.0", False) or the second one to ("<= 1.1", "= 1.0", True), then the test fail on main. I'm happy to add a couple extra cases to this test in the PR 🙏


version_constraint = struct(
relop = _version_relop,
Expand Down