From 04a16c6070655b000f1daef2f9761f9de576f12a Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Wed, 18 Sep 2024 15:35:34 +0200 Subject: [PATCH 1/2] improvement: Respect bspEnabled when generating bloop config files --- .../bloop/integrations/sbt/SbtBloop.scala | 4 +++- .../bsp-enabled/bar/src/test/scala/Bar.scala | 1 + .../sbt-test/sbt-bloop/bsp-enabled/build.sbt | 24 +++++++++++++++++++ .../bsp-enabled/foo/src/main/scala/Foo.scala | 1 + .../sbt-bloop/bsp-enabled/project/plugins.sbt | 1 + .../src/sbt-test/sbt-bloop/bsp-enabled/test | 2 ++ project/Dependencies.scala | 2 +- 7 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/bar/src/test/scala/Bar.scala create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/build.sbt create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/foo/src/main/scala/Foo.scala create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/project/plugins.sbt create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/test diff --git a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala index 7da554c3a5..6c4cb11ae1 100644 --- a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala +++ b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala @@ -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 diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/bar/src/test/scala/Bar.scala b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/bar/src/test/scala/Bar.scala new file mode 100644 index 0000000000..7deef9e552 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/bar/src/test/scala/Bar.scala @@ -0,0 +1 @@ +trait BarTest diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/build.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/build.sbt new file mode 100644 index 0000000000..e56511a0c9 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/build.sbt @@ -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)) +} diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/foo/src/main/scala/Foo.scala b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/foo/src/main/scala/Foo.scala new file mode 100644 index 0000000000..c389887ee5 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/foo/src/main/scala/Foo.scala @@ -0,0 +1 @@ +class Foo diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/project/plugins.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/project/plugins.sbt new file mode 100644 index 0000000000..1a5c0709e6 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version")) diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/test b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/test new file mode 100644 index 0000000000..ecb46662df --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/bsp-enabled/test @@ -0,0 +1,2 @@ +> bloopInstall +> checkBloopFiles diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 0bb2fc819f..5ec6d87e1f 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -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" From 42a2c61929d83f567c09980abf98725be0040754 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Wed, 18 Sep 2024 19:54:40 +0200 Subject: [PATCH 2/2] bugfix: Fix tests broken by updating sbt version --- .../sbt-bloop/non-compiling/build.sbt | 7 ++--- .../sbt-bloop/runtime-dependency/build.sbt | 27 ++++++++++--------- .../src/sbt-test/sbt-bloop/scala-js/build.sbt | 2 +- .../sbt-bloop/scala-js/project/plugins.sbt | 2 +- .../sbt-test/sbt-bloop/working-dir/build.sbt | 17 ++++++------ 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/non-compiling/build.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/non-compiling/build.sbt index 3aeb0bae3a..7b5335431a 100644 --- a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/non-compiling/build.sbt +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/non-compiling/build.sbt @@ -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 } diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/runtime-dependency/build.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/runtime-dependency/build.sbt index 617aa7335d..b8b9d5de99 100644 --- a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/runtime-dependency/build.sbt +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/runtime-dependency/build.sbt @@ -1,27 +1,29 @@ 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] @@ -29,10 +31,10 @@ ThisBuild / checkBloopFiles := { 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) @@ -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) diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/build.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/build.sbt index 29b513bbd2..9e9ed43824 100644 --- a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/build.sbt +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/build.sbt @@ -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"""")) } ) diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/project/plugins.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/project/plugins.sbt index fca381ca0d..6eb5189c80 100644 --- a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/project/plugins.sbt +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/scala-js/project/plugins.sbt @@ -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") diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/working-dir/build.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/working-dir/build.sbt index 6906e096f1..6518925099 100644 --- a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/working-dir/build.sbt +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/working-dir/build.sbt @@ -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( @@ -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" ) }