mirror of
https://github.com/NixOS/nix.git
synced 2025-11-22 18:29:36 +01:00
Merge pull request #14600 from edef1c/push-tvmtozyqsmno
Simplify `Derivation::type()`
This commit is contained in:
commit
5caebab63a
1 changed files with 46 additions and 53 deletions
|
|
@ -13,6 +13,7 @@
|
||||||
#include <boost/container/small_vector.hpp>
|
#include <boost/container/small_vector.hpp>
|
||||||
#include <boost/unordered/concurrent_flat_map.hpp>
|
#include <boost/unordered/concurrent_flat_map.hpp>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
@ -791,71 +792,63 @@ std::string outputPathName(std::string_view drvName, OutputNameView outputName)
|
||||||
|
|
||||||
DerivationType BasicDerivation::type() const
|
DerivationType BasicDerivation::type() const
|
||||||
{
|
{
|
||||||
std::set<std::string_view> inputAddressedOutputs, fixedCAOutputs, floatingCAOutputs, deferredIAOutputs,
|
|
||||||
impureOutputs;
|
|
||||||
std::optional<HashAlgorithm> floatingHashAlgo;
|
std::optional<HashAlgorithm> floatingHashAlgo;
|
||||||
|
std::optional<DerivationType> ty;
|
||||||
|
|
||||||
|
auto decide = [&](DerivationType newTy) {
|
||||||
|
if (!ty)
|
||||||
|
ty = newTy;
|
||||||
|
else if (ty.value() != newTy)
|
||||||
|
throw Error("can't mix derivation output types");
|
||||||
|
else if (ty.value() == DerivationType::ContentAddressed{.sandboxed = false, .fixed = true})
|
||||||
|
// FIXME: Experimental feature?
|
||||||
|
throw Error("only one fixed output is allowed for now");
|
||||||
|
};
|
||||||
|
|
||||||
for (auto & i : outputs) {
|
for (auto & i : outputs) {
|
||||||
std::visit(
|
std::visit(
|
||||||
overloaded{
|
overloaded{
|
||||||
[&](const DerivationOutput::InputAddressed &) { inputAddressedOutputs.insert(i.first); },
|
[&](const DerivationOutput::InputAddressed &) {
|
||||||
[&](const DerivationOutput::CAFixed &) { fixedCAOutputs.insert(i.first); },
|
decide(
|
||||||
[&](const DerivationOutput::CAFloating & dof) {
|
DerivationType::InputAddressed{
|
||||||
floatingCAOutputs.insert(i.first);
|
.deferred = false,
|
||||||
if (!floatingHashAlgo) {
|
});
|
||||||
floatingHashAlgo = dof.hashAlgo;
|
|
||||||
} else {
|
|
||||||
if (*floatingHashAlgo != dof.hashAlgo)
|
|
||||||
throw Error("all floating outputs must use the same hash algorithm");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[&](const DerivationOutput::Deferred &) { deferredIAOutputs.insert(i.first); },
|
[&](const DerivationOutput::CAFixed &) {
|
||||||
[&](const DerivationOutput::Impure &) { impureOutputs.insert(i.first); },
|
decide(
|
||||||
|
DerivationType::ContentAddressed{
|
||||||
|
.sandboxed = false,
|
||||||
|
.fixed = true,
|
||||||
|
});
|
||||||
|
if (i.first != "out"sv)
|
||||||
|
throw Error("single fixed output must be named \"out\"");
|
||||||
|
},
|
||||||
|
[&](const DerivationOutput::CAFloating & dof) {
|
||||||
|
decide(
|
||||||
|
DerivationType::ContentAddressed{
|
||||||
|
.sandboxed = true,
|
||||||
|
.fixed = false,
|
||||||
|
});
|
||||||
|
if (!floatingHashAlgo)
|
||||||
|
floatingHashAlgo = dof.hashAlgo;
|
||||||
|
else if (*floatingHashAlgo != dof.hashAlgo)
|
||||||
|
throw Error("all floating outputs must use the same hash algorithm");
|
||||||
|
},
|
||||||
|
[&](const DerivationOutput::Deferred &) {
|
||||||
|
decide(
|
||||||
|
DerivationType::InputAddressed{
|
||||||
|
.deferred = true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[&](const DerivationOutput::Impure &) { decide(DerivationType::Impure{}); },
|
||||||
},
|
},
|
||||||
i.second.raw);
|
i.second.raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputAddressedOutputs.empty() && fixedCAOutputs.empty() && floatingCAOutputs.empty()
|
if (!ty)
|
||||||
&& deferredIAOutputs.empty() && impureOutputs.empty())
|
|
||||||
throw Error("must have at least one output");
|
throw Error("must have at least one output");
|
||||||
|
|
||||||
if (!inputAddressedOutputs.empty() && fixedCAOutputs.empty() && floatingCAOutputs.empty()
|
return ty.value();
|
||||||
&& deferredIAOutputs.empty() && impureOutputs.empty())
|
|
||||||
return DerivationType::InputAddressed{
|
|
||||||
.deferred = false,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (inputAddressedOutputs.empty() && !fixedCAOutputs.empty() && floatingCAOutputs.empty()
|
|
||||||
&& deferredIAOutputs.empty() && impureOutputs.empty()) {
|
|
||||||
if (fixedCAOutputs.size() > 1)
|
|
||||||
// FIXME: Experimental feature?
|
|
||||||
throw Error("only one fixed output is allowed for now");
|
|
||||||
if (*fixedCAOutputs.begin() != "out"sv)
|
|
||||||
throw Error("single fixed output must be named \"out\"");
|
|
||||||
return DerivationType::ContentAddressed{
|
|
||||||
.sandboxed = false,
|
|
||||||
.fixed = true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputAddressedOutputs.empty() && fixedCAOutputs.empty() && !floatingCAOutputs.empty()
|
|
||||||
&& deferredIAOutputs.empty() && impureOutputs.empty())
|
|
||||||
return DerivationType::ContentAddressed{
|
|
||||||
.sandboxed = true,
|
|
||||||
.fixed = false,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (inputAddressedOutputs.empty() && fixedCAOutputs.empty() && floatingCAOutputs.empty()
|
|
||||||
&& !deferredIAOutputs.empty() && impureOutputs.empty())
|
|
||||||
return DerivationType::InputAddressed{
|
|
||||||
.deferred = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (inputAddressedOutputs.empty() && fixedCAOutputs.empty() && floatingCAOutputs.empty()
|
|
||||||
&& deferredIAOutputs.empty() && !impureOutputs.empty())
|
|
||||||
return DerivationType::Impure{};
|
|
||||||
|
|
||||||
throw Error("can't mix derivation output types");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DrvHashes drvHashes;
|
DrvHashes drvHashes;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue