mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
exportReferencesGraph: Handle heterogeneous arrays
This barfed with error: [json.exception.type_error.302] type must be string, but is array on `nix build github:malt3/bazel-env#bazel-env` because it has a `exportReferencesGraph` with a value like `["string",...["string"]]`.
This commit is contained in:
parent
090f7fb05e
commit
94f410b628
3 changed files with 20 additions and 9 deletions
|
|
@ -99,6 +99,17 @@ DerivationOptions DerivationOptions::fromStructuredAttrs(
|
||||||
return fromStructuredAttrs(env, parsed ? &*parsed : nullptr);
|
return fromStructuredAttrs(env, parsed ? &*parsed : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void flatten(const nlohmann::json & value, StringSet & res)
|
||||||
|
{
|
||||||
|
if (value.is_array())
|
||||||
|
for (auto & v : value)
|
||||||
|
flatten(v, res);
|
||||||
|
else if (value.is_string())
|
||||||
|
res.insert(value);
|
||||||
|
else
|
||||||
|
throw Error("'exportReferencesGraph' value is not an array or a string");
|
||||||
|
}
|
||||||
|
|
||||||
DerivationOptions
|
DerivationOptions
|
||||||
DerivationOptions::fromStructuredAttrs(const StringMap & env, const StructuredAttrs * parsed, bool shouldWarn)
|
DerivationOptions::fromStructuredAttrs(const StringMap & env, const StructuredAttrs * parsed, bool shouldWarn)
|
||||||
{
|
{
|
||||||
|
|
@ -219,12 +230,9 @@ DerivationOptions::fromStructuredAttrs(const StringMap & env, const StructuredAt
|
||||||
if (!e || !e->is_object())
|
if (!e || !e->is_object())
|
||||||
return ret;
|
return ret;
|
||||||
for (auto & [key, value] : getObject(*e)) {
|
for (auto & [key, value] : getObject(*e)) {
|
||||||
if (value.is_array())
|
StringSet ss;
|
||||||
ret.insert_or_assign(key, value);
|
flatten(value, ss);
|
||||||
else if (value.is_string())
|
ret.insert_or_assign(key, std::move(ss));
|
||||||
ret.insert_or_assign(key, StringSet{value});
|
|
||||||
else
|
|
||||||
throw Error("'exportReferencesGraph' value is not an array or a string");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto s = getOr(env, "exportReferencesGraph", "");
|
auto s = getOr(env, "exportReferencesGraph", "");
|
||||||
|
|
|
||||||
|
|
@ -82,4 +82,8 @@ mkDerivation {
|
||||||
"foo$" = "BAD";
|
"foo$" = "BAD";
|
||||||
|
|
||||||
exportReferencesGraph.refs = [ dep ];
|
exportReferencesGraph.refs = [ dep ];
|
||||||
|
exportReferencesGraph.refs2 = [
|
||||||
|
dep
|
||||||
|
[ dep ]
|
||||||
|
]; # regression test for heterogeneous arrays
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
source common.sh
|
source common.sh
|
||||||
|
|
||||||
# 27ce722638 required some incompatible changes to the nix file, so skip this
|
# https://github.com/NixOS/nix/pull/14189
|
||||||
# tests for the older versions
|
requireDaemonNewerThan "2.33"
|
||||||
requireDaemonNewerThan "2.4pre20210712"
|
|
||||||
|
|
||||||
clearStoreIfPossible
|
clearStoreIfPossible
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue