Remove obsolete code about runtime versions conflict

This commit is contained in:
Alexander Udalov
2017-07-07 18:44:18 +03:00
parent 4128064f87
commit c94b21edd5
11 changed files with 28 additions and 118 deletions
@@ -92,19 +92,9 @@ class AnalyzerWithCompilerReport(private val messageCollector: MessageCollector)
return messageCollector.hasErrors()
}
interface Analyzer {
fun analyze(): AnalysisResult
fun reportEnvironmentErrors() {
}
}
fun analyzeAndReport(files: Collection<KtFile>, analyzer: Analyzer) {
analysisResult = analyzer.analyze()
fun analyzeAndReport(files: Collection<KtFile>, analyze: () -> AnalysisResult) {
analysisResult = analyze()
reportSyntaxErrors(files)
if (analysisResult.bindingContext.diagnostics.any { it.isValid && it.severity == Severity.ERROR }) {
analyzer.reportEnvironmentErrors()
}
reportDiagnostics(analysisResult.bindingContext.diagnostics, messageCollector)
reportIncompleteHierarchies()
reportAlternativeSignatureErrors()
@@ -162,7 +162,8 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
return COMPILATION_ERROR;
}
AnalyzerWithCompilerReport analyzerWithCompilerReport = analyzeAndReportErrors(messageCollector, sourcesFiles, config);
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(messageCollector);
analyzerWithCompilerReport.analyzeAndReport(sourcesFiles, () -> TopDownAnalyzerFacadeForJS.analyzeFiles(sourcesFiles, config));
if (analyzerWithCompilerReport.hasErrors()) {
return COMPILATION_ERROR;
}
@@ -280,24 +281,6 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
messageCollector.report(LOGGING, "Compiling source files: " + StringsKt.join(fileNames, ", "), null);
}
private static AnalyzerWithCompilerReport analyzeAndReportErrors(
@NotNull MessageCollector messageCollector, @NotNull List<KtFile> sources, @NotNull JsConfig config
) {
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(messageCollector);
analyzerWithCompilerReport.analyzeAndReport(sources, new AnalyzerWithCompilerReport.Analyzer() {
@NotNull
@Override
public AnalysisResult analyze() {
return TopDownAnalyzerFacadeForJS.analyzeFiles(sources, config);
}
@Override
public void reportEnvironmentErrors() {
}
});
return analyzerWithCompilerReport;
}
@Override
protected void setupPlatformSpecificArgumentsAndServices(
@NotNull CompilerConfiguration configuration, @NotNull K2JSCompilerArguments arguments,
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.cli.jvm.compiler
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.io.JarUtil
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiManager
@@ -34,7 +33,8 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.checkKotlinPackageUsage
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.OUTPUT
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.WARNING
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil
import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAll
@@ -59,14 +59,11 @@ import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.script.tryConstructClassFromStringArgs
import org.jetbrains.kotlin.util.PerformanceCounter
import org.jetbrains.kotlin.utils.KotlinPaths
import org.jetbrains.kotlin.utils.PathUtil
import org.jetbrains.kotlin.utils.newLinkedHashMapWithExpectedSize
import java.io.File
import java.io.IOException
import java.lang.reflect.InvocationTargetException
import java.net.URLClassLoader
import java.util.concurrent.TimeUnit
import java.util.jar.Attributes
object KotlinToJVMBytecodeCompiler {
@@ -365,30 +362,24 @@ object KotlinToJVMBytecodeCompiler {
val analysisStart = PerformanceCounter.currentTime()
val analyzerWithCompilerReport = AnalyzerWithCompilerReport(collector)
analyzerWithCompilerReport.analyzeAndReport(sourceFiles, object : AnalyzerWithCompilerReport.Analyzer {
override fun analyze(): AnalysisResult {
val project = environment.project
val moduleOutputs = environment.configuration.get(JVMConfigurationKeys.MODULES)?.mapNotNull { module ->
environment.findLocalFile(module.getOutputDirectory())
}.orEmpty()
val sourcesOnly = TopDownAnalyzerFacadeForJVM.newModuleSearchScope(project, sourceFiles)
// To support partial and incremental compilation, we add the scope which contains binaries from output directories
// of the compiled modules (.class) to the list of scopes of the source module
val scope = if (moduleOutputs.isEmpty()) sourcesOnly else sourcesOnly.uniteWith(DirectoriesScope(project, moduleOutputs))
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
project,
sourceFiles,
CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(),
environment.configuration,
environment::createPackagePartProvider,
sourceModuleSearchScope = scope
)
}
override fun reportEnvironmentErrors() {
reportRuntimeConflicts(collector, environment.configuration.jvmClasspathRoots)
}
})
analyzerWithCompilerReport.analyzeAndReport(sourceFiles) {
val project = environment.project
val moduleOutputs = environment.configuration.get(JVMConfigurationKeys.MODULES)?.mapNotNull { module ->
environment.findLocalFile(module.getOutputDirectory())
}.orEmpty()
val sourcesOnly = TopDownAnalyzerFacadeForJVM.newModuleSearchScope(project, sourceFiles)
// To support partial and incremental compilation, we add the scope which contains binaries from output directories
// of the compiled modules (.class) to the list of scopes of the source module
val scope = if (moduleOutputs.isEmpty()) sourcesOnly else sourcesOnly.uniteWith(DirectoriesScope(project, moduleOutputs))
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
project,
sourceFiles,
CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(),
environment.configuration,
environment::createPackagePartProvider,
sourceModuleSearchScope = scope
)
}
val analysisNanos = PerformanceCounter.currentTime() - analysisStart
@@ -476,28 +467,4 @@ object KotlinToJVMBytecodeCompiler {
private val KotlinCoreEnvironment.messageCollector: MessageCollector
get() = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
private fun reportRuntimeConflicts(messageCollector: MessageCollector, jvmClasspathRoots: List<File>) {
fun String.removeIdeaVersionSuffix(): String {
val versionIndex = indexOfAny(arrayListOf("-IJ", "-Idea"))
return if (versionIndex >= 0) substring(0, versionIndex) else this
}
val runtimes = jvmClasspathRoots.map {
try {
it.canonicalFile
}
catch (e: IOException) {
it
}
}.filter { it.name == PathUtil.KOTLIN_JAVA_RUNTIME_JAR && it.exists() }
val runtimeVersions = runtimes.map {
JarUtil.getJarAttribute(it, Attributes.Name.IMPLEMENTATION_VERSION).orEmpty().removeIdeaVersionSuffix()
}
if (runtimeVersions.toSet().size > 1) {
messageCollector.report(ERROR, "Conflicting versions of Kotlin runtime on classpath: " + runtimes.joinToString { it.path })
}
}
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.cli.metadata
import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.analyzer.common.DefaultAnalyzerFacade
import org.jetbrains.kotlin.builtins.BuiltInsBinaryVersion
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
@@ -63,11 +62,11 @@ open class MetadataSerializer(private val dependOnOldBuiltIns: Boolean) {
}
val analyzer = AnalyzerWithCompilerReport(messageCollector)
analyzer.analyzeAndReport(files, object : AnalyzerWithCompilerReport.Analyzer {
override fun analyze(): AnalysisResult = DefaultAnalyzerFacade.analyzeFiles(files, moduleName, dependOnOldBuiltIns) {
_, content -> environment.createPackagePartProvider(content.moduleContentScope)
analyzer.analyzeAndReport(files) {
DefaultAnalyzerFacade.analyzeFiles(files, moduleName, dependOnOldBuiltIns) { _, content ->
environment.createPackagePartProvider(content.moduleContentScope)
}
})
}
if (analyzer.hasErrors()) return
@@ -1,5 +0,0 @@
$TESTDATA_DIR$/conflictingRuntimeVersions.kt
-classpath
$TESTDATA_DIR$/kotlin-runtime-4584-stub/kotlin-runtime.jar
-d
$TEMP_DIR$
@@ -1,5 +0,0 @@
error: conflicting versions of Kotlin runtime on classpath: $TESTDATA_DIR$/kotlin-runtime-4584-stub/kotlin-runtime.jar, $PROJECT_DIR$/lib/kotlin-runtime.jar
compiler/testData/cli/jvm/conflictingRuntimeVersions.kt:1:9: error: unresolved reference: unresolvedFunction
val f = unresolvedFunction()
^
COMPILATION_ERROR
@@ -1,5 +0,0 @@
$TESTDATA_DIR$/simple.kt
-classpath
$TESTDATA_DIR$/kotlin-runtime-4584-stub/kotlin-runtime.jar
-d
$TEMP_DIR$
@@ -1 +0,0 @@
OK
@@ -1 +0,0 @@
val f = unresolvedFunction()
@@ -116,18 +116,6 @@ public class CliTestGenerated extends AbstractCliTest {
doJvmTest(fileName);
}
@TestMetadata("conflictingRuntimeVersion.args")
public void testConflictingRuntimeVersion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/conflictingRuntimeVersion.args");
doJvmTest(fileName);
}
@TestMetadata("conflictingRuntimeVersionNoError.args")
public void testConflictingRuntimeVersionNoError() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/conflictingRuntimeVersionNoError.args");
doJvmTest(fileName);
}
@TestMetadata("coroutinesEnable.args")
public void testCoroutinesEnable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/coroutinesEnable.args");