Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / solver / detail / Resolver.h
index 943ff00..31b976f 100644 (file)
 
 #ifndef ZYPP_SOLVER_DETAIL_RESOLVER_H
 #define ZYPP_SOLVER_DETAIL_RESOLVER_H
+#ifndef ZYPP_USE_RESOLVER_INTERNALS
+#error Do not directly include this file!
+#else
 
 #include <iosfwd>
+#include <string>
 #include <list>
 #include <map>
-#include <string>
-
-#include "zypp/base/ReferenceCounted.h"
-#include "zypp/base/PtrTypes.h"
 
 #include "zypp/ResPool.h"
-
-#include "zypp/solver/detail/Types.h"
-#include "zypp/solver/detail/ResolverQueue.h"
-#include "zypp/solver/detail/ResolverContext.h"
+#include "zypp/TriBool.h"
+#include "zypp/base/SerialNumber.h"
+#include "zypp/base/NonCopyable.h"
 
 #include "zypp/ProblemTypes.h"
 #include "zypp/ResolverProblem.h"
 #include "zypp/ProblemSolution.h"
-#include "zypp/UpgradeStatistics.h"
-
-#include "zypp/CapSet.h"
-
+#include "zypp/Capabilities.h"
+#include "zypp/Capability.h"
 
 /////////////////////////////////////////////////////////////////////////
 namespace zypp
