Add Resolver::setSolveSrcPackages to per default disable solving of source package...
[platform/upstream/libzypp.git] / zypp / solver / detail / SATResolver.h
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* SATResolver.h
3  *
4  * Copyright (C) 2000-2002 Ximian, Inc.
5  * Copyright (C) 2005 SUSE Linux Products GmbH
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  * 02111-1307, USA.
20  */
21
22 #ifndef ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H
23 #define ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H
24
25 #include <iosfwd>
26 #include <list>
27 #include <map>
28 #include <string>
29
30 #include "zypp/base/ReferenceCounted.h"
31 #include "zypp/base/PtrTypes.h"
32 #include "zypp/ResPool.h"
33 #include "zypp/base/SerialNumber.h"
34 #include "zypp/ProblemTypes.h"
35 #include "zypp/ResolverProblem.h"
36 #include "zypp/ProblemSolution.h"
37 #include "zypp/Capability.h"
38 #include "zypp/solver/detail/SolverQueueItem.h"
39 extern "C" {
40 #include "satsolver/solver.h"
41 #include "satsolver/pool.h"
42 }
43
44
45 /////////////////////////////////////////////////////////////////////////
46 namespace zypp
47 { ///////////////////////////////////////////////////////////////////////
48   ///////////////////////////////////////////////////////////////////////
49   namespace solver
50   { /////////////////////////////////////////////////////////////////////
51     /////////////////////////////////////////////////////////////////////
52     namespace detail
53     { ///////////////////////////////////////////////////////////////////
54
55
56 ///////////////////////////////////////////////////////////////////
57 //
58 //      CLASS NAME : SATResolver
59 /**
60  * \todo The way solver options are passed as individual booleans from Resolver
61  * via solver::detail::Resolver to SATResolver is pedestrian and error prone.
62  * Introdce a dedicated solver option structure which is passed down as a whole.
63 */
64 class SATResolver : public base::ReferenceCounted, private base::NonCopyable {
65
66   private:
67     ResPool _pool;
68     Pool *_SATPool;
69     Solver *_solv;
70     Queue _jobQueue;
71
72     // list of problematic items (orphaned)
73     PoolItemList _problem_items;
74
75     // list populated by calls to addPoolItemTo*()
76     PoolItemList _items_to_install;
77     PoolItemList _items_to_remove;
78     PoolItemList _items_to_lock;
79     PoolItemList _items_to_keep;
80
81     // solve results
82     PoolItemList _result_items_to_install;
83     PoolItemList _result_items_to_remove;
84
85     bool _fixsystem;                    // repair errors in rpm dependency graph
86     bool _allowdowngrade;               // allow to downgrade installed solvable
87     bool _allowarchchange;              // allow to change architecture of installed solvables
88     bool _allowvendorchange;            // allow to change vendor of installed solvables
89     bool _allowuninstall;               // allow removal of installed solvables
90     bool _updatesystem;                 // update
91     bool _allowvirtualconflicts;        // false: conflicts on package name, true: conflicts on package provides
92     bool _noupdateprovide;              // true: update packages needs not to provide old package
93     bool _dosplitprovides;              // true: consider legacy split provides
94     bool _onlyRequires;                 // true: consider required packages only
95     bool _ignorealreadyrecommended;     // true: ignore recommended packages that were already recommended by the installed packages
96     bool _distupgrade;
97     bool _distupgrade_removeunsupported;
98     bool _solveSrcPackages;             // false: generate no job rule for source packages selected in the pool
99
100     // ---------------------------------- methods
101     std::string SATprobleminfoString (Id problem, std::string &detail, Id &ignoreId);
102     void resetItemTransaction (PoolItem item);
103
104     // Create a SAT solver and reset solver selection in the pool (Collecting
105     void solverInit(const PoolItemList & weakItems);
106     // common solver run with the _jobQueue; Save results back to pool
107     bool solving(const CapabilitySet & requires_caps = CapabilitySet(),
108                  const CapabilitySet & conflict_caps = CapabilitySet());
109     // cleanup solver
110     void solverEnd();
111     // set locks for the solver
112     void setLocks();
113     // set requirements for a running system
114     void setSystemRequirements();
115
116    // Checking if this solvable/item has a buddy which reflect the real
117    // user visible description of an item
118    // e.g. The release package has a buddy to the concerning product item.
119    // This user want's the message "Product foo conflicts with product bar" and
120    // NOT "package release-foo conflicts with package release-bar"
121    // So these functions return the concerning buddy (e.g. product item)
122     sat::Solvable mapSolvable (const Id &id);
123     PoolItem mapItem (const PoolItem &item);
124
125   public:
126
127     SATResolver (const ResPool & pool, Pool *SATPool);
128     virtual ~SATResolver();
129
130     // ---------------------------------- I/O
131
132     virtual std::ostream & dumpOn( std::ostream & str ) const;
133     friend std::ostream& operator<<(std::ostream& str, const SATResolver & obj)
134     { return obj.dumpOn (str); }
135
136     ResPool pool (void) const;
137     void setPool (const ResPool & pool) { _pool = pool; }
138
139     // solver run with pool selected items
140     bool resolvePool(const CapabilitySet & requires_caps,
141                      const CapabilitySet & conflict_caps,
142                      const PoolItemList & weakItems
143                      );
144     // solver run with the given request queue
145     bool resolveQueue(const SolverQueueItemList &requestQueue,
146                       const PoolItemList & weakItems
147                       );
148     // searching for new packages
149     void doUpdate();
150
151     ResolverProblemList problems ();
152     void applySolutions (const ProblemSolutionList &solutions);
153
154     void addPoolItemToInstall (PoolItem item);
155     void addPoolItemsToInstallFromList (PoolItemList & rl);
156
157     void addPoolItemToLock (PoolItem item);
158     void addPoolItemToKeep (PoolItem item);
159
160     void addPoolItemToRemove (PoolItem item);
161     void addPoolItemsToRemoveFromList (PoolItemList & rl);
162
163     bool fixsystem () const {return _fixsystem;}
164     void setFixsystem ( const bool fixsystem) { _fixsystem = fixsystem;}
165
166     bool ignorealreadyrecommended () const {return _ignorealreadyrecommended;}
167     void setIgnorealreadyrecommended ( const bool ignorealreadyrecommended) { _ignorealreadyrecommended = ignorealreadyrecommended;}
168
169     bool distupgrade () const {return _distupgrade;}
170     void setDistupgrade ( const bool distupgrade) { _distupgrade = distupgrade;}
171
172     bool distupgrade_removeunsupported () const {return _distupgrade_removeunsupported;}
173     void setDistupgrade_removeunsupported ( const bool distupgrade_removeunsupported) { _distupgrade_removeunsupported = distupgrade_removeunsupported;}
174
175     bool allowdowngrade () const {return _allowdowngrade;}
176     void setAllowdowngrade ( const bool allowdowngrade) { _allowdowngrade = allowdowngrade;}
177
178     bool allowarchchange () const {return _allowarchchange;}
179     void setAllowarchchange ( const bool allowarchchange) { _allowarchchange = allowarchchange;}
180
181     bool allowvendorchange () const {return _allowvendorchange;}
182     void setAllowvendorchange ( const bool allowvendorchange) { _allowvendorchange = allowvendorchange;}
183
184     bool allowuninstall () const {return _allowuninstall;}
185     void setAllowuninstall ( const bool allowuninstall) { _allowuninstall = allowuninstall;}
186
187     bool updatesystem () const {return _updatesystem;}
188     void setUpdatesystem ( const bool updatesystem) { _updatesystem = updatesystem;}
189
190     bool allowvirtualconflicts () const {return _allowvirtualconflicts;}
191     void setAllowvirtualconflicts ( const bool allowvirtualconflicts) { _allowvirtualconflicts = allowvirtualconflicts;}
192
193     bool noupdateprovide () const {return _noupdateprovide;}
194     void setNoupdateprovide ( const bool noupdateprovide) { _noupdateprovide = noupdateprovide;}
195
196     bool dosplitprovides () const {return _dosplitprovides;}
197     void setDosplitprovides ( const bool dosplitprovides) { _dosplitprovides = dosplitprovides;}
198
199     bool onlyRequires () const {return _onlyRequires;}
200     void setOnlyRequires ( const bool onlyRequires) { _onlyRequires = onlyRequires;}
201
202     bool solveSrcPackages() const               { return _solveSrcPackages; }
203     void setSolveSrcPackages( bool state_r )    { _solveSrcPackages = state_r; }
204
205     PoolItemList problematicUpdateItems( void ) const { return _problem_items; }
206
207     PoolItemList resultItemsToInstall () { return _result_items_to_install; }
208     PoolItemList resultItemsToRemove () { return _result_items_to_remove; }
209     PoolItemList problematicUpdateItems() { return _problem_items; }
210
211 };
212
213 ///////////////////////////////////////////////////////////////////
214     };// namespace detail
215     /////////////////////////////////////////////////////////////////////
216     /////////////////////////////////////////////////////////////////////
217   };// namespace solver
218   ///////////////////////////////////////////////////////////////////////
219   ///////////////////////////////////////////////////////////////////////
220 };// namespace zypp
221 /////////////////////////////////////////////////////////////////////////
222
223 #endif // ZYPP_SOLVER_DETAIL_SAT_RESOLVER_H