aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2021-05-13 16:11:56 +0200
committerMaximilian Bosch <maximilian@mbosch.me>2021-06-22 19:15:57 +0200
commitf1e281c4fe1263a0c848bc8aaf57a0e61a99fa93 (patch)
tree0441e2eb826aad0530f7c6522a355ad332b9581f /src/libstore
parent447928bdb55d160617387e7ac5954f9a8f36004b (diff)
Split shell & json creation for build environments with structured attrs
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/build/local-derivation-goal.cc7
-rw-r--r--src/libstore/parsed-derivations.cc10
-rw-r--r--src/libstore/parsed-derivations.hh3
3 files changed, 12 insertions, 8 deletions
diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc
index e6b552b94..60495ae3e 100644
--- a/src/libstore/build/local-derivation-goal.cc
+++ b/src/libstore/build/local-derivation-goal.cc
@@ -1086,10 +1086,9 @@ void LocalDerivationGoal::initEnv()
void LocalDerivationGoal::writeStructuredAttrs()
{
- if (auto structAttrs = parsedDrv->generateStructuredAttrs(inputRewrites, worker.store, inputPaths)) {
- auto value = structAttrs.value();
- auto jsonSh = value.first;
- auto json = value.second;
+ if (auto structAttrsJson = parsedDrv->prepareStructuredAttrs(inputRewrites, worker.store, inputPaths)) {
+ auto json = structAttrsJson.value();
+ auto jsonSh = parsedDrv->writeStructuredAttrsShell(json);
writeFile(tmpDir + "/.attrs.sh", rewriteStrings(jsonSh, inputRewrites));
chownToBuilder(tmpDir + "/.attrs.sh");
diff --git a/src/libstore/parsed-derivations.cc b/src/libstore/parsed-derivations.cc
index 029da8bd3..5675600c4 100644
--- a/src/libstore/parsed-derivations.cc
+++ b/src/libstore/parsed-derivations.cc
@@ -124,8 +124,7 @@ bool ParsedDerivation::substitutesAllowed() const
}
static std::regex shVarName("[A-Za-z_][A-Za-z0-9_]*");
-std::optional<StructuredAttrsWithShellRC> ParsedDerivation::generateStructuredAttrs(
- std::optional<StringMap> inputRewrites, Store & store, const StorePathSet & inputPaths)
+std::optional<nlohmann::json> ParsedDerivation::prepareStructuredAttrs(std::optional<StringMap> inputRewrites, Store & store, const StorePathSet & inputPaths)
{
auto structuredAttrs = getStructuredAttrs();
if (!structuredAttrs) return std::nullopt;
@@ -163,6 +162,11 @@ std::optional<StructuredAttrsWithShellRC> ParsedDerivation::generateStructuredAt
}
}
+ return json;
+}
+
+std::string ParsedDerivation::writeStructuredAttrsShell(nlohmann::json & json)
+{
/* As a convenience to bash scripts, write a shell file that
maps all attributes that are representable in bash -
namely, strings, integers, nulls, Booleans, and arrays and
@@ -229,6 +233,6 @@ std::optional<StructuredAttrsWithShellRC> ParsedDerivation::generateStructuredAt
}
}
- return std::make_pair(jsonSh, json);
+ return jsonSh;
}
}
diff --git a/src/libstore/parsed-derivations.hh b/src/libstore/parsed-derivations.hh
index 4b8b8c8ff..37af36630 100644
--- a/src/libstore/parsed-derivations.hh
+++ b/src/libstore/parsed-derivations.hh
@@ -39,7 +39,8 @@ public:
bool substitutesAllowed() const;
- std::optional<StructuredAttrsWithShellRC> generateStructuredAttrs(std::optional<StringMap> inputRewrites, Store & store, const StorePathSet & inputPaths);
+ std::optional<nlohmann::json> prepareStructuredAttrs(std::optional<StringMap> inputRewrites, Store & store, const StorePathSet & inputPaths);
+ std::string writeStructuredAttrsShell(nlohmann::json & json);
};
}