forked from typelevel/simulacrum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
222 lines (208 loc) · 7.55 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
import sbtrelease._
import com.typesafe.tools.mima.core._
import sbtcrossproject.{crossProject, CrossType}
import ReleaseTransformations._
val Scala211 = "2.11.12"
def ifAtLeast(scalaBinaryVersion: String, atLeastVersion: String)(options: String*): Seq[String] = {
case class ScalaBinaryVersion(major: Int, minor: Int) extends Ordered[ScalaBinaryVersion] {
def compare(that: ScalaBinaryVersion) = Ordering[(Int, Int)].compare((this.major, this.minor), (that.major, that.minor))
}
val Pattern = """(\d+)\.(\d+).*""".r
def getScalaBinaryVersion(v: String) = v match { case Pattern(major, minor) => ScalaBinaryVersion(major.toInt, minor.toInt) }
if (getScalaBinaryVersion(scalaBinaryVersion) >= getScalaBinaryVersion(atLeastVersion)) options
else Seq.empty
}
lazy val scalatestSetting = Def.setting(
if (scalaVersion.value == "2.13.0-M4") {
Seq("org.scalatest" %%% "scalatest" % "3.0.6-SNAP1" % "test")
} else {
Seq("org.scalatest" %%% "scalatest" % "3.1.0-KH" % "test")
}
)
lazy val nativeCommonSettings = Def.settings(
// https://github.com/scalatest/scalatest/issues/1112#issuecomment-366856502
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.0-SNAP10" % "test",
scalaVersion := Scala211,
crossScalaVersions := Seq(Scala211),
nativeLinkStubs := true
)
lazy val commonSettings = Seq(
organization := "com.github.mpilquist",
scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-language:higherKinds",
"-language:implicitConversions"
) ++ ifAtLeast(scalaBinaryVersion.value, "2.11.0")(
"-Ywarn-unused-import"
),
scalacOptions in (Compile, doc) ~= { _ filterNot { o => o == "-Ywarn-unused-import" || o == "-Xfatal-warnings" } },
scalacOptions in (Compile, console) ~= { _ filterNot { o => o == "-Ywarn-unused-import" || o == "-Xfatal-warnings" } },
scalacOptions in (Test, console) := (scalacOptions in (Compile, console)).value,
scalaVersion := "2.12.6",
crossScalaVersions := Seq("2.13.0-M4"),
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
),
libraryDependencies := {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v >= 13 =>
libraryDependencies.value.filterNot{ d =>
d.organization == "org.wartremover" && d.name == "wartremover"
}
case _ =>
libraryDependencies.value
}
},
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v <= 12 =>
Seq(
compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
)
case _ =>
// if scala 2.13.0-M4 or later, macro annotations merged into scala-reflect
// https://github.com/scala/scala/pull/6606
Nil
}
},
licenses += ("Three-clause BSD-style", url("https://github.com/mpilquist/simulacrum/blob/master/LICENSE")),
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")
},
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := { x => false },
pomExtra := (
<url>http://github.com/mpilquist/simulacrum</url>
<scm>
<url>git@github.com:mpilquist/simulacrum.git</url>
<connection>scm:git:git@github.com:mpilquist/simulacrum.git</connection>
</scm>
<developers>
<developer>
<id>mpilquist</id>
<name>Michael Pilquist</name>
<url>http://github.com/mpilquist</url>
</developer>
</developers>
),
pomPostProcess := { (node) =>
import scala.xml._
import scala.xml.transform._
def stripIf(f: Node => Boolean) = new RewriteRule {
override def transform(n: Node) =
if (f(n)) NodeSeq.Empty else n
}
val stripTestScope = stripIf { n => n.label == "dependency" && (n \ "scope").text == "test" }
new RuleTransformer(stripTestScope).transform(node)(0)
},
releaseCrossBuild := true,
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
publishArtifacts,
releaseStepCommandAndRemaining(s";++${Scala211}!;coreNative/publishSigned"),
setNextVersion,
commitNextVersion,
pushChanges
),
useGpg := true,
useGpgAgent := true,
wartremoverErrors in (Test, compile) ++= Seq(
Wart.ExplicitImplicitTypes,
Wart.ImplicitConversion)
) ++ Seq(Compile, Test).map{ scope =>
scalacOptions in (scope, compile) := {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v >= 13 =>
(scalacOptions in (scope, compile)).value.filterNot(_.contains("wartremover")) :+ "-Ymacro-annotations"
case _ =>
(scalacOptions in (scope, compile)).value
}
}
}
lazy val root = project.in(file("."))
.settings(commonSettings: _*)
.settings(noPublishSettings: _*)
.aggregate(coreJVM, examplesJVM, coreJS, examplesJS)
def previousVersion(currentVersion: String): Option[String] = {
val Version = """(\d+)\.(\d+)\.(\d+).*""".r
val Version(x, y, z) = currentVersion
if (z == "0") None
else Some(s"$x.$y.${z.toInt - 1}")
}
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure)
.settings(commonSettings: _*)
.settings(
moduleName := "simulacrum",
libraryDependencies += "org.typelevel" %% "macro-compat" % "1.1.2-KH",
scalacOptions in (Test) += "-Yno-imports"
)
.settings(scalaMacroDependencies:_*)
.nativeSettings(
nativeCommonSettings
)
.platformsSettings(JVMPlatform, JSPlatform)(
libraryDependencies ++= scalatestSetting.value
)
.platformsSettings(JSPlatform, NativePlatform)(
excludeFilter in (Test, unmanagedSources) := "jvm.scala"
)
.jvmSettings(
mimaPreviousArtifacts := previousVersion(version.value).map { pv =>
organization.value % ("simulacrum" + "_" + scalaBinaryVersion.value) % pv
}.toSet
)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val coreNative = core.native
lazy val examples = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure)
.dependsOn(core % "provided")
.settings(commonSettings: _*)
.settings(moduleName := "simulacrum-examples")
.settings(noPublishSettings: _*)
.platformsSettings(JVMPlatform, JSPlatform)(
libraryDependencies ++= scalatestSetting.value
)
.nativeSettings(
nativeCommonSettings
)
lazy val examplesJVM = examples.jvm
lazy val examplesJS = examples.js
lazy val examplesNative = examples.native
// Base Build Settings
lazy val scalaMacroDependencies: Seq[Setting[_]] = Seq(
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided",
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided"
),
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
// if scala 2.11+ is used, quasiquotes are merged into scala-reflect
case Some((2, scalaMajor)) if scalaMajor >= 11 => Seq()
// in Scala 2.10, quasiquotes are provided by macro paradise
case Some((2, 10)) =>
Seq(
compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full),
"org.scalamacros" %% "quasiquotes" % "2.1.0" cross CrossVersion.binary
)
}
}
)
lazy val noPublishSettings = Seq(
publish := {},
publishLocal := {},
publishArtifact := false
)