Fix compiler bridge concurrency issue

Fixes https://github.com/sbt/sbt/issues/5785
This commit is contained in:
Eugene Yokota 2020-12-21 00:13:14 -05:00
parent f5d4a0779e
commit 3c955abea6
2 changed files with 6 additions and 3 deletions

View File

@ -36,6 +36,7 @@ private[sbt] object ZincComponentCompiler {
private[sbt] final lazy val incrementalVersion: String = ZincComponentManager.version private[sbt] final lazy val incrementalVersion: String = ZincComponentManager.version
private val CompileConf = Some(Configurations.Compile.name) private val CompileConf = Some(Configurations.Compile.name)
private val lock: AnyRef = new {}
private[sbt] def getDefaultBridgeModule(scalaVersion: String): ModuleID = { private[sbt] def getDefaultBridgeModule(scalaVersion: String): ModuleID = {
val compilerBridgeId = scalaVersion match { val compilerBridgeId = scalaVersion match {
@ -68,7 +69,7 @@ private[sbt] object ZincComponentCompiler {
bridgeSources: ModuleID, bridgeSources: ModuleID,
scalaInstance: ScalaInstance, scalaInstance: ScalaInstance,
logger: Logger, logger: Logger,
): File = { ): File = lock.synchronized {
val raw = new RawCompiler(scalaInstance, ClasspathOptionsUtil.auto, logger) val raw = new RawCompiler(scalaInstance, ClasspathOptionsUtil.auto, logger)
val zinc = val zinc =
new ZincComponentCompiler(raw, manager, dependencyResolution, bridgeSources, logger) new ZincComponentCompiler(raw, manager, dependencyResolution, bridgeSources, logger)
@ -312,7 +313,7 @@ private object ZincLMHelper {
logger.info(s"Attempting to fetch $dependencies.") logger.info(s"Attempting to fetch $dependencies.")
dependencyResolution.update(module, updateConfiguration, warningConf, logger) match { dependencyResolution.update(module, updateConfiguration, warningConf, logger) match {
case Left(uw) => case Left(uw) =>
logger.debug(s"Couldn't retrieve module(s) ${prettyPrintDependency(module)}.") logger.debug(s"couldn't retrieve module(s) ${prettyPrintDependency(module)}.")
val unretrievedMessage = s"The $desc could not be retrieved." val unretrievedMessage = s"The $desc could not be retrieved."
val unresolvedLines = UnresolvedWarning.unresolvedWarningLines.showLines(uw).mkString("\n") val unresolvedLines = UnresolvedWarning.unresolvedWarningLines.showLines(uw).mkString("\n")
throw new InvalidComponent(s"$unretrievedMessage\n$unresolvedLines") throw new InvalidComponent(s"$unretrievedMessage\n$unresolvedLines")

View File

@ -39,7 +39,9 @@ class ZincComponentManager(
def notFound = invalid(s"Could not find required component '$id'") def notFound = invalid(s"Could not find required component '$id'")
def getOrElse(orElse: => Iterable[File]): Iterable[File] = { def getOrElse(orElse: => Iterable[File]): Iterable[File] = {
val existing = provider.component(id) val existing = provider.component(id)
if (existing.isEmpty) orElse else existing // log.info(s"[zinc-lm] existing = ${existing.toList}")
if (existing.isEmpty) orElse
else existing
} }
def createAndCache = { def createAndCache = {