2023-01-10 18:27:19 +02:00
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
///@file
|
2023-01-10 18:27:19 +02:00
|
|
|
|
2023-01-13 03:41:29 +02:00
|
|
|
#include <cassert>
|
2023-01-12 01:57:18 +02:00
|
|
|
#include <optional>
|
2023-01-11 08:51:14 +02:00
|
|
|
#include <set>
|
2023-01-10 18:27:19 +02:00
|
|
|
#include <variant>
|
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
#include "comparator.hh"
|
2023-01-11 23:32:30 +02:00
|
|
|
#include "json-impls.hh"
|
2023-08-16 19:29:23 +03:00
|
|
|
#include "comparator.hh"
|
|
|
|
#include "variant-wrapper.hh"
|
2023-01-10 18:27:19 +02:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
struct OutputsSpec {
|
|
|
|
/**
|
|
|
|
* A non-empty set of outputs, specified by name
|
|
|
|
*/
|
|
|
|
struct Names : std::set<std::string> {
|
|
|
|
using std::set<std::string>::set;
|
|
|
|
|
|
|
|
/* These need to be "inherited manually" */
|
|
|
|
|
|
|
|
Names(const std::set<std::string> & s)
|
|
|
|
: std::set<std::string>(s)
|
|
|
|
{ assert(!empty()); }
|
2023-01-11 18:54:43 +02:00
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
/**
|
|
|
|
* Needs to be "inherited manually"
|
|
|
|
*/
|
|
|
|
Names(std::set<std::string> && s)
|
|
|
|
: std::set<std::string>(s)
|
|
|
|
{ assert(!empty()); }
|
2023-01-13 03:41:29 +02:00
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
/* This set should always be non-empty, so we delete this
|
|
|
|
constructor in order make creating empty ones by mistake harder.
|
|
|
|
*/
|
|
|
|
Names() = delete;
|
|
|
|
};
|
2023-01-13 03:41:29 +02:00
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
/**
|
2023-08-16 19:29:23 +03:00
|
|
|
* The set of all outputs, without needing to name them explicitly
|
2023-03-26 01:12:44 +02:00
|
|
|
*/
|
2023-08-16 19:29:23 +03:00
|
|
|
struct All : std::monostate { };
|
|
|
|
|
|
|
|
typedef std::variant<All, Names> Raw;
|
2023-01-10 18:27:19 +02:00
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
Raw raw;
|
2023-01-10 18:27:19 +02:00
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
GENERATE_CMP(OutputsSpec, me->raw);
|
2023-01-12 01:57:18 +02:00
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
MAKE_WRAPPER_CONSTRUCTOR(OutputsSpec);
|
2023-01-12 01:57:18 +02:00
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
/**
|
|
|
|
* Force choosing a variant
|
|
|
|
*/
|
2023-01-11 23:32:30 +02:00
|
|
|
OutputsSpec() = delete;
|
|
|
|
|
2023-01-12 01:57:18 +02:00
|
|
|
bool contains(const std::string & output) const;
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
/**
|
|
|
|
* Create a new OutputsSpec which is the union of this and that.
|
|
|
|
*/
|
2023-01-13 03:20:27 +02:00
|
|
|
OutputsSpec union_(const OutputsSpec & that) const;
|
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
/**
|
|
|
|
* Whether this OutputsSpec is a subset of that.
|
|
|
|
*/
|
2023-01-13 03:20:27 +02:00
|
|
|
bool isSubsetOf(const OutputsSpec & outputs) const;
|
2023-01-12 01:57:18 +02:00
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
/**
|
|
|
|
* Parse a string of the form 'output1,...outputN' or '*', returning
|
|
|
|
* the outputs spec.
|
|
|
|
*/
|
2023-01-12 01:57:18 +02:00
|
|
|
static OutputsSpec parse(std::string_view s);
|
|
|
|
static std::optional<OutputsSpec> parseOpt(std::string_view s);
|
|
|
|
|
|
|
|
std::string to_string() const;
|
|
|
|
};
|
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
struct ExtendedOutputsSpec {
|
|
|
|
struct Default : std::monostate { };
|
|
|
|
using Explicit = OutputsSpec;
|
|
|
|
|
|
|
|
typedef std::variant<Default, Explicit> Raw;
|
2023-01-10 18:27:19 +02:00
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
Raw raw;
|
2023-01-11 08:51:14 +02:00
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
GENERATE_CMP(ExtendedOutputsSpec, me->raw);
|
2023-01-11 08:51:14 +02:00
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
MAKE_WRAPPER_CONSTRUCTOR(ExtendedOutputsSpec);
|
2023-01-10 18:27:19 +02:00
|
|
|
|
2023-08-16 19:29:23 +03:00
|
|
|
/**
|
|
|
|
* Force choosing a variant
|
|
|
|
*/
|
|
|
|
ExtendedOutputsSpec() = delete;
|
2023-01-10 18:27:19 +02:00
|
|
|
|
2023-03-26 01:12:44 +02:00
|
|
|
/**
|
|
|
|
* Parse a string of the form 'prefix^output1,...outputN' or
|
|
|
|
* 'prefix^*', returning the prefix and the extended outputs spec.
|
|
|
|
*/
|
2023-01-12 01:57:18 +02:00
|
|
|
static std::pair<std::string_view, ExtendedOutputsSpec> parse(std::string_view s);
|
2023-01-12 00:31:32 +02:00
|
|
|
static std::optional<std::pair<std::string_view, ExtendedOutputsSpec>> parseOpt(std::string_view s);
|
2023-01-11 08:51:14 +02:00
|
|
|
|
|
|
|
std::string to_string() const;
|
|
|
|
};
|
2023-01-10 18:27:19 +02:00
|
|
|
|
|
|
|
}
|
2023-01-11 23:32:30 +02:00
|
|
|
|
|
|
|
JSON_IMPL(OutputsSpec)
|
|
|
|
JSON_IMPL(ExtendedOutputsSpec)
|