From 95429b52f986e2eae26e3c3ffb73ace3b2be8f50 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Fri, 9 Feb 2024 14:13:32 +0200 Subject: [PATCH] [Native][Tests] Generalise SwiftCompilation We will produce dynamic libraries in case of Swift export tests, and we don't need some flags there as well. --- .../kotlin/konan/test/blackbox/FrameworkTest.kt | 9 +++++++-- .../support/compilation/TestCompilation.kt | 17 +++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/FrameworkTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/FrameworkTest.kt index dad978feed2..c19d87a4eb4 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/FrameworkTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/FrameworkTest.kt @@ -471,7 +471,11 @@ abstract class FrameworkTestBase : AbstractNativeSimpleTest() { """.trimMargin() ) } - + val frameworkOpts = listOf( + "-Xlinker", "-rpath", "-Xlinker", "@executable_path/Frameworks", + "-Xlinker", "-rpath", "-Xlinker", buildDir.absolutePath, + "-F", buildDir.absolutePath + ) return SwiftCompilation( testRunSettings, testSources + listOf( @@ -479,7 +483,8 @@ abstract class FrameworkTestBase : AbstractNativeSimpleTest() { testSuiteDir.resolve("main.swift") ), TestCompilationArtifact.Executable(buildDir.resolve("swiftTestExecutable")), - swiftExtraOpts, + swiftExtraOpts + frameworkOpts, + outputFile = { executable -> executable.executableFile } ).result.assertSuccess() } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt index 02bc3a62398..37a193778f4 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt @@ -438,28 +438,25 @@ internal class CInteropCompilation( } } -internal class SwiftCompilation( +internal class SwiftCompilation( testRunSettings: Settings, sources: List, - expectedArtifact: Executable, + expectedArtifact: T, swiftExtraOpts: List, -) : TestCompilation() { - override val result: TestCompilationResult by lazy { - val buildDir = testRunSettings.get().testBinariesDir + outputFile: (T) -> File, +) : TestCompilation() { + override val result: TestCompilationResult by lazy { val configs = testRunSettings.configurables as AppleConfigurables val swiftTarget = configs.targetTriple.withOSVersion(configs.osVersionMin).toString() val args = swiftExtraOpts + sources.map { it.absolutePath } + listOf( "-sdk", configs.absoluteTargetSysRoot, "-target", swiftTarget, - "-o", expectedArtifact.executableFile.absolutePath, + "-o", outputFile(expectedArtifact).absolutePath, "-g", // TODO https://youtrack.jetbrains.com/issue/KT-65436/K-N-ObjCExport-tests-use-various-optimization-flags-for-swiftc - "-Xlinker", "-rpath", "-Xlinker", "@executable_path/Frameworks", - "-Xlinker", "-rpath", "-Xlinker", buildDir.absolutePath, - "-F", buildDir.absolutePath, "-Xcc", "-Werror", // To fail compilation on warnings in framework header. ) val loggedSwiftCParameters = LoggedData.SwiftCParameters(args, sources) - val (loggedCall: LoggedData, immediateResult: TestCompilationResult.ImmediateResult) = try { + val (loggedCall: LoggedData, immediateResult: TestCompilationResult.ImmediateResult) = try { val (exitCode, swiftcOutput, swiftcOutputHasErrors, duration) = invokeSwiftC(testRunSettings, args)