summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2026-01-20 13:57:33 +0000
committerJulian Andres Klode <jak@debian.org>2026-01-20 13:57:33 +0000
commit9cb74f8992db1d21b091147ca3791531b3c43a73 (patch)
tree80f46c6ca2d0fd35e66a3d7d054cd33e0934f813 /apt-pkg
parent7fcbb7f89aa22af8761b878927330468193c5806 (diff)
parent34876ed2e5cdf504e2a4f9721486d279ae5f3be6 (diff)
Merge branch 'solver3-why' into 'main'
why: Render info about all providers on virtual packages See merge request apt-team/apt!545
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/solver3.cc41
1 files changed, 28 insertions, 13 deletions
diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc
index 096cbb521..a09c27f2a 100644
--- a/apt-pkg/solver3.cc
+++ b/apt-pkg/solver3.cc
@@ -1372,19 +1372,34 @@ bool DependencySolver::ToDepCache(pkgDepCache &depcache) const
std::string DependencySolver::InternalCliWhy(pkgDepCache &cache, pkgCache::PkgIterator pkg, bool assignment)
{
DependencySolver solver(cache.GetCache(), cache.GetPolicy(), EDSP::Request::Flags(0));
- // In case nothing has a positive dependency on pkg it may not actually be discovered in a `why-not`
- // scenario, so make sure we discover it explicitly.
- solver.Discover(Var(pkg));
- if (not solver.FromDepCache(cache) || not solver.Solve())
- return "";
- std::unordered_set<Var> seen;
std::string buf;
- if (solver[Var(pkg)].assignment == LiftedBool::Undefined)
- return strprintf(buf, "%s is undecided\n", pkg.FullName().c_str()), buf;
- if (assignment && solver[Var(pkg)].assignment != LiftedBool::True)
- return strprintf(buf, "%s is not actually marked for install\n", pkg.FullName().c_str()), buf;
- if (not assignment && solver[Var(pkg)].assignment == LiftedBool::True)
- return strprintf(buf, "%s is actually marked for install\n", pkg.FullName().c_str()), buf;
- return solver.LongWhyStr(Var(pkg), assignment, solver[Var(pkg)].reason, "", seen);
+
+ auto doOne = [&](Var var) -> std::string
+ {
+ solver.Discover(var);
+ if (not solver.FromDepCache(cache) || not solver.Solve())
+ return "";
+ std::unordered_set<Var> seen;
+ if (solver[var].assignment == LiftedBool::Undefined)
+ return strprintf(buf, "%s is undecided\n", var.toString(cache).c_str()), buf;
+ if (assignment && solver[var].assignment != LiftedBool::True)
+ return strprintf(buf, "%s is not actually marked for install\n", var.toString(cache).c_str()), buf;
+ if (not assignment && solver[var].assignment == LiftedBool::True)
+ return strprintf(buf, "%s is actually marked for install\n", var.toString(cache).c_str()), buf;
+ return solver.LongWhyStr(var, assignment, solver[var].reason, "", seen);
+ };
+
+ if (pkg.VersionList().end())
+ {
+ if (pkg.ProvidesList().end())
+ return strprintf(buf, "%s is a virtual package without a provider\n", pkg.FullName().c_str()), buf;
+
+ std::ostringstream out;
+ ioprintf(out, "%s is a virtual package, printing all providers\n", pkg.FullName().c_str());
+ for (auto prv = pkg.ProvidesList(); not prv.end(); ++prv)
+ out << doOne(Var(prv.OwnerVer()));
+ return out.str();
+ }
+ return doOne(Var(pkg));
}
} // namespace APT::Solver