August 11, 2012
Implicit preferences in OR dependencies
Debian packages commonly use or dependencies of the form “a | b” to mean that a or b should be installed, while preferring option a over b. In general, for resolving an or dependency, we will try all options from the left to the right, preferring the left-most option. We also prefer real packages over virtual ones. If one of the alternatives is already installed we use that.
def solve_or(or): best_real = None best_virtual = None for dep in or: for target in dep: if target.name == dep.name and best_real is None: best_real = target if target.name != dep.name and best_virtual is None: best_virtual = target if target.is_installed(): return target return best_real if best_real is not None else best_virtual Now, this way of solving dependencies is slightly problematic. Let us consider a package that depends on: a | b, b. APT will likely choose to install ‘a’ to satisfy the first dependency and ‘b’ to satisfy the second. I currently have draft code around for a future version of APT that will cause it to later on revert unneeded changes, which means that APT will then only install ‘b’. This result closely matches the CUDF solvers and cupt’s solver.
...
Read more 》