Added translation using Weblate (Italian)
[cygwin-setup.git] / libsolv.h
blob43f7269b34cfd7a3d940a0c146e0b78f4529f95f
1 /*
2 * Copyright (c) 2017 Jon Turney
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.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
14 #ifndef LIBSOLV_H
15 #define LIBSOLV_H
17 #include "solv/pool.h"
18 #include "solv/repo.h"
19 #include "solv/solver.h"
20 #include "PackageSpecification.h"
21 #include "PackageTrust.h"
22 #include "package_source.h"
23 #include "package_depends.h"
24 #include <map>
25 #include <vector>
27 typedef trusts package_stability_t;
29 typedef enum
31 package_binary,
32 package_source
34 package_type_t;
36 // ---------------------------------------------------------------------------
37 // interface to class SolverVersion
39 // a wrapper around a libsolv Solvable
40 // ---------------------------------------------------------------------------
42 class SolverPool;
43 class SolverSolution;
45 class SolvableVersion
47 public:
48 SolvableVersion() : id(0), pool(0) {};
49 SolvableVersion(Id _id, Pool *_pool) : id(_id), pool(_pool) {};
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); }
55 const std::string Name () const;
56 const std::string SDesc () const;
57 const std::string LDesc () const;
58 // In setup-speak, 'Canonical' version means 'e:v-r', the non-decomposed version
59 const std::string Canonical_version () const;
60 // Return the dependency list
61 const PackageDepends depends() const;
62 // Return the obsoletes list
63 const PackageDepends obsoletes() const;
64 // Return the provides list
65 const PackageDepends provides() const;
66 // Return the conflicts list
67 const PackageDepends conflicts() const;
68 bool accessible () const;
69 package_type_t Type () const;
70 package_stability_t Stability () const;
71 // the associated source package name, if this is a binary package
72 const std::string sourcePackageName () const;
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;
77 const std::string Vendor () const;
79 // fixup spkg_id
80 void fixup_spkg_id(SolvableVersion spkg_id) const;
82 // utility function to compare package versions
83 static int compareVersions(const SolvableVersion &a, const SolvableVersion &b);
85 // comparison operators
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;
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;
97 void remove() const;
99 private:
100 Id id;
101 Pool *pool;
103 friend SolverPool;
104 friend SolverSolution;
106 const PackageDepends deplist(Id keyname) const;
107 Id name_id () const;
110 // ---------------------------------------------------------------------------
111 // Helper class SolvRepo
113 // ---------------------------------------------------------------------------
115 class SolvRepo
117 public:
118 typedef enum
120 priorityLow = 0,
121 priorityNormal,
122 priorityHigh,
123 } priority_t;
124 Repo *repo;
125 Repodata *data;
126 bool test;
127 void setPriority(priority_t p) { repo->priority = p; }
130 // ---------------------------------------------------------------------------
131 // interface to class SolverPool
133 // a simplified wrapper for libsolv
134 // ---------------------------------------------------------------------------
136 class SolverPool
138 public:
139 SolverPool();
140 void clear();
141 SolvRepo *getRepo(const std::string &name, bool test = false);
143 // Utility class for passing arguments to addPackage()
144 class addPackageData
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;
158 PackageDepends *obsoletes;
159 PackageDepends *provides;
160 PackageDepends *conflicts;
163 SolvableVersion addPackage(const std::string& pkgname,
164 const addPackageData &pkgdata);
166 void internalize(void);
167 void use_test_packages(bool use_test_packages);
168 bool is_test_package(SolvableVersion id);
170 private:
171 void init();
172 Id makedeps(Repo *repo, PackageDepends *requires);
173 Pool *pool;
175 typedef std::map<std::string, SolvRepo *> RepoList;
176 RepoList repos;
178 friend SolverSolution;
182 // ---------------------------------------------------------------------------
183 // interface to class SolverTaskQueue
185 // This is used to contain a set of package install/uninstall tasks selected via
186 // the UI to be passed to solver
187 // ---------------------------------------------------------------------------
189 class SolverTasks
191 public:
192 enum task
194 taskInstall,
195 taskUninstall,
196 taskReinstall,
197 taskKeep,
198 taskSkip,
199 taskForceDistUpgrade,
200 taskInstallAny,
202 void add(const SolvableVersion &v, task t)
204 tasks.push_back(taskList::value_type(v, t));
206 /* Create solver tasks corresponding to state of database */
207 void setTasks();
209 private:
210 typedef std::vector<std::pair<const SolvableVersion, task>> taskList;
211 taskList tasks;
213 friend SolverSolution;
216 // ---------------------------------------------------------------------------
217 // SolverTransactionList
219 // a list of transactions output by the solver
220 // ---------------------------------------------------------------------------
222 class SolverTransaction
224 public:
225 typedef enum
227 transIgnore,
228 transInstall,
229 transErase,
230 } transType;
232 SolverTransaction(SolvableVersion version_, transType type_) :
233 version(version_), type(type_) {};
235 SolvableVersion version;
236 transType type;
239 typedef std::vector<SolverTransaction> SolverTransactionList;
241 // ---------------------------------------------------------------------------
242 // interface to class SolverSolution
244 // A wrapper around the libsolv solver
245 // ---------------------------------------------------------------------------
247 class SolverSolution
249 public:
250 SolverSolution(SolverPool &_pool);
251 ~SolverSolution();
252 void clear();
254 /* Reset package database to correspond to trans */
255 void trans2db() const;
257 /* Reset transaction list to correspond to package database */
258 void db2trans();
260 enum updateMode
262 keep, // don't update
263 updateBest, // update to best version
264 updateForce, // distupdate: downgrade if necessary to best version in repo
266 bool update(SolverTasks &tasks, updateMode update, bool use_test_packages);
267 void augmentTasks(SolverTasks &tasks);
268 void addSource(bool include_source);
269 void applyDefaultProblemSolutions();
270 std::string report() const;
272 const SolverTransactionList &transactions() const;
273 void dumpTransactionList() const;
275 private:
276 static SolverTransaction::transType type(Transaction *trans, int pos);
277 bool solve();
278 void tasksToJobs(SolverTasks &tasks, updateMode update, Queue &job);
279 void solutionToTransactionList();
281 SolverPool &pool;
282 Solver *solv;
283 Queue job;
284 SolverTransactionList trans;
287 #endif // LIBSOLV_H