Skip to content

Commit

Permalink
fix: deps checker
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyklim committed May 23, 2024
1 parent cb41b9e commit bdd6e0a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rules/scala/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def scala_repositories():
)

scala2 = "2.13.14"
scala3 = "3.4.1-RC2"
scala3 = "3.5.0-RC1"
scalajs = "1.16.0"

direct_deps = [
Expand Down
20 changes: 12 additions & 8 deletions scala/workers/deps/DepsRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ object DepsRunner extends WorkerMain[Unit]:
val pathsMap = new mutable.HashMap[String, String](initialCapacity = groups.size, loadFactor = 0.75)

for group <- groups do
val depLabel = group.label.tail match
case label if label.startsWith("@@//") => label.drop(2)
case label if label.startsWith("@//") => label.drop(1)
case label if label.startsWith("@@") => label.drop(1)
case label => label

val depLabel = normalizeLabel(group.label.tail)
depLabelsMap.put(depLabel, group.jars.toSet)

for path <- group.jars do pathsMap.put(path, depLabel)
Expand All @@ -106,7 +101,8 @@ object DepsRunner extends WorkerMain[Unit]:
val remove =
if workArgs.checkUsed then
val usedWhitelist = workArgs.usedWhitelist.map(_.tail)
directLabels.diff(usedWhitelist).filterNot(depLabel => depLabelToPaths(depLabel).exists(usedPaths))
directLabels.diff(usedWhitelist).filterNot: depLabel =>
depLabelToPaths.get(normalizeLabel(depLabel)).fold(false)(_.exists(usedPaths))
else Nil

for depLabel <- remove do
Expand All @@ -118,7 +114,9 @@ object DepsRunner extends WorkerMain[Unit]:
if workArgs.checkDirect then
val unusedWhitelist = workArgs.unusedWhitelist.map(_.tail)
usedPaths
.diff(Set.concat(directLabels, unusedWhitelist).flatMap(depLabelToPaths))
.diff:
Set.concat(directLabels, unusedWhitelist).flatMap: label =>
depLabelToPaths.get(normalizeLabel(label)).fold(Set.empty)(identity)
.flatMap: path =>
pathToLabel.get(path) match
case res @ None =>
Expand All @@ -137,3 +135,9 @@ object DepsRunner extends WorkerMain[Unit]:

private val EmptyLabelsMap = Map.empty[String, collection.Set[String]]
private val EmptyPathsMap = Map.empty[String, String]

private def normalizeLabel(label: String): String = label match
case label if label.startsWith("@@//") => label.drop(2)
case label if label.startsWith("@//") => label.drop(1)
case label if label.startsWith("@@") => label.drop(1)
case label => label
2 changes: 1 addition & 1 deletion scala/workers/zinc/test/TestFrameworkRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ object TestFrameworkRunner:
reporter: TestReporter
): (mutable.ListBuffer[(String, collection.Seq[Event])], collection.Set[String]) =
val finishedTasks =
if parallel then
if parallel && tasks.size > 1 then
val xs = parallelN.fold(Seq(tasks))(tasks.grouped(_).toSeq)
val fut = Future.traverse(xs): xs =>
Future.sequence(xs.map(t => Future(runTask(t))))
Expand Down

0 comments on commit bdd6e0a

Please sign in to comment.