diff options
-rw-r--r-- | src/libcmd/repl.cc | 4 | ||||
-rw-r--r-- | src/libexpr/eval.cc | 17 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 5 | ||||
-rw-r--r-- | src/libexpr/flake/flake.cc | 2 | ||||
-rw-r--r-- | src/libexpr/nixexpr.cc | 6 | ||||
-rw-r--r-- | src/libexpr/nixexpr.hh | 2 | ||||
-rw-r--r-- | src/libexpr/parser.y | 2 | ||||
-rw-r--r-- | src/libexpr/primops.cc | 3 | ||||
-rw-r--r-- | src/libexpr/value-to-xml.cc | 4 |
9 files changed, 22 insertions, 23 deletions
diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 9002fa555..c7fd0db91 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -594,8 +594,8 @@ bool NixRepl::processLine(std::string line) return {path, 0}; } else if (v.isLambda()) { auto pos = state->positions[v.lambda.fun->pos]; - if (auto path = std::get_if<Path>(&pos.origin)) - return {SourcePath(CanonPath(*path)), pos.line}; + if (auto path = std::get_if<SourcePath>(&pos.origin)) + return {*path, pos.line}; else throw Error("'%s' cannot be shown in an editor", pos); } else { diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 3b2877602..dec123b69 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -499,6 +499,7 @@ EvalState::EvalState( , sOutputSpecified(symbols.create("outputSpecified")) , repair(NoRepair) , emptyBindings(0) + , derivationInternal(rootPath(CanonPath("/builtin/derivation.nix"))) , store(store) , buildStore(buildStore ? buildStore : store) , debugRepl(nullptr) @@ -991,9 +992,9 @@ void EvalState::mkThunk_(Value & v, Expr * expr) void EvalState::mkPos(Value & v, PosIdx p) { auto pos = positions[p]; - if (auto path = std::get_if<Path>(&pos.origin)) { + if (auto path = std::get_if<SourcePath>(&pos.origin)) { auto attrs = buildBindings(3); - attrs.alloc(sFile).mkString(*path); + attrs.alloc(sFile).mkString(path->path.abs()); attrs.alloc(sLine).mkInt(pos.line); attrs.alloc(sColumn).mkInt(pos.column); v.mkAttrs(attrs); @@ -1373,8 +1374,8 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v) } catch (Error & e) { if (pos2) { auto pos2r = state.positions[pos2]; - auto origin = std::get_if<Path>(&pos2r.origin); - if (!(origin && *origin == state.derivationNixPath)) + auto origin = std::get_if<SourcePath>(&pos2r.origin); + if (!(origin && *origin == state.derivationInternal)) state.addErrorTrace(e, pos2, "while evaluating the attribute '%1%'", showAttrPath(state, env, attrPath)); } @@ -2417,8 +2418,8 @@ void EvalState::printStats() else obj["name"] = nullptr; if (auto pos = positions[fun->pos]) { - if (auto path = std::get_if<Path>(&pos.origin)) - obj["file"] = *path; + if (auto path = std::get_if<SourcePath>(&pos.origin)) + obj["file"] = path->to_string(); obj["line"] = pos.line; obj["column"] = pos.column; } @@ -2432,8 +2433,8 @@ void EvalState::printStats() for (auto & i : attrSelects) { json obj = json::object(); if (auto pos = positions[i.first]) { - if (auto path = std::get_if<Path>(&pos.origin)) - obj["file"] = *path; + if (auto path = std::get_if<SourcePath>(&pos.origin)) + obj["file"] = path->to_string(); obj["line"] = pos.line; obj["column"] = pos.column; } diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 1e8f8391c..b9578321f 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -127,8 +127,6 @@ public: SymbolTable symbols; PosTable positions; - static inline std::string derivationNixPath = "//builtin/derivation.nix"; - const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName, sValue, sSystem, sOverrides, sOutputs, sOutputName, sIgnoreNulls, sFile, sLine, sColumn, sFunctor, sToString, @@ -139,7 +137,6 @@ public: sDescription, sSelf, sEpsilon, sStartSet, sOperator, sKey, sPath, sPrefix, sOutputSpecified; - Symbol sDerivationNix; /* If set, force copying files to the Nix store even if they already exist there. */ @@ -151,6 +148,8 @@ public: Bindings emptyBindings; + const SourcePath derivationInternal; + /* Store used to materialise .drv files. */ const ref<Store> store; diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 2b858ee98..4c571fd7d 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -220,7 +220,7 @@ static Flake getFlake( Value vInfo; state.evalFile(CanonPath(flakeFile), vInfo, true); // FIXME: symlink attack - expectType(state, nAttrs, vInfo, state.positions.add({flakeFile}, 1, 1)); + expectType(state, nAttrs, vInfo, state.positions.add({CanonPath(flakeFile)}, 1, 1)); if (auto description = vInfo.attrs->get(state.sDescription)) { expectType(state, nString, *description->value, description->pos); diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index eb6f062b4..2c9d5754e 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -31,9 +31,9 @@ struct PosAdapter : AbstractPos // Get rid of the null terminators added by the parser. return std::string(s.source->c_str()); }, - [](const Path & path) -> std::optional<std::string> { + [](const SourcePath & path) -> std::optional<std::string> { try { - return readFile(path); + return path.readFile(); } catch (Error &) { return std::nullopt; } @@ -47,7 +47,7 @@ struct PosAdapter : AbstractPos [&](const Pos::none_tag &) { out << "«none»"; }, [&](const Pos::Stdin &) { out << "«stdin»"; }, [&](const Pos::String & s) { out << "«string»"; }, - [&](const Path & path) { out << path; } + [&](const SourcePath & path) { out << path; } }, origin); } }; diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 4079a7b24..d70280582 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -32,7 +32,7 @@ struct Pos struct Stdin { ref<std::string> source; }; struct String { ref<std::string> source; }; - typedef std::variant<none_tag, Stdin, String, Path> Origin; + typedef std::variant<none_tag, Stdin, String, SourcePath> Origin; Origin origin; diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 8b67665db..4d981712a 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -700,7 +700,7 @@ Expr * EvalState::parseExprFromFile(const SourcePath & path, std::shared_ptr<Sta auto buffer = path.readFile(); // readFile hopefully have left some extra space for terminators buffer.append("\0\0", 2); - return parse(buffer.data(), buffer.size(), path.path.abs(), path.parent(), staticEnv); + return parse(buffer.data(), buffer.size(), Pos::Origin(path), path.parent(), staticEnv); } diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index c77d45bd3..7c34e93ad 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -4136,7 +4136,6 @@ void EvalState::createBaseEnv() /* Add a wrapper around the derivation primop that computes the `drvPath' and `outPath' attributes lazily. */ - sDerivationNix = symbols.create(derivationNixPath); auto vDerivation = allocValue(); addConstant("derivation", vDerivation); @@ -4153,7 +4152,7 @@ void EvalState::createBaseEnv() // the parser needs two NUL bytes as terminators; one of them // is implied by being a C string. "\0"; - eval(parse(code, sizeof(code), derivationNixPath, {CanonPath::root}, staticBaseEnv), *vDerivation); + eval(parse(code, sizeof(code), derivationInternal, {CanonPath::root}, staticBaseEnv), *vDerivation); } diff --git a/src/libexpr/value-to-xml.cc b/src/libexpr/value-to-xml.cc index a9fcb803e..4e87ac4b6 100644 --- a/src/libexpr/value-to-xml.cc +++ b/src/libexpr/value-to-xml.cc @@ -24,8 +24,8 @@ static void printValueAsXML(EvalState & state, bool strict, bool location, static void posToXML(EvalState & state, XMLAttrs & xmlAttrs, const Pos & pos) { - if (auto path = std::get_if<Path>(&pos.origin)) - xmlAttrs["path"] = *path; + if (auto path = std::get_if<SourcePath>(&pos.origin)) + xmlAttrs["path"] = path->path.abs(); xmlAttrs["line"] = fmt("%1%", pos.line); xmlAttrs["column"] = fmt("%1%", pos.column); } |