nix-super/src/libstore/build/substitution-goal.hh

123 lines
2.7 KiB
C++
Raw Normal View History

2020-10-11 19:17:24 +03:00
#pragma once
///@file
2020-10-11 19:17:24 +03:00
#include "lock.hh"
2020-10-12 20:16:25 +03:00
#include "store-api.hh"
#include "goal.hh"
namespace nix {
class Worker;
struct PathSubstitutionGoal : public Goal
{
/**
* The store path that should be realised through a substitute.
*/
2020-10-11 19:17:24 +03:00
StorePath storePath;
2019-05-12 23:47:41 +03:00
/**
* The path the substituter refers to the path as. This will be
* different when the stores have different names.
*/
2020-10-11 19:17:24 +03:00
std::optional<StorePath> subPath;
2019-05-12 23:47:41 +03:00
/**
* The remaining substituters.
*/
2020-10-11 19:17:24 +03:00
std::list<ref<Store>> subs;
/**
* The current substituter.
*/
2020-10-11 19:17:24 +03:00
std::shared_ptr<Store> sub;
/**
* Whether a substituter failed.
*/
2020-10-11 19:17:24 +03:00
bool substituterFailed = false;
/**
* Path info returned by the substituter's query info operation.
*/
2020-10-11 19:17:24 +03:00
std::shared_ptr<const ValidPathInfo> info;
/**
* Pipe for the substituter's standard output.
*/
2020-10-11 19:17:24 +03:00
Pipe outPipe;
/**
* The substituter thread.
*/
2020-10-11 19:17:24 +03:00
std::thread thr;
2020-10-11 19:17:24 +03:00
std::promise<void> promise;
/**
* Whether to try to repair a valid path.
*/
2020-10-11 19:17:24 +03:00
RepairFlag repair;
/**
* Location where we're downloading the substitute. Differs from
* storePath when doing a repair.
*/
2020-10-11 19:17:24 +03:00
Path destPath;
2020-10-11 19:17:24 +03:00
std::unique_ptr<MaintainCount<uint64_t>> maintainExpectedSubstitutions,
maintainRunningSubstitutions, maintainExpectedNar, maintainExpectedDownload;
typedef void (PathSubstitutionGoal::*GoalState)();
2020-10-11 19:17:24 +03:00
GoalState state;
/**
* Content address for recomputing store path
*/
2020-10-11 19:17:24 +03:00
std::optional<ContentAddress> ca;
void done(
ExitCode result,
BuildResult::Status status,
std::optional<std::string> errorMsg = {});
public:
PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
~PathSubstitutionGoal();
2020-10-11 19:17:24 +03:00
void timedOut(Error && ex) override { abort(); };
/**
* We prepend "a$" to the key name to ensure substitution goals
* happen before derivation goals.
*/
std::string key() override
2020-10-11 19:17:24 +03:00
{
return "a$" + std::string(storePath.name()) + "$" + worker.store.printStorePath(storePath);
}
2020-10-11 19:17:24 +03:00
void work() override;
2003-07-20 22:29:38 +03:00
/**
* The states.
*/
2020-10-11 19:17:24 +03:00
void init();
void tryNext();
void gotInfo();
void referencesValid();
void tryToRun();
void finished();
/**
* Callback used by the worker to write to the log.
*/
void handleChildOutput(int fd, std::string_view data) override;
2020-10-11 19:17:24 +03:00
void handleEOF(int fd) override;
void cleanup() override;
2023-05-08 21:45:46 +03:00
JobCategory jobCategory() override { return JobCategory::Substitution; };
2020-10-11 19:17:24 +03:00
};
}