diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 7fd35786607..f2b3189cfda 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -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' diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/CacheTesting.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/CacheTesting.kt new file mode 100644 index 00000000000..b20beed8681 --- /dev/null +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/CacheTesting.kt @@ -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, 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) +} \ No newline at end of file diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt index 67c8436d247..8eabef6a6b6 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt @@ -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 diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt index e93a23d96d1..d697010d027 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/Utils.kt @@ -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 get() = with(findProperty("globalTestArgs")) {