Last active
November 23, 2017 07:28
-
-
Save xuwei-k/58b082737d564b4720b850045cf7b5a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// workaround https://github.com/sbt/sbt/issues/3427 | |
import java.io.File | |
import java.util.Optional | |
import xsbti.{AnalysisCallback, Reporter} | |
import xsbti.compile._ | |
val plainScalacCompiler = Def.task { | |
val options = classpathOptions.value | |
sbt.internal.inc.ZincUtil.compilers( | |
instance = Keys.scalaInstance.value, | |
classpathOptions = options, | |
javaHome = None, | |
new ScalaCompiler { | |
override def classpathOptions = options | |
// https://github.com/scala/scala/blob/v2.13.0-M2/src/compiler/scala/tools/nsc/Main.scala | |
// https://github.com/scala/scala/blob/v2.13.0-M2/src/compiler/scala/tools/nsc/Driver.scala#L40 | |
private[this] val mainMethod = { | |
val clazz = scalaInstance.loader.loadClass("scala.tools.nsc.Main") | |
clazz.getMethod("process", classOf[Array[String]]) | |
} | |
private[this] def callScalacMain(args: Array[String]): Boolean = { | |
mainMethod.invoke(null, args).asInstanceOf[Boolean] | |
} | |
override def compile( | |
source: Array[File], | |
changes: DependencyChanges, | |
options: Array[String], | |
output: Output, | |
callback: AnalysisCallback, | |
reporter: Reporter, | |
cache: GlobalsCache, | |
log: xsbti.Logger, | |
progressOpt: Optional[CompileProgress] | |
): Unit = { | |
val dir = output.getSingleOutput.get | |
IO.delete(dir) | |
dir.mkdir | |
val args: Array[String] = options ++ Array("-d", dir.getAbsolutePath) ++ source.map(_.getAbsolutePath) | |
println("=============== args =================") | |
args.foreach(println) | |
println("======================================") | |
callScalacMain(args) | |
} | |
override def compile( | |
source: Array[File], | |
changes: DependencyChanges, | |
callback: AnalysisCallback, | |
log: xsbti.Logger, | |
reporter: Reporter, | |
progress: CompileProgress, | |
compiler: CachedCompiler | |
): Unit = { | |
??? | |
} | |
override def scalaInstance = | |
Keys.scalaInstance.value | |
} | |
) | |
} | |
compilers in ThisBuild := { | |
val scalac = plainScalacCompiler.value | |
val default = compilers.value | |
if (scalaVersion.value == "2.13.0-M2") { | |
scalac | |
} else { | |
default | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment