Skip to content

Commit 946752f

Browse files
committed
Change requests from reviews
1 parent ac8531d commit 946752f

File tree

12 files changed

+79
-52
lines changed

12 files changed

+79
-52
lines changed

dist/bin/scaladoc

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ eval "\"$JAVACMD\"" \
127127
${JAVA_OPTS:-$default_java_opts} \
128128
"${java_args[@]}" \
129129
"${jvm_cp_args-}" \
130+
-Dscala.usejavacp=true \
130131
"dotty.tools.scaladoc.Main" \
131132
"${scala_args[@]}" \
132133
"${residual_args[@]}" \

project/Build.scala

+20-15
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ object Build {
12431243
libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13)
12441244
)
12451245

1246-
def generateDocumentation(targets: Seq[String], name: String, outDir: String, ref: String, params: Seq[String] = Nil, addBootclasspath: Boolean = false) =
1246+
def generateDocumentation(targets: Seq[String], name: String, outDir: String, ref: String, params: Seq[String] = Nil, usingScript: Boolean = true) =
12471247
Def.taskDyn {
12481248
val distLocation = (dist / pack).value
12491249
val projectVersion = version.value
@@ -1255,13 +1255,6 @@ object Build {
12551255
def srcManaged(v: String, s: String) = s"out/bootstrap/stdlib-bootstrapped/scala-$v/src_managed/main/$s-library-src"
12561256
def scalaSrcLink(v: String, s: String) = s"-source-links:$s=github://scala/scala/v$v#src/library"
12571257
def dottySrcLink(v: String, s: String) = s"-source-links:$s=github://lampepfl/dotty/$v#library/src"
1258-
def bootclasspath: Seq[String] = if(addBootclasspath) Seq(
1259-
"-bootclasspath",
1260-
Seq(
1261-
scalaLib,
1262-
dottyLib
1263-
).mkString(System.getProperty("path.separator"))
1264-
) else Nil
12651258

12661259
val revision = Seq("-revision", ref, "-project-version", projectVersion)
12671260
val cmd = Seq(
@@ -1272,9 +1265,22 @@ object Build {
12721265
scalaSrcLink(stdLibVersion, srcManaged(dottyNonBootstrappedVersion, "scala")),
12731266
dottySrcLink(referenceVersion, srcManaged(dottyNonBootstrappedVersion, "dotty")),
12741267
s"-source-links:github://lampepfl/dotty/$referenceVersion",
1275-
) ++ scalacOptionsDocSettings ++ revision ++ params ++ targets ++ bootclasspath
1268+
) ++ scalacOptionsDocSettings ++ revision ++ params ++ targets
12761269
import _root_.scala.sys.process._
1277-
Def.task((s"$distLocation/bin/scaladoc" +: cmd).!)
1270+
if (usingScript)
1271+
Def.task((s"$distLocation/bin/scaladoc" +: cmd).!)
1272+
else {
1273+
val escapedCmd = cmd.map(arg => if(arg.contains(" ")) s""""$arg"""" else arg)
1274+
Def.task {
1275+
try {
1276+
(Compile / run).toTask(escapedCmd.mkString(" ", " ", "")).value
1277+
0
1278+
} catch {
1279+
case _ : Throwable => 1
1280+
}
1281+
}
1282+
}
1283+
12781284
}
12791285

12801286
val SourceLinksIntegrationTest = config("sourceLinksIntegrationTest") extend Test
@@ -1321,8 +1327,7 @@ object Build {
13211327
generateSelfDocumentation := Def.taskDyn {
13221328
generateDocumentation(
13231329
(Compile / classDirectory).value.getAbsolutePath :: Nil,
1324-
"scaladoc", "scaladoc/output/self", VersionUtil.gitHash,
1325-
addBootclasspath = true
1330+
"scaladoc", "scaladoc/output/self", VersionUtil.gitHash
13261331
)
13271332
}.value,
13281333
generateScalaDocumentation := Def.inputTaskDyn {
@@ -1363,7 +1368,7 @@ object Build {
13631368
s"-source-links:docs=github://lampepfl/dotty/master#docs",
13641369
"-doc-root-content", docRootFile.toString,
13651370
"-Ydocument-synthetic-types"
1366-
)
1371+
), usingScript = false
13671372
))
13681373
}.evaluated,
13691374

@@ -1372,8 +1377,8 @@ object Build {
13721377
(Test / Build.testcasesOutputDir).value,
13731378
"scaladoc testcases",
13741379
"scaladoc/output/testcases",
1375-
"master",
1376-
addBootclasspath = true)
1380+
"master"
1381+
)
13771382
}.value,
13781383

