Skip to content

Commit

Permalink
Set up Dotty
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Jun 19, 2020
1 parent 22c3618 commit b874fd5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 27 deletions.
82 changes: 55 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def scalaVersionSpecificFolders(srcName: String, srcBaseDir: java.io.File, scala
List(CrossType.Pure, CrossType.Full)
.flatMap(_.sharedSrcDir(srcBaseDir, srcName).toList.map(f => file(f.getPath + suffix)))
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, y)) if y >= 13 =>
extraDirs("-2.13+")
case _ => Nil
case Some((2, y)) => extraDirs("-2.x") ++ (if (y >= 13) extraDirs("-2.13+") else Nil)
case Some((0, _)) => extraDirs("-2.13+") ++ extraDirs("-3.x")
case _ => Nil
}
}

Expand All @@ -59,8 +59,11 @@ commonScalaVersionSettings

ThisBuild / mimaFailOnNoPrevious := false

def doctestGenTestsDottyCompat(isDotty: Boolean, genTests: Seq[File]): Seq[File] =
if (isDotty) Nil else genTests

lazy val commonSettings = commonScalaVersionSettings ++ Seq(
scalacOptions ++= commonScalacOptions(scalaVersion.value),
scalacOptions ++= commonScalacOptions(scalaVersion.value, isDotty.value),
Compile / unmanagedSourceDirectories ++= scalaVersionSpecificFolders("main", baseDirectory.value, scalaVersion.value),
Test / unmanagedSourceDirectories ++= scalaVersionSpecificFolders("test", baseDirectory.value, scalaVersion.value),
resolvers ++= Seq(Resolver.sonatypeRepo("releases"), Resolver.sonatypeRepo("snapshots")),
Expand All @@ -69,19 +72,24 @@ lazy val commonSettings = commonScalaVersionSettings ++ Seq(
) ++ warnUnusedImport

def macroDependencies(scalaVersion: String) =
Seq("org.scala-lang" % "scala-reflect" % scalaVersion % Provided)
if (scalaVersion.startsWith("2")) Seq("org.scala-lang" % "scala-reflect" % scalaVersion % Provided) else Nil

lazy val catsSettings = Seq(
incOptions := incOptions.value.withLogRecompileOnMacro(false),
libraryDependencies ++= Seq(
compilerPlugin(("org.typelevel" %% "kind-projector" % kindProjectorVersion).cross(CrossVersion.full))
libraryDependencies ++= (
if (isDotty.value) Nil else Seq(
compilerPlugin(("org.typelevel" %% "kind-projector" % kindProjectorVersion).cross(CrossVersion.full))
)
) ++ macroDependencies(scalaVersion.value)
) ++ commonSettings ++ publishSettings ++ scoverageSettings ++ simulacrumSettings

lazy val simulacrumSettings = Seq(
addCompilerPlugin(scalafixSemanticdb),
scalacOptions ++= Seq(s"-P:semanticdb:targetroot:${baseDirectory.value}/target/.semanticdb", "-Yrangepos"),
libraryDependencies += "org.typelevel" %% "simulacrum-scalafix-annotations" % "0.5.0",
libraryDependencies ++= (if (isDotty.value) Nil else Seq(compilerPlugin(scalafixSemanticdb))),
scalacOptions ++= (
if (isDotty.value) Nil else Seq(s"-P:semanticdb:targetroot:${baseDirectory.value}/target/.semanticdb", "-Yrangepos")
),
libraryDependencies +=
("org.typelevel" %% "simulacrum-scalafix-annotations" % "0.5.0").withDottyCompat(scalaVersion.value),
pomPostProcess := { (node: xml.Node) =>
new RuleTransformer(new RewriteRule {
override def transform(node: xml.Node): Seq[xml.Node] =
Expand Down Expand Up @@ -141,17 +149,25 @@ lazy val includeGeneratedSrc: Setting[_] = {
}

lazy val disciplineDependencies = Seq(
libraryDependencies ++= Seq("org.scalacheck" %%% "scalacheck" % scalaCheckVersion,
"org.typelevel" %%% "discipline-core" % disciplineVersion
)
libraryDependencies ++= Seq(
"org.scalacheck" %%% "scalacheck" % scalaCheckVersion,
"org.typelevel" %%% "discipline-core" % disciplineVersion
).map(_.withDottyCompat(scalaVersion.value))
)

lazy val testingDependencies = Seq(
libraryDependencies ++= Seq(
"org.typelevel" %%% "discipline-scalatest" % disciplineScalatestVersion % Test,
"org.scalatest" %%% "scalatest-shouldmatchers" % scalatestVersion % Test,
"org.scalatest" %%% "scalatest-funsuite" % scalatestVersion % Test,
"org.scalatestplus" %%% "scalacheck-1-14" % scalatestplusScalaCheckVersion % Test
),
libraryDependencies ++= Seq(
("org.typelevel" %%% "discipline-scalatest" % disciplineScalatestVersion % Test)
).map(
_.exclude("org.scalatestplus", "scalacheck-1-14_2.13")
.exclude("org.scalactic", "scalactic_2.13")
.exclude("org.scalatest", "scalatest_2.13")
.withDottyCompat(scalaVersion.value)
)
)

Expand Down Expand Up @@ -397,6 +413,7 @@ lazy val docs = project
.settings(docSettings)
.settings(commonJvmSettings)
.settings(
crossScalaVersions := crossScalaVersions.value.init,
libraryDependencies ++= Seq(
"org.typelevel" %%% "discipline-scalatest" % disciplineScalatestVersion
),
Expand Down Expand Up @@ -489,7 +506,10 @@ lazy val kernel = crossProject(JSPlatform, JVMPlatform)
.settings(includeGeneratedSrc)
.jsSettings(commonJsSettings)
.jvmSettings(commonJvmSettings ++ mimaSettings("cats-kernel"))
.settings(libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion % Test)
.settings(
libraryDependencies += ("org.scalacheck" %%% "scalacheck" % scalaCheckVersion % Test)
.withDottyCompat(scalaVersion.value)
)

lazy val kernelLaws = crossProject(JSPlatform, JVMPlatform)
.in(file("kernel-laws"))
Expand All @@ -512,7 +532,11 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
.settings(catsSettings)
.settings(sourceGenerators in Compile += (sourceManaged in Compile).map(Boilerplate.gen).taskValue)
.settings(includeGeneratedSrc)
.settings(libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion % Test)
.settings(
libraryDependencies += ("org.scalacheck" %%% "scalacheck" % scalaCheckVersion % Test)
.withDottyCompat(scalaVersion.value),
doctestGenTests := doctestGenTestsDottyCompat(isDotty.value, doctestGenTests.value)
)
.jsSettings(commonJsSettings)
.jvmSettings(commonJvmSettings ++ mimaSettings("cats-core"))

Expand Down Expand Up @@ -776,29 +800,33 @@ lazy val crossVersionSharedSources: Seq[Setting[_]] =
}
}

def commonScalacOptions(scalaVersion: String) =
def commonScalacOptions(scalaVersion: String, isDotty: Boolean) =
Seq(
"-encoding",
"UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfatal-warnings",
"-deprecation",
"-Xlint:-unused,_"
"-deprecation"
) ++ (if (priorTo2_13(scalaVersion))
Seq(
"-Yno-adapted-args",
"-Ypartial-unification",
"-Xfuture"
)
else
Nil)
Nil) ++ (if (isDotty)
Seq("-language:implicitConversions", "-Ykind-projector", "-Xignore-scala2-macros")
else
Seq(
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xlint:-unused,_"
))

def priorTo2_13(scalaVersion: String): Boolean =
CrossVersion.partialVersion(scalaVersion) match {
Expand Down Expand Up @@ -839,7 +867,7 @@ lazy val sharedReleaseProcess = Seq(
)

lazy val warnUnusedImport = Seq(
scalacOptions ++= Seq("-Ywarn-unused:imports"),
scalacOptions ++= (if (isDotty.value) Nil else Seq("-Ywarn-unused:imports")),
scalacOptions in (Compile, console) ~= { _.filterNot(Set("-Ywarn-unused-import", "-Ywarn-unused:imports")) },
scalacOptions in (Test, console) := (scalacOptions in (Compile, console)).value
)
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.17")
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.3")
addSbtPlugin("com.github.gseitz" %% "sbt-release" % "1.0.13")
Expand Down

0 comments on commit b874fd5

Please sign in to comment.