diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/ObjCToKotlinSteppingInLLDBTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/ObjCToKotlinSteppingInLLDBTest.kt index be7f8d03e49..f61f6426e19 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/ObjCToKotlinSteppingInLLDBTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/ObjCToKotlinSteppingInLLDBTest.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.konan.test.blackbox.support.settings.PipelineType import org.jetbrains.kotlin.konan.test.blackbox.support.settings.Timeouts import org.jetbrains.kotlin.konan.test.blackbox.support.settings.configurables import org.jetbrains.kotlin.konan.test.blackbox.support.util.LLDBSessionSpec +import org.jetbrains.kotlin.konan.test.blackbox.support.util.compileWithClang import org.junit.jupiter.api.Assumptions import org.junit.jupiter.api.Test import java.io.File @@ -222,22 +223,11 @@ class ObjCToKotlinSteppingInLLDBTest : AbstractNativeSimpleTest() { val clangExecutableName = "clangMain" val executableFile = File(buildDir, clangExecutableName) - // FIXME: absoluteTargetToolchain might not work correctly with KONAN_USE_INTERNAL_SERVER because - // :kotlin-native:dependencies:update is not a dependency of :native:native.tests:test where this test runs - val process = ProcessBuilder( - "${testRunSettings.configurables.absoluteTargetToolchain}/bin/clang", - clangFile.absolutePath, - "-isysroot", testRunSettings.configurables.absoluteTargetSysRoot, - "-target", testRunSettings.configurables.targetTriple.toString(), - "-g", "-fmodules", - "-F", buildDir.absolutePath, - "-o", executableFile.absolutePath - ).redirectErrorStream(true).start() - val clangOutput = process.inputStream.readBytes() - - check( - process.waitFor() == 0 - ) { clangOutput.decodeToString() } + compileWithClang( + sourceFiles = listOf(clangFile), + outputFile = executableFile, + frameworkDirectories = listOf(buildDir), + ) // 4. Generate the test case val testExecutable = TestExecutable( diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/util/Clang.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/util/Clang.kt new file mode 100644 index 00000000000..a3b46b95fbd --- /dev/null +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/util/Clang.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2023 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.test.blackbox.support.util + +import org.jetbrains.kotlin.konan.test.blackbox.AbstractNativeSimpleTest +import org.jetbrains.kotlin.konan.test.blackbox.support.settings.configurables +import java.io.File + +// FIXME: absoluteTargetToolchain might not work correctly with KONAN_USE_INTERNAL_SERVER because +// :kotlin-native:dependencies:update is not a dependency of :native:native.tests:test where this test runs +internal fun AbstractNativeSimpleTest.compileWithClang( + sourceFiles: List, + outputFile: File, + frameworkDirectories: List +) { + val process = ProcessBuilder( + "${testRunSettings.configurables.absoluteTargetToolchain}/bin/clang", + *sourceFiles.map { it.absolutePath }.toTypedArray(), + "-isysroot", testRunSettings.configurables.absoluteTargetSysRoot, + "-target", testRunSettings.configurables.targetTriple.toString(), + "-g", "-fmodules", + *frameworkDirectories.flatMap { listOf("-F", it.absolutePath) }.toTypedArray(), + "-o", outputFile.absolutePath + ).redirectErrorStream(true).start() + val clangOutput = process.inputStream.readBytes() + + check( + process.waitFor() == 0 + ) { clangOutput.decodeToString() } +} \ No newline at end of file