[Gradle][MPP] Disabled CInteorp warning: Show cinterops instead of compilations
KT-51176
This commit is contained in:
+14
-4
@@ -23,7 +23,7 @@ class DisabledCInteropCommonizationWarningTest {
|
|||||||
private val project by lazy { ProjectBuilder.builder().build() as ProjectInternal }
|
private val project by lazy { ProjectBuilder.builder().build() as ProjectInternal }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test warning shows affected source sets and compilations`() {
|
fun `test warning shows affected source sets, affected cinterops and how to hide the warning`() {
|
||||||
project.enableCInteropCommonization(false)
|
project.enableCInteropCommonization(false)
|
||||||
project.setupNativeTargetsWithCInterops()
|
project.setupNativeTargetsWithCInterops()
|
||||||
project.evaluate()
|
project.evaluate()
|
||||||
@@ -38,8 +38,18 @@ class DisabledCInteropCommonizationWarningTest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"[metadata/commonMain, metadata/nativeMain]" in warningMessage,
|
"[" +
|
||||||
"Expected compilations being mentioned in the warning message. Found\n\n$warningMessage"
|
"cinterop:compilation/compileKotlinLinuxArm64/dummy1, " +
|
||||||
|
"cinterop:compilation/compileKotlinLinuxArm64/dummy2, " +
|
||||||
|
"cinterop:compilation/compileKotlinLinuxX64/dummy1, " +
|
||||||
|
"cinterop:compilation/compileKotlinLinuxX64/dummy2" +
|
||||||
|
"]" in warningMessage,
|
||||||
|
"Expected affected cinterops being mentioned in the warning message. Found\n\n$warningMessage"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
"$KOTLIN_MPP_ENABLE_CINTEROP_COMMONIZATION.nowarn=true" in warningMessage,
|
||||||
|
"Expected warning message to include hint on how to disable the warning"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +62,7 @@ class DisabledCInteropCommonizationWarningTest {
|
|||||||
|
|
||||||
assertNull(
|
assertNull(
|
||||||
project.runHealthCheckAndGetWarning(),
|
project.runHealthCheckAndGetWarning(),
|
||||||
"Expected no warning message shown when explictily ignored"
|
"Expected no warning message shown when explicitly ignored"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-4
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_CINTEROP_COMMONIZATION
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinSharedNativeCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinSharedNativeCompilation
|
||||||
import org.jetbrains.kotlin.gradle.targets.android.findAndroidTarget
|
import org.jetbrains.kotlin.gradle.targets.android.findAndroidTarget
|
||||||
@@ -75,12 +76,18 @@ internal fun Project.runDisabledCInteropCommonizationOnHmppProjectConfigurationH
|
|||||||
if (isAllowCommonizer() && !kotlinPropertiesProvider.enableCInteropCommonization) {
|
if (isAllowCommonizer() && !kotlinPropertiesProvider.enableCInteropCommonization) {
|
||||||
val multiplatformExtension = multiplatformExtensionOrNull ?: return
|
val multiplatformExtension = multiplatformExtensionOrNull ?: return
|
||||||
|
|
||||||
val affectedCompilations = multiplatformExtension.targets.flatMap { it.compilations }
|
val sharedCompilationsWithInterops = multiplatformExtension.targets.flatMap { it.compilations }
|
||||||
.filterIsInstance<KotlinSharedNativeCompilation>()
|
.filterIsInstance<KotlinSharedNativeCompilation>()
|
||||||
.filter { compilation -> CInteropCommonizerDependent.from(compilation)?.interops.orEmpty().isNotEmpty() }
|
.mapNotNull { compilation -> compilation to (CInteropCommonizerDependent.from(compilation) ?: return@mapNotNull null) }
|
||||||
|
.toMap()
|
||||||
|
|
||||||
|
val affectedCompilations = sharedCompilationsWithInterops.keys
|
||||||
|
val affectedCInterops = sharedCompilationsWithInterops.values.flatMap { it.interops }.toSet()
|
||||||
|
|
||||||
|
|
||||||
/* CInterop commonizer would not affect the project: No compilation that would actually benefit */
|
/* CInterop commonizer would not affect the project: No compilation that would actually benefit */
|
||||||
if (affectedCompilations.isEmpty()) return
|
if (affectedCompilations.isEmpty()) return
|
||||||
|
if (affectedCInterops.isEmpty()) return
|
||||||
|
|
||||||
warningLogger(
|
warningLogger(
|
||||||
"""
|
"""
|
||||||
@@ -90,11 +97,15 @@ internal fun Project.runDisabledCInteropCommonizationOnHmppProjectConfigurationH
|
|||||||
'cinterop commonization' can be enabled in your 'gradle.properties'
|
'cinterop commonization' can be enabled in your 'gradle.properties'
|
||||||
kotlin.mpp.enableCInteropCommonization=true
|
kotlin.mpp.enableCInteropCommonization=true
|
||||||
|
|
||||||
|
To hide this message, add to your 'gradle.properties'
|
||||||
|
$KOTLIN_MPP_ENABLE_CINTEROP_COMMONIZATION.nowarn=true
|
||||||
|
|
||||||
The following source sets are affected:
|
The following source sets are affected:
|
||||||
${affectedCompilations.map { it.defaultSourceSetName }.sorted().joinToString(", ", "[", "]")}
|
${affectedCompilations.map { it.defaultSourceSetName }.sorted().joinToString(", ", "[", "]")}
|
||||||
|
|
||||||
The following compilations are affected:
|
The following cinterops are affected:
|
||||||
${affectedCompilations.map { "${it.target.name}/${it.compilationName}" }.sorted().joinToString(", ", "[", "]")}
|
${affectedCInterops.map { it.toString() }.sorted().joinToString(", ", "[", "]")}
|
||||||
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user