mirror of https://github.com/sbt/sbt.git
Add Scala 3 binary versioning
This commit is contained in:
parent
6c1926603f
commit
f1ede7cd06
|
|
@ -1,6 +1,8 @@
|
|||
package sbt.internal.librarymanagement
|
||||
package cross
|
||||
|
||||
import sbt.librarymanagement.ScalaArtifacts
|
||||
|
||||
object CrossVersionUtil {
|
||||
val trueString = "true"
|
||||
val falseString = "false"
|
||||
|
|
@ -8,7 +10,6 @@ object CrossVersionUtil {
|
|||
val noneString = "none"
|
||||
val disabledString = "disabled"
|
||||
val binaryString = "binary"
|
||||
val TransitionDottyVersion = "" // Dotty always respects binary compatibility
|
||||
val TransitionScalaVersion = "2.10" // ...but scalac doesn't until Scala 2.10
|
||||
val TransitionSbtVersion = "0.12"
|
||||
|
||||
|
|
@ -22,8 +23,9 @@ object CrossVersionUtil {
|
|||
private val longPattern = """\d{1,19}"""
|
||||
private val basicVersion = raw"""($longPattern)\.($longPattern)\.($longPattern)"""
|
||||
private val ReleaseV = raw"""$basicVersion(-\d+)?""".r
|
||||
private val BinCompatV = raw"""$basicVersion-bin(-.*)?""".r
|
||||
private val BinCompatV = raw"""$basicVersion(-\w+)?-bin(-.*)?""".r
|
||||
private val CandidateV = raw"""$basicVersion(-RC\d+)""".r
|
||||
private val MilestonV = raw"""$basicVersion(-M\d+)""".r
|
||||
private val NonReleaseV_n = raw"""$basicVersion([-\w]*)""".r // 0-n word suffixes, with leading dashes
|
||||
private val NonReleaseV_1 = raw"""$basicVersion(-\w+)""".r // 1 word suffix, after a dash
|
||||
private[sbt] val PartialVersion = raw"""($longPattern)\.($longPattern)(?:\..+)?""".r
|
||||
|
|
@ -61,7 +63,7 @@ object CrossVersionUtil {
|
|||
*/
|
||||
private[sbt] def scalaApiVersion(v: String): Option[(Long, Long)] = v match {
|
||||
case ReleaseV(x, y, _, _) => Some((x.toLong, y.toLong))
|
||||
case BinCompatV(x, y, _, _) => Some((x.toLong, y.toLong))
|
||||
case BinCompatV(x, y, _, _, _) => Some((x.toLong, y.toLong))
|
||||
case NonReleaseV_1(x, y, z, _) if z.toInt > 0 => Some((x.toLong, y.toLong))
|
||||
case _ => None
|
||||
}
|
||||
|
|
@ -72,9 +74,18 @@ object CrossVersionUtil {
|
|||
case _ => None
|
||||
}
|
||||
|
||||
private[sbt] def binaryScala3Version(full: String): String = full match {
|
||||
case ReleaseV(maj, _, _, _) => maj
|
||||
case CandidateV(maj, min, _, _) if min.toLong > 0 => maj
|
||||
case MilestonV(maj, min, _, _) if min.toLong > 0 => maj
|
||||
case BinCompatV(maj, min, patch, stage, _) => binaryScala3Version(s"$maj.$min.$patch$stage")
|
||||
case _ => full
|
||||
}
|
||||
|
||||
def binaryScalaVersion(full: String): String = {
|
||||
val cutoff = if (full.startsWith("0.")) TransitionDottyVersion else TransitionScalaVersion
|
||||
binaryVersionWithApi(full, cutoff)(scalaApiVersion)
|
||||
if (ScalaArtifacts.isScala3(full)) binaryScala3Version(full)
|
||||
else
|
||||
binaryVersionWithApi(full, TransitionScalaVersion)(scalaApiVersion) // Scala 2 binary version
|
||||
}
|
||||
|
||||
def binarySbtVersion(full: String): String =
|
||||
|
|
|
|||
|
|
@ -207,8 +207,35 @@ class CrossVersionTest extends UnitSpec {
|
|||
it should "for 2.20170314093845.0-87654321 return 2.20170314093845" in {
|
||||
binaryScalaVersion("2.20170314093845.0-87654321") shouldBe "2.20170314093845"
|
||||
}
|
||||
it should "for Dotty 0.1.1 return 0.1" in {
|
||||
binaryScalaVersion("0.1.1") shouldBe "0.1"
|
||||
it should "for 3.0.0-M2 return 3.0.0-M2" in {
|
||||
binaryScalaVersion("3.0.0-M2") shouldBe "3.0.0-M2"
|
||||
}
|
||||
it should "for 3.0.0-M3-bin-SNAPSHOT return 3.0.0-M3" in {
|
||||
binaryScalaVersion("3.0.0-M3-bin-SNAPSHOT") shouldBe "3.0.0-M3"
|
||||
}
|
||||
it should "for 3.0.0-M3-bin-20201215-cbe50b3-NIGHTLY return 3.0.0-M3" in {
|
||||
binaryScalaVersion("3.0.0-M3-bin-20201215-cbe50b3-NIGHTLY") shouldBe "3.0.0-M3"
|
||||
}
|
||||
it should "for 3.0.0-RC1 return 3.0.0-RC1" in {
|
||||
binaryScalaVersion("3.0.0-RC1") shouldBe "3.0.0-RC1"
|
||||
}
|
||||
|
||||
// Not set in stone but 3 is the favorite candidate so far
|
||||
// (see https://github.com/lampepfl/dotty/issues/10244)
|
||||
it should "for 3.0.0 return 3" in {
|
||||
binaryScalaVersion("3.0.0") shouldBe "3"
|
||||
}
|
||||
it should "for 3.1.0-M1 return 3" in {
|
||||
binaryScalaVersion("3.1.0-M1") shouldBe "3"
|
||||
}
|
||||
it should "for 3.1.0-RC1-bin-SNAPSHOT return 3" in {
|
||||
binaryScalaVersion("3.1.0-RC1-bin-SNAPSHOT") shouldBe "3"
|
||||
}
|
||||
it should "for 3.1.0-RC1 return 3" in {
|
||||
binaryScalaVersion("3.1.0-RC1") shouldBe "3"
|
||||
}
|
||||
it should "for 3.1.0 return 3" in {
|
||||
binaryScalaVersion("3.1.0") shouldBe "3"
|
||||
}
|
||||
|
||||
private def patchVersion(fullVersion: String) =
|
||||
|
|
|
|||
Loading…
Reference in New Issue