fixup Fix to build with libxml 2.12.x (fixes #505)
[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      * Setting whether required packages are installed ONLY
193      * So recommended packages, language packages and packages which depend
194      * on hardware (modalias) will not be regarded.
195      **/
196     void setOnlyRequires( bool yesno_r );
197     void resetOnlyRequires(); // set back to default (described in zypp.conf)
198     bool onlyRequires() const;
199
200     /**
201      * Setting whether the solver should perform in 'upgrade' mode or
202      * not.
203      * \see \ref doUpgrade.
204      */
205     void setUpgradeMode( bool yesno_r );
206     bool upgradeMode() const;
207
208     /**
209      * Setting whether the solver should perform in 'update' mode or
210      * not. If on, it will add a resolver job to update all packages.
211      * \see \ref doUpdate.
212      */
213     void setUpdateMode( bool yesno_r );
214     bool updateMode() const;
215
216
217     /** \name  Solver flags (non DUP modes)
218      * Default for all flags is \c false unless overwritten by zypp.conf.
219      */
220     //@{
221     /** Whether to allow to downgrade installed solvable */
222     void setAllowDowngrade( bool yesno_r );
223     void setDefaultAllowDowngrade();    // Set back to default
224     bool allowDowngrade() const;
225
226     /** Whether to allow to change name of installed solvable */
227     void setAllowNameChange( bool yesno_r );
228     void setDefaultAllowNameChange();   // Set back to default
229     bool allowNameChange() const;
230
231     /** Whether to allow to change architecture of installed solvables */
232     void setAllowArchChange( bool yesno_r );
233     void setDefaultAllowArchChange();   // Set back to default
234     bool allowArchChange() const;
235
236     /**  Whether to allow to change vendor of installed solvables
237      * \see \ref VendorAttr for definition of vendor equivalence.
238      */
239     void setAllowVendorChange( bool yesno_r );
240     void setDefaultAllowVendorChange(); // Set back to default
241     bool allowVendorChange() const;
242     //@}
243
244     /**
245      * System verification mode also monitors and repairs dependencies
246      * of already installed packages.
247      * \see \ref verifySystem
248      */
249     void setSystemVerification( bool yesno_r );
250     void setDefaultSystemVerification();
251     bool systemVerification() const;
252
253     /**
254      * Set whether to solve source packages build dependencies per default.
255      * Usually turned off and if, enabled per source package.
256      * \NOTE This affects only source packges selected in the \ref ResPool. No solver rule
257      * will be generated for them. Source packages requested via e.g. \ref addRequire will
258      * always be solved.
259      * \NOTE Be carefull. The older the source package is, the stranger may be the
260      * result of solving it's build dependencies.
261      */
262     void setSolveSrcPackages( bool yesno_r );
263     void setDefaultSolveSrcPackages();
264     bool solveSrcPackages() const;
265
266     /**
267      * Cleanup when deleting packages. Whether the solver should per default
268      * try to remove packages exclusively required by the ones he's asked to delete.
269      */
270     void setCleandepsOnRemove( bool yesno_r );
271     void setDefaultCleandepsOnRemove(); // set back to default (in zypp.conf)
272     bool cleandepsOnRemove() const;
273
274     /** \name  Solver flags for DUP mode.
275      * DUP mode default settings differ from 'ordinary' ones. Default for
276      * all DUP flags is \c true unless overwritten by zypp.conf.
277      */
278     //@{
279     /** dup mode: allow to downgrade installed solvable */
280     void dupSetAllowDowngrade( bool yesno_r );
281     void dupSetDefaultAllowDowngrade();         // Set back to default (in zypp.conf)
282     bool dupAllowDowngrade() const;
283
284     /** dup mode: allow to change name of installed solvable */
285     void dupSetAllowNameChange( bool yesno_r );
286     void dupSetDefaultAllowNameChange();        // Set back to default (in zypp.conf)
287     bool dupAllowNameChange() const;
288
289     /** dup mode: allow to change architecture of installed solvables */
290     void dupSetAllowArchChange( bool yesno_r );
291     void dupSetDefaultAllowArchChange();        // Set back to default (in zypp.conf)
292     bool dupAllowArchChange() const;
293
294     /**  dup mode: allow to change vendor of installed solvables*/
295     void dupSetAllowVendorChange( bool yesno_r );
296     void dupSetDefaultAllowVendorChange();      // Set back to default (in zypp.conf)
297     bool dupAllowVendorChange() const;
298     //@}
299
300     /** \name Upgrade to content of a specific repository.
301      * \note This is an ordinary solver request. You should simply
302      * \ref resolvePool to execute, and not \ref doUpgrade.
303      */
304     //@{
305     /**
306      * Adding request to perform a dist upgrade restricted to this repository.
307      *
308      * This is what e.g. <tt>zypper dup --repo myrepo</tt> should perform.
309      * \see \ref doUpgrade
310      */
311     void addUpgradeRepo( Repository repo_r );
312
313     /**
314      * Whether there is at least one \c UpgradeRepo request pending
315      */
316     bool upgradingRepos() const;
317
318     /**
319      * Whether there is an \c UpgradeRepo request pending for this repo.
320      */
321     bool upgradingRepo( Repository repo_r ) const;
322
323     /**
324      * Remove an upgrade request for this repo.
325      */
326     void removeUpgradeRepo( Repository repo_r );
327
328     /**
329      * Remove all upgrade repo requests.
330      */
331     void removeUpgradeRepos();
332     //@}
333
334     /**
335      * Adding additional requirement
336      *
337      */
338     void addRequire( const Capability & capability );
339
340     /**
341      * Adding additional conflict
342      *
343      */
344     void addConflict( const Capability & capability );
345
346     /**
347      * Remove the additional requirement set by \ref addRequire(Capability).
348      *
349      */
350     void removeRequire( const Capability & capability );
351
352     /**
353      * Remove the additional conflict set by \ref addConflict(Capability).
354      *
355      */
356     void removeConflict( const Capability & capability );
357
358     /**
359      * Get all the additional requirements set by \ref addRequire(Capability).
360      *
361      */
362     CapabilitySet getRequire() const;
363
364     /**
365      * Get all the additional conflicts set by \ref addConflict(Capability).
366      *
367      */
368     CapabilitySet getConflict() const;
369
370     /**
371      * Generates a solver Testcase of the current state
372      *
373      * \parame dumpPath destination directory of the created directory
374      * \return true if it was successful
375      */
376     bool createSolverTestcase( const std::string & dumpPath = "/var/log/YaST2/solverTestcase", bool runSolver = true );
377
378     /**
379      * Gives information about WHO has pused an installation of an given item.
380      *
381      * \param item    Evaluate additional information for this resolvable.
382      * \return A list of structures which contains:
383      *          item                Item which has triggered the installation of the given param item.
384      *          initialInstallation This item has triggered the installation
385      *                              Not already fullfilled requierement only.
386      *          cap                 Capability which has triggerd this installation
387      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
388      *
389      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
390      *
391      */
392     solver::detail::ItemCapKindList isInstalledBy( const PoolItem & item );
393
394     /**
395      * Gives information about WHICH additional items will be installed due the installation of an item.
396      *
397      * \param item     Evaluate additional information for this resolvable.
398      * \return A list of structures which contains:
399      *          item                Item which has triggered the installation of the given param item.
400      *          initialInstallation This item has triggered the installation
401      *                              Not already fullfilled requierement only.
402      *          cap                 Capability which has triggerd this installation
403      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
404      *
405      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
406      *
407      */
408     solver::detail::ItemCapKindList installs( const PoolItem & item );
409
410     /**
411      * Gives information about WHICH installed items are requested by the installation of an item.
412      *
413      * \param item     Evaluate additional information for this resolvable.
414      * \return A list of structures which contains:
415      *          item                Item which has triggered the installation of the given param item.
416      *          initialInstallation This item has triggered the installation
417      *                              Not already fullfilled requierement only.
418      *          cap                 Capability which has triggerd this installation
419      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
420      *
421      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
422      *
423      */
424     solver::detail::ItemCapKindList satifiedByInstalled( const PoolItem & item );
425
426
427     /**
428      * Gives information about WHICH items require an already installed item.
429      *
430      * \param item     Evaluate additional information for this resolvable.
431      * \return A list of structures which contains:
432      *          item                Item which has triggered the installation of the given param item.
433      *          initialInstallation This item has triggered the installation
434      *                              Not already fullfilled requierement only.
435      *          cap                 Capability which has triggerd this installation
436      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
437      *
438      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
439      *
440      */
441     solver::detail::ItemCapKindList installedSatisfied( const PoolItem & item );
442
443
444   private:
445     friend std::ostream & operator<<( std::ostream & str, const Resolver & obj );
446     zypp::RW_pointer<solver::detail::ResolverInternal> _pimpl;
447   };
448   ///////////////////////////////////////////////////////////////////
449
450   /** \relates Resolver Stream output */
451   std::ostream & operator<<( std::ostream & str, const Resolver & obj );
452
453   /////////////////////////////////////////////////////////////////
454 } // namespace zypp
455 ///////////////////////////////////////////////////////////////////
456 #endif // ZYPP_RESOLVER_H