Skip to content

Commit

Permalink
Fix scala-js#4875: Change our strategy for crossScalaVersions handling.
Browse files Browse the repository at this point in the history
sbt 1.7.0 made `++` even stricter than before. It now only applies
if the target version appears as is in `crossScalaVersions`, rather
than a binary-compatible one.

We now introduce specific keys to hold a list of minor versions we
support for each major version. As keys, they can be overridden
with `set` commands if we want to test nightly versions of Scala.

We also make sure to apply the full `crossScalaVersions` list even
in projects that should only build with the default 2.12 version,
like the `javalib`. Otherwise, tests with other minor 2.12 versions
refuse to resolve because it is not the same 2.12 version
everywhere.
  • Loading branch information
sjrd committed Jun 5, 2023
1 parent cb2da22 commit 6069594
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 60 deletions.
83 changes: 69 additions & 14 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ import org.scalajs.linker.interface._
*/
object ExposedValues extends AutoPlugin {
object autoImport {
val cross212ScalaVersions: SettingKey[Seq[String]] =
settingKey("an ordered sequence of 2.12.x versions with which we build (most recent last)")

val cross213ScalaVersions: SettingKey[Seq[String]] =
settingKey("an ordered sequence of 2.13.x versions with which we build (most recent last)")

val default212ScalaVersion: SettingKey[String] =
settingKey("the default Scala 2.12.x version for this build (derived from cross212ScalaVersions)")
val default213ScalaVersion: SettingKey[String] =
settingKey("the default Scala 2.13.x version for this build (derived from cross213ScalaVersions)")

// set scalaJSLinkerConfig in someProject ~= makeCompliant
val makeCompliant: StandardConfig => StandardConfig = {
_.withSemantics { semantics =>
Expand Down Expand Up @@ -224,18 +235,19 @@ object MyScalaJSPlugin extends AutoPlugin {
}

object Build {
import ExposedValues.autoImport.{
cross212ScalaVersions,
cross213ScalaVersions,
default212ScalaVersion,
default213ScalaVersion
}

import MyScalaJSPlugin.{
scalaJSCompilerOption,
scalaJSMapSourceURIOption,
isGeneratingForIDE
}

import MultiScalaProject.{
Default2_12ScalaVersion,
Default2_13ScalaVersion,
DefaultScalaVersion
}

val scalastyleCheck = taskKey[Unit]("Run scalastyle")

val fetchScalaSource = taskKey[File](
Expand All @@ -260,8 +272,6 @@ object Build {

val previousBinaryCrossVersion = CrossVersion.binaryWith("sjs1_", "")

val scalaVersionsUsedForPublishing: Set[String] =
Set(Default2_12ScalaVersion, Default2_13ScalaVersion)
val newScalaBinaryVersionsInThisRelease: Set[String] =
Set()

Expand Down Expand Up @@ -317,6 +327,8 @@ object Build {
mimaPreviousArtifacts ++= {
val scalaV = scalaVersion.value
val scalaBinaryV = scalaBinaryVersion.value
val scalaVersionsUsedForPublishing: Set[String] =
Set(default212ScalaVersion.value, default213ScalaVersion.value)
if (!scalaVersionsUsedForPublishing.contains(scalaV)) {
// This artifact will not be published. Binary compatibility is irrelevant.
Set.empty
Expand Down Expand Up @@ -502,6 +514,12 @@ object Build {
}
)

private val defaultScalaVersionOnlySettings = Def.settings(
// We still need to support all cross versions, otherwise ++2.12.x creates inconsistent graphs
crossScalaVersions := cross212ScalaVersions.value,
scalaVersion := default212ScalaVersion.value,
)

private val basePublishSettings = Seq(
publishMavenStyle := true,
publishTo := {
Expand Down Expand Up @@ -763,6 +781,41 @@ object Build {
}

val thisBuildSettings = Def.settings(
cross212ScalaVersions := Seq(
"2.12.2",
"2.12.3",
"2.12.4",
"2.12.5",
"2.12.6",
"2.12.7",
"2.12.8",
"2.12.9",
"2.12.10",
"2.12.11",
"2.12.12",
"2.12.13",
"2.12.14",
"2.12.15",
"2.12.16",
"2.12.17",
),
cross213ScalaVersions := Seq(
"2.13.0",
"2.13.1",
"2.13.2",
"2.13.3",
"2.13.4",
"2.13.5",
"2.13.6",
"2.13.7",
"2.13.8",
"2.13.9",
"2.13.10",
),

default212ScalaVersion := cross212ScalaVersions.value.last,
default213ScalaVersion := cross213ScalaVersions.value.last,

// JDK version we are running with
javaVersion in Global := {
val fullVersion = System.getProperty("java.version")
Expand Down Expand Up @@ -1005,7 +1058,7 @@ object Build {
MyScalaJSPlugin
).settings(
commonSettings,
scalaVersion := DefaultScalaVersion,
defaultScalaVersionOnlySettings,
fatalWarningsSettings,
name := "Scala.js linker private library",
publishArtifact in Compile := false,
Expand Down Expand Up @@ -1192,8 +1245,7 @@ object Build {
name := "Scala.js sbt plugin",
normalizedName := "sbt-scalajs",
sbtPlugin := true,
crossScalaVersions := Seq(DefaultScalaVersion),
scalaVersion := crossScalaVersions.value.head,
defaultScalaVersionOnlySettings,
sbtVersion := "1.0.0",
scalaBinaryVersion :=
CrossVersion.binaryScalaVersion(scalaVersion.value),
Expand Down Expand Up @@ -1297,7 +1349,7 @@ object Build {
MyScalaJSPlugin
).settings(
commonSettings,
scalaVersion := DefaultScalaVersion,
defaultScalaVersionOnlySettings,
fatalWarningsSettings,
name := "scalajs-javalib-internal",
publishArtifact in Compile := false,
Expand Down Expand Up @@ -1787,16 +1839,19 @@ object Build {
},

MyScalaJSPlugin.expectedSizes := {
val default212Version = default212ScalaVersion.value
val default213Version = default213ScalaVersion.value

scalaVersion.value match {
case Default2_12ScalaVersion =>
case `default212Version` =>
Some(ExpectedSizes(
fastLink = 772000 to 773000,
fullLink = 145000 to 146000,
fastLinkGz = 91000 to 92000,
fullLinkGz = 35000 to 36000,
))

case Default2_13ScalaVersion =>
case `default213Version` =>
Some(ExpectedSizes(
fastLink = 456000 to 457000,
fullLink = 97000 to 98000,
Expand Down
57 changes: 11 additions & 46 deletions project/MultiScalaProject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,68 +79,33 @@ object MultiScalaProject {
private def strictMapValues[K, U, V](v: Map[K, U])(f: U => V): Map[K, V] =
v.map(v => (v._1, f(v._2)))

private final val versions = Map[String, Seq[String]](
"2.12" -> Seq(
"2.12.2",
"2.12.3",
"2.12.4",
"2.12.5",
"2.12.6",
"2.12.7",
"2.12.8",
"2.12.9",
"2.12.10",
"2.12.11",
"2.12.12",
"2.12.13",
"2.12.14",
"2.12.15",
"2.12.16",
"2.12.17",
),
"2.13" -> Seq(
"2.13.0",
"2.13.1",
"2.13.2",
"2.13.3",
"2.13.4",
"2.13.5",
"2.13.6",
"2.13.7",
"2.13.8",
"2.13.9",
"2.13.10",
),
)

val Default2_12ScalaVersion = versions("2.12").last
val Default2_13ScalaVersion = versions("2.13").last

/** The default Scala version is the default 2.12 Scala version, because it
* must work for sbt plugins.
*/
val DefaultScalaVersion = Default2_12ScalaVersion

private final val ideVersion = "2.12"

private def projectID(id: String, major: String) = id + major.replace('.', '_')

def apply(id: String, base: File): MultiScalaProject = {
import ExposedValues.autoImport._

val projects = for {
(major, minors) <- versions
major <- List("2.12", "2.13")
} yield {
val noIDEExportSettings =
if (major == ideVersion) Nil
else NoIDEExport.noIDEExportSettings

val (crossVersionsKey, defaultVersionKey) = major match {
case "2.12" => (cross212ScalaVersions, default212ScalaVersion)
case "2.13" => (cross213ScalaVersions, default213ScalaVersion)
}

major -> Project(id = projectID(id, major), base = new File(base, "." + major)).settings(
scalaVersion := minors.last,
crossScalaVersions := minors,
crossScalaVersions := crossVersionsKey.value,
scalaVersion := defaultVersionKey.value,
noIDEExportSettings,
)
}

new MultiScalaProject(projects).settings(
new MultiScalaProject(projects.toMap).settings(
sourceDirectory := baseDirectory.value.getParentFile / "src",
)
}
Expand Down

0 comments on commit 6069594

Please sign in to comment.