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 ) 165 ZOLV_FLAG_SATSOLV( setAllowArchChange ,allowArchChange ,false ,_allowarchchange )
166 ZOLV_FLAG_SATSOLV( setAllowVendorChange ,allowVendorChange ,
ZConfig::instance().solver_allowVendorChange() ,_allowvendorchange )
168 ZOLV_FLAG_SATSOLV( dupSetAllowNameChange ,dupAllowNameChange ,
ZConfig::instance().solver_dupAllowNameChange() ,_dup_allownamechange )
170 ZOLV_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();
197 return resolvePool();
203 return _satResolver->doUpdate();
207 {
return _satResolver->problematicUpdateItems(); }
209 void Resolver::addExtraRequire(
const Capability & capability )
210 { _extra_requires.insert (capability); }
212 void Resolver::removeExtraRequire(
const Capability & capability )
213 { _extra_requires.erase (capability); }
215 void Resolver::addExtraConflict(
const Capability & capability )
216 { _extra_conflicts.insert (capability); }
218 void Resolver::removeExtraConflict(
const Capability & capability )
219 { _extra_conflicts.erase (capability); }
221 void Resolver::removeQueueItem( SolverQueueItem_Ptr item )
224 for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
225 iter != _added_queue_items.end(); iter++) {
227 _added_queue_items.remove(*iter);
233 _removed_queue_items.push_back (item);
234 _removed_queue_items.unique ();
238 void Resolver::addQueueItem( SolverQueueItem_Ptr item )
241 for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
242 iter != _removed_queue_items.end(); iter++) {
244 _removed_queue_items.remove(*iter);
250 _added_queue_items.push_back (item);
251 _added_queue_items.unique ();
255 void Resolver::addWeak(
const PoolItem & item )
256 { _addWeak.push_back( item ); }
294 DBG <<
"Resolver::verifySystem()" << endl;
300 std::ref(resetting) );
302 return resolvePool();
311 MIL <<
"*** undo ***" << endl;
319 _removed_queue_items.clear();
320 _added_queue_items.clear();
325 void Resolver::solverInit()
328 static bool poolDumped =
false;
329 MIL <<
"-------------- Calling SAT Solver -------------------" << endl;
330 if ( getenv(
"ZYPP_FULLLOG") and
get() ) {
331 Testcase testcase(
"/var/log/YaST2/autoTestcase");
333 testcase.createTestcase (*
this,
true,
false);
336 testcase.createTestcase (*
this,
false,
false);
340 _satResolver->setFixsystem ( isVerifyingMode() );
341 _satResolver->setIgnorealreadyrecommended ( ignoreAlreadyRecommended() );
342 _satResolver->setUpdatesystem (_updateMode);
343 _satResolver->setSolveSrcPackages ( solveSrcPackages() );
345 _satResolver->setDistupgrade (_upgradeMode);
348 _satResolver->setDistupgrade_removeunsupported (
false);
352 _isInstalledBy.clear();
354 _satifiedByInstalled.clear();
355 _installedSatisfied.clear();
361 return _satResolver->resolvePool(_extra_requires, _extra_conflicts, _addWeak, _upgradeRepos );
369 for (SolverQueueItemList::const_iterator iter = _removed_queue_items.begin();
370 iter != _removed_queue_items.end(); iter++) {
371 for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
372 if ( (*iterQueue)->cmp(*iter) == 0) {
373 MIL <<
"remove from queue" << *iter;
374 queue.remove(*iterQueue);
380 for (SolverQueueItemList::const_iterator iter = _added_queue_items.begin();
381 iter != _added_queue_items.end(); iter++) {
383 for (SolverQueueItemList::const_iterator iterQueue = queue.begin(); iterQueue != queue.end(); iterQueue++) {
384 if ( (*iterQueue)->cmp(*iter) == 0) {
390 MIL <<
"add to queue" << *iter;
391 queue.push_back(*iter);
397 _removed_queue_items.clear();
398 _added_queue_items.clear();
400 return _satResolver->resolveQueue(queue, _addWeak);
407 ret.autoInstalled( _satResolver->autoInstalled() );
417 MIL <<
"Resolver::problems()" << endl;
418 return _satResolver->problems();
423 for ( ProblemSolution_Ptr solution : solutions )
425 if ( ! applySolution( *solution ) )
430 bool Resolver::applySolution(
const ProblemSolution & solution )
433 DBG <<
"apply solution " << solution << endl;
434 for ( SolutionAction_Ptr action : solution.actions() )
436 if ( ! action->execute( *
this ) )
438 WAR <<
"apply solution action failed: " << action << endl;
448 void Resolver::collectResolverInfo()
451 && _isInstalledBy.empty()
452 && _installs.empty()) {
455 PoolItemList itemsToInstall = _satResolver->resultItemsToInstall();
457 for (PoolItemList::const_iterator instIter = itemsToInstall.begin();
458 instIter != itemsToInstall.end(); instIter++) {
460 for (Capabilities::const_iterator capIt = (*instIter)->dep (
Dep::REQUIRES).begin(); capIt != (*instIter)->dep (
Dep::REQUIRES).end(); ++capIt)
462 sat::WhatProvides possibleProviders(*capIt);
463 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
468 bool alreadySetForInstallation =
false;
469 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(provider);
470 while (pos != _isInstalledBy.end()
471 && pos->first == provider
473 alreadySetForInstallation =
true;
474 ItemCapKind capKind = pos->second;
475 if (capKind.item() == *instIter) found =
true;
480 && provider.status().isToBeInstalled()) {
481 if (provider.status().isBySolver()) {
482 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::REQUIRES, !alreadySetForInstallation );
483 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
486 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::REQUIRES,
false );
487 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
489 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::REQUIRES, !alreadySetForInstallation );
490 _installs.insert (make_pair( *instIter, capKindisInstalledBy));
493 if (provider.status().staysInstalled()) {
494 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::REQUIRES,
false );
495 _satifiedByInstalled.insert (make_pair( *instIter, capKindisInstalledBy));
497 ItemCapKind installedSatisfied( *instIter, *capIt,
Dep::REQUIRES,
false );
498 _installedSatisfied.insert (make_pair( provider, installedSatisfied));
503 if (!(_satResolver->onlyRequires())) {
507 sat::WhatProvides possibleProviders(*capIt);
508 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
513 bool alreadySetForInstallation =
false;
514 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(provider);
515 while (pos != _isInstalledBy.end()
516 && pos->first == provider
518 alreadySetForInstallation =
true;
519 ItemCapKind capKind = pos->second;
520 if (capKind.item() == *instIter) found =
true;
525 && provider.status().isToBeInstalled()) {
526 if (provider.status().isBySolver()) {
527 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::RECOMMENDS, !alreadySetForInstallation );
528 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
531 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::RECOMMENDS,
false );
532 _isInstalledBy.insert (make_pair( provider, capKindisInstalledBy));
534 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::RECOMMENDS, !alreadySetForInstallation );
535 _installs.insert (make_pair( *instIter, capKindisInstalledBy));
538 if (provider.status().staysInstalled()) {
539 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::RECOMMENDS,
false );
540 _satifiedByInstalled.insert (make_pair( *instIter, capKindisInstalledBy));
542 ItemCapKind installedSatisfied( *instIter, *capIt,
Dep::RECOMMENDS,
false );
543 _installedSatisfied.insert (make_pair( provider, installedSatisfied));
551 sat::WhatProvides possibleProviders(*capIt);
552 for_( iter, possibleProviders.begin(), possibleProviders.end() ) {
556 bool alreadySetForInstallation =
false;
557 ItemCapKindMap::const_iterator pos = _isInstalledBy.find(*instIter);
558 while (pos != _isInstalledBy.end()
559 && pos->first == *instIter
561 alreadySetForInstallation =
true;
562 ItemCapKind capKind = pos->second;
563 if (capKind.item() == provider) found =
true;
568 && instIter->status().isToBeInstalled()) {
569 if (instIter->status().isBySolver()) {
570 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
571 _isInstalledBy.insert (make_pair( *instIter, capKindisInstalledBy));
574 ItemCapKind capKindisInstalledBy( provider, *capIt,
Dep::SUPPLEMENTS,
false );
575 _isInstalledBy.insert (make_pair( *instIter, capKindisInstalledBy));
577 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
578 _installs.insert (make_pair( provider, capKindisInstalledBy));
581 if (instIter->status().staysInstalled()) {
582 ItemCapKind capKindisInstalledBy( *instIter, *capIt,
Dep::SUPPLEMENTS, !alreadySetForInstallation );
583 _satifiedByInstalled.insert (make_pair( provider, capKindisInstalledBy));
585 ItemCapKind installedSatisfied( provider, *capIt,
Dep::SUPPLEMENTS,
false );
586 _installedSatisfied.insert (make_pair( *instIter, installedSatisfied));
599 collectResolverInfo();
601 for (ItemCapKindMap::const_iterator iter = _isInstalledBy.find(item); iter != _isInstalledBy.end();) {
602 ItemCapKind info = iter->second;
603 PoolItem iterItem = iter->first;
604 if (iterItem == item) {
609 iter = _isInstalledBy.end();
618 collectResolverInfo();
620 for (ItemCapKindMap::const_iterator iter = _installs.find(item); iter != _installs.end();) {
621 ItemCapKind info = iter->second;
622 PoolItem iterItem = iter->first;
623 if (iterItem == item) {
628 iter = _installs.end();
637 collectResolverInfo();
639 for (ItemCapKindMap::const_iterator iter = _satifiedByInstalled.find(item); iter != _satifiedByInstalled.end();) {
640 ItemCapKind info = iter->second;
641 PoolItem iterItem = iter->first;
642 if (iterItem == item) {
647 iter = _satifiedByInstalled.end();
656 collectResolverInfo();
658 for (ItemCapKindMap::const_iterator iter = _installedSatisfied.find(item); iter != _installedSatisfied.end();) {
659 ItemCapKind info = iter->second;
660 PoolItem iterItem = iter->first;
661 if (iterItem == item) {
666 iter = _installedSatisfied.end();
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)
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)
ZOLV_FLAG_SATSOLV(setCleandepsOnRemove, cleandepsOnRemove, ZConfig::instance().solver_cleandepsOnRemove(), _cleandepsOnRemove) ZOLV_FLAG_SATSOLV(setOnlyRequires
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().
_onlyRequires _dup_allowdowngrade dupAllowArchChange
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
Interim helper class to collect global options and settings.
detail::CPool * get() const
Expert backdoor.
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
_onlyRequires dupAllowDowngrade
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
sat::detail::CSolver * get() const
Expert backdoor.
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.