aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorBen Burdette <bburdette@gmail.com>2020-04-06 10:00:00 -0600
committerBen Burdette <bburdette@gmail.com>2020-04-06 10:00:00 -0600
commit216263c36f7827a1cf578627579f9cb074dc2749 (patch)
treef9cd590c619319be2b3116f03f1f369051797fcc /src/libexpr
parent1221ae3dd07959d47d9f27e9d2271671003d2bed (diff)
parentebb20a5356af023498506324bd0f88a99175e295 (diff)
Merge branch 'master' into error-format
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/attr-path.cc18
-rw-r--r--src/libexpr/attr-path.hh5
-rw-r--r--src/libexpr/attr-set.cc6
-rw-r--r--src/libexpr/eval.hh3
-rw-r--r--src/libexpr/function-trace.cc1
-rw-r--r--src/libexpr/local.mk2
-rw-r--r--src/libexpr/primops/fromTOML.cc2
7 files changed, 25 insertions, 12 deletions
diff --git a/src/libexpr/attr-path.cc b/src/libexpr/attr-path.cc
index 06b472d8b..76d101b98 100644
--- a/src/libexpr/attr-path.cc
+++ b/src/libexpr/attr-path.cc
@@ -32,15 +32,13 @@ 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);
- Error attrError =
- Error(format("attribute selection path '%1%' does not match expression") % attrPath);
-
Value * v = &vIn;
+ Pos pos = noPos;
for (auto & attr : tokens) {
@@ -70,8 +68,9 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
Bindings::iterator a = v->attrs->find(state.symbols.create(attr));
if (a == v->attrs->end())
- throw Error(format("attribute '%1%' in selection path '%2%' not found") % attr % attrPath);
+ throw AttrPathNotFound("attribute '%1%' in selection path '%2%' not found", attr, attrPath);
v = &*a->value;
+ pos = *a->pos;
}
else if (apType == apIndex) {
@@ -82,14 +81,15 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
% attrPath % showType(*v));
if (attrIndex >= v->listSize())
- throw Error(format("list index %1% in selection path '%2%' is out of range") % attrIndex % 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,9 +98,9 @@ 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);
+ throw NoPositionInfo("package '%s' has no source location information", what);
}
// FIXME: is it possible to extract the Pos object instead of doing this
diff --git a/src/libexpr/attr-path.hh b/src/libexpr/attr-path.hh
index 716e5ba27..fce160da7 100644
--- a/src/libexpr/attr-path.hh
+++ b/src/libexpr/attr-path.hh
@@ -7,7 +7,10 @@
namespace nix {
-Value * findAlongAttrPath(EvalState & state, const string & attrPath,
+MakeError(AttrPathNotFound, Error);
+MakeError(NoPositionInfo, Error);
+
+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. */
diff --git a/src/libexpr/attr-set.cc b/src/libexpr/attr-set.cc
index 0785897d2..b1d61a285 100644
--- a/src/libexpr/attr-set.cc
+++ b/src/libexpr/attr-set.cc
@@ -43,6 +43,12 @@ Value * EvalState::allocAttr(Value & vAttrs, const Symbol & name)
}
+Value * EvalState::allocAttr(Value & vAttrs, const std::string & name)
+{
+ return allocAttr(vAttrs, symbols.create(name));
+}
+
+
void Bindings::sort()
{
std::sort(begin(), end());
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index eac53b894..1485dc7fe 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -272,6 +272,7 @@ public:
Env & allocEnv(size_t size);
Value * allocAttr(Value & vAttrs, const Symbol & name);
+ Value * allocAttr(Value & vAttrs, const std::string & name);
Bindings * allocBindings(size_t capacity);
@@ -367,7 +368,7 @@ struct EvalSettings : Config
"Prefixes of URIs that builtin functions such as fetchurl and fetchGit are allowed to fetch."};
Setting<bool> traceFunctionCalls{this, false, "trace-function-calls",
- "Emit log messages for each function entry and exit at the 'vomit' log level (-vvvv)"};
+ "Emit log messages for each function entry and exit at the 'vomit' log level (-vvvv)."};
};
extern EvalSettings evalSettings;
diff --git a/src/libexpr/function-trace.cc b/src/libexpr/function-trace.cc
index af1486f78..c6057b384 100644
--- a/src/libexpr/function-trace.cc
+++ b/src/libexpr/function-trace.cc
@@ -1,4 +1,5 @@
#include "function-trace.hh"
+#include "logging.hh"
namespace nix {
diff --git a/src/libexpr/local.mk b/src/libexpr/local.mk
index 8a9b3c2ea..a4ccab376 100644
--- a/src/libexpr/local.mk
+++ b/src/libexpr/local.mk
@@ -6,6 +6,8 @@ libexpr_DIR := $(d)
libexpr_SOURCES := $(wildcard $(d)/*.cc) $(wildcard $(d)/primops/*.cc) $(d)/lexer-tab.cc $(d)/parser-tab.cc
+libexpr_CXXFLAGS += -I src/libutil -I src/libstore -I src/libmain -I src/libexpr
+
libexpr_LIBS = libutil libstore libnixrust
libexpr_LDFLAGS =
diff --git a/src/libexpr/primops/fromTOML.cc b/src/libexpr/primops/fromTOML.cc
index a84e569e9..c43324dbb 100644
--- a/src/libexpr/primops/fromTOML.cc
+++ b/src/libexpr/primops/fromTOML.cc
@@ -1,7 +1,7 @@
#include "primops.hh"
#include "eval-inline.hh"
-#include "cpptoml/cpptoml.h"
+#include "../../cpptoml/cpptoml.h"
namespace nix {