Skip to content

Commit

Permalink
Fix classpath problems. Add support for scala.js. Add bootclasspath t…
Browse files Browse the repository at this point in the history
…o generateDocumentation task
  • Loading branch information
pikinier20 committed May 17, 2021
1 parent 764ff69 commit 799e543
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 11 deletions.
18 changes: 15 additions & 3 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1242,16 +1242,26 @@ object Build {
libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13)
)

def generateDocumentation(targets: Seq[String], name: String, outDir: String, ref: String, params: Seq[String] = Nil) =
def generateDocumentation(targets: Seq[String], name: String, outDir: String, ref: String, params: Seq[String] = Nil, addBootclasspath: Boolean = false) =
Def.taskDyn {
val distLocation = (dist / pack).value
val projectVersion = version.value
IO.createDirectory(file(outDir))
val stdLibVersion = stdlibVersion(Bootstrapped)
val scalaLib = findArtifactPath(externalCompilerClasspathTask.value, "scala-library")
val dottyLib = (`scala3-library` / Compile / classDirectory).value
// TODO add versions etc.
def srcManaged(v: String, s: String) = s"out/bootstrap/stdlib-bootstrapped/scala-$v/src_managed/main/$s-library-src"
def scalaSrcLink(v: String, s: String) = s"-source-links:$s=github://scala/scala/v$v#src/library"
def dottySrcLink(v: String, s: String) = s"-source-links:$s=github://lampepfl/dotty/$v#library/src"
def bootclasspath: Seq[String] = if(addBootclasspath) Seq(
"-bootclasspath",
Seq(
scalaLib,
dottyLib
).mkString(System.getProperty("path.separator"))
) else Nil

val revision = Seq("-revision", ref, "-project-version", projectVersion)
val cmd = Seq(
"-d",
Expand All @@ -1260,7 +1270,7 @@ object Build {
name,
scalaSrcLink(stdLibVersion, srcManaged(dottyNonBootstrappedVersion, "scala")),
dottySrcLink(referenceVersion, srcManaged(dottyNonBootstrappedVersion, "dotty"))
) ++ scalacOptionsDocSettings ++ revision ++ params ++ targets
) ++ scalacOptionsDocSettings ++ revision ++ params ++ targets ++ bootclasspath
import _root_.scala.sys.process._
Def.task((s"$distLocation/bin/scaladoc" +: cmd).!)
}
Expand Down Expand Up @@ -1310,6 +1320,7 @@ object Build {
generateDocumentation(
(Compile / classDirectory).value.getAbsolutePath :: Nil,
"scaladoc", "scaladoc/output/self", VersionUtil.gitHash,
addBootclasspath = true
)
}.value,
generateScalaDocumentation := Def.inputTaskDyn {
Expand Down Expand Up @@ -1361,7 +1372,8 @@ object Build {
(Test / Build.testcasesOutputDir).value,
"scaladoc testcases",
"scaladoc/output/testcases",
"master")
"master",
addBootclasspath = true)
}.value,

