From 82327e3cc474be3c72a22480ad6e219f072e27e0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 25 Oct 2017 15:18:49 +0200 Subject: [PATCH] exportReferencesGraph: Allow exporting a list of store paths --- src/libstore/build.cc | 36 ++++++++++++++++++++++-------------- tests/structured-attrs.nix | 2 +- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 2bca7e1d..51afbac7 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1742,24 +1742,29 @@ int childEntry(void * arg) } -PathSet exportReferences(Store & store, Path storePath) +PathSet exportReferences(Store & store, PathSet storePaths) { - /* Check that the store path is valid. */ - if (!store.isInStore(storePath)) - throw BuildError(format("'exportReferencesGraph' contains a non-store path '%1%'") - % storePath); - storePath = store.toStorePath(storePath); - if (!store.isValidPath(storePath)) - throw BuildError(format("'exportReferencesGraph' contains an invalid path '%1%'") - % storePath); + PathSet paths; + + for (auto storePath : storePaths) { + + /* Check that the store path is valid. */ + if (!store.isInStore(storePath)) + throw BuildError(format("'exportReferencesGraph' contains a non-store path '%1%'") + % storePath); + storePath = store.toStorePath(storePath); + if (!store.isValidPath(storePath)) + throw BuildError(format("'exportReferencesGraph' contains an invalid path '%1%'") + % storePath); + + store.computeFSClosure(storePath, paths); + } /* If there are derivations in the graph, then include their outputs as well. This is useful if you want to do things like passing all build-time dependencies of some path to a derivation that builds a NixOS DVD image. */ - PathSet paths, paths2; - store.computeFSClosure(storePath, paths); - paths2 = paths; + PathSet paths2(paths); for (auto & j : paths2) { if (isDerivation(j)) { @@ -1868,7 +1873,7 @@ void DerivationGoal::startBuilder() /* Write closure info to . */ writeFile(tmpDir + "/" + fileName, worker.store.makeValidityRegistration( - exportReferences(worker.store, storePath), false, false)); + exportReferences(worker.store, {storePath}), false, false)); } } @@ -2366,8 +2371,11 @@ void DerivationGoal::writeStructuredAttrs() std::ostringstream str; { JSONPlaceholder jsonRoot(str, true); + PathSet storePaths; + for (auto & p : *i) + storePaths.insert(p.get()); worker.store.pathInfoToJSON(jsonRoot, - exportReferences(worker.store, i->get()), false, true); + exportReferences(worker.store, storePaths), false, true); } json[i.key()] = nlohmann::json::parse(str.str()); // urgh } diff --git a/tests/structured-attrs.nix b/tests/structured-attrs.nix index 72e9c674..6c77a439 100644 --- a/tests/structured-attrs.nix +++ b/tests/structured-attrs.nix @@ -62,5 +62,5 @@ mkDerivation { "1foobar" = "BAD"; "foo$" = "BAD"; - exportReferencesGraph.refs = dep; + exportReferencesGraph.refs = [ dep ]; }