Nix  2.93.0-dev
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
36enum struct JobCategory {
40 Build,
45};
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
118public:
119 explicit Goal(Worker & worker, bool isDependency)
120 : worker(worker)
122 { }
123
124 virtual ~Goal() noexcept(false)
125 {
126 trace("goal destroyed");
127 }
128
129 kj::Promise<Result<WorkResult>> work() noexcept;
130
131 virtual void waiteeDone(GoalPtr waitee) { }
132
133 void trace(std::string_view s);
134
135 std::string getName() const
136 {
137 return name;
138 }
139
140 virtual void cleanup() { }
141
146 virtual JobCategory jobCategory() const = 0;
147};
148
149}
A semaphore implementation usable from within a KJ event loop.
Definition async-semaphore.hh:20
Definition worker.hh:89
JobCategory
Definition goal.hh:36
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
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