Add DerivationType::CAFloating

This commit is contained in:
John Ericson 2020-07-17 19:55:41 +00:00
parent bbc633c98c
commit 6756cecfcf
2 changed files with 22 additions and 7 deletions

View file

@ -28,6 +28,7 @@ bool derivationIsCA(DerivationType dt) {
switch (dt) { switch (dt) {
case DerivationType::Regular: return false; case DerivationType::Regular: return false;
case DerivationType::CAFixed: return true; case DerivationType::CAFixed: return true;
case DerivationType::CAFloating: return true;
}; };
// Since enums can have non-variant values, but making a `default:` would // Since enums can have non-variant values, but making a `default:` would
// disable exhaustiveness warnings. // disable exhaustiveness warnings.
@ -38,6 +39,7 @@ bool derivationIsFixed(DerivationType dt) {
switch (dt) { switch (dt) {
case DerivationType::Regular: return false; case DerivationType::Regular: return false;
case DerivationType::CAFixed: return true; case DerivationType::CAFixed: return true;
case DerivationType::CAFloating: return false;
}; };
abort(); abort();
} }
@ -46,6 +48,7 @@ bool derivationIsImpure(DerivationType dt) {
switch (dt) { switch (dt) {
case DerivationType::Regular: return false; case DerivationType::Regular: return false;
case DerivationType::CAFixed: return true; case DerivationType::CAFixed: return true;
case DerivationType::CAFloating: return false;
}; };
abort(); abort();
} }
@ -387,7 +390,8 @@ bool isDerivation(const string & fileName)
DerivationType BasicDerivation::type() const DerivationType BasicDerivation::type() const
{ {
std::set<std::string_view> inputAddressedOutputs, fixedCAOutputs; std::set<std::string_view> inputAddressedOutputs, fixedCAOutputs, floatingCAOutputs;
std::optional<HashType> floatingHashType;
for (auto & i : outputs) { for (auto & i : outputs) {
std::visit(overloaded { std::visit(overloaded {
[&](DerivationOutputInputAddressed _) { [&](DerivationOutputInputAddressed _) {
@ -396,23 +400,31 @@ DerivationType BasicDerivation::type() const
[&](DerivationOutputFixed _) { [&](DerivationOutputFixed _) {
fixedCAOutputs.insert(i.first); fixedCAOutputs.insert(i.first);
}, },
[&](DerivationOutputFloating _) { [&](DerivationOutputFloating dof) {
throw Error("Floating CA output derivations are not yet implemented"); floatingCAOutputs.insert(i.first);
if (!floatingHashType) {
floatingHashType = dof.hashType;
} else {
if (*floatingHashType != dof.hashType)
throw Error("All floating outputs must use the same hash type");
}
}, },
}, i.second.output); }, i.second.output);
} }
if (inputAddressedOutputs.empty() && fixedCAOutputs.empty()) { if (inputAddressedOutputs.empty() && fixedCAOutputs.empty() && floatingCAOutputs.empty()) {
throw Error("Must have at least one output"); throw Error("Must have at least one output");
} else if (! inputAddressedOutputs.empty() && fixedCAOutputs.empty()) { } else if (! inputAddressedOutputs.empty() && fixedCAOutputs.empty() && floatingCAOutputs.empty()) {
return DerivationType::Regular; return DerivationType::Regular;
} else if (inputAddressedOutputs.empty() && ! fixedCAOutputs.empty()) { } else if (inputAddressedOutputs.empty() && ! fixedCAOutputs.empty() && floatingCAOutputs.empty()) {
if (fixedCAOutputs.size() > 1) if (fixedCAOutputs.size() > 1)
// FIXME: Experimental feature? // FIXME: Experimental feature?
throw Error("Only one fixed output is allowed for now"); throw Error("Only one fixed output is allowed for now");
if (*fixedCAOutputs.begin() != "out") if (*fixedCAOutputs.begin() != "out")
throw Error("Single fixed output must be named \"out\""); throw Error("Single fixed output must be named \"out\"");
return DerivationType::CAFixed; return DerivationType::CAFixed;
} else if (inputAddressedOutputs.empty() && fixedCAOutputs.empty() && ! floatingCAOutputs.empty()) {
return DerivationType::CAFloating;
} else { } else {
throw Error("Can't mix derivation output types"); throw Error("Can't mix derivation output types");
} }
@ -464,6 +476,8 @@ DrvHashModulo hashDerivationModulo(Store & store, const Derivation & drv, bool m
{ {
/* Return a fixed hash for fixed-output derivations. */ /* Return a fixed hash for fixed-output derivations. */
switch (drv.type()) { switch (drv.type()) {
case DerivationType::CAFloating:
throw Error("Regular input-addressed derivations are not yet allowed to depend on CA derivations");
case DerivationType::CAFixed: { case DerivationType::CAFixed: {
std::map<std::string, Hash> outputHashes; std::map<std::string, Hash> outputHashes;
for (const auto & i : drv.outputs) { for (const auto & i : drv.outputs) {
@ -476,7 +490,7 @@ DrvHashModulo hashDerivationModulo(Store & store, const Derivation & drv, bool m
} }
return outputHashes; return outputHashes;
} }
default: case DerivationType::Regular:
break; break;
} }

View file

@ -61,6 +61,7 @@ typedef std::map<string, string> StringPairs;
enum struct DerivationType : uint8_t { enum struct DerivationType : uint8_t {
Regular, Regular,
CAFixed, CAFixed,
CAFloating,
}; };
/* Do the outputs of the derivation have paths calculated from their content, /* Do the outputs of the derivation have paths calculated from their content,