Skip to content

Commit

Permalink
SubstitutionGoal -> PathSubstitutionGoal
Browse files Browse the repository at this point in the history
To prepare for the upcoming DrvOutputSubstitutionGoal
  • Loading branch information
thufschmitt committed Nov 9, 2020
1 parent 6aa848f commit 97aca21
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
8 changes: 4 additions & 4 deletions src/libstore/build/derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void DerivationGoal::getDerivation()
return;
}

addWaitee(upcast_goal(worker.makeSubstitutionGoal(drvPath)));
addWaitee(upcast_goal(worker.makePathSubstitutionGoal(drvPath)));

state = &DerivationGoal::loadDerivation;
}
Expand Down Expand Up @@ -304,7 +304,7 @@ void DerivationGoal::haveDerivation()
/* Nothing to wait for; tail call */
return DerivationGoal::gaveUpOnSubstitution();
}
addWaitee(upcast_goal(worker.makeSubstitutionGoal(
addWaitee(upcast_goal(worker.makePathSubstitutionGoal(
status.known->path,
buildMode == bmRepair ? Repair : NoRepair,
getDerivationCA(*drv))));
Expand Down Expand Up @@ -388,7 +388,7 @@ void DerivationGoal::gaveUpOnSubstitution()
if (!settings.useSubstitutes)
throw Error("dependency '%s' of '%s' does not exist, and substitution is disabled",
worker.store.printStorePath(i), worker.store.printStorePath(drvPath));
addWaitee(upcast_goal(worker.makeSubstitutionGoal(i)));
addWaitee(upcast_goal(worker.makePathSubstitutionGoal(i)));
}

if (waitees.empty()) /* to prevent hang (no wake-up event) */
Expand Down Expand Up @@ -442,7 +442,7 @@ void DerivationGoal::repairClosure()
});
auto drvPath2 = outputsToDrv.find(i);
if (drvPath2 == outputsToDrv.end())
addWaitee(upcast_goal(worker.makeSubstitutionGoal(i, Repair)));
addWaitee(upcast_goal(worker.makePathSubstitutionGoal(i, Repair)));
else
addWaitee(worker.makeDerivationGoal(drvPath2->second, StringSet(), bmRepair));
}
Expand Down
8 changes: 4 additions & 4 deletions src/libstore/build/local-store-build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void LocalStore::buildPaths(const std::vector<StorePathWithOutputs> & drvPaths,
if (path.path.isDerivation())
goals.insert(worker.makeDerivationGoal(path.path, path.outputs, buildMode));
else
goals.insert(worker.makeSubstitutionGoal(path.path, buildMode == bmRepair ? Repair : NoRepair));
goals.insert(worker.makePathSubstitutionGoal(path.path, buildMode == bmRepair ? Repair : NoRepair));
}

worker.run(goals);
Expand All @@ -46,7 +46,7 @@ void LocalStore::buildPaths(const std::vector<StorePathWithOutputs> & drvPaths,
if (i->exitCode != Goal::ecSuccess) {
DerivationGoal * i2 = dynamic_cast<DerivationGoal *>(i.get());
if (i2) failed.insert(i2->getDrvPath());
else failed.insert(dynamic_cast<SubstitutionGoal *>(i.get())->getStorePath());
else failed.insert(dynamic_cast<PathSubstitutionGoal *>(i.get())->getStorePath());
}
}

Expand Down Expand Up @@ -87,7 +87,7 @@ void LocalStore::ensurePath(const StorePath & path)
primeCache(*this, {{path}});

Worker worker(*this);
GoalPtr goal = worker.makeSubstitutionGoal(path);
GoalPtr goal = worker.makePathSubstitutionGoal(path);
Goals goals = {goal};