-{ ///////////////////////////////////////////////////////////////////////
+{
+  namespace sat
+  {
+    class Transaction;
+  }
   ///////////////////////////////////////////////////////////////////////
   namespace solver
-  { /////////////////////////////////////////////////////////////////////
+  {
     /////////////////////////////////////////////////////////////////////
     namespace detail
-    { ///////////////////////////////////////////////////////////////////
+    {
+      class SATResolver;
+      typedef std::list<PoolItem> PoolItemList;
+      typedef std::set<PoolItem> PoolItemSet;
 
 ///////////////////////////////////////////////////////////////////
 //
 //     CLASS NAME : Resolver
-
-class Resolver : public base::ReferenceCounted, private base::NonCopyable {
-
+/** A mid layer class we should remove
+ * \todo Merge this and class SATResolver. Logic and date are horribly
+ * distributed between this and SATResolver. Either SATResolver becomes
+ * a pure wrapper adapting the libsolv C interface to fit our needs, and
+ * all the solver logic and problem handling goes here; or completely merge
+ * both classes.
+ */
+class Resolver : private base::NonCopyable
+{
+  typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
   private:
     ResPool _pool;
+    SATResolver *_satResolver;
+    SerialNumberWatcher _poolchanged;
+
+    CapabilitySet _extra_requires;
+    CapabilitySet _extra_conflicts;
+    std::set<Repository> _upgradeRepos;
+
+    // Regard dependencies of the item weak onl
+    PoolItemList _addWeak;
+
+    /** \name Solver flags */
+    //@{
+    bool _forceResolve;           // remove items which are conflicts with others or
+                                  // have unfulfilled requirements.
+                                  // This behaviour is favourited by ZMD
+    bool _upgradeMode;            // Resolver has been called with doUpgrade
+    bool _updateMode;            // Resolver has been called with doUpdate
+    bool _verifying;              // The system will be checked
+    bool _onlyRequires;          // do install required resolvables only
+                                  // no recommended resolvables, language
+                                  // packages, hardware packages (modalias)
+    bool _allowVendorChange;   // whether the solver should allow or disallow vendor changes.
+    bool _solveSrcPackages;    // whether to generate solver jobs for selected source packges.
+    bool _cleandepsOnRemove;   // whether removing a package should also remove no longer needed requirements
+
+    bool _ignoreAlreadyRecommended;   //ignore recommended packages that have already been recommended by the installed packages
+    //@}
+
+    // Additional QueueItems which has to be regarded by the solver
+    // This will be used e.g. by solution actions
+    solver::detail::SolverQueueItemList _removed_queue_items;
+    solver::detail::SolverQueueItemList _added_queue_items;
+
+    // Additional information about the solverrun
+    ItemCapKindMap _isInstalledBy;
+    ItemCapKindMap _installs;
+    ItemCapKindMap _satifiedByInstalled;
+    ItemCapKindMap _installedSatisfied;
+
+    // helpers
+    void collectResolverInfo();
+
+    // Unmaintained packages which does not fit to the updated system
+    // (broken dependencies) will be deleted.
+    // returns true if solving was successful
+    bool checkUnmaintainedItems ();
+
+    void solverInit();
 
-    int _timeout_seconds;
-    bool _verifying;
+  public:
 
-    QueueItemList _initial_items;
-    PoolItemList _items_to_install;
-    PoolItemList _items_to_establish;
-    PoolItemList _items_to_remove;
-    PoolItemList _items_to_verify;
+    Resolver( const ResPool & pool );
+    virtual ~Resolver();
 
-    CapSet _extra_caps;
-    CapSet _extra_conflicts;
+    // ---------------------------------- I/O
 
-    //typedef std::map<PoolItem_Ref,Capability> IgnoreMap;
+    std::ostream & dumpOn( std::ostream & str ) const;
 
-    // These conflict should be ignored of the concering item
-    IgnoreMap _ignoreConflicts;
-    // These conflict should be ignored of the concering item    
-    IgnoreMap _ignoreRequires;
-    // Ignore architecture of the item
-    PoolItemList _ignoreArchitecture;
-    // Ignore the status "installed" of the item
-    PoolItemList _ignoreInstalledItem;    
+    friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
+    { return obj.dumpOn (str); }
 
-    ResolverQueueList _pending_queues;
-    ResolverQueueList _pruned_queues;
-    ResolverQueueList _complete_queues;
-    ResolverQueueList _deferred_queues;
-    ResolverQueueList _invalid_queues;
+    // ---------------------------------- methods
 
-    int _valid_solution_count;
+    ResPool pool() const;
+    void setPool( const ResPool & pool ) { _pool = pool; }
 
-    ResolverContext_Ptr _best_context;
-    bool _timed_out;
+    void addUpgradeRepo( Repository repo_r )           { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
+    bool upgradingRepo( Repository repo_r ) const      { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
+    void removeUpgradeRepo( Repository repo_r )                { _upgradeRepos.erase( repo_r ); }
+    void removeUpgradeRepos()                          { _upgradeRepos.clear(); }
+    const std::set<Repository> & upgradeRepos() const  { return _upgradeRepos; }
 
-    std::set<Source_Ref> _subscribed;
+    void addExtraRequire( const Capability & capability );
+    void removeExtraRequire( const Capability & capability );
+    void addExtraConflict( const Capability & capability );
+    void removeExtraConflict( const Capability & capability );
 
-    // helpers
-    bool doesObsoleteCapability (PoolItem_Ref candidate, const Capability & cap);
-    bool doesObsoleteItem (PoolItem_Ref candidate, PoolItem_Ref installed);
+    void removeQueueItem( SolverQueueItem_Ptr item );
+    void addQueueItem( SolverQueueItem_Ptr item );
 
-  public:
+    CapabilitySet extraRequires() const                { return _extra_requires; }
+    CapabilitySet extraConflicts() const       { return _extra_conflicts; }
 
-    Resolver (const ResPool & pool);
-    virtual ~Resolver();
+    void addWeak( const PoolItem & item );
 
-    // ---------------------------------- I/O
+    bool verifySystem();
+    bool resolvePool();
+    bool resolveQueue( SolverQueueItemList & queue );
+    void doUpdate();
 
-    virtual std::ostream & dumpOn( std::ostream & str ) const;
-    friend std::ostream& operator<<(std::ostream& str, const Resolver & obj)
-    { return obj.dumpOn (str); }
+    bool doUpgrade();
+    PoolItemList problematicUpdateItems() const;
 
-    // ---------------------------------- accessors
+    /** \name Solver flags */
+    //@{
+    bool ignoreAlreadyRecommended() const      { return _ignoreAlreadyRecommended; }
+    void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
 
-    QueueItemList initialItems () const { return _initial_items; }
+    bool onlyRequires () const                 { return _onlyRequires; }
+    void setOnlyRequires( TriBool state_r );
 
-    ResolverQueueList pendingQueues () const { return _pending_queues; }
-    ResolverQueueList prunedQueues () const { return _pruned_queues; }
-    ResolverQueueList completeQueues () const { return _complete_queues; }
-    ResolverQueueList deferredQueues () const { return _deferred_queues; }
-    ResolverQueueList invalidQueues () const { return _invalid_queues; }
+    bool forceResolve()        const                   { return _forceResolve; }
+    void setForceResolve( TriBool state_r )    { _forceResolve = indeterminate(state_r) ? false : bool(state_r); }
 
-    ResolverContext_Ptr bestContext (void) const { return _best_context; }
+    bool isUpgradeMode() const                         { return _upgradeMode; }// Resolver has been called with doUpgrade
+    void setUpgradeMode( bool yesno_r )                { _upgradeMode = yesno_r; }
 
-    // ---------------------------------- methods
+    bool isUpdateMode() const                  { return _updateMode; } // Resolver has been called with doUpdate
+
+    bool isVerifyingMode() const               { return _verifying; }  // The system will be checked
+    void setVerifyingMode( TriBool state_r )   { _verifying = indeterminate(state_r) ? false : bool(state_r); }
 
-    void setTimeout (int seconds) { _timeout_seconds = seconds; }
+    bool allowVendorChange() const             { return _allowVendorChange; }
+    void setAllowVendorChange( TriBool state_r );
 
-    ResPool pool (void) const;
-    void setPool (const ResPool & pool) { _pool = pool; }
+    bool solveSrcPackages() const              { return _solveSrcPackages; }
+    void setSolveSrcPackages( TriBool state_r )        { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
 
-    void addSubscribedSource (Source_Ref source);
+    bool cleandepsOnRemove() const             { return _cleandepsOnRemove; }
+    void setCleandepsOnRemove( TriBool state_r );
+    //@}
 
-    void addPoolItemToInstall (PoolItem_Ref item);
-    void addPoolItemsToInstallFromList (PoolItemList & rl);
+#define ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER )  \
+    void ZSETTER( TriBool state_r );           \
+    bool ZGETTER() const;                      \
 
-    void addPoolItemToRemove (PoolItem_Ref item);
-    void addPoolItemsToRemoveFromList (PoolItemList & rl);
+    ZOLV_FLAG_TRIBOOL( dupSetAllowDowngrade,   dupAllowDowngrade )
+    ZOLV_FLAG_TRIBOOL( dupSetAllowNameChange,  dupAllowNameChange )
+    ZOLV_FLAG_TRIBOOL( dupSetAllowArchChange,  dupAllowArchChange )
+    ZOLV_FLAG_TRIBOOL( dupSetAllowVendorChange,        dupAllowVendorChange )
 
-    void addPoolItemToEstablish (PoolItem_Ref item);
-    void addPoolItemsToEstablishFromList (PoolItemList & rl);
+#undef ZOLV_FLAG_TRIBOOL
 
-    void addPoolItemToVerify (PoolItem_Ref item);
+    ResolverProblemList problems() const;
 
-    void addExtraCapability (const Capability & capability);
-    void addExtraConflict (const Capability & capability);
+    void applySolutions( const ProblemSolutionList & solutions );
+    bool applySolution( const ProblemSolution & solution );
 
-    void addIgnoreConflict (const PoolItem_Ref item,
-                           const Capability & capability);
-    void addIgnoreRequires (const PoolItem_Ref item,
-                           const Capability & capability);
-    void addIgnoreArchitecture (const PoolItem_Ref item);
-    void addIgnoreInstalledItem (const PoolItem_Ref item);
+    // Return the Transaction computed by the last solver run.
+    sat::Transaction getTransaction();
 
-    void verifySystem (void);
-    void establishState (const ResolverContext_Ptr context = NULL);
-    void establishPool (void);
-    bool resolveDependencies (const ResolverContext_Ptr context = NULL);
-    bool resolvePool (void);
+    // reset all SOLVER transaction in pool
+    void undo();
 
-    void doUpgrade( zypp::UpgradeStatistics & opt_stats_r );
+    void reset( bool keepExtras = false );
 
-    ResolverProblemList problems (void) const;
-    bool applySolutions (const ProblemSolutionList &solutions);
+    // Get more information about the solverrun
+    // Which item will be installed by another item or triggers an item for
+    // installation
+    ItemCapKindList isInstalledBy( const PoolItem & item );
+    ItemCapKindList installs( const PoolItem & item );
+    ItemCapKindList satifiedByInstalled (const PoolItem & item );
+    ItemCapKindList installedSatisfied( const PoolItem & item );
 
-    void reset (void);
 };
 
 ///////////////////////////////////////////////////////////////////
@@ -179,5 +238,5 @@ class Resolver : public base::ReferenceCounted, private base::NonCopyable {
   ///////////////////////////////////////////////////////////////////////
 };// namespace zypp
 /////////////////////////////////////////////////////////////////////////
-
+#endif // ZYPP_USE_RESOLVER_INTERNALS
 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H