Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::Goal Struct Referenceabstract
Inheritance diagram for nix::Goal:
nix::DerivationBuildingGoal nix::DerivationGoal nix::DerivationResolutionGoal nix::DerivationTrampolineGoal nix::DrvOutputSubstitutionGoal nix::PathSubstitutionGoal

Classes

struct  ChildOutput
struct  ChildEOF
struct  Suspend
struct  WaitForChildEvent
class  AwaitableFrame
struct  Co
class  CoBase
struct  AsyncCallback
class  AwaitableFrameBase
struct  AwaitableFrame< void >

Public Types

enum  ExitCode { ecSuccess , ecFailed , ecNoSubstituters }
using ChildEvent = std::variant<ChildOutput, ChildEOF, std::unique_ptr<TimedOut>>
template<typename T>
using HandleType = std::coroutine_handle<AwaitableFrame<T>>
using HandleTypeBase = std::coroutine_handle<AwaitableFrameBase>

Public Member Functions

virtual void cleanup ()
 Goal (Worker &worker, Co< ExitCode > init)
void work ()
void handleChildOutput (Descriptor fd, std::string_view data)
void handleEOF (Descriptor fd)
void timedOut (TimedOut &&ex)
void trace (std::string_view s)
std::string getName () const
virtual std::string key ()=0
std::string_view keyCached () &
virtual JobCategory jobCategory () const =0
 Hint for the scheduler, which concurrency limit applies.

Public Attributes

Worker & worker
WeakGoals waiters
size_t nrFailed = 0
size_t nrNoSubstituters = 0
std::string name
std::optional< ExitCode > exitCode
BuildResult buildResult
bool preserveFailure = false

Protected Member Functions

Co< void > await (Goals waitees)
Co< void > waitForAWhile ()
Co< void > waitUntilWoken ()
Co< void > waitForBuildSlot ()
Co< void > yield ()

Protected Attributes

std::optional< CoBase > top_co
std::optional< ExitCode > finalExitCode

Member Typedef Documentation

◆ HandleType

template<typename T>
using nix::Goal::HandleType = std::coroutine_handle<AwaitableFrame<T>>

Handle to coroutine using Co and promise_type.

Member Function Documentation

◆ handleChildOutput()

void nix::Goal::handleChildOutput ( Descriptor fd,
std::string_view data )

Called by the worker when data is received from a child process. Stores the event and resumes the coroutine.

◆ handleEOF()

void nix::Goal::handleEOF ( Descriptor fd)

Called by the worker when EOF is received from a child process. Stores the event and resumes the coroutine.

◆ jobCategory()

virtual JobCategory nix::Goal::jobCategory ( ) const
pure virtual

Hint for the scheduler, which concurrency limit applies.

See also
JobCategory

Implemented in nix::DerivationGoal, nix::DerivationTrampolineGoal, nix::DrvOutputSubstitutionGoal, and nix::PathSubstitutionGoal.

◆ key()

virtual std::string nix::Goal::key ( )
pure virtual

Used for comparisons. The order matters a bit for scheduling. We want:

  1. Substitution
  2. Derivation administrativia
  3. Actual building

Also, ensure that derivations get processed in order of their name, i.e. a derivation named "aardvark" always comes before "baboon".

Implemented in nix::DerivationGoal, nix::DerivationTrampolineGoal, nix::DrvOutputSubstitutionGoal, and nix::PathSubstitutionGoal.

◆ keyCached()

std::string_view nix::Goal::keyCached ( ) &
inline

Memoising variant of key(). We really don't want to pay the overhead of allocating strings just to compare Goals.

◆ timedOut()

void nix::Goal::timedOut ( TimedOut && ex)

Called by the worker when a build times out. Stores the event and resumes the coroutine.

◆ waitForAWhile()

Goal::Co< void > nix::Goal::waitForAWhile ( )
protected

Awaiting on the resulting coroutine yields the goal for several seconds. Used for retrying goals blocked on acquiring lockfiles.

◆ waitUntilWoken()

Goal::Co< void > nix::Goal::waitUntilWoken ( )
protected

Awaiting on the resulting coroutine yields the goal until it is explicitly woken up via Worker::wakeUp. Wakeup can be queued from another thread via Worker::Waker.

◆ work()

void nix::Goal::work ( )

Resume the goal's coroutine. If it ran to completion, finish the goal: record the exit code, notify waiters, and remove it from the worker.

Member Data Documentation

◆ buildResult

BuildResult nix::Goal::buildResult

Build result.

◆ exitCode

std::optional<ExitCode> nix::Goal::exitCode

How the goal finished, once it has: set exactly once, by work. Not set while the goal is still running, or if it never ran or was cancelled.

◆ finalExitCode

std::optional<ExitCode> nix::Goal::finalExitCode
protected

Where the top-level coroutine's co_return-ed exit code lands, consumed by work once the coroutine has finished.

◆ name

std::string nix::Goal::name

Name of this goal for debugging purposes.

◆ nrFailed

size_t nix::Goal::nrFailed = 0

Number of goals we are/were waiting for that have failed.

◆ nrNoSubstituters

size_t nix::Goal::nrNoSubstituters = 0

Number of substitution goals we are/were waiting for that failed because there are no substituters.

◆ preserveFailure

bool nix::Goal::preserveFailure = false

Hack to say that this goal should not log the failure, but instead keep it around. Set by a waitee which sees itself as the designated continuation of this goal, responsible for reporting its successes or failures.

Todo
this is yet another not-nice hack in the goal system that we ought to get rid of. See #11927

◆ top_co

std::optional<CoBase> nix::Goal::top_co
protected

The coroutine being currently executed. MUST be updated when switching the coroutine being executed. This is used both for memory management and to resume the last coroutine executed. Destroying this should destroy all coroutines created for this goal.

◆ waiters

WeakGoals nix::Goal::waiters

Goals waiting for this one to finish. Must use weak pointers here to prevent cycles.

◆ worker

Worker& nix::Goal::worker

Backlink to the worker.


The documentation for this struct was generated from the following files:
  • libstore/include/nix/store/build/goal.hh
  • libstore/build/goal.cc