Skip to content

Commit 05f1466

Browse files
authored
Add 3.lts and lts scala version option (#2709)
1 parent dc8edf3 commit 05f1466

File tree

7 files changed

+45
-0
lines changed

7 files changed

+45
-0
lines changed

build.sc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ trait Core extends ScalaCliSbtModule with ScalaCliPublishModule with HasTests
451451
| def defaultScalaVersion = "${Scala.defaultUser}"
452452
| def defaultScala212Version = "${Scala.scala212}"
453453
| def defaultScala213Version = "${Scala.scala213}"
454+
| def scala3Lts = "${Scala.scala3Lts}"
454455
|
455456
| def workspaceDirName = "$workspaceDirName"
456457
| def projectFileName = "$projectFileName"

modules/build/src/test/scala/scala/build/tests/BuildOptionsTests.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import scala.build.Directories
2929
import scala.build.Positioned
3030
import scala.build.tests.util.BloopServer
3131
import scala.concurrent.duration.DurationInt
32+
import scala.build.internal.Regexes.scala3LtsRegex
33+
import scala.build.errors.ScalaVersionError
3234

3335
class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
3436

@@ -95,6 +97,21 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
9597
)
9698
}
9799

100+
test(s"Scala 2.lts shows Scala Version Error") {
101+
102+
val options = BuildOptions(
103+
scalaOptions = ScalaOptions(
104+
scalaVersion = Some(MaybeScalaVersion(s"3.${Int.MaxValue}"))
105+
)
106+
)
107+
assert(
108+
options.projectParams.swap.exists {
109+
case _: ScalaVersionError => true; case _ => false
110+
},
111+
s"specifying 2.lts scala version does not lead to Scala Version Error"
112+
)
113+
}
114+
98115
test("Scala 2.11.2 shows Unupported Scala Version Error") {
99116

100117
val options = BuildOptions(
@@ -226,6 +243,19 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
226243
)
227244
}
228245

246+
test("-S 3.lts option works") {
247+
val options = BuildOptions(
248+
scalaOptions = ScalaOptions(
249+
scalaVersion = Some(MaybeScalaVersion("3.lts"))
250+
)
251+
)
252+
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
253+
assert(
254+
scala3LtsRegex.unapplySeq(scalaParams.scalaVersion).isDefined,
255+
"-S 3.lts argument does not lead to scala3 LTS"
256+
)
257+
}
258+
229259
test("-S 2.12.nightly option works") {
230260
val options = BuildOptions(
231261
scalaOptions = ScalaOptions(

modules/core/src/main/scala/scala/build/errors/ScalaVersionError.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ object ScalaVersionError {
2020
|In addition, you can request compilation with the last nightly versions of Scala,
2121
|by passing the 2.nightly, 2.12.nightly, 2.13.nightly, or 3.nightly arguments.
2222
|Specific Scala 2 or Scala 3 nightly versions are also accepted.
23+
|You can also request the latest Scala 3 LTS by passing lts or 3.lts.
2324
|""".stripMargin
2425
}

modules/core/src/main/scala/scala/build/internals/Regexes.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ package scala.build.internal
33
object Regexes {
44
val scala2NightlyRegex = raw"""2\.(\d+)\.(\d+)-bin-[a-f0-9]*""".r
55
val scala3NightlyNicknameRegex = raw"""3\.([0-9]*)\.nightly""".r
6+
val scala3LtsRegex = raw"""3\.3\.[0-9]+""".r
67
}

modules/options/src/main/scala/scala/build/options/BuildOptions.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,14 @@ final case class BuildOptions(
330330
case Some(MaybeScalaVersion(Some(svInput))) =>
331331
val sv = value {
332332
svInput match {
333+
case sv if ScalaVersionUtil.scala3Lts.contains(sv) =>
334+
ScalaVersionUtil.validateStable(
335+
Constants.scala3Lts,
336+
cache,
337+
repositories
338+
)
339+
case sv if ScalaVersionUtil.scala2Lts.contains(sv) =>
340+
Left(new ScalaVersionError(s"Invalid Scala version: ${sv}. There is no official LTS version for Scala 2."))
333341
case sv if sv == ScalaVersionUtil.scala3Nightly =>
334342
ScalaVersionUtil.GetNightly.scala3(cache)
335343
case scala3NightlyNicknameRegex(threeSubBinaryNum) =>

modules/options/src/main/scala/scala/build/options/ScalaVersionUtil.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ object ScalaVersionUtil {
3131
def scala212Nightly = "2.12.nightly"
3232
def scala213Nightly = List("2.13.nightly", "2.nightly")
3333
def scala3Nightly = "3.nightly"
34+
def scala3Lts = List("3.lts", "lts")
35+
// not valid versions, defined only for informative error messages
36+
def scala2Lts = List("2.13.lts", "2.12.lts", "2.lts")
3437
extension (cache: FileCache[Task]) {
3538
def fileWithTtl0(artifact: Artifact): Either[ArtifactError, File] =
3639
cache.logger.use {

project/deps.sc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ object Scala {
55
def scala213 = "2.13.12"
66
def runnerScala3 = "3.0.2" // the newest version that is compatible with all Scala 3.x versions
77
def scala3 = "3.3.1"
8+
def scala3Lts = "3.3" //the full version should be resolved later
89

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

0 commit comments

Comments
 (0)