From ede0851fb4fd31a6974c41900e4aa66778b5be58 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 17 Dec 2024 16:25:00 +0100 Subject: [PATCH] libexpr: move resolveExprPath to EvalPaths Change-Id: I4f8e27bb816d6498df4d73a57e10b654eb995c32 --- lix/legacy/nix-build.cc | 8 ++++++-- lix/legacy/nix-instantiate.cc | 2 +- lix/libcmd/installables.cc | 6 +++--- lix/libexpr/eval.cc | 4 ++-- lix/libexpr/eval.hh | 10 +++++----- lix/libexpr/flake/flake.cc | 2 +- lix/libexpr/primops.cc | 2 +- lix/nix/prefetch.cc | 2 +- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lix/legacy/nix-build.cc b/lix/legacy/nix-build.cc index 0642a995b..dae707379 100644 --- a/lix/legacy/nix-build.cc +++ b/lix/legacy/nix-build.cc @@ -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 + )) + ))); } } diff --git a/lix/legacy/nix-instantiate.cc b/lix/legacy/nix-instantiate.cc index 57653f8ab..688201f2f 100644 --- a/lix/legacy/nix-instantiate.cc +++ b/lix/legacy/nix-instantiate.cc @@ -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); } diff --git a/lix/libcmd/installables.cc b/lix/libcmd/installables.cc index 9970d4319..33a3acb4e 100644 --- a/lix/libcmd/installables.cc +++ b/lix/libcmd/installables.cc @@ -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); diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 4dee03c79..da660d75a 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -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; diff --git a/lix/libexpr/eval.hh b/lix/libexpr/eval.hh index b391f68f8..bb87add5d 100644 --- a/lix/libexpr/eval.hh +++ b/lix/libexpr/eval.hh @@ -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__/"}; diff --git a/lix/libexpr/flake/flake.cc b/lix/libexpr/flake/flake.cc index 8ccdf7373..653ee56d1 100644 --- a/lix/libexpr/flake/flake.cc +++ b/lix/libexpr/flake/flake.cc @@ -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. diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index e2bddcd15..8ce50bf1a 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -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); } diff --git a/lix/nix/prefetch.cc b/lix/nix/prefetch.cc index 9457ad797..c45caa063 100644 --- a/lix/nix/prefetch.cc +++ b/lix/nix/prefetch.cc @@ -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);