Skip to content

Commit

Permalink
Decouple within-build (structured attrs) and unstable CLI path info JSON
Browse files Browse the repository at this point in the history
See code comment for details.
  • Loading branch information
Ericson2314 committed May 31, 2024
1 parent 56a7275 commit 8949616
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/libstore/parsed-derivations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,37 @@ static std::regex shVarName("[A-Za-z_][A-Za-z0-9_]*");
/**
* Write a JSON representation of store object metadata, such as the
* hash and the references.
*
* @note Do *not* use `ValidPathInfo::toJSON` because this function is
* subject to stronger stability requirements since it is used to
* prepare build environments. Perhaps someday we'll have a versionining
* mechanism to allow this to evolve again and get back in sync, but for
* now we don't have one.
*/
static nlohmann::json pathInfoToJSON(
Store & store,
const StorePathSet & storePaths)
{
nlohmann::json::array_t jsonList = nlohmann::json::array();
using nlohmann::json;

nlohmann::json::array_t jsonList = json::array();

for (auto & storePath : storePaths) {
auto info = store.queryPathInfo(storePath);

auto & jsonPath = jsonList.emplace_back(
info->toJSON(store, false, HashFormat::Nix32));
auto & jsonPath = jsonList.emplace_back(json::object());

jsonPath["narHash"] = info->narHash.to_string(HashFormat::Nix32, true);
jsonPath["narSize"] = info->narSize;

{
auto & jsonRefs = jsonPath["references"] = json::array();
for (auto & ref : info->references)
jsonRefs.emplace_back(store.printStorePath(ref));
}

if (info->ca)
jsonPath["ca"] = renderContentAddress(info->ca);

// Add the path to the object whose metadata we are including.
jsonPath["path"] = store.printStorePath(storePath);
Expand Down

0 comments on commit 8949616

Please sign in to comment.