Introduce "-Xreport-output-files" to report source-output mapping for JPS
This makes "-verbose" not required for JPS to run correctly and therefore allows to print more useful debugging stuff in the compiler and read them in CLI, for example. The output will also be more readable because there'll be no "output" messages
This commit is contained in:
+4
-3
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.compiler.plugin.CliOption
|
||||
import org.jetbrains.kotlin.compiler.plugin.CliOptionProcessingException
|
||||
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
|
||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
|
||||
@@ -89,10 +90,10 @@ class AnnotationCollectorComponentRegistrar : ComponentRegistrar {
|
||||
}
|
||||
|
||||
val stubs = configuration.get(AnnotationCollectorConfigurationKeys.STUBS_PATH)
|
||||
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
||||
if (stubs != null) {
|
||||
AnalysisHandlerExtension.registerExtension(project, StubProducerExtension(File(stubs), messageCollector))
|
||||
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
||||
val reportOutputFiles = configuration.getBoolean(CommonConfigurationKeys.REPORT_OUTPUT_FILES)
|
||||
AnalysisHandlerExtension.registerExtension(project, StubProducerExtension(File(stubs), messageCollector, reportOutputFiles))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -32,7 +32,11 @@ import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
|
||||
import org.jetbrains.org.objectweb.asm.ClassWriter
|
||||
import java.io.File
|
||||
|
||||
class StubProducerExtension(val stubsOutputDir: File, val messageCollector: MessageCollector) : AnalysisHandlerExtension {
|
||||
class StubProducerExtension(
|
||||
private val stubsOutputDir: File,
|
||||
private val messageCollector: MessageCollector,
|
||||
private val reportOutputFiles: Boolean
|
||||
) : AnalysisHandlerExtension {
|
||||
override fun analysisCompleted(
|
||||
project: Project,
|
||||
module: ModuleDescriptor,
|
||||
@@ -50,7 +54,7 @@ class StubProducerExtension(val stubsOutputDir: File, val messageCollector: Mess
|
||||
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION)
|
||||
|
||||
if (!stubsOutputDir.exists()) stubsOutputDir.mkdirs()
|
||||
generationState.factory.writeAll(stubsOutputDir, messageCollector)
|
||||
generationState.factory.writeAll(stubsOutputDir, messageCollector, reportOutputFiles)
|
||||
|
||||
generationState.destroy()
|
||||
return AnalysisResult.success(BindingContext.EMPTY, module, shouldGenerateCode = false)
|
||||
|
||||
@@ -19,13 +19,15 @@ package org.jetbrains.kotlin.kapt3
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.sun.tools.javac.tree.JCTree
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.OUTPUT
|
||||
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
|
||||
import org.jetbrains.kotlin.codegen.CompilationErrorHandler
|
||||
import org.jetbrains.kotlin.codegen.KotlinCodegenFacade
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.kapt3.diagnostic.ErrorsKapt3
|
||||
@@ -250,17 +252,21 @@ abstract class AbstractKapt3Extension(
|
||||
converter: ClassFileToSourceStubConverter) {
|
||||
val incrementalDataOutputDir = this.incrementalDataOutputDir ?: return
|
||||
|
||||
generationState.factory.writeAll(incrementalDataOutputDir) { file, sources, output ->
|
||||
val stubFileObject = converter.bindings[file.relativePath.substringBeforeLast(".class", missingDelimiterValue = "")]
|
||||
if (stubFileObject != null) {
|
||||
val stubFile = File(stubsOutputDir, stubFileObject.name)
|
||||
if (stubFile.exists()) {
|
||||
messageCollector.report(CompilerMessageSeverity.OUTPUT, OutputMessageUtil.formatOutputMessage(sources, stubFile))
|
||||
}
|
||||
}
|
||||
val reportOutputFiles = generationState.configuration.getBoolean(CommonConfigurationKeys.REPORT_OUTPUT_FILES)
|
||||
generationState.factory.writeAll(
|
||||
incrementalDataOutputDir,
|
||||
if (!reportOutputFiles) null else fun(file: OutputFile, sources: List<File>, output: File) {
|
||||
val stubFileObject = converter.bindings[file.relativePath.substringBeforeLast(".class", missingDelimiterValue = "")]
|
||||
if (stubFileObject != null) {
|
||||
val stubFile = File(stubsOutputDir, stubFileObject.name)
|
||||
if (stubFile.exists()) {
|
||||
messageCollector.report(OUTPUT, OutputMessageUtil.formatOutputMessage(sources, stubFile))
|
||||
}
|
||||
}
|
||||
|
||||
messageCollector.report(CompilerMessageSeverity.OUTPUT, OutputMessageUtil.formatOutputMessage(sources, output))
|
||||
}
|
||||
messageCollector.report(OUTPUT, OutputMessageUtil.formatOutputMessage(sources, output))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
protected abstract fun loadProcessors(): List<Processor>
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ abstract class AbstractAnnotationProcessorBoxTest : KotlinTestWithEnvironment()
|
||||
|
||||
if (supportStubs) {
|
||||
val stubsDir = KotlinTestUtils.tmpDir("class-stubs")
|
||||
val stubProducerExtension = StubProducerExtension(stubsDir, MessageCollector.NONE)
|
||||
val stubProducerExtension = StubProducerExtension(stubsDir, MessageCollector.NONE, false)
|
||||
AnalysisHandlerExtension.registerExtension(project, stubProducerExtension)
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -208,7 +208,8 @@ class SourceSectionsTest : TestCaseWithTmpdir() {
|
||||
sourceToOutput.forEach { (source, expectedOutput) ->
|
||||
val args = arrayOf(source.canonicalPath, "-d", tmpdir.canonicalPath,
|
||||
"-Xplugin=${sourceSectionsPluginJar.canonicalPath}",
|
||||
"-P", TEST_ALLOWED_SECTIONS.joinToString(",") { "plugin:${SourceSectionsCommandLineProcessor.PLUGIN_ID}:${SourceSectionsCommandLineProcessor.SECTIONS_OPTION.name}=$it" })
|
||||
"-P", TEST_ALLOWED_SECTIONS.joinToString(",") { "plugin:${SourceSectionsCommandLineProcessor.PLUGIN_ID}:${SourceSectionsCommandLineProcessor.SECTIONS_OPTION.name}=$it" },
|
||||
"-Xreport-output-files")
|
||||
|
||||
messageCollector.clear()
|
||||
val outputs = arrayListOf<OutputMessageUtil.Output>()
|
||||
|
||||
Reference in New Issue
Block a user