[MPP] Fix propagation of cinterops from associate compilations and leafs
KT-54975
This commit is contained in:
committed by
Space Team
parent
8a83870306
commit
7308583388
+6
-6
@@ -102,14 +102,13 @@ class MppIdeDependencyResolutionIT : KGPBaseTest() {
|
||||
val linuxArmTestDependencies = dependencies["linuxArm64Test"].cinteropDependencies()
|
||||
|
||||
for (commonDeps in listOf(commonMainDependencies, commonTestDependencies)) {
|
||||
commonDeps.assertMatches(binaryCoordinates(Regex("a:dep.*linux_arm64, linux_x64")))
|
||||
commonDeps.assertMatches(binaryCoordinates(Regex("a:dep.*\\(linux_arm64, linux_x64\\)")))
|
||||
}
|
||||
|
||||
linuxX64MainDependencies.assertMatches(binaryCoordinates(Regex("a:dep.*linux_x64")))
|
||||
linuxArmMainDependencies.assertMatches(binaryCoordinates(Regex("a:dep.*linux_arm64")))
|
||||
// TODO (kirpichenkov): cinterops from associate compilations for platform source sets
|
||||
linuxX64TestDependencies.assertMatches(/*binaryCoordinates(Regex("a:dep.*linux_x64"))*/)
|
||||
linuxArmTestDependencies.assertMatches(/*binaryCoordinates(Regex("a:dep.*linux_arm64"))*/)
|
||||
linuxX64TestDependencies.assertMatches(binaryCoordinates(Regex("a:dep.*linux_x64")))
|
||||
linuxArmTestDependencies.assertMatches(binaryCoordinates(Regex("a:dep.*linux_arm64")))
|
||||
}
|
||||
|
||||
resolveIdeDependencies("client-for-binary-dep") { dependencies ->
|
||||
@@ -122,12 +121,13 @@ class MppIdeDependencyResolutionIT : KGPBaseTest() {
|
||||
|
||||
for (commonDeps in listOf(commonMainDependencies, commonTestDependencies)) {
|
||||
commonDeps.assertMatches(
|
||||
commonDeps.assertMatches(binaryCoordinates(Regex("a:dep.*linux_arm64, linux_x64")))
|
||||
commonDeps.assertMatches(binaryCoordinates(Regex("a:dep.*\\(linux_arm64, linux_x64\\)")))
|
||||
)
|
||||
}
|
||||
|
||||
for (platformDeps in listOf(linuxMainDependencies, linuxTestDependencies, linux2MainDependencies, linux2TestDependencies)) {
|
||||
platformDeps.assertMatches(
|
||||
// TODO (kirpichenkov): consider extracting cinterops from , platform source set cinterops
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,7 @@ class MppIdeDependencyResolutionIT : KGPBaseTest() {
|
||||
val linux2TestDependencies = dependencies["linuxArm64Test"].cinteropDependencies()
|
||||
|
||||
for (commonDeps in listOf(commonMainDependencies, commonTestDependencies)) {
|
||||
commonDeps.assertMatches(binaryCoordinates(Regex("a:dep.*linux_arm64, linux_x64")))
|
||||
commonDeps.assertMatches(binaryCoordinates(Regex("a:dep.*\\(linux_arm64, linux_x64\\)")))
|
||||
}
|
||||
|
||||
for (platformDeps in listOf(linuxMainDependencies, linuxTestDependencies, linux2MainDependencies, linux2TestDependencies)) {
|
||||
|
||||
-1
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.gradle.plugin.ide.IdeMultiplatformImport.SourceSetCo
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.dependencyTransformers.IdePlatformStdlibCommonDependencyFilter
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.getCommonizerTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.dependencyTransformers.UnusedSourcesAndDocumentationFilter
|
||||
|
||||
internal fun IdeMultiplatformImport(extension: KotlinProjectExtension): IdeMultiplatformImport {
|
||||
return IdeMultiplatformImportImpl(extension).apply {
|
||||
|
||||
+2
-6
@@ -8,19 +8,15 @@ package org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.IdeDependencyResolver
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.getAllCInteropOutputFiles
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.getPlatformCinteropDependenciesOrEmpty
|
||||
|
||||
object IdePlatformCinteropDependencyResolver : IdeDependencyResolver {
|
||||
override fun resolve(sourceSet: KotlinSourceSet): Set<IdeaKotlinDependency> {
|
||||
if (sourceSet !is DefaultKotlinSourceSet) return emptySet()
|
||||
val project = sourceSet.project
|
||||
|
||||
val nativeCompilation = sourceSet.internal.compilations.singleOrNull().safeAs<KotlinNativeCompilation>() ?: return emptySet()
|
||||
val cinteropFiles = project.getAllCInteropOutputFiles(nativeCompilation)
|
||||
val cinteropFiles = project.getPlatformCinteropDependenciesOrEmpty(sourceSet)
|
||||
|
||||
return resolveCinteropDependencies(project, cinteropFiles)
|
||||
}
|
||||
|
||||
+6
-11
@@ -7,16 +7,11 @@ package org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinBinaryCoordinates
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinResolvedBinaryDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.*
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.extras.klibExtra
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.KlibExtra
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.library.KLIB_FILE_EXTENSION
|
||||
import org.jetbrains.kotlin.library.ToolingSingleFileKlibResolveStrategy
|
||||
import org.jetbrains.kotlin.library.commonizerTarget
|
||||
import org.jetbrains.kotlin.library.resolveSingleFileKlib
|
||||
import org.jetbrains.kotlin.library.*
|
||||
|
||||
fun resolveCinteropDependencies(project: Project, cinteropFiles: FileCollection): Set<IdeaKotlinDependency> {
|
||||
return cinteropFiles.files
|
||||
@@ -38,13 +33,13 @@ private fun createCinteropLibraryDependency(project: Project, libraryFile: java.
|
||||
}
|
||||
|
||||
return IdeaKotlinResolvedBinaryDependency(
|
||||
binaryType = IdeaKotlinDependency.CLASSPATH_BINARY_TYPE,
|
||||
binaryFile = libraryFile,
|
||||
binaryType = IdeaKotlinBinaryDependency.KOTLIN_COMPILE_BINARY_TYPE,
|
||||
classpath = IdeaKotlinClasspath(libraryFile),
|
||||
coordinates = IdeaKotlinBinaryCoordinates(
|
||||
group = project.group.toString(),
|
||||
module = library.moduleDisplayName,
|
||||
version = null,
|
||||
sourceSetName = library.commonizerTarget
|
||||
version = null, // TODO (kirpichenkov): if/when used for published cinterops, should be set up correctly
|
||||
sourceSetName = library.nativeTargets.singleOrNull() ?: library.nativeTargets.joinToString(prefix = "(", postfix = ")")
|
||||
),
|
||||
).apply {
|
||||
klibExtra = KlibExtra(library)
|
||||
|
||||
+12
-4
@@ -55,7 +55,16 @@ internal fun Project.setupCInteropPropagatedDependencies() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Project.getPropagatedCInteropDependenciesOrEmpty(sourceSet: DefaultKotlinSourceSet): FileCollection {
|
||||
internal fun Project.getPropagatedCInteropDependenciesOrEmpty(sourceSet: DefaultKotlinSourceSet): FileCollection =
|
||||
getPlatformCinteropDependenciesOrEmpty(sourceSet) { relevantCompilation ->
|
||||
/* Source Set is directly included in compilation -> No need to add dependency again (when looking for propagated dependencies) */
|
||||
sourceSet !in relevantCompilation.kotlinSourceSets
|
||||
}
|
||||
|
||||
internal fun Project.getPlatformCinteropDependenciesOrEmpty(
|
||||
sourceSet: DefaultKotlinSourceSet,
|
||||
compilationFilter: (KotlinNativeCompilation) -> Boolean = { true },
|
||||
): FileCollection {
|
||||
return filesProvider files@{
|
||||
/*
|
||||
compatibility metadata variant will still register
|
||||
@@ -69,8 +78,7 @@ private fun Project.getPropagatedCInteropDependenciesOrEmpty(sourceSet: DefaultK
|
||||
|
||||
(compilation.associateWith + compilation)
|
||||
.filterIsInstance<KotlinNativeCompilation>()
|
||||
/* Source Set is directly included in compilation -> No need to add dependency again (will be handled already) */
|
||||
.filter { relevantCompilation -> sourceSet !in relevantCompilation.kotlinSourceSets }
|
||||
.filter(compilationFilter)
|
||||
.map { relevantCompilation -> getAllCInteropOutputFiles(relevantCompilation) }
|
||||
}
|
||||
}
|
||||
@@ -81,7 +89,7 @@ private fun Project.getPropagatedCInteropDependenciesOrEmpty(compilation: Kotlin
|
||||
getAllCInteropOutputFiles(platformCompilation)
|
||||
}
|
||||
|
||||
internal fun Project.getAllCInteropOutputFiles(compilation: KotlinNativeCompilation): FileCollection {
|
||||
private fun Project.getAllCInteropOutputFiles(compilation: KotlinNativeCompilation): FileCollection {
|
||||
val cinteropTasks = compilation.cinterops.map { interop -> interop.interopProcessingTaskName }
|
||||
.mapNotNull { taskName -> tasks.findByName(taskName) as? CInteropProcess }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user