@@ -136,6 +136,11 @@ object Build {
136
136
137
137
val fetchScalaJSSource = taskKey[File ](" Fetch the sources of Scala.js" )
138
138
139
+ // Scala3doc specific tasks
140
+ val buildDokkaApi = taskKey[File ](" Compile dokka wrapper and put jar in lib" )
141
+ val generateSelfDocumentation = taskKey[Unit ](" Generate example documentation" )
142
+ val generateDottyLibDocumentation = taskKey[Unit ](" Generate documentation for dotty lib" )
143
+
139
144
lazy val SourceDeps = config(" sourcedeps" )
140
145
141
146
// Settings shared by the build (scoped in ThisBuild). Used in build.sbt
@@ -221,11 +226,6 @@ object Build {
221
226
resourceDirectory in Compile := baseDirectory.value / " resources" ,
222
227
resourceDirectory in Test := baseDirectory.value / " test-resources" ,
223
228
224
- // Disable scaladoc generation, it's way too slow and we'll replace it
225
- // by dottydoc anyway. We still publish an empty -javadoc.jar to make
226
- // sonatype happy.
227
- sources in (Compile , doc) := Seq (),
228
-
229
229
// Prevent sbt from rewriting our dependencies
230
230
scalaModuleInfo ~= (_.map(_.withOverrideScalaVersion(false ))),
231
231
@@ -236,6 +236,12 @@ object Build {
236
236
sourcesInBase := false ,
237
237
)
238
238
239
+ lazy val disableDocSetting =
240
+ // Disable scaladoc generation, it's way too slow and we'll replace it
241
+ // by dottydoc anyway. We still publish an empty -javadoc.jar to make
242
+ // sonatype happy.
243
+ sources in (Compile , doc) := Seq ()
244
+
239
245
// Settings used for projects compiled only with Java
240
246
lazy val commonJavaSettings = commonSettings ++ Seq (
241
247
version := dottyVersion,
@@ -244,7 +250,9 @@ object Build {
244
250
crossPaths := false ,
245
251
// Do not depend on the Scala library
246
252
autoScalaLibrary := false ,
247
- excludeFromIDE := true
253
+ excludeFromIDE := true ,
254
+
255
+ disableDocSetting,
248
256
)
249
257
250
258
// Settings used when compiling dotty (both non-bootstrapped and bootstrapped)
@@ -258,6 +266,8 @@ object Build {
258
266
moduleName ~= { _.stripSuffix(" -scala2" ) },
259
267
version := dottyVersion,
260
268
target := baseDirectory.value / " .." / " out" / " scala-2" / name.value,
269
+
270
+ disableDocSetting,
261
271
)
262
272
263
273
// Settings used when compiling dotty with the reference compiler
@@ -267,10 +277,17 @@ object Build {
267
277
version := dottyNonBootstrappedVersion,
268
278
scalaVersion := referenceVersion,
269
279
excludeFromIDE := true ,
280
+
281
+ disableDocSetting,
270
282
)
271
283
272
284
// Settings used when compiling dotty with a non-bootstrapped dotty
273
- lazy val commonBootstrappedSettings = commonDottySettings ++ Seq (
285
+ lazy val commonBootstrappedSettings = commonBootstrappedSettings0 ++ Seq (
286
+ // sbt-dotty defines `scalaInstance in doc` so we need to override it manually
287
+ scalaInstance in doc := scalaInstance.value,
288
+ disableDocSetting,
289
+ )
290
+ lazy val commonBootstrappedSettings0 = commonDottySettings ++ Seq (
274
291
unmanagedSourceDirectories in Compile += baseDirectory.value / " src-bootstrapped" ,
275
292
276
293
version := dottyVersion,
@@ -326,8 +343,6 @@ object Build {
326
343
allJars
327
344
)
328
345
},
329
- // sbt-dotty defines `scalaInstance in doc` so we need to override it manually
330
- scalaInstance in doc := scalaInstance.value,
331
346
)
332
347
333
348
lazy val commonBenchmarkSettings = Seq (
@@ -1153,6 +1168,9 @@ object Build {
1153
1168
lazy val `scala3-bench-bootstrapped` = project.in(file(" bench" )).asDottyBench(Bootstrapped )
1154
1169
lazy val `scala3-bench-run` = project.in(file(" bench-run" )).asDottyBench(Bootstrapped )
1155
1170
1171
+ lazy val `scala3doc` = project.in(file(" scala3doc" )).asScala3doc
1172
+ lazy val `scala3doc-example-project` = project.in(file(" scala3doc-example-project" )).asDocExampleProject
1173
+
1156
1174
// sbt plugin to use Dotty in your own build, see
1157
1175
// https://github.com/lampepfl/scala3-example-project for usage.
1158
1176
lazy val `sbt-dotty` = project.in(file(" sbt-dotty" )).
@@ -1192,6 +1210,7 @@ object Build {
1192
1210
publishLocal in `scala3-staging`,
1193
1211
publishLocal in `scala3-tasty-inspector`,
1194
1212
publishLocal in `scala3-doc-bootstrapped`,
1213
+ publishLocal in `scala3doc`,
1195
1214
publishLocal in `scala3-bootstrapped` // Needed because sbt currently hardcodes the dotty artifact
1196
1215
).evaluated
1197
1216
)
@@ -1392,8 +1411,7 @@ object Build {
1392
1411
// FIXME: we do not aggregate `bin` because its tests delete jars, thus breaking other tests
1393
1412
def asDottyRoot (implicit mode : Mode ): Project = project.withCommonSettings.
1394
1413
aggregate(`scala3-interfaces`, dottyLibrary, dottyCompiler, tastyCore, dottyDoc, `scala3-sbt-bridge`).
1395
- bootstrappedAggregate(`scala3-language-server`, `scala3-staging`, `scala3-tasty-inspector`,
1396
- `scala3-library-bootstrappedJS`).
1414
+ bootstrappedAggregate(`scala3-language-server`, `scala3-staging`, `scala3-tasty-inspector`, `scala3-library-bootstrappedJS`, scala3doc).
1397
1415
dependsOn(tastyCore).
1398
1416
dependsOn(dottyCompiler).
1399
1417
dependsOn(dottyLibrary).
@@ -1440,6 +1458,129 @@ object Build {
1440
1458
settings(commonBenchmarkSettings).
1441
1459
enablePlugins(JmhPlugin )
1442
1460
1461
+ def asScala3doc : Project = {
1462
+ val dokkaVersion = " 1.4.10.2"
1463
+ val kotlinxVersion = " 0.7.2" // upgrade when upgrading dokka
1464
+ val flexmarkVersion = " 0.42.12"
1465
+ val jacksonVersion = " 2.9.8"
1466
+ val scalaTagsVersion = " 0.9.1"
1467
+ val dokkaSiteVersion = " 0.1.9"
1468
+
1469
+ project.
1470
+ settings(commonBootstrappedSettings).
1471
+ dependsOn(`scala3-compiler-bootstrapped`).
1472
+ settings(
1473
+ Compile / scalaSource := baseDirectory.value / " src/main/scala" ,
1474
+ Test / scalaSource := baseDirectory.value / " src/test/scala" ,
1475
+ Compile / resourceDirectory := baseDirectory.value / " src/main/resources" ,
1476
+ Test / resourceDirectory := baseDirectory.value / " src/test/resources" ,
1477
+
1478
+ scalaVersion := dottyVersion,
1479
+ resolvers ++= Seq (
1480
+ Resolver .jcenterRepo,
1481
+ Resolver .bintrayRepo(" kotlin" , " kotlin-dev" ),
1482
+ Resolver .bintrayRepo(" virtuslab" , " dokka" ),
1483
+ ),
1484
+ libraryDependencies ++= Seq (
1485
+ " org.jetbrains.dokka" % " dokka-test-api" % dokkaVersion % " test" ,
1486
+
1487
+ " org.scala-lang" %% " scala3-tasty-inspector" % dottyVersion,
1488
+
1489
+ " org.jetbrains.dokka" % " dokka-base" % dokkaVersion,
1490
+ " org.jetbrains.dokka" % " dokka-core" % dokkaVersion,
1491
+ " org.jetbrains.dokka" % " dokka-test-api" % dokkaVersion,
1492
+ " org.jetbrains.kotlinx" % " kotlinx-html-jvm" % kotlinxVersion,
1493
+ " com.virtuslab.dokka" % " dokka-site" % dokkaSiteVersion,
1494
+
1495
+ " org.scala-sbt" % " io_2.13" % " 1.3.4" ,
1496
+
1497
+ " com.vladsch.flexmark" % " flexmark-all" % flexmarkVersion,
1498
+ " com.lihaoyi" % " scalatags_2.13" % scalaTagsVersion,
1499
+ " nl.big-o" % " liqp" % " 0.6.7" ,
1500
+ " args4j" % " args4j" % " 2.33" ,
1501
+ ),
1502
+
1503
+ run / fork := true ,
1504
+ Test / fork := true ,
1505
+ Test / parallelExecution := false ,
1506
+ Compile / mainClass := Some (" dotty.dokka.Main" ),
1507
+
1508
+ Test / envVars := Map (
1509
+ " scala3doc.classroot" -> (Compile / target/ classDirectory).value.getAbsolutePath.toString,
1510
+ ),
1511
+
1512
+ // hack, we cannot build documentation so we need this to publish locally
1513
+ Compile / packageDoc / publishArtifact := false ,
1514
+
1515
+ generateSelfDocumentation := Def .taskDyn {
1516
+ val classdir = (Compile / target/ classDirectory).value
1517
+ (Compile / run).toTask(s " -o output/self -t ${classdir} -d documentation -n scala3doc -s src/main/scala=https://github.com/lampepfl/scala3doc/tree/master/src/main/scala#L " )
1518
+ }.value,
1519
+
1520
+ generateDottyLibDocumentation := Def .taskDyn {
1521
+ val dottyLib = (Compile / fullClasspath).value.find{ a =>
1522
+ val info = a.get(moduleID.key)
1523
+ info.nonEmpty &&
1524
+ info.get.organization == " ch.epfl.lamp" &&
1525
+ info.get.name.startsWith(" dotty-library" )
1526
+ }
1527
+ if (dottyLib.isEmpty) Def .task {
1528
+ streams.value.log.error(" Dotty lib wasn't found" )
1529
+ } else Def .task {
1530
+ (Compile / run).toTask(s " -o output/stdLib -t ${dottyLib.get.data} -d dotty-docs/docs -n dotty-lib -s library/src=https://github.com/lampepfl/dotty/tree/master/library/src#L " ).value
1531
+ }
1532
+ }.value,
1533
+
1534
+ )
1535
+ }
1536
+
1537
+ def asDocExampleProject : Project = project.
1538
+ settings(commonBootstrappedSettings0).
1539
+ dependsOn(`scala3-compiler-bootstrapped`).
1540
+ settings(
1541
+ Compile / scalaSource := baseDirectory.value / " src/main/scala" ,
1542
+ Test / scalaSource := baseDirectory.value / " src/test/scala" ,
1543
+ Compile / resourceDirectory := baseDirectory.value / " src/main/resources" ,
1544
+ Test / resourceDirectory := baseDirectory.value / " src/test/resources" ,
1545
+
1546
+ name := " scala3doc-example-project" ,
1547
+ description := " Example SBT project that is documented using Scala3doc" ,
1548
+ version := " 0.1.0-SNAPSHOT" ,
1549
+ scalaVersion := dottyVersion,
1550
+
1551
+ useScala3doc := true ,
1552
+ scala3docOptions ++= Seq (" --name" , " example-project" ),
1553
+ Compile / doc / target := file(" out/doc/example-project" ),
1554
+
1555
+ // we cannot set
1556
+ doc/ scalaInstance := {
1557
+ val externalNonBootstrappedDeps = externalDependencyClasspath.in(`scala3doc`, Compile ).value
1558
+ val scalaLibrary = findArtifact(externalNonBootstrappedDeps, " scala-library" )
1559
+
1560
+ // IMPORTANT: We need to use actual jars to form the ScalaInstance and not
1561
+ // just directories containing classfiles because sbt maintains a cache of
1562
+ // compiler instances. This cache is invalidated based on timestamps
1563
+ // however this is only implemented on jars, directories are never
1564
+ // invalidated.
1565
+ val tastyCore = packageBin.in(`tasty-core`, Compile ).value
1566
+ val dottyLibrary = packageBin.in(`scala3-library-bootstrapped`, Compile ).value
1567
+ val dottyInterfaces = packageBin.in(`scala3-interfaces`, Compile ).value
1568
+ val dottyCompiler = packageBin.in(`scala3-compiler-bootstrapped`, Compile ).value
1569
+ val doctool = packageBin.in(`scala3doc`, Compile ).value
1570
+
1571
+ val allJars = Seq (tastyCore, dottyLibrary, dottyInterfaces, dottyCompiler, doctool) ++ externalNonBootstrappedDeps.map(_.data)
1572
+
1573
+ makeScalaInstance(
1574
+ state.value,
1575
+ scalaVersion.value,
1576
+ scalaLibrary,
1577
+ dottyLibrary,
1578
+ dottyCompiler,
1579
+ allJars
1580
+ )
1581
+ },
1582
+ )
1583
+
1443
1584
def asDist (implicit mode : Mode ): Project = project.
1444
1585
enablePlugins(PackPlugin ).
1445
1586
withCommonSettings.
0 commit comments