[Gradle] Implement 'BuildIdentifier.isCurrentBuildCompat'

^KT-58157 In Progress
This commit is contained in:
Sebastian Sellmair
2023-07-27 17:39:14 +02:00
committed by Space Team
parent 33a61c62ba
commit e9e0a4741c
7 changed files with 21 additions and 8 deletions
@@ -232,7 +232,7 @@ internal class GranularMetadataTransformation(
error("Artifacts of dependency ${module.id.displayName} is built by old Kotlin Gradle Plugin and can't be consumed in this way")
}
val isResolvedToProject = moduleId is ProjectComponentIdentifier && moduleId.build.isCurrentBuild
val isResolvedToProject = moduleId is ProjectComponentIdentifier && moduleId.build.isCurrentBuildCompat
val sourceSetVisibility =
params.sourceSetVisibilityProvider.getVisibleSourceSets(
@@ -300,7 +300,7 @@ internal class GranularMetadataTransformation(
return when (val componentId = component.id) {
is ModuleComponentIdentifier -> ModuleDependencyIdentifier(componentId.group, componentId.module)
is ProjectComponentIdentifier -> {
if (componentId.build.isCurrentBuild) {
if (componentId.build.isCurrentBuildCompat) {
params.projectData[componentId.projectPath]?.moduleId?.getOrThrow()
?: error("Cant find project Module ID by ${componentId.projectPath}")
} else {
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.gradle.plugin.mpp
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.jetbrains.kotlin.gradle.utils.isCurrentBuildCompat
import org.jetbrains.kotlin.project.model.KpmModuleIdentifier
import java.io.File
import java.io.InputStream
@@ -56,7 +57,7 @@ internal class IncludedBuildMppDependencyProjectStructureMetadataExtractor(
) : JarMppDependencyProjectStructureMetadataExtractor(primaryArtifact) {
init {
require(!componentId.build.isCurrentBuild) { "should be a project from an included build" }
require(!componentId.build.isCurrentBuildCompat) { "should be a project from an included build" }
}
override fun getProjectStructureMetadata(): KotlinProjectStructureMetadata? = projectStructureMetadataProvider()
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.toSingleKpmModuleIdentifier
import org.jetbrains.kotlin.gradle.utils.buildNameCompat
import org.jetbrains.kotlin.gradle.utils.buildPathCompat
import org.jetbrains.kotlin.gradle.utils.getOrPut
import org.jetbrains.kotlin.gradle.utils.isCurrentBuildCompat
internal val Project.kotlinMppDependencyProjectStructureMetadataExtractorFactory: MppDependencyProjectStructureMetadataExtractorFactory
get() = MppDependencyProjectStructureMetadataExtractorFactory.getOrCreate(this)
@@ -34,7 +35,7 @@ private constructor(
val moduleId = metadataArtifact.variant.owner
return if (moduleId is ProjectComponentIdentifier) {
if (moduleId.build.isCurrentBuild) {
if (moduleId.build.isCurrentBuildCompat) {
val projectStructureMetadataProvider = currentBuildProjectStructureMetadataProviders[moduleId.projectPath]
?: error("Project structure metadata not found for project '${moduleId.projectPath}'")
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder
import org.jetbrains.kotlin.gradle.utils.getOrPutRootProjectProperty
import org.jetbrains.kotlin.gradle.utils.isCurrentBuildCompat
import org.jetbrains.kotlin.project.model.*
class GradleKpmModuleDependencyResolver(
@@ -35,7 +36,7 @@ class GradleKpmModuleDependencyResolver(
val classifier = moduleClassifiersFromCapabilities(component?.variants?.flatMap { it.capabilities }.orEmpty()).single()
return when {
id is ProjectComponentIdentifier && id.build.isCurrentBuild ->
id is ProjectComponentIdentifier && id.build.isCurrentBuildCompat ->
projectModuleBuilder.buildModulesFromProject(project.project(id.projectPath))
.find { it.moduleIdentifier.moduleClassifier == classifier }
id is ModuleComponentIdentifier -> {
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KpmGradleModuleVariantResolver
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.allDependencyModules
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.disambiguateName
import org.jetbrains.kotlin.gradle.utils.filesProvider
import org.jetbrains.kotlin.gradle.utils.isCurrentBuildCompat
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
import org.jetbrains.kotlin.project.model.KpmVariantResolution
@@ -38,7 +39,7 @@ interface GradleKpmVariantCompilationDataInternal<T : KotlinCommonOptions> : Gra
view.componentFilter { id ->
// FIXME rewrite using the proper module resolution after those changes are merged
val asProject = id as? ProjectComponentIdentifier
asProject?.build?.isCurrentBuild == true &&
asProject?.build?.isCurrentBuildCompat == true &&
asProject.projectPath == owner.project.path
}
}.artifacts.filter {
@@ -52,4 +52,13 @@ internal val BuildIdentifier.buildNameCompat: String
*/
internal val BuildIdentifier.buildPathCompat: String
get() = if (GradleVersion.current() >= GradleVersion.version("8.2")) buildPath
else @Suppress("DEPRECATION") if (name.startsWith(":")) name else ":$name"
else @Suppress("DEPRECATION") if (name.startsWith(":")) name else ":$name"
/**
* Will return [BuildIdentifier.isCurrentBuild] for Gradle versions less than 8.2
* Will use the [BuildIdentifier.getBuildPath] to check if the buildIdentifier is the 'current' build
*/
internal val BuildIdentifier.isCurrentBuildCompat: Boolean
get() = if (GradleVersion.current() >= GradleVersion.version("8.2")) buildPath == ":"
else @Suppress("DEPRECATION") isCurrentBuild
@@ -21,7 +21,7 @@ internal val ComponentIdentifier.isProjectComponentIdentifierInCurrentBuild: Boo
internal val ComponentIdentifier.currentBuildProjectIdOrNull
get(): ProjectComponentIdentifier? = when {
this is ProjectComponentIdentifier && build.isCurrentBuild -> this
this is ProjectComponentIdentifier && build.isCurrentBuildCompat -> this
else -> null
}