BuildResult: Use DerivedPath

This commit is contained in:
Eelco Dolstra 2022-03-09 12:25:35 +01:00
parent a4604f1928
commit 761242afa0
9 changed files with 48 additions and 43 deletions

View file

@ -826,15 +826,17 @@ BuiltPaths Installable::build(
for (auto & buildResult : store->buildPathsWithResults(pathsToBuild, bMode, evalStore)) { for (auto & buildResult : store->buildPathsWithResults(pathsToBuild, bMode, evalStore)) {
if (!buildResult.success()) if (!buildResult.success())
buildResult.rethrow(); buildResult.rethrow();
if (buildResult.drvPath) { std::visit(overloaded {
std::map<std::string, StorePath> outputs; [&](const DerivedPath::Built & bfd) {
for (auto & path : buildResult.builtOutputs) std::map<std::string, StorePath> outputs;
outputs.emplace(path.first.outputName, path.second.outPath); for (auto & path : buildResult.builtOutputs)
res.push_back(BuiltPath::Built{*buildResult.drvPath, outputs}); outputs.emplace(path.first.outputName, path.second.outPath);
} else if (buildResult.outPath) { res.push_back(BuiltPath::Built { bfd.drvPath, outputs });
res.push_back(BuiltPath::Opaque{*buildResult.outPath}); },
} else [&](const DerivedPath::Opaque & bo) {
abort(); res.push_back(BuiltPath::Opaque { bo.path });
},
}, buildResult.path.raw());
} }
return res; return res;
} }

View file

@ -64,13 +64,13 @@ struct BuildResult
non-determinism.) */ non-determinism.) */
bool isNonDeterministic = false; bool isNonDeterministic = false;
/* The derivation we built or the store path we substituted. */
DerivedPath path;
/* For derivations, the derivation path and the wanted outputs. */ /* For derivations, the derivation path and the wanted outputs. */
std::optional<StorePath> drvPath; std::optional<StorePath> drvPath;
DrvOutputs builtOutputs; DrvOutputs builtOutputs;
/* For substitutions, the substituted path. */
std::optional<StorePath> outPath;
/* The start/stop times of the build (or one of the rounds, if it /* The start/stop times of the build (or one of the rounds, if it
was repeated). */ was repeated). */
time_t startTime = 0, stopTime = 0; time_t startTime = 0, stopTime = 0;

View file

@ -66,7 +66,7 @@ namespace nix {
DerivationGoal::DerivationGoal(const StorePath & drvPath, DerivationGoal::DerivationGoal(const StorePath & drvPath,
const StringSet & wantedOutputs, Worker & worker, BuildMode buildMode) const StringSet & wantedOutputs, Worker & worker, BuildMode buildMode)
: Goal(worker) : Goal(worker, DerivedPath::Built { .drvPath = drvPath, .outputs = wantedOutputs })
, useDerivation(true) , useDerivation(true)
, drvPath(drvPath) , drvPath(drvPath)
, wantedOutputs(wantedOutputs) , wantedOutputs(wantedOutputs)
@ -85,7 +85,7 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath,
DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation & drv, DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation & drv,
const StringSet & wantedOutputs, Worker & worker, BuildMode buildMode) const StringSet & wantedOutputs, Worker & worker, BuildMode buildMode)
: Goal(worker) : Goal(worker, DerivedPath::Built { .drvPath = drvPath, .outputs = wantedOutputs })
, useDerivation(false) , useDerivation(false)
, drvPath(drvPath) , drvPath(drvPath)
, wantedOutputs(wantedOutputs) , wantedOutputs(wantedOutputs)
@ -509,7 +509,7 @@ void DerivationGoal::inputsRealised()
state = &DerivationGoal::tryToBuild; state = &DerivationGoal::tryToBuild;
worker.wakeUp(shared_from_this()); worker.wakeUp(shared_from_this());
buildResult = BuildResult(); buildResult = BuildResult { .path = buildResult.path };
} }
void DerivationGoal::started() void DerivationGoal::started()

View file

