about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-10-25T13·18+0200
committerEelco Dolstra <edolstra@gmail.com>2017-10-25T13·18+0200
commit82327e3cc474be3c72a22480ad6e219f072e27e0 (patch)
treecc7005cbd1684049c722a005077327f001936026
parent8191992c83bf4387b03c5fdaba818dc2b520462d (diff)
exportReferencesGraph: Allow exporting a list of store paths
-rw-r--r--src/libstore/build.cc36
-rw-r--r--tests/structured-attrs.nix2
2 files changed, 23 insertions, 15 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 2bca7e1d02a5..51afbac7fc7b 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 <fileName>. */
             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<std::string>());
                     worker.store.pathInfoToJSON(jsonRoot,
-                        exportReferences(worker.store, i->get<std::string>()), 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 72e9c6747502..6c77a43913a7 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 ];
 }