Expose compiled metadata for project deps, set capabilities on elements
This commit is contained in:
+6
-14
@@ -206,19 +206,8 @@ class VariantDependencyDiscovery(
|
||||
private fun ModuleComponentIdentifier.toModuleIdentifier(classifier: String? = null): MavenModuleIdentifier =
|
||||
MavenModuleIdentifier(moduleIdentifier.group, moduleIdentifier.name, classifier)
|
||||
|
||||
internal fun ComponentIdentifier.matchesModule(module: KotlinModule): Boolean {
|
||||
return when (val moduleId = module.moduleIdentifier) {
|
||||
is LocalModuleIdentifier -> {
|
||||
val projectId = this as? ProjectComponentIdentifier
|
||||
projectId?.build?.name == moduleId.buildId && projectId.projectPath == moduleId.projectId
|
||||
}
|
||||
is MavenModuleIdentifier -> {
|
||||
val componentId = this as? ModuleComponentIdentifier
|
||||
componentId?.toModuleIdentifier() == moduleId
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
internal fun ComponentIdentifier.matchesModule(module: KotlinModule): Boolean =
|
||||
matchesModuleIdentifier(module.moduleIdentifier)
|
||||
|
||||
internal fun ResolvedComponentResult.toModuleIdentifier(): KotlinModuleIdentifier {
|
||||
val capabilities = variants.flatMap { it.capabilities } // expected to be disjoint
|
||||
@@ -251,7 +240,10 @@ internal fun ComponentSelector.toModuleDependency(): KotlinModuleDependency {
|
||||
}
|
||||
|
||||
internal fun ComponentIdentifier.matchesModuleDependency(moduleDependency: KotlinModuleDependency) =
|
||||
when (val id = moduleDependency.moduleIdentifier) {
|
||||
matchesModuleIdentifier(moduleDependency.moduleIdentifier)
|
||||
|
||||
internal fun ComponentIdentifier.matchesModuleIdentifier(id: KotlinModuleIdentifier): Boolean =
|
||||
when (id) {
|
||||
is LocalModuleIdentifier -> {
|
||||
val projectId = this as? ProjectComponentIdentifier
|
||||
projectId?.build?.name == id.buildId && projectId.projectPath == id.projectId
|
||||
|
||||
+3
-22
@@ -6,34 +6,14 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.mpp.pm20
|
||||
|
||||
import org.gradle.api.*
|
||||
import org.gradle.api.attributes.Usage
|
||||
import org.gradle.api.plugins.JavaBasePlugin
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.pm20Extension
|
||||
import org.jetbrains.kotlin.gradle.internal.customizeKotlinDependencies
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCommonSourceSetProcessor
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MULTIPLATFORM_PROJECT_METADATA_JSON_FILE_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.addSourcesToKotlinCompileTask
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.buildKotlinProjectStructureMetadata
|
||||
import org.jetbrains.kotlin.gradle.plugin.usageByName
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.createGenerateProjectStructureMetadataTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.utils.addExtendsFromRelation
|
||||
import org.jetbrains.kotlin.gradle.utils.checkGradleCompatibility
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import org.jetbrains.kotlin.project.model.KotlinModuleFragment
|
||||
import org.jetbrains.kotlin.project.model.KotlinModuleIdentifier
|
||||
import java.util.concurrent.Callable
|
||||
|
||||
abstract class KotlinPm20GradlePlugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
@@ -62,12 +42,13 @@ abstract class KotlinPm20GradlePlugin : Plugin<Project> {
|
||||
modules.create(KotlinGradleModule.TEST_MODULE_NAME)
|
||||
main { makePublic() }
|
||||
}
|
||||
setupMetadataCompilationAndDependencyResolution(project)
|
||||
setupFragmentsMetadata(project)
|
||||
}
|
||||
|
||||
private fun setupMetadataCompilationAndDependencyResolution(project: Project) {
|
||||
private fun setupFragmentsMetadata(project: Project) {
|
||||
project.pm20Extension.modules.all { module ->
|
||||
configureMetadataResolutionAndBuild(module)
|
||||
module.ifMadePublic { configureMetadataExposure(module) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -96,5 +96,8 @@ internal val KotlinGradleModule.resolvableMetadataConfigurationName: String
|
||||
internal val KotlinGradleModule.isMain
|
||||
get() = moduleIdentifier.moduleClassifier == null
|
||||
|
||||
fun KotlinGradleModule.variantsContainingFragment(fragment: KotlinModuleFragment): Iterable<KotlinGradleVariant> =
|
||||
internal fun KotlinGradleModule.disambiguateName(simpleName: String) =
|
||||
lowerCamelCaseName(moduleClassifier, simpleName)
|
||||
|
||||
internal fun KotlinGradleModule.variantsContainingFragment(fragment: KotlinModuleFragment): Iterable<KotlinGradleVariant> =
|
||||
variants.filter { fragment in it.refinesClosure }
|
||||
+7
-2
@@ -9,6 +9,7 @@ import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.attributes.Usage
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.LazyCapability
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.sourcesJarTask
|
||||
import org.jetbrains.kotlin.gradle.utils.addExtendsFromRelation
|
||||
import org.jetbrains.kotlin.project.model.refinesClosure
|
||||
@@ -68,7 +69,7 @@ abstract class AbstractKotlinGradleVariantFactory<T : KotlinGradleVariant>(
|
||||
isCanBeConsumed = false
|
||||
module.ifMadePublic {
|
||||
isCanBeConsumed = true
|
||||
// FIXME set capability
|
||||
setModuleCapability(this, fragment.containingModule)
|
||||
}
|
||||
attributes.attribute<Usage>(Usage.USAGE_ATTRIBUTE, KotlinUsages.producerApiUsage(project, fragment.platformType))
|
||||
extendsFrom(project.configurations.getByName(fragment.transitiveApiConfigurationName))
|
||||
@@ -111,7 +112,7 @@ abstract class AbstractKotlinGradleVariantWithRuntimeDependenciesFactory<T : Kot
|
||||
isCanBeConsumed = false
|
||||
module.ifMadePublic {
|
||||
isCanBeConsumed = true
|
||||
// FIXME set capability
|
||||
setModuleCapability(this, fragment.containingModule)
|
||||
}
|
||||
configureRuntimeElementsConfiguration(fragment, this@apply)
|
||||
extendsFrom(project.configurations.getByName(fragment.transitiveApiConfigurationName))
|
||||
@@ -120,3 +121,7 @@ abstract class AbstractKotlinGradleVariantWithRuntimeDependenciesFactory<T : Kot
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun setModuleCapability(configuration: Configuration, module: KotlinGradleModule) {
|
||||
configuration.outgoing.capability(LazyCapability.fromModule(module))
|
||||
}
|
||||
+15
-4
@@ -16,10 +16,6 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCommonSourceSetProcessor
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MULTIPLATFORM_PROJECT_METADATA_JSON_FILE_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.addSourcesToKotlinCompileTask
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.buildKotlinProjectStructureMetadata
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.disambiguateName
|
||||
import org.jetbrains.kotlin.gradle.plugin.usageByName
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.createGenerateProjectStructureMetadataTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||
@@ -44,6 +40,21 @@ internal fun configureMetadataResolutionAndBuild(module: KotlinGradleModule) {
|
||||
generateAndExportProjectStructureMetadata(module)
|
||||
}
|
||||
|
||||
internal fun configureMetadataExposure(module: KotlinGradleModule) {
|
||||
val project = module.project
|
||||
project.configurations.create(module.disambiguateName("metadataElements")).apply {
|
||||
isCanBeConsumed = true
|
||||
isCanBeResolved = false
|
||||
project.artifacts.add(name, project.tasks.named(metadataJarName(module)))
|
||||
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.usageByName(KotlinUsages.KOTLIN_METADATA))
|
||||
module.fragments.all { fragment ->
|
||||
// FIXME: native api-implementation
|
||||
project.addExtendsFromRelation(name, fragment.apiConfigurationName)
|
||||
}
|
||||
setModuleCapability(this, module)
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateAndExportProjectStructureMetadata(
|
||||
module: KotlinGradleModule
|
||||
) {
|
||||
|
||||
+2
-1
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import org.jetbrains.kotlin.gradle.utils.addExtendsFromRelation
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||
import java.util.concurrent.Callable
|
||||
|
||||
internal const val COMMON_MAIN_ELEMENTS_CONFIGURATION_NAME = "commonMainMetadataElements"
|
||||
internal const val ALL_COMPILE_METADATA_CONFIGURATION_NAME = "allSourceSetsCompileDependenciesMetadata"
|
||||
@@ -503,7 +504,7 @@ internal fun createTransformedMetadataClasspath(
|
||||
metadataResolutionProviders: Lazy<Iterable<ResolvedMetadataFilesProvider>>
|
||||
): FileCollection {
|
||||
return project.files(
|
||||
project.provider {
|
||||
Callable {
|
||||
val allResolutionsByComponentId: Map<ComponentIdentifier, List<MetadataDependencyResolution>> =
|
||||
mutableMapOf<ComponentIdentifier, MutableList<MetadataDependencyResolution>>().apply {
|
||||
metadataResolutionProviders.value.forEach {
|
||||
|
||||
Reference in New Issue
Block a user