From d3e7f9102a29635b0c5dff9152a1cf110a9f89c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Tue, 5 Oct 2021 20:43:19 +0200 Subject: [PATCH] Scala 3.1.0-RC3 support, use the right phase (#82) --- .github/workflows/ci.yml | 11 ++++ README.md | 2 +- build.sbt | 53 +++++++++++-------- plugin/src/main/scala-3.0.x/AfterPhase.scala | 3 ++ plugin/src/main/scala-3.1.0+/AfterPhase.scala | 3 ++ .../main/scala-3/BetterToStringPlugin.scala | 3 +- 6 files changed, 49 insertions(+), 26 deletions(-) create mode 100644 plugin/src/main/scala-3.0.x/AfterPhase.scala create mode 100644 plugin/src/main/scala-3.1.0+/AfterPhase.scala diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe65119..09524a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,7 @@ jobs: - 3.0.1 - 3.0.2 - 3.1.0-RC2 + - 3.1.0-RC3 java: [graalvm-ce-java11@20.3.0] runs-on: ${{ matrix.os }} steps: @@ -211,6 +212,16 @@ jobs: tar xf targets.tar rm targets.tar + - name: Download target directories (3.1.0-RC3) + uses: actions/download-artifact@v2 + with: + name: target-${{ matrix.os }}-3.1.0-RC3-${{ matrix.java }} + + - name: Inflate target directories (3.1.0-RC3) + run: | + tar xf targets.tar + rm targets.tar + - uses: olafurpg/setup-gpg@v3 - run: sbt ++${{ matrix.scala }} ci-release diff --git a/README.md b/README.md index 57defb4..aa95017 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ The plugin is currently published for the following Scala versions: - 2.12.13, 2.12.14, 2.12.15 - 2.13.4, 2.13.5, 2.13.6 -- 3.0.0, 3.0.1, 3.0.2, 3.1.0-RC2 +- 3.0.0, 3.0.1, 3.0.2, 3.1.0-RC2, 3.1.0-RC3 For older Scala versions, see [previous versions of better-tostring](https://repo1.maven.org/maven2/org/polyvariant) ([or even older versions](https://repo1.maven.org/maven2/org/polyvariant)). diff --git a/build.sbt b/build.sbt index 2fb1c11..609b7c5 100644 --- a/build.sbt +++ b/build.sbt @@ -42,6 +42,7 @@ ThisBuild / crossScalaVersions := Seq( "3.0.1", "3.0.2", "3.1.0-RC2", + "3.1.0-RC3" ) ThisBuild / githubWorkflowJavaVersions := Seq(GraalVM11) @@ -82,31 +83,37 @@ val plugin = project.settings( s"scala3-compiler_3" else "scala-compiler" ) % scalaVersion.value - ) + ), + Compile / unmanagedSourceDirectories ++= { + val extraDirectoriesWithPredicates = Map[String, String => Boolean]( + ("scala-3.0.x", (_.startsWith("3.0"))), + ("scala-3.1.0+", (v => v.startsWith("3") && !v.startsWith("3.0"))) + ) + + extraDirectoriesWithPredicates.collect { + case (dir, predicate) if predicate(scalaVersion.value) => + sourceDirectory.value / "main" / dir + }.toList + } ) -val tests = project.settings( - (publish / skip) := true, - commonSettings, - scalacOptions ++= { - val jar = (plugin / Compile / packageBin).value - Seq( - s"-Xplugin:${jar.getAbsolutePath}", - s"-Xplugin-require:better-tostring", - s"-Jdummy=${jar.lastModified}" - ) //borrowed from bm4 - }, - libraryDependencies ++= Seq( - "org.scalameta" %% "munit" % (scalaVersion.value match { - case "3.0.0-M3" => "0.7.22" - case "3.0.0-RC1" => "0.7.23" - case "3.0.0-RC2" => "0.7.25" - case _ => "0.7.26" - }) % Test - ), - buildInfoKeys ++= Seq(scalaVersion), - buildInfoPackage := "b2s.buildinfo" -).enablePlugins(BuildInfoPlugin) +val tests = project + .settings( + (publish / skip) := true, + commonSettings, + scalacOptions ++= { + val jar = (plugin / Compile / packageBin).value + Seq( + s"-Xplugin:${jar.getAbsolutePath}", + s"-Xplugin-require:better-tostring", + s"-Jdummy=${jar.lastModified}" + ) //borrowed from bm4 + }, + libraryDependencies ++= Seq("org.scalameta" %% "munit" % "0.7.26" % Test), + buildInfoKeys ++= Seq(scalaVersion), + buildInfoPackage := "b2s.buildinfo" + ) + .enablePlugins(BuildInfoPlugin) val betterToString = project diff --git a/plugin/src/main/scala-3.0.x/AfterPhase.scala b/plugin/src/main/scala-3.0.x/AfterPhase.scala new file mode 100644 index 0000000..f2715aa --- /dev/null +++ b/plugin/src/main/scala-3.0.x/AfterPhase.scala @@ -0,0 +1,3 @@ +package org.polyvariant + +val AfterPhase = dotty.tools.dotc.typer.FrontEnd diff --git a/plugin/src/main/scala-3.1.0+/AfterPhase.scala b/plugin/src/main/scala-3.1.0+/AfterPhase.scala new file mode 100644 index 0000000..43ec8f5 --- /dev/null +++ b/plugin/src/main/scala-3.1.0+/AfterPhase.scala @@ -0,0 +1,3 @@ +package org.polyvariant + +val AfterPhase = dotty.tools.dotc.typer.TyperPhase diff --git a/plugin/src/main/scala-3/BetterToStringPlugin.scala b/plugin/src/main/scala-3/BetterToStringPlugin.scala index 64c7dad..6f97221 100644 --- a/plugin/src/main/scala-3/BetterToStringPlugin.scala +++ b/plugin/src/main/scala-3/BetterToStringPlugin.scala @@ -7,7 +7,6 @@ import dotty.tools.dotc.core.Flags.Package import dotty.tools.dotc.core.Symbols import dotty.tools.dotc.plugins.PluginPhase import dotty.tools.dotc.plugins.StandardPlugin -import dotty.tools.dotc.typer.FrontEnd import scala.annotation.tailrec @@ -21,7 +20,7 @@ final class BetterToStringPlugin extends StandardPlugin: final class BetterToStringPluginPhase extends PluginPhase: override val phaseName: String = "better-tostring-phase" - override val runsAfter: Set[String] = Set(FrontEnd.name) + override val runsAfter: Set[String] = Set(org.polyvariant.AfterPhase.name) override def transformTemplate(t: Template)(using ctx: Context): Tree = val clazz = ctx.owner.asClass