[Gradle] Minor: rename verboseDiagnostics -> useParsableDiagnosticsFormat

^KT-59615 Fixed
This commit is contained in:
Dmitry Savvinov
2023-07-27 09:38:40 +02:00
committed by Space Team
parent 83c53b7ce3
commit e334523fd8
11 changed files with 51 additions and 51 deletions
@@ -280,7 +280,7 @@ abstract class BaseGradleIT {
val withReports: List<BuildReportType> = emptyList(),
val enableKpmModelMapping: Boolean? = null,
val useDaemonFallbackStrategy: Boolean = false,
val useVerboseDiagnosticsReporting: Boolean = true,
val useParsableDiagnosticsFormatting: Boolean = true,
) {
val safeAndroidGradlePluginVersion: AGPVersion
get() = androidGradlePluginVersion ?: error("AGP version is expected to be set")
@@ -937,8 +937,8 @@ abstract class BaseGradleIT {
add("-Dorg.gradle.unsafe.configuration-cache=${options.configurationCache}")
add("-Dorg.gradle.unsafe.configuration-cache-problems=${options.configurationCacheProblems.name.lowercase(Locale.getDefault())}")
if (options.useVerboseDiagnosticsReporting) {
add("-Pkotlin.internal.verboseDiagnostics=true")
if (options.useParsableDiagnosticsFormatting) {
add("-Pkotlin.internal.diagnostics.useParsableFormatting=true")
}
// Workaround: override a console type set in the user machine gradle.properties (since Gradle 4.3):
@@ -19,7 +19,7 @@ class MppDiagnosticsIt : KGPBaseTest() {
fun testDiagnosticsRenderingSmoke(gradleVersion: GradleVersion) {
project("diagnosticsRenderingSmoke", gradleVersion) {
build {
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirDiagnostics())
}
}
}
@@ -52,22 +52,22 @@ class MppDiagnosticsIt : KGPBaseTest() {
project("errorDiagnosticBuildFails", gradleVersion) {
// 'assemble' (triggers compileKotlin-tasks indirectly): fail
buildAndFail("assemble") {
assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirDiagnostics())
}
// 'clean', not directly relevant to Kotlin tasks: build is OK
build("clean") {
assertEqualsToFile(expectedOutputFile("clean"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("clean"), extractProjectsAndTheirDiagnostics())
}
// Custom task, irrelevant to Kotlin tasks: build is OK
build("myTask", "--rerun-tasks") {
assertEqualsToFile(expectedOutputFile("customTask"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("customTask"), extractProjectsAndTheirDiagnostics())
}
// commonizer task: build is OK (otherwise IDE will be bricked)
build("commonize") {
assertEqualsToFile(expectedOutputFile("commonize"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("commonize"), extractProjectsAndTheirDiagnostics())
}
}
}
@@ -79,13 +79,13 @@ class MppDiagnosticsIt : KGPBaseTest() {
project("errorDiagnosticBuildFails", gradleVersion) {
buildAndFail("assemble", buildOptions = buildOptions.copy(configurationCache = true)) {
assertConfigurationCacheStored()
assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirDiagnostics())
}
// fails again
buildAndFail("assemble", buildOptions = buildOptions.copy(configurationCache = true)) {
assertConfigurationCacheReused()
assertEqualsToFile(expectedOutputFile("assemble-cache-reused"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("assemble-cache-reused"), extractProjectsAndTheirDiagnostics())
}
}
}
@@ -94,10 +94,10 @@ class MppDiagnosticsIt : KGPBaseTest() {
fun testErrorDiagnosticBuildSucceeds(gradleVersion: GradleVersion) {
project("errorDiagnosticBuildSucceeds", gradleVersion) {
build("assemble") {
assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirDiagnostics())
}
build("myTask", "--rerun-tasks") {
assertEqualsToFile(expectedOutputFile("customTask"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("customTask"), extractProjectsAndTheirDiagnostics())
}
}
}
@@ -107,7 +107,7 @@ class MppDiagnosticsIt : KGPBaseTest() {
project("suppressGradlePluginErrors", gradleVersion) {
// build succeeds
build("assemble") {
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirDiagnostics())
}
}
}
@@ -116,7 +116,7 @@ class MppDiagnosticsIt : KGPBaseTest() {
fun testSuppressGradlePluginWarnings(gradleVersion: GradleVersion) {
project("suppressGradlePluginWarnings", gradleVersion) {
build("assemble") {
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirDiagnostics())
}
}
}
@@ -128,7 +128,7 @@ class MppDiagnosticsIt : KGPBaseTest() {
// Gradle 8.0+ for some reason renders exception twice in the build log
val testDataSuffixIfAny = if (gradleVersion < GradleVersion.version(TestVersions.Gradle.G_8_0)) "gradle-6.8.3" else null
assertEqualsToFile(expectedOutputFile(testDataSuffixIfAny), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile(testDataSuffixIfAny), extractProjectsAndTheirDiagnostics())
}
}
}
@@ -137,24 +137,24 @@ class MppDiagnosticsIt : KGPBaseTest() {
fun testErrorsFailOnlyRelevantProjects(gradleVersion: GradleVersion) {
project("errorsFailOnlyRelevantProjects", gradleVersion) {
buildAndFail("brokenProjectA:assemble") {
assertEqualsToFile(expectedOutputFile("brokenA"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("brokenA"), extractProjectsAndTheirDiagnostics())
}
buildAndFail("brokenProjectB:assemble") {
assertEqualsToFile(expectedOutputFile("brokenB"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("brokenB"), extractProjectsAndTheirDiagnostics())
}
build("healthyProject:assemble") {
assertEqualsToFile(expectedOutputFile("healthy"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("healthy"), extractProjectsAndTheirDiagnostics())
}
// Turn off parallel execution so that order of execution (and therefore the testdata) is stable
buildAndFail("assemble", buildOptions = buildOptions.copy(parallel = false)) {
assertEqualsToFile(expectedOutputFile("root"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("root"), extractProjectsAndTheirDiagnostics())
}
buildAndFail("assemble", "--continue", buildOptions = buildOptions.copy(parallel = false)) {
assertEqualsToFile(expectedOutputFile("root-with-continue"), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile("root-with-continue"), extractProjectsAndTheirDiagnostics())
}
}
}
@@ -163,7 +163,7 @@ class MppDiagnosticsIt : KGPBaseTest() {
fun testEarlyTasksMaterializationDoesntBreakReports(gradleVersion: GradleVersion) {
project("earlyTasksMaterializationDoesntBreakReports", gradleVersion) {
buildAndFail("assemble") {
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirVerboseDiagnostics())
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirDiagnostics())
}
}
}
@@ -43,7 +43,7 @@ data class BuildOptions(
val usePreciseOutputsBackup: Boolean? = null,
val keepIncrementalCompilationCachesInMemory: Boolean? = null,
val useDaemonFallbackStrategy: Boolean = false,
val verboseDiagnostics: Boolean = true,
val useParsableDiagnosticsFormatting: Boolean = true,
val nativeOptions: NativeOptions = NativeOptions(),
val compilerExecutionStrategy: KotlinCompilerExecutionStrategy? = null,
val runViaBuildToolsApi: Boolean? = null,
@@ -175,8 +175,8 @@ data class BuildOptions(
arguments.add("-Pkotlin.daemon.useFallbackStrategy=$useDaemonFallbackStrategy")
if (verboseDiagnostics) {
arguments.add("-Pkotlin.internal.verboseDiagnostics=$verboseDiagnostics")
if (useParsableDiagnosticsFormatting) {
arguments.add("-Pkotlin.internal.diagnostics.useParsableFormatting=$useParsableDiagnosticsFormatting")
}
if (compilerExecutionStrategy != null) {
@@ -69,12 +69,12 @@ fun String.assertNoDiagnostic(diagnosticFactory: ToolingDiagnosticFactory, withS
}
/**
* NB: Needs verbose mode of diagnostics, see [org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.internalVerboseDiagnostics]
* NB: Needs parsable formatting of diagnostics, see [org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.internalDiagnosticsUseParsableFormat]
* Because this mode is enabled by the 'kotlin.internal'-property, actual output will always contain
* [org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics.InternalKotlinGradlePluginPropertiesUsed].
* For the sake of clarity, this diagnostic is filtered by default.
*/
fun BuildResult.extractProjectsAndTheirVerboseDiagnostics(): String = buildString {
fun BuildResult.extractProjectsAndTheirDiagnostics(): String = buildString {
var diagnosticStarted = false
val currentDiagnostic = mutableListOf<String>()
@@ -101,10 +101,10 @@ fun BuildResult.extractProjectsAndTheirVerboseDiagnostics(): String = buildStrin
currentDiagnostic += line
// Suppress InternalKotlinGradlePluginProperties, but only if the single property it complains about is
// 'kotlin.internal.verboseDiagnostics'
// 'kotlin.internal.diagnostics.useParsableFormatting'
val offendingProperties = currentDiagnostic.asSequence().filter { it.startsWith("kotlin.internal.") }
if (KotlinToolingDiagnostics.InternalKotlinGradlePluginPropertiesUsed.id !in currentDiagnostic.first() ||
offendingProperties.singleOrNull() != "kotlin.internal.verboseDiagnostics"
offendingProperties.singleOrNull() != "kotlin.internal.diagnostics.useParsableFormatting"
) {
appendLine(currentDiagnostic.joinToString(separator = "\n", postfix = "\n"))
}
@@ -2,7 +2,7 @@
w: [InternalKotlinGradlePluginPropertiesUsed | WARNING] ATTENTION! This build uses the following Kotlin Gradle Plugin properties:
kotlin.internal.suppressGradlePluginErrors
kotlin.internal.verboseDiagnostics
kotlin.internal.diagnostics.useParsableFormatting
kotlin.internal-properties are not recommended for production use.
Stability and future compatibility of the build is not guaranteed.
@@ -294,7 +294,7 @@ private fun Project.setupDiagnosticsChecksAndReporting() {
renderReportedDiagnostics(
collectorProvider.get().getDiagnosticsForProject(project),
logger,
diagnosticRenderingOptions.isVerbose
diagnosticRenderingOptions.useParsableFormat
)
}
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLI
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_COMPILER_USE_PRECISE_COMPILATION_RESULTS_BACKUP
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_CREATE_DEFAULT_MULTIPLATFORM_PUBLICATIONS
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_EXPERIMENTAL_TRY_K2
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_INTERNAL_VERBOSE_DIAGNOSTICS
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_INTERNAL_DIAGNOSTICS_USE_PARSABLE_FORMATTING
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_JS_KARMA_BROWSERS
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_JS_STDLIB_DOM_API_INCLUDED
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ALLOW_LEGACY_DEPENDENCIES
@@ -524,8 +524,8 @@ internal class PropertiesProvider private constructor(private val project: Proje
}
.orElse(false)
val internalVerboseDiagnostics: Boolean
get() = booleanProperty(KOTLIN_INTERNAL_VERBOSE_DIAGNOSTICS) ?: false
val internalDiagnosticsUseParsableFormat: Boolean
get() = booleanProperty(KOTLIN_INTERNAL_DIAGNOSTICS_USE_PARSABLE_FORMATTING) ?: false
val suppressedGradlePluginWarnings: List<String>
get() = property(PropertyNames.KOTLIN_SUPPRESS_GRADLE_PLUGIN_WARNINGS)?.split(",").orEmpty()
@@ -650,7 +650,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
**/
val KOTLIN_MPP_HIERARCHICAL_STRUCTURE_BY_DEFAULT = property("$KOTLIN_INTERNAL_NAMESPACE.mpp.hierarchicalStructureByDefault")
val KOTLIN_CREATE_DEFAULT_MULTIPLATFORM_PUBLICATIONS = property("$KOTLIN_INTERNAL_NAMESPACE.mpp.createDefaultMultiplatformPublications")
val KOTLIN_INTERNAL_VERBOSE_DIAGNOSTICS = property("$KOTLIN_INTERNAL_NAMESPACE.verboseDiagnostics")
val KOTLIN_INTERNAL_DIAGNOSTICS_USE_PARSABLE_FORMATTING = property("$KOTLIN_INTERNAL_NAMESPACE.diagnostics.useParsableFormatting")
val KOTLIN_SUPPRESS_GRADLE_PLUGIN_ERRORS = property("$KOTLIN_INTERNAL_NAMESPACE.suppressGradlePluginErrors")
val MPP_13X_FLAGS_SET_BY_PLUGIN = property("$KOTLIN_INTERNAL_NAMESPACE.mpp.13X.flags.setByPlugin")
}
@@ -29,7 +29,7 @@ internal abstract class CheckKotlinGradlePluginConfigurationErrors : DefaultTask
@TaskAction
fun checkNoErrors() {
if (errorDiagnostics.get().isNotEmpty()) {
renderReportedDiagnostics(errorDiagnostics.get(), logger, renderingOptions.get().isVerbose)
renderReportedDiagnostics(errorDiagnostics.get(), logger, renderingOptions.get().useParsableFormat)
throw InvalidUserCodeException("Kotlin Gradle Plugin reported errors. Check the log for details")
}
}
@@ -39,7 +39,7 @@ internal abstract class KotlinToolingDiagnosticsCollector : BuildService<BuildSe
fun report(task: UsesKotlinToolingDiagnostics, diagnostic: ToolingDiagnostic) {
val options = task.diagnosticRenderingOptions.get()
if (!diagnostic.isSuppressed(options)) {
renderReportedDiagnostic(diagnostic, task.logger, options.isVerbose)
renderReportedDiagnostic(diagnostic, task.logger, options.useParsableFormat)
}
}
@@ -62,10 +62,10 @@ internal abstract class KotlinToolingDiagnosticsCollector : BuildService<BuildSe
private fun handleDiagnostic(project: Project, diagnostic: ToolingDiagnostic) {
if (diagnostic.isSuppressed(ToolingDiagnosticRenderingOptions.forProject(project))) return
val isVerbose = project.kotlinPropertiesProvider.internalVerboseDiagnostics
val useParsableFormat = project.kotlinPropertiesProvider.internalDiagnosticsUseParsableFormat
if (isTransparent) {
renderReportedDiagnostic(diagnostic, project.logger, isVerbose)
renderReportedDiagnostic(diagnostic, project.logger, useParsableFormat)
return
}
@@ -9,14 +9,14 @@ import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
internal class ToolingDiagnosticRenderingOptions(
val isVerbose: Boolean,
val useParsableFormat: Boolean,
val suppressedWarningIds: List<String>,
val suppressedErrorIds: List<String>
) {
companion object {
fun forProject(project: Project): ToolingDiagnosticRenderingOptions = with(project.kotlinPropertiesProvider) {
ToolingDiagnosticRenderingOptions(
internalVerboseDiagnostics,
internalDiagnosticsUseParsableFormat,
suppressedGradlePluginWarnings,
suppressedGradlePluginErrors
)
@@ -9,34 +9,34 @@ import org.gradle.api.InvalidUserCodeException
import org.gradle.api.logging.Logger
import org.jetbrains.kotlin.gradle.plugin.diagnostics.ToolingDiagnostic.Severity.*
internal fun renderReportedDiagnostics(diagnostics: Collection<ToolingDiagnostic>, logger: Logger, isVerbose: Boolean) {
internal fun renderReportedDiagnostics(diagnostics: Collection<ToolingDiagnostic>, logger: Logger, useParsableFormat: Boolean) {
for (diagnostic in diagnostics) {
renderReportedDiagnostic(diagnostic, logger, isVerbose)
renderReportedDiagnostic(diagnostic, logger, useParsableFormat)
}
}
internal fun renderReportedDiagnostic(
diagnostic: ToolingDiagnostic,
logger: Logger,
isVerbose: Boolean,
useParsableFormat: Boolean,
) {
when (diagnostic.severity) {
WARNING -> logger.warn("w: ${diagnostic.render(isVerbose)}\n")
WARNING -> logger.warn("w: ${diagnostic.render(useParsableFormat)}\n")
ERROR -> logger.error("e: ${diagnostic.render(isVerbose)}\n")
ERROR -> logger.error("e: ${diagnostic.render(useParsableFormat)}\n")
FATAL -> throw diagnostic.createAnExceptionForFatalDiagnostic(isVerbose)
FATAL -> throw diagnostic.createAnExceptionForFatalDiagnostic(useParsableFormat)
}
}
internal fun ToolingDiagnostic.createAnExceptionForFatalDiagnostic(isVerbose: Boolean): InvalidUserCodeException =
internal fun ToolingDiagnostic.createAnExceptionForFatalDiagnostic(useParsableFormat: Boolean): InvalidUserCodeException =
if (throwable != null)
InvalidUserCodeException(render(isVerbose), throwable)
InvalidUserCodeException(render(useParsableFormat), throwable)
else
InvalidUserCodeException(render(isVerbose))
InvalidUserCodeException(render(useParsableFormat))
private fun ToolingDiagnostic.render(isVerbose: Boolean): String = buildString {
if (isVerbose) {
private fun ToolingDiagnostic.render(useParsableFormat: Boolean): String = buildString {
if (useParsableFormat) {
appendLine(this@render)
append(DIAGNOSTIC_SEPARATOR)
} else {