From a861ea9dd39ab3c4cc74ec3e1cf73355219d1836 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 8 Nov 2017 20:01:25 -0800 Subject: Swap `compileScala` over to `T{...}` macro --- .../main/scala/forge/scalaplugin/Subproject.scala | 131 ++++++++++----------- 1 file changed, 64 insertions(+), 67 deletions(-) (limited to 'scalaplugin') 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()) } -- cgit v1.2.3