Add % syntax for configuration scoping

This commit is contained in:
Eugene Yokota 2020-04-12 13:37:57 -04:00
parent 376c8f4a78
commit b9a18bab2a
7 changed files with 70 additions and 3 deletions

View File

@ -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]

View File

@ -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)
}
}

View File

@ -0,0 +1,5 @@
package a
object Main extends App {
val core = Core
}

View File

@ -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")

View File

@ -0,0 +1,6 @@
package a
class Core {
}
object Core extends Core

View File

@ -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)
}

View File

@ -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