[Native][tests] Extract Clang invocation to a separate function

This commit is contained in:
Sergey Bogolepov
2023-12-05 10:21:17 +02:00
committed by Space Team
parent e311b95893
commit 13618fc03b
2 changed files with 39 additions and 16 deletions
@@ -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(
@@ -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<File>,
outputFile: File,
frameworkDirectories: List<File>
) {
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() }
}