13791384
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.bootclasspath, args.tastyFiles, compilerContext.settings.scalajs.value(using compilerContext))
79+
lazy val snippetChecker = snippets.SnippetChecker(args)(using compilerContext)
8080

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ 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-
extdirs, javabootclasspath, encoding, usejavacp,
22+
extdirs, javabootclasspath, encoding,
2323
// Needed for plugin architecture
2424
plugin,disable,require, pluginsDir, pluginOptions,
2525
// we need support for sourcepath and sourceroot
@@ -100,7 +100,7 @@ class ScaladocSettings extends SettingGroup with AllScalaSettings:
100100
MultiStringSetting("-snippet-compiler", "snippet-compiler", snippets.SnippetCompilerArgs.usage)
101101

102102
val snippetCompilerDebug: Setting[Boolean] =
103-
BooleanSetting("-snippet-compiler-debug", snippets.SnippetCompilerArgs.debugUsage, false)
103+
BooleanSetting("-Ysnippet-compiler-debug", snippets.SnippetCompilerArgs.debugUsage, false)
104104

105105
def scaladocSpecificSettings: Set[Setting[_]] =
106106
Set(sourceLinks, syntax, revision, externalDocumentationMappings, socialLinks, skipById, skipByRegex, deprecatedSkipPackages, docRootContent, snippetCompiler, snippetCompilerDebug)

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@ import java.io.File
77

88
import dotty.tools.io.AbstractFile
99
import dotty.tools.dotc.fromtasty.TastyFileUtil
10+
import dotty.tools.dotc.config.Settings._
11+
import dotty.tools.dotc.config.ScalaSettings
1012

11-
class SnippetChecker(val classpath: String, val bootclasspath: String, val tastyFiles: Seq[File], isScalajs: Boolean):
13+
class SnippetChecker(val args: Scaladoc.Args)(using cctx: CompilerContext):
14+
15+
// (val classpath: String, val bootclasspath: String, val tastyFiles: Seq[File], isScalajs: Boolean, useJavaCp: Boolean):
1216
private val sep = System.getProperty("path.separator")
13-
private val cp = List(
14-
tastyFiles
17+
18+
private val fullClasspath = List(
19+
args.tastyFiles
1520
.map(_.getAbsolutePath())
1621
.map(AbstractFile.getFile(_))
1722
.flatMap(t => try { TastyFileUtil.getClassPath(t) } catch { case e: AssertionError => Seq() })
1823
.distinct.mkString(sep),
19-
classpath,
20-
bootclasspath
24+
args.classpath
2125
).mkString(sep)
2226

27+
private val snippetCompilerSettings: Seq[SnippetCompilerSetting[_]] = cctx.settings.userSetSettings(cctx.settingsState).filter(_ != cctx.settings.classpath).map( s =>
28+
SnippetCompilerSetting(s, s.valueIn(cctx.settingsState))
29+
) :+ SnippetCompilerSetting(cctx.settings.classpath, fullClasspath)
2330

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

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

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

+22-18
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ package dotty.tools.scaladoc
22
package snippets
33

44
import dotty.tools.io.{AbstractFile, VirtualDirectory}
5-
import dotty.tools.dotc.interactive.InteractiveDriver
6-
import dotty.tools.dotc.interactive.Interactive
7-
import dotty.tools.dotc.interactive.InteractiveCompiler
5+
import dotty.tools.dotc.Driver
86
import dotty.tools.dotc.core.Contexts.Context
7+
import dotty.tools.dotc.core.Mode
98
import dotty.tools.dotc.config.Settings.Setting._
109
import dotty.tools.dotc.interfaces.SourcePosition
1110
import dotty.tools.dotc.ast.Trees.Tree
@@ -21,22 +20,27 @@ import dotty.tools.dotc.interfaces.Diagnostic._
2120
import scala.util.{ Try, Success, Failure }
2221

2322
class SnippetCompiler(
24-
classpath: String,
25-
val scalacOptions: String = "",
23+
val snippetCompilerSettings: Seq[SnippetCompilerSetting[_]],
2624
target: AbstractFile = new VirtualDirectory("(memory)")
2725
):
26+
object SnippetDriver extends Driver:
27+
val currentCtx =
28+
val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions).addMode(Mode.Interactive)
29+
rootCtx.setSetting(rootCtx.settings.YretainTrees, true)
30+
rootCtx.setSetting(rootCtx.settings.YcookComments, true)
31+
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
32+
rootCtx.setSetting(rootCtx.settings.color, "never")
33+
rootCtx.setSetting(rootCtx.settings.XimportSuggestionTimeout, 0)
2834

29-
private def newDriver: InteractiveDriver = {
30-
val defaultFlags =
31-
List("-color:never", "-unchecked", "-deprecation", "-Ximport-suggestion-timeout", "0")
32-
val options = scalacOptions.split("\\s+").toList
33-
val settings =
34-
options ::: defaultFlags ::: "-classpath" :: classpath :: Nil
35-
36-
new InteractiveDriver(settings)
37-
}
38-
39-
private val driver = newDriver
35+
val ctx = setup(Array(""), rootCtx) match
36+
case Some((_, ctx)) =>
37+
ctx
38+
case None => rootCtx
39+
val res = snippetCompilerSettings.foldLeft(ctx.fresh) { (ctx, setting) =>
40+
ctx.setSetting(setting.setting, setting.value)
41+
}
42+
res.initialize()(using res)
43+
res
4044

