2023-01-10 16:27:19 +00:00
|
|
|
#pragma once
|
2023-04-01 03:18:41 +00:00
|
|
|
///@file
|
2023-01-10 16:27:19 +00:00
|
|
|
|
2023-01-13 01:41:29 +00:00
|
|
|
#include <cassert>
|
2023-01-11 23:57:18 +00:00
|
|
|
#include <optional>
|
2023-01-11 06:51:14 +00:00
|
|
|
#include <set>
|
2023-01-10 16:27:19 +00:00
|
|
|
#include <variant>
|
|
|
|
|
2023-01-11 21:32:30 +00:00
|
|
|
#include "json-impls.hh"
|
2023-01-10 16:27:19 +00:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* A non-empty set of outputs, specified by name
|
|
|
|
*/
|
2023-01-11 16:54:43 +00:00
|
|
|
struct OutputNames : std::set<std::string> {
|
|
|
|
using std::set<std::string>::set;
|
|
|
|
|
2023-01-13 01:41:29 +00:00
|
|
|
/* These need to be "inherited manually" */
|
|
|
|
|
2023-01-11 16:54:43 +00:00
|
|
|
OutputNames(const std::set<std::string> & s)
|
|
|
|
: std::set<std::string>(s)
|
2023-01-13 01:41:29 +00:00
|
|
|
{ assert(!empty()); }
|
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* Needs to be "inherited manually"
|
|
|
|
*/
|
2023-01-11 16:54:43 +00:00
|
|
|
OutputNames(std::set<std::string> && s)
|
|
|
|
: std::set<std::string>(s)
|
2023-01-13 01:41:29 +00:00
|
|
|
{ assert(!empty()); }
|
2023-01-11 16:54:43 +00:00
|
|
|
|
|
|
|
/* 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 16:27:19 +00:00
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* The set of all outputs, without needing to name them explicitly
|
|
|
|
*/
|
2023-01-11 22:31:32 +00:00
|
|
|
struct AllOutputs : std::monostate { };
|
2023-01-10 16:27:19 +00:00
|
|
|
|
2023-01-11 23:57:18 +00:00
|
|
|
typedef std::variant<AllOutputs, OutputNames> _OutputsSpecRaw;
|
|
|
|
|
|
|
|
struct OutputsSpec : _OutputsSpecRaw {
|
|
|
|
using Raw = _OutputsSpecRaw;
|
|
|
|
using Raw::Raw;
|
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* Force choosing a variant
|
|
|
|
*/
|
2023-01-11 21:32:30 +00:00
|
|
|
OutputsSpec() = delete;
|
|
|
|
|
2023-01-11 23:57:18 +00:00
|
|
|
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;
|
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* Create a new OutputsSpec which is the union of this and that.
|
|
|
|
*/
|
2023-01-13 01:20:27 +00:00
|
|
|
OutputsSpec union_(const OutputsSpec & that) const;
|
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* Whether this OutputsSpec is a subset of that.
|
|
|
|
*/
|
2023-01-13 01:20:27 +00:00
|
|
|
bool isSubsetOf(const OutputsSpec & outputs) const;
|
2023-01-11 23:57:18 +00:00
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* Parse a string of the form 'output1,...outputN' or '*', returning
|
|
|
|
* the outputs spec.
|
|
|
|
*/
|
2023-01-11 23:57:18 +00:00
|
|
|
static OutputsSpec parse(std::string_view s);
|
|
|
|
static std::optional<OutputsSpec> parseOpt(std::string_view s);
|
|
|
|
|
|
|
|
std::string to_string() const;
|
|
|
|
};
|
|
|
|
|
2023-01-11 22:31:32 +00:00
|
|
|
struct DefaultOutputs : std::monostate { };
|
2023-01-10 16:27:19 +00:00
|
|
|
|
2023-01-11 23:57:18 +00:00
|
|
|
typedef std::variant<DefaultOutputs, OutputsSpec> _ExtendedOutputsSpecRaw;
|
2023-01-11 06:51:14 +00:00
|
|
|
|
2023-01-11 07:00:44 +00:00
|
|
|
struct ExtendedOutputsSpec : _ExtendedOutputsSpecRaw {
|
|
|
|
using Raw = _ExtendedOutputsSpecRaw;
|
2023-01-11 06:51:14 +00:00
|
|
|
using Raw::Raw;
|
|
|
|
|
|
|
|
using Default = DefaultOutputs;
|
2023-01-11 23:57:18 +00:00
|
|
|
using Explicit = OutputsSpec;
|
2023-01-10 16:27:19 +00:00
|
|
|
|
2023-01-11 06:51:14 +00:00
|
|
|
inline const Raw & raw() const {
|
|
|
|
return static_cast<const Raw &>(*this);
|
|
|
|
}
|
2023-01-10 16:27:19 +00:00
|
|
|
|
2023-03-25 23:12:44 +00:00
|
|
|
/**
|
|
|
|
* Parse a string of the form 'prefix^output1,...outputN' or
|
|
|
|
* 'prefix^*', returning the prefix and the extended outputs spec.
|
|
|
|
*/
|
2023-01-11 23:57:18 +00:00
|
|
|
static std::pair<std::string_view, ExtendedOutputsSpec> parse(std::string_view s);
|
2023-01-11 22:31:32 +00:00
|
|
|
static std::optional<std::pair<std::string_view, ExtendedOutputsSpec>> parseOpt(std::string_view s);
|
2023-01-11 06:51:14 +00:00
|
|
|
|
|
|
|
std::string to_string() const;
|
|
|
|
};
|
2023-01-10 16:27:19 +00:00
|
|
|
|
|
|
|
}
|
2023-01-11 21:32:30 +00:00
|
|
|
|
|
|
|
JSON_IMPL(OutputsSpec)
|
|
|
|
JSON_IMPL(ExtendedOutputsSpec)
|