Desugar StorePathWithOutputs in nix-build implementation

`DerivedPath` has replaced `StorePathWithOutputs` internally, so
shrinking the usage of `StorePathWithOutputs` to just the boundary is
good.
This commit is contained in:
John Ericson 2022-03-11 14:42:09 +00:00
parent aee56e0f89
commit 015d2ad507

View file

@ -325,8 +325,7 @@ static void main_nix_build(int argc, char * * argv)
state->printStats(); state->printStats();
auto buildPaths = [&](const std::vector<StorePathWithOutputs> & paths0) { auto buildPaths = [&](const std::vector<DerivedPath> & paths) {
auto paths = toDerivedPaths(paths0);
/* Note: we do this even when !printMissing to efficiently /* Note: we do this even when !printMissing to efficiently
fetch binary cache data. */ fetch binary cache data. */
uint64_t downloadSize, narSize; uint64_t downloadSize, narSize;
@ -348,7 +347,7 @@ static void main_nix_build(int argc, char * * argv)
auto & drvInfo = drvs.front(); auto & drvInfo = drvs.front();
auto drv = evalStore->derivationFromPath(drvInfo.requireDrvPath()); auto drv = evalStore->derivationFromPath(drvInfo.requireDrvPath());
std::vector<StorePathWithOutputs> pathsToBuild; std::vector<DerivedPath> pathsToBuild;
RealisedPath::Set pathsToCopy; RealisedPath::Set pathsToCopy;
/* Figure out what bash shell to use. If $NIX_BUILD_SHELL /* Figure out what bash shell to use. If $NIX_BUILD_SHELL
@ -370,7 +369,10 @@ static void main_nix_build(int argc, char * * argv)
throw Error("the 'bashInteractive' attribute in <nixpkgs> did not evaluate to a derivation"); throw Error("the 'bashInteractive' attribute in <nixpkgs> did not evaluate to a derivation");
auto bashDrv = drv->requireDrvPath(); auto bashDrv = drv->requireDrvPath();
pathsToBuild.push_back({bashDrv}); pathsToBuild.push_back(DerivedPath::Built {
.drvPath = bashDrv,
.outputs = {},
});
pathsToCopy.insert(bashDrv); pathsToCopy.insert(bashDrv);
shellDrv = bashDrv; shellDrv = bashDrv;
@ -382,17 +384,24 @@ static void main_nix_build(int argc, char * * argv)
} }
// Build or fetch all dependencies of the derivation. // Build or fetch all dependencies of the derivation.
for (const auto & input : drv.inputDrvs) for (const auto & [inputDrv0, inputOutputs] : drv.inputDrvs) {
// To get around lambda capturing restrictions in the
// standard.
const auto & inputDrv = inputDrv0;
if (std::all_of(envExclude.cbegin(), envExclude.cend(), if (std::all_of(envExclude.cbegin(), envExclude.cend(),
[&](const std::string & exclude) { [&](const std::string & exclude) {
return !std::regex_search(store->printStorePath(input.first), std::regex(exclude)); return !std::regex_search(store->printStorePath(inputDrv), std::regex(exclude));
})) }))
{ {
pathsToBuild.push_back({input.first, input.second}); pathsToBuild.push_back(DerivedPath::Built {
pathsToCopy.insert(input.first); .drvPath = inputDrv,
.outputs = inputOutputs
});
pathsToCopy.insert(inputDrv);
} }
}
for (const auto & src : drv.inputSrcs) { for (const auto & src : drv.inputSrcs) {
pathsToBuild.push_back({src}); pathsToBuild.push_back(DerivedPath::Opaque{src});
pathsToCopy.insert(src); pathsToCopy.insert(src);
} }
@ -543,7 +552,7 @@ static void main_nix_build(int argc, char * * argv)
else { else {
std::vector<StorePathWithOutputs> pathsToBuild; std::vector<DerivedPath> pathsToBuild;
std::vector<std::pair<StorePath, std::string>> pathsToBuildOrdered; std::vector<std::pair<StorePath, std::string>> pathsToBuildOrdered;
RealisedPath::Set drvsToCopy; RealisedPath::Set drvsToCopy;
@ -556,7 +565,7 @@ static void main_nix_build(int argc, char * * argv)
if (outputName == "") if (outputName == "")
throw Error("derivation '%s' lacks an 'outputName' attribute", store->printStorePath(drvPath)); throw Error("derivation '%s' lacks an 'outputName' attribute", store->printStorePath(drvPath));
pathsToBuild.push_back({drvPath, {outputName}}); pathsToBuild.push_back(DerivedPath::Built{drvPath, {outputName}});
pathsToBuildOrdered.push_back({drvPath, {outputName}}); pathsToBuildOrdered.push_back({drvPath, {outputName}});
drvsToCopy.insert(drvPath); drvsToCopy.insert(drvPath);