Skip to content

Commit

Permalink
break cycle by tracking parents
Browse files Browse the repository at this point in the history
  • Loading branch information
patriknw committed Oct 17, 2023
1 parent 050ea29 commit bbd2838
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: Stri
r <- graph.roots
d <- children(graph, r)
}
renderTreeNode(p, graph, d)
renderTreeNode(p, graph, d, Set.empty)
p.print("</pre></dd>").println()
}

private def renderTreeNode(p: Printer, graph: ModuleGraph, n: Module): Unit = {
// not useful with too many indents and that may be infinite recursion
if (p.indent < 100 && n.evictedByVersion.isEmpty) {
private def renderTreeNode(p: Printer, graph: ModuleGraph, n: Module, parents: Set[Module]): Unit =
// avoid cycles by checking if in parents
if (n.evictedByVersion.isEmpty && !parents.contains(n)) {
val moduleId = n.id
val name = moduleId.name
p.println()
Expand All @@ -100,11 +100,10 @@ class DependenciesDirective(showLicenses: Boolean)(projectIdToDependencies: Stri
n.license.foreach(l => p.print(" ").print(l))
if (children(graph, n).nonEmpty) {
p.indent(4)
children(graph, n).foreach(renderTreeNode(p, graph, _))
children(graph, n).foreach(renderTreeNode(p, graph, _, parents + n))
p.indent(-4)
}
}
}

private def children(graph: ModuleGraph, module: Module) = graph.dependencyMap(module.id)

Expand Down
4 changes: 3 additions & 1 deletion src/sbt-test/dependencies/happy-path/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
enablePlugins(ParadoxPlugin)
paradoxTheme := None

libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.17"
//libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.17"

libraryDependencies += "io.grpc" % "grpc-core" % "1.58.0"

0 comments on commit bbd2838

Please sign in to comment.