From 2e1fc15a9a42089e5a30138710e50ffa780e31b2 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Tue, 28 Dec 2021 15:32:35 +0100 Subject: [PATCH] [MPP] Only enable cinterop metadata transformation when cinterop commonization is enabled Both library author and consumer need to enable cinterop commonization in order to support libraries with commonized cinterops in their API surface. --- .../jetbrains/kotlin/gradle/plugin/KotlinProperties.kt | 4 +++- .../internal/CInteropMetadataDependencyClasspath.kt | 3 ++- .../CInteropMetadataDependencyTransformationTask.kt | 9 +++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinProperties.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinProperties.kt index 8c5a1db607f..af358a0f4ca 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinProperties.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinProperties.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessageOutputStreamHandler.Companion.IGNORE_TCSM_OVERFLOW import org.jetbrains.kotlin.gradle.plugin.Kotlin2JsPlugin.Companion.NOWARN_2JS_FLAG import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.Companion.jsCompilerProperty +import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_CINTEROP_COMMONIZATION import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_GRANULAR_SOURCE_SETS_METADATA import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_HIERARCHICAL_STRUCTURE_BY_DEFAULT import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_HIERARCHICAL_STRUCTURE_SUPPORT @@ -284,7 +285,7 @@ internal class PropertiesProvider private constructor(private val project: Proje * Enables experimental commonization of user defined c-interop libraries. */ val enableCInteropCommonization: Boolean - get() = booleanProperty("kotlin.mpp.enableCInteropCommonization") ?: false + get() = booleanProperty(KOTLIN_MPP_ENABLE_CINTEROP_COMMONIZATION) ?: false val commonizerLogLevel: String? @@ -429,6 +430,7 @@ internal class PropertiesProvider private constructor(private val project: Proje object PropertyNames { const val KOTLIN_MPP_ENABLE_GRANULAR_SOURCE_SETS_METADATA = "kotlin.mpp.enableGranularSourceSetsMetadata" + const val KOTLIN_MPP_ENABLE_CINTEROP_COMMONIZATION = "kotlin.mpp.enableCInteropCommonization" const val KOTLIN_MPP_HIERARCHICAL_STRUCTURE_BY_DEFAULT = "kotlin.internal.mpp.hierarchicalStructureByDefault" const val KOTLIN_MPP_HIERARCHICAL_STRUCTURE_SUPPORT = "kotlin.mpp.hierarchicalStructureSupport" const val KOTLIN_NATIVE_DEPENDENCY_PROPAGATION = "kotlin.native.enableDependencyPropagation" diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropMetadataDependencyClasspath.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropMetadataDependencyClasspath.kt index 6539c3dffa8..b4aba5491e9 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropMetadataDependencyClasspath.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropMetadataDependencyClasspath.kt @@ -31,6 +31,7 @@ internal fun Project.createCInteropMetadataDependencyClasspathForIde(sourceSet: internal fun Project.createCInteropMetadataDependencyClasspath(sourceSet: DefaultKotlinSourceSet, forIde: Boolean): FileCollection { val dependencyTransformationTask = if (forIde) locateOrRegisterCInteropMetadataDependencyTransformationTaskForIde(sourceSet) else locateOrRegisterCInteropMetadataDependencyTransformationTask(sourceSet) + if (dependencyTransformationTask == null) return project.files() /* The classpath will be assembled by three independent parts @@ -98,4 +99,4 @@ internal val ChooseVisibleSourceSets.visibleSourceSetsProvidingCInterops: Set { +): TaskProvider? { + if (!kotlinPropertiesProvider.enableCInteropCommonization) return null + return locateOrRegisterTask( lowerCamelCaseName("transform", sourceSet.name, "CInteropDependenciesMetadata"), args = listOf( @@ -45,7 +48,9 @@ internal fun Project.locateOrRegisterCInteropMetadataDependencyTransformationTas internal fun Project.locateOrRegisterCInteropMetadataDependencyTransformationTaskForIde( sourceSet: DefaultKotlinSourceSet, -): TaskProvider { +): TaskProvider? { + if (!kotlinPropertiesProvider.enableCInteropCommonization) return null + return locateOrRegisterTask( lowerCamelCaseName("transform", sourceSet.name, "CInteropDependenciesMetadataForIde"), invokeWhenRegistered = { commonizeTask.dependsOn(this) },