kapt: Stop compiler gracefully
This commit is contained in:
@@ -152,9 +152,6 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
Disposer.dispose(rootDisposable);
|
Disposer.dispose(rootDisposable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (CompilationInterruptedException e) {
|
|
||||||
return e.exitCode;
|
|
||||||
}
|
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
groupingCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(t),
|
groupingCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(t),
|
||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
@@ -204,12 +201,4 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
return INTERNAL_ERROR;
|
return INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CompilationInterruptedException extends RuntimeException {
|
|
||||||
final ExitCode exitCode;
|
|
||||||
|
|
||||||
public CompilationInterruptedException(ExitCode exitCode) {
|
|
||||||
this.exitCode = exitCode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -287,6 +287,8 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!result.getShouldGenerateCode()) return null;
|
||||||
|
|
||||||
result.throwIfError();
|
result.throwIfError();
|
||||||
|
|
||||||
return generate(environment, result, environment.getSourceFiles(), null, null);
|
return generate(environment, result, environment.getSourceFiles(), null, null);
|
||||||
|
|||||||
+2
-1
@@ -155,7 +155,8 @@ public enum TopDownAnalyzerFacadeForJVM {
|
|||||||
AnalysisCompletedHandlerExtension.Companion.getInstances(moduleContext.getProject());
|
AnalysisCompletedHandlerExtension.Companion.getInstances(moduleContext.getProject());
|
||||||
|
|
||||||
for (AnalysisCompletedHandlerExtension extension : analysisCompletedHandlerExtensions) {
|
for (AnalysisCompletedHandlerExtension extension : analysisCompletedHandlerExtensions) {
|
||||||
extension.analysisCompleted(project, module, bindingContext, files);
|
AnalysisResult result = extension.analysisCompleted(project, module, bindingContext, files);
|
||||||
|
if (result != null) return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return AnalysisResult.success(bindingContext, module);
|
return AnalysisResult.success(bindingContext, module);
|
||||||
|
|||||||
+2
-1
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.resolve.jvm.extensions
|
package org.jetbrains.kotlin.resolve.jvm.extensions
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
||||||
@@ -33,5 +34,5 @@ public interface AnalysisCompletedHandlerExtension {
|
|||||||
project: Project,
|
project: Project,
|
||||||
module: ModuleDescriptor,
|
module: ModuleDescriptor,
|
||||||
bindingContext: BindingContext,
|
bindingContext: BindingContext,
|
||||||
files: Collection<JetFile>)
|
files: Collection<JetFile>): AnalysisResult?
|
||||||
}
|
}
|
||||||
@@ -21,9 +21,10 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
import org.jetbrains.kotlin.types.ErrorUtils
|
import org.jetbrains.kotlin.types.ErrorUtils
|
||||||
import kotlin.platform.platformStatic
|
import kotlin.platform.platformStatic
|
||||||
|
|
||||||
public data open class AnalysisResult protected (
|
public data open class AnalysisResult protected constructor(
|
||||||
public val bindingContext: BindingContext,
|
public val bindingContext: BindingContext,
|
||||||
public val moduleDescriptor: ModuleDescriptor
|
public val moduleDescriptor: ModuleDescriptor,
|
||||||
|
public val shouldGenerateCode: Boolean = true
|
||||||
) {
|
) {
|
||||||
|
|
||||||
public val error: Throwable
|
public val error: Throwable
|
||||||
@@ -43,7 +44,11 @@ public data open class AnalysisResult protected (
|
|||||||
public val EMPTY: AnalysisResult = success(BindingContext.EMPTY, ErrorUtils.getErrorModule())
|
public val EMPTY: AnalysisResult = success(BindingContext.EMPTY, ErrorUtils.getErrorModule())
|
||||||
|
|
||||||
platformStatic public fun success(bindingContext: BindingContext, module: ModuleDescriptor): AnalysisResult {
|
platformStatic public fun success(bindingContext: BindingContext, module: ModuleDescriptor): AnalysisResult {
|
||||||
return AnalysisResult(bindingContext, module)
|
return AnalysisResult(bindingContext, module, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
platformStatic public fun success(bindingContext: BindingContext, module: ModuleDescriptor, shouldGenerateCode: Boolean): AnalysisResult {
|
||||||
|
return AnalysisResult(bindingContext, module, shouldGenerateCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
platformStatic public fun error(bindingContext: BindingContext, error: Throwable): AnalysisResult {
|
platformStatic public fun error(bindingContext: BindingContext, error: Throwable): AnalysisResult {
|
||||||
|
|||||||
+8
-2
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.annotation
|
package org.jetbrains.kotlin.annotation
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAllTo
|
import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAllTo
|
||||||
@@ -34,7 +35,12 @@ import java.io.File
|
|||||||
|
|
||||||
public class StubProducerExtension(val stubsOutputDir: File) : AnalysisCompletedHandlerExtension {
|
public class StubProducerExtension(val stubsOutputDir: File) : AnalysisCompletedHandlerExtension {
|
||||||
|
|
||||||
override fun analysisCompleted(project: Project, module: ModuleDescriptor, bindingContext: BindingContext, files: Collection<JetFile>) {
|
override fun analysisCompleted(
|
||||||
|
project: Project,
|
||||||
|
module: ModuleDescriptor,
|
||||||
|
bindingContext: BindingContext,
|
||||||
|
files: Collection<JetFile>
|
||||||
|
): AnalysisResult? {
|
||||||
val forExtraDiagnostics = BindingTraceContext()
|
val forExtraDiagnostics = BindingTraceContext()
|
||||||
|
|
||||||
val generationState = GenerationState(
|
val generationState = GenerationState(
|
||||||
@@ -60,7 +66,7 @@ public class StubProducerExtension(val stubsOutputDir: File) : AnalysisCompleted
|
|||||||
generationState.getFactory().writeAllTo(stubsOutputDir)
|
generationState.getFactory().writeAllTo(stubsOutputDir)
|
||||||
|
|
||||||
generationState.destroy()
|
generationState.destroy()
|
||||||
throw CLICompiler.CompilationInterruptedException(ExitCode.OK)
|
return AnalysisResult.success(BindingContext.EMPTY, module, shouldGenerateCode = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user