-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sbt
297 lines (273 loc) · 10.2 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
lazy val scala213 = "2.13.3"
lazy val scala212 = "2.12.11"
lazy val scala211 = "2.11.12"
lazy val scala210 = "2.10.7"
lazy val supportedScalaVersions = List(scala213, scala212, scala211, scala210)
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.2.0" % Test
ThisBuild / name := "auxify"
ThisBuild / organization := "com.github.dmytromitin"
ThisBuild / organizationName := "Dmytro Mitin"
ThisBuild / organizationHomepage := Some(url("https://github.com/DmytroMitin"))
ThisBuild / version := "0.9"
ThisBuild / scalaVersion := scala213
ThisBuild / scmInfo := Some(ScmInfo(
url("https://github.com/DmytroMitin/AUXify"),
"https://github.com/DmytroMitin/AUXify.git"
))
ThisBuild / developers := List(Developer(
id = "DmytroMitin",
name = "Dmytro Mitin",
email = "[email protected]",
url = url("https://github.com/DmytroMitin")
))
ThisBuild / description := "Library providing macro/meta annotations @aux, @self, @instance, @apply, @delegated, @syntax and String-based type class LabelledGeneric"
ThisBuild / licenses := List("Apache 2" -> new URL("http://www.apache.org/licenses/LICENSE-2.0.txt"))
ThisBuild / homepage := Some(url("https://github.com/DmytroMitin/AUXify"))
// Remove all additional repository other than Maven Central from POM
ThisBuild / pomIncludeRepository := { _ => false }
ThisBuild / publishMavenStyle := true
ThisBuild / credentials += Credentials(Path.userHome / ".sbt" / "sonatype_credential")
ThisBuild / publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
def previousVersion(version: String): String = {
val prefix = "0."
val decremented = version.stripPrefix(prefix).toInt - 1
s"$prefix$decremented"
}
lazy val root = (project in file("."))
.aggregate(
shapeless,
macros,
macrosTests,
metaCore,
metaRules,
metaTests,
metaUnitTests,
syntacticMeta,
syntacticMetaTests,
)
.settings(
crossScalaVersions := Nil,
publish / skip := true,
)
// ======================= SHAPELESS =============================
lazy val shapeless = (project in file("shapeless")).settings(
name := "auxify-shapeless",
macrosCommonSettings,
// scalaVersion := scala210, // for test
libraryDependencies ++= Seq(
scalaOrganization.value % "scala-reflect" % scalaVersion.value,
organization.value %% "auxify-macros" % previousVersion(version.value),
scalaTest,
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v >= 11 =>
Seq(organization.value %% "shapeless" % "2.4.0-M1-30032020-e6c3f71-PATCH")
// Seq("com.chuusai" %% "shapeless" % "2.4.0-M1")
// Seq() //lib-2.11+
case _ =>
Seq(organization.value %% "shapeless" % "2.4.0-SNAPSHOT-18022020-bf55524-PATCH")
// Seq("com.chuusai" %% "shapeless" % "2.4.0-SNAPSHOT")
// Seq("com.chuusai" %% "shapeless" % "2.3.3")
// Seq() //lib-2.10
}),
scalacOptions ++= Seq(
// "-deprecation",
// "-unchecked",
// "-Ymacro-debug-lite",
// "-Xlog-implicits",
// "-Ylog-classpath",
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v >= 11 && v <= 12 => Seq("-Ypartial-unification")
case _ => Seq()
}),
//https://stackoverflow.com/questions/24558700/using-a-2-10-only-sbt-plugin-in-a-project-thats-cross-built-against-2-9/
resolvers ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v >= 11 => Seq()
case _ =>
addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.2")
Seq(Classpaths.sbtPluginReleases)
}),
// unmanagedBase := baseDirectory.value / (CrossVersion.partialVersion(scalaVersion.value) match {
// case Some((2, v)) => s"lib-2.$v"
// case _ => "lib"
// })
)
// ======================= MACROS ================================
lazy val macroCompatV = "1.1.2"
//lazy val macroCompatV = "1.1.1"
lazy val macrosCommonSettings = Seq(
crossScalaVersions := supportedScalaVersions,
scalacOptions ++= (
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v >= 13 => Seq("-Ymacro-annotations")
case _ => Nil
}) ++ Seq(
// "-Ymacro-debug-lite",
// "-Ymacro-debug-verbose",
// "-Ydebug",
// "-Xprint:typer",
// "-Xprint-types",
),
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("public"),
),
libraryDependencies ++= (
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v >= 13 => Seq(
// "org.typelevel" % "macro-compat_2.13.0-RC2" % macroCompatV,
)
case _ => Seq(
compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full),
// "org.typelevel" %% "macro-compat" % macroCompatV,
)
}
) ++ Seq(
"com.github.dmytromitin" %% "macro-compat" % macroCompatV,
scalaOrganization.value % "scala-compiler" % scalaVersion.value % Provided, // for macro-compat
)
)
lazy val macros = (project in file("macros")).settings(
name := "auxify-macros",
libraryDependencies += scalaOrganization.value % "scala-reflect" % scalaVersion.value,
macrosCommonSettings,
)
lazy val macrosTests = (project in file("macros-tests")).dependsOn(macros).settings(
name := "auxify-macros-tests",
libraryDependencies += scalaTest,
macrosCommonSettings,
publish / skip := true,
)
// ======================= META ================================
lazy val V = _root_.scalafix.sbt.BuildInfo
lazy val metaCommonSettings = Seq(
crossScalaVersions := Seq(V.scala213, V.scala212, V.scala211),
scalaVersion := V.scala213,
addCompilerPlugin(scalafixSemanticdb),
scalacOptions ++= List(
"-Yrangepos",
"-P:semanticdb:synthetics:on",
)
)
lazy val metaRules = (project in file("meta"))
.settings(
name := "auxify-meta",
libraryDependencies ++= Seq(
"ch.epfl.scala" %% "scalafix-core" % V.scalafixVersion,
),
metaCommonSettings
)
lazy val metaIn = (project in file("meta-in"))
.dependsOn(metaCore)
.settings(
name := "auxify-meta-in",
publish / skip := true,
metaCommonSettings
)
lazy val metaOut = (project in file("meta-out"))
.dependsOn(metaCore) // for import and if meta annotation is not expanded // TODO #15
.settings(
name := "auxify-meta-out",
sourceGenerators.in(Compile) += Def.taskDyn {
val root = baseDirectory.in(ThisBuild).value.toURI.toString
val from = sourceDirectory.in(metaIn, Compile).value
val to = sourceManaged.in(Compile).value
val outFrom = from.toURI.toString.stripSuffix("/").stripPrefix(root)
val outTo = to.toURI.toString.stripSuffix("/").stripPrefix(root)
Def.task {
scalafix
.in(metaIn, Compile)
.toTask(s" --rules=file:meta/src/main/scala/com/github/dmytromitin/auxify/meta/AuxRule.scala --out-from=$outFrom --out-to=$outTo")
.value
(to ** "*.scala").get
}
}.taskValue,
publish / skip := true,
metaCommonSettings
)
lazy val metaOutExpectedForTests = (project in file("meta-out-expected-for-tests"))
.dependsOn(metaCore) // for import statement and if meta annotation is not expanded // TODO #15
.settings(
name := "auxify-out-expected-for-tests",
skip in publish := true,
metaCommonSettings
)
// config file meta/src/main/resources/META-INF/services/scalafix.v1.Rule and top comment /* SomeRule */
// in meta-in/src/main/scala/[package]/[input file].scala are necessary for tests,
// for code generation they are not necessary
lazy val metaTests = (project in file("meta-tests"))
.dependsOn(metaRules)
.settings(
name := "auxify-meta-tests",
skip in publish := true,
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % V.scalafixVersion % Test cross CrossVersion.full,
compile.in(Compile) :=
compile.in(Compile).dependsOn(compile.in(metaIn, Compile)).value,
scalafixTestkitOutputSourceDirectories :=
sourceDirectories.in(metaOutExpectedForTests, Compile).value,
scalafixTestkitInputSourceDirectories :=
sourceDirectories.in(metaIn, Compile).value,
scalafixTestkitInputClasspath :=
fullClasspath.in(metaIn, Compile).value,
metaCommonSettings
)
.enablePlugins(ScalafixTestkitPlugin)
lazy val metaUnitTests = (project in file("meta-unit-tests"))
.dependsOn(metaOut)
.settings(
name := "auxify-meta-tests",
publish / skip := true,
libraryDependencies += scalaTest,
metaCommonSettings
)
// ======================= SYNTACTIC META ================================
lazy val syntacticMetaCommonSettings = Seq(
crossScalaVersions := Seq(scala213, scala212, scala211),
scalaVersion := scala213,
)
lazy val metaCore = (project in file("meta-core"))
.settings(
name := "auxify-meta-core",
syntacticMetaCommonSettings,
)
lazy val syntacticMeta = (project in file("syntactic-meta"))
.settings(
name := "auxify-syntactic-meta",
libraryDependencies ++= Seq(
"org.scalameta" %% "scalameta" % "4.3.18",
),
syntacticMetaCommonSettings,
)
lazy val syntacticMetaIn = (project in file("syntactic-meta-in"))
.dependsOn(metaCore)
.settings(
name := "auxify-syntactic-meta-in",
syntacticMetaCommonSettings,
skip in publish := true,
)
lazy val syntacticMetaOut = (project in file("syntactic-meta-out"))
.dependsOn(metaCore) // for import statement and if meta annotation is not expanded // TODO #15
.settings(
name := "auxify-syntactic-meta-out",
sourceGenerators in Compile += Def.task {
import com.github.dmytromitin.auxify.meta.syntactic.Generator
Generator.gen(
inputDir = sourceDirectory.in(syntacticMetaIn, Compile).value,
outputDir = sourceManaged.in(Compile).value
)
}.taskValue,
syntacticMetaCommonSettings,
skip in publish := true,
)
lazy val syntacticMetaTests = (project in file("syntactic-meta-tests"))
.dependsOn(syntacticMetaOut)
.settings(
name := "auxify-syntactic-meta-tests",
libraryDependencies += scalaTest,
syntacticMetaCommonSettings,
skip in publish := true,
)