Merge pull request #7328 from eed3si9n/wip/cross_fix

Let ++ fall back to a bincompat Scala version
This commit is contained in:
eugene yokota 2023-07-09 21:02:39 -04:00 committed by GitHub
commit bcc286d31e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View File

@ -20,7 +20,7 @@ import sbt.internal.util.MessageOnlyException
import sbt.internal.util.complete.DefaultParsers._
import sbt.internal.util.complete.{ DefaultParsers, Parser }
import sbt.io.IO
import sbt.librarymanagement.{ SemanticSelector, VersionNumber }
import sbt.librarymanagement.{ CrossVersion, SemanticSelector, VersionNumber }
/**
* Cross implements the Scala cross building commands:
@ -340,8 +340,23 @@ object Cross {
case (project, scalaVersions) =>
val selector = SemanticSelector(version)
scalaVersions.filter(v => selector.matches(VersionNumber(v))) match {
case Nil => (project, None, scalaVersions)
case Seq(version) => (project, Some(version), scalaVersions)
case Nil =>
// The Scala version queried via ++, like ++2.13.1 was not found.
// However, it's possible to keep the build going by falling back to a
// binary-compatible Scala version if available.
// In sbt 1.6.x (prior to https://github.com/sbt/sbt/pull/6946), we use to
// use the queried ++2.13.1 version as the fallback, which was wrong and unsafe.
// Instead this picks an actual Scala version listed in `crossScalaVersion`.
val svOpt = scalaVersions.find(
CrossVersion.isScalaBinaryCompatibleWith(newVersion = version, _)
)
svOpt.foreach { sv =>
state.log.info(
s"Falling back ${project.project} to listed $sv instead of unlisted $version"
)
}
(project, svOpt, scalaVersions)
case multiple =>
sys.error(
s"Multiple crossScalaVersions matched query '$version': ${multiple.mkString(", ")}"

View File

@ -1 +1 @@
sbt.version=1.9.0
sbt.version=1.9.1

View File

@ -1,6 +1,8 @@
-> ++2.12.0-magic
-> ++2.12.12
> ++2.12.12
> clean
> ++2.13.11 compile