Use binary compiler bridge

Problem
-------
Starting Scala 2.13.12, Scala 2 has in-sourced the compiler bridge
implementtion, which hopefully will be kept up to date more than the
ones in Zinc.

Solution
--------
This switches to using the pre-compiled compiler bridge for >=2.13.12.
This commit is contained in:
Eugene Yokota 2023-09-11 23:15:15 -04:00
parent edac172780
commit b1e9308ebe
29 changed files with 43 additions and 31 deletions

View File

@ -715,7 +715,9 @@ object Defaults extends BuildCommon {
clean := clean.dependsOn(cleanIvy).value,
scalaCompilerBridgeBinaryJar := Def.settingDyn {
val sv = scalaVersion.value
if (ScalaArtifacts.isScala3(sv)) fetchBridgeBinaryJarTask(sv)
if (ScalaArtifacts.isScala3(sv) || VersionNumber(sv)
.matchesSemVer(SemanticSelector(s"=2.13 >=${ZincLmUtil.scala2SbtBridgeStart}")))
fetchBridgeBinaryJarTask(sv)
else Def.task[Option[File]](None)
}.value,
scalaCompilerBridgeSource := ZincLmUtil.getDefaultBridgeSourceModule(scalaVersion.value),

View File

@ -1,6 +1,7 @@
lazy val check = taskKey[Unit]("")
lazy val compile2 = taskKey[Unit]("")
lazy val scala212 = "2.12.18"
lazy val scala213 = "2.13.12"
lazy val root = (project in file("."))
.aggregate(foo, bar, client)
@ -11,7 +12,7 @@ lazy val root = (project in file("."))
lazy val foo = project
.settings(
crossScalaVersions := Seq(scala212, "2.13.11"),
crossScalaVersions := Seq(scala212, scala213),
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.0",
check := {
@ -43,7 +44,7 @@ lazy val bar = project
lazy val baz = project
.settings(
crossScalaVersions := Seq("2.13.11"),
crossScalaVersions := Seq(scala213),
check := {
// This tests that +baz/check will respect bar's crossScalaVersions and not switch
val x = (LocalProject("bar") / scalaVersion).value
@ -54,7 +55,7 @@ lazy val baz = project
lazy val client = project
.settings(
crossScalaVersions := Seq(scala212, "2.13.11"),
crossScalaVersions := Seq(scala212, scala213),
check := (Compile / compile).value,
compile2 := (Compile / compile).value,
)

View File

@ -17,7 +17,7 @@
## test + with command or alias
> clean
## for command cross building you do need crossScalaVerions on root
> set root/crossScalaVersions := Seq("2.12.18", "2.13.11")
> set root/crossScalaVersions := Seq("2.12.18", "2.13.12")
> + build
$ exists foo/target/scala-2.12
$ exists foo/target/scala-2.13

View File

@ -1,5 +1,5 @@
scalaVersion := "2.12.18"
crossScalaVersions := List("2.12.18", "2.13.11")
crossScalaVersions := List("2.12.18", "2.13.12")
val setLastModified = taskKey[Unit]("Sets the last modified time for classfiles")
setLastModified := {

View File

@ -1,5 +1,5 @@
lazy val scala212 = "2.12.18"
lazy val scala213 = "2.13.11"
lazy val scala213 = "2.13.12"
ThisBuild / crossScalaVersions := Seq(scala212, scala213)
ThisBuild / scalaVersion := scala212

View File

@ -36,7 +36,7 @@ $ exists extras/target/scala-2.12
# test safe switching
> clean
> ++ 2.13.11 -v compile
> ++ 2.13.12 -v compile
$ exists lib/target/scala-2.13
-$ exists lib/target/scala-2.12
# -$ exists sbt-foo/target/scala-2.12

View File

@ -1,5 +1,5 @@
lazy val scala212 = "2.12.18"
lazy val scala213 = "2.13.11"
lazy val scala213 = "2.13.12"
ThisBuild / scalaVersion := scala212

View File

@ -4,7 +4,7 @@
> clean
> ++2.13.11 compile
> ++2.13.12 compile
$ exists core/target/scala-2.13
-$ exists module/target/scala-2.13

View File

@ -5,7 +5,7 @@ import Parsers._
lazy val root = (project in file("."))
.settings(
crossPaths := false,
crossScalaVersions := Seq("2.12.18", "2.13.11"),
crossScalaVersions := Seq("2.12.18", "2.13.12"),
scalaVersion := "2.12.18",
Compile / doc / scalacOptions += "-Xfatal-warnings",
commands += Command.command("excludeB") { s =>

View File

@ -1,5 +1,5 @@
lazy val scala212 = "2.12.18"
lazy val scala213 = "2.13.11"
lazy val scala213 = "2.13.12"
ThisBuild / scalaVersion := scala212
lazy val root = (project in file("."))

View File

@ -1,4 +1,4 @@
scalaVersion := "2.13.11"
scalaVersion := "2.13.12"
// Send some bogus initial command so that it doesn't get stuck.
// The task itself will still succeed.

View File

@ -1,5 +1,5 @@
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
name := "asciiGraphWidthSpecs"

View File

@ -1,5 +1,5 @@
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
name := "whatDependsOn"

View File

@ -1,5 +1,5 @@
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
name := "whatDependsOn"

View File

@ -1,4 +1,4 @@
scalaVersion := "2.13.11"
scalaVersion := "2.13.12"
csrConfiguration := csrConfiguration.value.withCache(target.value / "coursier-cache")
libraryDependencies += "com.typesafe.play" %% "play-test" % "2.8.0-RC1" % Test // worked around in 2.8.0

View File

@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / csrCacheDirectory := (ThisBuild / baseDirectory).value / "coursier-cache"
ivyPaths := IvyPaths(baseDirectory.value, Some(target.value / "ivy-cache"))

View File

@ -1,7 +1,7 @@
import xsbti.AppConfiguration
// ThisBuild / useCoursier := false
ThisBuild / organization := "com.example"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / versionScheme := Some("semver-spec")
ThisBuild / csrCacheDirectory := (ThisBuild / baseDirectory).value / "coursier-cache"

View File

@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.3.3",
// non-existing

View File

@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / scalacOptions += "-Ytasty-reader"
lazy val scala3code = project

View File

@ -1,7 +1,7 @@
ThisBuild / scalaVersion := "3.1.3"
ThisBuild / scalacOptions += "-Ytasty-reader"
lazy val scala213 = "2.13.11"
lazy val scala213 = "2.13.12"
lazy val root = (project in file("."))
.aggregate(fooApp, fooCore, barApp, barCore)

View File

@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / version := "0.1.0-SNAPSHOT"
lazy val check = taskKey[Unit]("")

View File

@ -8,7 +8,7 @@ $ copy-file changes/A2.scala A.scala
> run 2
> clean
> ++2.13.11!
> ++2.13.12!
$ copy-file changes/A1.scala A.scala
> run 1

View File

@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / usePipelining := true
lazy val root = (project in file("."))

View File

@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / usePipelining := true
lazy val root = (project in file("."))

View File

@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
val hedgehogVersion = "0.10.0"

View File

@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "com.example"
ThisBuild / organizationName := "example"

View File

@ -1,3 +1,3 @@
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
libraryDependencies += "com.disneystreaming" %% "weaver-cats" % "0.8.3" % Test

View File

@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.12"
libraryDependencies += "dev.zio" %% "zio-test" % "2.0.2" % Test
libraryDependencies += "dev.zio" %% "zio-test-sbt" % "2.0.2" % Test

View File

@ -15,8 +15,10 @@ import sbt.librarymanagement.{
DependencyResolution,
ModuleID,
ScalaArtifacts,
SemanticSelector,
UnresolvedWarningConfiguration,
UpdateConfiguration
UpdateConfiguration,
VersionNumber,
}
import sbt.librarymanagement.syntax._
import xsbti.ArtifactInfo.SbtOrganization
@ -25,6 +27,8 @@ import xsbti.compile.{ ClasspathOptions, ScalaInstance => XScalaInstance }
object ZincLmUtil {
final val scala2SbtBridgeStart = "2.13.12"
/**
* Instantiate a Scala compiler that is instrumented to analyze dependencies.
* This Scala compiler is useful to create your own instance of incremental
@ -86,6 +90,11 @@ object ZincLmUtil {
if (ScalaArtifacts.isScala3(scalaVersion)) {
ModuleID(ScalaArtifacts.Organization, "scala3-sbt-bridge", scalaVersion)
.withConfigurations(Some(Compile.name))
} else if (VersionNumber(scalaVersion).matchesSemVer(
SemanticSelector(s"=2.13 >=$scala2SbtBridgeStart")
)) {
ModuleID(ScalaArtifacts.Organization, "scala2-sbt-bridge", scalaVersion)
.withConfigurations(Some(Compile.name))
} else {
val compilerBridgeId = scalaVersion match {
case sc if sc startsWith "2.10." => "compiler-bridge_2.10"