Skip to content

Commit

Permalink
Merge pull request #2446 from tgodzik/respect-bsp-enabled
Browse files Browse the repository at this point in the history
improvement: Respect bspEnabled when generating bloop config files
  • Loading branch information
tgodzik authored Sep 19, 2024
2 parents c1399d7 + 42a2c61 commit 97b71d9
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ object BloopDefaults {
BloopKeys.bloopProductDirectories := List(BloopKeys.bloopClassDirectory.value),
BloopKeys.bloopClassDirectory := generateBloopProductDirectories.value,
BloopKeys.bloopInternalClasspath := bloopInternalDependencyClasspath.value,
BloopKeys.bloopGenerate := bloopGenerate.value,
BloopKeys.bloopGenerate := {
if (Keys.bspEnabled.value) bloopGenerate.value else Value(None)
},
BloopKeys.bloopPostGenerate := bloopPostGenerate.value,
BloopKeys.bloopMainClass := None,
BloopKeys.bloopMainClass in Keys.run := BloopKeys.bloopMainClass.value
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trait BarTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
val foo = project
.in(file(".") / "foo")

val bar = project
.in(file(".") / "bar")
.settings(
bspEnabled := false
)
.dependsOn(foo)

val checkBloopFiles = taskKey[Unit]("Check bloop file contents")
checkBloopFiles in ThisBuild := {
import java.nio.file.Files
val bloopDir = Keys.baseDirectory.value./(".bloop")
val fooConfig = bloopDir./("foo.json")
val barConfig = bloopDir./("bar.json")
val barTestConfig = bloopDir./("bar-test.json")
val fooTestConfig = bloopDir./("foo-test.json")

assert(Files.exists(fooConfig.toPath))
assert(Files.exists(fooTestConfig.toPath))
assert(!Files.exists(barConfig.toPath))
assert(!Files.exists(barTestConfig.toPath))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> bloopInstall
> checkBloopFiles
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import bloop.integrations.sbt.BloopDefaults

name := "non-compiling"
val nonCompiling = project
.in(file("."))

val bloopConfigFile = settingKey[File]("Config file to test")
ThisBuild / bloopConfigFile := {
val bloopDir = Keys.baseDirectory.value./(".bloop")
val config = bloopDir./("non-compiling.json")
val config = bloopDir./("nonCompiling.json")
config
}

val bloopTestConfigFile = settingKey[File]("Test config file to test")
ThisBuild / bloopTestConfigFile := {
val bloopDir = Keys.baseDirectory.value./(".bloop")
val config = bloopDir./("non-compiling-test.json")
val config = bloopDir./("nonCompiling-test.json")
config
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
import bloop.integrations.sbt.BloopDefaults

name := "runtime-dependency"

libraryDependencies +=
"ch.qos.logback" % "logback-classic" % "1.2.7" % Runtime
val runtimeDependency = project
.in(file("."))
.settings(
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.7" % Runtime
)

val bloopConfigFile = settingKey[File]("Config file to test")
ThisBuild / bloopConfigFile := {
val bloopDir = Keys.baseDirectory.value./(".bloop")
val config = bloopDir./("runtime-dependency.json")
val config = bloopDir./("runtimeDependency.json")
config
}

val bloopTestConfigFile = settingKey[File]("Test config file to test")
ThisBuild / bloopTestConfigFile := {
val bloopDir = Keys.baseDirectory.value./(".bloop")
val config = bloopDir./("runtime-dependency-test.json")
val config = bloopDir./("runtimeDependency-test.json")
config
}

val checkBloopFiles = taskKey[Unit]("Check bloop file contents")
ThisBuild / checkBloopFiles := {
val configContents = BloopDefaults.unsafeParseConfig(bloopConfigFile.value.toPath)

assert(configContents.project.platform.isDefined)
val platformJvm =
configContents.project.platform.get.asInstanceOf[bloop.config.Config.Platform.Jvm]
val obtainedRuntimeClasspath = platformJvm.classpath.map(_.map(_.getFileName.toString))
val expectedRuntimeClasspath = Some(
List(
"classes",
"logback-core-1.2.7.jar",
"scala-library.jar",
"slf4j-api-1.7.32.jar",
"logback-classic-1.2.7.jar"
"logback-classic-1.2.7.jar",
"logback-core-1.2.7.jar",
"slf4j-api-1.7.32.jar"
)
)
assert(obtainedRuntimeClasspath == expectedRuntimeClasspath)
Expand All @@ -46,14 +48,13 @@ ThisBuild / checkBloopFiles := {
assert(testPlatformJvm.classpath.isEmpty)

val obtainedTestClasspath = configTestContents.project.classpath.map(_.getFileName.toString)
println(obtainedTestClasspath)
val expectedTestClasspath =
List(
"classes",
"logback-core-1.2.7.jar",
"scala-library.jar",
"slf4j-api-1.7.32.jar",
"logback-classic-1.2.7.jar"
"logback-classic-1.2.7.jar",
"logback-core-1.2.7.jar",
"slf4j-api-1.7.32.jar"
)

assert(obtainedTestClasspath == expectedTestClasspath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ val jsProject = project
val lines = IO.read(config).replaceAll("\\s", "")
assert(lines.contains(s""""platform":{"name":"$expected""""))
assert(lines.contains(s""""mode":"debug""""))
assert(lines.contains(s""""version":"0.6.28""""))
assert(lines.contains(s""""version":"1.5.1""""))
}
)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version"))
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1")
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ checkBloopFiles in ThisBuild := {
config.project.platform.get.asInstanceOf[bloop.config.Config.Platform.Jvm].config.options
}

val userDir = sys.props.get("user.dir").getOrElse("working-dir")
assert(
readJvmOptions(fooConfig)
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith("working-dir")),
"foo working directory ends with working-dir"
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith(userDir)),
s"foo working directory ends with $userDir"
)

assert(
readJvmOptions(fooTestConfig)
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith("working-dir")),
"foo test working directory ends with working-dir"
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith(userDir)),
s"foo test working directory ends with $userDir"
)

assert(
Expand All @@ -75,13 +76,13 @@ checkBloopFiles in ThisBuild := {

assert(
readJvmOptions(bazConfig)
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith("working-dir")),
"baz working directory ends with working-dir"
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith(userDir)),
s"baz working directory ends with $userDir"
)

assert(
readJvmOptions(bazTestConfig)
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith("working-dir")),
"baz test working directory ends with working-dir"
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith(userDir)),
s"baz test working directory ends with $userDir"
)
}
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Dependencies {
val Scala212Version = "2.12.20"
val Scala213Version = "2.13.14"

val SbtVersion = "1.3.3"
val SbtVersion = "1.5.8"

// Keep in sync in BloopComponentCompiler
val zincVersion = "1.10.2"
Expand Down

0 comments on commit 97b71d9

Please sign in to comment.