[build][tests] more utilities functions used

This commit is contained in:
Vasily Levchenko
2020-12-11 08:42:07 +01:00
parent 39fb47892c
commit 46f2182ba6
4 changed files with 65 additions and 23 deletions
@@ -22,17 +22,12 @@ buildscript {
url project.bootstrapKotlinRepo
}
}
ext.useCustomDist = project.hasProperty("kotlin.native.home") ||
project.hasProperty("org.jetbrains.kotlin.native.home") ||
project.hasProperty("konan.home")
ext.kotlinNativeDist = project.findProperty("kotlin.native.home")
?: project.findProperty("org.jetbrains.kotlin.native.home")
?: project.findProperty("konan.home")
?: distDir.absolutePath
ext.useCustomDist = UtilsKt.getUseCustomDist(project)
ext.kotlinNativeDist = UtilsKt.getKotlinNativeDist(project)
if (!useCustomDist) {
ext.setProperty("kotlin.native.home", distDir.absolutePath)
ext.setProperty("org.jetbrains.kotlin.native.home", distDir.absolutePath)
ext.setProperty("konan.home", distDir.absolutePath)
ext.setProperty("kotlin.native.home", kotlinNativeDist.absolutePath)
ext.setProperty("org.jetbrains.kotlin.native.home", kotlinNativeDist.absolutePath)
ext.setProperty("konan.home", kotlinNativeDist.absolutePath)
}
}
@@ -133,9 +128,6 @@ allprojects {
testOutputExternal.mkdirs()
testOutputStdlib.mkdirs()
ext.dist = project.rootProject.file(project.findProperty("org.jetbrains.kotlin.native.home") ?:
project.findProperty("konan.home") ?: "dist")
konanArtifacts {
library('testLibrary') {
if (!useCustomDist) {
@@ -166,7 +158,7 @@ def installTestLib = tasks.register("installTestLibrary", KlibInstall) {
void konanc(String[] args) {
def konancScript = isWindows() ? "konanc.bat" : "konanc"
def konanc = "$dist/bin/$konancScript"
def konanc = "$kotlinNativeDist/bin/$konancScript"
def allArgs = args.join(" ")
println("$konanc $allArgs")
"$konanc $allArgs".execute().waitFor()
@@ -4421,7 +4413,7 @@ if (PlatformInfo.isAppleTarget(project)) {
standaloneTest("jsinterop_math") {
doBeforeBuild {
def jsinteropScript = isWindows() ? "jsinterop.bat" : "jsinterop"
def jsinterop = "$dist/bin/$jsinteropScript"
def jsinterop = "$kotlinNativeDist/bin/$jsinteropScript"
// TODO: We probably need a NativeInteropPlugin for jsinterop?
"$jsinterop -pkg kotlinx.interop.wasm.math -o $buildDir/jsmath -target wasm32".execute().waitFor()
@@ -5224,7 +5216,7 @@ project.tasks.register("debugger_test", Test.class) {
enabled = (target.family == Family.OSX) // KT-30366
testLogging { exceptionFormat = 'full' }
UtilsKt.dependsOnDist(it)
systemProperties = ['kotlin.native.home': dist]
systemProperties = ['kotlin.native.home': kotlinNativeDist]
}
// Configure build for iOS device targets.
@@ -11,6 +11,7 @@ import org.gradle.api.Task
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.jetbrains.kotlin.konan.target.AppleConfigurables
import org.jetbrains.kotlin.gradle.plugin.tasks.*
/**
* Test task for -Xcoverage and -Xlibraries-to-cover flags. Requires a binary to be built by the Konan plugin
@@ -64,7 +65,11 @@ open class CoverageTest : DefaultTask() {
override fun configure(closure: Closure<Any>): Task {
super.configure(closure)
dependsOnDist()
dependsOn(project.tasks.getByName("compileKonan$binaryName"))
val compileBinaryTask = project.tasks.getByName("compileKonan$binaryName")
compileBinaryTask.konanOldPluginTaskDependenciesWalker{
dependsOnDist()
}
dependsOn(compileBinaryTask)
return this
}
@@ -4,7 +4,9 @@
*/
package org.jetbrains.kotlin
import groovy.lang.Closure
import org.gradle.api.DefaultTask
import org.gradle.api.Task
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.jetbrains.kotlin.klib.metadata.CInteropComparisonConfig
@@ -58,6 +60,12 @@ open class MetadataComparisonTest : DefaultTask() {
}
}
override fun configure(closure: Closure<Any>): Task {
super.configure(closure)
dependsOnDist()
return this
}
private fun cinterop(defFile: File, mode: Mode): File {
val dist = project.kotlinNativeDist
val output = "${project.buildDir.absolutePath}/${defFile.nameWithoutExtension}_$mode"
@@ -29,6 +29,9 @@ val Project.platformManager
val Project.testTarget
get() = findProperty("target") as KonanTarget
val Project.testTargetSuffix
get() = (findProperty("target") as KonanTarget ?: HostManager.host).name.capitalize()
val Project.verboseTest
get() = hasProperty("test_verbose")
@@ -48,8 +51,32 @@ val Project.testOutputExternal
get() = (findProperty("testOutputExternal") as File).toString()
val Project.kotlinNativeDist
get() = this.rootProject.file(this.findProperty("org.jetbrains.kotlin.native.home")
?: this.findProperty("konan.home") ?: "dist")
get() = this.rootProject.file(findProperty("kotlin.native.home")
?: findProperty("org.jetbrains.kotlin.native.home")
?: findProperty("konan.home") ?: "dist")
val Project.useCustomDist
get() = hasProperty("kotlin.native.home") ||
hasProperty("org.jetbrains.kotlin.native.home") ||
hasProperty("konan.home")
private val libraryRegexp = Regex("""^import\s+platform\.(\S+)\..*$""")
fun File.dependencies() =
readLines().filter(libraryRegexp::containsMatchIn)
.map { libraryRegexp.matchEntire(it)?.groups?.get(1)?.value ?: "" }
.toSortedSet()
fun Task.dependsOnPlatformLibs() {
val platformManager = project.project(":kotlin-native").platformManager
val target = project.testTarget ?: platformManager.hostPlatform.target
(this as? KonanTest)?.run {
project.file(source).dependencies().forEach {
this.dependsOn(":kotlin-native:platformLibs:${target.name}-$it")
//this.dependsOn(":kotlin-native:platformLibs:${target.name}-${it}Cache")
}
} ?: error("unsupported task : $this")
}
@Suppress("UNCHECKED_CAST")
val Project.globalTestArgs: List<String>
@@ -105,19 +132,27 @@ fun Project.dependsOnDist(taskName: String) {
}
fun Task.dependsOnDist() {
val rootTasks = project.rootProject.tasks
// We don't build the compiler if a custom dist path is specified.
if (!(project.findProperty("useCustomDist") as Boolean)) {
dependsOn(rootTasks.getByName("dist"))
dependsOn(":kotlin-native:dist")
val target = project.testTarget
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(rootTasks.getByName("${target.name}CrossDist"))
dependsOn(":kotlin-native:${target.name}CrossDist")
}
}
}
fun Task.konanOldPluginTaskDependenciesWalker(index:Int = 0, walker: Task.(Int)->Unit) {
walker(index + 1)
dependsOn.forEach{
val task = (it as? Task) ?: return@forEach
if (task.name.startsWith("compileKonan"))
task.konanOldPluginTaskDependenciesWalker(index + 1, walker)
}
}
/**
* Sets the same dependencies for the receiver task from the given [task]
*/
@@ -140,7 +175,9 @@ fun Task.sameDependenciesAs(task: Task) {
*/
fun Task.dependsOnKonanBuildingTask(artifact: String, target: KonanTarget) {
val buildTask = project.findKonanBuildTask(artifact, target)
buildTask.dependsOnDist()
buildTask.konanOldPluginTaskDependenciesWalker {
dependsOnDist()
}
buildTask.sameDependenciesAs(this)
dependsOn(buildTask)
}