From 437a3f7f505525ec44ba338f5a9e9d80724d1730 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Sun, 29 May 2011 19:17:31 -0400 Subject: [PATCH] clean up incremental debugging messages --- compile/inc/Compile.scala | 4 +-- compile/inc/Incremental.scala | 45 +++++++++++++++------------- main/actions/AggressiveCompile.scala | 2 +- project/build/XSbt.scala | 2 +- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/compile/inc/Compile.scala b/compile/inc/Compile.scala index 830d0c823..5f73ebed4 100644 --- a/compile/inc/Compile.scala +++ b/compile/inc/Compile.scala @@ -9,12 +9,12 @@ import java.io.File object IncrementalCompile { - def apply(sources: Set[File], entry: String => Option[File], compile: (Set[File], xsbti.AnalysisCallback) => Unit, previous: Analysis, forEntry: File => Option[Analysis], outputPath: File): (Boolean, Analysis) = + def apply(sources: Set[File], entry: String => Option[File], compile: (Set[File], xsbti.AnalysisCallback) => Unit, previous: Analysis, forEntry: File => Option[Analysis], outputPath: File, log: Logger): (Boolean, Analysis) = { 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, outputPath)) + Incremental.compile(sources, entry, previous, current, forEntry, doCompile(compile, internalMap, externalAPI, current, outputPath), log) } def doCompile(compile: (Set[File], xsbti.AnalysisCallback) => Unit, internalMap: File => Option[File], externalAPI: (File, String) => Option[Source], current: ReadStamps, outputPath: File) = (srcs: Set[File]) => { val callback = new AnalysisCallback(internalMap, externalAPI, current, outputPath) diff --git a/compile/inc/Incremental.scala b/compile/inc/Incremental.scala index aec1725fd..f73394ca3 100644 --- a/compile/inc/Incremental.scala +++ b/compile/inc/Incremental.scala @@ -12,19 +12,18 @@ import java.io.File object Incremental { def debug(s: => String) = if(java.lang.Boolean.getBoolean("xsbt.inc.debug")) println(s) else () - def compile(sources: Set[File], entry: String => Option[File], previous: Analysis, current: ReadStamps, forEntry: File => Option[Analysis], doCompile: Set[File] => Analysis)(implicit equivS: Equiv[Stamp]): (Boolean, Analysis) = + def compile(sources: Set[File], entry: String => Option[File], previous: Analysis, current: ReadStamps, forEntry: File => Option[Analysis], doCompile: Set[File] => Analysis, log: Logger)(implicit equivS: Equiv[Stamp]): (Boolean, Analysis) = { val initialChanges = changedInitial(entry, sources, previous, current, forEntry) - debug("Initial changes: " + initialChanges) - val initialInv = invalidateInitial(previous.relations, initialChanges) - debug("Initially invalidated: " + initialInv) - val analysis = cycle(initialInv, previous, doCompile) + val initialInv = invalidateInitial(previous.relations, initialChanges, log) + log.debug("Initially invalidated: " + initialInv) + val analysis = cycle(initialInv, previous, doCompile, log) (!initialInv.isEmpty, analysis) } // TODO: the Analysis for the last successful compilation should get returned + Boolean indicating success // TODO: full external name changes, scopeInvalidations - def cycle(invalidated: Set[File], previous: Analysis, doCompile: Set[File] => Analysis): Analysis = + def cycle(invalidated: Set[File], previous: Analysis, doCompile: Set[File] => Analysis, log: Logger): Analysis = if(invalidated.isEmpty) previous else @@ -37,9 +36,9 @@ object Incremental debug("********* Merged: \n" + merged.relations + "\n*********") val incChanges = changedIncremental(invalidated, previous.apis.internalAPI _, merged.apis.internalAPI _) debug("Changes:\n" + incChanges) - val incInv = invalidateIncremental(merged.relations, incChanges, invalidated) - debug("Incrementally invalidated: " + incInv) - cycle(incInv, merged, doCompile) + val incInv = invalidateIncremental(merged.relations, incChanges, invalidated, log) + log.debug("Incrementally invalidated: " + incInv) + cycle(incInv, merged, doCompile, log) } @@ -84,9 +83,9 @@ object Incremental val (changed, unmodified) = inBoth.partition(existingModified) } - def invalidateIncremental(previous: Relations, changes: APIChanges[File], recompiledSources: Set[File]): Set[File] = + def invalidateIncremental(previous: Relations, changes: APIChanges[File], recompiledSources: Set[File], log: Logger): Set[File] = { - val inv = invalidateTransitive(previous.usesInternalSrc _, changes.modified )// ++ scopeInvalidations(previous.extAPI _, changes.modified, changes.names) + val inv = invalidateTransitive(previous.usesInternalSrc _, changes.modified, log)// ++ scopeInvalidations(previous.extAPI _, changes.modified, changes.names) if((inv -- recompiledSources).isEmpty) Set.empty else inv } @@ -96,26 +95,32 @@ object Incremental (modified flatMap dependsOnSrc) -- modified /** Invalidates transitive source dependencies including `modified`. It excludes any sources that were recompiled during the previous run.*/ - @tailrec def invalidateTransitive(dependsOnSrc: File => Set[File], modified: Set[File]): Set[File] = + @tailrec def invalidateTransitive(dependsOnSrc: File => Set[File], modified: Set[File], log: Logger): Set[File] = { val newInv = invalidateDirect(dependsOnSrc, modified) - debug("\tInvalidated direct: " + newInv) - if(newInv.isEmpty) modified else invalidateTransitive(dependsOnSrc, modified ++ newInv) + log.debug("\tInvalidated direct: " + newInv) + if(newInv.isEmpty) modified else invalidateTransitive(dependsOnSrc, modified ++ newInv, log) } /** Invalidates sources based on initially detected 'changes' to the sources, products, and dependencies.*/ - def invalidateInitial(previous: Relations, changes: InitialChanges): Set[File] = + def invalidateInitial(previous: Relations, changes: InitialChanges, log: Logger): Set[File] = { val srcChanges = changes.internalSrc - debug("Initial source changes: \n\tremoved:" + srcChanges.removed + "\n\tadded: " + srcChanges.added + "\n\tmodified: " + srcChanges.changed) val srcDirect = srcChanges.removed ++ srcChanges.removed.flatMap(previous.usesInternalSrc) ++ srcChanges.added ++ srcChanges.changed - debug("Initial source direct: " + srcDirect) val byProduct = changes.removedProducts.flatMap(previous.produced) - debug("Initial by product: " + byProduct) val byBinaryDep = changes.binaryDeps.flatMap(previous.usesBinary) - debug("Initial by binary dep: " + byBinaryDep) val byExtSrcDep = changes.external.modified.flatMap(previous.usesExternal) // ++ scopeInvalidations - debug("Initial by binary dep: " + byExtSrcDep) + log.debug( + "\nInitial source changes: \n\tremoved:" + srcChanges.removed + "\n\tadded: " + srcChanges.added + "\n\tmodified: " + srcChanges.changed + + "\nRemoved products: " + changes.removedProducts + + "\nModified external sources: " + changes.external.modified + + "\nModified binary dependencies: " + changes.binaryDeps + + "\nInitial directly invalidated sources: " + srcDirect + + "\n\nSources indirectly invalidated by:" + + "\n\tproduct: " + byProduct + + "\n\tbinary dep: " + byBinaryDep + + "\n\texternal source: " + byExtSrcDep + ) srcDirect ++ byProduct ++ byBinaryDep ++ byExtSrcDep } diff --git a/main/actions/AggressiveCompile.scala b/main/actions/AggressiveCompile.scala index 0f1b311f6..5c4484dfe 100644 --- a/main/actions/AggressiveCompile.scala +++ b/main/actions/AggressiveCompile.scala @@ -83,7 +83,7 @@ class AggressiveCompile(cacheDirectory: File) case Some(previous) if equiv.equiv(previous, currentSetup) => previousAnalysis case _ => Incremental.prune(sourcesSet, previousAnalysis) } - IncrementalCompile(sourcesSet, entry, compile0, analysis, getAnalysis, outputDirectory) + IncrementalCompile(sourcesSet, entry, compile0, analysis, getAnalysis, outputDirectory, log) } private[this] def logInputs(log: Logger, javaCount: Int, scalaCount: Int) { diff --git a/project/build/XSbt.scala b/project/build/XSbt.scala index e9ec3146d..e7dd46131 100644 --- a/project/build/XSbt.scala +++ b/project/build/XSbt.scala @@ -63,7 +63,7 @@ class XSbt(info: ProjectInfo) extends ParentProject(info) with NoCrossPaths val compileInterfaceSub = project(compilePath / "interface", "Compiler Interface", new CompilerInterfaceProject(_), interfaceSub) // Implements the core functionality of detecting and propagating changes incrementally. // Defines the data structures for representing file fingerprints and relationships and the overall source analysis - val compileIncrementalSub = testedBase(compilePath / "inc", "Incremental Compiler", collectionSub, apiSub, ioSub) + val compileIncrementalSub = testedBase(compilePath / "inc", "Incremental Compiler", collectionSub, apiSub, ioSub, logSub) // Persists the incremental data structures using SBinary val compilePersistSub = project(compilePath / "persist", "Persist", new PersistProject(_), compileIncrementalSub, apiSub) // sbt-side interface to compiler. Calls compiler-side interface reflectively