Fix compilation of KotlinMPPGradleModelBuilder
This commit is contained in:
@@ -57,7 +57,7 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
|
|||||||
reportUnresolvedDependencies(targets)
|
reportUnresolvedDependencies(targets)
|
||||||
val kotlinNativeHome = KotlinNativeHomeEvaluator.getKotlinNativeHome(project) ?: NO_KOTLIN_NATIVE_HOME
|
val kotlinNativeHome = KotlinNativeHomeEvaluator.getKotlinNativeHome(project) ?: NO_KOTLIN_NATIVE_HOME
|
||||||
return KotlinMPPGradleModelImpl(
|
return KotlinMPPGradleModelImpl(
|
||||||
filterOrphanSourceSets(sourceSetMap, targets),
|
filterOrphanSourceSets(sourceSetMap, targets, project),
|
||||||
targets,
|
targets,
|
||||||
ExtraFeaturesImpl(coroutinesState, isHMPPEnabled(project)),
|
ExtraFeaturesImpl(coroutinesState, isHMPPEnabled(project)),
|
||||||
kotlinNativeHome,
|
kotlinNativeHome,
|
||||||
@@ -65,8 +65,21 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun filterOrphanSourceSets(
|
||||||
|
sourceSets: Map<String, KotlinSourceSetImpl>,
|
||||||
|
targets: Collection<KotlinTarget>,
|
||||||
|
project: Project
|
||||||
|
): Map<String, KotlinSourceSetImpl> {
|
||||||
|
if (project.properties["import_orphan_source_sets"]?.toString()?.toBoolean() ?: DEFAULT_IMPORT_ORPHAN_SOURCE_SETS) return sourceSets
|
||||||
|
val compiledSourceSets: Collection<String> = 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 {
|
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
|
return (project.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata") as? String)?.toBoolean() ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,16 +595,6 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (sourceSet in sourceSets.values) {
|
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]
|
val compilations = sourceSetToCompilations[sourceSet]
|
||||||
if (compilations != null) {
|
if (compilations != null) {
|
||||||
val platforms = compilations.map { it.platform }
|
val platforms = compilations.map { it.platform }
|
||||||
@@ -605,8 +608,16 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
|
|||||||
|
|
||||||
sourceSet.isTestModule = compilations.all { it.isTestModule }
|
sourceSet.isTestModule = compilations.all { it.isTestModule }
|
||||||
} else {
|
} else {
|
||||||
// TODO: change me after design about it
|
//TODO(auskov): remove this branch as far as import of orphan source sets is dropped
|
||||||
sourceSet.isTestModule = "Test" in sourceSet.name
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user