exportReferencesGraph: Allow exporting a list of store paths

This commit is contained in:
Eelco Dolstra 2017-10-25 15:18:49 +02:00
parent 8191992c83
commit 82327e3cc4
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
2 changed files with 23 additions and 15 deletions

View file

@ -1742,8 +1742,12 @@ int childEntry(void * arg)
}
PathSet exportReferences(Store & store, Path storePath)
PathSet exportReferences(Store & store, PathSet storePaths)
{
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%'")
@ -1753,13 +1757,14 @@ PathSet exportReferences(Store & store, Path 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
}

View file

@ -62,5 +62,5 @@ mkDerivation {
"1foobar" = "BAD";
"foo$" = "BAD";
exportReferencesGraph.refs = dep;
exportReferencesGraph.refs = [ dep ];
}