[Gradle] Support CInteropCommonizerTask with Gradle Configuration Cache
This commit is contained in:
+28
-11
@@ -54,6 +54,22 @@ internal open class CInteropCommonizerTask
|
|||||||
@get:Nested
|
@get:Nested
|
||||||
internal val runnerSettings = KotlinNativeCommonizerToolRunner.Settings(project)
|
internal val runnerSettings = KotlinNativeCommonizerToolRunner.Settings(project)
|
||||||
|
|
||||||
|
private val konanHome = project.file(project.konanHome)
|
||||||
|
private val commonizerLogLevel = project.commonizerLogLevel
|
||||||
|
private val additionalCommonizerSettings = project.additionalCommonizerSettings
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Gradle Configuration Cache support the Group-to-Dependencies relation should be pre-cached.
|
||||||
|
* It is used during execution phase.
|
||||||
|
*/
|
||||||
|
private val nativeDistributionDependenciesMap: Map<CInteropCommonizerGroup, Set<CommonizerDependency>> by lazy {
|
||||||
|
getAllInteropsGroups().associateWith { group ->
|
||||||
|
(group.targets + group.targets.allLeaves()).flatMapTo(mutableSetOf()) { target ->
|
||||||
|
project.getNativeDistributionDependencies(target).map { dependency -> TargetedCommonizerDependency(target, dependency) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@get:Nested
|
@get:Nested
|
||||||
internal var cinterops = setOf<CInteropGist>()
|
internal var cinterops = setOf<CInteropGist>()
|
||||||
private set
|
private set
|
||||||
@@ -99,25 +115,26 @@ internal open class CInteropCommonizerTask
|
|||||||
)
|
)
|
||||||
|
|
||||||
GradleCliCommonizer(commonizerRunner).commonizeLibraries(
|
GradleCliCommonizer(commonizerRunner).commonizeLibraries(
|
||||||
konanHome = project.file(project.konanHome),
|
konanHome = konanHome,
|
||||||
outputTargets = group.targets,
|
outputTargets = group.targets,
|
||||||
inputLibraries = cinteropsForTarget.map { it.libraryFile.get() }.filter { it.exists() }.toSet(),
|
inputLibraries = cinteropsForTarget.map { it.libraryFile.get() }.filter { it.exists() }.toSet(),
|
||||||
dependencyLibraries = getNativeDistributionDependencies(group),
|
dependencyLibraries = getNativeDistributionDependencies(group),
|
||||||
outputDirectory = outputDirectory(group),
|
outputDirectory = outputDirectory(group),
|
||||||
logLevel = project.commonizerLogLevel,
|
logLevel = commonizerLogLevel,
|
||||||
additionalSettings = project.additionalCommonizerSettings,
|
additionalSettings = additionalCommonizerSettings,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNativeDistributionDependencies(group: CInteropCommonizerGroup): Set<CommonizerDependency> {
|
private fun getNativeDistributionDependencies(group: CInteropCommonizerGroup): Set<CommonizerDependency> {
|
||||||
return (group.targets + group.targets.allLeaves()).flatMapTo(mutableSetOf()) { target ->
|
val dependencies = nativeDistributionDependenciesMap[group]
|
||||||
project.getNativeDistributionDependencies(target).map { dependency -> TargetedCommonizerDependency(target, dependency) }
|
requireNotNull(dependencies) { "Unexpected $group" }
|
||||||
}
|
|
||||||
|
return dependencies
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
internal fun getAllInteropsGroups(): Set<CInteropCommonizerGroup> {
|
internal fun getAllInteropsGroups(): Set<CInteropCommonizerGroup> {
|
||||||
val dependents = getAllDependents()
|
val dependents = allDependents
|
||||||
val allScopeSets = dependents.map { it.scopes }.toSet()
|
val allScopeSets = dependents.map { it.scopes }.toSet()
|
||||||
val rootScopeSets = allScopeSets.filter { scopeSet ->
|
val rootScopeSets = allScopeSets.filter { scopeSet ->
|
||||||
allScopeSets.none { otherScopeSet -> otherScopeSet != scopeSet && otherScopeSet.containsAll(scopeSet) }
|
allScopeSets.none { otherScopeSet -> otherScopeSet != scopeSet && otherScopeSet.containsAll(scopeSet) }
|
||||||
@@ -147,9 +164,9 @@ internal open class CInteropCommonizerTask
|
|||||||
return suitableGroups.firstOrNull()
|
return suitableGroups.firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Internal
|
//@Internal
|
||||||
internal fun getAllDependents(): Set<CInteropCommonizerDependent> {
|
private val allDependents: Set<CInteropCommonizerDependent> by lazy {
|
||||||
val multiplatformExtension = project.multiplatformExtensionOrNull ?: return emptySet()
|
val multiplatformExtension = project.multiplatformExtensionOrNull ?: return@lazy emptySet()
|
||||||
|
|
||||||
val fromSharedNativeCompilations = multiplatformExtension
|
val fromSharedNativeCompilations = multiplatformExtension
|
||||||
.targets.flatMap { target -> target.compilations }
|
.targets.flatMap { target -> target.compilations }
|
||||||
@@ -165,7 +182,7 @@ internal open class CInteropCommonizerTask
|
|||||||
.mapNotNull { sourceSet -> CInteropCommonizerDependent.fromAssociateCompilations(project, sourceSet) }
|
.mapNotNull { sourceSet -> CInteropCommonizerDependent.fromAssociateCompilations(project, sourceSet) }
|
||||||
.toSet()
|
.toSet()
|
||||||
|
|
||||||
return (fromSharedNativeCompilations + fromSourceSets + fromSourceSetsAssociateCompilations)
|
return@lazy (fromSharedNativeCompilations + fromSourceSets + fromSourceSetsAssociateCompilations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user