1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 15:51:15 +02:00

Use BuildableReq for buildPaths and ensurePath

This avoids an ambiguity where the `StorePathWithOutputs { drvPath, {}
}` could mean "build `brvPath`" or "substitute `drvPath`" depending on
context.

It also brings the internals closer in line to the new CLI, by
generalizing the `Buildable` type is used there and makes that
distinction already.

In doing so, relegate `StorePathWithOutputs` to being a type just for
backwards compatibility (CLI and RPC).
This commit is contained in:
John Ericson 2021-03-02 03:50:41 +00:00
parent 32f4454b9f
commit 255d145ba7
31 changed files with 364 additions and 126 deletions

View file

@ -1,3 +1,4 @@
#include "path-with-outputs.hh"
#include "store-api.hh"
namespace nix {
@ -10,6 +11,40 @@ std::string StorePathWithOutputs::to_string(const Store & store) const
}
BuildableReq StorePathWithOutputs::toBuildableReq() const
{
if (!outputs.empty() || path.isDerivation())
return BuildableReqFromDrv { path, outputs };
else
return BuildableOpaque { path };
}
std::vector<BuildableReq> toBuildableReqs(const std::vector<StorePathWithOutputs> ss)
{
std::vector<BuildableReq> reqs;
for (auto & s : ss) reqs.push_back(s.toBuildableReq());
return reqs;
}
std::variant<StorePathWithOutputs, StorePath> StorePathWithOutputs::tryFromBuildableReq(const BuildableReq & p)
{
return std::visit(overloaded {
[&](BuildableOpaque bo) -> std::variant<StorePathWithOutputs, StorePath> {
if (bo.path.isDerivation()) {
// drv path gets interpreted as "build", not "get drv file itself"
return bo.path;
}
return StorePathWithOutputs { bo.path };
},
[&](BuildableReqFromDrv bfd) -> std::variant<StorePathWithOutputs, StorePath> {
return StorePathWithOutputs { bfd.drvPath, bfd.outputs };
},
}, p);
}
std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s)
{
size_t n = s.find("!");