-
Notifications
You must be signed in to change notification settings - Fork 352
/
Copy pathbuild.sbt
642 lines (608 loc) Β· 19.4 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
import scala.collection.mutable
def localSnapshotVersion = "0.8.5-SNAPSHOT"
def isCI = System.getenv("CI") != null
def isScala211(v: Option[(Long, Long)]): Boolean = v.contains((2, 11))
def isScala212(v: Option[(Long, Long)]): Boolean = v.contains((2, 12))
def isScala213(v: Option[(Long, Long)]): Boolean = v.contains((2, 13))
def isScala2(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2)
def isScala3(v: Option[(Long, Long)]): Boolean =
v.exists(_._1 == 0) || v.exists(_._1 == 3)
def crossSetting[A](
scalaVersion: String,
if211: List[A] = Nil,
if2: List[A] = Nil,
if3: List[A] = Nil,
otherwise: List[A] = Nil
): List[A] =
CrossVersion.partialVersion(scalaVersion) match {
case partialVersion
if isScala211(partialVersion) && isScala2(partialVersion) =>
if211 ::: if2
case partialVersion if isScala211(partialVersion) => if211
case partialVersion if isScala2(partialVersion) => if2
case partialVersion if isScala3(partialVersion) => if3
case _ => otherwise
}
val MUnitFramework = new TestFramework("munit.Framework")
inThisBuild(
List(
version ~= { dynVer =>
if (isCI) dynVer
else localSnapshotVersion // only for local publishing
},
scalaVersion := V.scala212,
crossScalaVersions := List(V.scala212),
scalacOptions ++= List(
"-target:jvm-1.8",
"-Yrangepos",
// -Xlint is unusable because of
// https://github.com/scala/bug/issues/10448
"-Ywarn-unused:imports"
),
organization := "org.scalameta",
licenses := Seq(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
),
homepage := Some(url("https://github.com/scalameta/metals")),
developers := List(
Developer(
"laughedelic",
"Alexey Alekhin",
url("https://github.com/laughedelic")
),
Developer(
"ckipp01",
"Chris Kipp",
url("https://chris-kipp.io")
),
Developer(
"gabro",
"Gabriele Petronella",
url("https://github.com/gabro")
),
Developer(
"mudsam",
"Johan Mudsam",
url("https://github.com/mudsam")
),
Developer(
"jvican",
"Jorge Vicente Cantero",
url("https://jvican.github.io/")
),
Developer(
"marek1840",
"Marek Ε»arnowski",
url("https://github.com/marek1840")
),
Developer(
"olafurpg",
"Γlafur PΓ‘ll Geirsson",
url("https://geirsson.com")
),
Developer(
"ShaneDelmore",
"Shane Delmore",
url("http://delmore.io")
),
Developer(
"tgodzik",
"Tomasz Godzik",
url("https://github.com/tgodzik")
)
),
testFrameworks := List(),
resolvers += Resolver.sonatypeRepo("public"),
dependencyOverrides += V.guava,
// faster publishLocal:
publishArtifact.in(packageDoc) := sys.env.contains("CI"),
publishArtifact.in(packageSrc) := sys.env.contains("CI"),
// forking options
javaOptions += {
import scala.collection.JavaConverters._
val props = System.getProperties
props
.stringPropertyNames()
.asScala
.map { configKey => s"-D$configKey=${props.getProperty(configKey)}" }
.mkString(" ")
},
resolvers += Resolver.bintrayRepo("scalacenter", "releases")
)
)
onLoad.in(Global) ~= { old =>
if (!scala.util.Properties.isWin) {
import java.nio.file._
val prePush = Paths.get(".git", "hooks", "pre-push")
Files.createDirectories(prePush.getParent)
Files.write(
prePush,
"""#!/bin/sh
|set -eux
|bin/scalafmt --diff
|git diff --exit-code
|""".stripMargin.getBytes()
)
prePush.toFile.setExecutable(true)
}
old
}
cancelable.in(Global) := true
crossScalaVersions := Nil
addCommandAlias("scalafixAll", "all compile:scalafix test:scalafix")
addCommandAlias("scalafixCheck", "; scalafix --check ; test:scalafix --check")
commands += Command.command("save-expect") { s =>
"unit/test:runMain tests.SaveExpect" ::
s
}
lazy val V = new {
val scala210 = "2.10.7"
val scala211 = "2.11.12"
val scala212 = "2.12.11"
val scala213 = "2.13.1"
val scalameta = "4.3.8"
val semanticdb = scalameta
val bsp = "2.0.0-M4+10-61e61e87"
val bloop = "1.4.0-RC1-192-72a856b6"
val scala3 = "0.23.0-RC1"
val bloopNightly = bloop
val sbtBloop = bloop
val gradleBloop = bloop
val mavenBloop = bloop
val mdoc = "2.1.5"
val scalafmt = "2.4.2"
val munit = "0.7.1"
// List of supported Scala versions in SemanticDB. Needs to be manually updated
// for every SemanticDB upgrade.
def supportedScalaBinaryVersions =
supportedScalaVersions.iterator
.map(CrossVersion.partialVersion)
.collect { case Some((a, b)) => s"$a.$b" }
.toList
.distinct
// Scala 2
def deprecatedScala2Versions =
Seq(scala211, "2.12.8", "2.12.9", "2.13.0")
def nonDeprecatedScala2Versions = Seq(scala213, scala212, "2.12.10")
def scala2Versions =
nonDeprecatedScala2Versions ++ deprecatedScala2Versions
// Scala 3
def nonDeprecatedScala3Versions = Seq(scala3)
def deprecatedScala3Versions = Seq()
def scala3Versions = nonDeprecatedScala3Versions ++ deprecatedScala3Versions
def supportedScalaVersions = scala2Versions ++ scala3Versions
def nonDeprecatedScalaVersions =
nonDeprecatedScala2Versions ++ nonDeprecatedScala3Versions
def deprecatedScalaVersions =
deprecatedScala2Versions ++ deprecatedScala3Versions
def guava = "com.google.guava" % "guava" % "29.0-jre"
def lsp4j = "org.eclipse.lsp4j" % "org.eclipse.lsp4j" % "0.9.0"
def dap4j =
"org.eclipse.lsp4j" % "org.eclipse.lsp4j.debug" % "0.9.0"
val coursier = "2.0.0-RC6-11"
val coursierInterfaces = "0.0.21"
}
val genyVersion = Def.setting {
if (scalaVersion.value.startsWith("2.11")) "0.1.6"
else "0.4.2"
}
val sharedSettings = List(
libraryDependencies ++= crossSetting(
scalaVersion.value,
if2 = List(
compilerPlugin(
"org.scalameta" % "semanticdb-scalac" % V.scalameta cross CrossVersion.full
)
)
),
scalacOptions ++= crossSetting(
scalaVersion.value,
if3 = List("-language:implicitConversions"),
if211 = List("-Xexperimental", "-Ywarn-unused-import")
),
scalacOptions --= crossSetting(
scalaVersion.value,
if3 = List("-Yrangepos", "-Ywarn-unused:imports"),
if211 = List("-Ywarn-unused:imports")
)
)
skip.in(publish) := true
lazy val interfaces = project
.in(file("mtags-interfaces"))
.settings(
moduleName := "mtags-interfaces",
autoScalaLibrary := false,
crossPaths := false,
libraryDependencies ++= List(
V.lsp4j
),
crossVersion := CrossVersion.disabled,
javacOptions in (Compile / doc) ++= List(
"-tag",
"implNote:a:Implementation Note:"
)
)
def multiScalaDirectories(root: File, scalaVersion: String) = {
val base = root / "src" / "main"
val result = mutable.ListBuffer.empty[File]
val partialVersion = CrossVersion.partialVersion(scalaVersion)
if (isScala211(partialVersion)) {
result += base / "scala-2.11"
}
if (isScala212(partialVersion)) {
result += base / "scala-2.12"
}
if (isScala213(partialVersion)) {
result += base / "scala-2.13"
}
if (isScala2(partialVersion)) {
result += base / "scala-2"
}
if (isScala3(partialVersion)) {
result += base / "scala-3"
}
result.toList
}
val mtagsSettings = List(
crossScalaVersions := V.supportedScalaVersions,
crossTarget := target.value / s"scala-${scalaVersion.value}",
crossVersion := CrossVersion.full,
unmanagedSourceDirectories.in(Compile) ++= multiScalaDirectories(
baseDirectory.in(ThisBuild).value / "mtags",
scalaVersion.value
),
libraryDependencies ++= crossSetting(
scalaVersion.value,
if2 = List(
// for token edit-distance used by goto definition
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0",
"com.thoughtworks.qdox" % "qdox" % "2.0.0", // for java mtags
"org.jsoup" % "jsoup" % "1.13.1", // for extracting HTML from javadocs
"com.lihaoyi" %% "geny" % genyVersion.value,
"org.scala-lang.modules" %% "scala-java8-compat" % "0.9.1",
"org.scalameta" % "semanticdb-scalac-core" % V.scalameta cross CrossVersion.full
),
if3 = List(
"ch.epfl.lamp" %% "dotty-compiler" % V.scala3,
"com.fasterxml.jackson.core" % "jackson-databind" % "2.9.8",
("org.scalameta" %% "scalameta" % V.scalameta)
.withDottyCompat(scalaVersion.value),
("com.lihaoyi" %% "geny" % genyVersion.value)
.withDottyCompat(scalaVersion.value)
)
),
libraryDependencies ++= List("org.lz4" % "lz4-java" % "1.7.1"),
libraryDependencies ++= {
if (isCI) Nil
// NOTE(olafur) pprint is indispensable for me while developing, I can't
// use println anymore for debugging because pprint.log is 100 times better.
else
crossSetting(
scalaVersion.value,
if211 = List("com.lihaoyi" %% "pprint" % "0.5.4"),
otherwise = List("com.lihaoyi" %% "pprint" % "0.5.9")
)
},
buildInfoPackage := "scala.meta.internal.mtags",
buildInfoKeys := Seq[BuildInfoKey](
"scalaCompilerVersion" -> scalaVersion.value
)
)
lazy val mtags3 = project
.in(file(".mtags"))
.settings(
sharedSettings,
mtagsSettings,
unmanagedSourceDirectories.in(Compile) += baseDirectory
.in(ThisBuild)
.value / "mtags" / "src" / "main" / "scala",
moduleName := "mtags3",
scalaVersion := V.scala3,
target := baseDirectory
.in(ThisBuild)
.value / "mtags" / "target" / "target3",
skip.in(publish) := true
)
.dependsOn(interfaces)
.disablePlugins(ScalafixPlugin)
lazy val mtags = project
.settings(
sharedSettings,
mtagsSettings,
moduleName := "mtags"
)
.dependsOn(interfaces)
.enablePlugins(BuildInfoPlugin)
lazy val metals = project
.settings(
sharedSettings,
fork.in(Compile, run) := true,
mainClass.in(Compile) := Some("scala.meta.metals.Main"),
// As a general rule of thumb, we try to keep Scala dependencies to a minimum.
libraryDependencies ++= List(
// =================
// Java dependencies
// =================
// for bloom filters
V.guava,
"com.geirsson" %% "metaconfig-core" % "0.9.10",
// for measuring memory footprint
"org.openjdk.jol" % "jol-core" % "0.10",
// for file watching
"io.methvin" % "directory-watcher" % "0.9.9",
// for http client
"io.undertow" % "undertow-core" % "2.0.30.Final",
"org.jboss.xnio" % "xnio-nio" % "3.8.0.Final",
// for persistent data like "dismissed notification"
"org.flywaydb" % "flyway-core" % "6.3.3",
"com.h2database" % "h2" % "1.4.200",
// for starting `sbt bloopInstall` process
"com.zaxxer" % "nuprocess" % "2.0.0",
"net.java.dev.jna" % "jna" % "4.5.2",
"net.java.dev.jna" % "jna-platform" % "4.5.2",
// for BSP
"org.scala-sbt.ipcsocket" % "ipcsocket" % "1.0.1",
"ch.epfl.scala" % "bsp4j" % V.bsp,
"ch.epfl.scala" %% "bloop-launcher" % V.bloopNightly,
// for LSP
V.lsp4j,
// for DAP
V.dap4j,
// for producing SemanticDB from Java source files
"com.thoughtworks.qdox" % "qdox" % "2.0.0",
// for finding paths of global log/cache directories
"io.github.soc" % "directories" % "11",
// ==================
// Scala dependencies
// ==================
"org.scala-lang.modules" %% "scala-java8-compat" % "0.9.1",
"org.scalameta" % "mdoc-interfaces" % V.mdoc,
"org.scalameta" %% "scalafmt-dynamic" % V.scalafmt,
// For reading classpaths.
// for fetching ch.epfl.scala:bloop-frontend and other library dependencies
"io.get-coursier" % "interface" % V.coursierInterfaces,
// for logging
"com.outr" %% "scribe" % "2.7.12",
"com.outr" %% "scribe-slf4j" % "2.7.12", // needed for flyway database migrations
// for debugging purposes, not strictly needed but nice for productivity
"com.lihaoyi" %% "pprint" % "0.5.9",
// For exporting Pants builds.
"com.lihaoyi" %% "ujson" % "1.0.0",
"ch.epfl.scala" %% "bloop-config" % V.bloop,
"ch.epfl.scala" %% "bloop-frontend" % V.bloop,
// For remote language server
"com.lihaoyi" %% "requests" % "0.5.1",
// for producing SemanticDB from Scala source files
"org.scalameta" %% "scalameta" % V.scalameta,
"org.scalameta" % "semanticdb-scalac-core" % V.scalameta cross CrossVersion.full
),
buildInfoPackage := "scala.meta.internal.metals",
buildInfoKeys := Seq[BuildInfoKey](
"localSnapshotVersion" -> localSnapshotVersion,
"metalsVersion" -> version.value,
"mdocVersion" -> V.mdoc,
"bspVersion" -> V.bsp,
"bloopVersion" -> V.bloop,
"bloopNightlyVersion" -> V.bloop,
"sbtBloopVersion" -> V.sbtBloop,
"gradleBloopVersion" -> V.gradleBloop,
"mavenBloopVersion" -> V.mavenBloop,
"scalametaVersion" -> V.scalameta,
"semanticdbVersion" -> V.semanticdb,
"scalafmtVersion" -> V.scalafmt,
"supportedScalaVersions" -> V.supportedScalaVersions,
"supportedScala2Versions" -> V.scala2Versions,
"supportedScalaBinaryVersions" -> V.supportedScalaBinaryVersions,
"deprecatedScalaVersions" -> V.deprecatedScalaVersions,
"nonDeprecatedScalaVersions" -> V.nonDeprecatedScalaVersions,
"scala211" -> V.scala211,
"scala212" -> V.scala212,
"scala213" -> V.scala213,
"scala3" -> V.scala3
),
mainClass in GraalVMNativeImage := Some(
"scala.meta.internal.pantsbuild.BloopPants"
),
graalVMNativeImageOptions ++= {
val reflectionFile =
Keys.sourceDirectory.in(Compile).value./("graal")./("reflection.json")
assert(reflectionFile.exists, "no such file: " + reflectionFile)
List(
"-H:+ReportUnsupportedElementsAtRuntime",
"--initialize-at-build-time",
"--initialize-at-run-time=scala.meta.internal.pantsbuild,metaconfig",
"--no-server",
"--enable-http",
"--enable-https",
"-H:EnableURLProtocols=http,https",
"--enable-all-security-services",
"--no-fallback",
s"-H:ReflectionConfigurationFiles=$reflectionFile",
"--allow-incomplete-classpath",
"-H:+ReportExceptionStackTraces"
)
}
)
.dependsOn(mtags)
.enablePlugins(BuildInfoPlugin, GraalVMNativeImagePlugin)
lazy val input = project
.in(file("tests/input"))
.settings(
sharedSettings,
skip.in(publish) := true,
scalacOptions ++= List(
"-P:semanticdb:synthetics:on"
),
libraryDependencies ++= List(
// these projects have macro annotations
"org.scalameta" %% "scalameta" % V.scalameta,
"io.circe" %% "circe-derivation-annotations" % "0.9.0-M5"
),
scalacOptions += "-P:semanticdb:synthetics:on",
addCompilerPlugin(
"org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full
)
)
.disablePlugins(ScalafixPlugin)
lazy val testSettings: Seq[Def.Setting[_]] = List(
Test / parallelExecution := false,
skip.in(publish) := true,
fork := true,
testFrameworks := List(MUnitFramework),
testOptions.in(Test) ++= {
if (isCI) {
// Enable verbose logging using sbt loggers in CI.
List(Tests.Argument(MUnitFramework, "+l", "--verbose"))
} else {
Nil
}
}
)
def crossPublishLocal(scalaV: String) = Def.task[Unit] {
// Runs `publishLocal` for mtags with `scalaVersion := $scalaV`
val newState = Project
.extract(state.value)
.appendWithSession(
List(
scalaVersion.in(mtags) := scalaV,
useSuperShell.in(ThisBuild) := false
),
state.value
)
val (s, _) = Project
.extract(newState)
.runTask(publishLocal.in(mtags), newState)
}
def publishAllMtags(
all: List[String]
): sbt.Def.Initialize[sbt.Task[Unit]] = {
all match {
case Nil =>
throw new Exception("The Scala versions list cannot be empty")
case head :: Nil =>
crossPublishLocal(head)
case head :: tl =>
crossPublishLocal(head).dependsOn(publishAllMtags(tl))
}
}
def publishBinaryMtags =
publishLocal
.in(interfaces)
.dependsOn(
publishAllMtags(List(V.scala211, V.scala212, V.scala213, V.scala3))
)
lazy val mtest = project
.in(file("tests/mtest"))
.settings(
testSettings,
sharedSettings,
libraryDependencies ++= List(
"org.scalameta" %% "munit" % V.munit,
"io.get-coursier" % "interface" % V.coursierInterfaces
),
buildInfoPackage := "tests",
buildInfoObject := "BuildInfoVersions",
buildInfoKeys := Seq[BuildInfoKey](
"scala211" -> V.scala211,
"scala212" -> V.scala212,
"scala213" -> V.scala213,
"scala3" -> V.scala3,
"scalaVersion" -> scalaVersion.value
),
unmanagedSourceDirectories.in(Compile) ++= multiScalaDirectories(
baseDirectory.in(ThisBuild).value / "tests" / "mtest",
scalaVersion.value
)
)
.dependsOn(mtags)
.enablePlugins(BuildInfoPlugin)
lazy val cross = project
.in(file("tests/cross"))
.settings(
testSettings,
sharedSettings,
crossScalaVersions := V.nonDeprecatedScalaVersions
)
.dependsOn(mtest, mtags)
lazy val unit = project
.in(file("tests/unit"))
.settings(
testSettings,
sharedSettings,
libraryDependencies ++= List(
"io.get-coursier" %% "coursier" % V.coursier, // for jars
"ch.epfl.scala" %% "bloop-config" % V.bloop,
"org.scalameta" %% "munit" % V.munit
),
buildInfoPackage := "tests",
resourceGenerators.in(Compile) += InputProperties.resourceGenerator(input),
compile.in(Compile) :=
compile.in(Compile).dependsOn(compile.in(input, Test)).value,
buildInfoKeys := Seq[BuildInfoKey](
"sourceroot" -> baseDirectory.in(ThisBuild).value,
"targetDirectory" -> target.in(Test).value,
"testResourceDirectory" -> resourceDirectory.in(Test).value,
"scalaVersion" -> scalaVersion.value
)
)
.dependsOn(mtest, metals)
.enablePlugins(BuildInfoPlugin)
lazy val slow = project
.in(file("tests/slow"))
.settings(
testSettings,
sharedSettings,
testOnly
.in(Test) := testOnly.in(Test).dependsOn(publishBinaryMtags).evaluated,
test.in(Test) := test.in(Test).dependsOn(publishBinaryMtags).value
)
.dependsOn(unit)
lazy val bench = project
.in(file("metals-bench"))
.enablePlugins(BuildInfoPlugin)
.settings(
sharedSettings,
fork.in(run) := true,
skip.in(publish) := true,
moduleName := "metals-bench",
libraryDependencies ++= List(
// for measuring memory usage
"org.spire-math" %% "clouseau" % "0.2.2"
),
buildInfoKeys := Seq[BuildInfoKey](scalaVersion),
buildInfoPackage := "bench"
)
.dependsOn(unit)
.enablePlugins(JmhPlugin)
lazy val docs = project
.in(file("metals-docs"))
.settings(
sharedSettings,
skip.in(publish) := true,
moduleName := "metals-docs",
mdoc := run.in(Compile).evaluated,
munitRepository := Some("scalameta/metals"),
libraryDependencies ++= List(
"org.jsoup" % "jsoup" % "1.13.1"
)
)
.dependsOn(metals)
.enablePlugins(DocusaurusPlugin, MUnitReportPlugin)
addCommandAlias(
"fastpass-link",
"; metals/graalvm-native-image:packageBin ; taskready"
)
commands += Command.command("taskready") { s =>
import scala.sys.process._
"say 'native-image ready'".!
s
}