Skip to content

Commit

Permalink
More future-proof version group handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed May 7, 2024
1 parent 7bb8f9e commit 0fa4637
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
15 changes: 3 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,9 @@ val plugin = project
else "scala-compiler"
) % scalaVersion.value
),
Compile / unmanagedSourceDirectories ++= {
val extraDirectoriesWithPredicates = Map[String, String => Boolean](
("scala-3.1.x", (_.startsWith("3.1"))),
("scala-3.2.x", (_.startsWith("3.2"))),
("scala-3.3.x", (_.startsWith("3.3"))),
("scala-3.4.x", (_.startsWith("3.4")))
)

extraDirectoriesWithPredicates.collect {
case (dir, predicate) if predicate(scalaVersion.value) =>
sourceDirectory.value / "main" / dir
}.toList
// 3.3.x -> "scala-3.3.x"
Compile / unmanagedSourceDirectories += {
sourceDirectory.value / "main" / s"scala-${scalaVersion.value.split("\\.").take(2).mkString(".")}.x"
}
)
.enablePlugins(BackpublishPlugin)
Expand Down
9 changes: 5 additions & 4 deletions project/ReadmePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ object ReadmePlugin extends AutoPlugin {

def pattern(inside: String) = s"""<!-- SCALA VERSIONS START -->$inside<!-- SCALA VERSIONS END -->"""

val groups = List("2.12", "2.13", "3.1", "3.2", "3.3", "3.4")

val versionsGrouped = crossScalaVersions.value.groupBy { v =>
groups.find(v.startsWith(_)).getOrElse(sys.error("Unknown group for version: " + v))
v.split("\\.").take(2).mkString(".")
}

val versionsString = groups
val versionsString = versionsGrouped
.keys
.toSeq
.sorted
.map { prefix =>
"- " + versionsGrouped(prefix).mkString(", ")
}
Expand Down

0 comments on commit 0fa4637

Please sign in to comment.