From ac1b4cf6b2b0e0465b9bf0f6ee105ea29a82c428 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 14 Jan 2019 17:13:09 +0700 Subject: [PATCH] Allow setting test binary linker options using a test compilation #KT-29254 Fixed --- .../kotlin/gradle/NewMultiplatformIT.kt | 16 ++++++++++------ .../build.gradle.kts | 1 + .../src/commonTest/kotlin/test.kt | 8 ++++++++ .../new-mpp-lib-and-app/sample-app/build.gradle | 1 + .../sample-app/src/commonTest/kotlin/test.kt | 8 ++++++++ .../gradle/dsl/KotlinNativeBinaryContainer.kt | 6 +++++- .../gradle/plugin/KotlinTargetConfigurator.kt | 5 +++++ 7 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/src/commonTest/kotlin/test.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/src/commonTest/kotlin/test.kt diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt index a3743259da5..7d85b1d1f6a 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt @@ -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.")) } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/build.gradle.kts index c97f793a3ea..af9db921fb7 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/build.gradle.kts @@ -30,6 +30,7 @@ kotlin { // Check that linker options are correctly passed to the compiler. linkerOpts = mutableListOf("-L.") } + compilations["test"].linkerOpts = mutableListOf("-L.") } sourceSets { diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/src/commonTest/kotlin/test.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/src/commonTest/kotlin/test.kt new file mode 100644 index 00000000000..13c5431a5ca --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/src/commonTest/kotlin/test.kt @@ -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") +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/build.gradle index 06b3a816e71..208c599eb71 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/build.gradle @@ -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.'] } } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/src/commonTest/kotlin/test.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/src/commonTest/kotlin/test.kt new file mode 100644 index 00000000000..13c5431a5ca --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/src/commonTest/kotlin/test.kt @@ -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") +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinNativeBinaryContainer.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinNativeBinaryContainer.kt index 24832cda6f4..2ae29ff930b 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinNativeBinaryContainer.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinNativeBinaryContainer.kt @@ -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) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt index 9a7af32165c..3ba6c280ff4 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt @@ -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) + } } }