Skip to content

Commit

Permalink
Set up Dotty
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Dec 4, 2019
1 parent a6a0eb3 commit 53165d5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jdk:

scala_version_212: &scala_version_212 2.12.10
scala_version_213: &scala_version_213 2.13.1
scala_version_dotty: &scala_version_dotty 0.21.0-bin-20191201-65a404f-NIGHTLY

before_install:
- export PATH=${PATH}:./vendor/bundle
Expand Down
72 changes: 45 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,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,7 +59,7 @@ commonScalaVersionSettings
ThisBuild / mimaFailOnNoPrevious := false

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 @@ -77,15 +77,21 @@ def macroDependencies(scalaVersion: String, scalaOrganization: String) =

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

lazy val simulacrumSettings = Seq(
addCompilerPlugin(scalafixSemanticdb),
scalacOptions ++= Seq(s"-P:semanticdb:targetroot:${baseDirectory.value}/.semanticdb", "-Yrangepos"),
libraryDependencies += "org.typelevel" %% "simulacrum-annotation" % "0.1.0-SNAPSHOT",
scalacOptions ++= (if (isDotty.value) Nil
else Seq(s"-P:semanticdb:targetroot:${baseDirectory.value}/.semanticdb", "-Yrangepos")),
libraryDependencies ++= (if (isDotty.value) Nil else Seq(compilerPlugin(scalafixSemanticdb))),
libraryDependencies += ("org.typelevel" %%% "simulacrum-annotation" % "0.1.0-SNAPSHOT")
.withDottyCompat(scalaVersion.value),
pomPostProcess := { (node: xml.Node) =>
new RuleTransformer(new RewriteRule {
override def transform(node: xml.Node): Seq[xml.Node] = node match {
Expand Down Expand Up @@ -143,15 +149,17 @@ 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.scalatestplus" %%% "scalatestplus-scalacheck" % scalatestplusScalaCheckVersion % "test"
)
).map(_.withDottyCompat(scalaVersion.value))
)

lazy val docsMappingsAPIDir = settingKey[String]("Name of subdirectory in site target directory for api docs")
Expand Down Expand Up @@ -496,7 +504,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 @@ -519,7 +530,10 @@ 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)
)
.jsSettings(commonJsSettings)
.jvmSettings(commonJvmSettings ++ mimaSettings("cats-core"))

Expand Down Expand Up @@ -782,29 +796,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",
"-language:experimental.macros",
"-unchecked",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfatal-warnings",
"-deprecation",
"-Xlint:-unused,_"
"-deprecation"
) ++ (if (priorTo2_13(scalaVersion))
Seq(
"-Yno-adapted-args",
"-Xfuture"
)
else
Nil)
Nil) ++ (if (isDotty)
Seq("-language:Scala2,implicitConversions", "-Ykind-projector", "-Xignore-scala2-macros")
else
Seq(
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-language:experimental.macros",
"-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 @@ -845,7 +863,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.3.4")
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.2")
addSbtPlugin("com.github.gseitz" %% "sbt-release" % "1.0.12")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0")
Expand Down

0 comments on commit 53165d5

Please sign in to comment.