Skip to content

Commit

Permalink
Merge pull request #2133 from tgodzik/scala2-sbt-bridge
Browse files Browse the repository at this point in the history
improvement: Correctly download Scala 2 bridge for Scala 2.13.12
  • Loading branch information
tgodzik authored Aug 17, 2023
2 parents a95134b + 0f2227f commit 625b4e3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
8 changes: 6 additions & 2 deletions backend/src/main/scala/bloop/ScalaInstance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import bloop.internal.build.BloopScalaInfo
import bloop.logging.DebugFilter
import bloop.logging.Logger

import coursierapi.Repository

final class ScalaInstance private (
val organization: String,
val name: String,
Expand Down Expand Up @@ -195,12 +197,14 @@ object ScalaInstance {
scalaOrg: String,
scalaName: String,
scalaVersion: String,
logger: Logger
logger: Logger,
additionalRepositories: List[Repository] = Nil
): ScalaInstance = {
def resolveInstance: ScalaInstance = {
val allPaths = DependencyResolution.resolve(
List(DependencyResolution.Artifact(scalaOrg, scalaName, scalaVersion)),
logger
logger,
additionalRepos = additionalRepositories
)
val allJars = allPaths.collect {
case path if path.underlying.toString.endsWith(".jar") => path.underlying.toFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import xsbti.ComponentProvider
import xsbti.Logger
import xsbti.compile.ClasspathOptionsUtil
import xsbti.compile.CompilerBridgeProvider
import scala.util.control.NonFatal

object BloopComponentCompiler {
import xsbti.compile.ScalaInstance
Expand All @@ -44,11 +45,22 @@ object BloopComponentCompiler {

private val CompileConf = Some(Configurations.Compile.name)
def getModuleForBridgeSources(scalaInstance: ScalaInstance): ModuleID = {
val isAfter2_13_11 =
try {
val Array(_, _, patch) = scalaInstance.version().split("\\.")
val patchTrimmed = patch.takeWhile(_.isDigit).toInt
scalaInstance.version().startsWith("2.13.") && patchTrimmed >= 12
} catch {
case NonFatal(_) => false
}

def compilerBridgeId(scalaVersion: String) = {

// Defaults to bridge for 2.13 for Scala versions bigger than 2.13.x
scalaVersion match {
case sc if (sc startsWith "0.") => "dotty-sbt-bridge"
case sc if (sc startsWith "3.") => "scala3-sbt-bridge"
case _ if isAfter2_13_11 => "scala2-sbt-bridge"
case sc if (sc startsWith "2.10.") => "compiler-bridge_2.10"
case sc if (sc startsWith "2.11.") => "compiler-bridge_2.11"
case sc if (sc startsWith "2.12.") => "compiler-bridge_2.12"
Expand All @@ -57,7 +69,7 @@ object BloopComponentCompiler {
}

val (isDotty, organization, version) = scalaInstance match {
case instance: BloopScalaInstance if instance.isDotty =>
case instance: BloopScalaInstance if instance.isDotty || isAfter2_13_11 =>
(true, instance.organization, instance.version)
case _ => (false, "org.scala-sbt", latestVersion)
}
Expand Down Expand Up @@ -250,7 +262,12 @@ private[inc] class BloopComponentCompiler(
.Artifact(bridgeSources.organization, bridgeSources.name, bridgeSources.revision)
),
logger,
resolveSources = shouldResolveSources
resolveSources = shouldResolveSources,
List(
coursierapi.MavenRepository.of(
"https://scala-ci.typesafe.com/artifactory/scala-integration/"
)
)
) match {
case Right(paths) => paths.map(_.underlying).toVector
case Left(t) =>
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/test/scala/bloop/ScalaVersionsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import bloop.task.Task
import bloop.util.TestProject
import bloop.util.TestUtil

import coursierapi.MavenRepository

object ScalaVersionsSpec extends bloop.testing.BaseSuite {
var loggers: List[RecordingLogger] = Nil

Expand All @@ -22,7 +24,15 @@ object ScalaVersionsSpec extends bloop.testing.BaseSuite {

def jarsForScalaVersion(version: String, logger: RecordingLogger) = {
ScalaInstance
.resolve(compilerOrg, compilerArtifact, version, logger)
.resolve(
compilerOrg,
compilerArtifact,
version,
logger,
List(
MavenRepository.of("https://scala-ci.typesafe.com/artifactory/scala-integration/")
)
)
.allJars
.map(AbsolutePath(_))
}
Expand Down Expand Up @@ -71,7 +81,8 @@ object ScalaVersionsSpec extends bloop.testing.BaseSuite {
"2.12.17",
"2.13.10",
"3.1.3",
"3.2.1"
"3.2.1",
"2.13.12-bin-86f40c2"
)

val allVersions = if (TestUtil.isJdk8) jdk8OnlyVersions ++ scalaVersions else scalaVersions
Expand Down

0 comments on commit 625b4e3

Please sign in to comment.