Skip to content

Commit

Permalink
Replace var/set with withClassLoaderCache
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand authored and retronym committed Sep 26, 2016
1 parent 5005abf commit 06cdefe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
18 changes: 6 additions & 12 deletions compile/src/main/scala/sbt/compiler/AnalyzingCompiler.scala
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions main/actions/src/main/scala/sbt/Compiler.scala
Expand Up @@ -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

Expand All @@ -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])
Expand Down
15 changes: 9 additions & 6 deletions main/src/main/scala/sbt/Defaults.scala
Expand Up @@ -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(
Expand Down

0 comments on commit 06cdefe

Please sign in to comment.