From 422d41498d43ad9b437b2d4460f61849e78bb6fa Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Mon, 4 Dec 2017 21:55:01 -0800 Subject: - Make `T.ctx()` available implicitly - Convert `ScalaModule.{compile,assembly}` to use the new implicit `T.ctx()` - Add a `log: PrintStream` to the `T.ctx()`, in preparation for per-task logging --- .../main/scala/mill/scalaplugin/ScalaModule.scala | 28 ++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'scalaplugin') diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala index 3d194190..e25d13de 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala @@ -13,6 +13,7 @@ import mill.define.Task.{Module, TaskModule} import mill.eval.{PathRef, Result} import mill.modules.Jvm import mill.modules.Jvm.{createAssembly, createJar, subprocess} +import mill.util.Ctx import sbt.internal.inc._ import sbt.internal.util.{ConsoleOut, MainAppender} import sbt.util.{InterfaceUtil, LogExchange} @@ -39,10 +40,10 @@ object ScalaModule{ compilerClasspath: Seq[Path], compilerBridge: Seq[Path], scalacOptions: Seq[String], - javacOptions: Seq[String], - outputPath: Path): PathRef = { + javacOptions: Seq[String]) + (implicit ctx: Ctx): PathRef = { val compileClasspathFiles = compileClasspath.map(_.toIO).toArray - val binaryScalaVersion = scalaVersion.split('.').dropRight(1).mkString(".") + def grepJar(classPath: Seq[Path], s: String) = { classPath .find(_.toString.endsWith(s)) @@ -79,13 +80,13 @@ object ScalaModule{ val scalac = ZincUtil.scalaCompiler(scalaInstance, compilerBridgeJar) - mkdir(outputPath) + mkdir(ctx.dest) val ic = new sbt.internal.inc.IncrementalCompilerImpl() val logger = { - val console = ConsoleOut.systemOut - val consoleAppender = MainAppender.defaultScreen(console) + + val consoleAppender = MainAppender.defaultScreen(ConsoleOut.printStreamOut(ctx.log)) val l = LogExchange.logger("Hello") LogExchange.unbindLoggerAppenders("Hello") LogExchange.bindLoggerAppenders("Hello", (consoleAppender -> sbt.util.Level.Info) :: Nil) @@ -105,9 +106,9 @@ object ScalaModule{ override def startUnit(phase: String, unitPath: String): Unit = () } - val zincFile = (outputPath/'zinc).toIO + val zincFile = (ctx.dest/'zinc).toIO val store = FileAnalysisStore.binary(zincFile) - val classesDir = (outputPath / 'classes).toIO + val classesDir = (ctx.dest / 'classes).toIO val newResult = ic.compile( ic.inputs( classpath = classesDir +: compileClasspathFiles, @@ -147,7 +148,7 @@ object ScalaModule{ ) ) - PathRef(outputPath/'classes) + PathRef(ctx.dest/'classes) } def resolveDependencies(repositories: Seq[Repository], @@ -344,18 +345,15 @@ trait ScalaModule extends Module with TaskModule{ outer => scalaCompilerClasspath().map(_.path), compilerBridgeClasspath().map(_.path), scalacOptions(), - javacOptions(), - T.ctx().dest + javacOptions() ) } def assembly = T{ - val dest = T.ctx().dest createAssembly( - dest, - (runDepClasspath().filter(_.path.ext != "pom") ++ Seq(resources(), compile())).map(_.path).filter(exists), + (runDepClasspath().filter(_.path.ext != "pom") ++ + Seq(resources(), compile())).map(_.path).filter(exists), prependShellScript = prependShellScript() ) - PathRef(dest) } def classpath = T{ Seq(resources(), compile()) } -- cgit v1.2.3