Skip to content

Commit

Permalink
Fix cross-Scala suffix conflict warning
Browse files Browse the repository at this point in the history
Fixes sbt/sbt#6578

Problem
-------
The regex currently expects two segments like2.x or 3.x,
but Scala 3 uses _3 as the cross suffix, and it's not caught.

Solution
--------
Change the regex.
  • Loading branch information
eed3si9n committed Jul 5, 2021
1 parent 564119c commit 2857d2b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object ConflictWarning {
private[this] def groupByRawName(ms: Seq[ModuleID]): Map[(String, String), Seq[ModuleID]] =
ms.groupBy(m => (m.organization, dropCrossSuffix(m.name)))

private[this] val CrossSuffixPattern = """(.+)_(\d+\.\d+(?:\.\d+)?(?:-.+)?)""".r
private[this] val CrossSuffixPattern = """(.+)_(\d+(?:\.\d+)?(?:\.\d+)?(?:-.+)?)""".r
private[this] def dropCrossSuffix(s: String): String = s match {
case CrossSuffixPattern(raw, _) => raw
case _ => s
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package sbt.internal.librarymanagement

import sbt.librarymanagement._
import sbt.librarymanagement.syntax._

object ConflictWarningSpec extends BaseIvySpecification {

test("it should print out message about the cross-Scala conflict") {
var found = false
val deps = Vector(
`scala2.13.6`,
`cats-effect3.1.1`,
`cats-core2.6.1`.cross(CrossVersion.for3Use2_13),
)
val m = module(defaultModuleId, deps, Some("3.0.1-RC2"))
val report = ivyUpdate(m)
val w = ConflictWarning.default("foo")

try {
ConflictWarning(w, report, log)
} catch {
case e: Throwable =>
found = true
assert(
e.getMessage.linesIterator.toList ==
List(
"Conflicting cross-version suffixes in: org.typelevel:simulacrum-scalafix-annotations, org.typelevel:cats-kernel, org.typelevel:cats-core"
)
)
}
if (!found) {
sys.error("conflict warning was expected, but didn't happen sbt/sbt#6578")
}
}

lazy val `scala2.13.6` =
ModuleID("org.scala-lang", "scala-library", "2.13.6").withConfigurations(Some("compile"))
lazy val `cats-effect3.1.1` =
("org.typelevel" %% "cats-effect" % "3.1.1").withConfigurations(Some("compile"))
lazy val `cats-core2.6.1` =
("org.typelevel" %% "cats-core" % "2.6.1").withConfigurations(Some("compile"))
}

0 comments on commit 2857d2b

Please sign in to comment.