Skip to content

Commit

Permalink
Merge pull request #2462 from tgodzik/do-not-add211
Browse files Browse the repository at this point in the history
bugfix: Don't add -release flag for Scala 2.11
  • Loading branch information
tgodzik authored Oct 11, 2024
2 parents 2540e44 + 18d2790 commit dc041e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
18 changes: 14 additions & 4 deletions backend/src/main/scala/bloop/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,8 @@ object Compiler {
private def adjustScalacReleaseOptions(
scalacOptions: Array[String],
javacBin: Option[AbsolutePath],
logger: Logger
logger: Logger,
scalaVersion: String
): Array[String] = {
def existsReleaseSetting = scalacOptions.exists(opt =>
opt.startsWith("-release") ||
Expand All @@ -813,7 +814,15 @@ object Compiler {
case Some(bin) => bin.getParent.getParent == JavaRuntime.home
case None => false
}

def releaseFlagForVersion(targetJvmVersion: Int): List[String] = {
// 2.11 does not support release flag
if (scalaVersion.startsWith("2.11")) Nil
/* At the moment, Scala does not support release flag for JDK 17
* This should not be an issue though since users can easily switch to JDK 17 for Bloop
*/
else if (targetJvmVersion > 17) Nil
else List("-release", targetJvmVersion.toString())
}
javacBin.flatMap(binary =>
// <JAVA_HOME>/bin/java
JavaRuntime.getJavaVersionFromJavaHome(binary.getParent.getParent)
Expand All @@ -828,7 +837,7 @@ object Compiler {
if (bloopNumVer >= 9 && numVer != bloopNumVer)
} yield {
if (bloopNumVer > numVer) {
scalacOptions ++ List("-release", numVer.toString())
scalacOptions ++ releaseFlagForVersion(numVer)
} else {
logger.warn(
s"Bloop is running with ${JavaRuntime.version} but your code requires $version to compile, " +
Expand Down Expand Up @@ -859,7 +868,8 @@ object Compiler {
val scalacOptions = adjustScalacReleaseOptions(
scalacOptions = inputs.scalacOptions,
javacBin = inputs.javacBin,
logger = logger
logger = logger,
inputs.scalaInstance.version
)

val optionsWithoutFatalWarnings = scalacOptions.filter(_ != "-Xfatal-warnings")
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/test/scala/bloop/JavaVersionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ object JavaVersionSpec extends bloop.testing.BaseSuite {

private val jvmManager = coursierapi.JvmManager.create()

def checkFlag(scalacOpts: List[String], jdkVersion: String = "8", shouldFail: Boolean = false) = {
def checkFlag(
scalacOpts: List[String],
jdkVersion: String = "8",
shouldFail: Boolean = false,
scalaVersion: Option[String] = None
) = {
val javaHome = jvmManager.get(jdkVersion).toPath()
val jvmConfig = Some(Config.JvmConfig(Some(javaHome), Nil))
TestUtil.withinWorkspace { workspace =>
Expand All @@ -25,7 +30,14 @@ object JavaVersionSpec extends bloop.testing.BaseSuite {

val logger = new RecordingLogger(ansiCodesSupported = false)
val `A` =
TestProject(workspace, "a", sources, jvmConfig = jvmConfig, scalacOptions = scalacOpts)
TestProject(
workspace,
"a",
sources,
jvmConfig = jvmConfig,
scalacOptions = scalacOpts,
scalaVersion = scalaVersion
)
val projects = List(`A`)
val state = loadState(workspace, projects, logger)
val compiledState = state.compile(`A`)
Expand Down Expand Up @@ -56,6 +68,8 @@ object JavaVersionSpec extends bloop.testing.BaseSuite {
test("flag-is-not-added-correctly") {
checkFlag(List("-release", "8"))
checkFlag(List("-release:8"))
// no release flag available in 2.11
checkFlag(Nil, jdkVersion = "11", scalaVersion = Some("2.11.12"))
}
}

Expand Down

0 comments on commit dc041e2

Please sign in to comment.