mirror of https://github.com/sbt/sbt.git
Update scala-library in scala-tool configuration for Scala 3
When a macro was compiled against a new scala-library (say 2.13.15), the runtime classpath of the Scala compiler should not contain an older scala-library. Otherwise the macro can cause a NoSuchMethodException during expansion. This commit updates scala-library in the scalaInstance to the version on the projects dependency classpath.
This commit is contained in:
parent
951d1c4ae4
commit
b9375f5e6b
|
|
@ -1149,9 +1149,29 @@ object Defaults extends BuildCommon {
|
||||||
val sv = scalaVersion.value
|
val sv = scalaVersion.value
|
||||||
val fullReport = update.value
|
val fullReport = update.value
|
||||||
|
|
||||||
val toolReport = fullReport
|
// For Scala 3, update scala-library.jar in `scala-tool` and `scala-doc-tool` in case a newer version
|
||||||
.configuration(Configurations.ScalaTool)
|
// is present in the `compile` configuration. This is needed once forwards binary compatibility is dropped
|
||||||
.getOrElse(sys.error(noToolConfiguration(managedScalaInstance.value)))
|
// to avoid NoSuchMethod exceptions when expanding macros.
|
||||||
|
def updateLibraryToCompileConfiguration(report: ConfigurationReport) =
|
||||||
|
if (!ScalaArtifacts.isScala3(sv)) report
|
||||||
|
else
|
||||||
|
(for {
|
||||||
|
compileConf <- fullReport.configuration(Configurations.Compile)
|
||||||
|
compileLibMod <- compileConf.modules.find(_.module.name == ScalaArtifacts.LibraryID)
|
||||||
|
reportLibMod <- report.modules.find(_.module.name == ScalaArtifacts.LibraryID)
|
||||||
|
if VersionNumber(reportLibMod.module.revision)
|
||||||
|
.matchesSemVer(SemanticSelector(s"<${compileLibMod.module.revision}"))
|
||||||
|
} yield {
|
||||||
|
val newMods = report.modules
|
||||||
|
.filterNot(_.module.name == ScalaArtifacts.LibraryID) :+ compileLibMod
|
||||||
|
report.withModules(newMods)
|
||||||
|
}).getOrElse(report)
|
||||||
|
|
||||||
|
val toolReport = updateLibraryToCompileConfiguration(
|
||||||
|
fullReport
|
||||||
|
.configuration(Configurations.ScalaTool)
|
||||||
|
.getOrElse(sys.error(noToolConfiguration(managedScalaInstance.value)))
|
||||||
|
)
|
||||||
|
|
||||||
if (Classpaths.isScala213(sv)) {
|
if (Classpaths.isScala213(sv)) {
|
||||||
for {
|
for {
|
||||||
|
|
@ -1182,6 +1202,7 @@ object Defaults extends BuildCommon {
|
||||||
val allDocJars =
|
val allDocJars =
|
||||||
fullReport
|
fullReport
|
||||||
.configuration(Configurations.ScalaDocTool)
|
.configuration(Configurations.ScalaDocTool)
|
||||||
|
.map(updateLibraryToCompileConfiguration)
|
||||||
.toSeq
|
.toSeq
|
||||||
.flatMap(_.modules)
|
.flatMap(_.modules)
|
||||||
.flatMap(_.artifacts.map(_._2))
|
.flatMap(_.artifacts.map(_._2))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue