mirror of https://github.com/sbt/sbt.git
Refactor: extract reportScalaLibEviction for Scala 2.13 and 3 eviction messages
This commit is contained in:
parent
7ad38eb221
commit
7fc522da65
|
|
@ -158,6 +158,34 @@ object Compiler:
|
||||||
val fullReport = Keys.update.value
|
val fullReport = Keys.update.value
|
||||||
val s = Keys.streams.value
|
val s = Keys.streams.value
|
||||||
|
|
||||||
|
def reportScalaLibEviction(
|
||||||
|
proj: String,
|
||||||
|
sv: String,
|
||||||
|
libVer: String,
|
||||||
|
libName: String,
|
||||||
|
err: Boolean,
|
||||||
|
alignmentLine: String,
|
||||||
|
evictedLine: String
|
||||||
|
): Unit =
|
||||||
|
val fix =
|
||||||
|
if err then
|
||||||
|
"""Upgrade the `scalaVersion` to fix the build. If upgrading the Scala compiler version is
|
||||||
|
|not possible (for example due to a regression in the compiler or a missing dependency),
|
||||||
|
|this error can be demoted by setting `allowUnsafeScalaLibUpgrade := true`.""".stripMargin
|
||||||
|
else s"""Note that the dependency classpath and the runtime classpath of your project
|
||||||
|
|contain the newer $libName $libVer, even if the scalaVersion is $sv.
|
||||||
|
|Compilation (macro expansion) or using the Scala REPL in sbt may fail with a LinkageError.""".stripMargin
|
||||||
|
val msg =
|
||||||
|
s"""Expected `$proj scalaVersion` to be $libVer or later, but found $sv.
|
||||||
|
|$alignmentLine
|
||||||
|
|
|
||||||
|
|$fix
|
||||||
|
|
|
||||||
|
|$evictedLine
|
||||||
|
|""".stripMargin
|
||||||
|
if err then sys.error(msg)
|
||||||
|
else s.log.warn(msg)
|
||||||
|
|
||||||
// For Scala 3, update scala-library.jar in `scala-tool` and `scala-doc-tool` in case a newer version
|
// For Scala 3, update scala-library.jar in `scala-tool` and `scala-doc-tool` in case a newer version
|
||||||
// is present in the `compile` configuration. This is needed once forwards binary compatibility is dropped
|
// is present in the `compile` configuration. This is needed once forwards binary compatibility is dropped
|
||||||
// to avoid NoSuchMethod exceptions when expanding macros.
|
// to avoid NoSuchMethod exceptions when expanding macros.
|
||||||
|
|
@ -194,26 +222,16 @@ object Compiler:
|
||||||
val proj =
|
val proj =
|
||||||
Def.displayBuildRelative(Keys.thisProjectRef.value.build, Keys.thisProjectRef.value)
|
Def.displayBuildRelative(Keys.thisProjectRef.value.build, Keys.thisProjectRef.value)
|
||||||
if VersionNumber(sv).matchesSemVer(SemanticSelector(s"<$libVer")) then
|
if VersionNumber(sv).matchesSemVer(SemanticSelector(s"<$libVer")) then
|
||||||
val err = !Keys.allowUnsafeScalaLibUpgrade.value
|
reportScalaLibEviction(
|
||||||
val fix =
|
proj,
|
||||||
if err then
|
sv,
|
||||||
"""Upgrade the `scalaVersion` to fix the build. If upgrading the Scala compiler version is
|
libVer,
|
||||||
|not possible (for example due to a regression in the compiler or a missing dependency),
|
libName,
|
||||||
|this error can be demoted by setting `allowUnsafeScalaLibUpgrade := true`.""".stripMargin
|
!Keys.allowUnsafeScalaLibUpgrade.value,
|
||||||
else s"""Note that the dependency classpath and the runtime classpath of your project
|
s"""To support backwards-only binary compatibility (SIP-51), the Scala 2.13 compiler
|
||||||
|contain the newer $libName $libVer, even if the scalaVersion is $sv.
|
|should not be older than $libName on the dependency classpath.""".stripMargin,
|
||||||
|Compilation (macro expansion) or using the Scala REPL in sbt may fail with a LinkageError.""".stripMargin
|
s"See `$proj evicted` to know why $libName $libVer is getting pulled in."
|
||||||
val msg =
|
)
|
||||||
s"""Expected `$proj scalaVersion` to be $libVer or later, but found $sv.
|
|
||||||
|To support backwards-only binary compatibility (SIP-51), the Scala 2.13 compiler
|
|
||||||
|should not be older than $libName on the dependency classpath.
|
|
||||||
|
|
|
||||||
|$fix
|
|
||||||
|
|
|
||||||
|See `$proj evicted` to know why $libName $libVer is getting pulled in.
|
|
||||||
|""".stripMargin
|
|
||||||
if err then sys.error(msg)
|
|
||||||
else s.log.warn(msg)
|
|
||||||
else ()
|
else ()
|
||||||
else if ScalaArtifacts.isScala3(sv) then
|
else if ScalaArtifacts.isScala3(sv) then
|
||||||
val scala3LibOpt = for
|
val scala3LibOpt = for
|
||||||
|
|
@ -228,25 +246,15 @@ object Compiler:
|
||||||
val proj =
|
val proj =
|
||||||
Def.displayBuildRelative(Keys.thisProjectRef.value.build, Keys.thisProjectRef.value)
|
Def.displayBuildRelative(Keys.thisProjectRef.value.build, Keys.thisProjectRef.value)
|
||||||
if VersionNumber(sv).matchesSemVer(SemanticSelector(s"<$libVer")) then
|
if VersionNumber(sv).matchesSemVer(SemanticSelector(s"<$libVer")) then
|
||||||
val err = !Keys.allowUnsafeScalaLibUpgrade.value
|
reportScalaLibEviction(
|
||||||
val fix =
|
proj,
|
||||||
if err then
|
sv,
|
||||||
"""Upgrade the `scalaVersion` to fix the build. If upgrading the Scala compiler version is
|
libVer,
|
||||||
|not possible (for example due to a regression in the compiler or a missing dependency),
|
libName,
|
||||||
|this error can be demoted by setting `allowUnsafeScalaLibUpgrade := true`.""".stripMargin
|
!Keys.allowUnsafeScalaLibUpgrade.value,
|
||||||
else s"""Note that the dependency classpath and the runtime classpath of your project
|
s"To maintain the compile-time alignment, the Scala compiler cannot be older than $libName on the dependency classpath.",
|
||||||
|contain the newer $libName $libVer, even if the scalaVersion is $sv.
|
s"See `$proj evicted` to know why $libName was upgraded from $sv to $libVer."
|
||||||
|Compilation (macro expansion) or using the Scala REPL in sbt may fail with a LinkageError.""".stripMargin
|
)
|
||||||
val msg =
|
|
||||||
s"""Expected `$proj scalaVersion` to be $libVer or later, but found $sv.
|
|
||||||
|To maintain the compile-time alignment, the Scala compiler cannot be older than $libName on the dependency classpath.
|
|
||||||
|
|
|
||||||
|$fix
|
|
||||||
|
|
|
||||||
|See `$proj evicted` to know why $libName was upgraded from $sv to $libVer.
|
|
||||||
|""".stripMargin
|
|
||||||
if err then sys.error(msg)
|
|
||||||
else s.log.warn(msg)
|
|
||||||
else ()
|
else ()
|
||||||
else ()
|
else ()
|
||||||
def file(id: String): Option[File] =
|
def file(id: String): Option[File] =
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue