Merge remote-tracking branch 'tweag/resolvedFlake' into flakes

This commit is contained in:
Eelco Dolstra 2019-04-19 15:56:17 +02:00
commit 4fb594a375
3 changed files with 34 additions and 34 deletions

View file

@ -351,7 +351,7 @@ NonFlake getNonFlake(EvalState & state, const FlakeRef & flakeRef, FlakeAlias al
dependencies. dependencies.
FIXME: this should return a graph of flakes. FIXME: this should return a graph of flakes.
*/ */
Dependencies resolveFlake(EvalState & state, const FlakeRef & topRef, ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef,
RegistryAccess registryAccess, bool isTopFlake) RegistryAccess registryAccess, bool isTopFlake)
{ {
Flake flake = getFlake(state, topRef, Flake flake = getFlake(state, topRef,
@ -362,7 +362,7 @@ Dependencies resolveFlake(EvalState & state, const FlakeRef & topRef,
if (isTopFlake) if (isTopFlake)
lockFile = readLockFile(flake.sourceInfo.storePath + "/flake.lock"); // FIXME: symlink attack lockFile = readLockFile(flake.sourceInfo.storePath + "/flake.lock"); // FIXME: symlink attack
Dependencies deps(flake); ResolvedFlake deps(flake);
for (auto & nonFlakeInfo : flake.nonFlakeRequires) for (auto & nonFlakeInfo : flake.nonFlakeRequires)
deps.nonFlakeDeps.push_back(getNonFlake(state, nonFlakeInfo.second, nonFlakeInfo.first)); deps.nonFlakeDeps.push_back(getNonFlake(state, nonFlakeInfo.second, nonFlakeInfo.first));
@ -377,14 +377,14 @@ Dependencies resolveFlake(EvalState & state, const FlakeRef & topRef,
return deps; return deps;
} }
LockFile::FlakeEntry dependenciesToFlakeEntry(const Dependencies & deps) LockFile::FlakeEntry dependenciesToFlakeEntry(const ResolvedFlake & resolvedFlake)
{ {
LockFile::FlakeEntry entry(deps.flake.sourceInfo.flakeRef); LockFile::FlakeEntry entry(resolvedFlake.flake.sourceInfo.flakeRef);
for (auto & deps : deps.flakeDeps) for (auto & newResFlake : resolvedFlake.flakeDeps)
entry.flakeEntries.insert_or_assign(deps.flake.id, dependenciesToFlakeEntry(deps)); entry.flakeEntries.insert_or_assign(newResFlake.flake.id, dependenciesToFlakeEntry(newResFlake));
for (auto & nonFlake : deps.nonFlakeDeps) for (auto & nonFlake : resolvedFlake.nonFlakeDeps)
entry.nonFlakeEntries.insert_or_assign(nonFlake.alias, nonFlake.ref); entry.nonFlakeEntries.insert_or_assign(nonFlake.alias, nonFlake.ref);
return entry; return entry;
@ -392,8 +392,8 @@ LockFile::FlakeEntry dependenciesToFlakeEntry(const Dependencies & deps)
static LockFile makeLockFile(EvalState & evalState, FlakeRef & flakeRef) static LockFile makeLockFile(EvalState & evalState, FlakeRef & flakeRef)
{ {
Dependencies deps = resolveFlake(evalState, flakeRef, AllowRegistry); ResolvedFlake resFlake = resolveFlake(evalState, flakeRef, AllowRegistry);
LockFile::FlakeEntry entry = dependenciesToFlakeEntry(deps); LockFile::FlakeEntry entry = dependenciesToFlakeEntry(resFlake);
LockFile lockFile; LockFile lockFile;
lockFile.flakeEntries = entry.flakeEntries; lockFile.flakeEntries = entry.flakeEntries;
lockFile.nonFlakeEntries = entry.nonFlakeEntries; lockFile.nonFlakeEntries = entry.nonFlakeEntries;
@ -414,37 +414,37 @@ void updateLockFile(EvalState & state, const Path & path)
runProgram("git", true, { "-C", path, "add", "flake.lock" }); runProgram("git", true, { "-C", path, "add", "flake.lock" });
} }
void callFlake(EvalState & state, const Dependencies & flake, Value & v) void callFlake(EvalState & state, const ResolvedFlake & resFlake, Value & v)
{ {
// Construct the resulting attrset '{description, provides, // Construct the resulting attrset '{description, provides,
// ...}'. This attrset is passed lazily as an argument to 'provides'. // ...}'. This attrset is passed lazily as an argument to 'provides'.
state.mkAttrs(v, flake.flakeDeps.size() + flake.nonFlakeDeps.size() + 8); state.mkAttrs(v, resFlake.flakeDeps.size() + resFlake.nonFlakeDeps.size() + 8);
for (auto & dep : flake.flakeDeps) { for (const ResolvedFlake newResFlake : resFlake.flakeDeps) {
auto vFlake = state.allocAttr(v, dep.flake.id); auto vFlake = state.allocAttr(v, newResFlake.flake.id);
callFlake(state, dep, *vFlake); callFlake(state, newResFlake, *vFlake);
} }
for (auto & dep : flake.nonFlakeDeps) { for (const NonFlake nonFlake : resFlake.nonFlakeDeps) {
auto vNonFlake = state.allocAttr(v, dep.alias); auto vNonFlake = state.allocAttr(v, nonFlake.alias);
state.mkAttrs(*vNonFlake, 4); state.mkAttrs(*vNonFlake, 4);
state.store->isValidPath(dep.path); state.store->isValidPath(nonFlake.path);
mkString(*state.allocAttr(*vNonFlake, state.sOutPath), dep.path, {dep.path}); mkString(*state.allocAttr(*vNonFlake, state.sOutPath), nonFlake.path, {nonFlake.path});
} }
mkString(*state.allocAttr(v, state.sDescription), flake.flake.description); mkString(*state.allocAttr(v, state.sDescription), resFlake.flake.description);
auto & path = flake.flake.sourceInfo.storePath; auto & path = resFlake.flake.sourceInfo.storePath;
state.store->isValidPath(path); state.store->isValidPath(path);
mkString(*state.allocAttr(v, state.sOutPath), path, {path}); mkString(*state.allocAttr(v, state.sOutPath), path, {path});
if (flake.flake.sourceInfo.revCount) if (resFlake.flake.sourceInfo.revCount)
mkInt(*state.allocAttr(v, state.symbols.create("revCount")), *flake.flake.sourceInfo.revCount); mkInt(*state.allocAttr(v, state.symbols.create("revCount")), *resFlake.flake.sourceInfo.revCount);
auto vProvides = state.allocAttr(v, state.symbols.create("provides")); auto vProvides = state.allocAttr(v, state.symbols.create("provides"));
mkApp(*vProvides, *flake.flake.vProvides, v); mkApp(*vProvides, *resFlake.flake.vProvides, v);
v.attrs->push_back(Attr(state.symbols.create("self"), &v)); v.attrs->push_back(Attr(state.symbols.create("self"), &v));

View file

@ -74,15 +74,15 @@ std::shared_ptr<FlakeRegistry> getGlobalRegistry();
Flake getFlake(EvalState &, const FlakeRef &, bool impureIsAllowed); Flake getFlake(EvalState &, const FlakeRef &, bool impureIsAllowed);
struct Dependencies struct ResolvedFlake
{ {
Flake flake; Flake flake;
std::vector<Dependencies> flakeDeps; // The flake dependencies std::vector<ResolvedFlake> flakeDeps; // The flake dependencies
std::vector<NonFlake> nonFlakeDeps; std::vector<NonFlake> nonFlakeDeps;
Dependencies(const Flake & flake) : flake(flake) {} ResolvedFlake(const Flake & flake) : flake(flake) {}
}; };
Dependencies resolveFlake(EvalState &, const FlakeRef &, RegistryAccess registryAccess, bool isTopFlake = true); ResolvedFlake resolveFlake(EvalState &, const FlakeRef &, RegistryAccess registryAccess, bool isTopFlake = true);
void updateLockFile(EvalState &, const Path & path); void updateLockFile(EvalState &, const Path & path);

View file

@ -90,20 +90,20 @@ struct CmdFlakeDeps : FlakeCommand, MixJSON, StoreCommand, MixEvalArgs
FlakeRef flakeRef(flakeUri); FlakeRef flakeRef(flakeUri);
Dependencies deps = resolveFlake(*evalState, flakeRef, AllowRegistryAtTop); ResolvedFlake resFlake = resolveFlake(*evalState, flakeRef, AllowRegistryAtTop);
std::queue<Dependencies> todo; std::queue<ResolvedFlake> todo;
todo.push(deps); todo.push(resFlake);
while (!todo.empty()) { while (!todo.empty()) {
deps = todo.front(); resFlake = todo.front();
todo.pop(); todo.pop();
for (auto & nonFlake : deps.nonFlakeDeps) for (NonFlake & nonFlake : resFlake.nonFlakeDeps)
printNonFlakeInfo(nonFlake, json); printNonFlakeInfo(nonFlake, json);
for (auto & newDeps : deps.flakeDeps) for (ResolvedFlake & newResFlake : resFlake.flakeDeps)
todo.push(newDeps); todo.push(newResFlake);
} }
} }
}; };