Skip to content

Commit

Permalink
Make older Scala 2.12 versions work
Browse files Browse the repository at this point in the history
Previously, we would only publish for the newest Scala 2.12 version, howeverthis might cause issues for versions older than 2.12.12. To help with that, I added a full cross version and made sure that a proper versions is picked up by the sbt plugin.
  • Loading branch information
tgodzik committed Jan 17, 2021
1 parent b3f96da commit 424397e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
13 changes: 12 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sbt.librarymanagement.CrossVersion
import scala.collection.mutable

def scala212 = "2.12.13"
def scala212Legacy = "2.12.12"
def scala211 = "2.11.12"
def scala213 = "2.13.4"
def scala3 = List("3.0.0-M3", "3.0.0-M2")
Expand Down Expand Up @@ -36,6 +38,8 @@ def multiScalaDirectories(projectName: String) =
partialVersion.collect { case (major, minor) =>
result += base / s"scala-$major.$minor"
}

result += base / s"scala-${scalaVersion.value}"
if (isScala3.value) {
result += base / "scala-3"
}
Expand Down Expand Up @@ -64,7 +68,7 @@ def crossSetting[A](
inThisBuild(
List(
scalaVersion := scala212,
crossScalaVersions := List(scala212, scala211, scala213) ::: scala3,
crossScalaVersions := List(scala212, scala212Legacy, scala211, scala213) ::: scala3,
organization := "org.scalameta",
licenses := Seq(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
Expand Down Expand Up @@ -152,6 +156,7 @@ lazy val runtime = project
sharedSettings,
moduleName := "mdoc-runtime",
unmanagedSourceDirectories.in(Compile) ++= multiScalaDirectories("runtime").value,
crossVersion := CrossVersion.full,
libraryDependencies ++= crossSetting(
scalaVersion.value,
if2 = List(
Expand All @@ -172,6 +177,7 @@ lazy val mdoc = project
.settings(
sharedSettings,
unmanagedSourceDirectories.in(Compile) ++= multiScalaDirectories("mdoc").value,
crossVersion := CrossVersion.full,
moduleName := "mdoc",
mainClass in assembly := Some("mdoc.Main"),
assemblyJarName in assembly := "mdoc.jar",
Expand Down Expand Up @@ -329,6 +335,10 @@ lazy val plugin = project
managedResourceDirectories.in(Compile).value.head / "sbt-mdoc.properties"
val props = new java.util.Properties()
props.put("version", version.value)
props.put("scala211", scala211)
props.put("scala212Legacy", scala212Legacy)
props.put("scala212", scala212)
props.put("scala213", scala213)
IO.write(props, "sbt-mdoc properties", out)
List(out)
},
Expand All @@ -352,6 +362,7 @@ lazy val js = project
.in(file("mdoc-js"))
.settings(
sharedSettings,
crossVersion := CrossVersion.full,
crossScalaVersions --= scala3,
moduleName := "mdoc-js",
libraryDependencies ++=
Expand Down
4 changes: 4 additions & 0 deletions mdoc-sbt/src/main/scala/mdoc/BuildInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import java.util.Properties
object BuildInfo {
def version: String =
props.getProperty("version", "0.8.0-SNAPSHOT")
def scala211: String = props.getProperty("scala211", "2.11.12")
def scala212: String = props.getProperty("scala212", "2.12.13")
def scala212Legacy: String = props.getProperty("scala212Legacy", "2.12.12")
def scala213: String = props.getProperty("scala213", "2.13.4")

private lazy val props: Properties = {
val props = new Properties()
Expand Down
14 changes: 13 additions & 1 deletion mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ object MdocPlugin extends AutoPlugin {
}
}

def findCompatibleScalaVersion(scalaV: String) = {
scalaV.split('.').take(3).map(_.toInt) match {
case Array(2, 11, _) => BuildInfo.scala211
case Array(2, 12, minor) if minor <= 12 => BuildInfo.scala212Legacy
case Array(2, 12, _) => BuildInfo.scala212
case Array(2, 13, _) => BuildInfo.scala213
case other =>
throw new RuntimeException(s"Expected a valid scala versions, but got ${other.toList}")
}
}

override def projectSettings: Seq[Def.Setting[_]] =
List(
mdocIn := baseDirectory.in(ThisBuild).value / "docs",
Expand All @@ -91,7 +102,8 @@ object MdocPlugin extends AutoPlugin {
val isJS = mdocJS.value.isDefined
if (mdocAutoDependency.value) {
val suffix = if (isJS) "-js" else ""
List("org.scalameta" %% s"mdoc$suffix" % BuildInfo.version)
val compatibleScalaVersion = findCompatibleScalaVersion(scalaVersion.value)
List("org.scalameta" % s"mdoc${suffix}_$compatibleScalaVersion" % BuildInfo.version)
} else {
List()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package mdoc.internal.markdown

import scala.tools.nsc.Settings
import scala.tools.nsc.reporters.AbstractReporter
import scala.reflect.internal.util.Position

trait VersionSpecificFilteringReporter extends AbstractReporter { self: FilterStoreReporter =>
override def display(pos: Position, msg: String, severity: Severity): Unit =
add(pos, msg, severity)
override def displayPrompt(): Unit = ()
}

0 comments on commit 424397e

Please sign in to comment.