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

Split OutputsSpec::merge into OuputsSpec::{union_, isSubsetOf}

Additionally get rid of the evil time we made an empty
`OutputSpec::Names()`.
This commit is contained in:
John Ericson 2023-01-12 20:20:27 -05:00
parent 0faf5326bd
commit 31875bcfb7
4 changed files with 56 additions and 30 deletions

View file

@ -144,9 +144,10 @@ void DerivationGoal::work()
void DerivationGoal::addWantedOutputs(const OutputsSpec & outputs)
{
bool newOutputs = wantedOutputs.merge(outputs);
if (newOutputs)
auto newWanted = wantedOutputs.union_(outputs);
if (!newWanted.isSubsetOf(wantedOutputs))
needRestart = true;
wantedOutputs = newWanted;
}

View file

@ -96,24 +96,20 @@ std::string ExtendedOutputsSpec::to_string() const
}
bool OutputsSpec::merge(const OutputsSpec & that)
OutputsSpec OutputsSpec::union_(const OutputsSpec & that) const
{
return std::visit(overloaded {
[&](OutputsSpec::All &) {
/* If we already refer to all outputs, there is nothing to do. */
return false;
[&](const OutputsSpec::All &) -> OutputsSpec {
return OutputsSpec::All { };
},
[&](OutputsSpec::Names & theseNames) {
[&](const OutputsSpec::Names & theseNames) -> OutputsSpec {
return std::visit(overloaded {
[&](const OutputsSpec::All &) {
*this = OutputsSpec::All {};
return true;
[&](const OutputsSpec::All &) -> OutputsSpec {
return OutputsSpec::All {};
},
[&](const OutputsSpec::Names & thoseNames) {
bool ret = false;
for (auto & i : thoseNames)
if (theseNames.insert(i).second)
ret = true;
[&](const OutputsSpec::Names & thoseNames) -> OutputsSpec {
OutputsSpec::Names ret = theseNames;
ret.insert(thoseNames.begin(), thoseNames.end());
return ret;
},
}, that.raw());
@ -121,6 +117,30 @@ bool OutputsSpec::merge(const OutputsSpec & that)
}, raw());
}
bool OutputsSpec::isSubsetOf(const OutputsSpec & that) const
{
return std::visit(overloaded {
[&](const OutputsSpec::All &) {
return true;
},
[&](const OutputsSpec::Names & thoseNames) {
return std::visit(overloaded {
[&](const OutputsSpec::All &) {
return false;
},
[&](const OutputsSpec::Names & theseNames) {
bool ret = true;
for (auto & o : theseNames)
if (thoseNames.count(o) == 0)
ret = false;
return ret;
},
}, raw());
},
}, that.raw());
}
}
namespace nlohmann {

View file

@ -49,10 +49,11 @@ struct OutputsSpec : _OutputsSpecRaw {
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);
/* Create a new OutputsSpec which is the union of this and that. */
OutputsSpec union_(const OutputsSpec & that) const;
/* Whether this OutputsSpec is a subset of that. */
bool isSubsetOf(const OutputsSpec & outputs) const;
/* Parse a string of the form 'output1,...outputN' or
'*', returning the outputs spec. */