Use toolchain clang for runtime tests on mac (#4632)
This commit is contained in:
committed by
Nikolay Krasko
parent
3eb2ec5cc1
commit
aed23ff098
@@ -50,6 +50,22 @@ class ExecClang(private val project: Project) {
|
||||
}
|
||||
}
|
||||
|
||||
fun resolveToolchainExecutable(target: KonanTarget, executableOrNull: String?): String {
|
||||
val executable = executableOrNull ?: "clang"
|
||||
|
||||
if (listOf("clang", "clang++").contains(executable)) {
|
||||
// TODO: This is copied from `BitcodeCompiler`. Consider sharing the code instead.
|
||||
val platform = platformManager.platform(target)
|
||||
return if (target.family.isAppleFamily) {
|
||||
"${platform.absoluteTargetToolchain}/usr/bin/$executable"
|
||||
} else {
|
||||
"${platform.absoluteTargetToolchain}/bin/$executable"
|
||||
}
|
||||
} else {
|
||||
throw GradleException("unsupported clang executable: $executable")
|
||||
}
|
||||
}
|
||||
|
||||
// The bare ones invoke clang with system default sysroot.
|
||||
|
||||
fun execBareClang(action: Action<in ExecSpec>): ExecResult {
|
||||
@@ -81,6 +97,30 @@ class ExecClang(private val project: Project) {
|
||||
return this.execClang(konanArgs(target), closure)
|
||||
}
|
||||
|
||||
// The toolchain ones execute clang from the toolchain.
|
||||
|
||||
fun execToolchainClang(target: String?, action: Action<in ExecSpec>): ExecResult {
|
||||
return this.execToolchainClang(platformManager.targetManager(target).target, action)
|
||||
}
|
||||
|
||||
fun execToolchainClang(target: String?, closure: Closure<in ExecSpec>): ExecResult {
|
||||
return this.execToolchainClang(platformManager.targetManager(target).target, ConfigureUtil.configureUsing(closure))
|
||||
}
|
||||
|
||||
fun execToolchainClang(target: KonanTarget, action: Action<in ExecSpec>): ExecResult {
|
||||
val extendedAction = Action<ExecSpec> { execSpec ->
|
||||
action.execute(execSpec)
|
||||
execSpec.apply {
|
||||
executable = resolveToolchainExecutable(target, executable)
|
||||
}
|
||||
}
|
||||
return project.exec(extendedAction)
|
||||
}
|
||||
|
||||
fun execToolchainClang(target: KonanTarget, closure: Closure<in ExecSpec>): ExecResult {
|
||||
return this.execToolchainClang(target, ConfigureUtil.configureUsing(closure))
|
||||
}
|
||||
|
||||
// These ones are private, so one has to choose either Bare or Konan.
|
||||
|
||||
private fun execClang(defaultArgs: List<String>, closure: Closure<in ExecSpec>): ExecResult {
|
||||
|
||||
+13
-6
@@ -17,10 +17,10 @@ import org.jetbrains.kotlin.konan.target.*
|
||||
|
||||
open class CompileNativeTest @Inject constructor(
|
||||
@InputFile val inputFile: File,
|
||||
@Input val target: String
|
||||
@Input val target: KonanTarget,
|
||||
) : DefaultTask() {
|
||||
@OutputFile
|
||||
var outputFile = project.buildDir.resolve("bin/test/$target/${inputFile.nameWithoutExtension}.o")
|
||||
var outputFile = project.buildDir.resolve("bin/test/${target.name}/${inputFile.nameWithoutExtension}.o")
|
||||
|
||||
@Input
|
||||
val clangArgs = mutableListOf<String>()
|
||||
@@ -28,9 +28,16 @@ open class CompileNativeTest @Inject constructor(
|
||||
@TaskAction
|
||||
fun compile() {
|
||||
val plugin = project.convention.getPlugin(ExecClang::class.java)
|
||||
plugin.execBareClang {
|
||||
it.executable = "clang++"
|
||||
it.args = clangArgs + listOf(inputFile.absolutePath, "-o", outputFile.absolutePath)
|
||||
if (target.family.isAppleFamily) {
|
||||
plugin.execToolchainClang(target) {
|
||||
it.executable = "clang++"
|
||||
it.args = clangArgs + listOf(inputFile.absolutePath, "-o", outputFile.absolutePath)
|
||||
}
|
||||
} else {
|
||||
plugin.execBareClang {
|
||||
it.executable = "clang++"
|
||||
it.args = clangArgs + listOf(inputFile.absolutePath, "-o", outputFile.absolutePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,7 +225,7 @@ fun createTestTask(
|
||||
"${testTaskName}Compile",
|
||||
CompileNativeTest::class.java,
|
||||
llvmLinkTask.outputFile,
|
||||
target
|
||||
konanTarget,
|
||||
).apply {
|
||||
dependsOn(llvmLinkTask)
|
||||
clangArgs.addAll(clangFlags.clangFlags)
|
||||
|
||||
Reference in New Issue
Block a user