forked from milessabin/shapeless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
223 lines (194 loc) · 8.71 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
import com.typesafe.sbt.SbtGit.GitKeys._
import sbtcrossproject.CrossProject
val Scala212 = "2.12.17"
val Scala213 = "2.13.7"
commonSettings
noPublishSettings
crossScalaVersions := Nil
ThisBuild / organization := "com.chuusai"
ThisBuild / scalaVersion := Scala213
ThisBuild / crossScalaVersions := Seq(Scala212, Scala213)
ThisBuild / mimaFailOnNoPrevious := false
// GHA configuration
ThisBuild / githubWorkflowBuildPreamble := Seq(WorkflowStep.Run(List("sudo apt install clang libunwind-dev libgc-dev libre2-dev")))
ThisBuild / githubWorkflowJavaVersions := Seq("adopt@1.8")
ThisBuild / githubWorkflowBuildMatrixAdditions += "platform" -> List("jvm", "js", "native")
ThisBuild / githubWorkflowArtifactUpload := false
ThisBuild / githubWorkflowBuildMatrixFailFast := Some(false)
val JvmCond = s"matrix.platform == 'jvm'"
val JsCond = s"matrix.platform == 'js'"
val NativeCond = s"matrix.platform == 'native'"
ThisBuild / githubWorkflowBuild := Seq(
WorkflowStep.Sbt(List("validateJVM"), name = Some("Validate JVM"), cond = Some(JvmCond)),
WorkflowStep.Sbt(List("validateJS"), name = Some("Validate JavaScript"), cond = Some(JsCond)),
WorkflowStep.Sbt(List("validateNative"), name = Some("Validate Scala Native"), cond = Some(NativeCond))
)
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches += RefPredicate.StartsWith(Ref.Tag("v"))
ThisBuild / githubWorkflowPublishPreamble += WorkflowStep.Use(UseRef.Public("olafurpg", "setup-gpg", "v3"))
ThisBuild / githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
List("ci-release"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
)
)
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;examplesJVM/runAll;coreJVM/doc")
addCommandAlias("validateJS", ";coreJS/compile;coreJS/mimaReportBinaryIssues;coreJS/test;examplesJS/compile;examplesJS/test;examplesJS/runAll;coreJS/doc")
addCommandAlias("validateNative", ";coreNative/compile;coreNative/test;examplesNative/compile;examplesNative/test;examplesNative/runAll;coreNative/doc")
addCommandAlias("runAll", ";examplesJVM/runAll")
def scalacOptionsAll(pluginJar: File) = List(
"-feature",
"-language:higherKinds,implicitConversions",
"-Xfatal-warnings",
"-deprecation",
"-unchecked",
s"-Xplugin:${pluginJar.getAbsolutePath}",
s"-Jdummy=${pluginJar.lastModified}"
)
val scalacOptions212 = Seq(
"-Xlint:-adapted-args,-delayedinit-select,-nullary-unit,-package-object-classes,-type-parameter-shadow,_",
"-Ywarn-unused:-implicits"
)
val scalacOptions213 = Seq(
"-Xlint:-adapted-args,-delayedinit-select,-nullary-unit,-package-object-classes,-type-parameter-shadow,-byname-implicit,_",
"-Ywarn-unused:-implicits"
)
lazy val commonSettings = crossVersionSharedSources ++ Seq(
resolvers ++= Resolver.sonatypeOssRepos("releases"),
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
incOptions := incOptions.value.withLogRecompileOnMacro(false),
scalacOptions := scalacOptionsAll((plugin / Compile / packageBin).value),
Compile / compile / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => scalacOptions212
case Some((2, 13)) => scalacOptions213
case _ => Nil
}),
Compile / console / scalacOptions -= "-Xfatal-warnings",
Test / console / scalacOptions -= "-Xfatal-warnings",
console / initialCommands := """import shapeless._""",
Test / parallelExecution := false,
libraryDependencies ++= Seq(
scalaOrganization.value % "scala-reflect" % scalaVersion.value % "provided",
scalaOrganization.value % "scala-compiler" % scalaVersion.value % "provided"
)
)
def configureJUnit(crossProject: CrossProject) = crossProject
.jvmSettings(libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.3" % "test")
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
.nativeConfigure(_.enablePlugins(ScalaNativeJUnitPlugin))
lazy val plugin = project.in(file("plugin"))
.settings(crossVersionSharedSources)
.settings(publishSettings)
.settings(
name := "shapeless-plugin",
moduleName := "shapeless-plugin",
sbtPlugin := true,
scalaVersion := Scala213,
crossScalaVersions := Seq(Scala213, Scala212)
)
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Full)
.configureCross(configureJUnit)
.settings(moduleName := "shapeless")
.settings(commonSettings)
.settings(publishSettings)
.configureCross(buildInfoSetup)
.enablePlugins(SbtOsgi)
.settings(coreOsgiSettings)
.settings(Compile / sourceManaged := baseDirectory.value.getParentFile / "shared" / "src" / "main" / "managed")
.settings(Compile / sourceGenerators += (Compile / sourceManaged).map(Boilerplate.gen).taskValue)
.settings(mimaSettings)
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(commonSettings)
.settings(noPublishSettings)
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]] = {
config / runAll := {
val classes = (config / discoveredMainClasses).value
val runner0 = (run / runner).value
val cp = (config / fullClasspath).value
val s = streams.value
classes.foreach(c => runner0.run(c, Attributed.data(cp), Nil, s.log))
}
}
lazy val examples = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.configureCross(configureJUnit)
.dependsOn(core)
.settings(moduleName := "examples")
.settings(libraryDependencies += "org.scala-lang.modules" %%% "scala-parser-combinators" % "2.1.1")
.settings(runAllIn(Compile))
.settings(commonSettings)
.settings(noPublishSettings)
.nativeSettings(Compile / sources ~= (_.filterNot(_.getName == "sexp.scala")))
lazy val examplesJVM = examples.jvm
lazy val examplesJS = examples.js
lazy val examplesNative = examples.native
lazy val crossVersionSharedSources: Seq[Setting[_]] =
Seq(Compile, Test).map { sc =>
(sc / unmanagedSourceDirectories) ++= {
(sc / unmanagedSourceDirectories).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 < 13 => Seq(new File(dir.getPath + "_2.13-"))
}
}
}
}
lazy val publishSettings = Seq(
Test / publishArtifact := 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:git@github.com:milessabin/shapeless.git")),
developers := List(
Developer("milessabin", "Miles Sabin", "", url("http://milessabin.com/blog")),
Developer("joroKr21", "Georgi Krastev", "joro.kr.21@gmail.com", url("https://twitter.com/Joro_Kr"))
)
)
lazy val noPublishSettings =
publish / skip := 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")
)