From a4a03aeb5c8c00ed1abcf7d0d29afffd7ed2a00f Mon Sep 17 00:00:00 2001 From: Andrey Uskov Date: Fri, 27 Sep 2019 12:14:43 +0300 Subject: [PATCH] Fix compilation of KotlinMPPGradleModelBuilder --- .../src/KotlinMPPGradleModelBuilder.kt | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt b/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt index 5bad7035c12..4fdac0f63a0 100644 --- a/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt +++ b/idea/kotlin-gradle-tooling/src/KotlinMPPGradleModelBuilder.kt @@ -57,7 +57,7 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService { reportUnresolvedDependencies(targets) val kotlinNativeHome = KotlinNativeHomeEvaluator.getKotlinNativeHome(project) ?: NO_KOTLIN_NATIVE_HOME return KotlinMPPGradleModelImpl( - filterOrphanSourceSets(sourceSetMap, targets), + filterOrphanSourceSets(sourceSetMap, targets, project), targets, ExtraFeaturesImpl(coroutinesState, isHMPPEnabled(project)), kotlinNativeHome, @@ -65,8 +65,21 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService { ) } + private fun filterOrphanSourceSets( + sourceSets: Map, + targets: Collection, + project: Project + ): Map { + if (project.properties["import_orphan_source_sets"]?.toString()?.toBoolean() ?: DEFAULT_IMPORT_ORPHAN_SOURCE_SETS) return sourceSets + val compiledSourceSets: Collection = targets.flatMap { it.compilations }.flatMap { it.sourceSets }.flatMap { it.dependsOnSourceSets.union(listOf(it.name)) }.distinct() + sourceSets.filter { !compiledSourceSets.contains(it.key) }.forEach { + logger.warn("[sync warning] Source set \"${it.key}\" is not compiled with any compilation. This source set is not imported in the IDE.") + } + return sourceSets.filter { compiledSourceSets.contains(it.key) } + } + private fun isHMPPEnabled(project: Project): Boolean { - //TODO(auskov): replace with Project.isKotlinGranularMetadataEnabled after merging with gradle pranch + //TODO(auskov): replace with Project.isKotlinGranularMetadataEnabled after merging with gradle branch return (project.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata") as? String)?.toBoolean() ?: false } @@ -582,16 +595,6 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService { } for (sourceSet in sourceSets.values) { - val name = sourceSet.name - if (name == KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) { - sourceSet.isTestModule = false - continue - } - if (name == KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME) { - sourceSet.isTestModule = true - continue - } - val compilations = sourceSetToCompilations[sourceSet] if (compilations != null) { val platforms = compilations.map { it.platform } @@ -605,8 +608,16 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService { sourceSet.isTestModule = compilations.all { it.isTestModule } } else { - // TODO: change me after design about it - sourceSet.isTestModule = "Test" in sourceSet.name + //TODO(auskov): remove this branch as far as import of orphan source sets is dropped + val name = sourceSet.name + if (name == KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) { + sourceSet.isTestModule = false + continue + } + if (name == KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME) { + sourceSet.isTestModule = true + continue + } } } }