Add scalaCompiler variant that accepts ModuleID

This commit is contained in:
Eugene Yokota 2017-05-29 05:05:10 -04:00
parent 9e28e0bfd6
commit c95396b020
1 changed files with 37 additions and 28 deletions

View File

@ -32,57 +32,57 @@ private[sbt] object ZincComponentCompiler {
private final val ZincVersionPropertyFile = "/incrementalcompiler.version.properties" private final val ZincVersionPropertyFile = "/incrementalcompiler.version.properties"
private final val ZincVersionProperty = "version" private final val ZincVersionProperty = "version"
private final lazy val incrementalVersion: String = { private[sbt] final lazy val incrementalVersion: String = {
val cl = this.getClass.getClassLoader val cl = this.getClass.getClassLoader
ResourceLoader.getPropertiesFor(ZincVersionPropertyFile, cl).getProperty(ZincVersionProperty) ResourceLoader.getPropertiesFor(ZincVersionPropertyFile, cl).getProperty(ZincVersionProperty)
} }
private val CompileConf = Some(Configurations.Compile.name)
private[sbt] def getDefaultBridgeModule(scalaVersion: String): ModuleID = {
def compilerBridgeId(scalaVersion: String) = {
// Defaults to bridge for 2.12 for Scala versions bigger than 2.12.x
scalaVersion match {
case sc if (sc startsWith "2.10.") => "compiler-bridge_2.10"
case sc if (sc startsWith "2.11.") => "compiler-bridge_2.11"
case _ => "compiler-bridge_2.12"
}
}
import xsbti.ArtifactInfo.SbtOrganization
val bridgeId = compilerBridgeId(scalaVersion)
ModuleID(SbtOrganization, bridgeId, incrementalVersion)
.withConfigurations(CompileConf)
.sources()
}
/** Defines the internal implementation of a bridge provider. */ /** Defines the internal implementation of a bridge provider. */
private class ZincCompilerBridgeProvider( private class ZincCompilerBridgeProvider(
userProvidedBridgeSources: Option[ModuleID],
manager: ZincComponentManager, manager: ZincComponentManager,
ivyConfiguration: IvyConfiguration, ivyConfiguration: IvyConfiguration,
scalaJarsTarget: File scalaJarsTarget: File
) extends CompilerBridgeProvider { ) extends CompilerBridgeProvider {
private val CompileConf = Some(Configurations.Compile.name)
private def getDefaultBridgeModule(scalaVersion: String): ModuleID = {
def compilerBridgeId(scalaVersion: String) = {
// Defaults to bridge for 2.12 for Scala versions bigger than 2.12.x
scalaVersion match {
case sc if (sc startsWith "2.10.") => "compiler-bridge_2.10"
case sc if (sc startsWith "2.11.") => "compiler-bridge_2.11"
case _ => "compiler-bridge_2.12"
}
}
import xsbti.ArtifactInfo.SbtOrganization
val bridgeId = compilerBridgeId(scalaVersion)
ModuleID(SbtOrganization, bridgeId, incrementalVersion)
.withConfigurations(CompileConf)
.sources()
}
/** /**
* Defines a richer interface for Scala users that want to pass in an explicit module id. * Defines a richer interface for Scala users that want to pass in an explicit module id.
* *
* Note that this method cannot be defined in [[CompilerBridgeProvider]] because [[ModuleID]] * Note that this method cannot be defined in [[CompilerBridgeProvider]] because [[ModuleID]]
* is a Scala-defined class to which the compiler bridge cannot depend on. * is a Scala-defined class to which the compiler bridge cannot depend on.
*/ */
def getCompiledBridge(bridgeSources: ModuleID, def compiledBridge(bridgeSources: ModuleID,
scalaInstance: xsbti.compile.ScalaInstance, scalaInstance: xsbti.compile.ScalaInstance,
logger: xsbti.Logger): File = { logger: xsbti.Logger): File = {
val autoClasspath = ClasspathOptionsUtil.auto val autoClasspath = ClasspathOptionsUtil.auto
val raw = new RawCompiler(scalaInstance, autoClasspath, logger) val raw = new RawCompiler(scalaInstance, autoClasspath, logger)
val zinc = new ZincComponentCompiler(raw, manager, ivyConfiguration, bridgeSources, logger) val zinc = new ZincComponentCompiler(raw, manager, ivyConfiguration, bridgeSources, logger)
logger.debug(InterfaceUtil.f0(s"Getting $bridgeSources for Scala ${scalaInstance.version}")) logger.debug(InterfaceUtil.f0(s"Getting $bridgeSources for Scala ${scalaInstance.version}"))
zinc.getCompiledBridgeJar zinc.compiledBridgeJar
} }
override def fetchCompiledBridge(scalaInstance: xsbti.compile.ScalaInstance, override def fetchCompiledBridge(scalaInstance: xsbti.compile.ScalaInstance,
logger: xsbti.Logger): File = { logger: xsbti.Logger): File = {
val scalaVersion = scalaInstance.actualVersion() val scalaVersion = scalaInstance.actualVersion()
val bridgeSources = getDefaultBridgeModule(scalaVersion) val bridgeSources = userProvidedBridgeSources getOrElse getDefaultBridgeModule(scalaVersion)
getCompiledBridge(bridgeSources, scalaInstance, logger) compiledBridge(bridgeSources, scalaInstance, logger)
} }
private final case class ScalaArtifacts(compiler: File, library: File, others: Vector[File]) private final case class ScalaArtifacts(compiler: File, library: File, others: Vector[File])
@ -134,10 +134,20 @@ private[sbt] object ZincComponentCompiler {
} }
} }
// Used by ZincUtil.
def interfaceProvider(compilerBridgeSource: ModuleID,
manager: ZincComponentManager,
ivyConfiguration: IvyConfiguration,
scalaJarsTarget: File): CompilerBridgeProvider =
new ZincCompilerBridgeProvider(Some(compilerBridgeSource),
manager,
ivyConfiguration,
scalaJarsTarget)
def interfaceProvider(manager: ZincComponentManager, def interfaceProvider(manager: ZincComponentManager,
ivyConfiguration: IvyConfiguration, ivyConfiguration: IvyConfiguration,
scalaJarsTarget: File): CompilerBridgeProvider = scalaJarsTarget: File): CompilerBridgeProvider =
new ZincCompilerBridgeProvider(manager, ivyConfiguration, scalaJarsTarget) new ZincCompilerBridgeProvider(None, manager, ivyConfiguration, scalaJarsTarget)
private final val LocalIvy = s"$${user.home}/.ivy2/local/${Resolver.localBasePattern}" private final val LocalIvy = s"$${user.home}/.ivy2/local/${Resolver.localBasePattern}"
final val LocalResolver: Resolver = { final val LocalResolver: Resolver = {
@ -211,7 +221,7 @@ private[inc] class ZincComponentCompiler(
private final val ivySbt: IvySbt = new IvySbt(ivyConfiguration) private final val ivySbt: IvySbt = new IvySbt(ivyConfiguration)
private final val buffered = new BufferedLogger(FullLogger(log)) private final val buffered = new BufferedLogger(FullLogger(log))
def getCompiledBridgeJar: File = { def compiledBridgeJar: File = {
val jarBinaryName = createBridgeSourcesID(bridgeSources) val jarBinaryName = createBridgeSourcesID(bridgeSources)
manager.file(jarBinaryName)(IfMissing.define(true, compileAndInstall(jarBinaryName))) manager.file(jarBinaryName)(IfMissing.define(true, compileAndInstall(jarBinaryName)))
} }
@ -290,7 +300,6 @@ object ZincIvyActions {
/** Define the default configurations for a Zinc module wrapper. */ /** Define the default configurations for a Zinc module wrapper. */
private final val DefaultConfigurations: Vector[Configuration] = private final val DefaultConfigurations: Vector[Configuration] =
Vector(Configurations.Component, Configurations.Compile) Vector(Configurations.Component, Configurations.Compile)
private final val DefaultUpdateOptions = UpdateOptions()
/** /**
* Create a module from its dummy wrapper and its dependencies. * Create a module from its dummy wrapper and its dependencies.