24ca3cd1a1ebd3edf056015db45d238e921ee80b
[platform/upstream/libzypp.git] / zypp / Resolver.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/Resolver.h
10  *
11 */
12 #ifndef ZYPP_RESOLVER_H
13 #define ZYPP_RESOLVER_H
14
15 #include <iosfwd>
16 #include <functional>
17
18 #include "zypp/base/ReferenceCounted.h"
19 #include "zypp/base/PtrTypes.h"
20
21 #include "zypp/ResPool.h"
22 #include "zypp/UpgradeStatistics.h"
23 #include "zypp/solver/detail/Resolver.h"
24 #include "zypp/solver/detail/SolverQueueItem.h"
25 #include "zypp/ProblemTypes.h"
26
27 ///////////////////////////////////////////////////////////////////
28 namespace zypp
29 { /////////////////////////////////////////////////////////////////
30
31
32   ///////////////////////////////////////////////////////////////////
33   //
34   //    CLASS NAME : Resolver
35   //
36   /**
37    * Dependency resolver interface.
38    *
39    * To resolve dependencies after making changes to the \ref ResPool (using
40    * \ref addRequire(), \ref addConflict(), \ref applySolutions(), or by making
41    * the changes directly on the \ref PoolItem status objects,
42    * call the \ref resolvePool() method.
43    */
44   class Resolver : public base::ReferenceCounted, private base::NonCopyable
45   {
46   public:
47
48     /** Ctor */
49     Resolver( const ResPool & pool );
50     /** Dtor */
51     virtual ~Resolver();
52
53     /**
54      * Resolve package dependencies:
55      *
56      * Enter \ref systemVerification mode to monitor and repair dependencies
57      * of already installed packages, and solve immediately.
58      *
59      * Call \ref setSystemVerification to turn of this mode.
60      **/
61     bool verifySystem();
62
63
64     /**
65      * Resolve package dependencies:
66      *
67      * Try to execute all pending transactions (there may be more than
68      * one!).
69      * The solver collects all transactions (install/delete resolvables)
70      * from the pool, generates task, solving it and writes the
71      * results back to pool
72      *
73      * Returns "true" on success (i.e., if there were no problems that
74      * need user interaction) and "false" if there were problems.  In
75      * the latter case, use problems() and later applySolutions()
76      * below.
77      **/
78     bool resolvePool();
79
80
81     /**
82      * Resolve package dependencies:
83      *
84      * The solver works off the given queue and writes back the solution
85      * to pool.
86      *
87      * Returns "true" on success (i.e., if there were no problems that
88      * need user interaction) and "false" if there were problems.  In
89      * the latter case, use problems() and later applySolutions()
90      * below.
91      * The solution could be that the solver remove/add some entries
92      * in the task queue. So make a new call of resolveQueue after you
93      * have applied any solution AND check the parameter "queue" if
94      * there has been any changes by the solver and adapt these changes
95      * to e.g. the selectables.
96      *
97      **/
98     bool resolveQueue( solver::detail::SolverQueueItemList & queue );
99
100     /*
101      * Undo solver changes done in resolvePool()
102      * Throwing away all ignored dependencies.
103      */
104     void undo();
105
106     /*
107      * Resets solver information and verify option.
108      */
109     void reset();
110
111
112     /**
113      * Do an distribution upgrade
114      *
115      * Perform a distribution upgrade. This performs an update of
116      * all packages with a special resolver algorithm which takes
117      * care of package splits, pattern  and  product  updates,
118      * etc.
119      **/
120     bool doUpgrade();
121     /** \deprecated The UpgradeStatistics argument is a meanwhile useless relict of pre-satsolver days. */
122     ZYPP_DEPRECATED bool doUpgrade( UpgradeStatistics & )
123     { return doUpgrade(); }
124
125     /**
126      * Update to newest package
127      *
128      * Install the newest version of your installed packages as
129      * far as possible. This means a newer package will NOT be
130      * installed if it generates dependency problems.
131      * So the user will not get an error message.
132      *
133      **/
134     void doUpdate( );
135
136
137     /**
138      * Unmaintained packages which does not fit to
139      * the updated system (broken dependencies) will be
140      * deleted.
141      * Return the list of deleted items.
142      * Note : This list is valid after the call doUpgrade() only.
143      **/
144     std::list<PoolItem> problematicUpdateItems() const;
145
146     /**
147      * Return the dependency problems found by the last call to
148      * resolveDependencies(). If there were no problems, the returned
149      * list will be empty.
150      **/
151     ResolverProblemList problems();
152
153
154     /**
155      * Apply problem solutions. No more than one solution per problem
156      * can be applied.
157      **/
158     void applySolutions( const ProblemSolutionList & solutions );
159
160
161     /**
162      * Remove resolvables which are conflicts with others or
163      * have unfulfilled requirements.
164      * This behaviour is favourited by ZMD.
165      **/
166     void setForceResolve( bool force );
167     bool forceResolve();
168
169     /**
170      * Ignore recommended packages that were already recommended by
171      * the installed packages
172      **/
173     void setIgnoreAlreadyRecommended( bool yesno_r );
174     bool ignoreAlreadyRecommended();
175
176     /**
177      * Setting whether required packages are installed ONLY
178      * So recommended packages, language packages and packages which depend
179      * on hardware (modalias) will not be regarded.
180      **/
181     void setOnlyRequires( bool yesno_r );
182     void resetOnlyRequires(); // set back to default (described in zypp.conf)
183     bool onlyRequires();
184
185     /**
186      * Setting whether the solver should allow or disallow vendor changes.
187      *
188      * If OFF (the default) the solver will replace packages with packages
189      * of the same (or equivalent) vendor ony.
190      *
191      * \see \ref VendorAttr for definition of vendor equivalence.
192      **/
193     void setAllowVendorChange( bool yesno_r );
194     void setDefaultAllowVendorChange(); // set back to default (in zypp.conf)
195     bool allowVendorChange() const;
196
197     /**
198      * System verification mode also monitors and repairs dependencies
199      * of already installed packages.
200      * \see \ref verifySystem
201      */
202     void setSystemVerification( bool yesno_r );
203     void setDefaultSystemVerification();
204     bool systemVerification() const;
205
206     /**
207      * Set whether to solve source packages build dependencies per default.
208      * Usually turned off and if, enabled per source package.
209      * \NOTE This affects only source packges selected in the \ref ResPool. No solver rule
210      * will be generated for them. Source packages requested via e.g. \ref addRequire will
211      * always be solved.
212      * \NOTE Be carefull. The older the source package is, the stranger may be the
213      * result of solving it's build dependencies.
214      */
215     void setSolveSrcPackages( bool yesno_r );
216     void setDefaultSolveSrcPackages();
217     bool solveSrcPackages() const;
218
219     /**
220      * Adding additional requirement
221      *
222      */
223     void addRequire( const Capability & capability );
224
225     /**
226      * Adding additional conflict
227      *
228      */
229     void addConflict( const Capability & capability );
230
231     /**
232      * Remove the additional requirement set by \ref addRequire(Capability).
233      *
234      */
235     void removeRequire( const Capability & capability );
236
237     /**
238      * Remove the additional conflict set by \ref addConflict(Capability).
239      *
240      */
241     void removeConflict( const Capability & capability );
242
243     /**
244      * Get all the additional requirements set by \ref addRequire(Capability).
245      *
246      */
247     CapabilitySet getRequire();
248
249     /**
250      * Get all the additional conflicts set by \ref addConflict(Capability).
251      *
252      */
253     CapabilitySet getConflict();
254
255     /**
256      * Generates a solver Testcase of the current state
257      *
258      * \parame dumpPath destination directory of the created directory
259      * \return true if it was successful
260      */
261     bool createSolverTestcase( const std::string & dumpPath = "/var/log/YaST2/solverTestcase" );
262
263     /**
264      * Gives information about WHO has pused an installation of an given item.
265      *
266      * \param item    Evaluate additional information for this resolvable.
267      * \return A list of structures which contains:
268      *          item                Item which has triggered the installation of the given param item.
269      *          initialInstallation This item has triggered the installation
270      *                              Not already fullfilled requierement only.
271      *          cap                 Capability which has triggerd this installation
272      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
273      *
274      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
275      *
276      */
277     solver::detail::ItemCapKindList isInstalledBy( const PoolItem & item );
278
279     /**
280      * Gives information about WHICH additional items will be installed due the installation of an item.
281      *
282      * \param item     Evaluate additional information for this resolvable.
283      * \return A list of structures which contains:
284      *          item                Item which has triggered the installation of the given param item.
285      *          initialInstallation This item has triggered the installation
286      *                              Not already fullfilled requierement only.
287      *          cap                 Capability which has triggerd this installation
288      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
289      *
290      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
291      *
292      */
293     solver::detail::ItemCapKindList installs( const PoolItem & item );
294
295     /**
296      * Gives information about WHICH installed items are requested by the installation of an item.
297      *
298      * \param item     Evaluate additional information for this resolvable.
299      * \return A list of structures which contains:
300      *          item                Item which has triggered the installation of the given param item.
301      *          initialInstallation This item has triggered the installation
302      *                              Not already fullfilled requierement only.
303      *          cap                 Capability which has triggerd this installation
304      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
305      *
306      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
307      *
308      */
309     solver::detail::ItemCapKindList satifiedByInstalled( const PoolItem & item );
310
311
312     /**
313      * Gives information about WHICH items require an already installed item.
314      *
315      * \param item     Evaluate additional information for this resolvable.
316      * \return A list of structures which contains:
317      *          item                Item which has triggered the installation of the given param item.
318      *          initialInstallation This item has triggered the installation
319      *                              Not already fullfilled requierement only.
320      *          cap                 Capability which has triggerd this installation
321      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
322      *
323      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
324      *
325      */
326     solver::detail::ItemCapKindList installedSatisfied( const PoolItem & item );
327
328
329
330   private:
331     solver::detail::Resolver_Ptr _pimpl;
332   };
333   ///////////////////////////////////////////////////////////////////
334
335   /////////////////////////////////////////////////////////////////
336 } // namespace zypp
337 ///////////////////////////////////////////////////////////////////
338 #endif // ZYPP_RESOLVER_H