Add initial support for building tests with stdlib cache (#3474)
This commit is contained in:
committed by
GitHub
parent
8efb8cacc3
commit
bac2e056b9
@@ -98,6 +98,21 @@ project.convention.plugins.executor = ExecutorServiceKt.create(project)
|
|||||||
// Do not generate run tasks for konan built artifacts
|
// Do not generate run tasks for konan built artifacts
|
||||||
ext.konanNoRun = true
|
ext.konanNoRun = true
|
||||||
|
|
||||||
|
final CacheTesting cacheTesting = CacheTestingKt.configureCacheTesting(project)
|
||||||
|
if (cacheTesting != null) {
|
||||||
|
// Note: can't do this in [CacheTesting.configure] since task classes aren't accessible there.
|
||||||
|
|
||||||
|
tasks.withType(KonanCompileNativeBinary.class) {
|
||||||
|
dependsOn cacheTesting.buildCacheTask
|
||||||
|
extraOpts cacheTesting.compilerArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(RunExternalTestGroup.class) {
|
||||||
|
dependsOn cacheTesting.buildCacheTask
|
||||||
|
flags = (flags ?: []) + cacheTesting.compilerArgs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Enable two-stage test compilation if the test_two_stage property is set.
|
// Enable two-stage test compilation if the test_two_stage property is set.
|
||||||
ext.twoStageEnabled = project.hasProperty("test_two_stage")
|
ext.twoStageEnabled = project.hasProperty("test_two_stage")
|
||||||
|
|
||||||
@@ -2427,18 +2442,21 @@ standaloneTest("args0") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
standaloneTest("devirtualization_lateinitInterface") {
|
standaloneTest("devirtualization_lateinitInterface") {
|
||||||
|
disabled = (cacheTesting != null) // Cache is not compatible with -opt.
|
||||||
goldValue = "42\n"
|
goldValue = "42\n"
|
||||||
flags = ["-opt"]
|
flags = ["-opt"]
|
||||||
source = "codegen/devirtualization/lateinitInterface.kt"
|
source = "codegen/devirtualization/lateinitInterface.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
standaloneTest("devirtualization_getter_looking_as_box_function") {
|
standaloneTest("devirtualization_getter_looking_as_box_function") {
|
||||||
|
disabled = (cacheTesting != null) // Cache is not compatible with -opt.
|
||||||
goldValue = "box\n"
|
goldValue = "box\n"
|
||||||
flags = ["-opt"]
|
flags = ["-opt"]
|
||||||
source = "codegen/devirtualization/getter_looking_as_box_function.kt"
|
source = "codegen/devirtualization/getter_looking_as_box_function.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
standaloneTest("devirtualization_anonymousObject") {
|
standaloneTest("devirtualization_anonymousObject") {
|
||||||
|
disabled = (cacheTesting != null) // Cache is not compatible with -opt.
|
||||||
goldValue = "zzz\n"
|
goldValue = "zzz\n"
|
||||||
flags = ["-opt"]
|
flags = ["-opt"]
|
||||||
source = "codegen/devirtualization/anonymousObject.kt"
|
source = "codegen/devirtualization/anonymousObject.kt"
|
||||||
@@ -3207,6 +3225,7 @@ task driver0(type: KonanDriverTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
task driver_opt(type: KonanDriverTest) {
|
task driver_opt(type: KonanDriverTest) {
|
||||||
|
disabled = (cacheTesting != null) // Cache is not compatible with -opt.
|
||||||
goldValue = "Hello, world!\n"
|
goldValue = "Hello, world!\n"
|
||||||
source = "runtime/basic/driver0.kt"
|
source = "runtime/basic/driver0.kt"
|
||||||
flags = ["-opt"]
|
flags = ["-opt"]
|
||||||
@@ -3743,7 +3762,7 @@ if (isAppleTarget(project)) {
|
|||||||
final String frameworkName = 'Stdlib'
|
final String frameworkName = 'Stdlib'
|
||||||
testName = frameworkName
|
testName = frameworkName
|
||||||
frameworkNames = [frameworkName]
|
frameworkNames = [frameworkName]
|
||||||
fullBitcode = true
|
if (cacheTesting == null) fullBitcode = true
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
framework(frameworkName, targets: [ targetName ]) {
|
framework(frameworkName, targets: [ targetName ]) {
|
||||||
srcDir 'framework/stdlib'
|
srcDir 'framework/stdlib'
|
||||||
@@ -3760,7 +3779,9 @@ if (isAppleTarget(project)) {
|
|||||||
swiftSources = ['framework/stdlib/stdlib.swift']
|
swiftSources = ['framework/stdlib/stdlib.swift']
|
||||||
}
|
}
|
||||||
|
|
||||||
task testMultipleFrameworks(type: FrameworkTest) {
|
if (cacheTesting != null && cacheTesting.isDynamic) {
|
||||||
|
// testMultipleFrameworks disabled until https://youtrack.jetbrains.com/issue/KT-34262 is fixed.
|
||||||
|
} else task testMultipleFrameworks(type: FrameworkTest) {
|
||||||
testName = "MultipleFrameworks"
|
testName = "MultipleFrameworks"
|
||||||
final String firstFrameworkName = 'First'
|
final String firstFrameworkName = 'First'
|
||||||
final String secondFrameworkName = 'Second'
|
final String secondFrameworkName = 'Second'
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package org.jetbrains.kotlin
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.Task
|
||||||
|
import org.gradle.api.tasks.Exec
|
||||||
|
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||||
|
import org.jetbrains.kotlin.konan.util.visibleName
|
||||||
|
|
||||||
|
class CacheTesting(val buildCacheTask: Task, val compilerArgs: List<String>, val isDynamic: Boolean)
|
||||||
|
|
||||||
|
fun configureCacheTesting(project: Project): CacheTesting? {
|
||||||
|
val cacheKindString = project.findProperty("test_with_cache_kind") as String? ?: return null
|
||||||
|
val isDynamic = when (cacheKindString) {
|
||||||
|
"dynamic" -> true
|
||||||
|
"static" -> false
|
||||||
|
else -> error(cacheKindString)
|
||||||
|
}
|
||||||
|
|
||||||
|
val cacheKind = if (isDynamic) {
|
||||||
|
CompilerOutputKind.DYNAMIC_CACHE
|
||||||
|
} else {
|
||||||
|
CompilerOutputKind.STATIC_CACHE
|
||||||
|
}
|
||||||
|
|
||||||
|
val target = project.testTarget
|
||||||
|
|
||||||
|
val cacheDir = project.file("${project.buildDir}/cache")
|
||||||
|
val cacheFile = "$cacheDir/${cacheKind.prefix(target)}stdlib-cache${cacheKind.suffix(target)}"
|
||||||
|
val dist = project.kotlinNativeDist
|
||||||
|
val stdlib = "$dist/klib/common/stdlib"
|
||||||
|
val compilerArgs = listOf("-Xcached-library=$stdlib,$cacheFile")
|
||||||
|
|
||||||
|
val buildCacheTask = project.tasks.create("buildStdlibCache", Exec::class.java) {
|
||||||
|
it.doFirst {
|
||||||
|
cacheDir.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(project.property("useCustomDist") as Boolean)) {
|
||||||
|
val tasks = listOf(
|
||||||
|
"${target}CrossDist",
|
||||||
|
"${target}CrossDistRuntime",
|
||||||
|
"commonDistRuntime",
|
||||||
|
"distCompiler"
|
||||||
|
).map { task -> project.rootProject.tasks.getByName(task) }
|
||||||
|
|
||||||
|
it.dependsOn(tasks)
|
||||||
|
}
|
||||||
|
|
||||||
|
it.commandLine(
|
||||||
|
"$dist/bin/konanc",
|
||||||
|
"-p", cacheKind.visibleName,
|
||||||
|
"-o", cacheFile,
|
||||||
|
"-Xmake-cache=$stdlib",
|
||||||
|
"-g"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return CacheTesting(buildCacheTask, compilerArgs, isDynamic)
|
||||||
|
}
|
||||||
@@ -344,8 +344,7 @@ open class KonanDriverTest : KonanStandaloneTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun konan() {
|
private fun konan() {
|
||||||
val dist = project.rootProject.file(project.findProperty("org.jetbrains.kotlin.native.home") ?:
|
val dist = project.kotlinNativeDist
|
||||||
project.findProperty("konan.home") ?: "dist")
|
|
||||||
val konancDriver = if (HostManager.hostIsMingw) "konanc.bat" else "konanc"
|
val konancDriver = if (HostManager.hostIsMingw) "konanc.bat" else "konanc"
|
||||||
val konanc = File("${dist.canonicalPath}/bin/$konancDriver").absolutePath
|
val konanc = File("${dist.canonicalPath}/bin/$konancDriver").absolutePath
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ val Project.testOutputStdlib
|
|||||||
val Project.testOutputFramework
|
val Project.testOutputFramework
|
||||||
get() = (findProperty("testOutputFramework") as File).toString()
|
get() = (findProperty("testOutputFramework") as File).toString()
|
||||||
|
|
||||||
|
val Project.kotlinNativeDist
|
||||||
|
get() = this.rootProject.file(this.findProperty("org.jetbrains.kotlin.native.home")
|
||||||
|
?: this.findProperty("konan.home") ?: "dist")
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val Project.globalTestArgs: List<String>
|
val Project.globalTestArgs: List<String>
|
||||||
get() = with(findProperty("globalTestArgs")) {
|
get() = with(findProperty("globalTestArgs")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user