From 869666cb651f97cdce3a6aabf62073bfe1130cbb Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Thu, 29 Aug 2024 21:06:30 +0200 Subject: libstore: hide Worker goal factory methods this doesn't serve a great purpose yet except to confine construction of goals to the stack frame of Worker::run() and its child frames. we don't need this yet (and the goal constructors remain fully visible), but in a future change that fully removes the current worker loop we'll need some way of knowing which goals are top-level goals without passing the goals themselves around. once that's possible we can remove visible goals as a concept and rely on build result futures and a scheduler built upon them Change-Id: Ia73cdeffcfb9ba1ce9d69b702dc0bc637a4c4ce6 --- src/libstore/build/entry-points.cc | 65 +++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'src/libstore/build/entry-points.cc') diff --git a/src/libstore/build/entry-points.cc b/src/libstore/build/entry-points.cc index 1f85881fa..a5bb05b24 100644 --- a/src/libstore/build/entry-points.cc +++ b/src/libstore/build/entry-points.cc @@ -10,11 +10,12 @@ void Store::buildPaths(const std::vector & reqs, BuildMode buildMod { Worker worker(*this, evalStore ? *evalStore : *this); - Goals goals; - for (auto & br : reqs) - goals.insert(worker.makeGoal(br, buildMode)); - - worker.run(goals); + auto goals = worker.run([&](GoalFactory & gf) { + Goals goals; + for (auto & br : reqs) + goals.insert(gf.makeGoal(br, buildMode)); + return goals; + }); StringSet failed; std::shared_ptr ex; @@ -48,17 +49,17 @@ std::vector Store::buildPathsWithResults( std::shared_ptr evalStore) { Worker worker(*this, evalStore ? *evalStore : *this); - - Goals goals; std::vector> state; - for (const auto & req : reqs) { - auto goal = worker.makeGoal(req, buildMode); - goals.insert(goal); - state.push_back({req, goal}); - } - - worker.run(goals); + auto goals = worker.run([&](GoalFactory & gf) { + Goals goals; + for (const auto & req : reqs) { + auto goal = gf.makeGoal(req, buildMode); + goals.insert(goal); + state.push_back({req, goal}); + } + return goals; + }); std::vector results; @@ -72,10 +73,12 @@ BuildResult Store::buildDerivation(const StorePath & drvPath, const BasicDerivat BuildMode buildMode) { Worker worker(*this, *this); - auto goal = worker.makeBasicDerivationGoal(drvPath, drv, OutputsSpec::All {}, buildMode); try { - worker.run(Goals{goal}); + auto goals = worker.run([&](GoalFactory & gf) -> Goals { + return Goals{gf.makeBasicDerivationGoal(drvPath, drv, OutputsSpec::All{}, buildMode)}; + }); + auto goal = *goals.begin(); return goal->buildResult.restrictTo(DerivedPath::Built { .drvPath = makeConstantStorePathRef(drvPath), .outputs = OutputsSpec::All {}, @@ -95,10 +98,10 @@ void Store::ensurePath(const StorePath & path) if (isValidPath(path)) return; Worker worker(*this, *this); - GoalPtr goal = worker.makePathSubstitutionGoal(path); - Goals goals = {goal}; - worker.run(goals); + auto goals = + worker.run([&](GoalFactory & gf) { return Goals{gf.makePathSubstitutionGoal(path)}; }); + auto goal = *goals.begin(); if (goal->exitCode != Goal::ecSuccess) { if (goal->ex) { @@ -113,23 +116,27 @@ void Store::ensurePath(const StorePath & path) void Store::repairPath(const StorePath & path) { Worker worker(*this, *this); - GoalPtr goal = worker.makePathSubstitutionGoal(path, Repair); - Goals goals = {goal}; - worker.run(goals); + auto goals = worker.run([&](GoalFactory & gf) { + return Goals{gf.makePathSubstitutionGoal(path, Repair)}; + }); + auto goal = *goals.begin(); if (goal->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)) { - goals.clear(); - goals.insert(worker.makeGoal(DerivedPath::Built { - .drvPath = makeConstantStorePathRef(*info->deriver), - // FIXME: Should just build the specific output we need. - .outputs = OutputsSpec::All { }, - }, bmRepair)); - worker.run(goals); + worker.run([&](GoalFactory & gf) { + return Goals{gf.makeGoal( + DerivedPath::Built{ + .drvPath = makeConstantStorePathRef(*info->deriver), + // FIXME: Should just build the specific output we need. + .outputs = OutputsSpec::All{}, + }, + bmRepair + )}; + }); } else throw Error(worker.failingExitStatus(), "cannot repair path '%s'", printStorePath(path)); } -- cgit v1.2.3