diff options
author | Katrin Shechtman <katrin.shechtman@gmail.com> | 2016-06-13 01:23:45 -0400 |
---|---|---|
committer | Katrin Shechtman <katrin.shechtman@gmail.com> | 2016-06-13 11:48:05 -0400 |
commit | 59c9e1e4bfc45f843f89da22e0190d19403b4dc6 (patch) | |
tree | c754e73fa8ac7f7363dd5a66521e17ef1dbab03d /plugins | |
parent | b69826c7bc44573f01366ef472a59def6e4f1fc5 (diff) | |
download | cbt-59c9e1e4bfc45f843f89da22e0190d19403b4dc6.tar.gz cbt-59c9e1e4bfc45f843f89da22e0190d19403b4dc6.tar.bz2 cbt-59c9e1e4bfc45f843f89da22e0190d19403b4dc6.zip |
scalajs cross project support as plugin
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/scalajs/ScalaJs.scala | 82 | ||||
-rw-r--r-- | plugins/scalajs/ScalaJsInformation.scala | 25 | ||||
-rw-r--r-- | plugins/scalajs/build/build.scala | 9 |
3 files changed, 116 insertions, 0 deletions
diff --git a/plugins/scalajs/ScalaJs.scala b/plugins/scalajs/ScalaJs.scala new file mode 100644 index 0000000..bde3307 --- /dev/null +++ b/plugins/scalajs/ScalaJs.scala @@ -0,0 +1,82 @@ +import java.io.File + +import cbt._ + +import scala.collection.immutable.Seq + +trait ScalaJsSbtDependencyDsl extends SbtDependencyDsl { self: ScalaJsBuild => + + //Note: We make same assumption about scala version. + //In order to be able to choose different scala version, one has to use %. + implicit class ScalaJsDependencyBuilder(groupId: String){ + def %%%(artifactId: String) = new DependencyBuilder2( + groupId, artifactId + artifactIdSuffix, Some(scalaMajorVersion)) + } +} + +trait ScalaJsBuild extends BasicBuild with ScalaJsSbtDependencyDsl with ScalaJsInformation { outer => + + def sharedFolder = projectDirectory ++ "/shared" + def jvmFolder = projectDirectory ++ "/jvm" + def jsFolder = projectDirectory ++ "/js" + + private lazy val jvmBuild = new BasicBuild(outer.context){ + override def sources = Seq(sharedFolder ++ "/src/main/scala", jvmFolder ++ "/src/main/scala") + override def target = jvmFolder ++ "/target" + override def dependencies = outer.dependencies ++ jvmDependencies + } + private lazy val jsBuild = new BasicBuild(outer.context){ + override def sources = Seq(sharedFolder ++ "/src/main/scala", jsFolder ++ "/src/main/scala") + override def target = jsFolder ++ "/target" + override def dependencies = outer.dependencies :+ scalaJsLibDep + override def scalacOptions = super.scalacOptions ++ + Seq(s"-Xplugin:${scalaJsCompilerDep.jar.getAbsolutePath}", "-Xplugin-require:scalajs") + } + + def jvmDependencies = Seq.empty[Dependency] + //TODO: implement + def jsDependencies = Seq.empty[Dependency] + def jvmCompile: Option[File] = jvmBuild.compile + def jsCompile: Option[File] = jsBuild.compile + override def compile = { + jvmCompile + jsCompile + } + + trait JsOutputMode { + def option: String + def fileSuffix: String + } + case object FastOptJS extends JsOutputMode{ + override val option = "-f" + override val fileSuffix = "fastopt" + } + case object FullOptJS extends JsOutputMode{ + override val option = "-u" + override val fileSuffix = "fullopt" + } + + private def output(mode: JsOutputMode) = s"${jsBuild.target.getAbsolutePath}/$projectName-${mode.fileSuffix}.js" + + //TODO: should process all options that Scalajsld recognizes? + private def link(mode: JsOutputMode, outputPath: String) = { + lib.runMain( + "org.scalajs.cli.Scalajsld", + Seq( + mode.option, + "-s", + "--stdlib", s"${scalaJsLibDep.jar.getAbsolutePath}", + "-o", outputPath, + jsBuild.target.getAbsolutePath) ++ + jsBuild.dependencies.collect{case d: BoundMavenDependency => d.jar.getAbsolutePath}, + scalaJsCliDep.classLoader(jsBuild.context.classLoaderCache)) + } + def fastOptJS = link(FastOptJS, fastOptOutput) + def fullOptJS = link(FullOptJS, fullOptOutput) + def fastOptOutput: String = output(FastOptJS) + def fullOptOutput: String = output(FullOptJS) +} + + + + diff --git a/plugins/scalajs/ScalaJsInformation.scala b/plugins/scalajs/ScalaJsInformation.scala new file mode 100644 index 0000000..938d207 --- /dev/null +++ b/plugins/scalajs/ScalaJsInformation.scala @@ -0,0 +1,25 @@ +import cbt._ + +trait ScalaJsInformation extends BasicBuild { outer => + + val sjsVersion = "0.6.8" + final private val sjsMajorVersion: String = lib.libMajorVersion(sjsVersion) + final protected val artifactIdSuffix = s"_sjs$sjsMajorVersion" + + final protected val scalaJsCompilerDep = + Resolver( mavenCentral ).bindOne( + // Has to be full Scala version because the compiler is incompatible between versions + MavenDependency("org.scala-js", "scalajs-compiler_2.11.8", sjsVersion) + ) + + final protected val scalaJsLibDep = + Resolver( mavenCentral ).bindOne( + ScalaDependency("org.scala-js", "scalajs-library", sjsVersion) + ) + + final protected val scalaJsCliDep = + Resolver( mavenCentral ).bindOne( + ScalaDependency("org.scala-js", "scalajs-cli", sjsVersion) + ) +} + diff --git a/plugins/scalajs/build/build.scala b/plugins/scalajs/build/build.scala new file mode 100644 index 0000000..9a73704 --- /dev/null +++ b/plugins/scalajs/build/build.scala @@ -0,0 +1,9 @@ +import cbt._ + +class Build(context: Context) extends BasicBuild(context) { + + override def dependencies = + super.dependencies :+ + context.cbtDependency +} + |