From 142d6499b51451d57fc050c71ffcfb8338e02b7e Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 6 Mar 2025 20:07:00 +0100 Subject: solver3: Support pretty printing clauses This will print the underlying dependency which is nicer to read. --- apt-pkg/solver3.cc | 21 ++++++++++++++++----- apt-pkg/solver3.h | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index 5469a1881..d9ed1a7bb 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -231,13 +231,24 @@ bool APT::Solver::Work::operator<(APT::Solver::Work const &b) const return false; } -std::string APT::Solver::Clause::toString(pkgCache &cache) const +std::string APT::Solver::Clause::toString(pkgCache &cache, bool pretty) const { std::string out; - if (auto Pkg = reason.Pkg(cache); not Pkg.end()) - out.append(Pkg.FullName()); - if (auto Ver = reason.Ver(cache); not Ver.end()) - out.append(Ver.ParentPkg().FullName()).append("=").append(Ver.VerStr()); + out.append(reason.toString(cache)); + if (dep && pretty) + { + out.append(" ").append(pkgCache::DepIterator(cache, dep).DepType()).append(" "); + for (auto dep = pkgCache::DepIterator(cache, this->dep); not dep.end(); ++dep) + { + out.append(dep.TargetPkg().FullName(true)); + if (dep.TargetVer()) + out.append(" (").append(dep.CompType()).append(" ").append(dep.TargetVer()).append(")"); + if (!(dep->CompareOp & pkgCache::Dep::Or)) + break; + out.append(" | "); + } + return out; + } out.append(" -> "); for (auto var : solutions) out.append(" | ").append(var.toString(cache)); diff --git a/apt-pkg/solver3.h b/apt-pkg/solver3.h index 73ed26030..519f48b13 100644 --- a/apt-pkg/solver3.h +++ b/apt-pkg/solver3.h @@ -377,7 +377,7 @@ struct APT::Solver::Clause inline Clause(Var reason, Group group, bool optional = false, bool negative = false) : reason(reason), group(group), optional(optional), negative(negative) {} - std::string toString(pkgCache &cache) const; + std::string toString(pkgCache &cache, bool pretty = false) const; }; /** -- cgit v1.2.3-70-g09d2