From b883dc54347aa0d2c649602895b6ad1af1b6c3b8 Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Wed, 30 Nov 2022 08:46:40 +0000 Subject: [PATCH] [KT-39120] Add "-fmodules" argument support to Cinterop Merge-request: KT-MR-6921 Merged-by: Vladimir Sukharev --- .../kotlin/native/interop/indexer/Indexer.kt | 108 +++++--- .../native/interop/indexer/MacroConstants.kt | 52 ++-- .../native/interop/indexer/ModuleSupport.kt | 8 +- .../native/interop/indexer/NativeIndex.kt | 2 +- .../kotlin/native/interop/indexer/Utils.kt | 215 ++++++++++----- .../native/interop/indexer/WorkaroundTests.kt | 2 +- .../native/interop/gen/StubIrBuilder.kt | 3 +- .../kotlin/native/interop/gen/jvm/main.kt | 56 ++-- .../native/interop/gen/InteropTestsBase.kt | 1 - .../backend.native/tests/build.gradle | 11 + .../tests/interop/kt54284/main.kt | 12 +- .../kotlin/cli/utilities/InteropCompiler.kt | 4 +- native/native.tests/README.md | 19 +- native/native.tests/build.gradle.kts | 1 + .../defs/KT-39120/pod1.contents.gold.txt | 4 + .../CInterop/KT-39120/defs/KT-39120/pod1.def | 2 + .../defs/KT-39120/pod2.contents.gold.txt | 4 + .../CInterop/KT-39120/defs/KT-39120/pod2.def | 2 + .../interModuleImport/pod1.contents.gold.txt | 4 + .../KT-39120/defs/interModuleImport/pod1.def | 2 + .../interModuleImport/pod2.contents.gold.txt | 4 + .../KT-39120/defs/interModuleImport/pod2.def | 2 + .../interpod1.framework/Headers/interpod1.h | 3 + .../Modules/module.modulemap | 6 + .../interpod2.framework/Headers/interpod2.h | 4 + .../Modules/module.modulemap | 6 + .../pod1.framework/Headers/pod1-umbrella.h | 16 ++ .../KT-39120/pod1.framework/Headers/pod1.h | 3 + .../pod1.framework/Modules/module.modulemap | 6 + .../pod2.framework/Headers/pod2-Swift.h | 220 +++++++++++++++ .../pod2.framework/Headers/pod2-umbrella.h | 16 ++ .../pod2.framework/Modules/module.modulemap | 11 + .../filterA/contents.gold.ARM32.txt | 21 ++ .../filterA/contents.gold.ARM64.txt | 33 +++ .../filterA/contents.gold.COpaquePointer.txt | 12 + .../filterA/contents.gold.CPointerByteVar.txt | 12 + .../filterA/contents.gold.X64.txt | 31 +++ .../builtins/builtinsDefs/filterA/pod1.def | 3 + .../filterStdargH/contents.gold.ARM32.txt | 19 ++ .../filterStdargH/contents.gold.ARM64.txt | 31 +++ .../contents.gold.COpaquePointer.txt | 11 + .../contents.gold.CPointerByteVar.txt | 11 + .../filterStdargH/contents.gold.X64.txt | 31 +++ .../builtinsDefs/filterStdargH/pod1.def | 3 + .../fullA/contents.gold.ARM32.txt | 24 ++ .../fullA/contents.gold.ARM64.txt | 36 +++ .../fullA/contents.gold.COpaquePointer.txt | 17 ++ .../fullA/contents.gold.CPointerByteVar.txt | 17 ++ .../builtinsDefs/fullA/contents.gold.X64.txt | 36 +++ .../builtins/builtinsDefs/fullA/pod1.def | 2 + .../fullStdargH/contents.gold.ARM32.txt | 19 ++ .../fullStdargH/contents.gold.ARM64.txt | 31 +++ .../contents.gold.COpaquePointer.txt | 11 + .../contents.gold.CPointerByteVar.txt | 11 + .../fullStdargH/contents.gold.X64.txt | 31 +++ .../builtinsDefs/fullStdargH/pod1.def | 2 + .../modulesA/contents.gold.ARM32.txt | 21 ++ .../modulesA/contents.gold.ARM64.txt | 33 +++ .../modulesA/contents.gold.COpaquePointer.txt | 12 + .../contents.gold.CPointerByteVar.txt | 12 + .../modulesA/contents.gold.X64.txt | 31 +++ .../builtins/builtinsDefs/modulesA/pod1.def | 2 + .../testData/CInterop/builtins/include/A.h | 4 + .../builtins/include/module.modulemap | 4 + .../macrosDefs/modulesPod1/contents.gold.txt | 9 + .../macrosDefs/modulesPod1/pod1.def | 2 + .../macrosDefs/myMacroType/contents.gold.txt | 9 + .../macrosDefs/myMacroType/pod1.def | 2 + .../pod1.framework/Headers/pod1.h | 8 + .../pod1.framework/Headers/pod1A.h | 7 + .../pod1.framework/Modules/module.modulemap | 6 + .../childImport.framework/Headers/child.h | 2 + .../childImport.framework/Headers/umbrella.h | 2 + .../Modules/module.modulemap | 7 + .../childImportFModules/contents.gold.txt | 10 + .../childImportFModules/pod1.def | 2 + .../excludePod1/contents.gold.txt | 10 + .../frameworkDefs/excludePod1/pod1.def | 5 + .../excludePod1Umbrella/contents.gold.txt | 7 + .../excludePod1Umbrella/pod1.def | 5 + .../filterPod1/contents.gold.txt | 7 + .../frameworkDefs/filterPod1/pod1.def | 4 + .../filterPod1A/contents.gold.txt | 7 + .../frameworkDefs/filterPod1A/pod1.def | 4 + .../filterPod1Umbrella/contents.gold.txt | 7 + .../frameworkDefs/filterPod1Umbrella/pod1.def | 4 + .../filterPod1UmbrellaPod1A/contents.gold.txt | 10 + .../filterPod1UmbrellaPod1A/pod1.def | 4 + .../frameworkDefs/full/contents.gold.txt | 13 + .../framework/frameworkDefs/full/pod1.def | 2 + .../importsAngleAngle/contents.gold.txt | 13 + .../frameworkDefs/importsAngleAngle/pod1.def | 2 + .../importsAngleQuote/contents.gold.txt | 13 + .../frameworkDefs/importsAngleQuote/pod1.def | 2 + .../importsQuoteAngle/contents.gold.txt | 13 + .../frameworkDefs/importsQuoteAngle/pod1.def | 2 + .../importsQuoteQuote/contents.gold.txt | 13 + .../frameworkDefs/importsQuoteQuote/pod1.def | 2 + .../modulesPod1/contents.gold.txt | 13 + .../frameworkDefs/modulesPod1/pod1.def | 2 + .../twoChildren/contents.gold.txt | 13 + .../frameworkDefs/twoChildren/pod1.def | 2 + .../visitOtherModules/contents.gold.txt | 7 + .../frameworkDefs/visitOtherModules/pod1.def | 2 + .../framework/m1.framework/Headers/m1.h | 9 + .../m1.framework/Modules/module.modulemap | 7 + .../framework/m2.framework/Headers/m2.h | 8 + .../m2.framework/Modules/module.modulemap | 7 + .../pod1.framework/Headers/pod1-umbrella.h | 2 + .../framework/pod1.framework/Headers/pod1.h | 2 + .../framework/pod1.framework/Headers/pod1A.h | 1 + .../pod1.framework/Modules/module.modulemap | 6 + .../Headers/podImportsAngleAngle-umbrella.h | 2 + .../Headers/podImportsAngleAngle.h | 2 + .../Headers/podImportsAngleAngleA.h | 1 + .../Modules/module.modulemap | 6 + .../Headers/podImportsAngleQuote-umbrella.h | 2 + .../Headers/podImportsAngleQuote.h | 2 + .../Headers/podImportsAngleQuoteA.h | 1 + .../Modules/module.modulemap | 6 + .../Headers/podImportsQuoteAngle-umbrella.h | 2 + .../Headers/podImportsQuoteAngle.h | 2 + .../Headers/podImportsQuoteAngleA.h | 1 + .../Modules/module.modulemap | 6 + .../Headers/podImportsQuoteQuote-umbrella.h | 2 + .../Headers/podImportsQuoteQuote.h | 2 + .../Headers/podImportsQuoteQuoteA.h | 1 + .../Modules/module.modulemap | 6 + .../twoChildren.framework/Headers/child1.h | 1 + .../twoChildren.framework/Headers/child2.h | 1 + .../twoChildren.framework/Headers/umbrella.h | 3 + .../Modules/module.modulemap | 7 + .../testData/CInterop/simple/include/A.h | 11 + .../testData/CInterop/simple/include/B.h | 8 + .../testData/CInterop/simple/include/C.h | 6 + .../CInterop/simple/include/module.modulemap | 10 + .../simpleDefs/filterA/contents.gold.txt | 8 + .../simple/simpleDefs/filterA/pod1.def | 3 + .../simpleDefs/filterAB/contents.gold.txt | 11 + .../simple/simpleDefs/filterAB/pod1.def | 3 + .../simpleDefs/filterABC/contents.gold.txt | 14 + .../simple/simpleDefs/filterABC/pod1.def | 3 + .../simpleDefs/filterAC/contents.gold.txt | 11 + .../simple/simpleDefs/filterAC/pod1.def | 3 + .../simpleDefs/filterB/contents.gold.txt | 7 + .../simple/simpleDefs/filterB/pod1.def | 3 + .../simpleDefs/filterBC/contents.gold.txt | 10 + .../simple/simpleDefs/filterBC/pod1.def | 3 + .../simpleDefs/filterC/contents.gold.txt | 7 + .../simple/simpleDefs/filterC/pod1.def | 3 + .../simple/simpleDefs/full/contents.gold.txt | 14 + .../CInterop/simple/simpleDefs/full/pod1.def | 2 + .../simpleDefs/modulesA/contents.gold.txt | 11 + .../simple/simpleDefs/modulesA/pod1.def | 2 + .../simpleDefs/modulesAB/contents.gold.txt | 14 + .../simple/simpleDefs/modulesAB/pod1.def | 2 + .../simpleDefs/modulesB/contents.gold.txt | 10 + .../simple/simpleDefs/modulesB/pod1.def | 2 + .../CInteropFModulesTestGenerated.java | 257 ++++++++++++++++++ .../CInteropKT39120TestGenerated.java | 38 +++ .../CInteropNoFModulesTestGenerated.java | 257 ++++++++++++++++++ .../generators/tests/GenerateNativeTests.kt | 30 +- .../AbstractNativeCInteropBaseTest.kt | 52 ++++ .../AbstractNativeCInteropKT39120Test.kt | 59 ++++ .../AbstractNativeCInteropTest.kt | 113 ++++++++ .../konan/blackboxtest/support/LoggedData.kt | 38 ++- ...CompilerCall.kt => CompilationToolCall.kt} | 64 ++++- .../support/compilation/TestCompilation.kt | 58 +++- .../compilation/TestCompilationResult.kt | 6 +- .../support/runner/LocalTestNameExtractor.kt | 2 +- .../support/runner/LocalTestRunner.kt | 2 +- .../blackboxtest/support/runner/TestRun.kt | 10 +- .../support/util/TestCompilationArtifacts.kt | 19 ++ 173 files changed, 2707 insertions(+), 214 deletions(-) create mode 100644 native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod1.contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod1.def create mode 100644 native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod2.contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod2.def create mode 100644 native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod1.contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod1.def create mode 100644 native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod2.contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod2.def create mode 100644 native/native.tests/testData/CInterop/KT-39120/interpod1.framework/Headers/interpod1.h create mode 100644 native/native.tests/testData/CInterop/KT-39120/interpod1.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/KT-39120/interpod2.framework/Headers/interpod2.h create mode 100644 native/native.tests/testData/CInterop/KT-39120/interpod2.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/KT-39120/pod1.framework/Headers/pod1-umbrella.h create mode 100644 native/native.tests/testData/CInterop/KT-39120/pod1.framework/Headers/pod1.h create mode 100644 native/native.tests/testData/CInterop/KT-39120/pod1.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/KT-39120/pod2.framework/Headers/pod2-Swift.h create mode 100644 native/native.tests/testData/CInterop/KT-39120/pod2.framework/Headers/pod2-umbrella.h create mode 100644 native/native.tests/testData/CInterop/KT-39120/pod2.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.ARM32.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.ARM64.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.COpaquePointer.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.CPointerByteVar.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.X64.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/pod1.def create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.ARM32.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.ARM64.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.COpaquePointer.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.CPointerByteVar.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.X64.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/pod1.def create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.ARM32.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.ARM64.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.COpaquePointer.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.CPointerByteVar.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.X64.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/pod1.def create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.ARM32.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.ARM64.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.COpaquePointer.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.CPointerByteVar.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.X64.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/pod1.def create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.ARM32.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.ARM64.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.COpaquePointer.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.CPointerByteVar.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.X64.txt create mode 100644 native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/pod1.def create mode 100644 native/native.tests/testData/CInterop/builtins/include/A.h create mode 100644 native/native.tests/testData/CInterop/builtins/include/module.modulemap create mode 100644 native/native.tests/testData/CInterop/framework.macros/macrosDefs/modulesPod1/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework.macros/macrosDefs/modulesPod1/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework.macros/macrosDefs/myMacroType/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework.macros/macrosDefs/myMacroType/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework.macros/pod1.framework/Headers/pod1.h create mode 100644 native/native.tests/testData/CInterop/framework.macros/pod1.framework/Headers/pod1A.h create mode 100644 native/native.tests/testData/CInterop/framework.macros/pod1.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/framework/childImport.framework/Headers/child.h create mode 100644 native/native.tests/testData/CInterop/framework/childImport.framework/Headers/umbrella.h create mode 100644 native/native.tests/testData/CInterop/framework/childImport.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/childImportFModules/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/childImportFModules/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1Umbrella/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1Umbrella/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1A/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1A/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1Umbrella/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1Umbrella/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1UmbrellaPod1A/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1UmbrellaPod1A/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/full/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/full/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleAngle/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleAngle/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleQuote/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleQuote/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteAngle/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteAngle/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteQuote/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteQuote/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/modulesPod1/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/modulesPod1/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/twoChildren/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/twoChildren/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/visitOtherModules/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/framework/frameworkDefs/visitOtherModules/pod1.def create mode 100644 native/native.tests/testData/CInterop/framework/m1.framework/Headers/m1.h create mode 100644 native/native.tests/testData/CInterop/framework/m1.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/framework/m2.framework/Headers/m2.h create mode 100644 native/native.tests/testData/CInterop/framework/m2.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1-umbrella.h create mode 100644 native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1.h create mode 100644 native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1A.h create mode 100644 native/native.tests/testData/CInterop/framework/pod1.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngle-umbrella.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngle.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngleA.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuote-umbrella.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuote.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuoteA.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngle-umbrella.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngle.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngleA.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuote-umbrella.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuote.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuoteA.h create mode 100644 native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/child1.h create mode 100644 native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/child2.h create mode 100644 native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/umbrella.h create mode 100644 native/native.tests/testData/CInterop/framework/twoChildren.framework/Modules/module.modulemap create mode 100644 native/native.tests/testData/CInterop/simple/include/A.h create mode 100644 native/native.tests/testData/CInterop/simple/include/B.h create mode 100644 native/native.tests/testData/CInterop/simple/include/C.h create mode 100644 native/native.tests/testData/CInterop/simple/include/module.modulemap create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterA/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterA/pod1.def create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterAB/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterAB/pod1.def create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterABC/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterABC/pod1.def create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterAC/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterAC/pod1.def create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterB/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterB/pod1.def create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterBC/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterBC/pod1.def create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterC/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/filterC/pod1.def create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/full/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/full/pod1.def create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/modulesA/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/modulesA/pod1.def create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/modulesAB/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/modulesAB/pod1.def create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/modulesB/contents.gold.txt create mode 100644 native/native.tests/testData/CInterop/simple/simpleDefs/modulesB/pod1.def create mode 100644 native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropFModulesTestGenerated.java create mode 100644 native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropKT39120TestGenerated.java create mode 100644 native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropNoFModulesTestGenerated.java create mode 100644 native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropBaseTest.kt create mode 100644 native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropKT39120Test.kt create mode 100644 native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropTest.kt rename native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/{CompilerCall.kt => CompilationToolCall.kt} (50%) create mode 100644 native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TestCompilationArtifacts.kt diff --git a/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt b/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt index 31cdbd4d3e7..8be63f76bce 100644 --- a/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt +++ b/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt @@ -151,7 +151,7 @@ public open class NativeIndexImpl(val library: NativeLibrary, val verbose: Boole override lateinit var includedHeaders: List - private fun log(message: String) { + internal fun log(message: String) { if (verbose) { println(message) } @@ -1187,67 +1187,85 @@ fun buildNativeIndexImpl(index: NativeIndexImpl): IndexerResult { } private fun indexDeclarations(nativeIndex: NativeIndexImpl): CompilationWithPCH { - withIndex { index -> + // Below, declarations from PCH should be excluded to restrict `visitChildren` to visit local declarations only + withIndex(excludeDeclarationsFromPCH = true) { index -> + val errors = mutableListOf() val translationUnit = nativeIndex.library.copyWithArgsForPCH().parse( index, - options = CXTranslationUnit_DetailedPreprocessingRecord or CXTranslationUnit_ForSerialization + options = CXTranslationUnit_DetailedPreprocessingRecord or CXTranslationUnit_ForSerialization, + diagnosticHandler = { if (it.isError()) errors.add(it) } ) try { + if (errors.isNotEmpty()) { + error(errors.take(10).joinToString("\n") { it.format }) + } translationUnit.ensureNoCompileErrors() val compilation = nativeIndex.library.withPrecompiledHeader(translationUnit) - val headers = getFilteredHeaders(nativeIndex, index, translationUnit) + UnitsHolder(index).use { unitsHolder -> + val (headers, ownTranslationUnits) = getHeadersAndUnits(nativeIndex.library, index, translationUnit, unitsHolder) + val ownHeaders = headers.ownHeaders + val headersCanonicalPaths = ownHeaders.map { it?.canonicalPath }.toSet() - nativeIndex.includedHeaders = headers.map { - nativeIndex.getHeaderId(it) - } + val unitsToProcess = (ownTranslationUnits + setOf(translationUnit)).toList() - indexTranslationUnit(index, translationUnit, 0, object : Indexer { - override fun indexDeclaration(info: CXIdxDeclInfo) { - val file = memScoped { - val fileVar = alloc() - clang_indexLoc_getFileLocation(info.loc.readValue(), null, fileVar.ptr, null, null, null) - fileVar.value - } - - if (file in headers) { - nativeIndex.indexDeclaration(info) - } + nativeIndex.includedHeaders = ownHeaders.map { + nativeIndex.getHeaderId(it) } - }) - if (nativeIndex.library.language == Language.CPP) { - visitChildren(clang_getTranslationUnitCursor(translationUnit)) { cursor, _ -> - if (getContainingFile(cursor) in headers) { - nativeIndex.indexCxxDeclaration(cursor) - } - CXChildVisitResult.CXChildVisit_Continue - } - } + unitsToProcess.forEach { + indexTranslationUnit(index, it, 0, object : Indexer { + override fun indexDeclaration(info: CXIdxDeclInfo) { + val file = memScoped { + val fileVar = alloc() + clang_indexLoc_getFileLocation(info.loc.readValue(), null, fileVar.ptr, null, null, null) + fileVar.value + } - visitChildren(clang_getTranslationUnitCursor(translationUnit)) { cursor, _ -> - val file = getContainingFile(cursor) - if (file in headers && nativeIndex.library.includesDeclaration(cursor)) { - when (cursor.kind) { - CXCursorKind.CXCursor_ObjCInterfaceDecl -> nativeIndex.indexObjCClass(cursor) - CXCursorKind.CXCursor_ObjCProtocolDecl -> nativeIndex.indexObjCProtocol(cursor) - CXCursorKind.CXCursor_ObjCCategoryDecl -> { - // This fixes https://youtrack.jetbrains.com/issue/KT-49455, which effectively seems to be a bug in libclang: - // the libclang indexer doesn't properly index categories with - // `__attribute__((external_source_symbol(language="Swift",...)))`. - // As a workaround, additionally enumerate all the categories explicitly. - nativeIndex.indexObjCCategory(cursor) + if (file?.canonicalPath in headersCanonicalPaths) { + nativeIndex.indexDeclaration(info) + } + } + }) + } + + if (nativeIndex.library.language == Language.CPP) { + unitsToProcess.forEach { + visitChildren(clang_getTranslationUnitCursor(it)) { cursor, _ -> + if (getContainingFile(cursor) in ownHeaders) { + nativeIndex.indexCxxDeclaration(cursor) + } + CXChildVisitResult.CXChildVisit_Continue } - else -> {} } } - CXChildVisitResult.CXChildVisit_Continue + + unitsToProcess.forEach { + visitChildren(clang_getTranslationUnitCursor(it)) { cursor, _ -> + val file = getContainingFile(cursor) + if (file in ownHeaders && nativeIndex.library.includesDeclaration(cursor)) { + when (cursor.kind) { + CXCursorKind.CXCursor_ObjCInterfaceDecl -> nativeIndex.indexObjCClass(cursor) + CXCursorKind.CXCursor_ObjCProtocolDecl -> nativeIndex.indexObjCProtocol(cursor) + CXCursorKind.CXCursor_ObjCCategoryDecl -> { + // This fixes https://youtrack.jetbrains.com/issue/KT-49455, which effectively seems to be a bug in libclang: + // the libclang indexer doesn't properly index categories with + // `__attribute__((external_source_symbol(language="Swift",...)))`. + // As a workaround, additionally enumerate all the categories explicitly. + nativeIndex.indexObjCCategory(cursor) + } + + else -> {} + } + } + CXChildVisitResult.CXChildVisit_Continue + } + } + + findMacros(nativeIndex, compilation, unitsToProcess, ownHeaders) + return compilation } - - findMacros(nativeIndex, compilation, translationUnit, headers) - - return compilation } finally { clang_disposeTranslationUnit(translationUnit) } diff --git a/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt b/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt index ef75406761a..873352a8a82 100644 --- a/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt +++ b/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/MacroConstants.kt @@ -20,16 +20,18 @@ import clang.* import kotlinx.cinterop.* import java.io.File +val predefinedMacros = setOf("__DATE__", "__TIME__", "__TIMESTAMP__", "__FILE__", "__FILE_NAME__", "__BASE_FILE__", "__LINE__") + /** * Finds all "macro constants" and registers them as [NativeIndex.constants] in given index. */ internal fun findMacros( nativeIndex: NativeIndexImpl, compilation: CompilationWithPCH, - translationUnit: CXTranslationUnit, + translationUnits: List, headers: Set ) { - val names = collectMacroNames(nativeIndex, translationUnit, headers) + val names = collectMacroNames(nativeIndex, translationUnits, headers) // TODO: apply user-defined filters. val macros = expandMacros(compilation, names, typeConverter = { nativeIndex.convertType(it) }) @@ -60,17 +62,10 @@ private fun expandMacros( // or function-like construction (e.g. #define FOO throw()) but such a function is undeclared. compilerArgs += "-Werror=implicit-function-declaration" - // Some predefined macros expand to contextual values that won't make sense to expose in Kotlin properties. - // We instead redefined them to string values of the macro name. - compilerArgs += "-Wno-builtin-macro-redefined" - val predefinedMacros = listOf("__DATE__", "__TIME__", "__TIMESTAMP__", "__FILE__", "__FILE_NAME__", "__BASE_FILE__", "__LINE__") - predefinedMacros.forEach { - compilerArgs += "-D${it}=\"${it}\"" - } // Ensure libclang reports all errors: compilerArgs += "-ferror-limit=0" - val translationUnit = parseTranslationUnit(index, sourceFile, compilerArgs, options = 0) + val translationUnit = parseTranslationUnit(index, sourceFile, compilerArgs, options = CXTranslationUnit_DetailedPreprocessingRecord) try { val nameToMacroDef = mutableMapOf() val unprocessedMacros = names.toMutableList() @@ -188,7 +183,7 @@ private fun reparseWithCodeSnippets(library: CompilationWithPCH, codeSnippetLines.forEach { writer.appendLine(it) } } } - clang_reparseTranslationUnit(translationUnit, 0, null, 0) + clang_reparseTranslationUnit(translationUnit, 0, null, CXTranslationUnit_DetailedPreprocessingRecord) } /** @@ -291,29 +286,30 @@ enum class VisitorState { EXPECT_END, INVALID } -private fun collectMacroNames(nativeIndex: NativeIndexImpl, translationUnit: CXTranslationUnit, headers: Set): List { +private fun collectMacroNames(nativeIndex: NativeIndexImpl, translationUnits: List, headers: Set): List { val result = mutableSetOf() - visitChildren(translationUnit) { cursor, _ -> - val file = memScoped { - val fileVar = alloc() - clang_getFileLocation(clang_getCursorLocation(cursor), fileVar.ptr, null, null, null) - fileVar.value - } + translationUnits.forEach { + visitChildren(it) { cursor, _ -> + val file = memScoped { + val fileVar = alloc() + clang_getFileLocation(clang_getCursorLocation(cursor), fileVar.ptr, null, null, null) + fileVar.value + } - if (cursor.kind == CXCursorKind.CXCursor_MacroDefinition && - nativeIndex.library.includesDeclaration(cursor) && - file != null && // Builtin macros mostly seem to be useless. - file in headers && - canMacroBeConstant(cursor)) - { - val spelling = getCursorSpelling(cursor) - result.add(spelling) + if (cursor.kind == CXCursorKind.CXCursor_MacroDefinition && + nativeIndex.library.includesDeclaration(cursor) && + file != null && // Builtin macros mostly seem to be useless. + file in headers && + canMacroBeConstant(cursor)) { + val spelling = getCursorSpelling(cursor) + result.add(spelling) + } + CXChildVisitResult.CXChildVisit_Continue } - CXChildVisitResult.CXChildVisit_Continue } - return result.toList() + return result.filterNot { predefinedMacros.contains(it) }.toList() } private fun canMacroBeConstant(cursor: CValue): Boolean { diff --git a/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/ModuleSupport.kt b/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/ModuleSupport.kt index 4b17bce2ae9..31ea46d517b 100644 --- a/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/ModuleSupport.kt +++ b/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/ModuleSupport.kt @@ -4,12 +4,12 @@ import clang.* import kotlinx.cinterop.* import java.nio.file.Files -data class ModulesInfo(val topLevelHeaders: List, val ownHeaders: Set) +data class ModulesInfo(val topLevelHeaders: List, val ownHeaders: Set, val modules: List) fun getModulesInfo(compilation: Compilation, modules: List): ModulesInfo { - if (modules.isEmpty()) return ModulesInfo(emptyList(), emptySet()) + if (modules.isEmpty()) return ModulesInfo(emptyList(), emptySet(), emptyList()) - withIndex { index -> + withIndex(excludeDeclarationsFromPCH = false) { index -> ModularCompilation(compilation).use { val modulesASTFiles = getModulesASTFiles(index, it, modules) return buildModulesInfo(index, modules, modulesASTFiles) @@ -30,7 +30,7 @@ private fun buildModulesInfo(index: CXIndex, modules: List, modulesASTFi } } - return ModulesInfo(topLevelHeaders.toList(), ownHeaders) + return ModulesInfo(topLevelHeaders.toList(), ownHeaders, modules) } internal open class ModularCompilation(compilation: Compilation): Compilation by compilation, Disposable { diff --git a/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/NativeIndex.kt b/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/NativeIndex.kt index 8b094d8c749..a7fa80ee463 100644 --- a/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/NativeIndex.kt +++ b/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/NativeIndex.kt @@ -48,7 +48,7 @@ sealed class NativeLibraryHeaderFilter { val excludeDepdendentModules: Boolean ) : NativeLibraryHeaderFilter() - class Predefined(val headers: Set) : NativeLibraryHeaderFilter() + class Predefined(val headers: Set, val modules: List) : NativeLibraryHeaderFilter() } interface Compilation { diff --git a/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt b/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt index 5dcf77deb1a..7e8385547be 100644 --- a/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt +++ b/kotlin-native/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt @@ -25,6 +25,7 @@ import java.nio.file.Path import java.nio.file.Paths import java.security.DigestInputStream import java.security.MessageDigest +import java.util.* import java.util.concurrent.ConcurrentHashMap val CValue.kind: CXTypeKind get() = this.useContents { kind } @@ -105,7 +106,7 @@ internal fun CValue.getSize(): Long { } internal inline fun withIndex( - excludeDeclarationsFromPCH: Boolean = false, + excludeDeclarationsFromPCH: Boolean, // disables visitChildren to visit declarations from imported translation units displayDiagnostics: Boolean = false, block: (index: CXIndex) -> R ): R { @@ -404,8 +405,8 @@ data class CompilationImpl( * * @return the library which includes the precompiled header instead of original ones. */ -fun Compilation.precompileHeaders(): CompilationWithPCH = withIndex { index -> - val options = CXTranslationUnit_ForSerialization +fun Compilation.precompileHeaders(): CompilationWithPCH = withIndex(excludeDeclarationsFromPCH = false) { index -> + val options = CXTranslationUnit_ForSerialization or CXTranslationUnit_DetailedPreprocessingRecord val translationUnit = copyWithArgsForPCH().parse(index, options) try { translationUnit.ensureNoCompileErrors() @@ -471,7 +472,7 @@ fun List>.mapFragmentIsCompilable(originalLibrary: CompilationWithP withIndex(excludeDeclarationsFromPCH = true) { index -> val sourceFile = library.createTempSource() - val translationUnit = parseTranslationUnit(index, sourceFile, library.compilerArgs, options = 0) + val translationUnit = parseTranslationUnit(index, sourceFile, library.compilerArgs, options = CXTranslationUnit_DetailedPreprocessingRecord) try { translationUnit.ensureNoCompileErrors() while (fragmentsToCheck.isNotEmpty()) { @@ -486,7 +487,7 @@ fun List>.mapFragmentIsCompilable(originalLibrary: CompilationWithP } } - clang_reparseTranslationUnit(translationUnit, 0, null, 0) + clang_reparseTranslationUnit(translationUnit, 0, null, CXTranslationUnit_DetailedPreprocessingRecord) val errorLineNumbers = translationUnit.getErrorLineNumbers().toSet() // Retain only those fragments that contain compilation error locations: @@ -653,19 +654,16 @@ internal fun getHeaderId(library: NativeLibrary, header: CXFile?): HeaderId { return library.headerToIdMapper.getHeaderId(filePath) } -internal fun getFilteredHeaders( - nativeIndex: NativeIndexImpl, - index: CXIndex, - translationUnit: CXTranslationUnit -): Set = getHeaders(nativeIndex.library, index, translationUnit).ownHeaders - class NativeLibraryHeaders
(val ownHeaders: Set
, val importedHeaders: Set
) +data class NativeLibraryHeadersAndUnits(val headers: NativeLibraryHeaders, val ownTranslationUnits: Set) -internal fun getHeaders( +internal fun getHeadersAndUnits( library: NativeLibrary, index: CXIndex, - translationUnit: CXTranslationUnit -): NativeLibraryHeaders { + translationUnit: CXTranslationUnit, + unitsHolder: UnitsHolder +): NativeLibraryHeadersAndUnits { + val ownTranslationUnits = mutableSetOf() val ownHeaders = mutableSetOf() val allHeaders = mutableSetOf(null) @@ -673,15 +671,31 @@ internal fun getHeaders( when (filter) { is NativeLibraryHeaderFilter.NameBased -> - filterHeadersByName(library, filter, index, translationUnit, ownHeaders, allHeaders) + filterHeadersByName(library, filter, index, translationUnit, ownTranslationUnits, ownHeaders, allHeaders, unitsHolder) is NativeLibraryHeaderFilter.Predefined -> - filterHeadersByPredefined(filter, index, translationUnit, ownHeaders, allHeaders) + filterHeadersByPredefined(filter, index, translationUnit, ownTranslationUnits, ownHeaders, allHeaders, unitsHolder) } ownHeaders.removeAll { library.headerExclusionPolicy.excludeAll(getHeaderId(library, it)) } - return NativeLibraryHeaders(ownHeaders, allHeaders - ownHeaders) + return NativeLibraryHeadersAndUnits(NativeLibraryHeaders(ownHeaders, allHeaders - ownHeaders), ownTranslationUnits) +} + +class UnitsHolder(val index: CXIndex) : Disposable { + private val unitByBinaryFile = mutableMapOf() + + internal fun load(info: CXIdxImportedASTFileInfo): CXTranslationUnit { + val canonicalPath: String = info.file!!.canonicalPath + return unitByBinaryFile.getOrPut(canonicalPath) { + clang_createTranslationUnit(index, canonicalPath)!! + } + } + + override fun dispose() { + unitByBinaryFile.values.forEach { clang_disposeTranslationUnit(it) } + unitByBinaryFile.clear() + } } private fun filterHeadersByName( @@ -689,57 +703,78 @@ private fun filterHeadersByName( filter: NativeLibraryHeaderFilter.NameBased, index: CXIndex, translationUnit: CXTranslationUnit, + ownTranslationUnits: MutableSet, ownHeaders: MutableSet, - allHeaders: MutableSet + allHeaders: MutableSet, + unitsHolder: UnitsHolder ) { - val topLevelFiles = mutableListOf() + val topLevelFiles = mutableSetOf() var mainFile: CXFile? = null + val translationUnits = mutableListOf(translationUnit) - indexTranslationUnit(index, translationUnit, 0, object : Indexer { - val headerToName = mutableMapOf() - // The *name* of the header here is the path relative to the include path element., e.g. `curl/curl.h`. + // The *name* of the header here is the path relative to the include path element., e.g. `curl/curl.h`. + val headerToName = mutableMapOf() - override fun enteredMainFile(file: CXFile) { - mainFile = file - allHeaders += file - } + var curUnitIndex = 0 + while (curUnitIndex < translationUnits.size) { + val curUnit = translationUnits[curUnitIndex++] - override fun ppIncludedFile(info: CXIdxIncludedFileInfo) { - val includeLocation = clang_indexLoc_getCXSourceLocation(info.hashLoc.readValue()) - val file = info.file!! - - allHeaders += file - - if (clang_Location_isFromMainFile(includeLocation) != 0) { - topLevelFiles.add(file) + indexTranslationUnit(index, curUnit, 0, object : Indexer { + override fun enteredMainFile(file: CXFile) { + mainFile = file + allHeaders += file } - val name = info.filename!!.toKString() - val headerName = if (info.isAngled != 0) { - // If the header is included with `#include <$name>`, then `name` is probably - // the path relative to the include path element. - name - } else { - // If it is included with `#include "$name"`, then `name` can also be the path relative to the includer. - val includerFile = includeLocation.getContainingFile()!! - val includerName = headerToName[includerFile] ?: "" - val includerPath = includerFile.path + override fun ppIncludedFile(info: CXIdxIncludedFileInfo) { + val includeLocation = clang_indexLoc_getCXSourceLocation(info.hashLoc.readValue()) + val file = info.file!! - if (clang_getFile(translationUnit, Paths.get(includerPath).resolveSibling(name).toString()) == file) { - // included file is accessible from the includer by `name` used as relative path, so - // `name` seems to be relative to the includer: - Paths.get(includerName).resolveSibling(name).normalize().toString() - } else { + allHeaders += file + + if (clang_Location_isFromMainFile(includeLocation) != 0) { + topLevelFiles.add(file) + } + + val name = info.filename!!.toKString() + val headerName = if (info.isAngled != 0) { + // If the header is included with `#include <$name>`, then `name` is probably + // the path relative to the include path element. name + } else { + // If it is included with `#include "$name"`, then `name` can also be the path relative to the includer. + // Warning: containingFile is null when one module imports another via AST file + val includerFile = includeLocation.getContainingFile()!! + val includerName = headerToName[includerFile.canonicalPath] ?: "" + val includerPath = includerFile.path + + val resolvedSibling = Paths.get(includerPath).resolveSibling(name).toString() + if (clang_getFile(curUnit, resolvedSibling) == file) { + // included file is accessible from the includer by `name` used as relative path, so + // `name` seems to be relative to the includer: + Paths.get(includerName).resolveSibling(name).normalize().toString() + } else { + name + } + } + + headerToName[file.canonicalPath] = headerName + + if (!filter.policy.excludeUnused(headerName)) { + ownHeaders.add(file) + ownTranslationUnits += curUnit } } - headerToName[file] = headerName - if (!filter.policy.excludeUnused(headerName)) { - ownHeaders.add(file) + override fun importedASTFile(info: CXIdxImportedASTFileInfo) { + unitsHolder.load(info).also { unit -> + if (!translationUnits.contains(unit)) { + translationUnits.add(unit) + ownTranslationUnits += unit + } + } } - } - }) + }) + } if (filter.excludeDepdendentModules) { ModulesMap(compilation, translationUnit).use { modulesMap -> @@ -765,35 +800,70 @@ private fun filterHeadersByPredefined( filter: NativeLibraryHeaderFilter.Predefined, index: CXIndex, translationUnit: CXTranslationUnit, + ownTranslationUnits: MutableSet, ownHeaders: MutableSet, - allHeaders: MutableSet + allHeaders: MutableSet, + unitsHolder: UnitsHolder ) { + val translationUnits = mutableListOf(translationUnit) // Note: suboptimal but simple. - indexTranslationUnit(index, translationUnit, 0, object : Indexer { - override fun enteredMainFile(file: CXFile) { - ownHeaders += file - allHeaders += file - } - - override fun ppIncludedFile(info: CXIdxIncludedFileInfo) { - val file = info.file - allHeaders += file - if (file?.canonicalPath in filter.headers) { + var curUnitIndex = 0 + while (curUnitIndex < translationUnits.size) { + indexTranslationUnit(index, translationUnits[curUnitIndex++], 0, object : Indexer { + override fun enteredMainFile(file: CXFile) { ownHeaders += file + allHeaders += file } - } - }) + + override fun ppIncludedFile(info: CXIdxIncludedFileInfo) { + val file = info.file + allHeaders += file + if (file?.canonicalPath in filter.headers) { + ownHeaders += file + } + } + + override fun importedASTFile(info: CXIdxImportedASTFileInfo) { + unitsHolder.load(info).also { unit -> + if (!translationUnits.contains(unit)) { + translationUnits.add(unit) + + // `info.module` might point to a submodule having name of a child header, not an actual name of a framework. + // Actual module name could be found at top of the parent chain + val topParentModuleName = getTopParentModule(info)?.name + if (filter.modules.contains(topParentModuleName)) { + ownTranslationUnits += unit + } + } + } + } + + /** + * Follows parent links and returns name of the topmost parent module. + */ + private fun getTopParentModule(info: CXIdxImportedASTFileInfo): CXModule? { + var parent = info.module + var module: CXModule? + do { + module = parent + parent = clang_Module_getParent(module) + } while (parent != null) + return module + } + }) + } } fun NativeLibrary.getHeaderPaths(): NativeLibraryHeaders { - withIndex { index -> + withIndex(excludeDeclarationsFromPCH = false) { index -> val translationUnit = this.parse(index, options = CXTranslationUnit_DetailedPreprocessingRecord).ensureNoCompileErrors() try { + val (headers, _) = UnitsHolder(index).use { unitsHolder -> + getHeadersAndUnits(this, index, translationUnit, unitsHolder) + } fun getPath(file: CXFile?) = if (file == null) "" else file.canonicalPath - - val headers = getHeaders(this, index, translationUnit) return NativeLibraryHeaders( headers.ownHeaders.map(::getPath).toSet(), headers.importedHeaders.map(::getPath).toSet() @@ -837,6 +907,7 @@ internal fun getContainingFile(cursor: CValue): CXFile? { } internal val CXFile.path: String get() = clang_getFileName(this).convertAndDispose() +internal val CXModule.name: String get() = clang_Module_getName(this).convertAndDispose() // TODO: this map doesn't get cleaned up but adds quite significant performance improvement. private val canonicalPaths = ConcurrentHashMap() @@ -906,11 +977,11 @@ fun Type.canonicalIsPointerToChar(): Boolean { return unwrappedType is PointerType && unwrappedType.pointeeType.unwrapTypedefs() == CharType } -internal interface Disposable { +interface Disposable { fun dispose() } -internal inline fun T.use(block: (T) -> R): R = try { +inline fun T.use(block: (T) -> R): R = try { block(this) } finally { this.dispose() diff --git a/kotlin-native/Interop/Indexer/src/test/kotlin/org/jetbrains/kotlin/native/interop/indexer/WorkaroundTests.kt b/kotlin-native/Interop/Indexer/src/test/kotlin/org/jetbrains/kotlin/native/interop/indexer/WorkaroundTests.kt index c08084bfd48..6a31e0f5a33 100644 --- a/kotlin-native/Interop/Indexer/src/test/kotlin/org/jetbrains/kotlin/native/interop/indexer/WorkaroundTests.kt +++ b/kotlin-native/Interop/Indexer/src/test/kotlin/org/jetbrains/kotlin/native/interop/indexer/WorkaroundTests.kt @@ -33,7 +33,7 @@ class WorkaroundTests : IndexerTests() { compilerArgs = defaultCompilerArgs(language), language = language ) - withIndex { index -> + withIndex(excludeDeclarationsFromPCH = false) { index -> val translationUnit = compilation.parse( index, options = CXTranslationUnit_DetailedPreprocessingRecord, diff --git a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBuilder.kt b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBuilder.kt index c250d74e92c..166bd375a47 100644 --- a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBuilder.kt +++ b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/StubIrBuilder.kt @@ -335,7 +335,8 @@ class StubIrBuilder(private val context: StubIrContext) { nativeIndex.enums.forEach { generateStubsForEnum(it) } nativeIndex.functions.filter { it.name !in excludedFunctions }.forEach { generateStubsForFunction(it) } nativeIndex.typedefs.forEach { generateStubsForTypedef(it) } - nativeIndex.globals.filter { it.name !in excludedFunctions }.forEach { generateStubsForGlobal(it) } + // globals are sorted, so its numbering is stable and thus testable with golden data + nativeIndex.globals.filter { it.name !in excludedFunctions }.sortedBy { it.name }.forEach { generateStubsForGlobal(it) } nativeIndex.macroConstants.filter { it.name !in excludedMacros }.forEach { generateStubsForMacroConstant(it) } nativeIndex.wrappedMacros.filter { it.name !in excludedMacros }.forEach { generateStubsForWrappedMacro(it) } diff --git a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt index bb4eeb1d096..b0ad3517cd0 100644 --- a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt +++ b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt @@ -68,21 +68,36 @@ fun main(args: Array) { processCLibSafe(flavorName, arguments, InternalInteropOptions(arguments.generated, arguments.natives), runFromDaemon = false) } -fun interop( - flavor: String, args: Array, - additionalArgs: InternalInteropOptions, - runFromDaemon: Boolean -): Array? = when (flavor) { - "jvm", "native" -> { - val cinteropArguments = CInteropArguments() - cinteropArguments.argParser.parse(args) - val platform = KotlinPlatform.values().single { it.name.equals(flavor, ignoreCase = true) } - processCLibSafe(platform, cinteropArguments, additionalArgs, runFromDaemon) +class Interop { + /** + * invoked via reflection from new test system: CompilationToolCallKt.invokeCInterop(), + * `interop()` has issues to be invoked directly due to NoSuchMethodError, caused by presence of InternalInteropOptions argtype: + * java.lang.IllegalArgumentException: argument type mismatch + */ + fun interopViaReflection( + flavor: String, args: Array, + runFromDaemon: Boolean, + generated: String, natives: String, manifest: String? = null, cstubsName: String? = null + ): Array? { + val internalInteropOptions = InternalInteropOptions(generated, natives, manifest, cstubsName) + return interop(flavor, args, internalInteropOptions, runFromDaemon) } - "wasm" -> processIdlLib(args, additionalArgs) - else -> error("Unexpected flavor") -} + fun interop( + flavor: String, args: Array, + additionalArgs: InternalInteropOptions, + runFromDaemon: Boolean + ): Array? = when (flavor) { + "jvm", "native" -> { + val cinteropArguments = CInteropArguments() + cinteropArguments.argParser.parse(args) + val platform = KotlinPlatform.values().single { it.name.equals(flavor, ignoreCase = true) } + processCLibSafe(platform, cinteropArguments, additionalArgs, runFromDaemon) + } + "wasm" -> processIdlLib(args, additionalArgs) + else -> error("Unexpected flavor") + } +} // Options, whose values are space-separated and can be escaped. val escapedOptions = setOf("-compilerOpts", "-linkerOpts", "-compiler-options", "-linker-options") @@ -390,7 +405,7 @@ private fun processCLib(flavor: KotlinPlatform, cinteropArguments: CInteropArgum // Note that the output bitcode contains the source file path, which can lead to non-deterministc builds (see KT-54284). // The source file is passed in via stdin to ensure the output library is deterministic. val compilerCmd = arrayOf(compiler, *compilerArgs, - "-emit-llvm", "-x", library.language.clangLanguageName, "-c", "-", "-o", outLib.absolutePath) + "-emit-llvm", "-x", library.language.clangLanguageName, "-c", "-", "-o", outLib.absolutePath, "-Xclang", "-detailed-preprocessing-record") runCmd(compilerCmd, verbose, redirectInputFile = File(outCFile.absolutePath)) outLib.absolutePath } @@ -496,11 +511,19 @@ internal fun buildNativeLibrary( addAll(tool.getDefaultCompilerOptsForLanguage(language)) addAll(additionalCompilerOpts) addAll(getCompilerFlagsForVfsOverlay(arguments.headerFilterPrefix.toTypedArray(), def)) + add("-Wno-builtin-macro-redefined") // to suppress warning from predefinedMacrosRedefinitions(see below) + } + + // Expanding macros such as __FILE__ or __TIME__ exposes arbitrary generated filenames and timestamps from the compiler pipeline + // which are not useful for interop though makes the klib generation non-deterministic. See KT-54284 + // This macro redefinition just maps to their name in the properties available from Kotlin. + val predefinedMacrosRedefinitions = predefinedMacros.map { + "#define $it \"$it\"" } val compilation = CompilationImpl( includes = headerFiles, - additionalPreambleLines = def.defHeaderLines, + additionalPreambleLines = def.defHeaderLines + predefinedMacrosRedefinitions, compilerArgs = defaultCompilerArgs(language) + compilerOpts + tool.platformCompilerOpts, language = language ) @@ -511,6 +534,7 @@ internal fun buildNativeLibrary( val modules = def.config.modules if (modules.isEmpty()) { + require(headerFiles.isEmpty() || !compilation.compilerArgs.contains("-fmodules")) { "cinterop doesn't support having headers in -fmodules mode" } val excludeDependentModules = def.config.excludeDependentModules val headerFilterGlobs = def.config.headerFilter @@ -526,7 +550,7 @@ internal fun buildNativeLibrary( val modulesInfo = getModulesInfo(compilation, modules) - headerFilter = NativeLibraryHeaderFilter.Predefined(modulesInfo.ownHeaders) + headerFilter = NativeLibraryHeaderFilter.Predefined(modulesInfo.ownHeaders, modulesInfo.modules) includes = modulesInfo.topLevelHeaders } diff --git a/kotlin-native/Interop/StubGenerator/src/test/kotlin/org/jetbrains/kotlin/native/interop/gen/InteropTestsBase.kt b/kotlin-native/Interop/StubGenerator/src/test/kotlin/org/jetbrains/kotlin/native/interop/gen/InteropTestsBase.kt index 4f5392c7ed3..ee37dded10c 100644 --- a/kotlin-native/Interop/StubGenerator/src/test/kotlin/org/jetbrains/kotlin/native/interop/gen/InteropTestsBase.kt +++ b/kotlin-native/Interop/StubGenerator/src/test/kotlin/org/jetbrains/kotlin/native/interop/gen/InteropTestsBase.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.native.interop.gen.jvm.KotlinPlatform import org.jetbrains.kotlin.native.interop.gen.jvm.buildNativeLibrary import org.jetbrains.kotlin.native.interop.gen.jvm.prepareTool import org.jetbrains.kotlin.native.interop.indexer.NativeLibrary -import org.jetbrains.kotlin.native.interop.indexer.getHeaderPaths import org.jetbrains.kotlin.native.interop.tool.CInteropArguments import kotlin.test.* import java.io.File diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 7c697525d94..117c6bbe20f 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -4315,6 +4315,11 @@ createInterop("kt54284") { it.defFile 'interop/kt54284/kt54284.def' } +createInterop("kt54284_fmodules") { + it.defFile 'interop/kt54284/kt54284.def' + it.extraOpts '-compiler-option', '-fmodules' +} + createInterop("kt43502") { it.defFile 'interop/kt43502/kt43502.def' it.headers "$projectDir/interop/kt43502/kt43502.h" @@ -4795,6 +4800,12 @@ interopTest("interop_kt54284") { source = "interop/kt54284/main.kt" } +interopTest("interop_kt54284_fmodules") { + disabled = (project.testTarget == 'wasm32') // No interop for wasm yet. + interop = 'kt54284_fmodules' + source = "interop/kt54284/main.kt" +} + // TODO: This test should be run with caches on. interopTest("interop_kt51925") { disabled = (project.testTarget == 'wasm32') // No interop for wasm yet. diff --git a/kotlin-native/backend.native/tests/interop/kt54284/main.kt b/kotlin-native/backend.native/tests/interop/kt54284/main.kt index b6ba650860b..9fca500b2af 100644 --- a/kotlin-native/backend.native/tests/interop/kt54284/main.kt +++ b/kotlin-native/backend.native/tests/interop/kt54284/main.kt @@ -3,10 +3,10 @@ import kt54284.* import kotlin.test.* fun main() { - assertEquals(KFILE, "FILE:__FILE__") - assertEquals(KLINE, "LINE:__LINE__") - assertEquals(KTIME, "TIME:__TIME__") - assertEquals(KDATE, "DATE:__DATE__") - assertEquals(KFILENAME, "NAME:__FILE_NAME__") - assertEquals(KBASEFILE, "BASE:__BASE_FILE__") + assertEquals("FILE:__FILE__", KFILE) + assertEquals("LINE:__LINE__", KLINE) + assertEquals("TIME:__TIME__", KTIME) + assertEquals("DATE:__DATE__", KDATE) + assertEquals("NAME:__FILE_NAME__", KFILENAME) + assertEquals("BASE:__BASE_FILE__", KBASEFILE) } diff --git a/kotlin-native/utilities/cli-runner/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/InteropCompiler.kt b/kotlin-native/utilities/cli-runner/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/InteropCompiler.kt index dcf23ea7506..5853b1bd6f5 100644 --- a/kotlin-native/utilities/cli-runner/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/InteropCompiler.kt +++ b/kotlin-native/utilities/cli-runner/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/InteropCompiler.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.konan.file.File import org.jetbrains.kotlin.konan.target.PlatformManager import org.jetbrains.kotlin.konan.util.KonanHomeProvider import org.jetbrains.kotlin.native.interop.gen.jvm.InternalInteropOptions -import org.jetbrains.kotlin.native.interop.gen.jvm.interop +import org.jetbrains.kotlin.native.interop.gen.jvm.Interop import org.jetbrains.kotlin.native.interop.tool.* // TODO: this function should eventually be eliminated from 'utilities'. @@ -42,7 +42,7 @@ fun invokeInterop(flavor: String, args: Array, runFromDaemon: Boolean): else (arguments as JSInteropArguments).target.toString() val target = PlatformManager(KonanHomeProvider.determineKonanHome()).targetManager(targetRequest).target - val cinteropArgsToCompiler = interop(flavor, args, + val cinteropArgsToCompiler = Interop().interop(flavor, args, InternalInteropOptions(generatedDir.absolutePath, nativesDir.absolutePath,manifest.path, cstubsName.takeIf { flavor == "native" } diff --git a/native/native.tests/README.md b/native/native.tests/README.md index 8be55ac916c..7cd53dea316 100644 --- a/native/native.tests/README.md +++ b/native/native.tests/README.md @@ -1,5 +1,22 @@ ## Running tests -For tests, use `./gradlew :native:native.tests:codegenBoxTest` and `./gradlew :kotlin-native:backend.native:tests:run`. +* To run all tests, use `./gradlew :native:native.tests:test`. Please note, this Gradle task is available only in development environment and it not available at CI server. +* To execute certain tests only, use the appropriate Gradle tasks. Example: `./gradlew :native:native.tests:codegenBoxTest` +* To execute InteropIndexer tests for all targets, use: +```bash +for TARGET in android_x64 android_x86 android_arm32 android_arm64 \ + ios_arm32 ios_arm64 ios_x64 ios_simulator_arm64 \ + linux_x64 linux_arm64 linux_arm32_hfp linux_mips32 linux_mipsel32 \ + macos_x64 macos_arm64 \ + mingw_x86 mingw_x64 \ + tvos_arm64 tvos_x64 tvos_simulator_arm64 \ + wasm32 \ + watchos_arm32 watchos_arm64 watchos_x86 watchos_x64 watchos_simulator_arm64 watchos_device_arm64 +do + echo $TARGET + ./gradlew :native:native.tests:interopIndexerTest -Pkotlin.internal.native.test.target=$TARGET +done +``` +* To re-generate tests, use `./gradlew :native:native.tests:generateTests` For more details see [Testing](../../kotlin-native/HACKING.md#Testing). diff --git a/native/native.tests/build.gradle.kts b/native/native.tests/build.gradle.kts index ffa1f7b1956..9384084e636 100644 --- a/native/native.tests/build.gradle.kts +++ b/native/native.tests/build.gradle.kts @@ -48,6 +48,7 @@ val stdlibTest = nativeTest("stdlibTest", "stdlib") val kotlinTestLibraryTest = nativeTest("kotlinTestLibraryTest", "kotlin-test") val klibAbiTest = nativeTest("klibAbiTest", "klib-abi") val klibBinaryCompatibilityTest = nativeTest("klibBinaryCompatibilityTest", "klib-binary-compatibility") +val cinteropTest = nativeTest("cinteropTest", "cinterop") // "test" task is created by convention. We can't just remove it. Let's enable it in developer's environment, so it can be used // to run any test from IDE or from console, but disable it at TeamCity where it is not supposed to be ever used. diff --git a/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod1.contents.gold.txt b/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod1.contents.gold.txt new file mode 100644 index 00000000000..27dc8d617e1 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod1.contents.gold.txt @@ -0,0 +1,4 @@ + @ExternalObjCClass open class Pod1 : NSObject { + @ExternalObjCClass open class Pod1Meta : NSObjectMeta { + var pod1VersionNumber: Double + val pod1VersionString: CArrayPointer */> /* = CPointer */> */ \ No newline at end of file diff --git a/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod1.def b/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod1.def new file mode 100644 index 00000000000..4316a3425b9 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = pod1 diff --git a/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod2.contents.gold.txt b/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod2.contents.gold.txt new file mode 100644 index 00000000000..43b23a6882a --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod2.contents.gold.txt @@ -0,0 +1,4 @@ + @ExternalObjCClass(binaryName = "_TtC4pod24Pod2") open class Pod2 : Pod1 { + @ExternalObjCClass(binaryName = "_TtC4pod24Pod2") open class Pod2Meta : Pod1Meta { + var pod2VersionNumber: Double + val pod2VersionString: CArrayPointer */> /* = CPointer */> */ \ No newline at end of file diff --git a/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod2.def b/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod2.def new file mode 100644 index 00000000000..66ffdd3bbf3 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/pod2.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = pod2 diff --git a/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod1.contents.gold.txt b/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod1.contents.gold.txt new file mode 100644 index 00000000000..55c97cc8cfc --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod1.contents.gold.txt @@ -0,0 +1,4 @@ + const val POD1MACRO: Int = 42 + var intPOD1: Int + @CCall(id = "knifunptr_pod10_intPOD1_getter") get + @CCall(id = "knifunptr_pod11_intPOD1_setter") set \ No newline at end of file diff --git a/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod1.def b/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod1.def new file mode 100644 index 00000000000..55af66e9ea1 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = interpod1 diff --git a/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod2.contents.gold.txt b/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod2.contents.gold.txt new file mode 100644 index 00000000000..75c51933dea --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod2.contents.gold.txt @@ -0,0 +1,4 @@ + const val POD2POD1MACRO: Int = 42 + var pointerIntPOD1: CPointer */>? + @CCall(id = "knifunptr_pod20_pointerIntPOD1_getter") get + @CCall(id = "knifunptr_pod21_pointerIntPOD1_setter") set \ No newline at end of file diff --git a/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod2.def b/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod2.def new file mode 100644 index 00000000000..6eba0ca9b71 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/pod2.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = interpod2 diff --git a/native/native.tests/testData/CInterop/KT-39120/interpod1.framework/Headers/interpod1.h b/native/native.tests/testData/CInterop/KT-39120/interpod1.framework/Headers/interpod1.h new file mode 100644 index 00000000000..9add547a7b6 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/interpod1.framework/Headers/interpod1.h @@ -0,0 +1,3 @@ +int intPOD1; + +#define POD1MACRO 42 diff --git a/native/native.tests/testData/CInterop/KT-39120/interpod1.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/KT-39120/interpod1.framework/Modules/module.modulemap new file mode 100644 index 00000000000..b0943f846de --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/interpod1.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module interpod1 { + umbrella header "interpod1.h" + + export * + module * { export * } +} diff --git a/native/native.tests/testData/CInterop/KT-39120/interpod2.framework/Headers/interpod2.h b/native/native.tests/testData/CInterop/KT-39120/interpod2.framework/Headers/interpod2.h new file mode 100644 index 00000000000..578e9d335c6 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/interpod2.framework/Headers/interpod2.h @@ -0,0 +1,4 @@ +#include "interpod1/interpod1.h" + +int* pointerIntPOD1 = &intPOD1; +#define POD2POD1MACRO POD1MACRO diff --git a/native/native.tests/testData/CInterop/KT-39120/interpod2.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/KT-39120/interpod2.framework/Modules/module.modulemap new file mode 100644 index 00000000000..3427ab9563d --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/interpod2.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module interpod2 { + umbrella header "interpod2.h" + + export * + module * { export * } +} diff --git a/native/native.tests/testData/CInterop/KT-39120/pod1.framework/Headers/pod1-umbrella.h b/native/native.tests/testData/CInterop/KT-39120/pod1.framework/Headers/pod1-umbrella.h new file mode 100644 index 00000000000..c8710ebdb5f --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/pod1.framework/Headers/pod1-umbrella.h @@ -0,0 +1,16 @@ +#ifdef __OBJC__ +#import +#else +#ifndef FOUNDATION_EXPORT +#if defined(__cplusplus) +#define FOUNDATION_EXPORT extern "C" +#else +#define FOUNDATION_EXPORT extern +#endif +#endif +#endif + +#import "pod1.h" + +FOUNDATION_EXPORT double pod1VersionNumber; +FOUNDATION_EXPORT const unsigned char pod1VersionString[]; diff --git a/native/native.tests/testData/CInterop/KT-39120/pod1.framework/Headers/pod1.h b/native/native.tests/testData/CInterop/KT-39120/pod1.framework/Headers/pod1.h new file mode 100644 index 00000000000..23dd1944231 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/pod1.framework/Headers/pod1.h @@ -0,0 +1,3 @@ +@interface Pod1 : NSObject +-(int)pod1; +@end diff --git a/native/native.tests/testData/CInterop/KT-39120/pod1.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/KT-39120/pod1.framework/Modules/module.modulemap new file mode 100644 index 00000000000..7d038af90cf --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/pod1.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module pod1 { + umbrella header "pod1-umbrella.h" + + export * + module * { export * } +} diff --git a/native/native.tests/testData/CInterop/KT-39120/pod2.framework/Headers/pod2-Swift.h b/native/native.tests/testData/CInterop/KT-39120/pod2.framework/Headers/pod2-Swift.h new file mode 100644 index 00000000000..4fcc9b46816 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/pod2.framework/Headers/pod2-Swift.h @@ -0,0 +1,220 @@ +#ifndef __POD2_SWIFT_H__ +#define __POD2_SWIFT_H__ +// Generated by Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wgcc-compat" + +#if !defined(__has_include) +# define __has_include(x) 0 +#endif +#if !defined(__has_attribute) +# define __has_attribute(x) 0 +#endif +#if !defined(__has_feature) +# define __has_feature(x) 0 +#endif +#if !defined(__has_warning) +# define __has_warning(x) 0 +#endif + +#if __has_include() +# include +#endif + +#pragma clang diagnostic ignored "-Wauto-import" +#include +#include +#include +#include + +#if !defined(SWIFT_TYPEDEFS) +# define SWIFT_TYPEDEFS 1 +# if __has_include() +# include +# elif !defined(__cplusplus) +typedef uint_least16_t char16_t; +typedef uint_least32_t char32_t; +# endif +typedef float swift_float2 __attribute__((__ext_vector_type__(2))); +typedef float swift_float33 __attribute__((__ext_vector_type__(3))); +typedef float swift_float4 __attribute__((__ext_vector_type__(4))); +typedef double swift_double2 __attribute__((__ext_vector_type__(2))); +typedef double swift_double3 __attribute__((__ext_vector_type__(3))); +typedef double swift_double4 __attribute__((__ext_vector_type__(4))); +typedef int swift_int2 __attribute__((__ext_vector_type__(2))); +typedef int swift_int3 __attribute__((__ext_vector_type__(3))); +typedef int swift_int4 __attribute__((__ext_vector_type__(4))); +typedef unsigned int swift_uint2 __attribute__((__ext_vector_type__(2))); +typedef unsigned int swift_uint3 __attribute__((__ext_vector_type__(3))); +typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4))); +#endif + +#if !defined(SWIFT_PASTE) +# define SWIFT_PASTE_HELPER(x, y) x##y +# define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y) +#endif +#if !defined(SWIFT_METATYPE) +# define SWIFT_METATYPE(X) Class +#endif +#if !defined(SWIFT_CLASS_PROPERTY) +# if __has_feature(objc_class_property) +# define SWIFT_CLASS_PROPERTY(...) __VA_ARGS__ +# else +# define SWIFT_CLASS_PROPERTY(...) +# endif +#endif + +#if __has_attribute(objc_runtime_name) +# define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X))) +#else +# define SWIFT_RUNTIME_NAME(X) +#endif +#if __has_attribute(swift_name) +# define SWIFT_COMPILE_NAME(X) __attribute__((swift_name(X))) +#else +# define SWIFT_COMPILE_NAME(X) +#endif +#if __has_attribute(objc_method_family) +# define SWIFT_METHOD_FAMILY(X) __attribute__((objc_method_family(X))) +#else +# define SWIFT_METHOD_FAMILY(X) +#endif +#if __has_attribute(noescape) +# define SWIFT_NOESCAPE __attribute__((noescape)) +#else +# define SWIFT_NOESCAPE +#endif +#if __has_attribute(ns_consumed) +# define SWIFT_RELEASES_ARGUMENT __attribute__((ns_consumed)) +#else +# define SWIFT_RELEASES_ARGUMENT +#endif +#if __has_attribute(warn_unused_result) +# define SWIFT_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#else +# define SWIFT_WARN_UNUSED_RESULT +#endif +#if __has_attribute(noreturn) +# define SWIFT_NORETURN __attribute__((noreturn)) +#else +# define SWIFT_NORETURN +#endif +#if !defined(SWIFT_CLASS_EXTRA) +# define SWIFT_CLASS_EXTRA +#endif +#if !defined(SWIFT_PROTOCOL_EXTRA) +# define SWIFT_PROTOCOL_EXTRA +#endif +#if !defined(SWIFT_ENUM_EXTRA) +# define SWIFT_ENUM_EXTRA +#endif +#if !defined(SWIFT_CLASS) +# if __has_attribute(objc_subclassing_restricted) +# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA +# define SWIFT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA +# else +# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA +# define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA +# endif +#endif +#if !defined(SWIFT_RESILIENT_CLASS) +# if __has_attribute(objc_class_stub) +# define SWIFT_RESILIENT_CLASS(SWIFT_NAME) SWIFT_CLASS(SWIFT_NAME) __attribute__((objc_class_stub)) +# define SWIFT_RESILIENT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_class_stub)) SWIFT_CLASS_NAMED(SWIFT_NAME) +# else +# define SWIFT_RESILIENT_CLASS(SWIFT_NAME) SWIFT_CLASS(SWIFT_NAME) +# define SWIFT_RESILIENT_CLASS_NAMED(SWIFT_NAME) SWIFT_CLASS_NAMED(SWIFT_NAME) +# endif +#endif + +#if !defined(SWIFT_PROTOCOL) +# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA +# define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA +#endif + +#if !defined(SWIFT_EXTENSION) +# define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__) +#endif + +#if !defined(OBJC_DESIGNATED_INITIALIZER) +# if __has_attribute(objc_designated_initializer) +# define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer)) +# else +# define OBJC_DESIGNATED_INITIALIZER +# endif +#endif +#if !defined(SWIFT_ENUM_ATTR) +# if defined(__has_attribute) && __has_attribute(enum_extensibility) +# define SWIFT_ENUM_ATTR(_extensibility) __attribute__((enum_extensibility(_extensibility))) +# else +# define SWIFT_ENUM_ATTR(_extensibility) +# endif +#endif +#if !defined(SWIFT_ENUM) +# define SWIFT_ENUM(_type, _name, _extensibility) enum _name : _type _name; enum SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA _name : _type +# if __has_feature(generalized_swift_name) +# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, _extensibility) enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); enum SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA _name : _type +# else +# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, _extensibility) SWIFT_ENUM(_type, _name, _extensibility) +# endif +#endif +#if !defined(SWIFT_UNAVAILABLE) +# define SWIFT_UNAVAILABLE __attribute__((unavailable)) +#endif +#if !defined(SWIFT_UNAVAILABLE_MSG) +# define SWIFT_UNAVAILABLE_MSG(msg) __attribute__((unavailable(msg))) +#endif +#if !defined(SWIFT_AVAILABILITY) +# define SWIFT_AVAILABILITY(plat, ...) __attribute__((availability(plat, __VA_ARGS__))) +#endif +#if !defined(SWIFT_WEAK_IMPORT) +# define SWIFT_WEAK_IMPORT __attribute__((weak_import)) +#endif +#if !defined(SWIFT_DEPRECATED) +# define SWIFT_DEPRECATED __attribute__((deprecated)) +#endif +#if !defined(SWIFT_DEPRECATED_MSG) +# define SWIFT_DEPRECATED_MSG(...) __attribute__((deprecated(__VA_ARGS__))) +#endif +#if __has_feature(attribute_diagnose_if_objc) +# define SWIFT_DEPRECATED_OBJC(Msg) __attribute__((diagnose_if(1, Msg, "warning"))) +#else +# define SWIFT_DEPRECATED_OBJC(Msg) SWIFT_DEPRECATED_MSG(Msg) +#endif +#if !defined(IBSegueAction) +# define IBSegueAction +#endif +#if __has_feature(modules) +#if __has_warning("-Watimport-in-framework-header") +#pragma clang diagnostic ignored "-Watimport-in-framework-header" +#endif +@import pod1; +#endif + +#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch" +#pragma clang diagnostic ignored "-Wduplicate-method-arg" +#if __has_warning("-Wpragma-clang-attribute") +# pragma clang diagnostic ignored "-Wpragma-clang-attribute" +#endif +#pragma clang diagnostic ignored "-Wunknown-pragmas" +#pragma clang diagnostic ignored "-Wnullability" + +#if __has_attribute(external_source_symbol) +# pragma push_macro("any") +# undef any +# pragma clang attribute push(__attribute__((external_source_symbol(language="Swift", defined_in="pod2",generated_declaration))), apply_to=any(function,enum,objc_interface,objc_category,objc_protocol)) +# pragma pop_macro("any") +#endif + + +SWIFT_CLASS("_TtC4pod24Pod2") +@interface Pod2 : Pod1 +- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; +@end + +#if __has_attribute(external_source_symbol) +# pragma clang attribute pop +#endif +#pragma clang diagnostic pop + +#endif \ No newline at end of file diff --git a/native/native.tests/testData/CInterop/KT-39120/pod2.framework/Headers/pod2-umbrella.h b/native/native.tests/testData/CInterop/KT-39120/pod2.framework/Headers/pod2-umbrella.h new file mode 100644 index 00000000000..43ca1ad8e12 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/pod2.framework/Headers/pod2-umbrella.h @@ -0,0 +1,16 @@ +#ifdef __OBJC__ +#import +#else +#ifndef FOUNDATION_EXPORT +#if defined(__cplusplus) +#define FOUNDATION_EXPORT extern "C" +#else +#define FOUNDATION_EXPORT extern +#endif +#endif +#endif + + +FOUNDATION_EXPORT double pod2VersionNumber; +FOUNDATION_EXPORT const unsigned char pod2VersionString[]; + diff --git a/native/native.tests/testData/CInterop/KT-39120/pod2.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/KT-39120/pod2.framework/Modules/module.modulemap new file mode 100644 index 00000000000..c18faaca138 --- /dev/null +++ b/native/native.tests/testData/CInterop/KT-39120/pod2.framework/Modules/module.modulemap @@ -0,0 +1,11 @@ +framework module pod2 { + umbrella header "pod2-umbrella.h" + + export * + module * { export * } +} + +module pod2.Swift { + header "pod2-Swift.h" + requires objc +} diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.ARM32.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.ARM32.txt new file mode 100644 index 00000000000..33557bb7d6e --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.ARM32.txt @@ -0,0 +1,21 @@ + +package pod1 { + + @CStruct(spelling = "struct { void* __ap; }") class __va_list constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var __ap: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + @CStruct.VarType(align = 4, size = 4.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + val A_va_list: __builtin_va_list /* = __va_list */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + typealias __builtin_va_list = __va_list +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.ARM64.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.ARM64.txt new file mode 100644 index 00000000000..6fc0317ac44 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.ARM64.txt @@ -0,0 +1,33 @@ + +package pod1 { + + @CStruct(spelling = "struct { void* __stack; void* __gr_top; void* __vr_top; int __gr_offs; int __vr_offs; }") class __va_list constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var __gr_offs: Int + @CStruct.MemberAt(offset = 24.toLong()) get + @CStruct.MemberAt(offset = 24.toLong()) set + var __gr_top: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 8.toLong()) get + @CStruct.MemberAt(offset = 8.toLong()) set + var __stack: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + var __vr_offs: Int + @CStruct.MemberAt(offset = 28.toLong()) get + @CStruct.MemberAt(offset = 28.toLong()) set + var __vr_top: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 16.toLong()) get + @CStruct.MemberAt(offset = 16.toLong()) set + @CStruct.VarType(align = 8, size = 32.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + val A_va_list: __builtin_va_list /* = __va_list */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + typealias __builtin_va_list = __va_list +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.COpaquePointer.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.COpaquePointer.txt new file mode 100644 index 00000000000..18821b3307d --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.COpaquePointer.txt @@ -0,0 +1,12 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + var A_va_list: __builtin_va_list? /* = CPointer? */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + @CCall(id = "knifunptr_pod13_A_va_list_setter") set + typealias __builtin_va_list = COpaquePointer + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.CPointerByteVar.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.CPointerByteVar.txt new file mode 100644 index 00000000000..69e79edebaa --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.CPointerByteVar.txt @@ -0,0 +1,12 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + var A_va_list: __builtin_va_list? /* = CPointer */>? */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + @CCall(id = "knifunptr_pod13_A_va_list_setter") set + typealias __builtin_va_list = CPointer */> + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer */> */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.X64.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.X64.txt new file mode 100644 index 00000000000..cf8e15e3aa1 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/contents.gold.X64.txt @@ -0,0 +1,31 @@ + +package pod1 { + + @CStruct(spelling = "struct { unsigned int gp_offset; unsigned int fp_offset; void* overflow_arg_area; void* reg_save_area; }") class __va_list_tag constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var fp_offset: UInt + @CStruct.MemberAt(offset = 4.toLong()) get + @CStruct.MemberAt(offset = 4.toLong()) set + var gp_offset: UInt + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + var overflow_arg_area: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 8.toLong()) get + @CStruct.MemberAt(offset = 8.toLong()) set + var reg_save_area: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 16.toLong()) get + @CStruct.MemberAt(offset = 16.toLong()) set + @CStruct.VarType(align = 8, size = 24.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + val A_va_list: __builtin_va_list /* = CPointer<__va_list_tag> */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + typealias __builtin_va_list = CArrayPointer<__va_list_tag> + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer<__va_list_tag> */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/pod1.def b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/pod1.def new file mode 100644 index 00000000000..09b9382ef10 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/pod1.def @@ -0,0 +1,3 @@ +language = C +headers = A.h +headerFilter = A.h diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.ARM32.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.ARM32.txt new file mode 100644 index 00000000000..9e296405ae7 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.ARM32.txt @@ -0,0 +1,19 @@ + +package pod1 { + + @CStruct(spelling = "struct { void* __ap; }") class __va_list constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var __ap: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + @CStruct.VarType(align = 4, size = 4.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = __va_list + typealias __gnuc_va_list = __builtin_va_list + typealias va_list = __builtin_va_list +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.ARM64.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.ARM64.txt new file mode 100644 index 00000000000..1afa4d509b4 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.ARM64.txt @@ -0,0 +1,31 @@ + +package pod1 { + + @CStruct(spelling = "struct { void* __stack; void* __gr_top; void* __vr_top; int __gr_offs; int __vr_offs; }") class __va_list constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var __gr_offs: Int + @CStruct.MemberAt(offset = 24.toLong()) get + @CStruct.MemberAt(offset = 24.toLong()) set + var __gr_top: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 8.toLong()) get + @CStruct.MemberAt(offset = 8.toLong()) set + var __stack: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + var __vr_offs: Int + @CStruct.MemberAt(offset = 28.toLong()) get + @CStruct.MemberAt(offset = 28.toLong()) set + var __vr_top: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 16.toLong()) get + @CStruct.MemberAt(offset = 16.toLong()) set + @CStruct.VarType(align = 8, size = 32.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = __va_list + typealias __gnuc_va_list = __builtin_va_list + typealias va_list = __builtin_va_list +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.COpaquePointer.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.COpaquePointer.txt new file mode 100644 index 00000000000..1cfffe871d4 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.COpaquePointer.txt @@ -0,0 +1,11 @@ + +package pod1 { + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = COpaquePointer + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer */> + typealias __gnuc_va_list = __builtin_va_list + typealias __gnuc_va_listVar = CPointerVarOf<__gnuc_va_list /* = CPointer */> + typealias va_list = __builtin_va_list + typealias va_listVar = CPointerVarOf */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.CPointerByteVar.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.CPointerByteVar.txt new file mode 100644 index 00000000000..9edbfa3a3e9 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.CPointerByteVar.txt @@ -0,0 +1,11 @@ + +package pod1 { + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = CPointer */> + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer */> */> + typealias __gnuc_va_list = __builtin_va_list + typealias __gnuc_va_listVar = CPointerVarOf<__gnuc_va_list /* = CPointer */> */> + typealias va_list = __builtin_va_list + typealias va_listVar = CPointerVarOf */> */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.X64.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.X64.txt new file mode 100644 index 00000000000..1f6dea14f25 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/contents.gold.X64.txt @@ -0,0 +1,31 @@ + +package pod1 { + + @CStruct(spelling = "struct { unsigned int gp_offset; unsigned int fp_offset; void* overflow_arg_area; void* reg_save_area; }") class __va_list_tag constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var fp_offset: UInt + @CStruct.MemberAt(offset = 4.toLong()) get + @CStruct.MemberAt(offset = 4.toLong()) set + var gp_offset: UInt + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + var overflow_arg_area: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 8.toLong()) get + @CStruct.MemberAt(offset = 8.toLong()) set + var reg_save_area: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 16.toLong()) get + @CStruct.MemberAt(offset = 16.toLong()) set + @CStruct.VarType(align = 8, size = 24.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = CArrayPointer<__va_list_tag> + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer<__va_list_tag> */> + typealias __gnuc_va_list = __builtin_va_list + typealias __gnuc_va_listVar = CPointerVarOf<__gnuc_va_list /* = CPointer<__va_list_tag> */> + typealias va_list = __builtin_va_list + typealias va_listVar = CPointerVarOf */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/pod1.def b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/pod1.def new file mode 100644 index 00000000000..a7a40a92d7d --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/pod1.def @@ -0,0 +1,3 @@ +language = C +headers = stdarg.h +headerFilter = stdarg.h diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.ARM32.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.ARM32.txt new file mode 100644 index 00000000000..3612d3a9a70 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.ARM32.txt @@ -0,0 +1,24 @@ + +package pod1 { + + @CStruct(spelling = "struct { void* __ap; }") class __va_list constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var __ap: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + @CStruct.VarType(align = 4, size = 4.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + val A_va_list: __builtin_va_list /* = __va_list */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = __va_list + typealias __gnuc_va_list = __builtin_va_list + typealias va_list = __builtin_va_list +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.ARM64.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.ARM64.txt new file mode 100644 index 00000000000..ff199d6b6a4 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.ARM64.txt @@ -0,0 +1,36 @@ + +package pod1 { + + @CStruct(spelling = "struct { void* __stack; void* __gr_top; void* __vr_top; int __gr_offs; int __vr_offs; }") class __va_list constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var __gr_offs: Int + @CStruct.MemberAt(offset = 24.toLong()) get + @CStruct.MemberAt(offset = 24.toLong()) set + var __gr_top: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 8.toLong()) get + @CStruct.MemberAt(offset = 8.toLong()) set + var __stack: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + var __vr_offs: Int + @CStruct.MemberAt(offset = 28.toLong()) get + @CStruct.MemberAt(offset = 28.toLong()) set + var __vr_top: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 16.toLong()) get + @CStruct.MemberAt(offset = 16.toLong()) set + @CStruct.VarType(align = 8, size = 32.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + val A_va_list: __builtin_va_list /* = __va_list */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = __va_list + typealias __gnuc_va_list = __builtin_va_list + typealias va_list = __builtin_va_list +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.COpaquePointer.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.COpaquePointer.txt new file mode 100644 index 00000000000..284cc65815e --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.COpaquePointer.txt @@ -0,0 +1,17 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + var A_va_list: __builtin_va_list? /* = CPointer? */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + @CCall(id = "knifunptr_pod13_A_va_list_setter") set + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = COpaquePointer + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer */> + typealias __gnuc_va_list = __builtin_va_list + typealias __gnuc_va_listVar = CPointerVarOf<__gnuc_va_list /* = CPointer */> + typealias va_list = __builtin_va_list + typealias va_listVar = CPointerVarOf */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.CPointerByteVar.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.CPointerByteVar.txt new file mode 100644 index 00000000000..a38cac7ee1c --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.CPointerByteVar.txt @@ -0,0 +1,17 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + var A_va_list: __builtin_va_list? /* = CPointer */>? */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + @CCall(id = "knifunptr_pod13_A_va_list_setter") set + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = CPointer */> + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer */> */> + typealias __gnuc_va_list = __builtin_va_list + typealias __gnuc_va_listVar = CPointerVarOf<__gnuc_va_list /* = CPointer */> */> + typealias va_list = __builtin_va_list + typealias va_listVar = CPointerVarOf */> */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.X64.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.X64.txt new file mode 100644 index 00000000000..1980b8b7100 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/contents.gold.X64.txt @@ -0,0 +1,36 @@ + +package pod1 { + + @CStruct(spelling = "struct { unsigned int gp_offset; unsigned int fp_offset; void* overflow_arg_area; void* reg_save_area; }") class __va_list_tag constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var fp_offset: UInt + @CStruct.MemberAt(offset = 4.toLong()) get + @CStruct.MemberAt(offset = 4.toLong()) set + var gp_offset: UInt + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + var overflow_arg_area: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 8.toLong()) get + @CStruct.MemberAt(offset = 8.toLong()) set + var reg_save_area: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 16.toLong()) get + @CStruct.MemberAt(offset = 16.toLong()) set + @CStruct.VarType(align = 8, size = 24.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + val A_va_list: __builtin_va_list /* = CPointer<__va_list_tag> */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = CArrayPointer<__va_list_tag> + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer<__va_list_tag> */> + typealias __gnuc_va_list = __builtin_va_list + typealias __gnuc_va_listVar = CPointerVarOf<__gnuc_va_list /* = CPointer<__va_list_tag> */> + typealias va_list = __builtin_va_list + typealias va_listVar = CPointerVarOf */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/pod1.def b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/pod1.def new file mode 100644 index 00000000000..75ca1c1dddd --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/pod1.def @@ -0,0 +1,2 @@ +language = C +headers = A.h diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.ARM32.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.ARM32.txt new file mode 100644 index 00000000000..9e296405ae7 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.ARM32.txt @@ -0,0 +1,19 @@ + +package pod1 { + + @CStruct(spelling = "struct { void* __ap; }") class __va_list constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var __ap: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + @CStruct.VarType(align = 4, size = 4.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = __va_list + typealias __gnuc_va_list = __builtin_va_list + typealias va_list = __builtin_va_list +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.ARM64.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.ARM64.txt new file mode 100644 index 00000000000..1afa4d509b4 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.ARM64.txt @@ -0,0 +1,31 @@ + +package pod1 { + + @CStruct(spelling = "struct { void* __stack; void* __gr_top; void* __vr_top; int __gr_offs; int __vr_offs; }") class __va_list constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var __gr_offs: Int + @CStruct.MemberAt(offset = 24.toLong()) get + @CStruct.MemberAt(offset = 24.toLong()) set + var __gr_top: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 8.toLong()) get + @CStruct.MemberAt(offset = 8.toLong()) set + var __stack: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + var __vr_offs: Int + @CStruct.MemberAt(offset = 28.toLong()) get + @CStruct.MemberAt(offset = 28.toLong()) set + var __vr_top: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 16.toLong()) get + @CStruct.MemberAt(offset = 16.toLong()) set + @CStruct.VarType(align = 8, size = 32.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = __va_list + typealias __gnuc_va_list = __builtin_va_list + typealias va_list = __builtin_va_list +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.COpaquePointer.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.COpaquePointer.txt new file mode 100644 index 00000000000..1cfffe871d4 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.COpaquePointer.txt @@ -0,0 +1,11 @@ + +package pod1 { + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = COpaquePointer + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer */> + typealias __gnuc_va_list = __builtin_va_list + typealias __gnuc_va_listVar = CPointerVarOf<__gnuc_va_list /* = CPointer */> + typealias va_list = __builtin_va_list + typealias va_listVar = CPointerVarOf */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.CPointerByteVar.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.CPointerByteVar.txt new file mode 100644 index 00000000000..9edbfa3a3e9 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.CPointerByteVar.txt @@ -0,0 +1,11 @@ + +package pod1 { + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = CPointer */> + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer */> */> + typealias __gnuc_va_list = __builtin_va_list + typealias __gnuc_va_listVar = CPointerVarOf<__gnuc_va_list /* = CPointer */> */> + typealias va_list = __builtin_va_list + typealias va_listVar = CPointerVarOf */> */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.X64.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.X64.txt new file mode 100644 index 00000000000..1f6dea14f25 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/contents.gold.X64.txt @@ -0,0 +1,31 @@ + +package pod1 { + + @CStruct(spelling = "struct { unsigned int gp_offset; unsigned int fp_offset; void* overflow_arg_area; void* reg_save_area; }") class __va_list_tag constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var fp_offset: UInt + @CStruct.MemberAt(offset = 4.toLong()) get + @CStruct.MemberAt(offset = 4.toLong()) set + var gp_offset: UInt + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + var overflow_arg_area: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 8.toLong()) get + @CStruct.MemberAt(offset = 8.toLong()) set + var reg_save_area: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 16.toLong()) get + @CStruct.MemberAt(offset = 16.toLong()) set + @CStruct.VarType(align = 8, size = 24.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + const val __GNUC_VA_LIST: Int = 1 + typealias __builtin_va_list = CArrayPointer<__va_list_tag> + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer<__va_list_tag> */> + typealias __gnuc_va_list = __builtin_va_list + typealias __gnuc_va_listVar = CPointerVarOf<__gnuc_va_list /* = CPointer<__va_list_tag> */> + typealias va_list = __builtin_va_list + typealias va_listVar = CPointerVarOf */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/pod1.def b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/pod1.def new file mode 100644 index 00000000000..fe666f54eb0 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/pod1.def @@ -0,0 +1,2 @@ +language = C +headers = stdarg.h diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.ARM32.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.ARM32.txt new file mode 100644 index 00000000000..33557bb7d6e --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.ARM32.txt @@ -0,0 +1,21 @@ + +package pod1 { + + @CStruct(spelling = "struct { void* __ap; }") class __va_list constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var __ap: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + @CStruct.VarType(align = 4, size = 4.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + val A_va_list: __builtin_va_list /* = __va_list */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + typealias __builtin_va_list = __va_list +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.ARM64.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.ARM64.txt new file mode 100644 index 00000000000..6fc0317ac44 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.ARM64.txt @@ -0,0 +1,33 @@ + +package pod1 { + + @CStruct(spelling = "struct { void* __stack; void* __gr_top; void* __vr_top; int __gr_offs; int __vr_offs; }") class __va_list constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var __gr_offs: Int + @CStruct.MemberAt(offset = 24.toLong()) get + @CStruct.MemberAt(offset = 24.toLong()) set + var __gr_top: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 8.toLong()) get + @CStruct.MemberAt(offset = 8.toLong()) set + var __stack: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + var __vr_offs: Int + @CStruct.MemberAt(offset = 28.toLong()) get + @CStruct.MemberAt(offset = 28.toLong()) set + var __vr_top: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 16.toLong()) get + @CStruct.MemberAt(offset = 16.toLong()) set + @CStruct.VarType(align = 8, size = 32.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + val A_va_list: __builtin_va_list /* = __va_list */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + typealias __builtin_va_list = __va_list +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.COpaquePointer.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.COpaquePointer.txt new file mode 100644 index 00000000000..18821b3307d --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.COpaquePointer.txt @@ -0,0 +1,12 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + var A_va_list: __builtin_va_list? /* = CPointer? */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + @CCall(id = "knifunptr_pod13_A_va_list_setter") set + typealias __builtin_va_list = COpaquePointer + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.CPointerByteVar.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.CPointerByteVar.txt new file mode 100644 index 00000000000..69e79edebaa --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.CPointerByteVar.txt @@ -0,0 +1,12 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + var A_va_list: __builtin_va_list? /* = CPointer */>? */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + @CCall(id = "knifunptr_pod13_A_va_list_setter") set + typealias __builtin_va_list = CPointer */> + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer */> */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.X64.txt b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.X64.txt new file mode 100644 index 00000000000..cf8e15e3aa1 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/contents.gold.X64.txt @@ -0,0 +1,31 @@ + +package pod1 { + + @CStruct(spelling = "struct { unsigned int gp_offset; unsigned int fp_offset; void* overflow_arg_area; void* reg_save_area; }") class __va_list_tag constructor(rawPtr: NativePtr /* = NativePtr */) : CStructVar { + var fp_offset: UInt + @CStruct.MemberAt(offset = 4.toLong()) get + @CStruct.MemberAt(offset = 4.toLong()) set + var gp_offset: UInt + @CStruct.MemberAt(offset = 0.toLong()) get + @CStruct.MemberAt(offset = 0.toLong()) set + var overflow_arg_area: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 8.toLong()) get + @CStruct.MemberAt(offset = 8.toLong()) set + var reg_save_area: COpaquePointer? /* = CPointer? */ + @CStruct.MemberAt(offset = 16.toLong()) get + @CStruct.MemberAt(offset = 16.toLong()) set + @CStruct.VarType(align = 8, size = 24.toLong()) @Deprecated(level = DeprecationLevel.WARNING, message = "Use sizeOf() or alignOf() instead.", replaceWith = ReplaceWith(imports = {})) companion object : CStructVar.Type + } + +} + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod10_A_getter") get + @CCall(id = "knifunptr_pod11_A_setter") set + val A_va_list: __builtin_va_list /* = CPointer<__va_list_tag> */ + @CCall(id = "knifunptr_pod12_A_va_list_getter") get + typealias __builtin_va_list = CArrayPointer<__va_list_tag> + typealias __builtin_va_listVar = CPointerVarOf<__builtin_va_list /* = CPointer<__va_list_tag> */> +} + diff --git a/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/pod1.def b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/pod1.def new file mode 100644 index 00000000000..12ec9154626 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = A diff --git a/native/native.tests/testData/CInterop/builtins/include/A.h b/native/native.tests/testData/CInterop/builtins/include/A.h new file mode 100644 index 00000000000..45602a2ff82 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/include/A.h @@ -0,0 +1,4 @@ +#import + +int A; +__builtin_va_list A_va_list; diff --git a/native/native.tests/testData/CInterop/builtins/include/module.modulemap b/native/native.tests/testData/CInterop/builtins/include/module.modulemap new file mode 100644 index 00000000000..3cd548eae47 --- /dev/null +++ b/native/native.tests/testData/CInterop/builtins/include/module.modulemap @@ -0,0 +1,4 @@ +module A { + header "A.h" + export * +} diff --git a/native/native.tests/testData/CInterop/framework.macros/macrosDefs/modulesPod1/contents.gold.txt b/native/native.tests/testData/CInterop/framework.macros/macrosDefs/modulesPod1/contents.gold.txt new file mode 100644 index 00000000000..83480036eb9 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework.macros/macrosDefs/modulesPod1/contents.gold.txt @@ -0,0 +1,9 @@ + +package pod1 { + const val MY_MACRO_CONST_POD1: Int = 42 + const val MY_MACRO_CONST_POD1A: Int = 153 + var myVar: Double + @CCall(id = "knifunptr_pod10_myVar_getter") get + @CCall(id = "knifunptr_pod11_myVar_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework.macros/macrosDefs/modulesPod1/pod1.def b/native/native.tests/testData/CInterop/framework.macros/macrosDefs/modulesPod1/pod1.def new file mode 100644 index 00000000000..4316a3425b9 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework.macros/macrosDefs/modulesPod1/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = pod1 diff --git a/native/native.tests/testData/CInterop/framework.macros/macrosDefs/myMacroType/contents.gold.txt b/native/native.tests/testData/CInterop/framework.macros/macrosDefs/myMacroType/contents.gold.txt new file mode 100644 index 00000000000..83480036eb9 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework.macros/macrosDefs/myMacroType/contents.gold.txt @@ -0,0 +1,9 @@ + +package pod1 { + const val MY_MACRO_CONST_POD1: Int = 42 + const val MY_MACRO_CONST_POD1A: Int = 153 + var myVar: Double + @CCall(id = "knifunptr_pod10_myVar_getter") get + @CCall(id = "knifunptr_pod11_myVar_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework.macros/macrosDefs/myMacroType/pod1.def b/native/native.tests/testData/CInterop/framework.macros/macrosDefs/myMacroType/pod1.def new file mode 100644 index 00000000000..f12fe397ec4 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework.macros/macrosDefs/myMacroType/pod1.def @@ -0,0 +1,2 @@ +language = C +headers=pod1/pod1.h diff --git a/native/native.tests/testData/CInterop/framework.macros/pod1.framework/Headers/pod1.h b/native/native.tests/testData/CInterop/framework.macros/pod1.framework/Headers/pod1.h new file mode 100644 index 00000000000..e3e8eb37b3d --- /dev/null +++ b/native/native.tests/testData/CInterop/framework.macros/pod1.framework/Headers/pod1.h @@ -0,0 +1,8 @@ +#ifndef __POD1_H__ +#define __POD1_H__ + +#import "pod1A.h" +MY_MACRO_TYPE myVar; +#define MY_MACRO_CONST_POD1 42 + +#endif diff --git a/native/native.tests/testData/CInterop/framework.macros/pod1.framework/Headers/pod1A.h b/native/native.tests/testData/CInterop/framework.macros/pod1.framework/Headers/pod1A.h new file mode 100644 index 00000000000..5046ade4d85 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework.macros/pod1.framework/Headers/pod1A.h @@ -0,0 +1,7 @@ +#ifndef __POD1A_H__ +#define __POD1A_H__ + +#define MY_MACRO_TYPE double +#define MY_MACRO_CONST_POD1A 153 + +#endif diff --git a/native/native.tests/testData/CInterop/framework.macros/pod1.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/framework.macros/pod1.framework/Modules/module.modulemap new file mode 100644 index 00000000000..161a9707d70 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework.macros/pod1.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module pod1 { + umbrella header "pod1.h" + + export * + module * { export * } +} diff --git a/native/native.tests/testData/CInterop/framework/childImport.framework/Headers/child.h b/native/native.tests/testData/CInterop/framework/childImport.framework/Headers/child.h new file mode 100644 index 00000000000..e3ab9296022 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/childImport.framework/Headers/child.h @@ -0,0 +1,2 @@ +@import m1; +int child; diff --git a/native/native.tests/testData/CInterop/framework/childImport.framework/Headers/umbrella.h b/native/native.tests/testData/CInterop/framework/childImport.framework/Headers/umbrella.h new file mode 100644 index 00000000000..fcf6e1e577f --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/childImport.framework/Headers/umbrella.h @@ -0,0 +1,2 @@ +#import +int umbrella; diff --git a/native/native.tests/testData/CInterop/framework/childImport.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/framework/childImport.framework/Modules/module.modulemap new file mode 100644 index 00000000000..691fce7296d --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/childImport.framework/Modules/module.modulemap @@ -0,0 +1,7 @@ +framework module childImport { + umbrella header "umbrella.h" + + export * + module * { export * } +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/childImportFModules/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/childImportFModules/contents.gold.txt new file mode 100644 index 00000000000..da61398c7a3 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/childImportFModules/contents.gold.txt @@ -0,0 +1,10 @@ + +package pod1 { + var child: Int + @CCall(id = "knifunptr_pod10_child_getter") get + @CCall(id = "knifunptr_pod11_child_setter") set + var umbrella: Int + @CCall(id = "knifunptr_pod12_umbrella_getter") get + @CCall(id = "knifunptr_pod13_umbrella_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/childImportFModules/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/childImportFModules/pod1.def new file mode 100644 index 00000000000..95562203b05 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/childImportFModules/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = childImport diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1/contents.gold.txt new file mode 100644 index 00000000000..9d1c7c92779 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1/contents.gold.txt @@ -0,0 +1,10 @@ + +package pod1 { + var pod1A: Int + @CCall(id = "knifunptr_pod10_pod1A_getter") get + @CCall(id = "knifunptr_pod11_pod1A_setter") set + var pod1_umbrella: Int + @CCall(id = "knifunptr_pod12_pod1_umbrella_getter") get + @CCall(id = "knifunptr_pod13_pod1_umbrella_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1/pod1.def new file mode 100644 index 00000000000..d80d19d2f19 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1/pod1.def @@ -0,0 +1,5 @@ +language = C +headers=pod1/pod1-umbrella.h + +headerFilter=** +excludeFilter=pod1/pod1.h diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1Umbrella/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1Umbrella/contents.gold.txt new file mode 100644 index 00000000000..63a7b9c856c --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1Umbrella/contents.gold.txt @@ -0,0 +1,7 @@ + +package pod1 { + var pod1A: Int + @CCall(id = "knifunptr_pod10_pod1A_getter") get + @CCall(id = "knifunptr_pod11_pod1A_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1Umbrella/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1Umbrella/pod1.def new file mode 100644 index 00000000000..dad0cd4d7c9 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1Umbrella/pod1.def @@ -0,0 +1,5 @@ +language = C +headers=pod1/pod1-umbrella.h + +headerFilter=pod1/pod1-umbrella.h pod1/pod1A.h +excludeFilter=pod1/pod1-umbrella.h diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1/contents.gold.txt new file mode 100644 index 00000000000..24e3c5e1265 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1/contents.gold.txt @@ -0,0 +1,7 @@ + +package pod1 { + var pod1: Int + @CCall(id = "knifunptr_pod10_pod1_getter") get + @CCall(id = "knifunptr_pod11_pod1_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1/pod1.def new file mode 100644 index 00000000000..a15d4022e23 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1/pod1.def @@ -0,0 +1,4 @@ +language = C +headers=pod1/pod1-umbrella.h + +headerFilter=pod1/pod1.h diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1A/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1A/contents.gold.txt new file mode 100644 index 00000000000..63a7b9c856c --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1A/contents.gold.txt @@ -0,0 +1,7 @@ + +package pod1 { + var pod1A: Int + @CCall(id = "knifunptr_pod10_pod1A_getter") get + @CCall(id = "knifunptr_pod11_pod1A_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1A/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1A/pod1.def new file mode 100644 index 00000000000..8c8d4109bfc --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1A/pod1.def @@ -0,0 +1,4 @@ +language = C +headers=pod1/pod1-umbrella.h + +headerFilter=pod1/pod1A.h diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1Umbrella/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1Umbrella/contents.gold.txt new file mode 100644 index 00000000000..8835822fe67 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1Umbrella/contents.gold.txt @@ -0,0 +1,7 @@ + +package pod1 { + var pod1_umbrella: Int + @CCall(id = "knifunptr_pod10_pod1_umbrella_getter") get + @CCall(id = "knifunptr_pod11_pod1_umbrella_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1Umbrella/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1Umbrella/pod1.def new file mode 100644 index 00000000000..a35a95f147d --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1Umbrella/pod1.def @@ -0,0 +1,4 @@ +language = C +headers=pod1/pod1-umbrella.h + +headerFilter=pod1/pod1-umbrella.h diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1UmbrellaPod1A/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1UmbrellaPod1A/contents.gold.txt new file mode 100644 index 00000000000..9d1c7c92779 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1UmbrellaPod1A/contents.gold.txt @@ -0,0 +1,10 @@ + +package pod1 { + var pod1A: Int + @CCall(id = "knifunptr_pod10_pod1A_getter") get + @CCall(id = "knifunptr_pod11_pod1A_setter") set + var pod1_umbrella: Int + @CCall(id = "knifunptr_pod12_pod1_umbrella_getter") get + @CCall(id = "knifunptr_pod13_pod1_umbrella_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1UmbrellaPod1A/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1UmbrellaPod1A/pod1.def new file mode 100644 index 00000000000..1340b1124fc --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1UmbrellaPod1A/pod1.def @@ -0,0 +1,4 @@ +language = C +headers=pod1/pod1-umbrella.h + +headerFilter=pod1/pod1-umbrella.h pod1/pod1A.h diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/full/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/full/contents.gold.txt new file mode 100644 index 00000000000..ea9c21792bd --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/full/contents.gold.txt @@ -0,0 +1,13 @@ + +package pod1 { + var pod1: Int + @CCall(id = "knifunptr_pod10_pod1_getter") get + @CCall(id = "knifunptr_pod11_pod1_setter") set + var pod1A: Int + @CCall(id = "knifunptr_pod12_pod1A_getter") get + @CCall(id = "knifunptr_pod13_pod1A_setter") set + var pod1_umbrella: Int + @CCall(id = "knifunptr_pod14_pod1_umbrella_getter") get + @CCall(id = "knifunptr_pod15_pod1_umbrella_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/full/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/full/pod1.def new file mode 100644 index 00000000000..7b12f4cf535 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/full/pod1.def @@ -0,0 +1,2 @@ +language = C +headers=pod1/pod1-umbrella.h diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleAngle/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleAngle/contents.gold.txt new file mode 100644 index 00000000000..24ff9b08c80 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleAngle/contents.gold.txt @@ -0,0 +1,13 @@ + +package pod1 { + var podImportsAngleAngle: Int + @CCall(id = "knifunptr_pod10_podImportsAngleAngle_getter") get + @CCall(id = "knifunptr_pod11_podImportsAngleAngle_setter") set + var podImportsAngleAngleA: Int + @CCall(id = "knifunptr_pod12_podImportsAngleAngleA_getter") get + @CCall(id = "knifunptr_pod13_podImportsAngleAngleA_setter") set + var podImportsAngleAngle_umbrella: Int + @CCall(id = "knifunptr_pod14_podImportsAngleAngle_umbrella_getter") get + @CCall(id = "knifunptr_pod15_podImportsAngleAngle_umbrella_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleAngle/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleAngle/pod1.def new file mode 100644 index 00000000000..7b3b532cdfe --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleAngle/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = podImportsAngleAngle diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleQuote/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleQuote/contents.gold.txt new file mode 100644 index 00000000000..69c21c1d526 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleQuote/contents.gold.txt @@ -0,0 +1,13 @@ + +package pod1 { + var podImportsAngleQuote: Int + @CCall(id = "knifunptr_pod10_podImportsAngleQuote_getter") get + @CCall(id = "knifunptr_pod11_podImportsAngleQuote_setter") set + var podImportsAngleQuoteA: Int + @CCall(id = "knifunptr_pod12_podImportsAngleQuoteA_getter") get + @CCall(id = "knifunptr_pod13_podImportsAngleQuoteA_setter") set + var podImportsAngleQuote_umbrella: Int + @CCall(id = "knifunptr_pod14_podImportsAngleQuote_umbrella_getter") get + @CCall(id = "knifunptr_pod15_podImportsAngleQuote_umbrella_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleQuote/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleQuote/pod1.def new file mode 100644 index 00000000000..4aaad7dd9a2 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleQuote/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = podImportsAngleQuote diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteAngle/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteAngle/contents.gold.txt new file mode 100644 index 00000000000..80a55bed255 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteAngle/contents.gold.txt @@ -0,0 +1,13 @@ + +package pod1 { + var podImportsQuoteAngle: Int + @CCall(id = "knifunptr_pod10_podImportsQuoteAngle_getter") get + @CCall(id = "knifunptr_pod11_podImportsQuoteAngle_setter") set + var podImportsQuoteAngleA: Int + @CCall(id = "knifunptr_pod12_podImportsQuoteAngleA_getter") get + @CCall(id = "knifunptr_pod13_podImportsQuoteAngleA_setter") set + var podImportsQuoteAngle_umbrella: Int + @CCall(id = "knifunptr_pod14_podImportsQuoteAngle_umbrella_getter") get + @CCall(id = "knifunptr_pod15_podImportsQuoteAngle_umbrella_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteAngle/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteAngle/pod1.def new file mode 100644 index 00000000000..f0ae94f054f --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteAngle/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = podImportsQuoteAngle diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteQuote/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteQuote/contents.gold.txt new file mode 100644 index 00000000000..047fc2d5b3e --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteQuote/contents.gold.txt @@ -0,0 +1,13 @@ + +package pod1 { + var podImportsQuoteQuote: Int + @CCall(id = "knifunptr_pod10_podImportsQuoteQuote_getter") get + @CCall(id = "knifunptr_pod11_podImportsQuoteQuote_setter") set + var podImportsQuoteQuoteA: Int + @CCall(id = "knifunptr_pod12_podImportsQuoteQuoteA_getter") get + @CCall(id = "knifunptr_pod13_podImportsQuoteQuoteA_setter") set + var podImportsQuoteQuote_umbrella: Int + @CCall(id = "knifunptr_pod14_podImportsQuoteQuote_umbrella_getter") get + @CCall(id = "knifunptr_pod15_podImportsQuoteQuote_umbrella_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteQuote/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteQuote/pod1.def new file mode 100644 index 00000000000..eb6ad6397c8 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteQuote/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = podImportsQuoteQuote diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/modulesPod1/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/modulesPod1/contents.gold.txt new file mode 100644 index 00000000000..ea9c21792bd --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/modulesPod1/contents.gold.txt @@ -0,0 +1,13 @@ + +package pod1 { + var pod1: Int + @CCall(id = "knifunptr_pod10_pod1_getter") get + @CCall(id = "knifunptr_pod11_pod1_setter") set + var pod1A: Int + @CCall(id = "knifunptr_pod12_pod1A_getter") get + @CCall(id = "knifunptr_pod13_pod1A_setter") set + var pod1_umbrella: Int + @CCall(id = "knifunptr_pod14_pod1_umbrella_getter") get + @CCall(id = "knifunptr_pod15_pod1_umbrella_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/modulesPod1/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/modulesPod1/pod1.def new file mode 100644 index 00000000000..4316a3425b9 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/modulesPod1/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = pod1 diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/twoChildren/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/twoChildren/contents.gold.txt new file mode 100644 index 00000000000..339cc3c7f76 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/twoChildren/contents.gold.txt @@ -0,0 +1,13 @@ + +package pod1 { + var child1: Int + @CCall(id = "knifunptr_pod10_child1_getter") get + @CCall(id = "knifunptr_pod11_child1_setter") set + var child2: Int + @CCall(id = "knifunptr_pod12_child2_getter") get + @CCall(id = "knifunptr_pod13_child2_setter") set + var umbrella: Int + @CCall(id = "knifunptr_pod14_umbrella_getter") get + @CCall(id = "knifunptr_pod15_umbrella_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/twoChildren/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/twoChildren/pod1.def new file mode 100644 index 00000000000..53167d5238d --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/twoChildren/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = twoChildren diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/visitOtherModules/contents.gold.txt b/native/native.tests/testData/CInterop/framework/frameworkDefs/visitOtherModules/contents.gold.txt new file mode 100644 index 00000000000..58a87fd0cf8 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/visitOtherModules/contents.gold.txt @@ -0,0 +1,7 @@ + +package pod1 { + var baz: Int + @CCall(id = "knifunptr_pod10_baz_getter") get + @CCall(id = "knifunptr_pod11_baz_setter") set +} + diff --git a/native/native.tests/testData/CInterop/framework/frameworkDefs/visitOtherModules/pod1.def b/native/native.tests/testData/CInterop/framework/frameworkDefs/visitOtherModules/pod1.def new file mode 100644 index 00000000000..65802531a86 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/frameworkDefs/visitOtherModules/pod1.def @@ -0,0 +1,2 @@ +language=Objective-C +modules=m2 diff --git a/native/native.tests/testData/CInterop/framework/m1.framework/Headers/m1.h b/native/native.tests/testData/CInterop/framework/m1.framework/Headers/m1.h new file mode 100644 index 00000000000..53e4b55adcc --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/m1.framework/Headers/m1.h @@ -0,0 +1,9 @@ +#ifndef M1_M1_h +#define M1_M1_h + +@protocol Foo +@end + +int bar; + +#endif diff --git a/native/native.tests/testData/CInterop/framework/m1.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/framework/m1.framework/Modules/module.modulemap new file mode 100644 index 00000000000..719cfa5d940 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/m1.framework/Modules/module.modulemap @@ -0,0 +1,7 @@ +framework module m1 { + umbrella header "m1.h" + + export * + module * { export * } +} + diff --git a/native/native.tests/testData/CInterop/framework/m2.framework/Headers/m2.h b/native/native.tests/testData/CInterop/framework/m2.framework/Headers/m2.h new file mode 100644 index 00000000000..1f1f56f8dc2 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/m2.framework/Headers/m2.h @@ -0,0 +1,8 @@ +#ifndef M2_M2_h +#define M2_M2_h + +#import + +int baz; + +#endif diff --git a/native/native.tests/testData/CInterop/framework/m2.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/framework/m2.framework/Modules/module.modulemap new file mode 100644 index 00000000000..8ffe32ca086 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/m2.framework/Modules/module.modulemap @@ -0,0 +1,7 @@ +framework module m2 { + umbrella header "m2.h" + + export * + module * { export * } +} + diff --git a/native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1-umbrella.h b/native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1-umbrella.h new file mode 100644 index 00000000000..eb07ea950a2 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1-umbrella.h @@ -0,0 +1,2 @@ +#import "pod1.h" +int pod1_umbrella; diff --git a/native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1.h b/native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1.h new file mode 100644 index 00000000000..49ee6720a93 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1.h @@ -0,0 +1,2 @@ +#import "pod1A.h" +int pod1; diff --git a/native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1A.h b/native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1A.h new file mode 100644 index 00000000000..33fdd7f6cf1 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/pod1.framework/Headers/pod1A.h @@ -0,0 +1 @@ +int pod1A; diff --git a/native/native.tests/testData/CInterop/framework/pod1.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/framework/pod1.framework/Modules/module.modulemap new file mode 100644 index 00000000000..7d038af90cf --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/pod1.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module pod1 { + umbrella header "pod1-umbrella.h" + + export * + module * { export * } +} diff --git a/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngle-umbrella.h b/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngle-umbrella.h new file mode 100644 index 00000000000..b31cbd2d770 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngle-umbrella.h @@ -0,0 +1,2 @@ +#import +int podImportsAngleAngle_umbrella; diff --git a/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngle.h b/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngle.h new file mode 100644 index 00000000000..08f06919ce8 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngle.h @@ -0,0 +1,2 @@ +#import // this angle import might have issues after angle import umbrella header +int podImportsAngleAngle; diff --git a/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngleA.h b/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngleA.h new file mode 100644 index 00000000000..17932f86508 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Headers/podImportsAngleAngleA.h @@ -0,0 +1 @@ +int podImportsAngleAngleA; diff --git a/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Modules/module.modulemap new file mode 100644 index 00000000000..c339edc5686 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsAngleAngle.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module podImportsAngleAngle { + umbrella header "podImportsAngleAngle-umbrella.h" + + export * + module * { export * } +} diff --git a/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuote-umbrella.h b/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuote-umbrella.h new file mode 100644 index 00000000000..2eb03e4ca17 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuote-umbrella.h @@ -0,0 +1,2 @@ +#import +int podImportsAngleQuote_umbrella; diff --git a/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuote.h b/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuote.h new file mode 100644 index 00000000000..fb13fe12852 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuote.h @@ -0,0 +1,2 @@ +#import "podImportsAngleQuoteA.h" // this quote import might have issues after angle import in umbrella header +int podImportsAngleQuote; diff --git a/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuoteA.h b/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuoteA.h new file mode 100644 index 00000000000..a54a9c9ec42 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Headers/podImportsAngleQuoteA.h @@ -0,0 +1 @@ +int podImportsAngleQuoteA; diff --git a/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Modules/module.modulemap new file mode 100644 index 00000000000..9b8eaf5f1a0 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsAngleQuote.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module podImportsAngleQuote { + umbrella header "podImportsAngleQuote-umbrella.h" + + export * + module * { export * } +} diff --git a/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngle-umbrella.h b/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngle-umbrella.h new file mode 100644 index 00000000000..78b62f28ef6 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngle-umbrella.h @@ -0,0 +1,2 @@ +#import "podImportsQuoteAngle.h" +int podImportsQuoteAngle_umbrella; diff --git a/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngle.h b/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngle.h new file mode 100644 index 00000000000..686a99113a5 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngle.h @@ -0,0 +1,2 @@ +#import // this angle import might have issues after quote import in umbrella header +int podImportsQuoteAngle; diff --git a/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngleA.h b/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngleA.h new file mode 100644 index 00000000000..1ad5b09a63e --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Headers/podImportsQuoteAngleA.h @@ -0,0 +1 @@ +int podImportsQuoteAngleA; diff --git a/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Modules/module.modulemap new file mode 100644 index 00000000000..5bdb2804725 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsQuoteAngle.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module podImportsQuoteAngle { + umbrella header "podImportsQuoteAngle-umbrella.h" + + export * + module * { export * } +} diff --git a/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuote-umbrella.h b/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuote-umbrella.h new file mode 100644 index 00000000000..44b4c40d35d --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuote-umbrella.h @@ -0,0 +1,2 @@ +#import "podImportsQuoteQuote.h" +int podImportsQuoteQuote_umbrella; diff --git a/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuote.h b/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuote.h new file mode 100644 index 00000000000..e4927b21a9b --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuote.h @@ -0,0 +1,2 @@ +#import "podImportsQuoteQuoteA.h" // this quote import might have issues after quote import in umbrella header +int podImportsQuoteQuote; diff --git a/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuoteA.h b/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuoteA.h new file mode 100644 index 00000000000..d5274248f67 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Headers/podImportsQuoteQuoteA.h @@ -0,0 +1 @@ +int podImportsQuoteQuoteA; diff --git a/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Modules/module.modulemap new file mode 100644 index 00000000000..12d823d6435 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/podImportsQuoteQuote.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module podImportsQuoteQuote { + umbrella header "podImportsQuoteQuote-umbrella.h" + + export * + module * { export * } +} diff --git a/native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/child1.h b/native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/child1.h new file mode 100644 index 00000000000..a4f1d87819e --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/child1.h @@ -0,0 +1 @@ +int child1; diff --git a/native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/child2.h b/native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/child2.h new file mode 100644 index 00000000000..9aef2d28da6 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/child2.h @@ -0,0 +1 @@ +int child2; diff --git a/native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/umbrella.h b/native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/umbrella.h new file mode 100644 index 00000000000..8764a881916 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/twoChildren.framework/Headers/umbrella.h @@ -0,0 +1,3 @@ +#import +#import +int umbrella; diff --git a/native/native.tests/testData/CInterop/framework/twoChildren.framework/Modules/module.modulemap b/native/native.tests/testData/CInterop/framework/twoChildren.framework/Modules/module.modulemap new file mode 100644 index 00000000000..8805a33c3e4 --- /dev/null +++ b/native/native.tests/testData/CInterop/framework/twoChildren.framework/Modules/module.modulemap @@ -0,0 +1,7 @@ +framework module twoChildren { + umbrella header "umbrella.h" + + export * + module * { export * } +} + diff --git a/native/native.tests/testData/CInterop/simple/include/A.h b/native/native.tests/testData/CInterop/simple/include/A.h new file mode 100644 index 00000000000..c1c851d3503 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/include/A.h @@ -0,0 +1,11 @@ +#ifndef __A_H__ +#define __A_H__ + +#import "C.h" +int A; + +int AAA() { + return A; +} + +#endif diff --git a/native/native.tests/testData/CInterop/simple/include/B.h b/native/native.tests/testData/CInterop/simple/include/B.h new file mode 100644 index 00000000000..4b6464655ba --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/include/B.h @@ -0,0 +1,8 @@ +#ifndef __B_H__ +#define __B_H__ + +#import "C.h" + +int B; + +#endif \ No newline at end of file diff --git a/native/native.tests/testData/CInterop/simple/include/C.h b/native/native.tests/testData/CInterop/simple/include/C.h new file mode 100644 index 00000000000..4c29967a51f --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/include/C.h @@ -0,0 +1,6 @@ +#ifndef __C_H__ +#define __C_H__ + +int C; + +#endif diff --git a/native/native.tests/testData/CInterop/simple/include/module.modulemap b/native/native.tests/testData/CInterop/simple/include/module.modulemap new file mode 100644 index 00000000000..83d323ad4fe --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/include/module.modulemap @@ -0,0 +1,10 @@ +module A { + header "A.h" + export * +} + +module B { + header "B.h" + export * +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterA/contents.gold.txt b/native/native.tests/testData/CInterop/simple/simpleDefs/filterA/contents.gold.txt new file mode 100644 index 00000000000..2cd6219c3c5 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterA/contents.gold.txt @@ -0,0 +1,8 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod11_A_getter") get + @CCall(id = "knifunptr_pod12_A_setter") set + @CCall(id = "knifunptr_pod10_AAA") external fun AAA(): Int +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterA/pod1.def b/native/native.tests/testData/CInterop/simple/simpleDefs/filterA/pod1.def new file mode 100644 index 00000000000..0623ab2b0d0 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterA/pod1.def @@ -0,0 +1,3 @@ +language = C +headers = A.h B.h +headerFilter=A.h \ No newline at end of file diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterAB/contents.gold.txt b/native/native.tests/testData/CInterop/simple/simpleDefs/filterAB/contents.gold.txt new file mode 100644 index 00000000000..7de71d05507 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterAB/contents.gold.txt @@ -0,0 +1,11 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod11_A_getter") get + @CCall(id = "knifunptr_pod12_A_setter") set + @CCall(id = "knifunptr_pod10_AAA") external fun AAA(): Int + var B: Int + @CCall(id = "knifunptr_pod13_B_getter") get + @CCall(id = "knifunptr_pod14_B_setter") set +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterAB/pod1.def b/native/native.tests/testData/CInterop/simple/simpleDefs/filterAB/pod1.def new file mode 100644 index 00000000000..741a6ed4448 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterAB/pod1.def @@ -0,0 +1,3 @@ +language = C +headers = A.h B.h +headerFilter=A.h B.h diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterABC/contents.gold.txt b/native/native.tests/testData/CInterop/simple/simpleDefs/filterABC/contents.gold.txt new file mode 100644 index 00000000000..3042e48d2b0 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterABC/contents.gold.txt @@ -0,0 +1,14 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod11_A_getter") get + @CCall(id = "knifunptr_pod12_A_setter") set + @CCall(id = "knifunptr_pod10_AAA") external fun AAA(): Int + var B: Int + @CCall(id = "knifunptr_pod13_B_getter") get + @CCall(id = "knifunptr_pod14_B_setter") set + var C: Int + @CCall(id = "knifunptr_pod15_C_getter") get + @CCall(id = "knifunptr_pod16_C_setter") set +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterABC/pod1.def b/native/native.tests/testData/CInterop/simple/simpleDefs/filterABC/pod1.def new file mode 100644 index 00000000000..3ed33996c3b --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterABC/pod1.def @@ -0,0 +1,3 @@ +language = C +headers = A.h B.h +headerFilter=A.h B.h C.h diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterAC/contents.gold.txt b/native/native.tests/testData/CInterop/simple/simpleDefs/filterAC/contents.gold.txt new file mode 100644 index 00000000000..b4921c6b31d --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterAC/contents.gold.txt @@ -0,0 +1,11 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod11_A_getter") get + @CCall(id = "knifunptr_pod12_A_setter") set + @CCall(id = "knifunptr_pod10_AAA") external fun AAA(): Int + var C: Int + @CCall(id = "knifunptr_pod13_C_getter") get + @CCall(id = "knifunptr_pod14_C_setter") set +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterAC/pod1.def b/native/native.tests/testData/CInterop/simple/simpleDefs/filterAC/pod1.def new file mode 100644 index 00000000000..2cd9b588aba --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterAC/pod1.def @@ -0,0 +1,3 @@ +language = C +headers = A.h B.h +headerFilter=A.h C.h diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterB/contents.gold.txt b/native/native.tests/testData/CInterop/simple/simpleDefs/filterB/contents.gold.txt new file mode 100644 index 00000000000..13334a34ed6 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterB/contents.gold.txt @@ -0,0 +1,7 @@ + +package pod1 { + var B: Int + @CCall(id = "knifunptr_pod10_B_getter") get + @CCall(id = "knifunptr_pod11_B_setter") set +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterB/pod1.def b/native/native.tests/testData/CInterop/simple/simpleDefs/filterB/pod1.def new file mode 100644 index 00000000000..90d86301ef4 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterB/pod1.def @@ -0,0 +1,3 @@ +language = C +headers = A.h B.h +headerFilter=B.h diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterBC/contents.gold.txt b/native/native.tests/testData/CInterop/simple/simpleDefs/filterBC/contents.gold.txt new file mode 100644 index 00000000000..43d71df508f --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterBC/contents.gold.txt @@ -0,0 +1,10 @@ + +package pod1 { + var B: Int + @CCall(id = "knifunptr_pod10_B_getter") get + @CCall(id = "knifunptr_pod11_B_setter") set + var C: Int + @CCall(id = "knifunptr_pod12_C_getter") get + @CCall(id = "knifunptr_pod13_C_setter") set +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterBC/pod1.def b/native/native.tests/testData/CInterop/simple/simpleDefs/filterBC/pod1.def new file mode 100644 index 00000000000..df9562b0fb5 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterBC/pod1.def @@ -0,0 +1,3 @@ +language = C +headers = A.h B.h +headerFilter=B.h C.h diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterC/contents.gold.txt b/native/native.tests/testData/CInterop/simple/simpleDefs/filterC/contents.gold.txt new file mode 100644 index 00000000000..4f0d6ca4ba8 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterC/contents.gold.txt @@ -0,0 +1,7 @@ + +package pod1 { + var C: Int + @CCall(id = "knifunptr_pod10_C_getter") get + @CCall(id = "knifunptr_pod11_C_setter") set +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/filterC/pod1.def b/native/native.tests/testData/CInterop/simple/simpleDefs/filterC/pod1.def new file mode 100644 index 00000000000..8826d871eca --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/filterC/pod1.def @@ -0,0 +1,3 @@ +language = C +headers = A.h B.h +headerFilter=C.h diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/full/contents.gold.txt b/native/native.tests/testData/CInterop/simple/simpleDefs/full/contents.gold.txt new file mode 100644 index 00000000000..3042e48d2b0 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/full/contents.gold.txt @@ -0,0 +1,14 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod11_A_getter") get + @CCall(id = "knifunptr_pod12_A_setter") set + @CCall(id = "knifunptr_pod10_AAA") external fun AAA(): Int + var B: Int + @CCall(id = "knifunptr_pod13_B_getter") get + @CCall(id = "knifunptr_pod14_B_setter") set + var C: Int + @CCall(id = "knifunptr_pod15_C_getter") get + @CCall(id = "knifunptr_pod16_C_setter") set +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/full/pod1.def b/native/native.tests/testData/CInterop/simple/simpleDefs/full/pod1.def new file mode 100644 index 00000000000..7c527590549 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/full/pod1.def @@ -0,0 +1,2 @@ +language = C +headers = A.h B.h diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/modulesA/contents.gold.txt b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesA/contents.gold.txt new file mode 100644 index 00000000000..b4921c6b31d --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesA/contents.gold.txt @@ -0,0 +1,11 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod11_A_getter") get + @CCall(id = "knifunptr_pod12_A_setter") set + @CCall(id = "knifunptr_pod10_AAA") external fun AAA(): Int + var C: Int + @CCall(id = "knifunptr_pod13_C_getter") get + @CCall(id = "knifunptr_pod14_C_setter") set +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/modulesA/pod1.def b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesA/pod1.def new file mode 100644 index 00000000000..12ec9154626 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesA/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = A diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/modulesAB/contents.gold.txt b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesAB/contents.gold.txt new file mode 100644 index 00000000000..3042e48d2b0 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesAB/contents.gold.txt @@ -0,0 +1,14 @@ + +package pod1 { + var A: Int + @CCall(id = "knifunptr_pod11_A_getter") get + @CCall(id = "knifunptr_pod12_A_setter") set + @CCall(id = "knifunptr_pod10_AAA") external fun AAA(): Int + var B: Int + @CCall(id = "knifunptr_pod13_B_getter") get + @CCall(id = "knifunptr_pod14_B_setter") set + var C: Int + @CCall(id = "knifunptr_pod15_C_getter") get + @CCall(id = "knifunptr_pod16_C_setter") set +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/modulesAB/pod1.def b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesAB/pod1.def new file mode 100644 index 00000000000..fe658884f84 --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesAB/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = A B diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/modulesB/contents.gold.txt b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesB/contents.gold.txt new file mode 100644 index 00000000000..43d71df508f --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesB/contents.gold.txt @@ -0,0 +1,10 @@ + +package pod1 { + var B: Int + @CCall(id = "knifunptr_pod10_B_getter") get + @CCall(id = "knifunptr_pod11_B_setter") set + var C: Int + @CCall(id = "knifunptr_pod12_C_getter") get + @CCall(id = "knifunptr_pod13_C_setter") set +} + diff --git a/native/native.tests/testData/CInterop/simple/simpleDefs/modulesB/pod1.def b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesB/pod1.def new file mode 100644 index 00000000000..8cb4ea3af6e --- /dev/null +++ b/native/native.tests/testData/CInterop/simple/simpleDefs/modulesB/pod1.def @@ -0,0 +1,2 @@ +language = Objective-C +modules = B diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropFModulesTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropFModulesTestGenerated.java new file mode 100644 index 00000000000..b6b7471757e --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropFModulesTestGenerated.java @@ -0,0 +1,257 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan.blackboxtest; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +public class CInteropFModulesTestGenerated extends AbstractNativeCInteropFModulesTest { + @Nested + @TestMetadata("native/native.tests/testData/CInterop/simple/simpleDefs") + @TestDataPath("$PROJECT_ROOT") + public class SimpleDefs { + @Test + public void testAllFilesPresentInSimpleDefs() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CInterop/simple/simpleDefs"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("filterA") + public void testFilterA() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterA/"); + } + + @Test + @TestMetadata("filterAB") + public void testFilterAB() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterAB/"); + } + + @Test + @TestMetadata("filterABC") + public void testFilterABC() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterABC/"); + } + + @Test + @TestMetadata("filterAC") + public void testFilterAC() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterAC/"); + } + + @Test + @TestMetadata("filterB") + public void testFilterB() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterB/"); + } + + @Test + @TestMetadata("filterBC") + public void testFilterBC() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterBC/"); + } + + @Test + @TestMetadata("filterC") + public void testFilterC() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterC/"); + } + + @Test + @TestMetadata("full") + public void testFull() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/full/"); + } + + @Test + @TestMetadata("modulesA") + public void testModulesA() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/modulesA/"); + } + + @Test + @TestMetadata("modulesAB") + public void testModulesAB() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/modulesAB/"); + } + + @Test + @TestMetadata("modulesB") + public void testModulesB() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/modulesB/"); + } + } + + @Nested + @TestMetadata("native/native.tests/testData/CInterop/framework/frameworkDefs") + @TestDataPath("$PROJECT_ROOT") + public class FrameworkDefs { + @Test + public void testAllFilesPresentInFrameworkDefs() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CInterop/framework/frameworkDefs"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("childImportFModules") + public void testChildImportFModules() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/childImportFModules/"); + } + + @Test + @TestMetadata("excludePod1") + public void testExcludePod1() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1/"); + } + + @Test + @TestMetadata("excludePod1Umbrella") + public void testExcludePod1Umbrella() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1Umbrella/"); + } + + @Test + @TestMetadata("filterPod1") + public void testFilterPod1() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1/"); + } + + @Test + @TestMetadata("filterPod1A") + public void testFilterPod1A() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1A/"); + } + + @Test + @TestMetadata("filterPod1Umbrella") + public void testFilterPod1Umbrella() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1Umbrella/"); + } + + @Test + @TestMetadata("filterPod1UmbrellaPod1A") + public void testFilterPod1UmbrellaPod1A() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1UmbrellaPod1A/"); + } + + @Test + @TestMetadata("full") + public void testFull() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/full/"); + } + + @Test + @TestMetadata("importsAngleAngle") + public void testImportsAngleAngle() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleAngle/"); + } + + @Test + @TestMetadata("importsAngleQuote") + public void testImportsAngleQuote() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleQuote/"); + } + + @Test + @TestMetadata("importsQuoteAngle") + public void testImportsQuoteAngle() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteAngle/"); + } + + @Test + @TestMetadata("importsQuoteQuote") + public void testImportsQuoteQuote() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteQuote/"); + } + + @Test + @TestMetadata("modulesPod1") + public void testModulesPod1() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/modulesPod1/"); + } + + @Test + @TestMetadata("twoChildren") + public void testTwoChildren() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/twoChildren/"); + } + + @Test + @TestMetadata("visitOtherModules") + public void testVisitOtherModules() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/visitOtherModules/"); + } + } + + @Nested + @TestMetadata("native/native.tests/testData/CInterop/framework.macros/macrosDefs") + @TestDataPath("$PROJECT_ROOT") + public class MacrosDefs { + @Test + public void testAllFilesPresentInMacrosDefs() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CInterop/framework.macros/macrosDefs"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("modulesPod1") + public void testModulesPod1() throws Exception { + runTest("native/native.tests/testData/CInterop/framework.macros/macrosDefs/modulesPod1/"); + } + + @Test + @TestMetadata("myMacroType") + public void testMyMacroType() throws Exception { + runTest("native/native.tests/testData/CInterop/framework.macros/macrosDefs/myMacroType/"); + } + } + + @Nested + @TestMetadata("native/native.tests/testData/CInterop/builtins/builtinsDefs") + @TestDataPath("$PROJECT_ROOT") + public class BuiltinsDefs { + @Test + public void testAllFilesPresentInBuiltinsDefs() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CInterop/builtins/builtinsDefs"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("filterA") + public void testFilterA() throws Exception { + runTest("native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/"); + } + + @Test + @TestMetadata("filterStdargH") + public void testFilterStdargH() throws Exception { + runTest("native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/"); + } + + @Test + @TestMetadata("fullA") + public void testFullA() throws Exception { + runTest("native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/"); + } + + @Test + @TestMetadata("fullStdargH") + public void testFullStdargH() throws Exception { + runTest("native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/"); + } + + @Test + @TestMetadata("modulesA") + public void testModulesA() throws Exception { + runTest("native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/"); + } + } +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropKT39120TestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropKT39120TestGenerated.java new file mode 100644 index 00000000000..1b7baecf150 --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropKT39120TestGenerated.java @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan.blackboxtest; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("native/native.tests/testData/CInterop/KT-39120/defs") +@TestDataPath("$PROJECT_ROOT") +public class CInteropKT39120TestGenerated extends AbstractNativeCInteropKT39120Test { + @Test + public void testAllFilesPresentInDefs() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CInterop/KT-39120/defs"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("interModuleImport") + public void testInterModuleImport() throws Exception { + runTest("native/native.tests/testData/CInterop/KT-39120/defs/interModuleImport/"); + } + + @Test + @TestMetadata("KT-39120") + public void testKT_39120() throws Exception { + runTest("native/native.tests/testData/CInterop/KT-39120/defs/KT-39120/"); + } +} diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropNoFModulesTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropNoFModulesTestGenerated.java new file mode 100644 index 00000000000..a23844cce07 --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/CInteropNoFModulesTestGenerated.java @@ -0,0 +1,257 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan.blackboxtest; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +public class CInteropNoFModulesTestGenerated extends AbstractNativeCInteropNoFModulesTest { + @Nested + @TestMetadata("native/native.tests/testData/CInterop/simple/simpleDefs") + @TestDataPath("$PROJECT_ROOT") + public class SimpleDefs { + @Test + public void testAllFilesPresentInSimpleDefs() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CInterop/simple/simpleDefs"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("filterA") + public void testFilterA() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterA/"); + } + + @Test + @TestMetadata("filterAB") + public void testFilterAB() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterAB/"); + } + + @Test + @TestMetadata("filterABC") + public void testFilterABC() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterABC/"); + } + + @Test + @TestMetadata("filterAC") + public void testFilterAC() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterAC/"); + } + + @Test + @TestMetadata("filterB") + public void testFilterB() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterB/"); + } + + @Test + @TestMetadata("filterBC") + public void testFilterBC() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterBC/"); + } + + @Test + @TestMetadata("filterC") + public void testFilterC() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/filterC/"); + } + + @Test + @TestMetadata("full") + public void testFull() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/full/"); + } + + @Test + @TestMetadata("modulesA") + public void testModulesA() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/modulesA/"); + } + + @Test + @TestMetadata("modulesAB") + public void testModulesAB() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/modulesAB/"); + } + + @Test + @TestMetadata("modulesB") + public void testModulesB() throws Exception { + runTest("native/native.tests/testData/CInterop/simple/simpleDefs/modulesB/"); + } + } + + @Nested + @TestMetadata("native/native.tests/testData/CInterop/framework/frameworkDefs") + @TestDataPath("$PROJECT_ROOT") + public class FrameworkDefs { + @Test + public void testAllFilesPresentInFrameworkDefs() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CInterop/framework/frameworkDefs"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("childImportFModules") + public void testChildImportFModules() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/childImportFModules/"); + } + + @Test + @TestMetadata("excludePod1") + public void testExcludePod1() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1/"); + } + + @Test + @TestMetadata("excludePod1Umbrella") + public void testExcludePod1Umbrella() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/excludePod1Umbrella/"); + } + + @Test + @TestMetadata("filterPod1") + public void testFilterPod1() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1/"); + } + + @Test + @TestMetadata("filterPod1A") + public void testFilterPod1A() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1A/"); + } + + @Test + @TestMetadata("filterPod1Umbrella") + public void testFilterPod1Umbrella() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1Umbrella/"); + } + + @Test + @TestMetadata("filterPod1UmbrellaPod1A") + public void testFilterPod1UmbrellaPod1A() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/filterPod1UmbrellaPod1A/"); + } + + @Test + @TestMetadata("full") + public void testFull() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/full/"); + } + + @Test + @TestMetadata("importsAngleAngle") + public void testImportsAngleAngle() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleAngle/"); + } + + @Test + @TestMetadata("importsAngleQuote") + public void testImportsAngleQuote() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/importsAngleQuote/"); + } + + @Test + @TestMetadata("importsQuoteAngle") + public void testImportsQuoteAngle() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteAngle/"); + } + + @Test + @TestMetadata("importsQuoteQuote") + public void testImportsQuoteQuote() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/importsQuoteQuote/"); + } + + @Test + @TestMetadata("modulesPod1") + public void testModulesPod1() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/modulesPod1/"); + } + + @Test + @TestMetadata("twoChildren") + public void testTwoChildren() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/twoChildren/"); + } + + @Test + @TestMetadata("visitOtherModules") + public void testVisitOtherModules() throws Exception { + runTest("native/native.tests/testData/CInterop/framework/frameworkDefs/visitOtherModules/"); + } + } + + @Nested + @TestMetadata("native/native.tests/testData/CInterop/framework.macros/macrosDefs") + @TestDataPath("$PROJECT_ROOT") + public class MacrosDefs { + @Test + public void testAllFilesPresentInMacrosDefs() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CInterop/framework.macros/macrosDefs"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("modulesPod1") + public void testModulesPod1() throws Exception { + runTest("native/native.tests/testData/CInterop/framework.macros/macrosDefs/modulesPod1/"); + } + + @Test + @TestMetadata("myMacroType") + public void testMyMacroType() throws Exception { + runTest("native/native.tests/testData/CInterop/framework.macros/macrosDefs/myMacroType/"); + } + } + + @Nested + @TestMetadata("native/native.tests/testData/CInterop/builtins/builtinsDefs") + @TestDataPath("$PROJECT_ROOT") + public class BuiltinsDefs { + @Test + public void testAllFilesPresentInBuiltinsDefs() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/CInterop/builtins/builtinsDefs"), Pattern.compile("^([^_](.+))$"), null, false); + } + + @Test + @TestMetadata("filterA") + public void testFilterA() throws Exception { + runTest("native/native.tests/testData/CInterop/builtins/builtinsDefs/filterA/"); + } + + @Test + @TestMetadata("filterStdargH") + public void testFilterStdargH() throws Exception { + runTest("native/native.tests/testData/CInterop/builtins/builtinsDefs/filterStdargH/"); + } + + @Test + @TestMetadata("fullA") + public void testFullA() throws Exception { + runTest("native/native.tests/testData/CInterop/builtins/builtinsDefs/fullA/"); + } + + @Test + @TestMetadata("fullStdargH") + public void testFullStdargH() throws Exception { + runTest("native/native.tests/testData/CInterop/builtins/builtinsDefs/fullStdargH/"); + } + + @Test + @TestMetadata("modulesA") + public void testModulesA() throws Exception { + runTest("native/native.tests/testData/CInterop/builtins/builtinsDefs/modulesA/"); + } + } +} diff --git a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt index 426b2fa24c9..825fed95d7a 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt @@ -7,10 +7,7 @@ package org.jetbrains.kotlin.generators.tests import org.jetbrains.kotlin.generators.generateTestGroupSuiteWithJUnit5 import org.jetbrains.kotlin.generators.model.annotation -import org.jetbrains.kotlin.konan.blackboxtest.AbstractNativeBlackBoxTest -import org.jetbrains.kotlin.konan.blackboxtest.AbstractNativeCodegenBoxTest -import org.jetbrains.kotlin.konan.blackboxtest.AbstractNativeKlibABITest -import org.jetbrains.kotlin.konan.blackboxtest.AbstractNativeKlibBinaryCompatibilityTest +import org.jetbrains.kotlin.konan.blackboxtest.* import org.jetbrains.kotlin.konan.blackboxtest.support.group.UseExtTestCaseGroupProvider import org.jetbrains.kotlin.konan.blackboxtest.support.group.UseStandardTestCaseGroupProvider import org.jetbrains.kotlin.test.TargetBackend @@ -59,6 +56,31 @@ fun main() { model("binaryCompatibility/klibEvolution", recursive = false) } } + + // CInterop tests. + testGroup("native/native.tests/tests-gen", "native/native.tests/testData") { + testClass( + suiteTestClassName = "CInteropFModulesTestGenerated" + ) { + model("CInterop/simple/simpleDefs", pattern = "^([^_](.+))$", recursive = false) + model("CInterop/framework/frameworkDefs", pattern = "^([^_](.+))$", recursive = false) + model("CInterop/framework.macros/macrosDefs", pattern = "^([^_](.+))$", recursive = false) + model("CInterop/builtins/builtinsDefs", pattern = "^([^_](.+))$", recursive = false) + } + testClass( + suiteTestClassName = "CInteropNoFModulesTestGenerated" + ) { + model("CInterop/simple/simpleDefs", pattern = "^([^_](.+))$", recursive = false) + model("CInterop/framework/frameworkDefs", pattern = "^([^_](.+))$", recursive = false) + model("CInterop/framework.macros/macrosDefs", pattern = "^([^_](.+))$", recursive = false) + model("CInterop/builtins/builtinsDefs", pattern = "^([^_](.+))$", recursive = false) + } + testClass( + suiteTestClassName = "CInteropKT39120TestGenerated" + ) { + model("CInterop/KT-39120/defs", pattern = "^([^_](.+))$", recursive = false) + } + } } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropBaseTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropBaseTest.kt new file mode 100644 index 00000000000..806353af292 --- /dev/null +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropBaseTest.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan.blackboxtest + +import org.jetbrains.kotlin.konan.blackboxtest.support.* +import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.* +import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationArtifact.* +import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationResult.Companion.assertSuccess +import org.jetbrains.kotlin.konan.blackboxtest.support.runner.* +import org.jetbrains.kotlin.konan.blackboxtest.support.settings.* +import java.io.File + +abstract class AbstractNativeCInteropBaseTest : AbstractNativeSimpleTest() { + private val buildDir: File get() = testRunSettings.get().testBuildDir + internal val targets: KotlinNativeTargets get() = testRunSettings.get() + internal val kotlinNativeClassLoader: KotlinNativeClassLoader get() = testRunSettings.get() + + internal fun TestCase.cinteropToLibrary(): TestCompilationResult.Success { + modules.singleOrNull() + val compilation = CInteropCompilation( + classLoader = testRunSettings.get(), + targets = targets, + freeCompilerArgs = freeCompilerArgs, + defFile = modules.singleOrNull()!!.files.singleOrNull()!!.location, + expectedArtifact = toLibraryArtifact() + ) + return compilation.result.assertSuccess() + } + + private fun TestCase.toLibraryArtifact() = KLIB(buildDir.resolve(modules.singleOrNull()!!.name + ".klib")) + + internal fun generateCInteropTestCaseWithSingleDef(defFile: File, extraArgs: List): TestCase { + val moduleName: String = defFile.name + val module = TestModule.Exclusive(moduleName, emptySet(), emptySet()) + module.files += TestFile.createCommitted(defFile, module) + + return TestCase( + id = TestCaseId.Named(moduleName), + kind = TestKind.STANDALONE, + modules = setOf(module), + freeCompilerArgs = TestCompilerArgs(extraArgs), + nominalPackageName = PackageName.EMPTY, + checks = TestRunChecks.Default(testRunSettings.get().executionTimeout), + extras = TestCase.WithTestRunnerExtras(TestRunnerType.DEFAULT) + ).apply { + initialize(null, null) + } + } +} diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropKT39120Test.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropKT39120Test.kt new file mode 100644 index 00000000000..97b82818032 --- /dev/null +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropKT39120Test.kt @@ -0,0 +1,59 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan.blackboxtest + +import com.intellij.openapi.util.text.StringUtilRt +import com.intellij.testFramework.TestDataFile +import org.jetbrains.kotlin.konan.blackboxtest.support.* +import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.* +import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationArtifact.* +import org.jetbrains.kotlin.konan.blackboxtest.support.settings.* +import org.jetbrains.kotlin.konan.blackboxtest.support.util.* +import org.junit.jupiter.api.Tag +import org.jetbrains.kotlin.konan.blackboxtest.support.runner.* +import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals +import org.junit.jupiter.api.Assumptions + +@Tag("cinterop") +abstract class AbstractNativeCInteropKT39120Test : AbstractNativeCInteropBaseTest() { + + @Synchronized + protected fun runTest(@TestDataFile testPath: String) { + // KT-39120 is about Objective-C, so this test is for Apple hosts/targets only + Assumptions.assumeTrue(targets.hostTarget.family.isAppleFamily && targets.testTarget.family.isAppleFamily) + + val testPathFull = getAbsoluteFile(testPath) + val testDataDir = testPathFull.parentFile.parentFile + val def1File = testPathFull.resolve("pod1.def") + val def2File = testPathFull.resolve("pod2.def") + val golden1File = testPathFull.resolve("pod1.contents.gold.txt") + val golden2File = testPathFull.resolve("pod2.contents.gold.txt") + + val includeFrameworkArgs = listOf("-compiler-option", "-F${testDataDir.canonicalPath}") + + val test1Case: TestCase = generateCInteropTestCaseWithSingleDef(def1File, includeFrameworkArgs) + val klib1: KLIB = test1Case.cinteropToLibrary().resultingArtifact + val contents1 = klib1.getContents(kotlinNativeClassLoader.classLoader) + + val expectedFiltered1Output = golden1File.readText() + val actualFiltered1Output = filterContentsOutput(contents1, " pod.Version|POD|class Pod") + assertEquals(StringUtilRt.convertLineSeparators(expectedFiltered1Output), StringUtilRt.convertLineSeparators(actualFiltered1Output)) + + val cinterop2ExtraArgs = listOf("-l", klib1.klibFile.canonicalPath, "-compiler-option", "-fmodules") + val test2Case: TestCase = generateCInteropTestCaseWithSingleDef(def2File, includeFrameworkArgs + cinterop2ExtraArgs) + val klib2: KLIB = test2Case.cinteropToLibrary().resultingArtifact + val contents2 = klib2.getContents(kotlinNativeClassLoader.classLoader) + + val expectedFiltered2Output = golden2File.readText() + val actualFiltered2Output = filterContentsOutput(contents2, " pod.Version|POD|class Pod") + assertEquals(StringUtilRt.convertLineSeparators(expectedFiltered2Output), StringUtilRt.convertLineSeparators(actualFiltered2Output)) + } + + private fun filterContentsOutput(contents: String, pattern: String) = + contents.split("\n").filter { + it.contains(Regex(pattern)) + }.joinToString(separator = "\n") +} diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropTest.kt new file mode 100644 index 00000000000..082fbe2656f --- /dev/null +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeCInteropTest.kt @@ -0,0 +1,113 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan.blackboxtest + +import com.intellij.openapi.util.text.StringUtilRt +import com.intellij.testFramework.TestDataFile +import org.jetbrains.kotlin.konan.blackboxtest.support.* +import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.* +import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationArtifact.* +import org.jetbrains.kotlin.konan.blackboxtest.support.runner.* +import org.jetbrains.kotlin.konan.blackboxtest.support.settings.* +import org.jetbrains.kotlin.konan.blackboxtest.support.util.* +import org.jetbrains.kotlin.konan.target.Family +import org.jetbrains.kotlin.konan.target.KonanTarget +import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals +import org.junit.jupiter.api.Assumptions +import org.junit.jupiter.api.Tag +import java.io.File + +abstract class AbstractNativeCInteropFModulesTest : AbstractNativeCInteropTest() { + override val fmodules = true +} + +abstract class AbstractNativeCInteropNoFModulesTest : AbstractNativeCInteropTest() { + override val fmodules = false +} + +@Tag("cinterop") +abstract class AbstractNativeCInteropTest : AbstractNativeCInteropBaseTest() { + abstract val fmodules: Boolean + + @Synchronized + protected fun runTest(@TestDataFile testPath: String) { + // FIXME: check the following failures under Android with -fmodules + // fatal error: could not build module 'std' + Assumptions.assumeFalse( + this is AbstractNativeCInteropFModulesTest && + targets.testTarget.family == Family.ANDROID + ) + Assumptions.assumeFalse(!fmodules && testPath.endsWith("FModules/")) + + val testPathFull = getAbsoluteFile(testPath) + val testDataDir = testPathFull.parentFile.parentFile + val includeFolder = testDataDir.resolve("include") + val defFile = testPathFull.resolve("pod1.def") + val defContents = defFile.readText().split("\n").map { it.trim() } + val defHasObjC = defContents.any { it.endsWith("Objective-C") } + Assumptions.assumeFalse(defHasObjC && !targets.testTarget.family.isAppleFamily) + + val defHasHeaders = defContents.any { it.startsWith("headers") } + Assumptions.assumeFalse(fmodules && defHasHeaders) + + val goldenFile = if (testDataDir.name == "builtins") + getBuiltinsGoldenFile(testPathFull) + else + getGoldenFile(testPathFull) + val fmodulesArgs = if (fmodules) listOf("-compiler-option", "-fmodules") else listOf() + val includeArgs = if (testDataDir.name.startsWith("framework")) + listOf("-compiler-option", "-F${testDataDir.canonicalPath}") + else + listOf("-compiler-option", "-I${includeFolder.canonicalPath}") + + val testCase: TestCase = generateCInteropTestCaseWithSingleDef(defFile, includeArgs + fmodulesArgs) + val testCompilationResult = testCase.cinteropToLibrary() + val klibContents = testCompilationResult.resultingArtifact.getContents(kotlinNativeClassLoader.classLoader) + + val expectedContents = goldenFile.readText() + assertEquals(StringUtilRt.convertLineSeparators(expectedContents), StringUtilRt.convertLineSeparators(klibContents)) { + "Test failed. CInterop compilation result was: $testCompilationResult" + } + } + + private fun getGoldenFile(testPathFull: File): File { + return testPathFull.resolve("contents.gold.txt") + } + + private fun getBuiltinsGoldenFile(testPathFull: File): File { + val goldenFilePart = when (targets.testTarget) { + KonanTarget.ANDROID_ARM32 -> "ARM32" + KonanTarget.ANDROID_ARM64 -> "ARM64" + KonanTarget.ANDROID_X64 -> "X64" + KonanTarget.ANDROID_X86 -> "CPointerByteVar" + KonanTarget.IOS_ARM32 -> "COpaquePointer" + KonanTarget.IOS_ARM64 -> "CPointerByteVar" + KonanTarget.IOS_SIMULATOR_ARM64 -> "CPointerByteVar" + KonanTarget.IOS_X64 -> "X64" + KonanTarget.LINUX_ARM32_HFP -> "ARM32" + KonanTarget.LINUX_ARM64 -> "ARM64" + KonanTarget.LINUX_MIPS32 -> "COpaquePointer" + KonanTarget.LINUX_MIPSEL32 -> "COpaquePointer" + KonanTarget.LINUX_X64 -> "X64" + KonanTarget.MACOS_ARM64 -> "CPointerByteVar" + KonanTarget.MACOS_X64 -> "X64" + KonanTarget.MINGW_X64 -> "CPointerByteVar" + KonanTarget.MINGW_X86 -> "CPointerByteVar" + KonanTarget.TVOS_ARM64 -> "CPointerByteVar" + KonanTarget.TVOS_SIMULATOR_ARM64 -> "CPointerByteVar" + KonanTarget.TVOS_X64 -> "X64" + KonanTarget.WASM32 -> "COpaquePointer" + KonanTarget.WATCHOS_ARM32 -> "CPointerByteVar" + KonanTarget.WATCHOS_ARM64 -> "CPointerByteVar" + KonanTarget.WATCHOS_DEVICE_ARM64 -> "CPointerByteVar" + KonanTarget.WATCHOS_SIMULATOR_ARM64 -> "CPointerByteVar" + KonanTarget.WATCHOS_X64 -> "X64" + KonanTarget.WATCHOS_X86 -> "CPointerByteVar" + is KonanTarget.ZEPHYR -> "COpaquePointer" + } + return testPathFull.resolve("contents.gold.${goldenFilePart}.txt") + } +} diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt index 137f3cd2b18..946125bc60d 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt @@ -83,31 +83,47 @@ internal abstract class LoggedData { abstract class CompilerCall : LoggedData() - class RealCompilerCall( - private val parameters: CompilerParameters, + class CInteropParameters( + private val extraArgs: Array, + private val defFile: File, + private val environment: JVMEnvironment = JVMEnvironment() // Capture environment. + ) : LoggedData() { + override fun computeText() = buildString { + appendArguments("CINTEROP INVOCATION EXTRA ARGUMENTS:", extraArgs.toList()) + appendLine() + appendLine(environment) + + appendLine() + appendLine("TEST DEF FILE: ${defFile.canonicalPath}") + } + } + + class CompilationToolCall( + private val toolName: String, + private val parameters: LoggedData, private val exitCode: ExitCode, - private val compilerOutput: String, - private val compilerOutputHasErrors: Boolean, + private val toolOutput: String, + private val toolOutputHasErrors: Boolean, private val duration: Duration ) : CompilerCall() { override fun computeText(): String { val problems = listOfNotNull( "- Non-zero exit code".takeIf { exitCode != ExitCode.OK }, - "- Errors reported by the compiler".takeIf { compilerOutputHasErrors } + "- Errors reported by the $toolName".takeIf { toolOutputHasErrors } ) return buildString { if (problems.isNotEmpty()) { - appendLine("COMPILATION PROBLEMS:") + appendLine("$toolName PROBLEMS:") problems.forEach(::appendLine) appendLine() } - appendLine("COMPILER CALL:") + appendLine("$toolName CALL:") appendLine("- Exit code: ${exitCode.code} (${exitCode.name})") appendDuration(duration) appendLine() - appendPotentiallyLargeOutput(compilerOutput, "RAW COMPILER OUTPUT", truncateLargeOutput = false) + appendPotentiallyLargeOutput(toolOutput, "RAW $toolName OUTPUT", truncateLargeOutput = false) appendLine() appendLine(parameters) } @@ -118,10 +134,10 @@ internal abstract class LoggedData { override fun computeText() = "No compiler call performed for external (given) artifact $artifactFile" } - class CompilerCallUnexpectedFailure(parameters: CompilerParameters, throwable: Throwable) : UnexpectedFailure(parameters, throwable) + class CompilationToolCallUnexpectedFailure(parameters: LoggedData, throwable: Throwable) : UnexpectedFailure(parameters, throwable) class TestRunParameters( - private val compilerCall: CompilerCall, + private val compilationToolCall: CompilerCall, private val testCaseId: TestCaseId?, private val runArgs: Iterable, private val runParameters: List? @@ -151,7 +167,7 @@ internal abstract class LoggedData { appendLine(expectedOutputDataFile) appendLine() } - appendLine(compilerCall) + appendLine(compilationToolCall) } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/CompilerCall.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/CompilationToolCall.kt similarity index 50% rename from native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/CompilerCall.kt rename to native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/CompilationToolCall.kt index 42ee9b7a624..ba60b12ff57 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/CompilerCall.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/CompilationToolCall.kt @@ -10,13 +10,23 @@ import org.jetbrains.kotlin.cli.common.messages.* import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl import org.jetbrains.kotlin.compilerRunner.processCompilerOutput import org.jetbrains.kotlin.config.Services +import org.jetbrains.kotlin.konan.blackboxtest.support.settings.KotlinNativeTargets import java.io.ByteArrayOutputStream +import java.io.File import java.io.PrintStream import kotlin.time.Duration import kotlin.time.ExperimentalTime import kotlin.time.measureTime +import org.jetbrains.kotlin.konan.file.File as KonanFile -internal fun callCompiler(compilerArgs: Array, kotlinNativeClassLoader: ClassLoader): CompilerCallResult { +internal data class CompilationToolCallResult( + val exitCode: ExitCode, + val toolOutput: String, + val toolOutputHasErrors: Boolean, + val duration: Duration +) + +internal fun callCompiler(compilerArgs: Array, kotlinNativeClassLoader: ClassLoader): CompilationToolCallResult { val compilerXmlOutput: ByteArrayOutputStream val exitCode: ExitCode @@ -60,12 +70,50 @@ internal fun callCompiler(compilerArgs: Array, kotlinNativeClassLoader: compilerOutput = outputStream.toString(Charsets.UTF_8.name()) } - return CompilerCallResult(exitCode, compilerOutput, messageCollector.hasErrors(), duration) + return CompilationToolCallResult(exitCode, compilerOutput, messageCollector.hasErrors(), duration) } -internal data class CompilerCallResult( - val exitCode: ExitCode, - val compilerOutput: String, - val compilerOutputHasErrors: Boolean, - val duration: Duration -) +internal fun invokeCInterop( + kotlinNativeClassLoader: ClassLoader, + targets: KotlinNativeTargets, + inputDef: File, + outputLib: File, + extraArgs: Array +): CompilationToolCallResult { + val args = arrayOf("-o", outputLib.canonicalPath, "-def", inputDef.canonicalPath, "-no-default-libs", "-target", targets.testTarget.name) + val buildDir = KonanFile("${outputLib.canonicalPath}-build") + val generatedDir = KonanFile(buildDir, "kotlin") + val nativesDir = KonanFile(buildDir, "natives") + val manifest = KonanFile(buildDir, "manifest.properties") + val cstubsName = "cstubs" + + val interopClass = Class.forName("org.jetbrains.kotlin.native.interop.gen.jvm.Interop", true, kotlinNativeClassLoader) + val entryPoint = interopClass.declaredMethods.single { it.name == "interopViaReflection" } + + val possibleSubsequentCompilerInvocationArgs: Array? + + @OptIn(ExperimentalTime::class) + val duration = measureTime { + @Suppress("UNCHECKED_CAST") + possibleSubsequentCompilerInvocationArgs = entryPoint.invoke( + interopClass.getDeclaredConstructor().newInstance(), + "native", + args + extraArgs, + false, + generatedDir.absolutePath, nativesDir.absolutePath, manifest.path, cstubsName // args for InternalInteropOptions() + ) as? Array? + } + // In currently tested usecases, cinterop must return no args for the subsequent compiler call + return if (possibleSubsequentCompilerInvocationArgs == null) { + // TODO There is no technical ability to extract `toolOutput` and `toolOutputHasErrors` + // from C-interop tool invocation at the moment. This should be fixed in the future. + CompilationToolCallResult(exitCode = ExitCode.OK, toolOutput = "", toolOutputHasErrors = false, duration) + } else { + CompilationToolCallResult( + exitCode = ExitCode.COMPILATION_ERROR, + toolOutput = possibleSubsequentCompilerInvocationArgs.joinToString(" "), + toolOutputHasErrors = true, + duration + ) + } +} diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt index c234120fb5e..407ab3e5685 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt @@ -88,17 +88,17 @@ internal abstract class BasicCompilation( kotlinNativeClassLoader = classLoader.classLoader ) - val loggedCompilerCall = - LoggedData.RealCompilerCall(loggedCompilerParameters, exitCode, compilerOutput, compilerOutputHasErrors, duration) + val loggedCompilationToolCall = + LoggedData.CompilationToolCall("COMPILER", loggedCompilerParameters, exitCode, compilerOutput, compilerOutputHasErrors, duration) val result = if (exitCode != ExitCode.OK || compilerOutputHasErrors) - TestCompilationResult.CompilerFailure(loggedCompilerCall) + TestCompilationResult.CompilationToolFailure(loggedCompilationToolCall) else - TestCompilationResult.Success(expectedArtifact, loggedCompilerCall) + TestCompilationResult.Success(expectedArtifact, loggedCompilationToolCall) - loggedCompilerCall to result + loggedCompilationToolCall to result } catch (unexpectedThrowable: Throwable) { - val loggedFailure = LoggedData.CompilerCallUnexpectedFailure(loggedCompilerParameters, unexpectedThrowable) + val loggedFailure = LoggedData.CompilationToolCallUnexpectedFailure(loggedCompilerParameters, unexpectedThrowable) val result = TestCompilationResult.UnexpectedFailure(loggedFailure) loggedFailure to result @@ -189,6 +189,52 @@ internal class GivenLibraryCompilation(givenArtifact: KLIB) : TestCompilation() { + + override val result: TestCompilationResult by lazy { + val extraArgsArray = freeCompilerArgs.compilerArgs.toTypedArray() + val loggedCInteropParameters = LoggedData.CInteropParameters(extraArgs = extraArgsArray, defFile = defFile) + val (loggedCall: LoggedData, immediateResult: TestCompilationResult.ImmediateResult) = try { + val (exitCode, cinteropOutput, cinteropOutputHasErrors, duration) = invokeCInterop( + classLoader.classLoader, + targets, + defFile, + expectedArtifact.klibFile, + extraArgsArray + ) + + val loggedInteropCall = LoggedData.CompilationToolCall( + toolName = "CINTEROP", + parameters = loggedCInteropParameters, + exitCode = exitCode, + toolOutput = cinteropOutput, + toolOutputHasErrors = cinteropOutputHasErrors, + duration = duration + ) + val res = if (exitCode != ExitCode.OK || cinteropOutputHasErrors) + TestCompilationResult.CompilationToolFailure(loggedInteropCall) + else + TestCompilationResult.Success(expectedArtifact, loggedInteropCall) + + loggedInteropCall to res + } catch (unexpectedThrowable: Throwable) { + val loggedFailure = LoggedData.CompilationToolCallUnexpectedFailure(loggedCInteropParameters, unexpectedThrowable) + val res = TestCompilationResult.UnexpectedFailure(loggedFailure) + + loggedFailure to res + } + expectedArtifact.logFile.writeText(loggedCall.toString()) + + immediateResult + } +} + internal class ExecutableCompilation( settings: Settings, freeCompilerArgs: TestCompilerArgs, diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationResult.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationResult.kt index d42598df830..f983a125f41 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationResult.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationResult.kt @@ -18,8 +18,8 @@ internal sealed interface TestCompilationResult { data class Success(val resultingArtifact: A, override val loggedData: LoggedData.CompilerCall) : ImmediateResult - data class CompilerFailure(override val loggedData: LoggedData.RealCompilerCall) : Failure - data class UnexpectedFailure(override val loggedData: LoggedData.CompilerCallUnexpectedFailure) : Failure + data class CompilationToolFailure(override val loggedData: LoggedData.CompilationToolCall) : Failure + data class UnexpectedFailure(override val loggedData: LoggedData) : Failure data class DependencyFailures(val causes: Set) : TestCompilationResult companion object { @@ -31,7 +31,7 @@ internal sealed interface TestCompilationResult { private fun Failure.describeFailure() = loggedData.withErrorMessage( when (this@describeFailure) { - is CompilerFailure -> "Compilation failed." + is CompilationToolFailure -> "Compilation failed." is UnexpectedFailure -> "Compilation failed with unexpected exception." } ) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestNameExtractor.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestNameExtractor.kt index 7838d77902c..ddad4c9229a 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestNameExtractor.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestNameExtractor.kt @@ -20,7 +20,7 @@ internal class LocalTestNameExtractor( override val outputFilter get() = TestOutputFilter.NO_FILTERING override fun getLoggedParameters() = LoggedData.TestRunParameters( - compilerCall = executable.loggedCompilerCall, + compilationToolCall = executable.loggedCompilationToolCall, testCaseId = null, runArgs = programArgs, runParameters = null diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestRunner.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestRunner.kt index a3edfc4d9e8..c22775b879e 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestRunner.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestRunner.kt @@ -25,7 +25,7 @@ internal class LocalTestRunner(private val testRun: TestRun) : AbstractLocalProc get() = if (testRun.runParameters.has()) TCTestOutputFilter else TestOutputFilter.NO_FILTERING override fun getLoggedParameters() = LoggedData.TestRunParameters( - compilerCall = executable.loggedCompilerCall, + compilationToolCall = executable.loggedCompilationToolCall, testCaseId = testRun.testCaseId, runArgs = programArgs, runParameters = testRun.runParameters diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/TestRun.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/TestRun.kt index 02f6c14ed09..9e2d732ee7f 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/TestRun.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/TestRun.kt @@ -18,7 +18,7 @@ import java.io.IOException internal class TestExecutable( val executableFile: File, - val loggedCompilerCall: LoggedData.CompilerCall, + val loggedCompilationToolCall: LoggedData.CompilerCall, val testNames: Collection ) { companion object { @@ -43,7 +43,7 @@ internal class TestExecutable( return TestExecutable( executableFile = compilationResult.resultingArtifact.executableFile, - loggedCompilerCall = compilationResult.loggedData, + loggedCompilationToolCall = compilationResult.loggedData, testNames = testNames ) } @@ -100,6 +100,12 @@ internal sealed interface TestRunParameter { class WithExpectedOutputData(val expectedOutputDataFile: File) : TestRunParameter { override fun applyTo(programArgs: MutableList) = Unit } + + class WithFreeCommandLineArguments(val args: List) : TestRunParameter { + override fun applyTo(programArgs: MutableList) { + programArgs += args + } + } } internal inline fun List.has(): Boolean = diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TestCompilationArtifacts.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TestCompilationArtifacts.kt new file mode 100644 index 00000000000..5c97bbba1ae --- /dev/null +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TestCompilationArtifacts.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan.blackboxtest.support.util + +import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationArtifact + +internal fun TestCompilationArtifact.KLIB.getContents(kotlinNativeClassLoader: ClassLoader): String { + val libraryClass = Class.forName("org.jetbrains.kotlin.cli.klib.Library", true, kotlinNativeClassLoader) + val entryPoint = libraryClass.declaredMethods.single { it.name == "contents" } + val lib = libraryClass.getDeclaredConstructor(String::class.java, String::class.java, String::class.java) + .newInstance(klibFile.canonicalPath, null, "host") + + val output = StringBuilder() + entryPoint.invoke(lib, output, false) + return output.toString() +}