|
| 1 | +#!/usr/bin/env -S scala-cli shebang |
| 2 | +//> using scala 3 |
| 3 | +//> using toolkit default |
| 4 | + |
| 5 | +val modules = |
| 6 | + os.proc(os.pwd / "mill", "-i", "resolve", "__[]") |
| 7 | + .call(cwd = os.pwd) |
| 8 | + .out |
| 9 | + .lines() |
| 10 | + |
| 11 | +for { module <- modules } { |
| 12 | + println(s"Checking for $module...") |
| 13 | + val depRegex = "[│└─\\S\\s]+\\s([\\w.-]+):([\\w.-]+):([\\w\\s\\S.-]+)".r |
| 14 | + val scalaDepSuffixRegex = "^(.+?)(_[23](?:\\.\\d{2})?)?$".r |
| 15 | + val deps = os.proc(os.pwd / "mill", "-i", s"$module.ivyDepsTree") |
| 16 | + .call(cwd = os.pwd) |
| 17 | + .out |
| 18 | + .lines() |
| 19 | + .map { case depRegex(org, name, depVersion) => (org, name, depVersion) } |
| 20 | + val scalaVersionsByOrgAndName = deps |
| 21 | + .groupBy { case (org, scalaDepSuffixRegex(nameWithoutSuffix, _), _) => |
| 22 | + s"$org:$nameWithoutSuffix" |
| 23 | + } |
| 24 | + .map { case (key, entries) => |
| 25 | + key -> entries.map { case (_, scalaDepSuffixRegex(_, scalaVersion), _) => |
| 26 | + scalaVersion |
| 27 | + }.distinct |
| 28 | + } |
| 29 | + .filter { case (_, scalaVersions) => scalaVersions.head != null } // filter out non-Scala deps |
| 30 | + println("Checking for clashing dependency Scala versions...") |
| 31 | + val conflictEntries: Map[String, Vector[String]] = |
| 32 | + scalaVersionsByOrgAndName |
| 33 | + .filter { case (key, scalaVersions) => |
| 34 | + if scalaVersions.length == 1 then |
| 35 | + println(s"[info] $key${scalaVersions.head} (OK)") |
| 36 | + false |
| 37 | + else |
| 38 | + println( |
| 39 | + s"[${Console.RED}error${Console.RESET}] $key: multiple conflicting Scala versions: ${scalaVersions.mkString(", ")}" |
| 40 | + ) |
| 41 | + true |
| 42 | + } |
| 43 | + if conflictEntries.nonEmpty then |
| 44 | + println(s"${Console.RED}ERROR: Found ${conflictEntries.size} conflicting entries for $module:") |
| 45 | + conflictEntries.foreach { |
| 46 | + case (key, scalaVersions) => |
| 47 | + println(s" $key: multiple conflicting Scala versions: ${scalaVersions.mkString(", ")}") |
| 48 | + } |
| 49 | + println(Console.RESET) |
| 50 | + sys.exit(1) |
| 51 | + else println(s"[info] $module OK") |
| 52 | +} |
| 53 | + |
| 54 | +println("Checks completed for:") |
| 55 | +modules.foreach(m => println(s" $m")) |
| 56 | +println("No conflicts detected.") |
| 57 | +sys.exit(0) |
0 commit comments