@@ -40,6 +40,7 @@ import sbt.util.InterfaceUtil
40
40
import xsbti .T2
41
41
import xsbti .VirtualFileRef
42
42
import xsbti .compile .{CompilerCache => _ , ScalaInstance => _ , _ }
43
+ import scala .util .Try
43
44
44
45
case class CompileInputs (
45
46
scalaInstance : ScalaInstance ,
@@ -319,6 +320,7 @@ object Compiler {
319
320
val classpathOptions = compileInputs.classpathOptions
320
321
val compilers = compileInputs.compilerCache.get(
321
322
scalaInstance,
323
+ classpathOptions,
322
324
compileInputs.javacBin,
323
325
compileInputs.javacOptions.toList
324
326
)
@@ -451,11 +453,12 @@ object Compiler {
451
453
452
454
val backgroundTasks = new CompileBackgroundTasks {
453
455
def trigger (
454
- clientClassesDir : AbsolutePath ,
456
+ clientClassesObserver : ClientClassesObserver ,
455
457
clientReporter : Reporter ,
456
458
clientTracer : BraveTracer ,
457
459
clientLogger : Logger
458
460
): Task [Unit ] = Task .defer {
461
+ val clientClassesDir = clientClassesObserver.classesDir
459
462
clientLogger.debug(s " Triggering background tasks for $clientClassesDir" )
460
463
val updateClientState =
461
464
updateExternalClassesDirWithReadOnly(clientClassesDir, clientTracer, clientLogger)
@@ -471,10 +474,20 @@ object Compiler {
471
474
}
472
475
473
476
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)
475
486
Task
476
- .gatherUnordered(allTasks)
477
- .map(_ => ())
487
+ .gatherUnordered(
488
+ List (deleteNewClassesDir, updateClientState, writeAnalysisIfMissing)
489
+ )
490
+ .flatMap(_ => publishClientAnalysis)
478
491
.onErrorHandleWith(err => {
479
492
clientLogger.debug(" Caught error in background tasks" ); clientLogger.trace(err);
480
493
Task .raiseError(err)
@@ -494,14 +507,12 @@ object Compiler {
494
507
)
495
508
} else {
496
509
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
+ )
505
516
506
517
val resultForFutureCompilationRuns = {
507
518
resultForDependentCompilationsInSameRun.withAnalysis(
@@ -516,12 +527,12 @@ object Compiler {
516
527
// Schedule the tasks to run concurrently after the compilation end
517
528
val backgroundTasksExecution = new CompileBackgroundTasks {
518
529
def trigger (
519
- clientClassesDir : AbsolutePath ,
530
+ clientClassesObserver : ClientClassesObserver ,
520
531
clientReporter : Reporter ,
521
532
clientTracer : BraveTracer ,
522
533
clientLogger : Logger
523
534
): Task [Unit ] = {
524
- val clientClassesDirPath = clientClassesDir.toString
535
+ val clientClassesDir = clientClassesObserver.classesDir
525
536
val successBackgroundTasks =
526
537
backgroundTasksWhenNewSuccessfulAnalysis
527
538
.map(f => f(clientClassesDir, clientReporter, clientTracer))
@@ -542,15 +553,26 @@ object Compiler {
542
553
val syntax = path.syntax
543
554
if (syntax.startsWith(readOnlyClassesDirPath)) {
544
555
val rebasedFile = AbsolutePath (
545
- syntax.replace(readOnlyClassesDirPath, clientClassesDirPath )
556
+ syntax.replace(readOnlyClassesDirPath, clientClassesDir.toString )
546
557
)
547
558
if (rebasedFile.exists) {
548
559
Files .delete(rebasedFile.underlying)
549
560
}
550
561
}
551
562
}
552
563
}
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)
554
576
}
555
577
556
578
allClientSyncTasks.doOnFinish(_ => Task (clientReporter.reportEndCompilation()))
@@ -632,25 +654,33 @@ object Compiler {
632
654
case None => scalacOptions
633
655
case Some (_) if existsReleaseSetting || sameHome => scalacOptions
634
656
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
+ }
646
672
}
647
- } catch {
648
- case NonFatal (_) =>
649
- scalacOptions
650
- }
673
+ options.getOrElse(scalacOptions)
651
674
}
652
675
}
653
676
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
+
654
684
private def getCompilationOptions (
655
685
inputs : CompileInputs ,
656
686
logger : Logger ,
@@ -688,11 +718,12 @@ object Compiler {
688
718
): CompileBackgroundTasks = {
689
719
new CompileBackgroundTasks {
690
720
def trigger (
691
- clientClassesDir : AbsolutePath ,
721
+ clientClassesObserver : ClientClassesObserver ,
692
722
clientReporter : Reporter ,
693
723
tracer : BraveTracer ,
694
724
clientLogger : Logger
695
725
): Task [Unit ] = {
726
+ val clientClassesDir = clientClassesObserver.classesDir
696
727
val backgroundTasks = tasks.map(f => f(clientClassesDir, clientReporter, tracer))
697
728
Task .gatherUnordered(backgroundTasks).memoize.map(_ => ())
698
729
}
@@ -780,19 +811,19 @@ object Compiler {
780
811
*/
781
812
def rebaseAnalysisClassFiles (
782
813
analysis0 : CompileAnalysis ,
783
- readOnlyClassesDir : Path ,
784
- newClassesDir : Path ,
814
+ origin : Path ,
815
+ target : Path ,
785
816
sourceFilesWithFatalWarnings : scala.collection.Set [File ]
786
817
): Analysis = {
787
818
// Cast to the only internal analysis that we support
788
819
val analysis = analysis0.asInstanceOf [Analysis ]
789
820
def rebase (file : VirtualFileRef ): VirtualFileRef = {
790
821
791
822
val filePath = converter.toPath(file).toAbsolutePath()
792
- if (! filePath.startsWith(readOnlyClassesDir )) file
823
+ if (! filePath.startsWith(origin )) file
793
824
else {
794
825
// 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))
796
827
converter.toVirtualFile(path)
797
828
}
798
829
}
0 commit comments