Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Make absolute path from relative plugin paths #2485

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading