Skip to content

Commit

Permalink
Install the sbt bridge from a binary jar instead of from sources
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
smarter authored and sjrd committed Jan 24, 2019
1 parent aab1f18 commit 22f21c4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
22 changes: 6 additions & 16 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,9 @@ object Build {
version := dottyVersion,
scalaVersion := dottyNonBootstrappedVersion,

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

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

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

fork in Test := true,
parallelExecution in Test := false
Expand Down
31 changes: 19 additions & 12 deletions sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,21 @@ object DottyPlugin extends AutoPlugin {
inc
},

scalaCompilerBridgeSource := {
val scalaBridge = scalaCompilerBridgeSource.value
val dottyBridge = (scalaOrganization.value % "dotty-sbt-bridge" % scalaVersion.value).withConfigurations(Some(Configurations.Compile.name)).sources()
if (isDotty.value)
dottyBridge
else
scalaBridge
},
scalaCompilerBridgeBinaryJar := Def.taskDyn {
if (isDotty.value) Def.task {
val dottyBridgeArtifacts = fetchArtifactsOf("dotty-sbt-bridge", CrossVersion.disabled).value
val jars = dottyBridgeArtifacts.filter(art => art.getName.startsWith("dotty-sbt-bridge") && art.getName.endsWith(".jar")).toArray
if (jars.size == 0)
throw new MessageOnlyException("No jar found for dotty-sbt-bridge")
else if (jars.size > 1)
throw new MessageOnlyException(s"Multiple jars found for dotty-sbt-bridge: ${jars.toList}")
else
jars.headOption
}
else Def.task {
None: Option[File]
}
}.value,

// Needed for RCs publishing
scalaBinaryVersion := {
Expand All @@ -184,7 +191,7 @@ object DottyPlugin extends AutoPlugin {
val si = scalaInstance.value
if (isDotty.value) {
Def.task {
val dottydocArtifacts = fetchArtifactsOf("dotty-doc").value
val dottydocArtifacts = fetchArtifactsOf("dotty-doc", CrossVersion.binary).value
val includeArtifact = (f: File) => f.getName.endsWith(".jar")
val dottydocJars = dottydocArtifacts.filter(includeArtifact).toArray
val allJars = (si.allJars ++ dottydocJars).distinct
Expand Down Expand Up @@ -229,15 +236,15 @@ object DottyPlugin extends AutoPlugin {
scalacOptions += "-from-tasty"
))

/** Fetch artefacts for scalaOrganization.value %% moduleName % scalaVersion.value */
private def fetchArtifactsOf(moduleName: String) = Def.task {
/** Fetch artifacts for scalaOrganization.value %% moduleName % scalaVersion.value */
private def fetchArtifactsOf(moduleName: String, crossVersion: CrossVersion) = Def.task {
val dependencyResolution = Keys.dependencyResolution.value
val log = streams.value.log
val scalaInfo = scalaModuleInfo.value
val updateConfiguration = Keys.updateConfiguration.value
val warningConfiguration = (unresolvedWarningConfiguration in update).value

val moduleID = (scalaOrganization.value %% moduleName % scalaVersion.value).cross(CrossVersion.binary)
val moduleID = (scalaOrganization.value % moduleName % scalaVersion.value).cross(crossVersion)
val descriptor = dependencyResolution.wrapDependencyInModule(moduleID, scalaInfo)

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

0 comments on commit 22f21c4

Please sign in to comment.