From 3b1a7c3ac11e1825b57adf243d84589bb259a606 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Wed, 24 May 2023 11:54:08 +0200 Subject: [PATCH] [Gradle] CInteropConfigurations: Support lazy configuration Using 'whenEvaluated' (aka 'afterEvaluate') is not supported when using lazy APIs (like register). In order to safely copy user configuration in both use-cases, 'launchInStage(AfterFinaliseDsl)' is used as this will be safe either way. ^KT-58838 Verification Pending --- .../targets/native/internal/CInteropConfigurations.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropConfigurations.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropConfigurations.kt index ce64bca7928..7d5fcd6e2f1 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropConfigurations.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropConfigurations.kt @@ -10,20 +10,21 @@ import org.gradle.api.artifacts.Configuration import org.gradle.api.attributes.* import org.gradle.api.tasks.TaskProvider import org.jetbrains.kotlin.gradle.plugin.KotlinNativeTargetConfigurator.NativeArtifactFormat +import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle.Stage.AfterFinaliseDsl import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.categoryByName import org.jetbrains.kotlin.gradle.plugin.internal.artifactTypeAttribute +import org.jetbrains.kotlin.gradle.plugin.launchInStage import org.jetbrains.kotlin.gradle.plugin.mpp.* import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.copyAttributes import org.jetbrains.kotlin.gradle.plugin.usesPlatformOf -import org.jetbrains.kotlin.gradle.plugin.whenEvaluated import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropKlibLibraryElements.cinteropKlibLibraryElements import org.jetbrains.kotlin.gradle.tasks.CInteropProcess internal fun createCInteropApiElementsKlibArtifact( target: KotlinNativeTarget, settings: DefaultCInteropSettings, - interopTask: TaskProvider + interopTask: TaskProvider, ) { val project = target.project val configurationName = cInteropApiElementsConfigurationName(target) @@ -51,7 +52,7 @@ internal fun Project.locateOrCreateCInteropDependencyConfiguration( isCanBeConsumed = false /* Deferring attributes to wait for compilation.attributes to be configured by user*/ - whenEvaluated { + launchInStage(AfterFinaliseDsl) { usesPlatformOf(compilation.target) copyAttributes(compilation.attributes, attributes) attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, cinteropKlibLibraryElements()) @@ -74,7 +75,7 @@ internal fun Project.locateOrCreateCInteropApiElementsConfiguration(target: Kotl isCanBeConsumed = true /* Deferring attributes to wait for target.attributes to be configured by user */ - whenEvaluated { + launchInStage(AfterFinaliseDsl) { usesPlatformOf(target) copyAttributes(target.attributes, attributes) attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, cinteropKlibLibraryElements())