From 2ab0760e353461afbdc221d429e4df2f98273eef Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 3 Jun 2019 18:42:55 +0700 Subject: [PATCH] Gradle, native: Fix creating test binaries for non-host platforms Issue #KT-31725 fixed --- .../kotlin/gradle/NewMultiplatformIT.kt | 14 +++++-- .../new-mpp-native-tests/build.gradle | 7 +++- .../gradle/dsl/KotlinNativeBinaryContainer.kt | 4 +- .../native/KotlinNativeTargetConfigurator.kt | 37 ++++++++++--------- 4 files changed, 37 insertions(+), 25 deletions(-) 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 a3225c828c3..5e8eea3b487 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 @@ -1173,7 +1173,15 @@ class NewMultiplatformIT : BaseGradleIT() { // Check that test binaries can be accessed in a buildscript. build("checkNewGetters") { assertSuccessful() - listOf("test.$suffix", "another.$suffix").forEach { + val suffixes = listOf("exe", "kexe", "wasm") + val names = listOf("test", "another") + val files = names.flatMap { name -> + suffixes.map { suffix -> + "$name.$suffix" + } + } + + files.forEach { assertContains("Get test: $it") assertContains("Find test: $it") } @@ -1187,7 +1195,7 @@ class NewMultiplatformIT : BaseGradleIT() { |Probably you are accessing the default test binary using the 'binaries.getExecutable("test", DEBUG)' method. |Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use: | - | binaries.getTest(DEBUG) + | binaries.getTest("DEBUG") """.trimMargin() ) } @@ -1199,7 +1207,7 @@ class NewMultiplatformIT : BaseGradleIT() { |Probably you are accessing the default test binary using the 'binaries.findExecutable("test", DEBUG)' method. |Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use: | - | binaries.findTest(DEBUG) + | binaries.findTest("DEBUG") """.trimMargin() ) assertContains("Find test: null") diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-tests/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-tests/build.gradle index 7ec28a19c2b..fb057b7da07 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-tests/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-tests/build.gradle @@ -25,7 +25,10 @@ kotlin { fromPreset(presets.linuxX64, 'linux64') fromPreset(presets.mingwX64, 'mingw64') - configure([macos64, linux64, mingw64]) { + // Test creating and accessing test binaries for cross-targets + fromPreset(presets.wasm32, 'wasm') + + configure([macos64, linux64, mingw64, wasm]) { compilations.create("anotherTest") binaries { test("another", [DEBUG]) { @@ -68,7 +71,7 @@ task checkOldFind { task checkNewGetters { doLast { kotlin.targets { - configure([macos64, linux64, mingw64]) { + configure([macos64, linux64, mingw64, wasm]) { println("Get test: ${binaries.getTest(DEBUG).outputFile.name}") println("Find test: ${binaries.findTest(DEBUG).outputFile.name}") println("Get test: ${binaries.getTest("another", DEBUG).outputFile.name}") 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 96ba9f11719..18e1f894cd5 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 @@ -163,7 +163,7 @@ open class KotlinNativeBinaryContainer @Inject constructor( |Probably you are accessing the default test binary using the 'binaries.getExecutable("$DEFAULT_TEST_NAME_PREFIX", ${DEFAULT_TEST_BUILD_TYPE.name})' method. |Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use: | - | binaries.getTest(DEBUG) + | binaries.getTest("DEBUG") | """.trimMargin() @@ -172,7 +172,7 @@ open class KotlinNativeBinaryContainer @Inject constructor( |Probably you are accessing the default test binary using the 'binaries.findExecutable("$DEFAULT_TEST_NAME_PREFIX", ${DEFAULT_TEST_BUILD_TYPE.name})' method. |Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use: | - | binaries.findTest(DEBUG) + | binaries.findTest("DEBUG") | """.trimMargin() } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeTargetConfigurator.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeTargetConfigurator.kt index e9282a3520e..fc731b8f45e 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeTargetConfigurator.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeTargetConfigurator.kt @@ -232,30 +232,31 @@ open class KotlinNativeTargetConfigurator( } override fun configureTest(target: KotlinNativeTarget): Unit = with(target.project) { - // We don't create test tasks for non-host platforms. - if (target.konanTarget !in listOf(KonanTarget.MACOS_X64, KonanTarget.MINGW_X64, KonanTarget.LINUX_X64)) { - return - } - - val taskName = lowerCamelCaseName(target.disambiguationClassifier, testTaskNameSuffix) + // We create test binaries for all platforms. target.binaries.test(listOf(NativeBuildType.DEBUG)) { - val testTask = createOrRegisterTask(taskName) { testTask -> - testTask.group = LifecycleBasePlugin.VERIFICATION_GROUP - testTask.description = "Executes Kotlin/Native unit tests for target ${target.name}." - testTask.targetName = compilation.target.targetName - testTask.enabled = target.konanTarget.isCurrentHost + // But run them only on host ones. + if (target.konanTarget in listOf(KonanTarget.MACOS_X64, KonanTarget.MINGW_X64, KonanTarget.LINUX_X64)) { - testTask.executable { outputFile } - testTask.workingDir = project.projectDir.absolutePath + val taskName = lowerCamelCaseName(target.disambiguationClassifier, testTaskNameSuffix) + val testTask = createOrRegisterTask(taskName) { testTask -> + testTask.group = LifecycleBasePlugin.VERIFICATION_GROUP + testTask.description = "Executes Kotlin/Native unit tests for target ${target.name}." + testTask.targetName = compilation.target.targetName - testTask.onlyIf { outputFile.exists() } - testTask.dependsOn(linkTaskName) + testTask.enabled = target.konanTarget.isCurrentHost - testTask.configureConventions() + testTask.executable { outputFile } + testTask.workingDir = project.projectDir.absolutePath + + testTask.onlyIf { outputFile.exists() } + testTask.dependsOn(linkTaskName) + + testTask.configureConventions() + } + + kotlinTestRegistry.registerTestTask(testTask) } - - kotlinTestRegistry.registerTestTask(testTask) } }