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