diff options
Diffstat (limited to 'src/libstore/build/worker.hh')
-rw-r--r-- | src/libstore/build/worker.hh | 83 |
1 files changed, 24 insertions, 59 deletions
diff --git a/src/libstore/build/worker.hh b/src/libstore/build/worker.hh index d6cde8384..1a913ca16 100644 --- a/src/libstore/build/worker.hh +++ b/src/libstore/build/worker.hh @@ -30,10 +30,12 @@ struct HookInstance; class GoalFactory { public: - virtual std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<void>> makeDerivationGoal( + virtual std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>> + makeDerivationGoal( const StorePath & drvPath, const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal ) = 0; - virtual std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<void>> makeBasicDerivationGoal( + virtual std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>> + makeBasicDerivationGoal( const StorePath & drvPath, const BasicDerivation & drv, const OutputsSpec & wantedOutputs, @@ -43,13 +45,13 @@ public: /** * @ref SubstitutionGoal "substitution goal" */ - virtual std::pair<std::shared_ptr<PathSubstitutionGoal>, kj::Promise<void>> + virtual std::pair<std::shared_ptr<PathSubstitutionGoal>, kj::Promise<Result<Goal::WorkResult>>> makePathSubstitutionGoal( const StorePath & storePath, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt ) = 0; - virtual std::pair<std::shared_ptr<DrvOutputSubstitutionGoal>, kj::Promise<void>> + virtual std::pair<std::shared_ptr<DrvOutputSubstitutionGoal>, kj::Promise<Result<Goal::WorkResult>>> makeDrvOutputSubstitutionGoal( const DrvOutput & id, RepairFlag repair = NoRepair, @@ -62,7 +64,7 @@ public: * It will be a `DerivationGoal` for a `DerivedPath::Built` or * a `SubstitutionGoal` for a `DerivedPath::Opaque`. */ - virtual std::pair<GoalPtr, kj::Promise<void>> + virtual std::pair<GoalPtr, kj::Promise<Result<Goal::WorkResult>>> makeGoal(const DerivedPath & req, BuildMode buildMode = bmNormal) = 0; }; @@ -82,28 +84,19 @@ protected: */ class Worker : public WorkerBase { +public: + using Targets = std::map<GoalPtr, kj::Promise<Result<Goal::WorkResult>>>; + using Results = std::map<GoalPtr, Goal::WorkResult>; + private: bool running = false; - /** - * The top-level goals of the worker. - */ - Goals topGoals; - template<typename G> struct CachedGoal { - std::weak_ptr<G> goal; - kj::Own<kj::ForkedPromise<void>> promise; - kj::Own<kj::PromiseFulfiller<void>> fulfiller; - - CachedGoal() - { - auto pf = kj::newPromiseAndFulfiller<void>(); - promise = kj::heap(pf.promise.fork()); - fulfiller = std::move(pf.fulfiller); - } + std::shared_ptr<G> goal; + kj::ForkedPromise<Result<Goal::WorkResult>> promise{nullptr}; }; /** * Maps used to prevent multiple instantiations of a goal for the @@ -139,35 +132,10 @@ private: */ bool checkMismatch = false; - void goalFinished(GoalPtr goal, Goal::Finished & f); - void handleWorkResult(GoalPtr goal, Goal::WorkResult how); - - kj::Own<kj::PromiseFulfiller<void>> childFinished; - - /** - * Wait for input to become available. - */ - kj::Promise<Result<void>> waitForInput(); - - /** - * Remove a dead goal. - */ - void removeGoal(GoalPtr goal); - - /** - * Registers a running child process. - */ - void childStarted(GoalPtr goal, kj::Promise<Result<Goal::WorkResult>> promise); - - /** - * Unregisters a running child process. - */ - void childTerminated(GoalPtr goal); - /** * Pass current stats counters to the logger for progress bar updates. */ - kj::Promise<Result<void>> updateStatistics(); + kj::Promise<Result<Results>> updateStatistics(); AsyncSemaphore statisticsUpdateSignal{1}; std::optional<AsyncSemaphore::Token> statisticsUpdateInhibitor; @@ -180,8 +148,8 @@ private: statisticsUpdateInhibitor = {}; } - kj::Promise<Result<void>> runImpl(); - kj::Promise<Result<void>> boopGC(LocalStore & localStore); + kj::Promise<Result<Results>> runImpl(Targets topGoals); + kj::Promise<Result<Results>> boopGC(LocalStore & localStore); public: @@ -196,7 +164,6 @@ public: private: kj::TaskSet children; - std::exception_ptr childException; public: struct HookState { @@ -237,29 +204,29 @@ public: */ private: template<typename ID, std::derived_from<Goal> G> - std::pair<std::shared_ptr<G>, kj::Promise<void>> makeGoalCommon( + std::pair<std::shared_ptr<G>, kj::Promise<Result<Goal::WorkResult>>> makeGoalCommon( std::map<ID, CachedGoal<G>> & map, const ID & key, InvocableR<std::unique_ptr<G>> auto create, - std::invocable<G &> auto modify + InvocableR<bool, G &> auto modify ); - std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<void>> makeDerivationGoal( + std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>> makeDerivationGoal( const StorePath & drvPath, const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal) override; - std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<void>> makeBasicDerivationGoal( + std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>> makeBasicDerivationGoal( const StorePath & drvPath, const BasicDerivation & drv, const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal) override; /** * @ref SubstitutionGoal "substitution goal" */ - std::pair<std::shared_ptr<PathSubstitutionGoal>, kj::Promise<void>> + std::pair<std::shared_ptr<PathSubstitutionGoal>, kj::Promise<Result<Goal::WorkResult>>> makePathSubstitutionGoal( const StorePath & storePath, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt ) override; - std::pair<std::shared_ptr<DrvOutputSubstitutionGoal>, kj::Promise<void>> + std::pair<std::shared_ptr<DrvOutputSubstitutionGoal>, kj::Promise<Result<Goal::WorkResult>>> makeDrvOutputSubstitutionGoal( const DrvOutput & id, RepairFlag repair = NoRepair, @@ -272,16 +239,14 @@ private: * It will be a `DerivationGoal` for a `DerivedPath::Built` or * a `SubstitutionGoal` for a `DerivedPath::Opaque`. */ - std::pair<GoalPtr, kj::Promise<void>> + std::pair<GoalPtr, kj::Promise<Result<Goal::WorkResult>>> makeGoal(const DerivedPath & req, BuildMode buildMode = bmNormal) override; public: - using Targets = std::map<GoalPtr, kj::Promise<void>>; - /** * Loop until the specified top-level goals have finished. */ - std::vector<GoalPtr> run(std::function<Targets (GoalFactory &)> req); + Results run(std::function<Targets (GoalFactory &)> req); /*** * The exit status in case of failure. |