@ -6,8 +6,12 @@
namespace nix { namespace nix {
DrvOutputSubstitutionGoal::DrvOutputSubstitutionGoal(const DrvOutput& id, Worker & worker, RepairFlag repair, std::optional<ContentAddress> ca) DrvOutputSubstitutionGoal::DrvOutputSubstitutionGoal(
: Goal(worker) const DrvOutput & id,
Worker & worker,
RepairFlag repair,
std::optional<ContentAddress> ca)
: Goal(worker, DerivedPath::Opaque { StorePath::dummy })
, id(id) , id(id)
{ {
state = &DrvOutputSubstitutionGoal::init; state = &DrvOutputSubstitutionGoal::init;

View file

@ -82,17 +82,16 @@ BuildResult Store::buildDerivation(const StorePath & drvPath, const BasicDerivat
Worker worker(*this, *this); Worker worker(*this, *this);
auto goal = worker.makeBasicDerivationGoal(drvPath, drv, {}, buildMode); auto goal = worker.makeBasicDerivationGoal(drvPath, drv, {}, buildMode);
BuildResult result;
try { try {
worker.run(Goals{goal}); worker.run(Goals{goal});
result = goal->buildResult; return goal->buildResult;
} catch (Error & e) { } catch (Error & e) {
result.status = BuildResult::MiscFailure; return BuildResult {
result.errorMsg = e.msg(); .status = BuildResult::MiscFailure,
} .errorMsg = e.msg(),
.path = DerivedPath::Built { .drvPath = drvPath },
return result; };
};
} }

View file

@ -62,7 +62,9 @@ struct Goal : public std::enable_shared_from_this<Goal>
/* Exception containing an error message, if any. */ /* Exception containing an error message, if any. */
std::optional<Error> ex; std::optional<Error> ex;
Goal(Worker & worker) : worker(worker) Goal(Worker & worker, DerivedPath path)
: worker(worker)
, buildResult { .path = std::move(path) }
{ {
nrFailed = nrNoSubstituters = nrIncompleteClosure = 0; nrFailed = nrNoSubstituters = nrIncompleteClosure = 0;
exitCode = ecBusy; exitCode = ecBusy;

View file

@ -6,7 +6,7 @@
namespace nix { namespace nix {
PathSubstitutionGoal::PathSubstitutionGoal(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) : Goal(worker, DerivedPath::Opaque { storePath })
, storePath(storePath) , storePath(storePath)
, repair(repair) , repair(repair)
, ca(ca) , ca(ca)
@ -26,7 +26,6 @@ PathSubstitutionGoal::~PathSubstitutionGoal()
void PathSubstitutionGoal::done(ExitCode result, BuildResult::Status status) void PathSubstitutionGoal::done(ExitCode result, BuildResult::Status status)
{ {
buildResult.outPath = storePath;
buildResult.status = status; buildResult.status = status;
amDone(result); amDone(result);
} }

View file

@ -279,7 +279,7 @@ public:
conn->to.flush(); conn->to.flush();
BuildResult status; BuildResult status { .path = DerivedPath::Built { .drvPath = drvPath } };
status.status = (BuildResult::Status) readInt(conn->from); status.status = (BuildResult::Status) readInt(conn->from);
conn->from >> status.errorMsg; conn->from >> status.errorMsg;
@ -317,7 +317,7 @@ public:
conn->to.flush(); conn->to.flush();
BuildResult result; BuildResult result { .path = DerivedPath::Opaque { StorePath::dummy } };
result.status = (BuildResult::Status) readInt(conn->from); result.status = (BuildResult::Status) readInt(conn->from);
if (!result.success()) { if (!result.success()) {

View file

@ -93,7 +93,8 @@ void write(const Store & store, Sink & out, const DrvOutput & drvOutput)
BuildResult read(const Store & store, Source & from, Phantom<BuildResult> _) BuildResult read(const Store & store, Source & from, Phantom<BuildResult> _)
{ {
BuildResult res; auto path = worker_proto::read(store, from, Phantom<DerivedPath> {});
BuildResult res { .path = path };
res.status = (BuildResult::Status) readInt(from); res.status = (BuildResult::Status) readInt(from);
from from
>> res.errorMsg >> res.errorMsg
@ -101,14 +102,13 @@ BuildResult read(const Store & store, Source & from, Phantom<BuildResult> _)
>> res.isNonDeterministic >> res.isNonDeterministic
>> res.startTime >> res.startTime
>> res.stopTime; >> res.stopTime;
res.drvPath = worker_proto::read(store, from, Phantom<std::optional<StorePath>> {});
res.builtOutputs = worker_proto::read(store, from, Phantom<DrvOutputs> {}); res.builtOutputs = worker_proto::read(store, from, Phantom<DrvOutputs> {});
res.outPath = worker_proto::read(store, from, Phantom<std::optional<StorePath>> {});
return res; return res;
} }
void write(const Store & store, Sink & to, const BuildResult & res) void write(const Store & store, Sink & to, const BuildResult & res)
{ {
worker_proto::write(store, to, res.path);
to to
<< res.status << res.status
<< res.errorMsg << res.errorMsg
@ -116,9 +116,7 @@ void write(const Store & store, Sink & to, const BuildResult & res)
<< res.isNonDeterministic << res.isNonDeterministic
<< res.startTime << res.startTime
<< res.stopTime; << res.stopTime;
worker_proto::write(store, to, res.drvPath);
worker_proto::write(store, to, res.builtOutputs); worker_proto::write(store, to, res.builtOutputs);
worker_proto::write(store, to, res.outPath);
} }
@ -842,15 +840,16 @@ std::vector<BuildResult> RemoteStore::buildPathsWithResults(
std::visit( std::visit(
overloaded { overloaded {
[&](const DerivedPath::Opaque & bo) { [&](const DerivedPath::Opaque & bo) {
BuildResult res; results.push_back(BuildResult {
res.status = BuildResult::Substituted; .status = BuildResult::Substituted,
res.outPath = bo.path; .path = bo,
results.push_back(res); });
}, },
[&](const DerivedPath::Built & bfd) { [&](const DerivedPath::Built & bfd) {
BuildResult res; BuildResult res {
res.status = BuildResult::Built; .status = BuildResult::Built,
res.drvPath = bfd.drvPath; .path = bfd,
};
OutputPathMap outputs; OutputPathMap outputs;
auto drv = evalStore->readDerivation(bfd.drvPath); auto drv = evalStore->readDerivation(bfd.drvPath);
@ -905,7 +904,7 @@ BuildResult RemoteStore::buildDerivation(const StorePath & drvPath, const BasicD
writeDerivation(conn->to, *this, drv); writeDerivation(conn->to, *this, drv);
conn->to << buildMode; conn->to << buildMode;
conn.processStderr(); conn.processStderr();
BuildResult res; BuildResult res { .path = DerivedPath::Built { .drvPath = drvPath } };
res.status = (BuildResult::Status) readInt(conn->from); res.status = (BuildResult::Status) readInt(conn->from);
conn->from >> res.errorMsg; conn->from >> res.errorMsg;
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 29) { if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 29) {