Skip to content

Commit 37c1b13

Browse files
authored
Adjust TASTY bump warnings to respect overridden Scala version defaults (#2888)
1 parent bf15e1f commit 37c1b13

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

build.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ trait TastyLib extends ScalaCliCrossSbtModule
11801180
|
11811181
|/** Build-time constants. Generated by mill. */
11821182
|object Constants {
1183-
| def latestSupportedScala = "${Scala.defaultUser}"
1183+
| def defaultScalaVersion = "${Scala.defaultUser}"
11841184
|}
11851185
|""".stripMargin
11861186
if (!os.isFile(dest) || os.read(dest) != code)

modules/build/src/main/scala/scala/build/postprocessing/TastyPostProcessor.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ case object TastyPostProcessor extends PostProcessor {
2727
}
2828
.toMap
2929

30-
TastyVersions.shouldRunPreprocessor(scalaVersion, Constants.version) match {
30+
TastyVersions.shouldRunPreprocessor(
31+
scalaVersion,
32+
Constants.version,
33+
buildOptions.scalaOptions.defaultScalaVersion
34+
) match {
3135
case Right(false) => Right(())
3236
case Left(msg) => if (updatedPaths.isEmpty) Right(()) else Left(msg)
3337
case Right(true) =>

modules/integration/src/test/scala/scala/cli/integration/SipScalaTests.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,4 +711,26 @@ class SipScalaTests extends ScalaCliSuite with SbtTestHelper with MillTestHelper
711711
expect(exportRes.out.trim().contains(s""""scalaVersion": "$defaultSv""""))
712712
}
713713
}
714+
715+
test("no warnings about TASTY when using the latest nightly with scripts") {
716+
val scriptName = "script.sc"
717+
TestInputs(os.rel / "script.sc" -> "println(1)").fromRoot { root =>
718+
val scala3Nightly =
719+
os.proc(
720+
TestUtil.cli,
721+
"-e",
722+
"println(dotty.tools.dotc.config.Properties.versionNumberString)",
723+
"-S",
724+
"3.nightly",
725+
"--with-compiler"
726+
)
727+
.call(cwd = root)
728+
.out.trim()
729+
val res =
730+
os.proc(TestUtil.cli, "--cli-default-scala-version", scala3Nightly, "run", scriptName)
731+
.call(cwd = root, stderr = os.Pipe)
732+
expect(res.exitCode == 0)
733+
expect(!res.err.trim().contains("TASTY"))
734+
}
735+
}
714736
}

modules/tasty-lib/src/main/scala/scala/build/tastylib/TastyVersions.scala

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,21 @@ object TastyVersions {
88
def majorVersion: Int = version.split('.')(0).toInt
99
def minorVersion: Int = version.split('.')(1).toInt
1010
def minorVersionOption: Option[Int] = Try(minorVersion).toOption
11-
}
12-
13-
// Every time tasty version is updated, please update LatestSupportedScala as well!
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+
def isLatestSupportedMajorVersion(latestSupportedScalaVersion: String): Boolean = {
12+
val latestSupportedMajor = latestSupportedScalaVersion.majorVersion.toString
13+
version.startsWith(s"$latestSupportedMajor.") || version == latestSupportedMajor
14+
}
2115
}
2216

2317
def shouldRunPreprocessor(
2418
scalaVersion: String,
25-
scalaCliVersion: String
26-
): Either[String, Boolean] =
27-
if (!LatestSupportedScala.isLatestSupportedMajorVersion(scalaVersion)) Right(false)
19+
scalaCliVersion: String,
20+
defaultScalaVersion: Option[String]
21+
): Either[String, Boolean] = {
22+
val scalaDefault = defaultScalaVersion.getOrElse(Constants.defaultScalaVersion)
23+
if (!scalaVersion.isLatestSupportedMajorVersion(scalaDefault)) Right(false)
2824
else scalaVersion.minorVersionOption match {
29-
case Some(scalaMinor) if scalaMinor > LatestSupportedScala.MinorVersion =>
25+
case Some(scalaMinor) if scalaMinor > scalaDefault.minorVersion =>
3026
Left(
3127
s"""Scala CLI (v$scalaCliVersion) cannot post process TASTY files from Scala $scalaVersion.
3228
|This is not a fatal error since post processing only cleans up source paths in TASTY file.
@@ -38,4 +34,5 @@ object TastyVersions {
3834
)
3935
case _ => Right(true)
4036
}
37+
}
4138
}

0 commit comments

Comments
 (0)