worker.run(goals);
Expand All @@ -105,7 +105,7 @@ void LocalStore::ensurePath(const StorePath & path)
void LocalStore::repairPath(const StorePath & path)
{
Worker worker(*this);
GoalPtr goal = worker.makeSubstitutionGoal(path, Repair);
GoalPtr goal = worker.makePathSubstitutionGoal(path, Repair);
Goals goals = {goal};

worker.run(goals);
Expand Down
32 changes: 16 additions & 16 deletions src/libstore/build/substitution-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

namespace nix {

SubstitutionGoal::SubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair, std::optional<ContentAddress> ca)
PathSubstitutionGoal::PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair, std::optional<ContentAddress> ca)
: Goal(worker)
, storePath(storePath)
, repair(repair)
, ca(ca)
{
state = &SubstitutionGoal::init;
state = &PathSubstitutionGoal::init;
name = fmt("substitution of '%s'", worker.store.printStorePath(this->storePath));
trace("created");
maintainExpectedSubstitutions = std::make_unique<MaintainCount<uint64_t>>(worker.expectedSubstitutions);
}


SubstitutionGoal::~SubstitutionGoal()
PathSubstitutionGoal::~PathSubstitutionGoal()
{
try {
if (thr.joinable()) {
Expand All @@ -32,13 +32,13 @@ SubstitutionGoal::~SubstitutionGoal()
}


void SubstitutionGoal::work()
void PathSubstitutionGoal::work()
{
(this->*state)();
}


void SubstitutionGoal::init()
void PathSubstitutionGoal::init()
{
trace("init");

Expand All @@ -59,7 +59,7 @@ void SubstitutionGoal::init()
}


void SubstitutionGoal::tryNext()
void PathSubstitutionGoal::tryNext()
{
trace("trying next substituter");

Expand Down Expand Up @@ -159,16 +159,16 @@ void SubstitutionGoal::tryNext()
paths referenced by this one. */
for (auto & i : info->references)
if (i != storePath) /* ignore self-references */
addWaitee(worker.makeSubstitutionGoal(i));
addWaitee(worker.makePathSubstitutionGoal(i));

if (waitees.empty()) /* to prevent hang (no wake-up event) */
referencesValid();
else
state = &SubstitutionGoal::referencesValid;
state = &PathSubstitutionGoal::referencesValid;
}


void SubstitutionGoal::referencesValid()
void PathSubstitutionGoal::referencesValid()
{
trace("all references realised");

Expand All @@ -182,12 +182,12 @@ void SubstitutionGoal::referencesValid()
if (i != storePath) /* ignore self-references */
assert(worker.store.isValidPath(i));

state = &SubstitutionGoal::tryToRun;
state = &PathSubstitutionGoal::tryToRun;
worker.wakeUp(shared_from_this());
}


void SubstitutionGoal::tryToRun()
void PathSubstitutionGoal::tryToRun()
{
trace("trying to run");

Expand Down Expand Up @@ -226,11 +226,11 @@ void SubstitutionGoal::tryToRun()

worker.childStarted(shared_from_this(), {outPipe.readSide.get()}, true, false);

state = &SubstitutionGoal::finished;
state = &PathSubstitutionGoal::finished;
}


void SubstitutionGoal::finished()
void PathSubstitutionGoal::finished()
{
trace("substitute finished");

Expand All @@ -254,7 +254,7 @@ void SubstitutionGoal::finished()
}

/* Try the next substitute. */
state = &SubstitutionGoal::tryNext;
state = &PathSubstitutionGoal::tryNext;
worker.wakeUp(shared_from_this());
return;
}
Expand Down Expand Up @@ -283,12 +283,12 @@ void SubstitutionGoal::finished()
}


void SubstitutionGoal::handleChildOutput(int fd, const string & data)
void PathSubstitutionGoal::handleChildOutput(int fd, const string & data)
{
}


