-
Notifications
You must be signed in to change notification settings - Fork 87
/
build.sbt
406 lines (372 loc) · 13.6 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
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
import _root_.scalafix.sbt.BuildInfo.{scalafixVersion, scala212 => scalafixScala212}
lazy val commonSettings = Seq(
headerLicense := Some(HeaderLicense.Custom(s"""|Scala (https://www.scala-lang.org)
|
|Copyright EPFL and Lightbend, Inc.
|
|Licensed under Apache License 2.0
|(http://www.apache.org/licenses/LICENSE-2.0).
|
|See the NOTICE file distributed with this work for
|additional information regarding copyright ownership.
|""".stripMargin))
)
lazy val root = project
.in(file("."))
.settings(commonSettings)
.settings(
name := "scala-collection-compat",
publish / skip := true
)
.aggregate(
compat211JVM,
compat211JS,
compat212JVM,
compat212JS,
compat212Native,
compat213JVM,
compat213JS,
compat213Native,
compat3JVM,
compat3JS,
compat3Native,
scalafixData211,
scalafixData212,
scalafixData213,
scalafixInput,
scalafixOutput211,
scalafixOutput212,
scalafixOutput213,
// scalafixOutput213Failure,
scalafixRules,
scalafixTests
)
.disablePlugins(ScalafixPlugin)
// == Core Libraries ==
lazy val junit = libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.3" % Test
lazy val scala211 = "2.11.12"
lazy val scala212 = "2.12.19"
lazy val scala213 = "2.13.13"
lazy val scala3 = "3.3.3"
lazy val compat = new MultiScalaCrossProject(
"compat",
_.settings(ScalaModulePlugin.scalaModuleSettings)
.settings(commonSettings)
.settings(
name := "scala-collection-compat",
moduleName := "scala-collection-compat",
scalaModuleAutomaticModuleName := Some("scala.collection.compat"),
scalacOptions ++= Seq("-feature", "-language:higherKinds", "-language:implicitConversions"),
Compile / unmanagedSourceDirectories += {
val sharedSourceDir = (ThisBuild / baseDirectory).value / "compat/src/main"
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _) | (2, 13)) =>
sharedSourceDir / "scala-2.13"
case _ =>
sharedSourceDir / "scala-2.11_2.12"
}
},
Test / unmanagedSourceDirectories += {
val sharedSourceDir = (ThisBuild / baseDirectory).value / "compat/src/test"
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _) | (2, 13)) =>
sharedSourceDir / "scala-2.13"
case _ =>
sharedSourceDir / "scala-2.11_2.12"
}
},
versionPolicyIntention := Compatibility.BinaryCompatible,
mimaBinaryIssueFilters ++= {
import com.typesafe.tools.mima.core._
import com.typesafe.tools.mima.core.ProblemFilters._
Seq(
exclude[ReversedMissingMethodProblem](
"scala.collection.compat.PackageShared.*"
), // it's package-private
exclude[Problem]("scala.collection.compat.*PreservingBuilder*")
)
}
)
.jvmSettings(
Test / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "compat/src/test/scala-jvm",
Compile / unmanagedSourceDirectories += {
val jvmParent = (ThisBuild / baseDirectory).value / "compat/jvm/src/main"
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _) | (2, 13)) =>
jvmParent / "scala-2.13"
case _ =>
jvmParent / "scala-2.11_2.12"
}
},
junit
)
.disablePlugins(ScalafixPlugin),
_.jsSettings(
scalacOptions ++= {
val x = (LocalRootProject / baseDirectory).value.toURI.toString
val y = "https://raw.githubusercontent.com/scala/scala-collection-compat/" + sys.process
.Process("git rev-parse HEAD")
.lineStream_!
.head
val opt = CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => "-scalajs-mapSourceURI"
case _ => "-P:scalajs:mapSourceURI"
}
Seq(s"$opt:$x->$y/")
},
Test / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value / "compat/src/test/scala-js",
Compile / unmanagedSourceDirectories += {
val jsAndNativeSourcesParent = (ThisBuild / baseDirectory).value / "compat/jsNative/src/main"
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _) | (2, 13)) =>
jsAndNativeSourcesParent / "scala-2.13"
case _ =>
jsAndNativeSourcesParent / "scala-2.11_2.12"
}
},
Test / fork := false // Scala.js cannot run forked tests
).jsEnablePlugins(ScalaJSJUnitPlugin),
_.nativeSettings(
mimaPreviousArtifacts := (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, 1)) => mimaPreviousArtifacts.value.filter(_.revision != "2.6.0")
case _ => mimaPreviousArtifacts.value
}),
Compile / unmanagedSourceDirectories += {
val jsAndNativeSourcesParent = (ThisBuild / baseDirectory).value / "compat/jsNative/src/main"
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _) | (2, 13)) =>
jsAndNativeSourcesParent / "scala-2.13"
case _ =>
jsAndNativeSourcesParent / "scala-2.11_2.12"
}
},
versionPolicyIntention := Compatibility.None,
versionCheck := {}, // I don't understand why this fails otherwise?! oh well
Test / fork := false // Scala Native cannot run forked tests
).nativeEnablePlugins(ScalaNativeJUnitPlugin)
)
val compat211 = compat(Seq(JSPlatform, JVMPlatform), scala211)
val compat212 = compat(Seq(JSPlatform, JVMPlatform, NativePlatform), scala212)
val compat213 = compat(Seq(JSPlatform, JVMPlatform, NativePlatform), scala213)
val compat3 = compat(Seq(JSPlatform, JVMPlatform, NativePlatform), scala3)
lazy val compat211JVM = compat211.jvm
lazy val compat211JS = compat211.js
lazy val compat212JVM = compat212.jvm
lazy val compat212JS = compat212.js
lazy val compat212Native = compat212.native
lazy val compat213JVM = compat213.jvm
lazy val compat213JS = compat213.js
lazy val compat213Native = compat213.native
lazy val compat3JVM = compat3.jvm
lazy val compat3JS = compat3.js
lazy val compat3Native = compat3.native
lazy val binaryCompatOld = project
.in(file("binary-compat/old"))
.settings(commonSettings)
.settings(scalaVersion := scala212)
.disablePlugins(ScalafixPlugin)
lazy val binaryCompatNew = project
.in(file("binary-compat/new"))
.settings(commonSettings)
.settings(scalaVersion := scala212)
.dependsOn(compat212JVM)
.disablePlugins(ScalafixPlugin)
lazy val binaryCompat = project
.in(file("binary-compat/test"))
.settings(commonSettings)
.settings(
scalaVersion := scala212,
libraryDependencies += "com.typesafe" %% "mima-core" % "0.8.0" % Test,
junit,
buildInfoPackage := "build",
buildInfoKeys := Seq[BuildInfoKey](
"oldClasses" -> (binaryCompatOld / Compile / classDirectory).value.toString,
"newClasses" -> (binaryCompatNew / Compile / classDirectory).value.toString
),
Test / test := (Test / test)
.dependsOn(
binaryCompatOld / Compile / compile,
binaryCompatNew / Compile / compile,
)
.value
)
.enablePlugins(BuildInfoPlugin)
.disablePlugins(ScalafixPlugin)
lazy val scalafixRules = project
.in(file("scalafix/rules"))
.settings(ScalaModulePlugin.scalaModuleSettings)
.settings(commonSettings)
.settings(
scalaModuleAutomaticModuleName := None,
versionPolicyIntention := Compatibility.None,
versionCheck := {}, // I don't understand why this fails otherwise?! oh well
name := "scala-collection-migrations",
scalaVersion := scalafixScala212,
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % scalafixVersion
)
// == Scalafix Test Setup ==
lazy val sharedScalafixSettings = Seq(
scalacOptions ++= Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-unchecked"
)
)
// common part between input/output
lazy val scalafixData = MultiScalaProject(
"scalafixData",
"scalafix/data",
_.settings(sharedScalafixSettings)
.settings(commonSettings)
.settings(publish / skip := true)
)
val scalafixData211 = scalafixData(scala211, _.dependsOn(compat211JVM))
val scalafixData212 = scalafixData(scalafixScala212, _.dependsOn(compat212JVM))
val scalafixData213 = scalafixData(scala213, _.dependsOn(compat213JVM))
lazy val scalafixInput = project
.in(file("scalafix/input"))
.settings(commonSettings)
.settings(sharedScalafixSettings)
.settings(
scalaVersion := scalafixScala212,
publish / skip := true,
headerCheck := Nil,
addCompilerPlugin(scalafixSemanticdb),
scalacOptions ++= Seq(
"-Yrangepos",
"-P:semanticdb:synthetics:on"
)
)
.dependsOn(scalafixData212)
val scalafixOutput = MultiScalaProject(
"scalafixOutput",
"scalafix/output",
_.settings(sharedScalafixSettings)
.settings(commonSettings)
.settings(
publish / skip := true,
headerCheck := Nil,
)
.disablePlugins(ScalafixPlugin)
)
lazy val outputCross =
Def.setting((ThisBuild / baseDirectory).value / "scalafix/output/src/main/scala")
lazy val output212 =
Def.setting((ThisBuild / baseDirectory).value / "scalafix/output212/src/main/scala")
lazy val addOutput212 = Compile / unmanagedSourceDirectories += output212.value
lazy val output212Plus =
Def.setting((ThisBuild / baseDirectory).value / "scalafix/output212+/src/main/scala")
lazy val addOutput212Plus = Compile / unmanagedSourceDirectories += output212Plus.value
lazy val output213 =
Def.setting((ThisBuild / baseDirectory).value / "scalafix/output213/src/main/scala")
lazy val addOutput213 = Compile / unmanagedSourceDirectories += output213.value
lazy val scalafixOutput211 = scalafixOutput(
scala211,
_.dependsOn(scalafixData211)
)
lazy val scalafixOutput212 = scalafixOutput(
scala212,
_.settings(addOutput212)
.settings(addOutput212Plus)
.dependsOn(scalafixData212)
)
lazy val scalafixOutput213 = scalafixOutput(
scala213,
_.settings(addOutput213)
.settings(addOutput212Plus)
.dependsOn(scalafixData213)
)
lazy val scalafixOutput213Failure = project
.in(file("scalafix/output213-failure"))
.settings(commonSettings)
.settings(sharedScalafixSettings)
.settings(publish / skip := true)
lazy val scalafixTests = project
.in(file("scalafix/tests"))
.settings(commonSettings)
.settings(sharedScalafixSettings)
.settings(
scalaVersion := scalafixScala212,
publish / skip := true,
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % scalafixVersion % Test cross CrossVersion
.full,
scalafixTestkitOutputSourceDirectories := Seq(
outputCross.value,
output212.value,
output212Plus.value,
output213.value
),
scalafixTestkitInputSourceDirectories := (scalafixInput / Compile / sourceDirectories).value,
scalafixTestkitInputClasspath := (scalafixInput / Compile / fullClasspath).value,
)
.dependsOn(scalafixInput, scalafixRules)
.enablePlugins(BuildInfoPlugin, ScalafixTestkitPlugin)
val ciScalaVersion = sys.env.get("CI_SCALA_VERSION").flatMap(Version.parse)
val ciPlatform = sys.env.get("CI_PLATFORM").map(p => if (p == "JVM") "" else p)
val isScalafix = sys.env.get("CI_MODE") == Some("testScalafix")
val isScalafmt = sys.env.get("CI_MODE") == Some("testScalafmt")
val isBinaryCompat = sys.env.get("CI_MODE") == Some("testBinaryCompat")
val isHeaderCheck = sys.env.get("CI_MODE") == Some("headerCheck")
val jdkVersion = sys.env.get("CI_JDK").map(_.toInt)
// required by sbt-scala-module
inThisBuild {
import scala.sys.process._
Seq(
commands += Command.command("scalafmtTest") { state =>
val exitCode = Seq("admin/scalafmt.sh", "--test") ! state.globalLogging.full
if (exitCode == 0) state else state.fail
},
commands += Command.command("scalafmt") { state =>
Seq("admin/scalafmt.sh") ! state.globalLogging.full
state
},
commands += Command.command("ci") { state =>
val toRun: Seq[String] =
if (isScalafmt)
Seq("scalafmtTest")
else if (isHeaderCheck)
Seq("headerCheck")
else {
List(
"CI_SCALA_VERSION",
"CI_PLATFORM",
"CI_MODE",
"CI_JDK",
).foreach(k =>
println(k.padTo(20, " ").mkString("") + " -> " + sys.env.getOrElse(k, "None")))
val compatProject = s"compat${ciScalaVersion.get}${ciPlatform.get}"
val binaryCompatProject = "binaryCompat"
val testProjectPrefix =
if (isScalafix) {
"scalafixTests"
} else if (isBinaryCompat) {
binaryCompatProject
} else {
compatProject
}
val projectPrefix =
if (isScalafix) {
"scalafixRules"
} else if (isBinaryCompat) {
binaryCompatProject
} else {
compatProject
}
Seq(
List(s"""++${sys.env.get("CI_SCALA_VERSION").get}"""),
List(s"$projectPrefix/clean"),
List(s"$testProjectPrefix/test"),
List(s"$projectPrefix/publishLocal"),
).flatten
}
println("---------")
println("Running CI: ")
toRun.foreach(println)
println("---------")
val newCommands = toRun.toList.map(Exec(_, None))
state.copy(remainingCommands = newCommands ::: state.remainingCommands)
}
)
}