Skip to content

Commit

Permalink
Move writeStructuredAttrsShell out of ParsedDerivation class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma27 committed Jun 22, 2021
1 parent 27ce722 commit 6f20654
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/libstore/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
12 changes: 6 additions & 6 deletions src/libstore/parsed-derivations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion src/libstore/parsed-derivations.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
3 changes: 3 additions & 0 deletions src/libstore/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/nix-build/nix-build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 6f20654

Please sign in to comment.