@@ -213,6 +213,12 @@ object Build {
213213 }
214214 )
215215
216+ lazy val disableDocSetting =
217+ // Disable scaladoc generation, it's way too slow and we'll replace it
218+ // by dottydoc anyway. We still publish an empty -javadoc.jar to make
219+ // sonatype happy.
220+ sources in (Compile , doc) := Seq ()
221+
216222 lazy val commonSettings = publishSettings ++ Seq (
217223 scalaSource in Compile := baseDirectory.value / " src" ,
218224 scalaSource in Test := baseDirectory.value / " test" ,
@@ -221,11 +227,6 @@ object Build {
221227 resourceDirectory in Compile := baseDirectory.value / " resources" ,
222228 resourceDirectory in Test := baseDirectory.value / " test-resources" ,
223229
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-
229230 // Prevent sbt from rewriting our dependencies
230231 scalaModuleInfo ~= (_.map(_.withOverrideScalaVersion(false ))),
231232
@@ -244,7 +245,8 @@ object Build {
244245 crossPaths := false ,
245246 // Do not depend on the Scala library
246247 autoScalaLibrary := false ,
247- excludeFromIDE := true
248+ excludeFromIDE := true ,
249+ disableDocSetting
248250 )
249251
250252 // Settings used when compiling dotty (both non-bootstrapped and bootstrapped)
@@ -258,6 +260,8 @@ object Build {
258260 moduleName ~= { _.stripSuffix(" -scala2" ) },
259261 version := dottyVersion,
260262 target := baseDirectory.value / " .." / " out" / " scala-2" / name.value,
263+
264+ disableDocSetting
261265 )
262266
263267 // Settings used when compiling dotty with the reference compiler
@@ -267,6 +271,8 @@ object Build {
267271 version := dottyNonBootstrappedVersion,
268272 scalaVersion := referenceVersion,
269273 excludeFromIDE := true ,
274+
275+ disableDocSetting
270276 )
271277
272278 // Settings used when compiling dotty with a non-bootstrapped dotty
@@ -328,6 +334,8 @@ object Build {
328334 },
329335 // sbt-dotty defines `scalaInstance in doc` so we need to override it manually
330336 scalaInstance in doc := scalaInstance.value,
337+
338+ disableDocSetting,
331339 )
332340
333341 lazy val commonBenchmarkSettings = Seq (
@@ -1153,6 +1161,14 @@ object Build {
11531161 lazy val `scala3-bench-bootstrapped` = project.in(file(" bench" )).asDottyBench(Bootstrapped )
11541162 lazy val `scala3-bench-run` = project.in(file(" bench-run" )).asDottyBench(Bootstrapped )
11551163
1164+ val testcasesOutputDir = taskKey[String ](" Root directory where tests classses are generated" )
1165+ val testcasesSourceRoot = taskKey[String ](" Root directory where tests sources are generated" )
1166+ val generateSelfDocumentation = taskKey[Unit ](" Generate example documentation" )
1167+ val generateScala3Documentation = taskKey[Unit ](" Generate documentation for dotty lib" )
1168+ val generateTestcasesDocumentation = taskKey[Unit ](" Generate documentation for testcases, usefull for debugging tests" )
1169+ lazy val `scala3doc` = project.in(file(" scala3doc" )).asScala3doc
1170+ lazy val `scala3doc-testcases` = project.in(file(" scala3doc-testcases" )).asScala3docTestcases
1171+
11561172 // sbt plugin to use Dotty in your own build, see
11571173 // https://github.com/lampepfl/scala3-example-project for usage.
11581174 lazy val `sbt-dotty` = project.in(file(" sbt-dotty" )).
@@ -1192,6 +1208,7 @@ object Build {
11921208 publishLocal in `scala3-staging`,
11931209 publishLocal in `scala3-tasty-inspector`,
11941210 publishLocal in `scala3-doc-bootstrapped`,
1211+ publishLocal in `scala3doc`,
11951212 publishLocal in `scala3-bootstrapped` // Needed because sbt currently hardcodes the dotty artifact
11961213 ).evaluated
11971214 )
@@ -1393,7 +1410,7 @@ object Build {
13931410 def asDottyRoot (implicit mode : Mode ): Project = project.withCommonSettings.
13941411 aggregate(`scala3-interfaces`, dottyLibrary, dottyCompiler, tastyCore, dottyDoc, `scala3-sbt-bridge`).
13951412 bootstrappedAggregate(`scala3-language-server`, `scala3-staging`, `scala3-tasty-inspector`,
1396- `scala3-library-bootstrappedJS`).
1413+ `scala3-library-bootstrappedJS`, scala3doc ).
13971414 dependsOn(tastyCore).
13981415 dependsOn(dottyCompiler).
13991416 dependsOn(dottyLibrary).
@@ -1440,6 +1457,70 @@ object Build {
14401457 settings(commonBenchmarkSettings).
14411458 enablePlugins(JmhPlugin )
14421459
1460+ def asScala3doc : Project = {
1461+ def generateDocumentation (targets : String , name : String , outDir : String , params : String = " " ) = Def .taskDyn {
1462+ val sourceMapping = " =https://github.com/lampepfl/dotty/tree/master#L"
1463+ run.in(Compile ).toTask(s """ -d output/ $outDir -t $targets -n " $name" -s $sourceMapping $params""" )
1464+ }
1465+
1466+ project.settings(commonBootstrappedSettings).
1467+ dependsOn(`scala3-compiler-bootstrapped`).
1468+ dependsOn(`scala3-tasty-inspector`).
1469+ settings(
1470+ // Needed to download dokka and its dependencies
1471+ resolvers += Resolver .jcenterRepo,
1472+ // Needed to download dokka-site
1473+ resolvers += Resolver .bintrayRepo(" virtuslab" , " dokka" ),
1474+ libraryDependencies ++= Seq (
1475+ " com.virtuslab.dokka" % " dokka-site" % " 0.1.9" ,
1476+ " com.vladsch.flexmark" % " flexmark-all" % " 0.42.12" ,
1477+ " nl.big-o" % " liqp" % " 0.6.7" ,
1478+ " args4j" % " args4j" % " 2.33" ,
1479+
1480+ " org.jetbrains.dokka" % " dokka-test-api" % " 1.4.10.2" % " test" ,
1481+ " com.novocode" % " junit-interface" % " 0.11" % " test" ,
1482+ ),
1483+ Test / test := (Test / test).dependsOn(compile.in(Compile ).in(`scala3doc-testcases`)).value,
1484+ testcasesOutputDir.in(Test ) := classDirectory.in(Compile ).in(`scala3doc-testcases`).value.getAbsolutePath.toString,
1485+ testcasesSourceRoot.in(Test ) := (baseDirectory.in(`scala3doc-testcases`).value / " src" ).getAbsolutePath.toString,
1486+ Compile / mainClass := Some (" dotty.dokka.Main" ),
1487+ // There is a bug in dokka that prevents parallel tests withing the same jvm
1488+ fork.in(test) := true ,
1489+ generateSelfDocumentation := Def .taskDyn {
1490+ generateDocumentation(classDirectory.in(Compile ).value.getAbsolutePath, " scala3doc" , " self" , " -p documentation" )
1491+ }.value,
1492+ generateScala3Documentation := Def .taskDyn {
1493+ val dottyJars = Seq (
1494+ // All projects below will be used to generated documentation for Scala 3
1495+ classDirectory.in(`scala3-interfaces`).in(Compile ).value,
1496+ classDirectory.in(`tasty-core`).in(Compile ).value,
1497+ classDirectory.in(`scala3-library`).in(Compile ).value,
1498+ // TODO this one fails to load using TASTY
1499+ // classDirectory.in(`stdlib-bootstrapped`).in(Compile).value,
1500+ )
1501+ val roots = dottyJars.map(_.toString).mkString(java.io.File .pathSeparator)
1502+
1503+ if (dottyJars.isEmpty) Def .task { streams.value.log.error(" Dotty lib wasn't found" ) }
1504+ else generateDocumentation(roots, " Scala 3" , " stdLib" , " -p dotty-docs/docs" )
1505+ }.value,
1506+ generateTestcasesDocumentation := Def .taskDyn {
1507+ generateDocumentation(Build .testcasesOutputDir.in(Test ).value, " Scala3doc testcases" , " testcases" )
1508+ }.value,
1509+ buildInfoKeys in Test := Seq [BuildInfoKey ](
1510+ Build .testcasesOutputDir.in(Test ),
1511+ Build .testcasesSourceRoot.in(Test ),
1512+ ),
1513+ buildInfoPackage in Test := " dotty.dokka" ,
1514+ BuildInfoPlugin .buildInfoScopedSettings(Test ),
1515+ BuildInfoPlugin .buildInfoDefaultSettings,
1516+ // Uncomment to debug dokka processing (require to run debug in listen mode on 5005 port)
1517+ // javaOptions.in(run) += "-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5005,suspend=y"
1518+ )
1519+ }
1520+
1521+ def asScala3docTestcases : Project =
1522+ project.dependsOn(`scala3-compiler-bootstrapped`).settings(commonBootstrappedSettings)
1523+
14431524 def asDist (implicit mode : Mode ): Project = project.
14441525 enablePlugins(PackPlugin ).
14451526 withCommonSettings.
0 commit comments