@@ -40,6 +40,7 @@ import sbt.util.InterfaceUtil
4040import xsbti .T2
4141import xsbti .VirtualFileRef
4242import xsbti .compile .{CompilerCache => _ , ScalaInstance => _ , _ }
43+ import scala .util .Try
4344
4445case class CompileInputs (
4546 scalaInstance : ScalaInstance ,
@@ -319,6 +320,7 @@ object Compiler {
319320 val classpathOptions = compileInputs.classpathOptions
320321 val compilers = compileInputs.compilerCache.get(
321322 scalaInstance,
323+ classpathOptions,
322324 compileInputs.javacBin,
323325 compileInputs.javacOptions.toList
324326 )
@@ -451,11 +453,12 @@ object Compiler {
451453
452454 val backgroundTasks = new CompileBackgroundTasks {
453455 def trigger (
454- clientClassesDir : AbsolutePath ,
456+ clientClassesObserver : ClientClassesObserver ,
455457 clientReporter : Reporter ,
456458 clientTracer : BraveTracer ,
457459 clientLogger : Logger
458460 ): Task [Unit ] = Task .defer {
461+ val clientClassesDir = clientClassesObserver.classesDir
459462 clientLogger.debug(s " Triggering background tasks for $clientClassesDir" )
460463 val updateClientState =
461464 updateExternalClassesDirWithReadOnly(clientClassesDir, clientTracer, clientLogger)
@@ -471,10 +474,20 @@ object Compiler {
471474 }
472475
473476 val deleteNewClassesDir = Task (BloopPaths .delete(AbsolutePath (newClassesDir)))
474- val allTasks = List (deleteNewClassesDir, updateClientState, writeAnalysisIfMissing)
477+ val publishClientAnalysis = Task {
478+ rebaseAnalysisClassFiles(
479+ analysis,
480+ readOnlyClassesDir,
481+ clientClassesDir.underlying,
482+ sourcesWithFatal
483+ )
484+ }
485+ .flatMap(clientClassesObserver.nextAnalysis)
475486 Task
476- .gatherUnordered(allTasks)
477- .map(_ => ())
487+ .gatherUnordered(
488+ List (deleteNewClassesDir, updateClientState, writeAnalysisIfMissing)
489+ )
490+ .flatMap(_ => publishClientAnalysis)
478491 .onErrorHandleWith(err => {
479492 clientLogger.debug(" Caught error in background tasks" ); clientLogger.trace(err);
480493 Task .raiseError(err)
@@ -494,14 +507,12 @@ object Compiler {
494507 )
495508 } else {
496509 val allGeneratedProducts = allGeneratedRelativeClassFilePaths.toMap
497- val analysisForFutureCompilationRuns = {
498- rebaseAnalysisClassFiles(
499- analysis,
500- readOnlyClassesDir,
501- newClassesDir,
502- sourcesWithFatal
503- )
504- }
510+ val analysisForFutureCompilationRuns = rebaseAnalysisClassFiles(
511+ analysis,
512+ readOnlyClassesDir,
513+ newClassesDir,
514+ sourcesWithFatal
515+ )
505516
506517 val resultForFutureCompilationRuns = {
507518 resultForDependentCompilationsInSameRun.withAnalysis(
@@ -516,12 +527,12 @@ object Compiler {
516527 // Schedule the tasks to run concurrently after the compilation end
517528 val backgroundTasksExecution = new CompileBackgroundTasks {
518529 def trigger (
519- clientClassesDir : AbsolutePath ,
530+ clientClassesObserver : ClientClassesObserver ,
520531 clientReporter : Reporter ,
521532 clientTracer : BraveTracer ,
522533 clientLogger : Logger
523534 ): Task [Unit ] = {
524- val clientClassesDirPath = clientClassesDir.toString
535+ val clientClassesDir = clientClassesObserver.classesDir
525536 val successBackgroundTasks =
526537 backgroundTasksWhenNewSuccessfulAnalysis
527538 .map(f => f(clientClassesDir, clientReporter, clientTracer))
@@ -542,15 +553,26 @@ object Compiler {
542553 val syntax = path.syntax
543554 if (syntax.startsWith(readOnlyClassesDirPath)) {
544555 val rebasedFile = AbsolutePath (
545- syntax.replace(readOnlyClassesDirPath, clientClassesDirPath )
556+ syntax.replace(readOnlyClassesDirPath, clientClassesDir.toString )
546557 )
547558 if (rebasedFile.exists) {
548559 Files .delete(rebasedFile.underlying)
549560 }
550561 }
551562 }
552563 }
553- Task .gatherUnordered(List (firstTask, secondTask)).map(_ => ())
564+
565+ val publishClientAnalysis = Task {
566+ rebaseAnalysisClassFiles(
567+ analysis,
568+ newClassesDir,
569+ clientClassesDir.underlying,
570+ sourcesWithFatal
571+ )
572+ }.flatMap(clientClassesObserver.nextAnalysis)
573+ Task
574+ .gatherUnordered(List (firstTask, secondTask))
575+ .flatMap(_ => publishClientAnalysis)
554576 }
555577
556578 allClientSyncTasks.doOnFinish(_ => Task (clientReporter.reportEndCompilation()))
@@ -632,25 +654,33 @@ object Compiler {
632654 case None => scalacOptions
633655 case Some (_) if existsReleaseSetting || sameHome => scalacOptions
634656 case Some (version) =>
635- try {
636- val numVer = if (version.startsWith(" 1.8" )) 8 else version.takeWhile(_.isDigit).toInt
637- val bloopNumVer = JavaRuntime .version.takeWhile(_.isDigit).toInt
638- if (bloopNumVer > numVer) {
639- scalacOptions ++ List (" -release" , numVer.toString())
640- } else {
641- logger.warn(
642- s " Bloop is runing with ${JavaRuntime .version} but your code requires $version to compile, " +
643- " this might cause some compilation issues when using JDK API unsupported by the Bloop's current JVM version"
644- )
645- scalacOptions
657+ val options : Option [Array [String ]] =
658+ for {
659+ numVer <- parseJavaVersion(version)
660+ bloopNumVer <- parseJavaVersion(JavaRuntime .version)
661+ if (bloopNumVer >= 9 && numVer != bloopNumVer)
662+ } yield {
663+ if (bloopNumVer > numVer) {
664+ scalacOptions ++ List (" -release" , numVer.toString())
665+ } else {
666+ logger.warn(
667+ s " Bloop is running with ${JavaRuntime .version} but your code requires $version to compile, " +
668+ " this might cause some compilation issues when using JDK API unsupported by the Bloop's current JVM version"
669+ )
670+ scalacOptions
671+ }
646672 }
647- } catch {
648- case NonFatal (_) =>
649- scalacOptions
650- }
673+ options.getOrElse(scalacOptions)
651674 }
652675 }
653676
677+ private def parseJavaVersion (version : String ): Option [Int ] =
678+ version.split('-' ).head.split('.' ).toList match {
679+ case " 1" :: minor :: _ => Try (minor.toInt).toOption
680+ case single :: _ => Try (single.toInt).toOption
681+ case _ => None
682+ }
683+
654684 private def getCompilationOptions (
655685 inputs : CompileInputs ,
656686 logger : Logger ,
@@ -688,11 +718,12 @@ object Compiler {
688718 ): CompileBackgroundTasks = {
689719 new CompileBackgroundTasks {
690720 def trigger (
691- clientClassesDir : AbsolutePath ,
721+ clientClassesObserver : ClientClassesObserver ,
692722 clientReporter : Reporter ,
693723 tracer : BraveTracer ,
694724 clientLogger : Logger
695725 ): Task [Unit ] = {
726+ val clientClassesDir = clientClassesObserver.classesDir
696727 val backgroundTasks = tasks.map(f => f(clientClassesDir, clientReporter, tracer))
697728 Task .gatherUnordered(backgroundTasks).memoize.map(_ => ())
698729 }
@@ -780,19 +811,19 @@ object Compiler {
780811 */
781812 def rebaseAnalysisClassFiles (
782813 analysis0 : CompileAnalysis ,
783- readOnlyClassesDir : Path ,
784- newClassesDir : Path ,
814+ origin : Path ,
815+ target : Path ,
785816 sourceFilesWithFatalWarnings : scala.collection.Set [File ]
786817 ): Analysis = {
787818 // Cast to the only internal analysis that we support
788819 val analysis = analysis0.asInstanceOf [Analysis ]
789820 def rebase (file : VirtualFileRef ): VirtualFileRef = {
790821
791822 val filePath = converter.toPath(file).toAbsolutePath()
792- if (! filePath.startsWith(readOnlyClassesDir )) file
823+ if (! filePath.startsWith(origin )) file
793824 else {
794825 // Hash for class file is the same because the copy duplicates metadata
795- val path = newClassesDir .resolve(readOnlyClassesDir .relativize(filePath))
826+ val path = target .resolve(origin .relativize(filePath))
796827 converter.toVirtualFile(path)
797828 }
798829 }
0 commit comments