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