[Gradle][Test] Add tests for K/Native and Configuration Cache
This commit is contained in:
+57
-1
@@ -6,6 +6,8 @@
|
|||||||
package org.jetbrains.kotlin.gradle
|
package org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.GenerateProjectStructureMetadata
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.TransformKotlinGranularMetadata
|
||||||
import org.jetbrains.kotlin.gradle.report.BuildReportType
|
import org.jetbrains.kotlin.gradle.report.BuildReportType
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat
|
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat
|
||||||
import org.jetbrains.kotlin.gradle.testbase.*
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
@@ -64,7 +66,7 @@ class ConfigurationCacheIT : AbstractConfigurationCacheIT() {
|
|||||||
fun testMppWithMavenPublish(gradleVersion: GradleVersion) {
|
fun testMppWithMavenPublish(gradleVersion: GradleVersion) {
|
||||||
project("new-mpp-lib-and-app/sample-lib", gradleVersion) {
|
project("new-mpp-lib-and-app/sample-lib", gradleVersion) {
|
||||||
// KT-49933: Support Gradle Configuration caching with HMPP
|
// KT-49933: Support Gradle Configuration caching with HMPP
|
||||||
val publishedTargets = listOf(/*"kotlinMultiplatform",*/ "jvm6", "nodeJs")
|
val publishedTargets = listOf(/*"kotlinMultiplatform",*/ "jvm6", "nodeJs", "linux64", "mingw64", "mingw86")
|
||||||
|
|
||||||
testConfigurationCacheOf(
|
testConfigurationCacheOf(
|
||||||
":buildKotlinToolingMetadata", // Remove it when KT-49933 is fixed and `kotlinMultiplatform` publication works
|
":buildKotlinToolingMetadata", // Remove it when KT-49933 is fixed and `kotlinMultiplatform` publication works
|
||||||
@@ -74,6 +76,58 @@ class ConfigurationCacheIT : AbstractConfigurationCacheIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeGradlePluginTests
|
||||||
|
@DisplayName("works with native tasks in complex project")
|
||||||
|
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_4)
|
||||||
|
@GradleTest
|
||||||
|
fun testNativeTasks(gradleVersion: GradleVersion) {
|
||||||
|
project("native-configuration-cache", gradleVersion) {
|
||||||
|
//testConfigurationCacheOf("assemble", checkUpToDateOnRebuild = false)
|
||||||
|
val buildOptions = buildOptions.copy(
|
||||||
|
configurationCache = true,
|
||||||
|
configurationCacheProblems = BaseGradleIT.ConfigurationCacheProblems.FAIL
|
||||||
|
)
|
||||||
|
// These tasks currently don't support Configuration Cache and marked as [Task::notCompatibleWithConfigurationCache]
|
||||||
|
val configCacheIncompatibleTaskTypes = listOf(
|
||||||
|
GenerateProjectStructureMetadata::class,
|
||||||
|
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
|
org.jetbrains.kotlin.gradle.targets.native.internal.CInteropMetadataDependencyTransformationTask::class,
|
||||||
|
TransformKotlinGranularMetadata::class
|
||||||
|
).map { it.java.name.replace(".", "\\.") }
|
||||||
|
|
||||||
|
build("assemble", 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.")
|
||||||
|
configCacheIncompatibleTaskTypes.forEach { taskType ->
|
||||||
|
assertOutputContains(
|
||||||
|
"""Task `\S+` of type `$taskType`: .+(at execution time is unsupported)|(not supported with the configuration cache)"""
|
||||||
|
.toRegex()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NativeGradlePluginTests
|
||||||
|
@DisplayName("works with commonizer")
|
||||||
|
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_4)
|
||||||
|
@GradleTest
|
||||||
|
fun testCommonizer(gradleVersion: GradleVersion) {
|
||||||
|
project("native-configuration-cache", gradleVersion) {
|
||||||
|
val buildOptions = buildOptions.copy(freeArgs = listOf("--rerun-tasks"))
|
||||||
|
testConfigurationCacheOf(
|
||||||
|
":lib:commonizeCInterop",
|
||||||
|
":commonizeNativeDistribution",
|
||||||
|
buildOptions = buildOptions,
|
||||||
|
// TODO(alakotka): Report will be still generated due to incorrect consumption of properties and environmental variables.
|
||||||
|
// https://docs.gradle.org/7.4.2/userguide/configuration_cache.html#config_cache:requirements:reading_sys_props_and_env_vars
|
||||||
|
checkConfigurationCacheFileReport = false,
|
||||||
|
checkUpToDateOnRebuild = false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@OtherGradlePluginTests
|
@OtherGradlePluginTests
|
||||||
@DisplayName("with project using incremental kapt")
|
@DisplayName("with project using incremental kapt")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
@@ -208,12 +262,14 @@ abstract class AbstractConfigurationCacheIT : KGPBaseTest() {
|
|||||||
vararg taskNames: String,
|
vararg taskNames: String,
|
||||||
executedTaskNames: List<String>? = null,
|
executedTaskNames: List<String>? = null,
|
||||||
checkUpToDateOnRebuild: Boolean = true,
|
checkUpToDateOnRebuild: Boolean = true,
|
||||||
|
checkConfigurationCacheFileReport: Boolean = true,
|
||||||
buildOptions: BuildOptions = defaultBuildOptions
|
buildOptions: BuildOptions = defaultBuildOptions
|
||||||
) {
|
) {
|
||||||
assertSimpleConfigurationCacheScenarioWorks(
|
assertSimpleConfigurationCacheScenarioWorks(
|
||||||
*taskNames,
|
*taskNames,
|
||||||
executedTaskNames = executedTaskNames,
|
executedTaskNames = executedTaskNames,
|
||||||
checkUpToDateOnRebuild = checkUpToDateOnRebuild,
|
checkUpToDateOnRebuild = checkUpToDateOnRebuild,
|
||||||
|
checkConfigurationCacheFileReport = checkConfigurationCacheFileReport,
|
||||||
buildOptions = buildOptions,
|
buildOptions = buildOptions,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -20,6 +20,7 @@ fun TestProject.assertSimpleConfigurationCacheScenarioWorks(
|
|||||||
buildOptions: BuildOptions,
|
buildOptions: BuildOptions,
|
||||||
executedTaskNames: List<String>? = null,
|
executedTaskNames: List<String>? = null,
|
||||||
checkUpToDateOnRebuild: Boolean = true,
|
checkUpToDateOnRebuild: Boolean = true,
|
||||||
|
checkConfigurationCacheFileReport: Boolean = true,
|
||||||
) {
|
) {
|
||||||
// First, run a build that serializes the tasks state for configuration cache in further builds
|
// First, run a build that serializes the tasks state for configuration cache in further builds
|
||||||
|
|
||||||
@@ -30,7 +31,10 @@ fun TestProject.assertSimpleConfigurationCacheScenarioWorks(
|
|||||||
assertOutputContains(
|
assertOutputContains(
|
||||||
"Calculating task graph as no configuration cache is available for tasks: ${buildArguments.joinToString(separator = " ")}"
|
"Calculating task graph as no configuration cache is available for tasks: ${buildArguments.joinToString(separator = " ")}"
|
||||||
)
|
)
|
||||||
assertConfigurationCacheSucceeded()
|
|
||||||
|
//assertOutputContains("0 problems were found storing the configuration cache.")
|
||||||
|
assertOutputContains("Configuration cache entry stored.")
|
||||||
|
if (checkConfigurationCacheFileReport) assertConfigurationCacheReportNotCreated()
|
||||||
}
|
}
|
||||||
|
|
||||||
build("clean", buildOptions = buildOptions)
|
build("clean", buildOptions = buildOptions)
|
||||||
@@ -73,7 +77,7 @@ private val GradleProject.configurationCacheReportFile
|
|||||||
private val Path.asClickableFileUrl
|
private val Path.asClickableFileUrl
|
||||||
get() = URI("file", "", toUri().path, null, null).toString()
|
get() = URI("file", "", toUri().path, null, null).toString()
|
||||||
|
|
||||||
private fun GradleProject.assertConfigurationCacheSucceeded() {
|
private fun GradleProject.assertConfigurationCacheReportNotCreated() {
|
||||||
configurationCacheReportFile?.let { htmlReportFile ->
|
configurationCacheReportFile?.let { htmlReportFile ->
|
||||||
fail("Configuration cache problems were found, check ${htmlReportFile.asClickableFileUrl} for details.")
|
fail("Configuration cache problems were found, check ${htmlReportFile.asClickableFileUrl} for details.")
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform").apply(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
kotlin.mpp.enableCInteropCommonization=true
|
||||||
|
kotlin.native.cacheKind=static
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64 {
|
||||||
|
binaries {
|
||||||
|
sharedLib(namePrefix = "shared")
|
||||||
|
staticLib(namePrefix = "static")
|
||||||
|
executable(namePrefix = "executable") { entryPoint = "main" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iosX64 {
|
||||||
|
binaries {
|
||||||
|
//framework(namePrefix = "framework")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iosArm64()
|
||||||
|
iosSimulatorArm64()
|
||||||
|
|
||||||
|
targets.filterIsInstance<KotlinNativeTarget>().forEach {
|
||||||
|
it.compilations {
|
||||||
|
val main by getting {
|
||||||
|
cinterops {
|
||||||
|
val myCinterop by creating {
|
||||||
|
defFile(project.file("src/my.def"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinArtifacts {
|
||||||
|
Native.Library("mylib") {
|
||||||
|
target = linuxX64
|
||||||
|
kotlinOptions {
|
||||||
|
freeCompilerArgs += "-Xmen=pool"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Native.Library("myslib") {
|
||||||
|
target = linuxX64
|
||||||
|
isStatic = false
|
||||||
|
modes(DEBUG)
|
||||||
|
kotlinOptions {
|
||||||
|
verbose = false
|
||||||
|
freeCompilerArgs = emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Native.Framework("myframe") {
|
||||||
|
modes(DEBUG, RELEASE)
|
||||||
|
target = iosArm64
|
||||||
|
isStatic = false
|
||||||
|
embedBitcode = EmbedBitcodeMode.MARKER
|
||||||
|
kotlinOptions {
|
||||||
|
verbose = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Native.FatFramework("myfatframe") {
|
||||||
|
targets(iosX64, iosSimulatorArm64)
|
||||||
|
embedBitcode = EmbedBitcodeMode.DISABLE
|
||||||
|
kotlinOptions {
|
||||||
|
suppressWarnings = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Native.XCFramework {
|
||||||
|
targets(iosX64, iosArm64, iosSimulatorArm64)
|
||||||
|
setModules(
|
||||||
|
project(":lib")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo() = "bar" + my.cinterop.foo()
|
||||||
|
|
||||||
|
fun main() = println(foo())
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
package = my.cinterop
|
||||||
|
---
|
||||||
|
|
||||||
|
static int foo() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user