Fix unstable testIncrementalCompilationAfterCacheHit test
This commit is contained in:
+1
-1
@@ -911,7 +911,7 @@ Finished executing task ':$taskName'|
|
||||
add("--dry-run")
|
||||
}
|
||||
if (options.abiSnapshot) {
|
||||
add("-Dkotlin.incremental.classpath.snapshot.enabled=true")
|
||||
add("-Pkotlin.incremental.classpath.snapshot.enabled=true")
|
||||
}
|
||||
|
||||
if (options.hierarchicalMPPStructureSupport != null) {
|
||||
|
||||
+5
-5
@@ -126,11 +126,10 @@ class BuildCacheIT : KGPBaseTest() {
|
||||
@DisplayName("Restore from build cache should not break incremental compilation")
|
||||
@GradleTest
|
||||
fun testIncrementalCompilationAfterCacheHit(gradleVersion: GradleVersion) {
|
||||
val withSnapshotProperty = "-Dkotlin.incremental.classpath.snapshot.enabled=true"
|
||||
project("incrementalMultiproject", gradleVersion) {
|
||||
project("incrementalMultiproject", gradleVersion, buildOptions = defaultBuildOptions.copy(useICClasspathSnapshot = true)) {
|
||||
enableLocalBuildCache(localBuildCacheDir)
|
||||
build("assemble", withSnapshotProperty)
|
||||
build("clean", "assemble", withSnapshotProperty) {
|
||||
build("assemble")
|
||||
build("clean", "assemble") {
|
||||
assertTasksFromCache(":lib:compileKotlin")
|
||||
assertTasksFromCache(":app:compileKotlin")
|
||||
}
|
||||
@@ -138,8 +137,9 @@ class BuildCacheIT : KGPBaseTest() {
|
||||
|
||||
bKtSourceFile.modify { it.replace("fun b() {}", "fun b() {}\nfun b2() {}") }
|
||||
|
||||
build("assemble", withSnapshotProperty, buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)) {
|
||||
build("assemble", buildOptions = defaultBuildOptions.copy(useICClasspathSnapshot = true, logLevel = LogLevel.DEBUG)) {
|
||||
assertOutputDoesNotContain("[KOTLIN] [IC] Non-incremental compilation will be performed")
|
||||
assertOutputContains("Incremental compilation with ABI snapshot enabled")
|
||||
assertCompiledKotlinSources(setOf(bKtSourceFile).map { it.relativeTo(projectPath)}, output)
|
||||
}
|
||||
|
||||
|
||||
+15
-18
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.api.logging.configuration.WarningMode
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
@@ -322,30 +323,33 @@ class BuildCacheRelocationIT : KGPBaseTest() {
|
||||
@DisplayName("Kotlin incremental compilation should work correctly")
|
||||
@GradleTest
|
||||
fun testKotlinIncrementalCompilation(gradleVersion: GradleVersion) {
|
||||
checkKotlinIncrementalCompilation(gradleVersion)
|
||||
checkKotlinIncrementalCompilationAfterCacheHit(gradleVersion) {
|
||||
assertNonIncrementalCompilation()
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Kotlin incremental compilation with `kotlin.incremental.useClasspathSnapshot` feature should work correctly")
|
||||
@GradleTest
|
||||
fun testKotlinIncrementalCompilation_withGradleClasspathSnapshot(gradleVersion: GradleVersion) {
|
||||
checkKotlinIncrementalCompilation(gradleVersion, useGradleClasspathSnapshot = true)
|
||||
checkKotlinIncrementalCompilationAfterCacheHit(gradleVersion, defaultBuildOptions.copy(useGradleClasspathSnapshot = true)) {
|
||||
assertIncrementalCompilation(listOf("src/main/kotlin/foo.kt", "src/main/kotlin/fooUsage.kt"))
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Kotlin incremental compilation with `kotlin.incremental.classpath.snapshot.enabled` feature should work correctly")
|
||||
@GradleTest
|
||||
fun testKotlinIncrementalCompilation_withICClasspathSnapshot(gradleVersion: GradleVersion) {
|
||||
checkKotlinIncrementalCompilation(gradleVersion, useICClasspathSnapshot = true)
|
||||
checkKotlinIncrementalCompilationAfterCacheHit(gradleVersion, defaultBuildOptions.copy(useICClasspathSnapshot = true)) {
|
||||
assertIncrementalCompilation(listOf("src/main/kotlin/foo.kt", "src/main/kotlin/fooUsage.kt"))
|
||||
assertOutputContains("Incremental compilation with ABI snapshot enabled")
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkKotlinIncrementalCompilation(
|
||||
private fun checkKotlinIncrementalCompilationAfterCacheHit(
|
||||
gradleVersion: GradleVersion,
|
||||
useGradleClasspathSnapshot: Boolean? = null,
|
||||
useICClasspathSnapshot: Boolean? = null
|
||||
buildOptions: BuildOptions = defaultBuildOptions,
|
||||
assertions: BuildResult.() -> Unit
|
||||
) {
|
||||
val buildOptions = defaultBuildOptions.copy(
|
||||
useGradleClasspathSnapshot = useGradleClasspathSnapshot,
|
||||
useICClasspathSnapshot = useICClasspathSnapshot
|
||||
)
|
||||
val (firstProject, secondProject) = prepareTestProjects("buildCacheSimple", gradleVersion, buildOptions)
|
||||
|
||||
// First build, should be stored into the build cache:
|
||||
@@ -361,14 +365,7 @@ class BuildCacheRelocationIT : KGPBaseTest() {
|
||||
// Check whether compilation after a cache hit is incremental (KT-34862)
|
||||
val fooKtSourceFile = secondProject.kotlinSourcesDir().resolve("foo.kt")
|
||||
fooKtSourceFile.modify { it.replace("Int = 1", "String = \"abc\"") }
|
||||
secondProject.build("assemble", buildOptions = buildOptions.copy(logLevel = LogLevel.DEBUG)) {
|
||||
if (useGradleClasspathSnapshot == true || useICClasspathSnapshot == true) {
|
||||
assertIncrementalCompilation(listOf("src/main/kotlin/foo.kt", "src/main/kotlin/fooUsage.kt"))
|
||||
} else {
|
||||
assertNonIncrementalCompilation()
|
||||
}
|
||||
}
|
||||
|
||||
secondProject.build("assemble", buildOptions = buildOptions.copy(logLevel = LogLevel.DEBUG), assertions = assertions)
|
||||
// Revert the change to the return type of foo(), and check if we get a cache hit
|
||||
fooKtSourceFile.modify { it.replace("String = \"abc\"", "Int = 1") }
|
||||
secondProject.build("clean", "assemble") {
|
||||
|
||||
+1
-2
@@ -9,7 +9,6 @@ import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.api.logging.configuration.WarningMode
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties.COMPILE_INCREMENTAL_WITH_ARTIFACT_TRANSFORM
|
||||
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties.COMPILE_INCREMENTAL_WITH_CLASSPATH_SNAPSHOTS
|
||||
import org.jetbrains.kotlin.gradle.BaseGradleIT
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||
import org.jetbrains.kotlin.gradle.report.BuildReportType
|
||||
@@ -88,7 +87,7 @@ data class BuildOptions(
|
||||
}
|
||||
|
||||
useGradleClasspathSnapshot?.let { arguments.add("-P${COMPILE_INCREMENTAL_WITH_ARTIFACT_TRANSFORM.property}=$it") }
|
||||
useICClasspathSnapshot?.let { arguments.add("-D${COMPILE_INCREMENTAL_WITH_CLASSPATH_SNAPSHOTS.property}=$it") }
|
||||
useICClasspathSnapshot?.let { arguments.add("-Pkotlin.incremental.classpath.snapshot.enabled=$it") }
|
||||
|
||||
if (gradleVersion >= GradleVersion.version("6.5")) {
|
||||
if (fileSystemWatchEnabled) {
|
||||
|
||||
+8
-2
@@ -7,8 +7,10 @@ package org.jetbrains.kotlin.compilerRunner
|
||||
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.jetbrains.kotlin.build.report.metrics.*
|
||||
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.toBooleanLenient
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.daemon.common.*
|
||||
import org.jetbrains.kotlin.gradle.logging.*
|
||||
@@ -20,6 +22,7 @@ import org.jetbrains.kotlin.gradle.tasks.cleanOutputsAndLocalState
|
||||
import org.jetbrains.kotlin.gradle.tasks.throwGradleExceptionIfError
|
||||
import org.jetbrains.kotlin.gradle.utils.stackTraceAsString
|
||||
import org.jetbrains.kotlin.incremental.ChangedFiles
|
||||
import org.jetbrains.kotlin.incremental.ClasspathChanges
|
||||
import org.jetbrains.kotlin.incremental.IncrementalModuleInfo
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.*
|
||||
@@ -129,7 +132,9 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
||||
} finally {
|
||||
val taskInfo = TaskExecutionInfo(
|
||||
changedFiles = incrementalCompilationEnvironment?.changedFiles,
|
||||
compilerArguments = compilerArgs
|
||||
compilerArguments = compilerArgs,
|
||||
withAbiSnapshot = incrementalCompilationEnvironment?.withAbiSnapshot,
|
||||
withArtifactTransform = incrementalCompilationEnvironment?.classpathChanges is ClasspathChanges.ClasspathSnapshotEnabled
|
||||
)
|
||||
val result = TaskExecutionResult(buildMetrics = metrics.getMetrics(), icLogLines = icLogLines, taskInfo = taskInfo)
|
||||
TaskExecutionResults[taskPath] = result
|
||||
@@ -282,7 +287,8 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
||||
outputFiles = outputFiles,
|
||||
multiModuleICSettings = icEnv.multiModuleICSettings,
|
||||
modulesInfo = incrementalModuleInfo!!,
|
||||
kotlinScriptExtensions = kotlinScriptExtensions
|
||||
kotlinScriptExtensions = kotlinScriptExtensions,
|
||||
withAbiSnapshot = icEnv.withAbiSnapshot
|
||||
)
|
||||
|
||||
log.info("Options for KOTLIN DAEMON: $compilationOptions")
|
||||
|
||||
+3
-2
@@ -17,9 +17,10 @@ internal class IncrementalCompilationEnvironment(
|
||||
val workingDir: File,
|
||||
val usePreciseJavaTracking: Boolean = false,
|
||||
val disableMultiModuleIC: Boolean = false,
|
||||
val multiModuleICSettings: MultiModuleICSettings
|
||||
val multiModuleICSettings: MultiModuleICSettings,
|
||||
val withAbiSnapshot: Boolean = false
|
||||
) : Serializable {
|
||||
companion object {
|
||||
const val serialVersionUID: Long = 0
|
||||
const val serialVersionUID: Long = 1
|
||||
}
|
||||
}
|
||||
+6
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessageOutputStreamHandler.Companion.IGNORE_TCSM_OVERFLOW
|
||||
import org.jetbrains.kotlin.gradle.plugin.Kotlin2JsPlugin.Companion.NOWARN_2JS_FLAG
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.Companion.jsCompilerProperty
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_ABI_SNAPSHOT
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_CINTEROP_COMMONIZATION
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_GRANULAR_SOURCE_SETS_METADATA
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_OPTIMISTIC_NUMBER_COMMONIZATION
|
||||
@@ -49,6 +50,7 @@ internal fun PropertiesProvider.mapKotlinTaskProperties(task: AbstractKotlinComp
|
||||
}
|
||||
}
|
||||
task.jvmTargetValidationMode.set(jvmTargetValidationMode)
|
||||
task.useKotlinAbiSnapshot.value(useKotlinAbiSnapshot).disallowChanges()
|
||||
}
|
||||
|
||||
if (task is Kotlin2JsCompile) {
|
||||
@@ -174,6 +176,9 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
||||
return gradleProperty || systemProperty
|
||||
}
|
||||
|
||||
val useKotlinAbiSnapshot: Boolean
|
||||
get() = booleanProperty(KOTLIN_ABI_SNAPSHOT) ?: false
|
||||
|
||||
val useFir: Boolean?
|
||||
get() = booleanProperty("kotlin.useFir")
|
||||
|
||||
@@ -503,6 +508,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
||||
const val KOTLIN_MPP_ENABLE_OPTIMISTIC_NUMBER_COMMONIZATION = "kotlin.mpp.enableOptimisticNumberCommonization"
|
||||
const val KOTLIN_KPM_EXPERIMENTAL_MODEL_MAPPING = "kotlin.kpm.experimentalModelMapping"
|
||||
const val KOTLIN_MPP_ENABLE_PLATFORM_INTEGER_COMMONIZATION = "kotlin.mpp.enablePlatformIntegerCommonization"
|
||||
const val KOTLIN_ABI_SNAPSHOT = "kotlin.incremental.classpath.snapshot.enabled"
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+1
-4
@@ -40,10 +40,7 @@ class BuildScanStatisticsListener(
|
||||
log.debug("Collect data takes $collectDataDuration: $compileStatData")
|
||||
|
||||
compileStatData?.also {
|
||||
val reportDataDuration = measureTimeMillis {
|
||||
report(it)
|
||||
}
|
||||
log.debug("Report data takes $reportDataDuration: $compileStatData")
|
||||
report(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-6
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.plugin.stat.CompileStatisticsData
|
||||
import org.jetbrains.kotlin.gradle.plugin.stat.StatTag
|
||||
import org.jetbrains.kotlin.gradle.report.TaskExecutionResult
|
||||
import org.jetbrains.kotlin.incremental.ChangedFiles
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.ifTrue
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.net.InetAddress
|
||||
import java.util.*
|
||||
@@ -100,12 +101,7 @@ class KotlinBuildStatListener {
|
||||
|
||||
private fun parseTags(taskExecutionResult: TaskExecutionResult?): List<StatTag> {
|
||||
val tags = ArrayList<StatTag>()
|
||||
CompilerSystemProperties.COMPILE_INCREMENTAL_WITH_CLASSPATH_SNAPSHOTS.value.toBooleanLenient()?.let {
|
||||
if (it) tags.add(StatTag.ABI_SNAPSHOT)
|
||||
}
|
||||
CompilerSystemProperties.COMPILE_INCREMENTAL_WITH_ARTIFACT_TRANSFORM.value.toBooleanLenient()?.let {
|
||||
if (it) tags.add(StatTag.ARTIFACT_TRANSFORM)
|
||||
}
|
||||
|
||||
val nonIncrementalAttributes = taskExecutionResult?.buildMetrics?.buildAttributes?.asMap() ?: emptyMap()
|
||||
|
||||
if (nonIncrementalAttributes.isEmpty()) {
|
||||
@@ -114,6 +110,15 @@ class KotlinBuildStatListener {
|
||||
tags.add(StatTag.NON_INCREMENTAL)
|
||||
}
|
||||
|
||||
val taskInfo = taskExecutionResult?.taskInfo
|
||||
|
||||
taskInfo?.withAbiSnapshot?.ifTrue {
|
||||
tags.add(StatTag.ABI_SNAPSHOT)
|
||||
}
|
||||
taskInfo?.withArtifactTransform?.ifTrue {
|
||||
tags.add(StatTag.ARTIFACT_TRANSFORM)
|
||||
}
|
||||
|
||||
val debugConfiguration = "-agentlib:"
|
||||
if (ManagementFactory.getRuntimeMXBean().inputArguments.firstOrNull { it.startsWith(debugConfiguration) } != null) {
|
||||
tags.add(StatTag.GRADLE_DEBUG)
|
||||
|
||||
+3
-1
@@ -16,5 +16,7 @@ internal class TaskExecutionResult(
|
||||
|
||||
internal class TaskExecutionInfo(
|
||||
val changedFiles: ChangedFiles? = null,
|
||||
val compilerArguments: Array<String> = emptyArray()
|
||||
val compilerArguments: Array<String> = emptyArray(),
|
||||
val withArtifactTransform: Boolean? = false,
|
||||
val withAbiSnapshot: Boolean? = false
|
||||
)
|
||||
|
||||
+5
-1
@@ -651,6 +651,9 @@ abstract class KotlinCompile @Inject constructor(
|
||||
return super.getClasspath()
|
||||
}
|
||||
|
||||
@get:Input
|
||||
abstract val useKotlinAbiSnapshot: Property<Boolean>
|
||||
|
||||
@get:Nested
|
||||
abstract val classpathSnapshotProperties: ClasspathSnapshotProperties
|
||||
|
||||
@@ -770,7 +773,8 @@ abstract class KotlinCompile @Inject constructor(
|
||||
workingDir = taskBuildCacheableOutputDirectory.get().asFile,
|
||||
usePreciseJavaTracking = usePreciseJavaTracking,
|
||||
disableMultiModuleIC = disableMultiModuleIC,
|
||||
multiModuleICSettings = multiModuleICSettings
|
||||
multiModuleICSettings = multiModuleICSettings,
|
||||
withAbiSnapshot = useKotlinAbiSnapshot.get()
|
||||
)
|
||||
} else null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user