[Gradle] KotlinSoftwareComponent: Use future instead of lazy
^KT-34662 Verification Pending
This commit is contained in:
committed by
Space Team
parent
50f4531c77
commit
ab81e92932
+1
-1
@@ -333,7 +333,7 @@ open class NewMultiplatformIT : BaseGradleIT() {
|
||||
options = defaultBuildOptions().copy(jsCompilerType = jsCompilerType)
|
||||
) {
|
||||
assertSuccessful()
|
||||
assertTasksSkipped(":compileCommonMainKotlinMetadata")
|
||||
assertTasksNotExecuted(":compileCommonMainKotlinMetadata")
|
||||
assertTasksExecuted(*compileTasksNames.toTypedArray(), ":allMetadataJar")
|
||||
|
||||
val groupDir = projectDir.resolve("repo/com/example")
|
||||
|
||||
+23
-14
@@ -21,11 +21,13 @@ import org.gradle.jvm.tasks.Jar
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle.Stage.AfterFinaliseCompilations
|
||||
import org.jetbrains.kotlin.gradle.utils.markResolvable
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.*
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.COMMON_MAIN_ELEMENTS_CONFIGURATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.isCompatibilityMetadataVariantEnabled
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.isKotlinGranularMetadataEnabled
|
||||
import org.jetbrains.kotlin.gradle.utils.Future
|
||||
import org.jetbrains.kotlin.gradle.utils.future
|
||||
import org.jetbrains.kotlin.gradle.utils.setProperty
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||
@@ -38,23 +40,30 @@ abstract class KotlinSoftwareComponent(
|
||||
|
||||
override fun getName(): String = name
|
||||
|
||||
private val metadataTarget get() = project.multiplatformExtension.metadata()
|
||||
private val metadataTarget get() = project.multiplatformExtension.metadata() as KotlinMetadataTarget
|
||||
|
||||
override fun getVariants(): Set<SoftwareComponent> = kotlinTargets
|
||||
.filter { target -> target !is KotlinMetadataTarget }
|
||||
.flatMap { target ->
|
||||
val targetPublishableComponentNames = target.internal.kotlinComponents
|
||||
.filter { component -> component.publishable }
|
||||
.map { component -> component.name }
|
||||
.toSet()
|
||||
private val _variants = project.future {
|
||||
await(AfterFinaliseCompilations)
|
||||
kotlinTargets
|
||||
.filter { target -> target !is KotlinMetadataTarget }
|
||||
.flatMap { target ->
|
||||
val targetPublishableComponentNames = target.internal.kotlinComponents
|
||||
.filter { component -> component.publishable }
|
||||
.map { component -> component.name }
|
||||
.toSet()
|
||||
|
||||
target.components.filter { it.name in targetPublishableComponentNames }
|
||||
}.toSet()
|
||||
target.components.filter { it.name in targetPublishableComponentNames }
|
||||
}.toSet()
|
||||
}
|
||||
|
||||
override fun getVariants(): Set<SoftwareComponent> = _variants.getOrThrow()
|
||||
|
||||
private val _usages: Future<Set<DefaultKotlinUsageContext>> = project.future {
|
||||
metadataTarget.awaitMetadataCompilationsCreated()
|
||||
|
||||
private val _usages: Set<DefaultKotlinUsageContext> by lazy {
|
||||
if (!project.isKotlinGranularMetadataEnabled) {
|
||||
val metadataCompilation = metadataTarget.compilations.getByName(MAIN_COMPILATION_NAME)
|
||||
return@lazy metadataTarget.createUsageContexts(metadataCompilation)
|
||||
return@future metadataTarget.createUsageContexts(metadataCompilation)
|
||||
}
|
||||
|
||||
mutableSetOf<DefaultKotlinUsageContext>().apply {
|
||||
@@ -70,7 +79,6 @@ abstract class KotlinSoftwareComponent(
|
||||
overrideConfigurationArtifacts = project.setProperty { listOf(allMetadataArtifact) }
|
||||
)
|
||||
|
||||
|
||||
if (project.isCompatibilityMetadataVariantEnabled) {
|
||||
// Ensure that consumers who expect Kotlin 1.2.x metadata package can still get one:
|
||||
// publish the old metadata artifact:
|
||||
@@ -97,8 +105,9 @@ abstract class KotlinSoftwareComponent(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun getUsages(): Set<UsageContext> {
|
||||
return _usages.publishableUsages()
|
||||
return _usages.getOrThrow().publishableUsages()
|
||||
}
|
||||
|
||||
private suspend fun allPublishableCommonSourceSets() = getCommonSourceSetsForMetadataCompilation(project) +
|
||||
|
||||
+1
-4
@@ -290,10 +290,7 @@ class KotlinMetadataTargetConfigurator :
|
||||
val project = target.project
|
||||
|
||||
val compilationName = sourceSet.name
|
||||
|
||||
val platformCompilations = sourceSet.internal.compilations
|
||||
.filter { it.target.name != KotlinMultiplatformPlugin.METADATA_TARGET_NAME }
|
||||
|
||||
val platformCompilations = sourceSet.internal.awaitPlatformCompilations()
|
||||
val isNativeSourceSet = sourceSet.isNativeSourceSet.await()
|
||||
|
||||
val compilationFactory: KotlinCompilationFactory<out KotlinCompilation<*>> = when {
|
||||
|
||||
Reference in New Issue
Block a user