4145
private val scala3Compiler = new Compiler
4246

@@ -86,9 +90,9 @@ class SnippetCompiler(
8690
wrappedSnippet: WrappedSnippet,
8791
arg: SnippetCompilerArg
8892
): SnippetCompilationResult = {
89-
val context = driver.currentCtx.fresh
93+
val context = SnippetDriver.currentCtx.fresh
9094
.setSetting(
91-
driver.currentCtx.settings.outputDir,
95+
SnippetDriver.currentCtx.settings.outputDir,
9296
target
9397
)
9498
.setReporter(new StoreReporter)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package dotty.tools.scaladoc
2+
package snippets
3+
4+
import dotty.tools.scaladoc.DocContext
5+
import dotty.tools.dotc.config.Settings._
6+
import dotty.tools.dotc.config.ScalaSettings
7+
8+
case class SnippetCompilerSetting[T](setting: Setting[T], value: T)

scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object SnippetRenderer:
1818
case MessageLevel.Error => "snippet-error"
1919
case MessageLevel.Debug => "snippet-debug"
2020

21-
private def cutBetwenSymbols[A](
21+
private def cutBetweenSymbols[A](
2222
startSymbol: String,
2323
endSymbol: String,
2424
snippetLines: Seq[SnippetLine]
@@ -33,7 +33,7 @@ object SnippetRenderer:
3333
} yield f(begin, mid, end)
3434

3535
private def wrapHiddenSymbols(snippetLines: Seq[SnippetLine]): Seq[SnippetLine] =
36-
val mRes = cutBetwenSymbols("//{", "//}", snippetLines) {
36+
val mRes = cutBetweenSymbols("//{", "//}", snippetLines) {
3737
case (begin, mid, end) =>
3838
begin ++ mid.drop(1).dropRight(1).map(_.withClass("hideable")) ++ wrapHiddenSymbols(end)
3939
}
@@ -74,7 +74,7 @@ object SnippetRenderer:
7474
}
7575

7676
private def wrapMultiLineComments(snippetLines: Seq[SnippetLine]): Seq[SnippetLine] =
77-
val mRes = cutBetwenSymbols("/*", "*/", snippetLines) {
77+
val mRes = cutBetweenSymbols("/*", "*/", snippetLines) {
7878
case (begin, mid, end) if mid.size == 1 =>
7979
val midRedacted = mid.map(wrapLineInBetween(Some("/*"), Some("*/"), _))
8080
begin ++ midRedacted ++ end

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class BaseHtmlTest:
3434
tastyFiles = pcks.flatMap(tastyFiles(_)),
3535
output = dest.toFile,
3636
docsRoot = docsRoot,
37-
projectVersion = Some(projectVersion),
38-
bootclasspath = dotty.tools.dotc.util.ClasspathFromClassloader(classOf[Predef$].getClassLoader())
37+
projectVersion = Some(projectVersion)
3938
)
4039
Scaladoc.run(args)(using testContext)
4140
op(using ProjectContext(dest))

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import org.junit.Assert._
66
import dotty.tools.io.{AbstractFile, VirtualDirectory}
77

88
class SnippetCompilerTest {
9-
val compiler = SnippetCompiler(System.getProperty("java.class.path"))
9+
val compiler = SnippetCompiler(
10+
Seq(SnippetCompilerSetting(testContext.settings.usejavacp, true))
11+
)
1012
def wrapFn: String => WrappedSnippet = (str: String) => WrappedSnippet(
1113
str,
1214
Some("test"),

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ 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,
42-
bootclasspath = dotty.tools.dotc.util.ClasspathFromClassloader(classOf[Predef$].getClassLoader())
41+
snippetCompilerDebug = debug
4342
)
4443

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

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ def testArgs(files: Seq[File] = Nil, dest: File = new File("notUsed")) = Scalado
5555
output = dest,
5656
tastyFiles = files,
5757
docsRoot = Some(""),
58-
bootclasspath = dotty.tools.dotc.util.ClasspathFromClassloader(classOf[Predef$].getClassLoader())
5958
)
6059

61-
def testContext = (new ContextBase).initialCtx.fresh.setReporter(new TestReporter)
60+
def testContext =
61+
val ctx = (new ContextBase).initialCtx.fresh.setReporter(new TestReporter)
62+
ctx.setSetting(ctx.settings.usejavacp, true)
63+
ctx
6264

6365
def testDocContext(files: Seq[File] = Nil) = DocContext(testArgs(files), testContext)
6466

0 commit comments

Comments
 (0)