forked from milessabin/shapeless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
300 lines (259 loc) · 9.98 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
import com.typesafe.sbt.SbtGit._
import GitKeys._
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
import sbtcrossproject.CrossProject
val Scala211 = "2.11.12"
val Scala212 = "2.12.11"
val Scala213 = "2.13.1"
val isScalaNative = System.getenv("SCALA_NATIVE") != null
val hasScalaJsVersion = System.getenv("SCALA_JS_VERSION") != null
commonSettings
noPublishSettings
crossScalaVersions := Nil
inThisBuild(Seq(
organization := "com.chuusai",
scalaVersion := Scala213,
crossScalaVersions := Seq(Scala211, Scala212, Scala213),
mimaFailOnNoPrevious := false
))
addCommandAlias("root", ";project shapeless")
addCommandAlias("core", ";project coreJVM")
addCommandAlias("scratch", ";project scratchJVM")
addCommandAlias("examples", ";project examplesJVM")
addCommandAlias("validate", ";root;validateJVM;validateJS;validateNative")
addCommandAlias("validateJVM", ";coreJVM/compile;coreJVM/mimaReportBinaryIssues;coreJVM/test;examplesJVM/compile;examplesJVM/test;coreJVM/doc")
addCommandAlias("validateJS", ";coreJS/compile;coreJS/mimaReportBinaryIssues;coreJS/test;examplesJS/compile;examplesJS/test;coreJS/doc")
addCommandAlias("validateNative", ";coreNative/compile;nativeTest/run;examplesNative/compile")
addCommandAlias("validateCI", if (isScalaNative) "validateNative" else if (hasScalaJsVersion) "validateJS" else "validateJVM")
addCommandAlias("runAll", ";examplesJVM/runAll")
lazy val scoverageSettings = Seq(
coverageMinimum := 60,
coverageFailOnMinimum := false,
coverageExcludedFiles := ".*/src/test/.*"
)
val scalacOptionsAll = Seq(
"-feature",
"-language:higherKinds,implicitConversions",
"-Xfatal-warnings",
"-deprecation",
"-unchecked",
)
val scalacOptions212 = Seq(
"-Xlint:-adapted-args,-delayedinit-select,-nullary-unit,-package-object-classes,-type-parameter-shadow,_",
"-Ywarn-unused:-implicits"
)
lazy val commonSettings = Seq(
incOptions := incOptions.value.withLogRecompileOnMacro(false),
scalacOptions := scalacOptionsAll,
scalacOptions in compile in Compile ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, y)) if y >= 12 => scalacOptions212
case _ => Nil
}),
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
),
scalacOptions in console in Compile -= "-Xfatal-warnings",
scalacOptions in console in Test -= "-Xfatal-warnings",
initialCommands in console := """import shapeless._""",
scmInfo :=
Some(ScmInfo(
url("https://github.com/milessabin/shapeless"),
"scm:git:[email protected]:milessabin/shapeless.git"
))
) ++ crossVersionSharedSources ++ scalaMacroDependencies
def configureJUnit(crossProject: CrossProject) = {
crossProject
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
.jvmSettings(
libraryDependencies +=
"com.novocode" % "junit-interface" % "0.11" % "test"
)
}
lazy val commonJsSettings = Seq(
scalacOptions in (Compile, doc) -= "-Xfatal-warnings",
parallelExecution in Test := false,
coverageEnabled := false
)
lazy val commonJvmSettings = Seq(
parallelExecution in Test := false,
coverageExcludedPackages := "shapeless.examples.*"
)
lazy val commonNativeSettings = Seq(
scalaVersion := Scala211,
crossScalaVersions := Seq(Scala211)
)
lazy val coreSettings = commonSettings ++ publishSettings
lazy val CrossTypeMixed: sbtcrossproject.CrossType = new sbtcrossproject.CrossType {
def projectDir(crossBase: File, projectType: String): File =
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 sharedSrcDir(projectBase: File, conf: String): Option[File] =
Some(projectBase.getParentFile / "src" / conf / "scala")
}
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossTypeMixed)
.configureCross(configureJUnit)
.settings(moduleName := "shapeless")
.settings(coreSettings:_*)
.configureCross(buildInfoSetup)
.enablePlugins(SbtOsgi)
.settings(coreOsgiSettings:_*)
.settings(sourceGenerators in Compile += (sourceManaged in Compile).map(Boilerplate.gen).taskValue)
.settings(mimaSettings:_*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)
.jvmSettings(scoverageSettings:_*)
.jvmSettings(skip in publish := hasScalaJsVersion)
.nativeSettings(skip in publish := hasScalaJsVersion)
.nativeSettings(
commonNativeSettings,
// disable scaladoc generation on native
// currently getting errors like
// [error] bnd: Invalid syntax for version: ${@}, for cmd: range, arguments; [range, [==,=+), ${@}]
publishArtifact in (Compile, packageDoc) := false,
publishArtifact in packageDoc := false,
sources in (Compile,doc) := Nil,
sources in Test := Nil
)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val coreNative = core.native
lazy val scratch = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure)
.configureCross(configureJUnit)
.dependsOn(core)
.settings(moduleName := "scratch")
.settings(coreSettings:_*)
.settings(noPublishSettings:_*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)
.nativeSettings(commonNativeSettings:_*)
lazy val scratchJVM = scratch.jvm
lazy val scratchJS = scratch.js
lazy val scratchNative = scratch.native
lazy val runAll = TaskKey[Unit]("runAll")
def runAllIn(config: Configuration): Setting[Task[Unit]] = {
runAll in config := {
val classes = (discoveredMainClasses in config).value
val runner0 = (runner in run).value
val cp = (fullClasspath in config).value
val s = streams.value
classes.foreach(c => runner0.run(c, Attributed.data(cp), Seq(), s.log))
}
}
lazy val examples = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure)
.configureCross(configureJUnit)
.dependsOn(core)
.settings(moduleName := "examples")
.settings(
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMajor)) if scalaMajor >= 11 =>
Seq("org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2")
case _ => Seq()
}
}
)
.settings(runAllIn(Compile))
.settings(coreSettings:_*)
.settings(noPublishSettings:_*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)
.nativeSettings(
commonNativeSettings,
sources in Compile ~= (_.filterNot(_.getName == "sexp.scala")),
sources in Test := Nil
)
lazy val examplesJVM = examples.jvm
lazy val examplesJS = examples.js
lazy val examplesNative = examples.native
lazy val nativeTest = project
.enablePlugins(ScalaNativePlugin)
.settings(
commonNativeSettings,
noPublishSettings,
sourceGenerators in Compile += Def.task {
val exclude = List(
"StagedTypeClassExample", // scala-reflect
"CombinatorTesting", // scala-parser-combinators
"ALaCacheDemo" // java.util.WeakHashMap, java.util.logging.Logger
)
val classNames = (discoveredMainClasses in Compile in examplesNative).value.filterNot{
c => exclude.exists(c.contains)
}.sorted
val src = s"""package shapeless
|
|object NativeMain {
| def main(args: Array[String]): Unit = {
|${classNames.map(" " + _ + ".main(args)").mkString("\n")}
| }
|}
|""".stripMargin
val f = (sourceManaged in Compile).value / "shapeless" / "NativeMain.scala"
IO.write(f, src)
f :: Nil
}.taskValue
).dependsOn(
examplesNative
)
lazy val scalaMacroDependencies: Seq[Setting[_]] = Seq(
libraryDependencies ++= Seq(
scalaOrganization.value % "scala-reflect" % scalaVersion.value % "provided",
scalaOrganization.value % "scala-compiler" % scalaVersion.value % "provided"
)
)
lazy val crossVersionSharedSources: Seq[Setting[_]] =
Seq(Compile, Test).map { sc =>
(unmanagedSourceDirectories in sc) ++= {
(unmanagedSourceDirectories in sc ).value.flatMap { dir: File =>
if(dir.getName != "scala") Seq(dir)
else
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, y)) if y >= 13 => Seq(new File(dir.getPath + "_2.13+"))
case Some((2, y)) if y >= 11 => Seq(new File(dir.getPath + "_2.13-"))
}
}
}
}
lazy val publishSettings = Seq(
publishArtifact in Test := false,
pomIncludeRepository := (_ => false),
homepage := Some(url("https://github.com/milessabin/shapeless")),
licenses := Seq("Apache 2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
scmInfo := Some(ScmInfo(url("https://github.com/milessabin/shapeless"), "scm:git:[email protected]:milessabin/shapeless.git")),
developers := List(
Developer("milessabin", "Miles Sabin", "", url("http://milessabin.com/blog")),
Developer("joroKr21", "Georgi Krastev", "[email protected]", url("https://twitter.com/Joro_Kr"))
)
)
lazy val noPublishSettings =
skip in publish := true
enablePlugins(MimaPlugin)
lazy val mimaSettings = Seq(
mimaPreviousArtifacts := Set(),
mimaBinaryIssueFilters := Seq()
)
def buildInfoSetup(crossProject: CrossProject): CrossProject = {
def transform(project: Project) = project enablePlugins BuildInfoPlugin settings (
buildInfoPackage := "shapeless",
buildInfoUsePackageAsPath := true,
buildInfoKeys := Seq[BuildInfoKey](version, scalaVersion, gitHeadCommit),
buildInfoOptions += BuildInfoOption.BuildTime
)
crossProject jvmConfigure transform jsConfigure transform nativeConfigure transform
}
lazy val coreOsgiSettings = osgiSettings ++ Seq(
OsgiKeys.bundleSymbolicName := "shapeless",
OsgiKeys.exportPackage := Seq("shapeless.*;version=${Bundle-Version}"),
OsgiKeys.importPackage := {
val Some((major, minor)) = CrossVersion.partialVersion(scalaVersion.value)
Seq(s"""!scala.quasiquotes,scala.*;version="[$major.$minor,$major.${minor+1})"""")
},
OsgiKeys.additionalHeaders := Map("-removeheaders" -> "Include-Resource,Private-Package")
)