aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/build/entry-points.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/build/entry-points.cc')
-rw-r--r--src/libstore/build/entry-points.cc78
1 files changed, 31 insertions, 47 deletions
diff --git a/src/libstore/build/entry-points.cc b/src/libstore/build/entry-points.cc
index 808179a4d..36ad35be0 100644
--- a/src/libstore/build/entry-points.cc
+++ b/src/libstore/build/entry-points.cc
@@ -6,26 +6,20 @@
namespace nix {
-static auto runWorker(Worker & worker, auto mkGoals)
-{
- return worker.run(mkGoals);
-}
-
void Store::buildPaths(const std::vector<DerivedPath> & reqs, BuildMode buildMode, std::shared_ptr<Store> evalStore)
{
auto aio = kj::setupAsyncIo();
- Worker worker(*this, evalStore ? *evalStore : *this, aio);
- auto goals = runWorker(worker, [&](GoalFactory & gf) {
+ auto results = processGoals(*this, evalStore ? *evalStore : *this, aio, [&](GoalFactory & gf) {
Worker::Targets goals;
for (auto & br : reqs)
- goals.emplace(gf.makeGoal(br, buildMode));
+ goals.emplace_back(gf.makeGoal(br, buildMode));
return goals;
- });
+ }).wait(aio.waitScope).value();
StringSet failed;
std::shared_ptr<Error> ex;
- for (auto & [i, result] : goals) {
+ for (auto & [i, result] : results.goals) {
if (result.ex) {
if (ex)
logError(result.ex->info());
@@ -33,19 +27,17 @@ void Store::buildPaths(const std::vector<DerivedPath> & reqs, BuildMode buildMod
ex = result.ex;
}
if (result.exitCode != Goal::ecSuccess) {
- if (auto i2 = dynamic_cast<DerivationGoal *>(i.get()))
- failed.insert(printStorePath(i2->drvPath));
- else if (auto i2 = dynamic_cast<PathSubstitutionGoal *>(i.get()))
- failed.insert(printStorePath(i2->storePath));
+ if (result.storePath)
+ failed.insert(printStorePath(*result.storePath));
}
}
if (failed.size() == 1 && ex) {
- ex->withExitStatus(worker.failingExitStatus());
+ ex->withExitStatus(results.failingExitStatus);
throw std::move(*ex);
} else if (!failed.empty()) {
if (ex) logError(ex->info());
- throw Error(worker.failingExitStatus(), "build of %s failed", concatStringsSep(", ", quoteStrings(failed)));
+ throw Error(results.failingExitStatus, "build of %s failed", concatStringsSep(", ", quoteStrings(failed)));
}
}
@@ -55,24 +47,19 @@ std::vector<KeyedBuildResult> Store::buildPathsWithResults(
std::shared_ptr<Store> evalStore)
{
auto aio = kj::setupAsyncIo();
- Worker worker(*this, evalStore ? *evalStore : *this, aio);
- std::vector<std::pair<const DerivedPath &, GoalPtr>> state;
-
- auto goals = runWorker(worker, [&](GoalFactory & gf) {
+ auto goals = processGoals(*this, evalStore ? *evalStore : *this, aio, [&](GoalFactory & gf) {
Worker::Targets goals;
for (const auto & req : reqs) {
- auto goal = gf.makeGoal(req, buildMode);
- state.push_back({req, goal.first});
- goals.emplace(std::move(goal));
+ goals.emplace_back(gf.makeGoal(req, buildMode));
}
return goals;
- });
+ }).wait(aio.waitScope).value().goals;
std::vector<KeyedBuildResult> results;
- for (auto & [req, goalPtr] : state)
- results.emplace_back(goals[goalPtr].result.restrictTo(req));
+ for (auto && [goalIdx, req] : enumerate(reqs))
+ results.emplace_back(goals[goalIdx].result.restrictTo(req));
return results;
}
@@ -81,15 +68,14 @@ BuildResult Store::buildDerivation(const StorePath & drvPath, const BasicDerivat
BuildMode buildMode)
{
auto aio = kj::setupAsyncIo();
- Worker worker(*this, *this, aio);
try {
- auto goals = runWorker(worker, [&](GoalFactory & gf) {
+ auto results = processGoals(*this, *this, aio, [&](GoalFactory & gf) {
Worker::Targets goals;
- goals.emplace(gf.makeBasicDerivationGoal(drvPath, drv, OutputsSpec::All{}, buildMode));
+ goals.emplace_back(gf.makeBasicDerivationGoal(drvPath, drv, OutputsSpec::All{}, buildMode));
return goals;
- });
- auto [goal, result] = *goals.begin();
+ }).wait(aio.waitScope).value();
+ auto & result = results.goals.begin()->second;
return result.result.restrictTo(DerivedPath::Built {
.drvPath = makeConstantStorePathRef(drvPath),
.outputs = OutputsSpec::All {},
@@ -109,21 +95,20 @@ void Store::ensurePath(const StorePath & path)
if (isValidPath(path)) return;
auto aio = kj::setupAsyncIo();
- Worker worker(*this, *this, aio);
- auto goals = runWorker(worker, [&](GoalFactory & gf) {
+ auto results = processGoals(*this, *this, aio, [&](GoalFactory & gf) {
Worker::Targets goals;
- goals.emplace(gf.makePathSubstitutionGoal(path));
+ goals.emplace_back(gf.makePathSubstitutionGoal(path));
return goals;
- });
- auto [goal, result] = *goals.begin();
+ }).wait(aio.waitScope).value();
+ auto & result = results.goals.begin()->second;
if (result.exitCode != Goal::ecSuccess) {
if (result.ex) {
- result.ex->withExitStatus(worker.failingExitStatus());
+ result.ex->withExitStatus(results.failingExitStatus);
throw std::move(*result.ex);
} else
- throw Error(worker.failingExitStatus(), "path '%s' does not exist and cannot be created", printStorePath(path));
+ throw Error(results.failingExitStatus, "path '%s' does not exist and cannot be created", printStorePath(path));
}
}
@@ -131,23 +116,22 @@ void Store::ensurePath(const StorePath & path)
void Store::repairPath(const StorePath & path)
{
auto aio = kj::setupAsyncIo();
- Worker worker(*this, *this, aio);
- auto goals = runWorker(worker, [&](GoalFactory & gf) {
+ auto results = processGoals(*this, *this, aio, [&](GoalFactory & gf) {
Worker::Targets goals;
- goals.emplace(gf.makePathSubstitutionGoal(path, Repair));
+ goals.emplace_back(gf.makePathSubstitutionGoal(path, Repair));
return goals;
- });
- auto [goal, result] = *goals.begin();
+ }).wait(aio.waitScope).value();
+ auto & result = results.goals.begin()->second;
if (result.exitCode != Goal::ecSuccess) {
/* Since substituting the path didn't work, if we have a valid
deriver, then rebuild the deriver. */
auto info = queryPathInfo(path);
if (info->deriver && isValidPath(*info->deriver)) {
- worker.run([&](GoalFactory & gf) {
+ processGoals(*this, *this, aio, [&](GoalFactory & gf) {
Worker::Targets goals;
- goals.emplace(gf.makeGoal(
+ goals.emplace_back(gf.makeGoal(
DerivedPath::Built{
.drvPath = makeConstantStorePathRef(*info->deriver),
// FIXME: Should just build the specific output we need.
@@ -156,9 +140,9 @@ void Store::repairPath(const StorePath & path)
bmRepair
));
return goals;
- });
+ }).wait(aio.waitScope).value();
} else
- throw Error(worker.failingExitStatus(), "cannot repair path '%s'", printStorePath(path));
+ throw Error(results.failingExitStatus, "cannot repair path '%s'", printStorePath(path));
}
}