[MPP] Support import of project-to-project cinterop dependencies
KT-54975
This commit is contained in:
committed by
Space Team
parent
424d1e23fc
commit
7bae2303aa
+8
-5
@@ -123,11 +123,14 @@ class MppIdeDependencyResolutionIT : KGPBaseTest() {
|
||||
dependencies["commonTest"].cinteropDependencies()
|
||||
.assertMatches(binaryCoordinates(Regex("a:dep.*\\(linux_arm64, linux_x64\\)")))
|
||||
|
||||
// TODO (kirpichenkov): project to project dependency, platform source set cinterops
|
||||
dependencies["linuxX64Main"].cinteropDependencies().assertMatches()
|
||||
dependencies["linuxX64Test"].cinteropDependencies().assertMatches()
|
||||
dependencies["linuxArm64Main"].cinteropDependencies().assertMatches()
|
||||
dependencies["linuxArm64Test"].cinteropDependencies().assertMatches()
|
||||
dependencies["linuxX64Main"].cinteropDependencies()
|
||||
.assertMatches(binaryCoordinates(Regex("a:dep-with-cinterop-cinterop-dep.*linux_x64")))
|
||||
dependencies["linuxX64Test"].cinteropDependencies()
|
||||
.assertMatches(binaryCoordinates(Regex("a:dep-with-cinterop-cinterop-dep.*linux_x64")))
|
||||
dependencies["linuxArm64Main"].cinteropDependencies()
|
||||
.assertMatches(binaryCoordinates(Regex("a:dep-with-cinterop-cinterop-dep.*linux_arm64")))
|
||||
dependencies["linuxArm64Test"].cinteropDependencies()
|
||||
.assertMatches(binaryCoordinates(Regex("a:dep-with-cinterop-cinterop-dep.*linux_arm64")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -107,6 +107,13 @@ internal fun IdeMultiplatformImport(extension: KotlinProjectExtension): IdeMulti
|
||||
level = IdeMultiplatformImport.DependencyResolutionLevel.Default,
|
||||
)
|
||||
|
||||
registerDependencyResolver(
|
||||
resolver = IdeProjectToProjectCInteropDependencyResolver,
|
||||
constraint = { SourceSetConstraint.isNative(it) && SourceSetConstraint.isLeaf(it) },
|
||||
phase = IdeMultiplatformImport.DependencyResolutionPhase.BinaryDependencyResolution,
|
||||
level = IdeMultiplatformImport.DependencyResolutionLevel.Default,
|
||||
)
|
||||
|
||||
/*
|
||||
Register resolution of dependencies for jvm+android dependencies:
|
||||
This resolver will resolve dependencies visible to the source set from a 'jvm' perspective.
|
||||
|
||||
+24
-15
@@ -7,25 +7,34 @@ package org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers
|
||||
|
||||
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
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.locateOrCreateCInteropDependencyConfiguration
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
object IdeProjectToProjectCInteropDependencyResolver : IdeDependencyResolver {
|
||||
private val platformDependencyResolver = IdeBinaryDependencyResolver(
|
||||
resolvedArtifactHandler = handler@{ artifact, context ->
|
||||
val identifier = artifact.id.componentIdentifier as? ProjectComponentIdentifier
|
||||
?: return@handler null
|
||||
|
||||
val projectArtifact = context.allArtifacts.filter { otherArtifact ->
|
||||
val otherIdentifier = otherArtifact.id.componentIdentifier
|
||||
otherIdentifier is ProjectComponentIdentifier && otherIdentifier.projectName == identifier.projectName
|
||||
}
|
||||
|
||||
null
|
||||
}
|
||||
)
|
||||
|
||||
override fun resolve(sourceSet: KotlinSourceSet): Set<IdeaKotlinDependency> {
|
||||
return platformDependencyResolver.resolve(sourceSet)
|
||||
if (sourceSet !is DefaultKotlinSourceSet) return emptySet()
|
||||
|
||||
val compilation = sourceSet.internal.compilations.singleOrNull { it.platformType != KotlinPlatformType.common }
|
||||
?.safeAs<KotlinNativeCompilation>() ?: return emptySet()
|
||||
|
||||
val project = sourceSet.project
|
||||
val configuration = project.locateOrCreateCInteropDependencyConfiguration(compilation)
|
||||
|
||||
val cinteropFiles = project.files(
|
||||
{
|
||||
configuration.incoming.artifactView {
|
||||
it.componentFilter { identifier -> identifier is ProjectComponentIdentifier }
|
||||
}.artifacts.map { it.file }
|
||||
}
|
||||
)
|
||||
|
||||
return resolveCinteropDependencies(project, cinteropFiles)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user