diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-14 17:28:31 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-14 17:28:31 -0800 |
commit | 606119317bf28b7029dbd40e04fda04c4fb1c7a5 (patch) | |
tree | cb0a0fa621673391cd9459fe9ea914d7f4140b2b /scalajslib/jsbridges | |
parent | c3f1b0d5c1f523146c718bf9fbb14594893af8e9 (diff) | |
download | mill-606119317bf28b7029dbd40e04fda04c4fb1c7a5.tar.gz mill-606119317bf28b7029dbd40e04fda04c4fb1c7a5.tar.bz2 mill-606119317bf28b7029dbd40e04fda04c4fb1c7a5.zip |
- Tweak Scalajs LinkerBridge project layout to match Mill defaults
- Update `build.sc`, `build.sbt` and `ci/` scripts
Diffstat (limited to 'scalajslib/jsbridges')
2 files changed, 48 insertions, 0 deletions
diff --git a/scalajslib/jsbridges/0.6/src/main/scala/mill/scalajslib/bridge/ScalaJSLinkerBridge.scala b/scalajslib/jsbridges/0.6/src/main/scala/mill/scalajslib/bridge/ScalaJSLinkerBridge.scala new file mode 100644 index 00000000..4826b1cd --- /dev/null +++ b/scalajslib/jsbridges/0.6/src/main/scala/mill/scalajslib/bridge/ScalaJSLinkerBridge.scala @@ -0,0 +1,24 @@ +package mill +package scalajslib +package bridge + +import java.io.File + +import org.scalajs.core.tools.io.IRFileCache.IRContainer +import org.scalajs.core.tools.io.{AtomicWritableFileVirtualJSFile, FileVirtualBinaryFile, FileVirtualScalaJSIRFile, VirtualJarFile} +import org.scalajs.core.tools.linker.{ModuleInitializer, StandardLinker} +import org.scalajs.core.tools.logging.ScalaConsoleLogger + +class ScalaJSLinkerBridge { + def link(sources: Array[File], libraries: Array[File], dest: File, main: String, fullOpt: Boolean): Unit = { + val config = StandardLinker.Config().withOptimizer(fullOpt) + val linker = StandardLinker(config) + val sourceSJSIRs = sources.map(new FileVirtualScalaJSIRFile(_)) + val jars = libraries.map(jar => IRContainer.Jar(new FileVirtualBinaryFile(jar) with VirtualJarFile)) + val jarSJSIRs = jars.flatMap(_.jar.sjsirFiles) + val destFile = AtomicWritableFileVirtualJSFile(dest) + val logger = new ScalaConsoleLogger + val initializer = Option(main).map { cls => ModuleInitializer.mainMethodWithArgs(cls, "main") } + linker.link(sourceSJSIRs ++ jarSJSIRs, initializer.toSeq, destFile, logger) + } +}
\ No newline at end of file diff --git a/scalajslib/jsbridges/1.0/src/main/scala/mill/scalajslib/bridge/ScalaJSLinkerBridge.scala b/scalajslib/jsbridges/1.0/src/main/scala/mill/scalajslib/bridge/ScalaJSLinkerBridge.scala new file mode 100644 index 00000000..ef896726 --- /dev/null +++ b/scalajslib/jsbridges/1.0/src/main/scala/mill/scalajslib/bridge/ScalaJSLinkerBridge.scala @@ -0,0 +1,24 @@ +package mill +package scalajslib +package bridge + +import java.io.File + +import org.scalajs.core.tools.io._ +import org.scalajs.core.tools.linker.{ModuleInitializer, StandardLinker} +import org.scalajs.core.tools.logging.ScalaConsoleLogger + +class ScalaJSLinkerBridge { + def link(sources: Array[File], libraries: Array[File], dest: File, main: String, fullOpt: Boolean): Unit = { + val config = StandardLinker.Config().withOptimizer(fullOpt) + val linker = StandardLinker(config) + val cache = new IRFileCache().newCache + val sourceIRs = sources.map(FileVirtualScalaJSIRFile) + val irContainers = FileScalaJSIRContainer.fromClasspath(libraries) + val libraryIRs = cache.cached(irContainers) + val destFile = AtomicWritableFileVirtualJSFile(dest) + val logger = new ScalaConsoleLogger + val initializer = Option(main).map { cls => ModuleInitializer.mainMethodWithArgs(cls, "main") } + linker.link(sourceIRs ++ libraryIRs, initializer.toSeq, destFile, logger) + } +}
\ No newline at end of file |