diff --git a/compiler/src/dotty/tools/dotc/Driver.scala b/compiler/src/dotty/tools/dotc/Driver.scala index b1c9496e3a8f..9170cfd0af55 100644 --- a/compiler/src/dotty/tools/dotc/Driver.scala +++ b/compiler/src/dotty/tools/dotc/Driver.scala @@ -61,7 +61,7 @@ class Driver { } /** Setup extra classpath and figure out class names for tasty file inputs */ - private def fromTastySetup(fileNames0: List[String], ctx0: Context) = { + protected def fromTastySetup(fileNames0: List[String], ctx0: Context): (List[String], Context) = { if (ctx0.settings.fromTasty.value(ctx0)) { // Resolve classpath and class names of tasty files val (classPaths, classNames) = fileNames0.map { name => diff --git a/doc-tool/src/dotty/tools/dottydoc/DocDriver.scala b/doc-tool/src/dotty/tools/dottydoc/DocDriver.scala index aacbdcdc3e80..63e66f0f91d3 100644 --- a/doc-tool/src/dotty/tools/dottydoc/DocDriver.scala +++ b/doc-tool/src/dotty/tools/dottydoc/DocDriver.scala @@ -27,7 +27,7 @@ class DocDriver extends Driver { ctx.setProperty(ContextDoc, new ContextDottydoc) val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx) - (fileNames, ctx) + fromTastySetup(fileNames, ctx) } override def newCompiler(implicit ctx: Context): Compiler = new DocCompiler diff --git a/sbt-bridge/src/xsbt/ScaladocInterface.scala b/sbt-bridge/src/xsbt/ScaladocInterface.scala index 0461447eefbc..09e785f3c4a6 100644 --- a/sbt-bridge/src/xsbt/ScaladocInterface.scala +++ b/sbt-bridge/src/xsbt/ScaladocInterface.scala @@ -6,6 +6,7 @@ package xsbt import xsbti.{ Logger, Severity } import java.net.URL import java.util.Optional +import java.nio.file.{Files, Paths} import dotty.tools.dotc.core.Contexts.{ Context, ContextBase } import dotty.tools.dotc.reporting.Reporter @@ -16,9 +17,21 @@ class ScaladocInterface { } } -class DottydocRunner(args: Array[String], log: Logger, delegate: xsbti.Reporter) { +class DottydocRunner(args0: Array[String], log: Logger, delegate: xsbti.Reporter) { def run(): Unit = { - log.debug(() => args.mkString("Calling Dottydoc with arguments (ScaladocInterface):\n\t", "\n\t", "")) + log.debug(() => args0.mkString("Calling Dottydoc with arguments (ScaladocInterface):\n\t", "\n\t", "")) + + val args = { + // When running with `-from-tasty`, remove the source files from arg list. + if (args0.contains("-from-tasty")) { + val (excluded, retained) = + args0.partition { arg => + (arg.endsWith(".scala") || arg.endsWith(".java")) && Files.exists(Paths.get(arg)) + } + log.debug(() => excluded.mkString("Running `-from-tasty`, excluding source files:\n\t", "\n\t", "")) + retained + } else args0 + } val ctx = (new ContextBase).initialCtx.fresh .setReporter(new DelegatingReporter(delegate)) diff --git a/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala b/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala index c00df73c1f63..fcd52a3ff815 100644 --- a/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala +++ b/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala @@ -216,9 +216,19 @@ object DottyPlugin extends AutoPlugin { old.withCircularDependencyLevel(sbt.librarymanagement.ivy.CircularDependencyLevel.Ignore) } else old } - ) + ) ++ inConfig(Compile)(docSettings) ++ inConfig(Test)(docSettings) } + private val docSettings = inTask(doc)(Seq( + sources := { + val _ = compile.value // Ensure that everything is compiled, so TASTy is available. + val prev = sources.value + val tastyFiles = (classDirectory.value ** "*.tasty").get.map(_.getAbsoluteFile) + prev ++ tastyFiles + }, + scalacOptions += "-from-tasty" + )) + /** Fetch artefacts for scalaOrganization.value %% moduleName % scalaVersion.value */ private def fetchArtifactsOf(moduleName: String) = Def.task { val dependencyResolution = Keys.dependencyResolution.value