Compare commits

...

1 Commits

Author SHA1 Message Date
Simon Ogorodnik
a852de6fde Add compiler key to dump arguments 2020-03-13 20:52:30 +03:00
4 changed files with 81 additions and 0 deletions

View File

@@ -337,6 +337,12 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
)
var explicitApi: String by FreezableVar(ExplicitApiMode.DISABLED.state)
@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

@@ -24,6 +24,7 @@ fun <A : CommonCompilerArguments> CompilerConfiguration.setupCommonArguments(
put(CommonConfigurationKeys.DISABLE_INLINE, arguments.noInline)
put(CommonConfigurationKeys.USE_FIR, arguments.useFir)
put(CommonConfigurationKeys.KLIB_MPP, arguments.klibBasedMpp)
putIfNotNull(CommonConfigurationKeys.DUMP_MODEL, arguments.dumpArgumentsDir)
putIfNotNull(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, arguments.intellijPluginRoot)
put(CommonConfigurationKeys.REPORT_OUTPUT_FILES, arguments.reportOutputFiles)

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
@@ -117,6 +122,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,
@@ -169,6 +235,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)) {
return compileModulesUsingFrontendIR(environment, buildFile, chunk)

View File

@@ -47,6 +47,9 @@ object CommonConfigurationKeys {
@JvmField
val KLIB_MPP = CompilerConfigurationKey.create<Boolean>("Klib based MPP")
@JvmField
val DUMP_MODEL = CompilerConfigurationKey.create<String>("Dump compiler arguments")
}
var CompilerConfiguration.languageVersionSettings: LanguageVersionSettings