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
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"
27 typedef trusts package_stability_t
;
36 // ---------------------------------------------------------------------------
37 // interface to class SolverVersion
39 // a wrapper around a libsolv Solvable
40 // ---------------------------------------------------------------------------
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 // In setup-speak, 'Canonical' version means 'e:v-r', the non-decomposed version
58 const std::string
Canonical_version () const;
59 // Return the dependency list
60 const PackageDepends
depends() const;
61 // Return the obsoletes list
62 const PackageDepends
obsoletes() const;
63 bool accessible () const;
64 package_type_t
Type () const;
65 package_stability_t
Stability () const;
66 // the associated source package name, if this is a binary package
67 const std::string
sourcePackageName () const;
68 // the associated source package, if this is a binary package
69 SolvableVersion
sourcePackage () const;
70 // where this package archive can be obtained from
71 packagesource
*source() const;
74 void fixup_spkg_id(SolvableVersion spkg_id
) const;
76 // utility function to compare package versions
77 static int compareVersions(const SolvableVersion
&a
, const SolvableVersion
&b
);
79 // comparison operators
81 // these are somewhat necessary as otherwise we are compared as bool values
82 bool operator == (SolvableVersion
const &) const;
83 bool operator != (SolvableVersion
const &) const;
85 // these are only well defined for versions of the same package
86 bool operator < (SolvableVersion
const &) const;
87 bool operator <= (SolvableVersion
const &) const;
88 bool operator > (SolvableVersion
const &) const;
89 bool operator >= (SolvableVersion
const &) const;
96 friend SolverSolution
;
98 const PackageDepends
deplist(Id keyname
) const;
102 // ---------------------------------------------------------------------------
103 // Helper class SolvRepo
105 // ---------------------------------------------------------------------------
119 void setPriority(priority_t p
) { repo
->priority
= p
; }
122 // ---------------------------------------------------------------------------
123 // interface to class SolverPool
125 // a simplified wrapper for libsolv
126 // ---------------------------------------------------------------------------
133 SolvRepo
*getRepo(const std::string
&name
, bool test
= false);
135 // Utility class for passing arguments to addPackage()
139 std::string reponame
;
144 package_stability_t stability
;
146 packagesource archive
;
147 PackageSpecification spkg
;
148 SolvableVersion spkg_id
;
149 PackageDepends
*requires
;
150 PackageDepends
*obsoletes
;
151 PackageDepends
*provides
;
154 SolvableVersion
addPackage(const std::string
& pkgname
,
155 const addPackageData
&pkgdata
);
157 void internalize(void);
158 void use_test_packages(bool use_test_packages
);
163 Id
makedeps(Repo
*repo
, PackageDepends
*requires
);
166 typedef std::map
<std::string
, SolvRepo
*> RepoList
;
169 friend SolverSolution
;
173 // ---------------------------------------------------------------------------
174 // interface to class SolverTaskQueue
176 // This is used to contain a set of package install/uninstall tasks selected via
177 // the UI to be passed to solver
178 // ---------------------------------------------------------------------------
190 taskForceDistUpgrade
,
192 void add(const SolvableVersion
&v
, task t
)
194 tasks
.push_back(taskList::value_type(v
, t
));
196 /* Create solver tasks corresponding to state of database */
200 typedef std::vector
<std::pair
<const SolvableVersion
, task
>> taskList
;
203 friend SolverSolution
;
206 // ---------------------------------------------------------------------------
207 // SolverTransactionList
209 // a list of transactions output by the solver
210 // ---------------------------------------------------------------------------
212 class SolverTransaction
222 SolverTransaction(SolvableVersion version_
, transType type_
) :
223 version(version_
), type(type_
) {};
225 SolvableVersion version
;
229 typedef std::vector
<SolverTransaction
> SolverTransactionList
;
231 // ---------------------------------------------------------------------------
232 // interface to class SolverSolution
234 // A wrapper around the libsolv solver
235 // ---------------------------------------------------------------------------
240 SolverSolution(SolverPool
&_pool
);
244 /* Reset package database to correspond to trans */
245 void trans2db() const;
247 /* Reset transaction list to correspond to package database */
252 keep
, // don't update
253 updateBest
, // update to best version
254 updateForce
, // distupdate: downgrade if necessary to best version in repo
256 bool update(SolverTasks
&tasks
, updateMode update
, bool use_test_packages
);
257 void augmentTasks(SolverTasks
&tasks
);
258 void addSource(bool include_source
);
259 void applyDefaultProblemSolutions();
260 std::string
report() const;
262 const SolverTransactionList
&transactions() const;
263 void dumpTransactionList() const;
266 static SolverTransaction::transType
type(Transaction
*trans
, int pos
);
268 void tasksToJobs(SolverTasks
&tasks
, updateMode update
, Queue
&job
);
269 void solutionToTransactionList();
274 SolverTransactionList trans
;