mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06: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
|
StringSet DerivationOptions::getRequiredSystemFeatures(const BasicDerivation & drv) const
|
||||||
{
|
{
|
||||||
// FIXME: cache this?
|
// FIXME: cache this?
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,12 @@
|
||||||
|
|
||||||
#include "nix/util/types.hh"
|
#include "nix/util/types.hh"
|
||||||
#include "nix/util/json-impls.hh"
|
#include "nix/util/json-impls.hh"
|
||||||
|
#include "nix/store/path.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
class Store;
|
class Store;
|
||||||
|
struct StoreDirConfig;
|
||||||
struct BasicDerivation;
|
struct BasicDerivation;
|
||||||
struct StructuredAttrs;
|
struct StructuredAttrs;
|
||||||
|
|
||||||
|
|
@ -116,6 +118,22 @@ struct DerivationOptions
|
||||||
*/
|
*/
|
||||||
std::map<std::string, StringSet> exportReferencesGraph;
|
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
|
* env: __sandboxProfile
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -113,10 +113,7 @@ nlohmann::json StructuredAttrs::prepareStructuredAttrs(
|
||||||
json["outputs"] = std::move(outputsJson);
|
json["outputs"] = std::move(outputsJson);
|
||||||
|
|
||||||
/* Handle exportReferencesGraph. */
|
/* Handle exportReferencesGraph. */
|
||||||
for (auto & [key, inputPaths] : drvOptions.exportReferencesGraph) {
|
for (auto & [key, storePaths] : drvOptions.getParsedExportReferencesGraph(store)) {
|
||||||
StorePathSet storePaths;
|
|
||||||
for (auto & p : inputPaths)
|
|
||||||
storePaths.insert(store.toStorePath(p).first);
|
|
||||||
json[key] = pathInfoToJSON(store, store.exportReferences(storePaths, storePaths));
|
json[key] = pathInfoToJSON(store, store.exportReferences(storePaths, storePaths));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -785,17 +785,11 @@ void DerivationBuilderImpl::startBuilder()
|
||||||
|
|
||||||
/* Handle exportReferencesGraph(), if set. */
|
/* Handle exportReferencesGraph(), if set. */
|
||||||
if (!drv.structuredAttrs) {
|
if (!drv.structuredAttrs) {
|
||||||
for (auto & [fileName, ss] : drvOptions.exportReferencesGraph) {
|
for (auto & [fileName, storePaths] : drvOptions.getParsedExportReferencesGraph(store)) {
|
||||||
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);
|
|
||||||
}
|
|
||||||
/* Write closure info to <fileName>. */
|
/* Write closure info to <fileName>. */
|
||||||
writeFile(
|
writeFile(
|
||||||
tmpDir + "/" + fileName,
|
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