forked from scala/scala-collection-compat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
371 lines (328 loc) · 12.1 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
import ScalaModulePlugin._
import sbtcrossproject.{crossProject, CrossType}
import _root_.scalafix.Versions.{version => scalafixVersion, scala212 => scalafixScala212}
lazy val root = project
.in(file("."))
.settings(dontPublish)
.aggregate(
compat211JVM,
compat211JS,
compat212JVM,
compat212JS,
compat213JVM,
compat213JS,
`scalafix-data211`,
`scalafix-data212`,
`scalafix-data213`,
`scalafix-input`,
`scalafix-output211`,
`scalafix-output212`,
`scalafix-output213`,
// `scalafix-output213-failure`,
`scalafix-rules`,
`scalafix-tests`
)
.disablePlugins(ScalafixPlugin)
// == Core Libraries ==
lazy val junit = libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test
lazy val scala211 = "2.11.12"
lazy val scala212 = "2.12.6"
lazy val scalaJs213 = "2.13.0-M4" // Scala.js does no have -pre
lazy val scala213 = "2.13.0-M4"
// lazy val scala213 = "2.13.0-pre-3ae6282" // use the sbt command `latest-213` to fetch the latest version
lazy val scala213Settings = Seq(
resolvers += "scala-pr" at "https://scala-ci.typesafe.com/artifactory/scala-integration/",
scalaVersion := scala213
)
lazy val compat = MultiScalaCrossProject(JSPlatform, JVMPlatform)(
"compat",
_.settings(scalaModuleSettings)
.jvmSettings(scalaModuleSettingsJVM)
.settings(
name := "scala-collection-compat",
moduleName := "scala-collection-compat",
version := "0.2.0-SNAPSHOT",
scalacOptions ++= Seq("-feature", "-language:higherKinds", "-language:implicitConversions"),
unmanagedSourceDirectories in Compile += {
val sharedSourceDir = (baseDirectory in ThisBuild).value / "compat/src/main"
if (scalaVersion.value.startsWith("2.13.")) sharedSourceDir / "scala-2.13"
else sharedSourceDir / "scala-2.11_2.12"
}
)
.jvmSettings(
OsgiKeys.exportPackage := Seq(s"scala.collection.compat.*;version=${version.value}"),
junit,
javaHome in Compile := {
val oldValue = (javaHome in Compile).value
val isOnCi = sys.env.get("CI").isDefined
if (isOnCi) {
// switch back to the jdk set by the build matrix
val ciJavaHome =
sys.env("TRAVIS_JDK_VERSION") match {
case "openjdk6" => "/usr/lib/jvm/java-6-openjdk-amd64"
case "oraclejdk8" => "/usr/lib/jvm/java-8-oracle"
}
println(s"using JAVA_HOME: $ciJavaHome")
Some(file(ciJavaHome))
} else oldValue
},
javaHome in Test := (javaHome in Compile).value
)
.jsSettings(
scalacOptions += {
val x = (baseDirectory in LocalRootProject).value.toURI.toString
val y = "https://raw.githubusercontent.com/scala/scala-collection-compat/" + sys.process
.Process("git rev-parse HEAD")
.lines_!
.head
s"-P:scalajs:mapSourceURI:$x->$y/"
},
fork in Test := false // Scala.js cannot run forked tests
)
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
.disablePlugins(ScalafixPlugin)
)
val compat211 = compat(scala211)
val compat212 = compat(scala212)
val compat213 = compat(scala213, scalaJs213, _.jvmSettings(scala213Settings))
lazy val compat211JVM = compat211.jvm
lazy val compat211JS = compat211.js
lazy val compat212JVM = compat212.jvm
lazy val compat212JS = compat212.js
lazy val compat213JVM = compat213.jvm
lazy val compat213JS = compat213.js
lazy val `binary-compat-old` = project
.in(file("binary-compat/old"))
.settings(scalaVersion := scala212)
.disablePlugins(ScalafixPlugin)
lazy val `binary-compat-new` = project
.in(file("binary-compat/new"))
.settings(scalaVersion := scala212)
.dependsOn(compat212JVM)
.disablePlugins(ScalafixPlugin)
lazy val `binary-compat` = project
.in(file("binary-compat/test"))
.settings(
scalaVersion := scala212,
libraryDependencies += "com.typesafe" %% "mima-reporter" % "0.3.0" % Test,
junit,
buildInfoPackage := "build",
buildInfoKeys := Seq[BuildInfoKey](
"oldClasspath" -> (classDirectory in (`binary-compat-old`, Compile)).value.toString,
"newClasspath" -> (classDirectory in (`binary-compat-new`, Compile)).value.toString
),
test in Test := (test in Test)
.dependsOn(
compile in (`binary-compat-old`, Compile),
compile in (`binary-compat-new`, Compile)
)
.value
)
.enablePlugins(BuildInfoPlugin)
.disablePlugins(ScalafixPlugin)
lazy val `scalafix-rules` = project
.in(file("scalafix/rules"))
.settings(
organization := (organization in compat212JVM).value,
version := (version in compat212JVM).value,
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 `scalafix-data` = MultiScalaProject("scalafix-data",
"scalafix/data",
_.settings(sharedScalafixSettings)
.settings(dontPublish))
val `scalafix-data211` = `scalafix-data`(scala211, _.dependsOn(compat211JVM))
val `scalafix-data212` = `scalafix-data`(scalafixScala212, _.dependsOn(compat212JVM))
val `scalafix-data213` =
`scalafix-data`(scala213, _.settings(scala213Settings).dependsOn(compat213JVM))
lazy val `scalafix-input` = project
.in(file("scalafix/input"))
.settings(sharedScalafixSettings)
.settings(dontPublish)
.settings(
scalaVersion := scalafixScala212,
scalafixSourceroot := sourceDirectory.in(Compile).value
)
.dependsOn(`scalafix-data212`)
val `scalafix-output` = MultiScalaProject("scalafix-output",
"scalafix/output",
_.settings(sharedScalafixSettings)
.settings(dontPublish)
.disablePlugins(ScalafixPlugin))
lazy val output212 = Def.setting((baseDirectory in ThisBuild).value / "scalafix/output212/src/main")
lazy val addOutput212 = unmanagedSourceDirectories in Compile += output212.value / "scala"
lazy val output212Plus =
Def.setting((baseDirectory in ThisBuild).value / "scalafix/output212+/src/main")
lazy val addOutput212Plus = unmanagedSourceDirectories in Compile += output212Plus.value / "scala"
lazy val output213 = Def.setting((baseDirectory in ThisBuild).value / "scalafix/output213/src/main")
lazy val addOutput213 = unmanagedSourceDirectories in Compile += output213.value / "scala"
lazy val `scalafix-output211` = `scalafix-output`(
scala211,
_.dependsOn(`scalafix-data211`)
)
lazy val `scalafix-output212` = `scalafix-output`(
scala212,
_.settings(addOutput212)
.settings(addOutput212Plus)
.dependsOn(`scalafix-data212`)
)
lazy val `scalafix-output213` = `scalafix-output`(
scala213,
_.settings(addOutput213)
.settings(addOutput212Plus)
.settings(scala213Settings)
.dependsOn(`scalafix-data213`)
)
lazy val `scalafix-output213-failure` = project
.in(file("scalafix/output213-failure"))
.settings(sharedScalafixSettings)
.settings(scala213Settings)
.settings(dontPublish)
lazy val `scalafix-tests` = project
.in(file("scalafix/tests"))
.settings(sharedScalafixSettings)
.settings(dontPublish)
.settings(
scalaVersion := scalafixScala212,
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % scalafixVersion % Test cross CrossVersion.full,
buildInfoPackage := "build",
buildInfoKeys := Seq[BuildInfoKey](
"inputSourceroot" -> sourceDirectory.in(`scalafix-input`, Compile).value,
"outputSourceroot" -> (baseDirectory in ThisBuild).value / "scalafix/output/src/main",
"output212Sourceroot" -> output212.value,
"output212PlusSourceroot" -> output212Plus.value,
"output213Sourceroot" -> output213.value,
"output213FailureSourceroot" -> sourceDirectory
.in(`scalafix-output213-failure`, Compile)
.value,
"inputClassdirectory" -> classDirectory.in(`scalafix-input`, Compile).value
),
test in Test := (test in Test)
.dependsOn(
compile in (`scalafix-output211`, Compile),
compile in (`scalafix-output212`, Compile),
compile in (`scalafix-output213`, Compile)
)
.value
)
.dependsOn(`scalafix-input`, `scalafix-rules`)
.enablePlugins(BuildInfoPlugin)
lazy val dontPublish = Seq(
publishArtifact := false,
packagedArtifacts := Map.empty,
publish := {},
publishLocal := {}
)
val preRelease = "pre-release"
val travisScalaVersion = sys.env.get("TRAVIS_SCALA_VERSION").flatMap(Version.parse)
val releaseVersion = sys.env.get("TRAVIS_TAG").flatMap(Version.parse)
val isScalaJs = sys.env.get("SCALAJS_VERSION").nonEmpty
val isScalafix = sys.env.get("TEST_SCALAFIX").nonEmpty
val isScalafmt = sys.env.get("TEST_SCALAFMT").nonEmpty
val isBinaryCompat = sys.env.get("TEST_BINARY_COMPAT").nonEmpty
val isRelease = releaseVersion.nonEmpty
val releaseCredentials =
if (isRelease) {
def env(key: String): String = Option(System.getenv(key)).getOrElse("")
Seq(
pgpPassphrase := Some(env("PGP_PASSPHRASE").toArray),
pgpPublicRing := file("admin/pubring.asc"),
pgpSecretRing := file("admin/secring.asc"),
credentials += Credentials("Sonatype Nexus Repository Manager",
"oss.sonatype.org",
env("SONA_USER"),
env("SONA_PASS"))
)
} else {
Seq()
}
inThisBuild(releaseCredentials)
// required by sbt-scala-module
inThisBuild(
Seq(
crossScalaVersions := Seq(scala211, scala212, scala213),
commands += Command.command("latest-213") { state =>
LatestScala.printLatestScala213()
state
},
commands += Command.command(preRelease) { state =>
// Show Compat version, Scala version, and Java Version
val jvmVersion = Version.parse(sys.props("java.specification.version")).get.minor
val tagVersion = releaseVersion.get
println(
s"Releasing $tagVersion with Scala ${travisScalaVersion.get} on Java version $jvmVersion.")
// Copy pgp stuff
"admin/pre-release.sh" ! state.globalLogging.full
state
},
commands += Command.command("scalafmt-test") { state =>
Seq("admin/scalafmt.sh", "--test") ! state.globalLogging.full
state
},
commands += Command.command("scalafmt") { state =>
Seq("admin/scalafmt.sh") ! state.globalLogging.full
state
},
commands += Command.command("ci") { state =>
val toRun =
if (isScalafmt) {
Seq("scalafmt-test")
} else {
val platformSuffix = if (isScalaJs) "JS" else ""
val compatProject = "compat" + travisScalaVersion.get.binary + platformSuffix
val binaryCompatProject = "binary-compat"
val testProjectPrefix =
if (isScalafix) {
"scalafix-tests"
} else if (isBinaryCompat) {
binaryCompatProject
} else {
compatProject
}
val projectPrefix =
if (isScalafix) {
"scalafix-rules"
} else if (isBinaryCompat) {
binaryCompatProject
} else {
compatProject
}
val setPublishVersion =
releaseVersion.map("set every version := " + _).toList
val publishTask =
if (releaseVersion.nonEmpty) {
List(
preRelease,
s"$projectPrefix/publish-signed"
)
} else {
Nil
}
Seq(
setPublishVersion,
List(s"$projectPrefix/clean"),
List(s"$testProjectPrefix/test"),
List(s"$projectPrefix/publishLocal"),
publishTask
).flatten
}
println("---------")
println("Running CI: ")
toRun.foreach(println)
println("---------")
toRun ::: state
}
))