Skip to content

Commit 022835f

Browse files
committed
Scala doc support for MillSome of mill projects are added to community build as well.
1 parent 7b11f0e commit 022835f

File tree

4 files changed

+45
-33
lines changed

4 files changed

+45
-33
lines changed

community-build/src/scala/dotty/communitybuild/Main.scala

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,34 @@ object Main:
1919
e.printStackTrace()
2020
Nil
2121

22-
def withProjects[T](names: Seq[String], opName: String)(op: CommunityProject => Unit): Unit =
22+
def withProjects[T](names: Seq[String], opName: String)(op: CommunityProject => T): Seq[T] =
2323
val missing = names.filterNot(projectMap.contains)
2424
if missing.nonEmpty then
25-
println(s"Missing projects: ${missing.mkString(", ")}. All projects: ${allProjects.mkString(", ")}")
25+
val allNames = allProjects.map(_.project).mkString(", ")
26+
println(s"Missing projects: ${missing.mkString(", ")}. All projects: $allNames")
2627
sys.exit(1)
2728

28-
val failed = names.flatMap( o =>
29+
val (failed, completed) = names.flatMap(projectMap.apply).partitionMap( o =>
2930
try
30-
op(projectMap(o))
31-
None
31+
Right(op(o))
3232
catch case e: Throwable =>
3333
e.printStackTrace()
34-
Some(o)
34+
Left(o)
3535
)
3636

3737
if failed.nonEmpty then
3838
println(s"$opName failed for ${failed.mkString(", ")}")
3939
sys.exit(1)
4040

41+
completed
42+
4143
/** Allows running various commands on community build projects. */
4244
def main(args: Array[String]): Unit =
4345
args.toList match
44-
case "publish" :: names =>
46+
case "publish" :: names if names.nonEmpty =>
4547
withProjects(names, "Publishing")(_.publish())
4648

47-
case "build" :: names =>
49+
case "build" :: names if names.nonEmpty =>
4850
withProjects(names, "Build")(_.build())
4951

5052
case "doc" :: "all" :: destStr :: Nil =>
@@ -90,16 +92,13 @@ object Main:
9092
sys.exit(1)
9193

9294
case "doc" :: names if names.nonEmpty =>
93-
val missing = names.filterNot(projectMap.contains)
94-
if missing.nonEmpty then
95-
println(s"Missing projects: ${missing.mkString(", ")}. All projects: ${allProjects.mkString(", ")}")
96-
sys.exit(1)
97-
98-
val failed = names.filter{ p =>
99-
val docsRoots = generateDocs(projectMap(p))
95+
val failed = withProjects(names, "Documenting"){ p =>
96+
val docsRoots = generateDocs(p)
97+
println(docsRoots)
10098
if docsRoots.nonEmpty then println(s"Docs for $p generated in $docsRoots")
101-
docsRoots.isEmpty
102-
}
99+
if docsRoots.isEmpty then Some(p.project) else None
100+
}.flatten
101+
103102
if failed.nonEmpty then
104103
println(s"Documentation not found for ${failed.mkString(", ")}")
105104
sys.exit(1)

community-build/src/scala/dotty/communitybuild/projects.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,15 @@ end CommunityProject
9393
final case class MillCommunityProject(
9494
project: String,
9595
baseCommand: String,
96-
dependencies: List[CommunityProject] = Nil) extends CommunityProject:
96+
dependencies: List[CommunityProject] = Nil,
97+
ignoreDocs: Boolean = false,
98+
) extends CommunityProject:
9799
override val binaryName: String = "./mill"
98100
override val testCommand = s"$baseCommand.test"
99101
override val publishCommand = s"$baseCommand.publishLocal"
100102
override val docCommand = null
103+
// uncomment once mill is released
104+
// if ignoreDocs then null else s"$baseCommand.docJar"
101105
override val runCommandsArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
102106

