about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr/primops
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-22T00·58+0100
committerVincent Ambo <tazjin@google.com>2020-05-22T00·59+0100
commit986a8f6b75ffa51682cbe730c5c2907296082cd4 (patch)
tree32c266920223bbfbf0beb49689dc05cb8eb1f2b7 /third_party/nix/src/libexpr/primops
parent42205f27fc820ddc64616d55c04e2ffde1948043 (diff)
fix(3p/nix): Update for usage of new attribute set API r/802
The new attribute set API uses the iterators of the btree_map
directly. This requires changes in various files because the internals
of libexpr are very entangled.

This code runs and compiles, but there is a bug causing empty
attribute sets to be assigned incorrectly.
Diffstat (limited to 'third_party/nix/src/libexpr/primops')
-rw-r--r--third_party/nix/src/libexpr/primops/context.cc51
-rw-r--r--third_party/nix/src/libexpr/primops/fetchGit.cc3
-rw-r--r--third_party/nix/src/libexpr/primops/fetchMercurial.cc3
3 files changed, 30 insertions, 27 deletions
diff --git a/third_party/nix/src/libexpr/primops/context.cc b/third_party/nix/src/libexpr/primops/context.cc
index efc94d91ce..1661ffbe2e 100644
--- a/third_party/nix/src/libexpr/primops/context.cc
+++ b/third_party/nix/src/libexpr/primops/context.cc
@@ -147,47 +147,48 @@ static void prim_appendContext(EvalState& state, const Pos& pos, Value** args,
 
   auto sPath = state.symbols.Create("path");
   auto sAllOutputs = state.symbols.Create("allOutputs");
-  for (auto& i : *args[1]->attrs) {
-    if (!state.store->isStorePath(i.name))
-      throw EvalError("Context key '%s' is not a store path, at %s", i.name,
-                      i.pos);
+  for (const auto& attr_iter : *args[1]->attrs) {
+    const Attr* i = &attr_iter.second;  // TODO(tazjin): get rid of this
+    if (!state.store->isStorePath(i->name))
+      throw EvalError("Context key '%s' is not a store path, at %s", i->name,
+                      i->pos);
     if (!settings.readOnlyMode) {
-      state.store->ensurePath(i.name);
+      state.store->ensurePath(i->name);
     }
-    state.forceAttrs(*i.value, *i.pos);
-    auto iter = i.value->attrs->find(sPath);
-    if (iter != i.value->attrs->end()) {
-      if (state.forceBool(*iter->value, *iter->pos)) {
-        context.insert(i.name);
+    state.forceAttrs(*i->value, *i->pos);
+    auto iter = i->value->attrs->find(sPath);
+    if (iter != i->value->attrs->end()) {
+      if (state.forceBool(*iter->second.value, *iter->second.pos)) {
+        context.insert(i->name);
       }
     }
 
-    iter = i.value->attrs->find(sAllOutputs);
-    if (iter != i.value->attrs->end()) {
-      if (state.forceBool(*iter->value, *iter->pos)) {
-        if (!isDerivation(i.name)) {
+    iter = i->value->attrs->find(sAllOutputs);
+    if (iter != i->value->attrs->end()) {
+      if (state.forceBool(*iter->second.value, *iter->second.pos)) {
+        if (!isDerivation(i->name)) {
           throw EvalError(
               "Tried to add all-outputs context of %s, which is not a "
               "derivation, to a string, at %s",
-              i.name, i.pos);
+              i->name, i->pos);
         }
-        context.insert("=" + string(i.name));
+        context.insert("=" + string(i->name));
       }
     }
 
-    iter = i.value->attrs->find(state.sOutputs);
-    if (iter != i.value->attrs->end()) {
-      state.forceList(*iter->value, *iter->pos);
-      if (iter->value->listSize() && !isDerivation(i.name)) {
+    iter = i->value->attrs->find(state.sOutputs);
+    if (iter != i->value->attrs->end()) {
+      state.forceList(*iter->second.value, *iter->second.pos);
+      if (iter->second.value->listSize() && !isDerivation(i->name)) {
         throw EvalError(
             "Tried to add derivation output context of %s, which is not a "
             "derivation, to a string, at %s",
-            i.name, i.pos);
+            i->name, i->pos);
       }
-      for (unsigned int n = 0; n < iter->value->listSize(); ++n) {
-        auto name =
-            state.forceStringNoCtx(*iter->value->listElems()[n], *iter->pos);
-        context.insert("!" + name + "!" + string(i.name));
+      for (unsigned int n = 0; n < iter->second.value->listSize(); ++n) {
+        auto name = state.forceStringNoCtx(*iter->second.value->listElems()[n],
+                                           *iter->second.pos);
+        context.insert("!" + name + "!" + string(i->name));
       }
     }
   }
diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc
index 7ef3dea8ee..cb4c008cdd 100644
--- a/third_party/nix/src/libexpr/primops/fetchGit.cc
+++ b/third_party/nix/src/libexpr/primops/fetchGit.cc
@@ -214,7 +214,8 @@ static void prim_fetchGit(EvalState& state, const Pos& pos, Value** args,
   if (args[0]->type == tAttrs) {
     state.forceAttrs(*args[0], pos);
 
-    for (auto& attr : *args[0]->attrs) {
+    for (auto& attr_iter : *args[0]->attrs) {
+      auto& attr = attr_iter.second;
       std::string n(attr.name);
       if (n == "url")
         url =
diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
index 4205442c73..1e7064f97d 100644
--- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc
+++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
@@ -190,7 +190,8 @@ static void prim_fetchMercurial(EvalState& state, const Pos& pos, Value** args,
   if (args[0]->type == tAttrs) {
     state.forceAttrs(*args[0], pos);
 
-    for (auto& attr : *args[0]->attrs) {
+    for (auto& attr_iter : *args[0]->attrs) {
+      auto& attr = attr_iter.second;
       std::string n(attr.name);
       if (n == "url")
         url =