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