summaryrefslogtreecommitdiff
path: root/scalaplugin
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-08 20:01:25 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-08 20:01:25 -0800
commita861ea9dd39ab3c4cc74ec3e1cf73355219d1836 (patch)
tree1a4c653ca18b070e0ffe47e5bd9abeab4da70dc7 /scalaplugin
parent2e62950a2c11793547a58c0e9b769baa30f42697 (diff)
downloadmill-a861ea9dd39ab3c4cc74ec3e1cf73355219d1836.tar.gz
mill-a861ea9dd39ab3c4cc74ec3e1cf73355219d1836.tar.bz2
mill-a861ea9dd39ab3c4cc74ec3e1cf73355219d1836.zip
Swap `compileScala` over to `T{...}` macro
Diffstat (limited to 'scalaplugin')
-rw-r--r--scalaplugin/src/main/scala/forge/scalaplugin/Subproject.scala131
1 files changed, 64 insertions, 67 deletions
diff --git a/scalaplugin/src/main/scala/forge/scalaplugin/Subproject.scala b/scalaplugin/src/main/scala/forge/scalaplugin/Subproject.scala
index b3dca832..eb71203e 100644
--- a/scalaplugin/src/main/scala/forge/scalaplugin/Subproject.scala
+++ b/scalaplugin/src/main/scala/forge/scalaplugin/Subproject.scala
@@ -17,73 +17,70 @@ import xsbti.compile.DependencyChanges
import scalaz.concurrent.Task
object Subproject{
- def compileScala(scalaVersion: T[String],
- sources: T[PathRef],
- compileClasspath: T[Seq[PathRef]],
- outputPath: T[Path]): T[PathRef] = {
- for((scalaVersion, sources, compileClasspath, outputPath) <- T.zip(scalaVersion, sources, compileClasspath, outputPath))
- yield {
- val binaryScalaVersion = scalaVersion.split('.').dropRight(1).mkString(".")
- def grepJar(s: String) = {
- compileClasspath
- .find(_.path.toString.endsWith(s))
- .getOrElse(throw new Exception("Cannot find " + s))
- .path
- .toIO
- }
- val scalac = ZincUtil.scalaCompiler(
- new ScalaInstance(
- version = scalaVersion,
- loader = getClass.getClassLoader,
- libraryJar = grepJar(s"scala-library-$scalaVersion.jar"),
- compilerJar = grepJar(s"scala-compiler-$scalaVersion.jar"),
- allJars = compileClasspath.toArray.map(_.path.toIO),
- explicitActual = None
- ),
- grepJar(s"compiler-bridge_$binaryScalaVersion-1.0.3.jar")
- )
-
- mkdir(outputPath)
-
-
- scalac.apply(
- sources = ls.rec(sources.path).filter(_.isFile).map(_.toIO).toArray,
- changes = new DependencyChanges {
- def isEmpty = true
- def modifiedBinaries() = Array[File]()
- def modifiedClasses() = Array[String]()
- },
- classpath = compileClasspath.map(_.path.toIO).toArray,
- singleOutput = outputPath.toIO,
- options = Array(),
- callback = new xsbti.AnalysisCallback {
- def startSource(source: File) = ()
- def apiPhaseCompleted() = ()
- def enabled() = true
- def binaryDependency(onBinaryEntry: File, onBinaryClassName: String, fromClassName: String, fromSourceFile: File, context: DependencyContext) = ()
- def generatedNonLocalClass(source: File, classFile: File, binaryClassName: String, srcClassName: String) = ()
- def problem(what: String, pos: xsbti.Position, msg: String, severity: xsbti.Severity, reported: Boolean) = ()
- def dependencyPhaseCompleted() = ()
- def classDependency(onClassName: String, sourceClassName: String, context: DependencyContext) = ()
- def generatedLocalClass(source: File, classFile: File) = ()
- def api(sourceFile: File, classApi: ClassLike) = ()
-
- def mainClass(sourceFile: File, className: String) = ()
- def usedName(className: String, name: String, useScopes: java.util.EnumSet[xsbti.UseScope]) = ()
- },
- maximumErrors = 10,
- cache = new FreshCompilerCache(),
- log = {
- val console = ConsoleOut.systemOut
- val consoleAppender = MainAppender.defaultScreen(console)
- val l = LogExchange.logger("Hello")
- LogExchange.unbindLoggerAppenders("Hello")
- LogExchange.bindLoggerAppenders("Hello", (consoleAppender -> sbt.util.Level.Warn) :: Nil)
- l
- }
- )
- PathRef(outputPath)
+ def compileScala(scalaVersion: String,
+ sources: PathRef,
+ compileClasspath: Seq[PathRef],
+ outputPath: Path): PathRef = {
+ val binaryScalaVersion = scalaVersion.split('.').dropRight(1).mkString(".")
+ def grepJar(s: String) = {
+ compileClasspath
+ .find(_.path.toString.endsWith(s))
+ .getOrElse(throw new Exception("Cannot find " + s))
+ .path
+ .toIO
}
+ val scalac = ZincUtil.scalaCompiler(
+ new ScalaInstance(
+ version = scalaVersion,
+ loader = getClass.getClassLoader,
+ libraryJar = grepJar(s"scala-library-$scalaVersion.jar"),
+ compilerJar = grepJar(s"scala-compiler-$scalaVersion.jar"),
+ allJars = compileClasspath.toArray.map(_.path.toIO),
+ explicitActual = None
+ ),
+ grepJar(s"compiler-bridge_$binaryScalaVersion-1.0.3.jar")
+ )
+
+ mkdir(outputPath)
+
+
+ scalac.apply(
+ sources = ls.rec(sources.path).filter(_.isFile).map(_.toIO).toArray,
+ changes = new DependencyChanges {
+ def isEmpty = true
+ def modifiedBinaries() = Array[File]()
+ def modifiedClasses() = Array[String]()
+ },
+ classpath = compileClasspath.map(_.path.toIO).toArray,
+ singleOutput = outputPath.toIO,
+ options = Array(),
+ callback = new xsbti.AnalysisCallback {
+ def startSource(source: File) = ()
+ def apiPhaseCompleted() = ()
+ def enabled() = true
+ def binaryDependency(onBinaryEntry: File, onBinaryClassName: String, fromClassName: String, fromSourceFile: File, context: DependencyContext) = ()
+ def generatedNonLocalClass(source: File, classFile: File, binaryClassName: String, srcClassName: String) = ()
+ def problem(what: String, pos: xsbti.Position, msg: String, severity: xsbti.Severity, reported: Boolean) = ()
+ def dependencyPhaseCompleted() = ()
+ def classDependency(onClassName: String, sourceClassName: String, context: DependencyContext) = ()
+ def generatedLocalClass(source: File, classFile: File) = ()
+ def api(sourceFile: File, classApi: ClassLike) = ()
+
+ def mainClass(sourceFile: File, className: String) = ()
+ def usedName(className: String, name: String, useScopes: java.util.EnumSet[xsbti.UseScope]) = ()
+ },
+ maximumErrors = 10,
+ cache = new FreshCompilerCache(),
+ log = {
+ val console = ConsoleOut.systemOut
+ val consoleAppender = MainAppender.defaultScreen(console)
+ val l = LogExchange.logger("Hello")
+ LogExchange.unbindLoggerAppenders("Hello")
+ LogExchange.bindLoggerAppenders("Hello", (consoleAppender -> sbt.util.Level.Warn) :: Nil)
+ l
+ }
+ )
+ PathRef(outputPath)
}
def resolveDependencies(repositories: Seq[Repository],
@@ -182,7 +179,7 @@ abstract class Subproject extends Cacher{
def resources = T{ PathRef(basePath() / 'resources) }
def compiledPath = T{ outputPath() / 'classpath }
def compiled = T{
- compileScala(scalaVersion, sources, compileDepClasspath, outputPath)
+ compileScala(scalaVersion(), sources(), compileDepClasspath(), outputPath())
}
def classpath = T{ Seq(resources(), compiled()) }