Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MultiProjectIncrementalSpec to test shadowing detection #179

Merged
merged 10 commits into from Sep 29, 2016
1 change: 0 additions & 1 deletion .gitignore
@@ -1,2 +1 @@
target/
.idea
Expand Up @@ -153,14 +153,6 @@
"name": "externalHooks",
"type": "xsbti.compile.ExternalHooks",
"doc": "External hooks that allows clients e.g. IDEs to interacts with compilation internals"
},
{
"name": "analysisOnlyExtDepLookup",
"type": "boolean",
"doc": [
"Ignore classpath entries without Analysis when searching for external dependencies.",
"It might miss changes in classes from jars external class directories."
]
}
]
},
Expand Down
Expand Up @@ -106,10 +106,6 @@ public static boolean defaultLogRecompileOnMacro() {
return true;
}

public static boolean defaultAnalysisOnlyExtDepLookup() {
return false;
}

public static IncOptions defaultIncOptions() {
IncOptions retval = new IncOptions(
defaultTransitiveStep(), defaultRecompileAllFraction(),
Expand All @@ -118,7 +114,7 @@ public static IncOptions defaultIncOptions() {
defaultClassfileManagerType(), defaultRecompileOnMacroDef(),
defaultNameHashing(), defaultStoreApis(), defaultAntStyle(),
defaultExtra(), defaultLogRecompileOnMacro(),
defaultExternal(), defaultAnalysisOnlyExtDepLookup());
defaultExternal());
return retval;
}

