Add initial support for building tests with stdlib cache (#3474)

This commit is contained in:
SvyatoslavScherbina
2019-10-25 13:46:09 +03:00
committed by GitHub
parent 8efb8cacc3
commit bac2e056b9
4 changed files with 87 additions and 4 deletions
+23 -2
View File
@@ -98,6 +98,21 @@ project.convention.plugins.executor = ExecutorServiceKt.create(project)
// Do not generate run tasks for konan built artifacts
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.
ext.twoStageEnabled = project.hasProperty("test_two_stage")
@@ -2427,18 +2442,21 @@ standaloneTest("args0") {
}
standaloneTest("devirtualization_lateinitInterface") {
disabled = (cacheTesting != null) // Cache is not compatible with -opt.
goldValue = "42\n"
flags = ["-opt"]
source = "codegen/devirtualization/lateinitInterface.kt"
}
standaloneTest("devirtualization_getter_looking_as_box_function") {
disabled = (cacheTesting != null) // Cache is not compatible with -opt.
goldValue = "box\n"
flags = ["-opt"]
source = "codegen/devirtualization/getter_looking_as_box_function.kt"
}
standaloneTest("devirtualization_anonymousObject") {
disabled = (cacheTesting != null) // Cache is not compatible with -opt.
goldValue = "zzz\n"
flags = ["-opt"]
source = "codegen/devirtualization/anonymousObject.kt"
@@ -3207,6 +3225,7 @@ task driver0(type: KonanDriverTest) {
}
task driver_opt(type: KonanDriverTest) {
disabled = (cacheTesting != null) // Cache is not compatible with -opt.
goldValue = "Hello, world!\n"
source = "runtime/basic/driver0.kt"
flags = ["-opt"]
@@ -3743,7 +3762,7 @@ if (isAppleTarget(project)) {
final String frameworkName = 'Stdlib'
testName = frameworkName
frameworkNames = [frameworkName]
fullBitcode = true
if (cacheTesting == null) fullBitcode = true
konanArtifacts {
framework(frameworkName, targets: [ targetName ]) {
srcDir 'framework/stdlib'
@@ -3760,7 +3779,9 @@ if (isAppleTarget(project)) {
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"
final String firstFrameworkName = 'First'
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() {
val dist = project.rootProject.file(project.findProperty("org.jetbrains.kotlin.native.home") ?:
project.findProperty("konan.home") ?: "dist")
val dist = project.kotlinNativeDist
val konancDriver = if (HostManager.hostIsMingw) "konanc.bat" else "konanc"
val konanc = File("${dist.canonicalPath}/bin/$konancDriver").absolutePath
@@ -38,6 +38,10 @@ val Project.testOutputStdlib
val Project.testOutputFramework
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")
val Project.globalTestArgs: List<String>
get() = with(findProperty("globalTestArgs")) {