aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-28 12:58:28 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-05-28 13:06:43 +0200
commit6d7efcfaeb715b04986ef5a6b1d8f57de4ba5509 (patch)
tree9cb888193b86a44fcf1cafd0ca13b7b6217a6061 /src/libexpr/primops
parentde36cf3db95afbc96eae80cae9cf2901d1f3d9db (diff)
Store SourceInfo in Flake and NonFlake
This deduplicates some shared fields. Factoring out the commonality is useful in places like makeFlakeValue().
Diffstat (limited to 'src/libexpr/primops')
-rw-r--r--src/libexpr/primops/flake.cc21
-rw-r--r--src/libexpr/primops/flake.hh14
2 files changed, 16 insertions, 19 deletions
diff --git a/src/libexpr/primops/flake.cc b/src/libexpr/primops/flake.cc
index d82c2389d..a8e3e0859 100644
--- a/src/libexpr/primops/flake.cc
+++ b/src/libexpr/primops/flake.cc
@@ -368,19 +368,19 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
// Get the `NonFlake` corresponding to a `FlakeRef`.
NonFlake getNonFlake(EvalState & state, const FlakeRef & flakeRef, FlakeAlias alias, bool impureIsAllowed = false)
{
- SourceInfo sourceInfo = fetchFlake(state, flakeRef, impureIsAllowed);
+ auto sourceInfo = fetchFlake(state, flakeRef, impureIsAllowed);
debug("got non-flake source '%s' with flakeref %s", sourceInfo.storePath, sourceInfo.resolvedRef.to_string());
FlakeRef resolvedRef = sourceInfo.resolvedRef;
NonFlake nonFlake(flakeRef, sourceInfo);
- state.store->assertStorePath(nonFlake.storePath);
+ state.store->assertStorePath(nonFlake.sourceInfo.storePath);
if (state.allowedPaths)
- state.allowedPaths->insert(nonFlake.storePath);
+ state.allowedPaths->insert(nonFlake.sourceInfo.storePath);
- nonFlake.hash = state.store->queryPathInfo(sourceInfo.storePath)->narHash;
+ nonFlake.hash = state.store->queryPathInfo(nonFlake.sourceInfo.storePath)->narHash;
nonFlake.alias = alias;
@@ -480,7 +480,7 @@ ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef, HandleLoc
if (!recreateLockFile (handleLockFile)) {
// If recreateLockFile, start with an empty lockfile
- oldLockFile = readLockFile(flake.storePath + "/flake.lock"); // FIXME: symlink attack
+ oldLockFile = readLockFile(flake.sourceInfo.storePath + "/flake.lock"); // FIXME: symlink attack
}
LockFile lockFile(oldLockFile);
@@ -527,15 +527,16 @@ void callFlake(EvalState & state, const ResolvedFlake & resFlake, Value & v)
auto vNonFlake = state.allocAttr(v, nonFlake.alias);
state.mkAttrs(*vNonFlake, 4);
- state.store->isValidPath(nonFlake.storePath);
- mkString(*state.allocAttr(*vNonFlake, state.sOutPath), nonFlake.storePath, {nonFlake.storePath});
+ state.store->isValidPath(nonFlake.sourceInfo.storePath);
+ mkString(*state.allocAttr(*vNonFlake, state.sOutPath),
+ nonFlake.sourceInfo.storePath, {nonFlake.sourceInfo.storePath});
// FIXME: add rev, shortRev, revCount, ...
}
mkString(*state.allocAttr(v, state.sDescription), resFlake.flake.description);
- auto & path = resFlake.flake.storePath;
+ auto & path = resFlake.flake.sourceInfo.storePath;
state.store->isValidPath(path);
mkString(*state.allocAttr(v, state.sOutPath), path, {path});
@@ -546,8 +547,8 @@ void callFlake(EvalState & state, const ResolvedFlake & resFlake, Value & v)
resFlake.flake.resolvedRef.rev->gitShortRev());
}
- if (resFlake.flake.revCount)
- mkInt(*state.allocAttr(v, state.symbols.create("revCount")), *resFlake.flake.revCount);
+ if (resFlake.flake.sourceInfo.revCount)
+ mkInt(*state.allocAttr(v, state.symbols.create("revCount")), *resFlake.flake.sourceInfo.revCount);
auto vProvides = state.allocAttr(v, state.symbols.create("provides"));
mkApp(*vProvides, *resFlake.flake.vProvides, v);
diff --git a/src/libexpr/primops/flake.hh b/src/libexpr/primops/flake.hh
index f85e62e7f..46489c085 100644
--- a/src/libexpr/primops/flake.hh
+++ b/src/libexpr/primops/flake.hh
@@ -94,17 +94,15 @@ struct Flake
FlakeRef originalRef;
FlakeRef resolvedRef;
std::string description;
- std::optional<uint64_t> revCount;
- Path storePath;
+ SourceInfo sourceInfo;
Hash hash; // content hash
std::vector<FlakeRef> requires;
std::map<FlakeAlias, FlakeRef> nonFlakeRequires;
Value * vProvides; // FIXME: gc
- // date
unsigned int epoch;
Flake(const FlakeRef & origRef, const SourceInfo & sourceInfo) : originalRef(origRef),
- resolvedRef(sourceInfo.resolvedRef), revCount(sourceInfo.revCount), storePath(sourceInfo.storePath) {};
+ resolvedRef(sourceInfo.resolvedRef), sourceInfo(sourceInfo) {};
};
struct NonFlake
@@ -112,12 +110,10 @@ struct NonFlake
FlakeAlias alias;
FlakeRef originalRef;
FlakeRef resolvedRef;
- std::optional<uint64_t> revCount;
+ SourceInfo sourceInfo;
Hash hash;
- Path storePath;
- // date
- NonFlake(const FlakeRef & origRef, const SourceInfo & sourceInfo) : originalRef(origRef),
- resolvedRef(sourceInfo.resolvedRef), revCount(sourceInfo.revCount), storePath(sourceInfo.storePath) {};
+ NonFlake(const FlakeRef & origRef, const SourceInfo & sourceInfo) :
+ originalRef(origRef), resolvedRef(sourceInfo.resolvedRef), sourceInfo(sourceInfo) {};
};
Flake getFlake(EvalState &, const FlakeRef &, bool impureIsAllowed);