Skip to content

Commit ce88cae

Browse files
authored
Merge pull request #9908 from dotty-staging/reproducible-stdlib-artifact
Reproducible stdlib artifact
2 parents 4b8a1de + 2625f03 commit ce88cae

File tree

4 files changed

+341
-322
lines changed

4 files changed

+341
-322
lines changed

community-build/test/scala/dotty/communitybuild/readme.md renamed to community-build/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ To add your project to the community build you can follow these steps:
1414
2. Open a PR against this repo that:
1515
- Adds your project as a new git submodule
1616
- `git submodule add https://github.com/lampepfl/XYZ.git community-build/community-projects/XYZ`
17+
- Add the project to [projects.scala](https://github.com/lampepfl/dotty/blob/master/community-build/src/scala/dotty/communitybuild/projects.scala)
1718
- Adds a test in [CommunityBuildTest.scala](https://github.com/lampepfl/dotty/blob/master/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package dotty.communitybuild
2+
3+
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+
*/
11+
def main(args: Array[String]): Unit =
12+
projects.stdLib213.publish()
13+
}
Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
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+
extraSbtArgs = List("-Dscala.build.compileWithDotty=true"),
227+
sbtTestCommand = """library/compile""",
228+
sbtPublishCommand = """;set publishArtifact in (library, Compile, packageDoc) := false ;library/publishLocal""",
229+
)
230+
231+
lazy val shapeless = SbtCommunityProject(
232+
project = "shapeless",
233+
sbtTestCommand = "test",
234+
)
235+
236+
lazy val xmlInterpolator = SbtCommunityProject(
237+
project = "xml-interpolator",
238+
sbtTestCommand = "test",
239+
)
240+
241+
lazy val effpi = SbtCommunityProject(
242+
project = "effpi",
243+
// We set `useEffpiPlugin := false` because we don't want to run their
244+
// compiler plugin since it relies on external binaries (from the model
245+
// checker mcrl2), however we do compile the compiler plugin.
246+
247+
// We have to drop the plugin and some akka tests for now, the plugin depends on github.com/bmc/scalasti which
248+
// has not been updated since 2018, so no 2.13 compat. Some akka tests are dropped due to MutableBehaviour being
249+
// dropped in the 2.13 compatible release
250+
251+
// sbtTestCommand = ";set ThisBuild / useEffpiPlugin := false; effpi/test:compile; plugin/test:compile; benchmarks/test:compile; examples/test:compile; pluginBenchmarks/test:compile",
252+
253+
sbtTestCommand = ";set ThisBuild / useEffpiPlugin := false; effpi/test:compile; benchmarks/test:compile; examples/test:compile; pluginBenchmarks/test:compile",
254+
)
255+
256+
// TODO @odersky? It got broken by #5458
257+
// val pdbp = test(
258+
// project = "pdbp",
259+
// sbtTestCommand = "compile",
260+
// )
261+
262+
lazy val sconfig = SbtCommunityProject(
263+
project = "sconfig",
264+
sbtTestCommand = "sconfigJVM/test",
265+
)
266+
267+
lazy val zio = SbtCommunityProject(
268+
project = "zio",
269+
sbtTestCommand = "testJVMDotty",
270+
)
271+
272+
lazy val munit = SbtCommunityProject(
273+
project = "munit",
274+
sbtTestCommand = "testsJVM/test",
275+
)
276+
277+
lazy val scodecBits = SbtCommunityProject(
278+
project = "scodec-bits",
279+
sbtTestCommand = "coreJVM/test",
280+
sbtPublishCommand = "coreJVM/publishLocal",
281+
dependencies = List(scalatest, scalacheck, scalatestplusScalacheck)
282+
)
283+
284+
lazy val scodec = SbtCommunityProject(
285+
project = "scodec",
286+
sbtTestCommand = "unitTests/test",
287+
dependencies = List(scalatest, scalacheck, scalatestplusScalacheck, scodecBits)
288+
)
289+
290+
lazy val scalaParserCombinators = SbtCommunityProject(
291+
project = "scala-parser-combinators",
292+
sbtTestCommand = "parserCombinators/test",
293+
)
294+
295+
lazy val dottyCpsAsync = SbtCommunityProject(
296+
project = "dotty-cps-async",
297+
sbtTestCommand = "test",
298+
)
299+
300+
lazy val scalaz = SbtCommunityProject(
301+
project = "scalaz",
302+
sbtTestCommand = "rootJVM/test",
303+
dependencies = List(scalacheck)
304+
)
305+
306+
lazy val endpoints4s = SbtCommunityProject(
307+
project = "endpoints4s",
308+
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"
309+
)
310+
311+
lazy val catsEffect2 = SbtCommunityProject(
312+
project = "cats-effect-2",
313+
sbtTestCommand = "test"
314+
)
315+
316+
lazy val catsEffect3 = SbtCommunityProject(
317+
project = "cats-effect-3",
318+
sbtTestCommand = "testIfRelevant"
319+
)
320+
321+
end projects

0 commit comments

Comments
 (0)