[MPP] KT-54974 Implement TCS dependency resolver for K/N stdlib
This commit is contained in:
committed by
Space Team
parent
4f736524b2
commit
ad0dee822e
+7
@@ -59,6 +59,13 @@ fun IdeMultiplatformImport(extension: KotlinMultiplatformExtension): IdeMultipla
|
|||||||
level = IdeMultiplatformImport.DependencyResolutionLevel.Default
|
level = IdeMultiplatformImport.DependencyResolutionLevel.Default
|
||||||
)
|
)
|
||||||
|
|
||||||
|
registerDependencyResolver(
|
||||||
|
resolver = IdeNativeStdlibDependencyResolver,
|
||||||
|
constraint = IdeMultiplatformImport.SourceSetConstraint.isNative,
|
||||||
|
phase = IdeMultiplatformImport.DependencyResolutionPhase.BinaryDependencyResolution,
|
||||||
|
level = IdeMultiplatformImport.DependencyResolutionLevel.Default,
|
||||||
|
)
|
||||||
|
|
||||||
registerExtrasSerializationExtension {
|
registerExtrasSerializationExtension {
|
||||||
register(kotlinDebugKey, IdeaKotlinExtrasSerializer.javaIoSerializable())
|
register(kotlinDebugKey, IdeaKotlinExtrasSerializer.javaIoSerializable())
|
||||||
}
|
}
|
||||||
|
|||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.commonizer.KonanDistribution
|
||||||
|
import org.jetbrains.kotlin.commonizer.stdlib
|
||||||
|
import org.jetbrains.kotlin.compilerRunner.konanHome
|
||||||
|
import org.jetbrains.kotlin.compilerRunner.konanVersion
|
||||||
|
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.plugin.KotlinSourceSet
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.ide.IdeDependencyResolver
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.sources.project
|
||||||
|
import org.jetbrains.kotlin.tooling.core.mutableExtrasOf
|
||||||
|
|
||||||
|
internal object IdeNativeStdlibDependencyResolver : IdeDependencyResolver {
|
||||||
|
override fun resolve(sourceSet: KotlinSourceSet): Set<IdeaKotlinDependency> {
|
||||||
|
return setOf(
|
||||||
|
IdeaKotlinResolvedBinaryDependency(
|
||||||
|
binaryType = IdeaKotlinDependency.CLASSPATH_BINARY_TYPE,
|
||||||
|
binaryFile = KonanDistribution(sourceSet.project.konanHome).stdlib,
|
||||||
|
extras = mutableExtrasOf(),
|
||||||
|
coordinates = IdeaKotlinBinaryCoordinates(
|
||||||
|
"org.jetbrains.kotlin", "stdlib-native", sourceSet.project.konanVersion.toString(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:Suppress("FunctionName", "DuplicatedCode")
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.ide
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.compilerRunner.konanVersion
|
||||||
|
import org.jetbrains.kotlin.gradle.buildProjectWithMPP
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||||
|
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.assertMatches
|
||||||
|
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.binaryCoordinates
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers.IdeNativeStdlibDependencyResolver
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class IdeNativeStdlibResolverTest {
|
||||||
|
@Test
|
||||||
|
fun `test single linux target`() {
|
||||||
|
val project = buildProjectWithMPP()
|
||||||
|
val kotlin = project.multiplatformExtension
|
||||||
|
|
||||||
|
kotlin.linuxX64()
|
||||||
|
|
||||||
|
val commonMain = kotlin.sourceSets.getByName("commonMain")
|
||||||
|
val commonTest = kotlin.sourceSets.getByName("commonTest")
|
||||||
|
val linuxX64Main = kotlin.sourceSets.getByName("linuxX64Main")
|
||||||
|
val linuxX64Test = kotlin.sourceSets.getByName("linuxX64Test")
|
||||||
|
|
||||||
|
val stdlibCoordinates = binaryCoordinates("org.jetbrains.kotlin:stdlib-native:${project.konanVersion}")
|
||||||
|
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(commonMain).assertMatches(stdlibCoordinates)
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(commonTest).assertMatches(stdlibCoordinates)
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(linuxX64Main).assertMatches(stdlibCoordinates)
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(linuxX64Test).assertMatches(stdlibCoordinates)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test shared non native target`() {
|
||||||
|
val project = buildProjectWithMPP()
|
||||||
|
val kotlin = project.multiplatformExtension
|
||||||
|
|
||||||
|
kotlin.linuxX64()
|
||||||
|
kotlin.jvm()
|
||||||
|
|
||||||
|
val linuxX64Main = kotlin.sourceSets.getByName("linuxX64Main")
|
||||||
|
val linuxX64Test = kotlin.sourceSets.getByName("linuxX64Test")
|
||||||
|
|
||||||
|
val stdlibCoordinates = binaryCoordinates("org.jetbrains.kotlin:stdlib-native:${project.konanVersion}")
|
||||||
|
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(linuxX64Main).assertMatches(stdlibCoordinates)
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(linuxX64Test).assertMatches(stdlibCoordinates)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test shared native target`() {
|
||||||
|
val project = buildProjectWithMPP()
|
||||||
|
val kotlin = project.multiplatformExtension
|
||||||
|
|
||||||
|
kotlin.linuxX64()
|
||||||
|
kotlin.linuxArm64()
|
||||||
|
kotlin.jvm()
|
||||||
|
|
||||||
|
val commonMain = kotlin.sourceSets.getByName("commonMain")
|
||||||
|
val commonTest = kotlin.sourceSets.getByName("commonTest")
|
||||||
|
val linuxX64Main = kotlin.sourceSets.getByName("linuxX64Main")
|
||||||
|
val linuxX64Test = kotlin.sourceSets.getByName("linuxX64Test")
|
||||||
|
val linuxArm64Main = kotlin.sourceSets.getByName("linuxArm64Main")
|
||||||
|
val linuxArm64Test = kotlin.sourceSets.getByName("linuxArm64Test")
|
||||||
|
val linuxMain = kotlin.sourceSets.create("linuxMain") { linuxMain ->
|
||||||
|
linuxMain.dependsOn(commonMain)
|
||||||
|
linuxArm64Main.dependsOn(linuxMain)
|
||||||
|
linuxX64Main.dependsOn(linuxMain)
|
||||||
|
}
|
||||||
|
val linuxTest = kotlin.sourceSets.create("linuxTest") { linuxTest ->
|
||||||
|
linuxTest.dependsOn(commonTest)
|
||||||
|
linuxArm64Main.dependsOn(linuxTest)
|
||||||
|
linuxX64Main.dependsOn(linuxTest)
|
||||||
|
}
|
||||||
|
|
||||||
|
val stdlibCoordinates = binaryCoordinates("org.jetbrains.kotlin:stdlib-native:${project.konanVersion}")
|
||||||
|
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(linuxX64Main).assertMatches(stdlibCoordinates)
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(linuxX64Test).assertMatches(stdlibCoordinates)
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(linuxArm64Main).assertMatches(stdlibCoordinates)
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(linuxArm64Test).assertMatches(stdlibCoordinates)
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(linuxMain).assertMatches(stdlibCoordinates)
|
||||||
|
IdeNativeStdlibDependencyResolver.resolve(linuxTest).assertMatches(stdlibCoordinates)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user