diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-12-12 22:15:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-12 22:15:38 +0800 |
commit | ea7fceb6e56f53bde3517586dfc57e10a605a524 (patch) | |
tree | cf2e4b7a403f8bcbcf3d1c4c45a8abd315cbefe6 /scalalib/worker | |
parent | d0e1b572e88d311e1aee23d92e0384a81de4bcb6 (diff) | |
download | mill-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 'scalalib/worker')
-rw-r--r-- | scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala index d494760e..705d4682 100644 --- a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala +++ b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala @@ -3,18 +3,14 @@ package mill.scalalib.worker import java.io.File import java.util.Optional -import ammonite.util.Colors -import mill.Agg -import mill.eval.PathRef -import mill.scalalib.{CompilationResult, Lib, TestRunner} +import mill.api.Loose.Agg +import mill.api.PathRef import xsbti.compile.{CompilerCache => _, FileAnalysisStore => _, ScalaInstance => _, _} -import mill.scalalib.Dep.isDotty -import mill.scalalib.Lib.{grepJar, scalaBinaryVersion} -import mill.util.{Ctx, PrintLogger} +import mill.scalalib.api.Util.{isDotty, grepJar, scalaBinaryVersion} import sbt.internal.inc._ import sbt.internal.util.{ConsoleOut, MainAppender} import sbt.util.LogExchange - +import mill.scalalib.api.CompilationResult case class MockedLookup(am: File => Optional[CompileAnalysis]) extends PerClasspathEntryLookup { override def analysis(classpathEntry: File): Optional[CompileAnalysis] = am(classpathEntry) @@ -23,8 +19,8 @@ case class MockedLookup(am: File => Optional[CompileAnalysis]) extends PerClassp Locate.definesClass(classpathEntry) } -class ZincWorkerImpl(ctx0: mill.util.Ctx, - compilerBridgeClasspath: Array[String]) extends mill.scalalib.ZincWorkerApi{ +class ZincWorkerImpl(ctx0: mill.api.Ctx, + compilerBridgeClasspath: Array[String]) extends mill.scalalib.api.ZincWorkerApi{ private val ic = new sbt.internal.inc.IncrementalCompilerImpl() val javaOnlyCompilers = { // Keep the classpath as written by the user @@ -53,7 +49,7 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, compilerClasspath: Agg[os.Path], scalacPluginClasspath: Agg[os.Path], args: Seq[String]) - (implicit ctx: mill.util.Ctx): Boolean = { + (implicit ctx: mill.api.Ctx): Boolean = { val compilers: Compilers = prepareCompilers( scalaVersion, compilerBridgeSources, @@ -79,8 +75,8 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, os.makeDir.all(workingDir) os.makeDir.all(compiledDest) - val sourceFolder = mill.modules.Util.unpackZip(sourcesJar)(workingDir) - val classloader = mill.util.ClassLoader.create(compilerJars.map(_.toURI.toURL), null)(ctx0) + val sourceFolder = mill.api.IO.unpackZip(sourcesJar)(workingDir) + val classloader = mill.api.ClassLoader.create(compilerJars.map(_.toURI.toURL), null)(ctx0) val compilerMain = classloader.loadClass( if (isDotty(scalaVersion)) "dotty.tools.dotc.Main" @@ -100,7 +96,7 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, - def discoverMainClasses(compilationResult: CompilationResult)(implicit ctx: mill.util.Ctx): Seq[String] = { + def discoverMainClasses(compilationResult: CompilationResult)(implicit ctx: mill.api.Ctx): Seq[String] = { def toScala[A](o: Optional[A]): Option[A] = if (o.isPresent) Some(o.get) else None toScala(FileAnalysisStore.binary(compilationResult.analysisFile.toIO).get()) @@ -118,7 +114,7 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, sources: Agg[os.Path], compileClasspath: Agg[os.Path], javacOptions: Seq[String]) - (implicit ctx: mill.util.Ctx): mill.eval.Result[CompilationResult] = { + (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = { compileInternal( upstreamCompileOutput, sources, @@ -138,7 +134,7 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, compilerBridgeSources: os.Path, compilerClasspath: Agg[os.Path], scalacPluginClasspath: Agg[os.Path]) - (implicit ctx: mill.util.Ctx): mill.eval.Result[CompilationResult] = { + (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = { val compilers: Compilers = prepareCompilers( scalaVersion, compilerBridgeSources, @@ -160,7 +156,7 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, compilerBridgeSources: os.Path, compilerClasspath: Agg[os.Path], scalacPluginClasspath: Agg[os.Path]) - (implicit ctx: mill.util.Ctx)= { + (implicit ctx: mill.api.Ctx)= { val combinedCompilerClasspath = compilerClasspath ++ scalacPluginClasspath val combinedCompilerJars = combinedCompilerClasspath.toArray.map(_.toIO) @@ -185,7 +181,7 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, "scala-compiler" val scalaInstance = new ScalaInstance( version = scalaVersion, - loader = mill.util.ClassLoader.create(combinedCompilerJars.map(_.toURI.toURL), null), + loader = mill.api.ClassLoader.create(combinedCompilerJars.map(_.toURI.toURL), null), libraryJar = grepJar(compilerClasspath, "scala-library", scalaVersion).toIO, compilerJar = grepJar(compilerClasspath, compilerName, scalaVersion).toIO, allJars = combinedCompilerJars, @@ -209,7 +205,7 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, javacOptions: Seq[String], scalacOptions: Seq[String], compilers: Compilers) - (implicit ctx: mill.util.Ctx): mill.eval.Result[CompilationResult] = { + (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = { os.makeDir.all(ctx.dest) val logger = { @@ -282,7 +278,7 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx, ) ) - mill.eval.Result.Success(CompilationResult(zincFile, PathRef(classesDir))) - }catch{case e: CompileFailed => mill.eval.Result.Failure(e.toString)} + mill.api.Result.Success(CompilationResult(zincFile, PathRef(classesDir))) + }catch{case e: CompileFailed => mill.api.Result.Failure(e.toString)} } } |