-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbuild.mill
More file actions
253 lines (224 loc) · 9 KB
/
Copy pathbuild.mill
File metadata and controls
253 lines (224 loc) · 9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
//| mvnDeps:
//| - com.goyeau::mill-scalafix::0.6.0
import mill._
import mill.scalalib._
import mill.scalalib.Assembly
import mill.scalalib.publish._
import mill.javalib.NativeImageModule
import mill.javalib.SonatypeCentralPublishModule
import mill.util.Jvm
import com.goyeau.mill.scalafix.ScalafixModule
trait CommonScalaModule extends ScalaModule with ScalafixModule {
def scalaVersion = "3.9.0"
def javacOptions = Seq("--release", "17")
def scalacOptions = Seq(
"-deprecation",
"-feature",
"-Werror",
"-Wunused:all",
"-Wvalue-discard",
"-Wnonunit-statement",
"-Wimplausible-patterns",
"-Wshadow:all",
"-Wsafe-init",
"-Wrecurse-with-default",
"-Wenum-comment-discard",
"-WunstableInlineAccessors",
"-Wwrong-arrow",
"-Winfer-union"
)
}
def cellarVersion: T[String] = Task.Input {
sys.env.getOrElse("CELLAR_VERSION", "0.1.0-SNAPSHOT").stripPrefix("v")
}
trait CellarPublishModule extends CommonScalaModule with SonatypeCentralPublishModule {
def publishVersion = cellarVersion()
override def docJar: T[PathRef] = Task {
val docs = Task.dest / "docs"
os.makeDir.all(docs)
PathRef(Jvm.createJar(Task.dest / "out.jar", Seq(docs)))
}
}
def cellarPom(desc: String) = PomSettings(
description = desc,
organization = "org.virtuslab",
url = "https://github.com/VirtusLab/cellar",
licenses = Seq(License.`MPL-2.0`),
versionControl = VersionControl.github("VirtusLab", "cellar"),
developers = Seq(Developer("rochala", "Jakub Rochala", "https://github.com/rochala"))
)
object lib extends CellarPublishModule {
def artifactName = "cellar-lib"
def pomSettings = cellarPom("Programmatic access to JVM dependency APIs (Scala 3, Scala 2, Java)")
def mvnDeps = Seq(
mvn"org.typelevel::cats-effect:3.7.1",
mvn"co.fs2::fs2-io:3.13.0",
mvn"io.get-coursier:interface:1.0.29-M4",
mvn"ch.epfl.scala::tasty-query:1.9.0",
mvn"org.scala-lang:scala3-tasty-inspector_3:3.9.0",
mvn"com.github.pureconfig::pureconfig-core:0.17.10",
mvn"org.typelevel::log4cats-core:2.8.0",
mvn"org.typelevel::otel4s-core-trace:1.1.0"
)
object test extends ScalaTests with TestModule.Munit {
// Every test class boots its own tasty-query Context; one forked JVM per class saturates
// the whole machine and starts failing under load, so run them in a single JVM.
def testParallelism = false
def mvnDeps = super.mvnDeps() ++ Seq(
mvn"org.scalameta::munit:1.3.5",
mvn"org.typelevel::munit-cats-effect:2.2.0"
)
def forkArgs = Task {
// Publish fixtures to ~/.m2 before running tests
fixtureJava.publishM2LocalCached()
fixtureScala2.publishM2LocalCached()
fixtureScala3.publishM2LocalCached()
val millAbsPath = (lib.moduleDir / os.up / "mill").toString
Seq(
s"-Dcellar.test.millBinary=$millAbsPath",
s"-Dcellar.test.localM2=${os.home / ".m2" / "repository"}",
s"-Dcellar.test.fixtureJavaGroup=cellar.test",
s"-Dcellar.test.fixtureJavaArtifact=cellar-fixture-java",
s"-Dcellar.test.fixtureJavaVersion=0.1.0-SNAPSHOT",
s"-Dcellar.test.fixtureScala2Group=cellar.test",
s"-Dcellar.test.fixtureScala2Artifact=cellar-fixture-scala2_2.13",
s"-Dcellar.test.fixtureScala2Version=0.1.0-SNAPSHOT",
s"-Dcellar.test.fixtureScala3Group=cellar.test",
s"-Dcellar.test.fixtureScala3Artifact=cellar-fixture-scala3_3",
s"-Dcellar.test.fixtureScala3Version=0.1.0-SNAPSHOT"
)
}
}
}
object profilingRuntime extends CellarPublishModule {
def artifactName = "cellar-profiling-runtime"
def pomSettings = cellarPom("Cellar profiling and tracing runtime (Pyroscope + OTLP)")
def mvnDeps = Seq(
mvn"org.typelevel::otel4s-sdk-trace:0.19.2",
mvn"org.typelevel::otel4s-sdk-exporter:0.19.2",
mvn"io.pyroscope:agent:2.9.1"
)
object test extends ScalaTests with TestModule.Munit {
def mvnDeps = super.mvnDeps() ++ Seq(
mvn"org.scalameta::munit:1.3.5",
mvn"org.typelevel::munit-cats-effect:2.2.0"
)
}
}
object cli extends CellarPublishModule with NativeImageModule {
def moduleDeps = Seq(lib, profilingRuntime)
def mainClass = Some("cellar.cli.CellarApp")
def artifactName = "cellar-cli"
def pomSettings = cellarPom("Cellar command-line interface — JVM dependency API explorer")
// Only consumed in native-image mode (JRT filesystem is unreliable there —
// graal#10013), so kept off `resources` to avoid bloating the published lib JAR.
def bundledJreJar: T[PathRef] = Task {
import java.net.URI
import java.nio.file.{Files, FileSystems}
import java.util.jar.{JarEntry, JarOutputStream}
import scala.jdk.CollectionConverters.*
val dest = Task.dest / "jre.bin"
val fs = FileSystems.getFileSystem(URI.create("jrt:/"))
val jos = new JarOutputStream(java.io.FileOutputStream(dest.toIO))
val seen = scala.collection.mutable.Set[String]()
Files.list(fs.getPath("modules")).iterator().asScala.toList.foreach { modPath =>
Files.walk(modPath).iterator().asScala
.filterNot(Files.isDirectory(_))
.foreach { p =>
val name = p.getFileName.toString
if (name.endsWith(".class") || name.endsWith(".tasty")) && name != "module-info.class" then
val rel = modPath.relativize(p)
val entryName = (0 until rel.getNameCount).map(i => rel.getName(i).toString).mkString("/")
if !seen(entryName) then
seen += entryName
jos.putNextEntry(new JarEntry(entryName))
jos.write(Files.readAllBytes(p))
jos.closeEntry()
}
}
jos.close()
PathRef(Task.dest)
}
override def nativeImageClasspath = Task {
super.nativeImageClasspath() ++ Seq(bundledJreJar())
}
def generatedSources = Task {
val dir = Task.dest
val safeVersion = cellarVersion().replace("\\", "\\\\").replace("\"", "\\\"").replaceAll("[\r\n]", "")
os.write(
dir / "BuildInfo.scala",
s"""package cellar.cli
|private[cli] object BuildInfo:
| val version = "${safeVersion}"
|""".stripMargin
)
super.generatedSources() ++ Seq(PathRef(dir))
}
def jvmVersion = "graalvm-community:23.0.2"
// No `-H:+AllowJRTFileSystem`: with the jrt provider present, the image carries the *build*
// machine's `java.home` baked into `jdk.internal.jrtfs.SystemImage`, so opening `jrt:/` on any
// other machine throws `InternalError: NoSuchFileException .../lib/modules`. dotc's
// `JrtClassPath` only recovers from `ProviderNotFoundException`/`FileSystemNotFoundException`,
// so the docstring inspector died and dotc printed a crash report over cellar's stdout. Without
// the provider the lookup raises `ProviderNotFoundException`, which dotc handles. Nothing in the
// native binary needs jrt: `JreClasspath` reads the bundled `jre.bin` there instead.
def nativeImageOptions = Seq(
"--no-fallback",
"--enable-url-protocols=http,https",
"-H:+ReportExceptionStackTraces"
)
def mvnDeps = Seq(
mvn"com.monovore::decline:2.6.2",
mvn"com.monovore::decline-effect:2.6.2",
mvn"org.slf4j:slf4j-nop:2.0.18"
)
def assemblyRules = Seq(
Assembly.Rule.Append("META-INF/services/.*"),
Assembly.Rule.Append("reference.conf"),
Assembly.Rule.ExcludePattern("META-INF/.*\\.SF"),
Assembly.Rule.ExcludePattern("META-INF/.*\\.DSA"),
Assembly.Rule.ExcludePattern("META-INF/.*\\.RSA"),
Assembly.Rule.ExcludePattern("module-info.class"),
Assembly.Rule.ExcludePattern("jre.bin")
) ++ Assembly.defaultRules
object test extends ScalaTests with TestModule.Munit {
def mvnDeps = super.mvnDeps() ++ Seq(
mvn"org.scalameta::munit:1.3.5",
mvn"org.typelevel::munit-cats-effect:2.2.0"
)
}
}
/** Publish all three fixture artifacts to ~/.m2. */
def publishFixtures() = Task.Command {
fixtureJava.publishM2Local()()
fixtureScala2.publishM2Local()()
fixtureScala3.publishM2Local()()
}
def fixturePom(desc: String) = PomSettings(
description = desc,
organization = "cellar.test",
url = "https://github.com/example/cellar",
licenses = Seq(License.`Apache-2.0`),
versionControl = VersionControl.github("example", "cellar"),
developers = Seq(
Developer("test-dev", "Test Developer", "https://github.com/test-dev")
)
)
object fixtureJava extends JavaModule with PublishModule {
def javacOptions = Seq("--release", "17")
def publishVersion = "0.1.0-SNAPSHOT"
def artifactName = "cellar-fixture-java"
def pomSettings = fixturePom("Cellar Java test fixture")
}
object fixtureScala2 extends ScalaModule with PublishModule {
def scalaVersion = "2.13.16"
def javacOptions = Seq("--release", "17")
def publishVersion = "0.1.0-SNAPSHOT"
def artifactName = "cellar-fixture-scala2"
def pomSettings = fixturePom("Cellar Scala 2.13 test fixture")
}
object fixtureScala3 extends CommonScalaModule with PublishModule {
def publishVersion = "0.1.0-SNAPSHOT"
def artifactName = "cellar-fixture-scala3"
def pomSettings = fixturePom("Cellar Scala 3 test fixture")
}