[Test] Update warning message for tasks that disables GCC
cherry-picked from 26b4c946e67b25b7206c37ba56a79e5ffeb04dd6 ^KT-51947
This commit is contained in:
+18
@@ -752,6 +752,24 @@ class HierarchicalMppIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@GradleTest
|
||||
@GradleTestVersions(maxVersion = TestVersions.Gradle.G_7_3)
|
||||
@DisplayName("KT-51946: Print warning on tasks that are not compatible with configuration cache")
|
||||
fun testHmppTasksReportConfigurationCacheWarningForGradleLessThan74(gradleVersion: GradleVersion, @TempDir tempDir: Path) {
|
||||
with(project("hmppGradleConfigurationCache", gradleVersion = gradleVersion, localRepoDir = tempDir)) {
|
||||
build(":lib:publish")
|
||||
|
||||
// Assert that no warnings are shown when configuration-cache is not enabled
|
||||
build("clean", "assemble") {
|
||||
assertOutputDoesNotContain("""Task \S+ is not compatible with configuration cache""".toRegex())
|
||||
}
|
||||
|
||||
val options = buildOptions.copy(configurationCache = true, configurationCacheProblems = BaseGradleIT.ConfigurationCacheProblems.FAIL)
|
||||
buildAndFail("clean", "assemble", buildOptions = options) {
|
||||
assertOutputContains("""Task \S+ is not compatible with configuration cache""".toRegex())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun TestProject.testDependencyTransformations(
|
||||
subproject: String? = null,
|
||||
|
||||
+18
-2
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.utils
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.internal.StartParameterInternal
|
||||
import org.gradle.api.invocation.Gradle
|
||||
|
||||
internal fun isConfigurationCacheAvailable(gradle: Gradle) =
|
||||
@@ -29,13 +30,28 @@ internal fun unavailableValueError(propertyName: String): Nothing =
|
||||
error("'$propertyName' should be available at configuration time but unavailable on configuration cache reuse")
|
||||
|
||||
fun Task.notCompatibleWithConfigurationCache(reason: String) {
|
||||
if (!isGradleVersionAtLeast(7, 4)) return
|
||||
val reportConfigurationCacheWarnings = try {
|
||||
val startParameters = project.gradle.startParameter as? StartParameterInternal
|
||||
startParameters?.run { isConfigurationCache && !isConfigurationCacheQuiet } ?: false
|
||||
} catch (_: IncompatibleClassChangeError) { // for cases when gradle is way too old
|
||||
false
|
||||
}
|
||||
|
||||
if (!isGradleVersionAtLeast(7, 4)) {
|
||||
if (reportConfigurationCacheWarnings) {
|
||||
logger.warn("Task $name is not compatible with configuration cache: $reason")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
val taskClass = Task::class.java
|
||||
val method = taskClass.getMethod("notCompatibleWithConfigurationCache", String::class.java)
|
||||
|
||||
method.invoke(this, reason)
|
||||
} catch (e: ReflectiveOperationException) {
|
||||
logger.warn("Can't mark task $this as notCompatibleWithConfigurationCache due to reflection issue", e)
|
||||
if (reportConfigurationCacheWarnings) {
|
||||
logger.warn("Reflection issue - task $name is not compatible with configuration cache: $reason", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user