Skip to content

Commit

Permalink
Make sure tasty-lib doesn't warn about Scala 3 Next (#2775)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao authored Mar 6, 2024
1 parent 008c32f commit 052aea8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ trait TastyLib extends ScalaCliCrossSbtModule
|
|/** Build-time constants. Generated by mill. */
|object Constants {
| def latestSupportedScala = "${Scala.defaultInternal}"
| def latestSupportedScala = "${Scala.defaultUser}"
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,4 +697,15 @@ abstract class CompileTestDefinitions
expect(out.contains("Too small maximum heap"))
}
}

test(s"TASTY processor does not warn about Scala $actualScalaVersion") {
TestInputs(os.rel / "simple.sc" -> s"""println("Hello")""")
.fromRoot { root =>
val result =
os.proc(TestUtil.cli, "compile", ".", extraOptions)
.call(cwd = root, stderr = os.Pipe)
expect(result.exitCode == 0)
expect(!result.err.text().contains("cannot post process TASTY files"))
}
}
}
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)
}
}

0 comments on commit 052aea8

Please sign in to comment.