mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 00:06:16 +02:00
"newtype" BuildableReq
This makes for better types errors and allows us to give it methods.
This commit is contained in:
parent
4fe41c6db3
commit
9dfb97c987
8 changed files with 24 additions and 16 deletions
|
@ -73,7 +73,7 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath,
|
||||||
state = &DerivationGoal::getDerivation;
|
state = &DerivationGoal::getDerivation;
|
||||||
name = fmt(
|
name = fmt(
|
||||||
"building of '%s' from .drv file",
|
"building of '%s' from .drv file",
|
||||||
to_string(worker.store, BuildableReqFromDrv { drvPath, wantedOutputs }));
|
BuildableReqFromDrv { drvPath, wantedOutputs }.to_string(worker.store));
|
||||||
trace("created");
|
trace("created");
|
||||||
|
|
||||||
mcExpectedBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.expectedBuilds);
|
mcExpectedBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.expectedBuilds);
|
||||||
|
@ -94,7 +94,7 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation
|
||||||
state = &DerivationGoal::haveDerivation;
|
state = &DerivationGoal::haveDerivation;
|
||||||
name = fmt(
|
name = fmt(
|
||||||
"building of '%s' from in-memory derivation",
|
"building of '%s' from in-memory derivation",
|
||||||
to_string(worker.store, BuildableReqFromDrv { drvPath, drv.outputNames() }));
|
BuildableReqFromDrv { drvPath, drv.outputNames() }.to_string(worker.store));
|
||||||
trace("created");
|
trace("created");
|
||||||
|
|
||||||
mcExpectedBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.expectedBuilds);
|
mcExpectedBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.expectedBuilds);
|
||||||
|
|
|
@ -19,7 +19,7 @@ void Store::buildPaths(const std::vector<BuildableReq> & reqs, BuildMode buildMo
|
||||||
[&](BuildableOpaque bo) {
|
[&](BuildableOpaque bo) {
|
||||||
goals.insert(worker.makePathSubstitutionGoal(bo.path, buildMode == bmRepair ? Repair : NoRepair));
|
goals.insert(worker.makePathSubstitutionGoal(bo.path, buildMode == bmRepair ? Repair : NoRepair));
|
||||||
},
|
},
|
||||||
}, br);
|
}, br.raw());
|
||||||
}
|
}
|
||||||
|
|
||||||
worker.run(goals);
|
worker.run(goals);
|
||||||
|
|
|
@ -1200,7 +1200,7 @@ static StorePath pathPartOfReq(const BuildableReq & req)
|
||||||
[&](BuildableReqFromDrv bfd) {
|
[&](BuildableReqFromDrv bfd) {
|
||||||
return bfd.drvPath;
|
return bfd.drvPath;
|
||||||
},
|
},
|
||||||
}, req);
|
}, req.raw());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1340,7 +1340,7 @@ struct RestrictedStore : public virtual RestrictedStoreConfig, public virtual Lo
|
||||||
|
|
||||||
for (auto & req : paths) {
|
for (auto & req : paths) {
|
||||||
if (!goal.isAllowed(req))
|
if (!goal.isAllowed(req))
|
||||||
throw InvalidPath("cannot build '%s' in recursive Nix because path is unknown", to_string(*next, req));
|
throw InvalidPath("cannot build '%s' in recursive Nix because path is unknown", req.to_string(*next));
|
||||||
}
|
}
|
||||||
|
|
||||||
next->buildPaths(paths, buildMode);
|
next->buildPaths(paths, buildMode);
|
||||||
|
|
|
@ -41,11 +41,11 @@ std::string BuildableReqFromDrv::to_string(const Store & store) const {
|
||||||
+ (outputs.empty() ? std::string { "*" } : concatStringsSep(",", outputs));
|
+ (outputs.empty() ? std::string { "*" } : concatStringsSep(",", outputs));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_string(const Store & store, const BuildableReq & req)
|
std::string BuildableReq::to_string(const Store & store) const
|
||||||
{
|
{
|
||||||
return std::visit(
|
return std::visit(
|
||||||
[&](const auto & req) { return req.to_string(store); },
|
[&](const auto & req) { return req.to_string(store); },
|
||||||
req);
|
this->raw());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ BuildableReqFromDrv BuildableReqFromDrv::parse(const Store & store, std::string_
|
||||||
return {drvPath, outputs};
|
return {drvPath, outputs};
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildableReq parseBuildableReq(const Store & store, std::string_view s)
|
BuildableReq BuildableReq::parse(const Store & store, std::string_view s)
|
||||||
{
|
{
|
||||||
size_t n = s.find("!");
|
size_t n = s.find("!");
|
||||||
return n == s.npos
|
return n == s.npos
|
||||||
|
|
|
@ -28,14 +28,22 @@ struct BuildableReqFromDrv {
|
||||||
static BuildableReqFromDrv parse(const Store & store, std::string_view);
|
static BuildableReqFromDrv parse(const Store & store, std::string_view);
|
||||||
};
|
};
|
||||||
|
|
||||||
using BuildableReq = std::variant<
|
using _BuildableReqRaw = std::variant<
|
||||||
BuildableOpaque,
|
BuildableOpaque,
|
||||||
BuildableReqFromDrv
|
BuildableReqFromDrv
|
||||||
>;
|
>;
|
||||||
|
|
||||||
std::string to_string(const Store & store, const BuildableReq &);
|
struct BuildableReq : _BuildableReqRaw {
|
||||||
|
using Raw = _BuildableReqRaw;
|
||||||
|
using Raw::Raw;
|
||||||
|
|
||||||
BuildableReq parseBuildableReq(const Store & store, std::string_view);
|
inline const Raw & raw() const {
|
||||||
|
return static_cast<const Raw &>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string to_string(const Store & store) const;
|
||||||
|
static BuildableReq parse(const Store & store, std::string_view);
|
||||||
|
};
|
||||||
|
|
||||||
struct BuildableFromDrv {
|
struct BuildableFromDrv {
|
||||||
StorePath drvPath;
|
StorePath drvPath;
|
||||||
|
|
|
@ -187,7 +187,7 @@ void Store::queryMissing(const std::vector<BuildableReq> & targets,
|
||||||
|
|
||||||
{
|
{
|
||||||
auto state(state_.lock());
|
auto state(state_.lock());
|
||||||
if (!state->done.insert(to_string(*this, req)).second) return;
|
if (!state->done.insert(req.to_string(*this)).second) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::visit(overloaded {
|
std::visit(overloaded {
|
||||||
|
@ -250,7 +250,7 @@ void Store::queryMissing(const std::vector<BuildableReq> & targets,
|
||||||
for (auto & ref : info->second.references)
|
for (auto & ref : info->second.references)
|
||||||
pool.enqueue(std::bind(doPath, BuildableOpaque { ref }));
|
pool.enqueue(std::bind(doPath, BuildableOpaque { ref }));
|
||||||
},
|
},
|
||||||
}, req);
|
}, req.raw());
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto & path : targets)
|
for (auto & path : targets)
|
||||||
|
|
|
@ -41,7 +41,7 @@ std::variant<StorePathWithOutputs, StorePath> StorePathWithOutputs::tryFromBuild
|
||||||
[&](BuildableReqFromDrv bfd) -> std::variant<StorePathWithOutputs, StorePath> {
|
[&](BuildableReqFromDrv bfd) -> std::variant<StorePathWithOutputs, StorePath> {
|
||||||
return StorePathWithOutputs { bfd.drvPath, bfd.outputs };
|
return StorePathWithOutputs { bfd.drvPath, bfd.outputs };
|
||||||
},
|
},
|
||||||
}, p);
|
}, p.raw());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,12 +55,12 @@ void write(const Store & store, Sink & out, const ContentAddress & ca)
|
||||||
BuildableReq read(const Store & store, Source & from, Phantom<BuildableReq> _)
|
BuildableReq read(const Store & store, Source & from, Phantom<BuildableReq> _)
|
||||||
{
|
{
|
||||||
auto s = readString(from);
|
auto s = readString(from);
|
||||||
return parseBuildableReq(store, s);
|
return BuildableReq::parse(store, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(const Store & store, Sink & out, const BuildableReq & req)
|
void write(const Store & store, Sink & out, const BuildableReq & req)
|
||||||
{
|
{
|
||||||
out << to_string(store, req);
|
out << req.to_string(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue