[Gradle] Move basic configuration cache IT scenario to helpers file
#KT-45745 In Progress
This commit is contained in:
+6
-61
@@ -9,11 +9,6 @@ import org.gradle.util.GradleVersion
|
|||||||
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.*
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
import java.net.URI
|
|
||||||
import java.nio.file.Path
|
|
||||||
import kotlin.io.path.ExperimentalPathApi
|
|
||||||
import kotlin.io.path.name
|
|
||||||
import kotlin.test.fail
|
|
||||||
|
|
||||||
@DisplayName("Configuration cache")
|
@DisplayName("Configuration cache")
|
||||||
class ConfigurationCacheIT : AbstractConfigurationCacheIT() {
|
class ConfigurationCacheIT : AbstractConfigurationCacheIT() {
|
||||||
@@ -231,61 +226,11 @@ abstract class AbstractConfigurationCacheIT : KGPBaseTest() {
|
|||||||
checkUpToDateOnRebuild: Boolean = true,
|
checkUpToDateOnRebuild: Boolean = true,
|
||||||
buildOptions: BuildOptions = defaultBuildOptions
|
buildOptions: BuildOptions = defaultBuildOptions
|
||||||
) {
|
) {
|
||||||
// First, run a build that serializes the tasks state for instant execution in further builds
|
assertSimpleConfigurationCacheScenarioWorks(
|
||||||
|
*taskNames,
|
||||||
val executedTask: List<String> = executedTaskNames ?: taskNames.toList()
|
executedTaskNames = executedTaskNames,
|
||||||
|
checkUpToDateOnRebuild = checkUpToDateOnRebuild,
|
||||||
build(*taskNames, buildOptions = buildOptions) {
|
buildOptions = buildOptions,
|
||||||
assertTasksExecuted(*executedTask.toTypedArray())
|
)
|
||||||
assertOutputContains(
|
|
||||||
"Calculating task graph as no configuration cache is available for tasks: ${taskNames.joinToString(separator = " ")}"
|
|
||||||
)
|
|
||||||
assertInstantExecutionSucceeded()
|
|
||||||
}
|
|
||||||
|
|
||||||
build("clean", buildOptions = buildOptions)
|
|
||||||
|
|
||||||
// Then run a build where tasks states are deserialized to check that they work correctly in this mode
|
|
||||||
build(*taskNames, buildOptions = buildOptions) {
|
|
||||||
assertTasksExecuted(*executedTask.toTypedArray())
|
|
||||||
assertOutputContains("Reusing configuration cache.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (checkUpToDateOnRebuild) {
|
|
||||||
build(*taskNames, buildOptions = buildOptions) {
|
|
||||||
assertTasksUpToDate(*executedTask.toTypedArray())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun GradleProject.assertInstantExecutionSucceeded() {
|
|
||||||
instantExecutionReportFile?.let { htmlReportFile ->
|
|
||||||
fail("Instant execution problems were found, check ${htmlReportFile.asClickableFileUrl} for details.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies all files from the directory containing the given [htmlReportFile] to a
|
|
||||||
* fresh temp dir and returns a reference to the copied [htmlReportFile] in the new
|
|
||||||
* directory.
|
|
||||||
*/
|
|
||||||
@OptIn(ExperimentalPathApi::class)
|
|
||||||
private fun copyReportToTempDir(htmlReportFile: Path): Path =
|
|
||||||
createTempDir("report").let { tempDir ->
|
|
||||||
htmlReportFile.parent.toFile().copyRecursively(tempDir.toFile())
|
|
||||||
tempDir.resolve(htmlReportFile.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The instant execution report file, if exists, indicates problems were
|
|
||||||
* found while caching the task graph.
|
|
||||||
*/
|
|
||||||
private val GradleProject.instantExecutionReportFile
|
|
||||||
get() = projectPath
|
|
||||||
.resolve("build")
|
|
||||||
.findInPath("configuration-cache-report.html")
|
|
||||||
?.let { copyReportToTempDir(it) }
|
|
||||||
|
|
||||||
private val Path.asClickableFileUrl
|
|
||||||
get() = URI("file", "", toUri().path, null, null).toString()
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-4
@@ -246,10 +246,7 @@ class JvmTargetValidationTest : KGPBaseTest() {
|
|||||||
project(
|
project(
|
||||||
projectName = "simple".fullProjectName,
|
projectName = "simple".fullProjectName,
|
||||||
gradleVersion = gradleVersion,
|
gradleVersion = gradleVersion,
|
||||||
buildOptions = defaultBuildOptions.copy(
|
buildOptions = defaultBuildOptions.withConfigurationCache,
|
||||||
configurationCache = true,
|
|
||||||
configurationCacheProblems = BaseGradleIT.ConfigurationCacheProblems.FAIL
|
|
||||||
),
|
|
||||||
buildJdk = getJdk11().javaHome // should differ from default Kotlin jvm target value
|
buildJdk = getJdk11().javaHome // should differ from default Kotlin jvm target value
|
||||||
) {
|
) {
|
||||||
// Validation mode should be 'warning' because of https://github.com/gradle/gradle/issues/9339
|
// Validation mode should be 'warning' because of https://github.com/gradle/gradle/issues/9339
|
||||||
|
|||||||
+1
-4
@@ -844,10 +844,7 @@ open class Kapt3IT : Kapt3BaseIT() {
|
|||||||
project(
|
project(
|
||||||
"incrementalRebuild".withPrefix,
|
"incrementalRebuild".withPrefix,
|
||||||
gradleVersion,
|
gradleVersion,
|
||||||
buildOptions = defaultBuildOptions.copy(
|
buildOptions = defaultBuildOptions.withConfigurationCache
|
||||||
configurationCache = true,
|
|
||||||
configurationCacheProblems = BaseGradleIT.ConfigurationCacheProblems.FAIL
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
build("assemble")
|
build("assemble")
|
||||||
|
|
||||||
|
|||||||
+2
-8
@@ -592,10 +592,7 @@ class KotlinJavaToolchainTest : KGPBaseTest() {
|
|||||||
project(
|
project(
|
||||||
projectName = "simple".fullProjectName,
|
projectName = "simple".fullProjectName,
|
||||||
gradleVersion = gradleVersion,
|
gradleVersion = gradleVersion,
|
||||||
buildOptions = defaultBuildOptions.copy(
|
buildOptions = defaultBuildOptions.withConfigurationCache
|
||||||
configurationCache = true,
|
|
||||||
configurationCacheProblems = BaseGradleIT.ConfigurationCacheProblems.FAIL
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
useToolchainExtension(15)
|
useToolchainExtension(15)
|
||||||
|
|
||||||
@@ -618,10 +615,7 @@ class KotlinJavaToolchainTest : KGPBaseTest() {
|
|||||||
project(
|
project(
|
||||||
projectName = "simple".fullProjectName,
|
projectName = "simple".fullProjectName,
|
||||||
gradleVersion = gradleVersion,
|
gradleVersion = gradleVersion,
|
||||||
buildOptions = defaultBuildOptions.copy(
|
buildOptions = defaultBuildOptions.withConfigurationCache
|
||||||
configurationCache = true,
|
|
||||||
configurationCacheProblems = BaseGradleIT.ConfigurationCacheProblems.FAIL
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
//language=properties
|
//language=properties
|
||||||
gradleProperties.append(
|
gradleProperties.append(
|
||||||
|
|||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.testbase
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.BaseGradleIT
|
||||||
|
import java.net.URI
|
||||||
|
import java.nio.file.Path
|
||||||
|
import kotlin.io.path.ExperimentalPathApi
|
||||||
|
import kotlin.io.path.name
|
||||||
|
import kotlin.test.fail
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether configuration cache for the tasks specified by [buildArguments] works on simple scenario when project is built twice non-incrementally.
|
||||||
|
*/
|
||||||
|
fun TestProject.assertSimpleConfigurationCacheScenarioWorks(
|
||||||
|
vararg buildArguments: String,
|
||||||
|
buildOptions: BuildOptions,
|
||||||
|
executedTaskNames: List<String>? = null,
|
||||||
|
checkUpToDateOnRebuild: Boolean = true,
|
||||||
|
) {
|
||||||
|
// First, run a build that serializes the tasks state for configuration cache in further builds
|
||||||
|
|
||||||
|
val executedTask: List<String> = executedTaskNames ?: buildArguments.toList()
|
||||||
|
|
||||||
|
build(*buildArguments, buildOptions = buildOptions) {
|
||||||
|
assertTasksExecuted(*executedTask.toTypedArray())
|
||||||
|
assertOutputContains(
|
||||||
|
"Calculating task graph as no configuration cache is available for tasks: ${buildArguments.joinToString(separator = " ")}"
|
||||||
|
)
|
||||||
|
assertConfigurationCacheSucceeded()
|
||||||
|
}
|
||||||
|
|
||||||
|
build("clean", buildOptions = buildOptions)
|
||||||
|
|
||||||
|
// Then run a build where tasks states are deserialized to check that they work correctly in this mode
|
||||||
|
build(*buildArguments, buildOptions = buildOptions) {
|
||||||
|
assertTasksExecuted(*executedTask.toTypedArray())
|
||||||
|
assertOutputContains("Reusing configuration cache.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkUpToDateOnRebuild) {
|
||||||
|
build(*buildArguments, buildOptions = buildOptions) {
|
||||||
|
assertTasksUpToDate(*executedTask.toTypedArray())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies all files from the directory containing the given [htmlReportFile] to a
|
||||||
|
* fresh temp dir and returns a reference to the copied [htmlReportFile] in the new
|
||||||
|
* directory.
|
||||||
|
*/
|
||||||
|
@OptIn(ExperimentalPathApi::class)
|
||||||
|
private fun copyReportToTempDir(htmlReportFile: Path): Path =
|
||||||
|
createTempDir("report").let { tempDir ->
|
||||||
|
htmlReportFile.parent.toFile().copyRecursively(tempDir.toFile())
|
||||||
|
tempDir.resolve(htmlReportFile.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configuration cache report file, if exists, indicates problems were
|
||||||
|
* found while caching the task graph.
|
||||||
|
*/
|
||||||
|
private val GradleProject.configurationCacheReportFile
|
||||||
|
get() = projectPath
|
||||||
|
.resolve("build")
|
||||||
|
.findInPath("configuration-cache-report.html")
|
||||||
|
?.let { copyReportToTempDir(it) }
|
||||||
|
|
||||||
|
private val Path.asClickableFileUrl
|
||||||
|
get() = URI("file", "", toUri().path, null, null).toString()
|
||||||
|
|
||||||
|
private fun GradleProject.assertConfigurationCacheSucceeded() {
|
||||||
|
configurationCacheReportFile?.let { htmlReportFile ->
|
||||||
|
fail("Configuration cache problems were found, check ${htmlReportFile.asClickableFileUrl} for details.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val BuildOptions.withConfigurationCache: BuildOptions
|
||||||
|
get() = copy(configurationCache = true, configurationCacheProblems = BaseGradleIT.ConfigurationCacheProblems.FAIL)
|
||||||
Reference in New Issue
Block a user