FIR: implement proper exit on errors in new cli pipeline

This commit is contained in:
Ilya Chernikov
2022-01-31 19:12:02 +01:00
committed by teamcity
parent f89765eb33
commit 090a451902
2 changed files with 18 additions and 6 deletions
@@ -258,3 +258,7 @@ object FirDiagnosticsCompilerResultsReporter {
} }
} }
} }
fun BaseDiagnosticsCollector.reportToMessageCollector(messageCollector: MessageCollector, renderDiagnosticName: Boolean) {
FirDiagnosticsCompilerResultsReporter.reportToMessageCollector(this, messageCollector, renderDiagnosticName)
}
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmGeneratorExtensionsImpl
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots
import org.jetbrains.kotlin.cli.common.fir.FirDiagnosticsCompilerResultsReporter import org.jetbrains.kotlin.cli.common.fir.reportToMessageCollector
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.* import org.jetbrains.kotlin.cli.jvm.compiler.*
@@ -110,6 +110,7 @@ fun compileModulesUsingFrontendIrAndLightTree(
else platformSources.add(file) else platformSources.add(file)
} }
val renderDiagnosticName = moduleConfiguration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME)
val diagnosticsReporter = DiagnosticReporterFactory.createReporter() val diagnosticsReporter = DiagnosticReporterFactory.createReporter()
val compilerInput = ModuleCompilerInput( val compilerInput = ModuleCompilerInput(
@@ -126,6 +127,12 @@ fun compileModulesUsingFrontendIrAndLightTree(
null, null,
diagnosticsReporter diagnosticsReporter
) )
if (diagnosticsReporter.hasErrors) {
diagnosticsReporter.reportToMessageCollector(messageCollector, renderDiagnosticName)
continue
}
// TODO: consider what to do if many modules has main classes // TODO: consider what to do if many modules has main classes
if (mainClassFqName == null && moduleConfiguration.get(JVMConfigurationKeys.OUTPUT_JAR) != null) { if (mainClassFqName == null && moduleConfiguration.get(JVMConfigurationKeys.OUTPUT_JAR) != null) {
mainClassFqName = findMainClass(analysisResults.fir) mainClassFqName = findMainClass(analysisResults.fir)
@@ -134,12 +141,13 @@ fun compileModulesUsingFrontendIrAndLightTree(
val irInput = convertAnalyzedFirToIr(compilerInput, analysisResults, compilerEnvironment) val irInput = convertAnalyzedFirToIr(compilerInput, analysisResults, compilerEnvironment)
val codegenOutput = generateCodeFromIr(irInput, compilerEnvironment) val codegenOutput = generateCodeFromIr(irInput, compilerEnvironment)
FirDiagnosticsCompilerResultsReporter.reportToMessageCollector( diagnosticsReporter.reportToMessageCollector(
diagnosticsReporter, messageCollector, moduleConfiguration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME)
messageCollector,
moduleConfiguration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME)
) )
outputs.add(codegenOutput.generationState)
if (!diagnosticsReporter.hasErrors) {
outputs.add(codegenOutput.generationState)
}
} }
return writeOutputs( return writeOutputs(