Skip to content

Commit e978efe

Browse files
committed
Move community build projects to normal sources
1 parent 09eaed7 commit e978efe

File tree

2 files changed

+302
-297
lines changed

2 files changed

+302
-297
lines changed
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
package dotty.communitybuild
2+
3+
import java.nio.file._
4+
import java.io.{PrintWriter, File}
5+
import java.nio.charset.StandardCharsets.UTF_8
6+
7+
lazy val communitybuildDir: Path = Paths.get(sys.props("user.dir"))
8+
9+
lazy val compilerVersion: String =
10+
val file = communitybuildDir.resolve("dotty-bootstrapped.version")
11+
new String(Files.readAllBytes(file), UTF_8)
12+
13+
lazy val sbtPluginFilePath: String =
14+
// Workaround for https://github.com/sbt/sbt/issues/4395
15+
new File(sys.props("user.home") + "/.sbt/1.0/plugins").mkdirs()
16+
communitybuildDir.resolve("sbt-dotty-sbt").toAbsolutePath().toString()
17+
18+
def log(msg: String) = println(Console.GREEN + msg + Console.RESET)
19+
20+
/** Executes shell command, returns false in case of error. */
21+
def exec(projectDir: Path, binary: String, arguments: String*): Int =
22+
val command = binary +: arguments
23+
log(command.mkString(" "))
24+
val builder = new ProcessBuilder(command: _*).directory(projectDir.toFile).inheritIO()
25+
val process = builder.start()
26+
val exitCode = process.waitFor()
27+
exitCode
28+
29+
30+
sealed trait CommunityProject:
31+
private var published = false
32+
33+
val project: String
34+
val testCommand: String
35+
val publishCommand: String
36+
val dependencies: List[CommunityProject]
37+
val binaryName: String
38+
val runCommandsArgs: List[String] = Nil
39+
40+
final val projectDir = communitybuildDir.resolve("community-projects").resolve(project)
41+
42+
/** Publish this project to the local Maven repository */
43+
final def publish(): Unit =
44+
if !published then
45+
log(s"Publishing $project")
46+
if publishCommand eq null then
47+
throw RuntimeException(s"Publish command is not specified for $project. Project details:\n$this")
48+
val exitCode = exec(projectDir, binaryName, (runCommandsArgs :+ publishCommand): _*)
49+
if exitCode != 0 then
50+
throw RuntimeException(s"Publish command exited with code $exitCode for project $project. Project details:\n$this")
51+
published = true
52+
end CommunityProject
53+
54+
final case class MillCommunityProject(
55+
project: String,
56+
baseCommand: String,
57+
dependencies: List[CommunityProject] = Nil) extends CommunityProject:
58+
override val binaryName: String = "./mill"
59+
override val testCommand = s"$baseCommand.test"
60+
override val publishCommand = s"$baseCommand.publishLocal"
61+
override val runCommandsArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
62+
63+
final case class SbtCommunityProject(
64+
project: String,
65+
sbtTestCommand: String,
66+
extraSbtArgs: List[String] = Nil,
67+
dependencies: List[CommunityProject] = Nil,
68+
sbtPublishCommand: String = null) extends CommunityProject:
69+
override val binaryName: String = "sbt"
70+
private val baseCommand = s";clean ;set logLevel in Global := Level.Error ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! "
71+
override val testCommand = s"$baseCommand$sbtTestCommand"
72+
override val publishCommand = s"$baseCommand$sbtPublishCommand"
73+
74+
override val runCommandsArgs: List[String] =
75+
// Run the sbt command with the compiler version and sbt plugin set in the build
76+
val sbtProps = Option(System.getProperty("sbt.ivy.home")) match
77+
case Some(ivyHome) => List(s"-Dsbt.ivy.home=$ivyHome")
78+
case _ => Nil
79+
extraSbtArgs ++ sbtProps ++ List(
80+
"-sbt-version", "1.3.8",
81+
"-Dsbt.supershell=false",
82+
s"--addPluginSbtFile=$sbtPluginFilePath")
83+
84+
object projects:
85+
86+
lazy val utest = MillCommunityProject(
87+
project = "utest",
88+
baseCommand = s"utest.jvm[$compilerVersion]",
89+
)
90+
91+
lazy val sourcecode = MillCommunityProject(
92+
project = "sourcecode",
93+
baseCommand = s"sourcecode.jvm[$compilerVersion]",
94+
)
95+
96+
lazy val oslib = MillCommunityProject(
97+
project = "os-lib",
98+
baseCommand = s"os[$compilerVersion]",
99+
dependencies = List(utest, sourcecode)
100+
)
101+
102+
lazy val oslibWatch = MillCommunityProject(
103+
project = "os-lib",
104+
baseCommand = s"os.watch[$compilerVersion]",
105+
dependencies = List(utest, sourcecode)
106+
)
107+
108+
lazy val ujson = MillCommunityProject(
109+
project = "upickle",
110+
baseCommand = s"ujson.jvm[$compilerVersion]",
111+
dependencies = List(scalatest, scalacheck, scalatestplusScalacheck, geny)
112+
)
113+
114+
lazy val upickle = MillCommunityProject(
115+
project = "upickle",
116+
baseCommand = s"upickle.jvm[$compilerVersion]",
117+
dependencies = List(scalatest, scalacheck, scalatestplusScalacheck, geny, utest)
118+
)
119+
120+
lazy val geny = MillCommunityProject(
121+
project = "geny",
122+
baseCommand = s"geny.jvm[$compilerVersion]",
123+
dependencies = List(utest)
124+
)
125+
126+
lazy val scas = MillCommunityProject(
127+
project = "scas",
128+
baseCommand = "scas.application"
129+
)
130+
131+
lazy val intent = SbtCommunityProject(
132+
project = "intent",
133+
sbtTestCommand = "test",
134+
)
135+
136+
lazy val algebra = SbtCommunityProject(
137+
project = "algebra",
138+
sbtTestCommand = "coreJVM/compile",
139+
)
140+
141+
lazy val scalacheck = SbtCommunityProject(
142+
project = "scalacheck",
143+
sbtTestCommand = "jvm/test",
144+
sbtPublishCommand = ";set jvm/publishArtifact in (Compile, packageDoc) := false ;jvm/publishLocal"
145+
)
146+
147+
lazy val scalatest = SbtCommunityProject(
148+
project = "scalatest",
149+
sbtTestCommand = ";scalacticDotty/clean;scalacticTestDotty/test;scalatestTestDotty/test",
150+
sbtPublishCommand = ";scalacticDotty/publishLocal; scalatestDotty/publishLocal"
151+
)
152+
153+
lazy val scalatestplusScalacheck = SbtCommunityProject(
154+
project = "scalatestplus-scalacheck",
155+
sbtTestCommand = "scalatestPlusScalaCheckJVM/test",
156+
sbtPublishCommand = "scalatestPlusScalaCheckJVM/publishLocal",
157+
dependencies = List(scalatest, scalacheck)
158+
)
159+
160+
lazy val scalaXml = SbtCommunityProject(
161+
project = "scala-xml",
162+
sbtTestCommand = "xml/test",
163+
)
164+
165+
lazy val scopt = SbtCommunityProject(
166+
project = "scopt",
167+
sbtTestCommand = "scoptJVM/compile",
168+
)
169+
170+
lazy val scalap = SbtCommunityProject(
171+
project = "scalap",
172+
sbtTestCommand = "scalap/compile",
173+
)
174+
175+
lazy val squants = SbtCommunityProject(
176+
project = "squants",
177+
sbtTestCommand = "squantsJVM/compile",
178+
)
179+
180+
lazy val betterfiles = SbtCommunityProject(
181+
project = "betterfiles",
182+
sbtTestCommand = "dotty-community-build/compile",
183+
)
184+
185+
lazy val ScalaPB = SbtCommunityProject(
186+
project = "ScalaPB",
187+
sbtTestCommand = "dotty-community-build/compile",
188+
)
189+
190+
lazy val minitest = SbtCommunityProject(
191+
project = "minitest",
192+
sbtTestCommand = "dotty-community-build/compile",
193+
)
194+
195+
lazy val fastparse = SbtCommunityProject(
196+
project = "fastparse",
197+
sbtTestCommand = "dotty-community-build/compile;dotty-community-build/test:compile",
198+
)
199+
200+
lazy val stdLib213 = SbtCommunityProject(
201+
project = "stdLib213",
202+
sbtTestCommand = """;set scalacOptions in Global += "-Yerased-terms" ;library/compile""",
203+
extraSbtArgs = List("-Dscala.build.compileWithDotty=true")
204+
)
205+
206+
lazy val shapeless = SbtCommunityProject(
207+
project = "shapeless",
208+
sbtTestCommand = "test",
209+
)
210+
211+
lazy val xmlInterpolator = SbtCommunityProject(
212+
project = "xml-interpolator",
213+
sbtTestCommand = "test",
214+
)
215+
216+
lazy val effpi = SbtCommunityProject(
217+
project = "effpi",
218+
// We set `useEffpiPlugin := false` because we don't want to run their
219+
// compiler plugin since it relies on external binaries (from the model
220+
// checker mcrl2), however we do compile the compiler plugin.
221+
222+
// We have to drop the plugin and some akka tests for now, the plugin depends on github.com/bmc/scalasti which
223+
// has not been updated since 2018, so no 2.13 compat. Some akka tests are dropped due to MutableBehaviour being
224+
// dropped in the 2.13 compatible release
225+
226+
// sbtTestCommand = ";set ThisBuild / useEffpiPlugin := false; effpi/test:compile; plugin/test:compile; benchmarks/test:compile; examples/test:compile; pluginBenchmarks/test:compile",
227+
228+
sbtTestCommand = ";set ThisBuild / useEffpiPlugin := false; effpi/test:compile; benchmarks/test:compile; examples/test:compile; pluginBenchmarks/test:compile",
229+
)
230+
231+
// TODO @odersky? It got broken by #5458
232+
// val pdbp = test(
233+
// project = "pdbp",
234+
// sbtTestCommand = "compile",
235+
// )
236+
237+
lazy val sconfig = SbtCommunityProject(
238+
project = "sconfig",
239+
sbtTestCommand = "sconfigJVM/test",
240+
)
241+
242+
lazy val zio = SbtCommunityProject(
243+
project = "zio",
244+
sbtTestCommand = "testJVMDotty",
245+
)
246+
247+
lazy val munit = SbtCommunityProject(
248+
project = "munit",
249+
sbtTestCommand = "testsJVM/test",
250+
)
251+
252+
lazy val scodecBits = SbtCommunityProject(
253+
project = "scodec-bits",
254+
sbtTestCommand = "coreJVM/test",
255+
sbtPublishCommand = "coreJVM/publishLocal",
256+
dependencies = List(scalatest, scalacheck, scalatestplusScalacheck)
257+
)
258+
259+
lazy val scodec = SbtCommunityProject(
260+
project = "scodec",
261+
sbtTestCommand = "unitTests/test",
262+
dependencies = List(scalatest, scalacheck, scalatestplusScalacheck, scodecBits)
263+
)
264+
265+
lazy val scalaParserCombinators = SbtCommunityProject(
266+
project = "scala-parser-combinators",
267+
sbtTestCommand = "parserCombinators/test",
268+
)
269+
270+
lazy val dottyCpsAsync = SbtCommunityProject(
271+
project = "dotty-cps-async",
272+
sbtTestCommand = "test",
273+
)
274+
275+
lazy val scalaz = SbtCommunityProject(
276+
project = "scalaz",
277+
sbtTestCommand = "rootJVM/test",
278+
dependencies = List(scalacheck)
279+
)
280+
281+
lazy val endpoints4s = SbtCommunityProject(
282+
project = "endpoints4s",
283+
sbtTestCommand = ";json-schemaJVM/compile;algebraJVM/compile;openapiJVM/compile;http4s-server/compile;http4s-client/compile;play-server/compile;play-client/compile;akka-http-server/compile;akka-http-client/compile"
284+
)
285+
286+
lazy val catsEffect2 = SbtCommunityProject(
287+
project = "cats-effect-2",
288+
sbtTestCommand = "test"
289+
)
290+
291+
lazy val catsEffect3 = SbtCommunityProject(
292+
project = "cats-effect-3",
293+
sbtTestCommand = "testIfRelevant"
294+
)
295+
296+
end projects

0 commit comments

Comments
 (0)