-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
build.mill
297 lines (248 loc) · 9.22 KB
/
build.mill
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
package build
import mill._
import scalalib._
import scalajslib._
import scalanativelib._
import publish._
import mill.api.Result
import mill.modules.Jvm.createJar
import mill.scalalib.api.ZincWorkerUtil.isScala3
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
import $ivy.`com.github.lolgab::mill-mima::0.0.23`
import de.tobiasroeser.mill.vcs.version.VcsVersion
import com.github.lolgab.mill.mima._
val scala3 = "3.3.3"
val scala213 = "2.13.14"
val scala212 = "2.12.19"
val scalaJS1 = "1.16.0"
val scalaNative05 = "0.5.1"
val crossVersions = Seq(scala3, scala213, scala212)
object fastparse extends Module{
object jvm extends Cross[fastparseJvmModule](crossVersions)
trait fastparseJvmModule extends FastparseModule{
object test extends ScalaTests with CommonTestModule
}
object js extends Cross[fastparseJsModule](crossVersions)
trait fastparseJsModule extends FastparseModule with ScalaJSModule {
def scalaJSVersion = scalaJS1
private def sourceMapOptions = T.task {
val vcsState = VcsVersion.vcsState()
vcsState.lastTag.collect {
case tag if vcsState.commitsSinceLastTag == 0 =>
val baseUrl = pomSettings().url.replace("github.com", "raw.githubusercontent.com")
val sourcesOptionName = if(isScala3(crossScalaVersion)) "-scalajs-mapSourceURI" else "-P:scalajs:mapSourceURI"
s"$sourcesOptionName:${T.workspace.toIO.toURI}->$baseUrl/$tag/"
}
}
override def scalacOptions = super.scalacOptions() ++ sourceMapOptions()
object test extends ScalaJSTests with CommonTestModule
}
object native extends Cross[fastparseNativeModule](crossVersions)
trait fastparseNativeModule extends FastparseModule with ScalaNativeModule {
def scalaNativeVersion = scalaNative05
object test extends ScalaNativeTests with CommonTestModule
}
}
trait FastparseModule extends CommonCrossModule with Mima{
def ivyDeps = Agg(
ivy"com.lihaoyi::sourcecode::0.4.0",
ivy"com.lihaoyi::geny::1.1.0"
)
def compileIvyDeps =
if(isScala3(crossScalaVersion)) Agg.empty[Dep]
else Agg(ivy"org.scala-lang:scala-reflect:$crossScalaVersion")
def generatedSources = T{
val dir = T.ctx().dest
val file = dir/"fastparse"/"SequencerGen.scala"
// Only go up to 21, because adding the last element makes it 22
val tuples = (2 to 21).map{ i =>
val ts = (1 to i) map ("T" + _)
val chunks = (1 to i) map { n =>
s"t._$n"
}
val tsD = (ts :+ "D").mkString(",")
val anys = ts.map(_ => "Any").mkString(", ")
s"""
val BaseSequencer$i: Sequencer[($anys), Any, ($anys, Any)] =
Sequencer0((t, d) => (${chunks.mkString(", ")}, d))
implicit def Sequencer$i[$tsD]: Sequencer[(${ts.mkString(", ")}), D, ($tsD)] =
BaseSequencer$i.asInstanceOf[Sequencer[(${ts.mkString(", ")}), D, ($tsD)]]
"""
}
val output = s"""
package fastparse
trait SequencerGen[Sequencer[_, _, _]] extends LowestPriSequencer[Sequencer]{
protected[this] def Sequencer0[A, B, C](f: (A, B) => C): Sequencer[A, B, C]
${tuples.mkString("\n")}
}
trait LowestPriSequencer[Sequencer[_, _, _]]{
protected[this] def Sequencer0[A, B, C](f: (A, B) => C): Sequencer[A, B, C]
implicit def Sequencer1[T1, T2]: Sequencer[T1, T2, (T1, T2)] = Sequencer0{case (t1, t2) => (t1, t2)}
}
""".stripMargin
os.write(file, output, createFolders = true)
Seq(PathRef(file))
}
override def scalacOptions =
super.scalacOptions() ++
Agg.when(scalaVersion() != scala3)(
"-Xfatal-warnings",
"-Xlint:unused",
"-Wconf:cat=feature:s,cat=deprecation:s"
)
def mimaReportBinaryIssues() =
if (this.isInstanceOf[ScalaNativeModule] || this.isInstanceOf[ScalaJSModule]) T.command()
else super.mimaReportBinaryIssues()
def mimaPreviousVersions = Seq(
VcsVersion
.vcsState()
.lastTag
.getOrElse(throw new Exception("Missing last tag"))
)
def mimaPreviousArtifacts =
if (isScala3(crossScalaVersion)) Agg.empty[Dep]
else super.mimaPreviousArtifacts()
def mimaBinaryIssueFilters = super.mimaBinaryIssueFilters() ++ Seq(
ProblemFilter.exclude[IncompatibleResultTypeProblem]("fastparse.Parsed#Failure.unapply"),
)
}
object scalaparse extends Module{
object js extends Cross[ScalaParseJsModule](crossVersions)
trait ScalaParseJsModule extends ExampleParseJsModule
object jvm extends Cross[ScalaParseJvmModule](crossVersions)
trait ScalaParseJvmModule extends ExampleParseJvmModule
object native extends Cross[ScalaParseNativeModule](crossVersions)
trait ScalaParseNativeModule extends ExampleParseNativeModule
}
object cssparse extends Module{
object js extends Cross[CssParseJsModule](crossVersions)
trait CssParseJsModule extends ExampleParseJsModule
object jvm extends Cross[CssParseJvmModule](crossVersions)
trait CssParseJvmModule extends ExampleParseJvmModule
object native extends Cross[CssParseNativeModule](crossVersions)
trait CssParseNativeModule extends ExampleParseNativeModule
}
object pythonparse extends Module{
object js extends Cross[PythonParseJsModule](crossVersions)
trait PythonParseJsModule extends ExampleParseJsModule
object jvm extends Cross[PythonParseJvmModule](crossVersions)
trait PythonParseJvmModule extends ExampleParseJvmModule
object native extends Cross[PythonParseNativeModule](crossVersions)
trait PythonParseNativeModule extends ExampleParseNativeModule
}
trait ExampleParseJsModule extends CommonCrossModule with ScalaJSModule{
def moduleDeps = Seq(fastparse.js())
def scalaJSVersion = scalaJS1
object test extends ScalaJSTests with CommonTestModule
}
trait ExampleParseJvmModule extends CommonCrossModule{
def moduleDeps = Seq(fastparse.jvm())
object test extends ScalaTests with CommonTestModule{
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"net.sourceforge.cssparser:cssparser:0.9.18",
) ++ Agg.when(!isScala3(crossScalaVersion))(
ivy"org.scala-lang:scala-compiler:$crossScalaVersion"
)
}
}
trait ExampleParseNativeModule extends CommonCrossModule with ScalaNativeModule{
def scalaNativeVersion = scalaNative05
def moduleDeps = Seq(fastparse.native())
object test extends ScalaNativeTests with CommonTestModule
}
trait CommonCrossModule extends CrossScalaModule with PublishModule with PlatformScalaModule{
def publishVersion = VcsVersion.vcsState().format()
def pomSettings = PomSettings(
description = artifactName(),
organization = "com.lihaoyi",
url = "https://github.com/lihaoyi/fastparse",
licenses = Seq(License.MIT),
versionControl = VersionControl.github(
"com-lihaoyi",
"fastparse"
),
developers = Seq(
Developer("lihaoyi", "Li Haoyi","https://github.com/lihaoyi")
)
)
def scalaDocPluginClasspath = T{ Agg[PathRef]() }
def sources = T.sources {
super.sources() ++
Agg(PathRef(millSourcePath / "src-2.12+"))
}
}
trait CommonTestModule extends ScalaModule with TestModule.Utest{
def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.8.3")
override def scalacOptions =
super.scalacOptions() ++
Agg.when(scalaVersion() != scala3)(
"-Xfatal-warnings",
"-Xlint:unused",
"-Wconf:cat=feature:s,cat=deprecation:s"
)
}
object perftests extends Module{
object bench2 extends PerfTestModule {
def scalaVersion0 = scala213
def moduleDeps = Seq(
scalaparse.jvm(scala213).test,
pythonparse.jvm(scala213).test,
cssparse.jvm(scala213).test,
fastparse.jvm(scala213).test,
)
}
object benchScala33 extends PerfTestModule {
def scalaVersion0 = scala3
def sources = T.sources { bench2.sources() }
def moduleDeps = Seq(
scalaparse.jvm(scala3).test,
pythonparse.jvm(scala3).test,
cssparse.jvm(scala3).test,
fastparse.jvm(scala3).test,
)
}
object compare extends PerfTestModule {
def scalaVersion0 = scala212
def moduleDeps = Seq(
fastparse.jvm(scala212).test,
scalaparse.jvm(scala212).test,
pythonparse.jvm(scala212).test
)
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"org.json4s::json4s-ast:3.6.0",
ivy"org.json4s::json4s-native:3.6.0",
ivy"org.json4s::json4s-jackson:3.6.0",
ivy"io.circe::circe-parser:0.9.1",
ivy"io.argonaut::argonaut:6.2",
ivy"com.typesafe.play::play-json:2.6.9",
ivy"com.fasterxml.jackson.core:jackson-databind:2.9.4",
ivy"com.lihaoyi::ujson:1.1.0",
ivy"org.scala-lang.modules::scala-parser-combinators:1.1.1",
ivy"org.python:jython:2.7.1b3"
)
}
trait PerfTestModule extends ScalaModule with TestModule.Utest{
def scalaVersion0: String
def scalaVersion = scalaVersion0
def scalacOptions = Seq("-opt:l:method")
def resources = T.sources{
Seq(PathRef(perftests.millSourcePath / "resources")) ++
fastparse.jvm(scalaVersion0).test.resources()
}
def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.8.3")
}
}
object demo extends ScalaJSModule{
def scalaJSVersion = scalaJS1
def scalaVersion = scala213
def moduleDeps = Seq(
scalaparse.js(scala213),
cssparse.js(scala213),
pythonparse.js(scala213),
fastparse.js(scala213).test,
)
def ivyDeps = Agg(
ivy"org.scala-js::scalajs-dom::0.9.8",
ivy"com.lihaoyi::scalatags::0.9.3"
)
}