[Gradle] ProjectMetadataProvider: Allow nullable compiled metadata for SourceSet
The commit leading to the issue described in KT-58319 was:
510eca9da1
[Gradle] Implement source set inspection methods as 'suspend'
In this commit one method called
'getCommonSourceSetsForMetadataCompilation' was implemented
in a suspend style.
This re-implementation however introduced a semantic change to the function:
Previously this method (counterintuitively) returned commonMain
even if the SourceSet only participated in a single platform compilation.
This is because the KotlinMetadataTarget still cas a 'main' compilation
that includes 'commonMain'. The previous implementation did not filter
this compilation therefore found two platform types for the SourceSet,
assuming that it can be compiled to metadata.
This lead to a 'commonMain' compilation created which then gets
correctly disabled by 'isMetadataCompilationSupported'.
After the commit, a single target project did not create a 'commonMain'
compilation anymore. This leads to no metadata being provided
by the metadata provider. This seems OK, but the 'ProjectMetadataProviderImpl'
threw an error in cases the IDE requested this metadata.
^KT-58319 Verification Pending
This commit is contained in:
committed by
Space Team
parent
900f26f3c5
commit
8273328726
+1
-1
@@ -75,7 +75,7 @@ internal sealed class MetadataDependencyResolution(
|
||||
abstract class ProjectMetadataProvider : MetadataProvider() {
|
||||
enum class MetadataConsumer { Ide, Cli }
|
||||
|
||||
abstract fun getSourceSetCompiledMetadata(sourceSetName: String): FileCollection
|
||||
abstract fun getSourceSetCompiledMetadata(sourceSetName: String): FileCollection?
|
||||
abstract fun getSourceSetCInteropMetadata(sourceSetName: String, consumer: MetadataConsumer): FileCollection?
|
||||
}
|
||||
}
|
||||
|
||||
+11
-9
@@ -25,7 +25,7 @@ internal fun ProjectMetadataProvider(
|
||||
}
|
||||
|
||||
internal class SourceSetMetadataOutputs(
|
||||
val metadata: FileCollection,
|
||||
val metadata: FileCollection?,
|
||||
val cinterop: CInterop?
|
||||
) {
|
||||
class CInterop(
|
||||
@@ -38,8 +38,11 @@ private class ProjectMetadataProviderImpl(
|
||||
private val sourceSetMetadataOutputs: Map<SourceSetName, SourceSetMetadataOutputs>
|
||||
) : ProjectMetadataProvider() {
|
||||
|
||||
override fun getSourceSetCompiledMetadata(sourceSetName: String): FileCollection =
|
||||
sourceSetMetadataOutputs[sourceSetName]?.metadata ?: error("Unexpected source set '$sourceSetName'")
|
||||
override fun getSourceSetCompiledMetadata(sourceSetName: String): FileCollection? {
|
||||
val metadataOutputs = sourceSetMetadataOutputs[sourceSetName] ?: error("Unexpected source set '$sourceSetName'")
|
||||
return metadataOutputs.metadata
|
||||
}
|
||||
|
||||
|
||||
override fun getSourceSetCInteropMetadata(sourceSetName: String, consumer: MetadataConsumer): FileCollection? {
|
||||
val metadataOutputs = sourceSetMetadataOutputs[sourceSetName] ?: error("Unexpected source set '$sourceSetName'")
|
||||
@@ -66,18 +69,17 @@ internal suspend fun Project.collectSourceSetMetadataOutputs(): Map<SourceSetNam
|
||||
}.mapKeys { it.key.name }
|
||||
}
|
||||
|
||||
private suspend fun KotlinMultiplatformExtension.sourceSetsMetadataOutputs(): Map<KotlinSourceSet, FileCollection> {
|
||||
private suspend fun KotlinMultiplatformExtension.sourceSetsMetadataOutputs(): Map<KotlinSourceSet, FileCollection?> {
|
||||
KotlinPluginLifecycle.Stage.AfterFinaliseDsl.await()
|
||||
|
||||
return sourceSets.mapNotNull { sourceSet ->
|
||||
val destination = when (val compilation = project.findMetadataCompilation(sourceSet) ?: return@mapNotNull null) {
|
||||
return sourceSets.associateWith { sourceSet ->
|
||||
when (val compilation = project.findMetadataCompilation(sourceSet)) {
|
||||
null -> null
|
||||
is KotlinCommonCompilation -> compilation.output.classesDirs
|
||||
is KotlinSharedNativeCompilation -> compilation.output.classesDirs
|
||||
else -> error("Unexpected compilation type: $compilation")
|
||||
}
|
||||
|
||||
Pair(sourceSet, destination)
|
||||
}.toMap()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun KotlinMultiplatformExtension.cInteropMetadataOfSourceSets(
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ internal fun Project.transformMetadataLibrariesForIde(
|
||||
): Map<String /* visibleSourceSetName */, Iterable<File>> {
|
||||
return when (val metadataProvider = resolution.metadataProvider) {
|
||||
is ProjectMetadataProvider -> resolution.visibleSourceSetNamesExcludingDependsOn.associateWith { visibleSourceSetName ->
|
||||
metadataProvider.getSourceSetCompiledMetadata(visibleSourceSetName)
|
||||
metadataProvider.getSourceSetCompiledMetadata(visibleSourceSetName) ?: emptyList()
|
||||
}
|
||||
|
||||
is ArtifactMetadataProvider -> transformMetadataLibrariesForIde(
|
||||
|
||||
Reference in New Issue
Block a user