summaryrefslogtreecommitdiff
path: root/scalajslib/src
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-12-12 22:15:38 +0800
committerGitHub <noreply@github.com>2018-12-12 22:15:38 +0800
commitea7fceb6e56f53bde3517586dfc57e10a605a524 (patch)
treecf2e4b7a403f8bcbcf3d1c4c45a8abd315cbefe6 /scalajslib/src
parentd0e1b572e88d311e1aee23d92e0384a81de4bcb6 (diff)
downloadmill-ea7fceb6e56f53bde3517586dfc57e10a605a524.tar.gz
mill-ea7fceb6e56f53bde3517586dfc57e10a605a524.tar.bz2
mill-ea7fceb6e56f53bde3517586dfc57e10a605a524.zip
First pass at splitting out worker-api from mill core. (#504)
This reduces the {scala,scalajs,scalanative}-worker dependency from the entirety of Mill to a much narrower `mill.api` module. This reduces the amount of classpath pollution within these workers, should mean they're much faster to download the first time, and reduces the amount of random junk they would pull in if they were to be used outside of the Mill project. The interactions between the various *Modules and their *WorkerImpls has been narrowed down to the `*.api` modules, which only depend on other `*.api` modules. A lot of things have been moved around; user code is unlikely to break, but it's possible some will if it references classes that have been moved around. Forwarders have been left for the few internal classes that Mill uses in it's own `build.sc`, to support bootstrapping. Third-party code which breaks should be a straightforward to fix just by updating imports The `*.api` modules have minimal dependencies (mostly uPickle and os-lib) and minimal code. There is still a bunch of implementation code in there: some of it defining data-types that are commonly sent across the module/worker interface (`Agg`, `PathRef`, ...), and some of it just general helper functions that are needed both in modules and workers. The latter code isn't strictly API definitions, but for now is small enough it's not worth splitting into it's own module
Diffstat (limited to 'scalajslib/src')
-rw-r--r--scalajslib/src/mill/scalajslib/NodeJSConfig.scala11
-rw-r--r--scalajslib/src/mill/scalajslib/ScalaJSModule.scala10
-rw-r--r--scalajslib/src/mill/scalajslib/ScalaJSWorkerApi.scala35
3 files changed, 9 insertions, 47 deletions
diff --git a/scalajslib/src/mill/scalajslib/NodeJSConfig.scala b/scalajslib/src/mill/scalajslib/NodeJSConfig.scala
deleted file mode 100644
index de39308c..00000000
--- a/scalajslib/src/mill/scalajslib/NodeJSConfig.scala
+++ /dev/null
@@ -1,11 +0,0 @@
-package mill.scalajslib
-
-object NodeJSConfig {
- import upickle.default.{ReadWriter => RW, macroRW}
- implicit def rw: RW[NodeJSConfig] = macroRW
-}
-
-final case class NodeJSConfig(executable: String = "node",
- args: List[String] = Nil,
- env: Map[String, String] = Map.empty,
- sourceMap: Boolean = true)
diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala
index 37537a85..8568c39b 100644
--- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala
+++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala
@@ -4,11 +4,11 @@ package scalajslib
import coursier.Cache
import coursier.maven.MavenRepository
import mill.eval.{PathRef, Result}
-import mill.eval.Result.Success
+import mill.api.Result.Success
import mill.scalalib.Lib.resolveDependencies
import mill.scalalib.{DepSyntax, Lib, TestModule, TestRunner}
import mill.util.{Ctx, Loose}
-
+import mill.scalajslib.api._
trait ScalaJSModule extends scalalib.ScalaModule { outer =>
def scalaJSVersion: T[String]
@@ -21,7 +21,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
override def moduleDeps = Seq(outer)
}
- def scalaJSBinaryVersion = T { Lib.scalaBinaryVersion(scalaJSVersion()) }
+ def scalaJSBinaryVersion = T { mill.scalalib.api.Util.scalaBinaryVersion(scalaJSVersion()) }
def scalaJSWorkerVersion = T{ scalaJSVersion().split('.').dropRight(1).mkString(".") }
@@ -92,11 +92,11 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
}
override def runMainLocal(mainClass: String, args: String*) = T.command[Unit] {
- mill.eval.Result.Failure("runMain is not supported in Scala.js")
+ mill.api.Result.Failure("runMain is not supported in Scala.js")
}
override def runMain(mainClass: String, args: String*) = T.command[Unit] {
- mill.eval.Result.Failure("runMain is not supported in Scala.js")
+ mill.api.Result.Failure("runMain is not supported in Scala.js")
}
def link(worker: ScalaJSWorker,
diff --git a/scalajslib/src/mill/scalajslib/ScalaJSWorkerApi.scala b/scalajslib/src/mill/scalajslib/ScalaJSWorkerApi.scala
index 881a65b9..bcaeb2d3 100644
--- a/scalajslib/src/mill/scalajslib/ScalaJSWorkerApi.scala
+++ b/scalajslib/src/mill/scalajslib/ScalaJSWorkerApi.scala
@@ -4,21 +4,10 @@ import java.io.File
import java.net.URLClassLoader
import mill.define.Discover
-import mill.eval.Result
-import mill.util.Ctx
+import mill.api.Result
+import mill.api.Ctx
import mill.{Agg, T}
-
-sealed trait OptimizeMode
-
-object FastOpt extends OptimizeMode
-object FullOpt extends OptimizeMode
-
-sealed trait ModuleKind
-object ModuleKind{
- object NoModule extends ModuleKind
- object CommonJSModule extends ModuleKind
-}
-
+import mill.scalajslib.api._
class ScalaJSWorker {
private var scalaInstanceCache = Option.empty[(Long, ScalaJSWorkerApi)]
@@ -29,7 +18,7 @@ class ScalaJSWorker {
scalaInstanceCache match {
case Some((sig, bridge)) if sig == classloaderSig => bridge
case _ =>
- val cl = mill.util.ClassLoader.create(
+ val cl = mill.api.ClassLoader.create(
toolsClasspath.map(_.toIO.toURI.toURL).toVector,
getClass.getClassLoader
)
@@ -76,22 +65,6 @@ class ScalaJSWorker {
}
-trait ScalaJSWorkerApi {
- def link(sources: Array[File],
- libraries: Array[File],
- dest: File,
- main: String,
- fullOpt: Boolean,
- moduleKind: ModuleKind): Result[File]
-
- def run(config: NodeJSConfig, linkedFile: File): Unit
-
- def getFramework(config: NodeJSConfig,
- frameworkName: String,
- linkedFile: File): (() => Unit, sbt.testing.Framework)
-
-}
-
object ScalaJSWorkerApi extends mill.define.ExternalModule {
def scalaJSWorker = T.worker { new ScalaJSWorker() }