Expand Down
Expand Up @@ -18,12 +18,7 @@ import sbt.io.syntax._
* the analysis plugin. Because these call Scala code for a different Scala version than the one used for this class, they must
* be compiled for the version of Scala being used.
*/
final class AnalyzingCompiler private (
val scalaInstance: XScalaInstance,
val provider: CompilerInterfaceProvider,
override val classpathOptions: ClasspathOptions,
onArgsF: Seq[String] => Unit
) extends CachedCompilerProvider with ScalaCompiler {
final class AnalyzingCompiler private (val scalaInstance: XScalaInstance, val provider: CompilerInterfaceProvider, override val classpathOptions: ClasspathOptions, onArgsF: Seq[String] => Unit) extends CachedCompilerProvider with ScalaCompiler {
def this(scalaInstance: XScalaInstance, provider: CompilerInterfaceProvider, cp: ClasspathOptions) =
this(scalaInstance, provider, cp, _ => ())
def this(scalaInstance: XScalaInstance, provider: CompilerInterfaceProvider) = this(scalaInstance, provider, ClasspathOptionsUtil.auto)
Expand Down
Expand Up @@ -59,6 +59,7 @@ object TextAnalysisFormatTest extends Properties("TextAnalysisFormat") {
TextAnalysisFormat.write(writer, analysis, commonSetup)

val result = writer.toString
// println(result)

val reader = new BufferedReader(new StringReader(result))

Expand Down
24 changes: 6 additions & 18 deletions zinc/src/main/scala/sbt/internal/inc/CompileConfiguration.scala
Expand Up @@ -25,27 +25,15 @@ import xsbti.compile.{ GlobalsCache, CompileProgress, IncOptions, MiniSetup, Com
*/
final class CompileConfiguration(
val sources: Seq[File],
override val classpath: Seq[File],
val classpath: Seq[File],
val previousAnalysis: CompileAnalysis,
val previousSetup: Option[MiniSetup],
override val currentSetup: MiniSetup,
val currentSetup: MiniSetup,
val progress: Option[CompileProgress],
override val perClasspathEntryLookup: PerClasspathEntryLookup,
val perClasspathEntryLookup: PerClasspathEntryLookup,
val reporter: Reporter,
override val compiler: xsbti.compile.ScalaCompiler,
val compiler: xsbti.compile.ScalaCompiler,
val javac: xsbti.compile.JavaCompiler,
val cache: GlobalsCache,
override val incOptions: IncOptions
) extends CompilerClasspathConfig

trait CompilerClasspathConfig {
val currentSetup: MiniSetup

def classpath: Seq[File]

def perClasspathEntryLookup: PerClasspathEntryLookup

def compiler: xsbti.compile.ScalaCompiler

def incOptions: IncOptions
}
val incOptions: IncOptions
)
46 changes: 18 additions & 28 deletions zinc/src/main/scala/sbt/internal/inc/LookupImpl.scala
Expand Up @@ -6,35 +6,32 @@ import sbt.util.Logger._
import xsbti.Maybe
import xsbti.compile.CompileAnalysis

class LookupImpl(compileConfiguration: CompilerClasspathConfig) extends Lookup {
private val (classpath, entry) = MixedAnalyzingCompiler.searchClasspathAndLookup(compileConfiguration)

/** External dependencies (Analysis) ordered in the same way as on classpath */
private val externalDependenciesCp: Stream[Analysis] = classpath.toStream.flatMap(analysisForCpEntry)

private lazy val externalLookup = Option(compileConfiguration.incOptions.externalHooks())
.flatMap(ext => Option(ext.externalLookup()))
.collect {
case externalLookup: ExternalLookup => externalLookup
}
class LookupImpl(compileConfiguration: CompileConfiguration) extends Lookup {
private val entry = MixedAnalyzingCompiler.classPathLookup(compileConfiguration)

override def lookupOnClasspath(binaryClassName: String): Option[File] =
entry(binaryClassName)

override def lookupAnalysis(classFile: File): Option[CompileAnalysis] =
externalDependenciesCp.find(definesProduct(classFile))
m2o(compileConfiguration.perClasspathEntryLookup.analysis(classFile))

override def lookupAnalysis(binaryDependency: File, binaryClassName: String): Option[CompileAnalysis] = {
lookupOnClasspath(binaryClassName) flatMap { defines =>
if (binaryDependency != Locate.resolve(defines, binaryClassName))
None
else
lookupAnalysis(defines)
}
}

override def lookupAnalysis(binaryDependency: File, binaryClassName: String): Option[CompileAnalysis] =
for {
classpathEntry <- lookupOnClasspath(binaryClassName)
analysis <- analysisForCpEntry(classpathEntry)
if definesProduct(binaryDependency)(analysis)
} yield analysis
lazy val externalLookup = Option(compileConfiguration.incOptions.externalHooks())
.flatMap(ext => Option(ext.externalLookup()))
.collect {
case externalLookup: ExternalLookup => externalLookup
}

override def lookupAnalysis(binaryClassName: String): Option[CompileAnalysis] =
if (compileConfiguration.incOptions.analysisOnlyExtDepLookup())
externalDependenciesCp.find(_.relations.binaryClassName.reverseMap.contains(binaryClassName))
else lookupOnClasspath(binaryClassName).flatMap(analysisForCpEntry)
lookupOnClasspath(binaryClassName).flatMap(lookupAnalysis)

override def changedSources(previousAnalysis: Analysis): Option[Changes[File]] =
externalLookup.flatMap(_.changedSources(previousAnalysis))
Expand All @@ -45,13 +42,6 @@ class LookupImpl(compileConfiguration: CompilerClasspathConfig) extends Lookup {
override def removedProducts(previousAnalysis: Analysis): Option[Set[File]] =
externalLookup.flatMap(_.removedProducts(previousAnalysis))

private def definesProduct(product: File)(a: Analysis): Boolean =
a.stamps.products.contains(product)

private def analysisForCpEntry(cpEntry: File): Option[Analysis] =
m2o(compileConfiguration.perClasspathEntryLookup.analysis(cpEntry).asInstanceOf[Maybe[Analysis]])

override def shouldDoIncrementalCompilation(changedClasses: Set[String], analysis: Analysis): Boolean =
externalLookup.forall(_.shouldDoIncrementalCompilation(changedClasses, analysis))
}

Expand Up @@ -157,7 +157,7 @@ object MixedAnalyzingCompiler {
}

/** Returns the search classpath (for dependencies) and a function which can also do so. */
def searchClasspathAndLookup(config: CompilerClasspathConfig): (Seq[File], String => Option[File]) = {
def searchClasspathAndLookup(config: CompileConfiguration): (Seq[File], String => Option[File]) = {
import config._
import currentSetup._
val absClasspath = classpath.map(_.getAbsoluteFile)
Expand Down
5 changes: 5 additions & 0 deletions zinc/src/test/resources/sbt/inc/Depender.scala
@@ -0,0 +1,5 @@
package test.pkg

object Depender {
val x = test.pkg.Ext1.x
}
5 changes: 5 additions & 0 deletions zinc/src/test/resources/sbt/inc/Depender2.scala
@@ -0,0 +1,5 @@
package test.pkg

object Depender2 {
val x = test.pkg.Ext2.x
}
5 changes: 5 additions & 0 deletions zinc/src/test/resources/sbt/inc/Ext1.scala
@@ -0,0 +1,5 @@
package test.pkg

object Ext1 {
val x = 2
}
5 changes: 5 additions & 0 deletions zinc/src/test/resources/sbt/inc/Ext2.scala
@@ -0,0 +1,5 @@
package test.pkg

object Ext2 {
val x = 3
}
Binary file not shown.
136 changes: 0 additions & 136 deletions zinc/src/test/scala/sbt/inc/BaseIncCompilerSpec.scala

This file was deleted.