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

Use closest previous version when looking for stable Scala versions #1032

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: 0 additions & 1 deletion .github/release/release-procedure.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
```bash
git shortlog -sn --no-merges {old-release-tag}...{new-release-tag}
```
- [ ] Create a pull request with supported scala-versions for the new release to this repository: [Virtuslab/scala-cli-scala-versions ](https://github.com/Virtuslab/scala-cli-scala-versions)
- [ ] ScalaCLI Setup
- [ ] Merge pull request with updated ScalaCLI version in [scala-cli-setup](https://github.com/VirtusLab/scala-cli-setup) repository. Pull request should be opened automatically after release.
- [ ] Make a release with the updated ScalaCLI version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class BuildOptionsTests extends munit.FunSuite {
test("-S 3.nightly option works") {
val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = Some(MaybeScalaVersion("3.nightly")),
scalaBinaryVersion = None,
supportedScalaVersionsUrl = None
scalaVersion = Some(MaybeScalaVersion("3.nightly"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
Expand All @@ -66,9 +64,7 @@ class BuildOptionsTests extends munit.FunSuite {

val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = Some(MaybeScalaVersion(s"3.${Int.MaxValue}")),
scalaBinaryVersion = None,
supportedScalaVersionsUrl = None
scalaVersion = Some(MaybeScalaVersion(s"3.${Int.MaxValue}"))
)
)
assert(
Expand All @@ -83,9 +79,7 @@ class BuildOptionsTests extends munit.FunSuite {

val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = Some(MaybeScalaVersion("2.11.2")),
scalaBinaryVersion = None,
supportedScalaVersionsUrl = None
scalaVersion = Some(MaybeScalaVersion("2.11.2"))
)
)
assert(
Expand All @@ -100,9 +94,7 @@ class BuildOptionsTests extends munit.FunSuite {

val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = Some(MaybeScalaVersion("2.11")),
scalaBinaryVersion = None,
supportedScalaVersionsUrl = None
scalaVersion = Some(MaybeScalaVersion("2.11"))
)
)
assert(
Expand All @@ -117,9 +109,7 @@ class BuildOptionsTests extends munit.FunSuite {

val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = Some(MaybeScalaVersion(s"3.${Int.MaxValue}.3")),
scalaBinaryVersion = None,
supportedScalaVersionsUrl = None
scalaVersion = Some(MaybeScalaVersion(s"3.${Int.MaxValue}.3"))
)
)
assert(
Expand All @@ -134,9 +124,7 @@ class BuildOptionsTests extends munit.FunSuite {

val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = Some(MaybeScalaVersion("3.1.3-RC1-bin-20220213-fd97eee-NIGHTLY")),
scalaBinaryVersion = None,
supportedScalaVersionsUrl = None
scalaVersion = Some(MaybeScalaVersion("3.1.3-RC1-bin-20220213-fd97eee-NIGHTLY"))
)
)
assert(
Expand Down Expand Up @@ -180,9 +168,7 @@ class BuildOptionsTests extends munit.FunSuite {

val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = Some(MaybeScalaVersion(s"2.${Int.MaxValue}")),
scalaBinaryVersion = None,
supportedScalaVersionsUrl = None
scalaVersion = Some(MaybeScalaVersion(s"2.${Int.MaxValue}"))
)
)
assert(
Expand All @@ -196,9 +182,7 @@ class BuildOptionsTests extends munit.FunSuite {
test("-S 2.nightly option works") {
val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = Some(MaybeScalaVersion("2.nightly")),
scalaBinaryVersion = None,
supportedScalaVersionsUrl = None
scalaVersion = Some(MaybeScalaVersion("2.nightly"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
Expand Down Expand Up @@ -237,9 +221,7 @@ class BuildOptionsTests extends munit.FunSuite {
test("-S 2.13.9-bin-4505094 option works without repo specification") {
val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = Some(MaybeScalaVersion("2.13.9-bin-4505094")),
scalaBinaryVersion = None,
supportedScalaVersionsUrl = None
scalaVersion = Some(MaybeScalaVersion("2.13.9-bin-4505094"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
Expand Down Expand Up @@ -275,9 +257,7 @@ class BuildOptionsTests extends munit.FunSuite {
) {
val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = prefix.map(MaybeScalaVersion(_)),
scalaBinaryVersion = None,
supportedScalaVersionsUrl = None
scalaVersion = prefix.map(MaybeScalaVersion(_))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
Expand All @@ -297,15 +277,34 @@ class BuildOptionsTests extends munit.FunSuite {
Some("2.13.2") -> "2.13.2"
)

val confFile = s"""[
| {
| "scalaCliVersion": "$version",
| "supportedScalaVersions": ["3.0.1", "2.13.4", "2.12.13"]
| }
|]""".stripMargin

for ((prefix, expectedScalaVersion) <- expectedScalaConfVersions)
test(s"use expected scala version from conf file, prefix: ${prefix.getOrElse("empty")}") {
val testVersion = "1.11.3"
val testRightAfterVersion = "1.11.4"
val testPrevVersion = "1.11.1"
val testNextVersion = "1.11.5"
val confFile =
s"""[
| {
| "scalaCliVersion": "$testPrevVersion",
| "supportedScalaVersions": ["3.0.0", "2.13.3", "2.12.11"]
| },
| {
| "scalaCliVersion": "$testVersion",
| "supportedScalaVersions": ["3.0.1", "2.13.4", "2.12.13"]
| },
| {
| "scalaCliVersion": "$testNextVersion",
| "supportedScalaVersions": ["3.1.0", "2.13.8", "2.12.15]"]
| }
|]""".stripMargin

for {
(testVer, testNameSuffix) <-
Seq((testVersion, "exact version"), (testRightAfterVersion, "next version"))
(prefix, expectedScalaVersion) <- expectedScalaConfVersions
}
test(
s"use expected scala version from conf file, prefix: ${prefix.getOrElse("empty")}, $testNameSuffix"
) {
TestInputs.withTmpDir("conf-scala-versions") { dirPath =>

val confFilePath = dirPath / "conf-file.json"
Expand All @@ -314,12 +313,11 @@ class BuildOptionsTests extends munit.FunSuite {
val options = BuildOptions(
scalaOptions = ScalaOptions(
scalaVersion = prefix.map(MaybeScalaVersion(_)),
scalaBinaryVersion = None,
supportedScalaVersionsUrl = Some(s"file://${confFilePath.toString()}")
supportedScalaVersionsUrl = Some(confFilePath.toNIO.toUri.toASCIIString)
)
)

val scalaParams = options.scalaParams.orThrow.getOrElse(???)
val scalaParams = options.computeScalaParams(testVer).orThrow.getOrElse(???)
val expectedScalaParams = ScalaParameters(expectedScalaVersion)

expect(scalaParams == expectedScalaParams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ package scala.build.internal

import com.github.plokhotnyuk.jsoniter_scala.core._
import com.github.plokhotnyuk.jsoniter_scala.macros._
import coursier.core.Version

final case class StableScalaVersion(scalaCliVersion: String, supportedScalaVersions: Seq[String])
final case class StableScalaVersion(
scalaCliVersion: String,
supportedScalaVersions: Seq[String]
) {
lazy val scalaCliVersion0 = Version(scalaCliVersion)
}

object StableScalaVersion {
val seqCodec: JsonValueCodec[Seq[StableScalaVersion]] = JsonCodecMaker.make
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.build.errors._
import scala.build.internal.Constants._
import scala.build.internal.CsLoggerUtil._
import scala.build.internal.Regexes.scala3NightlyNicknameRegex
import scala.build.internal.{OsLibc, StableScalaVersion}
import scala.build.internal.{Constants, OsLibc, StableScalaVersion}
import scala.build.options.validation.BuildOptionsRule
import scala.build.{Artifacts, Logger, Os, Position, Positioned}
import scala.util.control.NonFatal
Expand Down Expand Up @@ -230,7 +230,7 @@ final case class BuildOptions(
private def defaultStableScalaVersions =
Seq(defaultScala212Version, defaultScala213Version, defaultScalaVersion)

private def latestSupportedStableScalaVersion(): Seq[Version] = {
private def latestSupportedStableScalaVersion(scalaCliVersion: String): Seq[Version] = {

val msg =
if (internal.verbosityOrDefault > 0)
Expand All @@ -252,8 +252,7 @@ final case class BuildOptions(
}
}

val scalaCliVersion = version
val launchersTask = cache.logger.using(task)
val launchersTask = cache.logger.using(task)

// If an error occurred while downloading stable versions,
// it uses stable scala versions from Deps.sc
Expand All @@ -267,8 +266,13 @@ final case class BuildOptions(
// wrapped in an exception so that the current stack trace appears in the exception
throw new Exception(e)
case Right(versions) =>
versions
.find(_.scalaCliVersion == scalaCliVersion)
versions.find(_.scalaCliVersion == scalaCliVersion)
.orElse {
val scalaCliVersion0 = Version(scalaCliVersion)
versions
.filter(_.scalaCliVersion0.compareTo(scalaCliVersion0) <= 0)
.maxByOption(_.scalaCliVersion0)
}
.map(_.supportedScalaVersions)
.getOrElse {
// FIXME Log that: logger.debug(s"Couldn't find Scala CLI version $scalaCliVersion in $versions")
Expand Down Expand Up @@ -324,9 +328,13 @@ final case class BuildOptions(
internal.localRepository.toSeq
}

lazy val scalaParams: Either[BuildException, Option[ScalaParameters]] = either {
lazy val scalaParams: Either[BuildException, Option[ScalaParameters]] =
computeScalaParams(Constants.version)

private[build] def computeScalaParams(scalaCliVersion: String)
: Either[BuildException, Option[ScalaParameters]] = either {

lazy val maxSupportedStableScalaVersions = latestSupportedStableScalaVersion()
lazy val maxSupportedStableScalaVersions = latestSupportedStableScalaVersion(scalaCliVersion)
lazy val latestSupportedStableVersions = maxSupportedStableScalaVersions.map(_.repr)

val svOpt: Option[String] = scalaOptions.scalaVersion match {
Expand Down