From a865197770172686839e15d18b89a84f2129e514 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Thu, 2 Feb 2023 22:22:59 -0800 Subject: [PATCH] Port to Scala 2.13 (#133) --- .github/workflows/scala.yml | 15 +++++++++---- build.sbt | 3 ++- each/build.sbt.shared | 18 +++++++++++++-- .../com/thoughtworks/each/macrocompat.scala | 7 ++++++ .../com/thoughtworks/each/MonadicTest.scala | 3 ++- project/plugins.sbt | 4 +++- project/plugins.sbt.scala-js.1.x | 22 +++++++++++++++++++ 7 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 each/src/main/scala-2.13/com/thoughtworks/each/macrocompat.scala create mode 100644 project/plugins.sbt.scala-js.1.x diff --git a/.github/workflows/scala.yml b/.github/workflows/scala.yml index f926aa5..df82d0d 100644 --- a/.github/workflows/scala.yml +++ b/.github/workflows/scala.yml @@ -15,10 +15,17 @@ jobs: strategy: fail-fast: false matrix: - scala: - - 2.10.7 - - 2.11.12 - - 2.12.11 + include: + - scala: 2.11.12 + sbt-args: --addPluginSbtFile=project/plugins.sbt.scala-js.1.x + - scala: 2.12.11 + sbt-args: --addPluginSbtFile=project/plugins.sbt.scala-js.1.x + - scala: 2.13.4 + sbt-args: --addPluginSbtFile=project/plugins.sbt.scala-js.1.x + - scala: 2.10.7 + - scala: 2.11.12 + - scala: 2.12.11 + - scala: 2.13.4 steps: - uses: actions/checkout@v3 diff --git a/build.sbt b/build.sbt index 398e843..c60d7a2 100644 --- a/build.sbt +++ b/build.sbt @@ -9,7 +9,8 @@ fork in Global in compile := true description in ThisBuild := "A collection of Scala language extension for specific domains." -lazy val each = crossProject.crossType(CrossType.Pure) +lazy val each = sbtcrossproject.CrossPlugin.autoImport.crossProject + .crossType(sbtcrossproject.CrossPlugin.autoImport.CrossType.Pure) lazy val eachJVM = each.jvm diff --git a/each/build.sbt.shared b/each/build.sbt.shared index 6293023..8138793 100644 --- a/each/build.sbt.shared +++ b/each/build.sbt.shared @@ -16,11 +16,25 @@ libraryDependencies ++= { } } -addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full) +libraryDependencies ++= PartialFunction.condOpt(VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector("<2.13"))) { + case true => + compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full) +} + +scalacOptions ++= PartialFunction.condOpt(scalaBinaryVersion.value) { + case "2.13" => + "-Ymacro-annotations" +} libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value % Provided -libraryDependencies += "com.thoughtworks.sde" %%% "core" % "3.3.2" +libraryDependencies += { + if (scalaBinaryVersion.value == "2.10") { + "com.thoughtworks.sde" %%% "core" % "3.3.2" + } else { + "com.thoughtworks.sde" %%% "core" % "3.3.4" + } +} libraryDependencies += "com.thoughtworks.sde" %%% "comprehension-monad" % "3.3.2" diff --git a/each/src/main/scala-2.13/com/thoughtworks/each/macrocompat.scala b/each/src/main/scala-2.13/com/thoughtworks/each/macrocompat.scala new file mode 100644 index 0000000..2c8bf11 --- /dev/null +++ b/each/src/main/scala-2.13/com/thoughtworks/each/macrocompat.scala @@ -0,0 +1,7 @@ +package com.thoughtworks.each + +import scala.annotation.StaticAnnotation + +private[each] object macrocompat { + class bundle extends StaticAnnotation +} \ No newline at end of file diff --git a/each/src/test/scala/com/thoughtworks/each/MonadicTest.scala b/each/src/test/scala/com/thoughtworks/each/MonadicTest.scala index 0f001d7..2ccab8a 100755 --- a/each/src/test/scala/com/thoughtworks/each/MonadicTest.scala +++ b/each/src/test/scala/com/thoughtworks/each/MonadicTest.scala @@ -318,7 +318,8 @@ class MonadicTest { } catch { case e: Exception => { count += 1 - 100 + // FIXME: compile time error on Scala 2.13 if removing `: Int` + 100: Int } } finally { count += 1 diff --git a/project/plugins.sbt b/project/plugins.sbt index 21b5bfa..447bac0 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,7 +4,7 @@ addSbtPlugin( addSbtPlugin("com.thoughtworks.sbt-scala-js-map" % "sbt-scala-js-map" % "4.0.0") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.32") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.33") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.17") @@ -15,3 +15,5 @@ addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1") addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.2") addSbtPlugin("com.thoughtworks.example" % "sbt-example" % "9.2.1") + +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0") diff --git a/project/plugins.sbt.scala-js.1.x b/project/plugins.sbt.scala-js.1.x new file mode 100644 index 0000000..7973856 --- /dev/null +++ b/project/plugins.sbt.scala-js.1.x @@ -0,0 +1,22 @@ +// An optional sbt file to replace Scala.js 1.0 with 0.6 +dependencyOverrides += Defaults.sbtPluginExtra( + "org.scala-js" % "sbt-scalajs" % "1.0.1", + sbtBinaryVersion.value, + scalaBinaryVersion.value, +) + +Compile / sourceGenerators += Def.task { + val file = (Compile / sourceManaged).value / "SkipPublishForNonScalaJSProjects.scala" + IO.write(file, """ + import scalajscrossproject.ScalaJSCrossPlugin.autoImport._ + import sbtcrossproject.CrossPlugin.autoImport._ + import sbt._, Keys._ + object SkipPublishForNonScalaJSProjects extends AutoPlugin { + override def trigger = allRequirements + override def projectSettings = Seq( + publish / skip := crossProjectPlatform.value != JSPlatform + ) + } + """) + Seq(file) +}.taskValue