From 376c8f4a78ab399aeca29d908e34434540eae840 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 12 Apr 2020 13:37:00 -0400 Subject: [PATCH 1/3] 0.4.1-SNAPSHOT --- README.markdown | 2 +- build.sbt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index a45e2210b..88486d26c 100644 --- a/README.markdown +++ b/README.markdown @@ -13,7 +13,7 @@ setup In `project/plugins.sbt`: ```scala -addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.3.0") +addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.4.0") // add also the following for Scala.js support addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.27") diff --git a/build.sbt b/build.sbt index cb218600b..c4f929df0 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,5 @@ ThisBuild / organization := "com.eed3si9n" -ThisBuild / version := "0.3.1-SNAPSHOT" +ThisBuild / version := "0.4.1-SNAPSHOT" ThisBuild / description := "sbt plugin to define project matrix for cross building" ThisBuild / licenses := Seq("MIT License" -> url("https://github.com/sbt/sbt-projectmatrix/blob/master/LICENSE")) From b9a18bab2a0280e3072a3901a31647d913abe43f Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 12 Apr 2020 13:37:57 -0400 Subject: [PATCH 2/3] Add % syntax for configuration scoping --- .../scala/sbt/internal/ProjectMatrix.scala | 8 +++++ .../ProjectMatrixPlugin.scala | 11 +++++-- .../app/src/main/scala/Main.scala | 5 +++ .../projectMatrix/jvm-with-scoping/build.sbt | 32 +++++++++++++++++++ .../core/src/main/scala/Core.scala | 6 ++++ .../jvm-with-scoping/project/plugins.sbt | 5 +++ .../projectMatrix/jvm-with-scoping/test | 6 ++++ 7 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/sbt-test/projectMatrix/jvm-with-scoping/app/src/main/scala/Main.scala create mode 100644 src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt create mode 100644 src/sbt-test/projectMatrix/jvm-with-scoping/core/src/main/scala/Core.scala create mode 100644 src/sbt-test/projectMatrix/jvm-with-scoping/project/plugins.sbt create mode 100644 src/sbt-test/projectMatrix/jvm-with-scoping/test diff --git a/src/main/scala/sbt/internal/ProjectMatrix.scala b/src/main/scala/sbt/internal/ProjectMatrix.scala index 51d031869..439930793 100644 --- a/src/main/scala/sbt/internal/ProjectMatrix.scala +++ b/src/main/scala/sbt/internal/ProjectMatrix.scala @@ -160,6 +160,14 @@ object ProjectMatrix { override def toString: String = s"ProjectRow($autoScalaLibrary, $axisValues)" } + final class ProjectMatrixReferenceSyntax(m: ProjectMatrixReference) { + def %(conf: String): ProjectMatrix.MatrixClasspathDependency = + ProjectMatrix.MatrixClasspathDependency(m, Some(conf)) + + def %(conf: Configuration): ProjectMatrix.MatrixClasspathDependency = + ProjectMatrix.MatrixClasspathDependency(m, Some(conf.name)) + } + final case class MatrixClasspathDependency( matrix: ProjectMatrixReference, configuration: Option[String] diff --git a/src/main/scala/sbtprojectmatrix/ProjectMatrixPlugin.scala b/src/main/scala/sbtprojectmatrix/ProjectMatrixPlugin.scala index 88fc607a7..5dc6ed229 100644 --- a/src/main/scala/sbtprojectmatrix/ProjectMatrixPlugin.scala +++ b/src/main/scala/sbtprojectmatrix/ProjectMatrixPlugin.scala @@ -11,9 +11,14 @@ object ProjectMatrixPlugin extends AutoPlugin { object autoImport { def projectMatrix: ProjectMatrix = macro ProjectMatrix.projectMatrixMacroImpl - implicit def matrixClasspathDependency[T]( + implicit def matrixClasspathDependency[T]( m: T - )(implicit ev: T => ProjectMatrixReference): ProjectMatrix.MatrixClasspathDependency = - ProjectMatrix.MatrixClasspathDependency(m, None) + )(implicit ev: T => ProjectMatrixReference): ProjectMatrix.MatrixClasspathDependency = + ProjectMatrix.MatrixClasspathDependency(m, None) + + implicit def matrixReferenceSyntax[T]( + m: T + )(implicit ev: T => ProjectMatrixReference): ProjectMatrix.ProjectMatrixReferenceSyntax = + new ProjectMatrix.ProjectMatrixReferenceSyntax(m) } } diff --git a/src/sbt-test/projectMatrix/jvm-with-scoping/app/src/main/scala/Main.scala b/src/sbt-test/projectMatrix/jvm-with-scoping/app/src/main/scala/Main.scala new file mode 100644 index 000000000..510a46894 --- /dev/null +++ b/src/sbt-test/projectMatrix/jvm-with-scoping/app/src/main/scala/Main.scala @@ -0,0 +1,5 @@ +package a + +object Main extends App { + val core = Core +} diff --git a/src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt b/src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt new file mode 100644 index 000000000..07d3dbb3a --- /dev/null +++ b/src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt @@ -0,0 +1,32 @@ +lazy val check = taskKey[Unit]("") + +lazy val root = (project in file(".")) + .aggregate(core.projectRefs ++ app.projectRefs: _*) + .settings( + ) + +lazy val app = (projectMatrix in file("app")) + .aggregate(core, intf) + .dependsOn(core % Compile, intf % "compile->compile;test->test") + .settings( + name := "app" + ) + .jvmPlatform(scalaVersions = Seq("2.12.8")) + +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")) + +lazy val intf = (projectMatrix in file("intf")) + .settings( + check := { + assert(moduleName.value == "intf", s"moduleName is ${moduleName.value}") + }, + ) + .jvmPlatform(autoScalaLibrary = false) + +lazy val core212 = core.jvm("2.12.8") diff --git a/src/sbt-test/projectMatrix/jvm-with-scoping/core/src/main/scala/Core.scala b/src/sbt-test/projectMatrix/jvm-with-scoping/core/src/main/scala/Core.scala new file mode 100644 index 000000000..274e01225 --- /dev/null +++ b/src/sbt-test/projectMatrix/jvm-with-scoping/core/src/main/scala/Core.scala @@ -0,0 +1,6 @@ +package a + +class Core { +} + +object Core extends Core diff --git a/src/sbt-test/projectMatrix/jvm-with-scoping/project/plugins.sbt b/src/sbt-test/projectMatrix/jvm-with-scoping/project/plugins.sbt new file mode 100644 index 000000000..4e80bbafc --- /dev/null +++ b/src/sbt-test/projectMatrix/jvm-with-scoping/project/plugins.sbt @@ -0,0 +1,5 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} diff --git a/src/sbt-test/projectMatrix/jvm-with-scoping/test b/src/sbt-test/projectMatrix/jvm-with-scoping/test new file mode 100644 index 000000000..a0ccaf5e7 --- /dev/null +++ b/src/sbt-test/projectMatrix/jvm-with-scoping/test @@ -0,0 +1,6 @@ +> compile + +$ exists core/target/jvm-2.12/classes/a/Core.class +$ exists core/target/jvm-2.11/classes/a/Core.class + +> coreJVM2_12/check From 20821a1cc7c17bb6a2bc611ac18adefae6fbfd8a Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 12 Apr 2020 14:04:25 -0400 Subject: [PATCH 3/3] Add configure(...) --- .../scala/sbt/internal/ProjectMatrix.scala | 27 ++++++++++++++----- .../projectMatrix/jvm-with-scoping/build.sbt | 10 +++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/scala/sbt/internal/ProjectMatrix.scala b/src/main/scala/sbt/internal/ProjectMatrix.scala index 439930793..6094c8033 100644 --- a/src/main/scala/sbt/internal/ProjectMatrix.scala +++ b/src/main/scala/sbt/internal/ProjectMatrix.scala @@ -56,6 +56,12 @@ sealed trait ProjectMatrix extends CompositeProject { /** Disable the given plugins on this project. */ def disablePlugins(ps: AutoPlugin*): ProjectMatrix + /** + * Applies the given functions to this Project. + * The second function is applied to the result of applying the first to this Project and so on. + * The intended use is a convenience for applying default configuration provided by a plugin. + */ + def configure(transforms: (Project => Project)*): ProjectMatrix /** * If autoScalaLibrary is false, add non-Scala row. @@ -182,7 +188,8 @@ object ProjectMatrix { val dependencies: Seq[MatrixClasspathDep[ProjectMatrixReference]], val settings: Seq[Def.Setting[_]], val configurations: Seq[Configuration], - val plugins: Plugins + val plugins: Plugins, + val transforms: Seq[Project => Project], ) extends ProjectMatrix { self => lazy val resolvedMappings: ListMap[ProjectRow, Project] = resolveMappings private def resolveProjectIds: Map[ProjectRow, String] = { @@ -240,6 +247,7 @@ object ProjectMatrix { inConfig(Test)(makeSources(nonScalaDirSuffix, svDirSuffix)) ) .settings(self.settings) + .configure(transforms: _*) r -> r.process(p) }): _*) @@ -300,6 +308,9 @@ object ProjectMatrix { override def disablePlugins(ps: AutoPlugin*): ProjectMatrix = setPlugins(Plugins.and(plugins, Plugins.And(ps.map(p => Plugins.Exclude(p)).toList))) + override def configure(ts: (Project => Project)*): ProjectMatrix = + copy(transforms = transforms ++ ts) + def setPlugins(ns: Plugins): ProjectMatrix = copy(plugins = ns) override def jvmPlatform(scalaVersions: Seq[String]): ProjectMatrix = @@ -434,7 +445,8 @@ object ProjectMatrix { dependencies: Seq[MatrixClasspathDep[ProjectMatrixReference]] = dependencies, settings: Seq[Setting[_]] = settings, configurations: Seq[Configuration] = configurations, - plugins: Plugins = plugins + plugins: Plugins = plugins, + transforms: Seq[Project => Project] = transforms, ): ProjectMatrix = { val matrix = unresolved( id, @@ -445,7 +457,8 @@ object ProjectMatrix { dependencies, settings, configurations, - plugins + plugins, + transforms ) allMatrices(id) = matrix matrix @@ -454,7 +467,7 @@ 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) + val matrix = unresolved(id, base, Nil, Nil, Nil, Nil, Nil, Nil, Plugins.Empty, Nil) allMatrices(id) = matrix matrix } @@ -468,7 +481,8 @@ object ProjectMatrix { dependencies: Seq[MatrixClasspathDep[ProjectMatrixReference]], settings: Seq[Def.Setting[_]], configurations: Seq[Configuration], - plugins: Plugins + plugins: Plugins, + transforms: Seq[Project => Project] ): ProjectMatrix = new ProjectMatrixDef( id, @@ -479,7 +493,8 @@ object ProjectMatrix { dependencies, settings, configurations, - plugins + plugins, + transforms ) def lookupMatrix(local: LocalProjectMatrix): ProjectMatrix = { diff --git a/src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt b/src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt index 07d3dbb3a..a7cbf2055 100644 --- a/src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt +++ b/src/sbt-test/projectMatrix/jvm-with-scoping/build.sbt @@ -17,9 +17,13 @@ lazy val core = (projectMatrix in file("core")) .settings( check := { assert(moduleName.value == "core", s"moduleName is ${moduleName.value}") + + val directs = libraryDependencies.value + assert(directs.size == 2, s"$directs") }, ) .jvmPlatform(scalaVersions = Seq("2.12.8", "2.11.12")) + .configure(addStuff) lazy val intf = (projectMatrix in file("intf")) .settings( @@ -30,3 +34,9 @@ lazy val intf = (projectMatrix in file("intf")) .jvmPlatform(autoScalaLibrary = false) lazy val core212 = core.jvm("2.12.8") + +def addStuff(p: Project): Project = { + p.settings( + libraryDependencies += "junit" % "junit" % "4.12" % Test + ) +}