Compare commits

...

1 Commits

Author SHA1 Message Date
Simon Ogorodnik
58146a192d Add compiler key to dump arguments 2020-10-29 19:40:00 +03:00
4 changed files with 81 additions and 0 deletions

View File

@@ -364,6 +364,12 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
)
var inferenceCompatibility: Boolean by FreezableVar(false)
@Argument(
value = "-Xdump-model",
description = "Don't even try to use it"
)
var dumpArgumentsDir: String? by FreezableVar(null)
open fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> {
return HashMap<AnalysisFlag<*>, Any>().apply {
put(AnalysisFlags.skipMetadataVersionCheck, skipMetadataVersionCheck)

View File

@@ -25,6 +25,7 @@ fun <A : CommonCompilerArguments> CompilerConfiguration.setupCommonArguments(
put(CommonConfigurationKeys.USE_FIR, arguments.useFir)
put(CommonConfigurationKeys.USE_FIR_EXTENDED_CHECKERS, arguments.useFirExtendedCheckers)
put(CommonConfigurationKeys.EXPECT_ACTUAL_LINKER, arguments.expectActualLinker)
putIfNotNull(CommonConfigurationKeys.DUMP_MODEL, arguments.dumpArgumentsDir)
putIfNotNull(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, arguments.intellijPluginRoot)
put(CommonConfigurationKeys.REPORT_OUTPUT_FILES, arguments.reportOutputFiles)
put(CommonConfigurationKeys.DESERIALIZE_FAKE_OVERRIDES, arguments.deserializeFakeOverrides)

View File

@@ -23,6 +23,11 @@ import com.intellij.psi.PsiElementFinder
import com.intellij.psi.PsiJavaModule
import com.intellij.psi.search.DelegatingGlobalSearchScope
import com.intellij.psi.search.GlobalSearchScope
import org.jdom.Attribute
import org.jdom.Document
import org.jdom.Element
import org.jdom.output.Format
import org.jdom.output.XMLOutputter
import com.intellij.psi.search.ProjectScope
import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.analyzer.ModuleInfo
@@ -118,6 +123,67 @@ object KotlinToJVMBytecodeCompiler {
}
}
private fun dumpModel(dir: String, chunk: List<Module>) {
val modules = Element("modules").apply {
for (module in chunk) {
addContent(Element("module").apply {
attributes.add(
Attribute("name", module.getModuleName())
)
attributes.add(
Attribute("type", module.getModuleType())
)
attributes.add(
Attribute("outputDir", module.getOutputDirectory())
)
for (friendDir in module.getFriendPaths()) {
addContent(Element("friendDir").setAttribute("path", friendDir))
}
for (source in module.getSourceFiles()) {
addContent(Element("sources").setAttribute("path", source))
}
for (javaSourceRoots in module.getJavaSourceRoots()) {
addContent(Element("javaSourceRoots").setAttribute("path", javaSourceRoots.path))
}
for (classpath in module.getClasspathRoots()) {
addContent(Element("classpath").setAttribute("path", classpath))
}
for (commonSources in module.getCommonSourceFiles()) {
addContent(Element("commonSources").setAttribute("path", commonSources))
}
})
}
}
val document = Document(modules)
val outputter = XMLOutputter(Format.getPrettyFormat())
val dirFile = File(dir)
if (!dirFile.exists()) {
dirFile.mkdirs()
}
val fileName = "model-${chunk.first().getModuleName()}"
var counter = 0
fun file(): File {
val postfix = if (counter != 0) ".$counter" else ""
return File(dirFile, "$fileName$postfix.xml")
}
var outputFile: File
do {
outputFile = file()
counter++
} while (outputFile.exists())
outputFile.bufferedWriter().use {
outputter.output(document, it)
}
}
private fun Module.getSourceFiles(
environment: KotlinCoreEnvironment,
localFileSystem: VirtualFileSystem,
@@ -185,6 +251,11 @@ object KotlinToJVMBytecodeCompiler {
moduleVisibilityManager.addFriendPath(path)
}
val dumpModelDir = environment.configuration.get(CommonConfigurationKeys.DUMP_MODEL)
if (dumpModelDir != null) {
dumpModel(dumpModelDir, chunk)
}
val projectConfiguration = environment.configuration
if (projectConfiguration.getBoolean(CommonConfigurationKeys.USE_FIR)) {
val extendedAnalysisMode = projectConfiguration.getBoolean(CommonConfigurationKeys.USE_FIR_EXTENDED_CHECKERS)

View File

@@ -53,6 +53,9 @@ object CommonConfigurationKeys {
@JvmField
val USE_FIR_EXTENDED_CHECKERS = CompilerConfigurationKey.create<Boolean>("fir extended checkers")
@JvmField
val DUMP_MODEL = CompilerConfigurationKey.create<String>("Dump compiler arguments")
}
var CompilerConfiguration.languageVersionSettings: LanguageVersionSettings