forked from scalaz/scalaz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.scala
393 lines (345 loc) · 13.5 KB
/
build.scala
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
import sbt._
import Project.Setting
import Keys._
import GenTypeClass._
import java.awt.Desktop
import sbtrelease._
import sbtrelease.ReleasePlugin.autoImport._
import sbtrelease.ReleaseStateTransformations._
import sbtrelease.Utilities._
import com.typesafe.sbt.pgp.PgpKeys._
import com.typesafe.sbt.osgi.OsgiKeys
import com.typesafe.sbt.osgi.SbtOsgi._
import sbtbuildinfo.BuildInfoPlugin.autoImport._
import com.typesafe.tools.mima.plugin.MimaPlugin.mimaDefaultSettings
import com.typesafe.tools.mima.plugin.MimaKeys.mimaPreviousArtifacts
import scalanative.sbtplugin.ScalaNativePlugin.autoImport._
import scalajscrossproject.ScalaJSCrossPlugin.autoImport.{toScalaJSGroupID => _, _}
import sbtcrossproject.CrossPlugin.autoImport._
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.isScalaJSProject
object build {
type Sett = Def.Setting[_]
val rootNativeId = "rootNative"
val nativeTestId = "nativeTest"
lazy val publishSignedArtifacts = ReleaseStep(
action = st => {
val extracted = st.extract
val ref = extracted.get(thisProjectRef)
extracted.runAggregated(publishSigned in Global in ref, st)
},
check = st => {
// getPublishTo fails if no publish repository is set up.
val ex = st.extract
val ref = ex.get(thisProjectRef)
Classpaths.getPublishTo(ex.get(publishTo in Global in ref))
st
},
enableCrossBuild = true
)
lazy val setMimaVersion: ReleaseStep = { st: State =>
val extracted = Project.extract(st)
val (releaseV, _) = st.get(ReleaseKeys.versions).getOrElse(sys.error("impossible"))
IO.write(extracted get releaseVersionFile, s"""\nbuild.scalazMimaBasis in ThisBuild := "${releaseV}"\n""", append = true)
reapply(Seq(scalazMimaBasis in ThisBuild := releaseV), st)
}
val scalaCheckVersion_1_12 = SettingKey[String]("scalaCheckVersion_1_12")
val scalaCheckVersion_1_13 = SettingKey[String]("scalaCheckVersion_1_13")
val kindProjectorVersion = SettingKey[String]("kindProjectorVersion")
private[this] def gitHash(): String = sys.process.Process("git rev-parse HEAD").lines_!.head
// no generic signatures for scala 2.10.x, see SI-7932, #571 and #828
def scalac210Options = Seq("-Yno-generic-signatures")
private[this] val tagName = Def.setting{
s"v${if (releaseUseGlobalVersion.value) (version in ThisBuild).value else version.value}"
}
private[this] val tagOrHash = Def.setting{
if(isSnapshot.value) gitHash() else tagName.value
}
val scalajsProjectSettings = Seq[Sett](
scalacOptions += {
val a = (baseDirectory in LocalRootProject).value.toURI.toString
val g = "https://raw.githubusercontent.com/scalaz/scalaz/" + tagOrHash.value
s"-P:scalajs:mapSourceURI:$a->$g/"
}
)
lazy val notPublish = Seq(
publishArtifact := false,
publish := {},
publishLocal := {},
publishSigned := {},
publishLocalSigned := {}
)
// avoid move files
object ScalazCrossType extends sbtcrossproject.CrossType {
override def projectDir(crossBase: File, projectType: String) =
crossBase / projectType
override def projectDir(crossBase: File, projectType: sbtcrossproject.Platform) = {
val dir = projectType match {
case JVMPlatform => "jvm"
case JSPlatform => "js"
case NativePlatform => "native"
}
crossBase / dir
}
def shared(projectBase: File, conf: String) =
projectBase.getParentFile / "src" / conf / "scala"
override def sharedSrcDir(projectBase: File, conf: String) =
Some(shared(projectBase, conf))
}
private def Scala211 = "2.11.11"
private def Scala212 = "2.12.4"
private val SetScala211 = releaseStepCommand("++" + Scala211)
private[this] val buildInfoPackageName = "scalaz"
lazy val standardSettings: Seq[Sett] = Seq[Sett](
unmanagedSourceDirectories in Compile += {
val base = ScalazCrossType.shared(baseDirectory.value, "main").getParentFile
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v >= 12 =>
base / "scala-2.12+"
case _ =>
base / "scala-2.12-"
}
},
organization := "org.scalaz",
mappings in (Compile, packageSrc) ++= (managedSources in Compile).value.map{ f =>
// https://github.com/sbt/sbt-buildinfo/blob/v0.7.0/src/main/scala/sbtbuildinfo/BuildInfoPlugin.scala#L58
val buildInfoDir = "sbt-buildinfo"
val path = if(f.getAbsolutePath.contains(buildInfoDir)) {
(file(buildInfoPackageName) / f.relativeTo((sourceManaged in Compile).value / buildInfoDir).get.getPath).getPath
} else {
f.relativeTo((sourceManaged in Compile).value).get.getPath
}
(f, path)
},
scalaVersion := Scala212,
crossScalaVersions := Seq("2.10.6", Scala211, Scala212, "2.13.0-M2"),
resolvers ++= (if (scalaVersion.value.endsWith("-SNAPSHOT")) List(Opts.resolver.sonatypeSnapshots) else Nil),
fullResolvers ~= {_.filterNot(_.name == "jcenter")}, // https://github.com/sbt/sbt/issues/2217
scalaCheckVersion_1_12 := {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v <= 11 =>
"1.12.5"
case _ =>
"1.12.6"
}
},
scalaCheckVersion_1_13 := "1.13.5",
scalacOptions ++= Seq(
// contains -language:postfixOps (because 1+ as a parameter to a higher-order function is treated as a postfix op)
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-Xfuture",
"-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-language:postfixOps",
"-unchecked"
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2,10)) => scalac210Options
case Some((2,v)) if v >= 12 => Seq("-opt:l:method")
case _ => Nil
}),
scalacOptions in (Compile, doc) ++= {
val base = (baseDirectory in LocalRootProject).value.getAbsolutePath
Seq("-sourcepath", base, "-doc-source-url", "https://github.com/scalaz/scalaz/tree/" + tagOrHash.value + "€{FILE_PATH}.scala")
},
// retronym: I was seeing intermittent heap exhaustion in scalacheck based tests, so opting for determinism.
parallelExecution in Test := false,
testOptions in Test += {
val scalacheckOptions = Seq("-maxSize", "5", "-workers", "1", "-maxDiscardRatio", "50") ++ {
if(isScalaJSProject.value)
Seq("-minSuccessfulTests", "10")
else
Seq("-minSuccessfulTests", "33")
}
Tests.Argument(TestFrameworks.ScalaCheck, scalacheckOptions: _*)
},
genTypeClasses := {
typeClasses.value.flatMap { tc =>
val dir = name.value match {
case ConcurrentName =>
(scalaSource in Compile).value
case _ =>
ScalazCrossType.shared(baseDirectory.value, "main")
}
typeclassSource(tc).sources.map(_.createOrUpdate(dir, streams.value.log))
}
},
checkGenTypeClasses := {
val classes = genTypeClasses.value
if(classes.exists(_._1 != FileStatus.NoChange))
sys.error(classes.groupBy(_._1).filterKeys(_ != FileStatus.NoChange).mapValues(_.map(_._2)).toString)
},
typeClasses := Seq(),
genToSyntax := {
val tcs = typeClasses.value
val objects = tcs.map(tc => "object %s extends To%sSyntax".format(Util.initLower(tc.name), tc.name)).mkString("\n")
val all = "object all extends " + tcs.map(tc => "To%sSyntax".format(tc.name)).mkString(" with ")
objects + "\n\n" + all
},
typeClassTree := {
typeClasses.value.map(_.doc).mkString("\n")
},
showDoc in Compile := {
val _ = (doc in Compile).value
val out = (target in doc in Compile).value
val index = out / "index.html"
if (index.exists()) Desktop.getDesktop.open(out / "index.html")
},
credentialsSetting,
publishSetting,
publishArtifact in Test := false,
// adapted from sbt-release defaults
// (performs `publish-signed` instead of `publish`)
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runTest,
SetScala211,
releaseStepCommand(s"${nativeTestId}/run"),
setReleaseVersion,
commitReleaseVersion,
tagRelease,
publishSignedArtifacts,
SetScala211,
releaseStepCommand(s"${rootNativeId}/publishSigned"),
setNextVersion,
setMimaVersion,
commitNextVersion,
pushChanges
),
releaseTagName := tagName.value,
pomIncludeRepository := {
x => false
},
pomExtra := (
<url>http://scalaz.org</url>
<licenses>
<license>
<name>BSD-style</name>
<url>http://opensource.org/licenses/BSD-3-Clause</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>[email protected]:scalaz/scalaz.git</url>
<connection>scm:git:[email protected]:scalaz/scalaz.git</connection>
</scm>
<developers>
{
Seq(
("runarorama", "Runar Bjarnason"),
("pchiusano", "Paul Chiusano"),
("tonymorris", "Tony Morris"),
("retronym", "Jason Zaugg"),
("ekmett", "Edward Kmett"),
("alexeyr", "Alexey Romanov"),
("copumpkin", "Daniel Peebles"),
("rwallace", "Richard Wallace"),
("nuttycom", "Kris Nuttycombe"),
("larsrh", "Lars Hupel")
).map {
case (id, name) =>
<developer>
<id>{id}</id>
<name>{name}</name>
<url>https://github.com/{id}</url>
</developer>
}
}
</developers>
),
// kind-projector plugin
libraryDependencies ++= (scalaBinaryVersion.value match {
case "2.10" =>
compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.patch) :: Nil
case _ =>
Nil
}),
resolvers += Resolver.sonatypeRepo("releases"),
kindProjectorVersion := "0.9.4",
libraryDependencies += compilerPlugin("org.spire-math" % "kind-projector" % kindProjectorVersion.value cross CrossVersion.binary)
) ++ osgiSettings ++ Seq[Sett](
OsgiKeys.additionalHeaders := Map("-removeheaders" -> "Include-Resource,Private-Package")
) ++ mimaDefaultSettings ++ Seq[Sett](
mimaPreviousArtifacts := {
val artifactId =
if(isScalaJSProject.value) {
s"${name.value}_sjs0.6_${scalaBinaryVersion.value}"
} else {
s"${name.value}_${scalaBinaryVersion.value}"
}
scalazMimaBasis.?.value.map {
organization.value % artifactId % _
}.toSet
}
)
val nativeSettings = Seq(
scalaVersion := Scala211,
crossScalaVersions := Scala211 :: Nil
)
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(ScalazCrossType)
.settings(standardSettings)
.settings(
name := "scalaz-core",
sourceGenerators in Compile += (sourceManaged in Compile).map{
dir => Seq(GenerateTupleW(dir), TupleNInstances(dir))
}.taskValue,
buildInfoKeys := Seq[BuildInfoKey](version, scalaVersion),
buildInfoPackage := buildInfoPackageName,
osgiExport("scalaz"),
OsgiKeys.importPackage := Seq("javax.swing;resolution:=optional", "*"))
.enablePlugins(sbtbuildinfo.BuildInfoPlugin)
.jsSettings(scalajsProjectSettings)
.jvmSettings(
typeClasses := TypeClass.core
)
.nativeSettings(
nativeSettings
)
final val ConcurrentName = "scalaz-concurrent"
lazy val effect = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(ScalazCrossType)
.settings(standardSettings)
.settings(
name := "scalaz-effect",
osgiExport("scalaz.effect", "scalaz.std.effect", "scalaz.syntax.effect"))
.dependsOn(core)
.jsSettings(scalajsProjectSettings)
.jvmSettings(
typeClasses := TypeClass.effect
)
.nativeSettings(
nativeSettings
)
lazy val iteratee = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(ScalazCrossType)
.settings(standardSettings)
.settings(
name := "scalaz-iteratee",
osgiExport("scalaz.iteratee"))
.dependsOn(core, effect)
.jsSettings(scalajsProjectSettings)
.nativeSettings(
nativeSettings
)
lazy val publishSetting = publishTo := {
val nexus = "https://oss.sonatype.org/"
if (version.value.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
lazy val credentialsSetting = credentials += {
Seq("build.publish.user", "build.publish.password") map sys.props.get match {
case Seq(Some(user), Some(pass)) =>
Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", user, pass)
case _ =>
Credentials(Path.userHome / ".ivy2" / ".credentials")
}
}
lazy val scalazMimaBasis = SettingKey[String]("scalazMimaBasis", "Version of scalaz against which to run MIMA.")
lazy val genTypeClasses = TaskKey[Seq[(FileStatus, File)]]("gen-type-classes")
lazy val typeClasses = TaskKey[Seq[TypeClass]]("type-classes")
lazy val genToSyntax = TaskKey[String]("gen-to-syntax")
lazy val showDoc = TaskKey[Unit]("show-doc")
lazy val typeClassTree = TaskKey[String]("type-class-tree", "Generates scaladoc formatted tree of type classes.")
lazy val checkGenTypeClasses = TaskKey[Unit]("check-gen-type-classes")
def osgiExport(packs: String*) = OsgiKeys.exportPackage := packs.map(_ + ".*;version=${Bundle-Version}")
}
// vim: expandtab:ts=2:sw=2