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 =
|
private fun ModuleComponentIdentifier.toModuleIdentifier(classifier: String? = null): MavenModuleIdentifier =
|
||||||
MavenModuleIdentifier(moduleIdentifier.group, moduleIdentifier.name, classifier)
|
MavenModuleIdentifier(moduleIdentifier.group, moduleIdentifier.name, classifier)
|
||||||
|
|
||||||
internal fun ComponentIdentifier.matchesModule(module: KotlinModule): Boolean {
|
internal fun ComponentIdentifier.matchesModule(module: KotlinModule): Boolean =
|
||||||
return when (val moduleId = module.moduleIdentifier) {
|
matchesModuleIdentifier(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 ResolvedComponentResult.toModuleIdentifier(): KotlinModuleIdentifier {
|
internal fun ResolvedComponentResult.toModuleIdentifier(): KotlinModuleIdentifier {
|
||||||
val capabilities = variants.flatMap { it.capabilities } // expected to be disjoint
|
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) =
|
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 -> {
|
is LocalModuleIdentifier -> {
|
||||||
val projectId = this as? ProjectComponentIdentifier
|
val projectId = this as? ProjectComponentIdentifier
|
||||||
projectId?.build?.name == id.buildId && projectId.projectPath == id.projectId
|
projectId?.build?.name == id.buildId && projectId.projectPath == id.projectId
|
||||||
|
|||||||
+3
-22
@@ -6,34 +6,14 @@
|
|||||||
package org.jetbrains.kotlin.gradle.plugin.mpp.pm20
|
package org.jetbrains.kotlin.gradle.plugin.mpp.pm20
|
||||||
|
|
||||||
import org.gradle.api.*
|
import org.gradle.api.*
|
||||||
import org.gradle.api.attributes.Usage
|
|
||||||
import org.gradle.api.plugins.JavaBasePlugin
|
import org.gradle.api.plugins.JavaBasePlugin
|
||||||
import org.gradle.api.publish.maven.MavenPublication
|
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.gradle.util.GradleVersion
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonOptions
|
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
|
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
|
||||||
import org.jetbrains.kotlin.gradle.dsl.pm20Extension
|
import org.jetbrains.kotlin.gradle.dsl.pm20Extension
|
||||||
import org.jetbrains.kotlin.gradle.internal.customizeKotlinDependencies
|
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.checkGradleCompatibility
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
|
||||||
import org.jetbrains.kotlin.project.model.KotlinModuleFragment
|
|
||||||
import org.jetbrains.kotlin.project.model.KotlinModuleIdentifier
|
import org.jetbrains.kotlin.project.model.KotlinModuleIdentifier
|
||||||
import java.util.concurrent.Callable
|
|
||||||
|
|
||||||
abstract class KotlinPm20GradlePlugin : Plugin<Project> {
|
abstract class KotlinPm20GradlePlugin : Plugin<Project> {
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
@@ -62,12 +42,13 @@ abstract class KotlinPm20GradlePlugin : Plugin<Project> {
|
|||||||
modules.create(KotlinGradleModule.TEST_MODULE_NAME)
|
modules.create(KotlinGradleModule.TEST_MODULE_NAME)
|
||||||
main { makePublic() }
|
main { makePublic() }
|
||||||
}
|
}
|
||||||
setupMetadataCompilationAndDependencyResolution(project)
|
setupFragmentsMetadata(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupMetadataCompilationAndDependencyResolution(project: Project) {
|
private fun setupFragmentsMetadata(project: Project) {
|
||||||
project.pm20Extension.modules.all { module ->
|
project.pm20Extension.modules.all { module ->
|
||||||
configureMetadataResolutionAndBuild(module)
|
configureMetadataResolutionAndBuild(module)
|
||||||
|
module.ifMadePublic { configureMetadataExposure(module) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -96,5 +96,8 @@ internal val KotlinGradleModule.resolvableMetadataConfigurationName: String
|
|||||||
internal val KotlinGradleModule.isMain
|
internal val KotlinGradleModule.isMain
|
||||||
get() = moduleIdentifier.moduleClassifier == null
|
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 }
|
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.gradle.api.attributes.Usage
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
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.plugin.mpp.sourcesJarTask
|
||||||
import org.jetbrains.kotlin.gradle.utils.addExtendsFromRelation
|
import org.jetbrains.kotlin.gradle.utils.addExtendsFromRelation
|
||||||
import org.jetbrains.kotlin.project.model.refinesClosure
|
import org.jetbrains.kotlin.project.model.refinesClosure
|
||||||
@@ -68,7 +69,7 @@ abstract class AbstractKotlinGradleVariantFactory<T : KotlinGradleVariant>(
|
|||||||
isCanBeConsumed = false
|
isCanBeConsumed = false
|
||||||
module.ifMadePublic {
|
module.ifMadePublic {
|
||||||
isCanBeConsumed = true
|
isCanBeConsumed = true
|
||||||
// FIXME set capability
|
setModuleCapability(this, fragment.containingModule)
|
||||||
}
|
}
|
||||||
attributes.attribute<Usage>(Usage.USAGE_ATTRIBUTE, KotlinUsages.producerApiUsage(project, fragment.platformType))
|
attributes.attribute<Usage>(Usage.USAGE_ATTRIBUTE, KotlinUsages.producerApiUsage(project, fragment.platformType))
|
||||||
extendsFrom(project.configurations.getByName(fragment.transitiveApiConfigurationName))
|
extendsFrom(project.configurations.getByName(fragment.transitiveApiConfigurationName))
|
||||||
@@ -111,7 +112,7 @@ abstract class AbstractKotlinGradleVariantWithRuntimeDependenciesFactory<T : Kot
|
|||||||
isCanBeConsumed = false
|
isCanBeConsumed = false
|
||||||
module.ifMadePublic {
|
module.ifMadePublic {
|
||||||
isCanBeConsumed = true
|
isCanBeConsumed = true
|
||||||
// FIXME set capability
|
setModuleCapability(this, fragment.containingModule)
|
||||||
}
|
}
|
||||||
configureRuntimeElementsConfiguration(fragment, this@apply)
|
configureRuntimeElementsConfiguration(fragment, this@apply)
|
||||||
extendsFrom(project.configurations.getByName(fragment.transitiveApiConfigurationName))
|
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.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
|
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.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.plugin.usageByName
|
||||||
import org.jetbrains.kotlin.gradle.targets.metadata.createGenerateProjectStructureMetadataTask
|
import org.jetbrains.kotlin.gradle.targets.metadata.createGenerateProjectStructureMetadataTask
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||||
@@ -44,6 +40,21 @@ internal fun configureMetadataResolutionAndBuild(module: KotlinGradleModule) {
|
|||||||
generateAndExportProjectStructureMetadata(module)
|
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(
|
private fun generateAndExportProjectStructureMetadata(
|
||||||
module: KotlinGradleModule
|
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.addExtendsFromRelation
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||||
|
import java.util.concurrent.Callable
|
||||||
|
|
||||||
internal const val COMMON_MAIN_ELEMENTS_CONFIGURATION_NAME = "commonMainMetadataElements"
|
internal const val COMMON_MAIN_ELEMENTS_CONFIGURATION_NAME = "commonMainMetadataElements"
|
||||||
internal const val ALL_COMPILE_METADATA_CONFIGURATION_NAME = "allSourceSetsCompileDependenciesMetadata"
|
internal const val ALL_COMPILE_METADATA_CONFIGURATION_NAME = "allSourceSetsCompileDependenciesMetadata"
|
||||||
@@ -503,7 +504,7 @@ internal fun createTransformedMetadataClasspath(
|
|||||||
metadataResolutionProviders: Lazy<Iterable<ResolvedMetadataFilesProvider>>
|
metadataResolutionProviders: Lazy<Iterable<ResolvedMetadataFilesProvider>>
|
||||||
): FileCollection {
|
): FileCollection {
|
||||||
return project.files(
|
return project.files(
|
||||||
project.provider {
|
Callable {
|
||||||
val allResolutionsByComponentId: Map<ComponentIdentifier, List<MetadataDependencyResolution>> =
|
val allResolutionsByComponentId: Map<ComponentIdentifier, List<MetadataDependencyResolution>> =
|
||||||
mutableMapOf<ComponentIdentifier, MutableList<MetadataDependencyResolution>>().apply {
|
mutableMapOf<ComponentIdentifier, MutableList<MetadataDependencyResolution>>().apply {
|
||||||
metadataResolutionProviders.value.forEach {
|
metadataResolutionProviders.value.forEach {
|
||||||
|
|||||||
Reference in New Issue
Block a user