Skip to content

Commit

Permalink
Merge pull request #633 from lukaszwawrzyk/ctj-switch
Browse files Browse the repository at this point in the history
Handle compile to jar switch
  • Loading branch information
jvican authored Jan 25, 2019
2 parents 5ff3ba8 + 9d93efe commit 11a7097
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object JarUtils {
* that changes between compilation runs (incremental compilation cycles).
* Caching may hide those changes and lead into incorrect results.
*/
val scalacOptions = Set("-YdisableFlatCpCaching")
val scalacOptions: Set[ClassFilePath] = Set("-YdisableFlatCpCaching")

/**
* Options that have to be specified when running javac in order
Expand All @@ -111,7 +111,7 @@ object JarUtils {
* -XDuseOptimizedZip=false holds jars open that causes problems
* with locks on Windows.
*/
val javacOptions = Set("-XDuseOptimizedZip=false")
val javacOptions: Set[ClassFilePath] = Set("-XDuseOptimizedZip=false")

/** Reads current index of a jar file to allow restoring it later with `unstashIndex` */
def stashIndex(jar: File): IndexBasedZipFsOps.CentralDir = {
Expand Down
26 changes: 22 additions & 4 deletions zinc/src/main/scala/sbt/internal/inc/IncrementalCompilerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,16 @@ class IncrementalCompilerImpl extends IncrementalCompiler {
val srcsSet = sources.toSet
val analysis = previousSetup match {
case Some(previous) =>
// Return an empty analysis if values of extra have changed
if (equiv.equiv(previous, currentSetup))
if (compileToJarSwitchedOn(mixedCompiler.config)) {
Analysis.empty
} else if (equiv.equiv(previous, currentSetup)) {
previousAnalysis
else if (!equivPairs.equiv(previous.extra, currentSetup.extra))
// Return an empty analysis if values of extra have changed
} else if (!equivPairs.equiv(previous.extra, currentSetup.extra)) {
Analysis.empty
else Incremental.prune(srcsSet, previousAnalysis, output, outputJarContent)
} else {
Incremental.prune(srcsSet, previousAnalysis, output, outputJarContent)
}
case None =>
Incremental.prune(srcsSet, previousAnalysis, output, outputJarContent)
}
Expand All @@ -341,6 +345,20 @@ class IncrementalCompilerImpl extends IncrementalCompiler {
compile.swap
}

private def compileToJarSwitchedOn(config: CompileConfiguration): Boolean = {
def isCompilingToJar = JarUtils.isCompilingToJar(config.currentSetup.output)
def previousCompilationWasToJar = config.previousAnalysis match {
case analysis: Analysis =>
analysis.relations.allProducts.headOption match {
case Some(product) => JarUtils.isClassInJar(product)
case None => true // we can assume it was, as it doesn't matter if there were no products
}
case _ => true
}

isCompilingToJar && !previousCompilationWasToJar
}

def setup(
lookup: PerClasspathEntryLookup,
skip: Boolean,
Expand Down

0 comments on commit 11a7097

Please sign in to comment.