mirror of
https://github.com/NixOS/nix.git
synced 2025-11-14 22:42:41 +01:00
Store StructuredAttrs directly in Derivation
Instead of parsing a structured attrs at some later point, we parsed it right away when parsing the A-Term format, and likewise serialize it to `__json = <JSON dump>` when serializing a derivation to A-Term. The JSON format can directly contain the JSON structured attrs without so encoding it, so we just do that.
This commit is contained in:
parent
b062730665
commit
8652b6b417
16 changed files with 177 additions and 109 deletions
|
|
@ -809,7 +809,7 @@ void DerivationBuilderImpl::startBuilder()
|
|||
writeStructuredAttrs();
|
||||
|
||||
/* Handle exportReferencesGraph(), if set. */
|
||||
if (!parsedDrv) {
|
||||
if (!drv.structuredAttrs) {
|
||||
for (auto & [fileName, ss] : drvOptions.exportReferencesGraph) {
|
||||
StorePathSet storePathSet;
|
||||
for (auto & storePathS : ss) {
|
||||
|
|
@ -1081,7 +1081,7 @@ void DerivationBuilderImpl::initEnv()
|
|||
/* In non-structured mode, set all bindings either directory in the
|
||||
environment or via a file, as specified by
|
||||
`DerivationOptions::passAsFile`. */
|
||||
if (!parsedDrv) {
|
||||
if (!drv.structuredAttrs) {
|
||||
for (auto & i : drv.env) {
|
||||
if (drvOptions.passAsFile.find(i.first) == drvOptions.passAsFile.end()) {
|
||||
env[i.first] = i.second;
|
||||
|
|
@ -1149,8 +1149,8 @@ void DerivationBuilderImpl::initEnv()
|
|||
|
||||
void DerivationBuilderImpl::writeStructuredAttrs()
|
||||
{
|
||||
if (parsedDrv) {
|
||||
auto json = parsedDrv->prepareStructuredAttrs(store, drvOptions, inputPaths, drv.outputs);
|
||||
if (drv.structuredAttrs) {
|
||||
auto json = drv.structuredAttrs->prepareStructuredAttrs(store, drvOptions, inputPaths, drv.outputs);
|
||||
nlohmann::json rewritten;
|
||||
for (auto & [i, v] : json["outputs"].get<nlohmann::json::object_t>()) {
|
||||
/* The placeholder must have a rewrite, so we use it to cover both the
|
||||
|
|
|
|||
|
|
@ -27,15 +27,6 @@ struct DerivationBuilderParams
|
|||
*/
|
||||
const Derivation & drv;
|
||||
|
||||
/**
|
||||
* The "structured attrs" of `drv`, if it has them.
|
||||
*
|
||||
* @todo this should be part of `Derivation`.
|
||||
*
|
||||
* @todo this should be renamed from `parsedDrv`.
|
||||
*/
|
||||
const StructuredAttrs * parsedDrv;
|
||||
|
||||
/**
|
||||
* The derivation options of `drv`.
|
||||
*
|
||||
|
|
@ -63,14 +54,12 @@ struct DerivationBuilderParams
|
|||
const BuildMode & buildMode,
|
||||
BuildResult & buildResult,
|
||||
const Derivation & drv,
|
||||
const StructuredAttrs * parsedDrv,
|
||||
const DerivationOptions & drvOptions,
|
||||
const StorePathSet & inputPaths,
|
||||
std::map<std::string, InitialOutput> & initialOutputs)
|
||||
: drvPath{drvPath}
|
||||
, buildResult{buildResult}
|
||||
, drv{drv}
|
||||
, parsedDrv{parsedDrv}
|
||||
, drvOptions{drvOptions}
|
||||
, inputPaths{inputPaths}
|
||||
, initialOutputs{initialOutputs}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue