From 2308d0a3a7d411122c5f60b3f454748fabc9a716 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sat, 19 Dec 2020 17:08:24 -0500 Subject: [PATCH] Fixes match error when using withDottyCompat Fixes https://github.com/sbt/sbt/issues/6210 scodec-bits is published with pvp versionScheme (nice), this means that we should just evaluate the version portion for pvp-ness, but I was using `guessSecondSegment` that checks for Scala suffix. That's mistake 1. `guessSecondSegment` assumes that the Scala suffix uses the given ScalaModuleInfo, but with 2.13-3 sandwich we can't assume this. In the reported case, Scala module is 3.0.0-M3 but scodec-bits uses 2.13. So that's mistake 2. This attempts to correct both the mistakes. 1. Instead of `guessSecondSegment`, this adds a simpler `evalPvp` function. 2. `guessSecondSegment` just looks for `_2.` or `_3` and ignores the Scala module. --- .../librarymanagement/EvictionWarning.scala | 21 +++++++++++++++---- .../EvictionWarningSpec.scala | 18 ++++++++++++++++ project/build.properties | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala b/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala index e8dff4e6f..1ac9d7039 100644 --- a/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala +++ b/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala @@ -98,12 +98,25 @@ object EvictionWarningOptions { lazy val defaultGuess: Function1[(ModuleID, Option[ModuleID], Option[ScalaModuleInfo]), Boolean] = guessSbtOne orElse guessSecondSegment orElse guessSemVer orElse guessFalse + private def isNameScalaSuffixed(name: String): Boolean = + name.contains("_2.") || name.contains("_3") || name.contains("_4") + + /** A partial function that checks if given m2 is suffixed, and use pvp to evaluate. */ lazy val guessSecondSegment : PartialFunction[(ModuleID, Option[ModuleID], Option[ScalaModuleInfo]), Boolean] = { - case (m1, Some(m2), Some(scalaModuleInfo)) - if m2.name.endsWith("_" + scalaModuleInfo.scalaFullVersion) || m2.name.endsWith( - "_" + scalaModuleInfo.scalaBinaryVersion - ) => + case (m1, Some(m2), Some(_)) if isNameScalaSuffixed(m2.name) => + (m1.revision, m2.revision) match { + case (VersionNumber(ns1, ts1, es1), VersionNumber(ns2, ts2, es2)) => + VersionNumber.SecondSegment + .isCompatible(VersionNumber(ns1, ts1, es1), VersionNumber(ns2, ts2, es2)) + case _ => false + } + } + + /** A partial function that checks two versions match pvp. */ + private[sbt] lazy val evalPvp + : PartialFunction[(ModuleID, Option[ModuleID], Option[ScalaModuleInfo]), Boolean] = { + case (m1, Some(m2), _) => (m1.revision, m2.revision) match { case (VersionNumber(ns1, ts1, es1), VersionNumber(ns2, ts2, es2)) => VersionNumber.SecondSegment diff --git a/ivy/src/test/scala/sbt/internal/librarymanagement/EvictionWarningSpec.scala b/ivy/src/test/scala/sbt/internal/librarymanagement/EvictionWarningSpec.scala index 925bdb599..09975ba5f 100644 --- a/ivy/src/test/scala/sbt/internal/librarymanagement/EvictionWarningSpec.scala +++ b/ivy/src/test/scala/sbt/internal/librarymanagement/EvictionWarningSpec.scala @@ -283,6 +283,24 @@ object EvictionWarningSpec extends BaseIvySpecification { ) } + test("Comparing 2.13 libraries with pvp under Scala 3.0.0-M3 should work") { + val m1 = "org.scodec" % "scodec-bits_2.13" % "1.1.21" + val m2 = "org.scodec" % "scodec-bits_2.13" % "1.1.22" + assert( + EvictionWarningOptions + .evalPvp((m1, Option(m2), Option(dummyScalaModuleInfo("3.0.0-M3")))) + ) + } + + test("Comparing 2.13 libraries with guessSecondSegment under Scala 3.0.0-M3 should work") { + val m1 = "org.scodec" % "scodec-bits_2.13" % "1.1.21" + val m2 = "org.scodec" % "scodec-bits_2.13" % "1.1.22" + assert( + EvictionWarningOptions + .guessSecondSegment((m1, Option(m2), Option(dummyScalaModuleInfo("3.0.0-M3")))) + ) + } + def akkaActor214 = ModuleID("com.typesafe.akka", "akka-actor", "2.1.4").withConfigurations(Some("compile")) cross CrossVersion.binary def akkaActor230 = diff --git a/project/build.properties b/project/build.properties index c19c768d6..c06db1bb2 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.4.2 +sbt.version=1.4.5