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

Add 3.lts and lts scala version option #2709

Merged
merged 1 commit into from
Feb 7, 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
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
Gedochao marked this conversation as resolved.
Show resolved Hide resolved

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