2023-01-10 18:27:19 +02:00
|
|
|
#pragma once
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
#include "nlohmann/json_fwd.hpp"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-01-11 18:54:43 +02:00
|
|
|
struct OutputNames : std::set<std::string> {
|
|
|
|
using std::set<std::string>::set;
|
|
|
|
|
|
|
|
// These need to be "inherited manually"
|
|
|
|
OutputNames(const std::set<std::string> & s)
|
|
|
|
: std::set<std::string>(s)
|
|
|
|
{ }
|
|
|
|
OutputNames(std::set<std::string> && s)
|
|
|
|
: std::set<std::string>(s)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/* This set should always be non-empty, so we delete this
|
|
|
|
constructor in order make creating empty ones by mistake harder.
|
|
|
|
*/
|
|
|
|
OutputNames() = delete;
|
|
|
|
};
|
2023-01-10 18:27:19 +02:00
|
|
|
|
|
|
|
struct AllOutputs {
|
|
|
|
bool operator < (const AllOutputs & _) const { return false; }
|
|
|
|
};
|
|
|
|
|
2023-01-12 01:57:18 +02:00
|
|
|
typedef std::variant<AllOutputs, OutputNames> _OutputsSpecRaw;
|
|
|
|
|
|
|
|
struct OutputsSpec : _OutputsSpecRaw {
|
|
|
|
using Raw = _OutputsSpecRaw;
|
|
|
|
using Raw::Raw;
|
|
|
|
|
|
|
|
using Names = OutputNames;
|
|
|
|
using All = AllOutputs;
|
|
|
|
|
|
|
|
inline const Raw & raw() const {
|
|
|
|
return static_cast<const Raw &>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Raw & raw() {
|
|
|
|
return static_cast<Raw &>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool contains(const std::string & output) const;
|
|
|
|
|
|
|
|
/* Modify the receiver outputs spec so it is the union of it's old value
|
|
|
|
and the argument. Return whether the output spec needed to be modified
|
|
|
|
--- if it didn't it was already "large enough". */
|
|
|
|
bool merge(const OutputsSpec & outputs);
|
|
|
|
|
|
|
|
/* Parse a string of the form 'output1,...outputN' or
|
|
|
|
'*', returning the outputs spec. */
|
|
|
|
static OutputsSpec parse(std::string_view s);
|
|
|
|
static std::optional<OutputsSpec> parseOpt(std::string_view s);
|
|
|
|
|
|
|
|
std::string to_string() const;
|
|
|
|
};
|
|
|
|
|
2023-01-10 18:27:19 +02:00
|
|
|
struct DefaultOutputs {
|
|
|
|
bool operator < (const DefaultOutputs & _) const { return false; }
|
|
|
|
};
|
|
|
|
|
2023-01-12 01:57:18 +02:00
|
|
|
typedef std::variant<DefaultOutputs, OutputsSpec> _ExtendedOutputsSpecRaw;
|
2023-01-11 08:51:14 +02:00
|
|
|
|
2023-01-11 09:00:44 +02:00
|
|
|
struct ExtendedOutputsSpec : _ExtendedOutputsSpecRaw {
|
|
|
|
using Raw = _ExtendedOutputsSpecRaw;
|
2023-01-11 08:51:14 +02:00
|
|
|
using Raw::Raw;
|
|
|
|
|
|
|
|
using Default = DefaultOutputs;
|
2023-01-12 01:57:18 +02:00
|
|
|
using Explicit = OutputsSpec;
|
2023-01-10 18:27:19 +02:00
|
|
|
|
2023-01-11 08:51:14 +02:00
|
|
|
inline const Raw & raw() const {
|
|
|
|
return static_cast<const Raw &>(*this);
|
|
|
|
}
|
2023-01-10 18:27:19 +02:00
|
|
|
|
2023-01-11 08:51:14 +02:00
|
|
|
/* Parse a string of the form 'prefix^output1,...outputN' or
|
2023-01-12 01:57:18 +02:00
|
|
|
'prefix^*', returning the prefix and the extended outputs spec. */
|
|
|
|
static std::pair<std::string_view, ExtendedOutputsSpec> parse(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-12 01:57:18 +02:00
|
|
|
|
|
|
|
void to_json(nlohmann::json &, const OutputsSpec &);
|
|
|
|
void from_json(const nlohmann::json &, OutputsSpec &);
|
|
|
|
|
2023-01-11 09:00:44 +02:00
|
|
|
void to_json(nlohmann::json &, const ExtendedOutputsSpec &);
|
|
|
|
void from_json(const nlohmann::json &, ExtendedOutputsSpec &);
|
2023-01-10 18:27:19 +02:00
|
|
|
|
|
|
|
}
|