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( _solveSrcPackages );
68 OUTS( _ignoreAlreadyRecommended );
70 return os <<
"<resolver/>";
79 , _poolchanged(_pool.serial() )
80 , _upgradeMode ( false )
81 , _updateMode ( false )
82 , _verifying ( false )
83 , _solveSrcPackages ( false )
84 , _ignoreAlreadyRecommended ( true )
85 , _applyDefault_focus ( true )
86 , _applyDefault_forceResolve ( true )
87 , _applyDefault_cleandepsOnRemove ( true )
88 , _applyDefault_onlyRequires ( true )
89 , _applyDefault_allowDowngrade ( true )
90 , _applyDefault_allowNameChange ( true )
91 , _applyDefault_allowArchChange ( true )
92 , _applyDefault_allowVendorChange ( true )
93 , _applyDefault_dupAllowDowngrade ( true )
94 , _applyDefault_dupAllowNameChange ( true )
95 , _applyDefault_dupAllowArchChange ( true )
96 , _applyDefault_dupAllowVendorChange ( true )
99 _satResolver =
new SATResolver(_pool, satPool.
get());
109{
return _satResolver->get(); }
114 MIL <<
"setDefaultSolverFlags all=" << all_r << endl;
118#define ZOLV_FLAG_DEFAULT( ZSETTER, ZGETTER ) \
119 if ( all_r || _applyDefault_##ZGETTER ) ZSETTER( indeterminate )
132#undef ZOLV_FLAG_TRIBOOL
142#define ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER, ZVARDEFAULT, ZVARNAME ) \
143 void Resolver::ZSETTER( TriBool state_r ) \
144 { _applyDefault_##ZGETTER = indeterminate(state_r); \
145 bool newval = _applyDefault_##ZGETTER ? ZVARDEFAULT : bool(state_r); \
146 if ( ZVARNAME != newval ) { \
147 DBG << #ZGETTER << ": changed from " << (bool)ZVARNAME << " to " << newval << endl;\
151 bool Resolver::ZGETTER() const \
152 { return ZVARNAME; } \
156#define ZOLV_FLAG_SATSOLV( ZSETTER, ZGETTER, ZVARDEFAULT, ZVARNAME ) \
157 ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER, ZVARDEFAULT, _satResolver->ZVARNAME )
168ZOLV_FLAG_SATSOLV( dupSetAllowNameChange ,dupAllowNameChange ,
ZConfig::instance().solver_dupAllowNameChange() ,_dup_allownamechange )
170ZOLV_FLAG_SATSOLV( dupSetAllowVendorChange ,dupAllowVendorChange ,
ZConfig::instance().solver_dupAllowVendorChange() ,_dup_allowvendorchange )
171#undef ZOLV_FLAG_SATSOLV
172#undef ZOLV_FLAG_TRIBOOL
183 _extra_requires.clear();
184 _extra_conflicts.clear();
187 _isInstalledBy.clear();
189 _satifiedByInstalled.clear();
190 _installedSatisfied.clear();
194{
return _satResolver->problematicUpdateItems(); }
196void Resolver::addExtraRequire(
const Capability & capability )
197{ _extra_requires.insert (capability); }
199void Resolver::removeExtraRequire(
const Capability & capability )
200{ _extra_requires.erase (capability); }
202void Resolver::addExtraConflict(
const Capability & capability )
203{ _extra_conflicts.insert (capability); }
205void Resolver::removeExtraConflict(
const Capability & capability )
206{ _extra_conflicts.erase (capability); }
208void Resolver::removeQueueItem( SolverQueueItem_Ptr item )
211 for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
212 iter != _added_queue_items.end(); iter++) {
214 _added_queue_items.remove(*iter);
220 _removed_queue_items.push_back (item);
221 _removed_queue_items.unique ();
225void Resolver::addQueueItem( SolverQueueItem_Ptr item )
228 for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
229 iter != _removed_queue_items.end(); iter++) {
231 _removed_queue_items.remove(*iter);
237 _added_queue_items.push_back (item);
238 _added_queue_items.unique ();
242void Resolver::addWeak(
const PoolItem & item )
243{ _addWeak.push_back( item ); }
281 MIL <<
"*** undo ***" << endl;
289 _removed_queue_items.clear();
290 _added_queue_items.clear();
295void Resolver::solverInit()
298 static bool poolDumped =
false;
299 MIL <<
"-------------- Calling SAT Solver -------------------" << endl;
300 if ( getenv(
"ZYPP_FULLLOG") and get() ) {
301 Testcase testcase(
"/var/log/YaST2/autoTestcase");
303 testcase.createTestcase (*
this,
true,
false);
306 testcase.createTestcase (*
this,
false,
false);
311 _satResolver->setDistupgrade (_upgradeMode);
312 _satResolver->setUpdatesystem (_updateMode);
313 _satResolver->setFixsystem ( isVerifyingMode() );
314 _satResolver->setSolveSrcPackages ( solveSrcPackages() );
315 _satResolver->setIgnorealreadyrecommended ( ignoreAlreadyRecommended() );
319 _satResolver->setDistupgrade_removeunsupported (
false);
323 _isInstalledBy.clear();
325 _satifiedByInstalled.clear();
326 _installedSatisfied.clear();
331 DBG <<
"Resolver::verifySystem()" << endl;
335 resfilter::ByTransact( ),
336 std::ref(resetting) );
337 return resolvePool();
345 return resolvePool();
351 return _satResolver->resolvePool(_extra_requires, _extra_conflicts, _addWeak, _upgradeRepos );
358 return _satResolver->doUpdate();
366 for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
367 iter != _removed_queue_items.end(); iter++) {
368 for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
369 if ( (*iterQueue)->cmp(*iter) == 0) {
370 MIL <<
"remove from queue" << *iter;
371 queue.remove(*iterQueue);
377 for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
378 iter != _added_queue_items.end(); iter++) {
380 for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
381 if ( (*iterQueue)->cmp(*iter) == 0) {
387 MIL <<
"add to queue" << *iter;
388 queue.push_back(*iter);
394 _removed_queue_items.clear();
395 _added_queue_items.clear();
397 return _satResolver->resolveQueue(queue, _addWeak);
404 ret.autoInstalled( _satResolver->autoInstalled() );
414 MIL <<
"Resolver::problems()" << endl;
415 return _satResolver->problems();
420 for ( ProblemSolution_Ptr solution : solutions )
422 if ( ! applySolution( *solution ) )
427bool Resolver::applySolution(
const ProblemSolution & solution )
430 DBG <<
"apply solution " << solution << endl;
431 for ( SolutionAction_Ptr action : solution.actions() )
433 if ( ! action->execute( *
this ) )
435 WAR <<
"apply solution action failed: " << action << endl;
445void Resolver::collectResolverInfo()
448 && _isInstalledBy.empty()
449 && _installs.empty()) {
452 PoolItemList itemsToInstall = _satResolver->resultItemsToInstall();
454 for (PoolItemList::const_iterator instIter = itemsToInstall.begin();
455 instIter != itemsToInstall.end(); instIter++) {
457 for (Capabilities::const_iterator capIt = (*instIter)->dep (
Dep::REQUIRES).begin(); capIt != (*instIter)->dep (
Dep::REQUIRES).end(); ++capIt)
459 sat::WhatProvides possibleProviders(*capIt);
460 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
465 bool alreadySetForInstallation =
false;
466 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(provider);
467 while (pos != _isInstalledBy.end()
468 && pos->first == provider
470 alreadySetForInstallation =
true;
471 ItemCapKind capKind = pos->second;
472 if (capKind.item() == *instIter) found =
true;
477 && provider.status().isToBeInstalled()) {
478 if (provider.status().isBySolver()) {
479 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::REQUIRES, !alreadySetForInstallation );
480 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
483 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::REQUIRES,
false );
484 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
486 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::REQUIRES, !alreadySetForInstallation );
487 _installs.insert (make_pair( *instIter, capKindisInstalledBy));
490 if (provider.status().staysInstalled()) {
491 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::REQUIRES,
false );
492 _satifiedByInstalled.insert (make_pair( *instIter, capKindisInstalledBy));
494 ItemCapKind installedSatisfied( *instIter, *capIt,
Dep::REQUIRES,
false );
495 _installedSatisfied.insert (make_pair( provider, installedSatisfied));
500 if (!(_satResolver->onlyRequires())) {
504 sat::WhatProvides possibleProviders(*capIt);
505 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
510 bool alreadySetForInstallation =
false;
511 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(provider);
512 while (pos != _isInstalledBy.end()
513 && pos->first == provider
515 alreadySetForInstallation =
true;
516 ItemCapKind capKind = pos->second;
517 if (capKind.item() == *instIter) found =
true;
522 && provider.status().isToBeInstalled()) {
523 if (provider.status().isBySolver()) {
524 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::RECOMMENDS, !alreadySetForInstallation );
525 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
528 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::RECOMMENDS,
false );
529 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
531 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::RECOMMENDS, !alreadySetForInstallation );
532 _installs.insert (make_pair( *instIter, capKindisInstalledBy));
535 if (provider.status().staysInstalled()) {
536 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::RECOMMENDS,
false );
537 _satifiedByInstalled.insert (make_pair( *instIter, capKindisInstalledBy));
539 ItemCapKind installedSatisfied( *instIter, *capIt,
Dep::RECOMMENDS,
false );
540 _installedSatisfied.insert (make_pair( provider, installedSatisfied));
548 sat::WhatProvides possibleProviders(*capIt);
549 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
553 bool alreadySetForInstallation =
false;
554 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(*instIter);
555 while (pos != _isInstalledBy.end()
556 && pos->first == *instIter
558 alreadySetForInstallation =
true;
559 ItemCapKind capKind = pos->second;
560 if (capKind.item() == provider) found =
true;
565 && instIter->status().isToBeInstalled()) {
566 if (instIter->status().isBySolver()) {
567 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
568 _isInstalledBy.insert (make_pair( *instIter, capKindisInstalledBy));
571 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::SUPPLEMENTS,
false );
572 _isInstalledBy.insert (make_pair( *instIter, capKindisInstalledBy));
574 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
575 _installs.insert (make_pair( provider, capKindisInstalledBy));
578 if (instIter->status().staysInstalled()) {
579 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
580 _satifiedByInstalled.insert (make_pair( provider, capKindisInstalledBy));
582 ItemCapKind installedSatisfied( provider, *capIt,
Dep::SUPPLEMENTS,
false );
583 _installedSatisfied.insert (make_pair( *instIter, installedSatisfied));
596 collectResolverInfo();
598 for (ItemCapKindMap::const_iterator iter = _isInstalledBy.find(item); iter != _isInstalledBy.end();) {
599 ItemCapKind info = iter->second;
600 PoolItem iterItem = iter->first;
601 if (iterItem == item) {
606 iter = _isInstalledBy.end();
615 collectResolverInfo();
617 for (ItemCapKindMap::const_iterator iter = _installs.find(item); iter != _installs.end();) {
618 ItemCapKind info = iter->second;
619 PoolItem iterItem = iter->first;
620 if (iterItem == item) {
625 iter = _installs.end();
634 collectResolverInfo();
636 for (ItemCapKindMap::const_iterator iter = _satifiedByInstalled.find(item); iter != _satifiedByInstalled.end();) {
637 ItemCapKind info = iter->second;
638 PoolItem iterItem = iter->first;
639 if (iterItem == item) {
644 iter = _satifiedByInstalled.end();
653 collectResolverInfo();
655 for (ItemCapKindMap::const_iterator iter = _installedSatisfied.find(item); iter != _installedSatisfied.end();) {
656 ItemCapKind info = iter->second;
657 PoolItem iterItem = iter->first;
658 if (iterItem == item) {
663 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 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 verifySystem()
Resolve package dependencies:
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.
detail::CPool * get() const
Expert backdoor.
static constexpr LoadFromPoolType loadFromPool
::s_Solver CSolver
Wrapped libsolv C data type exposed as backdoor.
std::list< ItemCapKind > ItemCapKindList
_onlyRequires dupAllowDowngrade
std::list< SolverQueueItem_Ptr > SolverQueueItemList
_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< ResolverProblem_Ptr > ResolverProblemList
std::list< ProblemSolution_Ptr > ProblemSolutionList
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
bool operator()(PoolItem item)
DoTransact(const ResStatus::TransactByValue &status)
bool operator()(PoolItem item)
UndoTransact(const ResStatus::TransactByValue &status)
ResStatus::TransactByValue resStatus
#define for_(IT, BEG, END)
Convenient for-loops using iterator.