Skip to content

Commit f17dcbc

Browse files
committed
Fix classpath problems. Add support for scala.js. Add bootclasspath to generateDocumentation task
1 parent d5011a4 commit f17dcbc

File tree

9 files changed

+37
-11
lines changed

9 files changed

+37
-11
lines changed

project/Build.scala

+15-3
Original file line numberDiff line numberDiff line change
@@ -1242,16 +1242,26 @@ object Build {
12421242
libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13)
12431243
)
12441244

1245-
def generateDocumentation(targets: Seq[String], name: String, outDir: String, ref: String, params: Seq[String] = Nil) =
1245+
def generateDocumentation(targets: Seq[String], name: String, outDir: String, ref: String, params: Seq[String] = Nil, addBootclasspath: Boolean = false) =
12461246
Def.taskDyn {
12471247
val distLocation = (dist / pack).value
12481248
val projectVersion = version.value
12491249
IO.createDirectory(file(outDir))
12501250
val stdLibVersion = stdlibVersion(Bootstrapped)
1251+
val scalaLib = findArtifactPath(externalCompilerClasspathTask.value, "scala-library")
1252+
val dottyLib = (`scala3-library` / Compile / classDirectory).value
12511253
// TODO add versions etc.
12521254
def srcManaged(v: String, s: String) = s"out/bootstrap/stdlib-bootstrapped/scala-$v/src_managed/main/$s-library-src"
12531255
def scalaSrcLink(v: String, s: String) = s"-source-links:$s=github://scala/scala/v$v#src/library"
12541256
def dottySrcLink(v: String, s: String) = s"-source-links:$s=github://lampepfl/dotty/$v#library/src"
1257+
def bootclasspath: Seq[String] = if(addBootclasspath) Seq(
1258+
"-bootclasspath",
1259+
Seq(
1260+
scalaLib,
1261+
dottyLib
1262+
).mkString(System.getProperty("path.separator"))
1263+
) else Nil
1264+
12551265
val revision = Seq("-revision", ref, "-project-version", projectVersion)
12561266
val cmd = Seq(
12571267
"-d",
@@ -1260,7 +1270,7 @@ object Build {
12601270
name,
12611271
scalaSrcLink(stdLibVersion, srcManaged(dottyNonBootstrappedVersion, "scala")),
12621272
dottySrcLink(referenceVersion, srcManaged(dottyNonBootstrappedVersion, "dotty"))
1263-
) ++ scalacOptionsDocSettings ++ revision ++ params ++ targets
1273+
) ++ scalacOptionsDocSettings ++ revision ++ params ++ targets ++ bootclasspath
12641274
import _root_.scala.sys.process._
12651275
Def.task((s"$distLocation/bin/scaladoc" +: cmd).!)
12661276
}
@@ -1310,6 +1320,7 @@ object Build {
13101320
generateDocumentation(
13111321
(Compile / classDirectory).value.getAbsolutePath :: Nil,
13121322
"scaladoc", "scaladoc/output/self", VersionUtil.gitHash,
1323+
addBootclasspath = true
13131324
)
13141325
}.value,
13151326
generateScalaDocumentation := Def.inputTaskDyn {
@@ -1361,7 +1372,8 @@ object Build {
13611372
(Test / Build.testcasesOutputDir).value,
13621373
"scaladoc testcases",
13631374
"scaladoc/output/testcases",
1364-
"master")
1375+
"master",
1376+
addBootclasspath = true)
13651377
}.value,
13661378

