forked from fthomas/refined
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
576 lines (514 loc) · 16.9 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
import sbtcrossproject.CrossProject
import sbtcrossproject.Platform
import org.typelevel.sbt.gha.JavaSpec.Distribution.Temurin
/// variables
val groupId = "eu.timepit"
val projectName = "refined"
val rootPkg = s"$groupId.$projectName"
val gitHubOwner = "fthomas"
val gitPubUrl = s"https://github.com/$gitHubOwner/$projectName.git"
val gitDevUrl = s"git@github.com:$gitHubOwner/$projectName.git"
val Scala_2_12 = "2.12.17"
val Scala_2_13 = "2.13.10"
val Scala_3 = "3.2.2"
val catsVersion = "2.9.0"
val jsonpathVersion = "2.7.0"
val macroParadiseVersion = "2.1.1"
val pureconfigVersion = "0.17.2"
val shapelessVersion = "2.3.10"
val scalaCheckVersion = "1.17.0"
val scalazVersion = "7.3.7"
val scodecVersion = "1.11.10"
val scoptVersion = "4.1.0"
def macroParadise(configuration: Configuration): Def.Initialize[Seq[ModuleID]] =
Def.setting {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v <= 12 =>
Seq(
compilerPlugin(
("org.scalamacros" % "paradise" % macroParadiseVersion cross CrossVersion.patch) % configuration
)
)
case _ =>
Seq.empty // https://github.com/scala/scala/pull/6606
}
}
val moduleCrossPlatformMatrix: Map[String, List[Platform]] = Map(
"cats" -> List(JVMPlatform, JSPlatform, NativePlatform),
"core" -> List(JVMPlatform, JSPlatform, NativePlatform),
"eval" -> List(JVMPlatform),
"jsonpath" -> List(JVMPlatform),
"pureconfig" -> List(JVMPlatform),
"scalacheck" -> List(JVMPlatform, JSPlatform, NativePlatform),
"scalaz" -> List(JVMPlatform),
"scodec" -> List(JVMPlatform, JSPlatform),
"scopt" -> List(JVMPlatform),
"shapeless" -> List(JVMPlatform, JSPlatform, NativePlatform)
)
val moduleCrossScalaVersionsMatrix: (String, Platform) => List[String] = {
case ("benchmark" | "eval" | "pureconfig" | "scalaz" | "scodec" | "shapeless", _) =>
List(Scala_2_12, Scala_2_13)
case _ =>
List(Scala_2_12, Scala_2_13, Scala_3)
}
def allSubprojectsOf(
platform: sbtcrossproject.Platform,
scalaVersions: Set[String] = Set.empty
): List[String] =
moduleCrossPlatformMatrix
.collect { case (prj, platforms) if platforms.contains(platform) => prj }
.filter(prj => scalaVersions.subsetOf(moduleCrossScalaVersionsMatrix(prj, platform).toSet))
.map(_ + platform.sbtSuffix)
.toList
.sorted
val allSubprojectsJVM = allSubprojectsOf(JVMPlatform)
val allSubprojectsJVM30 = allSubprojectsOf(JVMPlatform, Set(Scala_3))
val allSubprojectsJS = allSubprojectsOf(JSPlatform)
val allSubprojectsJS30 = allSubprojectsOf(JSPlatform, Set(Scala_3))
val allSubprojectsNative = allSubprojectsOf(NativePlatform)
val allSubprojectsNative30 = allSubprojectsOf(NativePlatform, Set(Scala_3))
/// sbt-github-actions configuration
ThisBuild / crossScalaVersions := Seq(Scala_2_12, Scala_2_13, Scala_3)
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches := Seq(
RefPredicate.Equals(Ref.Branch("master")),
RefPredicate.StartsWith(Ref.Tag("v"))
)
ThisBuild / githubWorkflowPublish := Seq(
WorkflowStep.Run(
List("sbt ci-release"),
name = Some("Publish JARs"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
)
)
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec(Temurin, "8"))
ThisBuild / githubWorkflowBuild :=
Seq(
WorkflowStep.Sbt(
List("validateJVM", "validateJS", "validateNative"),
name = Some("Build project (Scala 2)"),
cond = Some(s"matrix.scala == '$Scala_2_12' || matrix.scala == '$Scala_2_13'")
),
WorkflowStep.Sbt(
List("validateJVM30", "validateJS30", "validateNative30"),
name = Some("Build project (Scala 3)"),
cond = Some(s"matrix.scala == '$Scala_3'")
),
WorkflowStep.Use(UseRef.Public("codecov", "codecov-action", "v1"), name = Some("Codecov"))
)
/// projects
lazy val root = project
.in(file("."))
.aggregate(benchmark, docs)
.aggregate(allSubprojectsJVM.map(LocalProject): _*)
.aggregate(allSubprojectsJS.map(LocalProject): _*)
.aggregate(allSubprojectsNative.map(LocalProject): _*)
.disablePlugins(MimaPlugin)
.settings(commonSettings)
.settings(noPublishSettings)
.settings(
crossScalaVersions := Nil,
console := (coreJVM / Compile / console).value,
Test / console := (coreJVM / Test / console).value,
ThisBuild / Test / parallelExecution := false
)
lazy val benchmark = project
.configure(moduleConfig("benchmark"))
.dependsOn(coreJVM)
.enablePlugins(JmhPlugin)
.disablePlugins(MimaPlugin)
.settings(noPublishSettings)
lazy val cats = myCrossProject("cats")
.dependsOn(core % "compile->compile;test->test", scalacheck % Test)
.settings(
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % catsVersion,
"org.typelevel" %%% "cats-laws" % catsVersion % Test,
"org.typelevel" %%% "discipline-scalatest" % "2.2.0" % Test
),
initialCommands += s"""
import $rootPkg.cats._
"""
)
lazy val catsJVM = cats.jvm
lazy val catsJS = cats.js
lazy val isScala3Setting = Def.setting {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => true
case _ => false
}
}
lazy val core = myCrossProject("core")
.enablePlugins(BuildInfoPlugin)
.settings(moduleName := projectName)
.settings(
libraryDependencies ++= {
macroParadise(Compile).value ++ (
if (isScala3Setting.value)
Seq()
else
Seq(
scalaOrganization.value % "scala-reflect" % scalaVersion.value,
scalaOrganization.value % "scala-compiler" % scalaVersion.value
)
) ++ Seq(
("com.chuusai" %%% "shapeless" % shapelessVersion).cross(CrossVersion.for3Use2_13),
"org.scalacheck" %%% "scalacheck" % scalaCheckVersion % Test
)
},
initialCommands += s"""
import shapeless.tag.@@
""",
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoPackage := s"$rootPkg.internal"
)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val docs = project
.configure(moduleConfig("docs"))
.dependsOn(coreJVM)
.disablePlugins(MimaPlugin)
.settings(noPublishSettings)
lazy val eval = myCrossProject("eval")
.dependsOn(core % "compile->compile;test->test")
.settings(
libraryDependencies += scalaOrganization.value % "scala-compiler" % scalaVersion.value,
initialCommands += s"""
import $rootPkg.eval._
"""
)
lazy val evalJVM = eval.jvm
lazy val jsonpath = myCrossProject("jsonpath")
.dependsOn(core % "compile->compile;test->test")
.settings(
libraryDependencies ++= macroParadise(Test).value ++ Seq(
"com.jayway.jsonpath" % "json-path" % jsonpathVersion
)
)
lazy val jsonpathJVM = jsonpath.jvm
lazy val pureconfig = myCrossProject("pureconfig")
.dependsOn(core % "compile->compile;test->test")
.settings(
libraryDependencies ++= macroParadise(Test).value ++ Seq(
"com.github.pureconfig" %% "pureconfig-core" % pureconfigVersion,
"com.github.pureconfig" %% "pureconfig-generic" % pureconfigVersion % Test
)
)
lazy val pureconfigJVM = pureconfig.jvm
lazy val scalacheck = myCrossProject("scalacheck")
.dependsOn(core)
.settings(
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion,
initialCommands += s"""
import org.scalacheck.Arbitrary
"""
)
lazy val scalacheckJVM = scalacheck.jvm
lazy val scalacheckJS = scalacheck.js
lazy val scalaz = myCrossProject("scalaz")
.dependsOn(core % "compile->compile;test->test")
.settings(
libraryDependencies += "org.scalaz" %%% "scalaz-core" % scalazVersion,
initialCommands += s"""
import $rootPkg.scalaz._
import $rootPkg.scalaz.auto._
import _root_.scalaz.@@
"""
)
lazy val scalazJVM = scalaz.jvm
lazy val scodec = myCrossProject("scodec")
.dependsOn(core % "compile->compile;test->test")
.settings(
libraryDependencies ++= macroParadise(Test).value ++ Seq(
"org.scodec" %%% "scodec-core" % scodecVersion
),
initialCommands += s"""
import $rootPkg.scodec.predicates.byteVector._
import _root_.scodec.bits.ByteVector
"""
)
lazy val scodecJVM = scodec.jvm
lazy val scodecJS = scodec.js
lazy val scopt = myCrossProject("scopt")
.dependsOn(core % "compile->compile;test->test")
.settings(
libraryDependencies ++= macroParadise(Test).value ++ Seq(
"com.github.scopt" %%% "scopt" % scoptVersion
)
)
lazy val scoptJVM = scopt.jvm
lazy val shapeless = myCrossProject("shapeless")
.dependsOn(core % "compile->compile;test->test")
.settings(
initialCommands += s"""
import $rootPkg.shapeless._
"""
)
lazy val shapelessJVM = shapeless.jvm
lazy val shapelessJS = shapeless.js
/// settings
lazy val commonSettings = Def.settings(
compileSettings,
metadataSettings,
scaladocSettings,
initialCommands := s"""
import $rootPkg._
import $rootPkg.api._
import $rootPkg.api.Inference.==>
import $rootPkg.api.RefType.ops._
import $rootPkg.auto._
import $rootPkg.predicates.all._
import $rootPkg.types.all._
import shapeless.{ ::, HList, HNil }
import shapeless.nat._
"""
)
def myCrossProject(name: String): CrossProject =
CrossProject(name, file(name))(moduleCrossPlatformMatrix(name): _*)
.configureCross(moduleCrossConfig(name))
def moduleConfig(name: String): Project => Project =
_.in(file(s"modules/$name"))
.settings(moduleName := s"$projectName-$name")
.settings(commonSettings)
.settings(
scalaVersion := Scala_2_13,
crossScalaVersions := moduleCrossScalaVersionsMatrix(name, JVMPlatform)
)
def moduleCrossConfig(name: String, module: String): CrossProject => CrossProject = {
val transform = (_: CrossProject)
.in(file(s"modules/$name"))
.settings(moduleName := s"$projectName-$module")
.settings(moduleCrossSettings)
moduleCrossPlatformMatrix(name).foldRight(transform) { case (platform, t) =>
platform match {
case JVMPlatform => t.andThen(_.jvmSettings(moduleJvmSettings(module)))
case JSPlatform => t.andThen(_.jsSettings(moduleJsSettings(module)))
case NativePlatform => t.andThen(_.nativeSettings(moduleNativeSettings(module)))
}
}
}
def moduleCrossConfig(name: String): CrossProject => CrossProject =
moduleCrossConfig(name, name)
lazy val moduleCrossSettings = Def.settings(
commonSettings
)
def moduleJvmSettings(name: String): Seq[Def.Setting[_]] =
Def.settings(
scalaVersion := Scala_2_13,
javaOptions ++= Seq("-Duser.language=en"),
Test / fork := true,
crossScalaVersions := moduleCrossScalaVersionsMatrix(name, JVMPlatform),
mimaPreviousArtifacts := {
val hasPredecessor = !unreleasedModules.value.contains(moduleName.value)
bincompatVersions.value
.get(scalaBinaryVersion.value)
.filter(_ => hasPredecessor && publishArtifact.value)
.fold(Set.empty[ModuleID])(_.map(v => groupId %% moduleName.value % v))
},
mimaBinaryIssueFilters ++= {
import com.typesafe.tools.mima.core._
import com.typesafe.tools.mima.core.ProblemFilters.exclude
Seq(
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Max.findValid"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Min.findValid")
)
}
)
def moduleJsSettings(name: String): Seq[Def.Setting[_]] =
Def.settings(
scalaVersion := Scala_2_13,
crossScalaVersions := moduleCrossScalaVersionsMatrix(name, JSPlatform),
doctestGenTests := Seq.empty,
mimaFailOnNoPrevious := false,
coverageEnabled := false,
scalacOptions += {
val tagOrHash =
if (!isSnapshot.value) s"v${version.value}"
else git.gitHeadCommit.value.getOrElse("master")
val local = (LocalRootProject / baseDirectory).value.toURI.toString
val remote = s"https://raw.githubusercontent.com/$gitHubOwner/$projectName/$tagOrHash/"
val opt = if (isScala3Setting.value) "-scalajs-mapSourceURI" else "-P:scalajs:mapSourceURI"
s"$opt:$local->$remote"
}
)
def moduleNativeSettings(name: String): Seq[Def.Setting[_]] =
Def.settings(
crossScalaVersions := moduleCrossScalaVersionsMatrix(name, NativePlatform),
doctestGenTests := Seq.empty,
mimaFailOnNoPrevious := false,
coverageEnabled := false
)
lazy val metadataSettings = Def.settings(
name := projectName,
description := "Simple refinement types for Scala",
organization := groupId,
homepage := Some(url(s"https://github.com/$gitHubOwner/$projectName")),
startYear := Some(2015),
licenses := Seq("MIT" -> url("http://opensource.org/licenses/MIT")),
scmInfo := Some(ScmInfo(homepage.value.get, s"scm:git:$gitPubUrl", Some(s"scm:git:$gitDevUrl"))),
developers := List(
Developer(
id = "fthomas",
name = "Frank S. Thomas",
email = "",
url("https://github.com/fthomas")
)
)
)
lazy val compileSettings = Def.settings(
scalacOptions ++= Seq(
// "-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-language:existentials,experimental.macros,higherKinds,implicitConversions",
"-unchecked"
),
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, minor)) if minor >= 12 =>
Seq(
"-Xfatal-warnings",
"-Xlint:-unused,_",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Ywarn-unused:implicits",
"-Ywarn-unused:imports"
// "-Ywarn-unused:locals",
// "-Ywarn-unused:params",
// "-Ywarn-unused:patvars"
// "-Ywarn-unused:privates"
)
case _ => Seq.empty
}
},
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, minor)) if minor >= 13 =>
Seq("-Xlint:-byname-implicit")
case _ => Seq.empty
}
},
Compile / console / scalacOptions -= "-Ywarn-unused:imports",
Test / console / scalacOptions := (Compile / console / scalacOptions).value,
Seq(Compile, Test).map { config =>
(config / unmanagedSourceDirectories) ++= {
(config / unmanagedSourceDirectories).value.flatMap { dir: File =>
if (dir.getName != "scala") Seq(dir)
else
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => Seq(file(dir.getPath + "-3.0-"))
case Some((2, 13)) => Seq(file(dir.getPath + "-3.0-"))
case Some((0, _)) => Seq(file(dir.getPath + "-3.0+"))
case Some((3, _)) => Seq(file(dir.getPath + "-3.0+"))
case other => sys.error(s"unmanagedSourceDirectories for scalaVersion $other not set")
}
}
}
}
)
lazy val scaladocSettings = Def.settings(
Compile / doc / sources := {
val result = (Compile / doc / sources).value
if (isScala3Setting.value) Seq.empty else result
},
Compile / doc / scalacOptions ++= {
val tag = s"v${version.value}"
val tree = if (isSnapshot.value) "master" else tag
Seq(
// "-diagrams",
"-diagrams-debug",
"-doc-source-url",
s"${scmInfo.value.get.browseUrl}/blob/$tree€{FILE_PATH}.scala",
"-sourcepath",
(LocalRootProject / baseDirectory).value.getAbsolutePath
)
},
autoAPIMappings := true,
apiURL := {
val binaryScalaVersion = CrossVersion.binaryScalaVersion(scalaVersion.value)
val refinedVersion = if (isSnapshot.value) latestVersion.value else version.value
val indexHtml = rootPkg.replace('.', '/') + "/index.html"
Some(
url(
s"https://static.javadoc.io/$groupId/${moduleName.value}_$binaryScalaVersion/$refinedVersion/$indexHtml"
)
)
}
)
lazy val noPublishSettings = Def.settings(
publish / skip := true
)
/// commands
def addCommandsAlias(name: String, cmds: Seq[String]): Seq[Def.Setting[State => State]] =
addCommandAlias(name, cmds.mkString(";", ";", ""))
addCommandsAlias(
"fmt",
Seq(
"scalafmtAll",
"scalafmtSbt"
)
)
addCommandsAlias(
"fmtCheck",
Seq(
"scalafmtCheckAll",
"scalafmtSbtCheck"
)
)
addCommandsAlias("testNative", allSubprojectsNative.map(_ + "/test"))
addCommandsAlias("testJS", allSubprojectsJS.map(_ + "/test"))
addCommandsAlias("testJVM", allSubprojectsJVM.map(_ + "/test"))
addCommandsAlias("testNative30", allSubprojectsNative30.map(_ + "/test"))
addCommandsAlias("testJS30", allSubprojectsJS30.map(_ + "/test"))
addCommandsAlias("testJVM30", allSubprojectsJVM30.map(_ + "/test"))
addCommandsAlias(
"validateJVM",
Seq(
"clean",
"fmtCheck",
"coverage",
"mimaReportBinaryIssues",
"testJVM",
"coverageReport",
"doc",
"package",
"packageSrc"
)
)
addCommandsAlias(
"validateJS",
Seq(
"testJS"
)
)
addCommandsAlias(
"validateNative",
Seq(
"testNative"
)
)
addCommandsAlias(
"validateJVM30",
Seq(
"clean",
"testJVM30"
)
)
addCommandsAlias(
"validateJS30",
Seq(
"testJS30"
)
)
addCommandsAlias(
"validateNative30",
Seq(
"testNative30"
)
)