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