Skip to content

Commit 6039f71

Browse files
committed
Move community build projects to normal sources
1 parent 826a089 commit 6039f71

File tree

2 files changed

+326
-322
lines changed

2 files changed

+326
-322
lines changed
Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
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+
dependencies.foreach(_.publish())
46+
log(s"Publishing $project")
47+
if publishCommand eq null then
48+
throw RuntimeException(s"Publish command is not specified for $project. Project details:\n$this")
49+
val exitCode = exec(projectDir, binaryName, (runCommandsArgs :+ publishCommand): _*)
50+
if exitCode != 0 then
51+
throw RuntimeException(s"Publish command exited with code $exitCode for project $project. Project details:\n$this")
52+
published = true
53+
end CommunityProject
54+
55+
final case class MillCommunityProject(
56+
project: String,
57+
baseCommand: String,
58+
dependencies: List[CommunityProject] = Nil) extends CommunityProject:
59+
override val binaryName: String = "./mill"
60+
override val testCommand = s"$baseCommand.test"
61+
override val publishCommand = s"$baseCommand.publishLocal"
62+
override val runCommandsArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
63+
64+
final case class SbtCommunityProject(
65+
project: String,
66+
sbtTestCommand: String,
67+
extraSbtArgs: List[String] = Nil,
68+
dependencies: List[CommunityProject] = Nil,
69+
sbtPublishCommand: String = null) extends CommunityProject:
70+
override val binaryName: String = "sbt"
71+
private val baseCommand = s";clean ;set logLevel in Global := Level.Error ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! "
72+
override val testCommand = s"$baseCommand$sbtTestCommand"
73+
override val publishCommand = s"$baseCommand$sbtPublishCommand"
74+
75+
override val runCommandsArgs: List[String] =
76+
// Run the sbt command with the compiler version and sbt plugin set in the build
77+
val sbtProps = Option(System.getProperty("sbt.ivy.home")) match
78+
case Some(ivyHome) => List(s"-Dsbt.ivy.home=$ivyHome")
79+
case _ => Nil
80+
extraSbtArgs ++ sbtProps ++ List(
81+
"-sbt-version", "1.3.8",
82+
"-Dsbt.supershell=false",
83+
s"--addPluginSbtFile=$sbtPluginFilePath")
84+
85+
object projects:
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 upickleCore = MillCommunityProject(
121+
project = "upickle",
122+
baseCommand = s"core.jvm[$compilerVersion]",
123+
dependencies = List(scalatest, scalacheck, scalatestplusScalacheck, geny, utest)
124+
)
125+
126+
lazy val geny = MillCommunityProject(
127+
project = "geny",
128+
baseCommand = s"geny.jvm[$compilerVersion]",
129+
dependencies = List(utest)
130+
)
131+
132+
lazy val fansi = MillCommunityProject(
133+
project = "fansi",
134+
baseCommand = s"fansi.jvm[$compilerVersion]",
135+
dependencies = List(utest, sourcecode)
136+
)
137+
138+
lazy val pprint = MillCommunityProject(
139+
project = "PPrint",
140+
baseCommand = s"pprint.jvm[$compilerVersion]",
141+
dependencies = List(fansi)
142+
)
143+
144+
lazy val requests = MillCommunityProject(
145+
project = "requests-scala",
146+
baseCommand = s"requests[$compilerVersion]",
147+
dependencies = List(geny, utest, ujson, upickleCore)
148+
)
149+
150+
lazy val scas = MillCommunityProject(
151+
project = "scas",
152+
baseCommand = "scas.application"
153+
)
154+
155+
lazy val intent = SbtCommunityProject(
156+
project = "intent",
157+
sbtTestCommand = "test",
158+
)
159+
160+
lazy val algebra = SbtCommunityProject(
161+
project = "algebra",
162+
sbtTestCommand = "coreJVM/compile",
163+
)
164+
165+
lazy val scalacheck = SbtCommunityProject(
166+
project = "scalacheck",
167+
sbtTestCommand = "jvm/test",
168+
sbtPublishCommand = ";set jvm/publishArtifact in (Compile, packageDoc) := false ;jvm/publishLocal"
169+
)
170+
171+
lazy val scalatest = SbtCommunityProject(
172+
project = "scalatest",
173+
sbtTestCommand = ";scalacticDotty/clean;scalacticTestDotty/test;scalatestTestDotty/test",
174+
sbtPublishCommand = ";scalacticDotty/publishLocal; scalatestDotty/publishLocal"
175+
)
176+
177+
lazy val scalatestplusScalacheck = SbtCommunityProject(
178+
project = "scalatestplus-scalacheck",
179+
sbtTestCommand = "scalatestPlusScalaCheckJVM/test",
180+
sbtPublishCommand = "scalatestPlusScalaCheckJVM/publishLocal",
181+
dependencies = List(scalatest, scalacheck)
182+
)
183+
184+
lazy val scalaXml = SbtCommunityProject(
185+
project = "scala-xml",
186+
sbtTestCommand = "xml/test",
187+
)
188+
189+
lazy val scopt = SbtCommunityProject(
190+
project = "scopt",
191+
sbtTestCommand = "scoptJVM/compile",
192+
)
193+
194+
lazy val scalap = SbtCommunityProject(
195+
project = "scalap",
196+
sbtTestCommand = "scalap/compile",
197+
)
198+
199+
lazy val squants = SbtCommunityProject(
200+
project = "squants",
201+
sbtTestCommand = "squantsJVM/compile",
202+
)
203+
204+
lazy val betterfiles = SbtCommunityProject(
205+
project = "betterfiles",
206+
sbtTestCommand = "dotty-community-build/compile",
207+
)
208+
209+
lazy val ScalaPB = SbtCommunityProject(
210+
project = "ScalaPB",
211+
sbtTestCommand = "dotty-community-build/compile",
212+
)
213+
214+
lazy val minitest = SbtCommunityProject(
215+
project = "minitest",
216+
sbtTestCommand = "dotty-community-build/compile",
217+
)
218+
219+
lazy val fastparse = SbtCommunityProject(
220+
project = "fastparse",
221+
sbtTestCommand = "dotty-community-build/compile;dotty-community-build/test:compile",
222+
)
223+
224+
lazy val stdLib213 = SbtCommunityProject(
225+
project = "stdLib213",
226+
sbtTestCommand = """;set scalacOptions in Global += "-Yerased-terms" ;library/compile""",
227+
extraSbtArgs = List("-Dscala.build.compileWithDotty=true")
228+
)
229+
230+
lazy val shapeless = SbtCommunityProject(
231+
project = "shapeless",
232+
sbtTestCommand = "test",
233+
)
234+
235+
lazy val xmlInterpolator = SbtCommunityProject(
236+
project = "xml-interpolator",
237+
sbtTestCommand = "test",
238+
)
239+
240+
lazy val effpi = SbtCommunityProject(
241+
project = "effpi",
242+
// We set `useEffpiPlugin := false` because we don't want to run their
243+
// compiler plugin since it relies on external binaries (from the model
244+
// checker mcrl2), however we do compile the compiler plugin.
245+
246+
// We have to drop the plugin and some akka tests for now, the plugin depends on github.com/bmc/scalasti which
247+
// has not been updated since 2018, so no 2.13 compat. Some akka tests are dropped due to MutableBehaviour being
248+
// dropped in the 2.13 compatible release
249+
250+
// sbtTestCommand = ";set ThisBuild / useEffpiPlugin := false; effpi/test:compile; plugin/test:compile; benchmarks/test:compile; examples/test:compile; pluginBenchmarks/test:compile",
251+
252+
sbtTestCommand = ";set ThisBuild / useEffpiPlugin := false; effpi/test:compile; benchmarks/test:compile; examples/test:compile; pluginBenchmarks/test:compile",
253+
)
254+
255+
// TODO @odersky? It got broken by #5458
256+
// val pdbp = test(
257+
// project = "pdbp",
258+
// sbtTestCommand = "compile",
259+
// )
260+
261+
lazy val sconfig = SbtCommunityProject(
262+
project = "sconfig",
263+
sbtTestCommand = "sconfigJVM/test",
264+
)
265+
266+
lazy val zio = SbtCommunityProject(
267+
project = "zio",
268+
sbtTestCommand = "testJVMDotty",
269+
)
270+
271+
lazy val munit = SbtCommunityProject(
272+
project = "munit",
273+
sbtTestCommand = "testsJVM/test",
274+
)
275+
276+
lazy val scodecBits = SbtCommunityProject(
277+
project = "scodec-bits",
278+
sbtTestCommand = "coreJVM/test",
279+
sbtPublishCommand = "coreJVM/publishLocal",
280+
dependencies = List(scalatest, scalacheck, scalatestplusScalacheck)
281+
)
282+
283+
lazy val scodec = SbtCommunityProject(
284+
project = "scodec",
285+
sbtTestCommand = "unitTests/test",
286+
dependencies = List(scalatest, scalacheck, scalatestplusScalacheck, scodecBits)
287+
)
288+
289+
lazy val scalaParserCombinators = SbtCommunityProject(
290+
project = "scala-parser-combinators",
291+
sbtTestCommand = "parserCombinators/test",
292+
)
293+
294+
lazy val dottyCpsAsync = SbtCommunityProject(
295+
project = "dotty-cps-async",
296+
sbtTestCommand = "test",
297+
)
298+
299+
lazy val scalaz = SbtCommunityProject(
300+
project = "scalaz",
301+
sbtTestCommand = "rootJVM/test",
302+
dependencies = List(scalacheck)
303+
)
304+
305+
lazy val endpoints4s = SbtCommunityProject(
306+
project = "endpoints4s",
307+
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"
308+
)
309+
310+
lazy val catsEffect2 = SbtCommunityProject(
311+
project = "cats-effect-2",
312+
sbtTestCommand = "test"
313+
)
314+
315+
lazy val catsEffect3 = SbtCommunityProject(
316+
project = "cats-effect-3",
317+
sbtTestCommand = "testIfRelevant"
318+
)
319+
320+
end projects

0 commit comments

Comments
 (0)