Skip to content

Commit

Permalink
Add 3.lts and lts scala version option (#2709)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek authored Feb 7, 2024
1 parent dc8edf3 commit 05f1466
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ trait Core extends ScalaCliSbtModule with ScalaCliPublishModule with HasTests
| def defaultScalaVersion = "${Scala.defaultUser}"
| def defaultScala212Version = "${Scala.scala212}"
| def defaultScala213Version = "${Scala.scala213}"
| def scala3Lts = "${Scala.scala3Lts}"
|
| def workspaceDirName = "$workspaceDirName"
| def projectFileName = "$projectFileName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import scala.build.Directories
import scala.build.Positioned
import scala.build.tests.util.BloopServer
import scala.concurrent.duration.DurationInt
import scala.build.internal.Regexes.scala3LtsRegex
import scala.build.errors.ScalaVersionError

class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {

Expand Down Expand Up @@ -95,6 +97,21 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
)
}

test(s"Scala 2.lts shows Scala Version Error") {

val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = Some(MaybeScalaVersion(s"3.${Int.MaxValue}"))
)
)
assert(
options.projectParams.swap.exists {
case _: ScalaVersionError => true; case _ => false
},
s"specifying 2.lts scala version does not lead to Scala Version Error"
)
}

test("Scala 2.11.2 shows Unupported Scala Version Error") {

val options = BuildOptions(
Expand Down Expand Up @@ -226,6 +243,19 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
)
}

test("-S 3.lts option works") {
val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = Some(MaybeScalaVersion("3.lts"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
assert(
scala3LtsRegex.unapplySeq(scalaParams.scalaVersion).isDefined,
"-S 3.lts argument does not lead to scala3 LTS"
)
}

test("-S 2.12.nightly option works") {
val options = BuildOptions(
scalaOptions = ScalaOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ object ScalaVersionError {
|In addition, you can request compilation with the last nightly versions of Scala,
|by passing the 2.nightly, 2.12.nightly, 2.13.nightly, or 3.nightly arguments.
|Specific Scala 2 or Scala 3 nightly versions are also accepted.
|You can also request the latest Scala 3 LTS by passing lts or 3.lts.
|""".stripMargin
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package scala.build.internal
object Regexes {
val scala2NightlyRegex = raw"""2\.(\d+)\.(\d+)-bin-[a-f0-9]*""".r
val scala3NightlyNicknameRegex = raw"""3\.([0-9]*)\.nightly""".r
val scala3LtsRegex = raw"""3\.3\.[0-9]+""".r
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ final case class BuildOptions(
case Some(MaybeScalaVersion(Some(svInput))) =>
val sv = value {
svInput match {
case sv if ScalaVersionUtil.scala3Lts.contains(sv) =>
ScalaVersionUtil.validateStable(
Constants.scala3Lts,
cache,
repositories
)
case sv if ScalaVersionUtil.scala2Lts.contains(sv) =>
Left(new ScalaVersionError(s"Invalid Scala version: ${sv}. There is no official LTS version for Scala 2."))
case sv if sv == ScalaVersionUtil.scala3Nightly =>
ScalaVersionUtil.GetNightly.scala3(cache)
case scala3NightlyNicknameRegex(threeSubBinaryNum) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ object ScalaVersionUtil {
def scala212Nightly = "2.12.nightly"
def scala213Nightly = List("2.13.nightly", "2.nightly")
def scala3Nightly = "3.nightly"
def scala3Lts = List("3.lts", "lts")
// not valid versions, defined only for informative error messages
def scala2Lts = List("2.13.lts", "2.12.lts", "2.lts")
extension (cache: FileCache[Task]) {
def fileWithTtl0(artifact: Artifact): Either[ArtifactError, File] =
cache.logger.use {
Expand Down
1 change: 1 addition & 0 deletions project/deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ object Scala {
def scala213 = "2.13.12"
def runnerScala3 = "3.0.2" // the newest version that is compatible with all Scala 3.x versions
def scala3 = "3.3.1"
def scala3Lts = "3.3" //the full version should be resolved later

// The Scala version used to build the CLI itself.
def defaultInternal = sys.props.get("scala.version.internal").getOrElse(scala3)
Expand Down

0 comments on commit 05f1466

Please sign in to comment.