Skip to content

Commit 955e16e

Browse files
abgruszeckiromanowski
authored andcommitted
Allow documenting community build projects
1 parent 0f0137e commit 955e16e

File tree

3 files changed

+88
-12
lines changed

3 files changed

+88
-12
lines changed
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package dotty.communitybuild
22

33
object Main {
4-
/** Builds stdlib.
5-
*
6-
* Output is available in build/pack/lib directory in stdlib project.
7-
*
8-
* In the future, we allow building different projects based on arguments,
9-
* but for now stdlib is the only usecase.
10-
*/
4+
/** Allows running various commands on community build projects. */
115
def main(args: Array[String]): Unit =
12-
projects.stdLib213.publish()
6+
if args.length != 2 then
7+
println("USAGE: <COMMAND> <PROJECT NAME>")
8+
println("COMMAND is one of: publish doc")
9+
println("Available projects are:")
10+
projects.projectMap.keys.foreach { k =>
11+
println(s"\t$k")
12+
}
13+
sys.exit(0)
14+
15+
val Array(cmd, proj) = args
16+
cmd match {
17+
case "doc" => projects(proj).doc()
18+
case "publish" => projects(proj).publish()
19+
}
1320
}

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

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,43 @@ def exec(projectDir: Path, binary: String, arguments: String*): Int =
2929
val exitCode = process.waitFor()
3030
exitCode
3131

32-
3332
sealed trait CommunityProject:
3433
private var published = false
3534

3635
val project: String
3736
val testCommand: String
3837
val publishCommand: String
38+
val docCommand: String
3939
val dependencies: List[CommunityProject]
4040
val binaryName: String
4141
val runCommandsArgs: List[String] = Nil
4242

4343
final val projectDir = communitybuildDir.resolve("community-projects").resolve(project)
4444

45+
final def publishDependencies(): Unit =
46+
dependencies.foreach(_.publish())
47+
4548
/** Publish this project to the local Maven repository */
4649
final def publish(): Unit =
4750
if !published then
48-
dependencies.foreach(_.publish())
51+
publishDependencies()
4952
log(s"Publishing $project")
5053
if publishCommand eq null then
5154
throw RuntimeException(s"Publish command is not specified for $project. Project details:\n$this")
5255
val exitCode = exec(projectDir, binaryName, (runCommandsArgs :+ publishCommand): _*)
5356
if exitCode != 0 then
5457
throw RuntimeException(s"Publish command exited with code $exitCode for project $project. Project details:\n$this")
5558
published = true
59+
60+
final def doc(): Unit =
61+
publishDependencies()
62+
log(s"Documenting $project")
63+
if docCommand eq null then
64+
throw RuntimeException(s"Doc command is not specified for $project. Project details:\n$this")
65+
val exitCode = exec(projectDir, binaryName, (runCommandsArgs :+ docCommand): _*)
66+
if exitCode != 0 then
67+
throw RuntimeException(s"Doc command exited with code $exitCode for project $project. Project details:\n$this")
68+
5669
end CommunityProject
5770

