1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-17 07:52:43 +01:00

Rename OutputPath -> ExtendedOutputPath

Do this prior to making a new more limitted `OutputPath` we will use in
more places.
This commit is contained in:
John Ericson 2023-01-11 02:00:44 -05:00
parent a8f45b5e5a
commit a7c0cff07f
9 changed files with 60 additions and 60 deletions

View file

@ -6,7 +6,7 @@
namespace nix {
std::pair<std::string, OutputsSpec> OutputsSpec::parse(std::string s)
std::pair<std::string, ExtendedOutputsSpec> ExtendedOutputsSpec::parse(std::string s)
{
static std::regex regex(R"((.*)\^((\*)|([a-z]+(,[a-z]+)*)))");
@ -20,43 +20,43 @@ std::pair<std::string, OutputsSpec> OutputsSpec::parse(std::string s)
return {match[1], tokenizeString<OutputNames>(match[4].str(), ",")};
}
std::string OutputsSpec::to_string() const
std::string ExtendedOutputsSpec::to_string() const
{
return std::visit(overloaded {
[&](const OutputsSpec::Default &) -> std::string {
[&](const ExtendedOutputsSpec::Default &) -> std::string {
return "";
},
[&](const OutputsSpec::All &) -> std::string {
[&](const ExtendedOutputsSpec::All &) -> std::string {
return "*";
},
[&](const OutputsSpec::Names & outputNames) -> std::string {
[&](const ExtendedOutputsSpec::Names & outputNames) -> std::string {
return "^" + concatStringsSep(",", outputNames);
},
}, raw());
}
void to_json(nlohmann::json & json, const OutputsSpec & outputsSpec)
void to_json(nlohmann::json & json, const ExtendedOutputsSpec & extendedOutputsSpec)
{
if (std::get_if<DefaultOutputs>(&outputsSpec))
if (std::get_if<DefaultOutputs>(&extendedOutputsSpec))
json = nullptr;
else if (std::get_if<AllOutputs>(&outputsSpec))
else if (std::get_if<AllOutputs>(&extendedOutputsSpec))
json = std::vector<std::string>({"*"});
else if (auto outputNames = std::get_if<OutputNames>(&outputsSpec))
else if (auto outputNames = std::get_if<OutputNames>(&extendedOutputsSpec))
json = *outputNames;
}
void from_json(const nlohmann::json & json, OutputsSpec & outputsSpec)
void from_json(const nlohmann::json & json, ExtendedOutputsSpec & extendedOutputsSpec)
{
if (json.is_null())
outputsSpec = DefaultOutputs();
extendedOutputsSpec = DefaultOutputs();
else {
auto names = json.get<OutputNames>();
if (names == OutputNames({"*"}))
outputsSpec = AllOutputs();
extendedOutputsSpec = AllOutputs();
else
outputsSpec = names;
extendedOutputsSpec = names;
}
}

View file

@ -17,10 +17,10 @@ struct DefaultOutputs {
bool operator < (const DefaultOutputs & _) const { return false; }
};
typedef std::variant<DefaultOutputs, AllOutputs, OutputNames> _OutputsSpecRaw;
typedef std::variant<DefaultOutputs, AllOutputs, OutputNames> _ExtendedOutputsSpecRaw;
struct OutputsSpec : _OutputsSpecRaw {
using Raw = _OutputsSpecRaw;
struct ExtendedOutputsSpec : _ExtendedOutputsSpecRaw {
using Raw = _ExtendedOutputsSpecRaw;
using Raw::Raw;
using Names = OutputNames;
@ -33,12 +33,12 @@ struct OutputsSpec : _OutputsSpecRaw {
/* Parse a string of the form 'prefix^output1,...outputN' or
'prefix^*', returning the prefix and the outputs spec. */
static std::pair<std::string, OutputsSpec> parse(std::string s);
static std::pair<std::string, ExtendedOutputsSpec> parse(std::string s);
std::string to_string() const;
};
void to_json(nlohmann::json &, const OutputsSpec &);
void from_json(const nlohmann::json &, OutputsSpec &);
void to_json(nlohmann::json &, const ExtendedOutputsSpec &);
void from_json(const nlohmann::json &, ExtendedOutputsSpec &);
}

View file

@ -4,42 +4,42 @@
namespace nix {
TEST(OutputsSpec_parse, basic)
TEST(ExtendedOutputsSpec_parse, basic)
{
{
auto [prefix, outputsSpec] = OutputsSpec::parse("foo");
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo");
ASSERT_EQ(prefix, "foo");
ASSERT_TRUE(std::get_if<DefaultOutputs>(&outputsSpec));
ASSERT_TRUE(std::get_if<DefaultOutputs>(&extendedOutputsSpec));
}
{
auto [prefix, outputsSpec] = OutputsSpec::parse("foo^*");
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^*");
ASSERT_EQ(prefix, "foo");
ASSERT_TRUE(std::get_if<AllOutputs>(&outputsSpec));
ASSERT_TRUE(std::get_if<AllOutputs>(&extendedOutputsSpec));
}
{
auto [prefix, outputsSpec] = OutputsSpec::parse("foo^out");
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^out");
ASSERT_EQ(prefix, "foo");
ASSERT_TRUE(std::get<OutputNames>(outputsSpec) == OutputNames({"out"}));
ASSERT_TRUE(std::get<OutputNames>(extendedOutputsSpec) == OutputNames({"out"}));
}
{
auto [prefix, outputsSpec] = OutputsSpec::parse("foo^out,bin");
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^out,bin");
ASSERT_EQ(prefix, "foo");
ASSERT_TRUE(std::get<OutputNames>(outputsSpec) == OutputNames({"out", "bin"}));
ASSERT_TRUE(std::get<OutputNames>(extendedOutputsSpec) == OutputNames({"out", "bin"}));
}
{
auto [prefix, outputsSpec] = OutputsSpec::parse("foo^bar^out,bin");
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^bar^out,bin");
ASSERT_EQ(prefix, "foo^bar");
ASSERT_TRUE(std::get<OutputNames>(outputsSpec) == OutputNames({"out", "bin"}));
ASSERT_TRUE(std::get<OutputNames>(extendedOutputsSpec) == OutputNames({"out", "bin"}));
}
{
auto [prefix, outputsSpec] = OutputsSpec::parse("foo^&*()");
auto [prefix, extendedOutputsSpec] = ExtendedOutputsSpec::parse("foo^&*()");
ASSERT_EQ(prefix, "foo^&*()");
ASSERT_TRUE(std::get_if<DefaultOutputs>(&outputsSpec));
ASSERT_TRUE(std::get_if<DefaultOutputs>(&extendedOutputsSpec));
}
}