Skip to content

Commit 1c1a707

Browse files
authored
Merge pull request #6221 from NixOS/build-paths-with-results
Add Store::buildPathsWithResults()
2 parents 92b8d4d + 761242a commit 1c1a707

17 files changed

+433
-203
lines changed

src/libcmd/installables.cc

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "eval-cache.hh"
1313
#include "url.hh"
1414
#include "registry.hh"
15+
#include "build-result.hh"
1516

1617
#include <regex>
1718
#include <queue>
@@ -769,8 +770,7 @@ BuiltPaths getBuiltPaths(ref<Store> evalStore, ref<Store> store, const DerivedPa
769770
throw Error(
770771
"the derivation '%s' doesn't have an output named '%s'",
771772
store->printStorePath(bfd.drvPath), output);
772-
if (settings.isExperimentalFeatureEnabled(
773-
Xp::CaDerivations)) {
773+
if (settings.isExperimentalFeatureEnabled(Xp::CaDerivations)) {
774774
auto outputId =
775775
DrvOutput{outputHashes.at(output), output};
776776
auto realisation =
@@ -816,12 +816,33 @@ BuiltPaths Installable::build(
816816
pathsToBuild.insert(pathsToBuild.end(), b.begin(), b.end());
817817
}
818818

819-
if (mode == Realise::Nothing || mode == Realise::Derivation)
819+
switch (mode) {
820+
case Realise::Nothing:
821+
case Realise::Derivation:
820822
printMissing(store, pathsToBuild, lvlError);
821-
else if (mode == Realise::Outputs)
822-
store->buildPaths(pathsToBuild, bMode, evalStore);
823-
824-
return getBuiltPaths(evalStore, store, pathsToBuild);
823+
return getBuiltPaths(evalStore, store, pathsToBuild);
824+
case Realise::Outputs: {
825+
BuiltPaths res;
826+
for (auto & buildResult : store->buildPathsWithResults(pathsToBuild, bMode, evalStore)) {
827+
if (!buildResult.success())
828+
buildResult.rethrow();
829+
std::visit(overloaded {
830+
[&](const DerivedPath::Built & bfd) {
831+
std::map<std::string, StorePath> outputs;
832+
for (auto & path : buildResult.builtOutputs)
833+
outputs.emplace(path.first.outputName, path.second.outPath);
834+
res.push_back(BuiltPath::Built { bfd.drvPath, outputs });
835+
},
836+
[&](const DerivedPath::Opaque & bo) {
837+
res.push_back(BuiltPath::Opaque { bo.path });
838+
},
839+
}, buildResult.path.raw());
840+
}
841+
return res;
842+
}
843+
default:
844+
assert(false);
845+
}
825846
}
826847

827848
BuiltPaths Installable::toBuiltPaths(

src/libstore/build-result.hh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct BuildResult
2828
LogLimitExceeded,
2929
NotDeterministic,
3030
ResolvesToAlreadyValid,
31+
NoSubstituters,
3132
} status = MiscFailure;
3233
std::string errorMsg;
3334

@@ -63,15 +64,26 @@ struct BuildResult
6364
non-determinism.) */
6465
bool isNonDeterministic = false;
6566

67+
/* The derivation we built or the store path we substituted. */
68+
DerivedPath path;
69+
70+
/* For derivations, the derivation path and the wanted outputs. */
71+
std::optional<StorePath> drvPath;
6672
DrvOutputs builtOutputs;
6773

6874
/* The start/stop times of the build (or one of the rounds, if it
6975
was repeated). */
7076
time_t startTime = 0, stopTime = 0;
7177

72-
bool success() {
78+
bool success()
79+
{
7380
return status == Built || status == Substituted || status == AlreadyValid || status == ResolvesToAlreadyValid;
7481
}
82+
83+
void rethrow()
84+
{
85+
throw Error("%s", errorMsg);
86+
}
7587
};
7688

7789
}

0 commit comments

Comments
 (0)