From a9d25ffb319af131c7cf8fa0fd72ecffde3cd902 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 25 Oct 2024 18:22:23 +0200 Subject: [PATCH] improvement: Use sbt bridge defined by the user This is needed to fully compile Dotty right now. --- .../internal/inc/BloopComponentCompiler.scala | 8 +++++++- .../bloop/integrations/sbt/SbtBloop.scala | 3 ++- .../sbt-test/sbt-bloop/custom-bridge/build.sbt | 18 ++++++++++++++++++ .../custom-bridge/project/plugins.sbt | 1 + .../src/sbt-test/sbt-bloop/custom-bridge/test | 3 +++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/build.sbt create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/project/plugins.sbt create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/test diff --git a/backend/src/main/scala/sbt/internal/inc/BloopComponentCompiler.scala b/backend/src/main/scala/sbt/internal/inc/BloopComponentCompiler.scala index 3be9edd926..126295ac43 100644 --- a/backend/src/main/scala/sbt/internal/inc/BloopComponentCompiler.scala +++ b/backend/src/main/scala/sbt/internal/inc/BloopComponentCompiler.scala @@ -117,7 +117,13 @@ object BloopComponentCompiler { private def compiledBridge(bridgeSources: ModuleID, scalaInstance: ScalaInstance): File = { val raw = new RawCompiler(scalaInstance, ClasspathOptionsUtil.auto, logger) val bridgeJarsOpt = scalaInstance match { - case b: _root_.bloop.ScalaInstance => b.bridgeJarsOpt + case b: _root_.bloop.ScalaInstance => + b.bridgeJarsOpt.foreach { jars => + logger.debug(s"Using user defined bridge jars for Scala ${jars.mkString(",")}")( + DebugFilter.Compilation + ) + } + b.bridgeJarsOpt case _ => None } val zinc = new BloopComponentCompiler(raw, manager, bridgeSources, bridgeJarsOpt, logger) diff --git a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala index 6c4cb11ae1..5ee26d0366 100644 --- a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala +++ b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala @@ -1025,6 +1025,7 @@ object BloopDefaults { val modules = onlyCompilationModules(allModules, classpath).toList if (modules.isEmpty) None else Some(Config.Resolution(modules)) } + val bridge = Keys.scalaCompilerBridgeBinaryJar.value.map(file => List(file.toPath())) // Force source generators on this task manually Keys.managedSources.value @@ -1034,7 +1035,7 @@ object BloopDefaults { val c = Keys.classpathOptions.value val java = Config.Java(javacOptions) val compileSetup = Config.CompileSetup(compileOrder, c.bootLibrary, c.compiler, c.extra, c.autoBoot, c.filterLibrary) - val `scala` = Config.Scala(scalaOrg, scalaName, scalaVersion, scalacOptions, allScalaJars, None, Some(compileSetup), None) + val `scala` = Config.Scala(scalaOrg, scalaName, scalaVersion, scalacOptions, allScalaJars, None, Some(compileSetup), bridge) val resources = Some(bloopResourcesTask.value) val sbt = None // Written by `postGenerate` instead diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/build.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/build.sbt new file mode 100644 index 0000000000..b02bfe05fa --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/build.sbt @@ -0,0 +1,18 @@ +import bloop.integrations.sbt.BloopDefaults + +val foo = project + .in(file(".") / "foo") + .settings( + scalaCompilerBridgeBinaryJar := Some(baseDirectory.value / "fake.jar") + ) + +val checkBloopFiles = taskKey[Unit]("Check bloop file contents") +checkBloopFiles in ThisBuild := { + val bloopDir = Keys.baseDirectory.value./(".bloop") + val fooConfig = bloopDir./("foo.json") + val config = BloopDefaults.unsafeParseConfig(fooConfig.toPath) + val bridgeJars = config.project.scala.get.bridgeJars.map(_.map(_.toString)) + val expectedJars = Some(List((Keys.baseDirectory.value / "foo" / "fake.jar").toString)) + assert(bridgeJars == expectedJars) + +} diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/project/plugins.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/project/plugins.sbt new file mode 100644 index 0000000000..1a5c0709e6 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version")) diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/test b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/test new file mode 100644 index 0000000000..01c64dc117 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/custom-bridge/test @@ -0,0 +1,3 @@ +> foo/bloopGenerate +> foo/test:bloopGenerate +> checkBloopFiles \ No newline at end of file