Native: support objcExportReportNameCollisions=true binary option

This binary option makes the compiler emit a warning whenever it mangles
a name emitted by ObjCExport.

^KT-63153 Fixed
This commit is contained in:
Svyatoslav Scherbina
2023-11-03 12:49:22 +01:00
committed by Space Team
parent 656b61b945
commit 8d20d5b16c
12 changed files with 144 additions and 13 deletions
@@ -0,0 +1,38 @@
@file:OptIn(kotlin.experimental.ExperimentalObjCName::class)
package pkg.lib1
interface InterfaceClash
class ClassClash
interface InterfaceClash2
class ClassClash2
@ObjCName("InterfaceClash2")
interface InterfaceClashWithObjCName
@ObjCName("ClassClash2")
class ClassClashWithObjCName
class Lib1Kt
enum class E {
ONE,
one,
@ObjCName("one")
TWO,
ENTRIES,
@ObjCName("values") VALUES1;
}
interface I1 {
val prop: Int
fun method()
}
interface I2 {
val prop: String
fun method()
}
fun topLevel(arg: Int) {}
fun topLevel(arg: Long) {}
@@ -0,0 +1,4 @@
package pkg.lib2
interface InterfaceClash
class ClassClash
@@ -0,0 +1,25 @@
warning: name is mangled when generating Objective-C header
(at class ClassClashWithObjCName defined in pkg.lib1)
warning: name is mangled when generating Objective-C header
(at enum entry one defined in pkg.lib1.E)
warning: name is mangled when generating Objective-C header
(at enum entry TWO defined in pkg.lib1.E)
warning: name is mangled when generating Objective-C header
(at fun values(): Array<E> defined in pkg.lib1.E)
warning: name is mangled when generating Objective-C header
(at val entries: EnumEntries<E> defined in pkg.lib1.E)
warning: name is mangled when generating Objective-C header
(at val prop: String defined in pkg.lib1.I2)
warning: name is mangled when generating Objective-C header
(at fun `<get-prop>`(): String defined in pkg.lib1.I2)
warning: name is mangled when generating Objective-C header
(at interface InterfaceClashWithObjCName defined in pkg.lib1)
warning: name is mangled when generating Objective-C header
(at class ClassClash defined in pkg.lib2)
warning: name is mangled when generating Objective-C header
(at interface InterfaceClash defined in pkg.lib2)
warning: name "TOCEDLib1Kt" is mangled when generating Objective-C header
warning: name "Lib1Kt" is mangled when generating Objective-C header
warning: name is mangled when generating Objective-C header
(at fun topLevel(arg: Long): Unit defined in pkg.lib1)
OK
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.konan.test.blackbox.support.EnforcedProperty
import org.jetbrains.kotlin.konan.test.blackbox.support.LoggedData
import org.jetbrains.kotlin.konan.test.blackbox.support.TestCompilerArgs
import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.LibraryCompilation
import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.ObjCFrameworkCompilation
import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationArtifact
import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationResult
import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationResult.Companion.assertSuccess
@@ -21,6 +22,7 @@ import org.jetbrains.kotlin.konan.test.blackbox.support.group.FirPipeline
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.PipelineType
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.Settings
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.jupiter.api.Assumptions
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import java.io.File
@@ -79,11 +81,39 @@ abstract class CompilerOutputTestBase : AbstractNativeSimpleTest() {
KotlinTestUtils.assertEqualsToFile(goldenData, compilationResult.toOutput())
}
@Test
fun testObjCExportDiagnostics() {
Assumptions.assumeTrue(targets.hostTarget.family.isAppleFamily)
val rootDir = File("native/native.tests/testData/compilerOutput/ObjCExportDiagnostics")
val settings = testRunSettings
val lib1 = compileLibrary(settings, rootDir.resolve("lib1.kt")).assertSuccess().resultingArtifact
val lib2 = compileLibrary(settings, rootDir.resolve("lib2.kt")).assertSuccess().resultingArtifact
val freeCompilerArgs = TestCompilerArgs(
"-Xinclude=${lib1.path}",
"-Xinclude=${lib2.path}",
"-Xbinary=objcExportReportNameCollisions=true"
)
val expectedArtifact = TestCompilationArtifact.ObjCFramework(buildDir, "testObjCExportDiagnostics")
val compilationResult = ObjCFrameworkCompilation(
settings,
freeCompilerArgs,
sourceModules = emptyList(),
dependencies = emptyList(),
expectedArtifact
).result
val goldenData = rootDir.resolve("output.txt")
KotlinTestUtils.assertEqualsToFile(goldenData, compilationResult.toOutput())
}
private fun compileLibrary(
settings: Settings,
source: File,
freeCompilerArgs: List<String>,
dependencies: List<TestCompilationArtifact.KLIB>
freeCompilerArgs: List<String> = emptyList(),
dependencies: List<TestCompilationArtifact.KLIB> = emptyList(),
): TestCompilationResult<out TestCompilationArtifact.KLIB> {
val testCase = generateTestCaseWithSingleModule(source, TestCompilerArgs(freeCompilerArgs))
val compilation = LibraryCompilation(