mirror of https://github.com/sbt/sbt.git
Implement Scala.js support
This commit is contained in:
parent
aa8474abe5
commit
f831911fbe
|
|
@ -67,6 +67,10 @@ sealed trait ProjectMatrix extends CompositeProject {
|
||||||
|
|
||||||
def jvm: ProjectFinder
|
def jvm: ProjectFinder
|
||||||
|
|
||||||
|
def jsPlatform(settings: Setting[_]*): ProjectMatrix
|
||||||
|
|
||||||
|
def js: ProjectFinder
|
||||||
|
|
||||||
def projectRefs: Seq[ProjectReference]
|
def projectRefs: Seq[ProjectReference]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,6 +90,8 @@ object ProjectMatrix {
|
||||||
|
|
||||||
val jvmIdSuffix: String = "JVM"
|
val jvmIdSuffix: String = "JVM"
|
||||||
val jvmDirectorySuffix: String = "-jvm"
|
val jvmDirectorySuffix: String = "-jvm"
|
||||||
|
val jsIdSuffix: String = "JS"
|
||||||
|
val jsDirectorySuffix: String = "-js"
|
||||||
|
|
||||||
/** A row in the project matrix, typically representing a platform.
|
/** A row in the project matrix, typically representing a platform.
|
||||||
*/
|
*/
|
||||||
|
|
@ -199,19 +205,26 @@ object ProjectMatrix {
|
||||||
override def jvmPlatform(settings: Setting[_]*): ProjectMatrix =
|
override def jvmPlatform(settings: Setting[_]*): ProjectMatrix =
|
||||||
custom(jvmIdSuffix, jvmDirectorySuffix, Nil, { _.settings(settings) })
|
custom(jvmIdSuffix, jvmDirectorySuffix, Nil, { _.settings(settings) })
|
||||||
|
|
||||||
override def jvm: ProjectFinder = new ProjectFinder {
|
override def jsPlatform(settings: Setting[_]*): ProjectMatrix =
|
||||||
def get: Seq[Project] = projectMatrix.toSeq collect {
|
custom(jsIdSuffix, jsDirectorySuffix, Nil, { _.settings(settings) })
|
||||||
case ((r, sv), v) if r.idSuffix == jvmIdSuffix => v
|
|
||||||
}
|
override def jvm: ProjectFinder = new SuffixBaseProjectFinder(jvmIdSuffix)
|
||||||
def apply(sv: String): Project =
|
|
||||||
(projectMatrix.toSeq collect {
|
override def js: ProjectFinder = new SuffixBaseProjectFinder(jsIdSuffix)
|
||||||
case ((r, `sv`), v) if r.idSuffix == jvmIdSuffix => v
|
|
||||||
}).headOption.getOrElse(sys.error(s"$sv was not found"))
|
|
||||||
}
|
|
||||||
|
|
||||||
override def projectRefs: Seq[ProjectReference] =
|
override def projectRefs: Seq[ProjectReference] =
|
||||||
componentProjects map { case p => (p: ProjectReference) }
|
componentProjects map { case p => (p: ProjectReference) }
|
||||||
|
|
||||||
|
private final class SuffixBaseProjectFinder(idSuffix: String) extends ProjectFinder {
|
||||||
|
def get: Seq[Project] = projectMatrix.toSeq collect {
|
||||||
|
case ((r, sv), v) if r.idSuffix == idSuffix => v
|
||||||
|
}
|
||||||
|
def apply(sv: String): Project =
|
||||||
|
(projectMatrix.toSeq collectFirst {
|
||||||
|
case ((r, `sv`), v) if r.idSuffix == idSuffix => v
|
||||||
|
}).getOrElse(sys.error(s"$sv was not found"))
|
||||||
|
}
|
||||||
|
|
||||||
override def custom(
|
override def custom(
|
||||||
idSuffix: String,
|
idSuffix: String,
|
||||||
directorySuffix: String,
|
directorySuffix: String,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
// lazy val root = (project in file("."))
|
||||||
|
// .aggregate(core.projectRefs ++ app.projectRefs: _*)
|
||||||
|
// .settings(
|
||||||
|
// )
|
||||||
|
|
||||||
|
lazy val core = (projectMatrix in file("core"))
|
||||||
|
.scalaVersions("2.12.6", "2.11.12")
|
||||||
|
.settings(
|
||||||
|
name := "core"
|
||||||
|
)
|
||||||
|
.jsPlatform()
|
||||||
|
|
||||||
|
lazy val app = (projectMatrix in file("app"))
|
||||||
|
.dependsOn(core)
|
||||||
|
.scalaVersions("2.12.6")
|
||||||
|
.settings(
|
||||||
|
name := "app"
|
||||||
|
)
|
||||||
|
.jsPlatform()
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package a
|
||||||
|
|
||||||
|
class Core {
|
||||||
|
}
|
||||||
|
|
||||||
|
object Core extends Core
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
> compile
|
||||||
|
|
||||||
|
$ exists core/target/js-2.12/classes/a/Core.class
|
||||||
|
$ exists core/target/js-2.11/classes/a/Core.class
|
||||||
Loading…
Reference in New Issue