Skip to content

Commit

Permalink
cross compile scala 3 (#504)
Browse files Browse the repository at this point in the history
* draft: cross compile scala 3

* update: scala 3 compiles except warning errors and field selectors

* test: try compiling tests in scala 3

* update: address more compiler errrors

* update tests to compile

* update: explicit implicit val types

* fix: avoid unsafe type match

* update: drop unused dependencies and build configs

* fix: avoid unsafe type checking

* fix: format and ci check

* fix: address compiler warnings

* feat: cross build for scala 3

* fix: drop invalid scalac options for 3

* tidy: enable lint and address linter warnings

* chore: drop comment

* fix: address compiler warnings
  • Loading branch information
i10416 authored Jul 3, 2023
1 parent 56db96b commit ff55e34
Show file tree
Hide file tree
Showing 59 changed files with 1,698 additions and 231 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.10, 2.12.17]
scala: [2.13.10, 2.12.17, 3.3.0]
java:
- adopt-hotspot@8
- adopt-hotspot@11
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.17]
scala: [2.12.18]
java: [adopt-hotspot@8]
runs-on: ${{ matrix.os }}
steps:
Expand Down
127 changes: 66 additions & 61 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Global / onChangedBuildSource := ReloadOnSourceChanges
inThisBuild(
Seq(
libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always,
organization := "com.github.alonsodomin.cron4s",
organizationName := "Antonio Alonso Dominguez",
description := "CRON expression parser for Scala",
startYear := Some(2017),
crossScalaVersions := Seq("2.13.10", "2.12.17"),
organization := "com.github.alonsodomin.cron4s",
organizationName := "Antonio Alonso Dominguez",
description := "CRON expression parser for Scala",
startYear := Some(2017),
crossScalaVersions := Seq("2.13.10", "2.12.17", "3.3.0"),
homepage := Some(url("https://github.com/alonsodomin/cron4s")),
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.txt")),
scmInfo := Some(
Expand All @@ -46,21 +46,26 @@ val commonSettings = Def.settings(
"-unchecked",
"-deprecation",
"-explaintypes",
"-Xlint:-unused,_",
"-Xfatal-warnings",
"-language:postfixOps",
"-language:implicitConversions",
"-language:higherKinds",
"-language:existentials"
),
scalacOptions ++= (if (scalaVersion.value.startsWith("2.")) {
Seq(
"-Xlint:-unused,_"
),
} else
Seq(
"-Wunused:imports",
"-Wunused:locals",
"-Wunused:implicits",
"-Wunused:privates"
)),
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n == 12 => Seq("-Ypartial-unification")
case _ => Nil
}
},
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n > 12 =>
Seq("-Xlint:-byname-implicit", "-Ymacro-annotations")
case _ => Nil
Expand All @@ -70,10 +75,10 @@ val commonSettings = Def.settings(
Set("-Xlint:-unused,_", "-Xfatal-warnings")
),
Test / console / scalacOptions := (Compile / console / scalacOptions).value,
apiURL := Some(url("https://alonsodomin.github.io/cron4s/api/")),
autoAPIMappings := true,
Test / parallelExecution := false,
consoleImports := Seq("cron4s._"),
apiURL := Some(url("https://alonsodomin.github.io/cron4s/api/")),
autoAPIMappings := true,
Test / parallelExecution := false,
consoleImports := Seq("cron4s._"),
console / initialCommands := consoleImports.value
.map(s => s"import $s")
.mkString("\n")
Expand All @@ -85,27 +90,28 @@ lazy val commonJvmSettings = Seq(

lazy val commonJsSettings = Seq(
Global / scalaJSStage := FastOptStage,
scalacOptions += {
val tagOrHash = {
if (isSnapshot.value)
sys.process.Process("git rev-parse HEAD").lineStream_!.head
else version.value
}
val a = (LocalRootProject / baseDirectory).value.toURI.toString
val g = "https://raw.githubusercontent.com/alonsodomin/cron4s/" + tagOrHash
s"-P:scalajs:mapSourceURI:$a->$g/"
},
scalacOptions ++= (if (scalaVersion.value.startsWith("2.")) Seq {
val tagOrHash = {
if (isSnapshot.value)
sys.process.Process("git rev-parse HEAD").lineStream_!.head
else version.value
}
val a = (LocalRootProject / baseDirectory).value.toURI.toString
val g = "https://raw.githubusercontent.com/alonsodomin/cron4s/" + tagOrHash
s"-P:scalajs:mapSourceURI:$a->$g/"
}
else Seq.empty),
scalaJSLinkerConfig := scalaJSLinkerConfig.value.withModuleKind(ModuleKind.CommonJSModule),
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv()
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv()
)

lazy val consoleSettings = Seq(
consoleImports ++= Seq("java.time._", "cron4s.lib.javatime._")
)

lazy val publishSettings = Seq(
sonatypeProfileName := "com.github.alonsodomin",
publishMavenStyle := true,
sonatypeProfileName := "com.github.alonsodomin",
publishMavenStyle := true,
Test / publishArtifact := false,
// don't include scoverage as a dependency in the pom
// see issue #980
Expand All @@ -125,17 +131,17 @@ lazy val publishSettings = Seq(
)

lazy val noPublishSettings = publishSettings ++ Seq(
publish / skip := true,
publishArtifact := false,
publish / skip := true,
publishArtifact := false,
mimaFailOnNoPrevious := false
)

lazy val coverageSettings = Seq(
coverageMinimumStmtTotal := 90,
coverageMinimumStmtTotal := 90,
coverageMinimumBranchTotal := 80,
coverageFailOnMinimum := true,
coverageHighlighting := true,
coverageExcludedPackages := "cron4s\\.bench\\..*"
coverageFailOnMinimum := true,
coverageHighlighting := true,
coverageExcludedPackages := "cron4s\\.bench\\..*"
)

def mimaSettings(module: String): Seq[Setting[_]] =
Expand Down Expand Up @@ -178,19 +184,19 @@ lazy val docsMappingsAPIDir =
settingKey[String]("Name of subdirectory in site target directory for api docs")

lazy val docSettings = Seq(
micrositeName := "Cron4s",
micrositeDescription := "Scala CRON Parser",
micrositeHighlightTheme := "atom-one-light",
micrositeAuthor := "Antonio Alonso Dominguez",
micrositeGithubOwner := "alonsodomin",
micrositeGithubRepo := "cron4s",
micrositeGitterChannel := true,
micrositeUrl := "https://www.alonsodomin.me",
micrositeBaseUrl := "/cron4s",
micrositeHomepage := "https://www.alonsodomin.me/cron4s/",
micrositeDocumentationUrl := "/cron4s/api/cron4s/index.html",
micrositeName := "Cron4s",
micrositeDescription := "Scala CRON Parser",
micrositeHighlightTheme := "atom-one-light",
micrositeAuthor := "Antonio Alonso Dominguez",
micrositeGithubOwner := "alonsodomin",
micrositeGithubRepo := "cron4s",
micrositeGitterChannel := true,
micrositeUrl := "https://www.alonsodomin.me",
micrositeBaseUrl := "/cron4s",
micrositeHomepage := "https://www.alonsodomin.me/cron4s/",
micrositeDocumentationUrl := "/cron4s/api/cron4s/index.html",
micrositeDocumentationLabelDescription := "API Documentation",
micrositeTwitterCreator := "@_alonsodomin_",
micrositeTwitterCreator := "@_alonsodomin_",
micrositeExtraMdFiles := Map(
file("CHANGELOG.md") -> ExtraMdFileConfig(
"changelog.md",
Expand Down Expand Up @@ -218,15 +224,15 @@ lazy val docSettings = Seq(
"momentjsVersion" -> Dependencies.version.momentjs
)
),
mdocIn := sourceDirectory.value / "main" / "mdoc",
Test / fork := true,
mdocIn := sourceDirectory.value / "main" / "mdoc",
Test / fork := true,
docsMappingsAPIDir := "api",
addMappingsToSiteDir(
ScalaUnidoc / packageDoc / mappings,
docsMappingsAPIDir
),
ghpagesNoJekyll := false,
git.remoteRepo := "https://github.com/alonsodomin/cron4s.git",
git.remoteRepo := "https://github.com/alonsodomin/cron4s.git",
ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(
core.jvm,
circe.jvm,
Expand Down Expand Up @@ -257,7 +263,7 @@ lazy val cron4s = (project in file("."))

lazy val cron4sJS = (project in file(".js"))
.settings(
name := "js",
name := "js",
moduleName := "cron4s-js"
)
.settings(commonSettings: _*)
Expand All @@ -269,7 +275,7 @@ lazy val cron4sJS = (project in file(".js"))

lazy val cron4sJVM = (project in file(".jvm"))
.settings(
name := "jvm",
name := "jvm",
moduleName := "cron4s-jvm"
)
.settings(commonSettings)
Expand All @@ -296,7 +302,7 @@ lazy val docs = project
lazy val core = (crossProject(JSPlatform, JVMPlatform) in file("modules/core"))
.enablePlugins(AutomateHeaderPlugin, ScalafmtPlugin, MimaPlugin)
.settings(
name := "core",
name := "core",
moduleName := "cron4s-core"
)
.settings(commonSettings)
Expand All @@ -313,7 +319,7 @@ lazy val testkit =
(crossProject(JSPlatform, JVMPlatform) in file("modules/testkit"))
.enablePlugins(AutomateHeaderPlugin, ScalafmtPlugin, MimaPlugin)
.settings(
name := "testkit",
name := "testkit",
moduleName := "cron4s-testkit"
)
.settings(commonSettings)
Expand All @@ -328,12 +334,11 @@ lazy val testkit =
lazy val tests = (crossProject(JSPlatform, JVMPlatform) in file("tests"))
.enablePlugins(AutomateHeaderPlugin, ScalafmtPlugin)
.settings(
name := "tests",
name := "tests",
moduleName := "cron4s-tests"
)
.settings(commonSettings)
.settings(noPublishSettings)
.settings(Dependencies.tests)
.jsSettings(commonJsSettings)
.jsSettings(Dependencies.testsJS)
.jvmSettings(commonJvmSettings)
Expand All @@ -343,7 +348,7 @@ lazy val tests = (crossProject(JSPlatform, JVMPlatform) in file("tests"))
lazy val bench = (project in file("bench"))
.enablePlugins(AutomateHeaderPlugin, ScalafmtPlugin)
.settings(
name := "bench",
name := "bench",
moduleName := "cron4s-bench"
)
.settings(commonSettings)
Expand All @@ -360,7 +365,7 @@ lazy val bench = (project in file("bench"))
lazy val joda = (project in file("modules/joda"))
.enablePlugins(AutomateHeaderPlugin, ScalafmtPlugin, MimaPlugin)
.settings(
name := "joda",
name := "joda",
moduleName := "cron4s-joda",
consoleImports ++= Seq("org.joda.time._", "cron4s.lib.joda._")
)
Expand All @@ -377,7 +382,7 @@ lazy val momentjs = (project in file("modules/momentjs"))
.settings(commonJsSettings)
.settings(publishSettings)
.settings(
name := "momentjs",
name := "momentjs",
moduleName := "cron4s-momentjs"
)
.settings(Dependencies.momentjs)
Expand All @@ -391,7 +396,7 @@ lazy val circe =
(crossProject(JSPlatform, JVMPlatform).crossType(CrossType.Pure) in file("modules/circe"))
.enablePlugins(AutomateHeaderPlugin, ScalafmtPlugin, MimaPlugin)
.settings(
name := "circe",
name := "circe",
moduleName := "cron4s-circe"
)
.settings(commonSettings)
Expand All @@ -406,7 +411,7 @@ lazy val decline =
(crossProject(JSPlatform, JVMPlatform).crossType(CrossType.Pure) in file("modules/decline"))
.enablePlugins(AutomateHeaderPlugin, ScalafmtPlugin, MimaPlugin)
.settings(
name := "decline",
name := "decline",
moduleName := "cron4s-decline"
)
.settings(commonSettings)
Expand All @@ -420,7 +425,7 @@ lazy val decline =
lazy val doobie = (project in file("modules/doobie"))
.enablePlugins(AutomateHeaderPlugin, ScalafmtPlugin, MimaPlugin)
.settings(
name := "doobie",
name := "doobie",
moduleName := "cron4s-doobie"
)
.settings(commonSettings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package cron4s.lib.js

import cats.syntax.either._

import cron4s.CronField
import cron4s.datetime.{DateTimeError, DateTimeUnit, InvalidFieldValue, IsDateTime}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ import scala.language.implicitConversions
* Created by alonsodomin on 24/01/2017.
*/
package object datetime {
import cron4s.expr._
private[datetime] def applyRange(
expr: DateCronExpr
): List[IndexedSeq[Int]] = expr.raw.map(ops.range).toList
private[datetime] def applyRange(
expr: TimeCronExpr
): List[IndexedSeq[Int]] = expr.raw.map(ops.range).toList
private[datetime] def applyRange(
expr: CronExpr
): List[IndexedSeq[Int]] = expr.raw.map(ops.range).toList
import CronField._

private[datetime] type AnyCron =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package cron4s.expr

import cats.{Eq, Show}
import cats.implicits._

import shapeless._

/**
Expand Down Expand Up @@ -51,17 +48,4 @@ final case class CronExpr(
raw.map(_root_.cron4s.expr.ops.show).toList.mkString(" ")
}

object CronExpr {
implicit val CronExprEq: Eq[CronExpr] =
Eq.instance { (lhs, rhs) =>
lhs.seconds === rhs.seconds &&
lhs.minutes === rhs.minutes &&
lhs.hours === rhs.hours &&
lhs.daysOfMonth === rhs.daysOfMonth &&
lhs.months === rhs.months &&
lhs.daysOfWeek === rhs.daysOfWeek
}

implicit val CronExprShow: Show[CronExpr] =
Show.fromToString[CronExpr]
}
object CronExpr extends Cron4sInstances
Loading

0 comments on commit ff55e34

Please sign in to comment.