Skip to content

Commit

Permalink
Merge pull request #30 from sbt/wip/default
Browse files Browse the repository at this point in the history
treat JVM and 2.13 as default axis
  • Loading branch information
eed3si9n authored Aug 24, 2020
2 parents f8973ae + f31e8cc commit 74feb45
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/main/scala/sbt/VirtualAxis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ object VirtualAxis {
compare(sbv1, sbv2) || compare(sbv2, sbv1)
}

// This admits partial Scala version
private[sbt] def isPartialVersionEquals(ax1: VirtualAxis, ax2: VirtualAxis): Boolean = {
(ax1, ax2) match {
case (ax1: ScalaVersionAxis, ax2: ScalaVersionAxis) =>
(ax1 == ax2) || (ax1.value == ax2.value)
case _ => ax1 == ax2
}
}

case class ScalaVersionAxis(scalaVersion: String, value: String) extends WeakAxis {
override def idSuffix: String = directorySuffix.replaceAll("""\W+""", "_")
override val suffixOrder: Int = 100
Expand Down
35 changes: 27 additions & 8 deletions src/main/scala/sbt/internal/ProjectMatrix.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ sealed trait ProjectMatrix extends CompositeProject {
def nativePlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix
def native: ProjectFinder

def defaultAxes(axes: VirtualAxis*): ProjectMatrix

def projectRefs: Seq[ProjectReference]

def filterProjects(axisValues: Seq[VirtualAxis]): Seq[Project]
Expand Down Expand Up @@ -193,19 +195,24 @@ object ProjectMatrix {
val configurations: Seq[Configuration],
val plugins: Plugins,
val transforms: Seq[Project => Project],
val defAxes: Seq[VirtualAxis],
) extends ProjectMatrix { self =>
lazy val resolvedMappings: ListMap[ProjectRow, Project] = resolveMappings
private def resolveProjectIds: Map[ProjectRow, String] = {
Map((for {
r <- rows
} yield {
val axes = r.axisValues.sortBy(_.suffixOrder)
.filterNot(isSortOfDefaultAxis)
val idSuffix = axes.map(_.idSuffix).mkString("")
val childId = self.id + idSuffix
r -> childId
}): _*)
}

private def isSortOfDefaultAxis(a: VirtualAxis): Boolean =
defAxes exists { da => VirtualAxis.isPartialVersionEquals(da, a) }

private def resolveMappings: ListMap[ProjectRow, Project] = {
val projectIds = resolveProjectIds

Expand Down Expand Up @@ -240,8 +247,11 @@ object ProjectMatrix {
name := self.id
)
.settings(
r.scalaVersionOpt.toList map { sv =>
Keys.scalaVersion := sv
r.scalaVersionOpt match {
case Some(sv) =>
List(Keys.scalaVersion := sv)
case _ =>
List(Keys.autoScalaLibrary := false, Keys.crossPaths := false)
}
)
.settings(
Expand Down Expand Up @@ -279,7 +289,8 @@ object ProjectMatrix {
case (Some(depProjId), Some(depSV), Some(depSBV), Some(depCross)) =>
if (sbv == depSBV || depCross != CrossVersion.binary)
Some(
depProjId.withConfigurations(dep.configuration).withExplicitArtifacts(Vector.empty)
depProjId.withConfigurations(dep.configuration)
.withExplicitArtifacts(Vector.empty)
)
else if (VirtualAxis.isScala2Scala3Sandwich(sbv, depSBV) && depCross == CrossVersion.binary)
Some(
Expand All @@ -288,7 +299,7 @@ object ProjectMatrix {
.withConfigurations(dep.configuration)
.withExplicitArtifacts(Vector.empty)
)
else sys.error(s"scalaBinaryVersion mismatch: expected $sbv but found ${depSBV}")
else sys.error(s"scalaBinaryVersion mismatch: expected $sbv but found ${depSBV} in $depProjId")
case _ => None
}
}
Expand Down Expand Up @@ -382,6 +393,9 @@ object ProjectMatrix {
.settings(settings)
})

override def defaultAxes(axes: VirtualAxis*): ProjectMatrix =
copy(defAxes = axes.toSeq)

def scalajsPlugin(classLoader: ClassLoader): Try[AutoPlugin] = {
import sbtprojectmatrix.ReflectionUtil._
withContextClassloader(classLoader) { loader =>
Expand Down Expand Up @@ -491,6 +505,7 @@ object ProjectMatrix {
configurations: Seq[Configuration] = configurations,
plugins: Plugins = plugins,
transforms: Seq[Project => Project] = transforms,
defAxes: Seq[VirtualAxis] = defAxes,
): ProjectMatrix = {
val matrix = unresolved(
id,
Expand All @@ -502,7 +517,8 @@ object ProjectMatrix {
settings,
configurations,
plugins,
transforms
transforms,
defAxes,
)
allMatrices(id) = matrix
matrix
Expand All @@ -511,7 +527,8 @@ object ProjectMatrix {

// called by macro
def apply(id: String, base: sbt.File): ProjectMatrix = {
val matrix = unresolved(id, base, Nil, Nil, Nil, Nil, Nil, Nil, Plugins.Empty, Nil)
val defaultDefAxes = Seq(VirtualAxis.jvm, VirtualAxis.scalaPartialVersion("2.13.3"))
val matrix = unresolved(id, base, Nil, Nil, Nil, Nil, Nil, Nil, Plugins.Empty, Nil, defaultDefAxes)
allMatrices(id) = matrix
matrix
}
Expand All @@ -526,7 +543,8 @@ object ProjectMatrix {
settings: Seq[Def.Setting[_]],
configurations: Seq[Configuration],
plugins: Plugins,
transforms: Seq[Project => Project]
transforms: Seq[Project => Project],
defAxes: Seq[VirtualAxis],
): ProjectMatrix =
new ProjectMatrixDef(
id,
Expand All @@ -538,7 +556,8 @@ object ProjectMatrix {
settings,
configurations,
plugins,
transforms
transforms,
defAxes,
)

def lookupMatrix(local: LocalProjectMatrix): ProjectMatrix = {
Expand Down
6 changes: 3 additions & 3 deletions src/sbt-test/projectMatrix/jvm-sandwich/test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
> fooAppJVM0_23/compile
> fooApp0_23/compile

> barAppJVM2_13/compile
> barApp/compile

> bazAppJVM2_13/check
> bazApp/check
8 changes: 5 additions & 3 deletions src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
lazy val scala213 = "2.13.3"
lazy val scala212 = "2.12.12"
lazy val check = taskKey[Unit]("")

lazy val root = (project in file("."))
Expand All @@ -11,7 +13,7 @@ lazy val app = (projectMatrix in file("app"))
.settings(
name := "app"
)
.jvmPlatform(scalaVersions = Seq("2.12.8"))
.jvmPlatform(scalaVersions = Seq(scala213))

lazy val core = (projectMatrix in file("core"))
.settings(
Expand All @@ -22,7 +24,7 @@ lazy val core = (projectMatrix in file("core"))
assert(directs.size == 2, s"$directs")
},
)
.jvmPlatform(scalaVersions = Seq("2.12.8", "2.11.12"))
.jvmPlatform(scalaVersions = Seq(scala213, scala212))
.configure(addStuff)

lazy val intf = (projectMatrix in file("intf"))
Expand All @@ -33,7 +35,7 @@ lazy val intf = (projectMatrix in file("intf"))
)
.jvmPlatform(autoScalaLibrary = false)

lazy val core212 = core.jvm("2.12.8")
lazy val core213 = core.jvm(scala213)

def addStuff(p: Project): Project = {
p.settings(
Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/projectMatrix/jvm-with-scoping/test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
> compile

$ exists core/target/jvm-2.13/classes/a/Core.class
$ exists core/target/jvm-2.12/classes/a/Core.class
$ exists core/target/jvm-2.11/classes/a/Core.class

> coreJVM2_12/check
> core/check
8 changes: 5 additions & 3 deletions src/sbt-test/projectMatrix/jvm/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
lazy val scala213 = "2.13.3"
lazy val scala212 = "2.12.12"
lazy val check = taskKey[Unit]("")

lazy val root = (project in file("."))
Expand All @@ -11,15 +13,15 @@ lazy val app = (projectMatrix in file("app"))
.settings(
name := "app"
)
.jvmPlatform(scalaVersions = Seq("2.12.8"))
.jvmPlatform(scalaVersions = Seq(scala213))

lazy val core = (projectMatrix in file("core"))
.settings(
check := {
assert(moduleName.value == "core", s"moduleName is ${moduleName.value}")
},
)
.jvmPlatform(scalaVersions = Seq("2.12.8", "2.11.12"))
.jvmPlatform(scalaVersions = Seq(scala213, scala212))

lazy val intf = (projectMatrix in file("intf"))
.settings(
Expand All @@ -29,4 +31,4 @@ lazy val intf = (projectMatrix in file("intf"))
)
.jvmPlatform(autoScalaLibrary = false)

lazy val core212 = core.jvm("2.12.8")
lazy val core213 = core.jvm(scala213)
4 changes: 2 additions & 2 deletions src/sbt-test/projectMatrix/jvm/test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
> compile

$ exists core/target/jvm-2.13/classes/a/Core.class
$ exists core/target/jvm-2.12/classes/a/Core.class
$ exists core/target/jvm-2.11/classes/a/Core.class

> coreJVM2_12/check
> core/check

0 comments on commit 74feb45

Please sign in to comment.