libzypp  17.30.2
Resolver.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* Resolver.h
3  *
4  * Copyright (C) 2000-2002 Ximian, Inc.
5  * Copyright (C) 2005 SUSE Linux Products GmbH
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  * 02111-1307, USA.
20  */
21 
22 #ifndef ZYPP_SOLVER_DETAIL_RESOLVER_H
23 #define ZYPP_SOLVER_DETAIL_RESOLVER_H
24 #ifndef ZYPP_USE_RESOLVER_INTERNALS
25 #error Do not directly include this file!
26 #else
27 
28 #include <iosfwd>
29 #include <string>
30 #include <list>
31 #include <map>
32 
33 #include <zypp/solver/Types.h>
34 #include <zypp/base/SerialNumber.h>
35 
37 namespace zypp
38 {
39  namespace sat
40  {
41  class Transaction;
42  }
44  namespace solver
45  {
47  namespace detail
48  {
49  class SATResolver;
50  typedef std::list<PoolItem> PoolItemList;
51  typedef std::set<PoolItem> PoolItemSet;
52 
54 //
55 // CLASS NAME : Resolver
63 class Resolver : private base::NonCopyable
64 {
65  typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
66  private:
67  ResPool _pool;
68  SATResolver *_satResolver;
69  SerialNumberWatcher _poolchanged;
70 
71  CapabilitySet _extra_requires;
72  CapabilitySet _extra_conflicts;
73  std::set<Repository> _upgradeRepos;
74 
75  // Regard dependencies of the item weak onl
76  PoolItemList _addWeak;
77 
80  bool _upgradeMode:1; // Resolver has been called with doUpgrade
81  bool _updateMode:1; // Resolver has been called with doUpdate
82  bool _verifying:1; // The system will be checked
83  bool _onlyRequires:1; // do install required resolvables only
84  bool _solveSrcPackages:1; // whether to generate solver jobs for selected source packges.
85  bool _cleandepsOnRemove:1; // whether removing a package should also remove no longer needed requirements
86  bool _ignoreAlreadyRecommended:1; // ignore recommended packages that have already been recommended by the installed packages
88 
94  bool _applyDefault_focus:1;
95  bool _applyDefault_forceResolve:1;
96  bool _applyDefault_cleandepsOnRemove:1;
97  bool _applyDefault_onlyRequires:1;
98  bool _applyDefault_allowDowngrade:1;
99  bool _applyDefault_allowNameChange:1;
100  bool _applyDefault_allowArchChange:1;
101  bool _applyDefault_allowVendorChange:1;
102  bool _applyDefault_dupAllowDowngrade:1;
103  bool _applyDefault_dupAllowNameChange:1;
104  bool _applyDefault_dupAllowArchChange:1;
105  bool _applyDefault_dupAllowVendorChange:1;
107 
108  // Additional QueueItems which has to be regarded by the solver
109  // This will be used e.g. by solution actions
110  solver::detail::SolverQueueItemList _removed_queue_items;
111  solver::detail::SolverQueueItemList _added_queue_items;
112 
113  // Additional information about the solverrun
114  ItemCapKindMap _isInstalledBy;
115  ItemCapKindMap _installs;
116  ItemCapKindMap _satifiedByInstalled;
117  ItemCapKindMap _installedSatisfied;
118 
119  // helpers
120  void collectResolverInfo();
121 
122  // Unmaintained packages which does not fit to the updated system
123  // (broken dependencies) will be deleted.
124  // returns true if solving was successful
125  bool checkUnmaintainedItems ();
126 
127  void solverInit();
128 
129  public:
130 
131  Resolver( const ResPool & pool );
132  virtual ~Resolver();
133 
134  // ---------------------------------- I/O
135 
136  std::ostream & dumpOn( std::ostream & str ) const;
137 
138  friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
139  { return obj.dumpOn (str); }
140 
141  // ---------------------------------- methods
142 
143  ResPool pool() const;
144  void setPool( const ResPool & pool ) { _pool = pool; }
145 
155  void setDefaultSolverFlags( bool all_r );
156 
157  void addUpgradeRepo( Repository repo_r ) { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
158  bool upgradingRepo( Repository repo_r ) const { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
159  void removeUpgradeRepo( Repository repo_r ) { _upgradeRepos.erase( repo_r ); }
160  void removeUpgradeRepos() { _upgradeRepos.clear(); }
161  const std::set<Repository> & upgradeRepos() const { return _upgradeRepos; }
162 
163  void addExtraRequire( const Capability & capability );
164  void removeExtraRequire( const Capability & capability );
165  void addExtraConflict( const Capability & capability );
166  void removeExtraConflict( const Capability & capability );
167 
168  void removeQueueItem( SolverQueueItem_Ptr item );
169  void addQueueItem( SolverQueueItem_Ptr item );
170 
171  CapabilitySet extraRequires() const { return _extra_requires; }
172  CapabilitySet extraConflicts() const { return _extra_conflicts; }
173 
174  void addWeak( const PoolItem & item );
175 
176  bool verifySystem();
177  bool resolvePool();
178  bool resolveQueue( SolverQueueItemList & queue );
179  void doUpdate();
180 
181  bool doUpgrade();
182  PoolItemList problematicUpdateItems() const;
183 
186  bool ignoreAlreadyRecommended() const { return _ignoreAlreadyRecommended; }
187  void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
188 
189  bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade
190  void setUpgradeMode( bool yesno_r ) { _upgradeMode = yesno_r; }
191 
192  bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate
193  void setUpdateMode( bool yesno_r ) { _updateMode = yesno_r; }
194 
195  bool isVerifyingMode() const { return _verifying; } // The system will be checked
196  void setVerifyingMode( TriBool state_r ) { _verifying = indeterminate(state_r) ? false : bool(state_r); }
197 
198  bool solveSrcPackages() const { return _solveSrcPackages; }
199  void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
201 
202  void setFocus( ResolverFocus focus_r );
203  ResolverFocus focus() const;
204 
205 #define ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER ) \
206  void ZSETTER( TriBool state_r ); \
207  bool ZGETTER() const; \
208 
209  ZOLV_FLAG_TRIBOOL( setForceResolve ,forceResolve )
210  ZOLV_FLAG_TRIBOOL( setCleandepsOnRemove ,cleandepsOnRemove )
211  ZOLV_FLAG_TRIBOOL( setOnlyRequires ,onlyRequires )
212  ZOLV_FLAG_TRIBOOL( setAllowDowngrade ,allowDowngrade )
213  ZOLV_FLAG_TRIBOOL( setAllowNameChange ,allowNameChange )
214  ZOLV_FLAG_TRIBOOL( setAllowArchChange ,allowArchChange )
215  ZOLV_FLAG_TRIBOOL( setAllowVendorChange ,allowVendorChange )
216  ZOLV_FLAG_TRIBOOL( dupSetAllowDowngrade ,dupAllowDowngrade )
217  ZOLV_FLAG_TRIBOOL( dupSetAllowNameChange ,dupAllowNameChange )
218  ZOLV_FLAG_TRIBOOL( dupSetAllowArchChange ,dupAllowArchChange )
219  ZOLV_FLAG_TRIBOOL( dupSetAllowVendorChange ,dupAllowVendorChange )
220 #undef ZOLV_FLAG_TRIBOOL
221 
222  ResolverProblemList problems() const;
223 
224  void applySolutions( const ProblemSolutionList & solutions );
225  bool applySolution( const ProblemSolution & solution );
226 
227  // Return the Transaction computed by the last solver run.
228  sat::Transaction getTransaction();
229 
230  // reset all SOLVER transaction in pool
231  void undo();
232 
233  void reset( bool keepExtras = false );
234 
235  // Get more information about the solverrun
236  // Which item will be installed by another item or triggers an item for
237  // installation
238  ItemCapKindList isInstalledBy( const PoolItem & item );
239  ItemCapKindList installs( const PoolItem & item );
240  ItemCapKindList satifiedByInstalled (const PoolItem & item );
241  ItemCapKindList installedSatisfied( const PoolItem & item );
242 
243 public:
245  sat::detail::CSolver * get() const;
246 };
247 
249  };// namespace detail
252  };// namespace solver
255 };// namespace zypp
257 #endif // ZYPP_USE_RESOLVER_INTERNALS
258 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H
A sat capability.
Definition: Capability.h:60
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:51
Class representing one possible solution to a problem found during resolving.
bool isSystemRepo() const
Return whether this is the system repository.
Definition: Repository.cc:53
Global ResObject pool.
Definition: ResPool.h:61
Dependency resolver interface.
Definition: Resolver.h:45
Simple serial number watcher.
Definition: SerialNumber.h:123
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
Libsolv transaction wrapper.
Definition: Transaction.h:52
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:30
String related utilities and Regular expression matching.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
::s_Solver CSolver
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:65
std::ostream & operator<<(std::ostream &os, const SolutionActionList &actionlist)
_allowvendorchange dupAllowNameChange
Definition: Resolver.cc:176
std::list< ItemCapKind > ItemCapKindList
Definition: Types.h:41
_allowvendorchange _dup_allownamechange dupAllowVendorChange
Definition: Resolver.cc:178
std::list< SolverQueueItem_Ptr > SolverQueueItemList
Definition: Types.h:45
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
ResolverFocus
The resolver's general attitude.
Definition: ResolverFocus.h:22
std::list< ResolverProblem_Ptr > ResolverProblemList
Definition: ProblemTypes.h:46
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:567
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:43
#define ZOLV_FLAG_TRIBOOL(ZSETTER, ZDEFAULT, ZGETTER)
Definition: Resolver.cc:146