Skip to content

Commit 07fe0d8

Browse files
alexarchambaulttgodzik
authored andcommitted
Take into account build tool-supplied bridge JARs
1 parent 35083fd commit 07fe0d8

File tree

3 files changed

+53
-22
lines changed

3 files changed

+53
-22
lines changed

backend/src/main/scala/bloop/ScalaInstance.scala

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ final class ScalaInstance private (
2323
val organization: String,
2424
val name: String,
2525
override val version: String,
26-
override val allJars: Array[File]
26+
override val allJars: Array[File],
27+
val bridgeJarsOpt: Option[Seq[File]] = None
2728
) extends xsbti.compile.ScalaInstance {
2829

2930
override lazy val loaderCompilerOnly: ClassLoader =
@@ -153,6 +154,15 @@ object ScalaInstance {
153154

154155
private[ScalaInstance] final val ScalacCompilerName = "scala-compiler"
155156

157+
def apply(
158+
scalaOrg: String,
159+
scalaName: String,
160+
scalaVersion: String,
161+
allJars: Seq[AbsolutePath],
162+
logger: Logger
163+
): ScalaInstance =
164+
apply(scalaOrg, scalaName, scalaVersion, allJars, logger, None)
165+
156166
/**
157167
* Reuses all jars to create an Scala instance if and only if all of them exist.
158168
*
@@ -170,7 +180,8 @@ object ScalaInstance {
170180
scalaName: String,
171181
scalaVersion: String,
172182
allJars: Seq[AbsolutePath],
173-
logger: Logger
183+
logger: Logger,
184+
bridgeJarsOpt: Option[Seq[AbsolutePath]]
174185
): ScalaInstance = {
175186
val jarsKey = allJars.map(_.underlying).sortBy(_.toString).toList
176187
if (allJars.nonEmpty) {
@@ -179,7 +190,13 @@ object ScalaInstance {
179190
DebugFilter.Compilation
180191
)
181192
jarsKey.foreach(p => logger.debug(s" => $p")(DebugFilter.Compilation))
182-
new ScalaInstance(scalaOrg, scalaName, scalaVersion, allJars.map(_.toFile).toArray)
193+
new ScalaInstance(
194+
scalaOrg,
195+
scalaName,
196+
scalaVersion,
197+
allJars.map(_.toFile).toArray,
198+
bridgeJarsOpt.map(_.map(_.toFile))
199+
)
183200
}
184201

185202
val nonExistingJars = allJars.filter(j => !Files.exists(j.underlying))

backend/src/main/scala/sbt/internal/inc/BloopComponentCompiler.scala

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ object BloopComponentCompiler {
116116
*/
117117
private def compiledBridge(bridgeSources: ModuleID, scalaInstance: ScalaInstance): File = {
118118
val raw = new RawCompiler(scalaInstance, ClasspathOptionsUtil.auto, logger)
119-
val zinc = new BloopComponentCompiler(raw, manager, bridgeSources, logger)
119+
val bridgeJarsOpt = scalaInstance match {
120+
case b: _root_.bloop.ScalaInstance => b.bridgeJarsOpt
121+
case _ => None
122+
}
123+
val zinc = new BloopComponentCompiler(raw, manager, bridgeSources, bridgeJarsOpt, logger)
120124
logger.debug(s"Getting $bridgeSources for Scala ${scalaInstance.version}")(
121125
DebugFilter.Compilation
122126
)
@@ -229,6 +233,7 @@ private[inc] class BloopComponentCompiler(
229233
compiler: RawCompiler,
230234
manager: BloopComponentManager,
231235
bridgeSources: ModuleID,
236+
bridgeJarsOpt: Option[Seq[File]],
232237
logger: BloopLogger
233238
) {
234239
implicit val debugFilter: DebugFilter.Compilation.type = DebugFilter.Compilation
@@ -257,23 +262,25 @@ private[inc] class BloopComponentCompiler(
257262
IO.withTemporaryDirectory { _ =>
258263
val shouldResolveSources =
259264
bridgeSources.explicitArtifacts.exists(_.`type` == "src")
260-
val allArtifacts = BloopDependencyResolution.resolveWithErrors(
261-
List(
262-
BloopDependencyResolution
263-
.Artifact(bridgeSources.organization, bridgeSources.name, bridgeSources.revision)
264-
),
265-
logger,
266-
resolveSources = shouldResolveSources,
267-
List(
268-
coursierapi.MavenRepository.of(
269-
"https://scala-ci.typesafe.com/artifactory/scala-integration/"
265+
val allArtifacts = bridgeJarsOpt.map(_.map(_.toPath)).getOrElse {
266+
BloopDependencyResolution.resolveWithErrors(
267+
List(
268+
BloopDependencyResolution
269+
.Artifact(bridgeSources.organization, bridgeSources.name, bridgeSources.revision)
270+
),
271+
logger,
272+
resolveSources = shouldResolveSources,
273+
List(
274+
coursierapi.MavenRepository.of(
275+
"https://scala-ci.typesafe.com/artifactory/scala-integration/"
276+
)
270277
)
271-
)
272-
) match {
273-
case Right(paths) => paths.map(_.underlying).toVector
274-
case Left(t) =>
275-
val msg = s"Couldn't retrieve module $bridgeSources"
276-
throw new InvalidComponent(msg, t)
278+
) match {
279+
case Right(paths) => paths.map(_.underlying).toVector
280+
case Left(t) =>
281+
val msg = s"Couldn't retrieve module $bridgeSources"
282+
throw new InvalidComponent(msg, t)
283+
}
277284
}
278285

279286
if (!shouldResolveSources) {
@@ -286,7 +293,7 @@ private[inc] class BloopComponentCompiler(
286293
if (!HydraSupport.isEnabled(compiler.scalaInstance)) (bridgeSources.name, sources)
287294
else {
288295
val hydraBridgeModule = HydraSupport.getModuleForBridgeSources(compiler.scalaInstance)
289-
mergeBloopAndHydraBridges(sources, hydraBridgeModule) match {
296+
mergeBloopAndHydraBridges(sources.toVector, hydraBridgeModule) match {
290297
case Right(mergedHydraBridgeSourceJar) =>
291298
(hydraBridgeModule.name, mergedHydraBridgeSourceJar)
292299
case Left(error) =>

frontend/src/main/scala/bloop/data/Project.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,14 @@ object Project {
290290
else {
291291
val scalaJars = scala.jars.map(AbsolutePath.apply)
292292
Some(
293-
ScalaInstance(scala.organization, scala.name, scala.version, scalaJars, logger)
293+
ScalaInstance(
294+
scala.organization,
295+
scala.name,
296+
scala.version,
297+
scalaJars,
298+
logger,
299+
scala.bridgeJars.map(_.map(AbsolutePath(_)))
300+
)
294301
)
295302
}
296303
}

0 commit comments

Comments
 (0)