@@ -452,11 +452,12 @@ object Compiler {
452
452
453
453
val backgroundTasks = new CompileBackgroundTasks {
454
454
def trigger (
455
- clientClassesDir : AbsolutePath ,
455
+ clientClassesObserver : ClientClassesObserver ,
456
456
clientReporter : Reporter ,
457
457
clientTracer : BraveTracer ,
458
458
clientLogger : Logger
459
459
): Task [Unit ] = Task .defer {
460
+ val clientClassesDir = clientClassesObserver.classesDir
460
461
clientLogger.debug(s " Triggering background tasks for $clientClassesDir" )
461
462
val updateClientState =
462
463
updateExternalClassesDirWithReadOnly(clientClassesDir, clientTracer, clientLogger)
@@ -472,10 +473,20 @@ object Compiler {
472
473
}
473
474
474
475
val deleteNewClassesDir = Task (BloopPaths .delete(AbsolutePath (newClassesDir)))
475
- val allTasks = List (deleteNewClassesDir, updateClientState, writeAnalysisIfMissing)
476
+ val publishClientAnalysis = Task {
477
+ rebaseAnalysisClassFiles(
478
+ analysis,
479
+ readOnlyClassesDir,
480
+ clientClassesDir.underlying,
481
+ sourcesWithFatal
482
+ )
483
+ }
484
+ .flatMap(clientClassesObserver.nextAnalysis)
476
485
Task
477
- .gatherUnordered(allTasks)
478
- .map(_ => ())
486
+ .gatherUnordered(
487
+ List (deleteNewClassesDir, updateClientState, writeAnalysisIfMissing)
488
+ )
489
+ .flatMap(_ => publishClientAnalysis)
479
490
.onErrorHandleWith(err => {
480
491
clientLogger.debug(" Caught error in background tasks" ); clientLogger.trace(err);
481
492
Task .raiseError(err)
@@ -495,14 +506,12 @@ object Compiler {
495
506
)
496
507
} else {
497
508
val allGeneratedProducts = allGeneratedRelativeClassFilePaths.toMap
498
- val analysisForFutureCompilationRuns = {
499
- rebaseAnalysisClassFiles(
500
- analysis,
501
- readOnlyClassesDir,
502
- newClassesDir,
503
- sourcesWithFatal
504
- )
505
- }
509
+ val analysisForFutureCompilationRuns = rebaseAnalysisClassFiles(
510
+ analysis,
511
+ readOnlyClassesDir,
512
+ newClassesDir,
513
+ sourcesWithFatal
514
+ )
506
515
507
516
val resultForFutureCompilationRuns = {
508
517
resultForDependentCompilationsInSameRun.withAnalysis(
@@ -517,12 +526,12 @@ object Compiler {
517
526
// Schedule the tasks to run concurrently after the compilation end
518
527
val backgroundTasksExecution = new CompileBackgroundTasks {
519
528
def trigger (
520
- clientClassesDir : AbsolutePath ,
529
+ clientClassesObserver : ClientClassesObserver ,
521
530
clientReporter : Reporter ,
522
531
clientTracer : BraveTracer ,
523
532
clientLogger : Logger
524
533
): Task [Unit ] = {
525
- val clientClassesDirPath = clientClassesDir.toString
534
+ val clientClassesDir = clientClassesObserver.classesDir
526
535
val successBackgroundTasks =
527
536
backgroundTasksWhenNewSuccessfulAnalysis
528
537
.map(f => f(clientClassesDir, clientReporter, clientTracer))
@@ -543,15 +552,26 @@ object Compiler {
543
552
val syntax = path.syntax
544
553
if (syntax.startsWith(readOnlyClassesDirPath)) {
545
554
val rebasedFile = AbsolutePath (
546
- syntax.replace(readOnlyClassesDirPath, clientClassesDirPath )
555
+ syntax.replace(readOnlyClassesDirPath, clientClassesDir.toString )
547
556
)
548
557
if (rebasedFile.exists) {
549
558
Files .delete(rebasedFile.underlying)
550
559
}
551
560
}
552
561
}
553
562
}
554
- Task .gatherUnordered(List (firstTask, secondTask)).map(_ => ())
563
+
564
+ val publishClientAnalysis = Task {
565
+ rebaseAnalysisClassFiles(
566
+ analysis,
567
+ newClassesDir,
568
+ clientClassesDir.underlying,
569
+ sourcesWithFatal
570
+ )
571
+ }.flatMap(clientClassesObserver.nextAnalysis)
572
+ Task
573
+ .gatherUnordered(List (firstTask, secondTask))
574
+ .flatMap(_ => publishClientAnalysis)
555
575
}
556
576
557
577
allClientSyncTasks.doOnFinish(_ => Task (clientReporter.reportEndCompilation()))
@@ -691,11 +711,12 @@ object Compiler {
691
711
): CompileBackgroundTasks = {
692
712
new CompileBackgroundTasks {
693
713
def trigger (
694
- clientClassesDir : AbsolutePath ,
714
+ clientClassesObserver : ClientClassesObserver ,
695
715
clientReporter : Reporter ,
696
716
tracer : BraveTracer ,
697
717
clientLogger : Logger
698
718
): Task [Unit ] = {
719
+ val clientClassesDir = clientClassesObserver.classesDir
699
720
val backgroundTasks = tasks.map(f => f(clientClassesDir, clientReporter, tracer))
700
721
Task .gatherUnordered(backgroundTasks).memoize.map(_ => ())
701
722
}
@@ -783,19 +804,19 @@ object Compiler {
783
804
*/
784
805
def rebaseAnalysisClassFiles (
785
806
analysis0 : CompileAnalysis ,
786
- readOnlyClassesDir : Path ,
787
- newClassesDir : Path ,
807
+ origin : Path ,
808
+ target : Path ,
788
809
sourceFilesWithFatalWarnings : scala.collection.Set [File ]
789
810
): Analysis = {
790
811
// Cast to the only internal analysis that we support
791
812
val analysis = analysis0.asInstanceOf [Analysis ]
792
813
def rebase (file : VirtualFileRef ): VirtualFileRef = {
793
814
794
815
val filePath = converter.toPath(file).toAbsolutePath()
795
- if (! filePath.startsWith(readOnlyClassesDir )) file
816
+ if (! filePath.startsWith(origin )) file
796
817
else {
797
818
// Hash for class file is the same because the copy duplicates metadata
798
- val path = newClassesDir .resolve(readOnlyClassesDir .relativize(filePath))
819
+ val path = target .resolve(origin .relativize(filePath))
799
820
converter.toVirtualFile(path)
800
821
}
801
822
}
0 commit comments