Add integration test for the case where incremental state is missing
^KT-53231 In progress
This commit is contained in:
+2
-1
@@ -4,6 +4,7 @@ import org.gradle.api.logging.LogLevel
|
|||||||
import org.gradle.api.logging.configuration.WarningMode
|
import org.gradle.api.logging.configuration.WarningMode
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
|
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
|
||||||
|
import org.jetbrains.kotlin.gradle.testbase.NON_INCREMENTAL_COMPILATION_WILL_BE_PERFORMED
|
||||||
import org.jetbrains.kotlin.gradle.testbase.TestVersions
|
import org.jetbrains.kotlin.gradle.testbase.TestVersions
|
||||||
import org.jetbrains.kotlin.gradle.tooling.BuildKotlinToolingMetadataTask
|
import org.jetbrains.kotlin.gradle.tooling.BuildKotlinToolingMetadataTask
|
||||||
import org.jetbrains.kotlin.gradle.util.*
|
import org.jetbrains.kotlin.gradle.util.*
|
||||||
@@ -694,7 +695,7 @@ open class KotlinAndroid70GradleIT : KotlinAndroid36GradleIT() {
|
|||||||
|
|
||||||
project.build(":app:testDebugUnitTest", options = options) {
|
project.build(":app:testDebugUnitTest", options = options) {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertNotContains("Non-incremental compilation will be performed")
|
assertNotContains(NON_INCREMENTAL_COMPILATION_WILL_BE_PERFORMED)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -160,7 +160,7 @@ class BuildCacheIT : KGPBaseTest() {
|
|||||||
bKtSourceFile.modify { it.replace("fun b() {}", "fun b() {}\nfun b2() {}") }
|
bKtSourceFile.modify { it.replace("fun b() {}", "fun b() {}\nfun b2() {}") }
|
||||||
|
|
||||||
build("assemble", buildOptions = defaultBuildOptions.copy(useICClasspathSnapshot = true, logLevel = LogLevel.DEBUG)) {
|
build("assemble", buildOptions = defaultBuildOptions.copy(useICClasspathSnapshot = true, logLevel = LogLevel.DEBUG)) {
|
||||||
assertOutputDoesNotContain("[KOTLIN] [IC] Non-incremental compilation will be performed")
|
assertOutputDoesNotContain(NON_INCREMENTAL_COMPILATION_WILL_BE_PERFORMED)
|
||||||
assertOutputContains("Incremental compilation with ABI snapshot enabled")
|
assertOutputContains("Incremental compilation with ABI snapshot enabled")
|
||||||
assertCompiledKotlinSources(setOf(bKtSourceFile).map { it.relativeTo(projectPath)}, output)
|
assertCompiledKotlinSources(setOf(bKtSourceFile).map { it.relativeTo(projectPath)}, output)
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-2
@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.gradle
|
|||||||
import org.gradle.testkit.runner.BuildResult
|
import org.gradle.testkit.runner.BuildResult
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
import org.jetbrains.kotlin.build.report.metrics.BuildAttribute
|
import org.jetbrains.kotlin.build.report.metrics.BuildAttribute
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy
|
||||||
import org.jetbrains.kotlin.gradle.testbase.*
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.jetbrains.kotlin.gradle.util.checkedReplace
|
import org.jetbrains.kotlin.gradle.util.checkedReplace
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
@@ -648,6 +649,35 @@ abstract class BaseIncrementalCompilationMultiProjectIT : IncrementalCompilation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("Test compilation when incremental state is missing")
|
||||||
|
@GradleTest
|
||||||
|
fun testMissingIncrementalState(gradleVersion: GradleVersion) {
|
||||||
|
defaultProject(gradleVersion) {
|
||||||
|
// Perform the first non-incremental build without using Kotlin daemon so that incremental state is not produced
|
||||||
|
build(
|
||||||
|
":lib:compileKotlin",
|
||||||
|
"-Pkotlin.compiler.execution.strategy=${KotlinCompilerExecutionStrategy.IN_PROCESS.propertyValue}"
|
||||||
|
) {
|
||||||
|
assert(projectPath.resolve("lib/build/kotlin/${compileKotlinTaskName}/classpath-snapshot").listDirectoryEntries().isEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the next build using Kotlin daemon without making a change and check that tasks are up-to-date. This is to ensure
|
||||||
|
// that the `kotlin.compiler.execution.strategy` property used above is not an input to the KotlinCompile task; otherwise the
|
||||||
|
// test in the next build would not be effective.
|
||||||
|
build(":lib:compileKotlin") {
|
||||||
|
assertTasksUpToDate(":lib:$compileKotlinTaskName")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make a change in the source code
|
||||||
|
changeMethodSignatureInLib()
|
||||||
|
|
||||||
|
// In the next build, compilation should be non-incremental as incremental state is missing
|
||||||
|
build(":lib:compileKotlin") {
|
||||||
|
assertNonIncrementalCompilation(BuildAttribute.INCREMENTAL_COMPILATION_FAILED)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@DisplayName("Test handling of failures caused by user errors")
|
@DisplayName("Test handling of failures caused by user errors")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
fun testFailureHandling_UserError(gradleVersion: GradleVersion) {
|
fun testFailureHandling_UserError(gradleVersion: GradleVersion) {
|
||||||
@@ -666,7 +696,7 @@ abstract class BaseIncrementalCompilationMultiProjectIT : IncrementalCompilation
|
|||||||
buildAndFail(":lib:compileKotlin") {
|
buildAndFail(":lib:compileKotlin") {
|
||||||
assertTasksFailed(":lib:$compileKotlinTaskName")
|
assertTasksFailed(":lib:$compileKotlinTaskName")
|
||||||
assertOutputContains("Compilation error. See log for more details")
|
assertOutputContains("Compilation error. See log for more details")
|
||||||
assertOutputDoesNotContain("Non-incremental compilation will be performed: ${BuildAttribute.INCREMENTAL_COMPILATION_FAILED.name}")
|
assertOutputDoesNotContain(NON_INCREMENTAL_COMPILATION_WILL_BE_PERFORMED)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix the compile error in the source code
|
// Fix the compile error in the source code
|
||||||
@@ -704,7 +734,7 @@ abstract class BaseIncrementalCompilationMultiProjectIT : IncrementalCompilation
|
|||||||
|
|
||||||
// In the next build, compilation should be incremental and fail, then fall back to non-incremental compilation and succeed
|
// In the next build, compilation should be incremental and fail, then fall back to non-incremental compilation and succeed
|
||||||
build(":lib:compileKotlin") {
|
build(":lib:compileKotlin") {
|
||||||
assertOutputContains("Non-incremental compilation will be performed: ${BuildAttribute.INCREMENTAL_COMPILATION_FAILED.name}")
|
assertNonIncrementalCompilation(BuildAttribute.INCREMENTAL_COMPILATION_FAILED)
|
||||||
// Also check that the output is not deleted (regression test for KT-49780)
|
// Also check that the output is not deleted (regression test for KT-49780)
|
||||||
assertFileExists(lookupFile)
|
assertFileExists(lookupFile)
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-4
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.testbase
|
|||||||
import org.gradle.api.logging.LogLevel
|
import org.gradle.api.logging.LogLevel
|
||||||
import org.gradle.testkit.runner.BuildResult
|
import org.gradle.testkit.runner.BuildResult
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
|
import org.jetbrains.kotlin.build.report.metrics.BuildAttribute
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
@@ -89,9 +90,12 @@ fun assertCompiledKotlinSources(
|
|||||||
*
|
*
|
||||||
* Note: Log level of output must be set to [LogLevel.DEBUG].
|
* Note: Log level of output must be set to [LogLevel.DEBUG].
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
fun BuildResult.assertNonIncrementalCompilation(reason: BuildAttribute? = null) {
|
||||||
fun BuildResult.assertNonIncrementalCompilation() {
|
if (reason != null) {
|
||||||
assertOutputContains("Non-incremental compilation will be performed")
|
assertOutputContains("$NON_INCREMENTAL_COMPILATION_WILL_BE_PERFORMED: ${reason.name}")
|
||||||
|
} else {
|
||||||
|
assertOutputContains(NON_INCREMENTAL_COMPILATION_WILL_BE_PERFORMED)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,8 +106,10 @@ fun BuildResult.assertNonIncrementalCompilation() {
|
|||||||
* Note: Log level of output must be set to [LogLevel.DEBUG].
|
* Note: Log level of output must be set to [LogLevel.DEBUG].
|
||||||
*/
|
*/
|
||||||
fun BuildResult.assertIncrementalCompilation(expectedCompiledKotlinFiles: Iterable<Path>) {
|
fun BuildResult.assertIncrementalCompilation(expectedCompiledKotlinFiles: Iterable<Path>) {
|
||||||
assertOutputDoesNotContain("Non-incremental compilation will be performed")
|
assertOutputDoesNotContain(NON_INCREMENTAL_COMPILATION_WILL_BE_PERFORMED)
|
||||||
|
|
||||||
val actualCompiledKotlinFiles = extractCompiledKotlinFiles(output)
|
val actualCompiledKotlinFiles = extractCompiledKotlinFiles(output)
|
||||||
assertSameFiles(expectedCompiledKotlinFiles, actualCompiledKotlinFiles, "Compiled Kotlin files differ:\n")
|
assertSameFiles(expectedCompiledKotlinFiles, actualCompiledKotlinFiles, "Compiled Kotlin files differ:\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const val NON_INCREMENTAL_COMPILATION_WILL_BE_PERFORMED = "Non-incremental compilation will be performed"
|
||||||
|
|||||||
Reference in New Issue
Block a user