forked from com-lihaoyi/upickle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sc
429 lines (374 loc) · 15.4 KB
/
build.sc
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
import mill._, mill.scalalib._, mill.scalalib.publish._, mill.scalajslib._, mill.scalanativelib._, mill.modules._
val scala211 = "2.11.12"
val scala212 = "2.12.10"
val scala213 = "2.13.1"
val scala3 = "3.0.0-M3"
val scalaJS06 = "0.6.32"
val scalaJS1 = "1.0.0"
val dottyCustomVersion = Option(sys.props("dottyVersion"))
def acyclicVersion(scalaVersion: String): String = if(scalaVersion.startsWith("2.11.")) "0.1.8" else "0.2.0"
val scala2JVMVersions = Seq(scala212, scala213)
val scalaJVMVersions = scala2JVMVersions ++ Seq(scala3) ++ dottyCustomVersion
val scalaJSVersions = Seq(
(scala212, scalaJS06),
(scala213, scalaJS06),
(scala212, scalaJS1),
(scala213, scalaJS1)
)
val scalaNativeVersions = Seq(
(scala211, "0.3.9"),
(scala211, "0.4.0-M2")
)
trait CommonModule extends ScalaModule {
def scalacOptions = T{ if (scalaVersion() == scala212) Seq("-opt:l:method") else Nil }
def platformSegment: String
def sources = T.sources{
super.sources() ++
Seq(PathRef(millSourcePath / s"src-$platformSegment"))
}
}
trait CommonPublishModule extends CommonModule with PublishModule with CrossScalaModule{
def publishVersion = "1.2.2"
def isDotty = crossScalaVersion.startsWith("0") || crossScalaVersion.startsWith("3")
def pomSettings = PomSettings(
description = artifactName(),
organization = "com.lihaoyi",
url = "https://github.com/lihaoyi/upickle",
licenses = Seq(License.MIT),
scm = SCM(
"git://github.com/lihaoyi/upickle.git",
"scm:git://github.com/lihaoyi/upickle.git"
),
developers = Seq(
Developer("lihaoyi", "Li Haoyi","https://github.com/lihaoyi")
)
)
trait CommonTestModule extends CommonModule with TestModule{
def ivyDeps = Agg(ivy"com.lihaoyi::utest::0.7.5") ++ (
if (isDotty) Agg.empty[mill.scalalib.Dep]
else Agg(ivy"com.lihaoyi::acyclic:${acyclicVersion(scalaVersion())}")
)
def testFrameworks = Seq("upickle.core.UTestFramework")
}
}
trait CommonJvmModule extends CommonPublishModule{
def platformSegment = "jvm"
def millSourcePath = super.millSourcePath / os.up
trait Tests extends super.Tests with CommonTestModule{
def platformSegment = "jvm"
}
}
trait CommonJsModule extends CommonPublishModule with ScalaJSModule{
def platformSegment = "js"
def crossScalaJSVersion: String
def scalaJSVersion = crossScalaJSVersion
def millSourcePath = super.millSourcePath / os.up / os.up
trait Tests extends super.Tests with CommonTestModule{
def platformSegment = "js"
def scalaJSVersion = crossScalaJSVersion
}
}
trait CommonNativeModule extends CommonPublishModule with ScalaNativeModule{
def platformSegment = "native"
def crossScalaNativeVersion: String
def scalaNativeVersion = crossScalaNativeVersion
def millSourcePath = super.millSourcePath / os.up / os.up
trait Tests extends super.Tests with CommonTestModule{
def platformSegment = "native"
def scalaNativeVersion = crossScalaNativeVersion
}
}
trait CommonCoreModule extends CommonPublishModule {
def artifactName = "upickle-core"
def ivyDeps = Agg(ivy"com.lihaoyi::geny::0.6.2") ++ (if (!isDotty) Agg(
ivy"org.scala-lang.modules::scala-collection-compat::2.1.4",
)
else Agg(
ivy"org.scala-lang.modules:scala-collection-compat_2.13:2.1.4",
))
}
object core extends Module {
object js extends Cross[CoreJsModule](scalaJSVersions:_*)
class CoreJsModule(val crossScalaVersion: String, val crossScalaJSVersion: String) extends CommonJsModule with CommonCoreModule{
object test extends Tests
}
object jvm extends Cross[CoreJvmModule](scalaJVMVersions:_*)
class CoreJvmModule(val crossScalaVersion: String) extends CommonJvmModule with CommonCoreModule{
object test extends Tests
}
object native extends Cross[CoreNativeModule](scalaNativeVersions:_*)
class CoreNativeModule(val crossScalaVersion: String, val crossScalaNativeVersion: String) extends CommonNativeModule with CommonCoreModule{
object test extends Tests
}
}
object implicits extends Module {
trait ImplicitsModule extends CommonPublishModule{
def compileIvyDeps = if (!isDotty) Agg(
ivy"com.lihaoyi::acyclic:${acyclicVersion(scalaVersion())}",
ivy"org.scala-lang:scala-reflect:${scalaVersion()}"
)
else Agg.empty[Dep]
def generatedSources = T{
val dir = T.ctx().dest
val file = dir / "upickle" / "Generated.scala"
ammonite.ops.mkdir(dir / "upickle")
val tuples = (1 to 22).map{ i =>
def commaSeparated(s: Int => String) = (1 to i).map(s).mkString(", ")
val writerTypes = commaSeparated(j => s"T$j: Writer")
val readerTypes = commaSeparated(j => s"T$j: Reader")
val typeTuple = commaSeparated(j => s"T$j")
val implicitWriterTuple = commaSeparated(j => s"implicitly[Writer[T$j]]")
val implicitReaderTuple = commaSeparated(j => s"implicitly[Reader[T$j]]")
val lookupTuple = commaSeparated(j => s"x(${j-1})")
val fieldTuple = commaSeparated(j => s"x._$j")
s"""
implicit def Tuple${i}Writer[$writerTypes]: TupleNWriter[Tuple$i[$typeTuple]] =
new TupleNWriter[Tuple$i[$typeTuple]](Array($implicitWriterTuple), x => if (x == null) null else Array($fieldTuple))
implicit def Tuple${i}Reader[$readerTypes]: TupleNReader[Tuple$i[$typeTuple]] =
new TupleNReader(Array($implicitReaderTuple), x => Tuple$i($lookupTuple).asInstanceOf[Tuple$i[$typeTuple]])
"""
}
ammonite.ops.write(file, s"""
package upickle.implicits
/**
* Auto-generated picklers and unpicklers, used for creating the 22
* versions of tuple-picklers and case-class picklers
*/
trait Generated extends upickle.core.Types{
${tuples.mkString("\n")}
}
""")
Seq(PathRef(dir))
}
}
object js extends Cross[JsModule](scalaJSVersions:_*)
class JsModule(val crossScalaVersion: String, val crossScalaJSVersion: String) extends ImplicitsModule with CommonJsModule{
def moduleDeps = Seq(core.js(crossScalaVersion, crossScalaJSVersion))
def artifactName = "upickle-implicits"
object test extends Tests {
def moduleDeps = super.moduleDeps ++ Seq(
ujson.js(crossScalaVersion, crossScalaJSVersion).test,
core.js(crossScalaVersion, crossScalaJSVersion).test
)
}
}
object jvm extends Cross[JvmModule](scalaJVMVersions:_*)
class JvmModule(val crossScalaVersion: String) extends ImplicitsModule with CommonJvmModule{
def moduleDeps = Seq(core.jvm())
def artifactName = "upickle-implicits"
object test extends Tests {
def moduleDeps = super.moduleDeps ++ Seq(ujson.jvm().test, core.jvm().test)
}
}
object native extends Cross[NativeModule](scalaNativeVersions:_*)
class NativeModule(val crossScalaVersion: String, val crossScalaNativeVersion: String) extends ImplicitsModule with CommonNativeModule{
def moduleDeps = Seq(core.native(crossScalaVersion, crossScalaNativeVersion))
def artifactName = "upickle-implicits"
// object test extends Tests {
// def moduleDeps = super.moduleDeps ++ Seq(
// ujson.native(crossScalaVersion, crossScalaNativeVersion).test,
// core.native(crossScalaVersion, crossScalaNativeVersion).test
// )
// }
}
}
object upack extends Module {
object js extends Cross[JsModule](scalaJSVersions:_*)
class JsModule(val crossScalaVersion: String, val crossScalaJSVersion: String) extends CommonJsModule {
def moduleDeps = Seq(core.js(crossScalaVersion, crossScalaJSVersion))
def artifactName = "upack"
object test extends Tests {
def moduleDeps = super.moduleDeps ++ Seq(
ujson.js(crossScalaVersion, crossScalaJSVersion).test,
core.js(crossScalaVersion, crossScalaJSVersion).test
)
}
}
object jvm extends Cross[JvmModule](scalaJVMVersions:_*)
class JvmModule(val crossScalaVersion: String) extends CommonJvmModule {
def moduleDeps = Seq(core.jvm())
def artifactName = "upack"
object test extends Tests with CommonModule {
def moduleDeps = super.moduleDeps ++ Seq(ujson.jvm().test, core.jvm().test)
}
}
object native extends Cross[NativeModule](scalaNativeVersions:_*)
class NativeModule(val crossScalaVersion: String, val crossScalaNativeVersion: String) extends CommonNativeModule {
def moduleDeps = Seq(core.native(crossScalaVersion, crossScalaNativeVersion))
def artifactName = "upack"
// object test extends Tests {
// def moduleDeps = super.moduleDeps ++ Seq(
// ujson.native(crossScalaVersion, crossScalaNativeVersion).test,
// core.native(crossScalaVersion, crossScalaNativeVersion).test
// )
// }
}
}
object ujson extends Module{
trait JsonModule extends CommonPublishModule{
def artifactName = "ujson"
trait JawnTestModule extends CommonTestModule{
def ivyDeps = T{
if (!isDotty) Agg(
ivy"org.scalatest::scalatest::3.1.1",
ivy"org.scalatestplus::scalacheck-1-14::3.1.1.1"
)
else Agg()
}
def testFrameworks = if (!isDotty) Seq("org.scalatest.tools.Framework") else Seq.empty[String]
}
}
object js extends Cross[JsModule](scalaJSVersions:_*)
class JsModule(val crossScalaVersion: String, val crossScalaJSVersion: String) extends JsonModule with CommonJsModule{
def moduleDeps = Seq(core.js(crossScalaVersion, crossScalaJSVersion))
object test extends Tests with JawnTestModule
}
object jvm extends Cross[JvmModule](scalaJVMVersions:_*)
class JvmModule(val crossScalaVersion: String) extends JsonModule with CommonJvmModule{
def moduleDeps = Seq(core.jvm())
object test extends Tests with JawnTestModule
}
object native extends Cross[NativeModule](scalaNativeVersions:_*)
class NativeModule(val crossScalaVersion: String, val crossScalaNativeVersion: String) extends JsonModule with CommonNativeModule{
def moduleDeps = Seq(core.native(crossScalaVersion, crossScalaNativeVersion))
// object test extends Tests with JawnTestModule {
// def ivyDeps = if(crossScalaNativeVersion == "0.3.9") T(Agg.empty) else super.ivyDeps()
// def testFrameworks = if(crossScalaNativeVersion == "0.3.9") T(Seq.empty[String]) else super.testFrameworks()
// def sources = if(crossScalaNativeVersion == "0.3.9") T.sources(Seq.empty) else super.sources
// }
}
object argonaut extends Cross[ArgonautModule](scala2JVMVersions:_*)
class ArgonautModule(val crossScalaVersion: String) extends CommonPublishModule{
def artifactName = "ujson-argonaut"
def platformSegment = "jvm"
def moduleDeps = Seq(ujson.jvm())
def ivyDeps = Agg(ivy"io.argonaut::argonaut:6.2.3")
}
object json4s extends Cross[Json4sModule](scala2JVMVersions:_*)
class Json4sModule(val crossScalaVersion: String) extends CommonPublishModule{
def artifactName = "ujson-json4s"
def platformSegment = "jvm"
def moduleDeps = Seq(ujson.jvm())
def ivyDeps = Agg(
ivy"org.json4s::json4s-ast:3.6.7",
ivy"org.json4s::json4s-native:3.6.7"
)
}
object circe extends Cross[CirceModule](scala2JVMVersions:_*)
class CirceModule(val crossScalaVersion: String) extends CommonPublishModule{
def artifactName = "ujson-circe"
def platformSegment = "jvm"
def moduleDeps = Seq(ujson.jvm())
def ivyDeps = Agg(ivy"io.circe::circe-parser:0.13.0")
}
object play extends Cross[PlayModule](scala2JVMVersions:_*)
class PlayModule(val crossScalaVersion: String) extends CommonPublishModule{
def artifactName = "ujson-play"
def platformSegment = "jvm"
def moduleDeps = Seq(ujson.jvm())
def ivyDeps = Agg(
ivy"com.typesafe.play::play-json:2.7.4"
)
}
}
trait UpickleModule extends CommonPublishModule{
def artifactName = "upickle"
def compileIvyDeps = if (!isDotty) Agg(
ivy"com.lihaoyi::acyclic:${acyclicVersion(scalaVersion())}",
ivy"org.scala-lang:scala-reflect:${scalaVersion()}",
ivy"org.scala-lang:scala-compiler:${scalaVersion()}"
)
else Agg.empty[Dep]
def scalacOptions = Seq(
"-unchecked",
"-deprecation",
"-encoding", "utf8",
"-feature",
)
}
object upickle extends Module{
object jvm extends Cross[JvmModule](scalaJVMVersions:_*)
class JvmModule(val crossScalaVersion: String) extends UpickleModule with CommonJvmModule{
def moduleDeps = Seq(ujson.jvm(), upack.jvm(), implicits.jvm())
object test extends Tests with CommonModule{
def moduleDeps = {
(super.moduleDeps :+ core.jvm().test) ++ (
if (isDotty) Nil else Seq(
ujson.argonaut(),
ujson.circe(),
ujson.json4s(),
ujson.play(),
))
}
def scalacOptions =
if (isDotty) Seq("-Ximport-suggestion-timeout", "0")
else Nil
}
}
object js extends Cross[JsModule](scalaJSVersions:_*)
class JsModule(val crossScalaVersion: String, val crossScalaJSVersion: String) extends UpickleModule with CommonJsModule {
def moduleDeps = Seq(
ujson.js(crossScalaVersion, crossScalaJSVersion),
upack.js(crossScalaVersion, crossScalaJSVersion),
implicits.js(crossScalaVersion, crossScalaJSVersion)
)
object test extends Tests with CommonModule{
def testFrameworks = Seq("upickle.core.UTestFramework")
def moduleDeps = super.moduleDeps ++ Seq(core.js(crossScalaVersion, crossScalaJSVersion).test)
}
}
object native extends Cross[NativeModule](scalaNativeVersions:_*)
class NativeModule(val crossScalaVersion: String, val crossScalaNativeVersion: String) extends UpickleModule with CommonNativeModule {
def moduleDeps = Seq(
ujson.native(crossScalaVersion, crossScalaNativeVersion),
upack.native(crossScalaVersion, crossScalaNativeVersion),
implicits.native(crossScalaVersion, crossScalaNativeVersion)
)
// object test extends Tests with CommonModule{
// def testFrameworks = if(crossScalaNativeVersion == "0.3.9") T(Seq.empty[String]) else super.testFrameworks()
// def sources = if(crossScalaNativeVersion == "0.3.9") T.sources(Seq.empty) else super.sources
// def allSourceFiles = T(super.allSourceFiles().filterNot(pr => Seq("Primitive", "Durations", "Legacy").map(s => s"${s}Tests.scala").contains(pr.path.last)))
// def moduleDeps = super.moduleDeps ++ Seq(core.native(crossScalaVersion, crossScalaNativeVersion).test)
// }
}
}
trait BenchModule extends CommonModule{
def scalaVersion = scala213
def millSourcePath = build.millSourcePath / "bench"
def ivyDeps = Agg(
ivy"io.circe::circe-core::0.12.1",
ivy"io.circe::circe-generic::0.12.1",
ivy"io.circe::circe-parser::0.12.1",
ivy"com.typesafe.play::play-json::2.7.4",
ivy"io.argonaut::argonaut:6.2.3",
ivy"org.json4s::json4s-ast:3.6.7",
ivy"com.lihaoyi::sourcecode::0.2.1",
)
}
object bench extends Module {
object js extends BenchModule with ScalaJSModule {
def scalaJSVersion = scalaJSVersions.head._2
def platformSegment = "js"
def moduleDeps = Seq(upickle.js(scala213, scalaJS1).test)
def run(args: String*) = T.command {
finalMainClassOpt() match{
case Left(err) => mill.eval.Result.Failure(err)
case Right(_) =>
ScalaJSWorkerApi.scalaJSWorker().run(
toolsClasspath().map(_.path),
jsEnvConfig(),
fullOpt().path.toIO
)
mill.eval.Result.Success(())
}
}
}
object jvm extends BenchModule {
def platformSegment = "jvm"
def moduleDeps = Seq(upickle.jvm(scala213).test)
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"com.fasterxml.jackson.module::jackson-module-scala:2.9.10",
ivy"com.fasterxml.jackson.core:jackson-databind:2.9.4",
)
}
}