Add configure(...)

This commit is contained in:
Eugene Yokota 2020-04-12 14:04:25 -04:00
parent b9a18bab2a
commit 20821a1cc7
2 changed files with 31 additions and 6 deletions

View File

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

View File

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