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: Don't use fullclasspath in sbt plugin #2199

Merged
merged 1 commit into from
Nov 23, 2023
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
Expand Up @@ -788,7 +788,8 @@ object BloopDefaults {
val isForkedExecution = (Keys.fork in configuration in forkScopedTask).value
val workingDir = if (isForkedExecution) Keys.baseDirectory.value else rootBaseDirectory
val extraJavaOptions = List(s"-Duser.dir=${workingDir.getAbsolutePath}")
lazy val runtimeClasspath = (Runtime / Keys.fullClasspath).value.map(_.data.toPath()).toList
lazy val runtimeClasspath = BloopKeys.bloopProductDirectories.value.head.toPath() +:
(emulateRuntimeDependencyClasspath).value.map(_.toPath.toAbsolutePath).toList
lazy val javaRuntimeHome = (Runtime / Keys.javaHome).value.map(_.toPath())
lazy val javaRuntimeOptions = (Runtime / Keys.javaOptions).value
val config = Config.JvmConfig(Some(javaHome.toPath), (extraJavaOptions ++ javaOptions).toList)
Expand Down Expand Up @@ -1209,6 +1210,12 @@ object BloopDefaults {
internalClasspath ++ externalClasspath
}

def emulateRuntimeDependencyClasspath: Def.Initialize[Task[Seq[File]]] = Def.task {
val internalClasspath = (Runtime / BloopKeys.bloopInternalClasspath).value.map(_._2)
val externalClasspath = (Runtime / Keys.externalDependencyClasspath).value.map(_.data)
internalClasspath ++ externalClasspath
}

/**
* This task is triggered by `bloopGenerate` and does stuff which is
* sometimes dangerous because it can incur on cyclic dependencies, such as:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import bloop.integrations.sbt.BloopDefaults

name := "non-compiling"

val bloopConfigFile = settingKey[File]("Config file to test")
ThisBuild / bloopConfigFile := {
val bloopDir = Keys.baseDirectory.value./(".bloop")
val config = bloopDir./("non-compiling.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")
config
}

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

val configTestContents = BloopDefaults.unsafeParseConfig(bloopTestConfigFile.value.toPath)
assert(configTestContents.project.platform.isDefined)
}
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,3 @@
object Obj {
val a: Int = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> bloopGenerate
> test:bloopGenerate
> checkBloopFiles
Comment on lines +1 to +3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this test check that the compilation is not triggered?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we really want to check is that the files are properly generated despite the error. Previously, when we used fullclasspath the bloopInstall task itself would fail and nothing would get generated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see there is an error in the Obj.scala file

Loading