Work-around for importing intermediate android source sets

Fixed failure on import fully actualized intermediate source sets with K2Metadata compiler arguments (Android plugin expects compiler arguments of another type)
This commit is contained in:
Andrey Uskov
2019-10-14 17:42:59 +03:00
parent aa6ff4b9da
commit 866ab51ce5
3 changed files with 20 additions and 4 deletions
@@ -332,7 +332,12 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
val gradleCompilations = getCompilations(gradleTarget) ?: return null
val compilations = gradleCompilations.mapNotNull {
buildCompilation(it, disambiguationClassifier, sourceSetMap, dependencyResolver, project, dependencyMapper)
val compilation = buildCompilation(it, disambiguationClassifier, sourceSetMap, dependencyResolver, project, dependencyMapper)
if (compilation == null || platform != KotlinPlatform.ANDROID) {
compilation
} else {
compilation.addDependsOnSourceSetsToCompilation(sourceSetMap)
}
}
val jar = buildTargetJar(gradleTarget, project)
val testTasks = buildTestTasks(project, gradleTarget)
@@ -354,6 +359,11 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
return target
}
private fun KotlinCompilationImpl.addDependsOnSourceSetsToCompilation(sourceSetMap: Map<String, KotlinSourceSet>): KotlinCompilationImpl {
val closedSourceSets = this.sourceSets.union(this.sourceSets.flatMap { it.dependsOnSourceSets }.mapNotNull { sourceSetMap[it] })
return KotlinCompilationImpl(this.name, closedSourceSets, this.dependencies, this.output, this.arguments, this.dependencyClasspath, this.kotlinTaskProperties, this.nativeExtensions)
}
private fun buildTestTasks(project: Project, gradleTarget: Named): Collection<KotlinTestTask> {
val getTestRunsMethod = gradleTarget.javaClass.getMethodOrNull("getTestRuns")
if (getTestRunsMethod != null) {