]>
Commit | Line | Data |
---|---|---|
1c159e0a JT |
1 | /* |
2 | * Copyright (c) 2017 Jon Turney | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | */ | |
13 | ||
14 | #ifndef LIBSOLV_H | |
15 | #define LIBSOLV_H | |
16 | ||
17 | #include "solv/pool.h" | |
18 | #include "solv/repo.h" | |
1d553f34 | 19 | #include "solv/solver.h" |
1c159e0a JT |
20 | #include "PackageSpecification.h" |
21 | #include "PackageTrust.h" | |
22 | #include "package_source.h" | |
23 | #include "package_depends.h" | |
24 | #include <map> | |
25 | #include <vector> | |
26 | ||
27 | typedef trusts package_stability_t; | |
28 | ||
29 | typedef enum | |
30 | { | |
31 | package_binary, | |
32 | package_source | |
33 | } | |
34 | package_type_t; | |
35 | ||
36 | // --------------------------------------------------------------------------- | |
37 | // interface to class SolverVersion | |
38 | // | |
39 | // a wrapper around a libsolv Solvable | |
40 | // --------------------------------------------------------------------------- | |
41 | ||
42 | class SolverPool; | |
1d553f34 | 43 | class SolverSolution; |
1c159e0a JT |
44 | |
45 | class SolvableVersion | |
46 | { | |
47 | public: | |
48 | SolvableVersion() : id(0), pool(0) {}; | |
49 | SolvableVersion(Id _id, Pool *_pool) : id(_id), pool(_pool) {}; | |
50 | ||
51 | // converted to a bool, this is true if this isn't the result of the default | |
52 | // constructor (an 'empty' version, in some sense) | |
53 | explicit operator bool () const { return (id != 0); } | |
54 | ||
55 | const std::string Name () const; | |
56 | const std::string SDesc () const; | |
30cae42f | 57 | const std::string LDesc () const; |
1c159e0a JT |
58 | // In setup-speak, 'Canonical' version means 'e:v-r', the non-decomposed version |
59 | const std::string Canonical_version () const; | |
5ebe14e4 | 60 | // Return the dependency list |
1c159e0a | 61 | const PackageDepends depends() const; |
5ebe14e4 KB |
62 | // Return the obsoletes list |
63 | const PackageDepends obsoletes() const; | |
6d23697e KB |
64 | // Return the provides list |
65 | const PackageDepends provides() const; | |
66 | // Return the conflicts list | |
67 | const PackageDepends conflicts() const; | |
1c159e0a JT |
68 | bool accessible () const; |
69 | package_type_t Type () const; | |
70 | package_stability_t Stability () const; | |
c59b92e8 JT |
71 | // the associated source package name, if this is a binary package |
72 | const std::string sourcePackageName () const; | |
1c159e0a JT |
73 | // the associated source package, if this is a binary package |
74 | SolvableVersion sourcePackage () const; | |
75 | // where this package archive can be obtained from | |
76 | packagesource *source() const; | |
f158577d | 77 | const std::string Vendor () const; |
1c159e0a | 78 | |
c59b92e8 JT |
79 | // fixup spkg_id |
80 | void fixup_spkg_id(SolvableVersion spkg_id) const; | |
81 | ||
1c159e0a JT |
82 | // utility function to compare package versions |
83 | static int compareVersions(const SolvableVersion &a, const SolvableVersion &b); | |
84 | ||
85 | // comparison operators | |
86 | ||
87 | // these are somewhat necessary as otherwise we are compared as bool values | |
88 | bool operator == (SolvableVersion const &) const; | |
89 | bool operator != (SolvableVersion const &) const; | |
90 | ||
91 | // these are only well defined for versions of the same package | |
92 | bool operator < (SolvableVersion const &) const; | |
93 | bool operator <= (SolvableVersion const &) const; | |
94 | bool operator > (SolvableVersion const &) const; | |
95 | bool operator >= (SolvableVersion const &) const; | |
96 | ||
972b2d9a JT |
97 | void remove() const; |
98 | ||
1c159e0a JT |
99 | private: |
100 | Id id; | |
101 | Pool *pool; | |
102 | ||
103 | friend SolverPool; | |
1d553f34 | 104 | friend SolverSolution; |
5ebe14e4 KB |
105 | |
106 | const PackageDepends deplist(Id keyname) const; | |
bfe593cf | 107 | Id name_id () const; |
1c159e0a JT |
108 | }; |
109 | ||
110 | // --------------------------------------------------------------------------- | |
111 | // Helper class SolvRepo | |
112 | // | |
113 | // --------------------------------------------------------------------------- | |
114 | ||
115 | class SolvRepo | |
116 | { | |
117 | public: | |
3c3d695d KB |
118 | typedef enum |
119 | { | |
120 | priorityLow = 0, | |
121 | priorityNormal, | |
122 | priorityHigh, | |
123 | } priority_t; | |
1c159e0a JT |
124 | Repo *repo; |
125 | Repodata *data; | |
126 | bool test; | |
3c3d695d | 127 | void setPriority(priority_t p) { repo->priority = p; } |
1c159e0a JT |
128 | }; |
129 | ||
130 | // --------------------------------------------------------------------------- | |
131 | // interface to class SolverPool | |
132 | // | |
133 | // a simplified wrapper for libsolv | |
134 | // --------------------------------------------------------------------------- | |
135 | ||
136 | class SolverPool | |
137 | { | |
138 | public: | |
139 | SolverPool(); | |
ab67dafa | 140 | void clear(); |
1c159e0a JT |
141 | SolvRepo *getRepo(const std::string &name, bool test = false); |
142 | ||
143 | // Utility class for passing arguments to addPackage() | |
144 | class addPackageData | |
145 | { | |
146 | public: | |
147 | std::string reponame; | |
148 | std::string version; | |
149 | std::string vendor; | |
150 | std::string sdesc; | |
151 | std::string ldesc; | |
152 | package_stability_t stability; | |
153 | package_type_t type; | |
154 | packagesource archive; | |
155 | PackageSpecification spkg; | |
156 | SolvableVersion spkg_id; | |
157 | PackageDepends *requires; | |
20b98f20 | 158 | PackageDepends *obsoletes; |
9c3e3256 | 159 | PackageDepends *provides; |
e6433da6 | 160 | PackageDepends *conflicts; |
1c159e0a JT |
161 | }; |
162 | ||
163 | SolvableVersion addPackage(const std::string& pkgname, | |
164 | const addPackageData &pkgdata); | |
165 | ||
166 | void internalize(void); | |
1d553f34 JT |
167 | void use_test_packages(bool use_test_packages); |
168 | ||
1c159e0a JT |
169 | |
170 | private: | |
ab67dafa | 171 | void init(); |
1c159e0a JT |
172 | Id makedeps(Repo *repo, PackageDepends *requires); |
173 | Pool *pool; | |
174 | ||
175 | typedef std::map<std::string, SolvRepo *> RepoList; | |
176 | RepoList repos; | |
1d553f34 JT |
177 | |
178 | friend SolverSolution; | |
1c159e0a JT |
179 | }; |
180 | ||
181 | ||
1d553f34 JT |
182 | // --------------------------------------------------------------------------- |
183 | // interface to class SolverTaskQueue | |
184 | // | |
185 | // This is used to contain a set of package install/uninstall tasks selected via | |
186 | // the UI to be passed to solver | |
187 | // --------------------------------------------------------------------------- | |
188 | ||
189 | class SolverTasks | |
190 | { | |
191 | public: | |
192 | enum task | |
193 | { | |
194 | taskInstall, | |
195 | taskUninstall, | |
9deed604 KB |
196 | taskReinstall, |
197 | taskKeep, | |
bfe593cf | 198 | taskSkip, |
d2e0c29e | 199 | taskForceDistUpgrade, |
1d553f34 JT |
200 | }; |
201 | void add(const SolvableVersion &v, task t) | |
202 | { | |
203 | tasks.push_back(taskList::value_type(v, t)); | |
204 | }; | |
16994679 KB |
205 | /* Create solver tasks corresponding to state of database */ |
206 | void setTasks(); | |
207 | ||
1d553f34 | 208 | private: |
389e4dff | 209 | typedef std::vector<std::pair<const SolvableVersion, task>> taskList; |
1d553f34 JT |
210 | taskList tasks; |
211 | ||
212 | friend SolverSolution; | |
213 | }; | |
214 | ||
215 | // --------------------------------------------------------------------------- | |
216 | // SolverTransactionList | |
217 | // | |
218 | // a list of transactions output by the solver | |
219 | // --------------------------------------------------------------------------- | |
220 | ||
221 | class SolverTransaction | |
222 | { | |
223 | public: | |
224 | typedef enum | |
225 | { | |
226 | transIgnore, | |
227 | transInstall, | |
228 | transErase, | |
229 | } transType; | |
230 | ||
231 | SolverTransaction(SolvableVersion version_, transType type_) : | |
232 | version(version_), type(type_) {}; | |
233 | ||
234 | SolvableVersion version; | |
235 | transType type; | |
236 | }; | |
237 | ||
238 | typedef std::vector<SolverTransaction> SolverTransactionList; | |
239 | ||
240 | // --------------------------------------------------------------------------- | |
241 | // interface to class SolverSolution | |
242 | // | |
243 | // A wrapper around the libsolv solver | |
244 | // --------------------------------------------------------------------------- | |
245 | ||
246 | class SolverSolution | |
247 | { | |
248 | public: | |
2506055b | 249 | SolverSolution(SolverPool &_pool); |
1d553f34 | 250 | ~SolverSolution(); |
ab67dafa | 251 | void clear(); |
1d553f34 | 252 | |
7c94d449 KB |
253 | /* Reset package database to correspond to trans */ |
254 | void trans2db() const; | |
255 | ||
9a7507eb KB |
256 | /* Reset transaction list to correspond to package database */ |
257 | void db2trans(); | |
258 | ||
45f5ab69 JT |
259 | enum updateMode |
260 | { | |
261 | keep, // don't update | |
262 | updateBest, // update to best version | |
263 | updateForce, // distupdate: downgrade if necessary to best version in repo | |
264 | }; | |
2506055b JT |
265 | bool update(SolverTasks &tasks, updateMode update, bool use_test_packages); |
266 | void augmentTasks(SolverTasks &tasks); | |
267 | void addSource(bool include_source); | |
268 | void applyDefaultProblemSolutions(); | |
1d553f34 JT |
269 | std::string report() const; |
270 | ||
271 | const SolverTransactionList &transactions() const; | |
2506055b | 272 | void dumpTransactionList() const; |
1d553f34 JT |
273 | |
274 | private: | |
275 | static SolverTransaction::transType type(Transaction *trans, int pos); | |
2506055b JT |
276 | bool solve(); |
277 | void tasksToJobs(SolverTasks &tasks, updateMode update, Queue &job); | |
278 | void solutionToTransactionList(); | |
1d553f34 JT |
279 | |
280 | SolverPool &pool; | |
281 | Solver *solv; | |
2506055b | 282 | Queue job; |
1d553f34 JT |
283 | SolverTransactionList trans; |
284 | }; | |
285 | ||
1c159e0a | 286 | #endif // LIBSOLV_H |