From 6d73aa29e01af2c7aecbc79da7486a73ee8d5223 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Tue, 2 Oct 2018 19:44:50 +0300 Subject: [PATCH] Pill: Understand dependencies with the 'apiElements' configuration name as module dependencies --- buildSrc/src/main/kotlin/pill/kotlinPluginArtifact.kt | 2 +- buildSrc/src/main/kotlin/pill/parser.kt | 5 ++++- buildSrc/src/main/kotlin/pill/plugin.kt | 10 ++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/kotlin/pill/kotlinPluginArtifact.kt b/buildSrc/src/main/kotlin/pill/kotlinPluginArtifact.kt index 5a5624a00e7..9cba641323f 100644 --- a/buildSrc/src/main/kotlin/pill/kotlinPluginArtifact.kt +++ b/buildSrc/src/main/kotlin/pill/kotlinPluginArtifact.kt @@ -173,7 +173,7 @@ fun generateKotlinPluginArtifactFile(rootProject: Project): PFile { for (dependencyInfo in listOf(configuration).collectDependencies()) { val dependency = (dependencyInfo as? DependencyInfo.ResolvedDependencyInfo)?.dependency ?: continue - if (dependency.configuration == "runtimeElements") { + if (dependency.isModuleDependency) { archiveForJar.add(ModuleOutput(dependency.moduleName + ".src")) } else if (dependency.configuration == "tests-jar" || dependency.configuration == "jpsTest") { error("Test configurations are not allowed here") diff --git a/buildSrc/src/main/kotlin/pill/parser.kt b/buildSrc/src/main/kotlin/pill/parser.kt index dbccc4a055b..8a9df58baa1 100644 --- a/buildSrc/src/main/kotlin/pill/parser.kt +++ b/buildSrc/src/main/kotlin/pill/parser.kt @@ -413,7 +413,7 @@ private fun ParserContext.parseDependencies(project: Project, forTests: Boolean) } } - mainRoots += if (dependency.configuration == "runtimeElements" && scope != Scope.TEST) { + mainRoots += if (dependency.isModuleDependency && scope != Scope.TEST) { POrderRoot(PDependency.Module(dependency.moduleName + ".src"), scope) } else if (dependency.configuration == "tests-jar" || dependency.configuration == "jpsTest") { POrderRoot( @@ -489,6 +489,9 @@ sealed class DependencyInfo(val scope: Scope) { class CustomDependencyInfo(scope: Scope, val files: List) : DependencyInfo(scope) } +val ResolvedDependency.isModuleDependency + get() = configuration in JpsCompatiblePlugin.MODULE_CONFIGURATIONS + fun List.collectDependencies(): List { val dependencies = mutableListOf() diff --git a/buildSrc/src/main/kotlin/pill/plugin.kt b/buildSrc/src/main/kotlin/pill/plugin.kt index 0293abc9736..351d850d282 100644 --- a/buildSrc/src/main/kotlin/pill/plugin.kt +++ b/buildSrc/src/main/kotlin/pill/plugin.kt @@ -20,6 +20,8 @@ class PillConfigurablePlugin : Plugin { class JpsCompatiblePlugin : Plugin { companion object { + val MODULE_CONFIGURATIONS = arrayOf("apiElements", "runtimeElements") + private fun mapper(module: String, vararg configurations: String): DependencyMapper { return DependencyMapper("org.jetbrains.kotlin", module, *configurations) { MappedDependency(PDependency.Library(module)) } } @@ -27,10 +29,10 @@ class JpsCompatiblePlugin : Plugin { private fun getDependencyMappers(projectLibraries: List): List { val mappersForKotlinLibrariesExeptStdlib = projectLibraries .filter { it.name != "kotlin-stdlib" } - .mapTo(mutableListOf()) { mapper(it.name, "default", "distJar", "runtimeElements") } + .mapTo(mutableListOf()) { mapper(it.name, "default", "distJar", *MODULE_CONFIGURATIONS) } return mappersForKotlinLibrariesExeptStdlib + listOf( - DependencyMapper("org.jetbrains.kotlin", "kotlin-stdlib", "distJar", "runtimeElements") { + DependencyMapper("org.jetbrains.kotlin", "kotlin-stdlib", "distJar", *MODULE_CONFIGURATIONS) { MappedDependency( PDependency.Library("kotlin-stdlib"), listOf(PDependency.Library("annotations-13.0")) @@ -42,13 +44,13 @@ class JpsCompatiblePlugin : Plugin { listOf(PDependency.Library("annotations-13.0")) ) }, - DependencyMapper("org.jetbrains.kotlin", "kotlin-reflect-api", "runtimeElements") { + DependencyMapper("org.jetbrains.kotlin", "kotlin-reflect-api", *MODULE_CONFIGURATIONS) { MappedDependency(PDependency.Library("kotlin-reflect")) }, DependencyMapper("org.jetbrains.kotlin", "kotlin-compiler-embeddable", "runtimeJar") { null }, DependencyMapper("org.jetbrains.kotlin", "kotlin-stdlib-js", "distJar") { null }, DependencyMapper("org.jetbrains.kotlin", "kotlin-compiler", "runtimeJar") { null }, - DependencyMapper("org.jetbrains.kotlin", "compiler", "runtimeElements") { null }, + DependencyMapper("org.jetbrains.kotlin", "compiler", *MODULE_CONFIGURATIONS) { null }, DependencyMapper("kotlin.build.custom.deps", "android", "default") { dep -> val (sdkCommon, otherJars) = dep.moduleArtifacts.map { it.file }.partition { it.name == "sdk-common.jar" } val mainLibrary = PDependency.ModuleLibrary(PLibrary(dep.moduleName, otherJars))