Skip to content

Commit 78ca5b8

Browse files
abgruszeckiromanowski
authored andcommitted
Allow documenting community build projects
1 parent e41701f commit 78ca5b8

File tree

3 files changed

+88
-13
lines changed

3 files changed

+88
-13
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 & 5 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,11 +84,16 @@ 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
private val baseCommand = s";clean ;set logLevel in Global := Level.Error ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! "
7692
override val testCommand = s"$baseCommand$sbtTestCommand"
77-
override val publishCommand = s"$baseCommand$sbtPublishCommand"
93+
override val publishCommand = if sbtPublishCommand eq null then null else s"$baseCommand$sbtPublishCommand"
94+
override val docCommand =
95+
if sbtDocCommand eq null then null else
96+
s"$baseCommand;set every useScala3doc := true $sbtDocCommand"
7897

7998
override val runCommandsArgs: List[String] =
8099
// Run the sbt command with the compiler version and sbt plugin set in the build
@@ -86,11 +105,12 @@ final case class SbtCommunityProject(
86105
else Nil
87106
extraSbtArgs ++ sbtProps ++ List(
88107
"-sbt-version", "1.3.8",
89-
"-Dsbt.supershell=false",
108+
"-Dsbt.supershell=false",
90109
s"--addPluginSbtFile=$sbtPluginFilePath"
91110
) ++ scalaJSPluginArgs
92111

93112
object projects:
113+
94114
lazy val utest = MillCommunityProject(
95115
project = "utest",
96116
baseCommand = s"utest.jvm[$compilerVersion]",
@@ -212,6 +232,7 @@ object projects:
212232
lazy val betterfiles = SbtCommunityProject(
213233
project = "betterfiles",
214234
sbtTestCommand = "dotty-community-build/compile",
235+
sbtDocCommand = ";core/doc ;akka/doc ;shapelessScanner/doc"
215236
)
216237

217238
lazy val ScalaPB = SbtCommunityProject(
@@ -308,6 +329,7 @@ object projects:
308329
lazy val scalaz = SbtCommunityProject(
309330
project = "scalaz",
310331
sbtTestCommand = "rootJVM/test",
332+
// has doc/sources set to Nil
311333
dependencies = List(scalacheck)
312334
)
313335

@@ -333,4 +355,48 @@ object projects:
333355
dependencies = List(scalacheck)
334356
)
335357

358+
val projectMap = Map(
359+
"utest" -> utest,
360+
"sourcecode" -> sourcecode,
361+
"oslib" -> oslib,
362+
"oslibWatch" -> oslibWatch,
363+
"ujson" -> ujson,
364+
"upickle" -> upickle,
365+
"upickleCore" -> upickleCore,
366+
"geny" -> geny,
367+
"fansi" -> fansi,
368+
"pprint" -> pprint,
369+
"requests" -> requests,
370+
"scas" -> scas,
371+
"intent" -> intent,
372+
"algebra" -> algebra,
373+
"scalacheck" -> scalacheck,
374+
"scalatest" -> scalatest,
375+
"scalatestplusScalacheck" -> scalatestplusScalacheck,
376+
"scalaXml" -> scalaXml,
377+
"scopt" -> scopt,
378+
"scalap" -> scalap,
379+
"squants" -> squants,
380+
"betterfiles" -> betterfiles,
381+
"ScalaPB" -> ScalaPB,
382+
"minitest" -> minitest,
383+
"fastparse" -> fastparse,
384+
"stdLib213" -> stdLib213,
385+
"shapeless" -> shapeless,
386+
"xmlInterpolator" -> xmlInterpolator,
387+
"effpi" -> effpi,
388+
"sconfig" -> sconfig,
389+
"zio" -> zio,
390+
"munit" -> munit,
391+
"scodecBits" -> scodecBits,
392+
"scodec" -> scodec,
393+
"scalaParserCombinators" -> scalaParserCombinators,
394+
"dottyCpsAsync" -> dottyCpsAsync,
395+
"scalaz" -> scalaz,
396+
"endpoints4s" -> endpoints4s,
397+
"catsEffect2" -> catsEffect2,
398+
"catsEffect3" -> catsEffect3,
399+
)
400+
def apply(key: String) = projectMap(key)
401+
336402
end projects

project/Build.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ object Build {
12891289
(publishLocal in `tasty-core-bootstrapped`).value
12901290
(publishLocal in `scala3-library-bootstrapped`).value
12911291
(publishLocal in `scala3-doc-bootstrapped`).value
1292+
(publishLocal in `scala3doc`).value
12921293
(publishLocal in `scala3-compiler-bootstrapped`).value
12931294
(publishLocal in `sbt-dotty`).value
12941295
(publishLocal in `scala3-bootstrapped`).value
@@ -1307,6 +1308,7 @@ object Build {
13071308
TestFrameworks.JUnit,
13081309
"--include-categories=dotty.communitybuild.TestCategory",
13091310
),
1311+
Compile/run := (Compile/run).dependsOn(prepareCommunityBuild).evaluated,
13101312
(Test / testOnly) := ((Test / testOnly) dependsOn prepareCommunityBuild).evaluated,
13111313
(Test / test ) := ((Test / test ) dependsOn prepareCommunityBuild).value,
13121314
javaOptions ++= {

0 commit comments

Comments
 (0)