Merge pull request #350 from adpi2/sbt-dotty

Add Scala 3 artifacts and binary versioning
This commit is contained in:
eugene yokota 2020-12-17 11:04:09 -05:00 committed by GitHub
commit 0672da475d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 16 deletions

View File

@ -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 =

View File

@ -8,27 +8,46 @@ object ScalaArtifacts {
val ActorsID = "scala-actors"
val ScalapID = "scalap"
val Artifacts = Vector(LibraryID, CompilerID, ReflectID, ActorsID, ScalapID)
val DottyIDPrefix = "dotty"
def dottyID(binaryVersion: String): String = s"${DottyIDPrefix}_${binaryVersion}"
val Scala3LibraryID = "scala3-library"
val Scala3CompilerID = "scala3-compiler"
def libraryDependency(version: String): ModuleID = ModuleID(Organization, LibraryID, version)
def isScala3(scalaVersion: String): Boolean = scalaVersion.startsWith("3.")
def libraryIds(version: String): Array[String] = {
if (isScala3(version))
Array(Scala3LibraryID, LibraryID)
else Array(LibraryID)
}
def compilerId(version: String): String = {
if (isScala3(version)) Scala3CompilerID
else CompilerID
}
def libraryDependency(version: String): ModuleID = libraryDependency(Organization, version)
def libraryDependency(org: String, version: String): ModuleID = {
if (isScala3(version))
ModuleID(org, Scala3LibraryID, version).withCrossVersion(CrossVersion.binary)
else
ModuleID(org, LibraryID, version)
}
private[sbt] def toolDependencies(
org: String,
version: String,
isDotty: Boolean = false
version: String
): Seq[ModuleID] =
if (isDotty)
if (isScala3(version))
Seq(
ModuleID(org, DottyIDPrefix, version)
ModuleID(org, Scala3CompilerID, version)
.withConfigurations(Some(Configurations.ScalaTool.name + "->default(compile)"))
.withCrossVersion(CrossVersion.binary)
)
else
Seq(
scalaToolDependency(org, ScalaArtifacts.CompilerID, version),
scalaToolDependency(org, ScalaArtifacts.LibraryID, version)
scalaToolDependency(org, CompilerID, version),
scalaToolDependency(org, LibraryID, version)
)
private[this] def scalaToolDependency(org: String, id: String, version: String): ModuleID =

View File

@ -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) =