findAlongAttrPath(): Return position
(cherry picked from commit 0b013a54dc
)
This commit is contained in:
parent
1eb952d27a
commit
c1ca4f0acc
|
@ -32,7 +32,7 @@ static Strings parseAttrPath(const string & s)
|
|||
}
|
||||
|
||||
|
||||
Value * findAlongAttrPath(EvalState & state, const string & attrPath,
|
||||
std::pair<Value *, Pos> findAlongAttrPath(EvalState & state, const string & attrPath,
|
||||
Bindings & autoArgs, Value & vIn)
|
||||
{
|
||||
Strings tokens = parseAttrPath(attrPath);
|
||||
|
@ -41,6 +41,7 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
|
|||
Error(format("attribute selection path '%1%' does not match expression") % attrPath);
|
||||
|
||||
Value * v = &vIn;
|
||||
Pos pos = noPos;
|
||||
|
||||
for (auto & attr : tokens) {
|
||||
|
||||
|
@ -72,6 +73,7 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
|
|||
if (a == v->attrs->end())
|
||||
throw AttrPathNotFound("attribute '%1%' in selection path '%2%' not found", attr, attrPath);
|
||||
v = &*a->value;
|
||||
pos = *a->pos;
|
||||
}
|
||||
|
||||
else if (apType == apIndex) {
|
||||
|
@ -85,11 +87,12 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
|
|||
throw AttrPathNotFound("list index %1% in selection path '%2%' is out of range", attrIndex, attrPath);
|
||||
|
||||
v = v->listElems()[attrIndex];
|
||||
pos = noPos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return v;
|
||||
return {v, pos};
|
||||
}
|
||||
|
||||
|
||||
|
@ -98,7 +101,7 @@ Pos findDerivationFilename(EvalState & state, Value & v, std::string what)
|
|||
Value * v2;
|
||||
try {
|
||||
auto dummyArgs = state.allocBindings(0);
|
||||
v2 = findAlongAttrPath(state, "meta.position", *dummyArgs, v);
|
||||
v2 = findAlongAttrPath(state, "meta.position", *dummyArgs, v).first;
|
||||
} catch (Error &) {
|
||||
throw Error("package '%s' has no source location information", what);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace nix {
|
|||
|
||||
MakeError(AttrPathNotFound, Error);
|
||||
|
||||
Value * findAlongAttrPath(EvalState & state, const string & attrPath,
|
||||
std::pair<Value *, Pos> findAlongAttrPath(EvalState & state, const string & attrPath,
|
||||
Bindings & autoArgs, Value & vIn);
|
||||
|
||||
/* Heuristic to find the filename and lineno or a nix value. */
|
||||
|
|
|
@ -314,7 +314,7 @@ static void _main(int argc, char * * argv)
|
|||
state->eval(e, vRoot);
|
||||
|
||||
for (auto & i : attrPaths) {
|
||||
Value & v(*findAlongAttrPath(*state, i, *autoArgs, vRoot));
|
||||
Value & v(*findAlongAttrPath(*state, i, *autoArgs, vRoot).first);
|
||||
state->forceValue(v);
|
||||
getDerivations(*state, v, "", *autoArgs, drvs, false);
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ static void loadDerivations(EvalState & state, Path nixExprPath,
|
|||
Value vRoot;
|
||||
loadSourceExpr(state, nixExprPath, vRoot);
|
||||
|
||||
Value & v(*findAlongAttrPath(state, pathPrefix, autoArgs, vRoot));
|
||||
Value & v(*findAlongAttrPath(state, pathPrefix, autoArgs, vRoot).first);
|
||||
|
||||
getDerivations(state, v, pathPrefix, autoArgs, elems, true);
|
||||
|
||||
|
@ -408,7 +408,7 @@ static void queryInstSources(EvalState & state,
|
|||
Value vRoot;
|
||||
loadSourceExpr(state, instSource.nixExprPath, vRoot);
|
||||
for (auto & i : args) {
|
||||
Value & v(*findAlongAttrPath(state, i, *instSource.autoArgs, vRoot));
|
||||
Value & v(*findAlongAttrPath(state, i, *instSource.autoArgs, vRoot).first);
|
||||
getDerivations(state, v, "", *instSource.autoArgs, elems, true);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -39,7 +39,7 @@ void processExpr(EvalState & state, const Strings & attrPaths,
|
|||
state.eval(e, vRoot);
|
||||
|
||||
for (auto & i : attrPaths) {
|
||||
Value & v(*findAlongAttrPath(state, i, autoArgs, vRoot));
|
||||
Value & v(*findAlongAttrPath(state, i, autoArgs, vRoot).first);
|
||||
state.forceValue(v);
|
||||
|
||||
PathSet context;
|
||||
|
|
|
@ -120,7 +120,7 @@ static int _main(int argc, char * * argv)
|
|||
Path path = resolveExprPath(lookupFileArg(*state, args.empty() ? "." : args[0]));
|
||||
Value vRoot;
|
||||
state->evalFile(path, vRoot);
|
||||
Value & v(*findAlongAttrPath(*state, attrPath, autoArgs, vRoot));
|
||||
Value & v(*findAlongAttrPath(*state, attrPath, autoArgs, vRoot).first);
|
||||
state->forceAttrs(v);
|
||||
|
||||
/* Extract the URI. */
|
||||
|
|
|
@ -193,7 +193,7 @@ struct InstallableAttrPath : InstallableValue
|
|||
|
||||
Bindings & autoArgs = *cmd.getAutoArgs(state);
|
||||
|
||||
Value * v = findAlongAttrPath(state, attrPath, autoArgs, *source);
|
||||
auto v = findAlongAttrPath(state, attrPath, autoArgs, *source).first;
|
||||
state.forceValue(*v);
|
||||
|
||||
return v;
|
||||
|
|
|
@ -145,7 +145,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
|
|||
auto v = state->allocValue();
|
||||
state->eval(state->parseExprFromString(*res.data, "/no-such-path"), *v);
|
||||
Bindings & bindings(*state->allocBindings(0));
|
||||
auto v2 = findAlongAttrPath(*state, settings.thisSystem, bindings, *v);
|
||||
auto v2 = findAlongAttrPath(*state, settings.thisSystem, bindings, *v).first;
|
||||
|
||||
return store->parseStorePath(state->forceString(*v2));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue