Skip to content

Commit d32b17f

Browse files
abgruszeckiromanowski
authored andcommitted
Allow documenting community build projects
1 parent f57055c commit d32b17f

File tree

3 files changed

+88
-11
lines changed

3 files changed

+88
-11
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,37 @@ sealed trait CommunityProject:
4545
val project: String
4646
val testCommand: String
4747
val publishCommand: String
48+
val docCommand: String
4849
val dependencies: List[CommunityProject]
4950
val binaryName: String
5051
val runCommandsArgs: List[String] = Nil
5152

5253
final val projectDir = communitybuildDir.resolve("community-projects").resolve(project)
5354

55+
final def publishDependencies(): Unit =
56+
dependencies.foreach(_.publish())
57+
5458
/** Publish this project to the local Maven repository */
5559
final def publish(): Unit =
5660
if !published then
57-
dependencies.foreach(_.publish())
61+
publishDependencies()
5862
log(s"Publishing $project")
5963
if publishCommand eq null then
6064
throw RuntimeException(s"Publish command is not specified for $project. Project details:\n$this")
6165
val exitCode = exec(projectDir, binaryName, (runCommandsArgs :+ publishCommand): _*)
6266
if exitCode != 0 then
6367
throw RuntimeException(s"Publish command exited with code $exitCode for project $project. Project details:\n$this")
6468
published = true
69+
70+
final def doc(): Unit =
71+
publishDependencies()
72+
log(s"Documenting $project")
73+
if docCommand eq null then
74+
throw RuntimeException(s"Doc command is not specified for $project. Project details:\n$this")
75+
val exitCode = exec(projectDir, binaryName, (runCommandsArgs :+ docCommand): _*)
76+
if exitCode != 0 then
77+
throw RuntimeException(s"Doc command exited with code $exitCode for project $project. Project details:\n$this")
78+
6579
end CommunityProject
6680

6781
final case class MillCommunityProject(
@@ -71,14 +85,17 @@ final case class MillCommunityProject(
7185
override val binaryName: String = "./mill"
7286
override val testCommand = s"$baseCommand.test"
7387
override val publishCommand = s"$baseCommand.publishLocal"
88+
override val docCommand = null
7489
override val runCommandsArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
7590

7691
final case class SbtCommunityProject(
7792
project: String,
7893
sbtTestCommand: String,
7994
extraSbtArgs: List[String] = Nil,
8095
dependencies: List[CommunityProject] = Nil,
81-
sbtPublishCommand: String = null) extends CommunityProject:
96+
sbtPublishCommand: String = null,
97+
sbtDocCommand: String = null
98+
) extends CommunityProject:
8299
override val binaryName: String = "sbt"
83100

84101
// A project in the community build can depend on an arbitrary version of
@@ -105,7 +122,10 @@ final case class SbtCommunityProject(
105122
++ s"++$compilerVersion!; "
106123

107124
override val testCommand = s"$baseCommand$sbtTestCommand"
108-
override val publishCommand = s"$baseCommand$sbtPublishCommand"
125+
override val publishCommand = if sbtPublishCommand eq null then null else s"$baseCommand$sbtPublishCommand"
126+
override val docCommand =
127+
if sbtDocCommand eq null then null else
128+
s"$baseCommand;set every useScala3doc := true $sbtDocCommand"
109129

110130
override val runCommandsArgs: List[String] =
111131
// Run the sbt command with the compiler version and sbt plugin set in the build
@@ -119,6 +139,7 @@ final case class SbtCommunityProject(
119139
)
120140

121141
object projects:
142+
122143
lazy val utest = MillCommunityProject(
123144
project = "utest",
124145
baseCommand = s"utest.jvm[$compilerVersion]",
@@ -230,6 +251,7 @@ object projects:
230251
lazy val betterfiles = SbtCommunityProject(
231252
project = "betterfiles",
232253
sbtTestCommand = "dotty-community-build/compile",
254+
sbtDocCommand = ";core/doc ;akka/doc ;shapelessScanner/doc"
233255
)
234256

235257
lazy val ScalaPB = SbtCommunityProject(
@@ -331,6 +353,7 @@ object projects:
331353
lazy val scalaz = SbtCommunityProject(
332354
project = "scalaz",
333355
sbtTestCommand = "rootJVM/test",
356+
// has doc/sources set to Nil
334357
dependencies = List(scalacheck)
335358
)
336359

@@ -360,4 +383,49 @@ object projects:
360383
sbtTestCommand = "compat30/test",
361384
)
362385

386+
val projectMap = Map(
387+
"utest" -> utest,
388+
"sourcecode" -> sourcecode,
389+
"oslib" -> oslib,
390+
"oslibWatch" -> oslibWatch,
391+
"ujson" -> ujson,
392+
"upickle" -> upickle,
393+
"upickleCore" -> upickleCore,
394+
"geny" -> geny,
395+
"fansi" -> fansi,
396+
"pprint" -> pprint,
397+
"requests" -> requests,
398+
"scas" -> scas,
399+
"intent" -> intent,
400+
"algebra" -> algebra,
401+
"scalacheck" -> scalacheck,
402+
"scalatest" -> scalatest,
403+
"scalatestplusScalacheck" -> scalatestplusScalacheck,
404+
"scalaXml" -> scalaXml,
405+
"scopt" -> scopt,
406+
"scalap" -> scalap,
407+
"squants" -> squants,
408+
"betterfiles" -> betterfiles,
409+
"ScalaPB" -> ScalaPB,
410+
"minitest" -> minitest,
411+
"fastparse" -> fastparse,
412+
"stdLib213" -> stdLib213,
413+
"shapeless" -> shapeless,
414+
"xmlInterpolator" -> xmlInterpolator,
415+
"effpi" -> effpi,
416+
"sconfig" -> sconfig,
417+
"zio" -> zio,
418+
"munit" -> munit,
419+
"scodecBits" -> scodecBits,
420+
"scodec" -> scodec,
421+
"scalaParserCombinators" -> scalaParserCombinators,
422+
"dottyCpsAsync" -> dottyCpsAsync,
423+
"scalaz" -> scalaz,
424+
"endpoints4s" -> endpoints4s,
425+
"catsEffect2" -> catsEffect2,
426+
"catsEffect3" -> catsEffect3,
427+
"scalaCollectionCompat" -> scalaCollectionCompat
428+
)
429+
def apply(key: String) = projectMap(key)
430+
363431
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
@@ -1318,6 +1319,7 @@ object Build {
13181319
TestFrameworks.JUnit,
13191320
"--include-categories=dotty.communitybuild.TestCategory",
13201321
),
1322+
Compile/run := (Compile/run).dependsOn(prepareCommunityBuild).evaluated,
13211323
(Test / testOnly) := ((Test / testOnly) dependsOn prepareCommunityBuild).evaluated,
13221324
(Test / test ) := ((Test / test ) dependsOn prepareCommunityBuild).value,
13231325
javaOptions ++= {

0 commit comments

Comments
 (0)