-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# This is currently only used for legacy modules ported to v1. | ||
# The dream-lock concept might be deprecated together with this module at some | ||
# point. | ||
{lib, ...}: let | ||
l = builtins // lib; | ||
|
||
nameVersionPair = name: version: { | ||
name = name; | ||
version = version; | ||
}; | ||
|
||
findCycles = { | ||
dependencyGraph, | ||
roots, | ||
}: let | ||
depGraphWithFakeRoot = | ||
l.recursiveUpdate | ||
dependencyGraph | ||
{ | ||
__fake-entry.__fake-version = | ||
l.mapAttrsToList | ||
nameVersionPair | ||
roots; | ||
}; | ||
|
||
findCycles_ = node: prevNodes: cycles: let | ||
children = | ||
depGraphWithFakeRoot."${node.name}"."${node.version}"; | ||
|
||
cyclicChildren = | ||
l.filter | ||
(child: prevNodes ? "${child.name}#${child.version}") | ||
children; | ||
|
||
nonCyclicChildren = | ||
l.filter | ||
(child: ! prevNodes ? "${child.name}#${child.version}") | ||
children; | ||
|
||
cycles' = | ||
cycles | ||
++ (l.map (child: { | ||
from = node; | ||
to = child; | ||
}) | ||
cyclicChildren); | ||
|
||
# use set for efficient lookups | ||
prevNodes' = | ||
prevNodes | ||
// {"${node.name}#${node.version}" = null;}; | ||
in | ||
if nonCyclicChildren == [] | ||
then cycles' | ||
else | ||
l.flatten | ||
(l.map | ||
(child: findCycles_ child prevNodes' cycles') | ||
nonCyclicChildren); | ||
|
||
cyclesList = | ||
findCycles_ | ||
( | ||
nameVersionPair | ||
"__fake-entry" | ||
"__fake-version" | ||
) | ||
{} | ||
[]; | ||
in | ||
l.foldl' | ||
(cycles: cycle: ( | ||
let | ||
existing = | ||
cycles."${cycle.from.name}"."${cycle.from.version}" | ||
or []; | ||
|
||
reverse = | ||
cycles."${cycle.to.name}"."${cycle.to.version}" | ||
or []; | ||
in | ||
# if edge or reverse edge already in cycles, do nothing | ||
if | ||
l.elem cycle.from reverse | ||
|| l.elem cycle.to existing | ||
then cycles | ||
else | ||
l.recursiveUpdate | ||
cycles | ||
{ | ||
"${cycle.from.name}"."${cycle.from.version}" = | ||
existing ++ [cycle.to]; | ||
} | ||
)) | ||
{} | ||
cyclesList; | ||
in | ||
findCycles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
{ | ||
lib ? import <nixpkgs/lib>, | ||
... | ||
}: let | ||
{lib ? import <nixpkgs/lib>, ...}: let | ||
sanitizeGraphTests = import ./sanitizeGraph.nix {inherit lib;}; | ||
in { | ||
inherit sanitizeGraphTests; | ||
inherit sanitizeGraphTests; | ||
} |