Skip to content

Commit b24faad

Browse files
authored
Merge pull request #2927 from Gedochao/maintenance/scala2-sbt-bridge-for-bloop
Pass scala2-sbt-bridge to Bloop explicitly for Scala 2.13.12+
2 parents ebafbb8 + 8fcb89f commit b24faad

File tree

4 files changed

+88
-20
lines changed

4 files changed

+88
-20
lines changed

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,17 @@ abstract class RunTestDefinitions
20212021
.call(cwd = root, env = extraEnv)
20222022
os.proc(TestUtil.cs, "install", s"scalac:$actualScalaVersion")
20232023
.call(cwd = root, env = extraEnv)
2024+
(if (actualScalaVersion.startsWith("3")) Some("scala3-sbt-bridge")
2025+
else if (
2026+
actualScalaVersion.startsWith("2.13.") &&
2027+
actualScalaVersion.coursierVersion >= "2.13.12".coursierVersion
2028+
)
2029+
Some("scala2-sbt-bridge")
2030+
else None)
2031+
.foreach { bridgeArtifactName =>
2032+
os.proc(TestUtil.cs, "fetch", s"org.scala-lang:$bridgeArtifactName:$actualScalaVersion")
2033+
.call(cwd = root, env = extraEnv)
2034+
}
20242035

20252036
// Download JVM that won't suit Bloop, also no Bloop artifacts are present
20262037
os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:11")

modules/integration/src/test/scala/scala/cli/integration/SipScalaTests.scala

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,9 @@ class SipScalaTests extends ScalaCliSuite with SbtTestHelper with MillTestHelper
597597
for {
598598
withBloop <- Seq(true, false)
599599
withBloopString = if (withBloop) "with Bloop" else "with --server=false"
600-
}
600+
} {
601601
test(
602-
s"default Scala version coming straight from a predefined local repository $withBloopString"
602+
s"default Scala version (3.4.1-RC1) coming straight from a predefined local repository $withBloopString"
603603
) {
604604
TestInputs(
605605
os.rel / "simple.sc" -> "println(dotty.tools.dotc.config.Properties.simpleVersionString)"
@@ -641,6 +641,53 @@ class SipScalaTests extends ScalaCliSuite with SbtTestHelper with MillTestHelper
641641
}
642642
}
643643

644+
test(
645+
s"default Scala version (2.13.15-bin-ccdcde3) coming straight from a predefined local repository $withBloopString"
646+
) {
647+
TestInputs(
648+
os.rel / "simple.sc" -> "println(scala.util.Properties.versionNumberString)"
649+
)
650+
.fromRoot { root =>
651+
val localRepoPath = root / "local-repo"
652+
val sv = "2.13.15-bin-ccdcde3"
653+
val artifactNames =
654+
Seq("scala-compiler") ++ (if (withBloop) Seq("scala2-sbt-bridge") else Nil)
655+
for { artifactName <- artifactNames } {
656+
val csRes = os.proc(
657+
TestUtil.cs,
658+
"fetch",
659+
"--cache",
660+
localRepoPath,
661+
"-r",
662+
"https://scala-ci.typesafe.com/artifactory/scala-integration",
663+
s"org.scala-lang:$artifactName:$sv"
664+
)
665+
.call(cwd = root)
666+
expect(csRes.exitCode == 0)
667+
}
668+
val buildServerOptions = if (withBloop) Nil else Seq("--server=false")
669+
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
670+
val r = os.proc(
671+
TestUtil.cli,
672+
"--cli-default-scala-version",
673+
sv,
674+
"--predefined-repository",
675+
(localRepoPath / "https" / "repo1.maven.org" / "maven2").toNIO.toUri.toASCIIString,
676+
"--predefined-repository",
677+
(localRepoPath / "https" / "scala-ci.typesafe.com" / "artifactory" / "scala-integration").toNIO.toUri.toASCIIString,
678+
"run",
679+
"simple.sc",
680+
"--with-compiler",
681+
"--offline",
682+
"--power",
683+
buildServerOptions
684+
)
685+
.call(cwd = root)
686+
expect(r.out.trim() == sv)
687+
}
688+
}
689+
}
690+
644691
test(s"default Scala version override launcher option is respected by the SBT export") {
645692
val input = "printVersion.sc"
646693
val code = """println(s"Default version: ${scala.util.Properties.versionNumberString}")"""

modules/options/src/main/scala/scala/build/Artifacts.scala

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,33 @@ object Artifacts {
177177
).left.flatMap(_.maybeRecoverWithDefault(Seq.empty, maybeRecoverOnError))
178178
}
179179

180-
val bridgeJarsOpt = Option.when(
181-
scalaArtifactsParams.params.scalaVersion.startsWith("3.") && includeBuildServerDeps
182-
) {
183-
Seq(dep"org.scala-lang:scala3-sbt-bridge:${scalaArtifactsParams.params.scalaVersion}")
184-
}.map { bridgeDependencies =>
185-
value {
186-
artifacts(
187-
bridgeDependencies.map(Positioned.none),
188-
allExtraRepositories,
189-
Some(scalaArtifactsParams.params),
190-
logger,
191-
cache.withMessage(
192-
s"Downloading Scala ${scalaArtifactsParams.params.scalaVersion} bridge"
193-
)
194-
).left.flatMap(_.maybeRecoverWithDefault(Seq.empty, maybeRecoverOnError))
195-
}.map(_._2)
196-
}
180+
val bridgeJarsOpt =
181+
(scalaArtifactsParams.params.scalaVersion -> includeBuildServerDeps match {
182+
case (sv, true) if sv.startsWith("3.") =>
183+
Some(Seq(
184+
dep"org.scala-lang:scala3-sbt-bridge:${scalaArtifactsParams.params.scalaVersion}"
185+
))
186+
case (sv, true)
187+
if Version(sv) >= Version("2.13.12") ||
188+
sv.startsWith(Constants.defaultScala213Version) =>
189+
Some(Seq(
190+
dep"org.scala-lang:scala2-sbt-bridge:${scalaArtifactsParams.params.scalaVersion}"
191+
))
192+
case _ => None
193+
})
194+
.map { bridgeDependencies =>
195+
value {
196+
artifacts(
197+
bridgeDependencies.map(Positioned.none),
198+
allExtraRepositories,
199+
Some(scalaArtifactsParams.params),
200+
logger,
201+
cache.withMessage(
202+
s"Downloading Scala ${scalaArtifactsParams.params.scalaVersion} bridge"
203+
)
204+
).left.flatMap(_.maybeRecoverWithDefault(Seq.empty, maybeRecoverOnError))
205+
}.map(_._2)
206+
}
197207

198208
def fetchedArtifactToPath(fetched: Fetch.Result): Seq[os.Path] =
199209
fetched.fullDetailedArtifacts.collect { case (_, _, _, Some(f)) => os.Path(f, Os.pwd) }

modules/options/src/main/scala/scala/build/options/BuildOptions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ final case class BuildOptions(
461461
addJmhDependencies = jmhOptions.addJmhDependencies,
462462
extraRepositories = value(finalRepositories),
463463
keepResolution = internal.keepResolution,
464-
includeBuildServerDeps = useBuildServer.getOrElse(false),
464+
includeBuildServerDeps = useBuildServer.getOrElse(true),
465465
cache = finalCache,
466466
logger = logger,
467467
maybeRecoverOnError = maybeRecoverOnError

0 commit comments

Comments
 (0)