From 11e77003f977978a958a35630d3af5acb58abe73 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 25 Oct 2024 19:03:59 +0200 Subject: [PATCH] bugfix: Make absolute path from relative plugin paths Otherwise this doesn't work, looks like Bloop and sbt's working dir have a mismatch? Fixes https://github.com/scalacenter/bloop/issues/1421 finally --- .../bloop/integrations/sbt/SbtBloop.scala | 26 ++++++++++++++++++- .../wartremover/bar/src/test/scala/Bar.scala | 1 + .../sbt-test/sbt-bloop/wartremover/build.sbt | 21 +++++++++++++++ .../wartremover/foo/src/main/scala/Foo.scala | 1 + .../sbt-bloop/wartremover/project/plugins.sbt | 3 +++ .../src/sbt-test/sbt-bloop/wartremover/test | 2 ++ 6 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/bar/src/test/scala/Bar.scala create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/build.sbt create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/foo/src/main/scala/Foo.scala create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/project/plugins.sbt create mode 100644 integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/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 6c4cb11ae1..1569cf29b5 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 @@ -1,8 +1,10 @@ package bloop.integrations.sbt +import java.io.File import java.nio.charset.StandardCharsets import java.nio.file.Files import java.nio.file.Path +import java.nio.file.Paths import java.nio.file.StandardCopyOption import java.util.concurrent.ConcurrentHashMap @@ -990,9 +992,31 @@ object BloopDefaults { Config.Test(frameworks, options) } + val pluginOpt = "-Xplugin:" + + def makePluginPathAbsolute(opt: String) = { + if (opt.startsWith(pluginOpt)) { + val pluginPath = opt.stripPrefix(pluginOpt) + if (Paths.get(pluginPath).isAbsolute()) opt + else { + val absolutePluginPath = cwd + File.separator + pluginPath + if (Paths.get(absolutePluginPath).toFile().exists()) + pluginOpt + absolutePluginPath + else opt + } + } else { + opt + } + } val javacOptions = Keys.javacOptions.in(Keys.compile).in(configuration).value.toList val scalacOptions = { - val options = Keys.scalacOptions.in(Keys.compile).in(configuration).value.toList + val options = Keys.scalacOptions + .in(Keys.compile) + .in(configuration) + .value + .toList + .map(makePluginPathAbsolute) + val internalClasspath = BloopKeys.bloopInternalClasspath.value replaceScalacOptionsPaths(options, internalClasspath, logger) } diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/bar/src/test/scala/Bar.scala b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/bar/src/test/scala/Bar.scala new file mode 100644 index 0000000000..7deef9e552 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/bar/src/test/scala/Bar.scala @@ -0,0 +1 @@ +trait BarTest diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/build.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/build.sbt new file mode 100644 index 0000000000..8a1c05a7e1 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/build.sbt @@ -0,0 +1,21 @@ +import java.nio.file.Paths +import bloop.integrations.sbt.BloopDefaults + +val foo = project + .in(file(".") / "foo") + .settings( + wartremoverWarnings := Warts.all + ) + +val checkBloopFiles = taskKey[Unit]("Check bloop file contents") +checkBloopFiles in ThisBuild := { + import java.nio.file.Files + val bloopDir = Keys.baseDirectory.value./(".bloop") + val fooConfigFile = bloopDir./("foo.json") + + val fooConfig = BloopDefaults.unsafeParseConfig(fooConfigFile.toPath) + + val pluginPath = + fooConfig.project.scala.get.options.find(_.startsWith("-Xplugin")).get.stripPrefix("-Xplugin:") + assert(Paths.get(pluginPath).toFile.exists()) +} diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/foo/src/main/scala/Foo.scala b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/foo/src/main/scala/Foo.scala new file mode 100644 index 0000000000..c389887ee5 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/foo/src/main/scala/Foo.scala @@ -0,0 +1 @@ +class Foo diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/project/plugins.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/project/plugins.sbt new file mode 100644 index 0000000000..39595dfb7c --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/project/plugins.sbt @@ -0,0 +1,3 @@ +addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version")) + +addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.1.8") diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/test b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/test new file mode 100644 index 0000000000..ecb46662df --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/wartremover/test @@ -0,0 +1,2 @@ +> bloopInstall +> checkBloopFiles