Added prop to suppress all bp plugin warnings Test: ./gradlew :benchmark:benchmark-baseline-profile-gradle-plugin:test Bug: 349646646 Relnote: "Added gradle property androidx.baselineprofile.suppressWarnings to suppress all baseline profile warnings" Change-Id: I7c36e3a0da43aa113394404215725b9c86b46cd5
diff --git a/benchmark/baseline-profile-gradle-plugin/src/main/kotlin/androidx/baselineprofile/gradle/utils/AgpPlugin.kt b/benchmark/baseline-profile-gradle-plugin/src/main/kotlin/androidx/baselineprofile/gradle/utils/AgpPlugin.kt index 29f7c75..8638ad0 100644 --- a/benchmark/baseline-profile-gradle-plugin/src/main/kotlin/androidx/baselineprofile/gradle/utils/AgpPlugin.kt +++ b/benchmark/baseline-profile-gradle-plugin/src/main/kotlin/androidx/baselineprofile/gradle/utils/AgpPlugin.kt
@@ -58,6 +58,10 @@ } ?: return@lazy null } + val suppressWarnings: Boolean by lazy { + project.providers.gradleProperty("androidx.baselineprofile.suppresswarnings").isPresent + } + // Logger protected val logger = BaselineProfilePluginLogger(project.logger) @@ -100,6 +104,14 @@ private fun configureWithAndroidPlugin() { + fun setWarnings() { + if (suppressWarnings) { + logger.suppressAllWarnings() + } else { + getWarnings()?.let { warnings -> logger.setWarnings(warnings) } + } + } + onBeforeFinalizeDsl() testAndroidComponentExtension()?.let { testComponent -> @@ -108,7 +120,7 @@ // This can be done only here, since warnings may depend on user configuration // that is ready only after `finalizeDsl`. - getWarnings()?.let { warnings -> logger.setWarnings(warnings) } + setWarnings() checkAgpVersion() } testComponent.beforeVariants { onTestBeforeVariants(it) } @@ -124,7 +136,7 @@ // This can be done only here, since warnings may depend on user configuration // that is ready only after `finalizeDsl`. - getWarnings()?.let { warnings -> logger.setWarnings(warnings) } + setWarnings() checkAgpVersion() } applicationComponent.beforeVariants { onApplicationBeforeVariants(it) } @@ -140,7 +152,7 @@ // This can be done only here, since warnings may depend on user configuration // that is ready only after `finalizeDsl`. - getWarnings()?.let { warnings -> logger.setWarnings(warnings) } + setWarnings() checkAgpVersion() } libraryComponent.beforeVariants { onLibraryBeforeVariants(it) }
diff --git a/benchmark/baseline-profile-gradle-plugin/src/main/kotlin/androidx/baselineprofile/gradle/utils/BaselineProfilePluginLogger.kt b/benchmark/baseline-profile-gradle-plugin/src/main/kotlin/androidx/baselineprofile/gradle/utils/BaselineProfilePluginLogger.kt index f41bbb1..daebf6e 100644 --- a/benchmark/baseline-profile-gradle-plugin/src/main/kotlin/androidx/baselineprofile/gradle/utils/BaselineProfilePluginLogger.kt +++ b/benchmark/baseline-profile-gradle-plugin/src/main/kotlin/androidx/baselineprofile/gradle/utils/BaselineProfilePluginLogger.kt
@@ -31,21 +31,28 @@ maxAgpVersion = false } + private var suppressAllWarnings: Boolean = false + fun setWarnings(warnings: Warnings) { this.warnings = warnings } + fun suppressAllWarnings() { + suppressAllWarnings = true + } + fun debug(message: String) = logger.debug(message) fun info(message: String) = logger.info(message) fun warn(property: Warnings.() -> (Boolean), propertyName: String?, message: String) { + if (suppressAllWarnings) return if (property(warnings)) { logger.warn(message) if (propertyName != null) { logger.warn( """ - + This warning can be disabled setting the following property: baselineProfile { warnings {
diff --git a/benchmark/baseline-profile-gradle-plugin/src/test/kotlin/androidx/baselineprofile/gradle/consumer/BaselineProfileConsumerPluginTest.kt b/benchmark/baseline-profile-gradle-plugin/src/test/kotlin/androidx/baselineprofile/gradle/consumer/BaselineProfileConsumerPluginTest.kt index e4f5538..736c8a4 100644 --- a/benchmark/baseline-profile-gradle-plugin/src/test/kotlin/androidx/baselineprofile/gradle/consumer/BaselineProfileConsumerPluginTest.kt +++ b/benchmark/baseline-profile-gradle-plugin/src/test/kotlin/androidx/baselineprofile/gradle/consumer/BaselineProfileConsumerPluginTest.kt
@@ -1501,6 +1501,46 @@ } @Test + fun testSuppressWarningWithProperty() { + val requiredLines = + listOf( + "This version of the Baseline Profile Gradle Plugin was tested with versions below", + // We skip the lines in between because they may contain changing version numbers. + "baselineProfile {", + " warnings {", + " maxAgpVersion = false", + " }", + "}" + ) + + projectSetup.consumer.setup(androidPlugin = ANDROID_APPLICATION_PLUGIN) + projectSetup.producer.setupWithoutFlavors( + releaseProfileLines = listOf(Fixtures.CLASS_1_METHOD_1, Fixtures.CLASS_1), + ) + + val gradleCmds = + arrayOf( + "generateBaselineProfile", + "-Pandroidx.benchmark.test.maxagpversion=1.0.0", + ) + + // Run with no suppress warnings property + projectSetup.consumer.gradleRunner.build(*gradleCmds) { + val notFound = it.lines().requireInOrder(*requiredLines.toTypedArray()) + assertThat(notFound).isEmpty() + } + + // Run with suppress warnings property + projectSetup.consumer.gradleRunner.build( + *gradleCmds, + "-Pandroidx.baselineprofile.suppresswarnings" + ) { + val notFound = it.lines().requireInOrder(*requiredLines.toTypedArray()) + assertThat(notFound).isEqualTo(requiredLines) + } + } + + @Test fun testMergeArtAndStartupProfilesShouldDependOnProfileGeneration() { projectSetup.producer.setupWithFreeAndPaidFlavors( freeReleaseProfileLines = listOf(Fixtures.CLASS_1_METHOD_1, Fixtures.CLASS_1),