[Gradle] Handle multiplatform composite builds when metadata.jar is not yet present
KT-52172
This commit is contained in:
committed by
Space Team
parent
90f8edbe80
commit
b872d42723
+5
@@ -21,6 +21,11 @@ internal interface CompositeMetadataArtifact {
|
||||
* Alternatively use the [read] function instead.
|
||||
*/
|
||||
fun open(): CompositeMetadataArtifactContent
|
||||
|
||||
/**
|
||||
* Checks if physical files are present on disk
|
||||
*/
|
||||
fun exists(): Boolean
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
@@ -26,6 +26,10 @@ internal class CompositeMetadataArtifactImpl(
|
||||
private val hostSpecificArtifactFilesBySourceSetName: Map<String, File>
|
||||
) : CompositeMetadataArtifact {
|
||||
|
||||
override fun exists(): Boolean {
|
||||
return primaryArtifactFile.exists() && hostSpecificArtifactFilesBySourceSetName.values.all { it.exists() }
|
||||
}
|
||||
|
||||
override fun open(): CompositeMetadataArtifactContent {
|
||||
return CompositeMetadataArtifactContentImpl()
|
||||
}
|
||||
|
||||
+6
-2
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.gradle.targets.metadata.ResolvedMetadataFilesProvide
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.dependsOnClosureWithInterCompilationDependencies
|
||||
import org.jetbrains.kotlin.gradle.utils.getValue
|
||||
import org.jetbrains.kotlin.gradle.utils.notCompatibleWithConfigurationCacheCompat
|
||||
import org.jetbrains.kotlin.gradle.utils.outputFilesProvider
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -117,8 +118,11 @@ open class MetadataDependencyTransformationTask
|
||||
get() = metadataDependencyResolutions
|
||||
.filterIsInstance<MetadataDependencyResolution.ChooseVisibleSourceSets>()
|
||||
.associateWith { chooseVisibleSourceSets ->
|
||||
val files = project.transformMetadataLibrariesForBuild(chooseVisibleSourceSets, outputsDir, materializeFiles = false)
|
||||
project.files(files).builtBy(this)
|
||||
outputFilesProvider {
|
||||
project.transformMetadataLibrariesForBuild(
|
||||
chooseVisibleSourceSets, outputsDir, materializeFiles = false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
|
||||
+11
-1
@@ -82,6 +82,16 @@ private fun transformMetadataLibrariesForBuild(
|
||||
materializeFiles: Boolean,
|
||||
compositeMetadataArtifact: CompositeMetadataArtifact
|
||||
): Set<File> {
|
||||
/*
|
||||
Careful handling of composite builds:
|
||||
Right now, composite multiplatform builds will compile against the composite artifact build by the producer build (not
|
||||
against compiled source sets directly).
|
||||
|
||||
This means, that this function might be called to figure out task inputs at a time, where
|
||||
this composite artifact is not present on disk yet.
|
||||
*/
|
||||
if (!materializeFiles && !compositeMetadataArtifact.exists()) return emptySet()
|
||||
|
||||
return compositeMetadataArtifact.read { artifactContent ->
|
||||
resolution.visibleSourceSetNamesExcludingDependsOn.mapNotNull { visibleSourceSetName ->
|
||||
val sourceSetContent = artifactContent.findSourceSet(visibleSourceSetName) ?: return@mapNotNull null
|
||||
@@ -94,4 +104,4 @@ private fun transformMetadataLibrariesForBuild(
|
||||
metadataLibraryFile
|
||||
}
|
||||
}.toSet()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user