From 03c9bf6c666941dc8f54168d0f8d6a12ddaf1434 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Wed, 21 Feb 2024 16:45:40 +0100 Subject: [PATCH 1/4] Add support for non-matrix projects to be aggregated in and depended on by matrix projects --- .gitignore | 3 ++ .../scala/sbt/internal/ProjectMatrix.scala | 28 ++++++++++++++++++- src/sbt-test/projectMatrix/jvm/build.sbt | 4 +++ .../jvm/domain/src/main/scala/DataType.scala | 3 ++ src/sbt-test/projectMatrix/jvm/test | 1 + 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 src/sbt-test/projectMatrix/jvm/domain/src/main/scala/DataType.scala diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ecc11aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +target/ +.idea/ +.bsp/ diff --git a/src/main/scala/sbt/internal/ProjectMatrix.scala b/src/main/scala/sbt/internal/ProjectMatrix.scala index 0eb191b..408c345 100644 --- a/src/main/scala/sbt/internal/ProjectMatrix.scala +++ b/src/main/scala/sbt/internal/ProjectMatrix.scala @@ -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 @@ -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, @@ -249,7 +259,9 @@ object ProjectMatrix { IO.createDirectory(dotSbtMatrix) val p = Project(childId, dotSbtMatrix / childId) .dependsOn(deps: _*) + .dependsOn(nonMatrixDependencies: _*) .aggregate(aggs: _*) + .aggregate(nonMatrixAggregate: _*) .setPlugins(plugins) .configs(configurations: _*) .settings( @@ -350,9 +362,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: _*)) @@ -526,7 +544,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, @@ -539,7 +559,9 @@ object ProjectMatrix { scalaVersions, rows, aggregate, + nonMatrixAggregate, dependencies, + nonMatrixDependencies, settings, configurations, plugins, @@ -554,7 +576,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 } @@ -565,7 +587,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, @@ -578,7 +602,9 @@ object ProjectMatrix { scalaVersions, rows, aggregate, + nonMatrixAggregate, dependencies, + nonMatrixDependencies, settings, configurations, plugins, diff --git a/src/sbt-test/projectMatrix/jvm/build.sbt b/src/sbt-test/projectMatrix/jvm/build.sbt index 65b08b9..3da6715 100644 --- a/src/sbt-test/projectMatrix/jvm/build.sbt +++ b/src/sbt-test/projectMatrix/jvm/build.sbt @@ -10,6 +10,8 @@ lazy val root = (project in file(".")) lazy val app = (projectMatrix in file("app")) .aggregate(core, intf) .dependsOn(core, intf) + .aggregate(domain) + .dependsOn(domain) .settings( name := "app" ) @@ -33,4 +35,6 @@ lazy val intf = (projectMatrix in file("intf")) ) .jvmPlatform(autoScalaLibrary = false) +lazy val domain = (project in file("domain")) + lazy val core213 = core.jvm(scala213) diff --git a/src/sbt-test/projectMatrix/jvm/domain/src/main/scala/DataType.scala b/src/sbt-test/projectMatrix/jvm/domain/src/main/scala/DataType.scala new file mode 100644 index 0000000..ee2fa58 --- /dev/null +++ b/src/sbt-test/projectMatrix/jvm/domain/src/main/scala/DataType.scala @@ -0,0 +1,3 @@ +package a + +case class DataType() \ No newline at end of file diff --git a/src/sbt-test/projectMatrix/jvm/test b/src/sbt-test/projectMatrix/jvm/test index 4a2cee2..806b8bd 100644 --- a/src/sbt-test/projectMatrix/jvm/test +++ b/src/sbt-test/projectMatrix/jvm/test @@ -2,5 +2,6 @@ $ exists core/target/jvm-2.13/classes/a/Core.class $ exists core/target/jvm-2.12/classes/a/Core.class +$ exists domain/target/classes/a/DataType.class > core/check From 4b60bde2c814a52c3d7ae651238da88244c63d11 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Wed, 21 Feb 2024 16:53:27 +0100 Subject: [PATCH 2/4] Move the test to a different project --- src/sbt-test/projectMatrix/jvm-with-project-axes/build.sbt | 7 +++++++ .../domain/src/main/scala/DataType.scala | 3 +++ src/sbt-test/projectMatrix/jvm-with-project-axes/test | 2 ++ src/sbt-test/projectMatrix/jvm/build.sbt | 4 ---- .../projectMatrix/jvm/domain/src/main/scala/DataType.scala | 3 --- src/sbt-test/projectMatrix/jvm/test | 1 - 6 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 src/sbt-test/projectMatrix/jvm-with-project-axes/domain/src/main/scala/DataType.scala delete mode 100644 src/sbt-test/projectMatrix/jvm/domain/src/main/scala/DataType.scala diff --git a/src/sbt-test/projectMatrix/jvm-with-project-axes/build.sbt b/src/sbt-test/projectMatrix/jvm-with-project-axes/build.sbt index 6d90cf4..4a7e5f3 100644 --- a/src/sbt-test/projectMatrix/jvm-with-project-axes/build.sbt +++ b/src/sbt-test/projectMatrix/jvm-with-project-axes/build.sbt @@ -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), @@ -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 + ) diff --git a/src/sbt-test/projectMatrix/jvm-with-project-axes/domain/src/main/scala/DataType.scala b/src/sbt-test/projectMatrix/jvm-with-project-axes/domain/src/main/scala/DataType.scala new file mode 100644 index 0000000..499a83d --- /dev/null +++ b/src/sbt-test/projectMatrix/jvm-with-project-axes/domain/src/main/scala/DataType.scala @@ -0,0 +1,3 @@ +package a + +case class DataType() diff --git a/src/sbt-test/projectMatrix/jvm-with-project-axes/test b/src/sbt-test/projectMatrix/jvm-with-project-axes/test index 15675b1..51a772e 100644 --- a/src/sbt-test/projectMatrix/jvm-with-project-axes/test +++ b/src/sbt-test/projectMatrix/jvm-with-project-axes/test @@ -1 +1,3 @@ > check + +$ exists domain/target/scala-2.12/classes/a/DataType.class diff --git a/src/sbt-test/projectMatrix/jvm/build.sbt b/src/sbt-test/projectMatrix/jvm/build.sbt index 3da6715..65b08b9 100644 --- a/src/sbt-test/projectMatrix/jvm/build.sbt +++ b/src/sbt-test/projectMatrix/jvm/build.sbt @@ -10,8 +10,6 @@ lazy val root = (project in file(".")) lazy val app = (projectMatrix in file("app")) .aggregate(core, intf) .dependsOn(core, intf) - .aggregate(domain) - .dependsOn(domain) .settings( name := "app" ) @@ -35,6 +33,4 @@ lazy val intf = (projectMatrix in file("intf")) ) .jvmPlatform(autoScalaLibrary = false) -lazy val domain = (project in file("domain")) - lazy val core213 = core.jvm(scala213) diff --git a/src/sbt-test/projectMatrix/jvm/domain/src/main/scala/DataType.scala b/src/sbt-test/projectMatrix/jvm/domain/src/main/scala/DataType.scala deleted file mode 100644 index ee2fa58..0000000 --- a/src/sbt-test/projectMatrix/jvm/domain/src/main/scala/DataType.scala +++ /dev/null @@ -1,3 +0,0 @@ -package a - -case class DataType() \ No newline at end of file diff --git a/src/sbt-test/projectMatrix/jvm/test b/src/sbt-test/projectMatrix/jvm/test index 806b8bd..4a2cee2 100644 --- a/src/sbt-test/projectMatrix/jvm/test +++ b/src/sbt-test/projectMatrix/jvm/test @@ -2,6 +2,5 @@ $ exists core/target/jvm-2.13/classes/a/Core.class $ exists core/target/jvm-2.12/classes/a/Core.class -$ exists domain/target/classes/a/DataType.class > core/check From f4132dc3f8b2ca2f408b4f74cd45b61a58b4573b Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Wed, 21 Feb 2024 17:06:33 +0100 Subject: [PATCH 3/4] Fix test --- src/sbt-test/projectMatrix/jvm-with-project-axes/test | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sbt-test/projectMatrix/jvm-with-project-axes/test b/src/sbt-test/projectMatrix/jvm-with-project-axes/test index 51a772e..29c0480 100644 --- a/src/sbt-test/projectMatrix/jvm-with-project-axes/test +++ b/src/sbt-test/projectMatrix/jvm-with-project-axes/test @@ -1,3 +1,5 @@ -> check +> compile $ exists domain/target/scala-2.12/classes/a/DataType.class + +> check From 9ffcf31e6bfb12cb383f99183b279c38cee75ca7 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Wed, 21 Feb 2024 17:47:58 +0100 Subject: [PATCH 4/4] Code style --- src/main/scala/sbt/internal/ProjectMatrix.scala | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/scala/sbt/internal/ProjectMatrix.scala b/src/main/scala/sbt/internal/ProjectMatrix.scala index 408c345..603a852 100644 --- a/src/main/scala/sbt/internal/ProjectMatrix.scala +++ b/src/main/scala/sbt/internal/ProjectMatrix.scala @@ -249,19 +249,17 @@ 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) .dependsOn(deps: _*) - .dependsOn(nonMatrixDependencies: _*) .aggregate(aggs: _*) - .aggregate(nonMatrixAggregate: _*) .setPlugins(plugins) .configs(configurations: _*) .settings(