Skip to content

Commit 526ba06

Browse files
committed
scala3doc has similar api like compiler
use arguments extends of --tasty-root parameter
1 parent 2b39c14 commit 526ba06

File tree

4 files changed

+34
-53
lines changed

4 files changed

+34
-53
lines changed

project/Build.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ object Build {
14721472
def generateDocumentation(targets: String, name: String, outDir: String, ref: String, params: String = "") = Def.taskDyn {
14731473
val projectVersion = version.value
14741474
val sourcesAndRevision = s"-s github://lampepfl/dotty --revision $ref --projectVersion $projectVersion"
1475-
val cmd = s""" -d $outDir -t $targets -n "$name" $sourcesAndRevision $params"""
1475+
val cmd = s""" -d $outDir -n "$name" $sourcesAndRevision $params $targets"""
14761476
run.in(Compile).toTask(cmd)
14771477
}
14781478

@@ -1525,7 +1525,7 @@ object Build {
15251525
(`scala3-library-bootstrapped`/Compile/products).value,
15261526
).flatten
15271527

1528-
val roots = joinProducts(dottyJars)
1528+
val roots = dottyJars.mkString(" ")
15291529

15301530
if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
15311531
else Def.task{

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,9 @@ object DottyPlugin extends AutoPlugin {
362362
useScala3doc := false,
363363
scala3docOptions := Nil,
364364
Compile / doc / scalacOptions := {
365-
// We are passing scala3doc argument list as single argument to scala instance starting with magic prefix "--+DOC+"
366-
val s3dOpts = scala3docOptions.value.map("--+DOC+" + _)
367365
val s3cOpts = (Compile / doc / scalacOptions).value
368366
if (isDotty.value && useScala3doc.value) {
369-
s3dOpts ++ s3cOpts
367+
scala3docOptions.value ++ s3cOpts
370368
} else {
371369
s3cOpts
372370
}

scala3doc/src/dotty/dokka/Main.scala

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ import java.nio.file.Files
1414

1515
import dotty.tools.dotc.config.Settings._
1616

17-
abstract class Scala3Args(reportError: String => Unit) extends SettingGroup:
18-
private val tastyRootsUsage = "Roots where tools should look for tasty files. Directories and jars are accepted"
19-
val tastyRoots: Setting[String] =
20-
StringSetting("--tastyRoots", "tastyRoots", tastyRootsUsage, "", aliases = List("-t"))
21-
val tastyRootsAlias: Setting[String] =
22-
StringSetting("-t", "tastyRoots", tastyRootsUsage, "", aliases = List("-t"))
17+
class Scala3Args(reportError: String => Unit) extends SettingGroup:
2318

2419
val dest: Setting[String] =
2520
StringSetting("--dest", "dest", "Output to generate documentation to", "", aliases = List("-d"))
@@ -29,7 +24,7 @@ abstract class Scala3Args(reportError: String => Unit) extends SettingGroup:
2924
val classpath: Setting[String] =
3025
StringSetting("--classpath", "classpath", "Classpath to load dependencies from", "", aliases = List("--cp", "-c"))
3126
val classpathAlias1: Setting[String] =
32-
StringSetting("--cp", "classpath", "Classpath to load dependencies from", "", aliases = List("--cp", "-c"))
27+
StringSetting("-classpath", "classpath", "Classpath to load dependencies from", "", aliases = List("--cp", "-c"))
3328
val classpathAlias2: Setting[String] =
3429
StringSetting("-c", "classpath", "Classpath to load dependencies from", "", aliases = List("--cp", "-c"))
3530

@@ -71,9 +66,7 @@ abstract class Scala3Args(reportError: String => Unit) extends SettingGroup:
7166
val syntax: Setting[String] =
7267
StringSetting("--syntax", "syntax", "Syntax of the comment used", "")
7368

74-
protected def defaultName(): String
75-
protected def defaultTastFiles(): List[File]
76-
protected def defaultDest(): File
69+
protected def defaultDest(): File = sys.error(s"Argument '${dest.name}' is required")
7770

7871
def extract(args: List[String]) =
7972
val initialSummary = ArgsSummary(defaultState, args, errors = Nil, warnings = Nil)
@@ -95,11 +88,13 @@ abstract class Scala3Args(reportError: String => Unit) extends SettingGroup:
9588

9689
def parseTastyRoots(roots: String) = roots.split(File.pathSeparatorChar).toList.map(new File(_))
9790

91+
val tastyRoots = res.arguments.map(new File(_)) // check provided files
92+
9893
Args(
99-
parseOptionalArg(name, nameAlias).getOrElse(defaultName()),
100-
parseOptionalArg(tastyRoots, tastyRootsAlias).fold(defaultTastFiles())(parseTastyRoots),
94+
parseOptionalArg(name, nameAlias).getOrElse("root"),
95+
tastyRoots,
10196
parseOptionalArg(classpath, classpathAlias1, classpathAlias2).getOrElse(System.getProperty("java.class.path")),
102-
parseOptionalArg(dest, destAlias).fold(defaultDest())(new File(_)),
97+
parseOptionalArg(dest, destAlias).fold(defaultDest())(File(_)),
10398
parseOptionalArg(docsRoot, docsRootAlias),
10499
parseOptionalArg(projectVersion, projectVersionAlias),
105100
parseOptionalArg(projectTitle, projectTitleAlias),
@@ -158,40 +153,35 @@ enum DocConfiguration extends BaseDocConfiguration:
158153
*/
159154
object Main:
160155
def main(parsedArgs: Args): Unit =
161-
try
162-
val (files, dirs) = parsedArgs.tastyRoots.partition(_.isFile)
163-
val (providedTastyFiles, jars) = files.toList.map(_.getAbsolutePath).partition(_.endsWith(".tasty"))
164-
jars.foreach(j => if(!j.endsWith(".jar")) sys.error(s"Provided file $j is not jar not tasty file") )
156+
val (files, dirs) = parsedArgs.tastyRoots.partition(_.isFile)
157+
val (providedTastyFiles, jars) = files.toList.map(_.getAbsolutePath).partition(_.endsWith(".tasty"))
158+
jars.foreach(j => if(!j.endsWith(".jar")) sys.error(s"Provided file $j is not jar not tasty file") )
165159

160+
def listTastyFiles(f: File): Seq[String] =
161+
val (files, dirs) = Option(f.listFiles()).toArray.flatten.partition(_.isFile)
162+
ArraySeq.unsafeWrapArray(
163+
files.filter(_.getName.endsWith(".tasty")).map(_.toString) ++ dirs.flatMap(listTastyFiles)
164+
)
165+
val tastyFiles = providedTastyFiles ++ dirs.flatMap(listTastyFiles)
166166

167-
def listTastyFiles(f: File): Seq[String] =
168-
val (files, dirs) = f.listFiles().partition(_.isFile)
169-
ArraySeq.unsafeWrapArray(
170-
files.filter(_.getName.endsWith(".tasty")).map(_.toString) ++ dirs.flatMap(listTastyFiles)
171-
)
172-
val tastyFiles = providedTastyFiles ++ dirs.flatMap(listTastyFiles)
167+
val config = DocConfiguration.Standalone(parsedArgs, tastyFiles, jars)
173168

174-
val config = DocConfiguration.Standalone(parsedArgs, tastyFiles, jars)
169+
if (parsedArgs.output.exists()) IO.delete(parsedArgs.output)
175170

176-
if (parsedArgs.output.exists()) IO.delete(parsedArgs.output)
171+
new DokkaGenerator(new DottyDokkaConfig(config), DokkaConsoleLogger.INSTANCE).generate()
172+
println("Done")
177173

178-
new DokkaGenerator(new DottyDokkaConfig(config), DokkaConsoleLogger.INSTANCE).generate()
179174

180-
println("Done")
175+
def main(args: Array[String]): Unit =
176+
try
177+
val argDefinition = new Scala3Args(sys.error)
178+
main(argDefinition.extract(args.toList))
179+
// Sometimes jvm is hanging, so we want to be sure that we force shout down the jvm
180+
sys.exit(0)
181181
catch
182182
case a: Exception =>
183183
a.printStackTrace()
184184
// Sometimes jvm is hanging, so we want to be sure that we force shout down the jvm
185185
sys.exit(1)
186186

187-
def main(args: Array[String]): Unit =
188-
val argDefinition = new Scala3Args(sys.error) {
189-
protected def defaultName(): String = sys.error(s"Argument '${name.name}' is required")
190-
protected def defaultTastFiles(): List[File] = sys.error(s"Argument '${tastyRoots.name}' is required")
191-
protected def defaultDest(): File = sys.error(s"Argument '${dest.name}' is required")
192-
}
193-
main(argDefinition.extract(args.toList))
194-
// Sometimes jvm is hanging, so we want to be sure that we force shout down the jvm
195-
sys.exit(0)
196-
197187

scala3doc/src/dotty/tools/dottydoc/Main.scala

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,13 @@ object Main extends Driver {
3333
* how they're split).
3434
*/
3535
override def process(args: Array[String], rootCtx: Context): Reporter = {
36+
given Context = rootCtx
3637

38+
val argDefinition = new Scala3Args(error(_))
39+
val parsedArgs = argDefinition.extract(args.toList)
3740

38-
val (filesToCompile, ctx) = setup(args, rootCtx)
39-
given Context = ctx
41+
dotty.dokka.Main.main(parsedArgs)
4042

41-
val argDefinition = new Scala3Args(error(_)) {
42-
protected def defaultName(): String = ctx.settings.projectName.value
43-
protected def defaultTastFiles(): List[File] = Nil
44-
protected def defaultDest(): File = File(ctx.settings.outputDir.value.toString)
45-
}
46-
47-
val config = DocConfiguration.Sbt(argDefinition.extract(args.toList), filesToCompile, ctx)
48-
val dokkaCfg = new DottyDokkaConfig(config)
49-
new DokkaGenerator(dokkaCfg, DokkaConsoleLogger.INSTANCE).generate()
5043

5144
rootCtx.reporter
5245
}

0 commit comments

Comments
 (0)