diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index bc9b3a3f1..a468b4c1a 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -450,7 +450,8 @@ object Defaults extends BuildCommon { val _ = clean.value IvyActions.cleanCachedResolutionCache(ivyModule.value, streams.value.log) }, - scalaCompilerBridgeSource := ZincUtil.getDefaultBridgeModule(scalaVersion.value) + scalaCompilerBridgeBinaryJar := None, + scalaCompilerBridgeSource := ZincUtil.getDefaultBridgeModule(scalaVersion.value), ) // must be a val: duplication detected by object identity private[this] lazy val compileBaseGlobal: Seq[Setting[_]] = globalDefaults( @@ -503,17 +504,27 @@ object Defaults extends BuildCommon { val zincDir = BuildPaths.getZincDirectory(st, g) val app = appConfiguration.value val launcher = app.provider.scalaProvider.launcher - val scalac = ZincUtil.scalaCompiler( - scalaInstance = scalaInstance.value, - classpathOptions = classpathOptions.value, - globalLock = launcher.globalLock, - componentProvider = app.provider.components, - secondaryCacheDir = Option(zincDir), - dependencyResolution = dependencyResolution.value, - compilerBridgeSource = scalaCompilerBridgeSource.value, - scalaJarsTarget = zincDir, - log = streams.value.log - ) + val scalac = + scalaCompilerBridgeBinaryJar.value match { + case Some(jar) => + ZincUtil.scalaCompiler( + scalaInstance = scalaInstance.value, + classpathOptions = classpathOptions.value, + compilerBridgeJar = jar + ) + case _ => + ZincUtil.scalaCompiler( + scalaInstance = scalaInstance.value, + classpathOptions = classpathOptions.value, + globalLock = launcher.globalLock, + componentProvider = app.provider.components, + secondaryCacheDir = Option(zincDir), + dependencyResolution = dependencyResolution.value, + compilerBridgeSource = scalaCompilerBridgeSource.value, + scalaJarsTarget = zincDir, + log = streams.value.log + ) + } val compilers = ZincUtil.compilers( instance = scalaInstance.value, classpathOptions = classpathOptions.value, diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index 10dfa7361..7abd4e9fc 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -220,7 +220,8 @@ object Keys { val crossSbtVersions = settingKey[Seq[String]]("The versions of Sbt used when cross-building an sbt plugin.") val printWarnings = taskKey[Unit]("Shows warnings from compilation, including ones that weren't printed initially.").withRank(BPlusTask) val fileInputOptions = settingKey[Seq[String]]("Options that take file input, which may invalidate the cache.").withRank(CSetting) - val scalaCompilerBridgeSource = settingKey[ModuleID]("Configures the module ID of the sources of the compiler bridge.").withRank(CSetting) + val scalaCompilerBridgeBinaryJar = taskKey[Option[File]]("Optionally, the jar of the compiler bridge. When not None, this takes precedence over scalaCompilerBridgeSource").withRank(CSetting) + val scalaCompilerBridgeSource = settingKey[ModuleID]("Configures the module ID of the sources of the compiler bridge when scalaCompilerBridgeBinaryJar is None").withRank(CSetting) val scalaArtifacts = settingKey[Seq[String]]("Configures the list of artifacts which should match the Scala binary version").withRank(CSetting) val enableBinaryCompileAnalysis = settingKey[Boolean]("Writes the analysis file in binary format") val crossJavaVersions = settingKey[Seq[String]]("The java versions used during JDK cross testing").withRank(BPlusSetting) diff --git a/main/src/main/scala/sbt/internal/ConsoleProject.scala b/main/src/main/scala/sbt/internal/ConsoleProject.scala index bb1279d8f..61f1362bf 100644 --- a/main/src/main/scala/sbt/internal/ConsoleProject.scala +++ b/main/src/main/scala/sbt/internal/ConsoleProject.scala @@ -21,7 +21,10 @@ object ConsoleProject { val cpImports = new Imports(extracted, state) val bindings = ("currentState" -> state) :: ("extracted" -> extracted) :: ("cpHelpers" -> cpImports) :: Nil val unit = extracted.currentUnit - val (_, dependencyResolution) = extracted.runTask(Keys.dependencyResolution, state) + val (state1, dependencyResolution) = + extracted.runTask(Keys.dependencyResolution, state) + val (_, scalaCompilerBridgeBinaryJar) = + extracted.runTask(Keys.scalaCompilerBridgeBinaryJar, state1) val scalaInstance = { val scalaProvider = state.configuration.provider.scalaProvider ScalaInstance(scalaProvider.version, scalaProvider.launcher) @@ -30,17 +33,26 @@ object ConsoleProject { val zincDir = BuildPaths.getZincDirectory(state, g) val app = state.configuration val launcher = app.provider.scalaProvider.launcher - val compiler = ZincUtil.scalaCompiler( - scalaInstance = scalaInstance, - classpathOptions = ClasspathOptionsUtil.repl, - globalLock = launcher.globalLock, - componentProvider = app.provider.components, - secondaryCacheDir = Option(zincDir), - dependencyResolution = dependencyResolution, - compilerBridgeSource = extracted.get(Keys.scalaCompilerBridgeSource), - scalaJarsTarget = zincDir, - log = log - ) + val compiler = scalaCompilerBridgeBinaryJar match { + case Some(jar) => + ZincUtil.scalaCompiler( + scalaInstance = scalaInstance, + classpathOptions = ClasspathOptionsUtil.repl, + compilerBridgeJar = jar + ) + case None => + ZincUtil.scalaCompiler( + scalaInstance = scalaInstance, + classpathOptions = ClasspathOptionsUtil.repl, + globalLock = launcher.globalLock, + componentProvider = app.provider.components, + secondaryCacheDir = Option(zincDir), + dependencyResolution = dependencyResolution, + compilerBridgeSource = extracted.get(Keys.scalaCompilerBridgeSource), + scalaJarsTarget = zincDir, + log = log + ) + } val imports = BuildUtil.getImports(unit.unit) ++ BuildUtil.importAll(bindings.map(_._1)) val importString = imports.mkString("", ";\n", ";\n\n") val initCommands = importString + extra diff --git a/sbt/src/sbt-test/dependency-management/compiler-bridge-binary/A.scala b/sbt/src/sbt-test/dependency-management/compiler-bridge-binary/A.scala new file mode 100644 index 000000000..69c493db2 --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/compiler-bridge-binary/A.scala @@ -0,0 +1 @@ +object A diff --git a/sbt/src/sbt-test/dependency-management/compiler-bridge-binary/build.sbt b/sbt/src/sbt-test/dependency-management/compiler-bridge-binary/build.sbt new file mode 100644 index 000000000..a3b3bf1f4 --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/compiler-bridge-binary/build.sbt @@ -0,0 +1,16 @@ +scalaVersion := "2.12.6" + +// We can't use "%%" here without breaking the "== bridgeModule" check below +val bridgeModule = "org.scala-sbt" % s"compiler-bridge_2.12" % "1.2.1" + +libraryDependencies += bridgeModule % Configurations.ScalaTool + +scalaCompilerBridgeSource := "shouldnotbeused" % "dummy" % "dummy" + +scalaCompilerBridgeBinaryJar := { + for { + toolReport <- update.value.configuration(Configurations.ScalaTool) + m <- toolReport.modules.find(m => m.module == bridgeModule) + (_, file) <- m.artifacts.find(art => art._1.`type` == Artifact.DefaultType) + } yield file +} diff --git a/sbt/src/sbt-test/dependency-management/compiler-bridge-binary/test b/sbt/src/sbt-test/dependency-management/compiler-bridge-binary/test new file mode 100644 index 000000000..5df2af1f3 --- /dev/null +++ b/sbt/src/sbt-test/dependency-management/compiler-bridge-binary/test @@ -0,0 +1 @@ +> compile