From cb8126538f1a7ee37eeae895a683d81d37305447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 9 Sep 2022 11:26:15 +0000 Subject: [PATCH] fix recurseIntoAttrs handling --- src/nix-eval-jobs.cc | 85 +++++++++++++++++++++----------------------- tests/test_eval.py | 7 ++-- 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/src/nix-eval-jobs.cc b/src/nix-eval-jobs.cc index 8544b15..68b6416 100644 --- a/src/nix-eval-jobs.cc +++ b/src/nix-eval-jobs.cc @@ -297,60 +297,55 @@ static void worker(EvalState &state, Bindings &autoArgs, AutoCloseFD &to, auto v = state.allocValue(); state.autoCallFunction(autoArgs, *vTmp, *v); - if (auto drvInfo = getDerivation(state, *v, false)) { + if (v->type() == nAttrs) { + if (auto drvInfo = getDerivation(state, *v, false)) { + auto drv = Drv(state, *drvInfo); + reply.update(drv); - auto drv = Drv(state, *drvInfo); - reply.update(drv); - - /* Register the derivation as a GC root. !!! This - registers roots for jobs that we may have already - done. */ - if (myArgs.gcRootsDir != "") { - Path root = myArgs.gcRootsDir + "/" + - std::string(baseNameOf(drv.drvPath)); - if (!pathExists(root)) { - auto localStore = - state.store.dynamic_pointer_cast(); - auto storePath = - localStore->parseStorePath(drv.drvPath); - localStore->addPermRoot(storePath, root); + /* Register the derivation as a GC root. !!! This + registers roots for jobs that we may have already + done. */ + if (myArgs.gcRootsDir != "") { + Path root = myArgs.gcRootsDir + "/" + + std::string(baseNameOf(drv.drvPath)); + if (!pathExists(root)) { + auto localStore = + state.store + .dynamic_pointer_cast(); + auto storePath = + localStore->parseStorePath(drv.drvPath); + localStore->addPermRoot(storePath, root); + } } - } + } else { + auto attrs = nlohmann::json::array(); + bool recurse = + path.size() == 0; // Dont require `recurseForDerivations + // = true;` for top-level attrset - } + for (auto &i : + v->attrs->lexicographicOrder(state.symbols)) { + const std::string &name = state.symbols[i->name]; + attrs.push_back(name); - else if (v->type() == nAttrs) { - auto attrs = nlohmann::json::array(); - bool recurse = - path.size() == 0; // Dont require `recurseForDerivations = - // true;` for top-level attrset - - for (auto &i : v->attrs->lexicographicOrder(state.symbols)) { - const std::string &name = state.symbols[i->name]; - attrs.push_back(name); - - if (name == "recurseForDerivations") { - auto attrv = - v->attrs->get(state.sRecurseForDerivations); - recurse = state.forceBool(*attrv->value, attrv->pos); + if (name == "recurseForDerivations") { + auto attrv = + v->attrs->get(state.sRecurseForDerivations); + recurse = + state.forceBool(*attrv->value, attrv->pos); + } } + if (recurse) + reply["attrs"] = std::move(attrs); + else + reply["attrs"] = nlohmann::json::array(); } - if (recurse) - reply["attrs"] = std::move(attrs); - else - reply["attrs"] = nlohmann::json::array(); + } else { + // We ignore everything that cannot be build + reply["attrs"] = nlohmann::json::array(); } - - else if (v->type() == nNull) - ; - - else - throw TypeError("attribute '%s' is %s, which is not supported", - path, showType(*v)); - } catch (EvalError &e) { auto err = e.info(); - std::ostringstream oss; showErrorInfo(oss, err, loggerSettings.showTrace.get()); auto msg = oss.str(); diff --git a/tests/test_eval.py b/tests/test_eval.py index 5cdad3b..a08332e 100644 --- a/tests/test_eval.py +++ b/tests/test_eval.py @@ -23,7 +23,7 @@ def common_test(extra_args: List[str]) -> List[Dict[str, Any]]: ) results = [json.loads(r) for r in res.stdout.split("\n") if r] - assert len(results) == 5 + assert len(results) == 4 built_job = results[0] assert built_job["attr"] == "builtJob" @@ -40,10 +40,7 @@ def common_test(extra_args: List[str]) -> List[Dict[str, Any]]: assert recurse_drv["attr"] == "recurse.drvB" assert recurse_drv["name"] == "drvB" - recurse_recurse_bool = results[3] - assert "error" in recurse_recurse_bool - - substituted_job = results[4] + substituted_job = results[3] assert substituted_job["attr"] == "substitutedJob" assert substituted_job["name"].startswith("hello-") assert substituted_job["meta"]["broken"] is False