forked from rallyhealth/weePickle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
252 lines (228 loc) · 8.15 KB
/
build.sbt
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
import com.typesafe.tools.mima.core.{DirectMissingMethodProblem, ProblemFilters}
import sbt._
// root
name := "weePickle-root"
noPublish
crossScalaVersions := Nil // crossScalaVersions must be set to Nil on the aggregating project
lazy val bench = project
.dependsOn(
`weepickle-tests` % "compile;test",
)
.enablePlugins(JmhPlugin)
.settings(
noPublish,
crossScalaVersions := Seq(scala213, scala3),
libraryDependencies ++= Seq(
"com.lihaoyi" %% "upickle" % "3.1.3", // need the latest Scala 3 support
"com.fasterxml.jackson.core" % "jackson-databind" % "2.15.2",
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-smile" % "2.15.2",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.15.2",
"io.circe" %% "circe-generic" % "0.14.6",
"io.circe" %% "circe-parser" % "0.14.6",
"org.msgpack" % "jackson-dataformat-msgpack" % "0.9.6",
"com.lihaoyi" %% "sourcecode" % "0.3.1",
)
)
lazy val `weepickle-core` = project
.settings(
libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-collection-compat" % "2.11.0"
)
)
lazy val `weepickle-implicits` = project
.dependsOn(weejson)
.settings(
libraryDependencies ++= {
if (scalaBinaryVersion.value == "3") Seq.empty else Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value)
},
Compile / sourceGenerators += Def.task[Seq[File]] {
val pkg = s"com.rallyhealth.weepickle.${shadedVersion.value}.implicits"
val contents =
s"""
package $pkg
import acyclic.file
import language.experimental.macros
/**
* Auto-generated picklers and unpicklers, used for creating the 22
* versions of tuple-picklers and case-class picklers
*/
trait Generated extends com.rallyhealth.weepickle.v1.core.Types{
${
(1 to 22).map { i =>
def commaSeparated(s: Int => String) = (1 to i).map(s).mkString(", ")
val writerTypes = commaSeparated(j => s"T$j: From")
val readerTypes = commaSeparated(j => s"T$j: To")
val typeTuple = commaSeparated(j => s"T$j")
val implicitFromTuple = commaSeparated(j => s"implicitly[From[T$j]]")
val implicitToTuple = commaSeparated(j => s"implicitly[To[T$j]]")
val lookupTuple = commaSeparated(j => s"x(${j - 1})")
val fieldTuple = commaSeparated(j => s"x._$j")
s"""
implicit def Tuple${i}From[$writerTypes]: TupleNFrom[Tuple$i[$typeTuple]] =
new TupleNFrom[Tuple$i[$typeTuple]](Array($implicitFromTuple), x => if (x == null) null else Array($fieldTuple))
implicit def Tuple${i}To[$readerTypes]: TupleNTo[Tuple$i[$typeTuple]] =
new TupleNTo(Array($implicitToTuple), x => Tuple$i($lookupTuple).asInstanceOf[Tuple$i[$typeTuple]])
"""
}.mkString("\n")
}
}
"""
val file = pkg.split('.').foldLeft((Compile / sourceManaged).value)(_ / _) / "Generated.scala"
IO.write(file, contents)
Seq(file)
}
)
lazy val weepickle = project
.dependsOn(
`weepickle-implicits`,
weejson,
)
/**
* Place for tests that would otherwise cause sbt to have circular project dependencies.
*/
lazy val `weepickle-tests` = project
.dependsOn(
`weepickle-core` % "compile;test->test",
`weejson-argonaut`,
`weejson-circe`,
`weejson-json4s`,
`weejson-play-base`,
`weejson` % "compile;test->test",
`weepack` % "compile;test->test",
`weepickle`,
`weexml`,
`weeyaml`,
)
.settings(
noPublish,
)
/**
* ADTs:
*
* - Value
* - BufferedValue
*/
lazy val weejson = project
.dependsOn(`weejson-jackson`)
lazy val weepack = project
.dependsOn(
`weepickle-core` % "compile;test->test",
weepickle,
weejson % "test->test",
)
/**
* Json string parsing and generation.
*
* @see https://github.com/FasterXML/jackson-core
*/
lazy val `weejson-jackson` = project
.dependsOn(`weepickle-core`)
.settings(
libraryDependencies ++= Seq(
"com.fasterxml.jackson.core" % "jackson-core" % "2.15.2"
),
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[DirectMissingMethodProblem]("com.rallyhealth.weejson.v1.jackson.TextBufferCharSequence.isEmpty")
)
)
lazy val `weejson-circe` = project
.dependsOn(weejson)
.settings(
libraryDependencies ++= Seq(
"io.circe" %% "circe-parser" % (if (scalaBinaryVersion.value == "2.11") "0.11.2" else "0.14.6")
)
)
lazy val `weejson-json4s` = project
.dependsOn(weejson)
.settings(
libraryDependencies ++= Seq(
// 4.x.x breaks binary compatibility, consider for weePickle v2
"org.json4s" %% "json4s-ast" % (if (scalaBinaryVersion.value == "3") "4.0.6" else "3.6.12"),
)
)
lazy val `weejson-argonaut` = project
.dependsOn(weejson)
.settings(
Compile / unmanagedSourceDirectories ++= (
if (scalaBinaryVersion.value == "2.11") Nil else Seq((Compile / sourceDirectory).value / "scala-2.12+")
),
libraryDependencies ++= Seq(
"io.argonaut" %% "argonaut" % (if (scalaBinaryVersion.value == "2.11") "6.2.6" else "6.3.9"),
)
)
// We need one project for 'weepickle-testing' to dependOn that is available on all Scala versions.
// This "base" project uses play-json 2.7 when on Scala 2.11 and play-json 2.10 when on later Scala versions.
lazy val `weejson-play-base` = (project in file("weejson-play"))
.dependsOn(weepickle)
.settings(
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-json" % (if (scalaBinaryVersion.value == "2.11") "2.7.4" else "2.10.1"),
),
noPublish
)
def playProject(playVersion: String, scalaVersions: Seq[String]) = {
val playString = playVersion.split('.').take(2).mkString("play", "", "")
Project(s"weejson-$playString", file(s"weejson-$playString"))
.dependsOn(weepickle)
.settings(
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-json" % playVersion,
),
Compile / unmanagedSourceDirectories ++= (`weejson-play-base` / Compile / unmanagedSourceDirectories).value,
Test / unmanagedSourceDirectories ++= (`weejson-play-base` / Test / unmanagedSourceDirectories).value,
crossScalaVersions := scalaVersions,
scalaVersion := scalaVersions.last,
ideSkipProject := true
)
}
lazy val `weejson-play25` = playProject("2.5.19", Seq(scala211))
lazy val `weejson-play27` = playProject("2.7.4", supportedScala2Versions)
lazy val `weejson-play28` = playProject("2.8.2", Seq(scala213))
// Using play-json version numbering, which is slightly confusing. Play 2.9 uses play-json 2.10 for some reason,
// and no version of Play actually uses play-json 2.9
lazy val `weejson-play29` = playProject("2.9.4", Seq(scala213))
lazy val `weejson-play210` = playProject("2.10.1", Seq(scala213, scala3)).settings(
mimaPreviousArtifacts := {
if (VersionNumber(version.value).matchesSemVer(SemanticSelector("<1.9.0")) && scalaBinaryVersion.value == "2.13")
Set.empty // TODO: remove once there's a previous Scala 2.13 artifact
else
mimaPreviousArtifacts.value
}
)
lazy val `weejson-upickle` = project
.dependsOn(weepickle)
.settings(
libraryDependencies ++= Seq(
// 2.x.x/3.x.x break binary compatibility, consider for weePickle v2
"com.lihaoyi" %% "upickle" % "1.6.0",
),
mimaPreviousArtifacts := {
if (VersionNumber(version.value).matchesSemVer(SemanticSelector("<1.6.0")))
Set.empty
else
mimaPreviousArtifacts.value
}
)
lazy val weeyaml = project
.dependsOn(`weejson-jackson`)
.settings(
libraryDependencies ++= Seq(
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % "2.15.2",
)
)
lazy val weexml = project
.dependsOn(
`weejson-jackson`,
weejson % Test,
)
.settings(
libraryDependencies ++= Seq(
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-xml" % "2.15.2",
)
)
lazy val `weepickle-macro-lint-tests` = project
.dependsOn(weepickle)
.settings(noPublish)
.settings(scalacOptions := (scalacOptions.value ++ Seq("-Xlint", "-Xfatal-warnings")).distinct)
.settings(crossScalaVersions := supportedScala2Versions) // TODO: Scala 3?
// .settings(scalacOptions += "-Ymacro-debug-lite")