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