Flox Package Database 1
CRUD Operations on Nix Package Metadata
Loading...
Searching...
No Matches
manifest-raw.hh
Go to the documentation of this file.
1/* ========================================================================== *
2 *
3 * @file flox/resolver/manifest-raw.hh
4 *
5 * @brief An abstract description of an environment in its unresolved state.
6 * This representation is intended for serialization and deserialization.
7 * For the _real_ representation, see
8 * [flox/resolver/manifest.hh](./manifest.hh).
9 *
10 *
11 * -------------------------------------------------------------------------- */
12
13#pragma once
14
15#include <algorithm>
16#include <optional>
17#include <string>
18#include <string_view>
19#include <unordered_map>
20#include <utility>
21#include <vector>
22
23#include <nlohmann/json.hpp>
24
25#include "compat/concepts.hh"
27#include "flox/core/types.hh"
29#include "flox/registry.hh"
30#include "flox/resolver/descriptor.hh" // IWYU pragma: keep
31
32
33/* -------------------------------------------------------------------------- */
34
35namespace flox::resolver {
36
37/* -------------------------------------------------------------------------- */
38
39/* Forward Declarations */
40
41struct GlobalManifestRaw;
42struct ManifestRaw;
43struct GlobalManifestRawGA;
44struct ManifestRawGA;
45
46
47/* -------------------------------------------------------------------------- */
48
56 "invalid manifest file" )
60/* -------------------------------------------------------------------------- */
61
62
66using InstallID = std::string;
67
68
69/* -------------------------------------------------------------------------- */
70
72struct Options
73{
74
75 std::optional<std::vector<System>> systems;
76
77 struct Allows
78 {
79 std::optional<bool> unfree;
80 std::optional<bool> broken;
81 std::optional<std::vector<std::string>> licenses;
82 }; /* End struct `Allows' */
83 std::optional<Allows> allow;
84
85 struct Semver
86 {
87 std::optional<bool> preferPreReleases;
88 }; /* End struct `Semver' */
89 std::optional<Semver> semver;
90
91 std::optional<std::string> packageGroupingStrategy;
92 std::optional<std::string> activationStrategy;
93 // TODO: Other options
94
95
99 void
100 merge( const Options & overrides );
101
103 explicit operator pkgdb::PkgQueryArgs() const;
104
105
106}; /* End struct `Options' */
107
108
109/* -------------------------------------------------------------------------- */
110
112void
113from_json( const nlohmann::json & jfrom, Options & opts );
114
116void
117to_json( nlohmann::json & jto, const Options & opts );
118
119
120/* -------------------------------------------------------------------------- */
121
133{
135 std::optional<RegistryRaw> registry;
136
138 std::optional<Options> options;
139
140
141 virtual ~GlobalManifestRaw() = default;
142 GlobalManifestRaw() = default;
143 GlobalManifestRaw( const GlobalManifestRaw & ) = default;
144 GlobalManifestRaw( GlobalManifestRaw && ) = default;
145
146 explicit GlobalManifestRaw( std::optional<RegistryRaw> registry,
147 std::optional<Options> options = std::nullopt )
148 : registry( std::move( registry ) ), options( std::move( options ) )
149 {}
150
151 explicit GlobalManifestRaw( std::optional<Options> options )
152 : options( std::move( options ) )
153 {}
154
155 GlobalManifestRaw &
156 operator=( const GlobalManifestRaw & )
157 = default;
158 GlobalManifestRaw &
159 operator=( GlobalManifestRaw && )
160 = default;
161
166 virtual void
167 check() const
168 {}
169
170 virtual void
171 clear()
172 {
173 this->registry = std::nullopt;
174 this->options = std::nullopt;
175 }
176
177 explicit operator GlobalManifestRawGA() const;
178
179
180}; /* End struct `GlobalManifestRaw' */
181
182
183/* -------------------------------------------------------------------------- */
184
186void
187from_json( const nlohmann::json & jfrom, GlobalManifestRaw & manifest );
188
190void
191to_json( nlohmann::json & jto, const GlobalManifestRaw & manifest );
192
193
194/* -------------------------------------------------------------------------- */
195
198{
200 std::optional<std::string> floxhub;
201
205 std::optional<std::string> dir;
206
207
215 void
216 check() const;
217
218 void
219 clear()
220 {
221 this->floxhub = std::nullopt;
222 this->dir = std::nullopt;
223 }
224
225
226}; /* End struct `EnvBaseRaw' */
227
228
229/* -------------------------------------------------------------------------- */
230
233{
235 std::optional<std::string> script;
236
238 std::optional<std::string> file;
239
240
245 void
246 check() const;
247
248
249}; /* End struct `HookRaw' */
250
251
252/* -------------------------------------------------------------------------- */
253
264{
265
266 std::optional<EnvBaseRaw> envBase;
267
268 std::optional<
269 std::unordered_map<InstallID, std::optional<ManifestDescriptorRaw>>>
270 install;
271
272 std::optional<std::unordered_map<std::string, std::string>> vars;
273
274 std::optional<HookRaw> hook;
275
276
277 ~ManifestRaw() override = default;
278 ManifestRaw() = default;
279 ManifestRaw( const ManifestRaw & ) = default;
280 ManifestRaw( ManifestRaw && ) = default;
281
282 explicit ManifestRaw( const GlobalManifestRaw & globalManifestRaw )
283 : GlobalManifestRaw( globalManifestRaw )
284 {}
285
286 explicit ManifestRaw( GlobalManifestRaw && globalManifestRaw )
287 : GlobalManifestRaw( globalManifestRaw )
288 {}
289
291 operator=( const ManifestRaw & )
292 = default;
293
295 operator=( ManifestRaw && )
296 = default;
297
299 operator=( const GlobalManifestRaw & globalManifestRaw )
300 {
301 GlobalManifestRaw::operator=( globalManifestRaw );
302 return *this;
303 }
304
306 operator=( GlobalManifestRaw && globalManifestRaw )
307 {
308 GlobalManifestRaw::operator=( globalManifestRaw );
309 return *this;
310 }
311
322 void
323 check() const override;
324
325 void
326 clear() override
327 {
328 /* From `GlobalManifestRaw' */
329 this->options = std::nullopt;
330 this->registry = std::nullopt;
331 /* From `ManifestRaw' */
332 this->envBase = std::nullopt;
333 this->install = std::nullopt;
334 this->vars = std::nullopt;
335 this->hook = std::nullopt;
336 }
337
343 nlohmann::json
344 diff( const ManifestRaw & old ) const;
345
346 explicit operator ManifestRawGA() const;
347
348
349}; /* End struct `ManifestRaw' */
350
351
352/* -------------------------------------------------------------------------- */
353
355void
356from_json( const nlohmann::json & jfrom, ManifestRaw & manifest );
357
359void
360to_json( nlohmann::json & jto, const ManifestRaw & manifest );
361
362
363/* -------------------------------------------------------------------------- */
364
378{
379
381 std::optional<Options> options;
382
383
384 virtual ~GlobalManifestRawGA() = default;
385 GlobalManifestRawGA() = default;
386 GlobalManifestRawGA( const GlobalManifestRawGA & ) = default;
388
389 explicit GlobalManifestRawGA( std::optional<Options> options )
390 : options( std::move( options ) )
391 {}
392
394 operator=( const GlobalManifestRawGA & )
395 = default;
396
398 operator=( GlobalManifestRawGA && )
399 = default;
400
405 virtual void
406 check() const
407 {}
408
409 virtual void
410 clear()
411 {
412 this->options = std::nullopt;
413 }
414
415 explicit operator GlobalManifestRaw() const
416 {
417 return GlobalManifestRaw( getGARegistry(), this->options );
418 }
419
420 explicit operator ManifestRaw() const
421 {
422 return ManifestRaw( static_cast<GlobalManifestRaw>( *this ) );
423 }
424
425
426}; /* End struct `GlobalManifestRawGA' */
427
428
429/* -------------------------------------------------------------------------- */
430
432void
433from_json( const nlohmann::json & jfrom, GlobalManifestRawGA & manifest );
434
436void
437to_json( nlohmann::json & jto, const GlobalManifestRawGA & manifest );
438
439
440/* -------------------------------------------------------------------------- */
441
453{
454
455 std::optional<
456 std::unordered_map<InstallID, std::optional<ManifestDescriptorRaw>>>
457 install;
458
459 std::optional<std::unordered_map<std::string, std::string>> vars;
460
461 std::optional<HookRaw> hook;
462
463
464 ~ManifestRawGA() override = default;
465 ManifestRawGA() = default;
466 ManifestRawGA( const ManifestRawGA & ) = default;
467 ManifestRawGA( ManifestRawGA && ) = default;
468
469 explicit ManifestRawGA( const GlobalManifestRawGA & globalManifestRawGA )
470 : GlobalManifestRawGA( globalManifestRawGA )
471 {}
472
473 explicit ManifestRawGA( GlobalManifestRawGA && globalManifestRawGA )
474 : GlobalManifestRawGA( globalManifestRawGA )
475 {}
476
478 operator=( const ManifestRawGA & )
479 = default;
480
482 operator=( ManifestRawGA && )
483 = default;
484
486 operator=( const GlobalManifestRawGA & globalManifestRawGA )
487 {
488 GlobalManifestRawGA::operator=( globalManifestRawGA );
489 return *this;
490 }
491
493 operator=( GlobalManifestRawGA && globalManifestRawGA )
494 {
495 GlobalManifestRawGA::operator=( globalManifestRawGA );
496 return *this;
497 }
498
507 void
508 check() const override;
509
510 void
511 clear() override
512 {
513 /* From `GlobalManifestRawGA' */
514 this->options = std::nullopt;
515 /* From `ManifestRawGA' */
516 this->install = std::nullopt;
517 this->vars = std::nullopt;
518 this->hook = std::nullopt;
519 }
520
526 nlohmann::json
527 diff( const ManifestRawGA & old ) const;
528
529 explicit operator ManifestRaw() const
530 {
531 ManifestRaw raw;
532 raw.registry = getGARegistry();
533 raw.options = this->options;
534 raw.install = this->install;
535 raw.vars = this->vars;
536 raw.hook = this->hook;
537 return raw;
538 }
539
540
541}; /* End struct `ManifestRawGA' */
542
543
544/* -------------------------------------------------------------------------- */
545
547void
548from_json( const nlohmann::json & jfrom, ManifestRawGA & manifest );
549
551void
552to_json( nlohmann::json & jto, const ManifestRawGA & manifest );
553
554
555/* -------------------------------------------------------------------------- */
556
561template<typename RawType>
562concept manifest_raw_type = std::derived_from<RawType, GlobalManifestRaw>
563 || std::derived_from<RawType, GlobalManifestRawGA>;
564
567static_assert( manifest_raw_type<ManifestRaw> );
568static_assert( manifest_raw_type<ManifestRawGA> );
569
570
571/* -------------------------------------------------------------------------- */
572
573} // namespace flox::resolver
574
575
576/* -------------------------------------------------------------------------- *
577 *
578 *
579 *
580 * ========================================================================== */
An exception thrown when a manifest file is invalid.
Restrict types to those derived from flox::resolver::GlobalManifestRaw or flox::resolver::GlobalManif...
Definition: manifest-raw.hh:562
Provides backports of some concepts features that are missing in Clang v11.
A set of user inputs used to set input preferences and query parameters during resolution.
Definitions of various std::exception children used for throwing errors with nice messages and typed ...
#define FLOX_DEFINE_EXCEPTION(NAME, ERROR_CODE, CATEGORY_MSG)
Generate a class definition with an error code and category message.
Definition: exceptions.hh:206
@ EC_INVALID_MANIFEST_FILE
Definition: exceptions.hh:45
RegistryRaw getGARegistry()
Get a hard coded registry for use with flox's GA release.
Definition: registry.cc:377
void from_json(const nlohmann::json &jfrom, RawPackage &pkg)
Convert a JSON object to a flox::RawPackage.
Definition: raw-package.cc:27
void to_json(nlohmann::json &jto, const FloxException &err)
Convert a flox::FloxException to a JSON object.
Definition: exceptions.cc:27
Interfaces for constructing complex ‘Packages’ queries.
A set of user inputs used to set input preferences during search and resolution.
Declares a base environment to extend.
Definition: manifest-raw.hh:198
void check() const
Validate the env-base field, throwing an exception if invalid information is found.
Definition: manifest-raw.cc:393
std::optional< std::string > dir
Definition: manifest-raw.hh:205
std::optional< std::string > floxhub
Definition: manifest-raw.hh:200
A global manifest containing only registry and options fields in its raw form. This form is limited t...
Definition: manifest-raw.hh:378
virtual void check() const
Validate manifest fields, throwing an exception if its contents are invalid.
Definition: manifest-raw.hh:406
std::optional< Options > options
Options controlling environment and search behaviors.
Definition: manifest-raw.hh:381
A global manifest containing only registry and options fields in its raw form.
Definition: manifest-raw.hh:133
virtual void check() const
Validate manifest fields, throwing an exception if its contents are invalid.
Definition: manifest-raw.hh:167
std::optional< Options > options
Options controlling environment and search behaviors.
Definition: manifest-raw.hh:138
std::optional< RegistryRaw > registry
Definition: manifest-raw.hh:135
Declares a hook to be run at environment activation.
Definition: manifest-raw.hh:233
void check() const
Validate Hook fields, throwing an exception if its contents are invalid.
Definition: manifest-raw.cc:529
std::optional< std::string > script
Definition: manifest-raw.hh:235
std::optional< std::string > file
Definition: manifest-raw.hh:238
A raw description of an environment to be read from a file. This form drops the registry field for us...
Definition: manifest-raw.hh:453
nlohmann::json diff(const ManifestRawGA &old) const
Generate a JSON diff between this manifest an old manifest.
Definition: manifest-raw.cc:796
void check() const override
Validate manifest fields, throwing an exception if its contents are invalid.
Definition: manifest-raw.cc:805
A raw description of an environment to be read from a file.
Definition: manifest-raw.hh:264
void check() const override
Validate manifest fields, throwing an exception if its contents are invalid.
Definition: manifest-raw.cc:672
nlohmann::json diff(const ManifestRaw &old) const
Generate a JSON diff between this manifest an old manifest.
Definition: manifest-raw.cc:702
Definition: manifest-raw.hh:78
Definition: manifest-raw.hh:86
A set of options that apply to an entire environment.
Definition: manifest-raw.hh:73
Miscellaneous typedefs and aliases.