From f8139da1920944b8a4912fa54d898c99ae81e36a Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 16 Aug 2020 17:38:07 -0400 Subject: [PATCH] Implement Scala 2.13-3.0 sandwich Fixes https://github.com/sbt/sbt/issues/5369 Ref https://contributors.scala-lang.org/t/roadmap-for-the-tasty-reader-for-scala-2/4231 This implements support for inter-project dependencies between Scala 2.13 and Dotty, and vice versa. Scala 2.13 depending on Dotty would require 2.13.4 and above. --- main/src/main/scala/sbt/Defaults.scala | 28 +++++++++++++++++-- .../plugins/dotty-compiler-plugin/build.sbt | 3 +- .../{pending => disabled} | 0 .../dotty-compiler-plugin/project/plugins.sbt | 2 +- .../plugins/dotty-sandwich/bar-app/D.scala | 5 ++++ .../plugins/dotty-sandwich/bar-core/C.scala | 5 ++++ .../sbt-test/plugins/dotty-sandwich/build.sbt | 24 ++++++++++++++++ .../plugins/dotty-sandwich/foo-app/B.scala | 5 ++++ .../plugins/dotty-sandwich/foo-core/A.scala | 5 ++++ .../dotty-sandwich/project/plugins.sbt | 1 + sbt/src/sbt-test/plugins/dotty-sandwich/test | 3 ++ sbt/src/sbt-test/plugins/dotty/build.sbt | 2 +- .../plugins/dotty/project/plugins.sbt | 2 +- 13 files changed, 78 insertions(+), 7 deletions(-) rename sbt/src/sbt-test/plugins/dotty-compiler-plugin/{pending => disabled} (100%) create mode 100644 sbt/src/sbt-test/plugins/dotty-sandwich/bar-app/D.scala create mode 100644 sbt/src/sbt-test/plugins/dotty-sandwich/bar-core/C.scala create mode 100644 sbt/src/sbt-test/plugins/dotty-sandwich/build.sbt create mode 100644 sbt/src/sbt-test/plugins/dotty-sandwich/foo-app/B.scala create mode 100644 sbt/src/sbt-test/plugins/dotty-sandwich/foo-core/A.scala create mode 100644 sbt/src/sbt-test/plugins/dotty-sandwich/project/plugins.sbt create mode 100644 sbt/src/sbt-test/plugins/dotty-sandwich/test diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 7a155a0a2..8d08ef7cc 100644 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -3450,14 +3450,38 @@ object Classpaths { def deliverPattern(outputPath: File): String = (outputPath / "[artifact]-[revision](-[classifier]).[ext]").absolutePath + private[sbt] def isScala2Scala3Sandwich(sbv1: String, sbv2: String): Boolean = { + def compare(a: String, b: String): Boolean = + a == "2.13" && (b.startsWith("0.") || b.startsWith("3.0")) + compare(sbv1, sbv2) || compare(sbv2, sbv1) + } + def projectDependenciesTask: Initialize[Task[Seq[ModuleID]]] = Def.task { + val sbv = scalaBinaryVersion.value val ref = thisProjectRef.value val data = settingsData.value val deps = buildDependencies.value deps.classpath(ref) flatMap { dep => - (projectID in dep.project) get data map { - _.withConfigurations(dep.configuration).withExplicitArtifacts(Vector.empty) + val depProjIdOpt = (dep.project / projectID).get(data) + val depSVOpt = (dep.project / scalaVersion).get(data) + val depSBVOpt = (dep.project / scalaBinaryVersion).get(data) + val depCrossOpt = (dep.project / crossVersion).get(data) + (depProjIdOpt, depSVOpt, depSBVOpt, depCrossOpt) match { + case (Some(depProjId), Some(depSV), Some(depSBV), Some(depCross)) => + if (sbv == depSBV || depCross != CrossVersion.binary) + Some( + depProjId.withConfigurations(dep.configuration).withExplicitArtifacts(Vector.empty) + ) + else if (isScala2Scala3Sandwich(sbv, depSBV) && depCross == CrossVersion.binary) + Some( + depProjId + .withCrossVersion(CrossVersion.constant(depSBV)) + .withConfigurations(dep.configuration) + .withExplicitArtifacts(Vector.empty) + ) + else sys.error(s"scalaBinaryVersion mismatch: expected $sbv but found ${depSBV}") + case _ => None } } } diff --git a/sbt/src/sbt-test/plugins/dotty-compiler-plugin/build.sbt b/sbt/src/sbt-test/plugins/dotty-compiler-plugin/build.sbt index b666df990..8800d7a56 100644 --- a/sbt/src/sbt-test/plugins/dotty-compiler-plugin/build.sbt +++ b/sbt/src/sbt-test/plugins/dotty-compiler-plugin/build.sbt @@ -1,4 +1,4 @@ -lazy val dottyVersion = "0.14.0-RC1" +ThisBuild / scalaVersion := "0.26.0-RC1" lazy val plugin = project .in(file("plugin")) @@ -6,7 +6,6 @@ lazy val plugin = project name := "dividezero", version := "0.0.1", organization := "ch.epfl.lamp", - scalaVersion := dottyVersion, scalacOptions ++= Seq( "-language:implicitConversions" diff --git a/sbt/src/sbt-test/plugins/dotty-compiler-plugin/pending b/sbt/src/sbt-test/plugins/dotty-compiler-plugin/disabled similarity index 100% rename from sbt/src/sbt-test/plugins/dotty-compiler-plugin/pending rename to sbt/src/sbt-test/plugins/dotty-compiler-plugin/disabled diff --git a/sbt/src/sbt-test/plugins/dotty-compiler-plugin/project/plugins.sbt b/sbt/src/sbt-test/plugins/dotty-compiler-plugin/project/plugins.sbt index 61407ff6b..03ee51a21 100644 --- a/sbt/src/sbt-test/plugins/dotty-compiler-plugin/project/plugins.sbt +++ b/sbt/src/sbt-test/plugins/dotty-compiler-plugin/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.3.1") +addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.1") diff --git a/sbt/src/sbt-test/plugins/dotty-sandwich/bar-app/D.scala b/sbt/src/sbt-test/plugins/dotty-sandwich/bar-app/D.scala new file mode 100644 index 000000000..b937ae06c --- /dev/null +++ b/sbt/src/sbt-test/plugins/dotty-sandwich/bar-app/D.scala @@ -0,0 +1,5 @@ +package example + +object D { + val x = C.x +} diff --git a/sbt/src/sbt-test/plugins/dotty-sandwich/bar-core/C.scala b/sbt/src/sbt-test/plugins/dotty-sandwich/bar-core/C.scala new file mode 100644 index 000000000..4d4fcc6df --- /dev/null +++ b/sbt/src/sbt-test/plugins/dotty-sandwich/bar-core/C.scala @@ -0,0 +1,5 @@ +package example + +object C { + val x = 1 +} diff --git a/sbt/src/sbt-test/plugins/dotty-sandwich/build.sbt b/sbt/src/sbt-test/plugins/dotty-sandwich/build.sbt new file mode 100644 index 000000000..d814ab38b --- /dev/null +++ b/sbt/src/sbt-test/plugins/dotty-sandwich/build.sbt @@ -0,0 +1,24 @@ +ThisBuild / scalaVersion := "0.23.0" + +ThisBuild / resolvers += "scala-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration/" +// TODO use 2.13.4 when it's out +lazy val scala213 = "2.13.4-bin-aeee8f0" + +lazy val root = (project in file(".")) + .aggregate(fooApp, fooCore, barApp, barCore) + +lazy val fooApp = (project in file("foo-app")) + .dependsOn(fooCore) + +lazy val fooCore = (project in file("foo-core")) + .settings( + scalaVersion := scala213 + ) + +lazy val barApp = (project in file("bar-app")) + .dependsOn(barCore) + .settings( + scalaVersion := scala213 + ) + +lazy val barCore = (project in file("bar-core")) diff --git a/sbt/src/sbt-test/plugins/dotty-sandwich/foo-app/B.scala b/sbt/src/sbt-test/plugins/dotty-sandwich/foo-app/B.scala new file mode 100644 index 000000000..ed82c07d1 --- /dev/null +++ b/sbt/src/sbt-test/plugins/dotty-sandwich/foo-app/B.scala @@ -0,0 +1,5 @@ +package example + +object B { + val x = A.x +} diff --git a/sbt/src/sbt-test/plugins/dotty-sandwich/foo-core/A.scala b/sbt/src/sbt-test/plugins/dotty-sandwich/foo-core/A.scala new file mode 100644 index 000000000..be4b82a9f --- /dev/null +++ b/sbt/src/sbt-test/plugins/dotty-sandwich/foo-core/A.scala @@ -0,0 +1,5 @@ +package example + +object A { + val x = 1 +} diff --git a/sbt/src/sbt-test/plugins/dotty-sandwich/project/plugins.sbt b/sbt/src/sbt-test/plugins/dotty-sandwich/project/plugins.sbt new file mode 100644 index 000000000..03ee51a21 --- /dev/null +++ b/sbt/src/sbt-test/plugins/dotty-sandwich/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.1") diff --git a/sbt/src/sbt-test/plugins/dotty-sandwich/test b/sbt/src/sbt-test/plugins/dotty-sandwich/test new file mode 100644 index 000000000..19ccc5787 --- /dev/null +++ b/sbt/src/sbt-test/plugins/dotty-sandwich/test @@ -0,0 +1,3 @@ +> fooApp/compile + +> barApp/compile diff --git a/sbt/src/sbt-test/plugins/dotty/build.sbt b/sbt/src/sbt-test/plugins/dotty/build.sbt index 6e6106c11..5116083a5 100644 --- a/sbt/src/sbt-test/plugins/dotty/build.sbt +++ b/sbt/src/sbt-test/plugins/dotty/build.sbt @@ -1 +1 @@ -scalaVersion := "0.14.0-RC1" +ThisBuild / scalaVersion := "0.26.0-RC1" diff --git a/sbt/src/sbt-test/plugins/dotty/project/plugins.sbt b/sbt/src/sbt-test/plugins/dotty/project/plugins.sbt index 61407ff6b..03ee51a21 100644 --- a/sbt/src/sbt-test/plugins/dotty/project/plugins.sbt +++ b/sbt/src/sbt-test/plugins/dotty/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.3.1") +addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.1")