Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
goal.hh
Go to the documentation of this file.
1#pragma once
3
9#include <concepts> // IWYU pragma: keep
10#include <kj/async.h>
11
12namespace nix {
13
17struct Goal;
18class Worker;
19
23typedef std::shared_ptr<Goal> GoalPtr;
24
28typedef std::set<GoalPtr> Goals;
29
46
47struct Goal
48{
49 typedef enum {ecSuccess, ecFailed, ecNoSubstituters, ecIncompleteClosure} ExitCode;
50
55
61 const bool isDependency;
62
66 size_t nrFailed = 0;
67
72 size_t nrNoSubstituters = 0;
73
79
83 std::string name;
84
85protected:
86 AsyncSemaphore::Token slotToken;
87
88public:
89 struct [[nodiscard]] WorkResult {
90 ExitCode exitCode;
91 BuildResult result = {};
92 std::shared_ptr<Error> ex = {};
93 bool permanentFailure = false;
94 bool timedOut = false;
95 bool hashMismatch = false;
96 bool checkMismatch = false;
99 std::optional<StorePath> storePath = {};
100 };
101
102protected:
103 kj::Promise<void> waitForAWhile();
104 kj::Promise<Result<void>>
105 waitForGoals(kj::Array<std::pair<GoalPtr, kj::Promise<Result<WorkResult>>>> dependencies) noexcept;
106
107 template<std::derived_from<Goal>... G>
108 kj::Promise<Result<void>>
109 waitForGoals(std::pair<std::shared_ptr<G>, kj::Promise<Result<WorkResult>>>... goals) noexcept
110 {
111 return waitForGoals(
112 kj::arrOf<std::pair<GoalPtr, kj::Promise<Result<WorkResult>>>>(std::move(goals)...)
113 );
114 }
115
116 virtual kj::Promise<Result<WorkResult>> workImpl() noexcept = 0;
117
118 std::string lixAsyncTaskContext() const
119 {
120 return name;
121 }
122
123public:
124 explicit Goal(Worker & worker, bool isDependency)
125 : worker(worker)
127 { }
128
129 virtual ~Goal() noexcept(false)
130 {
131 trace("goal destroyed");
132 }
133
134 kj::Promise<Result<WorkResult>> work() noexcept;
135
136 virtual void waiteeDone(GoalPtr waitee) { }
137
138 void trace(std::string_view s);
139
140 std::string getName() const
141 {
142 return name;
143 }
144
145 virtual void cleanup() { }
146
151 virtual JobCategory jobCategory() const = 0;
152};
153
154}
A semaphore implementation usable from within a KJ event loop.
Definition async-semaphore.hh:20
Definition worker.hh:89
JobCategory
Definition goal.hh:36
@ Substitution
Definition goal.hh:44
@ Build
Definition goal.hh:40
std::shared_ptr< Goal > GoalPtr
Definition goal.hh:23
std::set< GoalPtr > Goals
Definition goal.hh:28
Definition build-result.hh:17
Definition goal.hh:89
std::optional< StorePath > storePath
Definition goal.hh:99
Definition goal.hh:48
size_t nrFailed
Definition goal.hh:66
std::string name
Definition goal.hh:83
virtual JobCategory jobCategory() const =0
Hint for the scheduler, which concurrency limit applies.
size_t nrIncompleteClosure
Definition goal.hh:78
size_t nrNoSubstituters
Definition goal.hh:72
const bool isDependency
Definition goal.hh:61
Worker & worker
Definition goal.hh:54