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