-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sbt
61 lines (48 loc) · 2.17 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import scala.util.matching.Regex.{Groups, Match}
val CovariantRegex = """extends TryTInstances0|covariant|\+\s*([A_])\b""".r
def copySource(fromProject: Project) = {
for (configuration <- Seq(Compile, Test)) yield {
sourceGenerators in configuration += Def.task {
for {
covariantFile <- (unmanagedSources in configuration in fromProject).value
covariantDirectory <- (unmanagedSourceDirectories in configuration in fromProject).value
relativeFile <- covariantFile.relativeTo(covariantDirectory)
} yield {
val covariantSource = IO.read(covariantFile, scala.io.Codec.UTF8.charSet)
val doubleSource = CovariantRegex.replaceAllIn(
covariantSource,
(_: Match) match {
case Match("extends TryTInstances0") => "extends TryTInstances0 with InvariantInstances"
case Match("covariant") => "invariant"
case Groups(name @ ("A" | "_")) => name
}
)
val outputFile = (sourceManaged in configuration).value / relativeFile.getPath
IO.write(outputFile, doubleSource, scala.io.Codec.UTF8.charSet)
outputFile
}
}.taskValue
}
}
lazy val covariant = crossProject(JSPlatform, JVMPlatform).crossType(CrossType.Pure).build()
lazy val invariant = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.jvmSettings(copySource(covariant.jvm))
.jsSettings(copySource(covariant.js))
organization in ThisBuild := "com.thoughtworks.tryt"
publish / skip := true
enablePlugins(ScalaUnidocPlugin)
unidocProjectFilter in ScalaUnidoc in unidoc := inProjects(invariant.jvm, covariant.jvm)
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Nil
case Some((2, 13)) => Seq(compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.2" cross CrossVersion.full))
}
}
ThisBuild / scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Seq("-Ykind-projector:underscores")
case Some((2, 13)) | Some((2, 12)) => Seq("-Xsource:3", "-P:kind-projector:underscore-placeholders")
}
}
scalacOptions += "-Xexperimental"