forked from slick/slick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
413 lines (375 loc) · 14.5 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
import com.jsuereth.sbtpgp.PgpKeys
val testAll = taskKey[Unit]("Run all tests")
val cleanCompileTimeTests =
taskKey[Unit]("Delete files used for compile-time tests which should be recompiled every time.")
/* Test Configuration for running tests on doc sources */
val DocTest = config("doctest").extend(Test)
val tagTestGroupOther = Tags.Tag("test-group-other")
Global / concurrentRestrictions :=
List(
Tags.limit(Tags.ForkedTestGroup, 4),
Tags.limit(tagTestGroupOther, 1),
Tags.limit(Tags.Tag("test-group-DB2"), 1),
Tags.limit(Tags.Tag("test-group-Postgres"), 1),
Tags.exclusiveGroup(tagTestGroupOther),
Tags.exclusiveGroup(Tags.Clean)
)
inThisBuild(
Seq(
organizationName := "Typesafe",
organization := "com.typesafe.slick",
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
homepage := Some(url("https://scala-slick.org")),
startYear := Some(2008),
licenses += ("Two-clause BSD-style license", url("https://github.com/slick/slick/blob/main/LICENSE.txt")),
developers :=
List(
Developer("szeiger", "Stefan Zeiger", "", url("http://szeiger.de")),
Developer("hvesalai", "Heikki Vesalainen", "", url("https://github.com/hvesalai/"))
),
scmInfo := Some(ScmInfo(url("https://github.com/slick/slick"), "scm:git:[email protected]:slick/slick.git"))
)
)
def scaladocSourceUrl(dir: String) =
Compile / doc / scalacOptions ++= {
val ref = Versioning.currentRef(baseDirectory.value)
Seq(
"-sourcepath",
(ThisBuild / baseDirectory).value.getAbsolutePath,
"-doc-source-url",
s"https://github.com/slick/slick/blob/${ref}€{FILE_PATH}.scala"
)
}
val scala2InlineSettings = Def.setting {
if (insideCI.value) {
val log = sLog.value
log.info(s"Running in CI, enabling Scala2 optimizer for module: ${name.value}")
List(
"-opt:l:inline",
// Code in slick.compat is private and is also not going to change so its safe to inline within this project. Remove
// when Scala 2.12 support is dropped along with slick.compat
"-opt-inline-from:slick.compat.**",
"-opt-inline-from:<sources>"
)
} else List.empty
}
def slickScalacOptions = Seq(
scalacOptions ++=
List(
"-deprecation",
"-feature",
"-unchecked",
"-Wconf:cat=unused-imports&src=src_managed/.*:silent"
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) =>
List("-Ywarn-unused:imports", "-language:higherKinds", "-Xsource:3") ++ scala2InlineSettings.value
case Some((2, 13)) =>
List(
"-Xsource:3",
"-Wunused:imports",
"-Wconf:cat=unused-imports&origin=scala\\.collection\\.compat\\._:s",
"-Wconf:cat=deprecation&origin=scala\\.math\\.Numeric\\.signum:s"
) ++ scala2InlineSettings.value
case Some((3, _)) =>
List("-source:3.0-migration")
case _ =>
Nil
})
)
def slickGeneralSettings =
Seq(
Test / publishArtifact := false,
pomIncludeRepository := { _ => false },
makePomConfiguration ~= {
_.withConfigurations(Vector(Compile, Runtime, Optional))
},
sonatypeProfileName := "com.typesafe.slick",
Compile / doc / scalacOptions ++= Seq(
"-doc-title", name.value,
"-doc-version", version.value,
"-doc-footer", "Slick is developed by Typesafe and EPFL Lausanne.",
"-implicits",
"-diagrams", // requires graphviz
"-groups"
),
logBuffered := false
) ++ slickScalacOptions
// add a scala 2 compiler dependency unless a local scala is in use
def compilerDependencySetting(config: String) =
libraryDependencies ++=
(if (sys.props("scala.home.local") == null && scalaVersion.value.startsWith("2."))
List("org.scala-lang" % "scala-compiler" % scalaVersion.value % config)
else
Nil)
def extTarget(extName: String): Seq[Setting[File]] =
sys.props("slick.build.target") match {
case null => Seq.empty
case path => Seq(target := file(path + "/" + extName))
}
def commonTestResourcesSetting =
Test / unmanagedResourceDirectories +=
(LocalProject("root") / baseDirectory).value / "common-test-resources"
def sampleSettings = Seq(
Compile / unmanagedClasspath :=
Attributed.blank(baseDirectory.value.getParentFile / "resources") +: (Compile / unmanagedClasspath).value
)
ThisBuild / crossScalaVersions := Dependencies.scalaVersions
ThisBuild / scalaVersion := Dependencies.scala213
ThisBuild / versionScheme := Some("pvp")
ThisBuild / versionPolicyIntention := Versioning.BumpMajor
ThisBuild / versionPolicyIgnoredInternalDependencyVersions := Some("^\\d+\\.\\d+\\.\\d+-pre\\.\\d+\\.\\w+\\.dirty".r)
val buildCapabilitiesTable = taskKey[File]("Build the capabilities.csv table for the documentation")
val buildCompatReport = taskKey[File]("Build the compatibility report")
val writeVersionToGitHubOutput = taskKey[Unit]("Write the version to github output")
val writeCompatReportToGitHubOutput = taskKey[Unit]("Write the compatibility report to github output")
val docDir = settingKey[File]("Base directory for documentation")
ThisBuild / docDir := (site / baseDirectory).value
lazy val slickCompatCollections =
project
.in(file("slick-compat-collections"))
.settings(
slickScalacOptions,
// Do not publish this artifact
publish / skip := true,
Compile / doc / sources := Seq.empty,
// Adds a `src/main/scala-2.13+` source directory for code shared
// between Scala 2.13 and Scala 3
Compile / unmanagedSourceDirectories ++= {
val sourceDir = (Compile / sourceDirectory).value
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, n)) => Seq(sourceDir / "scala-2.13+")
case Some((2, n)) if n >= 13 => Seq(sourceDir / "scala-2.13+")
case _ => Nil
}
},
)
def slickCollectionsCompatSettings = Seq(
libraryDependencies ++= Dependencies.scalaCollectionCompat.value,
// So that compiled from slickCompatCollections sbt module appear in slick
(Compile / packageBin / mappings) ++= (slickCompatCollections / Compile / packageBin / mappings).value,
(Compile / packageSrc / mappings) ++= (slickCompatCollections / Compile / packageSrc / mappings).value,
projectDependencies := projectDependencies.value.filterNot(_.name.equalsIgnoreCase("slickcompatcollections")),
scalacOptions ++= scala2InlineSettings.value
)
lazy val slick =
project
.enablePlugins(MimaPlugin)
.settings(
slickGeneralSettings,
compilerDependencySetting("provided"),
FMPP.preprocessorSettings,
extTarget("slick"),
slickCollectionsCompatSettings,
name := "Slick",
description := "Scala Language-Integrated Connection Kit",
libraryDependencies ++= Dependencies.mainDependencies,
scaladocSourceUrl("slick"),
Compile / doc / scalacOptions ++= Seq(
"-doc-root-content", "scaladoc-root.txt"
),
// suppress test status output
test := {},
testOnly := {}
).dependsOn(slickCompatCollections)
lazy val testkit =
project
.in(file("slick-testkit"))
.configs(DocTest)
.dependsOn(slick, codegen % s"compile->compile;${TypeProviders.TypeProvidersConfig.name}->test", hikaricp)
.settings(
slickGeneralSettings,
compilerDependencySetting(Provided.name),
compilerDependencySetting(TypeProviders.TypeProvidersConfig.name),
inConfig(DocTest)(Defaults.testSettings),
TypeProviders.codegenSettings,
extTarget("testkit"),
name := "Slick-TestKit",
description := "Test Kit for Slick (Scala Language-Integrated Connection Kit)",
scaladocSourceUrl("slick-testkit"),
testOptions +=
Tests.Argument(
Some(TestFrameworks.JUnit),
List("-q", "-v", "-s", "-a", "-Djava.awt.headless=true") ++
(if (sys.env.get("GITHUB_ACTIONS").contains("true"))
Some("--run-listener=com.typesafe.slick.testkit.util.GitHubActionsRunListener")
else
None)
),
//scalacOptions in Compile += "-Yreify-copypaste",
libraryDependencies ++=
Dependencies.junit ++:
(Dependencies.reactiveStreamsTCK % Test) +:
(Dependencies.logback +: Dependencies.testDBs).map(_ % Test) ++:
(Dependencies.logback +: Dependencies.testDBs).map(_ % TypeProviders.TypeProvidersConfig),
run / fork := true,
//connectInput in run := true,
run / javaOptions += "-Dslick.ansiDump=true",
//javaOptions in run += "-verbose:gc",
// Delete classes in "compile" packages after compiling. (Currently only slick.test.compile.NestedShapeTest)
// These are used for compile-time tests and should be recompiled every time.
Test / cleanCompileTimeTests := {
val products = fileTreeView.value.list(
(Test / classDirectory).value.toGlob / ** / "compile" / *
).map(x => x._1.toFile)
streams.value.log.info(s"Deleting $products")
IO.delete(products)
},
(Test / cleanCompileTimeTests) := ((Test / cleanCompileTimeTests) triggeredBy (Test / compile)).value,
Test / testGrouping := {
val re = """slick\.test\.profile\.(.+?)(?:\d\d+)?(?:Disk|Mem|Rownum|SQLJDBC)?Test$""".r
(Test / definedTests).value
.groupBy(_.name match {
case re(name) => name
case _ => "other"
})
.map { case (name, tests) =>
new Tests.Group(name, tests, Tests.SubProcess(ForkOptions()), Seq(Tags.Tag(s"test-group-$name") -> 1))
}
.toSeq
.sortBy(_.name)
},
buildCapabilitiesTable := {
val logger = ConsoleLogger()
val file = (buildCapabilitiesTable / sourceManaged).value / "capabilities.md"
Run.run(
mainClass = "com.typesafe.slick.testkit.util.BuildCapabilitiesTable",
classpath = (Compile / fullClasspath).value.map(_.data),
options = Seq(file.toString),
log = logger
)(runner.value)
.map(_ => file)
.get
},
DocTest / unmanagedSourceDirectories += docDir.value / "code",
DocTest / unmanagedResourceDirectories += docDir.value / "code",
DocTest / parallelExecution := false
)
lazy val codegen =
project
.in(file("slick-codegen"))
.dependsOn(slick)
.settings(
slickGeneralSettings,
extTarget("codegen"),
name := "Slick-CodeGen",
description := "Code Generator for Slick (Scala Language-Integrated Connection Kit)",
scaladocSourceUrl("slick-codegen"),
test := {}, testOnly := {}, // suppress test status output
commonTestResourcesSetting
)
lazy val hikaricp =
project
.in(file("slick-hikaricp"))
.dependsOn(slick)
.settings(
slickGeneralSettings,
extTarget("hikaricp"),
name := "Slick-HikariCP",
description := "HikariCP integration for Slick (Scala Language-Integrated Connection Kit)",
scaladocSourceUrl("slick-hikaricp"),
test := {}, testOnly := {}, // suppress test status output
libraryDependencies += Dependencies.hikariCP.exclude("org.slf4j", "*"),
)
lazy val `reactive-streams-tests` =
project
.dependsOn(testkit)
.settings(
slickGeneralSettings,
name := "Slick-ReactiveStreamsTests",
libraryDependencies += "org.scalatestplus" %% "testng-7-5" % "3.2.17.0",
libraryDependencies ++=
(Dependencies.logback +: Dependencies.testDBs).map(_ % Test),
libraryDependencies += Dependencies.reactiveStreamsTCK,
Test / parallelExecution := false,
commonTestResourcesSetting
)
def writeToGitHubOutput(text: String, logger: Logger) = {
val string = s"result=$text\n"
logger.info(s"Writing to GitHub Actions output file: $string")
IO.append(file(sys.env("GITHUB_OUTPUT")), string)
}
lazy val site: Project =
project
.in(file("doc"))
.enablePlugins(Docs)
.settings(
description := "Scala Slick documentation",
scaladocDirs := Seq(
"api" -> (slick / Compile / doc).value,
"codegen-api" -> (codegen / Compile / doc).value,
"hikaricp-api" -> (hikaricp / Compile / doc).value,
"testkit-api" -> (testkit / Compile / doc).value
),
buildCompatReport := {
val compatReports =
(CompatReport / compatReportMarkdown)
.all(ScopeFilter(inProjects(slick, codegen, hikaricp, testkit)))
.value
val file = (buildCompatReport / target).value / "compat-report.md"
IO.write(
file,
"## Incompatible changes\n\n" +
(if (compatReports.forall(_.trim.isEmpty))
"There are no incompatible changes"
else
compatReports.sorted.mkString("", "\n\n", "\n"))
)
file
},
writeVersionToGitHubOutput := {
writeToGitHubOutput(version.value, streams.value.log)
},
writeCompatReportToGitHubOutput := {
writeToGitHubOutput(buildCompatReport.value.toString, streams.value.log)
},
preprocessDocs := {
val out = (preprocessDocs / target).value
val capabilitiesTableFile = (testkit / buildCapabilitiesTable).value
IO.copyFile(capabilitiesTableFile, out / capabilitiesTableFile.getName)
val compatReportFile = buildCompatReport.value
IO.copyFile(compatReportFile, out / compatReportFile.getName)
preprocessDocs.value
},
(Compile / paradoxMarkdownToHtml / excludeFilter) :=
(Compile / paradoxMarkdownToHtml / excludeFilter).value ||
globFilter("capabilities.md"),
publishArtifact := false,
publish := {},
publishLocal := {},
test := {},
testOnly := {},
versionPolicyPreviousVersions := Nil
)
lazy val root =
project
.in(file("."))
.aggregate(slick, codegen, hikaricp, testkit, site)
.settings(
name := "slick-root",
slickGeneralSettings,
extTarget("root"),
publishArtifact := false,
publish := {},
publishLocal := {},
versionPolicyPreviousVersions := Nil,
PgpKeys.publishSigned := {},
PgpKeys.publishLocalSigned := {},
// suppress test status output
test := {},
testOnly := {},
testAll := {
Def.sequential(
testkit / Test / test,
testkit / DocTest / test,
`reactive-streams-tests` / Test / test,
slick / Compile / packageDoc,
codegen / Compile / packageDoc,
hikaricp / Compile / packageDoc,
testkit / Compile / packageDoc,
slick / versionPolicyCheck,
testkit / versionPolicyCheck,
hikaricp / versionPolicyCheck,
codegen / versionPolicyCheck
).value
}
)