mirror of https://github.com/sbt/sbt.git
Merge pull request #8086 from bjaglin/cache-semanticdb
[2.x] cache semanticdb output when not included in JAR
This commit is contained in:
commit
187eb0f584
|
|
@ -18,6 +18,7 @@ import sbt.librarymanagement.{ Configuration, CrossVersion }
|
||||||
import ProjectExtra.inConfig
|
import ProjectExtra.inConfig
|
||||||
import sbt.internal.inc.ScalaInstance
|
import sbt.internal.inc.ScalaInstance
|
||||||
import sbt.ScopeFilter.Make.*
|
import sbt.ScopeFilter.Make.*
|
||||||
|
import sbt.util.CacheImplicits.given
|
||||||
|
|
||||||
object SemanticdbPlugin extends AutoPlugin {
|
object SemanticdbPlugin extends AutoPlugin {
|
||||||
override def requires = JvmPlugin
|
override def requires = JvmPlugin
|
||||||
|
|
@ -54,6 +55,10 @@ object SemanticdbPlugin extends AutoPlugin {
|
||||||
inConfig(Test)(configurationSettings)
|
inConfig(Test)(configurationSettings)
|
||||||
|
|
||||||
lazy val configurationSettings: Seq[Def.Setting[?]] = List(
|
lazy val configurationSettings: Seq[Def.Setting[?]] = List(
|
||||||
|
compileIncremental := Def.taskIf {
|
||||||
|
if (semanticdbIncludeInJar.value || !semanticdbEnabled.value) compileIncremental.value
|
||||||
|
else compileIncAndCacheSemanticdbTargetRootTask.value
|
||||||
|
}.value,
|
||||||
semanticdbTargetRoot := {
|
semanticdbTargetRoot := {
|
||||||
val converter = fileConverter.value
|
val converter = fileConverter.value
|
||||||
val in = semanticdbIncludeInJar.value
|
val in = semanticdbIncludeInJar.value
|
||||||
|
|
@ -93,6 +98,16 @@ object SemanticdbPlugin extends AutoPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val compileIncAndCacheSemanticdbTargetRootTask = Def.cachedTask {
|
||||||
|
val prev = compileIncremental.value
|
||||||
|
val converter = fileConverter.value
|
||||||
|
val targetRoot = semanticdbTargetRoot.value
|
||||||
|
|
||||||
|
val vfTargetRoot = converter.toVirtualFile(targetRoot.toPath)
|
||||||
|
Def.declareOutputDirectory(vfTargetRoot)
|
||||||
|
prev
|
||||||
|
}
|
||||||
|
|
||||||
private def ancestorConfigs(config: Configuration) = {
|
private def ancestorConfigs(config: Configuration) = {
|
||||||
def ancestors(configs: Vector[Configuration]): Vector[Configuration] =
|
def ancestors(configs: Vector[Configuration]): Vector[Configuration] =
|
||||||
configs ++ configs.flatMap(conf => ancestors(conf.extendsConfigs))
|
configs ++ configs.flatMap(conf => ancestors(conf.extendsConfigs))
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ lazy val expectErrorNotCrash = taskKey[Unit]("Ensures that sbt properly set type
|
||||||
|
|
||||||
expectErrorNotCrash := {
|
expectErrorNotCrash := {
|
||||||
val fail = (Compile / compileIncremental).failure.value
|
val fail = (Compile / compileIncremental).failure.value
|
||||||
fail.directCause match
|
Incomplete.allExceptions(fail).headOption match
|
||||||
case Some(x: xsbti.CompileFailed) => ()
|
case Some(x: xsbti.CompileFailed) => ()
|
||||||
case _ => sys.error("Compiler crashed instead of providing a compile-time-only exception.")
|
case _ => sys.error("Compiler crashed instead of providing a compile-time-only exception.")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
semanticdbEnabled := true
|
||||||
|
|
||||||
|
val matrix = projectMatrix
|
||||||
|
.defaultAxes(VirtualAxis.jvm)
|
||||||
|
.jvmPlatform(scalaVersions =
|
||||||
|
Seq(
|
||||||
|
"2.12.20", // semanticdb support via semanticdb-scalac
|
||||||
|
"3.6.4" // built-in semanticdb support
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
> compile
|
||||||
|
$ exists target/**/scala-2.12*/**/meta/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
$ exists target/**/scala-3*/**/meta/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
|
||||||
|
> clean
|
||||||
|
-$ exists target/**/scala-2.12*/**/meta/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
-$ exists target/**/scala-3*/**/meta/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
> compile
|
||||||
|
$ exists target/**/scala-2.12*/**/meta/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
$ exists target/**/scala-3*/**/meta/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
|
||||||
|
> set LocalProject("matrix2_12") / Compile / semanticdbTargetRoot := (LocalProject("matrix2_12") / Compile / target).value / "custom212"
|
||||||
|
> set LocalProject("matrix3") / Compile / semanticdbTargetRoot := (LocalProject("matrix3") / Compile / target).value / "custom3"
|
||||||
|
|
||||||
|
> compile
|
||||||
|
$ exists target/**/scala-2.12*/**/custom212/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
$ exists target/**/scala-3*/**/custom3/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
|
||||||
|
> clean
|
||||||
|
> compile
|
||||||
|
-$ exists target/**/scala-2.12*/**/meta/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
-$ exists target/**/scala-3*/**/meta/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
$ exists target/**/scala-2.12*/**/custom212/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
$ exists target/**/scala-3*/**/custom3/META-INF/semanticdb/matrix/src/main/scala/foo/Compile.scala.semanticdb
|
||||||
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package foo
|
||||||
|
|
||||||
|
object Compile {
|
||||||
|
def main(args: Array[String]): Unit = {
|
||||||
|
println("hello world")
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue