Move writeStructuredAttrsShell out of ParsedDerivation class

This commit is contained in:
Maximilian Bosch 2021-06-22 20:37:25 +02:00
parent 27ce722638
commit 6f206549ba
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E
5 changed files with 13 additions and 9 deletions

View file

@ -1088,7 +1088,7 @@ void LocalDerivationGoal::writeStructuredAttrs()
{
if (auto structAttrsJson = parsedDrv->prepareStructuredAttrs(inputRewrites, worker.store, inputPaths)) {
auto json = structAttrsJson.value();
auto jsonSh = parsedDrv->writeStructuredAttrsShell(json);
auto jsonSh = writeStructuredAttrsShell(json);
writeFile(tmpDir + "/.attrs.sh", rewriteStrings(jsonSh, inputRewrites));
chownToBuilder(tmpDir + "/.attrs.sh");

View file

@ -165,13 +165,13 @@ std::optional<nlohmann::json> ParsedDerivation::prepareStructuredAttrs(std::opti
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
objects consisting entirely of those values. (So nested
arrays or objects are not supported.) */
std::string 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
objects consisting entirely of those values. (So nested
arrays or objects are not supported.) */
auto handleSimpleType = [](const nlohmann::json & value) -> std::optional<std::string> {
if (value.is_string())

View file

@ -38,7 +38,8 @@ public:
bool substitutesAllowed() const;
std::optional<nlohmann::json> prepareStructuredAttrs(std::optional<StringMap> inputRewrites, Store & store, const StorePathSet & inputPaths);
std::string writeStructuredAttrsShell(nlohmann::json & json);
};
std::string writeStructuredAttrsShell(nlohmann::json & json);
}

View file

@ -695,6 +695,9 @@ public:
const Stats & getStats();
/* Computes the full closure of of a set of store-paths for e.g.
derivations that need this information for `exportReferencesGraph`.
*/
StorePathSet exportReferences(const StorePathSet & storePaths, const StorePathSet & inputPaths);
/* Return the build log of the specified store path, if available,

View file

@ -446,7 +446,7 @@ static void main_nix_build(int argc, char * * argv)
if (auto structAttrs = parsedDrv.prepareStructuredAttrs(std::nullopt, *store, inputs)) {
auto json = structAttrs.value();
structuredAttrsRC = parsedDrv.writeStructuredAttrsShell(json);
structuredAttrsRC = writeStructuredAttrsShell(json);
auto attrsJSON = (Path) tmpDir + "/.attrs.json";
writeFile(attrsJSON, json.dump());