Skip to content

Commit e84ad19

Browse files
committed
Scala3doc is configured in Build.scala
1 parent b195184 commit e84ad19

File tree

2 files changed

+56
-79
lines changed

2 files changed

+56
-79
lines changed

project/Build.scala

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ object Build {
136136

137137
val fetchScalaJSSource = taskKey[File]("Fetch the sources of Scala.js")
138138

139-
val artifactsForScala3Documentation = taskKey[Seq[File]]("Artifacts to be documented by Scala3doc")
140-
141139
lazy val SourceDeps = config("sourcedeps")
142140

143141
// Settings shared by the build (scoped in ThisBuild). Used in build.sbt
@@ -1160,6 +1158,9 @@ object Build {
11601158

11611159
val testcasesOutputDir = taskKey[String]("Root directory where tests classses are generated")
11621160
val testcasesSourceRoot = taskKey[String]("Root directory where tests sources are generated")
1161+
val generateSelfDocumentation = inputKey[Unit]("Generate example documentation")
1162+
val generateScala3Documentation = taskKey[Unit]("Generate documentation for dotty lib")
1163+
val generateTestcasesDocumentation = taskKey[Unit]("Generate documentation for testcases, usefull for debugging tests")
11631164
lazy val `scala3doc` = project.in(file("scala3doc")).asScala3doc
11641165
lazy val `scala3doc-testcases` = project.in(file("scala3doc-testcases")).asScala3docTestcases
11651166

@@ -1450,30 +1451,69 @@ object Build {
14501451
settings(commonBenchmarkSettings).
14511452
enablePlugins(JmhPlugin)
14521453

1453-
def asScala3doc: Project =
1454+
def asScala3doc: Project = {
1455+
def generateDocumentation(targets: String, name: String, outDir: String, params: String = "") = Def.taskDyn {
1456+
val sourceMapping = "=https://github.com/lampepfl/dotty/tree/master#L"
1457+
run.in(Compile).toTask(s""" -o output/$outDir -t $targets -n "$name" -s $sourceMapping $params""")
1458+
}
1459+
14541460
project.settings(commonBootstrappedSettings).
14551461
dependsOn(`scala3-compiler-bootstrapped`).
14561462
dependsOn(`scala3-tasty-inspector`).
14571463
settings(
14581464
resolvers += Resolver.jcenterRepo,
14591465
resolvers += Resolver.bintrayRepo("kotlin", "kotlin-dev"),
14601466
resolvers += Resolver.bintrayRepo("virtuslab", "dokka"),
1461-
artifactsForScala3Documentation := Seq(
1462-
// All projects below will be used to generated documentation for Scala 3
1463-
classDirectory.in(`scala3-interfaces`).in(Compile).value,
1464-
classDirectory.in(`tasty-core`).in(Compile).value,
1465-
classDirectory.in(`scala3-library`).in(Compile).value,
1466-
// TODO this one fails to load using TASTY
1467-
// classDirectory.in(`stdlib-bootstrapped`).in(Compile).value,
1467+
libraryDependencies ++= Seq(
1468+
"org.scala-lang" %% "scala3-tasty-inspector" % scalaVersion.value,
1469+
1470+
"com.virtuslab.dokka" % "dokka-site" % "0.1.9",
1471+
"com.vladsch.flexmark" % "flexmark-all" % "0.42.12",
1472+
"nl.big-o" % "liqp" % "0.6.7",
1473+
"args4j" % "args4j" % "2.33",
1474+
1475+
"org.jetbrains.dokka" % "dokka-test-api" % "1.4.10.2" % "test",
1476+
"com.novocode" % "junit-interface" % "0.11" % "test",
14681477
),
1469-
test.in(Test) := {
1470-
// Test
1471-
compile.in(Compile).in(`scala3doc-testcases`).value
1472-
test.in(Test).value
1473-
},
1478+
test.in(Test) := test.in(Test).dependsOn(compile.in(Compile).in(`scala3doc-testcases`)).value,
14741479
testcasesOutputDir.in(Test) := classDirectory.in(Compile).in(`scala3doc-testcases`).value.getAbsolutePath.toString,
1475-
testcasesSourceRoot.in(Test) := (baseDirectory.in(`scala3doc-testcases`).value / "src").getAbsolutePath.toString
1480+
testcasesSourceRoot.in(Test) := (baseDirectory.in(`scala3doc-testcases`).value / "src").getAbsolutePath.toString,
1481+
fork.in(run) := true,
1482+
Compile / mainClass := Some("dotty.dokka.Main"),
1483+
// There is a bug in dokka that prevents parallel tests withing the same jvm
1484+
fork.in(test) := true,
1485+
Test / parallelExecution := false,
1486+
generateSelfDocumentation := Def.inputTaskDyn {
1487+
generateDocumentation(classDirectory.in(Compile).value.getAbsolutePath, "scala3doc", "self", "-d documentation")
1488+
}.evaluated,
1489+
generateScala3Documentation := Def.taskDyn {
1490+
val dottyJars = Seq(
1491+
// All projects below will be used to generated documentation for Scala 3
1492+
classDirectory.in(`scala3-interfaces`).in(Compile).value,
1493+
classDirectory.in(`tasty-core`).in(Compile).value,
1494+
classDirectory.in(`scala3-library`).in(Compile).value,
1495+
// TODO this one fails to load using TASTY
1496+
// classDirectory.in(`stdlib-bootstrapped`).in(Compile).value,
1497+
)
1498+
val roots = dottyJars.map(_.toString).mkString(java.io.File.pathSeparator)
1499+
1500+
if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
1501+
else generateDocumentation(roots, "Scala 3", "stdLib", "-d dotty-docs/docs")
1502+
}.value,
1503+
generateTestcasesDocumentation := Def.taskDyn {
1504+
generateDocumentation(Build.testcasesOutputDir.in(Test).value, "Scala3doc testcases", "testcases")
1505+
}.value,
1506+
buildInfoKeys in Test := Seq[BuildInfoKey](
1507+
Build.testcasesOutputDir.in(Test),
1508+
Build.testcasesSourceRoot.in(Test),
1509+
),
1510+
buildInfoPackage in Test := "dotty.dokka",
1511+
BuildInfoPlugin.buildInfoScopedSettings(Test),
1512+
BuildInfoPlugin.buildInfoDefaultSettings,
1513+
// Uncomment to debug dokka processing (require to run debug in listen mode on 5005 port)
1514+
// javaOptions.in(run) += "-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5005,suspend=y"
14761515
)
1516+
}
14771517

14781518
def asScala3docTestcases: Project =
14791519
project.dependsOn(`scala3-compiler-bootstrapped`).settings(commonBootstrappedSettings)

scala3doc/build.sbt

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)