Test / buildInfoKeys := Seq[BuildInfoKey](
Expand Down
2 changes: 1 addition & 1 deletion scaladoc/src/dotty/tools/scaladoc/DocContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ case class DocContext(args: Scaladoc.Args, compilerContext: CompilerContext):

lazy val snippetCompilerArgs = snippets.SnippetCompilerArgs.load(args.snippetCompiler, args.snippetCompilerDebug)(using compilerContext)

lazy val snippetChecker = snippets.SnippetChecker(args.classpath, args.tastyDirs)
lazy val snippetChecker = snippets.SnippetChecker(args.classpath, args.bootclasspath, args.tastyFiles, compilerContext.settings.scalajs.value(using compilerContext))

lazy val staticSiteContext = args.docsRoot.map(path => StaticSiteContext(
File(path).getAbsoluteFile(),
Expand Down
2 changes: 2 additions & 0 deletions scaladoc/src/dotty/tools/scaladoc/Scaladoc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ object Scaladoc:
tastyDirs: Seq[File] = Nil,
tastyFiles: Seq[File] = Nil,
classpath: String = "",
bootclasspath: String = "",
output: File,
docsRoot: Option[String] = None,
projectVersion: Option[String] = None,
Expand Down Expand Up @@ -174,6 +175,7 @@ object Scaladoc:
dirs,
validFiles,
classpath.get,
bootclasspath.get,
destFile,
siteRoot.nonDefault,
projectVersion.nonDefault,
Expand Down
3 changes: 2 additions & 1 deletion scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import dotty.tools.dotc.core.Contexts._
class ScaladocSettings extends SettingGroup with AllScalaSettings:
val unsupportedSettings = Seq(
// Options that we like to support
bootclasspath, extdirs, javabootclasspath, encoding, usejavacp,
extdirs, javabootclasspath, encoding, usejavacp,
// Needed for plugin architecture
plugin,disable,require, pluginsDir, pluginOptions,
// we need support for sourcepath and sourceroot
sourcepath, sourceroot
)


val projectName: Setting[String] =
StringSetting("-project", "project title", "The name of the project.", "", aliases = List("-doc-title"))

Expand Down
15 changes: 11 additions & 4 deletions scaladoc/src/dotty/tools/scaladoc/snippets/SnippetChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ import dotty.tools.scaladoc.DocContext
import java.nio.file.Paths
import java.io.File

class SnippetChecker(val classpath: String, val tastyDirs: Seq[File]):
import dotty.tools.io.AbstractFile
import dotty.tools.dotc.fromtasty.TastyFileUtil

class SnippetChecker(val classpath: String, val bootclasspath: String, val tastyFiles: Seq[File], isScalajs: Boolean):
private val sep = System.getProperty("path.separator")
private val cp = List(
tastyDirs.map(_.getAbsolutePath()).mkString(sep),
tastyFiles
.map(_.getAbsolutePath())
.map(AbstractFile.getFile(_))
.flatMap(t => try { TastyFileUtil.getClassPath(t) } catch { case e: AssertionError => Seq() })
.distinct.mkString(sep),
classpath,
System.getProperty("java.class.path")
bootclasspath
).mkString(sep)


private val compiler: SnippetCompiler = SnippetCompiler(classpath = cp)
private val compiler: SnippetCompiler = SnippetCompiler(classpath = cp, scalacOptions = if isScalajs then "-scalajs" else "")

// These constants were found empirically to make snippet compiler
// report errors in the same position as main compiler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SnippetCompiler(
val options = scalacOptions.split("\\s+").toList
val settings =
options ::: defaultFlags ::: "-classpath" :: classpath :: Nil

new InteractiveDriver(settings)
}

Expand Down
1 change: 1 addition & 0 deletions scaladoc/test/dotty/tools/scaladoc/BaseHtmlTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class BaseHtmlTest:
output = dest.toFile,
docsRoot = docsRoot,
projectVersion = Some(projectVersion),
bootclasspath = dotty.tools.dotc.util.ClasspathFromClassloader(classOf[Predef$].getClassLoader())
)
Scaladoc.run(args)(using testContext)
op(using ProjectContext(dest))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ abstract class SnippetsE2eTest(testName: String, flag: SCFlags, debug: Boolean)
output = getTempDir().getRoot,
projectVersion = Some("1.0"),
snippetCompiler = List(s"${BuildInfo.test_testcasesSourceRoot}/tests=${flag.flagName}"),
snippetCompilerDebug = debug
snippetCompilerDebug = debug,
bootclasspath = dotty.tools.dotc.util.ClasspathFromClassloader(classOf[Predef$].getClassLoader())
)

override def withModule(op: DocContext ?=> Module => Unit) =
Expand Down
3 changes: 2 additions & 1 deletion scaladoc/test/dotty/tools/scaladoc/testUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def testArgs(files: Seq[File] = Nil, dest: File = new File("notUsed")) = Scalado
name = "Test Project Name",
output = dest,
tastyFiles = files,
docsRoot = Some("")
docsRoot = Some(""),
bootclasspath = dotty.tools.dotc.util.ClasspathFromClassloader(classOf[Predef$].getClassLoader())
)

def testContext = (new ContextBase).initialCtx.fresh.setReporter(new TestReporter)
Expand Down

0 comments on commit 799e543

Please sign in to comment.