From 03b17d5fef27c913bf1fba055ff824a9854d16d7 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 26 Mar 2021 16:07:10 +0100 Subject: [PATCH] Make all older Scala versions work Previously, we cross published 2.12.13 and for older versions we used 2.12.12 due to changes to compiler API. This however did not work for the sbt plugin, which had the coursier resolve a wrong version for a transitive dependency. Now, we are using a more base reporting API, which should work for both 2.12.12- and 2.12.13+ versions. I previously haven't noticed that this is possible. The couriser issue is https://github.com/coursier/coursier/issues/1950 --- .github/workflows/ci.yml | 2 ++ build.sbt | 15 +-------------- mdoc-sbt/src/main/scala/mdoc/BuildInfo.scala | 1 - mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala | 11 +---------- .../VersionSpecificFilteringReporter.scala | 11 ----------- .../VersionSpecificFilteringReporter.scala | 10 ---------- .../VersionSpecificFilteringReporter.scala | 18 ++++++++++++++++++ 7 files changed, 22 insertions(+), 46 deletions(-) delete mode 100644 mdoc/src/main/scala-2.12.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala delete mode 100644 mdoc/src/main/scala-2.12.13/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala create mode 100644 mdoc/src/main/scala-2.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a4e8edba..639301792 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,8 @@ jobs: java: [adopt@1.8, adopt@1.11] command: - "'++2.11.12 test'" + # Test legacy Scala versions, where reporting API changed + - "'++2.12.12 test'" - "'++2.12.13 test' scripted" - "'++2.13.4 test'" - "'++3.0.0-M3 test'" diff --git a/build.sbt b/build.sbt index 5478107b2..157502588 100644 --- a/build.sbt +++ b/build.sbt @@ -1,8 +1,6 @@ -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-RC1", "3.0.0-M3", "3.0.0-M2") @@ -68,7 +66,7 @@ def crossSetting[A]( inThisBuild( List( scalaVersion := scala212, - crossScalaVersions := List(scala212, scala212Legacy, scala211, scala213) ::: scala3, + crossScalaVersions := List(scala212, scala211, scala213) ::: scala3, organization := "org.scalameta", licenses := Seq( "Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0") @@ -118,13 +116,6 @@ 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" @@ -163,7 +154,6 @@ lazy val runtime = project sharedSettings, moduleName := "mdoc-runtime", unmanagedSourceDirectories.in(Compile) ++= multiScalaDirectories("runtime").value, - crossVersion := crossVersionLegacy.value, libraryDependencies ++= crossSetting( scalaVersion.value, if2 = List( @@ -184,7 +174,6 @@ 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", @@ -342,7 +331,6 @@ 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) }, @@ -366,7 +354,6 @@ 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 a27e04a74..6408e3f3f 100644 --- a/mdoc-sbt/src/main/scala/mdoc/BuildInfo.scala +++ b/mdoc-sbt/src/main/scala/mdoc/BuildInfo.scala @@ -5,7 +5,6 @@ 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 ff98e263c..26333a5ad 100644 --- a/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala +++ b/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala @@ -66,13 +66,6 @@ object MdocPlugin extends AutoPlugin { } } - def compatibleScalaVersion = Def.setting { - scalaVersion.value.takeWhile(_ != '-').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", @@ -98,9 +91,7 @@ object MdocPlugin extends AutoPlugin { val isJS = mdocJS.value.isDefined if (mdocAutoDependency.value) { val suffix = if (isJS) "-js" else "" - List( - "org.scalameta" % s"mdoc${suffix}_${compatibleScalaVersion.value}" % BuildInfo.version - ) + List("org.scalameta" %% s"mdoc$suffix" % 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 deleted file mode 100644 index 76abcb14c..000000000 --- a/mdoc/src/main/scala-2.12.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala +++ /dev/null @@ -1,11 +0,0 @@ -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.13/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala b/mdoc/src/main/scala-2.12.13/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala deleted file mode 100644 index b638f7e81..000000000 --- a/mdoc/src/main/scala-2.12.13/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala +++ /dev/null @@ -1,10 +0,0 @@ -package mdoc.internal.markdown - -import scala.tools.nsc.Settings -import scala.tools.nsc.reporters.FilteringReporter -import scala.reflect.internal.util.Position - -trait VersionSpecificFilteringReporter extends FilteringReporter { self: FilterStoreReporter => - override def doReport(pos: Position, msg: String, severity: Severity): Unit = - add(pos, msg, severity) -} diff --git a/mdoc/src/main/scala-2.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala b/mdoc/src/main/scala-2.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala new file mode 100644 index 000000000..b4dc950f7 --- /dev/null +++ b/mdoc/src/main/scala-2.12/mdoc/internal/markdown/VersionSpecificFilteringReporter.scala @@ -0,0 +1,18 @@ +package mdoc.internal.markdown + +import scala.tools.nsc.Settings +import scala.tools.nsc.reporters.Reporter +import scala.reflect.internal.util.Position +import scala.reflect.internal.util.NoPosition + +trait VersionSpecificFilteringReporter extends Reporter { self: FilterStoreReporter => + override def info0(pos: Position, msg: String, severity: Severity, force: Boolean): Unit = { + if (!infos.exists(info => pos != NoPosition && info.pos.point == pos.point)) + add(pos, msg, severity) + } + + override def hasErrors: Boolean = infos.exists(_.severity == ERROR) + + override def hasWarnings: Boolean = infos.exists(_.severity == WARNING) + +}