[JPS] Fix JS incremental compilation
Disable Idea JPS build mechanism for marking all sources of common output if one of them is dirty Add source-to-outputs map for correctly removing Kotlin/JS outputs #KT-45763 Fixed #KT-44351 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
c2389a94fa
commit
5f4be07225
@@ -25,6 +25,7 @@ import org.jetbrains.jps.builders.java.JavaBuilderUtil
|
||||
import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor
|
||||
import org.jetbrains.jps.builders.storage.BuildDataCorruptedException
|
||||
import org.jetbrains.jps.incremental.*
|
||||
import org.jetbrains.jps.incremental.BuildOperations.deleteRecursively
|
||||
import org.jetbrains.jps.incremental.ModuleLevelBuilder.ExitCode.*
|
||||
import org.jetbrains.jps.incremental.java.JavaBuilder
|
||||
import org.jetbrains.jps.model.JpsProject
|
||||
@@ -32,8 +33,8 @@ import org.jetbrains.kotlin.build.GeneratedFile
|
||||
import org.jetbrains.kotlin.build.GeneratedJvmClass
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.INFO
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil
|
||||
import org.jetbrains.kotlin.compilerRunner.*
|
||||
import org.jetbrains.kotlin.config.IncrementalCompilation
|
||||
@@ -291,7 +292,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
||||
if (chunk.modules.any { it.kotlinKind == KotlinModuleKind.SOURCE_SET_HOLDER }) {
|
||||
if (chunk.modules.size > 1) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.ERROR,
|
||||
ERROR,
|
||||
"Cyclically dependent modules are not supported in multiplatform projects"
|
||||
)
|
||||
return ABORT
|
||||
@@ -410,6 +411,8 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
||||
kotlinDirtyFilesHolder.allRemovedFilesFiles
|
||||
)
|
||||
|
||||
cleanJsOutputs(context, kotlinChunk, incrementalCaches, kotlinDirtyFilesHolder)
|
||||
|
||||
if (LOG.isDebugEnabled) {
|
||||
LOG.debug("Compiling files: ${kotlinDirtyFilesHolder.allDirtyFiles}")
|
||||
}
|
||||
@@ -509,6 +512,43 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
|
||||
return OK
|
||||
}
|
||||
|
||||
private fun cleanJsOutputs(
|
||||
context: CompileContext,
|
||||
kotlinChunk: KotlinChunk,
|
||||
incrementalCaches: Map<KotlinModuleBuildTarget<*>, JpsIncrementalCache>,
|
||||
kotlinDirtyFilesHolder: KotlinDirtySourceFilesHolder
|
||||
) {
|
||||
for (target in kotlinChunk.targets) {
|
||||
val cache = incrementalCaches[target] ?: continue
|
||||
|
||||
if (cache is IncrementalJsCache) {
|
||||
val filesToDelete = mutableListOf<File>()
|
||||
val dirtyFiles = kotlinDirtyFilesHolder.getDirtyFiles(target.jpsModuleBuildTarget).keys
|
||||
val removedFiles = kotlinDirtyFilesHolder.getRemovedFiles(target.jpsModuleBuildTarget)
|
||||
|
||||
for (file: File in dirtyFiles + removedFiles) {
|
||||
filesToDelete.addAll(cache.getOutputsBySource(file).filter { it !in filesToDelete })
|
||||
}
|
||||
|
||||
if (filesToDelete.isNotEmpty()) {
|
||||
val deletedForThisSource = mutableSetOf<String>()
|
||||
val parentDirs = mutableSetOf<File>()
|
||||
|
||||
for (kjsmFile in filesToDelete) {
|
||||
deleteRecursively(kjsmFile.path, deletedForThisSource, parentDirs)
|
||||
}
|
||||
|
||||
FSOperations.pruneEmptyDirs(context, parentDirs)
|
||||
|
||||
val logger = context.loggingManager.projectBuilderLogger
|
||||
if (logger.isEnabled && deletedForThisSource.isNotEmpty()) {
|
||||
logger.logDeletedFiles(deletedForThisSource)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// todo(1.2.80): got rid of ModuleChunk (replace with KotlinChunk)
|
||||
// todo(1.2.80): introduce KotlinRoundCompileContext, move dirtyFilesHolder, fsOperations, environment to it
|
||||
private fun doCompileModuleChunk(
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.jps.targets
|
||||
|
||||
import org.jetbrains.jps.builders.storage.BuildDataPaths
|
||||
import org.jetbrains.jps.incremental.ModuleBuildTarget
|
||||
import org.jetbrains.jps.incremental.ModuleLevelBuilder
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType
|
||||
import org.jetbrains.jps.model.module.JpsModule
|
||||
import org.jetbrains.jps.util.JpsPathUtil
|
||||
@@ -224,7 +225,20 @@ class KotlinJsModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleBu
|
||||
val jsCache = jpsIncrementalCache as IncrementalJsCache
|
||||
jsCache.header = incrementalResults.headerMetadata
|
||||
|
||||
jsCache.updateSourceToOutputMap(files)
|
||||
jsCache.compareAndUpdate(incrementalResults, changesCollector)
|
||||
jsCache.clearCacheForRemovedClasses(changesCollector)
|
||||
}
|
||||
|
||||
override fun registerOutputItems(outputConsumer: ModuleLevelBuilder.OutputConsumer, outputItems: List<GeneratedFile>) {
|
||||
if (isIncrementalCompilationEnabled) {
|
||||
for (output in outputItems) {
|
||||
for (source in output.sourceFiles) {
|
||||
outputConsumer.registerOutputFile(jpsModuleBuildTarget, File("${source.path.hashCode()}"), listOf(source.path))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.registerOutputItems(outputConsumer, outputItems)
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-5
@@ -3,11 +3,6 @@
|
||||
Building module1
|
||||
Exit code: NOTHING_DONE
|
||||
------------------------------------------
|
||||
Cleaning output files:
|
||||
out/production/module2/module2.js
|
||||
out/production/module2/module2.meta.js
|
||||
out/production/module2/module2/foo/foo.kjsm
|
||||
End of files
|
||||
Building module2
|
||||
Marked as dirty by Kotlin:
|
||||
module2/src/B.kt
|
||||
@@ -16,6 +11,9 @@ Marked as dirty by Kotlin:
|
||||
module2/src/useAfoo.kt
|
||||
module2/src/useBbar.kt
|
||||
Cleaning output files:
|
||||
out/production/module2/module2.js
|
||||
out/production/module2/module2.meta.js
|
||||
out/production/module2/module2/foo/foo.kjsm
|
||||
out/production/module2/module2/use/use.kjsm
|
||||
End of files
|
||||
Compiling files:
|
||||
|
||||
Vendored
+3
-5
@@ -11,15 +11,13 @@ Exit code: ADDITIONAL_PASS_REQUIRED
|
||||
------------------------------------------
|
||||
Exit code: NOTHING_DONE
|
||||
------------------------------------------
|
||||
Cleaning output files:
|
||||
out/production/module2/module2.js
|
||||
out/production/module2/module2.meta.js
|
||||
out/production/module2/module2/b/b.kjsm
|
||||
End of files
|
||||
Building module2
|
||||
Marked as dirty by Kotlin:
|
||||
module2/src/useClassB.kt
|
||||
Cleaning output files:
|
||||
out/production/module2/module2.js
|
||||
out/production/module2/module2.meta.js
|
||||
out/production/module2/module2/b/b.kjsm
|
||||
out/production/module2/module2/usage/usage.kjsm
|
||||
End of files
|
||||
Compiling files:
|
||||
|
||||
+1
-1
@@ -63,12 +63,12 @@ Exit code: NOTHING_DONE
|
||||
Building pNative1
|
||||
Exit code: NOTHING_DONE
|
||||
------------------------------------------
|
||||
Building pJs
|
||||
Cleaning output files:
|
||||
out/production/pJs/pJs.js
|
||||
out/production/pJs/pJs.meta.js
|
||||
out/production/pJs/pJs/root-package.kjsm
|
||||
End of files
|
||||
Building pJs
|
||||
Compiling files:
|
||||
End of files
|
||||
Exit code: OK
|
||||
|
||||
+1
-1
@@ -48,12 +48,12 @@ Exit code: OK
|
||||
Building c
|
||||
Exit code: NOTHING_DONE
|
||||
------------------------------------------
|
||||
Building pJs
|
||||
Cleaning output files:
|
||||
out/production/pJs/pJs.js
|
||||
out/production/pJs/pJs.meta.js
|
||||
out/production/pJs/pJs/root-package.kjsm
|
||||
End of files
|
||||
Building pJs
|
||||
Compiling files:
|
||||
End of files
|
||||
Exit code: OK
|
||||
|
||||
+1
-1
@@ -38,12 +38,12 @@ Exit code: NOTHING_DONE
|
||||
Building c
|
||||
Exit code: NOTHING_DONE
|
||||
------------------------------------------
|
||||
Building pJs
|
||||
Cleaning output files:
|
||||
out/production/pJs/pJs.js
|
||||
out/production/pJs/pJs.meta.js
|
||||
out/production/pJs/pJs/root-package.kjsm
|
||||
End of files
|
||||
Building pJs
|
||||
Compiling files:
|
||||
End of files
|
||||
Exit code: OK
|
||||
|
||||
+1
-1
@@ -42,12 +42,12 @@ Exit code: OK
|
||||
================ Step #3 delete new service =================
|
||||
|
||||
Building c
|
||||
Building pJs
|
||||
Cleaning output files:
|
||||
out/production/pJs/pJs.js
|
||||
out/production/pJs/pJs.meta.js
|
||||
out/production/pJs/pJs/root-package.kjsm
|
||||
End of files
|
||||
Building pJs
|
||||
Compiling files:
|
||||
End of files
|
||||
Exit code: OK
|
||||
|
||||
+1
-1
@@ -32,12 +32,12 @@ Exit code: NOTHING_DONE
|
||||
================ Step #3 delete new service =================
|
||||
|
||||
Building c
|
||||
Building pJs
|
||||
Cleaning output files:
|
||||
out/production/pJs/pJs.js
|
||||
out/production/pJs/pJs.meta.js
|
||||
out/production/pJs/pJs/root-package.kjsm
|
||||
End of files
|
||||
Building pJs
|
||||
Compiling files:
|
||||
End of files
|
||||
Exit code: OK
|
||||
|
||||
Reference in New Issue
Block a user