Skip to content

Commit

Permalink
bugfix: Make absolute path from relative plugin paths
Browse files Browse the repository at this point in the history
Otherwise this doesn't work, looks like Bloop and sbt's working dir have a mismatch?

Fixes #1421 finally
  • Loading branch information
tgodzik committed Oct 25, 2024
1 parent 57eb430 commit 11e7700
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
}
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,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())
}
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,3 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version"))

addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.1.8")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> bloopInstall
> checkBloopFiles

0 comments on commit 11e7700

Please sign in to comment.