[Gradle] Support Gradle Configuration Cache with KotlinNativeTest

This commit is contained in:
Anton Lakotka
2022-06-22 13:36:21 +02:00
committed by Space
parent 9fe9cf745c
commit a1d6ebd8ea
4 changed files with 39 additions and 10 deletions
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.gradle
import org.gradle.api.logging.configuration.WarningMode
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.plugin.mpp.GenerateProjectStructureMetadata
import org.jetbrains.kotlin.gradle.plugin.mpp.TransformKotlinGranularMetadata
@@ -82,20 +83,22 @@ class ConfigurationCacheIT : AbstractConfigurationCacheIT() {
@GradleTest
fun testNativeTasks(gradleVersion: GradleVersion) {
project("native-configuration-cache", gradleVersion) {
//testConfigurationCacheOf("assemble", checkUpToDateOnRebuild = false)
// testConfigurationCacheOf("build", checkUpToDateOnRebuild = false)
val buildOptions = buildOptions.copy(
configurationCache = true,
configurationCacheProblems = BaseGradleIT.ConfigurationCacheProblems.FAIL
configurationCacheProblems = BaseGradleIT.ConfigurationCacheProblems.FAIL,
warningMode = WarningMode.All
)
// These tasks currently don't support Configuration Cache and marked as [Task::notCompatibleWithConfigurationCache]
val configCacheIncompatibleTaskTypes = listOf(
GenerateProjectStructureMetadata::class,
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@Suppress("INVISIBLE_REFERENCE")
org.jetbrains.kotlin.gradle.targets.native.internal.CInteropMetadataDependencyTransformationTask::class,
TransformKotlinGranularMetadata::class
).map { it.java.name.replace(".", "\\.") }
build("assemble", buildOptions = buildOptions) {
build("build", buildOptions = buildOptions) {
// Reduce the problem numbers when a Task become compatible with GCC.
// When all tasks support GCC, replace these assertions with `testConfigurationCacheOf`
assertOutputContains("17 problems were found storing the configuration cache, 6 of which seem unique.")
@@ -105,6 +108,10 @@ class ConfigurationCacheIT : AbstractConfigurationCacheIT() {
.toRegex()
)
}
// TODO: Enable `warningMode = Fail` back and remove these asserts when KGP supports Gradle 8.0
assertOutputContains("The TestReport.destinationDir property has been deprecated.")
assertOutputContains("The TestReport.reportOn(Object...) method has been deprecated.")
}
}
}
@@ -31,6 +31,14 @@ kotlin {
}
}
}
sourceSets {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
}
}
kotlinArtifacts {
@@ -0,0 +1,10 @@
import kotlin.test.Test
import kotlin.test.assertEquals
class CommonTest {
@Test
fun sampleTest() {
assertEquals("bar42", foo())
}
}
@@ -74,6 +74,14 @@ abstract class KotlinNativeTest : KotlinTest() {
private val trackedEnvironmentVariablesKeys = mutableSetOf<String>()
private val hasTCProjectProperty = if (isConfigurationCacheAvailable(project.gradle)) {
project.providers.gradleProperty(TC_PROJECT_PROPERTY).forUseAtConfigurationTime().isPresent
} else {
project.hasProperty(TC_PROJECT_PROPERTY)
}
private val konanVersion = project.konanVersion
@Suppress("unused")
@get:Input
val trackedEnvironment
@@ -136,18 +144,14 @@ abstract class KotlinNativeTest : KotlinTest() {
prependSuiteName = targetName != null,
treatFailedTestOutputAsStacktrace = false,
stackTraceParser = ::parseKotlinNativeStackTraceAsJvm,
escapeTCMessagesInLog = if (isConfigurationCacheAvailable(project.gradle)) {
project.providers.gradleProperty(TC_PROJECT_PROPERTY).forUseAtConfigurationTime().isPresent
} else {
project.hasProperty(TC_PROJECT_PROPERTY)
}
escapeTCMessagesInLog = hasTCProjectProperty
)
// The KotlinTest expects that the exit code is zero even if some tests failed.
// In this case it can check exit code and distinguish test failures from crashes.
// But K/N allows forcing a zero exit code only since 1.3 (which was included in Kotlin 1.3.40).
// Thus we check the exit code only for newer versions.
val checkExitCode = project.konanVersion.isAtLeast(1, 3, 0)
val checkExitCode = konanVersion.isAtLeast(1, 3, 0)
val cliArgs = testCommand.cliArgs("TEAMCITY", checkExitCode, includePatterns, excludePatterns, args)