From f831911fbe869558d6395f66ac4cfd8b1a0d2594 Mon Sep 17 00:00:00 2001 From: exoego Date: Wed, 8 May 2019 16:04:52 +0900 Subject: [PATCH] Implement Scala.js support --- src/main/scala/sbt/ProjectMatrix.scala | 31 +++++++++++++------ src/sbt-test/projectMatrix/js/build.sbt | 19 ++++++++++++ .../js/core/src/main/scala/Core.scala | 6 ++++ .../projectMatrix/js/project/plugins.sbt | 5 +++ src/sbt-test/projectMatrix/js/test | 4 +++ 5 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 src/sbt-test/projectMatrix/js/build.sbt create mode 100644 src/sbt-test/projectMatrix/js/core/src/main/scala/Core.scala create mode 100644 src/sbt-test/projectMatrix/js/project/plugins.sbt create mode 100644 src/sbt-test/projectMatrix/js/test diff --git a/src/main/scala/sbt/ProjectMatrix.scala b/src/main/scala/sbt/ProjectMatrix.scala index 7b696b3d4..9ae8fa8cd 100644 --- a/src/main/scala/sbt/ProjectMatrix.scala +++ b/src/main/scala/sbt/ProjectMatrix.scala @@ -67,6 +67,10 @@ sealed trait ProjectMatrix extends CompositeProject { def jvm: ProjectFinder + def jsPlatform(settings: Setting[_]*): ProjectMatrix + + def js: ProjectFinder + def projectRefs: Seq[ProjectReference] } @@ -86,6 +90,8 @@ object ProjectMatrix { val jvmIdSuffix: String = "JVM" val jvmDirectorySuffix: String = "-jvm" + val jsIdSuffix: String = "JS" + val jsDirectorySuffix: String = "-js" /** A row in the project matrix, typically representing a platform. */ @@ -199,19 +205,26 @@ object ProjectMatrix { override def jvmPlatform(settings: Setting[_]*): ProjectMatrix = custom(jvmIdSuffix, jvmDirectorySuffix, Nil, { _.settings(settings) }) - override def jvm: ProjectFinder = new ProjectFinder { - def get: Seq[Project] = projectMatrix.toSeq collect { - case ((r, sv), v) if r.idSuffix == jvmIdSuffix => v - } - def apply(sv: String): Project = - (projectMatrix.toSeq collect { - case ((r, `sv`), v) if r.idSuffix == jvmIdSuffix => v - }).headOption.getOrElse(sys.error(s"$sv was not found")) - } + override def jsPlatform(settings: Setting[_]*): ProjectMatrix = + custom(jsIdSuffix, jsDirectorySuffix, Nil, { _.settings(settings) }) + + override def jvm: ProjectFinder = new SuffixBaseProjectFinder(jvmIdSuffix) + + override def js: ProjectFinder = new SuffixBaseProjectFinder(jsIdSuffix) override def projectRefs: Seq[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( idSuffix: String, directorySuffix: String, diff --git a/src/sbt-test/projectMatrix/js/build.sbt b/src/sbt-test/projectMatrix/js/build.sbt new file mode 100644 index 000000000..4263f054a --- /dev/null +++ b/src/sbt-test/projectMatrix/js/build.sbt @@ -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() diff --git a/src/sbt-test/projectMatrix/js/core/src/main/scala/Core.scala b/src/sbt-test/projectMatrix/js/core/src/main/scala/Core.scala new file mode 100644 index 000000000..274e01225 --- /dev/null +++ b/src/sbt-test/projectMatrix/js/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/js/project/plugins.sbt b/src/sbt-test/projectMatrix/js/project/plugins.sbt new file mode 100644 index 000000000..4e80bbafc --- /dev/null +++ b/src/sbt-test/projectMatrix/js/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/js/test b/src/sbt-test/projectMatrix/js/test new file mode 100644 index 000000000..8ade538b7 --- /dev/null +++ b/src/sbt-test/projectMatrix/js/test @@ -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