-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure
tasty-lib
doesn't warn about Scala 3 Next (#2775)
- Loading branch information
Showing
3 changed files
with
39 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 27 additions & 16 deletions
43
modules/tasty-lib/src/main/scala/scala/build/tastylib/TastyVersions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
package scala.build.tastylib | ||
|
||
import scala.build.tastylib.internal.Constants | ||
import scala.util.Try | ||
|
||
object TastyVersions { | ||
implicit class VersionOps(version: String) { | ||
def majorVersion: Int = version.split('.')(0).toInt | ||
def minorVersion: Int = version.split('.')(1).toInt | ||
def minorVersionOption: Option[Int] = Try(minorVersion).toOption | ||
} | ||
|
||
// Every time tasty version is updated, please update LatestSupportedScala as well! | ||
object LatestSupportedScala { | ||
final val MajorVersion: Int = 3 | ||
final val MinorVersion: Int = Constants.latestSupportedScala.split('.')(1).toInt | ||
private object LatestSupportedScala { | ||
final val MajorVersion: Int = Constants.latestSupportedScala.majorVersion | ||
final val MinorVersion: Int = Constants.latestSupportedScala.minorVersion | ||
|
||
def isLatestSupportedMajorVersion(scalaVersion: String): Boolean = | ||
scalaVersion.startsWith(s"${LatestSupportedScala.MajorVersion}.") || | ||
scalaVersion == LatestSupportedScala.MajorVersion.toString | ||
} | ||
|
||
def shouldRunPreprocessor( | ||
scalaVersion: String, | ||
scalaCliVersion: String | ||
): Either[String, Boolean] = | ||
if (!scalaVersion.startsWith("3.") && scalaVersion != "3") Right(false) | ||
else | ||
scalaVersion.split('.')(1).toInt match { | ||
case scalaMinor if scalaMinor > LatestSupportedScala.MinorVersion => | ||
Left( | ||
s"Scala CLI (v. $scalaCliVersion) cannot post process TASTY files from Scala $scalaVersion.\n" + | ||
s"This is not a fatal error since post processing only cleans up source paths in TASTY file " + | ||
s"and it should not affect your application.\n" + | ||
s"To get rid of this message, please update Scala CLI version." | ||
) | ||
case _ => | ||
Right(true) | ||
} | ||
if (!LatestSupportedScala.isLatestSupportedMajorVersion(scalaVersion)) Right(false) | ||
else scalaVersion.minorVersionOption match { | ||
case Some(scalaMinor) if scalaMinor > LatestSupportedScala.MinorVersion => | ||
Left( | ||
s"""Scala CLI (v$scalaCliVersion) cannot post process TASTY files from Scala $scalaVersion. | ||
|This is not a fatal error since post processing only cleans up source paths in TASTY file. | ||
|It should not affect your application. | ||
|You may be getting this warning because you are using a newer version of Scala than the one supported by Scala CLI (v$scalaCliVersion). | ||
|Make sure your Scala CLI is up-to-date. | ||
|You may need to wait for $scalaVersion support in a future version of Scala CLI. | ||
|""".stripMargin | ||
) | ||
case _ => Right(true) | ||
} | ||
} |