[K/N] Add binary option to produce error on mangled objc names (#5264)
objcExportErrorOnNameCollisions=true binary option makes the compiler emit an error whenever it mangles a name emitted by ObjCExport. ^KT-65863 Fixed
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
error: name is mangled when generating Objective-C header
|
||||
(at class ClassClashWithObjCName defined in pkg.lib1)
|
||||
error: name is mangled when generating Objective-C header
|
||||
(at enum entry one defined in pkg.lib1.E)
|
||||
error: name is mangled when generating Objective-C header
|
||||
(at enum entry TWO defined in pkg.lib1.E)
|
||||
error: name is mangled when generating Objective-C header
|
||||
(at fun values(): Array<E> defined in pkg.lib1.E)
|
||||
error: name is mangled when generating Objective-C header
|
||||
(at val entries: EnumEntries<E> defined in pkg.lib1.E)
|
||||
error: name is mangled when generating Objective-C header
|
||||
(at val prop: String defined in pkg.lib1.I2)
|
||||
error: name is mangled when generating Objective-C header
|
||||
(at fun `<get-prop>`(): String defined in pkg.lib1.I2)
|
||||
error: name is mangled when generating Objective-C header
|
||||
(at interface InterfaceClashWithObjCName defined in pkg.lib1)
|
||||
error: name is mangled when generating Objective-C header
|
||||
(at class ClassClash defined in pkg.lib2)
|
||||
error: name is mangled when generating Objective-C header
|
||||
(at interface InterfaceClash defined in pkg.lib2)
|
||||
error: name "TOCEDLib1Kt" is mangled when generating Objective-C header
|
||||
error: name "Lib1Kt" is mangled when generating Objective-C header
|
||||
error: name is mangled when generating Objective-C header
|
||||
(at fun topLevel(arg: Long): Unit defined in pkg.lib1)
|
||||
COMPILATION_ERROR
|
||||
+24
-8
@@ -26,6 +26,7 @@ import org.junit.jupiter.api.Assumptions
|
||||
import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertIs
|
||||
|
||||
abstract class CompilerOutputTestBase : AbstractNativeSimpleTest() {
|
||||
@Test
|
||||
@@ -83,30 +84,45 @@ abstract class CompilerOutputTestBase : AbstractNativeSimpleTest() {
|
||||
|
||||
@Test
|
||||
fun testObjCExportDiagnostics() {
|
||||
val rootDir = File("native/native.tests/testData/compilerOutput/ObjCExportDiagnostics")
|
||||
val compilationResult = doBuildObjCFrameworkWithNameCollisions(rootDir, listOf("-Xbinary=objcExportReportNameCollisions=true"))
|
||||
val goldenData = rootDir.resolve("output.txt")
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(goldenData, compilationResult.toOutput())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testObjCExportDiagnosticsErrors() {
|
||||
val rootDir = File("native/native.tests/testData/compilerOutput/ObjCExportDiagnostics")
|
||||
val compilationResult = doBuildObjCFrameworkWithNameCollisions(rootDir, listOf("-Xbinary=objcExportErrorOnNameCollisions=true"))
|
||||
assertIs<TestCompilationResult.Failure>(compilationResult)
|
||||
val goldenData = rootDir.resolve("error.txt")
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(goldenData, compilationResult.toOutput())
|
||||
}
|
||||
|
||||
private fun doBuildObjCFrameworkWithNameCollisions(rootDir: File, additionalOptions: List<String>): TestCompilationResult<out TestCompilationArtifact.ObjCFramework> {
|
||||
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"
|
||||
listOf(
|
||||
"-Xinclude=${lib1.path}",
|
||||
"-Xinclude=${lib2.path}"
|
||||
) + additionalOptions
|
||||
)
|
||||
val expectedArtifact = TestCompilationArtifact.ObjCFramework(buildDir, "testObjCExportDiagnostics")
|
||||
|
||||
val compilationResult = ObjCFrameworkCompilation(
|
||||
return ObjCFrameworkCompilation(
|
||||
settings,
|
||||
freeCompilerArgs,
|
||||
sourceModules = emptyList(),
|
||||
dependencies = emptyList(),
|
||||
expectedArtifact
|
||||
).result
|
||||
val goldenData = rootDir.resolve("output.txt")
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(goldenData, compilationResult.toOutput())
|
||||
}
|
||||
|
||||
internal fun compileLibrary(
|
||||
|
||||
Reference in New Issue
Block a user