2020-10-11 16:17:24 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-10-12 17:16:00 +00:00
|
|
|
#include "types.hh"
|
|
|
|
#include "store-api.hh"
|
2009-01-12 16:30:32 +00:00
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
namespace nix {
|
|
|
|
|
2004-06-18 18:09:32 +00:00
|
|
|
/* Forward definition. */
|
2020-10-12 17:16:00 +00:00
|
|
|
struct Goal;
|
|
|
|
struct Worker;
|
2004-06-18 18:09:32 +00:00
|
|
|
|
|
|
|
/* A pointer to a goal. */
|
2014-03-29 23:49:23 +00:00
|
|
|
typedef std::shared_ptr<Goal> GoalPtr;
|
|
|
|
typedef std::weak_ptr<Goal> WeakGoalPtr;
|
2004-06-18 18:09:32 +00:00
|
|
|
|
2014-11-24 15:48:04 +00:00
|
|
|
struct CompareGoalPtrs {
|
2017-12-11 18:05:14 +00:00
|
|
|
bool operator() (const GoalPtr & a, const GoalPtr & b) const;
|
2014-11-24 15:48:04 +00:00
|
|
|
};
|
|
|
|
|
2004-06-25 15:36:09 +00:00
|
|
|
/* Set of goals. */
|
2014-11-24 15:48:04 +00:00
|
|
|
typedef set<GoalPtr, CompareGoalPtrs> Goals;
|
2014-03-29 23:49:23 +00:00
|
|
|
typedef list<WeakGoalPtr> WeakGoals;
|
2004-06-18 18:09:32 +00:00
|
|
|
|
|
|
|
/* A map of paths to goals (and the other way around). */
|
2019-12-05 18:11:09 +00:00
|
|
|
typedef std::map<StorePath, WeakGoalPtr> WeakGoalMap;
|
2004-06-18 18:09:32 +00:00
|
|
|
|
2020-06-15 17:25:35 +00:00
|
|
|
struct Goal : public std::enable_shared_from_this<Goal>
|
2004-06-18 18:09:32 +00:00
|
|
|
{
|
2013-01-02 11:38:28 +00:00
|
|
|
typedef enum {ecBusy, ecSuccess, ecFailed, ecNoSubstituters, ecIncompleteClosure} ExitCode;
|
2012-07-27 13:59:18 +00:00
|
|
|
|
2004-06-18 18:09:32 +00:00
|
|
|
/* Backlink to the worker. */
|
|
|
|
Worker & worker;
|
|
|
|
|
2004-06-25 15:36:09 +00:00
|
|
|
/* Goals that this goal is waiting for. */
|
|
|
|
Goals waitees;
|
|
|
|
|
|
|
|
/* Goals waiting for this one to finish. Must use weak pointers
|
|
|
|
here to prevent cycles. */
|
|
|
|
WeakGoals waiters;
|
2004-06-18 18:09:32 +00:00
|
|
|
|
2004-08-30 11:51:36 +00:00
|
|
|
/* Number of goals we are/were waiting for that have failed. */
|
2004-06-25 10:21:44 +00:00
|
|
|
unsigned int nrFailed;
|
|
|
|
|
2012-07-08 22:39:24 +00:00
|
|
|
/* Number of substitution goals we are/were waiting for that
|
|
|
|
failed because there are no substituters. */
|
|
|
|
unsigned int nrNoSubstituters;
|
|
|
|
|
2013-01-02 11:38:28 +00:00
|
|
|
/* Number of substitution goals we are/were waiting for that
|
|
|
|
failed because othey had unsubstitutable references. */
|
|
|
|
unsigned int nrIncompleteClosure;
|
|
|
|
|
2005-02-18 09:50:20 +00:00
|
|
|
/* Name of this goal for debugging purposes. */
|
|
|
|
string name;
|
|
|
|
|
2005-02-23 11:19:27 +00:00
|
|
|
/* Whether the goal is finished. */
|
|
|
|
ExitCode exitCode;
|
|
|
|
|
2020-06-15 17:25:35 +00:00
|
|
|
/* Exception containing an error message, if any. */
|
|
|
|
std::optional<Error> ex;
|
|
|
|
|
2005-01-19 11:16:11 +00:00
|
|
|
Goal(Worker & worker) : worker(worker)
|
2004-06-18 18:09:32 +00:00
|
|
|
{
|
2013-01-02 11:38:28 +00:00
|
|
|
nrFailed = nrNoSubstituters = nrIncompleteClosure = 0;
|
2005-02-23 11:19:27 +00:00
|
|
|
exitCode = ecBusy;
|
2004-06-18 18:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~Goal()
|
|
|
|
{
|
2005-02-18 09:50:20 +00:00
|
|
|
trace("goal destroyed");
|
2004-06-18 18:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void work() = 0;
|
|
|
|
|
2004-06-25 15:36:09 +00:00
|
|
|
void addWaitee(GoalPtr waitee);
|
2004-06-18 18:09:32 +00:00
|
|
|
|
2006-12-08 17:26:21 +00:00
|
|
|
virtual void waiteeDone(GoalPtr waitee, ExitCode result);
|
2004-06-25 10:21:44 +00:00
|
|
|
|
2005-10-17 15:33:24 +00:00
|
|
|
virtual void handleChildOutput(int fd, const string & data)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void handleEOF(int fd)
|
2004-06-29 09:41:50 +00:00
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2018-03-14 18:01:22 +00:00
|
|
|
void trace(const FormatOrString & fs);
|
2005-02-18 09:50:20 +00:00
|
|
|
|
|
|
|
string getName()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
2012-07-27 13:59:18 +00:00
|
|
|
|
2015-07-20 01:15:45 +00:00
|
|
|
/* Callback in case of a timeout. It should wake up its waiters,
|
|
|
|
get rid of any running child processes that are being monitored
|
|
|
|
by the worker (important!), etc. */
|
2020-06-15 17:25:35 +00:00
|
|
|
virtual void timedOut(Error && ex) = 0;
|
2006-12-08 17:26:21 +00:00
|
|
|
|
2014-11-24 15:48:04 +00:00
|
|
|
virtual string key() = 0;
|
|
|
|
|
2020-06-15 17:25:35 +00:00
|
|
|
void amDone(ExitCode result, std::optional<Error> ex = {});
|
2004-06-18 18:09:32 +00:00
|
|
|
};
|
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
void addToWeakGoals(WeakGoals & goals, GoalPtr p);
|
2012-10-02 18:08:59 +00:00
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
}
|