21#include <boost/static_assert.hpp>
24#define ZYPP_USE_RESOLVER_INTERNALS
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;
68 OUTS( _solveSrcPackages );
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
149#define ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER, ZVARDEFAULT, ZVARNAME ) \
150 void Resolver::ZSETTER( TriBool state_r ) \
151 { _applyDefault_##ZGETTER = indeterminate(state_r); \
152 bool newval = _applyDefault_##ZGETTER ? ZVARDEFAULT : bool(state_r); \
153 if ( ZVARNAME != newval ) { \
154 DBG << #ZGETTER << ": changed from " << (bool)ZVARNAME << " to " << newval << endl;\
158 bool Resolver::ZGETTER() const \
159 { return ZVARNAME; } \
163#define ZOLV_FLAG_SATSOLV( ZSETTER, ZGETTER, ZVARDEFAULT, ZVARNAME ) \
164 ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER, ZVARDEFAULT, _satResolver->ZVARNAME )
175ZOLV_FLAG_SATSOLV( dupSetAllowNameChange ,dupAllowNameChange ,
ZConfig::instance().solver_dupAllowNameChange() ,_dup_allownamechange )
177ZOLV_FLAG_SATSOLV( dupSetAllowVendorChange ,dupAllowVendorChange ,
ZConfig::instance().solver_dupAllowVendorChange() ,_dup_allowvendorchange )
178#undef ZOLV_FLAG_SATSOLV
179#undef ZOLV_FLAG_TRIBOOL
190 _extra_requires.clear();
191 _extra_conflicts.clear();
194 _isInstalledBy.clear();
196 _satifiedByInstalled.clear();
197 _installedSatisfied.clear();
201{
return _satResolver->problematicUpdateItems(); }
203void Resolver::addExtraRequire(
const Capability & capability )
204{ _extra_requires.insert (capability); }
206void Resolver::removeExtraRequire(
const Capability & capability )
207{ _extra_requires.erase (capability); }
209void Resolver::addExtraConflict(
const Capability & capability )
210{ _extra_conflicts.insert (capability); }
212void Resolver::removeExtraConflict(
const Capability & capability )
213{ _extra_conflicts.erase (capability); }
215void Resolver::removeQueueItem(
const SolverQueueItem_Ptr& item )
218 for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
219 iter != _added_queue_items.end(); iter++) {
221 _added_queue_items.remove(*iter);
227 _removed_queue_items.push_back (item);
228 _removed_queue_items.unique ();
232void Resolver::addQueueItem(
const SolverQueueItem_Ptr& item )
235 for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
236 iter != _removed_queue_items.end(); iter++) {
238 _removed_queue_items.remove(*iter);
244 _added_queue_items.push_back (item);
245 _added_queue_items.unique ();
249void Resolver::addWeak(
const PoolItem & item )
250{ _addWeak.push_back( item ); }
288 MIL <<
"*** undo ***" << endl;
296 _removed_queue_items.clear();
297 _added_queue_items.clear();
302void Resolver::solverInit()
305 static bool poolDumped =
false;
306 MIL <<
"-------------- Calling SAT Solver -------------------" << endl;
307 if ( getenv(
"ZYPP_FULLLOG") and get() ) {
308 Testcase testcase(
"/var/log/YaST2/autoTestcase");
310 testcase.createTestcase (*
this,
true,
false);
313 testcase.createTestcase (*
this,
false,
false);
318 _satResolver->setDistupgrade (_upgradeMode);
319 _satResolver->setUpdatesystem (_updateMode);
320 _satResolver->setFixsystem ( isVerifyingMode() );
321 _satResolver->setSolveSrcPackages ( solveSrcPackages() );
322 _satResolver->setIgnorealreadyrecommended ( ignoreAlreadyRecommended() );
332 _isInstalledBy.clear();
334 _satifiedByInstalled.clear();
335 _installedSatisfied.clear();
340 DBG <<
"Resolver::verifySystem()" << endl;
344 resfilter::ByTransact( ),
345 std::ref(resetting) );
346 return resolvePool();
354 return resolvePool();
360 return _satResolver->resolvePool(_extra_requires, _extra_conflicts, _addWeak, _upgradeRepos );
367 return _satResolver->doUpdate();
375 for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
376 iter != _removed_queue_items.end(); iter++) {
377 for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
378 if ( (*iterQueue)->cmp(*iter) == 0) {
379 MIL <<
"remove from queue" << *iter;
380 queue.remove(*iterQueue);
386 for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
387 iter != _added_queue_items.end(); iter++) {
389 for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
390 if ( (*iterQueue)->cmp(*iter) == 0) {
396 MIL <<
"add to queue" << *iter;
397 queue.push_back(*iter);
403 _removed_queue_items.clear();
404 _added_queue_items.clear();
406 return _satResolver->resolveQueue(queue, _addWeak);
413 ret.autoInstalled( _satResolver->autoInstalled() );
423 MIL <<
"Resolver::problems()" << endl;
424 return _satResolver->problems();
429 for (
const ProblemSolution_Ptr& solution : solutions )
431 if ( ! applySolution( *solution ) )
436bool Resolver::applySolution(
const ProblemSolution & solution )
439 DBG <<
"apply solution " << solution << endl;
440 for (
const SolutionAction_Ptr& action : solution.actions() )
442 if ( ! action->execute( *
this ) )
444 WAR <<
"apply solution action failed: " << action << endl;
454void Resolver::collectResolverInfo()
457 && _isInstalledBy.empty()
458 && _installs.empty()) {
461 PoolItemList itemsToInstall = _satResolver->resultItemsToInstall();
463 for (PoolItemList::const_iterator instIter = itemsToInstall.begin();
464 instIter != itemsToInstall.end(); instIter++) {
466 for (Capabilities::const_iterator capIt = (*instIter)->dep (Dep::REQUIRES).begin(); capIt != (*instIter)->dep (Dep::REQUIRES).end(); ++capIt)
468 sat::WhatProvides possibleProviders(*capIt);
469 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
474 bool alreadySetForInstallation =
false;
475 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(provider);
476 while (pos != _isInstalledBy.end()
477 && pos->first == provider
479 alreadySetForInstallation =
true;
480 ItemCapKind capKind = pos->second;
481 if (capKind.item() == *instIter) found =
true;
486 && provider.status().isToBeInstalled()) {
487 if (provider.status().isBySolver()) {
488 ItemCapKind capKindisInstalledBy( *instIter, *capIt, Dep::REQUIRES, !alreadySetForInstallation );
489 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
492 ItemCapKind capKindisInstalledBy( *instIter, *capIt, Dep::REQUIRES,
false );
493 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
495 ItemCapKind capKindisInstalledBy( provider, *capIt, Dep::REQUIRES, !alreadySetForInstallation );
496 _installs.insert (make_pair( *instIter, capKindisInstalledBy));
499 if (provider.status().staysInstalled()) {
500 ItemCapKind capKindisInstalledBy( provider, *capIt, Dep::REQUIRES,
false );
501 _satifiedByInstalled.insert (make_pair( *instIter, capKindisInstalledBy));
503 ItemCapKind installedSatisfied( *instIter, *capIt, Dep::REQUIRES,
false );
504 _installedSatisfied.insert (make_pair( provider, installedSatisfied));
509 if (!(_satResolver->onlyRequires())) {
511 for (Capabilities::const_iterator capIt = (*instIter)->dep (Dep::RECOMMENDS).begin(); capIt != (*instIter)->dep (Dep::RECOMMENDS).end(); ++capIt)
513 sat::WhatProvides possibleProviders(*capIt);
514 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
519 bool alreadySetForInstallation =
false;
520 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(provider);
521 while (pos != _isInstalledBy.end()
522 && pos->first == provider
524 alreadySetForInstallation =
true;
525 ItemCapKind capKind = pos->second;
526 if (capKind.item() == *instIter) found =
true;
531 && provider.status().isToBeInstalled()) {
532 if (provider.status().isBySolver()) {
533 ItemCapKind capKindisInstalledBy( *instIter, *capIt, Dep::RECOMMENDS, !alreadySetForInstallation );
534 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
537 ItemCapKind capKindisInstalledBy( *instIter, *capIt, Dep::RECOMMENDS,
false );
538 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
540 ItemCapKind capKindisInstalledBy( provider, *capIt, Dep::RECOMMENDS, !alreadySetForInstallation );
541 _installs.insert (make_pair( *instIter, capKindisInstalledBy));
544 if (provider.status().staysInstalled()) {
545 ItemCapKind capKindisInstalledBy( provider, *capIt, Dep::RECOMMENDS,
false );
546 _satifiedByInstalled.insert (make_pair( *instIter, capKindisInstalledBy));
548 ItemCapKind installedSatisfied( *instIter, *capIt, Dep::RECOMMENDS,
false );
549 _installedSatisfied.insert (make_pair( provider, installedSatisfied));
555 for (Capabilities::const_iterator capIt = (*instIter)->dep (Dep::SUPPLEMENTS).begin(); capIt != (*instIter)->dep (Dep::SUPPLEMENTS).end(); ++capIt)
557 sat::WhatProvides possibleProviders(*capIt);
558 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
562 bool alreadySetForInstallation =
false;
563 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(*instIter);
564 while (pos != _isInstalledBy.end()
565 && pos->first == *instIter
567 alreadySetForInstallation =
true;
568 ItemCapKind capKind = pos->second;
569 if (capKind.item() == provider) found =
true;
574 && instIter->status().isToBeInstalled()) {
575 if (instIter->status().isBySolver()) {
576 ItemCapKind capKindisInstalledBy( provider, *capIt, Dep::SUPPLEMENTS, !alreadySetForInstallation );
577 _isInstalledBy.insert (make_pair( *instIter, capKindisInstalledBy));
580 ItemCapKind capKindisInstalledBy( provider, *capIt, Dep::SUPPLEMENTS,
false );
581 _isInstalledBy.insert (make_pair( *instIter, capKindisInstalledBy));
583 ItemCapKind capKindisInstalledBy( *instIter, *capIt, Dep::SUPPLEMENTS, !alreadySetForInstallation );
584 _installs.insert (make_pair( provider, capKindisInstalledBy));
587 if (instIter->status().staysInstalled()) {
588 ItemCapKind capKindisInstalledBy( *instIter, *capIt, Dep::SUPPLEMENTS, !alreadySetForInstallation );
589 _satifiedByInstalled.insert (make_pair( provider, capKindisInstalledBy));
591 ItemCapKind installedSatisfied( provider, *capIt, Dep::SUPPLEMENTS,
false );
592 _installedSatisfied.insert (make_pair( *instIter, installedSatisfied));
605 collectResolverInfo();
607 for (ItemCapKindMap::const_iterator iter = _isInstalledBy.find(item); iter != _isInstalledBy.end();) {
608 ItemCapKind info = iter->second;
609 PoolItem iterItem = iter->first;
610 if (iterItem == item) {
615 iter = _isInstalledBy.end();
624 collectResolverInfo();
626 for (ItemCapKindMap::const_iterator iter = _installs.find(item); iter != _installs.end();) {
627 ItemCapKind info = iter->second;
628 PoolItem iterItem = iter->first;
629 if (iterItem == item) {
634 iter = _installs.end();
643 collectResolverInfo();
645 for (ItemCapKindMap::const_iterator iter = _satifiedByInstalled.find(item); iter != _satifiedByInstalled.end();) {
646 ItemCapKind info = iter->second;
647 PoolItem iterItem = iter->first;
648 if (iterItem == item) {
653 iter = _satifiedByInstalled.end();
662 collectResolverInfo();
664 for (ItemCapKindMap::const_iterator iter = _installedSatisfied.find(item); iter != _installedSatisfied.end();) {
665 ItemCapKind info = iter->second;
666 PoolItem iterItem = iter->first;
667 if (iterItem == item) {
672 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.
void setRemoveUnneeded(bool yesno_r)
File weak remove jobs for unneeded installed packages.
bool removeOrphaned() const
bool verifySystem()
Resolve package dependencies:
~Resolver() override
Dtor.
bool doUpgrade()
Do an distribution upgrade (DUP)
ResolverFocus focus() const
bool removeUnneeded() 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
_onlyRequires dupAllowDowngrade
std::list< ItemCapKind > ItemCapKindList
_onlyRequires _dup_allowdowngrade dupAllowArchChange
Easy-to use interface to the ZYPP dependency resolver.
std::list< ProblemSolution_Ptr > ProblemSolutionList
@ Default
Request the standard behavior (as defined in zypp.conf or 'Job')
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)
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.