libstore: also pass unwanted outputs to the post-build-hook

This commit is contained in:
Yorick 2023-01-31 12:51:12 +01:00
parent 869fb1a2f6
commit 2ca2c80c4e
No known key found for this signature in database
GPG key ID: A36E70F9DC014A15
5 changed files with 30 additions and 10 deletions

View file

@ -1064,7 +1064,7 @@ void DerivationGoal::resolvedFinished()
worker.store.registerDrvOutput(newRealisation); worker.store.registerDrvOutput(newRealisation);
} }
outputPaths.insert(realisation.outPath); outputPaths.insert(realisation.outPath);
builtOutputs.emplace(wantedOutput, realisation); builtOutputs.emplace(outputName, realisation);
} }
runPostBuildHook( runPostBuildHook(
@ -1406,7 +1406,7 @@ std::pair<bool, SingleDrvOutputs> DerivationGoal::checkPathValidity()
); );
} }
} }
if (info.wanted && info.known && info.known->isValid()) if (info.known && info.known->isValid())
validOutputs.emplace(i.first, Realisation { drvOutput, info.known->path }); validOutputs.emplace(i.first, Realisation { drvOutput, info.known->path });
} }
@ -1457,8 +1457,9 @@ void DerivationGoal::done(
mcRunningBuilds.reset(); mcRunningBuilds.reset();
if (buildResult.success()) { if (buildResult.success()) {
assert(!builtOutputs.empty()); auto wantedBuiltOutputs = filterDrvOutputs(wantedOutputs, std::move(builtOutputs));
buildResult.builtOutputs = std::move(builtOutputs); assert(!wantedBuiltOutputs.empty());
buildResult.builtOutputs = std::move(wantedBuiltOutputs);
if (status == BuildResult::Built) if (status == BuildResult::Built)
worker.doneBuilds++; worker.doneBuilds++;
} else { } else {

View file

@ -306,15 +306,13 @@ struct DerivationGoal : public Goal
* Update 'initialOutputs' to determine the current status of the * Update 'initialOutputs' to determine the current status of the
* outputs of the derivation. Also returns a Boolean denoting * outputs of the derivation. Also returns a Boolean denoting
* whether all outputs are valid and non-corrupt, and a * whether all outputs are valid and non-corrupt, and a
* 'SingleDrvOutputs' structure containing the valid and wanted * 'SingleDrvOutputs' structure containing the valid outputs.
* outputs.
*/ */
std::pair<bool, SingleDrvOutputs> checkPathValidity(); std::pair<bool, SingleDrvOutputs> checkPathValidity();
/** /**
* Aborts if any output is not valid or corrupt, and otherwise * Aborts if any output is not valid or corrupt, and otherwise
* returns a 'SingleDrvOutputs' structure containing the wanted * returns a 'SingleDrvOutputs' structure containing all outputs.
* outputs.
*/ */
SingleDrvOutputs assertPathValidity(); SingleDrvOutputs assertPathValidity();

View file

@ -2701,8 +2701,7 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
signRealisation(thisRealisation); signRealisation(thisRealisation);
worker.store.registerDrvOutput(thisRealisation); worker.store.registerDrvOutput(thisRealisation);
} }
if (wantedOutputs.contains(outputName)) builtOutputs.emplace(outputName, thisRealisation);
builtOutputs.emplace(outputName, thisRealisation);
} }
return builtOutputs; return builtOutputs;

View file

@ -136,6 +136,19 @@ size_t Realisation::checkSignatures(const PublicKeys & publicKeys) const
return good; return good;
} }
SingleDrvOutputs filterDrvOutputs(const OutputsSpec& wanted, SingleDrvOutputs&& outputs)
{
SingleDrvOutputs ret = std::move(outputs);
for (auto it = ret.begin(); it != ret.end(); ) {
if (!wanted.contains(it->first))
it = ret.erase(it);
else
++it;
}
return ret;
}
StorePath RealisedPath::path() const { StorePath RealisedPath::path() const {
return std::visit([](auto && arg) { return arg.getPath(); }, raw); return std::visit([](auto && arg) { return arg.getPath(); }, raw);
} }

View file

@ -12,6 +12,7 @@
namespace nix { namespace nix {
class Store; class Store;
struct OutputsSpec;
/** /**
* A general `Realisation` key. * A general `Realisation` key.
@ -93,6 +94,14 @@ typedef std::map<std::string, Realisation> SingleDrvOutputs;
*/ */
typedef std::map<DrvOutput, Realisation> DrvOutputs; typedef std::map<DrvOutput, Realisation> DrvOutputs;
/**
* Filter a SingleDrvOutputs to include only specific output names
*
* Moves the `outputs` input.
*/
SingleDrvOutputs filterDrvOutputs(const OutputsSpec&, SingleDrvOutputs&&);
struct OpaquePath { struct OpaquePath {
StorePath path; StorePath path;