[Gradle] Implement 'BuildIdentifier.isCurrentBuildCompat'
^KT-58157 In Progress
This commit is contained in:
committed by
Space Team
parent
33a61c62ba
commit
e9e0a4741c
+2
-2
@@ -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")
|
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 =
|
val sourceSetVisibility =
|
||||||
params.sourceSetVisibilityProvider.getVisibleSourceSets(
|
params.sourceSetVisibilityProvider.getVisibleSourceSets(
|
||||||
@@ -300,7 +300,7 @@ internal class GranularMetadataTransformation(
|
|||||||
return when (val componentId = component.id) {
|
return when (val componentId = component.id) {
|
||||||
is ModuleComponentIdentifier -> ModuleDependencyIdentifier(componentId.group, componentId.module)
|
is ModuleComponentIdentifier -> ModuleDependencyIdentifier(componentId.group, componentId.module)
|
||||||
is ProjectComponentIdentifier -> {
|
is ProjectComponentIdentifier -> {
|
||||||
if (componentId.build.isCurrentBuild) {
|
if (componentId.build.isCurrentBuildCompat) {
|
||||||
params.projectData[componentId.projectPath]?.moduleId?.getOrThrow()
|
params.projectData[componentId.projectPath]?.moduleId?.getOrThrow()
|
||||||
?: error("Cant find project Module ID by ${componentId.projectPath}")
|
?: error("Cant find project Module ID by ${componentId.projectPath}")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+2
-1
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||||
|
|
||||||
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
|
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.isCurrentBuildCompat
|
||||||
import org.jetbrains.kotlin.project.model.KpmModuleIdentifier
|
import org.jetbrains.kotlin.project.model.KpmModuleIdentifier
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
@@ -56,7 +57,7 @@ internal class IncludedBuildMppDependencyProjectStructureMetadataExtractor(
|
|||||||
) : JarMppDependencyProjectStructureMetadataExtractor(primaryArtifact) {
|
) : JarMppDependencyProjectStructureMetadataExtractor(primaryArtifact) {
|
||||||
|
|
||||||
init {
|
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()
|
override fun getProjectStructureMetadata(): KotlinProjectStructureMetadata? = projectStructureMetadataProvider()
|
||||||
|
|||||||
+2
-1
@@ -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.buildNameCompat
|
||||||
import org.jetbrains.kotlin.gradle.utils.buildPathCompat
|
import org.jetbrains.kotlin.gradle.utils.buildPathCompat
|
||||||
import org.jetbrains.kotlin.gradle.utils.getOrPut
|
import org.jetbrains.kotlin.gradle.utils.getOrPut
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.isCurrentBuildCompat
|
||||||
|
|
||||||
internal val Project.kotlinMppDependencyProjectStructureMetadataExtractorFactory: MppDependencyProjectStructureMetadataExtractorFactory
|
internal val Project.kotlinMppDependencyProjectStructureMetadataExtractorFactory: MppDependencyProjectStructureMetadataExtractorFactory
|
||||||
get() = MppDependencyProjectStructureMetadataExtractorFactory.getOrCreate(this)
|
get() = MppDependencyProjectStructureMetadataExtractorFactory.getOrCreate(this)
|
||||||
@@ -34,7 +35,7 @@ private constructor(
|
|||||||
val moduleId = metadataArtifact.variant.owner
|
val moduleId = metadataArtifact.variant.owner
|
||||||
|
|
||||||
return if (moduleId is ProjectComponentIdentifier) {
|
return if (moduleId is ProjectComponentIdentifier) {
|
||||||
if (moduleId.build.isCurrentBuild) {
|
if (moduleId.build.isCurrentBuildCompat) {
|
||||||
val projectStructureMetadataProvider = currentBuildProjectStructureMetadataProviders[moduleId.projectPath]
|
val projectStructureMetadataProvider = currentBuildProjectStructureMetadataProviders[moduleId.projectPath]
|
||||||
?: error("Project structure metadata not found for project '${moduleId.projectPath}'")
|
?: error("Project structure metadata not found for project '${moduleId.projectPath}'")
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder
|
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder
|
||||||
import org.jetbrains.kotlin.gradle.utils.getOrPutRootProjectProperty
|
import org.jetbrains.kotlin.gradle.utils.getOrPutRootProjectProperty
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.isCurrentBuildCompat
|
||||||
import org.jetbrains.kotlin.project.model.*
|
import org.jetbrains.kotlin.project.model.*
|
||||||
|
|
||||||
class GradleKpmModuleDependencyResolver(
|
class GradleKpmModuleDependencyResolver(
|
||||||
@@ -35,7 +36,7 @@ class GradleKpmModuleDependencyResolver(
|
|||||||
val classifier = moduleClassifiersFromCapabilities(component?.variants?.flatMap { it.capabilities }.orEmpty()).single()
|
val classifier = moduleClassifiersFromCapabilities(component?.variants?.flatMap { it.capabilities }.orEmpty()).single()
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
id is ProjectComponentIdentifier && id.build.isCurrentBuild ->
|
id is ProjectComponentIdentifier && id.build.isCurrentBuildCompat ->
|
||||||
projectModuleBuilder.buildModulesFromProject(project.project(id.projectPath))
|
projectModuleBuilder.buildModulesFromProject(project.project(id.projectPath))
|
||||||
.find { it.moduleIdentifier.moduleClassifier == classifier }
|
.find { it.moduleIdentifier.moduleClassifier == classifier }
|
||||||
id is ModuleComponentIdentifier -> {
|
id is ModuleComponentIdentifier -> {
|
||||||
|
|||||||
+2
-1
@@ -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.allDependencyModules
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.disambiguateName
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.disambiguateName
|
||||||
import org.jetbrains.kotlin.gradle.utils.filesProvider
|
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.gradle.utils.lowerCamelCaseName
|
||||||
import org.jetbrains.kotlin.project.model.KpmVariantResolution
|
import org.jetbrains.kotlin.project.model.KpmVariantResolution
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ interface GradleKpmVariantCompilationDataInternal<T : KotlinCommonOptions> : Gra
|
|||||||
view.componentFilter { id ->
|
view.componentFilter { id ->
|
||||||
// FIXME rewrite using the proper module resolution after those changes are merged
|
// FIXME rewrite using the proper module resolution after those changes are merged
|
||||||
val asProject = id as? ProjectComponentIdentifier
|
val asProject = id as? ProjectComponentIdentifier
|
||||||
asProject?.build?.isCurrentBuild == true &&
|
asProject?.build?.isCurrentBuildCompat == true &&
|
||||||
asProject.projectPath == owner.project.path
|
asProject.projectPath == owner.project.path
|
||||||
}
|
}
|
||||||
}.artifacts.filter {
|
}.artifacts.filter {
|
||||||
|
|||||||
+10
-1
@@ -52,4 +52,13 @@ internal val BuildIdentifier.buildNameCompat: String
|
|||||||
*/
|
*/
|
||||||
internal val BuildIdentifier.buildPathCompat: String
|
internal val BuildIdentifier.buildPathCompat: String
|
||||||
get() = if (GradleVersion.current() >= GradleVersion.version("8.2")) buildPath
|
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
|
||||||
+1
-1
@@ -21,7 +21,7 @@ internal val ComponentIdentifier.isProjectComponentIdentifierInCurrentBuild: Boo
|
|||||||
|
|
||||||
internal val ComponentIdentifier.currentBuildProjectIdOrNull
|
internal val ComponentIdentifier.currentBuildProjectIdOrNull
|
||||||
get(): ProjectComponentIdentifier? = when {
|
get(): ProjectComponentIdentifier? = when {
|
||||||
this is ProjectComponentIdentifier && build.isCurrentBuild -> this
|
this is ProjectComponentIdentifier && build.isCurrentBuildCompat -> this
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user