Subsume platform cross building

Problem
-------
In sbt 1, platform cross building is implemented using in the user-land
using `%%%` operator, which clevery handles both Scala cross building
and appending platform suffix like sjs1.
However, in general symbolic `%%%` is confusing, and hard to explain.

Solution
--------
In sbt 2, we should subsume the idea of platform cross building,
so `%%` can act as the current `%%%` operator.
This adds a new setting called `platform`, which defaults to
`Platform.jvm` by default.
When a subprojects sets it to `Platform.sjs1`, `ModuleID`s defined using
`%%` operator will inject the platform suffix `_sjs1` **in addition**
to the Scala binary suffix `_2.13` etc.

Note: Explicit JVM dependencies will now require `.platform(Platform.jvm)`.
This commit is contained in:
Eugene Yokota 2023-03-12 13:38:56 -04:00
parent dbaa34bdac
commit 72af500294
7 changed files with 33 additions and 7 deletions

View File

@ -270,6 +270,7 @@ object Defaults extends BuildCommon {
pomIncludeRepository :== Classpaths.defaultRepositoryFilter,
updateOptions := UpdateOptions(),
forceUpdatePeriod :== None,
platform :== Platform.jvm,
// coursier settings
csrExtraCredentials :== Nil,
csrLogger := LMCoursier.coursierLoggerTask.value,
@ -703,7 +704,7 @@ object Defaults extends BuildCommon {
case CrossValue.Full => CrossVersion.full
case CrossValue.Binary => CrossVersion.binary
}
val base = ModuleID(id.groupID, id.name, sv).withCrossVersion(cross)
val base = ModuleID(id.groupID, id.name, sv).withCrossVersion(cross).platform(Platform.jvm)
CrossVersion(scalaV, binVersion)(base).withCrossVersion(Disabled())
},
crossSbtVersions := Vector((pluginCrossBuild / sbtVersion).value),
@ -2960,7 +2961,9 @@ object Classpaths {
case CrossValue.Full => CrossVersion.binary
case CrossValue.Binary => CrossVersion.full
}
val base = ModuleID(id.groupID, id.name, sbtVersion.value).withCrossVersion(cross)
val base = ModuleID(id.groupID, id.name, sbtVersion.value)
.withCrossVersion(cross)
.platform(Platform.jvm)
CrossVersion(scalaVersion, binVersion)(base).withCrossVersion(Disabled())
},
shellPrompt := sbt.internal.ui.UITask.NoShellPrompt,
@ -3084,6 +3087,7 @@ object Classpaths {
overrideScalaVersion = true
).withScalaOrganization(scalaOrganization.value)
.withScalaArtifacts(scalaArtifacts.value.toVector)
.withPlatform(platform.?.value)
)
}
)).value,
@ -3335,7 +3339,7 @@ object Classpaths {
ScalaArtifacts.toolDependencies(sbtOrg, version) ++
ScalaArtifacts.docToolDependencies(sbtOrg, version)
} else ScalaArtifacts.toolDependencies(sbtOrg, version)
allToolDeps ++ pluginAdjust
allToolDeps.map(_.platform(Platform.jvm)) ++ pluginAdjust
},
// in case of meta build, exclude all sbt modules from the dependency graph, so we can use the sbt resolved by the launcher
allExcludeDependencies := {
@ -4162,7 +4166,8 @@ object Classpaths {
version: String
): Seq[ModuleID] =
if (auto)
modifyForPlugin(plugin, ScalaArtifacts.libraryDependency(org, version)) :: Nil
modifyForPlugin(plugin, ScalaArtifacts.libraryDependency(org, version))
.platform(Platform.jvm) :: Nil
else
Nil

View File

@ -192,6 +192,7 @@ object Keys {
val scalaBinaryVersion = settingKey[String]("The Scala version substring describing binary compatibility.").withRank(BPlusSetting)
val crossScalaVersions = settingKey[Seq[String]]("The versions of Scala used when cross-building.").withRank(BPlusSetting)
val crossVersion = settingKey[CrossVersion]("Configures handling of the Scala version when cross-building.").withRank(CSetting)
val platform = settingKey[String]("Configures the default suffix to be used for %% operator.").withRank(CSetting)
val classpathOptions = settingKey[ClasspathOptions]("Configures handling of Scala classpaths.").withRank(DSetting)
val discoveredSbtPlugins = taskKey[PluginDiscovery.DiscoveredNames]("The names of sbt plugin-related modules (modules that extend Build, Plugin, AutoPlugin) defined by this project.").withRank(CTask)
val sbtPlugin = settingKey[Boolean]("If true, enables adding sbt as a dependency and auto-generation of the plugin descriptor file.").withRank(BMinusSetting)

View File

@ -49,6 +49,7 @@ object CoursierInputsTasks {
description: String,
homepage: Option[URL],
vsOpt: Option[String],
projectPlatform: Option[String],
log: Logger
): CProject = {
@ -59,7 +60,8 @@ object CoursierInputsTasks {
dependencies,
configMap,
sv,
sbv
sbv,
projectPlatform,
)
val proj1 = auOpt match {
case Some(au) =>
@ -88,6 +90,7 @@ object CoursierInputsTasks {
description.value,
homepage.value,
versionScheme.value,
scalaModuleInfo.value.flatMap(_.platform),
streams.value.log
)
}

View File

@ -15,7 +15,7 @@ object Dependencies {
// sbt modules
private val ioVersion = nightlyVersion.getOrElse("1.8.0")
private val lmVersion =
sys.props.get("sbt.build.lm.version").orElse(nightlyVersion).getOrElse("2.0.0-alpha10")
sys.props.get("sbt.build.lm.version").orElse(nightlyVersion).getOrElse("2.0.0-alpha11")
val zincVersion = nightlyVersion.getOrElse("2.0.0-alpha6")
private val sbtIO = "org.scala-sbt" %% "io" % ioVersion
@ -80,7 +80,7 @@ object Dependencies {
def addSbtZincCompileCore = addSbtModule(sbtZincPath, "zincCompileCore", zincCompileCore)
// val lmCoursierShaded = "io.get-coursier" %% "lm-coursier-shaded" % "2.0.10"
val lmCoursierShaded = "org.scala-sbt" %% "librarymanagement-coursier" % "2.0.0-alpha4"
val lmCoursierShaded = "org.scala-sbt" %% "librarymanagement-coursier" % "2.0.0-alpha5"
lazy val sjsonNewVersion = "0.13.0"
def sjsonNew(n: String) = Def.setting(

View File

@ -328,6 +328,7 @@ trait Import {
val Patterns = sbt.librarymanagement.Patterns
type Patterns = sbt.librarymanagement.Patterns
type PatternsBasedRepository = sbt.librarymanagement.PatternsBasedRepository
val Platform = sbt.librarymanagement.Platform
val PublishConfiguration = sbt.librarymanagement.PublishConfiguration
type PublishConfiguration = sbt.librarymanagement.PublishConfiguration
type RawRepository = sbt.librarymanagement.RawRepository

View File

@ -0,0 +1,15 @@
lazy val check = taskKey[Unit]("Runs the check")
scalaVersion := "2.13.10"
platform := Platform.sjs1
// By default platformOpt field is set to None
// Given %% lm engines will sustitute it with the subproject's platform suffix on `update`
libraryDependencies += "com.github.scopt" %% "scopt" % "4.1.0"
TaskKey[Unit]("check") := {
val ur = update.value
val files = ur.matching(moduleFilter(organization = "com.github.scopt", name = "scopt_sjs1_2.13", revision = "*"))
assert(files.nonEmpty, s"sjs1 scopt module was not found in update report: $ur")
}
csrCacheDirectory := baseDirectory.value / "coursier-cache"

View File

@ -0,0 +1 @@
> check