mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-11 00:36:20 +02:00
Refactor: extract source file patching
This commit is contained in:
parent
0c9c7d5d44
commit
ab3c6a2295
2 changed files with 44 additions and 33 deletions
|
@ -542,19 +542,16 @@ std::optional<Path> getSourceFilePathFromInStorePath(Store & store, const Path &
|
||||||
|
|
||||||
return betterFilePath;
|
return betterFilePath;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableFlake::toDerivation()
|
std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> toDerivationImpl(InstallableFlake & flake) {
|
||||||
{
|
auto lockedFlake = flake.getLockedFlake();
|
||||||
try {
|
|
||||||
auto lockedFlake = getLockedFlake();
|
|
||||||
|
|
||||||
auto cache = openEvalCache(*state, lockedFlake);
|
auto cache = openEvalCache(*flake.state, lockedFlake);
|
||||||
auto root = cache->getRoot();
|
auto root = cache->getRoot();
|
||||||
|
|
||||||
for (auto & attrPath : getActualAttrPaths()) {
|
for (auto & attrPath : flake.getActualAttrPaths()) {
|
||||||
auto attr = root->findAlongAttrPath(
|
auto attr = root->findAlongAttrPath(
|
||||||
parseAttrPath(*state, attrPath),
|
parseAttrPath(*flake.state, attrPath),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -565,25 +562,39 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF
|
||||||
|
|
||||||
auto drvPath = attr->forceDerivation();
|
auto drvPath = attr->forceDerivation();
|
||||||
|
|
||||||
auto drvInfo = DerivationInfo{
|
auto drvInfo = InstallableValue::DerivationInfo{
|
||||||
std::move(drvPath),
|
std::move(drvPath),
|
||||||
state->store->maybeParseStorePath(attr->getAttr(state->sOutPath)->getString()),
|
flake.state->store->maybeParseStorePath(attr->getAttr(flake.state->sOutPath)->getString()),
|
||||||
attr->getAttr(state->sOutputName)->getString()
|
attr->getAttr(flake.state->sOutputName)->getString()
|
||||||
};
|
};
|
||||||
|
|
||||||
return {attrPath, lockedFlake->flake.lockedRef, std::move(drvInfo)};
|
return {attrPath, lockedFlake->flake.lockedRef, std::move(drvInfo)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw Error("flake '%s' does not provide attribute %s",
|
||||||
|
flake.flakeRef, showAttrPaths(flake.getActualAttrPaths()));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class F>
|
||||||
|
auto patchErrorSourceFile(Store & store, const fetchers::Input & flakeInput, F && func) {
|
||||||
|
try {
|
||||||
|
return func();
|
||||||
} catch (BaseError & e) {
|
} catch (BaseError & e) {
|
||||||
if (auto pos = e.info().errPos) {
|
if (auto pos = e.info().errPos) {
|
||||||
if (auto sourceFilePath = getSourceFilePathFromInStorePath(*state->store, pos->file, flakeRef.input)) {
|
if (auto sourceFilePath = getSourceFilePathFromInStorePath(store, pos->file, flakeInput)) {
|
||||||
e.setBetterErrPosFile(*sourceFilePath);
|
e.replacePosFile(*sourceFilePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
throw Error("flake '%s' does not provide attribute %s",
|
std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableFlake::toDerivation()
|
||||||
flakeRef, showAttrPaths(getActualAttrPaths()));
|
{
|
||||||
|
return patchErrorSourceFile(*state->store, flakeRef.input, [&] {
|
||||||
|
return toDerivationImpl(*this);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<InstallableValue::DerivationInfo> InstallableFlake::toDerivations()
|
std::vector<InstallableValue::DerivationInfo> InstallableFlake::toDerivations()
|
||||||
|
|
|
@ -165,7 +165,7 @@ public:
|
||||||
const string & msg() const { return calcWhat(); }
|
const string & msg() const { return calcWhat(); }
|
||||||
const ErrorInfo & info() const { calcWhat(); return err; }
|
const ErrorInfo & info() const { calcWhat(); return err; }
|
||||||
|
|
||||||
void setBetterErrPosFile(std::string file) {
|
void replacePosFile(std::string file) {
|
||||||
if (err.errPos) {
|
if (err.errPos) {
|
||||||
err.errPos->file = std::move(file);
|
err.errPos->file = std::move(file);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue