forked from scalameta/scalafmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
339 lines (317 loc) · 9.26 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
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
import Dependencies._
import sbtcrossproject.CrossPlugin.autoImport.crossProject
def parseTagVersion: String = {
import scala.sys.process._
// drop `v` prefix
"git describe --abbrev=0 --tags".!!.drop(1).trim
}
def localSnapshotVersion: String = s"$parseTagVersion-SNAPSHOT"
def isCI = System.getenv("CI") != null
def scala212 = "2.12.15"
def scala213 = "2.13.8"
inThisBuild(
List(
version ~= { dynVer =>
if (isCI) dynVer
else localSnapshotVersion // only for local publishing
},
organization := "org.scalameta",
homepage := Some(url("https://github.com/scalameta/scalafmt")),
licenses := List(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
),
developers := List(
Developer(
"olafurpg",
"Ólafur Páll Geirsson",
url("https://geirsson.com")
)
),
scalaVersion := scala213,
crossScalaVersions := List(scala213, scala212),
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
),
libraryDependencies ++= List(
munit.value % Test,
scalacheck % Test,
scalametaTestkit % Test
),
testFrameworks += new TestFramework("munit.Framework")
)
)
name := "scalafmtRoot"
publish / skip := true
addCommandAlias("native-image", "cli/nativeImage")
commands += Command.command("ci-test") { s =>
val scalaVersion = sys.env.get("TEST") match {
case Some("2.12") => scala212
case _ => scala213
}
val docsTest = if (scalaVersion == scala212) "docs/run" else "version"
s"++$scalaVersion" ::
"tests/test" ::
"dynamic/test" ::
"publishLocal" ::
docsTest ::
s
}
lazy val dynamic = project
.in(file("scalafmt-dynamic"))
.settings(
moduleName := "scalafmt-dynamic",
description := "Implementation of scalafmt-interfaces",
buildInfoSettings,
buildInfoPackage := "org.scalafmt.dynamic",
buildInfoObject := "BuildInfo",
libraryDependencies ++= List(
"io.get-coursier" % "interface" % "0.0.17",
"com.typesafe" % "config" % "1.4.2",
munit.value % Test,
scalametaTestkit % Test
),
scalacOptions ++= scalacJvmOptions.value
)
.dependsOn(interfaces)
.enablePlugins(BuildInfoPlugin)
lazy val interfaces = project
.in(file("scalafmt-interfaces"))
.settings(
moduleName := "scalafmt-interfaces",
description := "Dependency-free, pure Java public interfaces to integrate with Scalafmt through a build tool or editor plugin.",
crossVersion := CrossVersion.disabled,
autoScalaLibrary := false,
Compile / resourceGenerators += Def.task {
val out =
(Compile / managedResourceDirectories).value.head / "scalafmt.properties"
val props = new java.util.Properties()
props.put("version", version.value)
IO.write(props, "scalafmt properties", out)
List(out)
}
)
lazy val sysops = crossProject(JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.in(file("scalafmt-sysops"))
.settings(
moduleName := "scalafmt-sysops",
description := "Scalafmt systems operations",
scalacOptions ++= scalacJvmOptions.value,
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) =>
Seq(
"com.github.bigwheel" %% "util-backports" % "2.1"
)
case Some((2, 13)) =>
Seq(
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4"
)
case _ =>
Seq(
)
}
}
)
lazy val config = crossProject(JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.in(file("scalafmt-config"))
.settings(
moduleName := "scalafmt-config",
description := "Scalafmt config parsing",
scalacOptions ++= scalacJvmOptions.value,
libraryDependencies ++= Seq(
metaconfig.value
)
)
.jvmSettings(
libraryDependencies ++= Seq(
metaconfigTypesafe.value
)
)
// .jsSettings(
// libraryDependencies ++= Seq(
// metaconfigHocon.value,
// )
// )
lazy val core = crossProject(JVMPlatform)
.in(file("scalafmt-core"))
.settings(
moduleName := "scalafmt-core",
buildInfoSettings,
scalacOptions ++= scalacJvmOptions.value,
libraryDependencies ++= Seq(
scalameta.value,
// scala-reflect is an undeclared dependency of fansi, see #1252.
// Scalafmt itself does not require scala-reflect.
"org.scala-lang" % "scala-reflect" % scalaVersion.value
),
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) =>
Seq(
)
case _ =>
Seq(
compilerPlugin(
"org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full
)
)
}
}
)
// .jsSettings(
// libraryDependencies ++= List(
// scalatest.value % Test // must be here for coreJS/test to run anything
// )
// )
.jvmSettings(
Test / run / fork := true
)
.dependsOn(sysops, config)
.enablePlugins(BuildInfoPlugin)
lazy val coreJVM = core.jvm
// lazy val coreJS = core.js
import sbtassembly.AssemblyPlugin.defaultUniversalScript
val scalacJvmOptions = Def.setting {
val cross = CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => Seq("-target:jvm-1.8")
case Some((2, 13)) =>
Seq(
"-Ymacro-annotations",
"-Xfatal-warnings",
"-deprecation:false"
)
case _ => Seq.empty
}
val unused = Seq(
"imports",
"privates",
"locals",
"patvars",
"implicits"
).map(x => s"-Ywarn-unused:$x")
cross ++ unused
}
lazy val cli = project
.in(file("scalafmt-cli"))
.settings(
moduleName := "scalafmt-cli",
assembly / mainClass := Some("org.scalafmt.cli.Cli"),
assembly / assemblyOption := (assembly / assemblyOption).value
.withPrependShellScript(Some(defaultUniversalScript(shebang = false))),
assembly / assemblyJarName := "scalafmt.jar",
assembly / assemblyMergeStrategy := {
case "reflect.properties" => MergeStrategy.first
case x =>
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(x)
},
libraryDependencies ++= Seq(
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0",
"com.martiansoftware" % "nailgun-server" % "0.9.1",
"com.github.scopt" %% "scopt" % "4.0.1",
// undeclared transitive dependency of coursier-small
"org.scala-lang.modules" %% "scala-xml" % "1.3.0"
),
scalacOptions ++= scalacJvmOptions.value,
Compile / mainClass := Some("org.scalafmt.cli.Cli"),
nativeImageVersion := "20.1.0",
nativeImageOptions ++= {
sys.env
.get("NATIVE_IMAGE_MUSL")
.map(path => s"-H:UseMuslC=$path")
.toSeq ++
sys.env
.get("NATIVE_IMAGE_STATIC")
.map(_.toBoolean)
.filter(identity)
.map(_ => "--static")
.toSeq
}
)
.dependsOn(coreJVM, dynamic)
.enablePlugins(NativeImagePlugin)
lazy val tests = project
.in(file("scalafmt-tests"))
.settings(
publish / skip := true,
libraryDependencies ++= Seq(
// Test dependencies
"com.lihaoyi" %% "scalatags" % "0.11.1",
scalametaTestkit,
munit.value
),
scalacOptions ++= scalacJvmOptions.value,
javaOptions += "-Dfile.encoding=UTF8",
buildInfoPackage := "org.scalafmt.tests",
buildInfoKeys := Seq[BuildInfoKey](
"resourceDirectory" -> (Test / resourceDirectory).value
)
)
.enablePlugins(BuildInfoPlugin)
.dependsOn(coreJVM, dynamic, cli)
lazy val benchmarks = project
.in(file("scalafmt-benchmarks"))
.settings(
publish / skip := true,
moduleName := "scalafmt-benchmarks",
libraryDependencies ++= Seq(
scalametaTestkit
),
run / javaOptions ++= Seq(
"-Djava.net.preferIPv4Stack=true",
"-XX:+AggressiveOpts",
"-XX:+UseParNewGC",
"-XX:+UseConcMarkSweepGC",
"-XX:+CMSParallelRemarkEnabled",
"-XX:+CMSClassUnloadingEnabled",
"-XX:ReservedCodeCacheSize=128m",
"-XX:MaxMetaspaceSize=1024m",
"-XX:SurvivorRatio=128",
"-XX:MaxTenuringThreshold=0",
"-Xss8M",
"-Xms512M",
"-Xmx2G",
"-server"
)
)
.dependsOn(coreJVM)
.enablePlugins(JmhPlugin)
lazy val docs = project
.in(file("scalafmt-docs"))
.settings(
crossScalaVersions := List(scala212),
publish / skip := true,
mdoc := (Compile / run).evaluated
)
.dependsOn(cli, dynamic)
.enablePlugins(DocusaurusPlugin)
val V = "\\d+\\.\\d+\\.\\d+"
val ReleaseCandidate = s"($V-RC\\d+).*".r
val Milestone = s"($V-M\\d+).*".r
lazy val stableVersion = Def.setting {
(ThisBuild / version).value.replaceAll("\\+.*", "")
}
lazy val buildInfoSettings: Seq[Def.Setting[_]] = Seq(
buildInfoKeys := Seq[BuildInfoKey](
name,
version,
"scalameta" -> scalametaV,
"nightly" -> version.value,
"stable" -> stableVersion.value,
"previousStable" ->
previousStableVersion.value.getOrElse(stableVersion.value),
"scala" -> scalaVersion.value,
"scala212" -> scala212,
"coursier" -> coursier,
"commit" -> sys.process.Process("git rev-parse HEAD").lineStream_!.head,
"timestamp" -> System.currentTimeMillis().toString,
scalaVersion,
sbtVersion
),
buildInfoPackage := "org.scalafmt",
buildInfoObject := "Versions"
)