From de203280299faeddefc8479f98091f3e95275518 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 9 Jul 2023 18:31:55 -0400 Subject: [PATCH 1/2] Let ++ fall back to a bincompat Scala version Fixes https://github.com/sbt/sbt/issues/7327 **Problem** In builds with mixed Scala patch versions (like scalameta), it's possible for a core subproject to be set to the lastest 2.12.x, but the compiler plugin component is cross published to 2.12.0 etc. `++ 2.12.0` in this case does not work since sbt 1.7.x onwards requires the queried Scala version to be listed in `crossScalaVersions`. **Solution** This implements sbt 1.6.x-like fallback mechanism, but instead of using the queried version (e.g. 2.12.0) it will set the Scala version to one of listed versions that is binary compatible. --- main/src/main/scala/sbt/Cross.scala | 19 +++++++++++++++++-- project/build.properties | 2 +- .../actions/cross-strict-aggregation/test | 4 +++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/main/src/main/scala/sbt/Cross.scala b/main/src/main/scala/sbt/Cross.scala index 8ab221140f..8494ebb763 100644 --- a/main/src/main/scala/sbt/Cross.scala +++ b/main/src/main/scala/sbt/Cross.scala @@ -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(", ")}" diff --git a/project/build.properties b/project/build.properties index 40b3b8e7b6..3c0b78a7c6 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.0 +sbt.version=1.9.1 diff --git a/sbt-app/src/sbt-test/actions/cross-strict-aggregation/test b/sbt-app/src/sbt-test/actions/cross-strict-aggregation/test index 8f64e9ce59..c52d1275ae 100644 --- a/sbt-app/src/sbt-test/actions/cross-strict-aggregation/test +++ b/sbt-app/src/sbt-test/actions/cross-strict-aggregation/test @@ -1,6 +1,8 @@ -> ++2.12.0-magic --> ++2.12.12 +> ++2.12.12 + +> clean > ++2.13.11 compile From 5f6eb1b2ec9665c49b53ae0afc4d9c854b31741c Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 9 Jul 2023 22:06:17 -0400 Subject: [PATCH 2/2] sbt 1.9.2 --- sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbt b/sbt index bbfa2161b7..fee64cf6df 100755 --- a/sbt +++ b/sbt @@ -1,7 +1,7 @@ #!/usr/bin/env bash set +e -declare builtin_sbt_version="1.9.1" +declare builtin_sbt_version="1.9.2" declare -a residual_args declare -a java_args declare -a scalac_args