Use more std::visit to prepare for new variant
N.B. not using `std::visit` for fetchurl because there is no attempt to handle all the cases (e.g. no `else`) and lambda complicates early return.
This commit is contained in:
parent
ffc18583b1
commit
fedfc913ad
3 changed files with 32 additions and 18 deletions
|
@ -283,13 +283,16 @@ string Derivation::unparse(const Store & store, bool maskOutputs,
|
||||||
if (first) first = false; else s += ',';
|
if (first) first = false; else s += ',';
|
||||||
s += '('; printUnquotedString(s, i.first);
|
s += '('; printUnquotedString(s, i.first);
|
||||||
s += ','; printUnquotedString(s, maskOutputs ? "" : store.printStorePath(i.second.path(store, name)));
|
s += ','; printUnquotedString(s, maskOutputs ? "" : store.printStorePath(i.second.path(store, name)));
|
||||||
if (auto hash = std::get_if<DerivationOutputFixed>(&i.second.output)) {
|
std::visit(overloaded {
|
||||||
s += ','; printUnquotedString(s, hash->hash.printMethodAlgo());
|
[&](DerivationOutputInputAddressed doi) {
|
||||||
s += ','; printUnquotedString(s, hash->hash.hash.to_string(Base16, false));
|
|
||||||
} else {
|
|
||||||
s += ','; printUnquotedString(s, "");
|
s += ','; printUnquotedString(s, "");
|
||||||
s += ','; printUnquotedString(s, "");
|
s += ','; printUnquotedString(s, "");
|
||||||
}
|
},
|
||||||
|
[&](DerivationOutputFixed dof) {
|
||||||
|
s += ','; printUnquotedString(s, dof.hash.printMethodAlgo());
|
||||||
|
s += ','; printUnquotedString(s, dof.hash.hash.to_string(Base16, false));
|
||||||
|
},
|
||||||
|
}, i.second.output);
|
||||||
s += ')';
|
s += ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -503,12 +506,15 @@ void writeDerivation(Sink & out, const Store & store, const BasicDerivation & dr
|
||||||
for (auto & i : drv.outputs) {
|
for (auto & i : drv.outputs) {
|
||||||
out << i.first
|
out << i.first
|
||||||
<< store.printStorePath(i.second.path(store, drv.name));
|
<< store.printStorePath(i.second.path(store, drv.name));
|
||||||
if (auto hash = std::get_if<DerivationOutputFixed>(&i.second.output)) {
|
std::visit(overloaded {
|
||||||
out << hash->hash.printMethodAlgo()
|
[&](DerivationOutputInputAddressed doi) {
|
||||||
<< hash->hash.hash.to_string(Base16, false);
|
|
||||||
} else {
|
|
||||||
out << "" << "";
|
out << "" << "";
|
||||||
}
|
},
|
||||||
|
[&](DerivationOutputFixed dof) {
|
||||||
|
out << dof.hash.printMethodAlgo()
|
||||||
|
<< dof.hash.hash.to_string(Base16, false);
|
||||||
|
},
|
||||||
|
}, i.second.output);
|
||||||
}
|
}
|
||||||
writeStorePaths(store, out, drv.inputSrcs);
|
writeStorePaths(store, out, drv.inputSrcs);
|
||||||
out << drv.platform << drv.builder << drv.args;
|
out << drv.platform << drv.builder << drv.args;
|
||||||
|
|
|
@ -25,7 +25,10 @@ struct DerivationOutputFixed
|
||||||
|
|
||||||
struct DerivationOutput
|
struct DerivationOutput
|
||||||
{
|
{
|
||||||
std::variant<DerivationOutputInputAddressed, DerivationOutputFixed> output;
|
std::variant<
|
||||||
|
DerivationOutputInputAddressed,
|
||||||
|
DerivationOutputFixed
|
||||||
|
> output;
|
||||||
StorePath path(const Store & store, std::string_view drvName) const;
|
StorePath path(const Store & store, std::string_view drvName) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -70,10 +70,15 @@ struct CmdShowDerivation : InstallablesCommand
|
||||||
for (auto & output : drv.outputs) {
|
for (auto & output : drv.outputs) {
|
||||||
auto outputObj(outputsObj.object(output.first));
|
auto outputObj(outputsObj.object(output.first));
|
||||||
outputObj.attr("path", store->printStorePath(output.second.path(*store, drv.name)));
|
outputObj.attr("path", store->printStorePath(output.second.path(*store, drv.name)));
|
||||||
if (auto hash = std::get_if<DerivationOutputFixed>(&output.second.output)) {
|
|
||||||
outputObj.attr("hashAlgo", hash->hash.printMethodAlgo());
|
std::visit(overloaded {
|
||||||
outputObj.attr("hash", hash->hash.hash.to_string(Base16, false));
|
[&](DerivationOutputInputAddressed doi) {
|
||||||
}
|
},
|
||||||
|
[&](DerivationOutputFixed dof) {
|
||||||
|
outputObj.attr("hashAlgo", dof.hash.printMethodAlgo());
|
||||||
|
outputObj.attr("hash", dof.hash.hash.to_string(Base16, false));
|
||||||
|
},
|
||||||
|
}, output.second.output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue