From 4543724e3cedc54797026442174734627dbeaec6 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Sun, 17 Jan 2021 19:44:33 +0100 Subject: [PATCH] Make older Scala 2.12 versions work 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. --- build.sbt | 17 ++++++++++++++++- mdoc-sbt/src/main/scala/mdoc/BuildInfo.scala | 1 + mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala | 11 ++++++++++- .../VersionSpecificFilteringReporter.scala | 11 +++++++++++ .../VersionSpecificFilteringReporter.scala | 0 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 mdoc/src/main/scala-2.12.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala rename mdoc/src/main/{scala-2.12 => scala-2.12.13}/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala (100%) diff --git a/build.sbt b/build.sbt index c86f04d74..c3506bb40 100644 --- a/build.sbt +++ b/build.sbt @@ -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") @@ -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" } @@ -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") @@ -114,6 +118,13 @@ val V = new { val scalacheck = "1.15.2" } +val crossVersionLegacy = Def.setting { + CrossVersion.binaryWith( + prefix = "", + suffix = if (scalaVersion.value == scala212Legacy) ".12" else "" + ) +} + lazy val pprintVersion = Def.setting { if (scalaVersion.value.startsWith("2.11")) "0.5.4" else "0.6.0" @@ -152,6 +163,7 @@ lazy val runtime = project sharedSettings, moduleName := "mdoc-runtime", unmanagedSourceDirectories.in(Compile) ++= multiScalaDirectories("runtime").value, + crossVersion := crossVersionLegacy.value, libraryDependencies ++= crossSetting( scalaVersion.value, if2 = List( @@ -172,6 +184,7 @@ lazy val mdoc = project .settings( sharedSettings, unmanagedSourceDirectories.in(Compile) ++= multiScalaDirectories("mdoc").value, + crossVersion := crossVersionLegacy.value, moduleName := "mdoc", mainClass in assembly := Some("mdoc.Main"), assemblyJarName in assembly := "mdoc.jar", @@ -329,6 +342,7 @@ 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("scala212Legacy", scala212Legacy) IO.write(props, "sbt-mdoc properties", out) List(out) }, @@ -352,6 +366,7 @@ lazy val js = project .in(file("mdoc-js")) .settings( sharedSettings, + crossVersion := crossVersionLegacy.value, crossScalaVersions --= scala3, moduleName := "mdoc-js", libraryDependencies ++= diff --git a/mdoc-sbt/src/main/scala/mdoc/BuildInfo.scala b/mdoc-sbt/src/main/scala/mdoc/BuildInfo.scala index 6408e3f3f..a27e04a74 100644 --- a/mdoc-sbt/src/main/scala/mdoc/BuildInfo.scala +++ b/mdoc-sbt/src/main/scala/mdoc/BuildInfo.scala @@ -5,6 +5,7 @@ import java.util.Properties object BuildInfo { def version: String = props.getProperty("version", "0.8.0-SNAPSHOT") + def scala212Legacy: String = props.getProperty("scala212Legacy", "2.12.12") private lazy val props: Properties = { val props = new Properties() diff --git a/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala b/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala index 26333a5ad..9994482ef 100644 --- a/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala +++ b/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala @@ -66,6 +66,13 @@ object MdocPlugin extends AutoPlugin { } } + def compatibleScalaVersion = Def.setting { + scalaVersion.value.split('.').take(3).map(_.toInt) match { + case Array(2, 12, minor) if minor <= 12 => BuildInfo.scala212Legacy + case _ => scalaBinaryVersion.value + } + } + override def projectSettings: Seq[Def.Setting[_]] = List( mdocIn := baseDirectory.in(ThisBuild).value / "docs", @@ -91,7 +98,9 @@ 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) + List( + "org.scalameta" % s"mdoc${suffix}_${compatibleScalaVersion.value}" % BuildInfo.version + ) } else { List() } diff --git a/mdoc/src/main/scala-2.12.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala b/mdoc/src/main/scala-2.12.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala new file mode 100644 index 000000000..76abcb14c --- /dev/null +++ b/mdoc/src/main/scala-2.12.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala @@ -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 = () +} diff --git a/mdoc/src/main/scala-2.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala b/mdoc/src/main/scala-2.12.13/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala similarity index 100% rename from mdoc/src/main/scala-2.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala rename to mdoc/src/main/scala-2.12.13/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala