Skip to content

Commit 22f21c4

Browse files
smartersjrd
authored andcommitted
Install the sbt bridge from a binary jar instead of from sources
Normally, the source of the sbt bridge is fetched from scalaCompilerBridgeSource, compiled, then cached by sbt. Unfortunately the logic in sbt to do this does not take .java source files into account, so the previous commit broke our bridge. Thankfully, it turns out that I have amazing foresight ;). In sbt/sbt#4332 I added scalaCompilerBridgeBinaryJar to sbt, which bypasses the whole bridge compilation and caching logic which is not needed when the bridge is Java-only and thus binary-compatible across Scala releases. So just using this setting is enough to make everything work!
1 parent aab1f18 commit 22f21c4

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

project/Build.scala

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,9 @@ object Build {
226226
version := dottyVersion,
227227
scalaVersion := dottyNonBootstrappedVersion,
228228

229-
// Avoid having to run `dotty-sbt-bridge/publishLocal` before compiling a bootstrapped project
230-
scalaCompilerBridgeSource :=
231-
(dottyOrganization %% "dotty-sbt-bridge" % dottyVersion)
232-
.artifacts(Artifact.sources("dotty-sbt-bridge").withUrl(
233-
// We cannot use the `packageSrc` task because a setting cannot depend
234-
// on a task. Instead, we make `compile` below depend on the bridge `packageSrc`
235-
Some((artifactPath in (`dotty-sbt-bridge`, Compile, packageSrc)).value.toURI.toURL))),
236-
compile in Compile := (compile in Compile)
237-
.dependsOn(packageSrc in (`dotty-sbt-bridge`, Compile))
238-
.dependsOn(compile in (`dotty-sbt-bridge`, Compile))
239-
.value,
229+
scalaCompilerBridgeBinaryJar := {
230+
Some((packageBin in (`dotty-sbt-bridge`, Compile)).value)
231+
},
240232

241233
// Use the same name as the non-bootstrapped projects for the artifacts
242234
moduleName ~= { _.stripSuffix("-bootstrapped") },
@@ -830,12 +822,10 @@ object Build {
830822
Dependencies.`compiler-interface` % Provided,
831823
(Dependencies.`zinc-api-info` % Test).withDottyCompat(scalaVersion.value)
832824
),
833-
// The sources should be published with crossPaths := false since they
834-
// need to be compiled by the project using the bridge.
835-
crossPaths := false,
836825

837-
// Don't publish any binaries for the bridge because of the above
838-
publishArtifact in (Compile, packageBin) := false,
826+
// sources are Java-only, tests are in Scala
827+
crossPaths in Compile := false,
828+
autoScalaLibrary in Compile := false,
839829

840830
fork in Test := true,
841831
parallelExecution in Test := false

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,21 @@ object DottyPlugin extends AutoPlugin {
163163
inc
164164
},
165165

166-
scalaCompilerBridgeSource := {
167-
val scalaBridge = scalaCompilerBridgeSource.value
168-
val dottyBridge = (scalaOrganization.value % "dotty-sbt-bridge" % scalaVersion.value).withConfigurations(Some(Configurations.Compile.name)).sources()
169-
if (isDotty.value)
170-
dottyBridge
171-
else
172-
scalaBridge
173-
},
166+
scalaCompilerBridgeBinaryJar := Def.taskDyn {
167+
if (isDotty.value) Def.task {
168+
val dottyBridgeArtifacts = fetchArtifactsOf("dotty-sbt-bridge", CrossVersion.disabled).value
169+
val jars = dottyBridgeArtifacts.filter(art => art.getName.startsWith("dotty-sbt-bridge") && art.getName.endsWith(".jar")).toArray
170+
if (jars.size == 0)
171+
throw new MessageOnlyException("No jar found for dotty-sbt-bridge")
172+
else if (jars.size > 1)
173+
throw new MessageOnlyException(s"Multiple jars found for dotty-sbt-bridge: ${jars.toList}")
174+
else
175+
jars.headOption
176+
}
177+
else Def.task {
178+
None: Option[File]
179+
}
180+
}.value,
174181

175182
// Needed for RCs publishing
176183
scalaBinaryVersion := {
@@ -184,7 +191,7 @@ object DottyPlugin extends AutoPlugin {
184191
val si = scalaInstance.value
185192
if (isDotty.value) {
186193
Def.task {
187-
val dottydocArtifacts = fetchArtifactsOf("dotty-doc").value
194+
val dottydocArtifacts = fetchArtifactsOf("dotty-doc", CrossVersion.binary).value
188195
val includeArtifact = (f: File) => f.getName.endsWith(".jar")
189196
val dottydocJars = dottydocArtifacts.filter(includeArtifact).toArray
190197
val allJars = (si.allJars ++ dottydocJars).distinct
@@ -229,15 +236,15 @@ object DottyPlugin extends AutoPlugin {
229236
scalacOptions += "-from-tasty"
230237
))
231238

232-
/** Fetch artefacts for scalaOrganization.value %% moduleName % scalaVersion.value */
233-
private def fetchArtifactsOf(moduleName: String) = Def.task {
239+
/** Fetch artifacts for scalaOrganization.value %% moduleName % scalaVersion.value */
240+
private def fetchArtifactsOf(moduleName: String, crossVersion: CrossVersion) = Def.task {
234241
val dependencyResolution = Keys.dependencyResolution.value
235242
val log = streams.value.log
236243
val scalaInfo = scalaModuleInfo.value
237244
val updateConfiguration = Keys.updateConfiguration.value
238245
val warningConfiguration = (unresolvedWarningConfiguration in update).value
239246

240-
val moduleID = (scalaOrganization.value %% moduleName % scalaVersion.value).cross(CrossVersion.binary)
247+
val moduleID = (scalaOrganization.value % moduleName % scalaVersion.value).cross(crossVersion)
241248
val descriptor = dependencyResolution.wrapDependencyInModule(moduleID, scalaInfo)
242249

243250
dependencyResolution.update(descriptor, updateConfiguration, warningConfiguration, log) match {

0 commit comments

Comments
 (0)