2020-10-12 17:08:52 +00:00
|
|
|
#include "goal.hh"
|
|
|
|
#include "worker.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
|
|
|
|
2017-12-11 18:05:14 +00:00
|
|
|
bool CompareGoalPtrs::operator() (const GoalPtr & a, const GoalPtr & b) const {
|
2014-11-24 15:48:04 +00:00
|
|
|
string s1 = a->key();
|
|
|
|
string s2 = b->key();
|
|
|
|
return s1 < s2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-29 23:49:23 +00:00
|
|
|
void addToWeakGoals(WeakGoals & goals, GoalPtr p)
|
|
|
|
{
|
2021-08-07 23:47:08 +00:00
|
|
|
if (goals.find(p) != goals.end())
|
|
|
|
return;
|
|
|
|
goals.insert(p);
|
2014-03-29 23:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-25 15:36:09 +00:00
|
|
|
void Goal::addWaitee(GoalPtr waitee)
|
2004-06-18 18:09:32 +00:00
|
|
|
{
|
2004-06-25 15:36:09 +00:00
|
|
|
waitees.insert(waitee);
|
2014-03-29 23:49:23 +00:00
|
|
|
addToWeakGoals(waitee->waiters, shared_from_this());
|
2004-06-18 18:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-08 17:26:21 +00:00
|
|
|
void Goal::waiteeDone(GoalPtr waitee, ExitCode result)
|
2004-06-18 18:09:32 +00:00
|
|
|
{
|
2004-06-25 15:36:09 +00:00
|
|
|
assert(waitees.find(waitee) != waitees.end());
|
|
|
|
waitees.erase(waitee);
|
2005-02-18 09:50:20 +00:00
|
|
|
|
2020-06-15 17:25:35 +00:00
|
|
|
trace(fmt("waitee '%s' done; %d left", waitee->name, waitees.size()));
|
2012-07-27 13:59:18 +00:00
|
|
|
|
2013-01-02 11:38:28 +00:00
|
|
|
if (result == ecFailed || result == ecNoSubstituters || result == ecIncompleteClosure) ++nrFailed;
|
2012-07-08 22:39:24 +00:00
|
|
|
|
|
|
|
if (result == ecNoSubstituters) ++nrNoSubstituters;
|
2012-07-27 13:59:18 +00:00
|
|
|
|
2013-01-02 11:38:28 +00:00
|
|
|
if (result == ecIncompleteClosure) ++nrIncompleteClosure;
|
|
|
|
|
2012-07-30 23:55:41 +00:00
|
|
|
if (waitees.empty() || (result == ecFailed && !settings.keepGoing)) {
|
2004-06-28 10:42:57 +00:00
|
|
|
|
|
|
|
/* If we failed and keepGoing is not set, we remove all
|
|
|
|
remaining waitees. */
|
2015-07-17 17:24:28 +00:00
|
|
|
for (auto & goal : waitees) {
|
2021-08-07 23:47:08 +00:00
|
|
|
goal->waiters.extract(shared_from_this());
|
2004-06-28 10:42:57 +00:00
|
|
|
}
|
|
|
|
waitees.clear();
|
2004-07-01 16:24:35 +00:00
|
|
|
|
2004-06-25 15:36:09 +00:00
|
|
|
worker.wakeUp(shared_from_this());
|
2004-06-28 10:42:57 +00:00
|
|
|
}
|
2004-06-18 18:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-15 17:25:35 +00:00
|
|
|
void Goal::amDone(ExitCode result, std::optional<Error> ex)
|
2004-06-18 18:09:32 +00:00
|
|
|
{
|
2004-06-25 15:36:09 +00:00
|
|
|
trace("done");
|
2005-02-23 11:19:27 +00:00
|
|
|
assert(exitCode == ecBusy);
|
2013-01-02 11:38:28 +00:00
|
|
|
assert(result == ecSuccess || result == ecFailed || result == ecNoSubstituters || result == ecIncompleteClosure);
|
2006-12-08 17:26:21 +00:00
|
|
|
exitCode = result;
|
2020-06-15 17:25:35 +00:00
|
|
|
|
|
|
|
if (ex) {
|
|
|
|
if (!waiters.empty())
|
|
|
|
logError(ex->info());
|
|
|
|
else
|
|
|
|
this->ex = std::move(*ex);
|
|
|
|
}
|
|
|
|
|
2015-07-17 17:24:28 +00:00
|
|
|
for (auto & i : waiters) {
|
|
|
|
GoalPtr goal = i.lock();
|
2006-12-08 17:26:21 +00:00
|
|
|
if (goal) goal->waiteeDone(shared_from_this(), result);
|
2004-06-25 15:36:09 +00:00
|
|
|
}
|
|
|
|
waiters.clear();
|
2004-06-18 18:09:32 +00:00
|
|
|
worker.removeGoal(shared_from_this());
|
2021-04-07 10:21:31 +00:00
|
|
|
|
|
|
|
cleanup();
|
2004-06-18 18:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-14 18:01:22 +00:00
|
|
|
void Goal::trace(const FormatOrString & fs)
|
2004-06-25 15:36:09 +00:00
|
|
|
{
|
2018-03-14 18:01:22 +00:00
|
|
|
debug("%1%: %2%", name, fs.s);
|
2004-06-25 15:36:09 +00:00
|
|
|
}
|
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
}
|