Fix clang invocation in the tests: use linker with the same options as the build. (#4499)
Fix clang invocation in the tests: use linker with the same options as the build.
This commit is contained in:
committed by
Stanislav Erokhin
parent
c98d68fe85
commit
ab02bbcc37
@@ -88,18 +88,15 @@ class ExecClang(private val project: Project) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun execClang(defaultArgs: List<String>, action: Action<in ExecSpec>): ExecResult {
|
private fun execClang(defaultArgs: List<String>, action: Action<in ExecSpec>): ExecResult {
|
||||||
val extendedAction = object : Action<ExecSpec> {
|
val extendedAction = Action<ExecSpec> { execSpec ->
|
||||||
override fun execute(execSpec: ExecSpec) {
|
action.execute(execSpec)
|
||||||
action.execute(execSpec)
|
execSpec.apply {
|
||||||
|
executable = resolveExecutable(executable)
|
||||||
|
|
||||||
execSpec.apply {
|
val hostPlatform = project.findProperty("hostPlatform") as Platform
|
||||||
executable = resolveExecutable(executable)
|
environment["PATH"] = project.files(hostPlatform.clang.clangPaths).asPath +
|
||||||
|
java.io.File.pathSeparator + environment["PATH"]
|
||||||
val hostPlatform = project.findProperty("hostPlatform") as Platform
|
args = args + defaultArgs
|
||||||
environment["PATH"] = project.files(hostPlatform.clang.clangPaths).asPath +
|
|
||||||
java.io.File.pathSeparator + environment["PATH"]
|
|
||||||
args(defaultArgs)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return project.exec(extendedAction)
|
return project.exec(extendedAction)
|
||||||
|
|||||||
+31
-10
@@ -14,13 +14,13 @@ import org.gradle.api.tasks.Input
|
|||||||
import org.gradle.api.tasks.Optional
|
import org.gradle.api.tasks.Optional
|
||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.tasks.TaskAction
|
||||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||||
import org.gradle.process.ExecSpec
|
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
|
import org.jetbrains.kotlin.konan.target.LinkerOutputKind
|
||||||
|
|
||||||
abstract class KonanTest : DefaultTask(), KonanTestExecutable {
|
abstract class KonanTest : DefaultTask(), KonanTestExecutable {
|
||||||
enum class Logger {
|
enum class Logger {
|
||||||
@@ -439,25 +439,46 @@ open class KonanDynamicTest : KonanStandaloneTest() {
|
|||||||
private fun clang() {
|
private fun clang() {
|
||||||
val log = ByteArrayOutputStream()
|
val log = ByteArrayOutputStream()
|
||||||
val plugin = project.convention.getPlugin(ExecClang::class.java)
|
val plugin = project.convention.getPlugin(ExecClang::class.java)
|
||||||
val execResult = plugin.execKonanClang(project.testTarget, Action<ExecSpec> {
|
val artifactsDir = "$outputDirectory/${project.testTarget}"
|
||||||
|
|
||||||
|
fun flagsContain(opt: String) = project.globalTestArgs.contains(opt) || flags.contains(opt)
|
||||||
|
val isOpt = flagsContain("-opt")
|
||||||
|
val isDebug = flagsContain("-g")
|
||||||
|
|
||||||
|
val execResult = plugin.execKonanClang(project.testTarget) {
|
||||||
it.workingDir = File(outputDirectory)
|
it.workingDir = File(outputDirectory)
|
||||||
it.executable = clangTool
|
it.executable = clangTool
|
||||||
val artifactsDir = "$outputDirectory/${project.testTarget}"
|
|
||||||
it.args = listOf(processCSource(),
|
it.args = listOf(processCSource(),
|
||||||
"-o", executable,
|
"-c",
|
||||||
"-I", artifactsDir,
|
"-o", "$executable.o",
|
||||||
"-L", artifactsDir,
|
"-I", artifactsDir
|
||||||
"-l", name,
|
)
|
||||||
"-Wl,-rpath,$artifactsDir")
|
|
||||||
|
|
||||||
it.standardOutput = log
|
it.standardOutput = log
|
||||||
it.errorOutput = log
|
it.errorOutput = log
|
||||||
it.isIgnoreExitValue = true
|
it.isIgnoreExitValue = true
|
||||||
})
|
}
|
||||||
log.toString("UTF-8").also {
|
log.toString("UTF-8").also {
|
||||||
project.file("$executable.compilation.log").writeText(it)
|
project.file("$executable.compilation.log").writeText(it)
|
||||||
println(it)
|
println(it)
|
||||||
}
|
}
|
||||||
execResult.assertNormalExitValue()
|
execResult.assertNormalExitValue()
|
||||||
|
|
||||||
|
val linker = project.platformManager.platform(project.testTarget).linker
|
||||||
|
val commands = linker.finalLinkCommands(
|
||||||
|
objectFiles = listOf("$executable.o"),
|
||||||
|
executable = executable,
|
||||||
|
libraries = listOf("-l$name"),
|
||||||
|
linkerArgs = listOf("-L", artifactsDir, "-rpath", artifactsDir),
|
||||||
|
optimize = isOpt,
|
||||||
|
debug = isDebug,
|
||||||
|
kind = LinkerOutputKind.EXECUTABLE,
|
||||||
|
outputDsymBundle = "",
|
||||||
|
needsProfileLibrary = false,
|
||||||
|
mimallocEnabled = false
|
||||||
|
)
|
||||||
|
commands.forEach {
|
||||||
|
it.logWith { message -> project.file("$executable.compilation.log").appendText(message()) }
|
||||||
|
it.execute()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user