Move dataclassGen to Utils

This commit is contained in:
Adrien Piquerez 2024-10-11 16:57:28 +02:00
parent 6d6cbce465
commit 2cef7222f1
2 changed files with 17 additions and 16 deletions

View File

@ -1461,21 +1461,6 @@ lazy val lmCoursierDependencies = Def.settings(
),
)
def dataclassGen(data: Reference) = Def.taskDyn {
val root = (ThisBuild / baseDirectory).value.toURI.toString
val from = (data / Compile / sourceDirectory).value
val to = (Compile / sourceManaged).value
val outFrom = from.toURI.toString.stripSuffix("/").stripPrefix(root)
val outTo = to.toURI.toString.stripSuffix("/").stripPrefix(root)
val _ = (data / Compile / compile).value
Def.task {
val _ = (data / Compile / scalafix)
.toTask(s" --rules GenerateDataClass --out-from=$outFrom --out-to=$outTo")
.value
(to ** "*.scala").get
}
}
lazy val lmCoursierDefinitions = project
.in(file("lm-coursier/definitions"))
.disablePlugins(MimaPlugin)
@ -1500,7 +1485,7 @@ lazy val lmCoursier = project
Mima.settings,
Mima.lmCoursierFilters,
lmCoursierDependencies,
Compile / sourceGenerators += dataclassGen(lmCoursierDefinitions).taskValue,
Compile / sourceGenerators += Utils.dataclassGen(lmCoursierDefinitions).taskValue,
)
.dependsOn(
// We depend on lmIvy rather than just lmCore to handle the ModuleDescriptor

View File

@ -1,6 +1,7 @@
import scala.util.control.NonFatal
import sbt._
import Keys._
import scalafix.sbt.ScalafixPlugin.autoImport.scalafix
import sbt.internal.inc.Analysis
@ -165,6 +166,21 @@ object Utils {
sourceGenerators += Def.task(Seq(generateKeywords.value)).taskValue
)
)
def dataclassGen(data: Reference) = Def.taskDyn {
val root = (ThisBuild / baseDirectory).value.toURI.toString
val from = (data / Compile / sourceDirectory).value
val to = (Compile / sourceManaged).value
val outFrom = from.toURI.toString.stripSuffix("/").stripPrefix(root)
val outTo = to.toURI.toString.stripSuffix("/").stripPrefix(root)
val _ = (data / Compile / compile).value
Def.task {
val _ = (data / Compile / scalafix)
.toTask(s" --rules GenerateDataClass --out-from=$outFrom --out-to=$outTo")
.value
(to ** "*.scala").get
}
}
}
object Licensed {