mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 20:16:03 +01:00
Merge pull request #13750 from obsidiansystems/simplify-derivation-goal-0
Simplify `DerivationGoal` in two ways
This commit is contained in:
commit
dfcbe70564
2 changed files with 47 additions and 61 deletions
|
|
@ -241,7 +241,17 @@ Goal::Co DerivationGoal::repairClosure()
|
||||||
that produced those outputs. */
|
that produced those outputs. */
|
||||||
|
|
||||||
/* Get the output closure. */
|
/* Get the output closure. */
|
||||||
auto outputs = queryDerivationOutputMap();
|
auto outputs = [&] {
|
||||||
|
for (auto * drvStore : {&worker.evalStore, &worker.store})
|
||||||
|
if (drvStore->isValidPath(drvPath))
|
||||||
|
return worker.store.queryDerivationOutputMap(drvPath, drvStore);
|
||||||
|
|
||||||
|
OutputPathMap res;
|
||||||
|
for (auto & [name, output] : drv->outputsAndOptPaths(worker.store))
|
||||||
|
res.insert_or_assign(name, *output.second);
|
||||||
|
return res;
|
||||||
|
}();
|
||||||
|
|
||||||
StorePathSet outputClosure;
|
StorePathSet outputClosure;
|
||||||
if (auto mPath = get(outputs, wantedOutput)) {
|
if (auto mPath = get(outputs, wantedOutput)) {
|
||||||
worker.store.computeFSClosure(*mPath, outputClosure);
|
worker.store.computeFSClosure(*mPath, outputClosure);
|
||||||
|
|
@ -304,10 +314,16 @@ Goal::Co DerivationGoal::repairClosure()
|
||||||
co_return done(BuildResult::AlreadyValid, assertPathValidity());
|
co_return done(BuildResult::AlreadyValid, assertPathValidity());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, std::optional<StorePath>> DerivationGoal::queryPartialDerivationOutputMap()
|
std::pair<bool, SingleDrvOutputs> DerivationGoal::checkPathValidity()
|
||||||
{
|
{
|
||||||
assert(!drv->type().isImpure());
|
if (drv->type().isImpure())
|
||||||
|
return {false, {}};
|
||||||
|
|
||||||
|
bool checkHash = buildMode == bmRepair;
|
||||||
|
StringSet wantedOutputsLeft{wantedOutput};
|
||||||
|
SingleDrvOutputs validOutputs;
|
||||||
|
|
||||||
|
auto partialDerivationOutputMap = [&] {
|
||||||
for (auto * drvStore : {&worker.evalStore, &worker.store})
|
for (auto * drvStore : {&worker.evalStore, &worker.store})
|
||||||
if (drvStore->isValidPath(drvPath))
|
if (drvStore->isValidPath(drvPath))
|
||||||
return worker.store.queryPartialDerivationOutputMap(drvPath, drvStore);
|
return worker.store.queryPartialDerivationOutputMap(drvPath, drvStore);
|
||||||
|
|
@ -318,33 +334,9 @@ std::map<std::string, std::optional<StorePath>> DerivationGoal::queryPartialDeri
|
||||||
for (auto & [name, output] : drv->outputs)
|
for (auto & [name, output] : drv->outputs)
|
||||||
res.insert_or_assign(name, output.path(worker.store, drv->name, name));
|
res.insert_or_assign(name, output.path(worker.store, drv->name, name));
|
||||||
return res;
|
return res;
|
||||||
}
|
}();
|
||||||
|
|
||||||
OutputPathMap DerivationGoal::queryDerivationOutputMap()
|
for (auto & i : partialDerivationOutputMap) {
|
||||||
{
|
|
||||||
assert(!drv->type().isImpure());
|
|
||||||
|
|
||||||
for (auto * drvStore : {&worker.evalStore, &worker.store})
|
|
||||||
if (drvStore->isValidPath(drvPath))
|
|
||||||
return worker.store.queryDerivationOutputMap(drvPath, drvStore);
|
|
||||||
|
|
||||||
// See comment in `DerivationGoal::queryPartialDerivationOutputMap`.
|
|
||||||
OutputPathMap res;
|
|
||||||
for (auto & [name, output] : drv->outputsAndOptPaths(worker.store))
|
|
||||||
res.insert_or_assign(name, *output.second);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::pair<bool, SingleDrvOutputs> DerivationGoal::checkPathValidity()
|
|
||||||
{
|
|
||||||
if (drv->type().isImpure())
|
|
||||||
return {false, {}};
|
|
||||||
|
|
||||||
bool checkHash = buildMode == bmRepair;
|
|
||||||
StringSet wantedOutputsLeft{wantedOutput};
|
|
||||||
SingleDrvOutputs validOutputs;
|
|
||||||
|
|
||||||
for (auto & i : queryPartialDerivationOutputMap()) {
|
|
||||||
auto initialOutput = get(initialOutputs, i.first);
|
auto initialOutput = get(initialOutputs, i.first);
|
||||||
if (!initialOutput)
|
if (!initialOutput)
|
||||||
// this is an invalid output, gets caught with (!wantedOutputsLeft.empty())
|
// this is an invalid output, gets caught with (!wantedOutputsLeft.empty())
|
||||||
|
|
|
||||||
|
|
@ -43,21 +43,6 @@ struct DerivationGoal : public Goal
|
||||||
*/
|
*/
|
||||||
OutputName wantedOutput;
|
OutputName wantedOutput;
|
||||||
|
|
||||||
/**
|
|
||||||
* The derivation stored at drvPath.
|
|
||||||
*/
|
|
||||||
std::unique_ptr<Derivation> drv;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The remainder is state held during the build.
|
|
||||||
*/
|
|
||||||
|
|
||||||
std::map<std::string, InitialOutput> initialOutputs;
|
|
||||||
|
|
||||||
BuildMode buildMode;
|
|
||||||
|
|
||||||
std::unique_ptr<MaintainCount<uint64_t>> mcExpectedBuilds;
|
|
||||||
|
|
||||||
DerivationGoal(
|
DerivationGoal(
|
||||||
const StorePath & drvPath,
|
const StorePath & drvPath,
|
||||||
const Derivation & drv,
|
const Derivation & drv,
|
||||||
|
|
@ -73,19 +58,33 @@ struct DerivationGoal : public Goal
|
||||||
|
|
||||||
std::string key() override;
|
std::string key() override;
|
||||||
|
|
||||||
|
JobCategory jobCategory() const override
|
||||||
|
{
|
||||||
|
return JobCategory::Administration;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The derivation stored at drvPath.
|
||||||
|
*/
|
||||||
|
std::unique_ptr<Derivation> drv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The remainder is state held during the build.
|
||||||
|
*/
|
||||||
|
|
||||||
|
std::map<std::string, InitialOutput> initialOutputs;
|
||||||
|
|
||||||
|
BuildMode buildMode;
|
||||||
|
|
||||||
|
std::unique_ptr<MaintainCount<uint64_t>> mcExpectedBuilds;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The states.
|
* The states.
|
||||||
*/
|
*/
|
||||||
Co haveDerivation();
|
Co haveDerivation();
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrappers around the corresponding Store methods that first consult the
|
|
||||||
* derivation. This is currently needed because when there is no drv file
|
|
||||||
* there also is no DB entry.
|
|
||||||
*/
|
|
||||||
std::map<std::string, std::optional<StorePath>> queryPartialDerivationOutputMap();
|
|
||||||
OutputPathMap queryDerivationOutputMap();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update 'initialOutputs' to determine the current status of the
|
* Update 'initialOutputs' to determine the current status of the
|
||||||
* outputs of the derivation. Also returns a Boolean denoting
|
* outputs of the derivation. Also returns a Boolean denoting
|
||||||
|
|
@ -103,11 +102,6 @@ struct DerivationGoal : public Goal
|
||||||
Co repairClosure();
|
Co repairClosure();
|
||||||
|
|
||||||
Done done(BuildResult::Status status, SingleDrvOutputs builtOutputs = {}, std::optional<Error> ex = {});
|
Done done(BuildResult::Status status, SingleDrvOutputs builtOutputs = {}, std::optional<Error> ex = {});
|
||||||
|
|
||||||
JobCategory jobCategory() const override
|
|
||||||
{
|
|
||||||
return JobCategory::Administration;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue