[Gradle] Implement GlobalProjectStructureMetadataStorageSetupAction

KT-61634
This commit is contained in:
Sebastian Sellmair
2023-10-16 18:45:44 +02:00
committed by Space Team
parent 2b823cba1e
commit 9ca22fa999
3 changed files with 18 additions and 20 deletions
@@ -64,24 +64,8 @@ class KotlinMultiplatformPlugin : Plugin<Project> {
project.setupGeneralKotlinExtensionParameters()
project.pluginManager.apply(ScriptingGradleSubplugin::class.java)
exportProjectStructureMetadataForOtherBuilds(kotlinMultiplatformExtension)
}
private fun exportProjectStructureMetadataForOtherBuilds(
extension: KotlinMultiplatformExtension,
) {
// Run in AfterEvaluate stage to avoid issues with Precompiled Script Plugins
// When Gradle runs `:generatePrecompiledScriptPluginAccessors` it creates dummy project and
// applies plugins from *.gradle.kts file to and generates accessors from it.
// These dummy projects never gets evaluated and should not expose any Project Structure Metadata.
// Putting registerProjectStructureMetadata in AfterEvaluate stage prevents PSM registration in dummy projects.
extension.project.launchInStage(AfterEvaluateBuildscript) {
GlobalProjectStructureMetadataStorage.registerProjectStructureMetadata(extension.project) {
extension.kotlinProjectStructureMetadata
}
}
}
private fun setupAdditionalCompilerArguments(project: Project) {
// common source sets use the compiler options from the metadata compilation:
@@ -15,6 +15,10 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle
import org.jetbrains.kotlin.gradle.plugin.KotlinProjectSetupCoroutine
import org.jetbrains.kotlin.gradle.plugin.await
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
import org.jetbrains.kotlin.gradle.plugin.sources.sourceSetDependencyConfigurationByScope
import org.jetbrains.kotlin.gradle.targets.metadata.dependsOnClosureWithInterCompilationDependencies
@@ -22,10 +26,6 @@ import org.jetbrains.kotlin.gradle.targets.metadata.getPublishedPlatformCompilat
import org.jetbrains.kotlin.gradle.targets.metadata.isNativeSourceSet
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropCommonizerCompositeMetadataJarBundling.cinteropMetadataDirectoryPath
import org.jetbrains.kotlin.gradle.utils.*
import org.jetbrains.kotlin.gradle.utils.buildPathCompat
import org.jetbrains.kotlin.gradle.utils.compositeBuildRootProject
import org.jetbrains.kotlin.gradle.utils.currentBuildId
import org.jetbrains.kotlin.gradle.utils.future
import org.w3c.dom.Document
import org.w3c.dom.Element
import org.w3c.dom.Node
@@ -388,6 +388,18 @@ internal fun <ParsingContext> parseKotlinSourceSetMetadata(
)
}
internal val GlobalProjectStructureMetadataStorageSetupAction = KotlinProjectSetupCoroutine {
// Run in AfterEvaluate stage to avoid issues with Precompiled Script Plugins
// When Gradle runs `:generatePrecompiledScriptPluginAccessors` it creates dummy project and
// applies plugins from *.gradle.kts file to and generates accessors from it.
// These dummy projects never gets evaluated and should not expose any Project Structure Metadata.
// Putting registerProjectStructureMetadata in AfterEvaluate stage prevents PSM registration in dummy projects.
KotlinPluginLifecycle.Stage.AfterEvaluateBuildscript.await()
GlobalProjectStructureMetadataStorage.registerProjectStructureMetadata(project) {
multiplatformExtension.kotlinProjectStructureMetadata
}
}
internal object GlobalProjectStructureMetadataStorage {
private const val propertyPrefix = "kotlin.projectStructureMetadata.build"
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.gradle.plugin.diagnostics.checkers.UnusedSourceSetsC
import org.jetbrains.kotlin.gradle.plugin.diagnostics.checkers.WasmSourceSetsNotFoundChecker
import org.jetbrains.kotlin.gradle.plugin.ide.IdeMultiplatformImportSetupAction
import org.jetbrains.kotlin.gradle.plugin.ide.IdeResolveDependenciesTaskSetupAction
import org.jetbrains.kotlin.gradle.plugin.mpp.GlobalProjectStructureMetadataStorageSetupAction
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.AddBuildListenerForXCodeSetupAction
import org.jetbrains.kotlin.gradle.targets.js.npm.AddNpmDependencyExtensionProjectSetupAction
import org.jetbrains.kotlin.gradle.targets.native.CreateFatFrameworksSetupAction
@@ -46,6 +47,7 @@ internal fun Project.registerKotlinPluginExtensions() {
register(project, KotlinToolingDiagnosticsSetupAction)
if (isMultiplatform) {
register(project, GlobalProjectStructureMetadataStorageSetupAction)
register(project, IdeMultiplatformImportSetupAction)
register(project, IdeResolveDependenciesTaskSetupAction)
register(project, CInteropCommonizedCInteropApiElementsConfigurationsSetupAction)