From 986a8f6b75ffa51682cbe730c5c2907296082cd4 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 22 May 2020 01:58:12 +0100 Subject: fix(3p/nix): Update for usage of new attribute set API 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. --- third_party/nix/src/libexpr/primops/context.cc | 51 +++++++++++++------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'third_party/nix/src/libexpr/primops/context.cc') diff --git a/third_party/nix/src/libexpr/primops/context.cc b/third_party/nix/src/libexpr/primops/context.cc index efc94d91ced8..1661ffbe2e88 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)); } } } -- cgit 1.4.1