mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
Deduplicate "export reference graph" logic a bit
The first part on `drvOptions.exportReferencesGraph` is the same in both cases. It is just how the information is finally rendered that is different.
This commit is contained in:
parent
ca86d34077
commit
2767ae35d9
4 changed files with 39 additions and 12 deletions
|
|
@ -256,6 +256,24 @@ DerivationOptions::fromStructuredAttrs(const StringMap & env, const StructuredAt
|
|||
};
|
||||
}
|
||||
|
||||
std::map<std::string, StorePathSet>
|
||||
DerivationOptions::getParsedExportReferencesGraph(const StoreDirConfig & store) const
|
||||
{
|
||||
std::map<std::string, StorePathSet> res;
|
||||
|
||||
for (auto & [fileName, ss] : exportReferencesGraph) {
|
||||
StorePathSet storePaths;
|
||||
for (auto & storePathS : ss) {
|
||||
if (!store.isInStore(storePathS))
|
||||
throw BuildError("'exportReferencesGraph' contains a non-store path '%1%'", storePathS);
|
||||
storePaths.insert(store.toStorePath(storePathS).first);
|
||||
}
|
||||
res.insert_or_assign(fileName, storePaths);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
StringSet DerivationOptions::getRequiredSystemFeatures(const BasicDerivation & drv) const
|
||||
{
|
||||
// FIXME: cache this?
|
||||
|
|
|
|||
|
|
@ -8,10 +8,12 @@
|
|||
|
||||
#include "nix/util/types.hh"
|
||||
#include "nix/util/json-impls.hh"
|
||||
#include "nix/store/path.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
class Store;
|
||||
struct StoreDirConfig;
|
||||
struct BasicDerivation;
|
||||
struct StructuredAttrs;
|
||||
|
||||
|
|
@ -116,6 +118,22 @@ struct DerivationOptions
|
|||
*/
|
||||
std::map<std::string, StringSet> exportReferencesGraph;
|
||||
|
||||
/**
|
||||
* Once a derivations is resolved, the strings in in
|
||||
* `exportReferencesGraph` should all be store paths (with possible
|
||||
* suffix paths, but those are discarded).
|
||||
*
|
||||
* @return The parsed path set for for each key in the map.
|
||||
*
|
||||
* @todo Ideally, `exportReferencesGraph` would just store
|
||||
* `StorePath`s for this, but we can't just do that, because for CA
|
||||
* derivations they is actually in general `DerivedPath`s (via
|
||||
* placeholder strings) until the derivation is resolved and exact
|
||||
* inputs store paths are known. We can use better types for that
|
||||
* too, but that is a longer project.
|
||||
*/
|
||||
std::map<std::string, StorePathSet> getParsedExportReferencesGraph(const StoreDirConfig & store) const;
|
||||
|
||||
/**
|
||||
* env: __sandboxProfile
|
||||
*
|
||||
|
|
|
|||
|
|
@ -113,10 +113,7 @@ nlohmann::json StructuredAttrs::prepareStructuredAttrs(
|
|||
json["outputs"] = std::move(outputsJson);
|
||||
|
||||
/* Handle exportReferencesGraph. */
|
||||
for (auto & [key, inputPaths] : drvOptions.exportReferencesGraph) {
|
||||
StorePathSet storePaths;
|
||||
for (auto & p : inputPaths)
|
||||
storePaths.insert(store.toStorePath(p).first);
|
||||
for (auto & [key, storePaths] : drvOptions.getParsedExportReferencesGraph(store)) {
|
||||
json[key] = pathInfoToJSON(store, store.exportReferences(storePaths, storePaths));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -785,17 +785,11 @@ void DerivationBuilderImpl::startBuilder()
|
|||
|
||||
/* Handle exportReferencesGraph(), if set. */
|
||||
if (!drv.structuredAttrs) {
|
||||
for (auto & [fileName, ss] : drvOptions.exportReferencesGraph) {
|
||||
StorePathSet storePathSet;
|
||||
for (auto & storePathS : ss) {
|
||||
if (!store.isInStore(storePathS))
|
||||
throw BuildError("'exportReferencesGraph' contains a non-store path '%1%'", storePathS);
|
||||
storePathSet.insert(store.toStorePath(storePathS).first);
|
||||
}
|
||||
for (auto & [fileName, storePaths] : drvOptions.getParsedExportReferencesGraph(store)) {
|
||||
/* Write closure info to <fileName>. */
|
||||
writeFile(
|
||||
tmpDir + "/" + fileName,
|
||||
store.makeValidityRegistration(store.exportReferences(storePathSet, inputPaths), false, false));
|
||||
store.makeValidityRegistration(store.exportReferences(storePaths, inputPaths), false, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue