|
1 | 1 | package scala.build.tastylib
|
2 | 2 |
|
3 | 3 | import scala.build.tastylib.internal.Constants
|
| 4 | +import scala.util.Try |
4 | 5 |
|
5 | 6 | object TastyVersions {
|
| 7 | + implicit class VersionOps(version: String) { |
| 8 | + def majorVersion: Int = version.split('.')(0).toInt |
| 9 | + def minorVersion: Int = version.split('.')(1).toInt |
| 10 | + def minorVersionOption: Option[Int] = Try(minorVersion).toOption |
| 11 | + } |
6 | 12 |
|
7 | 13 | // Every time tasty version is updated, please update LatestSupportedScala as well!
|
8 |
| - object LatestSupportedScala { |
9 |
| - final val MajorVersion: Int = 3 |
10 |
| - final val MinorVersion: Int = Constants.latestSupportedScala.split('.')(1).toInt |
| 14 | + private object LatestSupportedScala { |
| 15 | + final val MajorVersion: Int = Constants.latestSupportedScala.majorVersion |
| 16 | + final val MinorVersion: Int = Constants.latestSupportedScala.minorVersion |
| 17 | + |
| 18 | + def isLatestSupportedMajorVersion(scalaVersion: String): Boolean = |
| 19 | + scalaVersion.startsWith(s"${LatestSupportedScala.MajorVersion}.") || |
| 20 | + scalaVersion == LatestSupportedScala.MajorVersion.toString |
11 | 21 | }
|
12 | 22 |
|
13 | 23 | def shouldRunPreprocessor(
|
14 | 24 | scalaVersion: String,
|
15 | 25 | scalaCliVersion: String
|
16 | 26 | ): Either[String, Boolean] =
|
17 |
| - if (!scalaVersion.startsWith("3.") && scalaVersion != "3") Right(false) |
18 |
| - else |
19 |
| - scalaVersion.split('.')(1).toInt match { |
20 |
| - case scalaMinor if scalaMinor > LatestSupportedScala.MinorVersion => |
21 |
| - Left( |
22 |
| - s"Scala CLI (v. $scalaCliVersion) cannot post process TASTY files from Scala $scalaVersion.\n" + |
23 |
| - s"This is not a fatal error since post processing only cleans up source paths in TASTY file " + |
24 |
| - s"and it should not affect your application.\n" + |
25 |
| - s"To get rid of this message, please update Scala CLI version." |
26 |
| - ) |
27 |
| - case _ => |
28 |
| - Right(true) |
29 |
| - } |
| 27 | + if (!LatestSupportedScala.isLatestSupportedMajorVersion(scalaVersion)) Right(false) |
| 28 | + else scalaVersion.minorVersionOption match { |
| 29 | + case Some(scalaMinor) if scalaMinor > LatestSupportedScala.MinorVersion => |
| 30 | + Left( |
| 31 | + s"""Scala CLI (v$scalaCliVersion) cannot post process TASTY files from Scala $scalaVersion. |
| 32 | + |This is not a fatal error since post processing only cleans up source paths in TASTY file. |
| 33 | + |It should not affect your application. |
| 34 | + |You may be getting this warning because you are using a newer version of Scala than the one supported by Scala CLI (v$scalaCliVersion). |
| 35 | + |Make sure your Scala CLI is up-to-date. |
| 36 | + |You may need to wait for $scalaVersion support in a future version of Scala CLI. |
| 37 | + |""".stripMargin |
| 38 | + ) |
| 39 | + case _ => Right(true) |
| 40 | + } |
30 | 41 | }
|
0 commit comments