mirror of https://github.com/sbt/sbt.git
Merge pull request #36 from keynmol/expose-project-axes
Make the generated subproject self-aware about its own virtual axes
This commit is contained in:
commit
0843222509
|
|
@ -152,7 +152,7 @@ lazy val app = (projectMatrix in file("app"))
|
|||
|
||||
This will create `appConfig1_22_11`, `appConfig1_22_12`, and `appConfig1_32_12` respectively producing `app_config1.3_2.12`, `app_config1.2_2.11`, and `app_config1.2_2.12` artifacts.
|
||||
|
||||
### referncing the generated subprojects
|
||||
### referencing the generated subprojects
|
||||
|
||||
You might want to reference to one of the projects within `build.sbt`.
|
||||
|
||||
|
|
@ -164,6 +164,29 @@ lazy val appConfig12_212 = app.finder(config13, VirtualAxis.jvm)("2.12.8")
|
|||
|
||||
In the above `core12` returns `Project` type.
|
||||
|
||||
### accessing axes from subprojects
|
||||
|
||||
Each generated subproject can access the values for all the axes using `virtualAxes` key:
|
||||
|
||||
```scala
|
||||
lazy val platformTest = settingKey[String]("")
|
||||
|
||||
lazy val core = (projectMatrix in file("core"))
|
||||
.settings(
|
||||
name := "core"
|
||||
)
|
||||
.jsPlatform(scalaVersions = Seq("2.12.12", "2.11.12"))
|
||||
.jvmPlatform(scalaVersion = Seq("2.12.12", "2.13.3"))
|
||||
.settings(
|
||||
platformTest := {
|
||||
if(virtualAxes.value.contains(VirtualAxis.jvm))
|
||||
"JVM project"
|
||||
else
|
||||
"JS project"
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
credits
|
||||
-------
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import Keys._
|
|||
import scala.util.Try
|
||||
import sbt.internal.inc.ReflectUtilities
|
||||
|
||||
import sbtprojectmatrix.ProjectMatrixKeys
|
||||
|
||||
/**
|
||||
* A project matrix is an implementation of a composite project
|
||||
* that represents cross building across some axis (such as platform)
|
||||
|
|
@ -261,6 +263,7 @@ object ProjectMatrix {
|
|||
inConfig(Compile)(makeSources(nonScalaDirSuffix, svDirSuffix)),
|
||||
inConfig(Test)(makeSources(nonScalaDirSuffix, svDirSuffix)),
|
||||
projectDependencies := projectDependenciesTask.value,
|
||||
ProjectMatrixKeys.virtualAxes := axes
|
||||
)
|
||||
.settings(self.settings)
|
||||
.configure(transforms: _*)
|
||||
|
|
|
|||
|
|
@ -5,10 +5,16 @@ import internal._
|
|||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import scala.language.experimental.macros
|
||||
|
||||
trait ProjectMatrixKeys {
|
||||
val virtualAxes = settingKey[Seq[VirtualAxis]]("Virtual axes for the project")
|
||||
}
|
||||
|
||||
object ProjectMatrixKeys extends ProjectMatrixKeys
|
||||
|
||||
object ProjectMatrixPlugin extends AutoPlugin {
|
||||
override val requires = sbt.plugins.CorePlugin
|
||||
override val trigger = allRequirements
|
||||
object autoImport {
|
||||
object autoImport extends ProjectMatrixKeys {
|
||||
def projectMatrix: ProjectMatrix = macro ProjectMatrix.projectMatrixMacroImpl
|
||||
|
||||
implicit def matrixClasspathDependency[T](
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
sbt.version = 1.4.3
|
||||
|
|
@ -3,4 +3,4 @@ sys.props.get("plugin.version") match {
|
|||
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|
||||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
|
||||
}
|
||||
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.9")
|
||||
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0-M2")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
lazy val scala213 = "2.13.3"
|
||||
lazy val scala212 = "2.12.12"
|
||||
lazy val check = taskKey[Unit]("")
|
||||
lazy val platformTest = settingKey[String]("")
|
||||
lazy val configTest = settingKey[String]("")
|
||||
|
||||
|
||||
lazy val config12 = ConfigAxis("Config1_2", "config1.2")
|
||||
lazy val config13 = ConfigAxis("Config1_3", "config1.3")
|
||||
|
||||
lazy val root = (project in file("."))
|
||||
.aggregate((core.projectRefs ++ custom.projectRefs):_*)
|
||||
|
||||
lazy val core = (projectMatrix in file("core"))
|
||||
.settings(
|
||||
check := {
|
||||
assert(platformTest.value.endsWith("-platform"))
|
||||
},
|
||||
)
|
||||
.jvmPlatform(scalaVersions = Seq(scala213, scala212))
|
||||
.jsPlatform(scalaVersions = Seq(scala212))
|
||||
.settings(platformSettings)
|
||||
|
||||
lazy val custom =
|
||||
(projectMatrix in file("custom"))
|
||||
.customRow(
|
||||
scalaVersions = Seq(scala212),
|
||||
axisValues = Seq(config13, VirtualAxis.jvm),
|
||||
_.settings()
|
||||
)
|
||||
.settings(platformSettings)
|
||||
.settings(customSettings)
|
||||
.settings(
|
||||
check := {
|
||||
assert(platformTest.value.endsWith("-platform"))
|
||||
assert(configTest.value.startsWith("config for"))
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
lazy val platformSettings = Seq[Def.Setting[_]](
|
||||
platformTest := {
|
||||
if(virtualAxes.value.contains(sbt.VirtualAxis.js)) "js-platform"
|
||||
else if(virtualAxes.value.contains(sbt.VirtualAxis.jvm)) "jvm-platform"
|
||||
else throw new RuntimeException(s"Something must be wrong (built-in platforms test) - virtualAxes value is ${virtualAxes.value}")
|
||||
}
|
||||
)
|
||||
|
||||
lazy val customSettings = Seq[Def.Setting[_]](
|
||||
configTest := {
|
||||
if(virtualAxes.value.contains(config12)) "config for 1.2"
|
||||
else if (virtualAxes.value.contains(config13)) "config for 1.3"
|
||||
else throw new RuntimeException(s"Something must be wrong (custom axis test ) - virtualAxes value is ${virtualAxes.value}")
|
||||
}
|
||||
)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import sbt._
|
||||
|
||||
case class ConfigAxis(idSuffix: String, directorySuffix: String) extends VirtualAxis.WeakAxis
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
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)
|
||||
}
|
||||
|
||||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.3.0")
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
> compile
|
||||
> check
|
||||
Loading…
Reference in New Issue