21 #include <boost/static_assert.hpp> 23 #define ZYPP_USE_RESOLVER_INTERNALS 25 #include <zypp/base/LogTools.h> 28 #include <zypp/solver/detail/Resolver.h> 38 #define MAXSOLVERRUNS 5 43 #undef ZYPP_BASE_LOGGER_LOGGROUP 44 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::solver" 62 os <<
"<resolver>" << endl;
63 #define OUTS(t) os << " " << #t << ":\t" << t << endl; 67 OUTS( _onlyRequires );
69 OUTS( _cleandepsOnRemove );
70 OUTS( _ignoreAlreadyRecommended );
72 return os <<
"<resolver/>";
81 , _poolchanged(_pool.serial() )
82 , _upgradeMode ( false )
83 , _updateMode ( false )
84 , _verifying ( false )
85 , _onlyRequires (
ZConfig::instance().solver_onlyRequires() )
86 , _solveSrcPackages ( false )
87 , _cleandepsOnRemove (
ZConfig::instance().solver_cleandepsOnRemove() )
88 , _ignoreAlreadyRecommended ( true )
89 , _applyDefault_focus ( true )
90 , _applyDefault_forceResolve ( true )
91 , _applyDefault_cleandepsOnRemove ( true )
92 , _applyDefault_onlyRequires ( true )
93 , _applyDefault_allowDowngrade ( true )
94 , _applyDefault_allowNameChange ( true )
95 , _applyDefault_allowArchChange ( true )
96 , _applyDefault_allowVendorChange ( true )
97 , _applyDefault_dupAllowDowngrade ( true )
98 , _applyDefault_dupAllowNameChange ( true )
99 , _applyDefault_dupAllowArchChange ( true )
100 , _applyDefault_dupAllowVendorChange ( true )
103 _satResolver =
new SATResolver(_pool, satPool.get());
113 {
return _satResolver->get(); }
118 MIL <<
"setDefaultSolverFlags all=" << all_r << endl;
122 #define ZOLV_FLAG_DEFAULT( ZSETTER, ZGETTER ) \ 123 if ( all_r || _applyDefault_##ZGETTER ) ZSETTER( indeterminate ) 136 #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; } \ 161 #define ZOLV_FLAG_LOCALTB( ZSETTER, ZGETTER, ZVARDEFAULT ) \ 162 ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER, ZVARDEFAULT, _##ZGETTER ) 164 #define ZOLV_FLAG_SATSOLV( ZSETTER, ZGETTER, ZVARDEFAULT, ZVARNAME ) \ 165 ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER, ZVARDEFAULT, _satResolver->ZVARNAME ) 175 ZOLV_FLAG_SATSOLV( dupSetAllowDowngrade ,dupAllowDowngrade ,
ZConfig::instance().solver_dupAllowDowngrade() ,_dup_allowdowngrade )
177 ZOLV_FLAG_SATSOLV( dupSetAllowArchChange ,dupAllowArchChange ,
ZConfig::instance().solver_dupAllowArchChange() ,_dup_allowarchchange )
179 #undef ZOLV_FLAG_SATSOLV 180 #undef ZOLV_FLAG_LOCALTB 181 #undef ZOLV_FLAG_TRIBOOL 192 _extra_requires.clear();
193 _extra_conflicts.clear();
196 _isInstalledBy.clear();
198 _satifiedByInstalled.clear();
199 _installedSatisfied.clear();
206 return resolvePool();
212 return _satResolver->doUpdate();
216 {
return _satResolver->problematicUpdateItems(); }
218 void Resolver::addExtraRequire(
const Capability & capability )
219 { _extra_requires.insert (capability); }
221 void Resolver::removeExtraRequire(
const Capability & capability )
222 { _extra_requires.erase (capability); }
224 void Resolver::addExtraConflict(
const Capability & capability )
225 { _extra_conflicts.insert (capability); }
227 void Resolver::removeExtraConflict(
const Capability & capability )
228 { _extra_conflicts.erase (capability); }
230 void Resolver::removeQueueItem( SolverQueueItem_Ptr item )
233 for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
234 iter != _added_queue_items.end(); iter++) {
236 _added_queue_items.remove(*iter);
242 _removed_queue_items.push_back (item);
243 _removed_queue_items.unique ();
247 void Resolver::addQueueItem( SolverQueueItem_Ptr item )
250 for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
251 iter != _removed_queue_items.end(); iter++) {
253 _removed_queue_items.remove(*iter);
259 _added_queue_items.push_back (item);
260 _added_queue_items.unique ();
264 void Resolver::addWeak(
const PoolItem & item )
265 { _addWeak.push_back( item ); }
303 DBG <<
"Resolver::verifySystem()" << endl;
309 functor::functorRef<bool,PoolItem>(resetting) );
311 return resolvePool();
320 MIL <<
"*** undo ***" << endl;
323 functor::functorRef<bool,PoolItem>(info) );
328 _removed_queue_items.clear();
329 _added_queue_items.clear();
334 void Resolver::solverInit()
337 static bool poolDumped =
false;
338 MIL <<
"-------------- Calling SAT Solver -------------------" << endl;
339 if ( getenv(
"ZYPP_FULLLOG") and
get() ) {
340 Testcase testcase(
"/var/log/YaST2/autoTestcase");
342 testcase.createTestcase (*
this,
true,
false);
345 testcase.createTestcase (*
this,
false,
false);
349 _satResolver->setFixsystem ( isVerifyingMode() );
350 _satResolver->setIgnorealreadyrecommended ( ignoreAlreadyRecommended() );
352 _satResolver->setUpdatesystem (_updateMode);
353 _satResolver->setSolveSrcPackages ( solveSrcPackages() );
354 _satResolver->setCleandepsOnRemove ( cleandepsOnRemove() );
356 _satResolver->setDistupgrade (_upgradeMode);
359 _satResolver->setDistupgrade_removeunsupported (
false);
363 _isInstalledBy.clear();
365 _satifiedByInstalled.clear();
366 _installedSatisfied.clear();
372 return _satResolver->resolvePool(_extra_requires, _extra_conflicts, _addWeak, _upgradeRepos );
380 for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
381 iter != _removed_queue_items.end(); iter++) {
382 for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
383 if ( (*iterQueue)->cmp(*iter) == 0) {
384 MIL <<
"remove from queue" << *iter;
385 queue.remove(*iterQueue);
391 for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
392 iter != _added_queue_items.end(); iter++) {
394 for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
395 if ( (*iterQueue)->cmp(*iter) == 0) {
401 MIL <<
"add to queue" << *iter;
402 queue.push_back(*iter);
408 _removed_queue_items.clear();
409 _added_queue_items.clear();
411 return _satResolver->resolveQueue(queue, _addWeak);
418 ret.autoInstalled( _satResolver->autoInstalled() );
428 MIL <<
"Resolver::problems()" << endl;
429 return _satResolver->problems();
434 for ( ProblemSolution_Ptr solution : solutions )
436 if ( ! applySolution( *solution ) )
441 bool Resolver::applySolution(
const ProblemSolution & solution )
444 DBG <<
"apply solution " << solution << endl;
445 for ( SolutionAction_Ptr action : solution.actions() )
447 if ( ! action->execute( *
this ) )
449 WAR <<
"apply solution action failed: " << action << endl;
459 void Resolver::collectResolverInfo()
462 && _isInstalledBy.empty()
463 && _installs.empty()) {
466 PoolItemList itemsToInstall = _satResolver->resultItemsToInstall();
468 for (PoolItemList::const_iterator instIter = itemsToInstall.begin();
469 instIter != itemsToInstall.end(); instIter++) {
471 for (Capabilities::const_iterator capIt = (*instIter)->dep (
Dep::REQUIRES).begin(); capIt != (*instIter)->dep (
Dep::REQUIRES).end(); ++capIt)
473 sat::WhatProvides possibleProviders(*capIt);
474 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
479 bool alreadySetForInstallation =
false;
480 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(provider);
481 while (pos != _isInstalledBy.end()
482 && pos->first == provider
484 alreadySetForInstallation =
true;
485 ItemCapKind capKind = pos->second;
486 if (capKind.item() == *instIter) found =
true;
491 && provider.status().isToBeInstalled()) {
492 if (provider.status().isBySolver()) {
493 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::REQUIRES, !alreadySetForInstallation );
494 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
497 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::REQUIRES,
false );
498 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
500 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::REQUIRES, !alreadySetForInstallation );
501 _installs.insert (make_pair( *instIter, capKindisInstalledBy));
504 if (provider.status().staysInstalled()) {
505 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::REQUIRES,
false );
506 _satifiedByInstalled.insert (make_pair( *instIter, capKindisInstalledBy));
508 ItemCapKind installedSatisfied( *instIter, *capIt,
Dep::REQUIRES,
false );
509 _installedSatisfied.insert (make_pair( provider, installedSatisfied));
514 if (!(_satResolver->onlyRequires())) {
518 sat::WhatProvides possibleProviders(*capIt);
519 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
524 bool alreadySetForInstallation =
false;
525 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(provider);
526 while (pos != _isInstalledBy.end()
527 && pos->first == provider
529 alreadySetForInstallation =
true;
530 ItemCapKind capKind = pos->second;
531 if (capKind.item() == *instIter) found =
true;
536 && provider.status().isToBeInstalled()) {
537 if (provider.status().isBySolver()) {
538 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::RECOMMENDS, !alreadySetForInstallation );
539 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
542 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::RECOMMENDS,
false );
543 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
545 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::RECOMMENDS, !alreadySetForInstallation );
546 _installs.insert (make_pair( *instIter, capKindisInstalledBy));
549 if (provider.status().staysInstalled()) {
550 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::RECOMMENDS,
false );
551 _satifiedByInstalled.insert (make_pair( *instIter, capKindisInstalledBy));
553 ItemCapKind installedSatisfied( *instIter, *capIt,
Dep::RECOMMENDS,
false );
554 _installedSatisfied.insert (make_pair( provider, installedSatisfied));
562 sat::WhatProvides possibleProviders(*capIt);
563 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
567 bool alreadySetForInstallation =
false;
568 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(*instIter);
569 while (pos != _isInstalledBy.end()
570 && pos->first == *instIter
572 alreadySetForInstallation =
true;
573 ItemCapKind capKind = pos->second;
574 if (capKind.item() == provider) found =
true;
579 && instIter->status().isToBeInstalled()) {
580 if (instIter->status().isBySolver()) {
581 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
582 _isInstalledBy.insert (make_pair( *instIter, capKindisInstalledBy));
585 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::SUPPLEMENTS,
false );
586 _isInstalledBy.insert (make_pair( *instIter, capKindisInstalledBy));
588 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
589 _installs.insert (make_pair( provider, capKindisInstalledBy));
592 if (instIter->status().staysInstalled()) {
593 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
594 _satifiedByInstalled.insert (make_pair( provider, capKindisInstalledBy));
596 ItemCapKind installedSatisfied( provider, *capIt,
Dep::SUPPLEMENTS,
false );
597 _installedSatisfied.insert (make_pair( *instIter, installedSatisfied));
610 collectResolverInfo();
612 for (ItemCapKindMap::const_iterator iter = _isInstalledBy.find(item); iter != _isInstalledBy.end();) {
613 ItemCapKind info = iter->second;
614 PoolItem iterItem = iter->first;
615 if (iterItem == item) {
620 iter = _isInstalledBy.end();
629 collectResolverInfo();
631 for (ItemCapKindMap::const_iterator iter = _installs.find(item); iter != _installs.end();) {
632 ItemCapKind info = iter->second;
633 PoolItem iterItem = iter->first;
634 if (iterItem == item) {
639 iter = _installs.end();
648 collectResolverInfo();
650 for (ItemCapKindMap::const_iterator iter = _satifiedByInstalled.find(item); iter != _satifiedByInstalled.end();) {
651 ItemCapKind info = iter->second;
652 PoolItem iterItem = iter->first;
653 if (iterItem == item) {
658 iter = _satifiedByInstalled.end();
667 collectResolverInfo();
669 for (ItemCapKindMap::const_iterator iter = _installedSatisfied.find(item); iter != _installedSatisfied.end();) {
670 ItemCapKind info = iter->second;
671 PoolItem iterItem = iter->first;
672 if (iterItem == item) {
677 iter = _installedSatisfied.end();
_allowvendorchange _dup_allownamechange dupAllowVendorChange
void doUpdate()
Update to newest package.
solver::detail::ItemCapKindList installs(const PoolItem &item)
Gives information about WHICH additional items will be installed due the installation of an item...
std::list< ProblemSolution_Ptr > ProblemSolutionList
bool resolvePool()
Resolve package dependencies:
sat::Transaction getTransaction()
Return the Transaction computed by the last solver run.
bool operator()(PoolItem item)
ZOLV_FLAG_LOCALTB(setCleandepsOnRemove, cleandepsOnRemove, ZConfig::instance().solver_cleandepsOnRemove()) ZOLV_FLAG_LOCALTB(setOnlyRequires
static const Dep RECOMMENDS
static const Dep SUPPLEMENTS
static ZConfig & instance()
Singleton ctor.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
PoolItem find(const sat::Solvable &slv_r) const
Return the corresponding PoolItem.
ResolverFocus
The resolver's general attitude.
ResStatus & status() const
Returns the current status.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
UndoTransact(const ResStatus::TransactByValue &status)
bool doUpgrade()
Do an distribution upgrade (DUP)
Request the standard behavior (as defined in zypp.conf or 'Job')
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
std::list< SolverQueueItem_Ptr > SolverQueueItemList
solver::detail::ItemCapKindList isInstalledBy(const PoolItem &item)
Gives information about WHO has pused an installation of an given item.
bool resolveQueue(solver::detail::SolverQueueItemList &queue)
Resolve package dependencies:
ResolverProblemList problems()
Return the dependency problems found by the last call to resolveDependencies().
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...
std::list< ResolverProblem_Ptr > ResolverProblemList
static Pool instance()
Singleton ctor.
#define ZOLV_FLAG_DEFAULT(ZSETTER, ZGETTER)
std::list< PoolItem > problematicUpdateItems() const
Unmaintained packages which does not fit to the updated system (broken dependencies) will be deleted...
ResolverFocus focus() const
ResStatus::TransactByValue resStatus
std::unary_function< PoolItem, bool > PoolItemFilterFunctor
Interim helper class to collect global options and settings.
static const Dep REQUIRES
bool operator()(PoolItem item)
Select PoolItem by transact.
bool setTransact(bool toTansact_r, TransactByValue causer_r)
Toggle between TRANSACT and KEEP_STATE.
void applySolutions(const ProblemSolutionList &solutions)
Apply problem solutions.
static constexpr LoadFromPoolType loadFromPool
ResolverFocus solver_focus() const
The resolver's general attitude when resolving jobs.
void setDefaultSolverFlags(bool all_r=true)
Reset all solver flags to the systems default (e.g.
::s_Solver CSolver
Wrapped libsolv C data type exposed as backdoor.
std::list< ItemCapKind > ItemCapKindList
ResStatus::TransactByValue resStatus
_allowvendorchange dupAllowNameChange
sat::detail::CSolver * get() const
Expert backdoor.
_allowvendorchange ZOLV_FLAG_SATSOLV(dupSetAllowDowngrade, dupAllowDowngrade, ZConfig::instance().solver_dupAllowDowngrade(), _dup_allowdowngrade) ZOLV_FLAG_SATSOLV(dupSetAllowNameChange
bool verifySystem()
Resolve package dependencies:
DoTransact(const ResStatus::TransactByValue &status)
Combining sat::Solvable and ResStatus.
void setFocus(ResolverFocus focus_r)
Define the resolver's general attitude when resolving jobs.
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.
Easy-to use interface to the ZYPP dependency resolver.
Resolver(const ResPool &pool)
Ctor.
static ResPool instance()
Singleton ctor.