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