Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support target files built with nightly Scala 3 compiler version #2153

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package scalafix.internal.config

import java.time.LocalDate
import java.time.format.DateTimeFormatter

import scala.util.Failure
import scala.util.Success
import scala.util.Try
Expand Down Expand Up @@ -44,9 +47,21 @@ sealed trait ScalaVersion {
case Minor(major, minorVersion) => s"${major.value}.${minorVersion}"
case Patch(major, minorVersion, patchVersion) =>
s"${major.value}.${minorVersion}.$patchVersion"
case RC(major, minorVersion, patchVersion, rc) =>
s"${major.value}.${minorVersion}.$patchVersion-RC$rc"
case Nightly(major, minorVersion, patchVersion, shortSha1) =>
case RC(major, minorVersion, patchVersion, rcVersion) =>
s"${major.value}.${minorVersion}.$patchVersion-RC$rcVersion"
// Scala 3 nightly
case Nightly(
major,
minorVersion,
patchVersion,
maybeRcVersion,
Some(dateVersion),
shortSha1
) =>
val maybeRcSuffix = maybeRcVersion.map("-RC" + _).getOrElse("")
s"${major.value}.${minorVersion}.$patchVersion$maybeRcSuffix-bin-${dateVersion.format(yyyyMMdd)}-$shortSha1-NIGHTLY"
// Scala 2 nightly
case Nightly(major, minorVersion, patchVersion, _, _, shortSha1) =>
s"${major.value}.${minorVersion}.$patchVersion-bin-$shortSha1"
}
}
Expand Down Expand Up @@ -92,6 +107,8 @@ object ScalaVersion {
major: MajorVersion,
minorVersion: Int,
patchVersion: Int,
rcVersion: Option[Int],
dateVersion: Option[LocalDate],
shortSha1Version: String
) extends ScalaVersion {
override val minor: Some[Int] = Some(minorVersion)
Expand Down Expand Up @@ -126,22 +143,34 @@ object ScalaVersion {
}

private val intPattern = """\d{1,2}"""
private val datePattern = """\d{8}"""
private val shortSha1Pattern = """[0-9a-f]{7}"""

private val FullVersion =
raw"""($intPattern)\.($intPattern)\.($intPattern)""".r
private val RcVersion =
raw"""($intPattern)\.($intPattern)\.($intPattern)-RC($intPattern)""".r
private val NightlyVersion =
raw"""($intPattern)\.($intPattern)\.($intPattern)-bin-($shortSha1Pattern)""".r
raw"""($intPattern)\.($intPattern)\.($intPattern)(?:-RC($intPattern))?-bin(?:-($datePattern))?-($shortSha1Pattern)(?:-NIGHTLY)?""".r
private val MajorPattern = raw"""($intPattern)""".r
private val PartialVersion = raw"""($intPattern)\.($intPattern)""".r

private val yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd")

def from(version: String): Try[ScalaVersion] = {
version match {
case NightlyVersion(major, minor, patch, shortSha1) =>
case NightlyVersion(major, minor, patch, rc, date, shortSha1) =>
MajorVersion.from(major.toLong).flatMap { major =>
Success(Nightly(major, minor.toInt, patch.toInt, shortSha1))
Success(
Nightly(
major,
minor.toInt,
patch.toInt,
Try(rc.toInt).toOption,
Try(LocalDate.parse(date, yyyyMMdd)).toOption,
shortSha1
)
)
}
case RcVersion(major, minor, patch, rc) =>
MajorVersion.from(major.toLong).flatMap { major =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,30 @@ class ScalaVersionSuite extends munit.FunSuite {

test("parse: 2.13.16-bin-ce78754") {
val scala2 = ScalaVersion.from("2.13.16-bin-ce78754")
assert(scala2.get == Nightly(Major.Scala2, 13, 16, "ce78754"))
assert(scala2.get == Nightly(Major.Scala2, 13, 16, None, None, "ce78754"))
assert(scala2.get.value == "2.13.16-bin-ce78754")
}

test("parse: 3.0.0-RC3") {
val scala3 = ScalaVersion.from("3.0.0-RC3")
assert(scala3.get == RC(Major.Scala3, 0, 0, 3))
}

test("parse: 3.6.0-RC1-bin-20241008-3408ed7-NIGHTLY") {
val scala3 = ScalaVersion.from("3.6.0-RC1-bin-20241008-3408ed7-NIGHTLY")
assert(
scala3.get == Nightly(
Major.Scala3,
6,
0,
Some(1),
Some(java.time.LocalDate.parse("2024-10-08")),
"3408ed7"
)
)
assert(scala3.get.value == "3.6.0-RC1-bin-20241008-3408ed7-NIGHTLY")
}

test("parse failure: 3.0.0RC3") {
val scala3 = ScalaVersion.from("3.0.0RC3")
assert(scala3.isFailure)
Expand Down
Loading