Don't use global state for keeping incremental compilation state
Previously IC state was stored in System properties. As result parallel compilation might cause incorrect state of IC, what led to corruption of kotlin_module files. Now IC state is stored via CompilerArguments and CompilerConfiguration #KT-46038 Fixed
This commit is contained in:
+3
@@ -394,6 +394,9 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
)
|
||||
var normalizeAbsolutePath: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(value = "-Xenable-incremental-compilation", description = "Enable incremental compilation")
|
||||
var incrementalCompilation: Boolean? by FreezableVar(null)
|
||||
|
||||
open fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> {
|
||||
return HashMap<AnalysisFlag<*>, Any>().apply {
|
||||
put(AnalysisFlags.skipMetadataVersionCheck, skipMetadataVersionCheck)
|
||||
|
||||
@@ -66,6 +66,7 @@ import java.util.stream.Collectors;
|
||||
import static org.jetbrains.kotlin.cli.common.ExitCode.COMPILATION_ERROR;
|
||||
import static org.jetbrains.kotlin.cli.common.ExitCode.OK;
|
||||
import static org.jetbrains.kotlin.cli.common.UtilsKt.getLibraryFromHome;
|
||||
import static org.jetbrains.kotlin.cli.common.UtilsKt.incrementalCompilationIsEnabledForJs;
|
||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*;
|
||||
|
||||
public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
@@ -181,7 +182,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
if (arguments.getFreeArgs().isEmpty() && !IncrementalCompilation.isEnabledForJs()) {
|
||||
if (arguments.getFreeArgs().isEmpty() && (!incrementalCompilationIsEnabledForJs(arguments))) {
|
||||
if (arguments.getVersion()) {
|
||||
return OK;
|
||||
}
|
||||
@@ -219,7 +220,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
return ExitCode.COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
if (sourcesFiles.isEmpty() && !IncrementalCompilation.isEnabledForJs()) {
|
||||
if (sourcesFiles.isEmpty() && !incrementalCompilationIsEnabledForJs(arguments)) {
|
||||
messageCollector.report(ERROR, "No source files", null);
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
return scriptingEvaluator.eval(arguments, configuration, projectEnv)
|
||||
}
|
||||
|
||||
if (arguments.freeArgs.isEmpty() && !IncrementalCompilation.isEnabledForJs()) {
|
||||
if (arguments.freeArgs.isEmpty() && !(incrementalCompilationIsEnabledForJs(arguments))) {
|
||||
if (arguments.version) {
|
||||
return OK
|
||||
}
|
||||
@@ -166,7 +166,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
return ExitCode.COMPILATION_ERROR
|
||||
}
|
||||
|
||||
if (sourcesFiles.isEmpty() && !IncrementalCompilation.isEnabledForJs() && arguments.includes.isNullOrEmpty()) {
|
||||
if (sourcesFiles.isEmpty() && (!incrementalCompilationIsEnabledForJs(arguments)) && arguments.includes.isNullOrEmpty()) {
|
||||
messageCollector.report(ERROR, "No source files", null)
|
||||
return COMPILATION_ERROR
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ fun <A : CommonCompilerArguments> CompilerConfiguration.setupCommonArguments(
|
||||
put(CommonConfigurationKeys.EXPECT_ACTUAL_LINKER, arguments.expectActualLinker)
|
||||
putIfNotNull(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, arguments.intellijPluginRoot)
|
||||
put(CommonConfigurationKeys.REPORT_OUTPUT_FILES, arguments.reportOutputFiles)
|
||||
put(CommonConfigurationKeys.INCREMENTAL_COMPILATION, incrementalCompilationIsEnabled(arguments))
|
||||
|
||||
val metadataVersionString = arguments.metadataVersion
|
||||
if (metadataVersionString != null) {
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.common
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageUtil
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.IncrementalCompilation
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.isSubpackageOf
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
@@ -28,6 +30,14 @@ import org.jetbrains.kotlin.utils.KotlinPaths
|
||||
import java.io.File
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
fun incrementalCompilationIsEnabled(arguments: CommonCompilerArguments): Boolean {
|
||||
return arguments.incrementalCompilation ?: IncrementalCompilation.isEnabledForJvm()
|
||||
}
|
||||
|
||||
fun incrementalCompilationIsEnabledForJs(arguments: CommonCompilerArguments): Boolean {
|
||||
return arguments.incrementalCompilation ?: IncrementalCompilation.isEnabledForJs()
|
||||
}
|
||||
|
||||
fun checkKotlinPackageUsage(configuration: CompilerConfiguration, files: Collection<KtFile>): Boolean {
|
||||
if (configuration.getBoolean(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE)) {
|
||||
return true
|
||||
|
||||
@@ -240,7 +240,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
configuration: CompilerConfiguration, arguments: K2JVMCompilerArguments, services: Services
|
||||
) {
|
||||
with(configuration) {
|
||||
if (IncrementalCompilation.isEnabledForJvm()) {
|
||||
if (incrementalCompilationIsEnabled(arguments)) {
|
||||
putIfNotNull(CommonConfigurationKeys.LOOKUP_TRACKER, services[LookupTracker::class.java])
|
||||
|
||||
putIfNotNull(CommonConfigurationKeys.EXPECT_ACTUAL_TRACKER, services[ExpectActualTracker::class.java])
|
||||
|
||||
Reference in New Issue
Block a user