21#include <boost/static_assert.hpp>
24#define ZYPP_USE_RESOLVER_INTERNALS
26#include <zypp/base/LogTools.h>
29#include <zypp/solver/detail/Resolver.h>
39#define MAXSOLVERRUNS 5
44#undef ZYPP_BASE_LOGGER_LOGGROUP
45#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::solver"
63 os <<
"<resolver>" << endl;
64 #define OUTS(t) os << " " << #t << ":\t" << t << endl;
69 OUTS( _ignoreAlreadyRecommended );
71 return os <<
"<resolver/>";
78 : _pool(
std::move(pool))
80 , _poolchanged(_pool.serial() )
81 , _upgradeMode ( false )
82 , _updateMode ( false )
83 , _verifying ( false )
84 , _solveSrcPackages ( false )
85 , _ignoreAlreadyRecommended ( true )
86 , _applyDefault_focus ( true )
87 , _applyDefault_forceResolve ( true )
88 , _applyDefault_cleandepsOnRemove ( true )
89 , _applyDefault_onlyRequires ( true )
90 , _applyDefault_allowDowngrade ( true )
91 , _applyDefault_allowNameChange ( true )
92 , _applyDefault_allowArchChange ( true )
93 , _applyDefault_allowVendorChange ( true )
94 , _applyDefault_dupAllowDowngrade ( true )
95 , _applyDefault_dupAllowNameChange ( true )
96 , _applyDefault_dupAllowArchChange ( true )
97 , _applyDefault_dupAllowVendorChange ( true )
100 _satResolver =
new SATResolver(_pool, satPool.get());
110{
return _satResolver->get(); }
115 MIL <<
"setDefaultSolverFlags all=" << all_r << endl;
119#define ZOLV_FLAG_DEFAULT( ZSETTER, ZGETTER ) \
120 if ( all_r || _applyDefault_##ZGETTER ) ZSETTER( indeterminate )
133#undef ZOLV_FLAG_TRIBOOL
146#define ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER, ZVARDEFAULT, ZVARNAME ) \
147 void Resolver::ZSETTER( TriBool state_r ) \
148 { _applyDefault_##ZGETTER = indeterminate(state_r); \
149 bool newval = _applyDefault_##ZGETTER ? ZVARDEFAULT : bool(state_r); \
150 if ( ZVARNAME != newval ) { \
151 DBG << #ZGETTER << ": changed from " << (bool)ZVARNAME << " to " << newval << endl;\
155 bool Resolver::ZGETTER() const \
156 { return ZVARNAME; } \
160#define ZOLV_FLAG_SATSOLV( ZSETTER, ZGETTER, ZVARDEFAULT, ZVARNAME ) \
161 ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER, ZVARDEFAULT, _satResolver->ZVARNAME )
172ZOLV_FLAG_SATSOLV( dupSetAllowNameChange ,dupAllowNameChange ,
ZConfig::instance().solver_dupAllowNameChange() ,_dup_allownamechange )
174ZOLV_FLAG_SATSOLV( dupSetAllowVendorChange ,dupAllowVendorChange ,
ZConfig::instance().solver_dupAllowVendorChange() ,_dup_allowvendorchange )
175#undef ZOLV_FLAG_SATSOLV
176#undef ZOLV_FLAG_TRIBOOL
187 _extra_requires.clear();
188 _extra_conflicts.clear();
191 _isInstalledBy.clear();
193 _satifiedByInstalled.clear();
194 _installedSatisfied.clear();
198{
return _satResolver->problematicUpdateItems(); }
200void Resolver::addExtraRequire(
const Capability & capability )
201{ _extra_requires.insert (capability); }
203void Resolver::removeExtraRequire(
const Capability & capability )
204{ _extra_requires.erase (capability); }
206void Resolver::addExtraConflict(
const Capability & capability )
207{ _extra_conflicts.insert (capability); }
209void Resolver::removeExtraConflict(
const Capability & capability )
210{ _extra_conflicts.erase (capability); }
212void Resolver::removeQueueItem(
const SolverQueueItem_Ptr& item )
215 for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
216 iter != _added_queue_items.end(); iter++) {
218 _added_queue_items.remove(*iter);
224 _removed_queue_items.push_back (item);
225 _removed_queue_items.unique ();
229void Resolver::addQueueItem(
const SolverQueueItem_Ptr& item )
232 for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
233 iter != _removed_queue_items.end(); iter++) {
235 _removed_queue_items.remove(*iter);
241 _added_queue_items.push_back (item);
242 _added_queue_items.unique ();
246void Resolver::addWeak(
const PoolItem & item )
247{ _addWeak.push_back( item ); }
285 MIL <<
"*** undo ***" << endl;
293 _removed_queue_items.clear();
294 _added_queue_items.clear();
299void Resolver::solverInit()
302 static bool poolDumped =
false;
303 MIL <<
"-------------- Calling SAT Solver -------------------" << endl;
304 if ( getenv(
"ZYPP_FULLLOG") and get() ) {
305 Testcase testcase(
"/var/log/YaST2/autoTestcase");
307 testcase.createTestcase (*
this,
true,
false);
310 testcase.createTestcase (*
this,
false,
false);
315 _satResolver->setDistupgrade (_upgradeMode);
316 _satResolver->setUpdatesystem (_updateMode);
317 _satResolver->setFixsystem ( isVerifyingMode() );
318 _satResolver->setSolveSrcPackages ( solveSrcPackages() );
319 _satResolver->setIgnorealreadyrecommended ( ignoreAlreadyRecommended() );
329 _isInstalledBy.clear();
331 _satifiedByInstalled.clear();
332 _installedSatisfied.clear();
337 DBG <<
"Resolver::verifySystem()" << endl;
341 resfilter::ByTransact( ),
342 std::ref(resetting) );
343 return resolvePool();
351 return resolvePool();
357 return _satResolver->resolvePool(_extra_requires, _extra_conflicts, _addWeak, _upgradeRepos );
364 return _satResolver->doUpdate();
372 for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
373 iter != _removed_queue_items.end(); iter++) {
374 for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
375 if ( (*iterQueue)->cmp(*iter) == 0) {
376 MIL <<
"remove from queue" << *iter;
377 queue.remove(*iterQueue);
383 for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
384 iter != _added_queue_items.end(); iter++) {
386 for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
387 if ( (*iterQueue)->cmp(*iter) == 0) {
393 MIL <<
"add to queue" << *iter;
394 queue.push_back(*iter);
400 _removed_queue_items.clear();
401 _added_queue_items.clear();
403 return _satResolver->resolveQueue(queue, _addWeak);
410 ret.autoInstalled( _satResolver->autoInstalled() );
420 MIL <<
"Resolver::problems()" << endl;
421 return _satResolver->problems();
426 for (
const ProblemSolution_Ptr& solution : solutions )
428 if ( ! applySolution( *solution ) )
433bool Resolver::applySolution(
const ProblemSolution & solution )
436 DBG <<
"apply solution " << solution << endl;
437 for (
const SolutionAction_Ptr& action : solution.actions() )
439 if ( ! action->execute( *
this ) )
441 WAR <<
"apply solution action failed: " << action << endl;
451void Resolver::collectResolverInfo()
454 && _isInstalledBy.empty()
455 && _installs.empty()) {
458 PoolItemList itemsToInstall = _satResolver->resultItemsToInstall();
460 for (PoolItemList::const_iterator instIter = itemsToInstall.begin();
461 instIter != itemsToInstall.end(); instIter++) {
463 for (Capabilities::const_iterator capIt = (*instIter)->dep (
Dep::REQUIRES).begin(); capIt != (*instIter)->dep (
Dep::REQUIRES).end(); ++capIt)
465 sat::WhatProvides possibleProviders(*capIt);
466 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
471 bool alreadySetForInstallation =
false;
472 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(provider);
473 while (pos != _isInstalledBy.end()
474 && pos->first == provider
476 alreadySetForInstallation =
true;
477 ItemCapKind capKind = pos->second;
478 if (capKind.item() == *instIter) found =
true;
483 && provider.status().isToBeInstalled()) {
484 if (provider.status().isBySolver()) {
485 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::REQUIRES, !alreadySetForInstallation );
486 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
489 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::REQUIRES,
false );
490 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
492 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::REQUIRES, !alreadySetForInstallation );
493 _installs.insert (make_pair( *instIter, capKindisInstalledBy));
496 if (provider.status().staysInstalled()) {
497 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::REQUIRES,
false );
498 _satifiedByInstalled.insert (make_pair( *instIter, capKindisInstalledBy));
500 ItemCapKind installedSatisfied( *instIter, *capIt,
Dep::REQUIRES,
false );
501 _installedSatisfied.insert (make_pair( provider, installedSatisfied));
506 if (!(_satResolver->onlyRequires())) {
510 sat::WhatProvides possibleProviders(*capIt);
511 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
516 bool alreadySetForInstallation =
false;
517 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(provider);
518 while (pos != _isInstalledBy.end()
519 && pos->first == provider
521 alreadySetForInstallation =
true;
522 ItemCapKind capKind = pos->second;
523 if (capKind.item() == *instIter) found =
true;
528 && provider.status().isToBeInstalled()) {
529 if (provider.status().isBySolver()) {
530 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::RECOMMENDS, !alreadySetForInstallation );
531 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
534 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::RECOMMENDS,
false );
535 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
537 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::RECOMMENDS, !alreadySetForInstallation );
538 _installs.insert (make_pair( *instIter, capKindisInstalledBy));
541 if (provider.status().staysInstalled()) {
542 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::RECOMMENDS,
false );
543 _satifiedByInstalled.insert (make_pair( *instIter, capKindisInstalledBy));
545 ItemCapKind installedSatisfied( *instIter, *capIt,
Dep::RECOMMENDS,
false );
546 _installedSatisfied.insert (make_pair( provider, installedSatisfied));
554 sat::WhatProvides possibleProviders(*capIt);
555 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
559 bool alreadySetForInstallation =
false;
560 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(*instIter);
561 while (pos != _isInstalledBy.end()
562 && pos->first == *instIter
564 alreadySetForInstallation =
true;
565 ItemCapKind capKind = pos->second;
566 if (capKind.item() == provider) found =
true;
571 && instIter->status().isToBeInstalled()) {
572 if (instIter->status().isBySolver()) {
573 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
574 _isInstalledBy.insert (make_pair( *instIter, capKindisInstalledBy));
577 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::SUPPLEMENTS,
false );
578 _isInstalledBy.insert (make_pair( *instIter, capKindisInstalledBy));
580 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
581 _installs.insert (make_pair( provider, capKindisInstalledBy));
584 if (instIter->status().staysInstalled()) {
585 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
586 _satifiedByInstalled.insert (make_pair( provider, capKindisInstalledBy));
588 ItemCapKind installedSatisfied( provider, *capIt,
Dep::SUPPLEMENTS,
false );
589 _installedSatisfied.insert (make_pair( *instIter, installedSatisfied));
602 collectResolverInfo();
604 for (ItemCapKindMap::const_iterator iter = _isInstalledBy.find(item); iter != _isInstalledBy.end();) {
605 ItemCapKind info = iter->second;
606 PoolItem iterItem = iter->first;
607 if (iterItem == item) {
612 iter = _isInstalledBy.end();
621 collectResolverInfo();
623 for (ItemCapKindMap::const_iterator iter = _installs.find(item); iter != _installs.end();) {
624 ItemCapKind info = iter->second;
625 PoolItem iterItem = iter->first;
626 if (iterItem == item) {
631 iter = _installs.end();
640 collectResolverInfo();
642 for (ItemCapKindMap::const_iterator iter = _satifiedByInstalled.find(item); iter != _satifiedByInstalled.end();) {
643 ItemCapKind info = iter->second;
644 PoolItem iterItem = iter->first;
645 if (iterItem == item) {
650 iter = _satifiedByInstalled.end();
659 collectResolverInfo();
661 for (ItemCapKindMap::const_iterator iter = _installedSatisfied.find(item); iter != _installedSatisfied.end();) {
662 ItemCapKind info = iter->second;
663 PoolItem iterItem = iter->first;
664 if (iterItem == item) {
669 iter = _installedSatisfied.end();
Combining sat::Solvable and ResStatus.
ResStatus & status() const
Returns the current status.
PoolItem find(const sat::Solvable &slv_r) const
Return the corresponding PoolItem.
static ResPool instance()
Singleton ctor.
bool setTransact(bool toTansact_r, TransactByValue causer_r)
Toggle between TRANSACT and KEEP_STATE.
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
bool resolveQueue(solver::detail::SolverQueueItemList &queue)
Resolve package dependencies:
sat::detail::CSolver * get() const
Expert backdoor.
void setRemoveOrphaned(bool yesno_r)
Set whether to remove unused orphans in 'upgrade' mode.
void setDefaultSolverFlags(bool all_r=true)
Reset all solver flags to the systems default (e.g.
ResolverProblemList problems()
Return the dependency problems found by the last call to resolveDependencies().
sat::Transaction getTransaction()
Return the Transaction computed by the last solver run.
void doUpdate()
Update to newest package.
std::list< PoolItem > problematicUpdateItems() const
Unmaintained packages which does not fit to the updated system (broken dependencies) will be deleted.
void applySolutions(const ProblemSolutionList &solutions)
Apply problem solutions.
Resolver(const ResPool &pool)
Ctor.
solver::detail::ItemCapKindList isInstalledBy(const PoolItem &item)
Gives information about WHO has pused an installation of an given item.
solver::detail::ItemCapKindList installs(const PoolItem &item)
Gives information about WHICH additional items will be installed due the installation of an item.
bool resolvePool()
Resolve package dependencies:
void setFocus(ResolverFocus focus_r)
Define the resolver's general attitude when resolving jobs.
bool removeOrphaned() const
bool verifySystem()
Resolve package dependencies:
~Resolver() override
Dtor.
bool doUpgrade()
Do an distribution upgrade (DUP)
ResolverFocus focus() const
solver::detail::ItemCapKindList installedSatisfied(const PoolItem &item)
Gives information about WHICH items require an already installed item.
solver::detail::ItemCapKindList satifiedByInstalled(const PoolItem &item)
Gives information about WHICH installed items are requested by the installation of an item.
Interim helper class to collect global options and settings.
ResolverFocus solver_focus() const
The resolver's general attitude when resolving jobs.
static ZConfig & instance()
Singleton ctor.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
static Pool instance()
Singleton ctor.
static constexpr LoadFromPoolType loadFromPool
::s_Solver CSolver
Wrapped libsolv C data type exposed as backdoor.
std::list< SolverQueueItem_Ptr > SolverQueueItemList
std::list< ItemCapKind > ItemCapKindList
_onlyRequires dupAllowDowngrade
_onlyRequires _dup_allowdowngrade dupAllowArchChange
Easy-to use interface to the ZYPP dependency resolver.
ResolverFocus
The resolver's general attitude.
@ Default
Request the standard behavior (as defined in zypp.conf or 'Job')
std::list< ProblemSolution_Ptr > ProblemSolutionList
std::list< ResolverProblem_Ptr > ResolverProblemList
int invokeOnEach(TIterator begin_r, TIterator end_r, TFilter filter_r, TFunction fnc_r)
Iterate through [begin_r,end_r) and invoke fnc_r on each item that passes filter_r.
#define ZOLV_FLAG_SATSOLV(ZSETTER, ZGETTER, ZVARDEFAULT, ZVARNAME)
#define ZOLV_FLAG_DEFAULT(ZSETTER, ZGETTER)
static const Dep REQUIRES
static const Dep RECOMMENDS
static const Dep SUPPLEMENTS
Select PoolItem by transact.
ResStatus::TransactByValue resStatus
DoTransact(const ResStatus::TransactByValue &status)
bool operator()(const PoolItem &item)
bool operator()(const PoolItem &item)
UndoTransact(const ResStatus::TransactByValue &status)
ResStatus::TransactByValue resStatus
#define for_(IT, BEG, END)
Convenient for-loops using iterator.