From f885458f370beee0ec3fcc9dfe0a0a1ea228563b Mon Sep 17 00:00:00 2001 From: Grzegorz Kossakowski Date: Tue, 19 Feb 2013 15:55:54 -0800 Subject: [PATCH] Do not minimize APIs if API debugging option is enabled. That's foundation for API dumping and tests based on API representation contents. Specific list of changes introduced by this commit: * `AnalysisCallback` class takes `IncOptions` as argument so it can determine if API should be minimized in `api` callback. * Introduce `Incremental.apiDebug` method that determines if api debugging is enabled. There are two ways to enable api debugging: through system property and through incremental compiler options. The system property method will be soon deprecated. We introduce it to make it easier to enable API debugging until tools (like zinc and ide) catch up with making incremental compiler configurable. NOTE: The `apiDebug` method has been introduced in Incremental for two reasons: 1. It's analogous to `incDebug` method that's already there. 2. In other branch I need `apiDebug` to be defined in Incremental. Once we deprecate and remove enabling debugging options through system properties the code will be cleaned up. --- compile/inc/src/main/scala/sbt/inc/Compile.scala | 13 ++++++++----- .../inc/src/main/scala/sbt/inc/Incremental.scala | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/compile/inc/src/main/scala/sbt/inc/Compile.scala b/compile/inc/src/main/scala/sbt/inc/Compile.scala index bba027cdc..33da13bb0 100644 --- a/compile/inc/src/main/scala/sbt/inc/Compile.scala +++ b/compile/inc/src/main/scala/sbt/inc/Compile.scala @@ -22,10 +22,11 @@ object IncrementalCompile val current = Stamps.initial(Stamp.exists, Stamp.hash, Stamp.lastModified) val internalMap = (f: File) => previous.relations.produced(f).headOption val externalAPI = getExternalAPI(entry, forEntry) - Incremental.compile(sources, entry, previous, current, forEntry, doCompile(compile, internalMap, externalAPI, current, output), log, options) + Incremental.compile(sources, entry, previous, current, forEntry, doCompile(compile, internalMap, externalAPI, current, output, options), log, options) } - def doCompile(compile: (Set[File], DependencyChanges, xsbti.AnalysisCallback) => Unit, internalMap: File => Option[File], externalAPI: (File, String) => Option[Source], current: ReadStamps, output: Output) = (srcs: Set[File], changes: DependencyChanges) => { - val callback = new AnalysisCallback(internalMap, externalAPI, current, output) + def doCompile(compile: (Set[File], DependencyChanges, xsbti.AnalysisCallback) => Unit, internalMap: File => Option[File], externalAPI: (File, String) => Option[Source], current: ReadStamps, output: Output, options: IncOptions) = + (srcs: Set[File], changes: DependencyChanges) => { + val callback = new AnalysisCallback(internalMap, externalAPI, current, output, options) compile(srcs, changes, callback) callback.get } @@ -42,7 +43,7 @@ object IncrementalCompile } } } -private final class AnalysisCallback(internalMap: File => Option[File], externalAPI: (File, String) => Option[Source], current: ReadStamps, output: Output) extends xsbti.AnalysisCallback +private final class AnalysisCallback(internalMap: File => Option[File], externalAPI: (File, String) => Option[Source], current: ReadStamps, output: Output, options: IncOptions) extends xsbti.AnalysisCallback { val compilation = { val outputSettings = output match { @@ -128,7 +129,9 @@ private final class AnalysisCallback(internalMap: File => Option[File], external def api(sourceFile: File, source: SourceAPI) { import xsbt.api.{APIUtil, HashAPI} if (APIUtil.hasMacro(source)) macroSources += sourceFile - apis(sourceFile) = (HashAPI(source), APIUtil.minimize(source)) + val shouldMinimize = !Incremental.apiDebug(options) + val savedSource = if (shouldMinimize) APIUtil.minimize(source) else source + apis(sourceFile) = (HashAPI(source), savedSource) } def endSource(sourcePath: File): Unit = diff --git a/compile/inc/src/main/scala/sbt/inc/Incremental.scala b/compile/inc/src/main/scala/sbt/inc/Incremental.scala index c8f3caa1f..5979feba1 100644 --- a/compile/inc/src/main/scala/sbt/inc/Incremental.scala +++ b/compile/inc/src/main/scala/sbt/inc/Incremental.scala @@ -35,6 +35,8 @@ object Incremental val incDebugProp = "xsbt.inc.debug" private def incDebug(options: IncOptions): Boolean = options.relationsDebug || java.lang.Boolean.getBoolean(incDebugProp) + val apiDebugProp = "xsbt.api.debug" + def apiDebug(options: IncOptions): Boolean = options.apiDebug || java.lang.Boolean.getBoolean(apiDebugProp) // TODO: the Analysis for the last successful compilation should get returned + Boolean indicating success // TODO: full external name changes, scopeInvalidations def cycle(invalidatedRaw: Set[File], allSources: Set[File], binaryChanges: DependencyChanges, previous: Analysis,