Skip to content

Commit

Permalink
Fix #475
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Nov 2, 2018
1 parent c948427 commit 189f950
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
10 changes: 8 additions & 2 deletions scalalib/src/mill/scalalib/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,21 @@ 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 ++
scalaDocOptions()

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")
}
Expand Down
7 changes: 6 additions & 1 deletion scalalib/src/mill/scalalib/ZincWorkerApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
51 changes: 39 additions & 12 deletions scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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],
Expand Down

0 comments on commit 189f950

Please sign in to comment.