103107
final case class SbtCommunityProject(
@@ -198,11 +202,13 @@ object projects:
198202
lazy val utest = MillCommunityProject(
199203
project = "utest",
200204
baseCommand = s"utest.jvm[$compilerVersion]",
205+
ignoreDocs = true
201206
)
202207

203208
lazy val sourcecode = MillCommunityProject(
204209
project = "sourcecode",
205210
baseCommand = s"sourcecode.jvm[$compilerVersion]",
211+
ignoreDocs = true
206212
)
207213

208214
lazy val oslib = MillCommunityProject(
@@ -214,7 +220,8 @@ object projects:
214220
lazy val oslibWatch = MillCommunityProject(
215221
project = "os-lib",
216222
baseCommand = s"os.watch[$compilerVersion]",
217-
dependencies = List(utest, sourcecode)
223+
dependencies = List(utest, sourcecode),
224+
ignoreDocs = true
218225
)
219226

220227
lazy val ujson = MillCommunityProject(
@@ -244,13 +251,15 @@ object projects:
244251
lazy val fansi = MillCommunityProject(
245252
project = "fansi",
246253
baseCommand = s"fansi.jvm[$compilerVersion]",
247-
dependencies = List(utest, sourcecode)
254+
dependencies = List(utest, sourcecode),
255+
ignoreDocs = true
248256
)
249257

250258
lazy val pprint = MillCommunityProject(
251259
project = "PPrint",
252260
baseCommand = s"pprint.jvm[$compilerVersion]",
253-
dependencies = List(fansi)
261+
dependencies = List(fansi),
262+
ignoreDocs = true
254263
)
255264

256265
lazy val requests = MillCommunityProject(
@@ -705,4 +714,4 @@ def allProjects = List(
705714
projects.perspective,
706715
)
707716

708-
lazy val projectMap = allProjects.map(p => p.project -> p).toMap
717+
lazy val projectMap = allProjects.groupBy(_.project)

project/Build.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,8 @@ object Build {
11601160
val generateTestcasesDocumentation = taskKey[Unit]("Generate documentation for testcases, usefull for debugging tests")
11611161
lazy val `scaladoc` = project.in(file("scaladoc")).asScaladoc
11621162
lazy val `scaladoc-nonBootstrapped` = project.in(file("scaladoc")).scaladocBasic(NonBootstrapped).settings(
1163+
// Unit tests in scaladoc depends on scaladoc-testcases
1164+
// we do not want to just cross compile them with bootstrapped and unbootstrapped compiler
11631165
sources.in(Test) := Nil
11641166
)
11651167

scaladoc/src/dotty/tools/scaladoc/Main.scala

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ import dotty.tools.dotc.config.CommonScalaSettings
1313
import dotty.tools.dotc.core.Contexts._
1414

1515
/** Main class for the doctool when used from cli. */
16+
class Main:
17+
// This is an entry point for Mill or other tools in the future since it provides easy access to reporter
18+
def run(args: Array[String]) = Scaladoc.run(args, (new ContextBase).initialCtx)
19+
1620
object Main:
1721
def main(args: Array[String]): Unit =
18-
try
19-
// We should create our own context here...
20-
val reporter = Scaladoc.run(args, (new ContextBase).initialCtx)
22+
try
23+
// We should create our own context here...
24+
val reporter = Main().run(args)
25+
// Sometimes jvm is hanging, so we want to be sure that we force shout down the jvm
26+
sys.exit(if reporter.hasErrors then 1 else 0)
27+
catch
28+
case a: Exception =>
29+
a.printStackTrace()
2130
// Sometimes jvm is hanging, so we want to be sure that we force shout down the jvm
22-
sys.exit(if reporter.hasErrors then 1 else 0)
23-
catch
24-
case a: Exception =>
25-
a.printStackTrace()
26-
// Sometimes jvm is hanging, so we want to be sure that we force shout down the jvm
27-
sys.exit(1)
28-
29-
31+
sys.exit(1)

0 commit comments

Comments
 (0)