5871
final case class MillCommunityProject(
@@ -62,6 +75,7 @@ final case class MillCommunityProject(
6275
override val binaryName: String = "./mill"
6376
override val testCommand = s"$baseCommand.test"
6477
override val publishCommand = s"$baseCommand.publishLocal"
78+
override val docCommand = null
6579
override val runCommandsArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
6680

6781
final case class SbtCommunityProject(
@@ -70,7 +84,9 @@ final case class SbtCommunityProject(
7084
extraSbtArgs: List[String] = Nil,
7185
forceUpgradeSbtScalajsPlugin: Boolean = false,
7286
dependencies: List[CommunityProject] = Nil,
73-
sbtPublishCommand: String = null) extends CommunityProject:
87+
sbtPublishCommand: String = null,
88+
sbtDocCommand: String = null
89+
) extends CommunityProject:
7490
override val binaryName: String = "sbt"
7591

7692
val dependencyOverrides = List(
@@ -85,7 +101,10 @@ final case class SbtCommunityProject(
85101
++ s"++$compilerVersion!; "
86102

87103
override val testCommand = s"$baseCommand$sbtTestCommand"
88-
override val publishCommand = s"$baseCommand$sbtPublishCommand"
104+
override val publishCommand = if sbtPublishCommand eq null then null else s"$baseCommand$sbtPublishCommand"
105+
override val docCommand =
106+
if sbtDocCommand eq null then null else
107+
s"$baseCommand;set every useScala3doc := true $sbtDocCommand"
89108

90109
override val runCommandsArgs: List[String] =
91110
// Run the sbt command with the compiler version and sbt plugin set in the build
@@ -102,6 +121,7 @@ final case class SbtCommunityProject(
102121
) ++ scalaJSPluginArgs
103122

104123
object projects:
124+
105125
lazy val utest = MillCommunityProject(
106126
project = "utest",
107127
baseCommand = s"utest.jvm[$compilerVersion]",
@@ -213,6 +233,7 @@ object projects:
213233
lazy val betterfiles = SbtCommunityProject(
214234
project = "betterfiles",
215235
sbtTestCommand = "dotty-community-build/compile",
236+
sbtDocCommand = ";core/doc ;akka/doc ;shapelessScanner/doc"
216237
)
217238

218239
lazy val ScalaPB = SbtCommunityProject(
@@ -310,6 +331,7 @@ object projects:
310331
lazy val scalaz = SbtCommunityProject(
311332
project = "scalaz",
312333
sbtTestCommand = "rootJVM/test",
334+
// has doc/sources set to Nil
313335
dependencies = List(scalacheck)
314336
)
315337

@@ -339,5 +361,50 @@ object projects:
339361
project = "scala-collection-compat",
340362
sbtTestCommand = "compat30/test",
341363
)
364+
365+
val projectMap = Map(
366+
"utest" -> utest,
367+
"sourcecode" -> sourcecode,
368+
"oslib" -> oslib,
369+
"oslibWatch" -> oslibWatch,
370+
"ujson" -> ujson,
371+
"upickle" -> upickle,
372+
"upickleCore" -> upickleCore,
373+
"geny" -> geny,
374+
"fansi" -> fansi,
375+
"pprint" -> pprint,
376+
"requests" -> requests,
377+
"scas" -> scas,
378+
"intent" -> intent,
379+
"algebra" -> algebra,
380+
"scalacheck" -> scalacheck,
381+
"scalatest" -> scalatest,
382+
"scalatestplusScalacheck" -> scalatestplusScalacheck,
383+
"scalaXml" -> scalaXml,
384+
"scopt" -> scopt,
385+
"scalap" -> scalap,
386+
"squants" -> squants,
387+
"betterfiles" -> betterfiles,
388+
"ScalaPB" -> ScalaPB,
389+
"minitest" -> minitest,
390+
"fastparse" -> fastparse,
391+
"stdLib213" -> stdLib213,
392+
"shapeless" -> shapeless,
393+
"xmlInterpolator" -> xmlInterpolator,
394+
"effpi" -> effpi,
395+
"sconfig" -> sconfig,
396+
"zio" -> zio,
397+
"munit" -> munit,
398+
"scodecBits" -> scodecBits,
399+
"scodec" -> scodec,
400+
"scalaParserCombinators" -> scalaParserCombinators,
401+
"dottyCpsAsync" -> dottyCpsAsync,
402+
"scalaz" -> scalaz,
403+
"endpoints4s" -> endpoints4s,
404+
"catsEffect2" -> catsEffect2,
405+
"catsEffect3" -> catsEffect3,
406+
"scalaCollectionCompat" -> scalaCollectionCompat
407+
)
408+
def apply(key: String) = projectMap(key)
342409

343410
end projects

project/Build.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ object Build {
13021302
(publishLocal in `tasty-core-bootstrapped`).value
13031303
(publishLocal in `scala3-library-bootstrapped`).value
13041304
(publishLocal in `scala3-doc-bootstrapped`).value
1305+
(publishLocal in `scala3doc`).value
13051306
(publishLocal in `scala3-compiler-bootstrapped`).value
13061307
(publishLocal in `sbt-dotty`).value
13071308
(publishLocal in `scala3-bootstrapped`).value
@@ -1320,6 +1321,7 @@ object Build {
13201321
TestFrameworks.JUnit,
13211322
"--include-categories=dotty.communitybuild.TestCategory",
13221323
),
1324+
Compile/run := (Compile/run).dependsOn(prepareCommunityBuild).evaluated,
13231325
(Test / testOnly) := ((Test / testOnly) dependsOn prepareCommunityBuild).evaluated,
13241326
(Test / test ) := ((Test / test ) dependsOn prepareCommunityBuild).value,
13251327
javaOptions ++= {

0 commit comments

Comments
 (0)