[K/N] K2/MPP: Move stdlib to the head of dependency list.

^KT-61645 Fixed

Merge-request: KT-MR-12079
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
Vladimir Sukharev
2023-09-13 13:56:21 +00:00
committed by Space Team
parent fbeed67931
commit c4201101ac
7 changed files with 54 additions and 3 deletions
@@ -15,9 +15,9 @@ import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
import org.jetbrains.kotlin.fir.resolve.calls.ConeCallConflictResolverFactory
import org.jetbrains.kotlin.fir.resolve.providers.impl.FirBuiltinSyntheticFunctionInterfaceProvider
import org.jetbrains.kotlin.fir.resolve.providers.impl.FirExtensionSyntheticFunctionInterfaceProvider
import org.jetbrains.kotlin.fir.scopes.FirKotlinScopeProvider
import org.jetbrains.kotlin.fir.scopes.FirPlatformClassMapper
import org.jetbrains.kotlin.library.isNativeStdlib
import org.jetbrains.kotlin.library.metadata.impl.KlibResolvedModuleDescriptorsFactoryImpl.Companion.FORWARD_DECLARATIONS_MODULE_NAME
import org.jetbrains.kotlin.library.metadata.resolver.KotlinResolvedLibrary
import org.jetbrains.kotlin.name.Name
@@ -52,7 +52,11 @@ object FirNativeSessionFactory : FirAbstractSessionFactory() {
).apply {
bindSession(session)
}
val kotlinLibraries = resolvedLibraries.map { it.library }
val resolvedKotlinLibraries = resolvedLibraries.map { it.library }
// KT-61645: stdlib-native must appear before stdlib-common metadata in the dependency list
// TODO: Consider not reordering libraries after KT-61430 is fixed, and Gradle plugin determines full order of dependencies.
val (stdlib, otherDeps) = resolvedKotlinLibraries.partition { it.isNativeStdlib }
val kotlinLibraries = stdlib + otherDeps
listOfNotNull(
KlibBasedSymbolProvider(session, moduleDataProvider, kotlinScopeProvider, kotlinLibraries),
NativeForwardDeclarationsSymbolProvider(session, forwardDeclarationsModuleData, kotlinScopeProvider, kotlinLibraries),
@@ -98,6 +98,9 @@ val BaseKotlinLibrary.uniqueName: String
val BaseKotlinLibrary.shortName: String?
get() = manifestProperties.getProperty(KLIB_PROPERTY_SHORT_NAME)
val BaseKotlinLibrary.isNativeStdlib: Boolean
get() = uniqueName == KOTLIN_STDLIB_NAME
val BaseKotlinLibrary.unresolvedDependencies: List<RequiredUnresolvedLibrary>
get() = unresolvedDependencies(lenient = false).map { it as RequiredUnresolvedLibrary }
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
import org.jetbrains.kotlin.gradle.testbase.*
import org.jetbrains.kotlin.gradle.util.checkedReplace
import org.jetbrains.kotlin.gradle.util.modify
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.condition.OS
import org.junit.jupiter.api.io.TempDir
@@ -1238,6 +1239,14 @@ open class HierarchicalMppIT : KGPBaseTest() {
}
}
@Disabled("Disabled until kotlin-native fix from MR https://jetbrains.team/p/kt/reviews/12079/timeline is deployed and can be tested")
@GradleTest
@DisplayName("K2: Check native stdlib is not shadowed by commonMain metadata")
fun testK2NativeStdlibConflict(gradleVersion: GradleVersion) {
nativeProject("kt61430", gradleVersion, buildOptions = defaultBuildOptions.copyEnsuringK2()) {
build("assemble")
}
}
private fun TestProject.testDependencyTransformations(
subproject: String? = null,
@@ -0,0 +1,16 @@
plugins {
kotlin("multiplatform")
}
group = "org.jetbrains.qa"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
mavenLocal()
}
kotlin {
linuxX64()
mingwX64() // can be any dummy target here, just for sake of nativeMain auto-insertion
}
@@ -0,0 +1,6 @@
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KType
public fun <K : Any?, V : Any?> returnTypeLinux(field: KMutableProperty1<K, V>): KType {
return field.returnType
}
@@ -0,0 +1,6 @@
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KType
fun <K : Any?, V : Any?> returnTypeShared(field: KMutableProperty1<K, V>): KType {
return field.returnType
}
+8 -1
View File
@@ -26,7 +26,14 @@ dependencies {
}
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")
implementation("org.jetbrains.kotlin:kotlin-native-utils:${project.bootstrapKotlinVersion}")
// KT-61897: Workaround for https://github.com/gradle/gradle/issues/26358
// (wrong conflict resolution, causing selection of not the latest version of `:kotlin-util-klib` module)
if (rootProject.name == "native-build-tools") {
implementation("org.jetbrains.kotlin:kotlin-native-utils:${project.bootstrapKotlinVersion}")
} else {
implementation(project(":native:kotlin-native-utils"))
}
}
group = "org.jetbrains.kotlin"