Store SourceInfo in Flake and NonFlake
This deduplicates some shared fields. Factoring out the commonality is useful in places like makeFlakeValue().
This commit is contained in:
parent
de36cf3db9
commit
6d7efcfaeb
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -80,9 +80,9 @@ void printFlakeInfo(const Flake & flake, bool json) {
|
|||
j["branch"] = *flake.resolvedRef.ref;
|
||||
if (flake.resolvedRef.rev)
|
||||
j["revision"] = flake.resolvedRef.rev->to_string(Base16, false);
|
||||
if (flake.revCount)
|
||||
j["revCount"] = *flake.revCount;
|
||||
j["path"] = flake.storePath;
|
||||
if (flake.sourceInfo.revCount)
|
||||
j["revCount"] = *flake.sourceInfo.revCount;
|
||||
j["path"] = flake.sourceInfo.storePath;
|
||||
j["epoch"] = flake.epoch;
|
||||
std::cout << j.dump(4) << std::endl;
|
||||
} else {
|
||||
|
@ -93,9 +93,9 @@ void printFlakeInfo(const Flake & flake, bool json) {
|
|||
std::cout << "Branch: " << *flake.resolvedRef.ref << "\n";
|
||||
if (flake.resolvedRef.rev)
|
||||
std::cout << "Revision: " << flake.resolvedRef.rev->to_string(Base16, false) << "\n";
|
||||
if (flake.revCount)
|
||||
std::cout << "Revcount: " << *flake.revCount << "\n";
|
||||
std::cout << "Path: " << flake.storePath << "\n";
|
||||
if (flake.sourceInfo.revCount)
|
||||
std::cout << "Revcount: " << *flake.sourceInfo.revCount << "\n";
|
||||
std::cout << "Path: " << flake.sourceInfo.storePath << "\n";
|
||||
std::cout << "Epoch: " << flake.epoch << "\n";
|
||||
}
|
||||
}
|
||||
|
@ -109,9 +109,9 @@ void printNonFlakeInfo(const NonFlake & nonFlake, bool json) {
|
|||
j["branch"] = *nonFlake.resolvedRef.ref;
|
||||
if (nonFlake.resolvedRef.rev)
|
||||
j["revision"] = nonFlake.resolvedRef.rev->to_string(Base16, false);
|
||||
if (nonFlake.revCount)
|
||||
j["revCount"] = *nonFlake.revCount;
|
||||
j["path"] = nonFlake.storePath;
|
||||
if (nonFlake.sourceInfo.revCount)
|
||||
j["revCount"] = *nonFlake.sourceInfo.revCount;
|
||||
j["path"] = nonFlake.sourceInfo.storePath;
|
||||
std::cout << j.dump(4) << std::endl;
|
||||
} else {
|
||||
std::cout << "ID: " << nonFlake.alias << "\n";
|
||||
|
@ -120,9 +120,9 @@ void printNonFlakeInfo(const NonFlake & nonFlake, bool json) {
|
|||
std::cout << "Branch: " << *nonFlake.resolvedRef.ref;
|
||||
if (nonFlake.resolvedRef.rev)
|
||||
std::cout << "Revision: " << nonFlake.resolvedRef.rev->to_string(Base16, false) << "\n";
|
||||
if (nonFlake.revCount)
|
||||
std::cout << "Revcount: " << *nonFlake.revCount << "\n";
|
||||
std::cout << "Path: " << nonFlake.storePath << "\n";
|
||||
if (nonFlake.sourceInfo.revCount)
|
||||
std::cout << "Revcount: " << *nonFlake.sourceInfo.revCount << "\n";
|
||||
std::cout << "Path: " << nonFlake.sourceInfo.storePath << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ void makeFlakeClosureGCRoot(Store & store, const FlakeRef & origFlakeRef, const
|
|||
const ResolvedFlake & flake = queue.front();
|
||||
queue.pop();
|
||||
if (!std::get_if<FlakeRef::IsPath>(&flake.flake.resolvedRef.data))
|
||||
closure.insert(flake.flake.storePath);
|
||||
closure.insert(flake.flake.sourceInfo.storePath);
|
||||
for (const auto & dep : flake.flakeDeps)
|
||||
queue.push(dep.second);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue