libexpr: move resolveExprPath to EvalPaths
Change-Id: I4f8e27bb816d6498df4d73a57e10b654eb995c32
This commit is contained in:
committed by
Jade Lovelace
parent
5af069b248
commit
ede0851fb4
@@ -253,8 +253,12 @@ static void main_nix_build(std::string programName, Strings argv)
|
||||
else
|
||||
/* If we're in a #! script, interpret filenames
|
||||
relative to the script. */
|
||||
exprs.push_back(evaluator->parseExprFromFile(resolveExprPath(evaluator->paths.checkSourcePath(lookupFileArg(*evaluator,
|
||||
inShebang && !packages ? absPath(i, absPath(dirOf(script))) : i)))));
|
||||
exprs.push_back(evaluator->parseExprFromFile(evaluator->paths.resolveExprPath(
|
||||
evaluator->paths.checkSourcePath(lookupFileArg(
|
||||
*evaluator,
|
||||
inShebang && !packages ? absPath(i, absPath(dirOf(script))) : i
|
||||
))
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ static int main_nix_instantiate(std::string programName, Strings argv)
|
||||
for (auto & i : files) {
|
||||
Expr & e = fromArgs
|
||||
? evaluator->parseExprFromString(i, CanonPath::fromCwd())
|
||||
: evaluator->parseExprFromFile(resolveExprPath(evaluator->paths.checkSourcePath(lookupFileArg(*evaluator, i))));
|
||||
: evaluator->parseExprFromFile(evaluator->paths.resolveExprPath(evaluator->paths.checkSourcePath(lookupFileArg(*evaluator, i))));
|
||||
processExpr(*state, attrPaths, parseOnly, strict, autoArgs,
|
||||
evalOnly, outputKind, xmlOutputSourceLocation, e);
|
||||
}
|
||||
|
||||
@@ -214,9 +214,9 @@ void SourceExprCommand::completeInstallable(EvalState & state, AddCompletions &
|
||||
|
||||
auto evaluator = getEvaluator();
|
||||
|
||||
Expr & e = evaluator->parseExprFromFile(
|
||||
resolveExprPath(evaluator->paths.checkSourcePath(lookupFileArg(*evaluator, *file)))
|
||||
);
|
||||
Expr & e = evaluator->parseExprFromFile(evaluator->paths.resolveExprPath(
|
||||
evaluator->paths.checkSourcePath(lookupFileArg(*evaluator, *file))
|
||||
));
|
||||
|
||||
Value root;
|
||||
state.eval(e, root);
|
||||
|
||||
+2
-2
@@ -951,7 +951,7 @@ void EvalState::evalFile(const SourcePath & path_, Value & v)
|
||||
return;
|
||||
}
|
||||
|
||||
auto resolvedPath = resolveExprPath(path);
|
||||
auto resolvedPath = ctx.paths.resolveExprPath(path);
|
||||
if (auto i = ctx.caches.fileEval.find(resolvedPath); i != ctx.caches.fileEval.end()) {
|
||||
v = i->second->result;
|
||||
return;
|
||||
@@ -2661,7 +2661,7 @@ void Evaluator::printStatistics()
|
||||
}
|
||||
|
||||
|
||||
SourcePath resolveExprPath(SourcePath path)
|
||||
SourcePath EvalPaths::resolveExprPath(SourcePath path)
|
||||
{
|
||||
unsigned int followCount = 0, maxFollow = 1024;
|
||||
|
||||
|
||||
+5
-5
@@ -418,6 +418,11 @@ public:
|
||||
*/
|
||||
SourcePath checkSourcePath(const SourcePath & path);
|
||||
|
||||
/**
|
||||
* If `path` refers to a directory, then append "/default.nix".
|
||||
*/
|
||||
SourcePath resolveExprPath(SourcePath path);
|
||||
|
||||
void checkURI(const std::string & uri);
|
||||
|
||||
/**
|
||||
@@ -848,11 +853,6 @@ private:
|
||||
std::string_view showType(ValueType type, bool withArticle = true);
|
||||
std::string showType(const Value & v);
|
||||
|
||||
/**
|
||||
* If `path` refers to a directory, then append "/default.nix".
|
||||
*/
|
||||
SourcePath resolveExprPath(SourcePath path);
|
||||
|
||||
static constexpr std::string_view corepkgsPrefix{"/__corepkgs__/"};
|
||||
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ static Flake getFlake(
|
||||
};
|
||||
|
||||
// FIXME: symlink attack
|
||||
auto resolvedFlakeFile = resolveExprPath(state.ctx.paths.checkSourcePath(CanonPath(flakeFile)));
|
||||
auto resolvedFlakeFile = state.ctx.paths.resolveExprPath(state.ctx.paths.checkSourcePath(CanonPath(flakeFile)));
|
||||
Expr & flakeExpr = state.ctx.parseExprFromFile(state.ctx.paths.checkSourcePath(resolvedFlakeFile));
|
||||
|
||||
// Enforce that 'flake.nix' is a direct attrset, not a computation.
|
||||
|
||||
@@ -251,7 +251,7 @@ static void import(EvalState & state, const PosIdx pos, Value & vPath, Value * v
|
||||
// args[0]->attrs is already sorted.
|
||||
|
||||
debug("evaluating file '%1%'", path);
|
||||
Expr & e = state.ctx.parseExprFromFile(resolveExprPath(path), staticEnv);
|
||||
Expr & e = state.ctx.parseExprFromFile(state.ctx.paths.resolveExprPath(path), staticEnv);
|
||||
|
||||
e.eval(state, *env, v);
|
||||
}
|
||||
|
||||
+1
-1
@@ -201,7 +201,7 @@ static int main_nix_prefetch_url(std::string programName, Strings argv)
|
||||
} else {
|
||||
Value vRoot;
|
||||
state->evalFile(
|
||||
resolveExprPath(
|
||||
evaluator->paths.resolveExprPath(
|
||||
lookupFileArg(*evaluator, args.empty() ? "." : args[0])),
|
||||
vRoot);
|
||||
Value & v(*findAlongAttrPath(*state, attrPath, autoArgs, vRoot).first);
|
||||
|
||||
Reference in New Issue
Block a user