-
Notifications
You must be signed in to change notification settings - Fork 276
/
build.sbt
333 lines (299 loc) · 11.6 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
import java.nio.file.Paths
import scala.scalanative.build._
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.20"
def scala213 = "2.13.15"
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 ++= Resolver.sonatypeOssRepos("releases"),
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
testFrameworks += new TestFramework("munit.Framework"),
// causes native image issues
dependencyOverrides += "org.jline" % "jline" % "3.23.0",
))
name := "scalafmtRoot"
publish / skip := true
addCommandAlias("native-image", "cli/nativeImage")
addCommandAlias("scala-native", "cliNative/compile;cliNative/nativeLink")
commands += Command.command("ci-test-jvm") { 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
}
commands += Command.command("ci-test-native") { s =>
val scalaVersion = sys.env.get("TEST") match {
case Some("2.12") => scala212
case _ => scala213
}
s"++$scalaVersion" :: "testsNative/test" :: s
}
lazy val dynamic = crossProject(JVMPlatform, NativePlatform)
.withoutSuffixFor(JVMPlatform).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" % "1.0.23",
"com.typesafe" % "config" % "1.4.3",
munit.value % Test,
scalametaTestkit.value % Test,
),
scalacOptions ++= scalacJvmOptions.value,
).dependsOn(interfaces, sysops).dependsOn(core % "test")
.enablePlugins(BuildInfoPlugin)
lazy val interfaces = crossProject(JVMPlatform, NativePlatform)
.withoutSuffixFor(JVMPlatform).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, NativePlatform)
.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, NativePlatform)
.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))
.nativeSettings(libraryDependencies ++= Seq(metaconfigSconfig.value))
// .jsSettings(
// libraryDependencies ++= Seq(
// metaconfigHocon.value,
// )
// )
lazy val core = crossProject(JVMPlatform, NativePlatform)
.in(file("scalafmt-core")).settings(
moduleName := "scalafmt-core",
buildInfoSettings,
scalacOptions ++= scalacJvmOptions.value,
libraryDependencies ++= Seq("org.scalameta" %%% "mdoc-parser" % mdocV),
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
// )
// )
.nativeSettings(libraryDependencies += "com.lihaoyi" %%% "fastparse" % "3.1.1")
.jvmSettings(Test / run / fork := true).dependsOn(sysops, config, macros)
.enablePlugins(BuildInfoPlugin)
lazy val coreJVM = core.jvm
// lazy val coreJS = core.js
lazy val macros = crossProject(JVMPlatform, NativePlatform)
.in(file("scalafmt-macros")).settings(
moduleName := "scalafmt-macros",
scalacOptions ++= scalacJvmOptions.value,
libraryDependencies ++= Seq(
scalameta.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
),
)
import sbtassembly.AssemblyPlugin.defaultUniversalScript
val scalacJvmOptions = Def.setting {
val cross = CrossVersion.partialVersion(scalaVersion.value) match {
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 = crossProject(JVMPlatform, NativePlatform)
.withoutSuffixFor(JVMPlatform).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(
"org.scalameta" %%% "munit-diff" % "1.0.2",
"com.martiansoftware" % "nailgun-server" % "0.9.1",
"com.github.scopt" %%% "scopt" % "4.1.0",
),
scalacOptions ++= scalacJvmOptions.value,
Compile / mainClass := Some("org.scalafmt.cli.Cli"),
nativeImageInstalled := isCI,
nativeImageOptions ++= {
// https://www.graalvm.org/22.3/reference-manual/native-image/guides/build-static-executables/
// https://www.graalvm.org/latest/reference-manual/native-image/guides/build-static-executables/
sys.env.get("NATIVE_IMAGE_STATIC") match {
case Some("nolibc") => Seq(
"-H:+UnlockExperimentalVMOptions",
"-H:+StaticExecutableWithDynamicLibC",
"-H:-UnlockExperimentalVMOptions",
)
case Some("musl") => Seq("--static", "--libc=musl")
case _ => Nil
}
},
).nativeSettings(scalaNativeConfig).dependsOn(core, dynamic)
.enablePlugins(NativeImagePlugin)
lazy val tests = crossProject(JVMPlatform, NativePlatform)
.withoutSuffixFor(JVMPlatform).in(file("scalafmt-tests")).settings(
publish / skip := true,
libraryDependencies ++= Seq(
// Test dependencies
"com.lihaoyi" %%% "scalatags" % "0.13.1",
scalametaTestkit.value,
munit.value,
),
scalacOptions ++= scalacJvmOptions.value,
buildInfoPackage := "org.scalafmt.tests",
buildInfoKeys := Seq[BuildInfoKey]("resourceDirectory" -> {
val sharedTests = (baseDirectory.value.getParentFile / "shared").toPath
(Test / resourceDirectories).value.find(_.toPath.startsWith(sharedTests))
.get
}),
).enablePlugins(BuildInfoPlugin)
.jvmSettings(javaOptions += "-Dfile.encoding=UTF8")
.dependsOn(core, dynamic, cli)
lazy val communityTestsCommon = project
.in(file("scalafmt-tests-community/common")).settings(
communityTestsSettings,
libraryDependencies ++= Seq(
// Test dependencies
"com.lihaoyi" %% "scalatags" % "0.13.1",
scalametaTestkit.value,
munit.value,
),
).enablePlugins(BuildInfoPlugin).dependsOn(coreJVM)
lazy val communityTestsScala2 = project
.in(file("scalafmt-tests-community/scala2")).settings(communityTestsSettings)
.enablePlugins(BuildInfoPlugin).dependsOn(communityTestsCommon)
lazy val communityTestsScala3 = project
.in(file("scalafmt-tests-community/scala3")).settings(communityTestsSettings)
.enablePlugins(BuildInfoPlugin).dependsOn(communityTestsCommon)
lazy val communityTestsSpark = project
.in(file("scalafmt-tests-community/spark")).settings(communityTestsSettings)
.enablePlugins(BuildInfoPlugin).dependsOn(communityTestsCommon)
lazy val communityTestsIntellij = project
.in(file("scalafmt-tests-community/intellij"))
.settings(communityTestsSettings).enablePlugins(BuildInfoPlugin)
.dependsOn(communityTestsCommon)
lazy val communityTestsOther = project
.in(file("scalafmt-tests-community/other")).settings(communityTestsSettings)
.enablePlugins(BuildInfoPlugin).dependsOn(communityTestsCommon)
lazy val benchmarks = project.in(file("scalafmt-benchmarks")).settings(
publish / skip := true,
moduleName := "scalafmt-benchmarks",
libraryDependencies ++= Seq(scalametaTestkit.value),
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.jvm, dynamic.jvm).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",
)
lazy val communityTestsSettings: Seq[Def.Setting[_]] = Seq(
publish / skip := true,
scalacOptions ++= scalacJvmOptions.value,
javaOptions += "-Dfile.encoding=UTF8",
buildInfoPackage := "org.scalafmt.tests",
)
lazy val scalaNativeConfig = nativeConfig ~= { _.withMode(Mode.releaseFull) }