From ea7fceb6e56f53bde3517586dfc57e10a605a524 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 12 Dec 2018 22:15:38 +0800 Subject: 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 --- main/src/mill/MillMain.scala | 4 ++-- main/src/mill/main/MainScopts.scala | 2 +- main/src/mill/main/MillServerMain.scala | 2 +- main/src/mill/main/RunScript.scala | 3 ++- main/src/mill/main/VisualizeModule.scala | 2 +- main/src/mill/modules/Jvm.scala | 9 +++++---- main/src/mill/modules/Util.scala | 31 +++++-------------------------- main/src/mill/package.scala | 4 ++-- 8 files changed, 19 insertions(+), 38 deletions(-) (limited to 'main/src') diff --git a/main/src/mill/MillMain.scala b/main/src/mill/MillMain.scala index e030fdc7..e953e65d 100644 --- a/main/src/mill/MillMain.scala +++ b/main/src/mill/MillMain.scala @@ -6,7 +6,7 @@ import scala.collection.JavaConverters._ import ammonite.main.Cli._ import io.github.retronym.java9rtexport.Export import mill.eval.Evaluator -import mill.util.DummyInputStream +import mill.api.DummyInputStream object MillMain { @@ -38,7 +38,7 @@ object MillMain { setIdle: Boolean => Unit): (Boolean, Option[Evaluator.State]) = { import ammonite.main.Cli - val millHome = mill.util.Ctx.defaultHome + val millHome = mill.api.Ctx.defaultHome val removed = Set("predef-code", "no-home-predef") var interactive = false diff --git a/main/src/mill/main/MainScopts.scala b/main/src/mill/main/MainScopts.scala index 5cc4d7ba..718a30e6 100644 --- a/main/src/mill/main/MainScopts.scala +++ b/main/src/mill/main/MainScopts.scala @@ -25,7 +25,7 @@ object Tasks{ class EvaluatorScopt[T]() extends scopt.Read[mill.eval.Evaluator]{ def arity = 0 - def reads = s => try{ + def reads = s => { Evaluator.currentEvaluator.get.asInstanceOf[mill.eval.Evaluator] } } diff --git a/main/src/mill/main/MillServerMain.scala b/main/src/mill/main/MillServerMain.scala index 5ced75eb..26ca99e6 100644 --- a/main/src/mill/main/MillServerMain.scala +++ b/main/src/mill/main/MillServerMain.scala @@ -9,7 +9,7 @@ import scala.collection.JavaConverters._ import org.scalasbt.ipcsocket._ import mill.main.client._ import mill.eval.Evaluator -import mill.util.DummyInputStream +import mill.api.DummyInputStream import sun.misc.{Signal, SignalHandler} trait MillServerMain[T]{ diff --git a/main/src/mill/main/RunScript.scala b/main/src/mill/main/RunScript.scala index 119ac2aa..47526631 100644 --- a/main/src/mill/main/RunScript.scala +++ b/main/src/mill/main/RunScript.scala @@ -9,7 +9,8 @@ import ammonite.util.{Name, Res, Util} import mill.define import mill.define._ import mill.eval.{Evaluator, PathRef, Result} -import mill.util.{EitherOps, Logger, ParseArgs, Watched} +import mill.util.{EitherOps, ParseArgs, Watched} +import mill.api.Logger import mill.util.Strict.Agg import scala.collection.mutable diff --git a/main/src/mill/main/VisualizeModule.scala b/main/src/mill/main/VisualizeModule.scala index 71b9fc22..e950973f 100644 --- a/main/src/mill/main/VisualizeModule.scala +++ b/main/src/mill/main/VisualizeModule.scala @@ -37,7 +37,7 @@ trait VisualizeModule extends mill.define.TaskModule{ val in = new LinkedBlockingQueue[(Seq[_], Seq[_], os.Path)]() val out = new LinkedBlockingQueue[Result[Seq[PathRef]]]() - val cl = mill.util.ClassLoader.create( + val cl = mill.api.ClassLoader.create( classpath().map(_.path.toNIO.toUri.toURL).toVector, getClass.getClassLoader ) diff --git a/main/src/mill/modules/Jvm.scala b/main/src/mill/modules/Jvm.scala index 8d2c4de4..1a51ed8b 100644 --- a/main/src/mill/modules/Jvm.scala +++ b/main/src/mill/modules/Jvm.scala @@ -13,7 +13,8 @@ import coursier.util.{Gather, Task} import geny.Generator import mill.main.client.InputPumper import mill.eval.{PathRef, Result} -import mill.util.{Ctx, IO} +import mill.util.Ctx +import mill.api.IO import mill.util.Loose.Agg import scala.collection.mutable @@ -165,15 +166,15 @@ object Jvm { val urls = classPath.map(_.toIO.toURI.toURL) val cl = if (classLoaderOverrideSbtTesting) { val outerClassLoader = getClass.getClassLoader - mill.util.ClassLoader.create(urls.toVector, null, customFindClass = { name => + mill.api.ClassLoader.create(urls.toVector, null, customFindClass = { name => if (name.startsWith("sbt.testing.")) Some(outerClassLoader.loadClass(name)) else None }) } else if (isolated) { - mill.util.ClassLoader.create(urls.toVector, null) + mill.api.ClassLoader.create(urls.toVector, null) } else { - mill.util.ClassLoader.create(urls.toVector, getClass.getClassLoader) + mill.api.ClassLoader.create(urls.toVector, getClass.getClassLoader) } val oldCl = Thread.currentThread().getContextClassLoader diff --git a/main/src/mill/modules/Util.scala b/main/src/mill/modules/Util.scala index 2f57595e..2b98a304 100644 --- a/main/src/mill/modules/Util.scala +++ b/main/src/mill/modules/Util.scala @@ -2,8 +2,9 @@ package mill.modules import coursier.Repository -import mill.eval.PathRef -import mill.util.{Ctx, IO, Loose} +import mill.api.{PathRef, IO} +import mill.util.{Ctx, Loose} + object Util { def cleanupScaladoc(v: String) = { @@ -42,31 +43,9 @@ object Util { val tmpName = if (dest == os.rel / "tmp.zip") "tmp2.zip" else "tmp.zip" val downloaded = download(url, tmpName) - unpackZip(downloaded.path, dest) + IO.unpackZip(downloaded.path, dest) } - def unpackZip(src: os.Path, dest: os.RelPath = "unpacked") - (implicit ctx: Ctx.Dest) = { - - val byteStream = os.read.inputStream(src) - val zipStream = new java.util.zip.ZipInputStream(byteStream) - while({ - zipStream.getNextEntry match{ - case null => false - case entry => - if (!entry.isDirectory) { - val entryDest = ctx.dest / dest / os.RelPath(entry.getName) - os.makeDir.all(entryDest / ammonite.ops.up) - val fileOut = new java.io.FileOutputStream(entryDest.toString) - IO.stream(zipStream, fileOut) - fileOut.close() - } - zipStream.closeEntry() - true - } - })() - PathRef(ctx.dest / dest) - } def millProjectModule(key: String, artifact: String, @@ -75,7 +54,7 @@ object Util { artifactSuffix: String = "_2.12") = { val localPath = sys.props(key) if (localPath != null) { - mill.eval.Result.Success( + mill.api.Result.Success( Loose.Agg.from(localPath.split(',').map(p => PathRef(os.Path(p), quick = true))) ) } else { diff --git a/main/src/mill/package.scala b/main/src/mill/package.scala index 93916c8b..0ccd094f 100644 --- a/main/src/mill/package.scala +++ b/main/src/mill/package.scala @@ -3,8 +3,8 @@ import mill.util.JsonFormatters package object mill extends JsonFormatters{ val T = define.Target type T[T] = define.Target[T] - val PathRef = mill.eval.PathRef - type PathRef = mill.eval.PathRef + val PathRef = mill.api.PathRef + type PathRef = mill.api.PathRef type Module = define.Module type Cross[T] = define.Cross[T] type Agg[T] = util.Loose.Agg[T] -- cgit v1.2.3