[Gradle][KT-53342] KotlinAndroidSourceSetNaming: Merge kotlinSourceSetName overloads
This commit is contained in:
committed by
Space
parent
c8e2888db9
commit
9b8fbea0dc
+3
-25
@@ -11,26 +11,13 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.AndroidCompilationDetails
|
||||
internal interface KotlinAndroidSourceSetNaming {
|
||||
|
||||
/**
|
||||
* Returns non-null name of the corresponding [KotlinSourceSet], if the name of said source set can be
|
||||
* determined by the [disambiguationClassifier] and [androidSourceSetName] alone.
|
||||
*
|
||||
* Returns `null`, if KotlinSourceSet name requires additional [AndroidVariantType] to be determined.
|
||||
* Returns the name of the corresponding [KotlinSourceSet]
|
||||
* This function can be called w/ or w/o a specific [type].
|
||||
*/
|
||||
fun kotlinSourceSetName(
|
||||
disambiguationClassifier: String,
|
||||
androidSourceSetName: String
|
||||
disambiguationClassifier: String, androidSourceSetName: String, type: AndroidVariantType?
|
||||
): String?
|
||||
|
||||
/**
|
||||
* Returns the name of the corresponding [KotlinSourceSet], if the name of said source set cannot be determined
|
||||
* by the [disambiguationClassifier] and [androidSourceSetName] alone.
|
||||
*/
|
||||
fun kotlinSourceSetName(
|
||||
disambiguationClassifier: String,
|
||||
androidSourceSetName: String,
|
||||
type: AndroidVariantType
|
||||
): String
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the default KotlinSourceSet for a given Android compilation.
|
||||
@@ -38,13 +25,4 @@ internal interface KotlinAndroidSourceSetNaming {
|
||||
* 'default' defaultSourceSetName will be constructed by the compilation.
|
||||
*/
|
||||
fun defaultKotlinSourceSetName(compilation: AndroidCompilationDetails): String? = null
|
||||
|
||||
/**
|
||||
* Always capable of creating the [KotlinSourceSet]'s name based upon the disambiguationClassifier and androidSourceSetName alone.
|
||||
*/
|
||||
interface Simple : KotlinAndroidSourceSetNaming {
|
||||
override fun kotlinSourceSetName(disambiguationClassifier: String, androidSourceSetName: String): String
|
||||
override fun kotlinSourceSetName(disambiguationClassifier: String, androidSourceSetName: String, type: AndroidVariantType): String =
|
||||
kotlinSourceSetName(disambiguationClassifier, androidSourceSetName)
|
||||
}
|
||||
}
|
||||
|
||||
+9
-4
@@ -35,8 +35,12 @@ internal object KotlinAndroidSourceSets {
|
||||
make them available in the buildscript dsl immediately.
|
||||
*/
|
||||
android.sourceSets.all { androidSourceSet ->
|
||||
val kotlinSourceSetName = layout.naming.kotlinSourceSetName(target.disambiguationClassifier, androidSourceSet.name)
|
||||
factory.getOrCreateConfiguredKotlinSourceSet(kotlinSourceSetName ?: return@all, androidSourceSet)
|
||||
val kotlinSourceSetName = layout.naming.kotlinSourceSetName(
|
||||
target.disambiguationClassifier, androidSourceSet.name,
|
||||
AndroidBaseSourceSetName.byName(androidSourceSet.name)?.variantType
|
||||
) ?: return@all
|
||||
|
||||
factory.getOrCreateConfiguredKotlinSourceSet(kotlinSourceSetName, androidSourceSet)
|
||||
}
|
||||
|
||||
/* Hook into Android's variant creation: This is invoked in 'afterEvaluate' */
|
||||
@@ -44,8 +48,9 @@ internal object KotlinAndroidSourceSets {
|
||||
variant.sourceSets.forEach { sourceProvider ->
|
||||
val androidSourceSet = android.sourceSets.findByName(sourceProvider.name) ?: return@forEach
|
||||
|
||||
val kotlinSourceSetName = layout.naming.kotlinSourceSetName(target.disambiguationClassifier, sourceProvider.name)
|
||||
?: layout.naming.kotlinSourceSetName(target.disambiguationClassifier, sourceProvider.name, variant.type)
|
||||
val kotlinSourceSetName = layout.naming.kotlinSourceSetName(
|
||||
target.disambiguationClassifier, sourceProvider.name, variant.type
|
||||
) ?: return@forEach
|
||||
|
||||
val kotlinSourceSet = factory.getOrCreateConfiguredKotlinSourceSet(kotlinSourceSetName, androidSourceSet)
|
||||
layout.sourceSetConfigurator.configureWithVariant(target, kotlinSourceSet, variant)
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.gradle.plugin.sources.android
|
||||
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
|
||||
internal object MultiplatformLayoutV1KotlinAndroidSourceSetNaming : KotlinAndroidSourceSetNaming.Simple {
|
||||
override fun kotlinSourceSetName(disambiguationClassifier: String, androidSourceSetName: String): String =
|
||||
internal object MultiplatformLayoutV1KotlinAndroidSourceSetNaming : KotlinAndroidSourceSetNaming {
|
||||
override fun kotlinSourceSetName(disambiguationClassifier: String, androidSourceSetName: String, type: AndroidVariantType?): String =
|
||||
lowerCamelCaseName(disambiguationClassifier, androidSourceSetName)
|
||||
}
|
||||
+3
-10
@@ -22,17 +22,10 @@ internal object MultiplatformLayoutV2KotlinAndroidSourceSetNaming : KotlinAndroi
|
||||
override fun kotlinSourceSetName(
|
||||
disambiguationClassifier: String,
|
||||
androidSourceSetName: String,
|
||||
type: AndroidVariantType?
|
||||
): String? {
|
||||
val androidBaseSourceSetName = AndroidBaseSourceSetName.byName(androidSourceSetName) ?: return null
|
||||
return lowerCamelCaseName(disambiguationClassifier, androidBaseSourceSetName.kotlinName)
|
||||
}
|
||||
|
||||
override fun kotlinSourceSetName(
|
||||
disambiguationClassifier: String,
|
||||
androidSourceSetName: String,
|
||||
type: AndroidVariantType
|
||||
): String {
|
||||
return lowerCamelCaseName(disambiguationClassifier, replaceAndroidBaseSourceSetName(androidSourceSetName, type))
|
||||
val knownType = type ?: AndroidBaseSourceSetName.byName(androidSourceSetName)?.variantType ?: return null
|
||||
return lowerCamelCaseName(disambiguationClassifier, replaceAndroidBaseSourceSetName(androidSourceSetName, knownType))
|
||||
}
|
||||
|
||||
override fun defaultKotlinSourceSetName(compilation: AndroidCompilationDetails): String? {
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ package org.jetbrains.kotlin.gradle.plugin.sources.android
|
||||
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
|
||||
internal object SingleTargetKotlinAndroidSourceSetNaming : KotlinAndroidSourceSetNaming.Simple {
|
||||
override fun kotlinSourceSetName(disambiguationClassifier: String, androidSourceSetName: String): String {
|
||||
internal object SingleTargetKotlinAndroidSourceSetNaming : KotlinAndroidSourceSetNaming {
|
||||
override fun kotlinSourceSetName(disambiguationClassifier: String, androidSourceSetName: String, type: AndroidVariantType?): String {
|
||||
assert(disambiguationClassifier.isEmpty()) { "Unexpected non-empty disambiguationClassifier found: $disambiguationClassifier" }
|
||||
return lowerCamelCaseName(disambiguationClassifier, androidSourceSetName)
|
||||
}
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ import org.gradle.api.logging.Logging
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.android.KotlinAndroidSourceSetLayout
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.android.androidSourceSetInfo
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.android.multiplatformAndroidSourceSetLayoutV1
|
||||
|
||||
/**
|
||||
@@ -26,7 +27,7 @@ internal object MultiplatformLayoutV2MultiplatformLayoutV1StyleSourceDirUsageChe
|
||||
androidSourceSet: AndroidSourceSet
|
||||
) {
|
||||
val v1kotlinSourceSetName = multiplatformAndroidSourceSetLayoutV1.naming.kotlinSourceSetName(
|
||||
target.disambiguationClassifier, androidSourceSet.name
|
||||
target.disambiguationClassifier, androidSourceSet.name, kotlinSourceSet.androidSourceSetInfo.androidVariantType
|
||||
) ?: return
|
||||
|
||||
/* Layouts did agree on the name of this KotlinSourceSet -> LGTM */
|
||||
|
||||
Reference in New Issue
Block a user