-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Introduce top-level structuredAttrs
field in JSON derivation format
#13349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1333,6 +1333,11 @@ nlohmann::json Derivation::toJSON(const StoreDirConfig & store) const | |
res["args"] = args; | ||
res["env"] = env; | ||
|
||
if (auto it = env.find("__json"); it != env.end()) { | ||
res["env"].erase("__json"); | ||
res["structuredAttrs"] = nlohmann::json::parse(it->second); | ||
} | ||
|
||
return res; | ||
} | ||
|
||
|
@@ -1396,7 +1401,17 @@ Derivation Derivation::fromJSON( | |
res.platform = getString(valueAt(json, "system")); | ||
res.builder = getString(valueAt(json, "builder")); | ||
res.args = getStringList(valueAt(json, "args")); | ||
res.env = getStringMap(valueAt(json, "env")); | ||
|
||
auto envJson = valueAt(json, "env"); | ||
try { | ||
res.env = getStringMap(envJson); | ||
} catch (Error & e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it catch exceptions for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It probably should do this for all of these, to the extent that we care about nice errors. There might be a closure-based way to do this more tersely. |
||
e.addTrace({}, "while reading key 'env'"); | ||
throw; | ||
} | ||
|
||
if (auto structuredAttrs = get(json, "structuredAttrs")) | ||
res.env.insert_or_assign("__json", structuredAttrs->dump()); | ||
|
||
return res; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't do this, because the iterator is for
env
, but we're deleting inres["env"]
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that when reading now too :). Only noticed after I got the compiler error.