Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for non-matrix projects to be aggregated in and depended on by matrix projects #89

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
.idea/
.bsp/
32 changes: 28 additions & 4 deletions src/main/scala/sbt/internal/ProjectMatrix.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@ sealed trait ProjectMatrix extends CompositeProject {
/** Adds classpath dependencies on internal or external projects. */
def dependsOn(deps: MatrixClasspathDep[ProjectMatrixReference]*): ProjectMatrix

/** Adds classpath dependencies on internal or external non-matrix projects. */
def dependsOn(deps: ClasspathDep[ProjectReference]*)(implicit dummyImplicit: DummyImplicit): ProjectMatrix

/**
* Adds projects to be aggregated. When a user requests a task to run on this project from the command line,
* the task will also be run in aggregated projects.
*/
def aggregate(refs: ProjectMatrixReference*): ProjectMatrix

/**
* Allows non-matrix projects to be aggregated in a matrix project.
*/
def aggregate(refs: ProjectReference*)(implicit dummyImplicit: DummyImplicit): ProjectMatrix

/** Appends settings to the current settings sequence for this project. */
def settings(ss: Def.SettingsDefinition*): ProjectMatrix

Expand Down Expand Up @@ -199,7 +207,9 @@ object ProjectMatrix {
val scalaVersions: Seq[String],
val rows: Seq[ProjectRow],
val aggregate: Seq[ProjectMatrixReference],
val nonMatrixAggregate: Seq[ProjectReference],
val dependencies: Seq[MatrixClasspathDep[ProjectMatrixReference]],
val nonMatrixDependencies: Seq[ClasspathDep[ProjectReference]],
val settings: Seq[Def.Setting[_]],
val configurations: Seq[Configuration],
val plugins: Plugins,
Expand Down Expand Up @@ -239,12 +249,12 @@ object ProjectMatrix {
case pa: VirtualAxis.PlatformAxis => pa
}).headOption.getOrElse(sys.error(s"platform axis is missing in $axes"))
val childId = projectIds(r)
val deps = dependencies map { resolveMatrixDependency(_, r) }
val aggs = aggregate map {
val deps = dependencies.map { resolveMatrixDependency(_, r) } ++ nonMatrixDependencies
val aggs = aggregate.map {
case ref: LocalProjectMatrix =>
val other = lookupMatrix(ref)
resolveMatrixAggregate(other, r)
}
} ++ nonMatrixAggregate
val dotSbtMatrix = new java.io.File(".sbt") / "matrix"
IO.createDirectory(dotSbtMatrix)
val p = Project(childId, dotSbtMatrix / childId)
Expand Down Expand Up @@ -350,9 +360,15 @@ object ProjectMatrix {
override def aggregate(refs: ProjectMatrixReference*): ProjectMatrix =
copy(aggregate = (aggregate: Seq[ProjectMatrixReference]) ++ refs)

override def aggregate(refs: ProjectReference*)(implicit dummyImplicit: DummyImplicit): ProjectMatrix =
copy(nonMatrixAggregate = (nonMatrixAggregate: Seq[ProjectReference]) ++ refs)

override def dependsOn(deps: MatrixClasspathDep[ProjectMatrixReference]*): ProjectMatrix =
copy(dependencies = dependencies ++ deps)

override def dependsOn(deps: ClasspathDep[ProjectReference]*)(implicit dummyImplicit: DummyImplicit) =
copy(nonMatrixDependencies = nonMatrixDependencies ++ deps)

/** Appends settings to the current settings sequence for this project. */
override def settings(ss: Def.SettingsDefinition*): ProjectMatrix =
copy(settings = (settings: Seq[Def.Setting[_]]) ++ Def.settings(ss: _*))
Expand Down Expand Up @@ -526,7 +542,9 @@ object ProjectMatrix {
scalaVersions: Seq[String] = scalaVersions,
rows: Seq[ProjectRow] = rows,
aggregate: Seq[ProjectMatrixReference] = aggregate,
nonMatrixAggregate: Seq[ProjectReference] = nonMatrixAggregate,
dependencies: Seq[MatrixClasspathDep[ProjectMatrixReference]] = dependencies,
nonMatrixDependencies: Seq[ClasspathDep[ProjectReference]] = nonMatrixDependencies,
settings: Seq[Setting[_]] = settings,
configurations: Seq[Configuration] = configurations,
plugins: Plugins = plugins,
Expand All @@ -539,7 +557,9 @@ object ProjectMatrix {
scalaVersions,
rows,
aggregate,
nonMatrixAggregate,
dependencies,
nonMatrixDependencies,
settings,
configurations,
plugins,
Expand All @@ -554,7 +574,7 @@ object ProjectMatrix {
// called by macro
def apply(id: String, base: sbt.File): ProjectMatrix = {
val defaultDefAxes = Seq(VirtualAxis.jvm, VirtualAxis.scalaABIVersion("2.13.3"))
val matrix = unresolved(id, base, Nil, Nil, Nil, Nil, Nil, Nil, Plugins.Empty, Nil, defaultDefAxes)
val matrix = unresolved(id, base, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Plugins.Empty, Nil, defaultDefAxes)
allMatrices(id) = matrix
matrix
}
Expand All @@ -565,7 +585,9 @@ object ProjectMatrix {
scalaVersions: Seq[String],
rows: Seq[ProjectRow],
aggregate: Seq[ProjectMatrixReference],
nonMatrixAggregate: Seq[ProjectReference],
dependencies: Seq[MatrixClasspathDep[ProjectMatrixReference]],
nonMatrixDependencies: Seq[ClasspathDep[ProjectReference]],
settings: Seq[Def.Setting[_]],
configurations: Seq[Configuration],
plugins: Plugins,
Expand All @@ -578,7 +600,9 @@ object ProjectMatrix {
scalaVersions,
rows,
aggregate,
nonMatrixAggregate,
dependencies,
nonMatrixDependencies,
settings,
configurations,
plugins,
Expand Down
7 changes: 7 additions & 0 deletions src/sbt-test/projectMatrix/jvm-with-project-axes/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ lazy val app: ProjectMatrix = (projectMatrix in file("app"))
name := "app",
ivyPaths := (ThisBuild / ivyPaths).value
)
.aggregate(domain)
.dependsOn(domain)
.customRow(
autoScalaLibrary = false,
scalaVersions = Seq(scala212),
Expand All @@ -44,3 +46,8 @@ lazy val app: ProjectMatrix = (projectMatrix in file("app"))
libraryDependencies += "com.typesafe" % "config" % "1.3.3"
)
)

lazy val domain = (project in file("domain"))
.settings(
scalaVersion := scala212
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package a

case class DataType()
4 changes: 4 additions & 0 deletions src/sbt-test/projectMatrix/jvm-with-project-axes/test
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
> compile

$ exists domain/target/scala-2.12/classes/a/DataType.class

> check
Loading