mirror of https://github.com/sbt/sbt.git
Replace var/set with withClassLoaderCache
This commit is contained in:
parent
5005abfef2
commit
06cdefebb9
|
|
@ -17,9 +17,9 @@ import sbt.classpath.ClassLoaderCache
|
|||
* 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: xsbti.compile.ScalaInstance, val provider: CompilerInterfaceProvider, val cp: xsbti.compile.ClasspathOptions, onArgsF: Seq[String] => Unit) extends CachedCompilerProvider {
|
||||
final class AnalyzingCompiler private (val scalaInstance: xsbti.compile.ScalaInstance, val provider: CompilerInterfaceProvider, val cp: xsbti.compile.ClasspathOptions, onArgsF: Seq[String] => Unit, val classLoaderCache: Option[ClassLoaderCache]) extends CachedCompilerProvider {
|
||||
def this(scalaInstance: xsbti.compile.ScalaInstance, provider: CompilerInterfaceProvider, cp: xsbti.compile.ClasspathOptions) =
|
||||
this(scalaInstance, provider, cp, _ => ())
|
||||
this(scalaInstance, provider, cp, _ => (), None)
|
||||
def this(scalaInstance: ScalaInstance, provider: CompilerInterfaceProvider) = this(scalaInstance, provider, ClasspathOptions.auto)
|
||||
|
||||
@deprecated("A Logger is no longer needed.", "0.13.0")
|
||||
|
|
@ -29,11 +29,10 @@ final class AnalyzingCompiler private (val scalaInstance: xsbti.compile.ScalaIns
|
|||
def this(scalaInstance: xsbti.compile.ScalaInstance, provider: CompilerInterfaceProvider, cp: xsbti.compile.ClasspathOptions, log: Logger) = this(scalaInstance, provider, cp)
|
||||
|
||||
def onArgs(f: Seq[String] => Unit): AnalyzingCompiler =
|
||||
{
|
||||
val ac = new AnalyzingCompiler(scalaInstance, provider, cp, f)
|
||||
ac.classLoaderCache = this.classLoaderCache
|
||||
ac
|
||||
}
|
||||
new AnalyzingCompiler(scalaInstance, provider, cp, f, classLoaderCache)
|
||||
|
||||
def withClassLoaderCache(classLoaderCache: ClassLoaderCache) =
|
||||
new AnalyzingCompiler(scalaInstance, provider, cp, onArgsF, Some(classLoaderCache))
|
||||
|
||||
def apply(sources: Seq[File], changes: DependencyChanges, classpath: Seq[File], singleOutput: File, options: Seq[String], callback: AnalysisCallback, maximumErrors: Int, cache: GlobalsCache, log: Logger) {
|
||||
val arguments = (new CompilerArguments(scalaInstance, cp))(Nil, classpath, None, options)
|
||||
|
|
@ -135,11 +134,6 @@ final class AnalyzingCompiler private (val scalaInstance: xsbti.compile.ScalaIns
|
|||
new classpath.DualLoader(scalaLoader, notXsbtiFilter, x => true, sbtLoader, xsbtiFilter, x => false)
|
||||
}
|
||||
|
||||
// TODO This should really be a constructor parameter, the var was used to avoid binary incompat changes
|
||||
// to signatures. Refactor for SBT 1.0.
|
||||
def setClassLoaderCache(cache: ClassLoaderCache): Unit = classLoaderCache = Some(cache)
|
||||
private var classLoaderCache: Option[ClassLoaderCache] = None
|
||||
|
||||
override def toString = "Analyzing compiler (Scala " + scalaInstance.actualVersion + ")"
|
||||
}
|
||||
object AnalyzingCompiler {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import xsbti.compile.{ CompileOrder, GlobalsCache }
|
|||
import CompileOrder.{ JavaThenScala, Mixed, ScalaThenJava }
|
||||
import compiler._
|
||||
import inc._
|
||||
import sbt.classpath.ClassLoaderCache
|
||||
import Locate.DefinesClass
|
||||
import java.io.File
|
||||
|
||||
|
|
@ -31,6 +32,8 @@ object Compiler {
|
|||
case x: JavaToolWithNewInterface => Some(x.newJavac)
|
||||
case _ => None
|
||||
}
|
||||
def withClassLoaderCache(classLoaderCache: ClassLoaderCache) =
|
||||
copy(scalac = scalac.withClassLoaderCache(classLoaderCache))
|
||||
}
|
||||
/** The previous source dependency analysis result from compilation. */
|
||||
final case class PreviousAnalysis(analysis: Analysis, setup: Option[CompileSetup])
|
||||
|
|
|
|||
|
|
@ -265,12 +265,15 @@ object Defaults extends BuildCommon {
|
|||
if (plugin) scalaBase / ("sbt-" + sbtv) else scalaBase
|
||||
}
|
||||
|
||||
def compilersSetting = compilers := {
|
||||
val compilers = Compiler.compilers(scalaInstance.value, classpathOptions.value, javaHome.value,
|
||||
bootIvyConfiguration.value, scalaCompilerBridgeSource.value)(appConfiguration.value, streams.value.log)
|
||||
if (!java.lang.Boolean.getBoolean("sbt.disable.interface.classloader.cache"))
|
||||
compilers.scalac.setClassLoaderCache(state.value.classLoaderCache)
|
||||
compilers
|
||||
def compilersSetting = {
|
||||
compilers := {
|
||||
val compilers = Compiler.compilers(
|
||||
scalaInstance.value, classpathOptions.value, javaHome.value, bootIvyConfiguration.value,
|
||||
scalaCompilerBridgeSource.value)(appConfiguration.value, streams.value.log)
|
||||
if (java.lang.Boolean.getBoolean("sbt.disable.interface.classloader.cache")) compilers else {
|
||||
compilers.withClassLoaderCache(state.value.classLoaderCache)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lazy val configTasks = docTaskSettings(doc) ++ inTask(compile)(compileInputsSettings) ++ configGlobal ++ compileAnalysisSettings ++ Seq(
|
||||
|
|
|
|||
Loading…
Reference in New Issue