2020-11-09 16:40:10 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "store-api.hh"
|
|
|
|
#include "goal.hh"
|
|
|
|
#include "realisation.hh"
|
2021-10-28 17:43:54 +03:00
|
|
|
#include <thread>
|
|
|
|
#include <future>
|
2020-11-09 16:40:10 +02:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
class Worker;
|
|
|
|
|
|
|
|
// Substitution of a derivation output.
|
|
|
|
// This is done in three steps:
|
|
|
|
// 1. Fetch the output info from a substituter
|
|
|
|
// 2. Substitute the corresponding output path
|
|
|
|
// 3. Register the output info
|
|
|
|
class DrvOutputSubstitutionGoal : public Goal {
|
2023-03-07 14:51:02 +02:00
|
|
|
|
2020-11-09 16:40:10 +02:00
|
|
|
// The drv output we're trying to substitue
|
|
|
|
DrvOutput id;
|
|
|
|
|
|
|
|
// The realisation corresponding to the given output id.
|
|
|
|
// Will be filled once we can get it.
|
2021-10-27 12:36:51 +03:00
|
|
|
std::shared_ptr<const Realisation> outputInfo;
|
2020-11-09 16:40:10 +02:00
|
|
|
|
|
|
|
/* The remaining substituters. */
|
|
|
|
std::list<ref<Store>> subs;
|
|
|
|
|
2021-10-28 17:43:54 +03:00
|
|
|
/* The current substituter. */
|
|
|
|
std::shared_ptr<Store> sub;
|
|
|
|
|
2023-03-07 14:51:02 +02:00
|
|
|
struct DownloadState
|
|
|
|
{
|
|
|
|
Pipe outPipe;
|
|
|
|
std::promise<std::shared_ptr<const Realisation>> promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::shared_ptr<DownloadState> downloadState;
|
2021-10-28 17:43:54 +03:00
|
|
|
|
2020-11-09 16:40:10 +02:00
|
|
|
/* Whether a substituter failed. */
|
|
|
|
bool substituterFailed = false;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DrvOutputSubstitutionGoal(const DrvOutput& id, Worker & worker, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
|
|
|
|
|
|
|
|
typedef void (DrvOutputSubstitutionGoal::*GoalState)();
|
|
|
|
GoalState state;
|
|
|
|
|
|
|
|
void init();
|
|
|
|
void tryNext();
|
2021-10-28 17:43:54 +03:00
|
|
|
void realisationFetched();
|
2020-11-09 16:40:10 +02:00
|
|
|
void outPathValid();
|
|
|
|
void finished();
|
|
|
|
|
|
|
|
void timedOut(Error && ex) override { abort(); };
|
|
|
|
|
2022-02-25 17:00:00 +02:00
|
|
|
std::string key() override;
|
2020-11-09 16:40:10 +02:00
|
|
|
|
|
|
|
void work() override;
|
2021-10-28 17:43:54 +03:00
|
|
|
void handleEOF(int fd) override;
|
2020-11-09 16:40:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|