@@ -45,6 +45,7 @@ val jnaDep = "net.java.dev.jna" % "jna"
45
45
val jlineDeps = Seq (jlineDep, jnaDep)
46
46
val testInterfaceDep = " org.scala-sbt" % " test-interface" % " 1.0"
47
47
val diffUtilsDep = " io.github.java-diff-utils" % " java-diff-utils" % " 4.12"
48
+ val compilerInterfaceDep = " org.scala-sbt" % " compiler-interface" % " 1.9.3"
48
49
49
50
val projectFolder = settingKey[String ](" subfolder in src when using configureAsSubproject, else the project name" )
50
51
@@ -275,8 +276,26 @@ def fixPom(extra: (String, scala.xml.Node)*): Setting[_] = {
275
276
) ++ extra) }
276
277
}
277
278
279
+ def ivyDependencyFilter (deps : Seq [(String , String )], scalaBinaryVersion : String ) = {
280
+ import scala .xml ._
281
+ import scala .xml .transform ._
282
+ new RuleTransformer (new RewriteRule {
283
+ override def transform (node : Node ) = node match {
284
+ case e : Elem if e.label == " dependency" && {
285
+ val org = e.attribute(" org" ).getOrElse(" " ).toString
286
+ val name = e.attribute(" name" ).getOrElse(" " ).toString
287
+ deps.exists { case (g, a) =>
288
+ org == g && (name == a || name == (a + " _" + scalaBinaryVersion))
289
+ }
290
+ } => Seq .empty
291
+ case n => n
292
+ }
293
+ })
294
+ }
295
+
278
296
val pomDependencyExclusions =
279
297
settingKey[Seq [(String , String )]](" List of (groupId, artifactId) pairs to exclude from the POM and ivy.xml" )
298
+ lazy val fixCsrIvy = taskKey[Unit ](" Apply pomDependencyExclusions to coursier ivy" )
280
299
281
300
Global / pomDependencyExclusions := Nil
282
301
@@ -294,27 +313,47 @@ lazy val removePomDependencies: Seq[Setting[_]] = Seq(
294
313
e.child.contains(<groupId >{g}</groupId >) &&
295
314
(e.child.contains(<artifactId >{a}</artifactId >) || e.child.contains(<artifactId >{a + " _" + scalaBinaryVersion.value}</artifactId >))
296
315
} => Seq .empty
297
- case n => Seq (n)
316
+ case n => n
298
317
}
299
318
}).transform(Seq (n2)).head
300
319
},
320
+ fixCsrIvy := {
321
+ // - coursier makes target/sbt-bridge/resolution-cache/org.scala-lang/scala2-sbt-bridge/2.13.12-bin-SNAPSHOT/resolved.xml.xml
322
+ // - copied to target/sbt-bridge//ivy-2.13.12-bin-SNAPSHOT.xml
323
+ // - copied to ~/.ivy2/local/org.scala-lang/scala2-sbt-bridge/2.13.12-bin-SNAPSHOT/ivys/ivy.xml
324
+ import scala .jdk .CollectionConverters ._
325
+ import scala .xml ._
326
+ val currentProject = csrProject.value
327
+ val ivyModule = org.apache.ivy.core.module.id.ModuleRevisionId .newInstance(
328
+ currentProject.module.organization.value,
329
+ currentProject.module.name.value,
330
+ currentProject.version,
331
+ currentProject.module.attributes.asJava)
332
+ val ivyFile = ivySbt.value.withIvy(streams.value.log)(_.getResolutionCacheManager).getResolvedIvyFileInCache(ivyModule)
333
+ val e = ivyDependencyFilter(pomDependencyExclusions.value, scalaBinaryVersion.value)
334
+ .transform(Seq (XML .loadFile(ivyFile))).head
335
+ XML .save(ivyFile.getAbsolutePath, e, xmlDecl = true )
336
+ },
337
+ publishConfiguration := Def .taskDyn {
338
+ val pc = publishConfiguration.value
339
+ Def .task {
340
+ fixCsrIvy.value
341
+ pc
342
+ }
343
+ }.value,
344
+ publishLocalConfiguration := Def .taskDyn {
345
+ val pc = publishLocalConfiguration.value
346
+ Def .task {
347
+ fixCsrIvy.value
348
+ pc
349
+ }
350
+ }.value,
301
351
deliverLocal := {
352
+ // this doesn't seem to do anything currently, it probably worked before sbt used coursier
302
353
import scala .xml ._
303
- import scala .xml .transform ._
304
354
val f = deliverLocal.value
305
- val deps = pomDependencyExclusions.value
306
- val e = new RuleTransformer (new RewriteRule {
307
- override def transform (node : Node ) = node match {
308
- case e : Elem if e.label == " dependency" && {
309
- val org = e.attribute(" org" ).getOrElse(" " ).toString
310
- val name = e.attribute(" name" ).getOrElse(" " ).toString
311
- deps.exists { case (g, a) =>
312
- org == g && (name == a || name == (a + " _" + scalaBinaryVersion.value))
313
- }
314
- } => Seq .empty
315
- case n => Seq (n)
316
- }
317
- }).transform(Seq (XML .loadFile(f))).head
355
+ val e = ivyDependencyFilter(pomDependencyExclusions.value, scalaBinaryVersion.value)
356
+ .transform(Seq (XML .loadFile(f))).head
318
357
XML .save(f.getAbsolutePath, e, xmlDecl = true )
319
358
f
320
359
}
@@ -579,6 +618,42 @@ lazy val scaladoc = configureAsSubproject(project)
579
618
)
580
619
.dependsOn(compiler)
581
620
621
+ // dependencies on compiler and compiler-interface are "provided" to align with scala3-sbt-bridge
622
+ lazy val sbtBridge = configureAsSubproject(project, srcdir = Some (" sbt-bridge" ))
623
+ .settings(Osgi .settings)
624
+ .settings(AutomaticModuleName .settings(" scala.sbtbridge" ))
625
+ // .settings(fatalWarningsSettings)
626
+ .settings(
627
+ name := " scala2-sbt-bridge" ,
628
+ description := " sbt compiler bridge for Scala 2" ,
629
+ libraryDependencies += compilerInterfaceDep % Provided ,
630
+ generateServiceProviderResources(" xsbti.compile.CompilerInterface2" -> " scala.tools.xsbt.CompilerBridge" ),
631
+ generateServiceProviderResources(" xsbti.compile.ConsoleInterface1" -> " scala.tools.xsbt.ConsoleBridge" ),
632
+ generateServiceProviderResources(" xsbti.compile.ScaladocInterface2" -> " scala.tools.xsbt.ScaladocBridge" ),
633
+ generateServiceProviderResources(" xsbti.InteractiveConsoleFactory" -> " scala.tools.xsbt.InteractiveConsoleBridgeFactory" ),
634
+ Compile / managedResourceDirectories := Seq ((Compile / resourceManaged).value),
635
+ pomDependencyExclusions ++= List ((organization.value, " scala-repl-frontend" ), (organization.value, " scala-compiler-doc" )),
636
+ fixPom(
637
+ " /project/name" -> <name >Scala 2 sbt Bridge </name >,
638
+ " /project/description" -> <description >sbt compiler bridge for Scala 2 </description >,
639
+ " /project/packaging" -> <packaging >jar</packaging >
640
+ ),
641
+ headerLicense := Some (HeaderLicense .Custom (
642
+ s """ Zinc - The incremental compiler for Scala.
643
+ |Copyright Scala Center, Lightbend, and Mark Harrah
644
+ |
645
+ |Scala ( ${(ThisBuild / homepage).value.get})
646
+ |Copyright EPFL and Lightbend, Inc.
647
+ |
648
+ |Licensed under Apache License 2.0
649
+ |(http://www.apache.org/licenses/LICENSE-2.0).
650
+ |
651
+ |See the NOTICE file distributed with this work for
652
+ |additional information regarding copyright ownership.
653
+ | """ .stripMargin)),
654
+ )
655
+ .dependsOn(compiler % Provided , replFrontend, scaladoc)
656
+
582
657
lazy val scalap = configureAsSubproject(project)
583
658
.settings(fatalWarningsSettings)
584
659
.settings(
@@ -727,7 +802,7 @@ val addOpensForTesting = "-XX:+IgnoreUnrecognizedVMOptions" +: "--add-exports=jd
727
802
Seq (" java.util.concurrent.atomic" , " java.lang" , " java.lang.reflect" , " java.net" ).map(p => s " --add-opens=java.base/ $p=ALL-UNNAMED " )
728
803
729
804
lazy val junit = project.in(file(" test" ) / " junit" )
730
- .dependsOn(testkit, compiler, replFrontend, scaladoc)
805
+ .dependsOn(testkit, compiler, replFrontend, scaladoc, sbtBridge )
731
806
.settings(commonSettings)
732
807
.settings(disableDocs)
733
808
.settings(fatalWarningsSettings)
@@ -745,7 +820,7 @@ lazy val junit = project.in(file("test") / "junit")
745
820
" -Ypatmat-exhaust-depth" , " 40" , // despite not caring about patmat exhaustiveness, we still get warnings for this
746
821
),
747
822
Compile / javacOptions ++= Seq (" -Xlint" ),
748
- libraryDependencies ++= Seq (junitInterfaceDep, jolDep, diffUtilsDep),
823
+ libraryDependencies ++= Seq (junitInterfaceDep, jolDep, diffUtilsDep, compilerInterfaceDep ),
749
824
testOptions += Tests .Argument (TestFrameworks .JUnit , " -a" , " -v" , " -s" ),
750
825
Compile / unmanagedSourceDirectories := Nil ,
751
826
Test / unmanagedSourceDirectories := List (baseDirectory.value),
@@ -1048,7 +1123,7 @@ lazy val root: Project = (project in file("."))
1048
1123
1049
1124
setIncOptions
1050
1125
)
1051
- .aggregate(library, reflect, compiler, interactive, repl, replFrontend,
1126
+ .aggregate(library, reflect, compiler, interactive, repl, replFrontend, sbtBridge,
1052
1127
scaladoc, scalap, testkit, partest, junit, scalacheck, tasty, tastytest, scalaDist).settings(
1053
1128
Compile / sources := Seq .empty,
1054
1129
onLoadMessage := s """ |*** Welcome to the sbt build definition for Scala! ***
0 commit comments