Allow setting test binary linker options using a test compilation

#KT-29254 Fixed
This commit is contained in:
Ilya Matveev
2019-01-14 17:13:09 +07:00
parent 2157c777b3
commit ac1b4cf6b2
7 changed files with 38 additions and 7 deletions
@@ -117,6 +117,14 @@ class NewMultiplatformIT : BaseGradleIT() {
setupWorkingDir()
gradleBuildScript().appendText("\nrepositories { maven { setUrl(\"$libLocalRepoUri\") } }")
fun CompiledProject.checkProgramCompilationCommandLine(check: (String) -> Unit) {
output.lineSequence().filter {
it.contains("Run tool: konanc") && it.contains("-p program")
}.toList().also {
assertTrue(it.isNotEmpty())
}.forEach(check)
}
fun CompiledProject.checkAppBuild() {
assertSuccessful()
assertTasksExecuted(*compileTasksNames.toTypedArray())
@@ -154,12 +162,8 @@ class NewMultiplatformIT : BaseGradleIT() {
assertFileExists("build/bin/$nativeHostTargetName/mainReleaseExecutable/$nativeExeName")
assertFileExists("build/bin/$nativeHostTargetName/mainDebugExecutable/$nativeExeName")
// Check that linker options was correctly passed to the K/N compiler.
output.lineSequence().filter {
it.contains("Run tool: konanc") && it.contains("-p program")
}.toList().also {
assertTrue(it.isNotEmpty())
}.forEach {
// Check that linker options were correctly passed to the K/N compiler.
checkProgramCompilationCommandLine {
assertTrue(it.contains("-linker-options -L."))
}
}
@@ -30,6 +30,7 @@ kotlin {
// Check that linker options are correctly passed to the compiler.
linkerOpts = mutableListOf("-L.")
}
compilations["test"].linkerOpts = mutableListOf("-L.")
}
sourceSets {
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
private fun test() {
println("test")
}
@@ -68,6 +68,7 @@ kotlin {
compilations.main.entryPoint = "com.example.app.native.main"
// Check that linker options are correctly passed to the compiler.
compilations.main.linkerOpts = ['-L.']
compilations.test.linkerOpts = ['-L.']
}
}
}
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
private fun test() {
println("test")
}
@@ -134,7 +134,7 @@ open class KotlinNativeBinaryContainer @Inject constructor(
internal fun defaultTestExecutable(
configure: Executable.() -> Unit
) = createBinaries(
"test",
DEFAULT_TEST_NAME_PREFIX,
"test",
NativeOutputKind.EXECUTABLE,
listOf(DEFAULT_TEST_BUILD_TYPE),
@@ -144,8 +144,12 @@ open class KotlinNativeBinaryContainer @Inject constructor(
configure
)
internal fun getDefaultTestExecutable(): Executable =
getExecutable(DEFAULT_TEST_NAME_PREFIX, DEFAULT_TEST_BUILD_TYPE)
companion object {
internal val DEFAULT_TEST_BUILD_TYPE = NativeBuildType.DEBUG
internal val DEFAULT_TEST_NAME_PREFIX = "test"
internal fun generateBinaryName(prefix: String, buildType: NativeBuildType, outputKindClassifier: String) =
lowerCamelCaseName(prefix, buildType.getName(), outputKindClassifier)
@@ -664,6 +664,11 @@ open class KotlinNativeTargetConfigurator(
}
}
}
// Allow setting linker options for the default test executable using the
// corresponding properties of the test compilation.
target.binaries.getDefaultTestExecutable().apply {
linkerOpts.addAll(target.compilations.getByName(TEST_COMPILATION_NAME).linkerOpts)
}
}
}