Pill: Import Kotlin facets
This commit is contained in:
@@ -50,9 +50,28 @@ data class PSourceRoot(
|
||||
}
|
||||
|
||||
data class PSourceRootKotlinOptions(
|
||||
val compileArguments: List<String>,
|
||||
val defaultCompileArguments: List<String>
|
||||
)
|
||||
val noStdlib: Boolean?,
|
||||
val noReflect: Boolean?,
|
||||
val moduleName: String?,
|
||||
val apiVersion: String?,
|
||||
val languageVersion: String?,
|
||||
val jvmTarget: String?,
|
||||
val addCompilerBuiltIns: Boolean?,
|
||||
val loadBuiltInsFromDependencies: Boolean?,
|
||||
val extraArguments: List<String>
|
||||
) {
|
||||
fun intersect(other: PSourceRootKotlinOptions) = PSourceRootKotlinOptions(
|
||||
if (noStdlib == other.noStdlib) noStdlib else null,
|
||||
if (noReflect == other.noReflect) noReflect else null,
|
||||
if (moduleName == other.moduleName) moduleName else null,
|
||||
if (apiVersion == other.apiVersion) apiVersion else null,
|
||||
if (languageVersion == other.languageVersion) languageVersion else null,
|
||||
if (jvmTarget == other.jvmTarget) jvmTarget else null,
|
||||
if (addCompilerBuiltIns == other.addCompilerBuiltIns) addCompilerBuiltIns else null,
|
||||
if (loadBuiltInsFromDependencies == other.loadBuiltInsFromDependencies) loadBuiltInsFromDependencies else null,
|
||||
extraArguments.intersect(other.extraArguments).toList()
|
||||
)
|
||||
}
|
||||
|
||||
data class POrderRoot(
|
||||
val dependency: PDependency,
|
||||
@@ -264,9 +283,27 @@ private fun parseSourceRoots(project: Project): List<PSourceRoot> {
|
||||
|
||||
private fun getKotlinOptions(kotlinCompileTask: Any): PSourceRootKotlinOptions? {
|
||||
val compileArguments = kotlinCompileTask.invokeInternal("getSerializedCompilerArguments") as List<String>
|
||||
val defaultCompileArguments = kotlinCompileTask.invokeInternal("getDefaultSerializedCompilerArguments") as List<String>
|
||||
fun parseBoolean(name: String) = compileArguments.contains("-$name")
|
||||
fun parseString(name: String) = compileArguments.dropWhile { it != "-$name" }.drop(1).firstOrNull()
|
||||
|
||||
return PSourceRootKotlinOptions(compileArguments, defaultCompileArguments)
|
||||
val addCompilerBuiltins = "Xadd-compiler-builtins"
|
||||
val loadBuiltinsFromDependencies = "Xload-builtins-from-dependencies"
|
||||
|
||||
val extraArguments = compileArguments.filter {
|
||||
it.startsWith("-X") && it != "-$addCompilerBuiltins" && it != "-$loadBuiltinsFromDependencies"
|
||||
}
|
||||
|
||||
return PSourceRootKotlinOptions(
|
||||
parseBoolean("no-stdlib"),
|
||||
parseBoolean("no-reflect"),
|
||||
parseString("module-name"),
|
||||
parseString("api-version"),
|
||||
parseString("language-version"),
|
||||
parseString("jvm-target"),
|
||||
parseBoolean(addCompilerBuiltins),
|
||||
parseBoolean(loadBuiltinsFromDependencies),
|
||||
extraArguments
|
||||
)
|
||||
}
|
||||
|
||||
private fun Any.invokeInternal(name: String, instance: Any = this): Any? {
|
||||
|
||||
@@ -54,10 +54,57 @@ private fun renderModule(project: PProject, module: PModule) = PFile(
|
||||
xml("component", "name" to "TestModuleProperties", "production-module" to moduleForProductionSources.name)
|
||||
}
|
||||
|
||||
xml("component", "name" to "NewModuleRootManager", "inherit-compiler-output" to "true") {
|
||||
xml("exclude-output")
|
||||
val kotlinCompileOptionsList = module.contentRoots.flatMap { it.sourceRoots }.mapNotNull { it.kotlinOptions }
|
||||
var kotlinCompileOptions = kotlinCompileOptionsList.firstOrNull()
|
||||
for (otherOptions in kotlinCompileOptionsList.drop(1)) {
|
||||
kotlinCompileOptions = kotlinCompileOptions?.intersect(otherOptions)
|
||||
}
|
||||
|
||||
val pathContext = ModuleContext(project, module)
|
||||
val pathContext = ModuleContext(project, module)
|
||||
|
||||
val platformVersion = (kotlinCompileOptions?.jvmTarget ?: "1.8")
|
||||
val classesDirectory = File(project.rootDirectory, "out/production/${module.name}")
|
||||
|
||||
if (kotlinCompileOptions != null) {
|
||||
xml("component", "name" to "FacetManager") {
|
||||
xml("facet", "type" to "kotlin-language", "name" to "Kotlin") {
|
||||
xml("configuration", "version" to 3, "platform" to "JVM $platformVersion", "useProjectSettings" to "false") {
|
||||
xml("compilerSettings") {
|
||||
xml(
|
||||
"option",
|
||||
"name" to "additionalArguments",
|
||||
"value" to kotlinCompileOptions.extraArguments.joinToString(" ")
|
||||
)
|
||||
}
|
||||
xml("compilerArguments") {
|
||||
xml("option", "name" to "destination", "value" to pathContext(classesDirectory))
|
||||
|
||||
fun Any?.option(name: String) {
|
||||
if (this != null) xml("option", "name" to name, "value" to this.toString())
|
||||
}
|
||||
|
||||
kotlinCompileOptions.noStdlib.option("noStdlib")
|
||||
kotlinCompileOptions.noReflect.option("noReflect")
|
||||
kotlinCompileOptions.moduleName.option("moduleName")
|
||||
kotlinCompileOptions.languageVersion.option("languageVersion")
|
||||
kotlinCompileOptions.apiVersion.option("apiVersion")
|
||||
kotlinCompileOptions.addCompilerBuiltIns.option("addCompilerBuiltIns")
|
||||
kotlinCompileOptions.loadBuiltInsFromDependencies.option("loadBuiltInsFromDependencies")
|
||||
|
||||
xml("option", "name" to "pluginOptions") { xml("array") }
|
||||
xml("option", "name" to "pluginClasspaths") { xml("array") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xml("component",
|
||||
"name" to "NewModuleRootManager",
|
||||
"LANGUAGE_LEVEL" to "JDK_${platformVersion.replace('.', '_')}",
|
||||
"inherit-compiler-output" to "true"
|
||||
) {
|
||||
xml("exclude-output")
|
||||
|
||||
for (contentRoot in module.contentRoots) {
|
||||
xml("content", pathContext.url(contentRoot.path)) {
|
||||
|
||||
Reference in New Issue
Block a user