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