aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/build/worker.hh
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-08-29 21:06:30 +0200
committereldritch horrors <pennae@lix.systems>2024-08-30 10:18:28 +0000
commit869666cb651f97cdce3a6aabf62073bfe1130cbb (patch)
treed9c2c67742d15eca4e44b6b6da5a5bb09fa2d94f /src/libstore/build/worker.hh
parenta5c1e73fa8e004a93e37254a3582ba91048c4550 (diff)
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
Diffstat (limited to 'src/libstore/build/worker.hh')
-rw-r--r--src/libstore/build/worker.hh63
1 files changed, 55 insertions, 8 deletions
diff --git a/src/libstore/build/worker.hh b/src/libstore/build/worker.hh
index 360366f8d..3fbf457fe 100644
--- a/src/libstore/build/worker.hh
+++ b/src/libstore/build/worker.hh
@@ -40,10 +40,57 @@ struct Child
/* Forward definition. */
struct HookInstance;
+class GoalFactory
+{
+public:
+ virtual std::shared_ptr<DerivationGoal> makeDerivationGoal(
+ const StorePath & drvPath, const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal
+ ) = 0;
+ virtual std::shared_ptr<DerivationGoal> makeBasicDerivationGoal(
+ const StorePath & drvPath,
+ const BasicDerivation & drv,
+ const OutputsSpec & wantedOutputs,
+ BuildMode buildMode = bmNormal
+ ) = 0;
+
+ /**
+ * @ref SubstitutionGoal "substitution goal"
+ */
+ virtual std::shared_ptr<PathSubstitutionGoal> makePathSubstitutionGoal(
+ const StorePath & storePath,
+ RepairFlag repair = NoRepair,
+ std::optional<ContentAddress> ca = std::nullopt
+ ) = 0;
+ virtual std::shared_ptr<DrvOutputSubstitutionGoal> makeDrvOutputSubstitutionGoal(
+ const DrvOutput & id,
+ RepairFlag repair = NoRepair,
+ std::optional<ContentAddress> ca = std::nullopt
+ ) = 0;
+
+ /**
+ * Make a goal corresponding to the `DerivedPath`.
+ *
+ * It will be a `DerivationGoal` for a `DerivedPath::Built` or
+ * a `SubstitutionGoal` for a `DerivedPath::Opaque`.
+ */
+ virtual GoalPtr makeGoal(const DerivedPath & req, BuildMode buildMode = bmNormal) = 0;
+};
+
+// elaborate hoax to let goals access factory methods while hiding them from the public
+class WorkerBase : protected GoalFactory
+{
+ friend struct DerivationGoal;
+ friend struct PathSubstitutionGoal;
+ friend class DrvOutputSubstitutionGoal;
+
+protected:
+ GoalFactory & goalFactory() { return *this; }
+};
+
/**
* The worker class.
*/
-class Worker
+class Worker : public WorkerBase
{
private:
@@ -215,19 +262,18 @@ private:
std::shared_ptr<DerivationGoal> makeDerivationGoalCommon(
const StorePath & drvPath, const OutputsSpec & wantedOutputs,
std::function<std::shared_ptr<DerivationGoal>()> mkDrvGoal);
-public:
std::shared_ptr<DerivationGoal> makeDerivationGoal(
const StorePath & drvPath,
- const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal);
+ const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal) override;
std::shared_ptr<DerivationGoal> makeBasicDerivationGoal(
const StorePath & drvPath, const BasicDerivation & drv,
- const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal);
+ const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal) override;
/**
* @ref SubstitutionGoal "substitution goal"
*/
- std::shared_ptr<PathSubstitutionGoal> makePathSubstitutionGoal(const StorePath & storePath, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
- std::shared_ptr<DrvOutputSubstitutionGoal> makeDrvOutputSubstitutionGoal(const DrvOutput & id, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
+ std::shared_ptr<PathSubstitutionGoal> makePathSubstitutionGoal(const StorePath & storePath, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt) override;
+ std::shared_ptr<DrvOutputSubstitutionGoal> makeDrvOutputSubstitutionGoal(const DrvOutput & id, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt) override;
/**
* Make a goal corresponding to the `DerivedPath`.
@@ -235,8 +281,9 @@ public:
* It will be a `DerivationGoal` for a `DerivedPath::Built` or
* a `SubstitutionGoal` for a `DerivedPath::Opaque`.
*/
- GoalPtr makeGoal(const DerivedPath & req, BuildMode buildMode = bmNormal);
+ GoalPtr makeGoal(const DerivedPath & req, BuildMode buildMode = bmNormal) override;
+public:
/**
* Unregisters a running child process.
*/
@@ -245,7 +292,7 @@ public:
/**
* Loop until the specified top-level goals have finished.
*/
- void run(const Goals & topGoals);
+ Goals run(std::function<Goals (GoalFactory &)> req);
/***
* The exit status in case of failure.