Skip to content

Generate documentation from TASTY in sbt plugin #5081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
2 changes: 1 addition & 1 deletion doc-tool/src/dotty/tools/dottydoc/DocDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions sbt-bridge/src/xsbt/ScaladocInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
12 changes: 11 additions & 1 deletion sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down