Cleanup zinc-lm-integration

This commit is contained in:
Dale Wijnand 2019-04-18 08:14:04 +01:00
parent e978357e47
commit 9a56c0d005
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
3 changed files with 81 additions and 57 deletions

View File

@ -71,9 +71,11 @@ private[sbt] object ZincComponentCompiler {
* Note that this method cannot be defined in [[CompilerBridgeProvider]] because [[ModuleID]]
* is a Scala-defined class to which the compiler bridge cannot depend on.
*/
def compiledBridge(bridgeSources: ModuleID,
scalaInstance: xsbti.compile.ScalaInstance,
logger: xsbti.Logger): File = {
def compiledBridge(
bridgeSources: ModuleID,
scalaInstance: xsbti.compile.ScalaInstance,
logger: xsbti.Logger
): File = {
import InterfaceUtil.{ toSupplier => f0 }
val autoClasspath = ClasspathOptionsUtil.auto
val raw = new RawCompiler(scalaInstance, autoClasspath, logger)
@ -83,8 +85,10 @@ private[sbt] object ZincComponentCompiler {
zinc.compiledBridgeJar
}
override def fetchCompiledBridge(scalaInstance: xsbti.compile.ScalaInstance,
logger: xsbti.Logger): File = {
override def fetchCompiledBridge(
scalaInstance: xsbti.compile.ScalaInstance,
logger: xsbti.Logger
): File = {
val scalaVersion = scalaInstance.actualVersion()
val bridgeSources = userProvidedBridgeSources getOrElse getDefaultBridgeModule(scalaVersion)
compiledBridge(bridgeSources, scalaInstance, logger)
@ -110,11 +114,13 @@ private[sbt] object ZincComponentCompiler {
.withConfigurations(ZincLMHelper.DefaultConfigurations)
val moduleDescriptor = dependencyResolution.moduleDescriptor(moduleDescriptorConfiguration)
ZincLMHelper.update(dependencyResolution,
moduleDescriptor,
scalaJarsTarget,
noSource = true,
fullLogger) match {
ZincLMHelper.update(
dependencyResolution,
moduleDescriptor,
scalaJarsTarget,
noSource = true,
fullLogger
) match {
case Left(uw) =>
val unresolvedLines = unresolvedWarningLines.showLines(uw).mkString("\n")
val unretrievedMessage = s"The Scala compiler and library could not be retrieved."
@ -131,42 +137,54 @@ private[sbt] object ZincComponentCompiler {
}
}
override def fetchScalaInstance(scalaVersion: String,
logger: xsbti.Logger): xsbti.compile.ScalaInstance = {
override def fetchScalaInstance(
scalaVersion: String,
logger: xsbti.Logger
): xsbti.compile.ScalaInstance = {
val scalaArtifacts = getScalaArtifacts(scalaVersion, logger)
val scalaCompiler = scalaArtifacts.compiler
val scalaLibrary = scalaArtifacts.library
val jarsToLoad = (scalaCompiler +: scalaLibrary +: scalaArtifacts.others).toArray
assert(jarsToLoad.forall(_.exists), "One or more jar(s) in the Scala instance do not exist.")
val loaderLibraryOnly = ClasspathUtilities.toLoader(Vector(scalaLibrary))
val loader = ClasspathUtilities.toLoader(jarsToLoad.toVector filterNot { _ == scalaLibrary },
loaderLibraryOnly)
val loader = ClasspathUtilities.toLoader(
jarsToLoad.toVector filterNot { _ == scalaLibrary },
loaderLibraryOnly
)
val properties = ResourceLoader.getSafePropertiesFor("compiler.properties", loader)
val loaderVersion = Option(properties.getProperty("version.number"))
val scalaV = loaderVersion.getOrElse("unknown")
new ScalaInstance(scalaV,
loader,
loaderLibraryOnly,
scalaLibrary,
scalaCompiler,
jarsToLoad,
loaderVersion)
new ScalaInstance(
scalaV,
loader,
loaderLibraryOnly,
scalaLibrary,
scalaCompiler,
jarsToLoad,
loaderVersion
)
}
}
// Used by ZincUtil.
def interfaceProvider(compilerBridgeSource: ModuleID,
manager: ZincComponentManager,
dependencyResolution: DependencyResolution,
scalaJarsTarget: File): CompilerBridgeProvider =
new ZincCompilerBridgeProvider(Some(compilerBridgeSource),
manager,
dependencyResolution,
scalaJarsTarget)
def interfaceProvider(
compilerBridgeSource: ModuleID,
manager: ZincComponentManager,
dependencyResolution: DependencyResolution,
scalaJarsTarget: File
): CompilerBridgeProvider =
new ZincCompilerBridgeProvider(
Some(compilerBridgeSource),
manager,
dependencyResolution,
scalaJarsTarget
)
def interfaceProvider(manager: ZincComponentManager,
dependencyResolution: DependencyResolution,
scalaJarsTarget: File): CompilerBridgeProvider =
def interfaceProvider(
manager: ZincComponentManager,
dependencyResolution: DependencyResolution,
scalaJarsTarget: File
): CompilerBridgeProvider =
new ZincCompilerBridgeProvider(None, manager, dependencyResolution, scalaJarsTarget)
private final val LocalIvy = s"$${user.home}/.ivy2/local/${Resolver.localBasePattern}"
@ -260,11 +278,13 @@ private[inc] class ZincComponentCompiler(
val target = new File(binaryDirectory, s"$compilerBridgeId.jar")
buffered bufferQuietly {
IO.withTemporaryDirectory { retrieveDirectory =>
ZincLMHelper.update(dependencyResolution,
moduleForBridge,
retrieveDirectory,
false,
buffered) match {
ZincLMHelper.update(
dependencyResolution,
moduleForBridge,
retrieveDirectory,
false,
buffered
) match {
case Left(uw) =>
val mod = bridgeSources.toString
val unresolvedLines = unresolvedWarningLines.showLines(uw).mkString("\n")
@ -292,11 +312,13 @@ private object ZincLMHelper {
private[inc] final val DefaultConfigurations: Vector[Configuration] =
Vector(Configurations.Component, Configurations.Compile)
private[inc] def update(dependencyResolution: DependencyResolution,
module: ModuleDescriptor,
retrieveDirectory: File,
noSource: Boolean = false,
logger: Logger): Either[UnresolvedWarning, Vector[File]] = {
private[inc] def update(
dependencyResolution: DependencyResolution,
module: ModuleDescriptor,
retrieveDirectory: File,
noSource: Boolean = false,
logger: Logger
): Either[UnresolvedWarning, Vector[File]] = {
val updateConfiguration = defaultUpdateConfiguration(retrieveDirectory, noSource)
val dependencies = prettyPrintDependency(module)
logger.info(s"Attempting to fetch $dependencies.")

View File

@ -24,10 +24,12 @@ import sbt.io.IO
* This is used for compiled source jars so that the compilation need not be repeated for other projects on the same
* machine.
*/
class ZincComponentManager(globalLock: xsbti.GlobalLock,
provider: xsbti.ComponentProvider,
secondaryCacheDir: Option[File],
log0: xsbti.Logger) {
class ZincComponentManager(
globalLock: xsbti.GlobalLock,
provider: xsbti.ComponentProvider,
secondaryCacheDir: Option[File],
log0: xsbti.Logger
) {
val log = new FullLogger(log0)
/** Get all of the files for component 'id', throwing an exception if no files exist for the component. */

View File

@ -26,22 +26,20 @@ abstract class IvyBridgeProviderSpecification extends FlatSpec with Matchers {
def currentBase: File = new File(".")
def currentTarget: File = currentBase / "target" / "ivyhome"
def currentManaged: File = currentBase / "target" / "lib_managed"
def secondaryCacheDirectory: File = file("target").getAbsoluteFile / "zinc-components"
val resolvers = Array(
ZincComponentCompiler.LocalResolver,
Resolver.mavenCentral,
MavenRepository("scala-integration",
"https://scala-ci.typesafe.com/artifactory/scala-integration/")
MavenRepository(
"scala-integration",
"https://scala-ci.typesafe.com/artifactory/scala-integration/"
),
)
private def ivyConfiguration(log: Logger) =
getDefaultConfiguration(currentBase, currentTarget, resolvers, log)
def secondaryCacheDirectory: File = {
val target = file("target").getAbsoluteFile
target / "zinc-components"
}
def getZincProvider(bridge: ModuleID, targetDir: File, log: Logger): CompilerBridgeProvider = {
val lock = ZincComponentCompiler.getDefaultLock
val secondaryCache = Some(secondaryCacheDirectory)
@ -66,10 +64,12 @@ abstract class IvyBridgeProviderSpecification extends FlatSpec with Matchers {
target
}
private def getDefaultConfiguration(baseDirectory: File,
ivyHome: File,
resolvers0: Array[Resolver],
log: xsbti.Logger): InlineIvyConfiguration = {
private def getDefaultConfiguration(
baseDirectory: File,
ivyHome: File,
resolvers0: Array[Resolver],
log: xsbti.Logger
): InlineIvyConfiguration = {
import sbt.io.syntax._
val resolvers = resolvers0.toVector
val chainResolver = ChainedResolver("zinc-chain", resolvers)