forked from scalameta/mdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
414 lines (386 loc) · 12.2 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
import sbt.librarymanagement.CrossVersion
import scala.collection.mutable
def scala212 = "2.12.13"
def scala212Legacy = "2.12.12"
def scala211 = "2.11.12"
def scala213 = "2.13.4"
def scala3 = List("3.0.0-RC1", "3.0.0-M3", "3.0.0-M2")
def scalajs = "1.3.0"
def scalajsBinaryVersion = "1"
def scalajsDom = "1.1.0"
def isScala2(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2)
def isScala212(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) && v.exists(_._2 == 12)
def isScala211(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) && v.exists(_._2 == 11)
def isScala3(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 3)
val isScala213 = Def.setting {
VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector(">=2.13"))
}
val isScala3 = Def.setting {
// doesn't work well with >= 3.0.0 for `3.0.0-M1`
VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector("<=1.0.0 || >=2.99.0"))
}
val isScalaJs1 = Def.setting {
VersionNumber(scalaJSVersion).matchesSemVer(SemanticSelector(">=1.0.0"))
}
def multiScalaDirectories(projectName: String) =
Def.setting {
val root = baseDirectory.in(ThisBuild).value / projectName
val base = root / "src" / "main"
val result = mutable.ListBuffer.empty[File]
val partialVersion = CrossVersion.partialVersion(scalaVersion.value)
partialVersion.collect { case (major, minor) =>
result += base / s"scala-$major.$minor"
}
result += base / s"scala-${scalaVersion.value}"
if (isScala3.value) {
result += base / "scala-3"
}
if (!isScala3.value) {
result += base / "scala-2"
}
result.toList
}
def crossSetting[A](
scalaVersion: String,
if2: List[A] = Nil,
if3: List[A] = Nil,
if211: List[A] = Nil,
if212: List[A] = Nil
): List[A] =
CrossVersion.partialVersion(scalaVersion) match {
case partialVersion if isScala2(partialVersion) => if2
case partialVersion if isScala3(partialVersion) => if3
case partialVersion if isScala211(partialVersion) => if2 ::: if211
case partialVersion if isScala212(partialVersion) => if2 ::: if212
case _ => Nil
}
inThisBuild(
List(
scalaVersion := scala212,
crossScalaVersions := List(scala212, scala212Legacy, scala211, scala213) ::: scala3,
organization := "org.scalameta",
licenses := Seq(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
),
homepage := Some(url("https://github.com/scalameta/mdoc")),
developers := List(
Developer(
"jvican",
"Jorge Vicente Cantero",
url("https://jvican.github.io/")
),
Developer(
"olafurpg",
"Ólafur Páll Geirsson",
url("https://geirsson.com")
)
),
testFrameworks := List(new TestFramework("munit.Framework")),
resolvers += Resolver.sonatypeRepo("public"),
// faster publishLocal:
publishArtifact.in(packageDoc) := "true" == System.getenv("CI"),
publishArtifact.in(packageSrc) := "true" == System.getenv("CI"),
turbo := true,
useSuperShell := false // overlaps with MUnit test failure reports.
)
)
name := "mdocRoot"
skip in publish := true
crossScalaVersions := Nil
lazy val sharedSettings = List(
scalacOptions ++= crossSetting(
scalaVersion.value,
if2 = List("-target:jvm-1.8", "-Yrangepos", "-deprecation"),
if212 = List("-Xexperimental"),
if211 = List("-Xexperimental"),
if3 = List("-language:implicitConversions", "-Ximport-suggestion-timeout", "0")
)
)
val V = new {
val scalameta = "4.4.9"
val munit = "0.7.22"
val coursier = "1.0.3"
val scalacheck = "1.15.2"
}
val crossVersionLegacy = Def.setting {
CrossVersion.binaryWith(
prefix = "",
suffix = if (scalaVersion.value == scala212Legacy) ".12" else ""
)
}
lazy val pprintVersion = Def.setting {
if (scalaVersion.value.startsWith("2.11")) "0.5.4"
else "0.6.0"
}
lazy val fansiVersion = Def.setting {
if (scalaVersion.value.startsWith("2.11")) "0.2.6"
else "0.2.9"
}
lazy val interfaces = project
.in(file("mdoc-interfaces"))
.settings(
moduleName := "mdoc-interfaces",
autoScalaLibrary := false,
libraryDependencies ++= List(
"io.get-coursier" % "interface" % V.coursier
),
// @note needed to deal with issues with dottyDoc
sources in (Compile, doc) := {
if (isScala3.value) {
Seq.empty
} else {
(sources in (Compile, doc)).value
}
},
crossVersion := CrossVersion.disabled,
javacOptions in (Compile / doc) ++= List(
"-tag",
"implNote:a:Implementation Note:"
)
)
lazy val runtime = project
.settings(
sharedSettings,
moduleName := "mdoc-runtime",
unmanagedSourceDirectories.in(Compile) ++= multiScalaDirectories("runtime").value,
crossVersion := crossVersionLegacy.value,
libraryDependencies ++= crossSetting(
scalaVersion.value,
if2 = List(
"com.lihaoyi" %% "pprint" % pprintVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % Provided
),
if3 = List(
"org.scala-lang" %% "scala3-compiler" % scalaVersion.value
)
)
)
.dependsOn(interfaces)
val excludePprint = ExclusionRule(organization = "com.lihaoyi")
lazy val mdoc = project
.settings(
sharedSettings,
unmanagedSourceDirectories.in(Compile) ++= multiScalaDirectories("mdoc").value,
crossVersion := crossVersionLegacy.value,
moduleName := "mdoc",
mainClass in assembly := Some("mdoc.Main"),
assemblyJarName in assembly := "mdoc.jar",
test in assembly := {},
assemblyMergeStrategy.in(assembly) ~= { old =>
{
case PathList("META-INF", "CHANGES") => MergeStrategy.discard
case x => old(x)
}
},
fork in run := true,
buildInfoPackage := "mdoc.internal",
buildInfoKeys := Seq[BuildInfoKey](
version,
scalaVersion,
scalaBinaryVersion
),
libraryDependencies ++= crossSetting(
scalaVersion.value,
if3 = List(
"org.scala-lang" %% "scala3-compiler" % scalaVersion.value,
("org.scalameta" %% "scalameta" % V.scalameta)
.excludeAll(excludePprint)
.withDottyCompat(scalaVersion.value),
("com.geirsson" %% "metaconfig-typesafe-config" % "0.9.10")
.excludeAll(excludePprint)
.withDottyCompat(scalaVersion.value)
),
if2 = List(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scalameta" %% "scalameta" % V.scalameta,
"com.geirsson" %% "metaconfig-typesafe-config" % "0.9.10",
"com.lihaoyi" %% "fansi" % fansiVersion.value
)
),
libraryDependencies ++= List(
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0",
"io.get-coursier" % "interface" % V.coursier,
"com.vladsch.flexmark" % "flexmark-all" % "0.62.2",
"io.methvin" % "directory-watcher" % "0.12.0",
// live reload
"io.undertow" % "undertow-core" % "2.2.4.Final",
"org.jboss.xnio" % "xnio-nio" % "3.8.4.Final",
"org.slf4j" % "slf4j-api" % "1.7.30"
)
)
.dependsOn(runtime)
.enablePlugins(BuildInfoPlugin)
lazy val testsInput = project
.in(file("tests/input"))
.settings(
sharedSettings,
skip in publish := true
)
def scala212LibraryDependencies(deps: List[ModuleID]) =
List(
libraryDependencies ++= {
if (isScala213.value || isScala3.value) Nil
else deps
}
)
val tests = project
.in(file("tests/tests"))
.settings(
sharedSettings,
skip in publish := true,
libraryDependencies ++= List(
"org.scalameta" %% "munit" % V.munit
),
buildInfoPackage := "tests",
buildInfoKeys := Seq[BuildInfoKey](
scalaVersion,
scalaBinaryVersion
)
)
.enablePlugins(BuildInfoPlugin)
val jsdocs = project
.in(file("tests/jsdocs"))
.settings(
sharedSettings,
skip in publish := true,
crossScalaVersions --= scala3,
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
},
libraryDependencies ++= List(
"org.scala-js" %%% "scalajs-dom" % scalajsDom
),
scalaJSUseMainModuleInitializer := true,
npmDependencies in Compile ++= List(
"ms" -> "2.1.1"
),
webpackBundlingMode := BundlingMode.LibraryOnly()
)
.enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin)
lazy val worksheets = project
.in(file("tests/worksheets"))
.settings(
sharedSettings,
skip in publish := true,
libraryDependencies ++= List(
"org.scalameta" %% "munit" % V.munit % Test
)
)
.dependsOn(mdoc, tests)
lazy val unit = project
.in(file("tests/unit"))
.settings(
sharedSettings,
skip in publish := true,
crossScalaVersions --= scala3,
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3"),
resolvers += Resolver.bintrayRepo("cibotech", "public"),
scala212LibraryDependencies(
List(
"com.cibo" %% "evilplot" % "0.6.3"
)
),
libraryDependencies ++= List(
"co.fs2" %% "fs2-core" % "2.1.0",
"org.scalacheck" %% "scalacheck" % V.scalacheck % Test,
"org.scalameta" %% "munit" % V.munit % Test,
"org.scalameta" %% "testkit" % V.scalameta % Test
),
buildInfoPackage := "tests.cli",
buildInfoKeys := Seq[BuildInfoKey](
"testsInputClassDirectory" -> classDirectory.in(testsInput, Compile).value
),
mdocJS := Some(jsdocs)
)
.dependsOn(mdoc, js, testsInput, tests)
.enablePlugins(BuildInfoPlugin, MdocPlugin)
lazy val plugin = project
.in(file("mdoc-sbt"))
.settings(
sharedSettings,
sbtPlugin := true,
sbtVersion in pluginCrossBuild := "1.0.0",
crossScalaVersions := List(scala212),
moduleName := "sbt-mdoc",
libraryDependencies ++= List(
"org.jsoup" % "jsoup" % "1.12.1",
"org.scalacheck" %% "scalacheck" % V.scalacheck % Test,
"org.scalameta" %% "munit" % V.munit % Test,
"org.scalameta" %% "testkit" % V.scalameta % Test
),
resourceGenerators.in(Compile) += Def.task {
val out =
managedResourceDirectories.in(Compile).value.head / "sbt-mdoc.properties"
val props = new java.util.Properties()
props.put("version", version.value)
props.put("scala212Legacy", scala212Legacy)
IO.write(props, "sbt-mdoc properties", out)
List(out)
},
publishLocal := publishLocal
.dependsOn(
publishLocal in interfaces,
publishLocal in runtime,
publishLocal in mdoc,
publishLocal in js
)
.value,
scriptedBufferLog := false,
scriptedLaunchOpts ++= Seq(
"-Xmx2048M",
s"-Dplugin.version=${version.value}"
)
)
.enablePlugins(ScriptedPlugin)
lazy val js = project
.in(file("mdoc-js"))
.settings(
sharedSettings,
crossVersion := crossVersionLegacy.value,
crossScalaVersions --= scala3,
moduleName := "mdoc-js",
libraryDependencies ++=
Seq(
"org.scala-js" % "scalajs-compiler" % scalajs cross CrossVersion.full,
"org.scala-js" %% "scalajs-linker" % scalajs
)
)
.dependsOn(mdoc)
lazy val docs = project
.in(file("mdoc-docs"))
.settings(
sharedSettings,
moduleName := "mdoc-docs",
crossScalaVersions := List(scala212),
skip in publish :=
!scalaVersion.value.startsWith("2.12") ||
version.in(ThisBuild).value.endsWith("-SNAPSHOT"),
mdocAutoDependency := false,
resolvers += Resolver.bintrayRepo("cibotech", "public"),
libraryDependencies ++= List(
"org.scala-sbt" % "sbt" % sbtVersion.value,
"com.cibo" %% "evilplot" % "0.6.3"
),
watchSources += baseDirectory.in(ThisBuild).value / "docs",
cancelable in Global := true,
MdocPlugin.autoImport.mdoc := run.in(Compile).evaluated,
mdocJS := Some(jsdocs),
mdocJSLibraries := webpack.in(jsdocs, Compile, fullOptJS).value,
mdocVariables := {
val stableVersion: String =
version.value.replaceFirst("\\+.*", "")
Map(
"VERSION" -> stableVersion,
"SCALA_BINARY_VERSION" -> scalaBinaryVersion.value,
"SCALA_VERSION" -> scalaVersion.value,
"SCALAJS_VERSION" -> scalajs,
"SCALAJS_BINARY_VERSION" -> scalajsBinaryVersion,
"SCALAJS_DOM_VERSION" -> scalajsDom
)
}
)
.dependsOn(mdoc, js, plugin)
.enablePlugins(DocusaurusPlugin)