[Gradle] Change signature of top-level await(Stage) to Stage.await()

^KT-56654 Verification Pending
This commit is contained in:
Sebastian Sellmair
2023-03-29 10:59:47 +02:00
committed by Space Team
parent 775e08e41d
commit 262b45405d
13 changed files with 23 additions and 27 deletions
@@ -27,7 +27,7 @@ abstract class KotlinMultiplatformExtension(project: Project) :
final override val targets: NamedDomainObjectCollection<KotlinTarget> = project.container(KotlinTarget::class.java) final override val targets: NamedDomainObjectCollection<KotlinTarget> = project.container(KotlinTarget::class.java)
internal suspend fun awaitTargets(): NamedDomainObjectCollection<KotlinTarget> { internal suspend fun awaitTargets(): NamedDomainObjectCollection<KotlinTarget> {
await(AfterFinaliseDsl) AfterFinaliseDsl.await()
return targets return targets
} }
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
import org.gradle.api.Action import org.gradle.api.Action
import org.gradle.api.GradleException
import org.gradle.api.Named import org.gradle.api.Named
import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project import org.gradle.api.Project
@@ -30,9 +29,7 @@ import org.jetbrains.kotlin.gradle.utils.castIsolatedKotlinPluginClassLoaderAwar
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
import org.jetbrains.kotlin.konan.target.CompilerOutputKind import org.jetbrains.kotlin.konan.target.CompilerOutputKind
import org.jetbrains.kotlin.statistics.metrics.StringMetrics import org.jetbrains.kotlin.statistics.metrics.StringMetrics
import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Provider
import kotlin.reflect.KClass import kotlin.reflect.KClass
private const val KOTLIN_PROJECT_EXTENSION_NAME = "kotlin" private const val KOTLIN_PROJECT_EXTENSION_NAME = "kotlin"
@@ -154,7 +151,7 @@ open class KotlinProjectExtension @Inject constructor(project: Project) : Kotlin
} }
internal suspend fun awaitSourceSets(): NamedDomainObjectContainer<KotlinSourceSet> { internal suspend fun awaitSourceSets(): NamedDomainObjectContainer<KotlinSourceSet> {
await(KotlinPluginLifecycle.Stage.AfterFinaliseDsl) KotlinPluginLifecycle.Stage.AfterFinaliseDsl.await()
return sourceSets return sourceSets
} }
} }
@@ -132,11 +132,11 @@ internal suspend fun currentKotlinPluginLifecycle(): KotlinPluginLifecycle {
} }
/** /**
* Suspends execution until we *at least* reached the specified [stage] * Suspends execution until we *at least* reached the specified [this@await]
* This will return right away if the specified [stage] was already executed or we are currently executing the [stage] * This will return right away if the specified [this@await] was already executed or we are currently executing the [this@await]
*/ */
internal suspend fun await(stage: Stage) { internal suspend fun Stage.await() {
currentKotlinPluginLifecycle().await(stage) currentKotlinPluginLifecycle().await(this)
} }
/** /**
@@ -181,7 +181,7 @@ internal suspend fun <T : Any> Property<T>.awaitFinalValue(): T? {
return lifecycleAwareProperty.awaitFinalValue() return lifecycleAwareProperty.awaitFinalValue()
} }
await(Stage.FinaliseDsl) Stage.FinaliseDsl.await()
finalizeValue() finalizeValue()
return orNull return orNull
} }
@@ -476,7 +476,7 @@ private class KotlinPluginLifecycleImpl(override val project: Project) : KotlinP
) : LifecycleAwareProperty<T> { ) : LifecycleAwareProperty<T> {
override suspend fun awaitFinalValue(): T? { override suspend fun awaitFinalValue(): T? {
await(finaliseIn) finaliseIn.await()
return property.orNull return property.orNull
} }
} }
@@ -338,7 +338,7 @@ private fun Project.collectAllProjectsData(): Map<String, GranularMetadataTransf
path = path, path = path,
sourceSetMetadataOutputs = currentProject.future { currentProject.collectSourceSetMetadataOutputs() }.lenient, sourceSetMetadataOutputs = currentProject.future { currentProject.collectSourceSetMetadataOutputs() }.lenient,
moduleId = currentProject.future { moduleId = currentProject.future {
await(KotlinPluginLifecycle.Stage.AfterFinaliseDsl) KotlinPluginLifecycle.Stage.AfterFinaliseDsl.await()
ModuleIds.idOfRootModule(currentProject) ModuleIds.idOfRootModule(currentProject)
}.lenient }.lenient
) )
@@ -16,7 +16,6 @@ import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
import org.jetbrains.kotlin.gradle.internal.customizeKotlinDependencies import org.jetbrains.kotlin.gradle.internal.customizeKotlinDependencies
import org.jetbrains.kotlin.gradle.plugin.* import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.plugin.ide.kotlinIdeMultiplatformImport import org.jetbrains.kotlin.gradle.plugin.ide.kotlinIdeMultiplatformImport
@@ -268,7 +267,7 @@ internal fun sourcesJarTask(compilation: KotlinCompilation<*>, componentName: St
sourcesJarTask( sourcesJarTask(
compilation.target.project, compilation.target.project,
compilation.target.project.future { compilation.target.project.future {
await(KotlinPluginLifecycle.Stage.AfterFinaliseCompilations) KotlinPluginLifecycle.Stage.AfterFinaliseCompilations.await()
compilation.allKotlinSourceSets.associate { it.name to it.kotlin } compilation.allKotlinSourceSets.associate { it.name to it.kotlin }
}, },
componentName, componentName,
@@ -43,7 +43,7 @@ abstract class KotlinSoftwareComponent(
private val metadataTarget get() = project.multiplatformExtension.metadata() as KotlinMetadataTarget private val metadataTarget get() = project.multiplatformExtension.metadata() as KotlinMetadataTarget
private val _variants = project.future { private val _variants = project.future {
await(AfterFinaliseCompilations) AfterFinaliseCompilations.await()
kotlinTargets kotlinTargets
.filter { target -> target !is KotlinMetadataTarget } .filter { target -> target !is KotlinMetadataTarget }
.flatMap { target -> .flatMap { target ->
@@ -67,7 +67,7 @@ internal suspend fun Project.collectSourceSetMetadataOutputs(): Map<SourceSetNam
} }
private suspend fun KotlinMultiplatformExtension.sourceSetsMetadataOutputs(): Map<KotlinSourceSet, FileCollection> { private suspend fun KotlinMultiplatformExtension.sourceSetsMetadataOutputs(): Map<KotlinSourceSet, FileCollection> {
await(KotlinPluginLifecycle.Stage.AfterFinaliseDsl) KotlinPluginLifecycle.Stage.AfterFinaliseDsl.await()
return sourceSets.mapNotNull { sourceSet -> return sourceSets.mapNotNull { sourceSet ->
val destination = when (val compilation = project.findMetadataCompilation(sourceSet) ?: return@mapNotNull null) { val destination = when (val compilation = project.findMetadataCompilation(sourceSet) ?: return@mapNotNull null) {
@@ -26,6 +26,6 @@ internal interface InternalKotlinSourceSet : KotlinSourceSet {
} }
internal suspend fun InternalKotlinSourceSet.awaitPlatformCompilations(): Set<KotlinCompilation<*>> { internal suspend fun InternalKotlinSourceSet.awaitPlatformCompilations(): Set<KotlinCompilation<*>> {
await(KotlinPluginLifecycle.Stage.FinaliseRefinesEdges) KotlinPluginLifecycle.Stage.FinaliseRefinesEdges.await()
return compilations.filter { it !is KotlinMetadataCompilation }.toSet() return compilations.filter { it !is KotlinMetadataCompilation }.toSet()
} }
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.gradle.utils.futureExtension
import org.jetbrains.kotlin.tooling.core.UnsafeApi import org.jetbrains.kotlin.tooling.core.UnsafeApi
internal val KotlinSourceSet.commonizerTarget: Future<CommonizerTarget?> by futureExtension { internal val KotlinSourceSet.commonizerTarget: Future<CommonizerTarget?> by futureExtension {
await(KotlinPluginLifecycle.Stage.AfterFinaliseRefinesEdges) KotlinPluginLifecycle.Stage.AfterFinaliseRefinesEdges.await()
@OptIn(UnsafeApi::class) @OptIn(UnsafeApi::class)
inferCommonizerTarget(this) inferCommonizerTarget(this)
} }
@@ -32,7 +32,7 @@ internal val KotlinSourceSet.sharedCommonizerTarget: Future<SharedCommonizerTarg
get() = project.future { commonizerTarget.await() as? SharedCommonizerTarget } get() = project.future { commonizerTarget.await() as? SharedCommonizerTarget }
internal val KotlinCompilation<*>.commonizerTarget: Future<CommonizerTarget?> by futureExtension { internal val KotlinCompilation<*>.commonizerTarget: Future<CommonizerTarget?> by futureExtension {
await(KotlinPluginLifecycle.Stage.AfterFinaliseRefinesEdges) KotlinPluginLifecycle.Stage.AfterFinaliseRefinesEdges.await()
@OptIn(UnsafeApi::class) @OptIn(UnsafeApi::class)
inferCommonizerTarget(this) inferCommonizerTarget(this)
} }
@@ -31,7 +31,7 @@ class FutureTest {
@Test @Test
fun `test - simple deferred future`() = project.runLifecycleAwareTest { fun `test - simple deferred future`() = project.runLifecycleAwareTest {
val future = project.future { val future = project.future {
await(FinaliseDsl) FinaliseDsl.await()
42 42
} }
@@ -44,7 +44,7 @@ class FutureTest {
@Test @Test
fun `test - future depending on another future`() = project.runLifecycleAwareTest { fun `test - future depending on another future`() = project.runLifecycleAwareTest {
val futureA = project.future { val futureA = project.future {
await(FinaliseDsl) FinaliseDsl.await()
42 42
} }
@@ -64,7 +64,7 @@ class FutureTest {
project.evaluate() project.evaluate()
val future = project.future { val future = project.future {
await(FinaliseDsl) FinaliseDsl.await()
42 42
} }
@@ -78,7 +78,7 @@ class InvokeWhenCreatedTest {
project.kotlinExtension.apply { project.kotlinExtension.apply {
val invocations = AtomicInteger(0) val invocations = AtomicInteger(0)
container.invokeWhenCreated("x") { assertEquals(1, invocations.incrementAndGet()) } container.invokeWhenCreated("x") { assertEquals(1, invocations.incrementAndGet()) }
await(KotlinPluginLifecycle.Stage.last) KotlinPluginLifecycle.Stage.last.await()
assertEquals(0, invocations.get()) assertEquals(0, invocations.get())
container.create("x") container.create("x")
assertEquals(1, invocations.get()) assertEquals(1, invocations.get())
@@ -68,7 +68,7 @@ class KotlinAndroidTargetVariantTypeDslImplTest {
instrumentedTest.targetHierarchy.module.set(KotlinTargetHierarchy.ModuleName.test) instrumentedTest.targetHierarchy.module.set(KotlinTargetHierarchy.ModuleName.test)
} }
await(AfterFinaliseRefinesEdges) AfterFinaliseRefinesEdges.await()
assertEquals(setOf("commonTest"), kotlin.sourceSets.getByName("androidInstrumentedTest").dependsOn.map { it.name }.toSet()) assertEquals(setOf("commonTest"), kotlin.sourceSets.getByName("androidInstrumentedTest").dependsOn.map { it.name }.toSet())
assertEquals(setOf("commonTest"), kotlin.sourceSets.getByName("androidUnitTest").dependsOn.map { it.name }.toSet()) assertEquals(setOf("commonTest"), kotlin.sourceSets.getByName("androidUnitTest").dependsOn.map { it.name }.toSet())
@@ -95,7 +95,7 @@ class KotlinAndroidTargetVariantTypeDslImplTest {
withModule(KotlinTargetHierarchy.ModuleName("yyy")) withModule(KotlinTargetHierarchy.ModuleName("yyy"))
} }
await(AfterFinaliseRefinesEdges) AfterFinaliseRefinesEdges.await()
assertEquals(setOf("commonXxx"), kotlin.sourceSets.getByName("androidUnitTest").dependsOn.map { it.name }.toSet()) assertEquals(setOf("commonXxx"), kotlin.sourceSets.getByName("androidUnitTest").dependsOn.map { it.name }.toSet())
assertEquals(setOf("commonYyy"), kotlin.sourceSets.getByName("androidInstrumentedTest").dependsOn.map { it.name }.toSet()) assertEquals(setOf("commonYyy"), kotlin.sourceSets.getByName("androidInstrumentedTest").dependsOn.map { it.name }.toSet())
@@ -371,9 +371,9 @@ class KotlinPluginLifecycleTest {
} }
} }
await(AfterEvaluateBuildscript.nextOrThrow.nextOrThrow) AfterEvaluateBuildscript.nextOrThrow.nextOrThrow.await()
assertEquals(1, actionInvocations.get()) assertEquals(1, actionInvocations.get())
await(Stage.values.last()) Stage.values.last().await()
} }
/** /**