1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 14:51:16 +02:00

libexpr: add findDerivationFilename

extract the derivation to filename:lineno heuristic
This commit is contained in:
zimbatm 2019-10-23 17:21:10 +02:00
parent 207a537343
commit 59c7249769
No known key found for this signature in database
GPG key ID: 71BAF6D40C1D63D7
4 changed files with 36 additions and 43 deletions

View file

@ -93,4 +93,32 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
}
std::tuple<std::string, int> findDerivationFilename(EvalState & state, Value & v, std::string what)
{
Value * v2;
try {
auto dummyArgs = state.allocBindings(0);
v2 = findAlongAttrPath(state, "meta.position", *dummyArgs, v);
} catch (Error &) {
throw Error("package '%s' has no source location information", what);
}
auto pos = state.forceString(*v2);
auto colon = pos.rfind(':');
if (colon == std::string::npos)
throw Error("cannot parse meta.position attribute '%s'", pos);
std::string filename(pos, 0, colon);
int lineno;
try {
lineno = std::stoi(std::string(pos, colon + 1));
} catch (std::invalid_argument & e) {
throw Error("cannot parse line number '%s'", pos);
}
return std::make_tuple(filename, lineno);
}
}