13671379
Test / buildInfoKeys := Seq[BuildInfoKey](

scaladoc/src/dotty/tools/scaladoc/DocContext.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ case class DocContext(args: Scaladoc.Args, compilerContext: CompilerContext):
7676

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

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

8181
lazy val staticSiteContext = args.docsRoot.map(path => StaticSiteContext(
8282
File(path).getAbsoluteFile(),

scaladoc/src/dotty/tools/scaladoc/Scaladoc.scala

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ object Scaladoc:
3131
tastyDirs: Seq[File] = Nil,
3232
tastyFiles: Seq[File] = Nil,
3333
classpath: String = "",
34+
bootclasspath: String = "",
3435
output: File,
3536
docsRoot: Option[String] = None,
3637
projectVersion: Option[String] = None,
@@ -174,6 +175,7 @@ object Scaladoc:
174175
dirs,
175176
validFiles,
176177
classpath.get,
178+
bootclasspath.get,
177179
destFile,
178180
siteRoot.nonDefault,
179181
projectVersion.nonDefault,

scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import dotty.tools.dotc.core.Contexts._
1919
class ScaladocSettings extends SettingGroup with AllScalaSettings:
2020
val unsupportedSettings = Seq(
2121
// Options that we like to support
22-
bootclasspath, extdirs, javabootclasspath, encoding, usejavacp,
22+
extdirs, javabootclasspath, encoding, usejavacp,
2323
// Needed for plugin architecture
2424
plugin,disable,require, pluginsDir, pluginOptions,
2525
// we need support for sourcepath and sourceroot
2626
sourcepath, sourceroot
2727
)
2828

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

scaladoc/src/dotty/tools/scaladoc/snippets/SnippetChecker.scala

+11-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@ import dotty.tools.scaladoc.DocContext
55
import java.nio.file.Paths
66
import java.io.File
77

8-
class SnippetChecker(val classpath: String, val tastyDirs: Seq[File]):
8+
import dotty.tools.io.AbstractFile
9+
import dotty.tools.dotc.fromtasty.TastyFileUtil
10+
11+
class SnippetChecker(val classpath: String, val bootclasspath: String, val tastyFiles: Seq[File], isScalajs: Boolean):
912
private val sep = System.getProperty("path.separator")
1013
private val cp = List(
11-
tastyDirs.map(_.getAbsolutePath()).mkString(sep),
14+
tastyFiles
15+
.map(_.getAbsolutePath())
16+
.map(AbstractFile.getFile(_))
17+
.flatMap(t => try { TastyFileUtil.getClassPath(t) } catch { case e: AssertionError => Seq() })
18+
.distinct.mkString(sep),
1219
classpath,
13-
System.getProperty("java.class.path")
20+
bootclasspath
1421
).mkString(sep)
1522

1623

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

1926
// These constants were found empirically to make snippet compiler
2027
// report errors in the same position as main compiler.

scaladoc/src/dotty/tools/scaladoc/snippets/SnippetCompiler.scala

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class SnippetCompiler(
3232
val options = scalacOptions.split("\\s+").toList
3333
val settings =
3434
options ::: defaultFlags ::: "-classpath" :: classpath :: Nil
35+
3536
new InteractiveDriver(settings)
3637
}
3738

scaladoc/test/dotty/tools/scaladoc/BaseHtmlTest.scala

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class BaseHtmlTest:
3535
output = dest.toFile,
3636
docsRoot = docsRoot,
3737
projectVersion = Some(projectVersion),
38+
bootclasspath = dotty.tools.dotc.util.ClasspathFromClassloader(classOf[Predef$].getClassLoader())
3839
)
3940
Scaladoc.run(args)(using testContext)
4041
op(using ProjectContext(dest))

scaladoc/test/dotty/tools/scaladoc/snippets/SnippetsE2eTest.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ abstract class SnippetsE2eTest(testName: String, flag: SCFlags, debug: Boolean)
3838
output = getTempDir().getRoot,
3939
projectVersion = Some("1.0"),
4040
snippetCompiler = List(s"${BuildInfo.test_testcasesSourceRoot}/tests=${flag.flagName}"),
41-
snippetCompilerDebug = debug
41+
snippetCompilerDebug = debug,
42+
bootclasspath = dotty.tools.dotc.util.ClasspathFromClassloader(classOf[Predef$].getClassLoader())
4243
)
4344

4445
override def withModule(op: DocContext ?=> Module => Unit) =

scaladoc/test/dotty/tools/scaladoc/testUtils.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def testArgs(files: Seq[File] = Nil, dest: File = new File("notUsed")) = Scalado
5454
name = "Test Project Name",
5555
output = dest,
5656
tastyFiles = files,
57-
docsRoot = Some("")
57+
docsRoot = Some(""),
58+
bootclasspath = dotty.tools.dotc.util.ClasspathFromClassloader(classOf[Predef$].getClassLoader())
5859
)
5960

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

0 commit comments

Comments
 (0)