void SubstitutionGoal::handleEOF(int fd)
void PathSubstitutionGoal::handleEOF(int fd)
{
if (fd == outPipe.readSide.get()) worker.wakeUp(shared_from_this());
}
Expand Down
8 changes: 4 additions & 4 deletions src/libstore/build/substitution-goal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace nix {

class Worker;

class SubstitutionGoal : public Goal
class PathSubstitutionGoal : public Goal
{
friend class Worker;

Expand Down Expand Up @@ -50,15 +50,15 @@ private:
std::unique_ptr<MaintainCount<uint64_t>> maintainExpectedSubstitutions,
maintainRunningSubstitutions, maintainExpectedNar, maintainExpectedDownload;

typedef void (SubstitutionGoal::*GoalState)();
typedef void (PathSubstitutionGoal::*GoalState)();
GoalState state;

/* Content address for recomputing store path */
std::optional<ContentAddress> ca;

public:
SubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
~SubstitutionGoal();
PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
~PathSubstitutionGoal();

void timedOut(Error && ex) override { abort(); };

Expand Down
10 changes: 5 additions & 5 deletions src/libstore/build/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ std::shared_ptr<DerivationGoal> Worker::makeBasicDerivationGoal(const StorePath
}


std::shared_ptr<SubstitutionGoal> Worker::makeSubstitutionGoal(const StorePath & path, RepairFlag repair, std::optional<ContentAddress> ca)
std::shared_ptr<PathSubstitutionGoal> Worker::makePathSubstitutionGoal(const StorePath & path, RepairFlag repair, std::optional<ContentAddress> ca)
{
std::weak_ptr<SubstitutionGoal> & goal_weak = substitutionGoals[path];
std::weak_ptr<PathSubstitutionGoal> & goal_weak = substitutionGoals[path];
auto goal = goal_weak.lock(); // FIXME
if (!goal) {
goal = std::make_shared<SubstitutionGoal>(path, *this, repair, ca);
goal = std::make_shared<PathSubstitutionGoal>(path, *this, repair, ca);
goal_weak = goal;
wakeUp(goal);
}
Expand All @@ -105,7 +105,7 @@ void Worker::removeGoal(GoalPtr goal)
{
if (auto drvGoal = std::dynamic_pointer_cast<DerivationGoal>(goal))
nix::removeGoal(drvGoal, derivationGoals);
else if (auto subGoal = std::dynamic_pointer_cast<SubstitutionGoal>(goal))
else if (auto subGoal = std::dynamic_pointer_cast<PathSubstitutionGoal>(goal))
nix::removeGoal(subGoal, substitutionGoals);
else
assert(false);
Expand Down Expand Up @@ -454,7 +454,7 @@ void Worker::markContentsGood(const StorePath & path)
}


GoalPtr upcast_goal(std::shared_ptr<SubstitutionGoal> subGoal) {
GoalPtr upcast_goal(std::shared_ptr<PathSubstitutionGoal> subGoal) {
return subGoal;
}

Expand Down
12 changes: 6 additions & 6 deletions src/libstore/build/worker.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ namespace nix {

/* Forward definition. */
class DerivationGoal;
class SubstitutionGoal;
class PathSubstitutionGoal;

/* Workaround for not being able to declare a something like
class SubstitutionGoal : public Goal;
class PathSubstitutionGoal : public Goal;
even when Goal is a complete type.
This is still a static cast. The purpose of exporting it is to define it in
a place where `SubstitutionGoal` is concrete, and use it in a place where it
a place where `PathSubstitutionGoal` is concrete, and use it in a place where it
is opaque. */
GoalPtr upcast_goal(std::shared_ptr<SubstitutionGoal> subGoal);
GoalPtr upcast_goal(std::shared_ptr<PathSubstitutionGoal> subGoal);

typedef std::chrono::time_point<std::chrono::steady_clock> steady_time_point;

Expand Down Expand Up @@ -69,7 +69,7 @@ private:
/* Maps used to prevent multiple instantiations of a goal for the
same derivation / path. */
std::map<StorePath, std::weak_ptr<DerivationGoal>> derivationGoals;
std::map<StorePath, std::weak_ptr<SubstitutionGoal>> substitutionGoals;
std::map<StorePath, std::weak_ptr<PathSubstitutionGoal>> substitutionGoals;

/* Goals waiting for busy paths to be unlocked. */
WeakGoals waitingForAnyGoal;
Expand Down Expand Up @@ -143,7 +143,7 @@ public:
const StringSet & wantedOutputs, BuildMode buildMode = bmNormal);

/* substitution goal */
std::shared_ptr<SubstitutionGoal> makeSubstitutionGoal(const StorePath & storePath, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
std::shared_ptr<PathSubstitutionGoal> makePathSubstitutionGoal(const StorePath & storePath, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);

/* Remove a dead goal. */
void removeGoal(GoalPtr goal);
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/local-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private:
void createUser(const std::string & userName, uid_t userId) override;

friend class DerivationGoal;
friend class SubstitutionGoal;
friend class PathSubstitutionGoal;
};


Expand Down

0 comments on commit 97aca21

Please sign in to comment.