2020-11-09 16:40:10 +02:00
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
///@file
|
2020-11-09 16:40:10 +02:00
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2020-11-09 16:40:10 +02:00
|
|
|
class DrvOutputSubstitutionGoal : public Goal {
|
2023-03-07 14:51:02 +02:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
2023-05-08 21:45:46 +03:00
|
|
|
* The drv output we're trying to substitute
|
2023-04-07 16:55:28 +03:00
|
|
|
*/
|
2020-11-09 16:40:10 +02:00
|
|
|
DrvOutput id;
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* The remaining substituters.
|
|
|
|
*/
|
2020-11-09 16:40:10 +02:00
|
|
|
std::list<ref<Store>> subs;
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* The current substituter.
|
|
|
|
*/
|
2021-10-28 17:43:54 +03:00
|
|
|
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
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Whether a substituter failed.
|
|
|
|
*/
|
2020-11-09 16:40:10 +02:00
|
|
|
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;
|
2023-05-08 21:45:46 +03:00
|
|
|
|
|
|
|
JobCategory jobCategory() override { return JobCategory::Substitution; };
|
2020-11-09 16:40:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|