From 0cc3cfb36444e1efda7c4b5661f8a7ef95fcd7da Mon Sep 17 00:00:00 2001 From: jvican Date: Fri, 14 Jul 2017 14:32:53 +0200 Subject: [PATCH 1/3] Synchronize with changes to Zinc logger API https://github.com/sbt/zinc/pull/325 --- main/src/main/scala/sbt/Defaults.scala | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index d29dd3858..db214bc33 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -101,7 +101,7 @@ import sbt.internal.inc.{ Analysis, FileValueCache, Locate, - LoggerReporter, + ManagedLoggedReporter, MixedAnalyzingCompiler, ScalaInstance } @@ -1435,9 +1435,13 @@ object Defaults extends BuildCommon { f1(foldMappers(sourcePositionMappers.value)), compileOrder.value ), - compilerReporter := new LoggerReporter(maxErrors.value, - streams.value.log, - foldMappers(sourcePositionMappers.value)), + compilerReporter := { + new ManagedLoggedReporter( + maxErrors.value, + streams.value.log, + foldMappers(sourcePositionMappers.value) + ) + }, compileInputs := new Inputs( compilers.value, compileOptions.value, @@ -1477,10 +1481,8 @@ object Defaults extends BuildCommon { val problems = analysis.infos.allInfos.values.flatMap(i => i.getReportedProblems ++ i.getUnreportedProblems) - val reporter = new LoggerReporter(max, streams.value.log, foldMappers(spms)) - problems foreach { p => - reporter.display(p) - } + val reporter = new ManagedLoggedReporter(max, streams.value.log, foldMappers(spms)) + problems.foreach(p => reporter.log(p)) } def sbtPluginExtra(m: ModuleID, sbtV: String, scalaV: String): ModuleID = From 32d8f4724842aed85e310543c3a745c3900caee3 Mon Sep 17 00:00:00 2001 From: jvican Date: Sat, 15 Jul 2017 09:46:55 +0200 Subject: [PATCH 2/3] Add setting to switch to text analysis As per suggestions in https://github.com/sbt/zinc/pull/351. --- main/src/main/scala/sbt/Defaults.scala | 11 ++++++++--- main/src/main/scala/sbt/Keys.scala | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index db214bc33..c2a9926d9 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -492,8 +492,11 @@ object Defaults extends BuildCommon { } } + def defaultCompileSettings: Seq[Setting[_]] = + globalDefaults(enableBinaryCompileAnalysis := true) + lazy val configTasks: Seq[Setting[_]] = docTaskSettings(doc) ++ inTask(compile)( - compileInputsSettings) ++ configGlobal ++ compileAnalysisSettings ++ Seq( + compileInputsSettings) ++ configGlobal ++ defaultCompileSettings ++ compileAnalysisSettings ++ Seq( compile := compileTask.value, manipulateBytecode := compileIncremental.value, compileIncremental := (compileIncrementalTask tag (Tags.Compile, Tags.CPU)).value, @@ -1369,10 +1372,11 @@ object Defaults extends BuildCommon { def compileTask: Initialize[Task[CompileAnalysis]] = Def.task { val setup: Setup = compileIncSetup.value + val useBinary: Boolean = enableBinaryCompileAnalysis.value // TODO - expose bytecode manipulation phase. val analysisResult: CompileResult = manipulateBytecode.value if (analysisResult.hasModified) { - val store = MixedAnalyzingCompiler.staticCachedStore(setup.cacheFile) + val store = MixedAnalyzingCompiler.staticCachedStore(setup.cacheFile, !enableBinaryCompileAnalysis) store.set(analysisResult.analysis, analysisResult.setup) } analysisResult.analysis @@ -1464,7 +1468,8 @@ object Defaults extends BuildCommon { def compileAnalysisSettings: Seq[Setting[_]] = Seq( previousCompile := { val setup = compileIncSetup.value - val store = MixedAnalyzingCompiler.staticCachedStore(setup.cacheFile) + val useBinary: Boolean = enableBinaryCompileAnalysis.value + val store = MixedAnalyzingCompiler.staticCachedStore(setup.cacheFile, !useBinary) store.get() match { case Some((an, setup)) => new PreviousResult(Option(an).toOptional, Option(setup).toOptional) diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index a492a72d4..1f196f269 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -208,6 +208,7 @@ object Keys { val fileInputOptions = SettingKey[Seq[String]]("file-input-options", "Options that take file input, which may invalidate the cache.", CSetting) val scalaCompilerBridgeSource = SettingKey[ModuleID]("scala-compiler-bridge-source", "Configures the module ID of the sources of the compiler bridge.", CSetting) val scalaArtifacts = SettingKey[Seq[String]]("scala-artifacts", "Configures the list of artifacts which should match the Scala binary version", CSetting) + val enableBinaryCompileAnalysis = SettingKey[Boolean]("binary-analysis", "Writes the analysis file in binary format") val clean = TaskKey[Unit]("clean", "Deletes files produced by the build, such as generated sources, compiled classes, and task caches.", APlusTask) val console = TaskKey[Unit]("console", "Starts the Scala interpreter with the project classes on the classpath.", APlusTask) From 2da90fee035b990f47f3420fe2e1db75201a213a Mon Sep 17 00:00:00 2001 From: jvican Date: Sat, 15 Jul 2017 10:08:08 +0200 Subject: [PATCH 3/3] Sync up with changes to `AnalysisContents` --- main/src/main/scala/sbt/Defaults.scala | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index c2a9926d9..06f1ebc20 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -74,7 +74,7 @@ import Scope.{ fillTaskAxis, GlobalScope, ThisScope } import sjsonnew.{ IsoLList, JsonFormat, LList, LNil }, LList.:*: import std.TaskExtra._ import testing.{ Framework, Runner, AnnotatedFingerprint, SubclassFingerprint } -import xsbti.compile.IncToolOptionsUtil +import xsbti.compile.{ IncToolOptionsUtil, AnalysisContents } import xsbti.CrossValue // incremental compiler @@ -1376,8 +1376,10 @@ object Defaults extends BuildCommon { // TODO - expose bytecode manipulation phase. val analysisResult: CompileResult = manipulateBytecode.value if (analysisResult.hasModified) { - val store = MixedAnalyzingCompiler.staticCachedStore(setup.cacheFile, !enableBinaryCompileAnalysis) - store.set(analysisResult.analysis, analysisResult.setup) + val store = + MixedAnalyzingCompiler.staticCachedStore(setup.cacheFile, !useBinary) + val contents = AnalysisContents.create(analysisResult.analysis(), analysisResult.setup()) + store.set(contents) } analysisResult.analysis } @@ -1470,9 +1472,11 @@ object Defaults extends BuildCommon { val setup = compileIncSetup.value val useBinary: Boolean = enableBinaryCompileAnalysis.value val store = MixedAnalyzingCompiler.staticCachedStore(setup.cacheFile, !useBinary) - store.get() match { - case Some((an, setup)) => - new PreviousResult(Option(an).toOptional, Option(setup).toOptional) + store.get().toOption match { + case Some(contents) => + val analysis = Option(contents.getAnalysis).toOptional + val setup = Option(contents.getMiniSetup).toOptional + new PreviousResult(analysis, setup) case None => new PreviousResult(jnone[CompileAnalysis], jnone[MiniSetup]) } }