From ad793ac624b814ee9bddf62256b51b963f015e04 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Wed, 2 Feb 2022 18:03:46 +0300 Subject: [PATCH] [K/N] Support cross targets in FileCheckTest Also mark property's getter with Input and Optional annotations instead of property itself. --- .../backend.native/tests/build.gradle | 1 + .../org/jetbrains/kotlin/FileCheckTest.kt | 47 ++++++++++++------- .../main/kotlin/org/jetbrains/kotlin/Utils.kt | 14 ++++++ 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 0863e385c26..e247b339b4e 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -5895,6 +5895,7 @@ Task fileCheckTest(String name, Closure configureClosure) { return project.tasks.create(name, FileCheckTest) { task -> task.configure(configureClosure) task.llvmIr = project.file("$testOutputFileCheck/$name/$target/out.${task.phaseToCheck}.ll") + def target = task.target if (task.enabled) { konanArtifacts { def lib = task.interop diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FileCheckTest.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FileCheckTest.kt index 03bb3f28073..576eee86a5a 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FileCheckTest.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FileCheckTest.kt @@ -11,8 +11,8 @@ import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.tasks.* import org.jetbrains.kotlin.gradle.plugin.tasks.KonanCompileProgramTask -import org.jetbrains.kotlin.konan.target.AppleConfigurables import org.jetbrains.kotlin.gradle.plugin.tasks.KonanCompileTask +import org.jetbrains.kotlin.konan.target.* import java.io.File import java.nio.file.Path import java.nio.file.Files @@ -21,15 +21,6 @@ import java.nio.file.Files * Gradle task that wraps FileCheck LLVM utility. */ open class FileCheckTest : DefaultTask() { - - private val target = project.testTarget - private val platform = project.platformManager.platform(target) - private val configurables = platform.configurables - - private val llvmBin = "${configurables.absoluteLlvmHome}/bin" - - private val fileCheck = "$llvmBin/FileCheck" - /** * File annotated with FileCheck directives. */ @@ -45,8 +36,8 @@ open class FileCheckTest : DefaultTask() { /** * Optional cinterop task dependency. */ - @Optional - @Input + @get:Optional + @get:Input var interop: String? = null @TaskAction @@ -57,23 +48,43 @@ open class FileCheckTest : DefaultTask() { /** * What prefix should checked for pattern instead of default CHECK? */ - @Input - @Optional + @get:Input + @get:Optional var checkPrefix: String? = null /** * Compiler pipeline phase name, after which check should be done */ - @Input + @get:Input var phaseToCheck: String = "CStubs" /** * Should we generate framework instead of an executable? * This option is useful for, well, checking framework-specific code. */ - @Input + @get:Input var generateFramework: Boolean = false + @get:Input + @get:Optional + var additionalFileCheckFlags: List? = null + + @get:Optional + @get:Input + var targetName: String = project.testTarget.name + + @get:Internal + val target: KonanTarget + get() = project.platformManager.targetByName(targetName) + + override fun configure(closure: Closure<*>): Task { + super.configure(closure) + if (target != HostManager.host) { + dependsOnCrossDist(target) + } + return this + } + /** * Check that [inputFile] matches [annotatedFile] with FileCheck. */ @@ -82,6 +93,10 @@ open class FileCheckTest : DefaultTask() { checkPrefix?.let { args.addAll(listOf("--check-prefix", it)) } + val platform = project.platformManager.platform(target) + val configurables = platform.configurables + val llvmBin = "${configurables.absoluteLlvmHome}/bin" + val fileCheck = "$llvmBin/FileCheck" return runProcess(localExecutor(project), fileCheck, *args.toTypedArray()) .ensureSuccessful(fileCheck, *args.toTypedArray()) } diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt index 3d0915ac13a..3c7e2272d49 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt @@ -264,6 +264,20 @@ fun Task.dependsOnDist() { } } +fun Task.dependsOnCrossDist(target: KonanTarget) { + if (project.isDefaultNativeHome) { + if (target != HostManager.host) { + // if a test_target property is set then tests should depend on a crossDist + // otherwise, runtime components would not be build for a target. + dependsOn(":kotlin-native:${target.name}CrossDist") + } + } else { + if (!project.isCrossDist) { + dependsOn(":kotlin-native:${target.name}CrossDist") + } + } +} + fun Task.konanOldPluginTaskDependenciesWalker(index:Int = 0, walker: Task.(Int)->Unit) { walker(index + 1) dependsOn.forEach{