Skip to content

Commit b908062

Browse files
authored
Merge pull request #5081 from dotty-staging/topic/sbt-doc-from-tasty
Generate documentation from TASTY in sbt plugin
2 parents 6e59705 + 385c2bd commit b908062

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

compiler/src/dotty/tools/dotc/Driver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Driver {
6161
}
6262

6363
/** Setup extra classpath and figure out class names for tasty file inputs */
64-
private def fromTastySetup(fileNames0: List[String], ctx0: Context) = {
64+
protected def fromTastySetup(fileNames0: List[String], ctx0: Context): (List[String], Context) = {
6565
if (ctx0.settings.fromTasty.value(ctx0)) {
6666
// Resolve classpath and class names of tasty files
6767
val (classPaths, classNames) = fileNames0.map { name =>

doc-tool/src/dotty/tools/dottydoc/DocDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DocDriver extends Driver {
2727
ctx.setProperty(ContextDoc, new ContextDottydoc)
2828

2929
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx)
30-
(fileNames, ctx)
30+
fromTastySetup(fileNames, ctx)
3131
}
3232

3333
override def newCompiler(implicit ctx: Context): Compiler = new DocCompiler

sbt-bridge/src/xsbt/ScaladocInterface.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package xsbt
66
import xsbti.{ Logger, Severity }
77
import java.net.URL
88
import java.util.Optional
9+
import java.nio.file.{Files, Paths}
910

1011
import dotty.tools.dotc.core.Contexts.{ Context, ContextBase }
1112
import dotty.tools.dotc.reporting.Reporter
@@ -16,9 +17,21 @@ class ScaladocInterface {
1617
}
1718
}
1819

19-
class DottydocRunner(args: Array[String], log: Logger, delegate: xsbti.Reporter) {
20+
class DottydocRunner(args0: Array[String], log: Logger, delegate: xsbti.Reporter) {
2021
def run(): Unit = {
21-
log.debug(() => args.mkString("Calling Dottydoc with arguments (ScaladocInterface):\n\t", "\n\t", ""))
22+
log.debug(() => args0.mkString("Calling Dottydoc with arguments (ScaladocInterface):\n\t", "\n\t", ""))
23+
24+
val args = {
25+
// When running with `-from-tasty`, remove the source files from arg list.
26+
if (args0.contains("-from-tasty")) {
27+
val (excluded, retained) =
28+
args0.partition { arg =>
29+
(arg.endsWith(".scala") || arg.endsWith(".java")) && Files.exists(Paths.get(arg))
30+
}
31+
log.debug(() => excluded.mkString("Running `-from-tasty`, excluding source files:\n\t", "\n\t", ""))
32+
retained
33+
} else args0
34+
}
2235

2336
val ctx = (new ContextBase).initialCtx.fresh
2437
.setReporter(new DelegatingReporter(delegate))

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,19 @@ object DottyPlugin extends AutoPlugin {
216216
old.withCircularDependencyLevel(sbt.librarymanagement.ivy.CircularDependencyLevel.Ignore)
217217
} else old
218218
}
219-
)
219+
) ++ inConfig(Compile)(docSettings) ++ inConfig(Test)(docSettings)
220220
}
221221

222+
private val docSettings = inTask(doc)(Seq(
223+
sources := {
224+
val _ = compile.value // Ensure that everything is compiled, so TASTy is available.
225+
val prev = sources.value
226+
val tastyFiles = (classDirectory.value ** "*.tasty").get.map(_.getAbsoluteFile)
227+
prev ++ tastyFiles
228+
},
229+
scalacOptions += "-from-tasty"
230+
))
231+
222232
/** Fetch artefacts for scalaOrganization.value %% moduleName % scalaVersion.value */
223233
private def fetchArtifactsOf(moduleName: String) = Def.task {
224234
val dependencyResolution = Keys.dependencyResolution.value

0 commit comments

Comments
 (0)