]> cygwin.com Git - cygwin-apps/setup.git/blame - libsolv.h
Add obsoletes: support
[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;
59 const PackageDepends depends() const;
60 bool accessible () const;
61 package_type_t Type () const;
62 package_stability_t Stability () const;
63 // the associated source package, if this is a binary package
64 SolvableVersion sourcePackage () const;
65 // where this package archive can be obtained from
66 packagesource *source() const;
67
68 // utility function to compare package versions
69 static int compareVersions(const SolvableVersion &a, const SolvableVersion &b);
70
71 // comparison operators
72
73 // these are somewhat necessary as otherwise we are compared as bool values
74 bool operator == (SolvableVersion const &) const;
75 bool operator != (SolvableVersion const &) const;
76
77 // these are only well defined for versions of the same package
78 bool operator < (SolvableVersion const &) const;
79 bool operator <= (SolvableVersion const &) const;
80 bool operator > (SolvableVersion const &) const;
81 bool operator >= (SolvableVersion const &) const;
82
83 private:
84 Id id;
85 Pool *pool;
86
87 friend SolverPool;
1d553f34 88 friend SolverSolution;
1c159e0a
JT
89};
90
91// ---------------------------------------------------------------------------
92// Helper class SolvRepo
93//
94// ---------------------------------------------------------------------------
95
96class SolvRepo
97{
98public:
99 Repo *repo;
100 Repodata *data;
101 bool test;
102};
103
104// ---------------------------------------------------------------------------
105// interface to class SolverPool
106//
107// a simplified wrapper for libsolv
108// ---------------------------------------------------------------------------
109
110class SolverPool
111{
112public:
113 SolverPool();
114 SolvRepo *getRepo(const std::string &name, bool test = false);
115
116 // Utility class for passing arguments to addPackage()
117 class addPackageData
118 {
119 public:
120 std::string reponame;
121 std::string version;
122 std::string vendor;
123 std::string sdesc;
124 std::string ldesc;
125 package_stability_t stability;
126 package_type_t type;
127 packagesource archive;
128 PackageSpecification spkg;
129 SolvableVersion spkg_id;
130 PackageDepends *requires;
20b98f20 131 PackageDepends *obsoletes;
1c159e0a
JT
132 };
133
134 SolvableVersion addPackage(const std::string& pkgname,
135 const addPackageData &pkgdata);
136
137 void internalize(void);
1d553f34
JT
138 void use_test_packages(bool use_test_packages);
139
1c159e0a
JT
140
141private:
142 Id makedeps(Repo *repo, PackageDepends *requires);
143 Pool *pool;
144
145 typedef std::map<std::string, SolvRepo *> RepoList;
146 RepoList repos;
1d553f34
JT
147
148 friend SolverSolution;
1c159e0a
JT
149};
150
151
1d553f34
JT
152// ---------------------------------------------------------------------------
153// interface to class SolverTaskQueue
154//
155// This is used to contain a set of package install/uninstall tasks selected via
156// the UI to be passed to solver
157// ---------------------------------------------------------------------------
158
159class SolverTasks
160{
161 public:
162 enum task
163 {
164 taskInstall,
165 taskUninstall,
166 taskReinstall
167 };
168 void add(const SolvableVersion &v, task t)
169 {
170 tasks.push_back(taskList::value_type(v, t));
171 };
172 private:
173 typedef std::vector<std::pair<const SolvableVersion &, task>> taskList;
174 taskList tasks;
175
176 friend SolverSolution;
177};
178
179// ---------------------------------------------------------------------------
180// SolverTransactionList
181//
182// a list of transactions output by the solver
183// ---------------------------------------------------------------------------
184
185class SolverTransaction
186{
187 public:
188 typedef enum
189 {
190 transIgnore,
191 transInstall,
192 transErase,
193 } transType;
194
195 SolverTransaction(SolvableVersion version_, transType type_) :
196 version(version_), type(type_) {};
197
198 SolvableVersion version;
199 transType type;
200};
201
202typedef std::vector<SolverTransaction> SolverTransactionList;
203
204// ---------------------------------------------------------------------------
205// interface to class SolverSolution
206//
207// A wrapper around the libsolv solver
208// ---------------------------------------------------------------------------
209
210class SolverSolution
211{
212 public:
213 SolverSolution(SolverPool &_pool) : pool(_pool), solv(NULL) {};
214 ~SolverSolution();
215
216 bool update(SolverTasks &tasks, bool update, bool use_test_packages, bool include_source);
217 std::string report() const;
218
219 const SolverTransactionList &transactions() const;
220
221 private:
222 static SolverTransaction::transType type(Transaction *trans, int pos);
223
224 SolverPool &pool;
225 Solver *solv;
226 SolverTransactionList trans;
227};
228
1c159e0a 229#endif // LIBSOLV_H
This page took 0.044259 seconds and 5 git commands to generate.