summaryrefslogtreecommitdiff
path: root/scalalib/worker/src
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2018-08-05 23:23:12 +0900
committerLi Haoyi <haoyi.sg@gmail.com>2018-08-05 22:23:12 +0800
commitb9824967392e4b674881e5dcec4c4fbb05e6cd9b (patch)
tree40c67dff4ffb26f085ef52b1ec3e2341f33d27be /scalalib/worker/src
parent66c133a2ff58823c43ddfa7643fb74b8cf2bd0a6 (diff)
downloadmill-b9824967392e4b674881e5dcec4c4fbb05e6cd9b.tar.gz
mill-b9824967392e4b674881e5dcec4c4fbb05e6cd9b.tar.bz2
mill-b9824967392e4b674881e5dcec4c4fbb05e6cd9b.zip
Add support for Dotty projects (#397)
* Abstract over the scala compiler organization * Support using a locally published compiler Publishing locally with sbt means publishing ivy-style, which uses a different naming convention than maven, we now handle both cases. * Add minimal support for Dotty projects * Rewrite scalalib.Dep, introduce scalalib.CrossVersion Instead of Dep being a trait with three cases (Java/Scala/Point), it is now a case class where the cross field is an instance of the CrossVersion trait which has three cases (Constant/Binary/Full). This is more versatile since it allows for non-empty constant suffixes which will be used to implement withDottyCompat in the next commit. It's also a cleaner separation of concerns. We also deduplicate various pieces of codes that computed the artifact name: this is now always handled in Dep and CrossVersion. * Add simple way to use Scala 2 deps in a Dotty project This is similar to the withDottyCompat method in the sbt-dotty plugin. * Turn off the Dotty test on Java >= 9
Diffstat (limited to 'scalalib/worker/src')
-rw-r--r--scalalib/worker/src/mill/scalalib/worker/ScalaWorker.scala23
1 files changed, 16 insertions, 7 deletions
diff --git a/scalalib/worker/src/mill/scalalib/worker/ScalaWorker.scala b/scalalib/worker/src/mill/scalalib/worker/ScalaWorker.scala
index 76f185c5..98b40889 100644
--- a/scalalib/worker/src/mill/scalalib/worker/ScalaWorker.scala
+++ b/scalalib/worker/src/mill/scalalib/worker/ScalaWorker.scala
@@ -9,7 +9,8 @@ import mill.Agg
import mill.eval.PathRef
import mill.scalalib.{CompilationResult, Lib, TestRunner}
import xsbti.compile.{CompilerCache => _, FileAnalysisStore => _, ScalaInstance => _, _}
-import mill.scalalib.Lib.grepJar
+import mill.scalalib.Dep.isDotty
+import mill.scalalib.Lib.{grepJar, scalaBinaryVersion}
import mill.util.{Ctx, PrintLogger}
import sbt.internal.inc._
import sbt.internal.util.{ConsoleOut, MainAppender}
@@ -44,15 +45,18 @@ class ScalaWorker(ctx0: mill.util.Ctx,
val sourceFolder = mill.modules.Util.unpackZip(sourcesJar)(workingDir)
val classloader = mill.util.ClassLoader.create(compilerJars.map(_.toURI.toURL), null)(ctx0)
- val scalacMain = classloader.loadClass("scala.tools.nsc.Main")
+ val compilerMain = classloader.loadClass(
+ if (isDotty(scalaVersion))
+ "dotty.tools.dotc.Main"
+ else
+ "scala.tools.nsc.Main"
+ )
val argsArray = Array[String](
"-d", compiledDest.toString,
"-classpath", (compilerJars ++ compilerBridgeClasspath).mkString(File.pathSeparator)
) ++ ls.rec(sourceFolder.path).filter(_.ext == "scala").map(_.toString)
- scalacMain.getMethods
- .find(_.getName == "process")
- .get
+ compilerMain.getMethod("process", classOf[Array[String]])
.invoke(null, argsArray)
}
compiledDest
@@ -97,11 +101,16 @@ class ScalaWorker(ctx0: mill.util.Ctx,
val compilers = compilersCache match {
case Some((k, v)) if k == compilersSig => v
case _ =>
+ val compilerName =
+ if (isDotty(scalaVersion))
+ s"dotty-compiler_${scalaBinaryVersion(scalaVersion)}"
+ else
+ "scala-compiler"
val scalaInstance = new ScalaInstance(
version = scalaVersion,
loader = mill.util.ClassLoader.create(compilerJars.map(_.toURI.toURL), null),
- libraryJar = grepJar(compilerClasspath, s"scala-library-$scalaVersion.jar"),
- compilerJar = grepJar(compilerClasspath, s"scala-compiler-$scalaVersion.jar"),
+ libraryJar = grepJar(compilerClasspath, "scala-library", scalaVersion).toIO,
+ compilerJar = grepJar(compilerClasspath, compilerName, scalaVersion).toIO,
allJars = compilerJars,
explicitActual = None
)