mirror of
https://github.com/NixOS/nix
synced 2025-06-25 02:21:16 +02:00
Deduplicate the goal creation functions
The weak reference logic is the same in both these cases, and if/when I get rid `addWantedOutputs`, also in the `DerivationGoal` case.
This commit is contained in:
parent
0d3750e902
commit
7bd9eef772
2 changed files with 15 additions and 16 deletions
|
@ -41,6 +41,16 @@ Worker::~Worker()
|
||||||
assert(expectedNarSize == 0);
|
assert(expectedNarSize == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class G, typename... Args>
|
||||||
|
std::shared_ptr<G> Worker::initGoalIfNeeded(std::weak_ptr<G> & goal_weak, Args && ...args)
|
||||||
|
{
|
||||||
|
if (auto goal = goal_weak.lock()) return goal;
|
||||||
|
|
||||||
|
auto goal = std::make_shared<G>(args...);
|
||||||
|
goal_weak = goal;
|
||||||
|
wakeUp(goal);
|
||||||
|
return goal;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<DerivationGoal> Worker::makeDerivationGoalCommon(
|
std::shared_ptr<DerivationGoal> Worker::makeDerivationGoalCommon(
|
||||||
const StorePath & drvPath,
|
const StorePath & drvPath,
|
||||||
|
@ -79,27 +89,13 @@ std::shared_ptr<DerivationGoal> Worker::makeBasicDerivationGoal(const StorePath
|
||||||
|
|
||||||
std::shared_ptr<PathSubstitutionGoal> Worker::makePathSubstitutionGoal(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<PathSubstitutionGoal> & goal_weak = substitutionGoals[path];
|
return initGoalIfNeeded(substitutionGoals[path], path, *this, repair, ca);
|
||||||
auto goal = goal_weak.lock(); // FIXME
|
|
||||||
if (!goal) {
|
|
||||||
goal = std::make_shared<PathSubstitutionGoal>(path, *this, repair, ca);
|
|
||||||
goal_weak = goal;
|
|
||||||
wakeUp(goal);
|
|
||||||
}
|
|
||||||
return goal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<DrvOutputSubstitutionGoal> Worker::makeDrvOutputSubstitutionGoal(const DrvOutput& id, RepairFlag repair, std::optional<ContentAddress> ca)
|
std::shared_ptr<DrvOutputSubstitutionGoal> Worker::makeDrvOutputSubstitutionGoal(const DrvOutput& id, RepairFlag repair, std::optional<ContentAddress> ca)
|
||||||
{
|
{
|
||||||
std::weak_ptr<DrvOutputSubstitutionGoal> & goal_weak = drvOutputSubstitutionGoals[id];
|
return initGoalIfNeeded(drvOutputSubstitutionGoals[id], id, *this, repair, ca);
|
||||||
auto goal = goal_weak.lock(); // FIXME
|
|
||||||
if (!goal) {
|
|
||||||
goal = std::make_shared<DrvOutputSubstitutionGoal>(id, *this, repair, ca);
|
|
||||||
goal_weak = goal;
|
|
||||||
wakeUp(goal);
|
|
||||||
}
|
|
||||||
return goal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -196,6 +196,9 @@ public:
|
||||||
* @ref DerivationGoal "derivation goal"
|
* @ref DerivationGoal "derivation goal"
|
||||||
*/
|
*/
|
||||||
private:
|
private:
|
||||||
|
template<class G, typename... Args>
|
||||||
|
std::shared_ptr<G> initGoalIfNeeded(std::weak_ptr<G> & goal_weak, Args && ...args);
|
||||||
|
|
||||||
std::shared_ptr<DerivationGoal> makeDerivationGoalCommon(
|
std::shared_ptr<DerivationGoal> makeDerivationGoalCommon(
|
||||||
const StorePath & drvPath, const OutputsSpec & wantedOutputs,
|
const StorePath & drvPath, const OutputsSpec & wantedOutputs,
|
||||||
std::function<std::shared_ptr<DerivationGoal>()> mkDrvGoal);
|
std::function<std::shared_ptr<DerivationGoal>()> mkDrvGoal);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue