forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
1638 lines (1522 loc) · 74.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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* The new, sbt-based build definition for Scala.
*
* What you see below is very much work-in-progress. The following features are implemented:
* - Compiling all classes for the compiler and library ("compile" in the respective subprojects)
* - Running JUnit ("junit/test"), ScalaCheck ("scalacheck/test"), and partest ("test/IntegrationTest/test") tests
* - Creating build/quick with all compiled classes and launcher scripts ("dist/mkQuick")
* - Creating build/pack with all JARs and launcher scripts ("dist/mkPack")
* - Building all scaladoc sets ("doc")
* - Publishing (standard sbt tasks like "publish" and "publishLocal")
*
* You'll notice that this build definition is much more complicated than your typical sbt build.
* The main reason is that we are not benefiting from sbt's conventions when it comes project
* layout. For that reason we have to configure a lot more explicitly. I've tried to explain in
* comments the less obvious settings.
*
* This nicely leads me to explain the goal and non-goals of this build definition. Goals are:
*
* - to be easy to tweak it in case a bug or small inconsistency is found
* - to be super explicit about any departure from standard sbt settings
* - to be readable and not necessarily succinct
* - to provide the nicest development experience for people hacking on Scala
* - originally, to mimic Ant's behavior as closely as possible, so the
* sbt and Ant builds could be maintained in parallel. the Ant build
* has now been removed, so we are now free to depart from that history.
*
* Non-goals are:
*
* - to have the shortest sbt build definition possible
* - to remove irregularities from our build process right away
* (but let's keep making gradual progress on this)
* - to modularize the Scala compiler or library further
*/
import scala.build._, VersionUtil._
// Non-Scala dependencies:
val junitDep = "junit" % "junit" % "4.13.2"
val junitInterfaceDep = "com.github.sbt" % "junit-interface" % "0.13.3" % Test
val scalacheckDep = "org.scalacheck" %% "scalacheck" % "1.18.1" % Test
val jolDep = "org.openjdk.jol" % "jol-core" % "0.16"
val asmDep = "org.scala-lang.modules" % "scala-asm" % versionProps("scala-asm.version")
val jlineDep = "org.jline" % "jline" % versionProps("jline.version") classifier "jdk8"
val testInterfaceDep = "org.scala-sbt" % "test-interface" % "1.0"
val diffUtilsDep = "io.github.java-diff-utils" % "java-diff-utils" % "4.12"
val compilerInterfaceDep = "org.scala-sbt" % "compiler-interface" % "1.10.4"
val projectFolder = settingKey[String]("subfolder in src when using configureAsSubproject, else the project name")
// `set Global / fatalWarnings := true` to enable -Werror for the certain modules
// currently, many modules cannot support -Werror; ideally this setting will eventually
// enable -Werror for all modules
val fatalWarnings = settingKey[Boolean]("whether or not warnings should be fatal in the build")
// enable fatal warnings automatically on CI
Global / fatalWarnings := insideCI.value
Global / credentials ++= {
val file = Path.userHome / ".credentials"
if (file.exists && !file.isDirectory) List(Credentials(file))
else Nil
}
lazy val publishSettings : Seq[Setting[_]] = Seq(
// Add a "default" Ivy configuration because sbt expects the Scala distribution to have one:
ivyConfigurations += Configuration.of("Default", "default", "Default", true, Vector(Configurations.Runtime), true),
publishMavenStyle := true
)
// Set the version number: We use the two settings `baseVersion` and `baseVersionSuffix` to compute all versions
// (canonical, Maven, OSGi). See VersionUtil.versionPropertiesImpl for details. The standard sbt `version` setting
// should not be set directly. It is the same as the Maven version and derived automatically from `baseVersion` and
// `baseVersionSuffix`.
globalVersionSettings
Global / baseVersion := "2.13.16"
Global / baseVersionSuffix := "SNAPSHOT"
ThisBuild / organization := "org.scala-lang"
ThisBuild / homepage := Some(url("https://www.scala-lang.org"))
ThisBuild / startYear := Some(2002)
ThisBuild / licenses += (("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0")))
ThisBuild / headerLicense := Some(HeaderLicense.Custom(
s"""Scala (${(ThisBuild/homepage).value.get})
|
|Copyright EPFL and Lightbend, Inc.
|
|Licensed under Apache License 2.0
|(http://www.apache.org/licenses/LICENSE-2.0).
|
|See the NOTICE file distributed with this work for
|additional information regarding copyright ownership.
|""".stripMargin
))
// Save MiMa logs
SavedLogs.settings
Global / scalaVersion := {
if (DottySupport.compileWithDotty)
DottySupport.dottyVersion
else
versionProps("starr.version")
}
// Run `sbt -Dscala.build.publishDevelocity` to publish build scans to develocity.scala-lang.org
// In Jenkins, the `...publishDevelocity=stage` value is used to set the `JENKINS_STAGE` value of the scan
ThisBuild / develocityConfiguration := {
def pubDev = Option(System.getProperty("scala.build.publishDevelocity"))
val isInsideCI = sys.env.get("JENKINS_URL").exists(_.contains("scala-ci.typesafe.com"))
val config = develocityConfiguration.value
val buildScan = config.buildScan
val buildCache = config.buildCache
config
.withProjectId(ProjectId("scala2"))
.withServer(config.server.withUrl(Some(url("https://develocity.scala-lang.org"))))
.withBuildScan(
buildScan
.withPublishing(Publishing.onlyIf(ctx => pubDev.nonEmpty && ctx.authenticated))
.withBackgroundUpload(false)
.withTag(if (isInsideCI) "CI" else "Local")
.withTag("2.13")
.withLinks(buildScan.links ++
sys.env.get("BUILD_URL").map(u => "Jenkins Build" -> url(u)) ++
sys.env.get("repo_ref").map(sha => "GitHub Commit" -> url(s"https://github.com/scala/scala/commit/$sha")) ++
sys.env.get("_scabot_pr").map(pr => "GitHub PR " -> url(s"https://github.com/scala/scala/pull/$pr")))
.withValues(buildScan.values +
("GITHUB_REPOSITORY" -> "scala/scala") +
("GITHUB_BRANCH" -> "2.13.x") ++
pubDev.filterNot(_.isEmpty).map("JENKINS_STAGE" -> _) ++
sys.env.get("JOB_NAME").map("JENKINS_JOB_NAME" -> _) ++
sys.env.get("repo_ref").map("GITHUB_SHA" -> _) ++
sys.env.get("_scabot_pr").map("GITHUB_PR" -> _) ++
sys.env.get("NODE_NAME").map("JENKINS_NODE" -> _))
.withObfuscation(buildScan.obfuscation.withIpAddresses(_.map(_ => "0.0.0.0")))
)
.withBuildCache(
buildCache
.withLocal(buildCache.local.withEnabled(false))
.withRemote(buildCache.remote.withEnabled(false))
)
}
lazy val instanceSettings = Seq[Setting[_]](
// we don't cross build Scala itself
crossPaths := false,
// do not add Scala library jar as a dependency automatically
autoScalaLibrary := false,
// Avoid circular dependencies for scalaInstance (see https://github.com/sbt/sbt/issues/1872)
managedScalaInstance := false,
scalaInstance := {
val s = (bootstrap / scalaInstance).value
// sbt claims that s.isManagedVersion is false even though s was resolved by Ivy
// We create a managed copy to prevent sbt from putting it on the classpath where we don't want it
if(s.isManagedVersion) s else {
import sbt.internal.inc.ScalaInstance
val s2 = new ScalaInstance(s.version, s.loader, s.loaderCompilerOnly, s.loaderLibraryOnly, s.libraryJars, s.compilerJars, s.allJars, Some(s.actualVersion))
assert(s2.isManagedVersion)
s2
}
},
// sbt endeavours to align both scalaOrganization and scalaVersion
// in the Scala artefacts, for example scala-library and scala-compiler.
// This doesn't work in the scala/scala build because the version of scala-library and the scalaVersion of
// scala-library are correct to be different. So disable overriding.
scalaModuleInfo ~= (_ map (_ withOverrideScalaVersion false)),
Quiet.silenceScalaBinaryVersionWarning
)
lazy val commonSettings = instanceSettings ++ clearSourceAndResourceDirectories ++ publishSettings ++ Seq[Setting[_]](
// we always assume that Java classes are standalone and do not have any dependency
// on Scala classes
compileOrder := CompileOrder.JavaThenScala,
projectFolder := thisProject.value.id, // overridden in configureAsSubproject
Compile / javacOptions ++= Seq("-g", "-source", "1.8", "-target", "1.8", "-Xlint:unchecked"),
Compile / javacOptions ++= (
if (scala.util.Properties.isJavaAtLeast("20"))
Seq("-Xlint:-options") // allow `-source 1.8` and `-target 1.8`
else
Seq()),
Compile / unmanagedJars := Seq.empty, // no JARs in version control!
Compile / sourceDirectory := baseDirectory.value,
Compile / unmanagedSourceDirectories := List(baseDirectory.value),
Compile / unmanagedResourceDirectories += (ThisBuild / baseDirectory).value / "src" / projectFolder.value,
sourcesInBase := false,
Compile / scalaSource := (Compile / sourceDirectory).value,
// for some reason sbt 1.4 issues unused-settings warnings for this, it seems to me incorrectly
Global / excludeLintKeys ++= Set(scalaSource),
// each subproject has to ask specifically for files they want to include
Compile / unmanagedResources / includeFilter := NothingFilter,
target := (ThisBuild / target).value / projectFolder.value,
Compile / classDirectory := buildDirectory.value / "quick/classes" / projectFolder.value,
Compile / doc / target := buildDirectory.value / "scaladoc" / projectFolder.value,
// given that classDirectory and doc target are overridden to be _outside_ of target directory, we have
// to make sure they are being cleaned properly
cleanFiles += (Compile / classDirectory).value,
cleanFiles += (Compile / doc / target).value,
run / fork := true,
run / connectInput := true,
Compile / scalacOptions ++= Seq("-feature", "-Xlint",
//"-Vprint",
//"-Xmaxerrs", "5", "-Xmaxwarns", "5", // uncomment for ease of development while breaking things
// work around https://github.com/scala/bug/issues/11534
"-Wconf:cat=unchecked&msg=The outer reference in this type test cannot be checked at run time.:s",
// optimizer warnings at INFO since `-Werror` may be turned on.
// optimizer runs in CI and release builds, though not in local development.
"-Wconf:cat=optimizer:is",
// we use @nowarn for methods that are deprecated in JDK > 8, but CI/release is under JDK 8
"-Wconf:cat=unused-nowarn:s",
"-Wunnamed-boolean-literal-strict",
),
Compile / doc / scalacOptions ++= Seq(
"-doc-footer", "epfl",
"-diagrams",
"-implicits",
"-groups",
"-doc-version", versionProperties.value.canonicalVersion,
"-doc-title", description.value,
"-sourcepath", (ThisBuild / baseDirectory).value.toString,
"-doc-source-url", s"https://github.com/scala/scala/blob/${versionProperties.value.githubTree}/€{FILE_PATH_EXT}#L€{FILE_LINE}"
),
//maxErrors := 10,
setIncOptions,
// http://stackoverflow.com/questions/16934488
apiMappings ++= {
Option(System.getProperty("sun.boot.class.path")).flatMap { classPath =>
classPath.split(java.io.File.pathSeparator).find(_.endsWith(java.io.File.separator + "rt.jar"))
}.map { jarPath =>
Map(
file(jarPath) -> url("https://docs.oracle.com/javase/8/docs/api")
)
}.getOrElse {
streams.value.log.warn("Failed to add bootstrap class path of Java to apiMappings")
Map.empty[File,URL]
}
},
apiURL := None, // set on a per-project basis
autoAPIMappings := true,
pomIncludeRepository := { _ => false },
pomExtra := {
<scm>
<connection>scm:git:git://github.com/scala/scala.git</connection>
<url>https://github.com/scala/scala</url>
</scm>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/scala/bug/issues</url>
</issueManagement>
<developers>
<developer>
<id>lamp</id>
<name>LAMP/EPFL</name>
</developer>
<developer>
<id>Lightbend</id>
<name>Lightbend, Inc.</name>
</developer>
</developers>
},
headerLicense := (ThisBuild / headerLicense).value,
// Remove auto-generated manifest attributes
Compile / packageBin / packageOptions := Seq.empty,
Compile / packageSrc / packageOptions := Seq.empty,
// Lets us CTRL-C partest without exiting SBT entirely
Global / cancelable := true,
// Don't log process output (e.g. of forked `compiler/runMain ...Main`), just pass it
// directly to stdout
run / outputStrategy := Some(StdoutOutput)
) ++ removePomDependencies ++ setForkedWorkingDirectory ++ (
if (DottySupport.compileWithDotty)
DottySupport.commonSettings
else
Seq()
)
lazy val fatalWarningsSettings = Seq(
Compile / scalacOptions ++= {
if (fatalWarnings.value) Seq("-Werror")
else Nil
},
Compile / javacOptions ++= {
if (fatalWarnings.value) Seq("-Werror")
else Nil
},
Compile / doc / scalacOptions -= "-Werror", // there are too many doc errors to enable this right now
)
/** Extra post-processing for the published POM files. These are needed to create POMs that
* are equivalent to the ones from the old Ant build. In the long term this should be removed and
* POMs, scaladocs, OSGi manifests, etc. should all use the same metadata. */
def fixPom(extra: (String, scala.xml.Node)*): Setting[_] = {
/** Find elements in an XML document by a simple XPath and replace them */
def fixXML(n: scala.xml.Node, repl: Map[String, scala.xml.Node]): scala.xml.Node = {
def f(n: scala.xml.Node, p: String): scala.xml.Node = n match {
case e: scala.xml.Elem =>
val pp = p + "/" + e.label
repl.get(pp) match {
case Some(xml) => xml
case None => e.copy(child = e.child.map(ch => f(ch, pp)))
}
case n => n
}
f(n, "")
}
pomPostProcess := { n => fixXML(pomPostProcess.value.apply(n), Map(
"/project/organization" ->
<organization>
<name>LAMP/EPFL</name>
<url>https://lamp.epfl.ch/</url>
</organization>,
"/project/url" -> <url>https://www.scala-lang.org/</url>
) ++ extra) }
}
def ivyDependencyFilter(deps: Seq[(String, String)], scalaBinaryVersion: String) = {
import scala.xml._
import scala.xml.transform._
new RuleTransformer(new RewriteRule {
override def transform(node: Node) = node match {
case e: Elem if e.label == "dependency" && {
val org = e.attribute("org").getOrElse("").toString
val name = e.attribute("name").getOrElse("").toString
deps.exists { case (g, a) =>
org == g && (name == a || name == (a + "_" + scalaBinaryVersion))
}
} => Seq.empty
case n => n
}
})
}
val pomDependencyExclusions =
settingKey[Seq[(String, String)]]("List of (groupId, artifactId) pairs to exclude from the POM and ivy.xml")
lazy val fixCsrIvy = taskKey[Unit]("Apply pomDependencyExclusions to coursier ivy")
Global / pomDependencyExclusions := Nil
/** Remove unwanted dependencies from the POM and ivy.xml. */
lazy val removePomDependencies: Seq[Setting[_]] = Seq(
pomPostProcess := { n =>
val n2 = pomPostProcess.value.apply(n)
val deps = pomDependencyExclusions.value
import scala.xml._
import scala.xml.transform._
new RuleTransformer(new RewriteRule {
override def transform(node: Node) = node match {
case e: Elem if e.label == "dependency" &&
deps.exists { case (g, a) =>
e.child.contains(<groupId>{g}</groupId>) &&
(e.child.contains(<artifactId>{a}</artifactId>) || e.child.contains(<artifactId>{a + "_" + scalaBinaryVersion.value}</artifactId>))
} => Seq.empty
case n => n
}
}).transform(Seq(n2)).head
},
fixCsrIvy := {
// - coursier makes target/sbt-bridge/resolution-cache/org.scala-lang/scala2-sbt-bridge/2.13.12-bin-SNAPSHOT/resolved.xml.xml
// - copied to target/sbt-bridge//ivy-2.13.12-bin-SNAPSHOT.xml
// - copied to ~/.ivy2/local/org.scala-lang/scala2-sbt-bridge/2.13.12-bin-SNAPSHOT/ivys/ivy.xml
import scala.jdk.CollectionConverters._
import scala.xml._
val currentProject = csrProject.value
val ivyModule = org.apache.ivy.core.module.id.ModuleRevisionId.newInstance(
currentProject.module.organization.value,
currentProject.module.name.value,
currentProject.version,
currentProject.module.attributes.asJava)
val ivyFile = ivySbt.value.withIvy(streams.value.log)(_.getResolutionCacheManager).getResolvedIvyFileInCache(ivyModule)
val e = ivyDependencyFilter(pomDependencyExclusions.value, scalaBinaryVersion.value)
.transform(Seq(XML.loadFile(ivyFile))).head
XML.save(ivyFile.getAbsolutePath, e, xmlDecl = true)
},
publishConfiguration := Def.taskDyn {
val pc = publishConfiguration.value
Def.task {
fixCsrIvy.value
pc
}
}.value,
publishLocalConfiguration := Def.taskDyn {
val pc = publishLocalConfiguration.value
Def.task {
fixCsrIvy.value
pc
}
}.value,
deliverLocal := {
// this doesn't seem to do anything currently, it probably worked before sbt used coursier
import scala.xml._
val f = deliverLocal.value
val e = ivyDependencyFilter(pomDependencyExclusions.value, scalaBinaryVersion.value)
.transform(Seq(XML.loadFile(f))).head
XML.save(f.getAbsolutePath, e, xmlDecl = true)
f
}
)
val disableDocs = Seq[Setting[_]](
Compile / doc / sources := Seq.empty,
Compile / packageDoc / publishArtifact := false
)
lazy val setJarLocation: Setting[_] =
Compile / packageBin / artifactPath := {
// two lines below are copied over from sbt's sources:
// https://github.com/sbt/sbt/blob/0.13/main/src/main/scala/sbt/Defaults.scala#L628
//val resolvedScalaVersion = ScalaVersion((scalaVersion in artifactName).value, (scalaBinaryVersion in artifactName).value)
//val resolvedArtifactName = artifactName.value(resolvedScalaVersion, projectID.value, artifact.value)
// if you would like to get a jar with version number embedded in it (as normally sbt does)
// uncomment the other definition of the `resolvedArtifactName`
val resolvedArtifact = artifact.value
val resolvedArtifactName = s"${resolvedArtifact.name}.${resolvedArtifact.extension}"
buildDirectory.value / "pack/lib" / resolvedArtifactName
}
lazy val scalaSubprojectSettings: Seq[Setting[_]] = commonSettings :+ setJarLocation
def filterDocSources(ff: FileFilter): Seq[Setting[_]] = Seq(
Compile / doc / sources ~= (_.filter(ff.accept)),
// Excluded sources may still be referenced by the included sources, so we add the compiler
// output to the scaladoc classpath to resolve them. For the `library` project this is
// always required because otherwise the compiler cannot even initialize Definitions without
// binaries of the library on the classpath. Specifically, we get this error:
// (library/compile:doc) scala.reflect.internal.FatalError: package class scala does not have a member Int
Compile / doc / dependencyClasspath += (Compile / classDirectory).value,
Compile / doc := (Compile / doc).dependsOn(Compile / compile).value
)
def regexFileFilter(s: String): FileFilter = new FileFilter {
val pat = s.r.pattern
def accept(f: File) = pat.matcher(f.getAbsolutePath.replace('\\', '/')).matches()
}
def setForkedWorkingDirectory: Seq[Setting[_]] = {
// When we fork subprocesses, use the base directory as the working directory.
// This enables `sbt> partest test/files/run/t1.scala` or `sbt> scalac sandbox/test.scala`
val setting = (Compile / forkOptions) := (Compile / forkOptions).value.withWorkingDirectory((ThisBuild / baseDirectory).value)
setting ++ inTask(run)(setting)
}
// This project provides the STARR scalaInstance for bootstrapping
lazy val bootstrap = project.in(file("target/bootstrap")).settings(bspEnabled := false)
lazy val library = configureAsSubproject(project)
.settings(generatePropertiesFileSettings)
.settings(Osgi.settings)
.settings(AutomaticModuleName.settings("scala.library"))
.settings(fatalWarningsSettings)
.settings(
name := "scala-library",
description := "Scala Standard Library",
Compile / scalacOptions ++= Seq("-sourcepath", (Compile / scalaSource).value.toString),
Compile / doc / scalacOptions ++= {
val libraryAuxDir = (ThisBuild / baseDirectory).value / "src/library-aux"
Seq(
"-doc-no-compile", libraryAuxDir.toString,
"-skip-packages", "scala.concurrent.impl",
"-doc-root-content", (Compile / sourceDirectory).value + "/rootdoc.txt",
//"-required", // placeholder for internal flag
)
},
Compile / console / scalacOptions := {
val opts = (console / scalacOptions).value
val ix = (console / scalacOptions).value.indexOfSlice(Seq[String]("-sourcepath", (Compile / scalaSource).value.toString))
opts.patch(ix, Nil, 2)
},
Compile / unmanagedResources / includeFilter := "*.tmpl" | "*.xml" | "*.js" | "*.css" | "rootdoc.txt",
// Include *.txt files in source JAR:
Compile / packageSrc / mappings ++= {
val base = (Compile / unmanagedResourceDirectories).value
(base ** "*.txt" pair Path.relativeTo(base)) ++ {
val auxBase = (ThisBuild / baseDirectory).value / "src/library-aux"
auxBase ** ("*.scala" || "*.java") pair Path.relativeTo(auxBase)
}
},
Osgi.headers += "Import-Package" -> "sun.misc;resolution:=optional, *",
Osgi.jarlist := true,
fixPom(
"/project/name" -> <name>Scala Library</name>,
"/project/description" -> <description>Standard library for the Scala Programming Language</description>,
"/project/packaging" -> <packaging>jar</packaging>
),
apiURL := Some(url(s"https://www.scala-lang.org/api/${versionProperties.value.mavenVersion}/")),
MimaFilters.mimaSettings,
)
.settings(filterDocSources("*.scala" -- regexFileFilter(".*/scala/runtime/.*")))
.settings(
if (DottySupport.compileWithDotty)
DottySupport.librarySettings
else
Seq()
)
lazy val reflect = configureAsSubproject(project)
.settings(generatePropertiesFileSettings)
.settings(Osgi.settings)
.settings(AutomaticModuleName.settings("scala.reflect"))
.settings(fatalWarningsSettings)
.settings(
name := "scala-reflect",
description := "Scala Reflection Library",
Osgi.bundleName := "Scala Reflect",
Compile / scalacOptions ++= Seq(
"-Wconf:cat=deprecation&msg=early initializers:s", // compiler heavily relies upon early initializers
),
Compile / doc / scalacOptions ++= Seq(
"-skip-packages", "scala.reflect.macros.internal:scala.reflect.internal:scala.reflect.io"
),
Osgi.headers +=
"Import-Package" -> (raw"""scala.*;version="$${range;[==,=+);$${ver}}",""" +
raw"""scala.tools.nsc;resolution:=optional;version="$${range;[==,=+);$${ver}}",""" +
"*"),
fixPom(
"/project/name" -> <name>Scala Reflect</name>,
"/project/description" -> <description>Reflection Library for the Scala Programming Language</description>,
"/project/packaging" -> <packaging>jar</packaging>
),
apiURL := Some(url(s"https://www.scala-lang.org/api/${versionProperties.value.mavenVersion}/scala-${projectFolder.value}/")),
MimaFilters.mimaSettings,
)
.dependsOn(library)
lazy val compiler = configureAsSubproject(project)
.settings(generatePropertiesFileSettings)
.settings(generateBuildCharacterFileSettings)
.settings(Osgi.settings)
.settings(AutomaticModuleName.settings("scala.tools.nsc"))
.settings(fatalWarningsSettings)
.settings(
name := "scala-compiler",
description := "Scala Compiler",
libraryDependencies += asmDep,
libraryDependencies += diffUtilsDep,
// This is only needed for the POM:
// TODO: jline dependency is only needed for the REPL shell, which should move to its own jar
libraryDependencies += jlineDep,
buildCharacterPropertiesFile := (Compile / resourceManaged).value / "scala-buildcharacter.properties",
Compile / resourceGenerators += generateBuildCharacterPropertiesFile.map(file => Seq(file)).taskValue,
// this a way to make sure that classes from interactive and scaladoc projects
// end up in compiler jar. note that we need to use LocalProject references
// (with strings) to deal with mutual recursion
Compile / packageBin / products :=
(Compile / packageBin / products).value ++
(Compile / dependencyClasspath).value.filter(_.get(moduleID.key).map(id => (id.organization, id.name, id.revision)) match {
case Some((diffUtilsDep.organization, diffUtilsDep.name, diffUtilsDep.revision)) => true
case Some((asmDep.organization, asmDep.name, asmDep.revision)) => true
case _ => false
}).map(_.data) ++
(LocalProject("interactive") / Compile / packageBin / products).value ++
(LocalProject("scaladoc") / Compile / packageBin / products).value ++
(LocalProject("repl") / Compile / packageBin / products).value ++
(LocalProject("replFrontend") / Compile / packageBin / products).value,
Compile / unmanagedResources / includeFilter :=
"*.tmpl" | "*.xml" | "*.js" | "*.css" | "*.html" | "*.properties" | "*.swf" |
"*.png" | "*.gif" | "*.gif" | "*.txt",
// Also include the selected unmanaged resources and source files from the additional projects in the source JAR:
Compile / packageSrc / mappings ++= {
val base = (Compile / unmanagedResourceDirectories).value ++
(LocalProject("interactive") / Compile / unmanagedResourceDirectories).value ++
(LocalProject("scaladoc") / Compile / unmanagedResourceDirectories).value ++
(LocalProject("repl") / Compile / unmanagedResourceDirectories).value ++
(LocalProject("replFrontend") / Compile / unmanagedResourceDirectories).value
base ** ((Compile / unmanagedResources / includeFilter).value || "*.scala" || "*.psd" || "*.ai" || "*.java") pair Path.relativeTo(base)
},
// Include the additional projects in the scaladoc JAR:
Compile / doc / sources ++= {
val base =
(LocalProject("interactive") / Compile / unmanagedSourceDirectories).value ++
(LocalProject("scaladoc") / Compile / unmanagedSourceDirectories).value ++
(LocalProject("repl") / Compile / unmanagedSourceDirectories).value ++
(LocalProject("replFrontend") / Compile / unmanagedSourceDirectories).value
((base ** ("*.scala" || "*.java"))
--- (base ** "Scaladoc*ModelTest.scala") // exclude test classes that depend on partest
).get
},
Compile / scalacOptions ++= Seq(
//"-Wunused", //"-Wnonunit-statement",
"-Wconf:cat=deprecation&msg=early initializers:s", // compiler heavily relies upon early initializers
),
Compile / doc / scalacOptions ++= Seq(
"-doc-root-content", (Compile / sourceDirectory).value + "/rootdoc.txt"
),
Osgi.headers ++= Seq(
"Import-Package" -> raw"""org.jline.keymap.*;resolution:=optional
|org.jline.reader.*;resolution:=optional
|org.jline.style.*;resolution:=optional
|org.jline.terminal;resolution:=optional
|org.jline.terminal.impl;resolution:=optional
|org.jline.terminal.spi;resolution:=optional
|org.jline.utils;resolution:=optional
|org.jline.builtins;resolution:=optional
|scala.*;version="$${range;[==,=+);$${ver}}"
|*""".stripMargin.linesIterator.mkString(","),
"Class-Path" -> "scala-reflect.jar scala-library.jar"
),
// Generate the ScriptEngineFactory service definition. The old Ant build did this when building
// the JAR but sbt has no support for it and it is easier to do as a resource generator:
generateServiceProviderResources("javax.script.ScriptEngineFactory" -> "scala.tools.nsc.interpreter.shell.Scripted$Factory"),
Compile / managedResourceDirectories := Seq((Compile / resourceManaged).value),
fixPom(
"/project/name" -> <name>Scala Compiler</name>,
"/project/description" -> <description>Compiler for the Scala Programming Language</description>,
"/project/packaging" -> <packaging>jar</packaging>
),
apiURL := Some(url(s"https://www.scala-lang.org/api/${versionProperties.value.mavenVersion}/scala-${projectFolder.value}/")),
pomDependencyExclusions += (("org.scala-lang.modules", "scala-asm"))
)
.dependsOn(library, reflect)
lazy val interactive = configureAsSubproject(project)
.settings(disableDocs)
.settings(fatalWarningsSettings)
.settings(publish / skip := true)
.settings(
name := "scala-compiler-interactive",
description := "Scala Interactive Compiler",
Compile / scalacOptions ++= Seq("-Wconf:cat=deprecation&msg=early initializers:s"),
)
.dependsOn(compiler)
lazy val repl = configureAsSubproject(project)
.settings(disableDocs)
.settings(fatalWarningsSettings)
.settings(publish / skip := true)
.settings(Compile / scalacOptions ++= Seq("-Wconf:cat=deprecation&msg=early initializers:s"))
.dependsOn(compiler, interactive)
lazy val replFrontend = configureAsSubproject(project, srcdir = Some("repl-frontend"))
.settings(disableDocs)
.settings(fatalWarningsSettings)
.settings(publish / skip := true)
.settings(
libraryDependencies += jlineDep,
name := "scala-repl-frontend",
)
.settings(
run := (Compile / run).partialInput(" -usejavacp").evaluated, // so `replFrontend/run` works
Compile / run / javaOptions += s"-Dscala.color=${!scala.util.Properties.isWin}",
Compile / run / javaOptions += "-Dorg.jline.terminal.output=forced-out",
)
.dependsOn(repl)
lazy val scaladoc = configureAsSubproject(project)
.settings(disableDocs)
.settings(fatalWarningsSettings)
.settings(publish / skip := true)
.settings(
name := "scala-compiler-doc",
description := "Scala Documentation Generator",
Compile / unmanagedResources / includeFilter := "*.html" | "*.css" | "*.gif" | "*.png" | "*.js" | "*.txt" | "*.svg" | "*.eot" | "*.woff" | "*.ttf",
libraryDependencies ++= ScaladocSettings.webjarResources,
Compile / resourceGenerators += ScaladocSettings.extractResourcesFromWebjar,
Compile / scalacOptions ++= Seq(
"-Wconf:cat=deprecation&msg=early initializers:s",
),
)
.dependsOn(compiler)
// dependencies on compiler and compiler-interface are "provided" to align with scala3-sbt-bridge
lazy val sbtBridge = configureAsSubproject(project, srcdir = Some("sbt-bridge"))
.settings(Osgi.settings)
.settings(AutomaticModuleName.settings("scala.sbtbridge"))
//.settings(fatalWarningsSettings)
.settings(
name := "scala2-sbt-bridge",
description := "sbt compiler bridge for Scala 2",
libraryDependencies += compilerInterfaceDep % Provided,
Compile / scalacOptions ++= Seq(
"-Wconf:cat=deprecation&msg=early initializers:s", // compiler heavily relies upon early initializers
),
generateServiceProviderResources("xsbti.compile.CompilerInterface2" -> "scala.tools.xsbt.CompilerBridge"),
generateServiceProviderResources("xsbti.compile.ConsoleInterface1" -> "scala.tools.xsbt.ConsoleBridge"),
generateServiceProviderResources("xsbti.compile.ScaladocInterface2" -> "scala.tools.xsbt.ScaladocBridge"),
generateServiceProviderResources("xsbti.InteractiveConsoleFactory" -> "scala.tools.xsbt.InteractiveConsoleBridgeFactory"),
Compile / managedResourceDirectories := Seq((Compile / resourceManaged).value),
pomDependencyExclusions ++= List((organization.value, "scala-repl-frontend"), (organization.value, "scala-compiler-doc")),
fixPom(
"/project/name" -> <name>Scala 2 sbt Bridge</name>,
"/project/description" -> <description>sbt compiler bridge for Scala 2</description>,
"/project/packaging" -> <packaging>jar</packaging>
),
headerLicense := Some(HeaderLicense.Custom(
s"""Zinc - The incremental compiler for Scala.
|Copyright Scala Center, Lightbend, and Mark Harrah
|
|Scala (${(ThisBuild/homepage).value.get})
|Copyright EPFL and Lightbend, Inc.
|
|Licensed under Apache License 2.0
|(http://www.apache.org/licenses/LICENSE-2.0).
|
|See the NOTICE file distributed with this work for
|additional information regarding copyright ownership.
|""".stripMargin)),
)
.dependsOn(compiler % Provided, replFrontend, scaladoc)
lazy val scalap = configureAsSubproject(project)
.settings(fatalWarningsSettings)
.settings(
description := "Scala Bytecode Parser",
// Include decoder.properties
Compile / unmanagedResources / includeFilter := "*.properties",
fixPom(
"/project/name" -> <name>Scalap</name>,
"/project/description" -> <description>bytecode analysis tool</description>,
"/project/properties" -> scala.xml.Text("")
),
headerLicense := Some(HeaderLicense.Custom(
s"""Scala classfile decoder (${(ThisBuild/homepage).value.get})
|
|Copyright EPFL and Lightbend, Inc.
|
|Licensed under Apache License 2.0
|(http://www.apache.org/licenses/LICENSE-2.0).
|
|See the NOTICE file distributed with this work for
|additional information regarding copyright ownership.
|""".stripMargin)),
Compile / headerSources ~= { xs =>
val excluded = Set("Memoisable.scala", "Result.scala", "Rule.scala", "Rules.scala", "SeqRule.scala")
xs filter { x => !excluded(x.getName) }
},
Compile / headerResources := Nil,
)
.dependsOn(compiler)
lazy val partest = configureAsSubproject(project)
.dependsOn(library, reflect, compiler, replFrontend, scalap, scaladoc, testkit)
.settings(Osgi.settings)
.settings(AutomaticModuleName.settings("scala.partest"))
.settings(fatalWarningsSettings)
.settings(
name := "scala-partest",
description := "Scala Compiler Testing Tool",
libraryDependencies ++= List(testInterfaceDep, diffUtilsDep, junitDep),
Compile / scalacOptions ++= Seq(
"-Wconf:cat=deprecation&msg=early initializers:s", // compiler heavily relies upon early initializers
),
Compile / javacOptions ++= Seq("-XDenableSunApiLintControl", "-Xlint") ++
(if (fatalWarnings.value) Seq("-Werror") else Seq()),
pomDependencyExclusions ++= List((organization.value, "scala-repl-frontend"), (organization.value, "scala-compiler-doc")),
fixPom(
"/project/name" -> <name>Scala Partest</name>,
"/project/description" -> <description>Scala Compiler Testing Tool</description>,
"/project/packaging" -> <packaging>jar</packaging>
)
)
lazy val tastytest = configureAsSubproject(project)
.dependsOn(library, reflect, compiler, scaladoc)
.settings(disableDocs)
.settings(fatalWarningsSettings)
.settings(publish / skip := true)
.settings(
name := "scala-tastytest",
description := "Scala TASTy Integration Testing Tool",
libraryDependencies += diffUtilsDep,
)
// An instrumented version of BoxesRunTime and ScalaRunTime for partest's "specialized" test category
lazy val specLib = project.in(file("test") / "instrumented")
.dependsOn(library, reflect, compiler)
.settings(commonSettings)
.settings(disableDocs)
.settings(fatalWarningsSettings)
.settings(
publish / skip := true,
bspEnabled := false,
Compile / sourceGenerators += Def.task {
import scala.collection.JavaConverters._
val srcBase = (library / Compile / sourceDirectories).value.head / "scala/runtime"
val targetBase = (Compile / sourceManaged).value / "scala/runtime"
def patch(srcFile: String, patchFile: String): File = try {
val p = difflib.DiffUtils.parseUnifiedDiff(IO.readLines(baseDirectory.value / patchFile).asJava)
val r = difflib.DiffUtils.patch(IO.readLines(srcBase / srcFile).asJava, p)
val target = targetBase / srcFile
IO.writeLines(target, r.asScala)
target
} catch { case ex: Exception =>
streams.value.log.error(s"Error patching $srcFile: $ex")
throw ex
}
IO.createDirectory(targetBase)
Seq(
patch("BoxesRunTime.java", "boxes.patch"),
patch("ScalaRunTime.scala", "srt.patch")
)
}.taskValue,
)
// The scala version used by the benchmark suites, leave undefined to use the ambient version.")
def benchmarkScalaVersion = System.getProperty("benchmark.scala.version", "")
lazy val bench = project.in(file("test") / "benchmarks")
.dependsOn((if (benchmarkScalaVersion == "") Seq[sbt.ClasspathDep[sbt.ProjectReference]](library, compiler) else Nil): _*)
.settings(if (benchmarkScalaVersion == "") instanceSettings else Seq(scalaVersion := benchmarkScalaVersion, crossPaths := false))
.settings(disableDocs)
.settings(publish / skip := true)
.enablePlugins(JmhPlugin)
.settings(
name := "test-benchmarks",
autoScalaLibrary := false,
crossPaths := true, // needed to enable per-scala-version source directories (https://github.com/sbt/sbt/pull/1799)
compileOrder := CompileOrder.JavaThenScala, // to allow inlining from Java ("... is defined in a Java source (mixed compilation), no bytecode is available")
libraryDependencies += "org.openjdk.jol" % "jol-core" % "0.10",
libraryDependencies ++= {
if (benchmarkScalaVersion == "") Nil
else "org.scala-lang" % "scala-compiler" % benchmarkScalaVersion :: Nil
},
//scalacOptions ++= Seq("-feature", "-opt:inline:scala/**", "-Wopt"),
scalacOptions ++= Seq("-feature", "-opt:l:inline", "-opt-inline-from:scala/**", "-opt-warnings"),
// Skips JMH source generators during IDE import to avoid needing to compile scala-library during the import
// should not be needed once sbt-jmh 0.4.3 is out (https://github.com/sbt/sbt-jmh/pull/207)
Jmh / bspEnabled := false
).settings(inConfig(JmhPlugin.JmhKeys.Jmh)(scalabuild.JitWatchFilePlugin.jitwatchSettings))
lazy val testkit = configureAsSubproject(project)
.dependsOn(compiler)
.settings(Osgi.settings)
.settings(AutomaticModuleName.settings("scala.testkit"))
.settings(fatalWarningsSettings)
.settings(
name := "scala-testkit",
description := "Scala Compiler Testkit",
libraryDependencies ++= Seq(junitDep, asmDep),
Compile / unmanagedSourceDirectories := List(baseDirectory.value),
fixPom(
"/project/name" -> <name>Scala Testkit</name>,
"/project/description" -> <description>Scala Compiler Testing Tool</description>,
"/project/packaging" -> <packaging>jar</packaging>
)
)
// Jigsaw: reflective access between modules (`setAccessible(true)`) requires an `opens` directive.
// This is enforced by error (not just by warning) since JDK 16. In our tests we use reflective access
// from the unnamed package (the classpath) to JDK modules in testing utilities like `assertNotReachable`.
// `add-exports=jdk.jdeps/com.sun.tools.javap` is tests that use `:javap` in the REPL, see scala/bug#12378
val addOpensForTesting = "-XX:+IgnoreUnrecognizedVMOptions" +: "--add-exports=jdk.jdeps/com.sun.tools.javap=ALL-UNNAMED" +:
Seq("java.util.concurrent.atomic", "java.lang", "java.lang.reflect", "java.net").map(p => s"--add-opens=java.base/$p=ALL-UNNAMED")
lazy val junit = project.in(file("test") / "junit")
.dependsOn(testkit, compiler, replFrontend, scaladoc, sbtBridge)
.settings(commonSettings)
.settings(disableDocs)
.settings(fatalWarningsSettings)
.settings(publish / skip := true)
.settings(
Test / fork := true,
Test / javaOptions ++= "-Xss1M" +: addOpensForTesting,
(Test / forkOptions) := (Test / forkOptions).value.withWorkingDirectory((ThisBuild / baseDirectory).value),
(Test / testOnly / forkOptions) := (Test / testOnly / forkOptions).value.withWorkingDirectory((ThisBuild / baseDirectory).value),
Compile / scalacOptions ++= Seq(
"-Xlint:-valpattern",
"-Wconf:msg=match may not be exhaustive:s", // if we missed a case, all that happens is the test fails
"-Wconf:cat=lint-nullary-unit&site=.*Test:s", // normal unit test style
"-Ypatmat-exhaust-depth", "40", // despite not caring about patmat exhaustiveness, we still get warnings for this
),
Compile / javacOptions ++= Seq("-Xlint"),
libraryDependencies ++= Seq(junitInterfaceDep, jolDep, diffUtilsDep, compilerInterfaceDep),
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-s"),
Compile / unmanagedSourceDirectories := Nil,
Test / unmanagedSourceDirectories := List(baseDirectory.value),
Test / headerSources := Nil,
)
lazy val tasty = project.in(file("test") / "tasty")
.settings(commonSettings)
.dependsOn(tastytest)
.settings(disableDocs)
.settings(publish / skip := true)
.settings(
Test / fork := true,
libraryDependencies ++= Seq(junitInterfaceDep, TastySupport.scala3Library),
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v"),
Test / testOptions += Tests.Argument(
s"-Dtastytest.src=${baseDirectory.value}",
s"-Dtastytest.packageName=tastytest"
),
Compile / unmanagedSourceDirectories := Nil,
Test / unmanagedSourceDirectories := List(baseDirectory.value/"test"),
)
.configs(TastySupport.CompilerClasspath, TastySupport.LibraryClasspath)
.settings(
inConfig(TastySupport.CompilerClasspath)(Defaults.configSettings),
inConfig(TastySupport.LibraryClasspath)(Defaults.configSettings),
libraryDependencies ++= Seq(
TastySupport.scala3Compiler % TastySupport.CompilerClasspath,
TastySupport.scala3Library % TastySupport.LibraryClasspath,
),
javaOptions ++= {
import java.io.File.pathSeparator
val scalaLibrary = (library / Compile / classDirectory).value.getAbsoluteFile()
val scalaReflect = (reflect / Compile / classDirectory).value.getAbsoluteFile()
val dottyCompiler = (TastySupport.CompilerClasspath / managedClasspath).value.seq.map(_.data) :+ scalaLibrary
val dottyLibrary = (TastySupport.LibraryClasspath / managedClasspath).value.seq.map(_.data) :+ scalaLibrary
Seq(
s"-Dtastytest.classpaths.dottyCompiler=${dottyCompiler.mkString(pathSeparator)}",
s"-Dtastytest.classpaths.dottyLibrary=${dottyLibrary.mkString(pathSeparator)}",
s"-Dtastytest.classpaths.scalaReflect=$scalaReflect",
)
},
Compile / scalacOptions ++= Seq(
"-Wconf:cat=lint-nullary-unit&site=.*Test:s", // normal unit test style
),
)
lazy val scalacheck = project.in(file("test") / "scalacheck")
.dependsOn(library, reflect, compiler, scaladoc)
.settings(commonSettings)
.settings(fatalWarningsSettings)
.settings(disableDocs)
.settings(publish / skip := true)
.settings(
// Enable forking to workaround https://github.com/sbt/sbt/issues/4009.
Test / fork := true,
// Instead of forking above, it should be possible to set:
// Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat,
Test / javaOptions ++= "-Xss1M" +: addOpensForTesting,
Test / testOptions += Tests.Argument(
// Full stack trace on failure:
"-verbosity", "2"
),
libraryDependencies ++= Seq(scalacheckDep, junitDep),
Compile / unmanagedSourceDirectories := Nil,
Test / unmanagedSourceDirectories := List(baseDirectory.value),
Compile / scalacOptions ++= Seq(
"-Wconf:msg=match may not be exhaustive:s", // if we missed a case, all that happens is the test fails
"-Wconf:msg=Classes which cannot access Tree:s", // extension is irrelevant to tests
),
)
lazy val osgiTestFelix = osgiTestProject(
project.in(file(".") / "target" / "osgiTestFelix"),
"org.apache.felix" % "org.apache.felix.framework" % "5.6.10")
lazy val osgiTestEclipse = osgiTestProject(
project.in(file(".") / "target" / "osgiTestEclipse"),
"org.eclipse.tycho" % "org.eclipse.osgi" % "3.13.0.v20180226-1711")
def osgiTestProject(p: Project, framework: ModuleID) = p
.dependsOn(library, reflect, compiler)
.settings(commonSettings)
.settings(disableDocs)
.settings(
publish / skip := true,
bspEnabled := false,
Test / fork := true,
Test / parallelExecution := false,
libraryDependencies ++= {
val paxExamVersion = "4.11.0" // Last version which supports Java 9+
Seq(
junitDep,
junitInterfaceDep,
"org.ops4j.pax.exam" % "pax-exam-container-native" % paxExamVersion,
"org.ops4j.pax.exam" % "pax-exam-junit4" % paxExamVersion,
"org.ops4j.pax.exam" % "pax-exam-link-assembly" % paxExamVersion,
"org.ops4j.pax.url" % "pax-url-aether" % "2.4.1",
"org.ops4j.pax.swissbox" % "pax-swissbox-tracker" % "1.8.1",
"ch.qos.logback" % "logback-core" % "1.2.8",
"ch.qos.logback" % "logback-classic" % "1.2.8",
"org.slf4j" % "slf4j-api" % "1.7.32",
framework % Test
)
},
Test / Keys.test := (Test / Keys.test).dependsOn(Compile / packageBin).value,
Test / Keys.testOnly := (Test / Keys.testOnly).dependsOn(Compile / packageBin).evaluated,
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-q"),
Test / javaOptions ++= ("-Dscala.bundle.dir=" + (ThisBuild / buildDirectory).value / "osgi") +: addOpensForTesting,
Test / Keys.test / forkOptions := (Test / Keys.test / forkOptions).value.withWorkingDirectory((ThisBuild / baseDirectory).value),
Test / unmanagedSourceDirectories := List((ThisBuild / baseDirectory).value / "test" / "osgi" / "src"),
Compile / unmanagedResourceDirectories := (Test / unmanagedSourceDirectories).value,
Compile / unmanagedResources / includeFilter := "*.xml",
Compile / packageBin := { // Put the bundle JARs required for the tests into build/osgi
val targetDir = (ThisBuild / buildDirectory).value / "osgi"
val mappings = ((dist / mkPack).value / "lib").listFiles.collect {
case f if f.getName.startsWith("scala-") && f.getName.endsWith(".jar") => (f, targetDir / f.getName)
}
IO.copy(mappings, CopyOptions() withOverwrite true)
targetDir
},
cleanFiles += (ThisBuild / buildDirectory).value / "osgi"
)
lazy val verifyScriptedBoilerplate = taskKey[Unit]("Ensure scripted tests have the necessary boilerplate.")
// Running scripted tests locally
// - `set ThisBuild / Compile / packageDoc / publishArtifact := false` for faster turn around time
// - `sbtTest/scripted source-dependencies/scalac-options` to run a single test
// - `set sbtTest/scriptedBufferLog := false` to see sbt log of test
// - add `> set logLevel := Level.Debug` to individual `test` script for debug output
// - uncomment `-agentlib:...` below to attach the debugger while running a test
lazy val sbtTest = project.in(file("test") / "sbt-test")
.enablePlugins(ScriptedPlugin)
.settings(disableDocs)
.settings(
scalaVersion := appConfiguration.value.provider.scalaProvider.version,
publish / skip := true,
bspEnabled := false,