Skip to content

Commit

Permalink
scala-x.xx- dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
pshirshov committed Apr 8, 2024
1 parent f97554a commit bfdc700
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion sbtgen/src/main/scala/izumi/sbtgen/Defaults.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ object Defaults {
Seq(
"unmanagedSourceDirectories" in SettingScope.Compile ++= addScalaVersionPlusSourceDirs("Compile / unmanagedSourceDirectories"),
"unmanagedSourceDirectories" in SettingScope.Test ++= addScalaVersionPlusSourceDirs("Test / unmanagedSourceDirectories"),
"unmanagedSourceDirectories" in SettingScope.Compile ++= addScalaVersionMinusSourceDirs("Compile / unmanagedSourceDirectories"),
"unmanagedSourceDirectories" in SettingScope.Test ++= addScalaVersionMinusSourceDirs("Test / unmanagedSourceDirectories"),
)
}

Expand All @@ -86,15 +88,29 @@ object Defaults {
|}""".stripMargin.raw
}

def addScalaVersionMinusSourceDirs(key: String): CRaw = {
s"""{
| val version = scalaVersion.value
| val crossVersions = crossScalaVersions.value
| import Ordering.Implicits._
| val gtEqVersions = crossVersions.map(CrossVersion.partialVersion).filter(_ >= CrossVersion.partialVersion(version)).flatten
| ($key).value.flatMap {
| case dir if dir.getPath.endsWith("scala") => gtEqVersions.map { case (m, n) => file(dir.getPath + s"-$$m.$$n-") }
| case _ => Seq.empty
| }
|}""".stripMargin.raw
}

def addScalaVersionRangeSourceDirs(key: String): CRaw = {
s"""{
| val crossVersions = crossScalaVersions.value
| import Ordering.Implicits._
| val ltEqVersions = crossVersions.map(CrossVersion.partialVersion).sorted.flatten
| def joinV = (_: Product).productIterator.mkString(".")
| val allRangeVersions = (2 to math.max(2, ltEqVersions.size - 1))
| val allRangeVersions = (2 to math.max(2, ltEqVersions.size))
| .flatMap(i => ltEqVersions.sliding(i).filter(_.size == i))
| .map(l => (l.head, l.last))
| .distinct
| CrossVersion.partialVersion(scalaVersion.value).toList.flatMap {
| version =>
| val rangeVersions = allRangeVersions
Expand Down

0 comments on commit bfdc700

Please sign in to comment.