summaryrefslogtreecommitdiff
path: root/scalalib
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-11-02 10:53:45 +0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-11-02 11:54:27 +0800
commit189f950d5ad3634a38652aac320c4fa103ea6100 (patch)
treee43d73df758bc9f75b1fdd5658461517e7b132c8 /scalalib
parentc948427e2c11b412ab7121c4c2804105cde711ae (diff)
downloadmill-189f950d5ad3634a38652aac320c4fa103ea6100.tar.gz
mill-189f950d5ad3634a38652aac320c4fa103ea6100.tar.bz2
mill-189f950d5ad3634a38652aac320c4fa103ea6100.zip
Fix https://github.com/lihaoyi/mill/issues/475
Diffstat (limited to 'scalalib')
-rw-r--r--scalalib/src/mill/scalalib/ScalaModule.scala10
-rw-r--r--scalalib/src/mill/scalalib/ZincWorkerApi.scala7
-rw-r--r--scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala51
3 files changed, 53 insertions, 15 deletions
diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala
index 35dc67d7..3c058013 100644
--- a/scalalib/src/mill/scalalib/ScalaModule.scala
+++ b/scalalib/src/mill/scalalib/ScalaModule.scala
@@ -178,7 +178,7 @@ trait ScalaModule extends JavaModule { outer =>
val pluginOptions = scalaDocPluginClasspath().map(pluginPathRef => s"-Xplugin:${pluginPathRef.path}")
val compileCp = compileClasspath().filter(_.path.ext != "pom").map(_.path)
val options = Seq(
- "-d", javadocDir.toNIO.toString, "-usejavacp",
+ "-d", javadocDir.toNIO.toString,
"-classpath", compileCp.mkString(":")
) ++
pluginOptions ++
@@ -186,7 +186,13 @@ trait ScalaModule extends JavaModule { outer =>
if (files.isEmpty) Result.Success(createJar(Agg(javadocDir))(outDir))
else {
- zincWorker.worker().docJar(files ++ options) match{
+ zincWorker.worker().docJar(
+ scalaVersion(),
+ scalaCompilerBridgeSources(),
+ scalaCompilerClasspath().map(_.path),
+ scalacPluginClasspath().map(_.path),
+ files ++ options
+ ) match{
case true => Result.Success(createJar(Agg(javadocDir))(outDir))
case false => Result.Failure("docJar generation failed")
}
diff --git a/scalalib/src/mill/scalalib/ZincWorkerApi.scala b/scalalib/src/mill/scalalib/ZincWorkerApi.scala
index c05ac62f..8e95eb29 100644
--- a/scalalib/src/mill/scalalib/ZincWorkerApi.scala
+++ b/scalalib/src/mill/scalalib/ZincWorkerApi.scala
@@ -80,5 +80,10 @@ trait ZincWorkerApi {
def discoverMainClasses(compilationResult: CompilationResult)
(implicit ctx: mill.util.Ctx): Seq[String]
- def docJar(args: Seq[String]): Boolean
+ def docJar(scalaVersion: String,
+ compilerBridgeSources: Path,
+ compilerClasspath: Agg[Path],
+ scalacPluginClasspath: Agg[Path],
+ args: Seq[String])
+ (implicit ctx: mill.util.Ctx): Boolean
}
diff --git a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala
index 8a3a3b02..78595b14 100644
--- a/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala
+++ b/scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala
@@ -49,8 +49,21 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx,
@volatile var mixedCompilersCache = Option.empty[(Long, Compilers)]
- def docJar(args: Seq[String]): Boolean = {
- new scala.tools.nsc.ScalaDoc().process(args.toArray)
+ def docJar(scalaVersion: String,
+ compilerBridgeSources: Path,
+ compilerClasspath: Agg[Path],
+ scalacPluginClasspath: Agg[Path],
+ args: Seq[String])
+ (implicit ctx: mill.util.Ctx): Boolean = {
+ val compilers: Compilers = prepareCompilers(
+ scalaVersion,
+ compilerBridgeSources,
+ compilerClasspath,
+ scalacPluginClasspath
+ )
+ val scaladocClass = compilers.scalac().scalaInstance().loader().loadClass("scala.tools.nsc.ScalaDoc")
+ val scaladocMethod = scaladocClass.getMethod("process", classOf[Array[String]])
+ scaladocMethod.invoke(scaladocClass.newInstance(), args.toArray).asInstanceOf[Boolean]
}
/** Compile the bridge if it doesn't exist yet and return the output directory.
* TODO: Proper invalidation, see #389
@@ -127,6 +140,28 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx,
compilerClasspath: Agg[Path],
scalacPluginClasspath: Agg[Path])
(implicit ctx: mill.util.Ctx): mill.eval.Result[CompilationResult] = {
+ val compilers: Compilers = prepareCompilers(
+ scalaVersion,
+ compilerBridgeSources,
+ compilerClasspath,
+ scalacPluginClasspath
+ )
+
+ compileInternal(
+ upstreamCompileOutput,
+ sources,
+ compileClasspath,
+ javacOptions,
+ scalacOptions = scalacPluginClasspath.map(jar => s"-Xplugin:${jar}").toSeq ++ scalacOptions,
+ compilers
+ )
+ }
+
+ private def prepareCompilers(scalaVersion: String,
+ compilerBridgeSources: Path,
+ compilerClasspath: Agg[Path],
+ scalacPluginClasspath: Agg[Path])
+ (implicit ctx: mill.util.Ctx)= {
val combinedCompilerClasspath = compilerClasspath ++ scalacPluginClasspath
val combinedCompilerJars = combinedCompilerClasspath.toArray.map(_.toIO)
@@ -139,7 +174,7 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx,
val compilersSig =
compilerBridgeSig +
- combinedCompilerClasspath.map(p => p.toString().hashCode + p.mtime.toMillis).sum
+ combinedCompilerClasspath.map(p => p.toString().hashCode + p.mtime.toMillis).sum
val compilers = mixedCompilersCache match {
case Some((k, v)) if k == compilersSig => v
@@ -166,15 +201,7 @@ class ZincWorkerImpl(ctx0: mill.util.Ctx,
mixedCompilersCache = Some((compilersSig, compilers))
compilers
}
-
- compileInternal(
- upstreamCompileOutput,
- sources,
- compileClasspath,
- javacOptions,
- scalacOptions = scalacPluginClasspath.map(jar => s"-Xplugin:${jar}").toSeq ++ scalacOptions,
- compilers
- )
+ compilers
}
private def compileInternal(upstreamCompileOutput: Seq[CompilationResult],