[Gradle][MPP] Disabled CInteorp warning: Show cinterops instead of compilations

KT-51176
This commit is contained in:
sebastian.sellmair
2022-02-08 09:18:24 +01:00
parent 56de13fe2f
commit 200cc9f75f
3 changed files with 31 additions and 10 deletions
+1 -1
View File
@@ -80,4 +80,4 @@
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
</codeStyleSettings>
</code_scheme>
</component>
</component>
@@ -23,7 +23,7 @@ class DisabledCInteropCommonizationWarningTest {
private val project by lazy { ProjectBuilder.builder().build() as ProjectInternal }
@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.setupNativeTargetsWithCInterops()
project.evaluate()
@@ -38,8 +38,18 @@ class DisabledCInteropCommonizationWarningTest {
)
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(
project.runHealthCheckAndGetWarning(),
"Expected no warning message shown when explictily ignored"
"Expected no warning message shown when explicitly ignored"
)
}
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
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.KotlinSharedNativeCompilation
import org.jetbrains.kotlin.gradle.targets.android.findAndroidTarget
@@ -75,12 +76,18 @@ internal fun Project.runDisabledCInteropCommonizationOnHmppProjectConfigurationH
if (isAllowCommonizer() && !kotlinPropertiesProvider.enableCInteropCommonization) {
val multiplatformExtension = multiplatformExtensionOrNull ?: return
val affectedCompilations = multiplatformExtension.targets.flatMap { it.compilations }
val sharedCompilationsWithInterops = multiplatformExtension.targets.flatMap { it.compilations }
.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 */
if (affectedCompilations.isEmpty()) return
if (affectedCInterops.isEmpty()) return
warningLogger(
"""
@@ -89,12 +96,16 @@ internal fun Project.runDisabledCInteropCommonizationOnHmppProjectConfigurationH
'cinterop commonization' can be enabled in your 'gradle.properties'
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:
${affectedCompilations.map { it.defaultSourceSetName }.sorted().joinToString(", ", "[", "]")}
The following compilations are affected:
${affectedCompilations.map { "${it.target.name}/${it.compilationName}" }.sorted().joinToString(", ", "[", "]")}
The following cinterops are affected:
${affectedCInterops.map { it.toString() }.sorted().joinToString(", ", "[", "]")}
""".trimIndent()
)
}