From 6f206549ba02c6f9bdbf9707bba9193a1d82e822 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 22 Jun 2021 20:37:25 +0200 Subject: [PATCH] Move `writeStructuredAttrsShell` out of `ParsedDerivation` class --- src/libstore/build/local-derivation-goal.cc | 2 +- src/libstore/parsed-derivations.cc | 12 ++++++------ src/libstore/parsed-derivations.hh | 3 ++- src/libstore/store-api.hh | 3 +++ src/nix-build/nix-build.cc | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc index de64737f4..15a7cb4ac 100644 --- a/src/libstore/build/local-derivation-goal.cc +++ b/src/libstore/build/local-derivation-goal.cc @@ -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"); diff --git a/src/libstore/parsed-derivations.cc b/src/libstore/parsed-derivations.cc index 5675600c4..f021e4de3 100644 --- a/src/libstore/parsed-derivations.cc +++ b/src/libstore/parsed-derivations.cc @@ -165,13 +165,13 @@ std::optional 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 { if (value.is_string()) diff --git a/src/libstore/parsed-derivations.hh b/src/libstore/parsed-derivations.hh index f02d5868e..8061e3a8b 100644 --- a/src/libstore/parsed-derivations.hh +++ b/src/libstore/parsed-derivations.hh @@ -38,7 +38,8 @@ public: bool substitutesAllowed() const; std::optional prepareStructuredAttrs(std::optional inputRewrites, Store & store, const StorePathSet & inputPaths); - std::string writeStructuredAttrsShell(nlohmann::json & json); }; +std::string writeStructuredAttrsShell(nlohmann::json & json); + } diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index b742fed6d..7415cb54c 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -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, diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index f67776083..459876465 100755 --- a/src/nix-build/nix-build.cc +++ b/src/nix-build/nix-build.cc @@ -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());