[Gradle] KotlinProjectStructureMetadata: Migrate to 'BuildIdentifier.getBuildPath'
^KT-58157 In Progress
This commit is contained in:
committed by
Space Team
parent
e07ae23df9
commit
9913ea2e20
+7
-6
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.gradle.targets.metadata.dependsOnClosureWithInterCom
|
|||||||
import org.jetbrains.kotlin.gradle.targets.metadata.getPublishedPlatformCompilations
|
import org.jetbrains.kotlin.gradle.targets.metadata.getPublishedPlatformCompilations
|
||||||
import org.jetbrains.kotlin.gradle.targets.metadata.isNativeSourceSet
|
import org.jetbrains.kotlin.gradle.targets.metadata.isNativeSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropCommonizerCompositeMetadataJarBundling.cinteropMetadataDirectoryPath
|
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropCommonizerCompositeMetadataJarBundling.cinteropMetadataDirectoryPath
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.buildPathCompat
|
||||||
import org.jetbrains.kotlin.gradle.utils.compositeBuildRootProject
|
import org.jetbrains.kotlin.gradle.utils.compositeBuildRootProject
|
||||||
import org.jetbrains.kotlin.gradle.utils.future
|
import org.jetbrains.kotlin.gradle.utils.future
|
||||||
import org.jetbrains.kotlin.gradle.utils.getOrPut
|
import org.jetbrains.kotlin.gradle.utils.getOrPut
|
||||||
@@ -421,13 +422,13 @@ internal object GlobalProjectStructureMetadataStorage {
|
|||||||
fun registerProjectStructureMetadata(project: Project, metadataProvider: () -> KotlinProjectStructureMetadata) {
|
fun registerProjectStructureMetadata(project: Project, metadataProvider: () -> KotlinProjectStructureMetadata) {
|
||||||
project.compositeBuildRootProject {
|
project.compositeBuildRootProject {
|
||||||
(it as ExtensionAware).extensions.extraProperties.set(
|
(it as ExtensionAware).extensions.extraProperties.set(
|
||||||
propertyName(project.currentBuildId().name, project.path),
|
propertyName(project.currentBuildId().buildPathCompat, project.path),
|
||||||
{ metadataProvider().toJson() }
|
{ metadataProvider().toJson() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getProjectStructureMetadataProvidersFromAllGradleBuilds(project: Project): Map<ProjectPathWithBuildName, Lazy<KotlinProjectStructureMetadata?>> {
|
fun getProjectStructureMetadataProvidersFromAllGradleBuilds(project: Project): Map<ProjectPathWithBuildPath, Lazy<KotlinProjectStructureMetadata?>> {
|
||||||
return project.compositeBuildRootProject.extensions.extraProperties.properties
|
return project.compositeBuildRootProject.extensions.extraProperties.properties
|
||||||
.filterKeys { it.startsWith(propertyPrefix) }
|
.filterKeys { it.startsWith(propertyPrefix) }
|
||||||
.entries
|
.entries
|
||||||
@@ -445,11 +446,11 @@ internal object GlobalProjectStructureMetadataStorage {
|
|||||||
return parseKotlinSourceSetMetadataFromJson(jsonString)
|
return parseKotlinSourceSetMetadataFromJson(jsonString)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.toProjectPathWithBuildName(): ProjectPathWithBuildName {
|
private fun String.toProjectPathWithBuildName(): ProjectPathWithBuildPath {
|
||||||
val (buildName, projectPath) = removePrefix("$propertyPrefix.").split(".path.")
|
val (buildPath, projectPath) = removePrefix("$propertyPrefix.").split(".path.")
|
||||||
return ProjectPathWithBuildName(
|
return ProjectPathWithBuildPath(
|
||||||
projectPath = projectPath,
|
projectPath = projectPath,
|
||||||
buildName = buildName
|
buildPath = buildPath
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-7
@@ -11,23 +11,25 @@ import org.gradle.api.artifacts.result.ResolvedArtifactResult
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||||
import org.jetbrains.kotlin.gradle.plugin.extraProperties
|
import org.jetbrains.kotlin.gradle.plugin.extraProperties
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.toSingleKpmModuleIdentifier
|
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.getOrPut
|
||||||
|
|
||||||
internal val Project.kotlinMppDependencyProjectStructureMetadataExtractorFactory: MppDependencyProjectStructureMetadataExtractorFactory
|
internal val Project.kotlinMppDependencyProjectStructureMetadataExtractorFactory: MppDependencyProjectStructureMetadataExtractorFactory
|
||||||
get() = MppDependencyProjectStructureMetadataExtractorFactory.getOrCreate(this)
|
get() = MppDependencyProjectStructureMetadataExtractorFactory.getOrCreate(this)
|
||||||
|
|
||||||
internal data class ProjectPathWithBuildName(
|
internal data class ProjectPathWithBuildPath(
|
||||||
val projectPath: String,
|
val projectPath: String,
|
||||||
val buildName: String
|
val buildPath: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
internal class MppDependencyProjectStructureMetadataExtractorFactory
|
internal class MppDependencyProjectStructureMetadataExtractorFactory
|
||||||
private constructor(
|
private constructor(
|
||||||
private val includedBuildsProjectStructureMetadataProviders: Lazy<Map<ProjectPathWithBuildName, Lazy<KotlinProjectStructureMetadata?>>>,
|
private val includedBuildsProjectStructureMetadataProviders: Lazy<Map<ProjectPathWithBuildPath, Lazy<KotlinProjectStructureMetadata?>>>,
|
||||||
private val currentBuildProjectStructureMetadataProviders: Map<String, Lazy<KotlinProjectStructureMetadata?>>
|
private val currentBuildProjectStructureMetadataProviders: Map<String, Lazy<KotlinProjectStructureMetadata?>>,
|
||||||
) {
|
) {
|
||||||
fun create(
|
fun create(
|
||||||
metadataArtifact: ResolvedArtifactResult
|
metadataArtifact: ResolvedArtifactResult,
|
||||||
): MppDependencyProjectStructureMetadataExtractor {
|
): MppDependencyProjectStructureMetadataExtractor {
|
||||||
val moduleId = metadataArtifact.variant.owner
|
val moduleId = metadataArtifact.variant.owner
|
||||||
|
|
||||||
@@ -42,11 +44,22 @@ private constructor(
|
|||||||
projectStructureMetadataProvider = projectStructureMetadataProvider::value
|
projectStructureMetadataProvider = projectStructureMetadataProvider::value
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
val key = ProjectPathWithBuildName(moduleId.projectPath, moduleId.build.name)
|
/*
|
||||||
|
We switched to using 'buildPath' instead of 'buildName' in 1.9.20,
|
||||||
|
(See: https://youtrack.jetbrains.com/issue/KT-58157/)
|
||||||
|
|
||||||
|
In order for 1.9.20 projects to consume included builds with lesser KGP versions,
|
||||||
|
we will still query this 'legacy key' which is the key we expect older KGP versions to use.
|
||||||
|
*/
|
||||||
|
val pre1920Key = ProjectPathWithBuildPath(moduleId.projectPath, moduleId.build.buildNameCompat)
|
||||||
|
val key = ProjectPathWithBuildPath(moduleId.projectPath, moduleId.build.buildPathCompat)
|
||||||
IncludedBuildMppDependencyProjectStructureMetadataExtractor(
|
IncludedBuildMppDependencyProjectStructureMetadataExtractor(
|
||||||
componentId = moduleId,
|
componentId = moduleId,
|
||||||
primaryArtifact = metadataArtifact.file,
|
primaryArtifact = metadataArtifact.file,
|
||||||
projectStructureMetadataProvider = { includedBuildsProjectStructureMetadataProviders.value[key]?.value }
|
projectStructureMetadataProvider = {
|
||||||
|
includedBuildsProjectStructureMetadataProviders.value[key]?.value
|
||||||
|
?: includedBuildsProjectStructureMetadataProviders.value[pre1920Key]?.value
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user