From fcbcabd3a2d76997b28530b93e612dafb420b70b Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Mon, 4 Jun 2018 17:40:55 +0300 Subject: [PATCH] Pill: Generate iml files more consistently with IDEA --- buildSrc/src/main/kotlin/pill/pathContext.kt | 18 ++++++++++++++++-- buildSrc/src/main/kotlin/pill/render.kt | 20 ++++++++++++-------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/buildSrc/src/main/kotlin/pill/pathContext.kt b/buildSrc/src/main/kotlin/pill/pathContext.kt index 1cd2d324e33..93661c47a83 100644 --- a/buildSrc/src/main/kotlin/pill/pathContext.kt +++ b/buildSrc/src/main/kotlin/pill/pathContext.kt @@ -4,6 +4,20 @@ package org.jetbrains.kotlin.pill import org.gradle.api.Project import java.io.File +private val USER_HOME_DIR_PATH = System.getProperty("user.home").withSlash() + +private fun replacePrefix(path: String, prefix: String, variableName: String): String { + if (path.startsWith(prefix)) { + return "$" + variableName + "$/" + path.drop(prefix.length) + } + + return path +} + +private fun simplifyUserHomeDirPath(path: String): String { + return replacePrefix(path, USER_HOME_DIR_PATH, "USER_HOME") +} + interface PathContext { operator fun invoke(file: File): String @@ -22,14 +36,14 @@ class ProjectContext private constructor(private val projectDir: File) : PathCon constructor(project: Project) : this(project.projectDir) override fun invoke(file: File): String { - return file.absolutePath.replace(projectDir.absolutePath, "\$PROJECT_DIR\$") + return simplifyUserHomeDirPath(replacePrefix(file.absolutePath, projectDir.absolutePath.withSlash(), "PROJECT_DIR")) } } class ModuleContext(val project: PProject, val module: PModule) : PathContext { override fun invoke(file: File): String { if (!file.startsWith(project.rootDirectory)) { - return file.absolutePath + return simplifyUserHomeDirPath(file.absolutePath) } return "\$MODULE_DIR\$/" + file.toRelativeString(module.moduleFile.parentFile) diff --git a/buildSrc/src/main/kotlin/pill/render.kt b/buildSrc/src/main/kotlin/pill/render.kt index 3957974317b..7eb711687cb 100644 --- a/buildSrc/src/main/kotlin/pill/render.kt +++ b/buildSrc/src/main/kotlin/pill/render.kt @@ -86,10 +86,11 @@ private fun renderModule(project: PProject, module: PModule) = PFile( kotlinCompileOptions.noStdlib.option("noStdlib") kotlinCompileOptions.noReflect.option("noReflect") kotlinCompileOptions.moduleName.option("moduleName") - kotlinCompileOptions.languageVersion.option("languageVersion") - kotlinCompileOptions.apiVersion.option("apiVersion") + xml("option", "name" to "jvmTarget", "value" to platformVersion) kotlinCompileOptions.addCompilerBuiltIns.option("addCompilerBuiltIns") kotlinCompileOptions.loadBuiltInsFromDependencies.option("loadBuiltInsFromDependencies") + kotlinCompileOptions.languageVersion.option("languageVersion") + kotlinCompileOptions.apiVersion.option("apiVersion") xml("option", "name" to "pluginOptions") { xml("array") } xml("option", "name" to "pluginClasspaths") { xml("array") } @@ -134,31 +135,34 @@ private fun renderModule(project: PProject, module: PModule) = PFile( for (orderRoot in module.orderRoots) { val dependency = orderRoot.dependency - var args = when (dependency) { - is PDependency.ModuleLibrary -> arrayOf( + val args = when (dependency) { + is PDependency.ModuleLibrary -> mutableListOf( "type" to "module-library" ) - is PDependency.Module -> arrayOf( + is PDependency.Module -> mutableListOf( "type" to "module", "module-name" to dependency.name ) - is PDependency.Library -> arrayOf( + is PDependency.Library -> mutableListOf( "type" to "library", "name" to dependency.name, "level" to "project" ) } + if (orderRoot.scope != POrderRoot.Scope.COMPILE) { + args.add(1, "scope" to orderRoot.scope.toString()) + } + if (dependency is PDependency.Module && orderRoot.isProductionOnTestDependency) { args += ("production-on-test" to "") } - args += ("scope" to orderRoot.scope.toString()) if (orderRoot.isExported) { args += ("exported" to "") } - xml("orderEntry", *args) { + xml("orderEntry", *args.toTypedArray()) { if (dependency is PDependency.ModuleLibrary) { add(renderLibraryToXml(dependency.library, pathContext, named = false)) }