(minor) Transform KotlinPlatformType attribute to String, rename entries
* To avoid unexpected effects from the Gradle instantiation mechanisms for attribute values, use a safer String attribute type for the KotlinPlatformType attribute * Rename its entries to keep enum entries naming consistent
This commit is contained in:
+15
-15
@@ -10,43 +10,43 @@ import org.gradle.api.attributes.*
|
|||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
enum class KotlinPlatformType: Named, Serializable {
|
enum class KotlinPlatformType(val attributeValue: String): Named, Serializable {
|
||||||
common, jvm, js, androidJvm, native;
|
COMMON("common"), JVM("jvm"), JS("js"), ANDROID_JVM("androidJvm"), NATIVE("native");
|
||||||
|
|
||||||
override fun toString(): String = name
|
override fun toString(): String = name
|
||||||
override fun getName(): String = name
|
override fun getName(): String = name
|
||||||
|
|
||||||
class CompatibilityRule : AttributeCompatibilityRule<KotlinPlatformType> {
|
class CompatibilityRule : AttributeCompatibilityRule<String> {
|
||||||
override fun execute(details: CompatibilityCheckDetails<KotlinPlatformType>) = with(details) {
|
override fun execute(details: CompatibilityCheckDetails<String?>) = with(details) {
|
||||||
if (producerValue == jvm && consumerValue == androidJvm)
|
if (producerValue == JVM.attributeValue && consumerValue == ANDROID_JVM.attributeValue)
|
||||||
compatible()
|
compatible()
|
||||||
|
|
||||||
// Allow the input metadata configuration consume platform-specific artifacts if no metadata is available, KT-26834
|
// Allow the input metadata configuration consume platform-specific artifacts if no metadata is available, KT-26834
|
||||||
if (consumerValue == common)
|
if (consumerValue == COMMON.attributeValue)
|
||||||
compatible()
|
compatible()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DisambiguationRule : AttributeDisambiguationRule<KotlinPlatformType> {
|
class DisambiguationRule : AttributeDisambiguationRule<String> {
|
||||||
override fun execute(details: MultipleCandidatesDetails<KotlinPlatformType?>) = with(details) {
|
override fun execute(details: MultipleCandidatesDetails<String?>) = with(details) {
|
||||||
if (candidateValues == setOf(androidJvm, jvm))
|
if (candidateValues == setOf(ANDROID_JVM.attributeValue, JVM.attributeValue))
|
||||||
closestMatch(androidJvm)
|
closestMatch(ANDROID_JVM.attributeValue)
|
||||||
|
|
||||||
if (common in candidateValues)
|
if (COMMON.attributeValue in candidateValues)
|
||||||
// then the consumer requests common or requests no platform-specific artifacts,
|
// then the consumer requests common or requests no platform-specific artifacts,
|
||||||
// so common is the best match, KT-26834
|
// so common is the best match, KT-26834
|
||||||
closestMatch(common)
|
closestMatch(COMMON.attributeValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val attribute = Attribute.of(
|
val ATTRIBUTE = Attribute.of(
|
||||||
"org.jetbrains.kotlin.platform.type",
|
"org.jetbrains.kotlin.platform.type",
|
||||||
KotlinPlatformType::class.java
|
String::class.java
|
||||||
)
|
)
|
||||||
|
|
||||||
fun setupAttributesMatchingStrategy(attributesSchema: AttributesSchema) {
|
fun setupAttributesMatchingStrategy(attributesSchema: AttributesSchema) {
|
||||||
attributesSchema.attribute(KotlinPlatformType.attribute).run {
|
attributesSchema.attribute(KotlinPlatformType.ATTRIBUTE).run {
|
||||||
if (isGradleVersionAtLeast(4, 0)) {
|
if (isGradleVersionAtLeast(4, 0)) {
|
||||||
compatibilityRules.add(CompatibilityRule::class.java)
|
compatibilityRules.add(CompatibilityRule::class.java)
|
||||||
disambiguationRules.add(DisambiguationRule::class.java)
|
disambiguationRules.add(DisambiguationRule::class.java)
|
||||||
|
|||||||
+6
-6
@@ -395,7 +395,7 @@ internal abstract class AbstractKotlinPlugin(
|
|||||||
val javaSourceSets = project.convention.getPlugin(JavaPluginConvention::class.java).sourceSets
|
val javaSourceSets = project.convention.getPlugin(JavaPluginConvention::class.java).sourceSets
|
||||||
|
|
||||||
val kotlinSourceSetDslName = when (kotlinTarget.platformType) {
|
val kotlinSourceSetDslName = when (kotlinTarget.platformType) {
|
||||||
KotlinPlatformType.js -> KOTLIN_JS_DSL_NAME
|
KotlinPlatformType.JS -> KOTLIN_JS_DSL_NAME
|
||||||
else -> KOTLIN_DSL_NAME
|
else -> KOTLIN_DSL_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,7 +428,7 @@ internal abstract class AbstractKotlinPlugin(
|
|||||||
val project = kotlinTarget.project
|
val project = kotlinTarget.project
|
||||||
|
|
||||||
// Setup the consuming configurations:
|
// Setup the consuming configurations:
|
||||||
project.dependencies.attributesSchema.attribute(KotlinPlatformType.attribute)
|
project.dependencies.attributesSchema.attribute(KotlinPlatformType.ATTRIBUTE)
|
||||||
kotlinTarget.compilations.all { compilation ->
|
kotlinTarget.compilations.all { compilation ->
|
||||||
AbstractKotlinTargetConfigurator.defineConfigurationsForCompilation(compilation, kotlinTarget, project.configurations)
|
AbstractKotlinTargetConfigurator.defineConfigurationsForCompilation(compilation, kotlinTarget, project.configurations)
|
||||||
}
|
}
|
||||||
@@ -436,7 +436,7 @@ internal abstract class AbstractKotlinPlugin(
|
|||||||
// Setup the published configurations:
|
// Setup the published configurations:
|
||||||
// Don't set the attributes for common module; otherwise their 'common' platform won't be compatible with the one in
|
// Don't set the attributes for common module; otherwise their 'common' platform won't be compatible with the one in
|
||||||
// platform-specific modules
|
// platform-specific modules
|
||||||
if (kotlinTarget.platformType != KotlinPlatformType.common) {
|
if (kotlinTarget.platformType != KotlinPlatformType.COMMON) {
|
||||||
project.configurations.getByName(kotlinTarget.apiElementsConfigurationName).run {
|
project.configurations.getByName(kotlinTarget.apiElementsConfigurationName).run {
|
||||||
attributes.attribute(Usage.USAGE_ATTRIBUTE, KotlinUsages.producerApiUsage(kotlinTarget))
|
attributes.attribute(Usage.USAGE_ATTRIBUTE, KotlinUsages.producerApiUsage(kotlinTarget))
|
||||||
usesPlatformOf(kotlinTarget)
|
usesPlatformOf(kotlinTarget)
|
||||||
@@ -493,7 +493,7 @@ internal open class KotlinPlugin(
|
|||||||
Kotlin2JvmSourceSetProcessor(project, tasksProvider, compilation, kotlinPluginVersion)
|
Kotlin2JvmSourceSetProcessor(project, tasksProvider, compilation, kotlinPluginVersion)
|
||||||
|
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
val target = KotlinWithJavaTarget(project, KotlinPlatformType.jvm, targetName).apply {
|
val target = KotlinWithJavaTarget(project, KotlinPlatformType.JVM, targetName).apply {
|
||||||
disambiguationClassifier = null // don't add anything to the task names
|
disambiguationClassifier = null // don't add anything to the task names
|
||||||
}
|
}
|
||||||
(project.kotlinExtension as KotlinSingleJavaTargetExtension).target = target
|
(project.kotlinExtension as KotlinSingleJavaTargetExtension).target = target
|
||||||
@@ -520,7 +520,7 @@ internal open class KotlinCommonPlugin(
|
|||||||
KotlinCommonSourceSetProcessor(project, compilation, tasksProvider, kotlinPluginVersion)
|
KotlinCommonSourceSetProcessor(project, compilation, tasksProvider, kotlinPluginVersion)
|
||||||
|
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
val target = KotlinWithJavaTarget(project, KotlinPlatformType.common, targetName)
|
val target = KotlinWithJavaTarget(project, KotlinPlatformType.COMMON, targetName)
|
||||||
(project.kotlinExtension as KotlinSingleJavaTargetExtension).target = target
|
(project.kotlinExtension as KotlinSingleJavaTargetExtension).target = target
|
||||||
|
|
||||||
super.apply(project)
|
super.apply(project)
|
||||||
@@ -546,7 +546,7 @@ internal open class Kotlin2JsPlugin(
|
|||||||
)
|
)
|
||||||
|
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
val target = KotlinWithJavaTarget(project, KotlinPlatformType.js, targetName)
|
val target = KotlinWithJavaTarget(project, KotlinPlatformType.JS, targetName)
|
||||||
|
|
||||||
(project.kotlinExtension as KotlinSingleJavaTargetExtension).target = target
|
(project.kotlinExtension as KotlinSingleJavaTargetExtension).target = target
|
||||||
super.apply(project)
|
super.apply(project)
|
||||||
|
|||||||
+1
-1
@@ -701,7 +701,7 @@ internal fun Project.usageByName(usageName: String): Usage =
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Configuration.usesPlatformOf(target: KotlinTarget): Configuration {
|
fun Configuration.usesPlatformOf(target: KotlinTarget): Configuration {
|
||||||
attributes.attribute(KotlinPlatformType.attribute, target.platformType)
|
attributes.attribute(KotlinPlatformType.ATTRIBUTE, target.platformType.attributeValue)
|
||||||
// TODO: Provide an universal way to copy attributes from the target.
|
// TODO: Provide an universal way to copy attributes from the target.
|
||||||
if (target is KotlinNativeTarget) {
|
if (target is KotlinNativeTarget) {
|
||||||
attributes.attribute(KotlinNativeTarget.konanTargetAttribute, target.konanTarget.name)
|
attributes.attribute(KotlinNativeTarget.konanTargetAttribute, target.konanTarget.name)
|
||||||
|
|||||||
+3
-3
@@ -8,8 +8,8 @@ package org.jetbrains.kotlin.gradle.plugin.mpp
|
|||||||
import org.gradle.api.attributes.*
|
import org.gradle.api.attributes.*
|
||||||
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.KotlinPlatformType.androidJvm
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.ANDROID_JVM
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.jvm
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.JVM
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||||
import org.jetbrains.kotlin.gradle.plugin.usageByName
|
import org.jetbrains.kotlin.gradle.plugin.usageByName
|
||||||
import org.jetbrains.kotlin.gradle.utils.isGradleVersionAtLeast
|
import org.jetbrains.kotlin.gradle.utils.isGradleVersionAtLeast
|
||||||
@@ -19,7 +19,7 @@ object KotlinUsages {
|
|||||||
const val KOTLIN_RUNTIME = "kotlin-runtime"
|
const val KOTLIN_RUNTIME = "kotlin-runtime"
|
||||||
val values = setOf(KOTLIN_API, KOTLIN_RUNTIME)
|
val values = setOf(KOTLIN_API, KOTLIN_RUNTIME)
|
||||||
|
|
||||||
private val jvmPlatformTypes: Set<KotlinPlatformType> = setOf(jvm, androidJvm)
|
private val jvmPlatformTypes: Set<KotlinPlatformType> = setOf(JVM, ANDROID_JVM)
|
||||||
|
|
||||||
internal fun consumerApiUsage(target: KotlinTarget) = target.project.usageByName(
|
internal fun consumerApiUsage(target: KotlinTarget) = target.project.usageByName(
|
||||||
when (target.platformType) {
|
when (target.platformType) {
|
||||||
|
|||||||
+4
-4
@@ -85,7 +85,7 @@ class KotlinMetadataTargetPreset(
|
|||||||
KotlinCommonCompilationFactory(forTarget)
|
KotlinCommonCompilationFactory(forTarget)
|
||||||
|
|
||||||
override val platformType: KotlinPlatformType
|
override val platformType: KotlinPlatformType
|
||||||
get() = KotlinPlatformType.common
|
get() = KotlinPlatformType.COMMON
|
||||||
|
|
||||||
override fun buildCompilationProcessor(compilation: KotlinCommonCompilation): KotlinSourceSetProcessor<*> =
|
override fun buildCompilationProcessor(compilation: KotlinCommonCompilation): KotlinSourceSetProcessor<*> =
|
||||||
KotlinCommonSourceSetProcessor(
|
KotlinCommonSourceSetProcessor(
|
||||||
@@ -136,7 +136,7 @@ class KotlinJvmTargetPreset(
|
|||||||
KotlinJvmCompilationFactory(forTarget)
|
KotlinJvmCompilationFactory(forTarget)
|
||||||
|
|
||||||
override val platformType: KotlinPlatformType
|
override val platformType: KotlinPlatformType
|
||||||
get() = KotlinPlatformType.jvm
|
get() = KotlinPlatformType.JVM
|
||||||
|
|
||||||
override fun buildCompilationProcessor(compilation: KotlinJvmCompilation): KotlinSourceSetProcessor<*> =
|
override fun buildCompilationProcessor(compilation: KotlinJvmCompilation): KotlinSourceSetProcessor<*> =
|
||||||
Kotlin2JvmSourceSetProcessor(project, KotlinTasksProvider(compilation.target.targetName), compilation, kotlinPluginVersion)
|
Kotlin2JvmSourceSetProcessor(project, KotlinTasksProvider(compilation.target.targetName), compilation, kotlinPluginVersion)
|
||||||
@@ -165,7 +165,7 @@ class KotlinJsTargetPreset(
|
|||||||
KotlinJsCompilationFactory(project, forTarget)
|
KotlinJsCompilationFactory(project, forTarget)
|
||||||
|
|
||||||
override val platformType: KotlinPlatformType
|
override val platformType: KotlinPlatformType
|
||||||
get() = KotlinPlatformType.js
|
get() = KotlinPlatformType.JS
|
||||||
|
|
||||||
override fun buildCompilationProcessor(compilation: KotlinJsCompilation): KotlinSourceSetProcessor<*> =
|
override fun buildCompilationProcessor(compilation: KotlinJsCompilation): KotlinSourceSetProcessor<*> =
|
||||||
Kotlin2JsSourceSetProcessor(project, KotlinTasksProvider(compilation.target.targetName), compilation, kotlinPluginVersion)
|
Kotlin2JsSourceSetProcessor(project, KotlinTasksProvider(compilation.target.targetName), compilation, kotlinPluginVersion)
|
||||||
@@ -210,7 +210,7 @@ class KotlinJvmWithJavaTargetPreset(
|
|||||||
override fun createTarget(name: String): KotlinWithJavaTarget {
|
override fun createTarget(name: String): KotlinWithJavaTarget {
|
||||||
project.plugins.apply(JavaPlugin::class.java)
|
project.plugins.apply(JavaPlugin::class.java)
|
||||||
|
|
||||||
val target = KotlinWithJavaTarget(project, KotlinPlatformType.jvm, name).apply {
|
val target = KotlinWithJavaTarget(project, KotlinPlatformType.JVM, name).apply {
|
||||||
disambiguationClassifier = name
|
disambiguationClassifier = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -122,7 +122,7 @@ open class KotlinAndroidTarget(
|
|||||||
internal set
|
internal set
|
||||||
|
|
||||||
override val platformType: KotlinPlatformType
|
override val platformType: KotlinPlatformType
|
||||||
get() = KotlinPlatformType.androidJvm
|
get() = KotlinPlatformType.ANDROID_JVM
|
||||||
|
|
||||||
private val compilationFactory = KotlinJvmAndroidCompilationFactory(project, this)
|
private val compilationFactory = KotlinJvmAndroidCompilationFactory(project, this)
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ open class KotlinOnlyTarget<T : KotlinCompilation>(
|
|||||||
class KotlinNativeTarget(
|
class KotlinNativeTarget(
|
||||||
project: Project,
|
project: Project,
|
||||||
val konanTarget: KonanTarget
|
val konanTarget: KonanTarget
|
||||||
) : KotlinOnlyTarget<KotlinNativeCompilation>(project, KotlinPlatformType.native) {
|
) : KotlinOnlyTarget<KotlinNativeCompilation>(project, KotlinPlatformType.NATIVE) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
attributes.attribute(konanTargetAttribute, konanTarget.name)
|
attributes.attribute(konanTargetAttribute, konanTarget.name)
|
||||||
|
|||||||
+1
-1
@@ -68,7 +68,7 @@ internal class DefaultKotlinSourceSetFactory(
|
|||||||
|
|
||||||
dependencyConfigurationWithMetadata.forEach { (configurationName, metadataName) ->
|
dependencyConfigurationWithMetadata.forEach { (configurationName, metadataName) ->
|
||||||
project.configurations.maybeCreate(metadataName).apply {
|
project.configurations.maybeCreate(metadataName).apply {
|
||||||
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common)
|
attributes.attribute(KotlinPlatformType.ATTRIBUTE, KotlinPlatformType.COMMON.attributeValue)
|
||||||
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.usageByName(KotlinUsages.KOTLIN_API))
|
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.usageByName(KotlinUsages.KOTLIN_API))
|
||||||
isVisible = false
|
isVisible = false
|
||||||
isCanBeConsumed = false
|
isCanBeConsumed = false
|
||||||
|
|||||||
Reference in New Issue
Block a user