Add compiler key to dump arguments
diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt
index 5e551b1..94f182921 100644
--- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt
+++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt
@@ -364,6 +364,12 @@
)
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)
diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt
index e457826..d38a44e 100644
--- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt
+++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt
@@ -25,6 +25,7 @@
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)
diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt
index 6228bb3..2819945 100644
--- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt
+++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt
@@ -23,6 +23,11 @@
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 @@
}
}
+
+ 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 @@
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)
diff --git a/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt b/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt
index f407fd0..4a572f7 100644
--- a/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt
+++ b/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt
@@ -53,6 +53,9 @@
@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